Merge remote-tracking branch 'upstream/develop' into public-redir
This commit is contained in:
commit
b5b172500d
59 changed files with 18880 additions and 13205 deletions
|
@ -54,7 +54,7 @@ define('API_METHOD_POST', 'POST,PUT');
|
|||
define('API_METHOD_DELETE', 'POST,DELETE');
|
||||
|
||||
$API = [];
|
||||
$called_api = null;
|
||||
$called_api = [];
|
||||
|
||||
/**
|
||||
* It is not sufficient to use local_user() to check whether someone is allowed to use the API,
|
||||
|
@ -935,7 +935,7 @@ function api_reformat_xml(&$item, &$key)
|
|||
*
|
||||
* @return string The XML data
|
||||
*/
|
||||
function api_create_xml($data, $root_element)
|
||||
function api_create_xml(array $data, $root_element)
|
||||
{
|
||||
$childname = key($data);
|
||||
$data2 = array_pop($data);
|
||||
|
@ -960,7 +960,7 @@ function api_create_xml($data, $root_element)
|
|||
$i = 1;
|
||||
|
||||
foreach ($data2 as $item) {
|
||||
$data4[$i++.":".$childname] = $item;
|
||||
$data4[$i++ . ":" . $childname] = $item;
|
||||
}
|
||||
|
||||
$data2 = $data4;
|
||||
|
@ -2216,7 +2216,7 @@ function api_statuses_repeat($type)
|
|||
}
|
||||
|
||||
// this should output the last post (the one we just posted).
|
||||
$called_api = null;
|
||||
$called_api = [];
|
||||
return api_status_show($type);
|
||||
}
|
||||
|
||||
|
@ -2732,7 +2732,7 @@ function api_convert_item($item)
|
|||
*
|
||||
* @param string $body
|
||||
*
|
||||
* @return array|false
|
||||
* @return array
|
||||
*/
|
||||
function api_get_attachments(&$body)
|
||||
{
|
||||
|
@ -2743,7 +2743,7 @@ function api_get_attachments(&$body)
|
|||
$ret = preg_match_all("/\[img\]([$URLSearchString]*)\[\/img\]/ism", $text, $images);
|
||||
|
||||
if (!$ret) {
|
||||
return false;
|
||||
return [];
|
||||
}
|
||||
|
||||
$attachments = [];
|
||||
|
@ -4395,7 +4395,6 @@ function api_fr_photo_create_update($type)
|
|||
throw new InternalServerErrorException("unknown error - this error on uploading or updating a photo should never happen");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief delete a single photo from the database through api
|
||||
*
|
||||
|
@ -4534,6 +4533,7 @@ function api_account_update_profile_image($type)
|
|||
} else {
|
||||
throw new InternalServerErrorException('Unsupported filetype');
|
||||
}
|
||||
|
||||
// change specified profile or all profiles to the new resource-id
|
||||
if ($is_default_profile) {
|
||||
$condition = ["`profile` AND `resource-id` != ? AND `uid` = ?", $data['photo']['id'], api_user()];
|
||||
|
@ -4547,7 +4547,6 @@ function api_account_update_profile_image($type)
|
|||
Contact::updateSelfFromUserID(api_user(), true);
|
||||
|
||||
// Update global directory in background
|
||||
//$user = api_get_user(get_app());
|
||||
$url = System::baseUrl() . '/profile/' . get_app()->user['nickname'];
|
||||
if ($url && strlen(Config::get('system', 'directory'))) {
|
||||
Worker::add(PRIORITY_LOW, "Directory", $url);
|
||||
|
@ -5289,27 +5288,27 @@ function api_in_reply_to($item)
|
|||
|
||||
/**
|
||||
*
|
||||
* @param string $Text
|
||||
* @param string $text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function api_clean_plain_items($Text)
|
||||
function api_clean_plain_items($text)
|
||||
{
|
||||
$include_entities = strtolower(x($_REQUEST, 'include_entities') ? $_REQUEST['include_entities'] : "false");
|
||||
|
||||
$Text = BBCode::cleanPictureLinks($Text);
|
||||
$text = BBCode::cleanPictureLinks($text);
|
||||
$URLSearchString = "^\[\]";
|
||||
|
||||
$Text = preg_replace("/([!#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $Text);
|
||||
$text = preg_replace("/([!#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $text);
|
||||
|
||||
if ($include_entities == "true") {
|
||||
$Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[url=$1]$1[/url]', $Text);
|
||||
$text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[url=$1]$1[/url]', $text);
|
||||
}
|
||||
|
||||
// Simplify "attachment" element
|
||||
$Text = api_clean_attachments($Text);
|
||||
$text = api_clean_attachments($text);
|
||||
|
||||
return($Text);
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -116,7 +116,7 @@ function localize_item(&$item) {
|
|||
$item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
|
||||
}
|
||||
|
||||
/// @Separted ???
|
||||
/// @TODO Separted ???
|
||||
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
|
||||
if (activity_match($item['verb'], ACTIVITY_LIKE)
|
||||
|| activity_match($item['verb'], ACTIVITY_DISLIKE)
|
||||
|
@ -162,22 +162,19 @@ function localize_item(&$item) {
|
|||
|
||||
if (activity_match($item['verb'], ACTIVITY_LIKE)) {
|
||||
$bodyverb = L10n::t('%1$s likes %2$s\'s %3$s');
|
||||
}
|
||||
elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
|
||||
} elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
|
||||
$bodyverb = L10n::t('%1$s doesn\'t like %2$s\'s %3$s');
|
||||
}
|
||||
elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) {
|
||||
} elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) {
|
||||
$bodyverb = L10n::t('%1$s attends %2$s\'s %3$s');
|
||||
}
|
||||
elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) {
|
||||
} elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) {
|
||||
$bodyverb = L10n::t('%1$s doesn\'t attend %2$s\'s %3$s');
|
||||
}
|
||||
elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
|
||||
} elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
|
||||
$bodyverb = L10n::t('%1$s attends maybe %2$s\'s %3$s');
|
||||
}
|
||||
$item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
|
||||
|
||||
$item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
|
||||
}
|
||||
|
||||
if (activity_match($item['verb'], ACTIVITY_FRIEND)) {
|
||||
|
||||
if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
|
||||
|
@ -304,8 +301,8 @@ function localize_item(&$item) {
|
|||
$item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag );
|
||||
|
||||
}
|
||||
if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
|
||||
|
||||
if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
|
||||
if ($item['object-type'] == "") {
|
||||
return;
|
||||
}
|
||||
|
@ -385,10 +382,9 @@ function visible_activity($item) {
|
|||
}
|
||||
}
|
||||
|
||||
if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
|
||||
if (!($item['self'] && ($item['uid'] == local_user()))) {
|
||||
return false;
|
||||
}
|
||||
// @TODO below if() block can be rewritten to a single line: $isVisible = allConditionsHere;
|
||||
if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE && empty($item['self']) && $item['uid'] == local_user()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1081,7 +1077,7 @@ function builtin_activity_puller($item, &$conv_responses) {
|
|||
|
||||
$url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
|
||||
|
||||
if (!$item['thr-parent']) {
|
||||
if (!x($item, 'thr-parent')) {
|
||||
$item['thr-parent'] = $item['parent-uri'];
|
||||
}
|
||||
|
||||
|
@ -1569,19 +1565,17 @@ function sort_thr_commented(array $a, array $b)
|
|||
return strcmp($b['commented'], $a['commented']);
|
||||
}
|
||||
|
||||
/// @TODO Add type-hint
|
||||
function render_location_dummy($item) {
|
||||
if ($item['location'] != "") {
|
||||
function render_location_dummy(array $item) {
|
||||
if (x($item, 'location') && !empty($item['location'])) {
|
||||
return $item['location'];
|
||||
}
|
||||
|
||||
if ($item['coord'] != "") {
|
||||
if (x($item, 'coord') && !empty($item['coord'])) {
|
||||
return $item['coord'];
|
||||
}
|
||||
}
|
||||
|
||||
/// @TODO Add type-hint
|
||||
function get_responses($conv_responses, $response_verbs, $ob, $item) {
|
||||
function get_responses(array $conv_responses, array $response_verbs, $ob, array $item) {
|
||||
$ret = [];
|
||||
foreach ($response_verbs as $v) {
|
||||
$ret[$v] = [];
|
||||
|
|
|
@ -92,6 +92,15 @@ class dba {
|
|||
return self::$connected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the database object.
|
||||
* @return PDO|mysqli
|
||||
*/
|
||||
public static function get_db()
|
||||
{
|
||||
return self::$db;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the MySQL server version string
|
||||
*
|
||||
|
|
|
@ -274,6 +274,7 @@ function consume_feed($xml, $importer, $contact, &$hub, $datedir = 0, $pass = 0)
|
|||
function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') {
|
||||
|
||||
$a = get_app();
|
||||
$r = null;
|
||||
|
||||
if (is_array($importer)) {
|
||||
$r = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1",
|
||||
|
|
|
@ -254,6 +254,7 @@ function can_write_wall($owner)
|
|||
return false;
|
||||
}
|
||||
|
||||
/// @TODO $groups should be array
|
||||
function permissions_sql($owner_id, $remote_verified = false, $groups = null)
|
||||
{
|
||||
$local_user = local_user();
|
||||
|
@ -275,6 +276,13 @@ function permissions_sql($owner_id, $remote_verified = false, $groups = null)
|
|||
*/
|
||||
if ($local_user && $local_user == $owner_id) {
|
||||
$sql = '';
|
||||
/**
|
||||
* Authenticated visitor. Unless pre-verified,
|
||||
* check that the contact belongs to this $owner_id
|
||||
* and load the groups the visitor belongs to.
|
||||
* If pre-verified, the caller is expected to have already
|
||||
* done this and passed the groups into this function.
|
||||
*/
|
||||
} elseif ($remote_user) {
|
||||
/*
|
||||
* Authenticated visitor. Unless pre-verified,
|
||||
|
@ -298,9 +306,10 @@ function permissions_sql($owner_id, $remote_verified = false, $groups = null)
|
|||
if ($remote_verified) {
|
||||
$gs = '<<>>'; // should be impossible to match
|
||||
|
||||
if (is_array($groups) && count($groups)) {
|
||||
foreach ($groups as $g)
|
||||
if (is_array($groups)) {
|
||||
foreach ($groups as $g) {
|
||||
$gs .= '|<' . intval($g) . '>';
|
||||
}
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
|
|
|
@ -152,7 +152,7 @@ function autoname($len) {
|
|||
'nd','ng','nk','nt','rn','rp','rt'];
|
||||
|
||||
$noend = ['bl', 'br', 'cl','cr','dr','fl','fr','gl','gr',
|
||||
'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh'];
|
||||
'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh','q'];
|
||||
|
||||
$start = mt_rand(0,2);
|
||||
if ($start == 0) {
|
||||
|
@ -178,14 +178,13 @@ function autoname($len) {
|
|||
$word = substr($word,0,$len);
|
||||
|
||||
foreach ($noend as $noe) {
|
||||
if ((strlen($word) > 2) && (substr($word, -2) == $noe)) {
|
||||
$word = substr($word, 0, -1);
|
||||
$noelen = strlen($noe);
|
||||
if ((strlen($word) > $noelen) && (substr($word, -$noelen) == $noe)) {
|
||||
$word = autoname($len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (substr($word, -1) == 'q') {
|
||||
$word = substr($word, 0, -1);
|
||||
}
|
||||
|
||||
return $word;
|
||||
}
|
||||
|
||||
|
@ -453,7 +452,7 @@ function perms2str($p) {
|
|||
if (is_array($p)) {
|
||||
$tmp = $p;
|
||||
} else {
|
||||
$tmp = explode(',',$p);
|
||||
$tmp = explode(',', $p);
|
||||
}
|
||||
|
||||
if (is_array($tmp)) {
|
||||
|
@ -1661,10 +1660,11 @@ function bb_translate_video($s) {
|
|||
$r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER);
|
||||
if ($r) {
|
||||
foreach ($matches as $mtch) {
|
||||
if ((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be')))
|
||||
$s = str_replace($mtch[0],'[youtube]' . $mtch[1] . '[/youtube]',$s);
|
||||
elseif (stristr($mtch[1],'vimeo'))
|
||||
$s = str_replace($mtch[0],'[vimeo]' . $mtch[1] . '[/vimeo]',$s);
|
||||
if ((stristr($mtch[1], 'youtube')) || (stristr($mtch[1], 'youtu.be'))) {
|
||||
$s = str_replace($mtch[0], '[youtube]' . $mtch[1] . '[/youtube]', $s);
|
||||
} elseif (stristr($mtch[1], 'vimeo')) {
|
||||
$s = str_replace($mtch[0], '[vimeo]' . $mtch[1] . '[/vimeo]', $s);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $s;
|
||||
|
@ -1782,7 +1782,7 @@ function file_tag_file_query($table,$s,$type = 'file') {
|
|||
}
|
||||
|
||||
// ex. given music,video return <music><video> or [music][video]
|
||||
function file_tag_list_to_file($list,$type = 'file') {
|
||||
function file_tag_list_to_file($list, $type = 'file') {
|
||||
$tag_list = '';
|
||||
if (strlen($list)) {
|
||||
$list_array = explode(",",$list);
|
||||
|
@ -1804,7 +1804,7 @@ function file_tag_list_to_file($list,$type = 'file') {
|
|||
}
|
||||
|
||||
// ex. given <music><video>[friends], return music,video or friends
|
||||
function file_tag_file_to_list($file,$type = 'file') {
|
||||
function file_tag_file_to_list($file, $type = 'file') {
|
||||
$matches = false;
|
||||
$list = '';
|
||||
if ($type == 'file') {
|
||||
|
@ -1830,8 +1830,7 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
|
|||
|
||||
if (!intval($uid)) {
|
||||
return false;
|
||||
}
|
||||
if ($file_old == $file_new) {
|
||||
} elseif ($file_old == $file_new) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1854,8 +1853,9 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
|
|||
$check_new_tags = explode(",",file_tag_file_to_list($file_new,$type));
|
||||
|
||||
foreach ($check_new_tags as $tag) {
|
||||
if (! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket))
|
||||
if (! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket)) {
|
||||
$new_tags[] = $tag;
|
||||
}
|
||||
}
|
||||
|
||||
$filetags_updated .= file_tag_list_to_file(implode(",",$new_tags),$type);
|
||||
|
@ -1865,8 +1865,9 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
|
|||
$check_deleted_tags = explode(",",file_tag_file_to_list($file_old,$type));
|
||||
|
||||
foreach ($check_deleted_tags as $tag) {
|
||||
if (! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket))
|
||||
if (! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket)) {
|
||||
$deleted_tags[] = $tag;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($deleted_tags as $key => $tag) {
|
||||
|
@ -1980,17 +1981,22 @@ function protect_sprintf($s) {
|
|||
return str_replace('%', '%%', $s);
|
||||
}
|
||||
|
||||
|
||||
/// @TODO Rewrite this
|
||||
function is_a_date_arg($s) {
|
||||
$i = intval($s);
|
||||
|
||||
if ($i > 1900) {
|
||||
$y = date('Y');
|
||||
|
||||
if ($i <= $y + 1 && strpos($s, '-') == 4) {
|
||||
$m = intval(substr($s,5));
|
||||
if ($m > 0 && $m <= 12)
|
||||
$m = intval(substr($s, 5));
|
||||
|
||||
if ($m > 0 && $m <= 12) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2008,6 +2014,7 @@ function deindent($text, $chr = "[\t ]", $count = NULL) {
|
|||
preg_match("|^" . $chr . "*|", $lines[$k], $m);
|
||||
$count = strlen($m[0]);
|
||||
}
|
||||
|
||||
for ($k = 0; $k < count($lines); $k++) {
|
||||
$lines[$k] = preg_replace("|^" . $chr . "{" . $count . "}|", "", $lines[$k]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue