added spaces + some curly braces

Signed-off-by: Roland Häder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2017-01-26 16:01:56 +01:00 committed by Roland Haeder
parent 0cd241bcbe
commit 41a36606c6
No known key found for this signature in database
GPG key ID: B72F8185C6C7BD78
60 changed files with 1018 additions and 930 deletions

View file

@ -33,10 +33,11 @@ class DirSearch {
$ostatus = NETWORK_DFRN; $ostatus = NETWORK_DFRN;
// check if we search only communities or every contact // check if we search only communities or every contact
if($mode === "community") if ($mode === "community") {
$extra_sql = " AND `community`"; $extra_sql = " AND `community`";
else } else {
$extra_sql = ""; $extra_sql = "";
}
$search .= "%"; $search .= "%";

View file

@ -154,12 +154,16 @@ class ForumManager {
foreach($contacts as $contact) { foreach($contacts as $contact) {
$forumlist .= micropro($contact,false,'forumlist-profile-advanced'); $forumlist .= micropro($contact,false,'forumlist-profile-advanced');
$total_shown ++; $total_shown ++;
if($total_shown == $show_total)
if ($total_shown == $show_total) {
break; break;
} }
}
if(count($contacts) > 0) if (count($contacts) > 0) {
$o .= $forumlist; $o .= $forumlist;
}
return $o; return $o;
} }

View file

@ -1133,15 +1133,17 @@ class Probe {
$password = ''; $password = '';
openssl_private_decrypt(hex2bin($r[0]['pass']), $password,$x[0]['prvkey']); openssl_private_decrypt(hex2bin($r[0]['pass']), $password,$x[0]['prvkey']);
$mbox = email_connect($mailbox,$r[0]['user'], $password); $mbox = email_connect($mailbox,$r[0]['user'], $password);
if(!mbox) if (!$mbox) {
return false; return false;
} }
}
$msgs = email_poll($mbox, $uri); $msgs = email_poll($mbox, $uri);
logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG); logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
if (!count($msgs)) if (!count($msgs)) {
return false; return false;
}
$data = array(); $data = array();
@ -1157,10 +1159,11 @@ class Probe {
$data["poll"] = 'email '.random_string(); $data["poll"] = 'email '.random_string();
$x = email_msg_meta($mbox, $msgs[0]); $x = email_msg_meta($mbox, $msgs[0]);
if(stristr($x[0]->from, $uri)) if (stristr($x[0]->from, $uri)) {
$adr = imap_rfc822_parse_adrlist($x[0]->from, ''); $adr = imap_rfc822_parse_adrlist($x[0]->from, '');
elseif(stristr($x[0]->to, $uri)) } elseif (stristr($x[0]->to, $uri)) {
$adr = imap_rfc822_parse_adrlist($x[0]->to, ''); $adr = imap_rfc822_parse_adrlist($x[0]->to, '');
}
if (isset($adr)) { if (isset($adr)) {
foreach($adr as $feadr) { foreach($adr as $feadr) {
if ((strcasecmp($feadr->mailbox, $data["name"]) == 0) if ((strcasecmp($feadr->mailbox, $data["name"]) == 0)

View file

@ -170,11 +170,13 @@ class Smilies {
* @todo: Rework because it doesn't work correctly * @todo: Rework because it doesn't work correctly
*/ */
private function preg_heart($x) { private function preg_heart($x) {
if(strlen($x[1]) == 1) if (strlen($x[1]) == 1) {
return $x[0]; return $x[0];
}
$t = ''; $t = '';
for($cnt = 0; $cnt < strlen($x[1]); $cnt ++) for($cnt = 0; $cnt < strlen($x[1]); $cnt ++) {
$t .= '<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-heart.gif" alt="&lt;3" />'; $t .= '<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-heart.gif" alt="&lt;3" />';
}
$r = str_replace($x[0],$t,$x[0]); $r = str_replace($x[0],$t,$x[0]);
return $r; return $r;
} }

View file

@ -215,9 +215,9 @@ function common_friends_visitor_widget($profile_uid) {
dbesc(normalise_link(get_my_url())), dbesc(normalise_link(get_my_url())),
intval($profile_uid) intval($profile_uid)
); );
if (dbm::is_result($r)) if (dbm::is_result($r)) {
$cid = $r[0]['id']; $cid = $r[0]['id'];
else { } else {
$r = q("select id from gcontact where nurl = '%s' limit 1", $r = q("select id from gcontact where nurl = '%s' limit 1",
dbesc(normalise_link(get_my_url())) dbesc(normalise_link(get_my_url()))
); );
@ -227,22 +227,26 @@ function common_friends_visitor_widget($profile_uid) {
} }
} }
if($cid == 0 && $zcid == 0) if ($cid == 0 && $zcid == 0) {
return; return;
}
require_once('include/socgraph.php'); require_once('include/socgraph.php');
if($cid) if ($cid) {
$t = count_common_friends($profile_uid,$cid); $t = count_common_friends($profile_uid,$cid);
else } else {
$t = count_common_friends_zcid($profile_uid,$zcid); $t = count_common_friends_zcid($profile_uid,$zcid);
if(! $t) }
if (! $t) {
return; return;
}
if($cid) if ($cid) {
$r = common_friends($profile_uid,$cid,0,5,true); $r = common_friends($profile_uid,$cid,0,5,true);
else } else {
$r = common_friends_zcid($profile_uid,$zcid,0,5,true); $r = common_friends_zcid($profile_uid,$zcid,0,5,true);
}
return replace_macros(get_markup_template('remote_friends_common.tpl'), array( return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
'$desc' => sprintf( tt("%d contact in common", "%d contacts in common", $t), $t), '$desc' => sprintf( tt("%d contact in common", "%d contacts in common", $t), $t),

View file

@ -1418,9 +1418,11 @@ function sort_thr_commented($a,$b) {
} }
function find_thread_parent_index($arr,$x) { function find_thread_parent_index($arr,$x) {
foreach($arr as $k => $v) foreach($arr as $k => $v) {
if($v['id'] == $x['parent']) if ($v['id'] == $x['parent']) {
return $k; return $k;
}
}
return false; return false;
} }
@ -1443,8 +1445,7 @@ function get_responses($conv_responses,$response_verbs,$ob,$item) {
$ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS); $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);
array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-' array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-'
. (($ob) ? $ob->get_id() : $item['id']) . '"><b>' . t('View all') . '</b></a>'); . (($ob) ? $ob->get_id() : $item['id']) . '"><b>' . t('View all') . '</b></a>');
} } else {
else {
$ret[$v]['list_part'] = ''; $ret[$v]['list_part'] = '';
} }
$ret[$v]['button'] = get_response_button_text($v,$ret[$v]['count']); $ret[$v]['button'] = get_response_button_text($v,$ret[$v]['count']);

View file

@ -290,11 +290,13 @@ function cron_clear_cache(App $a) {
if ($last) { if ($last) {
$next = $last + (3600); // Once per hour $next = $last + (3600); // Once per hour
$clear_cache = ($next <= time()); $clear_cache = ($next <= time());
} else } else {
$clear_cache = true; $clear_cache = true;
}
if (!$clear_cache) if (!$clear_cache) {
return; return;
}
// clear old cache // clear old cache
Cache::clear(); Cache::clear();
@ -313,7 +315,9 @@ function cron_clear_cache(App $a) {
clear_cache($a->get_basepath(), $a->get_basepath()."/proxy"); clear_cache($a->get_basepath(), $a->get_basepath()."/proxy");
$cachetime = get_config('system','proxy_cache_time'); $cachetime = get_config('system','proxy_cache_time');
if (!$cachetime) $cachetime = PROXY_DEFAULT_TIME; if (!$cachetime) {
$cachetime = PROXY_DEFAULT_TIME;
}
q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime); q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime);
} }
@ -326,26 +330,30 @@ function cron_clear_cache(App $a) {
// Maximum table size in megabyte // Maximum table size in megabyte
$max_tablesize = intval(get_config('system','optimize_max_tablesize')) * 1000000; $max_tablesize = intval(get_config('system','optimize_max_tablesize')) * 1000000;
if ($max_tablesize == 0) if ($max_tablesize == 0) {
$max_tablesize = 100 * 1000000; // Default are 100 MB $max_tablesize = 100 * 1000000; // Default are 100 MB
}
if ($max_tablesize > 0) { if ($max_tablesize > 0) {
// Minimum fragmentation level in percent // Minimum fragmentation level in percent
$fragmentation_level = intval(get_config('system','optimize_fragmentation')) / 100; $fragmentation_level = intval(get_config('system','optimize_fragmentation')) / 100;
if ($fragmentation_level == 0) if ($fragmentation_level == 0) {
$fragmentation_level = 0.3; // Default value is 30% $fragmentation_level = 0.3; // Default value is 30%
}
// Optimize some tables that need to be optimized // Optimize some tables that need to be optimized
$r = q("SHOW TABLE STATUS"); $r = q("SHOW TABLE STATUS");
foreach($r as $table) { foreach($r as $table) {
// Don't optimize tables that are too large // Don't optimize tables that are too large
if ($table["Data_length"] > $max_tablesize) if ($table["Data_length"] > $max_tablesize) {
continue; continue;
}
// Don't optimize empty tables // Don't optimize empty tables
if ($table["Data_length"] == 0) if ($table["Data_length"] == 0) {
continue; continue;
}
// Calculate fragmentation // Calculate fragmentation
$fragmentation = $table["Data_free"] / ($table["Data_length"] + $table["Index_length"]); $fragmentation = $table["Data_free"] / ($table["Data_length"] + $table["Index_length"]);
@ -353,8 +361,9 @@ function cron_clear_cache(App $a) {
logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG); logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG);
// Don't optimize tables that needn't to be optimized // Don't optimize tables that needn't to be optimized
if ($fragmentation < $fragmentation_level) if ($fragmentation < $fragmentation_level) {
continue; continue;
}
// So optimize it // So optimize it
logger("Optimize Table ".$table["Name"], LOGGER_DEBUG); logger("Optimize Table ".$table["Name"], LOGGER_DEBUG);
@ -414,9 +423,11 @@ function cron_repair_database() {
// Update the global contacts for local users // Update the global contacts for local users
$r = q("SELECT `uid` FROM `user` WHERE `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`"); $r = q("SELECT `uid` FROM `user` WHERE `verified` AND NOT `blocked` AND NOT `account_removed` AND NOT `account_expired`");
if (dbm::is_result($r)) if (dbm::is_result($r)) {
foreach ($r AS $user) foreach ($r AS $user) {
update_gcontact_for_user($user["uid"]); update_gcontact_for_user($user["uid"]);
}
}
/// @todo /// @todo
/// - remove thread entries without item /// - remove thread entries without item

View file

@ -8,19 +8,21 @@ function cronhooks_run(&$argv, &$argc){
require_once('include/datetime.php'); require_once('include/datetime.php');
if (($argc == 2) AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) { if (($argc == 2) AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
foreach ($a->hooks["cron"] as $hook) foreach ($a->hooks["cron"] as $hook) {
if ($hook[1] == $argv[1]) { if ($hook[1] == $argv[1]) {
logger("Calling cron hook '".$hook[1]."'", LOGGER_DEBUG); logger("Calling cron hook '".$hook[1]."'", LOGGER_DEBUG);
call_single_hook($a, $name, $hook, $data); call_single_hook($a, $name, $hook, $data);
} }
}
return; return;
} }
$last = get_config('system', 'last_cronhook'); $last = get_config('system', 'last_cronhook');
$poll_interval = intval(get_config('system','cronhook_interval')); $poll_interval = intval(get_config('system','cronhook_interval'));
if(! $poll_interval) if (! $poll_interval) {
$poll_interval = 9; $poll_interval = 9;
}
if ($last) { if ($last) {
$next = $last + ($poll_interval * 60); $next = $last + ($poll_interval * 60);

View file

@ -486,10 +486,12 @@ function cal($y = 0,$m = 0, $links = false, $class='') {
$thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y'); $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
$thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m'); $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m');
if(! $y) if (! $y) {
$y = $thisyear; $y = $thisyear;
if(! $m) }
if (! $m) {
$m = intval($thismonth); $m = intval($thismonth);
}
$dn = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); $dn = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
$f = get_first_dim($y,$m); $f = get_first_dim($y,$m);
@ -498,29 +500,33 @@ function cal($y = 0,$m = 0, $links = false, $class='') {
$dow = 0; $dow = 0;
$started = false; $started = false;
if(($y == $thisyear) && ($m == $thismonth)) if (($y == $thisyear) && ($m == $thismonth)) {
$tddate = intval(datetime_convert('UTC',date_default_timezone_get(),'now','j')); $tddate = intval(datetime_convert('UTC',date_default_timezone_get(),'now','j'));
}
$str_month = day_translate($mtab[$m]); $str_month = day_translate($mtab[$m]);
$o = '<table class="calendar' . $class . '">'; $o = '<table class="calendar' . $class . '">';
$o .= "<caption>$str_month $y</caption><tr>"; $o .= "<caption>$str_month $y</caption><tr>";
for($a = 0; $a < 7; $a ++) for($a = 0; $a < 7; $a ++) {
$o .= '<th>' . mb_substr(day_translate($dn[$a]),0,3,'UTF-8') . '</th>'; $o .= '<th>' . mb_substr(day_translate($dn[$a]),0,3,'UTF-8') . '</th>';
}
$o .= '</tr><tr>'; $o .= '</tr><tr>';
while ($d <= $l) { while ($d <= $l) {
if(($dow == $f) && (! $started)) if (($dow == $f) && (! $started)) {
$started = true; $started = true;
}
$today = (((isset($tddate)) && ($tddate == $d)) ? "class=\"today\" " : ''); $today = (((isset($tddate)) && ($tddate == $d)) ? "class=\"today\" " : '');
$o .= "<td $today>"; $o .= "<td $today>";
$day = str_replace(' ','&nbsp;',sprintf('%2.2d', $d)); $day = str_replace(' ','&nbsp;',sprintf('%2.2d', $d));
if ($started) { if ($started) {
if(is_array($links) && isset($links[$d])) if (is_array($links) && isset($links[$d])) {
$o .= "<a href=\"{$links[$d]}\">$day</a>"; $o .= "<a href=\"{$links[$d]}\">$day</a>";
else } else {
$o .= $day; $o .= $day;
}
$d ++; $d ++;
} else { } else {
@ -534,9 +540,11 @@ function cal($y = 0,$m = 0, $links = false, $class='') {
$o .= '</tr><tr>'; $o .= '</tr><tr>';
} }
} }
if($dow) if ($dow) {
for($a = $dow; $a < 7; $a ++) for ($a = $dow; $a < 7; $a ++) {
$o .= '<td>&nbsp;</td>'; $o .= '<td>&nbsp;</td>';
}
}
$o .= '</tr></table>'."\r\n"; $o .= '</tr></table>'."\r\n";

View file

@ -3632,17 +3632,20 @@ class Diaspora {
} }
$r = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($contact['uid'])); $r = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($contact['uid']));
if(!$r) if (!dbm::is_result($r)) {
return false; return false;
}
$contact["uprvkey"] = $r[0]['prvkey']; $contact["uprvkey"] = $r[0]['prvkey'];
$r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", intval($post_id)); $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", intval($post_id));
if (!$r) if (!dbm::is_result($r)) {
return false; return false;
}
if (!in_array($r[0]["verb"], array(ACTIVITY_LIKE, ACTIVITY_DISLIKE))) if (!in_array($r[0]["verb"], array(ACTIVITY_LIKE, ACTIVITY_DISLIKE))) {
return false; return false;
}
$message = self::construct_like($r[0], $contact); $message = self::construct_like($r[0], $contact);
$message["author_signature"] = self::signature($contact, $message); $message["author_signature"] = self::signature($contact, $message);

View file

@ -177,7 +177,7 @@ function discover_directory($search) {
foreach ($j->results as $jj) { foreach ($j->results as $jj) {
// Check if the contact already exists // Check if the contact already exists
$exists = q("SELECT `id`, `last_contact`, `last_failure`, `updated` FROM `gcontact` WHERE `nurl` = '%s'", normalise_link($jj->url)); $exists = q("SELECT `id`, `last_contact`, `last_failure`, `updated` FROM `gcontact` WHERE `nurl` = '%s'", normalise_link($jj->url));
if ($exists) { if (dbm::is_result($exists)) {
logger("Profile ".$jj->url." already exists (".$search.")", LOGGER_DEBUG); logger("Profile ".$jj->url." already exists (".$search.")", LOGGER_DEBUG);
if (($exists[0]["last_contact"] < $exists[0]["last_failure"]) AND if (($exists[0]["last_contact"] < $exists[0]["last_failure"]) AND

View file

@ -411,10 +411,12 @@ function notification($params) {
$hash = random_string(); $hash = random_string();
$r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1", $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1",
dbesc($hash)); dbesc($hash));
if (dbm::is_result($r)) if (dbm::is_result($r)) {
$dups = true; $dups = true;
}
} while ($dups == true); } while ($dups == true);
/// @TODO One statement is enough
$datarray = array(); $datarray = array();
$datarray['hash'] = $hash; $datarray['hash'] = $hash;
$datarray['name'] = $params['source_name']; $datarray['name'] = $params['source_name'];

View file

@ -750,12 +750,14 @@ function event_format_export ($events, $format = 'ical', $timezone) {
* @return array Query results * @return array Query results
*/ */
function events_by_uid($uid = 0, $sql_extra = '') { function events_by_uid($uid = 0, $sql_extra = '') {
if($uid == 0) if ($uid == 0) {
return; return;
}
// The permission condition if no condition was transmitted // The permission condition if no condition was transmitted
if($sql_extra == '') if ($sql_extra == '') {
$sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' "; $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' ";
}
// does the user who requests happen to be the owner of the events // does the user who requests happen to be the owner of the events
// requested? then show all of your events, otherwise only those that // requested? then show all of your events, otherwise only those that
@ -772,9 +774,10 @@ function events_by_uid($uid = 0, $sql_extra = '') {
); );
} }
if (dbm::is_result($r)) if (dbm::is_result($r)) {
return $r; return $r;
} }
}
/** /**
* *
@ -795,20 +798,23 @@ function event_export($uid, $format = 'ical') {
// we are allowed to show events // we are allowed to show events
// get the timezone the user is in // get the timezone the user is in
$r = q("SELECT `timezone` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid)); $r = q("SELECT `timezone` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
if (dbm::is_result($r)) if (dbm::is_result($r)) {
$timezone = $r[0]['timezone']; $timezone = $r[0]['timezone'];
}
// get all events which are owned by a uid (respects permissions); // get all events which are owned by a uid (respects permissions);
$events = events_by_uid($uid); $events = events_by_uid($uid);
// we have the events that are available for the requestor // we have the events that are available for the requestor
// now format the output according to the requested format // now format the output according to the requested format
if(count($events)) if (count($events)) {
$res = event_format_export($events, $format, $timezone); $res = event_format_export($events, $format, $timezone);
}
// If there are results the precess was successfull // If there are results the precess was successfull
if(x($res)) if (x($res)) {
$process = true; $process = true;
}
// get the file extension for the format // get the file extension for the format
switch ($format) { switch ($format) {
@ -851,8 +857,9 @@ function widget_events() {
// The permission testing is a little bit tricky because we have to respect many cases // The permission testing is a little bit tricky because we have to respect many cases
// It's not the private events page (we don't get the $owner_uid for /events) // It's not the private events page (we don't get the $owner_uid for /events)
if(! local_user() && ! $owner_uid) if (! local_user() && ! $owner_uid) {
return; return;
}
// Cal logged in user (test permission at foreign profile page) // Cal logged in user (test permission at foreign profile page)
// If the $owner uid is available we know it is part of one of the profile pages (like /cal) // If the $owner uid is available we know it is part of one of the profile pages (like /cal)
@ -860,13 +867,15 @@ function widget_events() {
// or a foreign one. For foreign profile pages we need to check if the feature // or a foreign one. For foreign profile pages we need to check if the feature
// for exporting the cal is enabled (otherwise the widget would appear for logged in users // for exporting the cal is enabled (otherwise the widget would appear for logged in users
// on foreigen profile pages even if the widget is disabled) // on foreigen profile pages even if the widget is disabled)
if(intval($owner_uid) && local_user() !== $owner_uid && ! feature_enabled($owner_uid, "export_calendar")) if (intval($owner_uid) && local_user() !== $owner_uid && ! feature_enabled($owner_uid, "export_calendar")) {
return; return;
}
// If it's a kind of profile page (intval($owner_uid)) return if the user not logged in and // If it's a kind of profile page (intval($owner_uid)) return if the user not logged in and
// export feature isn't enabled // export feature isn't enabled
if(intval($owner_uid) && ! local_user() && ! feature_enabled($owner_uid, "export_calendar")) if (intval($owner_uid) && ! local_user() && ! feature_enabled($owner_uid, "export_calendar")) {
return; return;
}
return replace_macros(get_markup_template("events_aside.tpl"), array( return replace_macros(get_markup_template("events_aside.tpl"), array(
'$etitle' => t("Export"), '$etitle' => t("Export"),

View file

@ -11,12 +11,13 @@ function expire_run(&$argv, &$argc){
// physically remove anything that has been deleted for more than two months // physically remove anything that has been deleted for more than two months
$r = q("delete from item where deleted = 1 and changed < UTC_TIMESTAMP() - INTERVAL 60 DAY"); $r = q("DELETE FROM `item` WHERE `deleted` = 1 AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY");
// make this optional as it could have a performance impact on large sites // make this optional as it could have a performance impact on large sites
if(intval(get_config('system','optimize_items'))) if (intval(get_config('system','optimize_items'))) {
q("optimize table item"); q("OPTIMIZE TABLE `item`");
}
logger('expire: start'); logger('expire: start');

View file

@ -289,8 +289,9 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
$type = $attributes->textContent; $type = $attributes->textContent;
} }
} }
if(strlen($item["attach"])) if (strlen($item["attach"])) {
$item["attach"] .= ','; $item["attach"] .= ',';
}
$attachments[] = array("link" => $href, "type" => $type, "length" => $length); $attachments[] = array("link" => $href, "type" => $type, "length" => $length);

View file

@ -878,16 +878,20 @@ function zrl_init(App $a) {
} }
function zrl($s,$force = false) { function zrl($s,$force = false) {
if(! strlen($s)) if (! strlen($s)) {
return $s; return $s;
if((! strpos($s,'/profile/')) && (! $force)) }
if ((! strpos($s,'/profile/')) && (! $force)) {
return $s; return $s;
if($force && substr($s,-1,1) !== '/') }
if ($force && substr($s,-1,1) !== '/') {
$s = $s . '/'; $s = $s . '/';
}
$achar = strpos($s,'?') ? '&' : '?'; $achar = strpos($s,'?') ? '&' : '?';
$mine = get_my_url(); $mine = get_my_url();
if($mine and ! link_compare($mine,$s)) if ($mine and ! link_compare($mine,$s)) {
return $s . $achar . 'zrl=' . urlencode($mine); return $s . $achar . 'zrl=' . urlencode($mine);
}
return $s; return $s;
} }
@ -908,9 +912,10 @@ function zrl($s,$force = false) {
function get_theme_uid() { function get_theme_uid() {
$uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0); $uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0);
if (local_user()) { if (local_user()) {
if((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid)) if ((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid)) {
return local_user(); return local_user();
} }
}
return $uid; return $uid;
} }

View file

@ -57,8 +57,9 @@ function block_on_function_lock($fn_name, $wait_sec = 2, $timeout = 30) {
dbesc($fn_name) dbesc($fn_name)
); );
if (dbm::is_result($r) && $r[0]['locked']) if (dbm::is_result($r) && $r[0]['locked']) {
sleep($wait_sec); sleep($wait_sec);
}
} while (dbm::is_result($r) && $r[0]['locked'] && ((time() - $start) < $timeout)); } while (dbm::is_result($r) && $r[0]['locked'] && ((time() - $start) < $timeout));

View file

@ -316,7 +316,9 @@ function oembed_html2bbcode($text) {
$xattr = "@rel='oembed'";//oe_build_xpath("rel","oembed"); $xattr = "@rel='oembed'";//oe_build_xpath("rel","oembed");
foreach($entries as $e) { foreach($entries as $e) {
$href = $xpath->evaluate("a[$xattr]/@href", $e)->item(0)->nodeValue; $href = $xpath->evaluate("a[$xattr]/@href", $e)->item(0)->nodeValue;
if(!is_null($href)) $e->parentNode->replaceChild(new DOMText("[embed]".$href."[/embed]"), $e); if (!is_null($href)) {
$e->parentNode->replaceChild(new DOMText("[embed]".$href."[/embed]"), $e);
}
} }
return oe_get_inner_html( $dom->getElementsByTagName("body")->item(0) ); return oe_get_inner_html( $dom->getElementsByTagName("body")->item(0) );
} else { } else {

View file

@ -61,7 +61,7 @@ function onepoll_run(&$argv, &$argc){
intval($contact_id) intval($contact_id)
); );
if (! count($contacts)) { if (! dbm::is_result($contacts)) {
return; return;
} }

View file

@ -524,12 +524,14 @@ function service_class_fetch($uid,$property) {
function upgrade_link($bbcode = false) { function upgrade_link($bbcode = false) {
$l = get_config('service_class','upgrade_link'); $l = get_config('service_class','upgrade_link');
if(! $l) if (! $l) {
return ''; return '';
if($bbcode) }
if ($bbcode) {
$t = sprintf('[url=%s]' . t('Click here to upgrade.') . '[/url]', $l); $t = sprintf('[url=%s]' . t('Click here to upgrade.') . '[/url]', $l);
else } else {
$t = sprintf('<a href="%s">' . t('Click here to upgrade.') . '</div>', $l); $t = sprintf('<a href="%s">' . t('Click here to upgrade.') . '</div>', $l);
}
return $t; return $t;
} }
@ -556,13 +558,15 @@ function upgrade_bool_message($bbcode = false) {
*/ */
function theme_include($file, $root = '') { function theme_include($file, $root = '') {
// Make sure $root ends with a slash / if it's not blank // Make sure $root ends with a slash / if it's not blank
if($root !== '' && $root[strlen($root)-1] !== '/') if ($root !== '' && $root[strlen($root)-1] !== '/') {
$root = $root . '/'; $root = $root . '/';
}
$theme_info = $a->theme_info; $theme_info = $a->theme_info;
if(is_array($theme_info) AND array_key_exists('extends',$theme_info)) if (is_array($theme_info) AND array_key_exists('extends',$theme_info)) {
$parent = $theme_info['extends']; $parent = $theme_info['extends'];
else } else {
$parent = 'NOPATH'; $parent = 'NOPATH';
}
$theme = current_theme(); $theme = current_theme();
$thname = $theme; $thname = $theme;
$ext = substr($file,strrpos($file,'.')+1); $ext = substr($file,strrpos($file,'.')+1);
@ -573,10 +577,11 @@ function theme_include($file, $root = '') {
); );
foreach($paths as $p) { foreach($paths as $p) {
// strpos() is faster than strstr when checking if one string is in another (http://php.net/manual/en/function.strstr.php) // strpos() is faster than strstr when checking if one string is in another (http://php.net/manual/en/function.strstr.php)
if(strpos($p,'NOPATH') !== false) if (strpos($p,'NOPATH') !== false) {
continue; continue;
if(file_exists($p)) } elseif (file_exists($p)) {
return $p; return $p;
} }
}
return ''; return '';
} }

View file

@ -28,9 +28,11 @@ function handle_pubsubhubbub($id) {
global $a; global $a;
$r = q("SELECT * FROM `push_subscriber` WHERE `id` = %d", intval($id)); $r = q("SELECT * FROM `push_subscriber` WHERE `id` = %d", intval($id));
if (!$r)
if (!dbm::is_result($r)) {
return; return;
else }
$rr = $r[0]; $rr = $r[0];
logger("Generate feed of user ".$rr['nickname']." to ".$rr['callback_url']." - last updated ".$rr['last_update'], LOGGER_DEBUG); logger("Generate feed of user ".$rr['nickname']." to ".$rr['callback_url']." - last updated ".$rr['last_update'], LOGGER_DEBUG);
@ -65,8 +67,10 @@ function handle_pubsubhubbub($id) {
// increment this until some upper limit where we give up // increment this until some upper limit where we give up
$new_push = intval($rr['push']) + 1; $new_push = intval($rr['push']) + 1;
if ($new_push > 30) // OK, let's give up if ($new_push > 30) {
// OK, let's give up
$new_push = 0; $new_push = 0;
}
q("UPDATE `push_subscriber` SET `push` = %d WHERE id = %d", q("UPDATE `push_subscriber` SET `push` = %d WHERE id = %d",
$new_push, $new_push,

View file

@ -49,12 +49,14 @@ function was_recently_delayed($cid) {
function add_to_queue($cid,$network,$msg,$batch = false) { function add_to_queue($cid,$network,$msg,$batch = false) {
$max_queue = get_config('system','max_contact_queue'); $max_queue = get_config('system','max_contact_queue');
if($max_queue < 1) if ($max_queue < 1) {
$max_queue = 500; $max_queue = 500;
}
$batch_queue = get_config('system','max_batch_queue'); $batch_queue = get_config('system','max_batch_queue');
if($batch_queue < 1) if ($batch_queue < 1) {
$batch_queue = 1000; $batch_queue = 1000;
}
$r = q("SELECT COUNT(*) AS `total` FROM `queue` INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id` $r = q("SELECT COUNT(*) AS `total` FROM `queue` INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id`
WHERE `queue`.`cid` = %d AND `contact`.`self` = 0 ", WHERE `queue`.`cid` = %d AND `contact`.`self` = 0 ",
@ -64,8 +66,7 @@ function add_to_queue($cid,$network,$msg,$batch = false) {
if ($batch && ($r[0]['total'] > $batch_queue)) { if ($batch && ($r[0]['total'] > $batch_queue)) {
logger('add_to_queue: too many queued items for batch server ' . $cid . ' - discarding message'); logger('add_to_queue: too many queued items for batch server ' . $cid . ' - discarding message');
return; return;
} } elseif ((! $batch) && ($r[0]['total'] > $max_queue)) {
elseif((! $batch) && ($r[0]['total'] > $max_queue)) {
logger('add_to_queue: too many queued items for contact ' . $cid . ' - discarding message'); logger('add_to_queue: too many queued items for contact ' . $cid . ' - discarding message');
return; return;
} }

View file

@ -69,8 +69,9 @@ function slapper($owner,$url,$slap) {
// does contact have a salmon endpoint? // does contact have a salmon endpoint?
if(! strlen($url)) if (! strlen($url)) {
return; return;
}
if (! $owner['sprvkey']) { if (! $owner['sprvkey']) {
@ -169,10 +170,12 @@ function slapper($owner,$url,$slap) {
} }
} }
logger('slapper for '.$url.' returned ' . $return_code); logger('slapper for '.$url.' returned ' . $return_code);
if(! $return_code) if (! $return_code) {
return(-1); return(-1);
if(($return_code == 503) && (stristr($a->get_curl_headers(),'retry-after'))) }
if (($return_code == 503) && (stristr($a->get_curl_headers(),'retry-after'))) {
return(-1); return(-1);
}
return ((($return_code >= 200) && ($return_code < 300)) ? 0 : 1); return ((($return_code >= 200) && ($return_code < 300)) ? 0 : 1);
} }

View file

@ -105,10 +105,11 @@ function create_tags_from_itemuri($itemuri, $uid) {
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid)); $messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
if (count($messages)) { if (count($messages)) {
foreach ($messages as $message) foreach ($messages as $message) {
create_tags_from_item($message["id"]); create_tags_from_item($message["id"]);
} }
} }
}
function update_items() { function update_items() {
global $db; global $db;

View file

@ -174,29 +174,34 @@ function add_shadow_entry($itemid) {
function update_thread_uri($itemuri, $uid) { function update_thread_uri($itemuri, $uid) {
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid)); $messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
if (dbm::is_result($messages)) if (dbm::is_result($messages)) {
foreach ($messages as $message) foreach ($messages as $message) {
update_thread($message["id"]); update_thread($message["id"]);
} }
}
}
function update_thread($itemid, $setmention = false) { function update_thread($itemid, $setmention = false) {
$items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`, $items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
`deleted`, `origin`, `forum_mode`, `network`, `rendered-html`, `rendered-hash` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid)); `deleted`, `origin`, `forum_mode`, `network`, `rendered-html`, `rendered-hash` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
if (!dbm::is_result($items)) if (!dbm::is_result($items)) {
return; return;
}
$item = $items[0]; $item = $items[0];
if ($setmention) if ($setmention) {
$item["mention"] = 1; $item["mention"] = 1;
}
$sql = ""; $sql = "";
foreach ($item AS $field => $data) foreach ($item AS $field => $data)
if (!in_array($field, array("guid", "title", "body", "rendered-html", "rendered-hash"))) { if (!in_array($field, array("guid", "title", "body", "rendered-html", "rendered-hash"))) {
if ($sql != "") if ($sql != "") {
$sql .= ", "; $sql .= ", ";
}
$sql .= "`".$field."` = '".dbesc($data)."'"; $sql .= "`".$field."` = '".dbesc($data)."'";
} }
@ -208,8 +213,9 @@ function update_thread($itemid, $setmention = false) {
// Updating a shadow item entry // Updating a shadow item entry
$items = q("SELECT `id` FROM `item` WHERE `guid` = '%s' AND `uid` = 0 LIMIT 1", dbesc($item["guid"])); $items = q("SELECT `id` FROM `item` WHERE `guid` = '%s' AND `uid` = 0 LIMIT 1", dbesc($item["guid"]));
if (!$items) if (!dbm::is_result($items)) {
return; return;
}
$result = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s' WHERE `id` = %d", $result = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s' WHERE `id` = %d",
dbesc($item["title"]), dbesc($item["title"]),
@ -224,10 +230,12 @@ function update_thread($itemid, $setmention = false) {
function delete_thread_uri($itemuri, $uid) { function delete_thread_uri($itemuri, $uid) {
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid)); $messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
if(count($messages)) if (dbm::is_result($messages)) {
foreach ($messages as $message) foreach ($messages as $message) {
delete_thread($message["id"], $itemuri); delete_thread($message["id"], $itemuri);
} }
}
}
function delete_thread($itemid, $itemuri = "") { function delete_thread($itemid, $itemuri = "") {
$item = q("SELECT `uid` FROM `thread` WHERE `iid` = %d", intval($itemid)); $item = q("SELECT `uid` FROM `thread` WHERE `iid` = %d", intval($itemid));

View file

@ -21,35 +21,41 @@ function update_gcontact_run(&$argv, &$argc){
$r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id)); $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
if (!$r) if (!dbm::is_result($r)) {
return; return;
}
if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) }
return; return;
}
$data = probe_url($r[0]["url"]); $data = probe_url($r[0]["url"]);
if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) { if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
if ($r[0]["server_url"] != "") if ($r[0]["server_url"] != "") {
poco_check_server($r[0]["server_url"], $r[0]["network"]); poco_check_server($r[0]["server_url"], $r[0]["network"]);
}
q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d", q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d",
dbesc(datetime_convert()), intval($contact_id)); dbesc(datetime_convert()), intval($contact_id));
return; return;
} }
if (($data["name"] == "") AND ($r[0]['name'] != "")) if (($data["name"] == "") AND ($r[0]['name'] != "")) {
$data["name"] = $r[0]['name']; $data["name"] = $r[0]['name'];
}
if (($data["nick"] == "") AND ($r[0]['nick'] != "")) if (($data["nick"] == "") AND ($r[0]['nick'] != "")) {
$data["nick"] = $r[0]['nick']; $data["nick"] = $r[0]['nick'];
}
if (($data["addr"] == "") AND ($r[0]['addr'] != "")) if (($data["addr"] == "") AND ($r[0]['addr'] != "")) {
$data["addr"] = $r[0]['addr']; $data["addr"] = $r[0]['addr'];
}
if (($data["photo"] == "") AND ($r[0]['photo'] != "")) if (($data["photo"] == "") AND ($r[0]['photo'] != "")) {
$data["photo"] = $r[0]['photo']; $data["photo"] = $r[0]['photo'];
}
q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s' q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
WHERE `id` = %d", WHERE `id` = %d",