From 2a77e426f9a26a2584da78c90daf8ec1d49fcc00 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 27 Jan 2017 17:00:34 +0000 Subject: [PATCH 01/65] Split poco discovery in smaller function calls --- include/socgraph.php | 124 ++++++++++++++++++++++++------------------- 1 file changed, 70 insertions(+), 54 deletions(-) diff --git a/include/socgraph.php b/include/socgraph.php index 32c151c04..b787452b8 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1260,6 +1260,71 @@ function poco_discover_federation() { set_config('poco','last_federation_discovery', time()); } +function poco_discover_single_server($id) { + $r = q("SELECT `poco`, `nurl`, `url`, `network` FROM `gserver` WHERE `id` = %d", intval($id)); + if (!dbm::is_result($r)) { + return false; + } + + $server = $r[0]; + + if (!poco_check_server($server["url"], $server["network"])) { + // The server is not reachable? Okay, then we will try it later + q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"])); + return false; + } + + // Fetch all users from the other server + $url = $server["poco"]."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; + + logger("Fetch all users from the server ".$server["nurl"], LOGGER_DEBUG); + + $retdata = z_fetch_url($url); + if ($retdata["success"]) { + $data = json_decode($retdata["body"]); + + poco_discover_server($data, 2); + + if (get_config('system','poco_discovery') > 1) { + + $timeframe = get_config('system','poco_discovery_since'); + if ($timeframe == 0) { + $timeframe = 30; + } + + $updatedSince = date("Y-m-d H:i:s", time() - $timeframe * 86400); + + // Fetch all global contacts from the other server (Not working with Redmatrix and Friendica versions before 3.3) + $url = $server["poco"]."/@global?updatedSince=".$updatedSince."&fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; + + $success = false; + + $retdata = z_fetch_url($url); + if ($retdata["success"]) { + logger("Fetch all global contacts from the server ".$server["nurl"], LOGGER_DEBUG); + $success = poco_discover_server(json_decode($retdata["body"])); + } + + if (!$success AND (get_config('system','poco_discovery') > 2)) { + logger("Fetch contacts from users of the server ".$server["nurl"], LOGGER_DEBUG); + poco_discover_server_users($data, $server); + } + } + + q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"])); + + return true; + } else { + // If the server hadn't replied correctly, then force a sanity check + poco_check_server($server["url"], $server["network"], true); + + // If we couldn't reach the server, we will try it some time later + q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"])); + + return false; + } +} + function poco_discover($complete = false) { // Update the server list @@ -1274,63 +1339,14 @@ function poco_discover($complete = false) { $last_update = date("c", time() - (60 * 60 * 24 * $requery_days)); - $r = q("SELECT `poco`, `nurl`, `url`, `network` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `poco` != '' AND `last_poco_query` < '%s' ORDER BY RAND()", dbesc($last_update)); - if ($r) + $r = q("SELECT `id` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `poco` != '' AND `last_poco_query` < '%s' ORDER BY RAND()", dbesc($last_update)); + if (dbm::is_result($r)) { foreach ($r AS $server) { - - if (!poco_check_server($server["url"], $server["network"])) { - // The server is not reachable? Okay, then we will try it later - q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"])); - continue; - } - - // Fetch all users from the other server - $url = $server["poco"]."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; - - logger("Fetch all users from the server ".$server["nurl"], LOGGER_DEBUG); - - $retdata = z_fetch_url($url); - if ($retdata["success"]) { - $data = json_decode($retdata["body"]); - - poco_discover_server($data, 2); - - if (get_config('system','poco_discovery') > 1) { - - $timeframe = get_config('system','poco_discovery_since'); - if ($timeframe == 0) - $timeframe = 30; - - $updatedSince = date("Y-m-d H:i:s", time() - $timeframe * 86400); - - // Fetch all global contacts from the other server (Not working with Redmatrix and Friendica versions before 3.3) - $url = $server["poco"]."/@global?updatedSince=".$updatedSince."&fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; - - $success = false; - - $retdata = z_fetch_url($url); - if ($retdata["success"]) { - logger("Fetch all global contacts from the server ".$server["nurl"], LOGGER_DEBUG); - $success = poco_discover_server(json_decode($retdata["body"])); - } - - if (!$success AND (get_config('system','poco_discovery') > 2)) { - logger("Fetch contacts from users of the server ".$server["nurl"], LOGGER_DEBUG); - poco_discover_server_users($data, $server); - } - } - - q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"])); - if (!$complete AND (--$no_of_queries == 0)) - break; - } else { - // If the server hadn't replied correctly, then force a sanity check - poco_check_server($server["url"], $server["network"], true); - - // If we couldn't reach the server, we will try it some time later - q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"])); + if (poco_discover_single_server($server['id']) AND !$complete AND (--$no_of_queries == 0)) { + break; } } + } } function poco_discover_server_users($data, $server) { From 8ae8465d48996b9d4ad557c744f9483b7da8abd1 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Thu, 16 Mar 2017 20:15:25 +0100 Subject: [PATCH 02/65] add dop event & fix event edit --- include/event.php | 11 +- mod/events.php | 211 ++++++++++++++++------------ view/templates/event.tpl | 1 + view/theme/frio/css/style.css | 3 + view/theme/frio/templates/event.tpl | 5 +- 5 files changed, 136 insertions(+), 95 deletions(-) diff --git a/include/event.php b/include/event.php index 9e5bafbdb..87fae4f8e 100644 --- a/include/event.php +++ b/include/event.php @@ -612,7 +612,14 @@ function process_events($arr) { $is_first = ($d !== $last_date); $last_date = $d; - $edit = ((! $rr['cid']) ? array(App::get_baseurl().'/events/event/'.$rr['id'],t('Edit event'),'','') : null); + + // Show edit and drop actions only if the user is the owner of the event and the event + // is a real event (no bithdays) + if (local_user() && local_user() == $rr['uid'] && $rr['type'] == 'event') { + $edit = ((! $rr['cid']) ? array(App::get_baseurl().'/events/event/'.$rr['id'],t('Edit event'),'','') : null); + $drop = array(App::get_baseurl().'/events/drop/'.$rr['id'],t('Delete event'),'',''); + } + $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8')); if(! $title) { list($title, $_trash) = explode(" $j, 'd' => $d, + 'edit' => $edit, + 'drop' => $drop, 'is_first'=>$is_first, 'item'=>$rr, 'html'=>$html, diff --git a/mod/events.php b/mod/events.php index ac0c444cb..5d80e8609 100644 --- a/mod/events.php +++ b/mod/events.php @@ -33,7 +33,7 @@ function events_init(App $a) { function events_post(App $a) { - logger('post: ' . print_r($_REQUEST,true)); + logger('post: ' . print_r($_REQUEST, true)); if (! local_user()) { return; @@ -41,7 +41,7 @@ function events_post(App $a) { $event_id = ((x($_POST,'event_id')) ? intval($_POST['event_id']) : 0); $cid = ((x($_POST,'cid')) ? intval($_POST['cid']) : 0); - $uid = local_user(); + $uid = local_user(); $start_text = escape_tags($_REQUEST['start_text']); $finish_text = escape_tags($_REQUEST['finish_text']); @@ -54,9 +54,8 @@ function events_post(App $a) { if ($start_text) { $start = $start_text; - } - else { - $start = sprintf('%d-%d-%d %d:%d:0',$startyear,$startmonth,$startday,$starthour,$startminute); + } else { + $start = sprintf('%d-%d-%d %d:%d:0', $startyear, $startmonth, $startday, $starthour, $startminute); } if ($nofinish) { @@ -65,21 +64,19 @@ function events_post(App $a) { if ($finish_text) { $finish = $finish_text; - } - else { - $finish = sprintf('%d-%d-%d %d:%d:0',$finishyear,$finishmonth,$finishday,$finishhour,$finishminute); + } else { + $finish = sprintf('%d-%d-%d %d:%d:0', $finishyear, $finishmonth, $finishday, $finishhour, $finishminute); } if ($adjust) { - $start = datetime_convert(date_default_timezone_get(),'UTC',$start); + $start = datetime_convert(date_default_timezone_get(), 'UTC',$start); if (! $nofinish) { - $finish = datetime_convert(date_default_timezone_get(),'UTC',$finish); + $finish = datetime_convert(date_default_timezone_get(), 'UTC',$finish); } - } - else { - $start = datetime_convert('UTC','UTC',$start); + } else { + $start = datetime_convert('UTC', 'UTC', $start); if (! $nofinish) { - $finish = datetime_convert('UTC','UTC',$finish); + $finish = datetime_convert('UTC', 'UTC', $finish); } } @@ -96,7 +93,7 @@ function events_post(App $a) { $action = ($event_id == '') ? 'new' : "event/" . $event_id; $onerror_url = App::get_baseurl() . "/events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish"; - if (strcmp($finish,$start) < 0 && !$nofinish) { + if (strcmp($finish, $start) < 0 && !$nofinish) { notice( t('Event can not end before it has started.') . EOL); if (intval($_REQUEST['preview'])) { echo( t('Event can not end before it has started.')); @@ -105,9 +102,9 @@ function events_post(App $a) { goaway($onerror_url); } - if((! $summary) || (! $start)) { + if ((! $summary) || (! $start)) { notice( t('Event title and start time are required.') . EOL); - if(intval($_REQUEST['preview'])) { + if (intval($_REQUEST['preview'])) { echo( t('Event title and start time are required.')); killme(); } @@ -116,35 +113,33 @@ function events_post(App $a) { $share = ((intval($_POST['share'])) ? intval($_POST['share']) : 0); - $c = q("select id from contact where uid = %d and self = 1 limit 1", + $c = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval(local_user()) ); - if(count($c)) + if (count($c)) { $self = $c[0]['id']; - else + } else { $self = 0; + } - if($share) { + if ($share) { $str_group_allow = perms2str($_POST['group_allow']); $str_contact_allow = perms2str($_POST['contact_allow']); $str_group_deny = perms2str($_POST['group_deny']); $str_contact_deny = perms2str($_POST['contact_deny']); // Undo the pseudo-contact of self, since there are real contacts now - if( strpos($str_contact_allow, '<' . $self . '>') !== false ) - { + if ( strpos($str_contact_allow, '<' . $self . '>') !== false ) { $str_contact_allow = str_replace('<' . $self . '>', '', $str_contact_allow); } // Make sure to set the `private` field as true. This is necessary to // have the posts show up correctly in Diaspora if an event is created // as visible only to self at first, but then edited to display to others. - if( strlen($str_group_allow) or strlen($str_contact_allow) or strlen($str_group_deny) or strlen($str_contact_deny) ) - { + if (strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) { $private_event = true; } - } - else { + } else { // Note: do not set `private` field for self-only events. It will // keep even you from seeing them! $str_contact_allow = '<' . $self . '>'; @@ -173,16 +168,17 @@ function events_post(App $a) { $datarray['created'] = $created; $datarray['edited'] = $edited; - if(intval($_REQUEST['preview'])) { + if (intval($_REQUEST['preview'])) { $html = format_event_html($datarray); echo $html; - killme(); + killme(); } $item_id = event_store($datarray); - if(! $cid) + if (! $cid) { proc_run(PRIORITY_HIGH, "include/notifier.php", "event", $item_id); + } goaway($_SESSION['return_url']); } @@ -201,14 +197,14 @@ function events_content(App $a) { } if (($a->argc > 2) && ($a->argv[1] === 'ignore') && intval($a->argv[2])) { - $r = q("update event set ignore = 1 where id = %d and uid = %d", + $r = q("UPDATE `event` SET `ignore` = 1 WHERE `id` = %d AND `uid` = %d", intval($a->argv[2]), intval(local_user()) ); } if (($a->argc > 2) && ($a->argv[1] === 'unignore') && intval($a->argv[2])) { - $r = q("update event set ignore = 0 where id = %d and uid = %d", + $r = q("UPDATE `event` SET `ignore` = 0 WHERE `id` = %d AND `uid` = %d", intval($a->argv[2]), intval(local_user()) ); @@ -224,7 +220,7 @@ function events_content(App $a) { $i18n = get_event_strings(); $htpl = get_markup_template('event_head.tpl'); - $a->page['htmlhead'] .= replace_macros($htpl,array( + $a->page['htmlhead'] .= replace_macros($htpl, array( '$baseurl' => App::get_baseurl(), '$module_url' => '/events', '$modparams' => 1, @@ -232,14 +228,15 @@ function events_content(App $a) { )); $etpl = get_markup_template('event_end.tpl'); - $a->page['end'] .= replace_macros($etpl,array( + $a->page['end'] .= replace_macros($etpl, array( '$baseurl' => App::get_baseurl(), )); - $o =""; + $o =''; // tabs - if ($a->theme_events_in_profile) - $tabs = profile_tabs($a, True); + if ($a->theme_events_in_profile) { + $tabs = profile_tabs($a, true); + } @@ -253,6 +250,10 @@ function events_content(App $a) { $mode = 'edit'; $event_id = intval($a->argv[2]); } + if($a->argc > 2 && $a->argv[1] == 'drop') { + $mode = 'drop'; + $event_id = intval($a->argv[2]); + } if ($a->argv[1] === 'new') { $mode = 'new'; $event_id = 0; @@ -267,9 +268,8 @@ function events_content(App $a) { // The view mode part is similiar to /mod/cal.php if ($mode == 'view') { - - $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y'); - $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m'); + $thisyear = datetime_convert('UTC', date_default_timezone_get(),'now', 'Y'); + $thismonth = datetime_convert('UTC', date_default_timezone_get(), 'now', 'm'); if (! $y) { $y = intval($thisyear); } @@ -289,22 +289,22 @@ function events_content(App $a) { $nextyear = $y; $nextmonth = $m + 1; - if($nextmonth > 12) { - $nextmonth = 1; + if ($nextmonth > 12) { + $nextmonth = 1; $nextyear ++; } $prevyear = $y; - if($m > 1) + if ($m > 1) { $prevmonth = $m - 1; - else { + } else { $prevmonth = 12; $prevyear --; } - $dim = get_dim($y,$m); - $start = sprintf('%d-%d-%d %d:%d:%d',$y,$m,1,0,0,0); - $finish = sprintf('%d-%d-%d %d:%d:%d',$y,$m,$dim,23,59,59); + $dim = get_dim($y, $m); + $start = sprintf('%d-%d-%d %d:%d:%d', $y, $m, 1, 0, 0, 0); + $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59); if ($a->argv[1] === 'json'){ @@ -312,20 +312,20 @@ function events_content(App $a) { if (x($_GET,'end')) $finish = $_GET['end']; } - $start = datetime_convert('UTC','UTC',$start); - $finish = datetime_convert('UTC','UTC',$finish); + $start = datetime_convert('UTC', 'UTC', $start); + $finish = datetime_convert('UTC', 'UTC', $finish); $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start); $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish); // put the event parametes in an array so we can better transmit them $event_params = array( - 'event_id' => (x($_GET,'id') ? $_GET["id"] : 0), - 'start' => $start, - 'finish' => $finish, - 'adjust_start' => $adjust_start, + 'event_id' => (x($_GET,'id') ? $_GET["id"] : 0), + 'start' => $start, + 'finish' => $finish, + 'adjust_start' => $adjust_start, 'adjust_finish' => $adjust_finish, - 'ignored' => $ignored, + 'ignored' => $ignored, ); // get events by id or by date @@ -340,7 +340,7 @@ function events_content(App $a) { if (dbm::is_result($r)) { $r = sort_by_date($r); foreach ($r as $rr) { - $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j')); + $j = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j')); if (! x($links,$j)) { $links[$j] = App::get_baseurl() . '/' . $a->cmd . '#link-' . $j; } @@ -356,18 +356,14 @@ function events_content(App $a) { } if ($a->argv[1] === 'json'){ - echo json_encode($events); killme(); + echo json_encode($events); + killme(); } - // links: array('href', 'text', 'extra css classes', 'title') if (x($_GET,'id')){ $tpl = get_markup_template("event.tpl"); } else { -// if (get_config('experimentals','new_calendar')==1){ - $tpl = get_markup_template("events_js.tpl"); -// } else { -// $tpl = get_markup_template("events.tpl"); -// } + $tpl = get_markup_template("events_js.tpl"); } // Get rid of dashes in key names, Smarty3 can't handle them @@ -385,27 +381,31 @@ function events_content(App $a) { '$tabs' => $tabs, '$title' => t('Events'), '$view' => t('View'), - '$new_event' => array(App::get_baseurl().'/events/new',t('Create New Event'),'',''), - '$previous' => array(App::get_baseurl()."/events/$prevyear/$prevmonth",t('Previous'),'',''), - '$next' => array(App::get_baseurl()."/events/$nextyear/$nextmonth",t('Next'),'',''), - '$calendar' => cal($y,$m,$links, ' eventcal'), + '$new_event' => array(App::get_baseurl() . '/events/new', t('Create New Event'), '', ''), + '$previous' => array(App::get_baseurl() . '/events/$prevyear/$prevmonth', t('Previous'), '', ''), + '$next' => array(App::get_baseurl() . '/events/$nextyear/$nextmonth', t('Next'), '', ''), + '$calendar' => cal($y, $m, $links, ' eventcal'), '$events' => $events, - "today" => t("today"), - "month" => t("month"), - "week" => t("week"), - "day" => t("day"), - "list" => t("list"), + '$today' => t('today'), + '$month' => t('month'), + '$week' => t('week'), + '$day' => t('day'), + '$list' => t('list'), )); - if (x($_GET,'id')){ echo $o; killme(); } + if (x($_GET,'id')) { + echo $o; + killme(); + + } return $o; } - if($mode === 'edit' && $event_id) { + if ($mode === 'edit' && $event_id) { $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($event_id), intval(local_user()) @@ -415,16 +415,16 @@ function events_content(App $a) { } // Passed parameters overrides anything found in the DB - if($mode === 'edit' || $mode === 'new') { - if(!x($orig_event)) $orig_event = array(); + if ($mode === 'edit' || $mode === 'new') { + if (!x($orig_event)) $orig_event = array(); // In case of an error the browser is redirected back here, with these parameters filled in with the previous values - if(x($_REQUEST,'nofinish')) $orig_event['nofinish'] = $_REQUEST['nofinish']; - if(x($_REQUEST,'adjust')) $orig_event['adjust'] = $_REQUEST['adjust']; - if(x($_REQUEST,'summary')) $orig_event['summary'] = $_REQUEST['summary']; - if(x($_REQUEST,'description')) $orig_event['description'] = $_REQUEST['description']; - if(x($_REQUEST,'location')) $orig_event['location'] = $_REQUEST['location']; - if(x($_REQUEST,'start')) $orig_event['start'] = $_REQUEST['start']; - if(x($_REQUEST,'finish')) $orig_event['finish'] = $_REQUEST['finish']; + if (x($_REQUEST,'nofinish')) $orig_event['nofinish'] = $_REQUEST['nofinish']; + if (x($_REQUEST,'adjust')) $orig_event['adjust'] = $_REQUEST['adjust']; + if (x($_REQUEST,'summary')) $orig_event['summary'] = $_REQUEST['summary']; + if (x($_REQUEST,'description')) $orig_event['description'] = $_REQUEST['description']; + if (x($_REQUEST,'location')) $orig_event['location'] = $_REQUEST['location']; + if (x($_REQUEST,'start')) $orig_event['start'] = $_REQUEST['start']; + if (x($_REQUEST,'finish')) $orig_event['finish'] = $_REQUEST['finish']; } if($mode === 'edit' || $mode === 'new') { @@ -439,21 +439,24 @@ function events_content(App $a) { $uri = ((x($orig_event)) ? $orig_event['uri'] : ''); - if(! x($orig_event)) + if (! x($orig_event)) { $sh_checked = ''; - else + } else { $sh_checked = (($orig_event['allow_cid'] === '<' . local_user() . '>' && (! $orig_event['allow_gid']) && (! $orig_event['deny_cid']) && (! $orig_event['deny_gid'])) ? '' : ' checked="checked" ' ); + } - if($cid OR ($mode !== 'new')) + if ($cid OR ($mode !== 'new')) { $sh_checked .= ' disabled="disabled" '; + } $sdt = ((x($orig_event)) ? $orig_event['start'] : 'now'); $fdt = ((x($orig_event)) ? $orig_event['finish'] : 'now'); $tz = date_default_timezone_get(); - if(x($orig_event)) + if (x($orig_event)) { $tz = (($orig_event['adjust']) ? date_default_timezone_get() : 'UTC'); + } $syear = datetime_convert('UTC', $tz, $sdt, 'Y'); $smonth = datetime_convert('UTC', $tz, $sdt, 'm'); @@ -470,13 +473,15 @@ function events_content(App $a) { $fminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0); $f = get_config('system','event_input_format'); - if(! $f) + if (! $f) { $f = 'ymd'; + } require_once('include/acl_selectors.php'); - if ($mode === 'new') + if ($mode === 'new') { $acl = (($cid) ? '' : populate_acl(((x($orig_event)) ? $orig_event : $a->user))); + } $tpl = get_markup_template('event_form.tpl'); @@ -489,11 +494,11 @@ function events_content(App $a) { '$title' => t('Event details'), '$desc' => t('Starting date and Title are required.'), '$s_text' => t('Event Starts:') . ' *', - '$s_dsel' => datetimesel($f,new DateTime(),DateTime::createFromFormat('Y',$syear+5),DateTime::createFromFormat('Y-m-d H:i',"$syear-$smonth-$sday $shour:$sminute"),t('Event Starts:'),'start_text',true,true,'','',true), + '$s_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $syear+5), DateTime::createFromFormat('Y-m-d H:i', "$syear-$smonth-$sday $shour:$sminute"), t('Event Starts:'), 'start_text', true, true, '', '', true), '$n_text' => t('Finish date/time is not known or not relevant'), '$n_checked' => $n_checked, '$f_text' => t('Event Finishes:'), - '$f_dsel' => datetimesel($f,new DateTime(),DateTime::createFromFormat('Y',$fyear+5),DateTime::createFromFormat('Y-m-d H:i',"$fyear-$fmonth-$fday $fhour:$fminute"),t('Event Finishes:'),'finish_text',true,true,'start_text'), + '$f_dsel' => datetimesel($f, new DateTime(), DateTime::createFromFormat('Y', $fyear+5), DateTime::createFromFormat('Y-m-d H:i', "$fyear-$fmonth-$fday $fhour:$fminute"), t('Event Finishes:'), 'finish_text', true, true, 'start_text'), '$a_text' => t('Adjust for viewer timezone'), '$a_checked' => $a_checked, '$d_text' => t('Description:'), @@ -511,12 +516,34 @@ function events_content(App $a) { '$preview' => t('Preview'), '$acl' => $acl, '$submit' => t('Submit'), - '$basic' => t("Basic"), - '$advanced' => t("Advanced"), + '$basic' => t('Basic'), + '$advanced' => t('Advanced'), '$permissions' => t('Permissions'), )); return $o; } + + // Remove an event from the calendar and its related items + if ($mode === 'drop' && $event_id) { + $del = 0; + + $event_params = array('event_id' => ($event_id)); + $ev = event_by_id(local_user(), $event_params); + + // Delete only real events (no birthdays) + if (dbm::is_result($ev) && $ev[0]['type'] == 'event') { + $del = drop_item($ev[0]['itemid'], false); + } + + if ($del == 0) { + notice( t('Failed to remove event' ) . EOL); + } else { + info( t('Event removed') . EOL); + } + + goaway(App::get_baseurl() . '/events'); + + } } diff --git a/view/templates/event.tpl b/view/templates/event.tpl index 9cad2444c..328e0e8a1 100644 --- a/view/templates/event.tpl +++ b/view/templates/event.tpl @@ -6,6 +6,7 @@ {{$event.html}} {{if $event.item.plink}}{{/if}} {{if $event.edit}}{{/if}} + {{if $event.drop}}{{/if}}
{{/foreach}} diff --git a/view/theme/frio/css/style.css b/view/theme/frio/css/style.css index 8d7a5f769..47973ed44 100644 --- a/view/theme/frio/css/style.css +++ b/view/theme/frio/css/style.css @@ -2193,6 +2193,9 @@ ul li:hover .contact-wrapper a.contact-action-link:hover { #event-edit-form-wrapper #event-edit-time { padding: 10px 0; } +.event-buttons .plink-event-link { + margin-left: 20px; +} /* Profiles Page */ .profile-listing-table { display: table; diff --git a/view/theme/frio/templates/event.tpl b/view/theme/frio/templates/event.tpl index ee2875686..dc37f1926 100644 --- a/view/theme/frio/templates/event.tpl +++ b/view/theme/frio/templates/event.tpl @@ -17,8 +17,9 @@
- {{if $event.item.plink}}{{/if}} - {{if $event.edit}}{{/if}} + {{if $event.edit}}{{/if}} + {{if $event.drop}}{{/if}} + {{if $event.item.plink}}{{/if}}
From c785eb29c67d0bf4e1cb6d2c252348305bc0fcfe Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Fri, 17 Mar 2017 17:57:57 +0100 Subject: [PATCH 03/65] more work on standards compliance --- include/event.php | 24 +++---- mod/events.php | 176 +++++++++++++++++++++++----------------------- 2 files changed, 100 insertions(+), 100 deletions(-) diff --git a/include/event.php b/include/event.php index 87fae4f8e..d9b89a7c6 100644 --- a/include/event.php +++ b/include/event.php @@ -595,17 +595,17 @@ function process_events($arr) { $last_date = ''; $fmt = t('l, F j'); if (count($arr)) { - foreach($arr as $rr) { + foreach ($arr as $rr) { - $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j')); - $d = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], $fmt) : datetime_convert('UTC','UTC',$rr['start'],$fmt)); + $j = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'j') : datetime_convert('UTC', 'UTC', $rr['start'], 'j')); + $d = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], $fmt) : datetime_convert('UTC', 'UTC', $rr['start'], $fmt)); $d = day_translate($d); - $start = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'c') : datetime_convert('UTC','UTC',$rr['start'],'c')); + $start = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'c') : datetime_convert('UTC', 'UTC', $rr['start'], 'c')); if ($rr['nofinish']){ $end = null; } else { - $end = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['finish'], 'c') : datetime_convert('UTC','UTC',$rr['finish'],'c')); + $end = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['finish'], 'c') : datetime_convert('UTC', 'UTC', $rr['finish'], 'c')); } @@ -616,14 +616,14 @@ function process_events($arr) { // Show edit and drop actions only if the user is the owner of the event and the event // is a real event (no bithdays) if (local_user() && local_user() == $rr['uid'] && $rr['type'] == 'event') { - $edit = ((! $rr['cid']) ? array(App::get_baseurl().'/events/event/'.$rr['id'],t('Edit event'),'','') : null); - $drop = array(App::get_baseurl().'/events/drop/'.$rr['id'],t('Delete event'),'',''); + $edit = ((! $rr['cid']) ? array(App::get_baseurl() . '/events/event/' . $rr['id'], t('Edit event'), '', '') : null); + $drop = array(App::get_baseurl() . '/events/drop/' . $rr['id'], t('Delete event'), '', ''); } - $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8')); - if(! $title) { - list($title, $_trash) = explode("$is_first, 'item'=>$rr, 'html'=>$html, - 'plink' => array($rr['plink'],t('link to source'),'',''), + 'plink' => array($rr['plink'], t('link to source'), '', ''), ); } } diff --git a/mod/events.php b/mod/events.php index 5d80e8609..d66ae764c 100644 --- a/mod/events.php +++ b/mod/events.php @@ -1,12 +1,12 @@ argc == 1) { // if it's a json request abort here becaus we don't // need the widget data - if ($a->argv[1] === 'json') + if ($a->argv[1] === 'json') { return; + } $cal_widget = widget_events(); @@ -39,11 +40,11 @@ function events_post(App $a) { return; } - $event_id = ((x($_POST,'event_id')) ? intval($_POST['event_id']) : 0); - $cid = ((x($_POST,'cid')) ? intval($_POST['cid']) : 0); + $event_id = ((x($_POST, 'event_id')) ? intval($_POST['event_id']) : 0); + $cid = ((x($_POST, 'cid')) ? intval($_POST['cid']) : 0); $uid = local_user(); - $start_text = escape_tags($_REQUEST['start_text']); + $start_text = escape_tags($_REQUEST['start_text']); $finish_text = escape_tags($_REQUEST['finish_text']); $adjust = intval($_POST['adjust']); @@ -69,9 +70,9 @@ function events_post(App $a) { } if ($adjust) { - $start = datetime_convert(date_default_timezone_get(), 'UTC',$start); + $start = datetime_convert(date_default_timezone_get(), 'UTC', $start); if (! $nofinish) { - $finish = datetime_convert(date_default_timezone_get(), 'UTC',$finish); + $finish = datetime_convert(date_default_timezone_get(), 'UTC', $finish); } } else { $start = datetime_convert('UTC', 'UTC', $start); @@ -94,18 +95,18 @@ function events_post(App $a) { $onerror_url = App::get_baseurl() . "/events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish"; if (strcmp($finish, $start) < 0 && !$nofinish) { - notice( t('Event can not end before it has started.') . EOL); + notice(t('Event can not end before it has started.') . EOL); if (intval($_REQUEST['preview'])) { - echo( t('Event can not end before it has started.')); + echo t('Event can not end before it has started.'); killme(); } goaway($onerror_url); } if ((! $summary) || (! $start)) { - notice( t('Event title and start time are required.') . EOL); + notice(t('Event title and start time are required.') . EOL); if (intval($_REQUEST['preview'])) { - echo( t('Event title and start time are required.')); + echo t('Event title and start time are required.'); killme(); } goaway($onerror_url); @@ -130,7 +131,7 @@ function events_post(App $a) { $str_contact_deny = perms2str($_POST['contact_deny']); // Undo the pseudo-contact of self, since there are real contacts now - if ( strpos($str_contact_allow, '<' . $self . '>') !== false ) { + if (strpos($str_contact_allow, '<' . $self . '>') !== false ) { $str_contact_allow = str_replace('<' . $self . '>', '', $str_contact_allow); } // Make sure to set the `private` field as true. This is necessary to @@ -148,25 +149,25 @@ function events_post(App $a) { $datarray = array(); - $datarray['guid'] = get_guid(32); - $datarray['start'] = $start; - $datarray['finish'] = $finish; - $datarray['summary'] = $summary; - $datarray['desc'] = $desc; - $datarray['location'] = $location; - $datarray['type'] = $type; - $datarray['adjust'] = $adjust; - $datarray['nofinish'] = $nofinish; - $datarray['uid'] = $uid; - $datarray['cid'] = $cid; + $datarray['guid'] = get_guid(32); + $datarray['start'] = $start; + $datarray['finish'] = $finish; + $datarray['summary'] = $summary; + $datarray['desc'] = $desc; + $datarray['location'] = $location; + $datarray['type'] = $type; + $datarray['adjust'] = $adjust; + $datarray['nofinish'] = $nofinish; + $datarray['uid'] = $uid; + $datarray['cid'] = $cid; $datarray['allow_cid'] = $str_contact_allow; $datarray['allow_gid'] = $str_group_allow; - $datarray['deny_cid'] = $str_contact_deny; - $datarray['deny_gid'] = $str_group_deny; - $datarray['private'] = (($private_event) ? 1 : 0); - $datarray['id'] = $event_id; - $datarray['created'] = $created; - $datarray['edited'] = $edited; + $datarray['deny_cid'] = $str_contact_deny; + $datarray['deny_gid'] = $str_group_deny; + $datarray['private'] = (($private_event) ? 1 : 0); + $datarray['id'] = $event_id; + $datarray['created'] = $created; + $datarray['edited'] = $edited; if (intval($_REQUEST['preview'])) { $html = format_event_html($datarray); @@ -188,7 +189,7 @@ function events_post(App $a) { function events_content(App $a) { if (! local_user()) { - notice( t('Permission denied.') . EOL); + notice(t('Permission denied.') . EOL); return; } @@ -232,7 +233,7 @@ function events_content(App $a) { '$baseurl' => App::get_baseurl(), )); - $o =''; + $o = ''; // tabs if ($a->theme_events_in_profile) { $tabs = profile_tabs($a, true); @@ -243,7 +244,7 @@ function events_content(App $a) { $mode = 'view'; $y = 0; $m = 0; - $ignored = ((x($_REQUEST,'ignored')) ? intval($_REQUEST['ignored']) : 0); + $ignored = ((x($_REQUEST, 'ignored')) ? intval($_REQUEST['ignored']) : 0); if($a->argc > 1) { if ($a->argc > 2 && $a->argv[1] == 'event') { @@ -268,7 +269,7 @@ function events_content(App $a) { // The view mode part is similiar to /mod/cal.php if ($mode == 'view') { - $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'); if (! $y) { $y = intval($thisyear); @@ -307,20 +308,20 @@ function events_content(App $a) { $finish = sprintf('%d-%d-%d %d:%d:%d', $y, $m, $dim, 23, 59, 59); - if ($a->argv[1] === 'json'){ - if (x($_GET,'start')) $start = $_GET['start']; - if (x($_GET,'end')) $finish = $_GET['end']; + if ($a->argv[1] === 'json') { + if (x($_GET, 'start')) {$start = $_GET['start'];} + if (x($_GET, 'end')) {$finish = $_GET['end'];} } $start = datetime_convert('UTC', 'UTC', $start); $finish = datetime_convert('UTC', 'UTC', $finish); - $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start); + $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start); $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish); // put the event parametes in an array so we can better transmit them $event_params = array( - 'event_id' => (x($_GET,'id') ? $_GET["id"] : 0), + 'event_id' => (x($_GET, 'id') ? $_GET['id'] : 0), 'start' => $start, 'finish' => $finish, 'adjust_start' => $adjust_start, @@ -329,7 +330,7 @@ function events_content(App $a) { ); // get events by id or by date - if (x($_GET,'id')){ + if (x($_GET, 'id')){ $r = event_by_id(local_user(), $event_params); } else { $r = events_by_date(local_user(), $event_params); @@ -360,33 +361,33 @@ function events_content(App $a) { killme(); } - if (x($_GET,'id')){ + if (x($_GET, 'id')){ $tpl = get_markup_template("event.tpl"); } else { $tpl = get_markup_template("events_js.tpl"); } // Get rid of dashes in key names, Smarty3 can't handle them - foreach($events as $key => $event) { + foreach ($events as $key => $event) { $event_item = array(); - foreach($event['item'] as $k => $v) { - $k = str_replace('-','_',$k); + foreach ($event['item'] as $k => $v) { + $k = str_replace('-' ,'_', $k); $event_item[$k] = $v; } $events[$key]['item'] = $event_item; } $o = replace_macros($tpl, array( - '$baseurl' => App::get_baseurl(), - '$tabs' => $tabs, - '$title' => t('Events'), - '$view' => t('View'), - '$new_event' => array(App::get_baseurl() . '/events/new', t('Create New Event'), '', ''), - '$previous' => array(App::get_baseurl() . '/events/$prevyear/$prevmonth', t('Previous'), '', ''), - '$next' => array(App::get_baseurl() . '/events/$nextyear/$nextmonth', t('Next'), '', ''), - '$calendar' => cal($y, $m, $links, ' eventcal'), + '$baseurl' => App::get_baseurl(), + '$tabs' => $tabs, + '$title' => t('Events'), + '$view' => t('View'), + '$new_event' => array(App::get_baseurl() . '/events/new', t('Create New Event'), '', ''), + '$previous' => array(App::get_baseurl() . '/events/$prevyear/$prevmonth', t('Previous'), '', ''), + '$next' => array(App::get_baseurl() . '/events/$nextyear/$nextmonth', t('Next'), '', ''), + '$calendar' => cal($y, $m, $links, ' eventcal'), - '$events' => $events, + '$events' => $events, '$today' => t('today'), '$month' => t('month'), @@ -395,14 +396,12 @@ function events_content(App $a) { '$list' => t('list'), )); - if (x($_GET,'id')) { + if (x($_GET, 'id')) { echo $o; killme(); - } return $o; - } if ($mode === 'edit' && $event_id) { @@ -410,39 +409,41 @@ function events_content(App $a) { intval($event_id), intval(local_user()) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $orig_event = $r[0]; + } } // Passed parameters overrides anything found in the DB if ($mode === 'edit' || $mode === 'new') { - if (!x($orig_event)) $orig_event = array(); + if (!x($orig_event)) {$orig_event = array();} // In case of an error the browser is redirected back here, with these parameters filled in with the previous values - if (x($_REQUEST,'nofinish')) $orig_event['nofinish'] = $_REQUEST['nofinish']; - if (x($_REQUEST,'adjust')) $orig_event['adjust'] = $_REQUEST['adjust']; - if (x($_REQUEST,'summary')) $orig_event['summary'] = $_REQUEST['summary']; - if (x($_REQUEST,'description')) $orig_event['description'] = $_REQUEST['description']; - if (x($_REQUEST,'location')) $orig_event['location'] = $_REQUEST['location']; - if (x($_REQUEST,'start')) $orig_event['start'] = $_REQUEST['start']; - if (x($_REQUEST,'finish')) $orig_event['finish'] = $_REQUEST['finish']; + if (x($_REQUEST, 'nofinish')) {$orig_event['nofinish'] = $_REQUEST['nofinish'];} + if (x($_REQUEST, 'adjust')) {$orig_event['adjust'] = $_REQUEST['adjust'];} + if (x($_REQUEST, 'summary')) {$orig_event['summary'] = $_REQUEST['summary'];} + if (x($_REQUEST, 'description')) {$orig_event['description'] = $_REQUEST['description'];} + if (x($_REQUEST, 'location')) {$orig_event['location'] = $_REQUEST['location'];} + if (x($_REQUEST, 'start')) {$orig_event['start'] = $_REQUEST['start'];} + if (x($_REQUEST, 'finish')) {$orig_event['finish'] = $_REQUEST['finish'];} } - if($mode === 'edit' || $mode === 'new') { + if ($mode === 'edit' || $mode === 'new') { $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : ''); - $a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : ''); - $t_orig = ((x($orig_event)) ? $orig_event['summary'] : ''); - $d_orig = ((x($orig_event)) ? $orig_event['desc'] : ''); + $a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : ''); + + $t_orig = ((x($orig_event)) ? $orig_event['summary'] : ''); + $d_orig = ((x($orig_event)) ? $orig_event['desc'] : ''); $l_orig = ((x($orig_event)) ? $orig_event['location'] : ''); - $eid = ((x($orig_event)) ? $orig_event['id'] : 0); - $cid = ((x($orig_event)) ? $orig_event['cid'] : 0); - $uri = ((x($orig_event)) ? $orig_event['uri'] : ''); + $eid = ((x($orig_event)) ? $orig_event['id'] : 0); + $cid = ((x($orig_event)) ? $orig_event['cid'] : 0); + $uri = ((x($orig_event)) ? $orig_event['uri'] : ''); if (! x($orig_event)) { $sh_checked = ''; } else { - $sh_checked = (($orig_event['allow_cid'] === '<' . local_user() . '>' && (! $orig_event['allow_gid']) && (! $orig_event['deny_cid']) && (! $orig_event['deny_gid'])) ? '' : ' checked="checked" ' ); + $sh_checked = (($orig_event['allow_cid'] === '<' . local_user() . '>' && (! $orig_event['allow_gid']) && (! $orig_event['deny_cid']) && (! $orig_event['deny_gid'])) ? '' : ' checked="checked" '); } if ($cid OR ($mode !== 'new')) { @@ -458,18 +459,18 @@ function events_content(App $a) { $tz = (($orig_event['adjust']) ? date_default_timezone_get() : 'UTC'); } - $syear = datetime_convert('UTC', $tz, $sdt, 'Y'); + $syear = datetime_convert('UTC', $tz, $sdt, 'Y'); $smonth = datetime_convert('UTC', $tz, $sdt, 'm'); - $sday = datetime_convert('UTC', $tz, $sdt, 'd'); + $sday = datetime_convert('UTC', $tz, $sdt, 'd'); - $shour = ((x($orig_event)) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0); + $shour = ((x($orig_event)) ? datetime_convert('UTC', $tz, $sdt, 'H') : 0); $sminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $sdt, 'i') : 0); - $fyear = datetime_convert('UTC', $tz, $fdt, 'Y'); + $fyear = datetime_convert('UTC', $tz, $fdt, 'Y'); $fmonth = datetime_convert('UTC', $tz, $fdt, 'm'); - $fday = datetime_convert('UTC', $tz, $fdt, 'd'); + $fday = datetime_convert('UTC', $tz, $fdt, 'd'); - $fhour = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0); + $fhour = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0); $fminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0); $f = get_config('system','event_input_format'); @@ -477,7 +478,7 @@ function events_content(App $a) { $f = 'ymd'; } - require_once('include/acl_selectors.php'); + require_once 'include/acl_selectors.php' ; if ($mode === 'new') { $acl = (($cid) ? '' : populate_acl(((x($orig_event)) ? $orig_event : $a->user))); @@ -529,8 +530,8 @@ function events_content(App $a) { if ($mode === 'drop' && $event_id) { $del = 0; - $event_params = array('event_id' => ($event_id)); - $ev = event_by_id(local_user(), $event_params); + $params = array('event_id' => ($event_id)); + $ev = event_by_id(local_user(), $params); // Delete only real events (no birthdays) if (dbm::is_result($ev) && $ev[0]['type'] == 'event') { @@ -538,12 +539,11 @@ function events_content(App $a) { } if ($del == 0) { - notice( t('Failed to remove event' ) . EOL); + notice(t('Failed to remove event' ) . EOL); } else { - info( t('Event removed') . EOL); + info(t('Event removed') . EOL); } goaway(App::get_baseurl() . '/events'); - } } From e1d22ef5d4333cff860079c92fea92d82fe58fda Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Fri, 17 Mar 2017 19:10:48 +0100 Subject: [PATCH 04/65] some code cleanup --- mod/events.php | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/mod/events.php b/mod/events.php index d66ae764c..8e34b1568 100644 --- a/mod/events.php +++ b/mod/events.php @@ -14,7 +14,7 @@ function events_init(App $a) { } if ($a->argc == 1) { - // if it's a json request abort here becaus we don't + // If it's a json request abort here because we don't // need the widget data if ($a->argv[1] === 'json') { return; @@ -34,7 +34,7 @@ function events_init(App $a) { function events_post(App $a) { - logger('post: ' . print_r($_REQUEST, true)); + logger('post: ' . print_r($_REQUEST, true), LOGGER_DATA); if (! local_user()) { return; @@ -53,20 +53,15 @@ function events_post(App $a) { // The default setting for the `private` field in event_store() is false, so mirror that $private_event = false; + $start = '0000-00-00 00:00:00'; + $finish = '0000-00-00 00:00:00'; + if ($start_text) { $start = $start_text; - } else { - $start = sprintf('%d-%d-%d %d:%d:0', $startyear, $startmonth, $startday, $starthour, $startminute); - } - - if ($nofinish) { - $finish = '0000-00-00 00:00:00'; } if ($finish_text) { $finish = $finish_text; - } else { - $finish = sprintf('%d-%d-%d %d:%d:0', $finishyear, $finishmonth, $finishday, $finishhour, $finishminute); } if ($adjust) { @@ -103,7 +98,7 @@ function events_post(App $a) { goaway($onerror_url); } - if ((! $summary) || (! $start)) { + if ((! $summary) || ($start === '0000-00-00 00:00:00')) { notice(t('Event title and start time are required.') . EOL); if (intval($_REQUEST['preview'])) { echo t('Event title and start time are required.'); @@ -184,8 +179,6 @@ function events_post(App $a) { goaway($_SESSION['return_url']); } - - function events_content(App $a) { if (! local_user()) { @@ -239,8 +232,6 @@ function events_content(App $a) { $tabs = profile_tabs($a, true); } - - $mode = 'view'; $y = 0; $m = 0; @@ -425,9 +416,6 @@ function events_content(App $a) { if (x($_REQUEST, 'location')) {$orig_event['location'] = $_REQUEST['location'];} if (x($_REQUEST, 'start')) {$orig_event['start'] = $_REQUEST['start'];} if (x($_REQUEST, 'finish')) {$orig_event['finish'] = $_REQUEST['finish'];} - } - - if ($mode === 'edit' || $mode === 'new') { $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : ''); $a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : ''); @@ -439,7 +427,6 @@ function events_content(App $a) { $cid = ((x($orig_event)) ? $orig_event['cid'] : 0); $uri = ((x($orig_event)) ? $orig_event['uri'] : ''); - if (! x($orig_event)) { $sh_checked = ''; } else { @@ -450,7 +437,6 @@ function events_content(App $a) { $sh_checked .= ' disabled="disabled" '; } - $sdt = ((x($orig_event)) ? $orig_event['start'] : 'now'); $fdt = ((x($orig_event)) ? $orig_event['finish'] : 'now'); From 497df57ef7581855e3d813e6a07a3d584b91f1d9 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Sat, 18 Mar 2017 04:41:54 +0100 Subject: [PATCH 05/65] more standards work --- include/event.php | 385 ++++++++++++++++++++++++++-------------------- mod/events.php | 8 +- 2 files changed, 225 insertions(+), 168 deletions(-) diff --git a/include/event.php b/include/event.php index d9b89a7c6..82d5a1ec5 100644 --- a/include/event.php +++ b/include/event.php @@ -4,39 +4,42 @@ * @brief functions specific to event handling */ -require_once('include/bbcode.php'); -require_once('include/map.php'); -require_once('include/datetime.php'); +require_once 'include/bbcode.php'; +require_once 'include/map.php'; +require_once 'include/datetime.php'; function format_event_html($ev, $simple = false) { - if(! ((is_array($ev)) && count($ev))) + if(! ((is_array($ev)) && count($ev))) { return ''; + } $bd_format = t('l F d, Y \@ g:i A') ; // Friday January 18, 2011 @ 8 AM $event_start = (($ev['adjust']) ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $ev['start'] , $bd_format )) - : day_translate(datetime_convert('UTC', 'UTC', + : day_translate(datetime_convert('UTC', 'UTC', $ev['start'] , $bd_format))); $event_end = (($ev['adjust']) ? day_translate(datetime_convert('UTC', date_default_timezone_get(), $ev['finish'] , $bd_format )) - : day_translate(datetime_convert('UTC', 'UTC', + : day_translate(datetime_convert('UTC', 'UTC', $ev['finish'] , $bd_format ))); if ($simple) { - $o = "

".bbcode($ev['summary'])."

"; + $o = "

" . bbcode($ev['summary']) . "

"; - $o .= "

".bbcode($ev['desc'])."

"; + $o .= "

" . bbcode($ev['desc']) . "

"; - $o .= "

".t('Starts:')."

".$event_start."

"; + $o .= "

" . t('Starts:') . "

" . $event_start . "

"; - if(! $ev['nofinish']) - $o .= "

".t('Finishes:')."

".$event_end."

"; + if (! $ev['nofinish']) { + $o .= "

" . t('Finishes:') . "

" . $event_end ."

"; + } - if(strlen($ev['location'])) - $o .= "

".t('Location:')."

".$ev['location']."

"; + if (strlen($ev['location'])) { + $o .= "

" . t('Location:') . "

" . $ev['location'] . "

"; + } return $o; } @@ -44,31 +47,34 @@ function format_event_html($ev, $simple = false) { $o = '
' . "\r\n"; - $o .= '

' . bbcode($ev['summary']) . '

' . "\r\n"; + $o .= '

' . bbcode($ev['summary']) . '

' . "\r\n"; - $o .= '

' . bbcode($ev['desc']) . '

' . "\r\n"; + $o .= '

' . bbcode($ev['desc']) . '

' . "\r\n"; $o .= '

' . t('Starts:') . ' '.$event_start . '

' . "\r\n"; - if(! $ev['nofinish']) + if (! $ev['nofinish']) { $o .= '

' . t('Finishes:') . ' '.$event_end - . '

' . "\r\n"; + . '

' . "\r\n"; + } - if(strlen($ev['location'])){ + if (strlen($ev['location'])) { $o .= '

' . t('Location:') . ' ' . bbcode($ev['location']) . '

' . "\r\n"; - if (strpos($ev['location'], "[map") !== False) { + // Include a map of the location if the [map] BBCode is used + if (strpos($ev['location'], "[map") !== false) { $map = generate_named_map($ev['location']); - if ($map!==$ev['location']) $o.=$map; + if ($map !== $ev['location']) { + $o.= $map; + } } - } $o .= '
' . "\r\n"; @@ -146,63 +152,81 @@ function format_event_bbcode($ev) { $o = ''; - if($ev['summary']) + if ($ev['summary']) { $o .= '[event-summary]' . $ev['summary'] . '[/event-summary]'; + } - if($ev['desc']) + if ($ev['desc']) { $o .= '[event-description]' . $ev['desc'] . '[/event-description]'; + } - if($ev['start']) + if ($ev['start']) { $o .= '[event-start]' . $ev['start'] . '[/event-start]'; + } - if(($ev['finish']) && (! $ev['nofinish'])) + if (($ev['finish']) && (! $ev['nofinish'])) { $o .= '[event-finish]' . $ev['finish'] . '[/event-finish]'; + } - if($ev['location']) + if ($ev['location']) { $o .= '[event-location]' . $ev['location'] . '[/event-location]'; + } - if($ev['adjust']) + if ($ev['adjust']) { $o .= '[event-adjust]' . $ev['adjust'] . '[/event-adjust]'; - + } return $o; - } function bbtovcal($s) { $o = ''; $ev = bbtoevent($s); - if($ev['desc']) + + if ($ev['desc']) { $o = format_event_html($ev); + } + return $o; } - function bbtoevent($s) { $ev = array(); $match = ''; - if(preg_match("/\[event\-summary\](.*?)\[\/event\-summary\]/is",$s,$match)) + if (preg_match("/\[event\-summary\](.*?)\[\/event\-summary\]/is",$s,$match)) { $ev['summary'] = $match[1]; - $match = ''; - if(preg_match("/\[event\-description\](.*?)\[\/event\-description\]/is",$s,$match)) - $ev['desc'] = $match[1]; - $match = ''; - if(preg_match("/\[event\-start\](.*?)\[\/event\-start\]/is",$s,$match)) - $ev['start'] = $match[1]; - $match = ''; - if(preg_match("/\[event\-finish\](.*?)\[\/event\-finish\]/is",$s,$match)) - $ev['finish'] = $match[1]; - $match = ''; - if(preg_match("/\[event\-location\](.*?)\[\/event\-location\]/is",$s,$match)) - $ev['location'] = $match[1]; - $match = ''; - if(preg_match("/\[event\-adjust\](.*?)\[\/event\-adjust\]/is",$s,$match)) - $ev['adjust'] = $match[1]; - $ev['nofinish'] = (((x($ev, 'start') && $ev['start']) && (!x($ev, 'finish') || !$ev['finish'])) ? 1 : 0); - return $ev; + } + $match = ''; + if (preg_match("/\[event\-description\](.*?)\[\/event\-description\]/is",$s,$match)) { + $ev['desc'] = $match[1]; + } + + $match = ''; + if (preg_match("/\[event\-start\](.*?)\[\/event\-start\]/is",$s,$match)) { + $ev['start'] = $match[1]; + } + + $match = ''; + if (preg_match("/\[event\-finish\](.*?)\[\/event\-finish\]/is",$s,$match)) { + $ev['finish'] = $match[1]; + } + + $match = ''; + if (preg_match("/\[event\-location\](.*?)\[\/event\-location\]/is",$s,$match)) { + $ev['location'] = $match[1]; + } + + $match = ''; + if (preg_match("/\[event\-adjust\](.*?)\[\/event\-adjust\]/is",$s,$match)) { + $ev['adjust'] = $match[1]; + } + + $ev['nofinish'] = (((x($ev, 'start') && $ev['start']) && (!x($ev, 'finish') || !$ev['finish'])) ? 1 : 0); + + return $ev; } @@ -212,21 +236,22 @@ function sort_by_date($a) { return $a; } - function ev_compare($a,$b) { - $date_a = (($a['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$a['start']) : $a['start']); - $date_b = (($b['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$b['start']) : $b['start']); + $date_a = (($a['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $a['start']) : $a['start']); + $date_b = (($b['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $b['start']) : $b['start']); - if($date_a === $date_b) - return strcasecmp($a['desc'],$b['desc']); + if ($date_a === $date_b) { + return strcasecmp($a['desc'], $b['desc']); + } - return strcmp($date_a,$date_b); + return strcmp($date_a, $date_b); } function event_delete($event_id) { - if ($event_id == 0) + if ($event_id == 0) { return; + } q("DELETE FROM `event` WHERE `id` = %d", intval($event_id)); logger("Deleted event ".$event_id, LOGGER_DEBUG); @@ -234,37 +259,39 @@ function event_delete($event_id) { function event_store($arr) { - require_once('include/datetime.php'); - require_once('include/items.php'); - require_once('include/bbcode.php'); + require_once 'include/datetime.php'; + require_once 'include/items.php'; + require_once 'include/bbcode.php'; $a = get_app(); - $arr['created'] = (($arr['created']) ? $arr['created'] : datetime_convert()); - $arr['edited'] = (($arr['edited']) ? $arr['edited'] : datetime_convert()); - $arr['type'] = (($arr['type']) ? $arr['type'] : 'event' ); - $arr['cid'] = ((intval($arr['cid'])) ? intval($arr['cid']) : 0); - $arr['uri'] = (x($arr,'uri') ? $arr['uri'] : item_new_uri($a->get_hostname(),$arr['uid'])); - $arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0); + $arr['created'] = (($arr['created']) ? $arr['created'] : datetime_convert()); + $arr['edited'] = (($arr['edited']) ? $arr['edited'] : datetime_convert()); + $arr['type'] = (($arr['type']) ? $arr['type'] : 'event' ); + $arr['cid'] = ((intval($arr['cid'])) ? intval($arr['cid']) : 0); + $arr['uri'] = (x($arr,'uri') ? $arr['uri'] : item_new_uri($a->get_hostname(), $arr['uid'])); + $arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0); $arr['guid'] = get_guid(32); - if($arr['cid']) + if($arr['cid']) { $c = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($arr['cid']), intval($arr['uid']) ); - else + } else { $c = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($arr['uid']) ); + } - if(count($c)) + if (dbm::is_result($c)) { $contact = $c[0]; + } // Existing event being modified - if($arr['id']) { + if ($arr['id']) { // has the event actually changed? @@ -272,7 +299,7 @@ function event_store($arr) { intval($arr['id']), intval($arr['uid']) ); - if((! dbm::is_result($r)) || ($r[0]['edited'] === $arr['edited'])) { + if ((! dbm::is_result($r)) || ($r[0]['edited'] === $arr['edited'])) { // Nothing has changed. Grab the item id to return. @@ -280,7 +307,7 @@ function event_store($arr) { intval($arr['id']), intval($arr['uid']) ); - return((dbm::is_result($r)) ? $r[0]['id'] : 0); + return ((dbm::is_result($r)) ? $r[0]['id'] : 0); } // The event changed. Update it. @@ -318,7 +345,6 @@ function event_store($arr) { $object .= '' . xmlify(format_event_bbcode($arr)) . ''; $object .= '' . "\n"; - q("UPDATE `item` SET `body` = '%s', `object` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc(format_event_bbcode($arr)), dbesc($object), @@ -328,8 +354,9 @@ function event_store($arr) { ); $item_id = $r[0]['id']; - } else + } else { $item_id = 0; + } call_hooks("event_updated", $arr['id']); @@ -366,8 +393,9 @@ function event_store($arr) { dbesc($arr['uri']), intval($arr['uid']) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $event = $r[0]; + } $item_arr = array(); @@ -399,7 +427,7 @@ function event_store($arr) { $item_arr['body'] = format_event_bbcode($event); - $item_arr['object'] = '' . xmlify(ACTIVITY_OBJ_EVENT) . '' . xmlify($arr['uri']) . ''; + $item_arr['object'] = '' . xmlify(ACTIVITY_OBJ_EVENT) . '' . xmlify($arr['uri']) . ''; $item_arr['object'] .= '' . xmlify(format_event_bbcode($event)) . ''; $item_arr['object'] .= '' . "\n"; @@ -412,7 +440,7 @@ function event_store($arr) { // $plink = App::get_baseurl() . '/display/' . $r[0]['nickname'] . '/' . $item_id; - if($item_id) { + if ($item_id) { //q("UPDATE `item` SET `plink` = '%s', `event-id` = %d WHERE `uid` = %d AND `id` = %d", // dbesc($plink), // intval($event['id']), @@ -433,12 +461,17 @@ function event_store($arr) { } function get_event_strings() { + // First day of the week (0 = Sunday) - $firstDay = get_pconfig(local_user(),'system','first_day_of_week'); - if ($firstDay === false) $firstDay=0; + $firstDay = get_pconfig(local_user(),'system', 'first_day_of_week'); + if ($firstDay === false) { + $firstDay = 0; + } $i18n = array( "firstDay" => $firstDay, + "allday" => t("all-day"), + "Sun" => t("Sun"), "Mon" => t("Mon"), "Tue" => t("Tue"), @@ -446,13 +479,15 @@ function get_event_strings() { "Thu" => t("Thu"), "Fri" => t("Fri"), "Sat" => t("Sat"), - "Sunday" => t("Sunday"), - "Monday" => t("Monday"), - "Tuesday" => t("Tuesday"), + + "Sunday" => t("Sunday"), + "Monday" => t("Monday"), + "Tuesday" => t("Tuesday"), "Wednesday" => t("Wednesday"), - "Thursday" => t("Thursday"), - "Friday" => t("Friday"), - "Saturday" => t("Saturday"), + "Thursday" => t("Thursday"), + "Friday" => t("Friday"), + "Saturday" => t("Saturday"), + "Jan" => t("Jan"), "Feb" => t("Feb"), "Mar" => t("Mar"), @@ -465,47 +500,49 @@ function get_event_strings() { "Oct" => t("Oct"), "Nov" => t("Nov"), "Dec" => t("Dec"), - "January" => t("January"), - "February" => t("February"), - "March" => t("March"), - "April" => t("April"), - "May" => t("May"), - "June" => t("June"), - "July" => t("July"), - "August" => t("August"), + + "January" => t("January"), + "February" => t("February"), + "March" => t("March"), + "April" => t("April"), + "May" => t("May"), + "June" => t("June"), + "July" => t("July"), + "August" => t("August"), "September" => t("September"), - "October" => t("October"), - "November" => t("November"), - "December" => t("December"), + "October" => t("October"), + "November" => t("November"), + "December" => t("December"), + "today" => t("today"), "month" => t("month"), - "week" => t("week"), - "day" => t("day"), - "allday" => t("all-day"), + "week" => t("week"), + "day" => t("day"), "noevent" => t("No events to display"), - "dtstart_label" => t("Starts:"), - "dtend_label" => t("Finishes:"), + "dtstart_label" => t("Starts:"), + "dtend_label" => t("Finishes:"), "location_label" => t("Location:") ); return $i18n; } -/// @todo We should replace this with a separate update function if there is some time left /** * @brief Removes duplicated birthday events * * @param array $dates Array of possibly duplicated events * @return array Cleaned events + * + * @todo We should replace this with a separate update function if there is some time left */ function event_remove_duplicates($dates) { $dates2 = array(); foreach ($dates AS $date) { if ($date['type'] == 'birthday') { - $dates2[$date['uid']."-".$date['cid']."-".$date['start']] = $date; + $dates2[$date['uid'] . "-" . $date['cid'] . "-" . $date['start']] = $date; } else { $dates2[] = $date; } @@ -524,10 +561,11 @@ function event_remove_duplicates($dates) { */ function event_by_id($owner_uid = 0, $event_params, $sql_extra = '') { // ownly allow events if there is a valid owner_id - if($owner_uid == 0) + if ($owner_uid == 0) { return; + } - // query for the event by event id + // Query for the event by event id $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`, `item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid` @@ -556,11 +594,12 @@ function event_by_id($owner_uid = 0, $event_params, $sql_extra = '') { * @return array Query results */ function events_by_date($owner_uid = 0, $event_params, $sql_extra = '') { - // ownly allow events if there is a valid owner_id - if($owner_uid == 0) + // Only allow events if there is a valid owner_id + if($owner_uid == 0) { return; + } - // query for the event by date + // Query for the event by date $r = q("SELECT `event`.*, `item`.`id` AS `itemid`,`item`.`plink`, `item`.`author-name`, `item`.`author-avatar`, `item`.`author-link` FROM `event` LEFT JOIN `item` ON `item`.`event-id` = `event`.`id` AND `item`.`uid` = `event`.`uid` @@ -602,13 +641,12 @@ function process_events($arr) { $d = day_translate($d); $start = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['start'], 'c') : datetime_convert('UTC', 'UTC', $rr['start'], 'c')); - if ($rr['nofinish']){ + if ($rr['nofinish']) { $end = null; } else { $end = (($rr['adjust']) ? datetime_convert('UTC', date_default_timezone_get(), $rr['finish'], 'c') : datetime_convert('UTC', 'UTC', $rr['finish'], 'c')); } - $is_first = ($d !== $last_date); $last_date = $d; @@ -630,20 +668,20 @@ function process_events($arr) { $rr['desc'] = bbcode($rr['desc']); $rr['location'] = bbcode($rr['location']); $events[] = array( - 'id'=>$rr['id'], - 'start'=> $start, - 'end' => $end, + 'id' => $rr['id'], + 'start' => $start, + 'end' => $end, 'allDay' => false, - 'title' => $title, + 'title' => $title, - 'j' => $j, - 'd' => $d, - 'edit' => $edit, - 'drop' => $drop, - 'is_first'=>$is_first, - 'item'=>$rr, - 'html'=>$html, - 'plink' => array($rr['plink'], t('link to source'), '', ''), + 'j' => $j, + 'd' => $d, + 'edit' => $edit, + 'drop' => $drop, + 'is_first' => $is_first, + 'item' => $rr, + 'html' => $html, + 'plink' => array($rr['plink'], t('link to source'), '', ''), ); } } @@ -661,34 +699,36 @@ function process_events($arr) { * @return string Content according to selected export format */ function event_format_export ($events, $format = 'ical', $timezone) { - if(! ((is_array($events)) && count($events))) + if(! ((is_array($events)) && count($events))) { return; + } switch ($format) { - // format the exported data as a CSV file + // Format the exported data as a CSV file case "csv": header("Content-type: text/csv"); $o = '"Subject", "Start Date", "Start Time", "Description", "End Date", "End Time", "Location"' . PHP_EOL; foreach ($events as $event) { - /// @todo the time / date entries don't include any information about the - // timezone the event is scheduled in :-/ + /// @todo The time / date entries don't include any information about the + /// timezone the event is scheduled in :-/ $tmp1 = strtotime($event['start']); $tmp2 = strtotime($event['finish']); $time_format = "%H:%M:%S"; $date_format = "%Y-%m-%d"; - $o .= '"'.$event['summary'].'", "'.strftime($date_format, $tmp1) . - '", "'.strftime($time_format, $tmp1).'", "'.$event['desc'] . - '", "'.strftime($date_format, $tmp2) . - '", "'.strftime($time_format, $tmp2) . - '", "'.$event['location'].'"' . PHP_EOL; + + $o .= '"' . $event['summary'] . '", "' . strftime($date_format, $tmp1) . + '", "' . strftime($time_format, $tmp1) . '", "' . $event['desc'] . + '", "' . strftime($date_format, $tmp2) . + '", "' . strftime($time_format, $tmp2) . + '", "' . $event['location'] . '"' . PHP_EOL; } break; - // format the exported data as a ics file + // Format the exported data as a ics file case "ical": header("Content-type: text/ics"); - $o = 'BEGIN:VCALENDAR'. PHP_EOL + $o = 'BEGIN:VCALENDAR' . PHP_EOL . 'VERSION:2.0' . PHP_EOL . 'PRODID:-//friendica calendar export//0.1//EN' . PHP_EOL; /// @todo include timezone informations in cases were the time is not in UTC @@ -700,35 +740,43 @@ function event_format_export ($events, $format = 'ical', $timezone) { // but test your solution against http://icalvalid.cloudapp.net/ // also long lines SHOULD be split at 75 characters length foreach ($events as $event) { + if ($event['adjust'] == 1) { $UTC = 'Z'; } else { $UTC = ''; } $o .= 'BEGIN:VEVENT' . PHP_EOL; - if ($event[start]) { + + if ($event['start']) { $tmp = strtotime($event['start']); - $dtformat = "%Y%m%dT%H%M%S".$UTC; - $o .= 'DTSTART:'.strftime($dtformat, $tmp).PHP_EOL; + $dtformat = "%Y%m%dT%H%M%S" . $UTC; + $o .= 'DTSTART:' . strftime($dtformat, $tmp) . PHP_EOL; } + if (!$event['nofinish']) { $tmp = strtotime($event['finish']); - $dtformat = "%Y%m%dT%H%M%S".$UTC; - $o .= 'DTEND:'.strftime($dtformat, $tmp).PHP_EOL; + $dtformat = "%Y%m%dT%H%M%S" . $UTC; + $o .= 'DTEND:' . strftime($dtformat, $tmp) . PHP_EOL; } - if ($event['summary']) + + if ($event['summary']) { $tmp = $event['summary']; - $tmp = str_replace(PHP_EOL, PHP_EOL.' ',$tmp); + $tmp = str_replace(PHP_EOL, PHP_EOL . ' ', $tmp); $tmp = addcslashes($tmp, ',;'); $o .= 'SUMMARY:' . $tmp . PHP_EOL; - if ($event['desc']) + } + + if ($event['desc']) { $tmp = $event['desc']; - $tmp = str_replace(PHP_EOL, PHP_EOL.' ',$tmp); + $tmp = str_replace(PHP_EOL, PHP_EOL . ' ', $tmp); $tmp = addcslashes($tmp, ',;'); $o .= 'DESCRIPTION:' . $tmp . PHP_EOL; + } + if ($event['location']) { $tmp = $event['location']; - $tmp = str_replace(PHP_EOL, PHP_EOL.' ',$tmp); + $tmp = str_replace(PHP_EOL, PHP_EOL . ' ', $tmp); $tmp = addcslashes($tmp, ',;'); $o .= 'LOCATION:' . $tmp . PHP_EOL; } @@ -759,16 +807,18 @@ function event_format_export ($events, $format = 'ical', $timezone) { * @return array Query results */ function events_by_uid($uid = 0, $sql_extra = '') { - if($uid == 0) + if ($uid == 0) { return; + } // The permission condition if no condition was transmitted - if($sql_extra == '') + if($sql_extra == '') { $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' "; + } - // does the user who requests happen to be the owner of the events - // requested? then show all of your events, otherwise only those that - // don't have limitations set in allow_cid and allow_gid + // Does the user who requests happen to be the owner of the events + // requested? then show all of your events, otherwise only those that + // don't have limitations set in allow_cid and allow_gid if (local_user() == $uid) { $r = q("SELECT `start`, `finish`, `adjust`, `summary`, `desc`, `location`, `nofinish` FROM `event` WHERE `uid`= %d AND `cid` = 0 ", @@ -781,8 +831,9 @@ function events_by_uid($uid = 0, $sql_extra = '') { ); } - if (dbm::is_result($r)) + if (dbm::is_result($r)) { return $r; + } } /** @@ -801,25 +852,28 @@ function event_export($uid, $format = 'ical') { $process = false; - // we are allowed to show events + // We are allowed to show events // get the timezone the user is in $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']; + } - // 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); - // we have the events that are available for the requestor - // now format the output according to the requested format - if(count($events)) + // We have the events that are available for the requestor + // now format the output according to the requested format + if (count($events)) { $res = event_format_export($events, $format, $timezone); + } // If there are results the precess was successfull - if(x($res)) + if (x($res)) { $process = true; + } - // get the file extension for the format + // Get the file extension for the format switch ($format) { case "ical": $file_ext = "ics"; @@ -834,10 +888,10 @@ function event_export($uid, $format = 'ical') { } $arr = array( - 'success' => $process, - 'format' => $format, + 'success' => $process, + 'format' => $format, 'extension' => $file_ext, - 'content' => $res, + 'content' => $res, ); return $arr; @@ -860,8 +914,9 @@ function widget_events() { // 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) - if(! local_user() && ! $owner_uid) + if (! local_user() && ! $owner_uid) { return; + } // 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) @@ -869,13 +924,15 @@ function widget_events() { // 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 // 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; + } // If it's a kind of profile page (intval($owner_uid)) return if the user not logged in and // 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 replace_macros(get_markup_template("events_aside.tpl"), array( '$etitle' => t("Export"), diff --git a/mod/events.php b/mod/events.php index 8e34b1568..bcf80dd1c 100644 --- a/mod/events.php +++ b/mod/events.php @@ -237,12 +237,12 @@ function events_content(App $a) { $m = 0; $ignored = ((x($_REQUEST, 'ignored')) ? intval($_REQUEST['ignored']) : 0); - if($a->argc > 1) { + if ($a->argc > 1) { if ($a->argc > 2 && $a->argv[1] == 'event') { $mode = 'edit'; $event_id = intval($a->argv[2]); } - if($a->argc > 2 && $a->argv[1] == 'drop') { + if ($a->argc > 2 && $a->argv[1] == 'drop') { $mode = 'drop'; $event_id = intval($a->argv[2]); } @@ -321,7 +321,7 @@ function events_content(App $a) { ); // get events by id or by date - if (x($_GET, 'id')){ + if (x($_GET, 'id')) { $r = event_by_id(local_user(), $event_params); } else { $r = events_by_date(local_user(), $event_params); @@ -352,7 +352,7 @@ function events_content(App $a) { killme(); } - if (x($_GET, 'id')){ + if (x($_GET, 'id')) { $tpl = get_markup_template("event.tpl"); } else { $tpl = get_markup_template("events_js.tpl"); From 1c6535c0b45c32ccbb0e2bd49e5bb7a6d5435d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Mon, 23 Jan 2017 09:44:53 +0100 Subject: [PATCH 06/65] applied coding convention: - replaced space -> tab (code indenting) - added curly braces - used dbm::is_result() if $r is no result (may happen) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/settings.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mod/settings.php b/mod/settings.php index 32ccaf541..94b93f9b9 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -381,13 +381,15 @@ function settings_post(App $a) { $err = true; } - // check if the old password was supplied correctly before - // changing it to the new value - $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user())); - if( $oldpass != $r[0]['password'] ) { - notice( t('Wrong password.') . EOL); - $err = true; - } + // check if the old password was supplied correctly before + // changing it to the new value + $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user())); + if (!dbm::is_result($r)) { + killme(); + } elseif ( $oldpass != $r[0]['password'] ) { + notice( t('Wrong password.') . EOL); + $err = true; + } if(! $err) { $password = hash('whirlpool',$newpass); @@ -395,10 +397,11 @@ function settings_post(App $a) { dbesc($password), intval(local_user()) ); - if($r) + if($r) { info( t('Password changed.') . EOL); - else + } else { notice( t('Password update failed. Please try again.') . EOL); + } } } From 63e4750b4abfd0ce80caf65b20d73d9ec9ef756f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Mon, 23 Jan 2017 09:50:25 +0100 Subject: [PATCH 07/65] more coding convention applied: - added curly braces - added spaces where needed - $r only needs to be tested with dbm::is_result() - made SQL keywords all uper-case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/contacts.php | 18 +++++++++++------- mod/crepair.php | 18 +++++++++++------- mod/message.php | 3 ++- mod/profiles.php | 10 ++++++---- mod/settings.php | 7 ++++--- mod/wall_upload.php | 8 ++++---- 6 files changed, 38 insertions(+), 26 deletions(-) diff --git a/mod/contacts.php b/mod/contacts.php index a2a77e2a5..70f4b7350 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -136,8 +136,7 @@ function contacts_batch_actions(App $a) { if (x($_SESSION,'return_url')) { goaway('' . $_SESSION['return_url']); - } - else { + } else { goaway('contacts'); } @@ -194,8 +193,10 @@ function contacts_post(App $a) { $ffi_keyword_blacklist = escape_tags(trim($_POST['ffi_keyword_blacklist'])); $priority = intval($_POST['poll']); - if($priority > 5 || $priority < 0) + + if ($priority > 5 || $priority < 0) { $priority = 0; + } $info = escape_tags(trim($_POST['info'])); @@ -212,17 +213,20 @@ function contacts_post(App $a) { intval($contact_id), intval(local_user()) ); - if($r) + if ($r) { info( t('Contact updated.') . EOL); - else + } else { notice( t('Failed to update contact record.') . EOL); + } - $r = q("select * from contact where id = %d and uid = %d limit 1", + $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval(local_user()) ); - if($r && dbm::is_result($r)) + + if (dbm::is_result($r)) { $a->data['contact'] = $r[0]; + } return; diff --git a/mod/crepair.php b/mod/crepair.php index 902a12930..ef7908661 100644 --- a/mod/crepair.php +++ b/mod/crepair.php @@ -20,10 +20,11 @@ function crepair_init(App $a) { } } - if(! x($a->page,'aside')) + if (! x($a->page,'aside')) { $a->page['aside'] = ''; + } - if($contact_id) { + if ($contact_id) { $a->data['contact'] = $r[0]; $contact = $r[0]; profile_load($a, "", 0, get_contact_details_by_url($contact["url"])); @@ -35,9 +36,12 @@ function crepair_post(App $a) { return; } + // Init $r here if $cid is not set + $r = false; + $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0); - if($cid) { + if ($cid) { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($cid), intval(local_user()) @@ -78,18 +82,18 @@ function crepair_post(App $a) { local_user() ); - if($photo) { + if ($photo) { logger('mod-crepair: updating photo from ' . $photo); require_once("include/Photo.php"); update_contact_avatar($photo,local_user(),$contact['id']); } - if($r) + if ($r) { info( t('Contact settings applied.') . EOL); - else + } else { notice( t('Contact update failed.') . EOL); - + } return; } diff --git a/mod/message.php b/mod/message.php index 9e9669146..df5b4709b 100644 --- a/mod/message.php +++ b/mod/message.php @@ -251,8 +251,9 @@ function message_content(App $a) { // ); //} - if($r) + if ($r) { info( t('Conversation removed.') . EOL ); + } } //goaway(App::get_baseurl(true) . '/message' ); goaway($_SESSION['return_url']); diff --git a/mod/profiles.php b/mod/profiles.php index 4c6ff926b..e359e9efb 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -34,8 +34,9 @@ function profiles_init(App $a) { intval($a->argv[2]), intval(local_user()) ); - if($r) + if ($r) { info(t('Profile deleted.').EOL); + } goaway('profiles'); return; // NOTREACHED @@ -473,11 +474,12 @@ function profiles_post(App $a) { intval(local_user()) ); - if($r) + if ($r) { info( t('Profile updated.') . EOL); + } - if($namechanged && $is_default) { + if ($namechanged && $is_default) { $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d", dbesc($name), dbesc(datetime_convert()), @@ -489,7 +491,7 @@ function profiles_post(App $a) { ); } - if($is_default) { + if ($is_default) { $location = formatted_location(array("locality" => $locality, "region" => $region, "country-name" => $country_name)); q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `self` AND `uid` = %d", diff --git a/mod/settings.php b/mod/settings.php index 94b93f9b9..b77b1336d 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -397,7 +397,7 @@ function settings_post(App $a) { dbesc($password), intval(local_user()) ); - if($r) { + if ($r) { info( t('Password changed.') . EOL); } else { notice( t('Password update failed. Please try again.') . EOL); @@ -602,8 +602,9 @@ function settings_post(App $a) { dbesc($language), intval(local_user()) ); - if($r) + if ($r) { info( t('Settings updated.') . EOL); + } // clear session language unset($_SESSION['language']); @@ -622,7 +623,7 @@ function settings_post(App $a) { ); - if($name_change) { + if ($name_change) { q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `self`", dbesc($username), dbesc(datetime_convert()), diff --git a/mod/wall_upload.php b/mod/wall_upload.php index 1f71f36b6..fa30a8ad3 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -228,14 +228,14 @@ function wall_upload_post(App $a, $desktopmode = true) { if($width > 640 || $height > 640) { $ph->scaleImage(640); $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1, 0, $defperm); - if($r) + if ($r) $smallest = 1; } - if($width > 320 || $height > 320) { + if ($width > 320 || $height > 320) { $ph->scaleImage(320); $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2, 0, $defperm); - if($r AND ($smallest == 0)) + if ($r AND ($smallest == 0)) $smallest = 2; } @@ -244,7 +244,7 @@ function wall_upload_post(App $a, $desktopmode = true) { if (!$desktopmode) { $r = q("SELECT `id`, `datasize`, `width`, `height`, `type` FROM `photo` WHERE `resource-id` = '%s' ORDER BY `width` DESC LIMIT 1", $hash); - if (!$r){ + if (!dbm::is_result($r)) { if ($r_json) { echo json_encode(array('error'=>'')); killme(); From 0b6336edb0fc44b14ba9836ed63015d7d763841a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Mon, 23 Jan 2017 10:14:48 +0100 Subject: [PATCH 08/65] unified most db upgrades: - common way is to check on result ($r mostly) of db upgrade - on success, return UPDATE_SUCCESS - on failure, return UPDATE_FAILED MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- update.php | 344 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 214 insertions(+), 130 deletions(-) diff --git a/update.php b/update.php index 64259bbb1..242fd1454 100644 --- a/update.php +++ b/update.php @@ -37,7 +37,7 @@ define('UPDATE_VERSION' , 1215); */ - +/// @TODO These old updates need to have UPDATE_SUCCESS returned on success? function update_1000() { q("ALTER TABLE `item` DROP `like`, DROP `dislike` "); @@ -308,7 +308,7 @@ function update_1030() { function update_1031() { // Repair any bad links that slipped into the item table $r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' "); - if($r && dbm::is_result($r)) { + if (dbm::is_result($r)) { foreach ($r as $rr) { if(strstr($rr['object'],'type="http')) { q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d", @@ -368,13 +368,11 @@ function update_1036() { } function update_1037() { - q("ALTER TABLE `contact` CHANGE `lrdd` `alias` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL "); - } function update_1038() { - q("ALTER TABLE `item` ADD `plink` CHAR( 255 ) NOT NULL AFTER `target` "); + q("ALTER TABLE `item` ADD `plink` CHAR( 255 ) NOT NULL AFTER `target` "); } function update_1039() { @@ -532,8 +530,10 @@ function update_1065() { function update_1066() { $r = q("ALTER TABLE `item` ADD `received` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `edited` "); - if($r) + + if ($r) { q("ALTER TABLE `item` ADD INDEX ( `received` ) "); + } $r = q("UPDATE `item` SET `received` = `edited` WHERE 1"); } @@ -567,6 +567,7 @@ function update_1069() { q("ALTER TABLE `fcontact` ADD `request` CHAR( 255 ) NOT NULL AFTER `photo` "); } +/// @TODO Still meeded? // mail body needs to accomodate private photos function update_1070() { @@ -614,8 +615,9 @@ function update_1075() { $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1", dbesc($guid) ); - if(! count($x)) + if (!dbm::is_result($x)) { $found = false; + } } while ($found == true ); q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d", @@ -684,14 +686,19 @@ function update_1082() { q("ALTER TABLE `photo` ADD `guid` CHAR( 64 ) NOT NULL AFTER `contact-id`, ADD INDEX ( `guid` ) "); // make certain the following code is only executed once - $r = q("select `id` from `photo` where `guid` != '' limit 1"); - if (dbm::is_result($r)) + + $r = q("SELECT `id` FROM `photo` WHERE `guid` != '' LIMIT 1"); + + if (dbm::is_result($r)) { return; + } + $r = q("SELECT distinct(`resource-id`) FROM `photo` WHERE 1 group by `id`"); + if (dbm::is_result($r)) { foreach ($r as $rr) { $guid = get_guid(); - q("update `photo` set `guid` = '%s' where `resource-id` = '%s'", + q("UPDATE `photo` SET `guid` = '%s' WHERE `resource-id` = '%s'", dbesc($guid), dbesc($rr['resource-id']) ); @@ -736,11 +743,13 @@ function update_1087() { $x = q("SELECT max(`created`) AS `cdate` FROM `item` WHERE `parent` = %d LIMIT 1", intval($rr['id']) ); - if(count($x)) + + if (dbm::is_result($x)) { q("UPDATE `item` SET `commented` = '%s' WHERE `id` = %d", dbesc($x[0]['cdate']), intval($rr['id']) ); + } } } } @@ -849,14 +858,14 @@ function update_1099() { function update_1100() { q("ALTER TABLE `contact` ADD `nurl` CHAR( 255 ) NOT NULL AFTER `url` "); - q("alter table contact add index (`nurl`) "); + q("ALTER TABLE `contact` ADD INDEX (`nurl`) "); require_once('include/text.php'); - $r = q("select id, url from contact where url != '' and nurl = '' "); + $r = q("SELECT `id`, `url` FROM `contact` WHERE `url` != '' AND `nurl` = '' "); if (dbm::is_result($r)) { foreach ($r as $rr) { - q("update contact set nurl = '%s' where id = %d", + q("UPDATE `contact` SET `nurl` = '%s' WHERE `id` = %d", dbesc(normalise_link($rr['url'])), intval($rr['id']) ); @@ -886,6 +895,7 @@ function update_1102() { function update_1103() { +/// @TODO Comented out: // q("ALTER TABLE `item` ADD INDEX ( `wall` ) "); q("ALTER TABLE `item` ADD FULLTEXT ( `tag` ) "); q("ALTER TABLE `contact` ADD INDEX ( `pending` ) "); @@ -1031,9 +1041,11 @@ function update_1120() { $r = q("describe item"); if (dbm::is_result($r)) { - foreach($r as $rr) - if($rr['Field'] == 'spam') + foreach($r as $rr) { + if ($rr['Field'] == 'spam') { return; + } + } } q("ALTER TABLE `item` ADD `spam` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` , ADD INDEX (`spam`) "); @@ -1067,16 +1079,16 @@ function update_1121() { } function update_1122() { -q("ALTER TABLE `notify` ADD `hash` CHAR( 64 ) NOT NULL AFTER `id` , + q("ALTER TABLE `notify` ADD `hash` CHAR( 64 ) NOT NULL AFTER `id` , ADD INDEX ( `hash` ) "); } function update_1123() { -set_config('system','allowed_themes','dispy,quattro,testbubble,vier,darkbubble,darkzero,duepuntozero,greenzero,purplezero,quattro-green,slackr'); + set_config('system','allowed_themes','dispy,quattro,testbubble,vier,darkbubble,darkzero,duepuntozero,greenzero,purplezero,quattro-green,slackr'); } function update_1124() { -q("alter table item add index (`author-name`) "); + q("ALTER TABLE `item` ADD INDEX (`author-name`) "); } function update_1125() { @@ -1112,7 +1124,7 @@ function update_1127() { function update_1128() { - q("alter table spam add `date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `term` "); + q("ALTER TABLE `spam` ADD `date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `term` "); } function update_1129() { @@ -1138,9 +1150,9 @@ INDEX ( `username` ) } function update_1133() { -q("ALTER TABLE `user` ADD `unkmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocktags` , ADD INDEX ( `unkmail` ) "); -q("ALTER TABLE `user` ADD `cntunkmail` INT NOT NULL DEFAULT '10' AFTER `unkmail` , ADD INDEX ( `cntunkmail` ) "); -q("ALTER TABLE `mail` ADD `unknown` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `replied` , ADD INDEX ( `unknown` ) "); + q("ALTER TABLE `user` ADD `unkmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocktags` , ADD INDEX ( `unkmail` ) "); + q("ALTER TABLE `user` ADD `cntunkmail` INT NOT NULL DEFAULT '10' AFTER `unkmail` , ADD INDEX ( `cntunkmail` ) "); + q("ALTER TABLE `mail` ADD `unknown` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `replied` , ADD INDEX ( `unknown` ) "); } function update_1134() { @@ -1167,38 +1179,38 @@ function update_1136() { // order in reverse so that we save the newest entry - $r = q("select * from config where 1 order by id desc"); + $r = q("SELECT * FROM `config` WHERE 1 ORDER BY `id` DESC"); if (dbm::is_result($r)) { foreach ($r as $rr) { $found = false; - foreach($arr as $x) { - if($x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { + foreach ($arr as $x) { + if ($x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { $found = true; - q("delete from config where id = %d", + q("DELETE FROM `config` WHERE `id` = %d", intval($rr['id']) ); } } - if(! $found) { + if (! $found) { $arr[] = $rr; } } } $arr = array(); - $r = q("select * from pconfig where 1 order by id desc"); + $r = q("SELECT * FROM `pconfig` WHERE 1 ORDER BY `id` DESC"); if (dbm::is_result($r)) { foreach ($r as $rr) { $found = false; - foreach($arr as $x) { - if($x['uid'] == $rr['uid'] && $x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { + foreach ($arr as $x) { + if ($x['uid'] == $rr['uid'] && $x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { $found = true; - q("delete from pconfig where id = %d", + q("DELETE FROM `pconfig` WHERE `id` = %d", intval($rr['id']) ); } } - if(! $found) { + if (! $found) { $arr[] = $rr; } } @@ -1210,102 +1222,138 @@ function update_1136() { function update_1137() { - q("alter table item_id DROP `face` , DROP `dspr` , DROP `twit` , DROP `stat` "); - q("ALTER TABLE `item_id` ADD `sid` CHAR( 255 ) NOT NULL AFTER `uid` , ADD `service` CHAR( 255 ) NOT NULL AFTER `sid` , add index (`sid`), add index ( `service`) "); + q("ALTER TABLE `item_id` DROP `face` , DROP `dspr` , DROP `twit` , DROP `stat` "); + q("ALTER TABLE `item_id` ADD `sid` CHAR( 255 ) NOT NULL AFTER `uid` , ADD `service` CHAR( 255 ) NOT NULL AFTER `sid` , ADD INDEX (`sid`), ADD INDEX ( `service`) "); } function update_1138() { - q("alter table contact add archive tinyint(1) not null default '0' after hidden, add index (archive)"); + q("ALTER TABLE `contact` ADD `archive` TINYINT(1) NOT NULL DEFAULT '0' AFTER `hidden`, ADD INDEX (`archive`)"); } function update_1139() { - $r = q("alter table user add account_removed tinyint(1) not null default '0' after expire, add index(account_removed) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE `user` ADD `account_removed` TINYINT(1) NOT NULL DEFAULT '0' AFTER `expire`, ADD INDEX(`account_removed`)"); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1140() { - $r = q("alter table addon add hidden tinyint(1) not null default '0' after installed, add index(hidden) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE `addon` ADD `hidden` TINYINT(1) NOT NULL DEFAULT '0' AFTER `installed`, ADD INDEX(`hidden`) "); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1141() { - $r = q("alter table glink add zcid int(11) not null after gcid, add index(zcid) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE `glink` ADD `zcid` INT(11) NOT NULL AFTER `gcid`, ADD INDEX(`zcid`) "); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1142() { - $r = q("alter table user add service_class char(32) not null after expire_notification_sent, add index(service_class) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE `user` ADD `service_class` CHAR(32) NOT NULL AFTER `expire_notification_sent`, ADD INDEX(`service_class`) "); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1143() { - $r = q("alter table user add def_gid int(11) not null default '0' after service_class"); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE `user` ADD `def_gid` INT(11) NOT NULL DEFAULT '0' AFTER `service_class`"); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1144() { - $r = q("alter table contact add prv tinyint(1) not null default '0' after forum"); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE `contact` ADD `prv` TINYINT(1) NOT NULL DEFAULT '0' AFTER `forum`"); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1145() { - $r = q("alter table profile add howlong datetime not null default '0000-00-00 00:00:00' after `with`"); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE `profile` ADD `howlong` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `with`"); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1146() { - $r = q("alter table profile add hometown char(255) not null after `country-name`, add index ( `hometown` ) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + $r = q("ALTER TABLE profile add hometown char(255) not null after `country-name`, add index ( `hometown` ) "); + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1147() { $r1 = q("ALTER TABLE `sign` ALTER `iid` SET DEFAULT '0'"); $r2 = q("ALTER TABLE `sign` ADD `retract_iid` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `iid`"); $r3 = q("ALTER TABLE `sign` ADD INDEX ( `retract_iid` )"); - if((! $r1) || (! $r2) || (! $r3)) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; + + if ($r1 && $r2 && $r3) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1148() { $r = q("ALTER TABLE photo ADD type CHAR(128) NOT NULL DEFAULT 'image/jpeg' AFTER filename"); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1149() { $r1 = q("ALTER TABLE profile ADD likes text NOT NULL after prv_keywords"); $r2 = q("ALTER TABLE profile ADD dislikes text NOT NULL after likes"); - if (! ($r1 && $r2)) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + + if ($r1 && $r2) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1150() { $r = q("ALTER TABLE event ADD summary text NOT NULL after finish, add index ( uid ), add index ( cid ), add index ( uri ), add index ( `start` ), add index ( finish ), add index ( `type` ), add index ( adjust ) "); - if(! $r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } @@ -1315,9 +1363,12 @@ function update_1151() { name CHAR( 128 ) NOT NULL , locked TINYINT( 1 ) NOT NULL DEFAULT '0' ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1152() { @@ -1333,23 +1384,32 @@ function update_1152() { KEY `type` ( `type` ), KEY `term` ( `term` ) ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1153() { $r = q("ALTER TABLE `hook` ADD `priority` INT(11) UNSIGNED NOT NULL DEFAULT '0'"); - if(!$r) return UPDATE_FAILED; - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1154() { $r = q("ALTER TABLE `event` ADD `ignore` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `adjust` , ADD INDEX ( `ignore` )"); - if(!$r) return UPDATE_FAILED; - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1155() { @@ -1357,8 +1417,9 @@ function update_1155() { $r2 = q("ALTER TABLE `item_id` ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST"); $r3 = q("ALTER TABLE `item_id` ADD INDEX ( `iid` ) "); - if($r1 && $r2 && $r3) + if ($r1 && $r2 && $r3) { return UPDATE_SUCCESS; + } return UPDATE_FAILED; } @@ -1367,12 +1428,15 @@ function update_1156() { $r = q("ALTER TABLE `photo` ADD `datasize` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `width` , ADD INDEX ( `datasize` ) "); - if(!$r) return UPDATE_FAILED; - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1157() { - $r = q("CREATE TABLE IF NOT EXISTS `dsprphotoq` ( + $r = q("CREATE TABLE IF NOT EXISTS `dsprphotoq` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `uid` int(11) NOT NULL, `msg` mediumtext NOT NULL, @@ -1381,8 +1445,11 @@ function update_1157() { ) ENGINE=MyISAM DEFAULT CHARSET=utf8" ); - if($r) + if ($r) { return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1158() { @@ -1395,8 +1462,9 @@ function update_1158() { $r = q("CREATE INDEX event_id ON item(`event-id`)"); set_config('system', 'maintenance', 0); - if($r) + if ($r) { return UPDATE_SUCCESS; + } return UPDATE_FAILED; } @@ -1407,10 +1475,11 @@ function update_1159() { ADD INDEX (`uid`), ADD INDEX (`aid`)"); - if(!$r) - return UPDATE_FAILED; + if ($r) { + return UPDATE_SUCCESS; + } - return UPDATE_SUCCESS; + return UPDATE_FAILED; } function update_1160() { @@ -1423,19 +1492,21 @@ function update_1160() { $r = q("ALTER TABLE `item` ADD `mention` TINYINT(1) NOT NULL DEFAULT '0', ADD INDEX (`mention`)"); set_config('system', 'maintenance', 0); - if(!$r) - return UPDATE_FAILED; + if ($r) { + return UPDATE_SUCCESS; + } - return UPDATE_SUCCESS; + return UPDATE_FAILED; } function update_1161() { $r = q("ALTER TABLE `pconfig` ADD INDEX (`cat`)"); - if(!$r) - return UPDATE_FAILED; + if ($r) { + return UPDATE_SUCCESS; + } - return UPDATE_SUCCESS; + return UPDATE_FAILED; } function update_1162() { @@ -1451,14 +1522,17 @@ function update_1163() { $r = q("ALTER TABLE `item` ADD `network` char(32) NOT NULL"); set_config('system', 'maintenance', 0); - if(!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1164() { set_config('system', 'maintenance', 1); + /// @TODO If one update fails, should it continue? $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '' AND `contact`.`uid` = `item`.`uid`)", NETWORK_DFRN); @@ -1511,19 +1585,21 @@ function update_1164() { function update_1165() { $r = q("CREATE TABLE IF NOT EXISTS `push_subscriber` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `uid` INT NOT NULL, - `callback_url` CHAR( 255 ) NOT NULL, - `topic` CHAR( 255 ) NOT NULL, - `nickname` CHAR( 255 ) NOT NULL, - `push` INT NOT NULL, - `last_update` DATETIME NOT NULL, - `secret` CHAR( 255 ) NOT NULL - ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - if (!$r) - return UPDATE_FAILED; + `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + `uid` INT NOT NULL, + `callback_url` CHAR( 255 ) NOT NULL, + `topic` CHAR( 255 ) NOT NULL, + `nickname` CHAR( 255 ) NOT NULL, + `push` INT NOT NULL, + `last_update` DATETIME NOT NULL, + `secret` CHAR( 255 ) NOT NULL + ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1166() { @@ -1535,26 +1611,32 @@ function update_1166() { `avatar` CHAR(255) NOT NULL, INDEX (`url`) ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1167() { $r = q("ALTER TABLE `contact` ADD `notify_new_posts` TINYINT(1) NOT NULL DEFAULT '0'"); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS; + } + + return UPDATE_FAILED; } function update_1168() { $r = q("ALTER TABLE `contact` ADD `fetch_further_information` TINYINT(1) NOT NULL DEFAULT '0'"); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; + if ($r) { + return UPDATE_SUCCESS ; + } + + return UPDATE_FAILED ; } function update_1169() { @@ -1592,8 +1674,10 @@ function update_1169() { KEY `uid_created` (`uid`,`created`), KEY `uid_commented` (`uid`,`commented`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); - if (!$r) + + if (!$r) { return UPDATE_FAILED; + } proc_run(PRIORITY_LOW, "include/threadupdate.php"); From 4adf74b06c0a96c3169c59b3cc66b4212930d3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Mon, 23 Jan 2017 10:27:05 +0100 Subject: [PATCH 09/65] more coding convention applied MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- update.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/update.php b/update.php index 242fd1454..fd6548d9a 100644 --- a/update.php +++ b/update.php @@ -1302,7 +1302,7 @@ function update_1145() { } function update_1146() { - $r = q("ALTER TABLE profile add hometown char(255) not null after `country-name`, add index ( `hometown` ) "); + $r = q("ALTER TABLE `profile` ADD `hometown` CHAR(255) NOT NULL AFTER `country-name`, ADD INDEX ( `hometown` ) "); if ($r) { return UPDATE_SUCCESS ; @@ -1324,7 +1324,7 @@ function update_1147() { } function update_1148() { - $r = q("ALTER TABLE photo ADD type CHAR(128) NOT NULL DEFAULT 'image/jpeg' AFTER filename"); + $r = q("ALTER TABLE `photo` ADD `type` CHAR(128) NOT NULL DEFAULT 'image/jpeg' AFTER `filename`"); if ($r) { return UPDATE_SUCCESS ; @@ -1335,8 +1335,8 @@ function update_1148() { function update_1149() { - $r1 = q("ALTER TABLE profile ADD likes text NOT NULL after prv_keywords"); - $r2 = q("ALTER TABLE profile ADD dislikes text NOT NULL after likes"); + $r1 = q("ALTER TABLE `profile` ADD `likes` TEXT NOT NULL AFTER `prv_keywords`"); + $r2 = q("ALTER TABLE `profile` ADD `dislikes` TEXT NOT NULL AFTER `likes`"); if ($r1 && $r2) { return UPDATE_SUCCESS; @@ -1347,7 +1347,7 @@ function update_1149() { function update_1150() { - $r = q("ALTER TABLE event ADD summary text NOT NULL after finish, add index ( uid ), add index ( cid ), add index ( uri ), add index ( `start` ), add index ( finish ), add index ( `type` ), add index ( adjust ) "); + $r = q("ALTER TABLE `event` ADD `summary` TEXT NOT NULL AFTER `finish`, ADD INDEX ( `uid` ), ADD INDEX ( `cid` ), ADD INDEX ( `uri` ), ADD INDEX ( `start` ), ADD INDEX ( `finish` ), ADD INDEX ( `type` ), ADD INDEX ( `adjust` ) "); if ($r) { return UPDATE_SUCCESS ; @@ -1358,10 +1358,10 @@ function update_1150() { function update_1151() { - $r = q("CREATE TABLE IF NOT EXISTS locks ( - id INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - name CHAR( 128 ) NOT NULL , - locked TINYINT( 1 ) NOT NULL DEFAULT '0' + $r = q("CREATE TABLE IF NOT EXISTS `locks` ( + `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , + `name` CHAR( 128 ) NOT NULL , + `locked` TINYINT( 1 ) NOT NULL DEFAULT '0' ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); if ($r) { From 92901d86269903ddab993b85bab2d6ec075630d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Mon, 23 Jan 2017 10:49:08 +0100 Subject: [PATCH 10/65] more curly braces added + dbm::is_result() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/ostatus.php | 100 +++++++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 34 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index 2c4b677a5..3e285a783 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -104,24 +104,29 @@ class ostatus { // $contact["poll"] = $value; $value = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $contact["alias"] = $value; + } $value = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $contact["name"] = $value; + } $value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $contact["nick"] = $value; + } $value = $xpath->evaluate('atom:author/poco:note/text()', $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $contact["about"] = html2bbcode($value); + } $value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $contact["location"] = $value; + } if (($contact["name"] != $r[0]["name"]) OR ($contact["nick"] != $r[0]["nick"]) OR ($contact["about"] != $r[0]["about"]) OR ($contact["alias"] != $r[0]["alias"]) OR ($contact["location"] != $r[0]["location"])) { @@ -179,8 +184,9 @@ class ostatus { */ public static function salmon_author($xml, $importer) { - if ($xml == "") + if ($xml == "") { return; + } $doc = new DOMDocument(); @$doc->loadXML($xml); @@ -217,8 +223,9 @@ class ostatus { logger("Import OStatus message", LOGGER_DEBUG); - if ($xml == "") + if ($xml == "") { return; + } //$tempfile = tempnam(get_temppath(), "import"); //file_put_contents($tempfile, $xml); @@ -238,12 +245,14 @@ class ostatus { $gub = ""; $hub_attributes = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0)->attributes; - if (is_object($hub_attributes)) - foreach($hub_attributes AS $hub_attribute) + if (is_object($hub_attributes)) { + foreach($hub_attributes AS $hub_attribute) { if ($hub_attribute->name == "href") { $hub = $hub_attribute->textContent; logger("Found hub ".$hub, LOGGER_DEBUG); } + } + } $header = array(); $header["uid"] = $importer["uid"]; @@ -257,10 +266,11 @@ class ostatus { // depending on that, the first node is different $first_child = $doc->firstChild->tagName; - if ($first_child == "feed") + if ($first_child == "feed") { $entries = $xpath->query('/atom:feed/atom:entry'); - else + } else { $entries = $xpath->query('/atom:entry'); + } $conversation = ""; $conversationlist = array(); @@ -277,16 +287,18 @@ class ostatus { $mention = false; // fetch the author - if ($first_child == "feed") + if ($first_child == "feed") { $author = self::fetchauthor($xpath, $doc->firstChild, $importer, $contact, false); - else + } else { $author = self::fetchauthor($xpath, $entry, $importer, $contact, false); + } $value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $nickname = $value; - else + } else { $nickname = $author["author-name"]; + } $item = array_merge($header, $author); @@ -295,7 +307,7 @@ class ostatus { $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", intval($importer["uid"]), dbesc($item["uri"])); - if ($r) { + if (dbm::is_result($r)) { logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG); continue; } @@ -306,8 +318,9 @@ class ostatus { if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) OR ($item["object-type"] == ACTIVITY_OBJ_EVENT)) { $item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue; $item["body"] = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue; - } elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) + } elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) { $item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue; + } $item["object"] = $xml; $item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue; @@ -352,8 +365,9 @@ class ostatus { } // http://activitystrea.ms/schema/1.0/rsvp-yes - if (!in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE))) + if (!in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE))) { logger("Unhandled verb ".$item["verb"]." ".print_r($item, true)); + } $item["created"] = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue; $item["edited"] = $xpath->query('atom:updated/text()', $entry)->item(0)->nodeValue; @@ -364,10 +378,12 @@ class ostatus { $inreplyto = $xpath->query('thr:in-reply-to', $entry); if (is_object($inreplyto->item(0))) { foreach($inreplyto->item(0)->attributes AS $attributes) { - if ($attributes->name == "ref") + if ($attributes->name == "ref") { $item["parent-uri"] = $attributes->textContent; - if ($attributes->name == "href") + } + if ($attributes->name == "href") { $related = $attributes->textContent; + } } } @@ -411,7 +427,7 @@ class ostatus { if ($attributes->name == "title") $title = $attributes->textContent; } - if (($rel != "") AND ($href != "")) + if (($rel != "") AND ($href != "")) { switch($rel) { case "alternate": $item["plink"] = $href; @@ -448,6 +464,7 @@ class ostatus { $mention = true; break; } + } } } @@ -457,12 +474,15 @@ class ostatus { $notice_info = $xpath->query('statusnet:notice_info', $entry); if ($notice_info AND ($notice_info->length > 0)) { foreach($notice_info->item(0)->attributes AS $attributes) { - if ($attributes->name == "source") + if ($attributes->name == "source") { $item["app"] = strip_tags($attributes->textContent); - if ($attributes->name == "local_id") + } + if ($attributes->name == "local_id") { $local_id = $attributes->textContent; - if ($attributes->name == "repeat_of") + } + if ($attributes->name == "repeat_of") { $repeat_of = $attributes->textContent; + } } } @@ -473,24 +493,32 @@ class ostatus { if (is_object($activityobjects)) { $orig_uri = $xpath->query("activity:object/atom:id", $activityobjects)->item(0)->nodeValue; - if (!isset($orig_uri)) + if (!isset($orig_uri)) { $orig_uri = $xpath->query('atom:id/text()', $activityobjects)->item(0)->nodeValue; + } $orig_links = $xpath->query("activity:object/atom:link[@rel='alternate']", $activityobjects); - if ($orig_links AND ($orig_links->length > 0)) - foreach($orig_links->item(0)->attributes AS $attributes) - if ($attributes->name == "href") + if ($orig_links AND ($orig_links->length > 0)) { + foreach ($orig_links->item(0)->attributes AS $attributes) { + if ($attributes->name == "href") { $orig_link = $attributes->textContent; + } + } + } - if (!isset($orig_link)) + if (!isset($orig_link)) { $orig_link = $xpath->query("atom:link[@rel='alternate']", $activityobjects)->item(0)->nodeValue; + } - if (!isset($orig_link)) + if (!isset($orig_link)) { $orig_link = self::convert_href($orig_uri); + } $orig_body = $xpath->query('activity:object/atom:content/text()', $activityobjects)->item(0)->nodeValue; - if (!isset($orig_body)) + + if (!isset($orig_body)) { $orig_body = $xpath->query('atom:content/text()', $activityobjects)->item(0)->nodeValue; + } $orig_created = $xpath->query('atom:published/text()', $activityobjects)->item(0)->nodeValue; $orig_edited = $xpath->query('atom:updated/text()', $activityobjects)->item(0)->nodeValue; @@ -511,8 +539,10 @@ class ostatus { $item["verb"] = $xpath->query('activity:verb/text()', $activityobjects)->item(0)->nodeValue; $item["object-type"] = $xpath->query('activity:object/activity:object-type/text()', $activityobjects)->item(0)->nodeValue; - if (!isset($item["object-type"])) + + if (!isset($item["object-type"])) { $item["object-type"] = $xpath->query('activity:object-type/text()', $activityobjects)->item(0)->nodeValue; + } } } @@ -540,12 +570,14 @@ class ostatus { intval($importer["uid"]), dbesc($item["parent-uri"])); } } - if ($r) { + + if (dbm::is_result($r)) { $item["type"] = 'remote-comment'; $item["gravity"] = GRAVITY_COMMENT; } - } else + } else { $item["parent-uri"] = $item["uri"]; + } $item_id = self::completion($conversation, $importer["uid"], $item, $self); From 5471dd79e89821909649b37e4f88d42f897e27a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 24 Jan 2017 17:50:49 +0100 Subject: [PATCH 11/65] added missing curly braces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/wall_upload.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mod/wall_upload.php b/mod/wall_upload.php index fa30a8ad3..b793c9e40 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -215,7 +215,7 @@ function wall_upload_post(App $a, $desktopmode = true) { $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, $defperm); - if(! $r) { + if (! $r) { $msg = t('Image upload failed.'); if ($r_json) { echo json_encode(array('error'=>$msg)); @@ -225,18 +225,20 @@ function wall_upload_post(App $a, $desktopmode = true) { killme(); } - if($width > 640 || $height > 640) { + if ($width > 640 || $height > 640) { $ph->scaleImage(640); $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1, 0, $defperm); - if ($r) + if ($r) { $smallest = 1; + } } if ($width > 320 || $height > 320) { $ph->scaleImage(320); $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2, 0, $defperm); - if ($r AND ($smallest == 0)) + if ($r AND ($smallest == 0)) { $smallest = 2; + } } $basename = basename($filename); From 108a2ccbd52942919cc4575ecaf7cdf91406d3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 24 Jan 2017 17:55:31 +0100 Subject: [PATCH 12/65] added more spaces/curly braces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- update.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/update.php b/update.php index fd6548d9a..8f581559d 100644 --- a/update.php +++ b/update.php @@ -567,7 +567,6 @@ function update_1069() { q("ALTER TABLE `fcontact` ADD `request` CHAR( 255 ) NOT NULL AFTER `photo` "); } -/// @TODO Still meeded? // mail body needs to accomodate private photos function update_1070() { @@ -596,7 +595,7 @@ function update_1074() { q("ALTER TABLE `user` ADD `hidewall` TINYINT( 1) NOT NULL DEFAULT '0' AFTER `blockwall` "); $r = q("SELECT `uid` FROM `profile` WHERE `is-default` = 1 AND `hidewall` = 1"); if (dbm::is_result($r)) { - foreach($r as $rr) + foreach ($r as $rr) q("UPDATE `user` SET `hidewall` = 1 WHERE `uid` = %d", intval($rr['uid']) ); @@ -895,7 +894,7 @@ function update_1102() { function update_1103() { -/// @TODO Comented out: +/// @TODO Commented out: // q("ALTER TABLE `item` ADD INDEX ( `wall` ) "); q("ALTER TABLE `item` ADD FULLTEXT ( `tag` ) "); q("ALTER TABLE `contact` ADD INDEX ( `pending` ) "); @@ -1041,7 +1040,7 @@ function update_1120() { $r = q("describe item"); if (dbm::is_result($r)) { - foreach($r as $rr) { + foreach ($r as $rr) { if ($rr['Field'] == 'spam') { return; } From 55e2411f07cba19b3e9c38497ff5be7e49e3412f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Tue, 24 Jan 2017 17:57:45 +0100 Subject: [PATCH 13/65] even more added MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- update.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/update.php b/update.php index 8f581559d..61410e89e 100644 --- a/update.php +++ b/update.php @@ -157,14 +157,15 @@ function update_1014() { $r = q("SELECT * FROM `contact` WHERE 1"); if (dbm::is_result($r)) { foreach ($r as $rr) { - if(stristr($rr['thumb'],'avatar')) + if (stristr($rr['thumb'],'avatar')) { q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d", dbesc(str_replace('avatar','micro',$rr['thumb'])), intval($rr['id'])); - else + } else { q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d", dbesc(str_replace('5.jpg','6.jpg',$rr['thumb'])), intval($rr['id'])); + } } } } @@ -595,10 +596,11 @@ function update_1074() { q("ALTER TABLE `user` ADD `hidewall` TINYINT( 1) NOT NULL DEFAULT '0' AFTER `blockwall` "); $r = q("SELECT `uid` FROM `profile` WHERE `is-default` = 1 AND `hidewall` = 1"); if (dbm::is_result($r)) { - foreach ($r as $rr) + foreach ($r as $rr) { q("UPDATE `user` SET `hidewall` = 1 WHERE `uid` = %d", intval($rr['uid']) ); + } } q("ALTER TABLE `profile` DROP `hidewall`"); } @@ -1782,19 +1784,22 @@ function update_1190() { $key = $rr['k']; $value = $rr['v']; - if ($key === 'randomise') + if ($key === 'randomise') { del_pconfig($uid,$family,$key); + } if ($key === 'show_on_profile') { - if ($value) + if ($value) { set_pconfig($uid,feature,forumlist_profile,$value); + } del_pconfig($uid,$family,$key); } if ($key === 'show_on_network') { - if ($value) + if ($value) { set_pconfig($uid,feature,forumlist_widget,$value); + } del_pconfig($uid,$family,$key); } From 3849e7c9ff8d3cbe097714e4811ed4c92a780f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Wed, 25 Jan 2017 15:59:27 +0100 Subject: [PATCH 14/65] added more curly braces + a bit more usage of dbm::is_result() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/dfrn.php | 235 +++++++++++++++++++++++++++---------------- mod/dfrn_confirm.php | 13 +-- mod/profiles.php | 5 +- update.php | 2 +- util/po2php.php | 2 +- 5 files changed, 160 insertions(+), 97 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 39372aef1..cd1fef904 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -637,18 +637,24 @@ class dfrn { $entry = $doc->createElement($element); $r = parse_xml_string($activity, false); - if(!$r) + if (!$r) { return false; - if($r->type) + } + if ($r->type) { xml::add_element($doc, $entry, "activity:object-type", $r->type); - if($r->id) + } + if ($r->id) { xml::add_element($doc, $entry, "id", $r->id); - if($r->title) + } + if ($r->title) { xml::add_element($doc, $entry, "title", $r->title); - if($r->link) { - if(substr($r->link,0,1) == '<') { - if(strstr($r->link,'&') && (! strstr($r->link,'&'))) + } + + if ($r->link) { + if (substr($r->link,0,1) == '<') { + if (strstr($r->link,'&') && (! strstr($r->link,'&'))) { $r->link = str_replace('&','&', $r->link); + } $r->link = preg_replace('/\/','',$r->link); @@ -657,8 +663,9 @@ class dfrn { if (is_object($data)) { foreach ($data->link AS $link) { $attributes = array(); - foreach ($link->attributes() AS $parameter => $value) + foreach ($link->attributes() AS $parameter => $value) { $attributes[$parameter] = $value; + } xml::add_element($doc, $entry, "link", "", $attributes); } } @@ -667,8 +674,9 @@ class dfrn { xml::add_element($doc, $entry, "link", "", $attributes); } } - if($r->content) + if ($r->content) { xml::add_element($doc, $entry, "content", bbcode($r->content), array("type" => "html")); + } return $entry; } @@ -687,20 +695,22 @@ class dfrn { */ private static function get_attachment($doc, $root, $item) { $arr = explode('[/attach],',$item['attach']); - if(count($arr)) { - foreach($arr as $r) { + if (count($arr)) { + foreach ($arr as $r) { $matches = false; $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches); - if($cnt) { + if ($cnt) { $attributes = array("rel" => "enclosure", "href" => $matches[1], "type" => $matches[3]); - if(intval($matches[2])) + if (intval($matches[2])) { $attributes["length"] = intval($matches[2]); + } - if(trim($matches[4]) != "") + if (trim($matches[4]) != "") { $attributes["title"] = trim($matches[4]); + } xml::add_element($doc, $root, "link", "", $attributes); } @@ -724,20 +734,22 @@ class dfrn { $mentioned = array(); - if(!$item['parent']) + if (!$item['parent']) { return; + } - if($item['deleted']) { + if ($item['deleted']) { $attributes = array("ref" => $item['uri'], "when" => datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)); return xml::create_element($doc, "at:deleted-entry", "", $attributes); } $entry = $doc->createElement("entry"); - if($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) + if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) { $body = fix_private_photos($item['body'],$owner['uid'],$item,$cid); - else + } else { $body = $item['body']; + } // Remove the abstract element. It is only locally important. $body = remove_abstract($body); @@ -745,8 +757,9 @@ class dfrn { if ($type == 'html') { $htmlbody = $body; - if ($item['title'] != "") + if ($item['title'] != "") { $htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody; + } $htmlbody = bbcode($htmlbody, false, false, 7); } @@ -757,7 +770,7 @@ class dfrn { $dfrnowner = self::add_entry_author($doc, "dfrn:owner", $item["owner-link"], $item); $entry->appendChild($dfrnowner); - if(($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) { + if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) { $parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"])); $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']); $attributes = array("ref" => $parent_item, "type" => "text/html", @@ -785,26 +798,33 @@ class dfrn { // "comment-allow" is some old fashioned stuff for old Friendica versions. // It is included in the rewritten code for completeness - if ($comment) + if ($comment) { xml::add_element($doc, $entry, "dfrn:comment-allow", intval($item['last-child'])); + } - if($item['location']) + if ($item['location']) { xml::add_element($doc, $entry, "dfrn:location", $item['location']); + } - if($item['coord']) + if ($item['coord']) { xml::add_element($doc, $entry, "georss:point", $item['coord']); + } - if(($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) + if (($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) { xml::add_element($doc, $entry, "dfrn:private", (($item['private']) ? $item['private'] : 1)); + } - if($item['extid']) + if ($item['extid']) { xml::add_element($doc, $entry, "dfrn:extid", $item['extid']); + } - if($item['bookmark']) + if ($item['bookmark']) { xml::add_element($doc, $entry, "dfrn:bookmark", "true"); + } - if($item['app']) + if ($item['app']) { xml::add_element($doc, $entry, "statusnet:notice_info", "", array("local_id" => $item['id'], "source" => $item['app'])); + } xml::add_element($doc, $entry, "dfrn:diaspora_guid", $item["guid"]); @@ -817,46 +837,56 @@ class dfrn { xml::add_element($doc, $entry, "activity:verb", construct_verb($item)); - if ($item['object-type'] != "") + if ($item['object-type'] != "") { xml::add_element($doc, $entry, "activity:object-type", $item['object-type']); - elseif ($item['id'] == $item['parent']) + } elseif ($item['id'] == $item['parent']) { xml::add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE); - else + } else { xml::add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_COMMENT); + } $actobj = self::create_activity($doc, "activity:object", $item['object']); - if ($actobj) + if ($actobj) { $entry->appendChild($actobj); + } $actarg = self::create_activity($doc, "activity:target", $item['target']); - if ($actarg) + if ($actarg) { $entry->appendChild($actarg); + } $tags = item_getfeedtags($item); - if(count($tags)) { - foreach($tags as $t) - if (($type != 'html') OR ($t[0] != "@")) + if( count($tags)) { + foreach ($tags as $t) { + if (($type != 'html') OR ($t[0] != "@")) { xml::add_element($doc, $entry, "category", "", array("scheme" => "X-DFRN:".$t[0].":".$t[1], "term" => $t[2])); + } + } } - if(count($tags)) - foreach($tags as $t) - if ($t[0] == "@") + if (count($tags)) { + foreach($tags as $t) { + if ($t[0] == "@") { $mentioned[$t[1]] = $t[1]; + } + } + } foreach ($mentioned AS $mention) { $r = q("SELECT `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'", intval($owner["uid"]), dbesc(normalise_link($mention))); - if ($r[0]["forum"] OR $r[0]["prv"]) + + if ($r[0]["forum"] OR $r[0]["prv"]) { xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_GROUP, "href" => $mention)); - else + } else { xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_PERSON, "href" => $mention)); + } } self::get_attachment($doc, $entry, $item); @@ -880,16 +910,20 @@ class dfrn { $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']); - if($contact['duplex'] && $contact['dfrn-id']) + if ($contact['duplex'] && $contact['dfrn-id']) { $idtosend = '0:' . $orig_id; - if($contact['duplex'] && $contact['issued-id']) + } + if ($contact['duplex'] && $contact['issued-id']) { $idtosend = '1:' . $orig_id; - + } $rino = get_config('system','rino_encrypt'); $rino = intval($rino); + // use RINO1 if mcrypt isn't installed and RINO2 was selected - if ($rino==2 and !function_exists('mcrypt_create_iv')) $rino=1; + if ($rino==2 and !function_exists('mcrypt_create_iv')) { + $rino=1; + } logger("Local rino version: ". $rino, LOGGER_DEBUG); @@ -928,10 +962,11 @@ class dfrn { logger('dfrn_deliver: ' . $xml, LOGGER_DATA); - if(! $xml) + if (! $xml) { return 3; + } - if(strpos($xml,'status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) + if ((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) { return (($res->status) ? $res->status : 3); + } $postvars = array(); $sent_dfrn_id = hex2bin((string) $res->dfrn_id); @@ -952,13 +988,14 @@ class dfrn { logger("Remote rino version: ".$rino_remote_version." for ".$contact["url"], LOGGER_DEBUG); - if($owner['page-flags'] == PAGE_PRVGROUP) + if ($owner['page-flags'] == PAGE_PRVGROUP) { $page = 2; + } $final_dfrn_id = ''; - if($perm) { - if((($perm == 'rw') && (! intval($contact['writable']))) + if ($perm) { + if ((($perm == 'rw') && (! intval($contact['writable']))) || (($perm == 'r') && (intval($contact['writable'])))) { q("update contact set writable = %d where id = %d", intval(($perm == 'rw') ? 1 : 0), @@ -968,7 +1005,7 @@ class dfrn { } } - if(($contact['duplex'] && strlen($contact['pubkey'])) + if (($contact['duplex'] && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey'])) || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) { openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']); @@ -980,10 +1017,11 @@ class dfrn { $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.')); - if(strpos($final_dfrn_id,':') == 1) + if (strpos($final_dfrn_id,':') == 1) { $final_dfrn_id = substr($final_dfrn_id,2); + } - if($final_dfrn_id != $orig_id) { + if ($final_dfrn_id != $orig_id) { logger('dfrn_deliver: wrong dfrn_id.'); // did not decode properly - cannot trust this site return 3; @@ -991,11 +1029,12 @@ class dfrn { $postvars['dfrn_id'] = $idtosend; $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; - if($dissolve) + if ($dissolve) { $postvars['dissolve'] = '1'; + } - if((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) { + if ((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) { $postvars['data'] = $atom; $postvars['perm'] = 'rw'; } else { @@ -1005,11 +1044,12 @@ class dfrn { $postvars['ssl_policy'] = $ssl_policy; - if($page) + if ($page) { $postvars['page'] = $page; + } - if($rino>0 && $rino_remote_version>0 && (! $dissolve)) { + if ($rino>0 && $rino_remote_version>0 && (! $dissolve)) { logger('rino version: '. $rino_remote_version); switch($rino_remote_version) { @@ -1047,23 +1087,25 @@ class dfrn { $postvars['rino'] = $rino_remote_version; $postvars['data'] = bin2hex($data); - #logger('rino: sent key = ' . $key, LOGGER_DEBUG); + //logger('rino: sent key = ' . $key, LOGGER_DEBUG); - if($dfrn_version >= 2.1) { - if(($contact['duplex'] && strlen($contact['pubkey'])) + if ($dfrn_version >= 2.1) { + if (($contact['duplex'] && strlen($contact['pubkey'])) { || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey'])) || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']); - else + } else { openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']); + } } else { - if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) + if (($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) { openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']); - else + } else { openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']); + } } @@ -1088,13 +1130,13 @@ class dfrn { return -10; } - if(strpos($xml,'attributes AS $attributes) { - if ($attributes->name == "href") + if ($attributes->name == "href") { $href = $attributes->textContent; - if ($attributes->name == "width") + } + if ($attributes->name == "width") { $width = $attributes->textContent; - if ($attributes->name == "updated") + } + if ($attributes->name == "updated") { $contact["avatar-date"] = $attributes->textContent; + } } - if (($width > 0) AND ($href != "")) + if (($width > 0) AND ($href != "")) { $avatarlist[$width] = $href; + } } if (count($avatarlist) > 0) { krsort($avatarlist); @@ -1208,40 +1255,50 @@ class dfrn { // When was the last change to name or uri? $name_element = $xpath->query($element."/atom:name", $context)->item(0); - foreach($name_element->attributes AS $attributes) - if ($attributes->name == "updated") + foreach ($name_element->attributes AS $attributes) { + if ($attributes->name == "updated") { $poco["name-date"] = $attributes->textContent; + } + } $link_element = $xpath->query($element."/atom:link", $context)->item(0); - foreach($link_element->attributes AS $attributes) - if ($attributes->name == "updated") + foreach ($link_element->attributes AS $attributes) { + if ($attributes->name == "updated") { $poco["uri-date"] = $attributes->textContent; + } + } // Update contact data $value = $xpath->evaluate($element."/dfrn:handle/text()", $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $poco["addr"] = $value; + } $value = $xpath->evaluate($element."/poco:displayName/text()", $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $poco["name"] = $value; + } $value = $xpath->evaluate($element."/poco:preferredUsername/text()", $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $poco["nick"] = $value; + } $value = $xpath->evaluate($element."/poco:note/text()", $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $poco["about"] = $value; + } $value = $xpath->evaluate($element."/poco:address/poco:formatted/text()", $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $poco["location"] = $value; + } /// @todo Only search for elements with "poco:type" = "xmpp" $value = $xpath->evaluate($element."/poco:ims/poco:value/text()", $context)->item(0)->nodeValue; - if ($value != "") + if ($value != "") { $poco["xmpp"] = $value; + } /// @todo Add support for the following fields that we don't support by now in the contact table: /// - poco:utcOffset @@ -1257,17 +1314,20 @@ class dfrn { // If the contact isn't searchable then set the contact to "hidden". // Problem: This can be manually overridden by the user. - if ($hide) + if ($hide) { $contact["hidden"] = true; + } // Save the keywords into the contact table $tags = array(); $tagelements = $xpath->evaluate($element."/poco:tags/text()", $context); - foreach($tagelements AS $tag) + foreach ($tagelements AS $tag) { $tags[$tag->nodeValue] = $tag->nodeValue; + } - if (count($tags)) + if (count($tags)) { $poco["keywords"] = implode(", ", $tags); + } // "dfrn:birthday" contains the birthday converted to UTC $old_bdyear = $contact["bdyear"]; @@ -1297,13 +1357,15 @@ class dfrn { $contact = array_merge($contact, $poco); - if ($old_bdyear != $contact["bdyear"]) + if ($old_bdyear != $contact["bdyear"]) { self::birthday_event($contact, $birthday); + } // Get all field names $fields = array(); - foreach ($r[0] AS $field => $data) + foreach ($r[0] AS $field => $data) { $fields[$field] = $data; + } unset($fields["id"]); unset($fields["uid"]); @@ -1368,8 +1430,9 @@ class dfrn { * @return string XML string */ private static function transform_activity($xpath, $activity, $element) { - if (!is_object($activity)) + if (!is_object($activity)) { return ""; + } $obj_doc = new DOMDocument("1.0", "utf-8"); $obj_doc->formatOutput = true; diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index e2ce80627..7e14610e3 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -586,17 +586,18 @@ function dfrn_confirm_post(App $a, $handsfree = null) { dbesc($decrypted_source_url), intval($local_uid) ); - if(! count($ret)) { - if(strstr($decrypted_source_url,'http:')) + if (!dbm::is_result($ret)) { + if (strstr($decrypted_source_url,'http:')) { $newurl = str_replace('http:','https:',$decrypted_source_url); - else + } else { $newurl = str_replace('https:','http:',$decrypted_source_url); + } $ret = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1", dbesc($newurl), intval($local_uid) ); - if(! count($ret)) { + if (!dbm::is_result($ret)) { // this is either a bogus confirmation (?) or we deleted the original introduction. $message = t('Contact record was not found for you on our site.'); xml_status(3,$message); @@ -611,7 +612,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) { $foreign_pubkey = $ret[0]['site-pubkey']; $dfrn_record = $ret[0]['id']; - if(! $foreign_pubkey) { + if (! $foreign_pubkey) { $message = sprintf( t('Site public key not available in contact record for URL %s.'), $newurl); xml_status(3,$message); } @@ -619,7 +620,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) { $decrypted_dfrn_id = ""; openssl_public_decrypt($dfrn_id,$decrypted_dfrn_id,$foreign_pubkey); - if(strlen($aes_key)) { + if (strlen($aes_key)) { $decrypted_aes_key = ""; openssl_private_decrypt($aes_key,$decrypted_aes_key,$my_prvkey); $dfrn_pubkey = openssl_decrypt($public_key,'AES-256-CBC',$decrypted_aes_key); diff --git a/mod/profiles.php b/mod/profiles.php index e359e9efb..282217208 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -264,13 +264,12 @@ function profiles_post(App $a) { } else { $newname = $lookup; -/* if(strstr($lookup,' ')) { +/* if (strstr($lookup,' ')) { $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", dbesc($newname), intval(local_user()) ); - } - else { + } else { $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1", dbesc($lookup), intval(local_user()) diff --git a/update.php b/update.php index 61410e89e..bc0e17b8b 100644 --- a/update.php +++ b/update.php @@ -311,7 +311,7 @@ function update_1031() { $r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' "); if (dbm::is_result($r)) { foreach ($r as $rr) { - if(strstr($rr['object'],'type="http')) { + if (strstr($rr['object'],'type="http')) { q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d", dbesc(str_replace('type="http','href="http',$rr['object'])), intval($rr['id']) diff --git a/util/po2php.php b/util/po2php.php index 30d77342b..5d3429796 100644 --- a/util/po2php.php +++ b/util/po2php.php @@ -12,7 +12,7 @@ function po2php_run(&$argv, &$argc) { $pofile = $argv[1]; $outfile = dirname($pofile)."/strings.php"; - if(strstr($outfile,'util')) + if (strstr($outfile,'util')) $lang = 'en'; else $lang = str_replace('-','_',basename(dirname($pofile))); From 6a171a96aa818acf38262a866b6ce2f24140ae53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Wed, 25 Jan 2017 16:02:02 +0100 Subject: [PATCH 15/65] Opps ... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/dfrn.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index cd1fef904..301735751 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -1091,9 +1091,9 @@ class dfrn { if ($dfrn_version >= 2.1) { - if (($contact['duplex'] && strlen($contact['pubkey'])) { + if (($contact['duplex'] && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey'])) - || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) + || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) { openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']); } else { From c6ef84a964839a41c03ba27afff7ce82da23be48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 09:38:52 +0100 Subject: [PATCH 16/65] Continued: - added missing space/curly braces - added TODOs for later adding a lot type-hints, without these (and they are long time around in PHP) anything can be handled over to the method/function. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/dfrn.php | 435 ++++++++++++++++++++++++++++++----------------- 1 file changed, 281 insertions(+), 154 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 301735751..0c88d22c4 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -41,6 +41,7 @@ class dfrn { * @param array $owner Owner record * * @return string DFRN entries + * @todo Add type-hints */ public static function entries($items,$owner) { @@ -49,10 +50,11 @@ class dfrn { $root = self::add_header($doc, $owner, "dfrn:owner", "", false); - if(! count($items)) + if (! count($items)) { return trim($doc->saveXML()); + } - foreach($items as $item) { + foreach ($items as $item) { $entry = self::entry($doc, "text", $item, $owner, $item["entry:comment-allow"], $item["entry:cid"]); $root->appendChild($entry); } @@ -82,14 +84,17 @@ class dfrn { $starred = false; // not yet implemented, possible security issues $converse = false; - if($public_feed && $a->argc > 2) { - for($x = 2; $x < $a->argc; $x++) { - if($a->argv[$x] == 'converse') + if ($public_feed && $a->argc > 2) { + for ($x = 2; $x < $a->argc; $x++) { + if ($a->argv[$x] == 'converse') { $converse = true; - if($a->argv[$x] == 'starred') + } + if ($a->argv[$x] == 'starred') { $starred = true; - if($a->argv[$x] == 'category' && $a->argc > ($x + 1) && strlen($a->argv[$x+1])) + } + if ($a->argv[$x] == 'category' && $a->argc > ($x + 1) && strlen($a->argv[$x+1])) { $category = $a->argv[$x+1]; + } } } @@ -115,7 +120,7 @@ class dfrn { $sql_post_table = ""; - if(! $public_feed) { + if (! $public_feed) { $sql_extra = ''; switch($direction) { @@ -148,12 +153,13 @@ class dfrn { require_once('include/security.php'); $groups = init_groups_visitor($contact['id']); - if(count($groups)) { - for($x = 0; $x < count($groups); $x ++) + if (count($groups)) { + for ($x = 0; $x < count($groups); $x ++) $groups[$x] = '<' . intval($groups[$x]) . '>' ; $gs = implode('|', $groups); - } else + } else { $gs = '<<>>' ; // Impossible to match + } $sql_extra = sprintf(" AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) @@ -168,23 +174,26 @@ class dfrn { ); } - if($public_feed) + if ($public_feed) { $sort = 'DESC'; - else + } else { $sort = 'ASC'; + } - if(! strlen($last_update)) + if (! strlen($last_update)) { $last_update = 'now -30 days'; + } - if(isset($category)) { + if (isset($category)) { $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", dbesc(protect_sprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($owner_id)); //$sql_extra .= file_tag_file_query('item',$category,'category'); } - if($public_feed) { - if(! $converse) + if ($public_feed) { + if (! $converse) { $sql_extra .= " AND `contact`.`self` = 1 "; + } } $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s'); @@ -207,6 +216,11 @@ class dfrn { dbesc($sort) ); + if (!dbm::is_result($r)) { + /// @TODO Some logging? + killme(); + } + // Will check further below if this actually returned results. // We will provide an empty feed if that is the case. @@ -217,13 +231,15 @@ class dfrn { $alternatelink = $owner['url']; - if(isset($category)) + if (isset($category)) { $alternatelink .= "/category/".$category; + } - if ($public_feed) + if ($public_feed) { $author = "dfrn:owner"; - else + } else { $author = "author"; + } $root = self::add_header($doc, $owner, $author, $alternatelink, true); @@ -238,21 +254,24 @@ class dfrn { return $atom; } - foreach($items as $item) { + foreach ($items as $item) { // prevent private email from leaking. - if($item['network'] == NETWORK_MAIL) + if ($item['network'] == NETWORK_MAIL) { continue; + } // public feeds get html, our own nodes use bbcode - if($public_feed) { + if ($public_feed) { $type = 'html'; // catch any email that's in a public conversation and make sure it doesn't leak - if($item['private']) + if ($item['private']) { continue; - } else + } + } else { $type = 'text'; + } $entry = self::entry($doc, $type, $item, $owner, true); $root->appendChild($entry); @@ -273,6 +292,7 @@ class dfrn { * @param array $owner Owner record * * @return string DFRN mail + * @todo Add type-hints */ public static function mail($item, $owner) { $doc = new DOMDocument('1.0', 'utf-8'); @@ -307,6 +327,7 @@ class dfrn { * @param array $owner Owner record * * @return string DFRN suggestions + * @todo Add type-hints */ public static function fsuggest($item, $owner) { $doc = new DOMDocument('1.0', 'utf-8'); @@ -334,12 +355,13 @@ class dfrn { * @param int $uid User ID * * @return string DFRN relocations + * @todo Add type-hints */ public static function relocate($owner, $uid) { /* get site pubkey. this could be a new installation with no site keys*/ $pubkey = get_config('system','site_pubkey'); - if(! $pubkey) { + if (! $pubkey) { $res = new_keypair(1024); set_config('system','site_prvkey', $res['prvkey']); set_config('system','site_pubkey', $res['pubkey']); @@ -350,8 +372,9 @@ class dfrn { $photos = array(); $ext = Photo::supportedTypes(); - foreach($rp as $p) + foreach ($rp as $p) { $photos[$p['scale']] = app::get_baseurl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']]; + } unset($rp, $ext); @@ -390,11 +413,13 @@ class dfrn { * @param bool $public Is it a header for public posts? * * @return object XML root object + * @todo Add type-hints */ private static function add_header($doc, $owner, $authorelement, $alternatelink = "", $public = false) { - if ($alternatelink == "") + if ($alternatelink == "") { $alternatelink = $owner['url']; + } $root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed'); $doc->appendChild($root); @@ -437,8 +462,9 @@ class dfrn { } // For backward compatibility we keep this element - if ($owner['page-flags'] == PAGE_COMMUNITY) + if ($owner['page-flags'] == PAGE_COMMUNITY) { xml::add_element($doc, $root, "dfrn:community", 1); + } // The former element is replaced by this one xml::add_element($doc, $root, "dfrn:account_type", $owner["account-type"]); @@ -461,6 +487,7 @@ class dfrn { * @param string $authorelement Element name for the author * * @return object XML author object + * @todo Add type-hints */ private static function add_author($doc, $owner, $authorelement, $public) { @@ -468,10 +495,11 @@ class dfrn { $r = q("SELECT `id` FROM `profile` INNER JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE (`hidewall` OR NOT `net-publish`) AND `user`.`uid` = %d", intval($owner['uid'])); - if ($r) + if (dbm::is_result($r)) { $hidewall = true; - else + } else { $hidewall = false; + } $author = $doc->createElement($authorelement); @@ -479,10 +507,11 @@ class dfrn { $uridate = datetime_convert('UTC', 'UTC', $owner['uri-date'].'+00:00', ATOM_TIME); $picdate = datetime_convert('UTC', 'UTC', $owner['avatar-date'].'+00:00', ATOM_TIME); - if (!$public OR !$hidewall) + $attributes = array(); + + if (!$public OR !$hidewall) { $attributes = array("dfrn:updated" => $namdate); - else - $attributes = array(); + } xml::add_element($doc, $author, "name", $owner["name"], $attributes); xml::add_element($doc, $author, "uri", app::get_baseurl().'/profile/'.$owner["nickname"], $attributes); @@ -491,20 +520,23 @@ class dfrn { $attributes = array("rel" => "photo", "type" => "image/jpeg", "media:width" => 175, "media:height" => 175, "href" => $owner['photo']); - if (!$public OR !$hidewall) + if (!$public OR !$hidewall) { $attributes["dfrn:updated"] = $picdate; + } xml::add_element($doc, $author, "link", "", $attributes); $attributes["rel"] = "avatar"; xml::add_element($doc, $author, "link", "", $attributes); - if ($hidewall) + if ($hidewall) { xml::add_element($doc, $author, "dfrn:hide", "true"); + } // The following fields will only be generated if the data isn't meant for a public feed - if ($public) + if ($public) { return $author; + } $birthday = feed_birthday($owner['uid'], $owner['timezone']); @@ -519,7 +551,7 @@ class dfrn { INNER JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `profile`.`is-default` AND NOT `user`.`hidewall` AND `user`.`uid` = %d", intval($owner['uid'])); - if ($r) { + if (dbm::is_result($r)) { $profile = $r[0]; xml::add_element($doc, $author, "poco:displayName", $profile["name"]); @@ -547,8 +579,9 @@ class dfrn { if (trim($profile["pub_keywords"]) != "") { $keywords = explode(",", $profile["pub_keywords"]); - foreach ($keywords AS $keyword) + foreach ($keywords AS $keyword) { xml::add_element($doc, $author, "poco:tags", trim($keyword)); + } } @@ -565,14 +598,17 @@ class dfrn { xml::add_element($doc, $element, "poco:formatted", formatted_location($profile)); - if (trim($profile["locality"]) != "") + if (trim($profile["locality"]) != "") { xml::add_element($doc, $element, "poco:locality", $profile["locality"]); + } - if (trim($profile["region"]) != "") + if (trim($profile["region"]) != "") { xml::add_element($doc, $element, "poco:region", $profile["region"]); + } - if (trim($profile["country-name"]) != "") + if (trim($profile["country-name"]) != "") { xml::add_element($doc, $element, "poco:country", $profile["country-name"]); + } $author->appendChild($element); } @@ -590,6 +626,7 @@ class dfrn { * @param array $items Item elements * * @return object XML author object + * @todo Add type-hints */ private static function add_entry_author($doc, $element, $contact_url, $item) { @@ -630,10 +667,11 @@ class dfrn { * @param string $activity activity value * * @return object XML activity object + * @todo Add type-hints */ private static function create_activity($doc, $element, $activity) { - if($activity) { + if ($activity) { $entry = $doc->createElement($element); $r = parse_xml_string($activity, false); @@ -692,6 +730,7 @@ class dfrn { * @param array $item Item element * * @return object XML attachment object + * @todo Add type-hints */ private static function get_attachment($doc, $root, $item) { $arr = explode('[/attach],',$item['attach']); @@ -729,6 +768,7 @@ class dfrn { * @param int $cid Contact ID of the recipient * * @return object XML entry object + * @todo Add type-hints */ private static function entry($doc, $type, $item, $owner, $comment = false, $cid = 0) { @@ -857,7 +897,7 @@ class dfrn { $tags = item_getfeedtags($item); - if( count($tags)) { + if (count($tags)) { foreach ($tags as $t) { if (($type != 'html') OR ($t[0] != "@")) { xml::add_element($doc, $entry, "category", "", array("scheme" => "X-DFRN:".$t[0].":".$t[1], "term" => $t[2])); @@ -866,7 +906,7 @@ class dfrn { } if (count($tags)) { - foreach($tags as $t) { + foreach ($tags as $t) { if ($t[0] == "@") { $mentioned[$t[1]] = $t[1]; } @@ -878,6 +918,11 @@ class dfrn { intval($owner["uid"]), dbesc(normalise_link($mention))); + if (!dbm::is_result($r)) { + /// @TODO Maybe some logging? + killme(); + } + if ($r[0]["forum"] OR $r[0]["prv"]) { xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_GROUP, @@ -903,6 +948,7 @@ class dfrn { * @param bool $dissolve (to be documented) * * @return int Deliver status. -1 means an error. + * @todo Add array type-hint for $owner, $contact */ public static function deliver($owner,$contact,$atom, $dissolve = false) { @@ -1152,7 +1198,7 @@ class dfrn { * * @param array $contact Contact record * @param string $birthday Birthday of the contact - * + * @todo Add array type-hint for $contact */ private static function birthday_event($contact, $birthday) { @@ -1196,6 +1242,7 @@ class dfrn { * @param bool $onlyfetch Should the data only be fetched or should it update the contact record as well * * @return Returns an array with relevant data of the author + * @todo Find good type-hints for all parameter */ private static function fetchauthor($xpath, $context, $importer, $element, $onlyfetch, $xml = "") { @@ -1213,8 +1260,9 @@ class dfrn { $author["contact-id"] = $r[0]["id"]; $author["network"] = $r[0]["network"]; } else { - if (!$onlyfetch) + if (!$onlyfetch) { logger("Contact ".$author["link"]." wasn't found for user ".$importer["uid"]." XML: ".$xml, LOGGER_DEBUG); + } $author["contact-id"] = $importer["id"]; $author["network"] = $importer["network"]; @@ -1225,10 +1273,11 @@ class dfrn { $avatarlist = array(); /// @todo check if "avatar" or "photo" would be the best field in the specification $avatars = $xpath->query($element."/atom:link[@rel='avatar']", $context); - foreach($avatars AS $avatar) { + foreach ($avatars AS $avatar) { $href = ""; $width = 0; - foreach($avatar->attributes AS $attributes) { + foreach ($avatar->attributes AS $attributes) { + /// @TODO Rewrite these similar if() to one switch if ($attributes->name == "href") { $href = $attributes->textContent; } @@ -1248,7 +1297,7 @@ class dfrn { $author["avatar"] = current($avatarlist); } - if ($r AND !$onlyfetch) { + if (dbm::is_result($r) AND !$onlyfetch) { logger("Check if contact details for contact ".$r[0]["id"]." (".$r[0]["nick"].") have to be updated.", LOGGER_DEBUG); $poco = array("url" => $contact["url"]); @@ -1376,17 +1425,19 @@ class dfrn { // Update check for this field has to be done differently $datefields = array("name-date", "uri-date"); - foreach ($datefields AS $field) + foreach ($datefields AS $field) { if (strtotime($contact[$field]) > strtotime($r[0][$field])) { logger("Difference for contact ".$contact["id"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$r[0][$field]."'", LOGGER_DEBUG); $update = true; } + } - foreach ($fields AS $field => $data) + foreach ($fields AS $field => $data) { if ($contact[$field] != $r[0][$field]) { logger("Difference for contact ".$contact["id"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$r[0][$field]."'", LOGGER_DEBUG); $update = true; } + } if ($update) { logger("Update contact data for contact ".$contact["id"]." (".$contact["nick"].")", LOGGER_DEBUG); @@ -1428,6 +1479,7 @@ class dfrn { * @param text $element element name * * @return string XML string + * @todo Find good type-hints for all parameter */ private static function transform_activity($xpath, $activity, $element) { if (!is_object($activity)) { @@ -1443,21 +1495,26 @@ class dfrn { xml::add_element($obj_doc, $obj_element, "type", $activity_type); $id = $xpath->query("atom:id", $activity)->item(0); - if (is_object($id)) + if (is_object($id)) { $obj_element->appendChild($obj_doc->importNode($id, true)); + } $title = $xpath->query("atom:title", $activity)->item(0); - if (is_object($title)) + if (is_object($title)) { $obj_element->appendChild($obj_doc->importNode($title, true)); + } $links = $xpath->query("atom:link", $activity); - if (is_object($links)) - foreach ($links AS $link) + if (is_object($links)) { + foreach ($links AS $link) { $obj_element->appendChild($obj_doc->importNode($link, true)); + } + } $content = $xpath->query("atom:content", $activity)->item(0); - if (is_object($content)) + if (is_object($content)) { $obj_element->appendChild($obj_doc->importNode($content, true)); + } $obj_doc->appendChild($obj_element); @@ -1474,11 +1531,13 @@ class dfrn { * @param object $xpath XPath object * @param object $mail mail elements * @param array $importer Record of the importer user mixed with contact of the content + * @todo Find good type-hints for all parameter */ private static function process_mail($xpath, $mail, $importer) { logger("Processing mails"); + /// @TODO Rewrite this to one statement $msg = array(); $msg["uid"] = $importer["importer_uid"]; $msg["from-name"] = $xpath->query("dfrn:sender/dfrn:name/text()", $mail)->item(0)->nodeValue; @@ -1498,7 +1557,7 @@ class dfrn { $r = dbq("INSERT INTO `mail` (`".implode("`, `", array_keys($msg))."`) VALUES (".implode(", ", array_values($msg)).")"); // send notifications. - + /// @TODO Arange this mess $notif_params = array( "type" => NOTIFY_MAIL, "notify_flags" => $importer["notify-flags"], @@ -1525,12 +1584,14 @@ class dfrn { * @param object $xpath XPath object * @param object $suggestion suggestion elements * @param array $importer Record of the importer user mixed with contact of the content + * @todo Find good type-hints for all parameter */ private static function process_suggestion($xpath, $suggestion, $importer) { $a = get_app(); logger("Processing suggestions"); + /// @TODO Rewrite this to one statement $suggest = array(); $suggest["uid"] = $importer["importer_uid"]; $suggest["cid"] = $importer["id"]; @@ -1547,8 +1608,10 @@ class dfrn { dbesc(normalise_link($suggest["url"])), intval($suggest["uid"]) ); - if (dbm::is_result($r)) + /// @TODO Really abort on valid result??? Maybe missed ! here? + if (dbm::is_result($r)) { return false; + } // Do we already have an fcontact record for this person? @@ -1566,10 +1629,12 @@ class dfrn { intval($suggest["uid"]), intval($fid) ); - if (dbm::is_result($r)) + /// @TODO Really abort on valid result??? Maybe missed ! here? + if (dbm::is_result($r)) { return false; + } } - if(!$fid) + if (!$fid) $r = q("INSERT INTO `fcontact` (`name`,`url`,`photo`,`request`) VALUES ('%s', '%s', '%s', '%s')", dbesc($suggest["name"]), dbesc($suggest["url"]), @@ -1581,11 +1646,12 @@ class dfrn { dbesc($suggest["name"]), dbesc($suggest["request"]) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $fid = $r[0]["id"]; - else + } else { // database record did not get created. Quietly give up. - return false; + killme(); + } $hash = random_string(); @@ -1627,11 +1693,13 @@ class dfrn { * @param object $xpath XPath object * @param object $relocation relocation elements * @param array $importer Record of the importer user mixed with contact of the content + * @todo Find good type-hints for all parameter */ private static function process_relocation($xpath, $relocation, $importer) { logger("Processing relocations"); + /// @TODO Rewrite this to one statement $relocate = array(); $relocate["uid"] = $importer["importer_uid"]; $relocate["cid"] = $importer["id"]; @@ -1648,18 +1716,22 @@ class dfrn { $relocate["poll"] = $xpath->query("dfrn:poll/text()", $relocation)->item(0)->nodeValue; $relocate["sitepubkey"] = $xpath->query("dfrn:sitepubkey/text()", $relocation)->item(0)->nodeValue; - if (($relocate["avatar"] == "") AND ($relocate["photo"] != "")) + if (($relocate["avatar"] == "") AND ($relocate["photo"] != "")) { $relocate["avatar"] = $relocate["photo"]; + } - if ($relocate["addr"] == "") + if ($relocate["addr"] == "") { $relocate["addr"] = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$3@$2", $relocate["url"]); + } // update contact $r = q("SELECT `photo`, `url` FROM `contact` WHERE `id` = %d AND `uid` = %d;", intval($importer["id"]), intval($importer["importer_uid"])); - if (!$r) - return false; + + if (!dbm::is_result($r)) { + killme(); + } $old = $r[0]; @@ -1715,8 +1787,9 @@ class dfrn { update_contact_avatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true); - if ($x === false) + if ($x === false) { return false; + } // update items /// @todo This is an extreme performance killer @@ -1731,7 +1804,7 @@ class dfrn { $n, dbesc($f[0]), intval($importer["importer_uid"])); - if ($r) { + if (dbm::is_result($r)) { $x = q("UPDATE `item` SET `%s` = '%s' WHERE `%s` = '%s' AND `uid` = %d", $n, dbesc($f[1]), $n, dbesc($f[0]), @@ -1780,12 +1853,13 @@ class dfrn { $changed = true; - if ($entrytype == DFRN_REPLY_RC) + if ($entrytype == DFRN_REPLY_RC) { proc_run(PRIORITY_HIGH, "include/notifier.php","comment-import", $current["id"]); + } } // update last-child if it changes - if($item["last-child"] AND ($item["last-child"] != $current["last-child"])) { + if ($item["last-child"] AND ($item["last-child"] != $current["last-child"])) { $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d", dbesc(datetime_convert()), dbesc($item["parent-uri"]), @@ -1817,8 +1891,9 @@ class dfrn { $sql_extra = ""; $community = true; logger("possible community action"); - } else + } else { $sql_extra = " AND `contact`.`self` AND `item`.`wall` "; + } // was the top-level post for this action written by somebody on this site? // Specifically, the recipient? @@ -1842,8 +1917,9 @@ class dfrn { dbesc($r[0]["parent-uri"]), intval($importer["importer_uid"]) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $is_a_remote_action = true; + } } // Does this have the characteristics of a community or private group action? @@ -1851,20 +1927,22 @@ class dfrn { // valid community action. Also forum_mode makes it valid for sure. // If neither, it's not. - if($is_a_remote_action && $community) { - if((!$r[0]["forum_mode"]) && (!$r[0]["wall"])) { + if ($is_a_remote_action && $community) { + if ((!$r[0]["forum_mode"]) && (!$r[0]["wall"])) { $is_a_remote_action = false; logger("not a community action"); } } - if ($is_a_remote_action) + if ($is_a_remote_action) { return DFRN_REPLY_RC; - else + } else { return DFRN_REPLY; + } - } else + } else { return DFRN_TOP_LEVEL; + } } @@ -1877,14 +1955,15 @@ class dfrn { */ private static function do_poke($item, $importer, $posted_id) { $verb = urldecode(substr($item["verb"],strpos($item["verb"], "#")+1)); - if(!$verb) + if (!$verb) { return; + } $xo = parse_xml_string($item["object"],false); - if(($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) { + if (($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) { // somebody was poked/prodded. Was it me? - foreach($xo->link as $l) { + foreach ($xo->link as $l) { $atts = $l->attributes(); switch($atts["rel"]) { case "alternate": @@ -1943,22 +2022,22 @@ class dfrn { // Big question: Do we need these functions? They were part of the "consume_feed" function. // This function once was responsible for DFRN and OStatus. - if(activity_match($item["verb"],ACTIVITY_FOLLOW)) { + if (activity_match($item["verb"],ACTIVITY_FOLLOW)) { logger("New follower"); new_follower($importer, $contact, $item, $nickname); return false; } - if(activity_match($item["verb"],ACTIVITY_UNFOLLOW)) { + if (activity_match($item["verb"],ACTIVITY_UNFOLLOW)) { logger("Lost follower"); lose_follower($importer, $contact, $item); return false; } - if(activity_match($item["verb"],ACTIVITY_REQ_FRIEND)) { + if (activity_match($item["verb"],ACTIVITY_REQ_FRIEND)) { logger("New friend request"); new_follower($importer, $contact, $item, $nickname, true); return false; } - if(activity_match($item["verb"],ACTIVITY_UNFRIEND)) { + if (activity_match($item["verb"],ACTIVITY_UNFRIEND)) { logger("Lost sharer"); lose_sharer($importer, $contact, $item); return false; @@ -1980,8 +2059,9 @@ class dfrn { dbesc($item["verb"]), dbesc($item["parent-uri"]) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { return false; + } $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `author-link` = '%s' AND `verb` = '%s' AND `thr-parent` = '%s' AND NOT `deleted` LIMIT 1", intval($item["uid"]), @@ -1989,28 +2069,31 @@ class dfrn { dbesc($item["verb"]), dbesc($item["parent-uri"]) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { return false; - } else + } + } else { $is_like = false; + } - if(($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { + if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { $xo = parse_xml_string($item["object"],false); $xt = parse_xml_string($item["target"],false); - if($xt->type == ACTIVITY_OBJ_NOTE) { + if ($xt->type == ACTIVITY_OBJ_NOTE) { $r = q("SELECT `id`, `tag` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($xt->id), intval($importer["importer_uid"]) ); - if (!dbm::is_result($r)) - return false; + if (!dbm::is_result($r)) { + killme(); + } // extract tag, if not duplicate, add to parent item - if($xo->content) { - if(!(stristr($r[0]["tag"],trim($xo->content)))) { + if ($xo->content) { + if (!(stristr($r[0]["tag"],trim($xo->content)))) { q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d", dbesc($r[0]["tag"] . (strlen($r[0]["tag"]) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]'), intval($r[0]["id"]) @@ -2029,6 +2112,7 @@ class dfrn { * * @param object $links link elements * @param array $item the item record + * @todo Add type-hints */ private static function parse_links($links, &$item) { $rel = ""; @@ -2037,17 +2121,23 @@ class dfrn { $length = "0"; $title = ""; foreach ($links AS $link) { - foreach($link->attributes AS $attributes) { - if ($attributes->name == "href") + foreach ($link->attributes AS $attributes) { + /// @TODO Rewrite these repeated (same) if() statements to a switch() + if ($attributes->name == "href") { $href = $attributes->textContent; - if ($attributes->name == "rel") + } + if ($attributes->name == "rel") { $rel = $attributes->textContent; - if ($attributes->name == "type") + } + if ($attributes->name == "type") { $type = $attributes->textContent; - if ($attributes->name == "length") + } + if ($attributes->name == "length") { $length = $attributes->textContent; - if ($attributes->name == "title") + } + if ($attributes->name == "title") { $title = $attributes->textContent; + } } if (($rel != "") AND ($href != "")) switch($rel) { @@ -2056,8 +2146,9 @@ class dfrn { break; case "enclosure": $enclosure = $href; - if(strlen($item["attach"])) + if (strlen($item["attach"])) { $item["attach"] .= ","; + } $item["attach"] .= '[attach]href="'.$href.'" length="'.$length.'" type="'.$type.'" title="'.$title.'"[/attach]'; break; @@ -2072,6 +2163,7 @@ class dfrn { * @param object $xpath XPath object * @param object $entry entry elements * @param array $importer Record of the importer user mixed with contact of the content + * @todo Add type-hints */ private static function process_entry($header, $xpath, $entry, $importer) { @@ -2122,7 +2214,7 @@ class dfrn { $item["body"] = limit_body_size($item["body"]); /// @todo Do we really need this check for HTML elements? (It was copied from the old function) - if((strpos($item['body'],'<') !== false) && (strpos($item['body'],'>') !== false)) { + if ((strpos($item['body'],'<') !== false) && (strpos($item['body'],'>') !== false)) { $item['body'] = reltoabs($item['body'],$base_url); @@ -2151,21 +2243,24 @@ class dfrn { $item["location"] = $xpath->query("dfrn:location/text()", $entry)->item(0)->nodeValue; $georsspoint = $xpath->query("georss:point", $entry); - if ($georsspoint) + if ($georsspoint) { $item["coord"] = $georsspoint->item(0)->nodeValue; + } $item["private"] = $xpath->query("dfrn:private/text()", $entry)->item(0)->nodeValue; $item["extid"] = $xpath->query("dfrn:extid/text()", $entry)->item(0)->nodeValue; - if ($xpath->query("dfrn:bookmark/text()", $entry)->item(0)->nodeValue == "true") + if ($xpath->query("dfrn:bookmark/text()", $entry)->item(0)->nodeValue == "true") { $item["bookmark"] = true; + } $notice_info = $xpath->query("statusnet:notice_info", $entry); if ($notice_info AND ($notice_info->length > 0)) { - foreach($notice_info->item(0)->attributes AS $attributes) { - if ($attributes->name == "source") + foreach ($notice_info->item(0)->attributes AS $attributes) { + if ($attributes->name == "source") { $item["app"] = strip_tags($attributes->textContent); + } } } @@ -2173,21 +2268,24 @@ class dfrn { // We store the data from "dfrn:diaspora_signature" in a different table, this is done in "item_store" $dsprsig = unxmlify($xpath->query("dfrn:diaspora_signature/text()", $entry)->item(0)->nodeValue); - if ($dsprsig != "") + if ($dsprsig != "") { $item["dsprsig"] = $dsprsig; + } $item["verb"] = $xpath->query("activity:verb/text()", $entry)->item(0)->nodeValue; - if ($xpath->query("activity:object-type/text()", $entry)->item(0)->nodeValue != "") + if ($xpath->query("activity:object-type/text()", $entry)->item(0)->nodeValue != "") { $item["object-type"] = $xpath->query("activity:object-type/text()", $entry)->item(0)->nodeValue; + } $object = $xpath->query("activity:object", $entry)->item(0); $item["object"] = self::transform_activity($xpath, $object, "object"); if (trim($item["object"]) != "") { $r = parse_xml_string($item["object"], false); - if (isset($r->type)) + if (isset($r->type)) { $item["object-type"] = $r->type; + } } $target = $xpath->query("activity:target", $entry)->item(0); @@ -2198,12 +2296,14 @@ class dfrn { foreach ($categories AS $category) { $term = ""; $scheme = ""; - foreach($category->attributes AS $attributes) { - if ($attributes->name == "term") + foreach ($category->attributes AS $attributes) { + if ($attributes->name == "term") { $term = $attributes->textContent; + } - if ($attributes->name == "scheme") + if ($attributes->name == "scheme") { $scheme = $attributes->textContent; + } } if (($term != "") AND ($scheme != "")) { @@ -2212,8 +2312,9 @@ class dfrn { $termhash = array_shift($parts); $termurl = implode(":", $parts); - if(strlen($item["tag"])) + if (strlen($item["tag"])) { $item["tag"] .= ","; + } $item["tag"] .= $termhash."[url=".$termurl."]".$term."[/url]"; } @@ -2224,37 +2325,46 @@ class dfrn { $enclosure = ""; $links = $xpath->query("atom:link", $entry); - if ($links) + if ($links) { self::parse_links($links, $item); + } // Is it a reply or a top level posting? $item["parent-uri"] = $item["uri"]; $inreplyto = $xpath->query("thr:in-reply-to", $entry); - if (is_object($inreplyto->item(0))) - foreach($inreplyto->item(0)->attributes AS $attributes) - if ($attributes->name == "ref") + if (is_object($inreplyto->item(0))) { + foreach ($inreplyto->item(0)->attributes AS $attributes) { + if ($attributes->name == "ref") { $item["parent-uri"] = $attributes->textContent; + } + } + } // Get the type of the item (Top level post, reply or remote reply) $entrytype = self::get_entry_type($importer, $item); // Now assign the rest of the values that depend on the type of the message if (in_array($entrytype, array(DFRN_REPLY, DFRN_REPLY_RC))) { - if (!isset($item["object-type"])) + if (!isset($item["object-type"])) { $item["object-type"] = ACTIVITY_OBJ_COMMENT; + } - if ($item["contact-id"] != $owner["contact-id"]) + if ($item["contact-id"] != $owner["contact-id"]) { $item["contact-id"] = $owner["contact-id"]; + } - if (($item["network"] != $owner["network"]) AND ($owner["network"] != "")) + if (($item["network"] != $owner["network"]) AND ($owner["network"] != "")) { $item["network"] = $owner["network"]; + } - if ($item["contact-id"] != $author["contact-id"]) + if ($item["contact-id"] != $author["contact-id"]) { $item["contact-id"] = $author["contact-id"]; + } - if (($item["network"] != $author["network"]) AND ($author["network"] != "")) + if (($item["network"] != $author["network"]) AND ($author["network"] != "")) { $item["network"] = $author["network"]; + } // This code was taken from the old DFRN code // When activated, forums don't work. @@ -2270,14 +2380,15 @@ class dfrn { $item["type"] = "remote-comment"; $item["wall"] = 1; } elseif ($entrytype == DFRN_TOP_LEVEL) { - if (!isset($item["object-type"])) + if (!isset($item["object-type"])) { $item["object-type"] = ACTIVITY_OBJ_NOTE; + } // Is it an event? if ($item["object-type"] == ACTIVITY_OBJ_EVENT) { logger("Item ".$item["uri"]." seems to contain an event.", LOGGER_DEBUG); $ev = bbtoevent($item["body"]); - if((x($ev, "desc") || x($ev, "summary")) && x($ev, "start")) { + if ((x($ev, "desc") || x($ev, "summary")) && x($ev, "start")) { logger("Event in item ".$item["uri"]." was found.", LOGGER_DEBUG); $ev["cid"] = $importer["id"]; $ev["uid"] = $importer["uid"]; @@ -2290,8 +2401,9 @@ class dfrn { dbesc($item["uri"]), intval($importer["uid"]) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $ev["id"] = $r[0]["id"]; + } $event_id = event_store($ev); logger("Event ".$event_id." was stored", LOGGER_DEBUG); @@ -2309,8 +2421,9 @@ class dfrn { if (dbm::is_result($current)) { if (self::update_content($r[0], $item, $importer, $entrytype)) logger("Item ".$item["uri"]." was updated.", LOGGER_DEBUG); - else + } else { logger("Item ".$item["uri"]." already existed.", LOGGER_DEBUG); + } return; } @@ -2318,7 +2431,7 @@ class dfrn { $posted_id = item_store($item); $parent = 0; - if($posted_id) { + if ($posted_id) { logger("Reply from contact ".$item["contact-id"]." was stored with id ".$posted_id, LOGGER_DEBUG); @@ -2333,7 +2446,7 @@ class dfrn { $parent_uri = $r[0]["parent-uri"]; } - if(!$is_like) { + if (!$is_like) { $r1 = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `uid` = %d AND `parent` = %d", dbesc(datetime_convert()), intval($importer["importer_uid"]), @@ -2347,7 +2460,7 @@ class dfrn { ); } - if($posted_id AND $parent AND ($entrytype == DFRN_REPLY_RC)) { + if ($posted_id AND $parent AND ($entrytype == DFRN_REPLY_RC)) { logger("Notifying followers about comment ".$posted_id, LOGGER_DEBUG); proc_run(PRIORITY_HIGH, "include/notifier.php", "comment-import", $posted_id); } @@ -2355,7 +2468,7 @@ class dfrn { return true; } } else { // $entrytype == DFRN_TOP_LEVEL - if(!link_compare($item["owner-link"],$importer["url"])) { + if (!link_compare($item["owner-link"],$importer["url"])) { // The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery, // but otherwise there's a possible data mixup on the sender's system. // the tgroup delivery code called from item_store will correct it if it's a forum, @@ -2366,7 +2479,7 @@ class dfrn { $item["owner-avatar"] = $importer["thumb"]; } - if(($importer["rel"] == CONTACT_IS_FOLLOWER) && (!tgroup_check($importer["importer_uid"], $item))) { + if (($importer["rel"] == CONTACT_IS_FOLLOWER) && (!tgroup_check($importer["importer_uid"], $item))) { logger("Contact ".$importer["id"]." is only follower and tgroup check was negative.", LOGGER_DEBUG); return; } @@ -2395,19 +2508,23 @@ class dfrn { logger("Processing deletions"); - foreach($deletion->attributes AS $attributes) { - if ($attributes->name == "ref") + foreach ($deletion->attributes AS $attributes) { + if ($attributes->name == "ref") { $uri = $attributes->textContent; - if ($attributes->name == "when") + } + if ($attributes->name == "when") { $when = $attributes->textContent; + } } - if ($when) + if ($when) { $when = datetime_convert("UTC", "UTC", $when, "Y-m-d H:i:s"); - else + } else { $when = datetime_convert("UTC", "UTC", "now", "Y-m-d H:i:s"); + } - if (!$uri OR !$importer["id"]) + if (!$uri OR !$importer["id"]) { return false; + } /// @todo Only select the used fields $r = q("SELECT `item`.*, `contact`.`self` FROM `item` INNER JOIN `contact` on `item`.`contact-id` = `contact`.`id` @@ -2425,22 +2542,23 @@ class dfrn { $entrytype = self::get_entry_type($importer, $item); - if(!$item["deleted"]) + if (!$item["deleted"]) { logger('deleting item '.$item["id"].' uri='.$uri, LOGGER_DEBUG); - else + } else { return; + } - if($item["object-type"] == ACTIVITY_OBJ_EVENT) { + if ($item["object-type"] == ACTIVITY_OBJ_EVENT) { logger("Deleting event ".$item["event-id"], LOGGER_DEBUG); event_delete($item["event-id"]); } - if(($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { + if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { $xo = parse_xml_string($item["object"],false); $xt = parse_xml_string($item["target"],false); - if($xt->type == ACTIVITY_OBJ_NOTE) { + if ($xt->type == ACTIVITY_OBJ_NOTE) { $i = q("SELECT `id`, `contact-id`, `tag` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($xt->id), intval($importer["importer_uid"]) @@ -2453,15 +2571,18 @@ class dfrn { $author_remove = (($item["origin"] && $item["self"]) ? true : false); $author_copy = (($item["origin"]) ? true : false); - if($owner_remove && $author_copy) + if ($owner_remove && $author_copy) { return; - if($author_remove || $owner_remove) { + } + if ($author_remove || $owner_remove) { $tags = explode(',',$i[0]["tag"]); $newtags = array(); - if(count($tags)) { - foreach($tags as $tag) - if(trim($tag) !== trim($xo->body)) + if (count($tags)) { + foreach ($tags as $tag) { + if (trim($tag) !== trim($xo->body)) { $newtags[] = trim($tag); + } + } } q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d", dbesc(implode(',',$newtags)), @@ -2602,25 +2723,30 @@ class dfrn { ); $mails = $xpath->query("/atom:feed/dfrn:mail"); - foreach ($mails AS $mail) + foreach ($mails AS $mail) { self::process_mail($xpath, $mail, $importer); + } $suggestions = $xpath->query("/atom:feed/dfrn:suggest"); - foreach ($suggestions AS $suggestion) + foreach ($suggestions AS $suggestion) { self::process_suggestion($xpath, $suggestion, $importer); + } $relocations = $xpath->query("/atom:feed/dfrn:relocate"); - foreach ($relocations AS $relocation) + foreach ($relocations AS $relocation) { self::process_relocation($xpath, $relocation, $importer); + } $deletions = $xpath->query("/atom:feed/at:deleted-entry"); - foreach ($deletions AS $deletion) + foreach ($deletions AS $deletion) { self::process_deletion($xpath, $deletion, $importer); + } if (!$sort_by_date) { $entries = $xpath->query("/atom:feed/atom:entry"); - foreach ($entries AS $entry) + foreach ($entries AS $entry) { self::process_entry($header, $xpath, $entry, $importer); + } } else { $newentries = array(); $entries = $xpath->query("/atom:feed/atom:entry"); @@ -2632,8 +2758,9 @@ class dfrn { // Now sort after the publishing date ksort($newentries); - foreach ($newentries AS $entry) + foreach ($newentries AS $entry) { self::process_entry($header, $xpath, $entry, $importer); + } } logger("Import done for user ".$importer["uid"]." from contact ".$importer["id"], LOGGER_DEBUG); } From 3ad0fd442e6dd580a85d0595d643add0312e5e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 10:01:15 +0100 Subject: [PATCH 17/65] Continued: - added missing spaces/curly braces - some more usage of dbm::is_result() - 2 oppsite if() statements can be mored to else - added more TODOs for type-hinting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/ostatus.php | 361 +++++++++++++++++++++++++++++--------------- 1 file changed, 237 insertions(+), 124 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index 3e285a783..0337e9a27 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -37,9 +37,11 @@ class ostatus { * @param bool $onlyfetch Only fetch the header without updating the contact entries * * @return array Array of author related entries for the item + * @todo Add type-hints */ private function fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch) { + /// @TODO One statment is enough ... $author = array(); $author["author-link"] = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue; $author["author-name"] = $xpath->evaluate('atom:author/atom:name/text()', $context)->item(0)->nodeValue; @@ -47,33 +49,41 @@ class ostatus { $aliaslink = $author["author-link"]; $alternate = $xpath->query("atom:author/atom:link[@rel='alternate']", $context)->item(0)->attributes; - if (is_object($alternate)) - foreach($alternate AS $attributes) - if ($attributes->name == "href") + if (is_object($alternate)) { + /// @TODO foreach() may only later work on objects that have iterator interface implemented, please check this + foreach ($alternate AS $attributes) { + if ($attributes->name == "href") { $author["author-link"] = $attributes->textContent; + } + } + } $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` IN ('%s', '%s') AND `network` != '%s'", intval($importer["uid"]), dbesc(normalise_link($author["author-link"])), dbesc(normalise_link($aliaslink)), dbesc(NETWORK_STATUSNET)); - if ($r) { + if (dbm::is_result($r)) { $contact = $r[0]; $author["contact-id"] = $r[0]["id"]; - } else + } else { $author["contact-id"] = $contact["id"]; + } $avatarlist = array(); $avatars = $xpath->query("atom:author/atom:link[@rel='avatar']", $context); - foreach($avatars AS $avatar) { + foreach ($avatars AS $avatar) { $href = ""; $width = 0; - foreach($avatar->attributes AS $attributes) { - if ($attributes->name == "href") + foreach ($avatar->attributes AS $attributes) { + if ($attributes->name == "href") { $href = $attributes->textContent; - if ($attributes->name == "width") + } + if ($attributes->name == "width") { $width = $attributes->textContent; + } } - if (($width > 0) AND ($href != "")) + if (($width > 0) AND ($href != "")) { $avatarlist[$width] = $href; + } } if (count($avatarlist) > 0) { krsort($avatarlist); @@ -81,15 +91,16 @@ class ostatus { } $displayname = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue; - if ($displayname != "") + if ($displayname != "") { $author["author-name"] = $displayname; + } $author["owner-name"] = $author["author-name"]; $author["owner-link"] = $author["author-link"]; $author["owner-avatar"] = $author["author-avatar"]; // Only update the contacts if it is an OStatus contact - if ($r AND !$onlyfetch AND ($contact["network"] == NETWORK_OSTATUS)) { + if (dbm::is_result($r) AND !$onlyfetch AND ($contact["network"] == NETWORK_OSTATUS)) { // Update contact data @@ -181,6 +192,7 @@ class ostatus { * @param array $importer user record of the importing user * * @return array Array of author related entries for the item + * @todo add type-hints */ public static function salmon_author($xml, $importer) { @@ -189,7 +201,7 @@ class ostatus { } $doc = new DOMDocument(); - @$doc->loadXML($xml); + $doc->loadXML($xml); $xpath = new DomXPath($doc); $xpath->registerNamespace('atom', NAMESPACE_ATOM1); @@ -217,6 +229,7 @@ class ostatus { * @param array $importer user record of the importing user * @param $contact * @param array $hub Called by reference, returns the fetched hub data + * @todo Add missing-type hint + determine type for $contact */ public static function import($xml,$importer,&$contact, &$hub) { /// @todo this function is too long. It has to be split in many parts @@ -231,7 +244,7 @@ class ostatus { //file_put_contents($tempfile, $xml); $doc = new DOMDocument(); - @$doc->loadXML($xml); + $doc->loadXML($xml); $xpath = new DomXPath($doc); $xpath->registerNamespace('atom', NAMESPACE_ATOM1); @@ -246,7 +259,7 @@ class ostatus { $gub = ""; $hub_attributes = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0)->attributes; if (is_object($hub_attributes)) { - foreach($hub_attributes AS $hub_attribute) { + foreach ($hub_attributes AS $hub_attribute) { if ($hub_attribute->name == "href") { $hub = $hub_attribute->textContent; logger("Found hub ".$hub, LOGGER_DEBUG); @@ -254,6 +267,7 @@ class ostatus { } } + /// @TODO One statement is enough ... $header = array(); $header["uid"] = $importer["uid"]; $header["network"] = NETWORK_OSTATUS; @@ -377,7 +391,7 @@ class ostatus { $inreplyto = $xpath->query('thr:in-reply-to', $entry); if (is_object($inreplyto->item(0))) { - foreach($inreplyto->item(0)->attributes AS $attributes) { + foreach ($inreplyto->item(0)->attributes AS $attributes) { if ($attributes->name == "ref") { $item["parent-uri"] = $attributes->textContent; } @@ -394,7 +408,7 @@ class ostatus { $categories = $xpath->query('atom:category', $entry); if ($categories) { foreach ($categories AS $category) { - foreach($category->attributes AS $attributes) + foreach ($category->attributes AS $attributes) if ($attributes->name == "term") { $term = $attributes->textContent; if(strlen($item["tag"])) @@ -415,7 +429,7 @@ class ostatus { $length = "0"; $title = ""; foreach ($links AS $link) { - foreach($link->attributes AS $attributes) { + foreach ($link->attributes AS $attributes) { if ($attributes->name == "href") $href = $attributes->textContent; if ($attributes->name == "rel") @@ -473,7 +487,7 @@ class ostatus { $notice_info = $xpath->query('statusnet:notice_info', $entry); if ($notice_info AND ($notice_info->length > 0)) { - foreach($notice_info->item(0)->attributes AS $attributes) { + foreach ($notice_info->item(0)->attributes AS $attributes) { if ($attributes->name == "source") { $item["app"] = strip_tags($attributes->textContent); } @@ -600,22 +614,26 @@ class ostatus { public static function convert_href($href) { $elements = explode(":",$href); - if ((count($elements) <= 2) OR ($elements[0] != "tag")) + if ((count($elements) <= 2) OR ($elements[0] != "tag")) { return $href; + } $server = explode(",", $elements[1]); $conversation = explode("=", $elements[2]); - if ((count($elements) == 4) AND ($elements[2] == "post")) + if ((count($elements) == 4) AND ($elements[2] == "post")) { return "http://".$server[0]."/notice/".$elements[3]; + } - if ((count($conversation) != 2) OR ($conversation[1] =="")) + if ((count($conversation) != 2) OR ($conversation[1] =="")) { return $href; + } - if ($elements[3] == "objectType=thread") + if ($elements[3] == "objectType=thread") { return "http://".$server[0]."/conversation/".$conversation[1]; - else + } else { return "http://".$server[0]."/notice/".$conversation[1]; + } return $href; } @@ -688,42 +706,53 @@ class ostatus { * @brief Updates the gcontact table with actor data from the conversation * * @param object $actor The actor object that contains the contact data + * @todo Add type-hint */ private function conv_fetch_actor($actor) { // We set the generation to "3" since the data here is not as reliable as the data we get on other occasions $contact = array("network" => NETWORK_OSTATUS, "generation" => 3); - if (isset($actor->url)) + if (isset($actor->url)) { $contact["url"] = $actor->url; + } - if (isset($actor->displayName)) + if (isset($actor->displayName)) { $contact["name"] = $actor->displayName; + } - if (isset($actor->portablecontacts_net->displayName)) + if (isset($actor->portablecontacts_net->displayName)) { $contact["name"] = $actor->portablecontacts_net->displayName; + } - if (isset($actor->portablecontacts_net->preferredUsername)) + if (isset($actor->portablecontacts_net->preferredUsername)) { $contact["nick"] = $actor->portablecontacts_net->preferredUsername; + } - if (isset($actor->id)) + if (isset($actor->id)) { $contact["alias"] = $actor->id; + } - if (isset($actor->summary)) + if (isset($actor->summary)) { $contact["about"] = $actor->summary; + } - if (isset($actor->portablecontacts_net->note)) + if (isset($actor->portablecontacts_net->note)) { $contact["about"] = $actor->portablecontacts_net->note; + } - if (isset($actor->portablecontacts_net->addresses->formatted)) + if (isset($actor->portablecontacts_net->addresses->formatted)) { $contact["location"] = $actor->portablecontacts_net->addresses->formatted; + } - if (isset($actor->image->url)) + if (isset($actor->image->url)) { $contact["photo"] = $actor->image->url; + } - if (isset($actor->image->width)) + if (isset($actor->image->width)) { $avatarwidth = $actor->image->width; + } if (is_array($actor->status_net->avatarLinks)) foreach ($actor->status_net->avatarLinks AS $avatar) { @@ -750,22 +779,26 @@ class ostatus { if ($conversation_id != "") { $elements = explode(":", $conversation_id); - if ((count($elements) <= 2) OR ($elements[0] != "tag")) + if ((count($elements) <= 2) OR ($elements[0] != "tag")) { return $conversation_id; + } } - if ($self == "") + if ($self == "") { return ""; + } $json = str_replace(".atom", ".json", $self); $raw = fetch_url($json); - if ($raw == "") + if ($raw == "") { return ""; + } $data = json_decode($raw); - if (!is_object($data)) + if (!is_object($data)) { return ""; + } $conversation_id = $data->statusnet_conversation_id; @@ -791,11 +824,12 @@ class ostatus { $contact = q("SELECT `id`, `rel`, `network` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'", $uid, normalise_link($actor), NETWORK_STATUSNET); - if (!$contact) + if (!dbm::is_result($contact)) { $contact = q("SELECT `id`, `rel`, `network` FROM `contact` WHERE `uid` = %d AND `alias` IN ('%s', '%s') AND `network` != '%s'", $uid, $actor, normalise_link($actor), NETWORK_STATUSNET); + } - if ($contact) { + if (dbm::is_resul($contact)) { logger("Found contact for url ".$actor, LOGGER_DEBUG); $details["contact_id"] = $contact[0]["id"]; $details["network"] = $contact[0]["network"]; @@ -827,6 +861,7 @@ class ostatus { * @param array $item Data of the item that is to be posted * * @return integer The item id of the posted item array + * @todo Add type-hints */ private function completion($conversation_url, $uid, $item = array(), $self = "") { @@ -859,9 +894,9 @@ class ostatus { (SELECT `oid` FROM `term` WHERE `uid` = %d AND `otype` = %d AND `type` = %d AND `url` = '%s'))", intval($uid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION), dbesc($conversation_url)); */ - if ($parents) + if (dbm::is_result($parents)) { $parent = $parents[0]; - elseif (count($item) > 0) { + } elseif (count($item) > 0) { $parent = $item; $parent["type"] = "remote"; $parent["verb"] = ACTIVITY_POST; @@ -869,9 +904,11 @@ class ostatus { } else { // Preset the parent $r = q("SELECT `id` FROM `contact` WHERE `self` AND `uid`=%d", $uid); - if (!$r) + if (!dbm::is_result($r)) { return(-2); + } + /// @TODO one statement is enough ... $parent = array(); $parent["id"] = 0; $parent["parent"] = 0; @@ -898,20 +935,24 @@ class ostatus { } elseif (!$conv_arr["success"] AND (substr($conv, 0, 8) == "https://")) { $conv = str_replace("https://", "http://", $conv); $conv_as = fetch_url($conv."?page=".$pageno); - } else + } else { $conv_as = $conv_arr["body"]; + } $conv_as = str_replace(',"statusnet:notice_info":', ',"statusnet_notice_info":', $conv_as); $conv_as = json_decode($conv_as); $no_of_items = sizeof($items); - if (@is_array($conv_as->items)) - foreach ($conv_as->items AS $single_item) + if (is_array($conv_as->items)) { + foreach ($conv_as->items AS $single_item) { $items[$single_item->id] = $single_item; + } + } - if ($no_of_items == sizeof($items)) + if ($no_of_items == sizeof($items)) { break; + } $pageno++; @@ -929,13 +970,19 @@ class ostatus { } return($item_stored); - } else + } else { return(-3); + } } $items = array_reverse($items); $r = q("SELECT `nurl` FROM `contact` WHERE `uid` = %d AND `self`", intval($uid)); + + if (!dbm::is_result($r)) { + killme(); + } + $importer = $r[0]; $new_parent = true; @@ -951,15 +998,18 @@ class ostatus { $mention = false; - if (isset($single_conv->object->id)) + if (isset($single_conv->object->id)) { $single_conv->id = $single_conv->object->id; + } $plink = self::convert_href($single_conv->id); - if (isset($single_conv->object->url)) + if (isset($single_conv->object->url)) { $plink = self::convert_href($single_conv->object->url); + } - if (@!$single_conv->id) + if (!isset($single_conv->id)) { continue; + } logger("Got id ".$single_conv->id, LOGGER_DEBUG); @@ -978,7 +1028,7 @@ class ostatus { (SELECT `parent` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s')) LIMIT 1", intval($uid), dbesc($first_id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); - if ($new_parents) { + if (dbm::is_result($new_parents)) { if ($new_parents[0]["parent"] == $parent["parent"]) { // Option 2: This post is already present inside our thread - but not as thread starter logger("Option 2: uri present in our thread: ".$first_id, LOGGER_DEBUG); @@ -1009,16 +1059,18 @@ class ostatus { if (isset($single_conv->context->inReplyTo->id)) { $parent_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", intval($uid), dbesc($single_conv->context->inReplyTo->id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); - if ($parent_exists) + if (dbm::is_result($parent_exists)) { $parent_uri = $single_conv->context->inReplyTo->id; + } } // This is the current way if (isset($single_conv->object->inReplyTo->id)) { $parent_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", intval($uid), dbesc($single_conv->object->inReplyTo->id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); - if ($parent_exists) + if (dbm::is_result($parent_exists)) { $parent_uri = $single_conv->object->inReplyTo->id; + } } $message_exists = q("SELECT `id`, `parent`, `uri` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", @@ -1065,14 +1117,18 @@ class ostatus { continue; } - if (is_array($single_conv->to)) - foreach($single_conv->to AS $to) - if ($importer["nurl"] == normalise_link($to->id)) + if (is_array($single_conv->to)) { + foreach ($single_conv->to AS $to) { + if ($importer["nurl"] == normalise_link($to->id)) { $mention = true; + } + } + } $actor = $single_conv->actor->id; - if (isset($single_conv->actor->url)) + if (isset($single_conv->actor->url)) { $actor = $single_conv->actor->url; + } $details = self::get_actor_details($actor, $uid, $parent["contact-id"]); @@ -1082,6 +1138,7 @@ class ostatus { continue; } + /// @TODO One statment is okay (until if() ) $arr = array(); $arr["network"] = $details["network"]; $arr["uri"] = $single_conv->id; @@ -1092,10 +1149,12 @@ class ostatus { $arr["created"] = $single_conv->published; $arr["edited"] = $single_conv->published; $arr["owner-name"] = $single_conv->actor->displayName; - if ($arr["owner-name"] == '') + if ($arr["owner-name"] == '') { $arr["owner-name"] = $single_conv->actor->contact->displayName; - if ($arr["owner-name"] == '') + } + if ($arr["owner-name"] == '') { $arr["owner-name"] = $single_conv->actor->portablecontacts_net->displayName; + } $arr["owner-link"] = $actor; $arr["owner-avatar"] = $single_conv->actor->image->url; @@ -1104,15 +1163,15 @@ class ostatus { $arr["author-avatar"] = $single_conv->actor->image->url; $arr["body"] = add_page_info_to_body(html2bbcode($single_conv->content)); - if (isset($single_conv->status_net->notice_info->source)) + if (isset($single_conv->status_net->notice_info->source)) { $arr["app"] = strip_tags($single_conv->status_net->notice_info->source); - elseif (isset($single_conv->statusnet->notice_info->source)) + } elseif (isset($single_conv->statusnet->notice_info->source)) { $arr["app"] = strip_tags($single_conv->statusnet->notice_info->source); - elseif (isset($single_conv->statusnet_notice_info->source)) + } elseif (isset($single_conv->statusnet_notice_info->source)) { $arr["app"] = strip_tags($single_conv->statusnet_notice_info->source); - elseif (isset($single_conv->provider->displayName)) + } elseif (isset($single_conv->provider->displayName)) { $arr["app"] = $single_conv->provider->displayName; - else + } else { $arr["app"] = "OStatus"; @@ -1131,20 +1190,23 @@ class ostatus { // $single_conv->object->context->conversation; - if (isset($single_conv->object->object->id)) + if (isset($single_conv->object->object->id)) { $arr["uri"] = $single_conv->object->object->id; - else + } else { $arr["uri"] = $single_conv->object->id; + } - if (isset($single_conv->object->object->url)) + if (isset($single_conv->object->object->url)) { $plink = self::convert_href($single_conv->object->object->url); - else + } else { $plink = self::convert_href($single_conv->object->url); + } - if (isset($single_conv->object->object->content)) + if (isset($single_conv->object->object->content)) { $arr["body"] = add_page_info_to_body(html2bbcode($single_conv->object->object->content)); - else + } else { $arr["body"] = add_page_info_to_body(html2bbcode($single_conv->object->content)); + } $arr["plink"] = $plink; @@ -1152,8 +1214,9 @@ class ostatus { $arr["edited"] = $single_conv->object->published; $arr["author-name"] = $single_conv->object->actor->displayName; - if ($arr["owner-name"] == '') + if ($arr["owner-name"] == '') { $arr["author-name"] = $single_conv->object->actor->contact->displayName; + } $arr["author-link"] = $single_conv->object->actor->url; $arr["author-avatar"] = $single_conv->object->actor->image->url; @@ -1165,20 +1228,24 @@ class ostatus { $arr["coord"] = trim($single_conv->object->location->lat." ".$single_conv->object->location->lon); } - if ($arr["location"] == "") + if ($arr["location"] == "") { unset($arr["location"]); + } - if ($arr["coord"] == "") + if ($arr["coord"] == "") { unset($arr["coord"]); + } // Copy fields from given item array if (isset($item["uri"]) AND (($item["uri"] == $arr["uri"]) OR ($item["uri"] == $single_conv->id))) { $copy_fields = array("owner-name", "owner-link", "owner-avatar", "author-name", "author-link", "author-avatar", "gravity", "body", "object-type", "object", "verb", "created", "edited", "coord", "tag", "title", "attach", "app", "type", "location", "contact-id", "uri"); - foreach ($copy_fields AS $field) - if (isset($item[$field])) - $arr[$field] = $item[$field]; + foreach ($copy_fields AS $field) { + if (isset($item[$field])) { + $arr[$field] = $item[$field]; { + } + } } @@ -1204,8 +1271,9 @@ class ostatus { logger('setting new parent to id '.$newitem); $new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($uid), intval($newitem)); - if ($new_parents) + if ($new_parents) { $parent = $new_parents[0]; + } } } @@ -1240,8 +1308,9 @@ class ostatus { $conversation_url = self::convert_href($conversation_url); $messages = q("SELECT `uid`, `parent`, `created`, `received`, `guid` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); - if (!$messages) + if (!dbm::is_result($messages)) { return; + } $message = $messages[0]; // Store conversation url if not done before @@ -1262,32 +1331,38 @@ class ostatus { * @param array $item The item array of thw post * * @return string The guid if the post is a reshare + * @todo Add type-hints */ private function get_reshared_guid($item) { $body = trim($item["body"]); // Skip if it isn't a pure repeated messages // Does it start with a share? - if (strpos($body, "[share") > 0) + if (strpos($body, "[share") > 0) { return(""); + } // Does it end with a share? - if (strlen($body) > (strrpos($body, "[/share]") + 8)) + if (strlen($body) > (strrpos($body, "[/share]") + 8)) { return(""); + } $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body); // Skip if there is no shared message in there - if ($body == $attributes) + if ($body == $attributes) { return(false); + } $guid = ""; preg_match("/guid='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") + if ($matches[1] != "") { $guid = $matches[1]; + } preg_match('/guid="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") + if ($matches[1] != "") { $guid = $matches[1]; + } return $guid; } @@ -1303,10 +1378,11 @@ class ostatus { $siteinfo = get_attached_data($body); if (($siteinfo["type"] == "photo")) { - if (isset($siteinfo["preview"])) + if (isset($siteinfo["preview"])) { $preview = $siteinfo["preview"]; - else + } else { $preview = $siteinfo["image"]; + } // Is it a remote picture? Then make a smaller preview here $preview = proxy_url($preview, false, PROXY_SIZE_SMALL); @@ -1315,10 +1391,11 @@ class ostatus { $preview = str_replace(array("-0.jpg", "-0.png"), array("-2.jpg", "-2.png"), $preview); $preview = str_replace(array("-1.jpg", "-1.png"), array("-2.jpg", "-2.png"), $preview); - if (isset($siteinfo["url"])) + if (isset($siteinfo["url"])) { $url = $siteinfo["url"]; - else + } else { $url = $siteinfo["image"]; + } $body = trim($siteinfo["text"])." [url]".$url."[/url]\n[img]".$preview."[/img]"; } @@ -1333,6 +1410,7 @@ class ostatus { * @param array $owner Contact data of the poster * * @return object header root element + * @todo Add type-hints */ private function add_header($doc, $owner) { @@ -1392,20 +1470,23 @@ class ostatus { * * @param object $doc XML document * @param object $root XML root element where the hub links are added + * @todo Add type-hints */ public static function hublinks($doc, $root) { $hub = get_config('system','huburl'); $hubxml = ''; - if(strlen($hub)) { + if (strlen($hub)) { $hubs = explode(',', $hub); - if(count($hubs)) { - foreach($hubs as $h) { + if (count($hubs)) { + foreach ($hubs as $h) { $h = trim($h); - if(! strlen($h)) + if (! strlen($h)) { continue; - if ($h === '[internal]') + } + if ($h === '[internal]') { $h = App::get_baseurl() . '/pubsubhubbub'; + } xml::add_element($doc, $root, "link", "", array("href" => $h, "rel" => "hub")); } } @@ -1418,6 +1499,7 @@ class ostatus { * @param object $doc XML document * @param object $root XML root element where the hub links are added * @param array $item Data of the item that is to be posted + * @todo Add type-hints */ private function get_attachment($doc, $root, $item) { $o = ""; @@ -1461,20 +1543,22 @@ class ostatus { $arr = explode('[/attach],',$item['attach']); - if(count($arr)) { - foreach($arr as $r) { + if (count($arr)) { + foreach ($arr as $r) { $matches = false; $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches); - if($cnt) { + if ($cnt) { $attributes = array("rel" => "enclosure", "href" => $matches[1], "type" => $matches[3]); - if(intval($matches[2])) + if (intval($matches[2])) { $attributes["length"] = intval($matches[2]); + } - if(trim($matches[4]) != "") + if (trim($matches[4]) != "") { $attributes["title"] = trim($matches[4]); + } xml::add_element($doc, $root, "link", "", $attributes); } @@ -1489,12 +1573,15 @@ class ostatus { * @param array $owner Contact data of the poster * * @return object author element + * @todo Add type-hints */ private function add_author($doc, $owner) { + $profile = null; $r = q("SELECT `homepage` FROM `profile` WHERE `uid` = %d AND `is-default` LIMIT 1", intval($owner["uid"])); - if ($r) + if (dbm::is_result($r)) { $profile = $r[0]; + } $author = $doc->createElement("author"); xml::add_element($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON); @@ -1562,10 +1649,12 @@ class ostatus { * @param array $item Data of the item that is to be posted * * @return string activity + * @todo Add type-hints */ function construct_verb($item) { - if ($item['verb']) + if ($item['verb']) { return $item['verb']; + } return ACTIVITY_POST; } @@ -1575,10 +1664,12 @@ class ostatus { * @param array $item Data of the item that is to be posted * * @return string Object type + * @todo Add type-hints */ function construct_objecttype($item) { - if (in_array($item['object-type'], array(ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT))) + if (in_array($item['object-type'], array(ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT))) { return $item['object-type']; + }; return ACTIVITY_OBJ_NOTE; } @@ -1616,6 +1707,7 @@ class ostatus { * @param array $contact Array of the contact that is added * * @return object Source element + * @todo Add type-hints */ private function source_entry($doc, $contact) { $source = $doc->createElement("source"); @@ -1640,39 +1732,41 @@ class ostatus { * @param array $owner Contact data of the poster * * @return array Contact array + * @todo Add array type-hint for $owner */ private function contact_entry($url, $owner) { $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` IN (0, %d) ORDER BY `uid` DESC LIMIT 1", dbesc(normalise_link($url)), intval($owner["uid"])); - if ($r) { + if (dbm::is_result($r)) { $contact = $r[0]; $contact["uid"] = -1; - } - - if (!$r) { + } else { $r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link($url))); - if ($r) { + if (dbm::is_result($r)) { $contact = $r[0]; $contact["uid"] = -1; $contact["success_update"] = $contact["updated"]; } } - if (!$r) - $contact = owner; + if (!dbm::is_result($r)) { + $contact = $owner; + } if (!isset($contact["poll"])) { $data = probe_url($url); $contact["poll"] = $data["poll"]; - if (!$contact["alias"]) + if (!$contact["alias"]) { $contact["alias"] = $data["alias"]; + } } - if (!isset($contact["alias"])) + if (!isset($contact["alias"])) { $contact["alias"] = $contact["url"]; + } return $contact; } @@ -1687,6 +1781,7 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return object Entry element + * @todo Add type-hints */ private function reshare_entry($doc, $item, $owner, $repeated_guid, $toplevel) { @@ -1699,10 +1794,12 @@ class ostatus { $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' AND NOT `private` AND `network` IN ('%s', '%s', '%s') LIMIT 1", intval($owner["uid"]), dbesc($repeated_guid), dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS)); - if ($r) - $repeated_item = $r[0]; - else + + if (!dbm::is_result($r)) { return false; + } + + $repeated_item = $r[0]; $contact = self::contact_entry($repeated_item['author-link'], $owner); @@ -1753,6 +1850,7 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return object Entry element with "like" + * @todo Add type-hints */ private function like_entry($doc, $item, $owner, $toplevel) { @@ -1790,6 +1888,7 @@ class ostatus { * @param array $contact Contact data of the target * * @return object author element + * @todo Add type-hints */ private function add_person_object($doc, $owner, $contact) { @@ -1836,6 +1935,7 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return object Entry element + * @todo Add type-hints */ private function follow_entry($doc, $item, $owner, $toplevel) { @@ -1898,6 +1998,7 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return object Entry element + * @todo Add type-hints */ private function note_entry($doc, $item, $owner, $toplevel) { @@ -1925,6 +2026,7 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return string The title for the element + * @todo Add type-hints */ private function entry_header($doc, &$entry, $owner, $toplevel) { /// @todo Check if this title stuff is really needed (I guess not) @@ -1960,19 +2062,22 @@ class ostatus { * @param string $title Title for the post * @param string $verb The activity verb * @param bool $complete Add the "status_net" element? + * @todo Add type-hints */ private function entry_content($doc, $entry, $item, $owner, $title, $verb = "", $complete = true) { - if ($verb == "") + if ($verb == "") { $verb = self::construct_verb($item); + } xml::add_element($doc, $entry, "id", $item["uri"]); xml::add_element($doc, $entry, "title", $title); $body = self::format_picture_post($item['body']); - if ($item['title'] != "") + if ($item['title'] != "") { $body = "[b]".$item['title']."[/b]\n\n".$body; + } $body = bbcode($body, false, false, 7); @@ -1998,6 +2103,7 @@ class ostatus { * @param array $item Data of the item that is to be posted * @param array $owner Contact data of the poster * @param $complete + * @todo Add type-hints */ private function entry_footer($doc, $entry, $item, $owner, $complete = true) { @@ -2024,7 +2130,7 @@ class ostatus { $thrparent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", intval($owner["uid"]), dbesc($parent_item)); - if ($thrparent) { + if (dbm::is_result($thrparent)) { $mentioned[$thrparent[0]["author-link"]] = $thrparent[0]["author-link"]; $mentioned[$thrparent[0]["owner-link"]] = $thrparent[0]["owner-link"]; } @@ -2038,10 +2144,13 @@ class ostatus { $tags = item_getfeedtags($item); - if(count($tags)) - foreach($tags as $t) - if ($t[0] == "@") + if (count($tags)) { + foreach ($tags as $t) { + if ($t[0] == "@") { $mentioned[$t[1]] = $t[1]; + } + } + } // Make sure that mentions are accepted (GNU Social has problems with mixing HTTP and HTTPS) $newmentions = array(); @@ -2055,14 +2164,15 @@ class ostatus { $r = q("SELECT `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'", intval($owner["uid"]), dbesc(normalise_link($mention))); - if ($r[0]["forum"] OR $r[0]["prv"]) + if ($r[0]["forum"] OR $r[0]["prv"]) { xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_GROUP, "href" => $mention)); - else + } else { xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_PERSON, "href" => $mention)); + } } if (!$item["private"]) { @@ -2073,10 +2183,13 @@ class ostatus { "href" => "http://activityschema.org/collection/public")); } - if(count($tags)) - foreach($tags as $t) - if ($t[0] != "@") + if (count($tags)) { + foreach ($tags as $t) { + if ($t[0] != "@") { xml::add_element($doc, $entry, "category", "", array("term" => $t[2])); + } + } + } self::get_attachment($doc, $entry, $item); From 6a3dc8b2862e29612d18a73e85c50ce312075696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 10:04:37 +0100 Subject: [PATCH 18/65] added more curly braces + fixed one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/ostatus.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/ostatus.php b/include/ostatus.php index 0337e9a27..2aca1c07d 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -1149,6 +1149,7 @@ class ostatus { $arr["created"] = $single_conv->published; $arr["edited"] = $single_conv->published; $arr["owner-name"] = $single_conv->actor->displayName; + if ($arr["owner-name"] == '') { $arr["owner-name"] = $single_conv->actor->contact->displayName; } @@ -1173,7 +1174,7 @@ class ostatus { $arr["app"] = $single_conv->provider->displayName; } else { $arr["app"] = "OStatus"; - + } $arr["object"] = json_encode($single_conv); $arr["verb"] = $parent["verb"]; @@ -1183,8 +1184,9 @@ class ostatus { // Is it a reshared item? if (isset($single_conv->verb) AND ($single_conv->verb == "share") AND isset($single_conv->object)) { - if (is_array($single_conv->object)) + if (is_array($single_conv->object)) { $single_conv->object = $single_conv->object[0]; + } logger("Found reshared item ".$single_conv->object->id); @@ -1271,7 +1273,7 @@ class ostatus { logger('setting new parent to id '.$newitem); $new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($uid), intval($newitem)); - if ($new_parents) { + if (dbm::is_result($new_parents)) { $parent = $new_parents[0]; } } @@ -1308,16 +1310,18 @@ class ostatus { $conversation_url = self::convert_href($conversation_url); $messages = q("SELECT `uid`, `parent`, `created`, `received`, `guid` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); + if (!dbm::is_result($messages)) { return; } + $message = $messages[0]; // Store conversation url if not done before $conversation = q("SELECT `url` FROM `term` WHERE `uid` = %d AND `oid` = %d AND `otype` = %d AND `type` = %d", intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION)); - if (!$conversation) { + if (!dbm::is_result($conversation)) { $r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`, `created`, `received`, `guid`) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION), dbesc($message["created"]), dbesc($conversation_url), dbesc($message["created"]), dbesc($message["received"]), dbesc($message["guid"])); From cc83e9d72a004c1f033f6587eb6d6a38bf8ada2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 10:07:12 +0100 Subject: [PATCH 19/65] fixed curly brace (opps) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/ostatus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ostatus.php b/include/ostatus.php index 2aca1c07d..d20e4cb4f 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -1245,7 +1245,7 @@ class ostatus { "title", "attach", "app", "type", "location", "contact-id", "uri"); foreach ($copy_fields AS $field) { if (isset($item[$field])) { - $arr[$field] = $item[$field]; { + $arr[$field] = $item[$field]; } } From 958c24e9f3417ace9283362256d08013a8350ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 10:09:54 +0100 Subject: [PATCH 20/65] spaces -> tab + added spaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/settings.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mod/settings.php b/mod/settings.php index b77b1336d..6f57bc0a8 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -364,22 +364,22 @@ function settings_post(App $a) { call_hooks('settings_post', $_POST); - if((x($_POST,'password')) || (x($_POST,'confirm'))) { + if ((x($_POST,'password')) || (x($_POST,'confirm'))) { $newpass = $_POST['password']; $confirm = $_POST['confirm']; $oldpass = hash('whirlpool', $_POST['opassword']); $err = false; - if($newpass != $confirm ) { + if ($newpass != $confirm ) { notice( t('Passwords do not match. Password unchanged.') . EOL); $err = true; } - if((! x($newpass)) || (! x($confirm))) { + if ((! x($newpass)) || (! x($confirm))) { notice( t('Empty passwords are not allowed. Password unchanged.') . EOL); $err = true; - } + } // check if the old password was supplied correctly before // changing it to the new value From 5f71da586274cf09d2df0b1e67ae432598bb7799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 10:12:54 +0100 Subject: [PATCH 21/65] added more curly braces + spaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/settings.php | 74 +++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/mod/settings.php b/mod/settings.php index 6f57bc0a8..4d23621cb 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -391,7 +391,7 @@ function settings_post(App $a) { $err = true; } - if(! $err) { + if (! $err) { $password = hash('whirlpool',$newpass); $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d", dbesc($password), @@ -445,32 +445,41 @@ function settings_post(App $a) { $notify = 0; - if(x($_POST,'notify1')) + if (x($_POST,'notify1')) { $notify += intval($_POST['notify1']); - if(x($_POST,'notify2')) + } + if (x($_POST,'notify2')) { $notify += intval($_POST['notify2']); - if(x($_POST,'notify3')) + } + if (x($_POST,'notify3')) { $notify += intval($_POST['notify3']); - if(x($_POST,'notify4')) + } + if (x($_POST,'notify4')) { $notify += intval($_POST['notify4']); - if(x($_POST,'notify5')) + } + if (x($_POST,'notify5')) { $notify += intval($_POST['notify5']); - if(x($_POST,'notify6')) + } + if (x($_POST,'notify6')) { $notify += intval($_POST['notify6']); - if(x($_POST,'notify7')) + } + if (x($_POST,'notify7')) { $notify += intval($_POST['notify7']); - if(x($_POST,'notify8')) + } + if (x($_POST,'notify8')) { $notify += intval($_POST['notify8']); + } // Adjust the page flag if the account type doesn't fit to the page flag. - if (($account_type == ACCOUNT_TYPE_PERSON) AND !in_array($page_flags, array(PAGE_NORMAL, PAGE_SOAPBOX, PAGE_FREELOVE))) + if (($account_type == ACCOUNT_TYPE_PERSON) AND !in_array($page_flags, array(PAGE_NORMAL, PAGE_SOAPBOX, PAGE_FREELOVE))) { $page_flags = PAGE_NORMAL; - elseif (($account_type == ACCOUNT_TYPE_ORGANISATION) AND !in_array($page_flags, array(PAGE_SOAPBOX))) + } elseif (($account_type == ACCOUNT_TYPE_ORGANISATION) AND !in_array($page_flags, array(PAGE_SOAPBOX))) { $page_flags = PAGE_SOAPBOX; - elseif (($account_type == ACCOUNT_TYPE_NEWS) AND !in_array($page_flags, array(PAGE_SOAPBOX))) + } elseif (($account_type == ACCOUNT_TYPE_NEWS) AND !in_array($page_flags, array(PAGE_SOAPBOX))) { $page_flags = PAGE_SOAPBOX; - elseif (($account_type == ACCOUNT_TYPE_COMMUNITY) AND !in_array($page_flags, array(PAGE_COMMUNITY, PAGE_PRVGROUP))) + } elseif (($account_type == ACCOUNT_TYPE_COMMUNITY) AND !in_array($page_flags, array(PAGE_COMMUNITY, PAGE_PRVGROUP))) { $page_flags = PAGE_COMMUNITY; + } $email_changed = false; @@ -480,13 +489,15 @@ function settings_post(App $a) { if($username != $a->user['username']) { $name_change = true; - if(strlen($username) > 40) + if (strlen($username) > 40) { $err .= t(' Please use a shorter name.'); - if(strlen($username) < 3) + } + if (strlen($username) < 3) { $err .= t(' Name too short.'); + } } - if($email != $a->user['email']) { + if ($email != $a->user['email']) { $email_changed = true; // check for the correct password $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user())); @@ -496,11 +507,12 @@ function settings_post(App $a) { $email = $a->user['email']; } // check the email is valid - if(! valid_email($email)) + if (! valid_email($email)) { $err .= t(' Not valid email.'); + } // ensure new email is not the admin mail //if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0)) { - if(x($a->config,'admin_email')) { + if (x($a->config,'admin_email')) { $adminlist = explode(",", str_replace(" ", "", strtolower($a->config['admin_email']))); if (in_array(strtolower($email), $adminlist)) { $err .= t(' Cannot change to that email.'); @@ -509,14 +521,13 @@ function settings_post(App $a) { } } - if(strlen($err)) { + if (strlen($err)) { notice($err . EOL); return; } - if($timezone != $a->user['timezone']) { - if(strlen($timezone)) - date_default_timezone_set($timezone); + if ($timezone != $a->user['timezone'] && strlen($timezone)) { + date_default_timezone_set($timezone); } $str_group_allow = perms2str($_POST['group_allow']); @@ -529,17 +540,17 @@ function settings_post(App $a) { // If openid has changed or if there's an openid but no openidserver, try and discover it. - if($openid != $a->user['openid'] || (strlen($openid) && (! strlen($openidserver)))) { + if ($openid != $a->user['openid'] || (strlen($openid) && (! strlen($openidserver)))) { $tmp_str = $openid; - if(strlen($tmp_str) && validate_url($tmp_str)) { + if (strlen($tmp_str) && validate_url($tmp_str)) { logger('updating openidserver'); require_once('library/openid.php'); $open_id_obj = new LightOpenID; $open_id_obj->identity = $openid; $openidserver = $open_id_obj->discover($open_id_obj->identity); - } - else + } else { $openidserver = ''; + } } set_pconfig(local_user(),'expire','items', $expire_items); @@ -555,14 +566,13 @@ function settings_post(App $a) { set_pconfig(local_user(),'system','email_textonly', $email_textonly); - if($page_flags == PAGE_PRVGROUP) { + if ($page_flags == PAGE_PRVGROUP) { $hidewall = 1; - if((! $str_contact_allow) && (! $str_group_allow) && (! $str_contact_deny) && (! $str_group_deny)) { - if($def_gid) { + if ((! $str_contact_allow) && (! $str_group_allow) && (! $str_contact_deny) && (! $str_group_deny)) { + if ($def_gid) { info( t('Private forum has no privacy permissions. Using default privacy group.'). EOL); $str_group_allow = '<' . $def_gid . '>'; - } - else { + } else { notice( t('Private forum has no privacy permissions and no default privacy group.') . EOL); } } @@ -673,8 +683,6 @@ function settings_content(App $a) { return; } - - if (($a->argc > 1) && ($a->argv[1] === 'oauth')) { if (($a->argc > 2) && ($a->argv[2] === 'add')) { From 9cb100228a431fbc31ff063b57418a8746b3dd83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 10:13:53 +0100 Subject: [PATCH 22/65] addec curly braces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- util/po2php.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/util/po2php.php b/util/po2php.php index 5d3429796..60736bf4a 100644 --- a/util/po2php.php +++ b/util/po2php.php @@ -12,10 +12,11 @@ function po2php_run(&$argv, &$argc) { $pofile = $argv[1]; $outfile = dirname($pofile)."/strings.php"; - if (strstr($outfile,'util')) + if (strstr($outfile,'util')) { $lang = 'en'; - else + } else { $lang = str_replace('-','_',basename(dirname($pofile))); + } From 15c77beee29ccda758b72fd30a59eca8951459f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 14:28:43 +0100 Subject: [PATCH 23/65] added missing spaces/curly braces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- boot.php | 457 +++++++++++++++++++++++++++++---------------------- index.php | 87 +++++----- testargs.php | 5 +- update.php | 4 +- 4 files changed, 316 insertions(+), 237 deletions(-) diff --git a/boot.php b/boot.php index 72c2e45aa..af11d8476 100644 --- a/boot.php +++ b/boot.php @@ -553,12 +553,12 @@ class App { * beyond are used. */ public $theme = array( - 'sourcename' => '', - 'videowidth' => 425, - 'videoheight' => 350, + 'sourcename' => '', + 'videowidth' => 425, + 'videoheight' => 350, 'force_max_items' => 0, - 'thread_allow' => true, - 'stylesheet' => '', + 'thread_allow' => true, + 'stylesheet' => '', 'template_engine' => 'smarty3', ); @@ -647,7 +647,7 @@ class App { $this->scheme = 'http'; - if((x($_SERVER,'HTTPS') && $_SERVER['HTTPS']) || + if ((x($_SERVER,'HTTPS') && $_SERVER['HTTPS']) || (x($_SERVER['HTTP_FORWARDED']) && preg_match("/proto=https/", $_SERVER['HTTP_FORWARDED'])) || (x($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') || (x($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') || @@ -655,12 +655,12 @@ class App { (x($_SERVER,'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) // XXX: reasonable assumption, but isn't this hardcoding too much? ) { $this->scheme = 'https'; - } + } - if(x($_SERVER,'SERVER_NAME')) { + if (x($_SERVER,'SERVER_NAME')) { $this->hostname = $_SERVER['SERVER_NAME']; - if(x($_SERVER,'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) + if (x($_SERVER,'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) $this->hostname .= ':' . $_SERVER['SERVER_PORT']; /* * Figure out if we are running at the top of a domain @@ -668,7 +668,7 @@ class App { */ $path = trim(dirname($_SERVER['SCRIPT_NAME']),'/\\'); - if(isset($path) && strlen($path) && ($path != $this->path)) + if (isset($path) && strlen($path) && ($path != $this->path)) $this->path = $path; } @@ -704,7 +704,6 @@ class App { // fix query_string $this->query_string = str_replace($this->cmd."&",$this->cmd."?", $this->query_string); - // unix style "homedir" if (substr($this->cmd,0,1) === '~') { @@ -735,11 +734,10 @@ class App { $this->argv = explode('/',$this->cmd); $this->argc = count($this->argv); - if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) { + if ((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) { $this->module = str_replace(".", "_", $this->argv[0]); $this->module = str_replace("-", "_", $this->module); - } - else { + } else { $this->argc = 1; $this->argv = array('home'); $this->module = 'home'; @@ -753,8 +751,9 @@ class App { $this->pager['page'] = ((x($_GET,'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1); $this->pager['itemspage'] = 50; $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage']; - if($this->pager['start'] < 0) + if ($this->pager['start'] < 0) { $this->pager['start'] = 0; + } $this->pager['total'] = 0; /* @@ -786,14 +785,17 @@ class App { $basepath = get_config("system", "basepath"); - if ($basepath == "") + if ($basepath == "") { $basepath = dirname(__FILE__); + } - if ($basepath == "") + if ($basepath == "") { $basepath = $_SERVER["DOCUMENT_ROOT"]; + } - if ($basepath == "") + if ($basepath == "") { $basepath = $_SERVER["PWD"]; + } return($basepath); } @@ -857,7 +859,7 @@ class App { function set_baseurl($url) { $parsed = @parse_url($url); - if($parsed) { + if ($parsed) { $this->scheme = $parsed['scheme']; $hostname = $parsed['host']; @@ -869,7 +871,7 @@ class App { } if (file_exists(".htpreconfig.php")) { - @include(".htpreconfig.php"); + include(".htpreconfig.php"); } if (get_config('config', 'hostname') != '') { @@ -883,8 +885,9 @@ class App { } function get_hostname() { - if (get_config('config','hostname') != "") + if (get_config('config','hostname') != "") { $this->hostname = get_config('config','hostname'); + } return $this->hostname; } @@ -919,44 +922,49 @@ class App { $interval = ((local_user()) ? get_pconfig(local_user(),'system','update_interval') : 40000); // If the update is "deactivated" set it to the highest integer number (~24 days) - if ($interval < 0) + if ($interval < 0) { $interval = 2147483647; + } - if($interval < 10000) + if ($interval < 10000) { $interval = 40000; + } // compose the page title from the sitename and the // current module called - if (!$this->module=='') - { - $this->page['title'] = $this->config['sitename'].' ('.$this->module.')'; + if (!$this->module=='') { + $this->page['title'] = $this->config['sitename'].' ('.$this->module.')'; } else { - $this->page['title'] = $this->config['sitename']; + $this->page['title'] = $this->config['sitename']; } /* put the head template at the beginning of page['htmlhead'] * since the code added by the modules frequently depends on it * being first */ - if(!isset($this->page['htmlhead'])) + if (!isset($this->page['htmlhead'])) { $this->page['htmlhead'] = ''; + } // If we're using Smarty, then doing replace_macros() will replace // any unrecognized variables with a blank string. Since we delay // replacing $stylesheet until later, we need to replace it now // with another variable name - if($this->theme['template_engine'] === 'smarty3') + if ($this->theme['template_engine'] === 'smarty3') { $stylesheet = $this->get_template_ldelim('smarty3') . '$stylesheet' . $this->get_template_rdelim('smarty3'); - else + } else { $stylesheet = '$stylesheet'; + } $shortcut_icon = get_config("system", "shortcut_icon"); - if ($shortcut_icon == "") + if ($shortcut_icon == "") { $shortcut_icon = "images/friendica-32.png"; + } $touch_icon = get_config("system", "touch_icon"); - if ($touch_icon == "") + if ($touch_icon == "") { $touch_icon = "images/friendica-128.png"; + } // get data wich is needed for infinite scroll on the network page $invinite_scroll = infinite_scroll_data($this->module); @@ -978,8 +986,9 @@ class App { } function init_page_end() { - if(!isset($this->page['end'])) + if (!isset($this->page['end'])) { $this->page['end'] = ''; + } $tpl = get_markup_template('end.tpl'); $this->page['end'] = replace_macros($tpl,array( '$baseurl' => $this->get_baseurl() // FIXME for z_path!!!! @@ -1015,13 +1024,13 @@ class App { // The following code is deactivated. It doesn't seem to make any sense and it slows down the system. /* - if($this->cached_profile_image[$avatar_image]) + if ($this->cached_profile_image[$avatar_image]) return $this->cached_profile_image[$avatar_image]; $path_parts = explode("/",$avatar_image); $common_filename = $path_parts[count($path_parts)-1]; - if($this->cached_profile_picdate[$common_filename]){ + if ($this->cached_profile_picdate[$common_filename]){ $this->cached_profile_image[$avatar_image] = $avatar_image . $this->cached_profile_picdate[$common_filename]; } else { $r = q("SELECT `contact`.`avatar-date` AS picdate FROM `contact` WHERE `contact`.`thumb` like '%%/%s'", @@ -1076,7 +1085,7 @@ class App { function register_template_engine($class, $name = '') { if ($name===""){ $v = get_class_vars( $class ); - if(x($v,"name")) $name = $v['name']; + if (x($v,"name")) $name = $v['name']; } if ($name===""){ echo "template engine $class cannot be registered without a name.\n"; @@ -1105,7 +1114,7 @@ class App { } if (isset($this->template_engines[$template_engine])){ - if(isset($this->template_engine_instance[$template_engine])){ + if (isset($this->template_engine_instance[$template_engine])){ return $this->template_engine_instance[$template_engine]; } else { $class = $this->template_engines[$template_engine]; @@ -1134,7 +1143,7 @@ class App { switch($engine) { case 'smarty3': - if(is_writable('view/smarty3/')) + if (is_writable('view/smarty3/')) $this->theme['template_engine'] = 'smarty3'; break; default: @@ -1152,8 +1161,9 @@ class App { } function save_timestamp($stamp, $value) { - if (!isset($this->config['system']['profiler']) || !$this->config['system']['profiler']) + if (!isset($this->config['system']['profiler']) || !$this->config['system']['profiler']) { return; + } $duration = (float)(microtime(true)-$stamp); @@ -1235,8 +1245,9 @@ class App { array_shift($trace); $callstack = array(); - foreach ($trace AS $func) + foreach ($trace AS $func) { $callstack[] = $func["function"]; + } return implode(", ", $callstack); } @@ -1258,31 +1269,33 @@ class App { * @return bool Is it a known backend? */ function is_backend() { - $backend = array(); - $backend[] = "_well_known"; - $backend[] = "api"; - $backend[] = "dfrn_notify"; - $backend[] = "fetch"; - $backend[] = "hcard"; - $backend[] = "hostxrd"; - $backend[] = "nodeinfo"; - $backend[] = "noscrape"; - $backend[] = "p"; - $backend[] = "poco"; - $backend[] = "post"; - $backend[] = "proxy"; - $backend[] = "pubsub"; - $backend[] = "pubsubhubbub"; - $backend[] = "receive"; - $backend[] = "rsd_xml"; - $backend[] = "salmon"; - $backend[] = "statistics_json"; - $backend[] = "xrd"; + static $backend = array( + "_well_known", + "api", + "dfrn_notify", + "fetch", + "hcard", + "hostxrd", + "nodeinfo", + "noscrape", + "p", + "poco", + "post", + "proxy", + "pubsub", + "pubsubhubbub", + "receive", + "rsd_xml", + "salmon", + "statistics_json", + "xrd", + ); - if (in_array($this->module, $backend)) + if (in_array($this->module, $backend)) { return(true); - else + } else { return($this->backend); + } } /** @@ -1295,13 +1308,15 @@ class App { if ($this->is_backend()) { $process = "backend"; $max_processes = get_config('system', 'max_processes_backend'); - if (intval($max_processes) == 0) + if (intval($max_processes) == 0) { $max_processes = 5; + } } else { $process = "frontend"; $max_processes = get_config('system', 'max_processes_frontend'); - if (intval($max_processes) == 0) + if (intval($max_processes) == 0) { $max_processes = 20; + } } $processlist = dbm::processlist(); @@ -1326,13 +1341,15 @@ class App { if ($this->is_backend()) { $process = "backend"; $maxsysload = intval(get_config('system', 'maxloadavg')); - if ($maxsysload < 1) + if ($maxsysload < 1) { $maxsysload = 50; + } } else { $process = "frontend"; $maxsysload = intval(get_config('system','maxloadavg_frontend')); - if ($maxsysload < 1) + if ($maxsysload < 1) { $maxsysload = 50; + } } $load = current_load(); @@ -1368,16 +1385,17 @@ class App { // add baseurl to args. cli scripts can't construct it $args[] = $this->get_baseurl(); - for($x = 0; $x < count($args); $x ++) + for ($x = 0; $x < count($args); $x ++) { $args[$x] = escapeshellarg($args[$x]); + } $cmdline = implode($args," "); - if(get_config('system','proc_windows')) + if (get_config('system','proc_windows')) { proc_close(proc_open('cmd /c start /b ' . $cmdline,array(),$foo,dirname(__FILE__))); - else + } else { proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__))); - + } } /** @@ -1454,17 +1472,17 @@ function get_app() { * @return bool|int */ function x($s,$k = NULL) { - if($k != NULL) { - if((is_array($s)) && (array_key_exists($k,$s))) { - if($s[$k]) + if ($k != NULL) { + if ((is_array($s)) && (array_key_exists($k,$s))) { + if ($s[$k]) { return (int) 1; + } return (int) 0; - } + } return false; - } - else { - if(isset($s)) { - if($s) { + } else { + if (isset($s)) { + if ($s) { return (int) 1; } return (int) 0; @@ -1492,8 +1510,9 @@ function clean_urls() { function z_path() { $base = App::get_baseurl(); - if(! clean_urls()) + if (! clean_urls()) { $base .= '/?q='; + } return $base; } @@ -1518,8 +1537,9 @@ function z_root() { * @return string */ function absurl($path) { - if(strpos($path,'/') === 0) + if (strpos($path,'/') === 0) { return z_path() . $path; + } return $path; } @@ -1535,12 +1555,13 @@ function is_ajax() { function check_db() { $build = get_config('system','build'); - if(! x($build)) { + if (! x($build)) { set_config('system','build',DB_UPDATE_VERSION); $build = DB_UPDATE_VERSION; } - if($build != DB_UPDATE_VERSION) + if ($build != DB_UPDATE_VERSION) { proc_run(PRIORITY_CRITICAL, 'include/dbupdate.php'); + } } @@ -1559,10 +1580,12 @@ function check_url(App $a) { // and www.example.com vs example.com. // We will only change the url to an ip address if there is no existing setting - if(! x($url)) + if (! x($url)) { $url = set_config('system','url',App::get_baseurl()); - if((! link_compare($url,App::get_baseurl())) && (! preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$a->get_hostname))) + } + if ((! link_compare($url,App::get_baseurl())) && (! preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/",$a->get_hostname))) { $url = set_config('system','url',App::get_baseurl()); + } return; } @@ -1573,13 +1596,14 @@ function check_url(App $a) { */ function update_db(App $a) { $build = get_config('system','build'); - if(! x($build)) + if (! x($build)) { $build = set_config('system','build',DB_UPDATE_VERSION); + } - if($build != DB_UPDATE_VERSION) { + if ($build != DB_UPDATE_VERSION) { $stored = intval($build); $current = intval(DB_UPDATE_VERSION); - if($stored < $current) { + if ($stored < $current) { Config::load('database'); // We're reporting a different version than what is currently installed. @@ -1589,12 +1613,13 @@ function update_db(App $a) { // updating right this very second and the correct version of the update.php // file may not be here yet. This can happen on a very busy site. - if(DB_UPDATE_VERSION == UPDATE_VERSION) { + if (DB_UPDATE_VERSION == UPDATE_VERSION) { // Compare the current structure with the defined structure $t = get_config('database','dbupdate_'.DB_UPDATE_VERSION); - if($t !== false) + if ($t !== false) { return; + } set_config('database','dbupdate_'.DB_UPDATE_VERSION, time()); @@ -1602,15 +1627,18 @@ function update_db(App $a) { // conflits with new routine) for ($x = $stored; $x < NEW_UPDATE_ROUTINE_VERSION; $x++) { $r = run_update_function($x); - if (!$r) break; + if (!$r) { + break; + } + } + if ($stored < NEW_UPDATE_ROUTINE_VERSION) { + $stored = NEW_UPDATE_ROUTINE_VERSION; } - if ($stored < NEW_UPDATE_ROUTINE_VERSION) $stored = NEW_UPDATE_ROUTINE_VERSION; - // run new update routine // it update the structure in one call $retval = update_structure(false, true); - if($retval) { + if ($retval) { update_fail( DB_UPDATE_VERSION, $retval @@ -1621,9 +1649,11 @@ function update_db(App $a) { } // run any left update_nnnn functions in update.php - for($x = $stored; $x < $current; $x ++) { + for ($x = $stored; $x < $current; $x ++) { $r = run_update_function($x); - if (!$r) break; + if (!$r) { + break; + } } } } @@ -1633,7 +1663,7 @@ function update_db(App $a) { } function run_update_function($x) { - if(function_exists('update_' . $x)) { + if (function_exists('update_' . $x)) { // There could be a lot of processes running or about to run. // We want exactly one process to run the update command. @@ -1644,8 +1674,9 @@ function run_update_function($x) { // delete the config entry to try again. $t = get_config('database','update_' . $x); - if($t !== false) + if ($t !== false) { return false; + } set_config('database','update_' . $x, time()); // call the specific update @@ -1653,7 +1684,7 @@ function run_update_function($x) { $func = 'update_' . $x; $retval = $func(); - if($retval) { + if ($retval) { //send the administrator an e-mail update_fail( $x, @@ -1686,39 +1717,40 @@ function run_update_function($x) { * * @param App $a * - */ + */ function check_plugins(App $a) { $r = q("SELECT * FROM `addon` WHERE `installed` = 1"); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $installed = $r; - else + } else { $installed = array(); + } $plugins = get_config('system','addon'); $plugins_arr = array(); - if($plugins) + if ($plugins) { $plugins_arr = explode(',',str_replace(' ', '',$plugins)); + } $a->plugins = $plugins_arr; $installed_arr = array(); - if(count($installed)) { - foreach($installed as $i) { - if(! in_array($i['name'],$plugins_arr)) { + if (count($installed)) { + foreach ($installed as $i) { + if (! in_array($i['name'],$plugins_arr)) { uninstall_plugin($i['name']); - } - else { + } else { $installed_arr[] = $i['name']; } } } - if(count($plugins_arr)) { - foreach($plugins_arr as $p) { - if(! in_array($p,$installed_arr)) { + if (count($plugins_arr)) { + foreach ($plugins_arr as $p) { + if (! in_array($p,$installed_arr)) { install_plugin($p); } } @@ -1778,10 +1810,9 @@ function login($register = false, $hiddens=false) { $dest_url = $a->query_string; - if(local_user()) { + if (local_user()) { $tpl = get_markup_template("logout.tpl"); - } - else { + } else { $a->page['htmlhead'] .= replace_macros(get_markup_template("login_head.tpl"),array( '$baseurl' => $a->get_baseurl(true) )); @@ -1793,29 +1824,29 @@ function login($register = false, $hiddens=false) { $o .= replace_macros($tpl, array( - '$dest_url' => $dest_url, - '$logout' => t('Logout'), - '$login' => t('Login'), + '$dest_url' => $dest_url, + '$logout' => t('Logout'), + '$login' => t('Login'), - '$lname' => array('username', t('Nickname or Email: ') , '', ''), - '$lpassword' => array('password', t('Password: '), '', ''), - '$lremember' => array('remember', t('Remember me'), 0, ''), + '$lname' => array('username', t('Nickname or Email: ') , '', ''), + '$lpassword' => array('password', t('Password: '), '', ''), + '$lremember' => array('remember', t('Remember me'), 0, ''), - '$openid' => !$noid, - '$lopenid' => array('openid_url', t('Or login using OpenID: '),'',''), + '$openid' => !$noid, + '$lopenid' => array('openid_url', t('Or login using OpenID: '),'',''), - '$hiddens' => $hiddens, + '$hiddens' => $hiddens, - '$register' => $reg, + '$register' => $reg, '$lostpass' => t('Forgot your password?'), '$lostlink' => t('Password Reset'), - '$tostitle' => t('Website Terms of Service'), - '$toslink' => t('terms of service'), + '$tostitle' => t('Website Terms of Service'), + '$toslink' => t('terms of service'), - '$privacytitle' => t('Website Privacy Policy'), - '$privacylink' => t('privacy policy'), + '$privacytitle' => t('Website Privacy Policy'), + '$privacylink' => t('privacy policy'), )); @@ -1829,8 +1860,9 @@ function login($register = false, $hiddens=false) { */ function killme() { - if (!get_app()->is_backend()) + if (!get_app()->is_backend()) { session_write_close(); + } exit; } @@ -1839,8 +1871,9 @@ function killme() { * @brief Redirect to another URL and terminate this process. */ function goaway($s) { - if (!strstr(normalise_link($s), "http://")) + if (!strstr(normalise_link($s), "http://")) { $s = App::get_baseurl()."/".$s; + } header("Location: $s"); killme(); @@ -1888,8 +1921,9 @@ function public_contact() { * @return int|bool visitor_id or false */ function remote_user() { - if((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id'))) + if ((x($_SESSION,'authenticated')) && (x($_SESSION,'visitor_id'))) { return intval($_SESSION['visitor_id']); + } return false; } @@ -1902,9 +1936,12 @@ function remote_user() { */ function notice($s) { $a = get_app(); - if(! x($_SESSION,'sysmsg')) $_SESSION['sysmsg'] = array(); - if($a->interactive) + if (! x($_SESSION,'sysmsg')) { + $_SESSION['sysmsg'] = array(); + } + if ($a->interactive) { $_SESSION['sysmsg'][] = $s; + } } /** @@ -1917,12 +1954,16 @@ function notice($s) { function info($s) { $a = get_app(); - if (local_user() AND get_pconfig(local_user(),'system','ignore_info')) + if (local_user() AND get_pconfig(local_user(),'system','ignore_info')) { return; + } - if(! x($_SESSION,'sysmsg_info')) $_SESSION['sysmsg_info'] = array(); - if($a->interactive) + if (! x($_SESSION,'sysmsg_info')) { + $_SESSION['sysmsg_info'] = array(); + } + if ($a->interactive) { $_SESSION['sysmsg_info'][] = $s; + } } @@ -1984,8 +2025,9 @@ function proc_run($cmd){ $arr = array('args' => $args, 'run_cmd' => true); call_hooks("proc_run", $arr); - if (!$arr['run_cmd'] OR !count($args)) + if (!$arr['run_cmd'] OR !count($args)) { return; + } $priority = PRIORITY_MEDIUM; $dont_fork = get_config("system", "worker_dont_fork"); @@ -2008,12 +2050,13 @@ function proc_run($cmd){ $found = q("SELECT `id` FROM `workerqueue` WHERE `parameter` = '%s'", dbesc($parameters)); - if (!$found) + if (!dbm::is_result($found)) { q("INSERT INTO `workerqueue` (`parameter`, `created`, `priority`) VALUES ('%s', '%s', %d)", dbesc($parameters), dbesc(datetime_convert()), intval($priority)); + } // Should we quit and wait for the poller to be called as a cronjob? if ($dont_fork) { @@ -2026,12 +2069,14 @@ function proc_run($cmd){ // Get number of allowed number of worker threads $queues = intval(get_config("system", "worker_queues")); - if ($queues == 0) + if ($queues == 0) { $queues = 4; + } // If there are already enough workers running, don't fork another one - if ($workers[0]["workers"] >= $queues) + if ($workers[0]["workers"] >= $queues) { return; + } // Now call the poller to execute the jobs that we just added to the queue $args = array("include/poller.php", "no_cron"); @@ -2048,20 +2093,22 @@ function current_theme(){ // Find the theme that belongs to the user whose stuff we are looking at - if($a->profile_uid && ($a->profile_uid != local_user())) { + if ($a->profile_uid && ($a->profile_uid != local_user())) { $r = q("select theme from user where uid = %d limit 1", intval($a->profile_uid) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $page_theme = $r[0]['theme']; + } } // Allow folks to over-rule user themes and always use their own on their own site. // This works only if the user is on the same server - if($page_theme && local_user() && (local_user() != $a->profile_uid)) { - if(get_pconfig(local_user(),'system','always_my_theme')) + if ($page_theme && local_user() && (local_user() != $a->profile_uid)) { + if (get_pconfig(local_user(),'system','always_my_theme')) { $page_theme = null; + } } // $mobile_detect = new Mobile_Detect(); @@ -2082,38 +2129,44 @@ function current_theme(){ } $theme_name = ((isset($_SESSION) && x($_SESSION,'mobile-theme')) ? $_SESSION['mobile-theme'] : $system_theme); - if($theme_name === '---') { + if ($theme_name === '---') { // user has selected to have the mobile theme be the same as the normal one $system_theme = $standard_system_theme; $theme_name = $standard_theme_name; - if($page_theme) + if ($page_theme) { $theme_name = $page_theme; + } } } - } - else { + } else { $system_theme = $standard_system_theme; $theme_name = $standard_theme_name; - if($page_theme) + if ($page_theme) { $theme_name = $page_theme; + } } - if($theme_name && + if ($theme_name && (file_exists('view/theme/' . $theme_name . '/style.css') || - file_exists('view/theme/' . $theme_name . '/style.php'))) + file_exists('view/theme/' . $theme_name . '/style.php'))) { return($theme_name); + } - foreach($app_base_themes as $t) { - if(file_exists('view/theme/' . $t . '/style.css')|| - file_exists('view/theme/' . $t . '/style.php')) + foreach ($app_base_themes as $t) { + if (file_exists('view/theme/' . $t . '/style.css') || + file_exists('view/theme/' . $t . '/style.php')) { return($t); + } } $fallback = array_merge(glob('view/theme/*/style.css'),glob('view/theme/*/style.php')); - if(count($fallback)) + if (count($fallback)) { return (str_replace('view/theme/','', substr($fallback[0],0,-10))); + } + + /// @TODO No final return statement? } @@ -2130,8 +2183,9 @@ function current_theme_url() { $t = current_theme(); $opts = (($a->profile_uid) ? '?f=&puid=' . $a->profile_uid : ''); - if (file_exists('view/theme/' . $t . '/style.php')) + if (file_exists('view/theme/' . $t . '/style.php')) { return('view/theme/'.$t.'/style.pcss'.$opts); + } return('view/theme/'.$t.'/style.css'); } @@ -2160,8 +2214,9 @@ function feed_birthday($uid,$tz) { $birthday = ''; - if(! strlen($tz)) + if (! strlen($tz)) { $tz = 'UTC'; + } $p = q("SELECT `dob` FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1", intval($uid) @@ -2169,13 +2224,14 @@ function feed_birthday($uid,$tz) { if (dbm::is_result($p)) { $tmp_dob = substr($p[0]['dob'],5); - if(intval($tmp_dob)) { + if (intval($tmp_dob)) { $y = datetime_convert($tz,$tz,'now','Y'); $bd = $y . '-' . $tmp_dob . ' 00:00'; $t_dob = strtotime($bd); $now = strtotime(datetime_convert($tz,$tz,'now')); - if($t_dob < $now) + if ($t_dob < $now) { $bd = $y + 1 . '-' . $tmp_dob . ' 00:00'; + } $birthday = datetime_convert($tz,'UTC',$bd,ATOM_TIME); } } @@ -2193,8 +2249,8 @@ function is_site_admin() { $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email'])); - //if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email'])) - if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && in_array($a->user['email'], $adminlist)) + //if (local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email'])) + if (local_user() && x($a->user,'email') && x($a->config,'admin_email') && in_array($a->user['email'], $adminlist)) return true; return false; } @@ -2209,16 +2265,16 @@ function is_site_admin() { */ function build_querystring($params, $name=null) { $ret = ""; - foreach($params as $key=>$val) { - if(is_array($val)) { - if($name==null) { + foreach ($params as $key=>$val) { + if (is_array($val)) { + if ($name==null) { $ret .= build_querystring($val, $key); } else { $ret .= build_querystring($val, $name."[$key]"); } } else { $val = urlencode($val); - if($name!=null) { + if ($name!=null) { $ret.=$name."[$key]"."=$val&"; } else { $ret.= "$key=$val&"; @@ -2230,7 +2286,7 @@ function build_querystring($params, $name=null) { function explode_querystring($query) { $arg_st = strpos($query, '?'); - if($arg_st !== false) { + if ($arg_st !== false) { $base = substr($query, 0, $arg_st); $arg_st += 1; } else { @@ -2239,13 +2295,14 @@ function explode_querystring($query) { } $args = explode('&', substr($query, $arg_st)); - foreach($args as $k=>$arg) { - if($arg === '') + foreach ($args as $k=>$arg) { + if ($arg === '') { unset($args[$k]); + } } $args = array_values($args); - if(!$base) { + if (!$base) { $base = $args[0]; unset($args[0]); $args = array_values($args); @@ -2264,7 +2321,9 @@ function explode_querystring($query) { */ function curPageURL() { $pageURL = 'http'; - if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} + if ($_SERVER["HTTPS"] == "on") { + $pageURL .= "s"; + } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; @@ -2276,7 +2335,7 @@ function curPageURL() { function random_digits($digits) { $rn = ''; - for($i = 0; $i < $digits; $i++) { + for ($i = 0; $i < $digits; $i++) { $rn .= rand(0,9); } return $rn; @@ -2285,8 +2344,9 @@ function random_digits($digits) { function get_server() { $server = get_config("system", "directory"); - if ($server == "") + if ($server == "") { $server = "http://dir.friendi.ca"; + } return($server); } @@ -2294,8 +2354,9 @@ function get_server() { function get_cachefile($file, $writemode = true) { $cache = get_itemcachepath(); - if ((! $cache) || (! is_dir($cache))) + if ((! $cache) || (! is_dir($cache))) { return(""); + } $subfolder = $cache."/".substr($file, 0, 2); @@ -2317,24 +2378,29 @@ function clear_cache($basepath = "", $path = "") { $path = $basepath; } - if (($path == "") OR (!is_dir($path))) + if (($path == "") OR (!is_dir($path))) { return; + } - if (substr(realpath($path), 0, strlen($basepath)) != $basepath) + if (substr(realpath($path), 0, strlen($basepath)) != $basepath) { return; + } $cachetime = (int)get_config('system','itemcache_duration'); - if ($cachetime == 0) + if ($cachetime == 0) { $cachetime = 86400; + } if (is_writable($path)){ if ($dh = opendir($path)) { while (($file = readdir($dh)) !== false) { $fullpath = $path."/".$file; - if ((filetype($fullpath) == "dir") and ($file != ".") and ($file != "..")) + if ((filetype($fullpath) == "dir") and ($file != ".") and ($file != "..")) { clear_cache($basepath, $fullpath); - if ((filetype($fullpath) == "file") and (filectime($fullpath) < (time() - $cachetime))) + } + if ((filetype($fullpath) == "file") and (filectime($fullpath) < (time() - $cachetime))) { unlink($fullpath); + } } closedir($dh); } @@ -2344,8 +2410,9 @@ function clear_cache($basepath = "", $path = "") { function get_itemcachepath() { // Checking, if the cache is deactivated $cachetime = (int)get_config('system','itemcache_duration'); - if ($cachetime < 0) + if ($cachetime < 0) { return ""; + } $itemcache = get_config('system','itemcache'); if (($itemcache != "") AND App::directory_usable($itemcache)) { @@ -2356,7 +2423,7 @@ function get_itemcachepath() { if ($temppath != "") { $itemcache = $temppath."/itemcache"; - if(!file_exists($itemcache) && !is_dir($itemcache)) { + if (!file_exists($itemcache) && !is_dir($itemcache)) { mkdir($itemcache); } @@ -2448,7 +2515,7 @@ function set_template_engine(App $a, $engine = 'internal') { $a->set_template_engine($engine); } -if(!function_exists('exif_imagetype')) { +if (!function_exists('exif_imagetype')) { function exif_imagetype($file) { $size = getimagesize($file); return($size[2]); @@ -2460,37 +2527,42 @@ function validate_include(&$file) { $file = realpath($file); - if (strpos($file, getcwd()) !== 0) + if (strpos($file, getcwd()) !== 0) { return false; + } $file = str_replace(getcwd()."/", "", $file, $count); - if ($count != 1) + if ($count != 1) { return false; + } - if ($orig_file !== $file) + if ($orig_file !== $file) { return false; + } $valid = false; - if (strpos($file, "include/") === 0) + if (strpos($file, "include/") === 0) { $valid = true; + } - if (strpos($file, "addon/") === 0) + if (strpos($file, "addon/") === 0) { $valid = true; + } - if (!$valid) - return false; - - return true; + // Simply return flag + return ($valid); } function current_load() { - if (!function_exists('sys_getloadavg')) + if (!function_exists('sys_getloadavg')) { return false; + } $load_arr = sys_getloadavg(); - if (!is_array($load_arr)) + if (!is_array($load_arr)) { return false; + } return max($load_arr[0], $load_arr[1]); } @@ -2511,8 +2583,9 @@ function argc() { * @return string Value of the argv key */ function argv($x) { - if(array_key_exists($x,get_app()->argv)) + if (array_key_exists($x,get_app()->argv)) { return get_app()->argv[$x]; + } return ''; } diff --git a/index.php b/index.php index 7408f495c..d3310ba1a 100644 --- a/index.php +++ b/index.php @@ -28,17 +28,17 @@ $a->backend = false; /** * * Load the configuration file which contains our DB credentials. - * Ignore errors. If the file doesn't exist or is empty, we are running in installation mode. + * Ignore errors. If the file doesn't exist or is empty, we are running in + * installation mode. * */ $install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false : true); -@include(".htconfig.php"); - - - - +// Only load config if found, don't surpress errors +if (!$install) { + include(".htconfig.php"); +} /** * @@ -48,7 +48,7 @@ $install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false require_once("include/dba.php"); -if(!$install) { +if (!$install) { $db = new dba($db_host, $db_user, $db_pass, $db_data, $install); unset($db_host, $db_user, $db_pass, $db_data); @@ -117,12 +117,12 @@ if (x($_SESSION,'authenticated') && !x($_SESSION,'language')) { if (dbm::is_result($r)) $_SESSION['language'] = $r[0]['language']; } -if((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) { +if ((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) { $lang = $_SESSION['language']; load_translation_table($lang); } -if((x($_GET,'zrl')) && (!$install && !$maintenance)) { +if ((x($_GET,'zrl')) && (!$install && !$maintenance)) { // Only continue when the given profile link seems valid // Valid profile links contain a path with "/profile/" and no query parameters if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == "") AND @@ -223,7 +223,7 @@ if ((local_user()) || (! $privateapps === "1")) { * further processing. */ -if(strlen($a->module)) { +if (strlen($a->module)) { /** * @@ -233,12 +233,14 @@ if(strlen($a->module)) { */ // Compatibility with the Android Diaspora client - if ($a->module == "stream") + if ($a->module == "stream") { $a->module = "network"; + } // Compatibility with the Firefox App - if (($a->module == "users") AND ($a->cmd == "users/sign_in")) + if (($a->module == "users") AND ($a->cmd == "users/sign_in")) { $a->module = "login"; + } $privateapps = get_config('config','private_addons'); @@ -246,11 +248,11 @@ if(strlen($a->module)) { //Check if module is an app and if public access to apps is allowed or not if ((!local_user()) && plugin_is_app($a->module) && $privateapps === "1") { info( t("You must be logged in to use addons. ")); - } - else { + } else { include_once("addon/{$a->module}/{$a->module}.php"); - if(function_exists($a->module . '_module')) + if (function_exists($a->module . '_module')) { $a->module_loaded = true; + } } } @@ -320,29 +322,29 @@ if (!$install && !$maintenance) { * Call module functions */ -if($a->module_loaded) { +if ($a->module_loaded) { $a->page['page_title'] = $a->module; $placeholder = ''; - if(function_exists($a->module . '_init')) { + if (function_exists($a->module . '_init')) { call_hooks($a->module . '_mod_init', $placeholder); $func = $a->module . '_init'; $func($a); } - if(function_exists(str_replace('-','_',current_theme()) . '_init')) { + if (function_exists(str_replace('-','_',current_theme()) . '_init')) { $func = str_replace('-','_',current_theme()) . '_init'; $func($a); } // elseif (x($a->theme_info,"extends") && file_exists("view/theme/".$a->theme_info["extends"]."/theme.php")) { // require_once("view/theme/".$a->theme_info["extends"]."/theme.php"); -// if(function_exists(str_replace('-','_',$a->theme_info["extends"]) . '_init')) { +// if (function_exists(str_replace('-','_',$a->theme_info["extends"]) . '_init')) { // $func = str_replace('-','_',$a->theme_info["extends"]) . '_init'; // $func($a); // } // } - if(($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error) + if (($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error) && (function_exists($a->module . '_post')) && (! x($_POST,'auth-params'))) { call_hooks($a->module . '_mod_post', $_POST); @@ -350,13 +352,13 @@ if($a->module_loaded) { $func($a); } - if((! $a->error) && (function_exists($a->module . '_afterpost'))) { + if ((! $a->error) && (function_exists($a->module . '_afterpost'))) { call_hooks($a->module . '_mod_afterpost',$placeholder); $func = $a->module . '_afterpost'; $func($a); } - if((! $a->error) && (function_exists($a->module . '_content'))) { + if ((! $a->error) && (function_exists($a->module . '_content'))) { $arr = array('content' => $a->page['content']); call_hooks($a->module . '_mod_content', $arr); $a->page['content'] = $arr['content']; @@ -366,7 +368,7 @@ if($a->module_loaded) { $a->page['content'] .= $arr['content']; } - if(function_exists(str_replace('-','_',current_theme()) . '_content_loaded')) { + if (function_exists(str_replace('-','_',current_theme()) . '_content_loaded')) { $func = str_replace('-','_',current_theme()) . '_content_loaded'; $func($a); } @@ -392,18 +394,20 @@ $a->init_page_end(); // If you're just visiting, let javascript take you home -if(x($_SESSION,'visitor_home')) +if (x($_SESSION,'visitor_home')) { $homebase = $_SESSION['visitor_home']; -elseif(local_user()) +} elseif (local_user()) { $homebase = 'profile/' . $a->user['nickname']; +} -if(isset($homebase)) +if (isset($homebase)) { $a->page['content'] .= ''; +} // now that we've been through the module content, see if the page reported // a permission problem and if so, a 403 response would seem to be in order. -if(stristr( implode("",$_SESSION['sysmsg']), t('Permission denied'))) { +if (stristr( implode("",$_SESSION['sysmsg']), t('Permission denied'))) { header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.')); } @@ -413,13 +417,13 @@ if(stristr( implode("",$_SESSION['sysmsg']), t('Permission denied'))) { * */ -/*if(x($_SESSION,'sysmsg')) { +/*if (x($_SESSION,'sysmsg')) { $a->page['content'] = "
{$_SESSION['sysmsg']}
\r\n" . ((x($a->page,'content')) ? $a->page['content'] : ''); $_SESSION['sysmsg']=""; unset($_SESSION['sysmsg']); } -if(x($_SESSION,'sysmsg_info')) { +if (x($_SESSION,'sysmsg_info')) { $a->page['content'] = "
{$_SESSION['sysmsg_info']}
\r\n" . ((x($a->page,'content')) ? $a->page['content'] : ''); $_SESSION['sysmsg_info']=""; @@ -437,7 +441,7 @@ call_hooks('page_end', $a->page['content']); * */ -if($a->module != 'install' && $a->module != 'maintenance') { +if ($a->module != 'install' && $a->module != 'maintenance') { nav($a); } @@ -445,27 +449,27 @@ if($a->module != 'install' && $a->module != 'maintenance') { * Add a "toggle mobile" link if we're using a mobile device */ -if($a->is_mobile || $a->is_tablet) { - if(isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) { +if ($a->is_mobile || $a->is_tablet) { + if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) { $link = 'toggle_mobile?address=' . curPageURL(); - } - else { + } else { $link = 'toggle_mobile?off=1&address=' . curPageURL(); } $a->page['footer'] = replace_macros(get_markup_template("toggle_mobile_footer.tpl"), array( - '$toggle_link' => $link, - '$toggle_text' => t('toggle mobile') - )); + '$toggle_link' => $link, + '$toggle_text' => t('toggle mobile') + )); } /** * Build the page - now that we have all the components */ -if(!$a->theme['stylesheet']) +if (!$a->theme['stylesheet']) { $stylesheet = current_theme_url(); -else +} else { $stylesheet = $a->theme['stylesheet']; +} $a->page['htmlhead'] = str_replace('{{$stylesheet}}',$stylesheet,$a->page['htmlhead']); //$a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array('$stylesheet' => $stylesheet)); @@ -499,8 +503,9 @@ if (isset($_GET["mode"]) AND ($_GET["mode"] == "raw")) { echo substr($target->saveHTML(), 6, -8); - if (!$a->is_backend()) + if (!$a->is_backend()) { session_write_close(); + } exit; } @@ -519,7 +524,7 @@ if (isset($_GET["mode"])) { } // If there is no page template use the default page template -if(!$template) { +if (!$template) { $template = theme_include("default.php"); } diff --git a/testargs.php b/testargs.php index a6042f8eb..a0ddea345 100644 --- a/testargs.php +++ b/testargs.php @@ -15,7 +15,8 @@ */ -if(($_SERVER["argc"] > 1) && isset($_SERVER["argv"][1])) +if (($_SERVER["argc"] > 1) && isset($_SERVER["argv"][1])) { echo $_SERVER["argv"][1]; -else +} else { echo ''; +} diff --git a/update.php b/update.php index bc0e17b8b..7c3b32e2d 100644 --- a/update.php +++ b/update.php @@ -148,7 +148,7 @@ function update_1014() { if (dbm::is_result($r)) { foreach ($r as $rr) { $ph = new Photo($rr['data']); - if($ph->is_valid()) { + if ($ph->is_valid()) { $ph->scaleImage(48); $ph->store($rr['uid'],$rr['contact-id'],$rr['resource-id'],$rr['filename'],$rr['album'],6,(($rr['profile']) ? 1 : 0)); } @@ -1756,7 +1756,7 @@ function update_1190() { $plugins = get_config('system','addon'); $plugins_arr = array(); - if($plugins) { + if ($plugins) { $plugins_arr = explode(",",str_replace(" ", "",$plugins)); $idx = array_search($plugin, $plugins_arr); From 720e7d6034abf216a444bf44b3965db067a3ef49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 14:44:46 +0100 Subject: [PATCH 24/65] curly braces + spaces added MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- util/db_update.php | 2 +- util/docblox_errorchecker.php | 24 ++++----- util/extract.php | 27 +++++----- util/maintenance.php | 8 +-- util/php2po.php | 8 +-- util/po2php.php | 56 ++++++++++++++------- util/typo.php | 93 +++++++++++++++++------------------ 7 files changed, 121 insertions(+), 97 deletions(-) diff --git a/util/db_update.php b/util/db_update.php index 32b44e6d0..7718162f6 100644 --- a/util/db_update.php +++ b/util/db_update.php @@ -24,7 +24,7 @@ echo "Old DB VERSION: " . $build . "\n"; echo "New DB VERSION: " . DB_UPDATE_VERSION . "\n"; -if($build != DB_UPDATE_VERSION) { +if ($build != DB_UPDATE_VERSION) { echo "Updating database..."; check_db($a); echo "Done\n"; diff --git a/util/docblox_errorchecker.php b/util/docblox_errorchecker.php index af4c76444..a7d1ecce1 100644 --- a/util/docblox_errorchecker.php +++ b/util/docblox_errorchecker.php @@ -33,7 +33,7 @@ */ function namesList($fileset) { $fsparam=""; - foreach($fileset as $file) { + foreach ($fileset as $file) { $fsparam=$fsparam.",".$file; } return $fsparam; @@ -50,7 +50,7 @@ function namesList($fileset) { function runs($fileset) { $fsParam=namesList($fileset); exec('docblox -t phpdoc_out -f '.$fsParam); - if(file_exists("phpdoc_out/index.html")) { + if (file_exists("phpdoc_out/index.html")) { echo "\n Subset ".$fsParam." is okay. \n"; exec('rm -r phpdoc_out'); return true; @@ -79,7 +79,7 @@ function reduce($fileset, $ps) { //filter working subsets... $parts=array_filter($parts, "runs"); //melt remaining parts together - if(is_array($parts)) { + if (is_array($parts)) { return array_reduce($parts, "array_merge", array()); } return array(); @@ -94,17 +94,17 @@ $dirstack=array(); $filelist=array(); //loop over all files in $dir -while($dh=opendir($dir)) { - while($file=readdir($dh)) { - if(is_dir($dir."/".$file)) { +while ($dh=opendir($dir)) { + while ($file=readdir($dh)) { + if (is_dir($dir."/".$file)) { //add to directory stack - if($file!=".." && $file!=".") { + if ($file!=".." && $file!=".") { array_push($dirstack, $dir."/".$file); echo "dir ".$dir."/".$file."\n"; } } else { //test if it is a source file and add to filelist - if(substr($file, strlen($file)-4)==".php") { + if (substr($file, strlen($file)-4)==".php") { array_push($filelist, $dir."/".$file); echo $dir."/".$file."\n"; } @@ -115,7 +115,7 @@ while($dh=opendir($dir)) { } //check the entire set -if(runs($filelist)) { +if (runs($filelist)) { echo "I can not detect a problem. \n"; exit; } @@ -128,15 +128,15 @@ do { echo $i."/".count($fileset)." elements remaining. \n"; $res=reduce($res, count($res)/2); shuffle($res); -} while(count($res)<$i); +} while (count($res)<$i); //check one file after another $needed=array(); -while(count($res)!=0) { +while (count($res)!=0) { $file=array_pop($res); - if(runs(array_merge($res, $needed))) { + if (runs(array_merge($res, $needed))) { echo "needs: ".$file." and file count ".count($needed); array_push($needed, $file); } diff --git a/util/extract.php b/util/extract.php index 90127f3c1..3eb332d4f 100644 --- a/util/extract.php +++ b/util/extract.php @@ -6,7 +6,7 @@ $files = array_merge($files,glob('mod/*'),glob('include/*'),glob('addon/*/*')); - foreach($files as $file) { + foreach ($files as $file) { $str = file_get_contents($file); $pat = '| t\(([^\)]*)\)|'; @@ -16,14 +16,14 @@ preg_match_all($patt, $str, $matchestt); - if(count($matches)){ - foreach($matches[1] as $match) { - if(! in_array($match,$arr)) + if (count($matches)){ + foreach ($matches[1] as $match) { + if (! in_array($match,$arr)) $arr[] = $match; } } - if(count($matchestt)){ - foreach($matchestt[1] as $match) { + if (count($matchestt)){ + foreach ($matchestt[1] as $match) { $matchtkns = preg_split("|[ \t\r\n]*,[ \t\r\n]*|",$match); if (count($matchtkns)==3 && !in_array($matchtkns,$arr)){ $arr[] = $matchtkns; @@ -41,23 +41,26 @@ function string_plural_select($n){ '; - foreach($arr as $a) { + foreach ($arr as $a) { if (is_array($a)){ - if(substr($a[1],0,1) == '$') + if (substr($a[1],0,1) == '$') { continue; + } $s .= '$a->strings[' . $a[0] . "] = array(\n"; $s .= "\t0 => ". $a[0]. ",\n"; $s .= "\t1 => ". $a[1]. ",\n"; $s .= ");\n"; } else { - if(substr($a,0,1) == '$') - continue; + if (substr($a,0,1) == '$') { + continue; + } $s .= '$a->strings[' . $a . '] = '. $a . ';' . "\n"; } } $zones = timezone_identifiers_list(); - foreach($zones as $zone) + foreach ($zones as $zone) { $s .= '$a->strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n"; - + } + echo $s; \ No newline at end of file diff --git a/util/maintenance.php b/util/maintenance.php index 28f3a503a..17f64ecc7 100644 --- a/util/maintenance.php +++ b/util/maintenance.php @@ -17,14 +17,16 @@ unset($db_host, $db_user, $db_pass, $db_data); Config::load(); $maint_mode = 1; -if($argc > 1) +if ($argc > 1) { $maint_mode = intval($argv[1]); +} set_config('system', 'maintenance', $maint_mode); -if($maint_mode) +if ($maint_mode) { $mode_str = "maintenance mode"; -else +} else { $mode_str = "normal mode"; +} echo "\n\tSystem set in $mode_str\n\n"; echo "Usage:\n\n"; diff --git a/util/php2po.php b/util/php2po.php index 2e888008c..8bc4ce8c6 100644 --- a/util/php2po.php +++ b/util/php2po.php @@ -10,7 +10,7 @@ DEFINE("NORM_REGEXP", "|[\\\]|"); - if(! class_exists('App')) { + if (! class_exists('App')) { class TmpA { public $strings = Array(); } @@ -68,7 +68,7 @@ } $infile = file($phpfile); - foreach($infile as $l) { + foreach ($infile as $l) { $l = trim($l); if (startsWith($l, 'function string_plural_select_')) { $lang = str_replace( 'function string_plural_select_' , '', str_replace( '($n){','', $l) ); @@ -94,7 +94,7 @@ $norm_base_msgids = array(); $base_f = file("util/messages.po") or die("No base messages.po\n"); $_f = 0; $_mid = ""; $_mids = array(); - foreach( $base_f as $l) { + foreach ( $base_f as $l) { $l = trim($l); //~ print $l."\n"; @@ -165,7 +165,7 @@ } $warnings = ""; - foreach($a->strings as $key=>$str) { + foreach ($a->strings as $key=>$str) { $msgid = massage_string($key); if (preg_match("|%[sd0-9](\$[sn])*|", $msgid)) { diff --git a/util/po2php.php b/util/po2php.php index 60736bf4a..86c41236e 100644 --- a/util/po2php.php +++ b/util/po2php.php @@ -42,34 +42,45 @@ function po2php_run(&$argv, &$argc) { foreach ($infile as $l) { $l = str_replace('\"', DQ_ESCAPE, $l); $len = strlen($l); - if ($l[0]=="#") $l=""; - if (substr($l,0,15)=='"Plural-Forms: '){ + if ($l[0]=="#") { + $l=""; + } + if (substr($l,0,15) == '"Plural-Forms: '){ $match=Array(); preg_match("|nplurals=([0-9]*); *plural=(.*)[;\\\\]|", $l, $match); $cond = str_replace('n','$n',$match[2]); // define plural select function if not already defined $fnname = 'string_plural_select_' . $lang; - $out .= 'if(! function_exists("'.$fnname.'")) {'."\n"; + $out .= 'if (! function_exists("'.$fnname.'")) {'."\n"; $out .= 'function '. $fnname . '($n){'."\n"; $out .= ' return '.$cond.';'."\n"; $out .= '}}'."\n"; } - - - - if ($k!="" && substr($l,0,7)=="msgstr "){ - if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; } - if ($inv) { $inv = False; $out .= '"'.$v.'"'; } + if ($k!="" && substr($l,0,7) == "msgstr "){ + if ($ink) { + $ink = False; + $out .= '$a->strings["'.$k.'"] = '; + } + if ($inv) { + $inv = False; + $out .= '"'.$v.'"'; + } $v = substr($l,8,$len-10); $v = preg_replace_callback($escape_s_exp,'escape_s',$v); $inv = True; //$out .= $v; } - if ($k!="" && substr($l,0,7)=="msgstr["){ - if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; } - if ($inv) { $inv = False; $out .= '"'.$v.'"'; } + if ($k!="" && substr($l,0,7) == "msgstr["){ + if ($ink) { + $ink = False; + $out .= '$a->strings["'.$k.'"] = '; + } + if ($inv) { + $inv = False; + $out .= '"'.$v.'"'; + } if (!$arr) { $arr=True; @@ -85,7 +96,6 @@ function po2php_run(&$argv, &$argc) { if (substr($l,0,6)=="msgid_") { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }; - if ($ink) { $k .= trim($l,"\"\r\n"); $k = preg_replace_callback($escape_s_exp,'escape_s',$k); @@ -93,9 +103,14 @@ function po2php_run(&$argv, &$argc) { } if (substr($l,0,6)=="msgid "){ - if ($inv) { $inv = False; $out .= '"'.$v.'"'; } - if ($k!="") $out .= $arr?");\n":";\n"; - $arr=False; + if ($inv) { + $inv = False; + $out .= '"'.$v.'"'; + } + if ($k != "") { + $out .= $arr?");\n":";\n"; + } + $arr = False; $k = str_replace("msgid ","",$l); if ($k != '""' ) { $k = trim($k,"\"\r\n"); @@ -116,8 +131,13 @@ function po2php_run(&$argv, &$argc) { } - if ($inv) { $inv = False; $out .= '"'.$v.'"'; } - if ($k!="") $out .= $arr?");\n":";\n"; + if ($inv) { + $inv = False; + $out .= '"'.$v.'"'; + } + if ($k!="") { + $out .= $arr?");\n":";\n"; + } $out = str_replace(DQ_ESCAPE, '\"', $out); file_put_contents($outfile, $out); diff --git a/util/typo.php b/util/typo.php index d68ac2ac9..c45be483c 100644 --- a/util/typo.php +++ b/util/typo.php @@ -1,59 +1,58 @@ config,'php_path')) - $phpath = $a->config['php_path']; - else - $phpath = 'php'; +if (x($a->config,'php_path')) { + $phpath = $a->config['php_path']; +} else { + $phpath = 'php'; +} +echo "Directory: mod\n"; +$files = glob('mod/*.php'); +foreach ($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); +} - echo "Directory: mod\n"; - $files = glob('mod/*.php'); - foreach($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); +echo "Directory: include\n"; +$files = glob('include/*.php'); +foreach ($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); +} + +echo "Directory: object\n"; +$files = glob('object/*.php'); +foreach ($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); +} + +echo "Directory: addon\n"; +$dirs = glob('addon/*'); + +foreach ($dirs as $dir) { + $addon = basename($dir); + $files = glob($dir . '/' . $addon . '.php'); + foreach ($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); } +} - echo "Directory: include\n"; - $files = glob('include/*.php'); - foreach($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); - } +echo "String files\n"; - echo "Directory: object\n"; - $files = glob('object/*.php'); - foreach($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); - } +echo 'util/strings.php' . "\n"; +passthru("$phpath -l util/strings.php", $ret); $ret===0 or die(); - echo "Directory: addon\n"; - $dirs = glob('addon/*'); - - foreach($dirs as $dir) { - $addon = basename($dir); - $files = glob($dir . '/' . $addon . '.php'); - foreach($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); - } - } - - - echo "String files\n"; - - echo 'util/strings.php' . "\n"; - passthru("$phpath -l util/strings.php", $ret); $ret===0 or die(); - - $files = glob('view/lang/*/strings.php'); - foreach($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); - } +$files = glob('view/lang/*/strings.php'); +foreach ($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); +} From 0cd241bcbe762e38e2eba0c58800eb60a2240e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 15:23:30 +0100 Subject: [PATCH 25/65] added spaces + some curly braces + some usage of dbm::is_result() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/_well_known.php | 2 +- mod/acctlink.php | 4 +- mod/admin.php | 9 ++- mod/allfriends.php | 3 +- mod/api.php | 2 +- mod/apps.php | 22 +++--- mod/attach.php | 4 +- mod/babel.php | 4 +- mod/cal.php | 59 +++++++------- mod/common.php | 11 +-- mod/community.php | 13 ++-- mod/contactgroup.php | 19 ++--- mod/contacts.php | 60 +++++++------- mod/content.php | 155 ++++++++++++++++++------------------ mod/crepair.php | 4 +- mod/delegate.php | 41 ++++++---- mod/dfrn_confirm.php | 94 +++++++++++----------- mod/dfrn_notify.php | 38 +++++---- mod/dfrn_poll.php | 76 +++++++++--------- mod/dfrn_request.php | 60 +++++++------- mod/directory.php | 35 +++++---- mod/dirfind.php | 3 +- mod/editpost.php | 8 +- mod/events.php | 62 ++++++++------- mod/fbrowser.php | 5 +- mod/filer.php | 2 +- mod/friendica.php | 26 ++++--- mod/fsuggest.php | 5 +- mod/group.php | 48 ++++++------ mod/help.php | 21 +++-- mod/home.php | 4 +- mod/hostxrd.php | 2 +- mod/hovercard.php | 14 ++-- mod/ignored.php | 7 +- mod/install.php | 20 ++--- mod/invite.php | 2 +- mod/item.php | 177 +++++++++++++++++++++++------------------- mod/like.php | 18 +++-- mod/localtime.php | 15 ++-- mod/lockview.php | 38 +++++---- mod/login.php | 9 ++- mod/lostpass.php | 7 +- mod/manage.php | 32 ++++---- mod/match.php | 14 ++-- mod/message.php | 97 ++++++++++++----------- mod/modexp.php | 2 +- mod/mood.php | 14 ++-- mod/msearch.php | 4 +- mod/network.php | 124 +++++++++++++++-------------- mod/newmember.php | 5 +- mod/nodeinfo.php | 6 +- mod/noscrape.php | 7 +- mod/notes.php | 5 +- mod/notifications.php | 27 +++---- mod/openid.php | 12 +-- mod/parse_url.php | 4 +- mod/photo.php | 25 +++--- mod/photos.php | 5 +- mod/ping.php | 4 +- mod/poco.php | 35 +++++---- mod/poke.php | 12 +-- mod/post.php | 9 ++- mod/pretheme.php | 7 +- mod/probe.php | 2 +- mod/profile.php | 28 +++---- mod/profile_photo.php | 24 +++--- mod/profiles.php | 103 ++++++++++++------------ mod/profperm.php | 30 +++---- mod/pubsub.php | 15 ++-- mod/pubsubhubbub.php | 4 +- mod/qsearch.php | 14 ++-- mod/receive.php | 12 +-- mod/redir.php | 12 +-- mod/register.php | 42 +++++----- mod/regmod.php | 5 +- mod/salmon.php | 28 +++---- mod/search.php | 32 ++++---- mod/settings.php | 40 +++++----- mod/share.php | 4 +- mod/smilies.php | 5 +- mod/subthread.php | 8 +- mod/tagger.php | 30 +++---- mod/uexport.php | 12 +-- mod/videos.php | 65 ++++++++-------- mod/view.php | 3 +- mod/viewcontacts.php | 13 ++-- mod/viewsrc.php | 4 +- mod/wall_attach.php | 24 +++--- mod/wall_upload.php | 32 ++++---- mod/wallmessage.php | 21 ++--- mod/webfinger.php | 2 +- mod/xrd.php | 5 +- 92 files changed, 1190 insertions(+), 1087 deletions(-) diff --git a/mod/_well_known.php b/mod/_well_known.php index 622d7fd93..9c862af71 100644 --- a/mod/_well_known.php +++ b/mod/_well_known.php @@ -54,7 +54,7 @@ function wk_social_relay(App $a) { } $taglist = array(); - foreach($tags AS $tag) { + foreach ($tags AS $tag) { $taglist[] = $tag; } diff --git a/mod/acctlink.php b/mod/acctlink.php index 892b59655..715f251fa 100644 --- a/mod/acctlink.php +++ b/mod/acctlink.php @@ -4,11 +4,11 @@ require_once('include/Scrape.php'); function acctlink_init(App $a) { - if(x($_GET,'addr')) { + if (x($_GET,'addr')) { $addr = trim($_GET['addr']); $res = probe_url($addr); //logger('acctlink: ' . print_r($res,true)); - if($res['url']) { + if ($res['url']) { goaway($res['url']); killme(); } diff --git a/mod/admin.php b/mod/admin.php index b1bc8de5f..8227252c6 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -861,6 +861,7 @@ function admin_page_site(App $a) { foreach ($files as $file) { if (intval(file_exists($file.'/unsupported'))) continue; + } $f = basename($file); @@ -1274,7 +1275,7 @@ function admin_page_users(App $a) { if ($a->argc>2) { $uid = $a->argv[3]; $user = q("SELECT `username`, `blocked` FROM `user` WHERE `uid` = %d", intval($uid)); - if (count($user) == 0) { + if (!dbm::is_result($user)) { notice('User not found'.EOL); goaway('admin/users'); return ''; // NOTREACHED @@ -1609,7 +1610,7 @@ function admin_page_plugins(App $a) { * @param int $result */ function toggle_theme(&$themes,$th,&$result) { - for($x = 0; $x < count($themes); $x ++) { + for ($x = 0; $x < count($themes); $x ++) { if ($themes[$x]['name'] === $th) { if ($themes[$x]['allowed']) { $themes[$x]['allowed'] = 0; @@ -1629,7 +1630,7 @@ function toggle_theme(&$themes,$th,&$result) { * @return int */ function theme_status($themes,$th) { - for($x = 0; $x < count($themes); $x ++) { + for ($x = 0; $x < count($themes); $x ++) { if ($themes[$x]['name'] === $th) { if ($themes[$x]['allowed']) { return 1; @@ -1761,7 +1762,7 @@ function admin_page_themes(App $a) { $status="off"; $action= t("Enable"); } - $readme = Null; + $readme = null; if (is_file("view/theme/$theme/README.md")) { $readme = file_get_contents("view/theme/$theme/README.md"); $readme = Markdown($readme); diff --git a/mod/allfriends.php b/mod/allfriends.php index f51070bbe..893cf6a5f 100644 --- a/mod/allfriends.php +++ b/mod/allfriends.php @@ -37,8 +37,9 @@ function allfriends_content(App $a) { $total = count_all_friends(local_user(), $cid); - if(count($total)) + if (count($total)) { $a->set_pager_total($total); + } $r = all_friends(local_user(), $cid, $a->pager['start'], $a->pager['itemspage']); diff --git a/mod/api.php b/mod/api.php index 3916636cf..e44fcc493 100644 --- a/mod/api.php +++ b/mod/api.php @@ -27,7 +27,7 @@ function api_post(App $a) { return; } - if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) { + if (count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) { notice( t('Permission denied.') . EOL); return; } diff --git a/mod/apps.php b/mod/apps.php index 199ce0f91..fea548367 100644 --- a/mod/apps.php +++ b/mod/apps.php @@ -1,25 +1,23 @@ apps)==0) + if (count($a->apps) == 0) { notice( t('No installed applications.') . EOL); - + } $tpl = get_markup_template("apps.tpl"); return replace_macros($tpl, array( '$title' => $title, '$apps' => $a->apps, )); - - - } diff --git a/mod/attach.php b/mod/attach.php index dd7154dfe..80a2222bc 100644 --- a/mod/attach.php +++ b/mod/attach.php @@ -4,7 +4,7 @@ require_once('include/security.php'); function attach_init(App $a) { - if($a->argc != 2) { + if ($a->argc != 2) { notice( t('Item not available.') . EOL); return; } @@ -38,7 +38,7 @@ function attach_init(App $a) { // error in Chrome for filenames with commas in them header('Content-type: ' . $r[0]['filetype']); header('Content-length: ' . $r[0]['filesize']); - if(isset($_GET['attachment']) && $_GET['attachment'] === '0') + if (isset($_GET['attachment']) && $_GET['attachment'] === '0') header('Content-disposition: filename="' . $r[0]['filename'] . '"'); else header('Content-disposition: attachment; filename="' . $r[0]['filename'] . '"'); diff --git a/mod/babel.php b/mod/babel.php index e8ea11c94..f65920d78 100644 --- a/mod/babel.php +++ b/mod/babel.php @@ -25,7 +25,7 @@ function babel_content(App $a) { $o .= '

'; - if(x($_REQUEST,'text')) { + if (x($_REQUEST,'text')) { $text = trim($_REQUEST['text']); $o .= "

" . t("Source input: ") . "

" . EOL. EOL; @@ -63,7 +63,7 @@ function babel_content(App $a) { } - if(x($_REQUEST,'d2bbtext')) { + if (x($_REQUEST,'d2bbtext')) { $d2bbtext = trim($_REQUEST['d2bbtext']); $o .= "

" . t("Source input (Diaspora format): ") . "

" . EOL. EOL; diff --git a/mod/cal.php b/mod/cal.php index f43a4e8a7..97a6a9d8b 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -10,10 +10,10 @@ require_once('include/event.php'); require_once('include/redir.php'); function cal_init(App $a) { - if($a->argc > 1) + if ($a->argc > 1) auto_redir($a, $a->argv[1]); - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { return; } @@ -21,13 +21,13 @@ function cal_init(App $a) { $o = ''; - if($a->argc > 1) { + if ($a->argc > 1) { $nick = $a->argv[1]; $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1", dbesc($nick) ); - if(! count($user)) + if (! count($user)) return; $a->data['user'] = $user[0]; @@ -54,7 +54,7 @@ function cal_init(App $a) { $cal_widget = widget_events(); - if(! x($a->page,'aside')) + if (! x($a->page,'aside')) $a->page['aside'] = ''; $a->page['aside'] .= $vcard_widget; @@ -69,6 +69,7 @@ function cal_content(App $a) { // First day of the week (0 = Sunday) $firstDay = get_pconfig(local_user(),'system','first_day_of_week'); + /// @TODO Convert all these to with curly braces if ($firstDay === false) $firstDay=0; // get the translation strings for the callendar @@ -94,8 +95,9 @@ function cal_content(App $a) { $m = 0; $ignored = ((x($_REQUEST,'ignored')) ? intval($_REQUEST['ignored']) : 0); - if($a->argc == 4) { - if($a->argv[2] == 'export') { + /// @TODO Convert to one if() statement + if ($a->argc == 4) { + if ($a->argv[2] == 'export') { $mode = 'export'; $format = $a->argv[3]; } @@ -112,15 +114,15 @@ function cal_content(App $a) { $owner_uid = $a->data['user']['uid']; $nick = $a->data['user']['nickname']; - if(is_array($_SESSION['remote'])) { - foreach($_SESSION['remote'] as $v) { - if($v['uid'] == $a->profile['profile_uid']) { + if (is_array($_SESSION['remote'])) { + foreach ($_SESSION['remote'] as $v) { + if ($v['uid'] == $a->profile['profile_uid']) { $contact_id = $v['cid']; break; } } } - if($contact_id) { + if ($contact_id) { $groups = init_groups_visitor($contact_id); $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), @@ -131,15 +133,15 @@ function cal_content(App $a) { $remote_contact = true; } } - if(! $remote_contact) { - if(local_user()) { + if (! $remote_contact) { + if (local_user()) { $contact_id = $_SESSION['cid']; $contact = $a->contact; } } $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false); - if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) { + if ($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) { notice( t('Access to this profile has been restricted.') . EOL); return; } @@ -153,33 +155,33 @@ function cal_content(App $a) { $tabs .= profile_tabs($a,false, $a->data['user']['nickname']); // The view mode part is similiar to /mod/events.php - if($mode == 'view') { + if ($mode == 'view') { $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y'); $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m'); - if(! $y) + if (! $y) $y = intval($thisyear); - if(! $m) + if (! $m) $m = intval($thismonth); // Put some limits on dates. The PHP date functions don't seem to do so well before 1900. // An upper limit was chosen to keep search engines from exploring links millions of years in the future. - if($y < 1901) + if ($y < 1901) $y = 1900; - if($y > 2099) + if ($y > 2099) $y = 2100; $nextyear = $y; $nextmonth = $m + 1; - if($nextmonth > 12) { + if ($nextmonth > 12) { $nextmonth = 1; $nextyear ++; } $prevyear = $y; - if($m > 1) + if ($m > 1) $prevmonth = $m - 1; else { $prevmonth = 12; @@ -235,9 +237,10 @@ function cal_content(App $a) { $events=array(); // transform the event in a usable array - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $r = sort_by_date($r); $events = process_events($r); + } if ($a->argv[2] === 'json'){ echo json_encode($events); killme(); @@ -255,9 +258,9 @@ function cal_content(App $a) { } // Get rid of dashes in key names, Smarty3 can't handle them - foreach($events as $key => $event) { + foreach ($events as $key => $event) { $event_item = array(); - foreach($event['item'] as $k => $v) { + foreach ($event['item'] as $k => $v) { $k = str_replace('-','_',$k); $event_item[$k] = $v; } @@ -287,15 +290,15 @@ function cal_content(App $a) { return $o; } - if($mode == 'export') { - if(! (intval($owner_uid))) { + if ($mode == 'export') { + if (! (intval($owner_uid))) { notice( t('User not found')); return; } // Test permissions // Respect the export feature setting for all other /cal pages if it's not the own profile - if( ((local_user() !== intval($owner_uid))) && ! feature_enabled($owner_uid, "export_calendar")) { + if ( ((local_user() !== intval($owner_uid))) && ! feature_enabled($owner_uid, "export_calendar")) { notice( t('Permission denied.') . EOL); goaway('cal/' . $nick); } @@ -304,7 +307,7 @@ function cal_content(App $a) { $evexport = event_export($owner_uid, $format); if (!$evexport["success"]) { - if($evexport["content"]) + if ($evexport["content"]) notice( t('This calendar format is not supported') ); else notice( t('No exportable data found')); diff --git a/mod/common.php b/mod/common.php index 5a40663f9..d18389559 100644 --- a/mod/common.php +++ b/mod/common.php @@ -57,20 +57,21 @@ function common_content(App $a) { return; } - if(! $cid) { - if(get_my_url()) { + if (! $cid) { + if (get_my_url()) { $r = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1", dbesc(normalise_link(get_my_url())), intval($profile_uid) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $cid = $r[0]['id']; - else { + } else { $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link(get_my_url())) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $zcid = $r[0]['id']; + } } } } diff --git a/mod/community.php b/mod/community.php index 174330401..2f48c985c 100644 --- a/mod/community.php +++ b/mod/community.php @@ -18,12 +18,12 @@ function community_content(App $a, $update = 0) { if ($update) return; - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { notice( t('Public access denied.') . EOL); return; } - if(get_config('system','community_page_style') == CP_NO_COMMUNITY_PAGE) { + if (get_config('system','community_page_style') == CP_NO_COMMUNITY_PAGE) { notice( t('Not available.') . EOL); return; } @@ -34,11 +34,11 @@ function community_content(App $a, $update = 0) { $o .= '

' . t('Community') . '

'; - if(! $update) { + if (! $update) { nav_set_selected('community'); } - if(x($a->data,'search')) + if (x($a->data,'search')) $search = notags(trim($a->data['search'])); else $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); @@ -79,14 +79,15 @@ function community_content(App $a, $update = 0) { $r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']); } while ((sizeof($s) < $a->pager['itemspage']) AND (++$count < 50) AND (sizeof($r) > 0)); - } else + } else { $s = $r; + } // we behave the same in message lists as the search module $o .= conversation($a, $s, 'community', $update); - $o .= alt_pager($a, count($r)); + $o .= alt_pager($a, count($r)); return $o; } diff --git a/mod/contactgroup.php b/mod/contactgroup.php index 5c4cd7986..b2ddc8735 100644 --- a/mod/contactgroup.php +++ b/mod/contactgroup.php @@ -9,16 +9,17 @@ function contactgroup_content(App $a) { killme(); } - if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) { + if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) { $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1", intval($a->argv[2]), intval(local_user()) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $change = intval($a->argv[2]); + } } - if(($a->argc > 1) && (intval($a->argv[1]))) { + if (($a->argc > 1) && (intval($a->argv[1]))) { $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1", intval($a->argv[1]), @@ -31,16 +32,16 @@ function contactgroup_content(App $a) { $group = $r[0]; $members = group_get_members($group['id']); $preselected = array(); - if(count($members)) { - foreach($members as $member) + if (count($members)) { + foreach ($members as $member) { $preselected[] = $member['id']; + } } - if($change) { - if(in_array($change,$preselected)) { + if ($change) { + if (in_array($change,$preselected)) { group_rmv_member(local_user(),$group['name'],$change); - } - else { + } else { group_add_member(local_user(),$group['name'],$change); } } diff --git a/mod/contacts.php b/mod/contacts.php index 70f4b7350..11a83f0a0 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -14,7 +14,7 @@ function contacts_init(App $a) { $contact_id = 0; - if((($a->argc == 2) && intval($a->argv[1])) OR (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) { + if ((($a->argc == 2) && intval($a->argv[1])) OR (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) { $contact_id = intval($a->argv[1]); $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1", intval(local_user()), @@ -107,7 +107,7 @@ function contacts_batch_actions(App $a) { ); $count_actions=0; - foreach($orig_records as $orig_record) { + foreach ($orig_records as $orig_record) { $contact_id = $orig_record['id']; if (x($_POST, 'contacts_batch_update')) { _contact_update($contact_id); @@ -281,7 +281,7 @@ function _contact_update_profile($contact_id) { $update["subhub"] = true; } - foreach($updatefields AS $field) + foreach ($updatefields AS $field) if (isset($data[$field]) AND ($data[$field] != "")) $update[$field] = $data[$field]; @@ -292,7 +292,7 @@ function _contact_update_profile($contact_id) { if (isset($data["priority"]) AND ($data["priority"] != 0)) $query = "`priority` = ".intval($data["priority"]); - foreach($update AS $key => $value) { + foreach ($update AS $key => $value) { if ($query != "") $query .= ", "; @@ -365,10 +365,10 @@ function contacts_content(App $a) { return; } - if($a->argc == 3) { + if ($a->argc == 3) { $contact_id = intval($a->argv[1]); - if(! $contact_id) + if (! $contact_id) return; $cmd = $a->argv[2]; @@ -378,25 +378,25 @@ function contacts_content(App $a) { intval(local_user()) ); - if(! count($orig_record)) { + if (! count($orig_record)) { notice( t('Could not access contact record.') . EOL); goaway('contacts'); return; // NOTREACHED } - if($cmd === 'update') { + if ($cmd === 'update') { _contact_update($contact_id); goaway('contacts/' . $contact_id); // NOTREACHED } - if($cmd === 'updateprofile') { + if ($cmd === 'updateprofile') { _contact_update_profile($contact_id); goaway('crepair/' . $contact_id); // NOTREACHED } - if($cmd === 'block') { + if ($cmd === 'block') { $r = _contact_block($contact_id, $orig_record[0]); if ($r) { $blocked = (($orig_record[0]['blocked']) ? 0 : 1); @@ -407,7 +407,7 @@ function contacts_content(App $a) { return; // NOTREACHED } - if($cmd === 'ignore') { + if ($cmd === 'ignore') { $r = _contact_ignore($contact_id, $orig_record[0]); if ($r) { $readonly = (($orig_record[0]['readonly']) ? 0 : 1); @@ -419,7 +419,7 @@ function contacts_content(App $a) { } - if($cmd === 'archive') { + if ($cmd === 'archive') { $r = _contact_archive($contact_id, $orig_record[0]); if ($r) { $archived = (($orig_record[0]['archive']) ? 0 : 1); @@ -430,16 +430,16 @@ function contacts_content(App $a) { return; // NOTREACHED } - if($cmd === 'drop') { + if ($cmd === 'drop') { // Check if we should do HTML-based delete confirmation - if($_REQUEST['confirm']) { + if ($_REQUEST['confirm']) { //
can't take arguments in its "action" parameter // so add any arguments as hidden inputs $query = explode_querystring($a->query_string); $inputs = array(); - foreach($query['args'] as $arg) { - if(strpos($arg, 'confirm=') === false) { + foreach ($query['args'] as $arg) { + if (strpos($arg, 'confirm=') === false) { $arg_parts = explode('=', $arg); $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]); } @@ -488,7 +488,7 @@ function contacts_content(App $a) { $_SESSION['return_url'] = $a->query_string; - if((x($a->data,'contact')) && (is_array($a->data['contact']))) { + if ((x($a->data,'contact')) && (is_array($a->data['contact']))) { $contact_id = $a->data['contact']['id']; $contact = $a->data['contact']; @@ -522,12 +522,12 @@ function contacts_content(App $a) { break; } - if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) + if (!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) $relation_text = ""; $relation_text = sprintf($relation_text,htmlentities($contact['name'])); - if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) { + if (($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) { $url = "redir/{$contact['id']}"; $sparkle = ' class="sparkle" '; } @@ -542,7 +542,7 @@ function contacts_content(App $a) { ? t('Never') : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A')); - if($contact['last-update'] !== '0000-00-00 00:00:00') + if ($contact['last-update'] !== '0000-00-00 00:00:00') $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29")); $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : ''); @@ -665,23 +665,23 @@ function contacts_content(App $a) { $ignored = false; $all = false; - if(($a->argc == 2) && ($a->argv[1] === 'all')) { + if (($a->argc == 2) && ($a->argv[1] === 'all')) { $sql_extra = ''; $all = true; } - elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) { + elseif (($a->argc == 2) && ($a->argv[1] === 'blocked')) { $sql_extra = " AND `blocked` = 1 "; $blocked = true; } - elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) { + elseif (($a->argc == 2) && ($a->argv[1] === 'hidden')) { $sql_extra = " AND `hidden` = 1 "; $hidden = true; } - elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) { + elseif (($a->argc == 2) && ($a->argv[1] === 'ignored')) { $sql_extra = " AND `readonly` = 1 "; $ignored = true; } - elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) { + elseif (($a->argc == 2) && ($a->argv[1] === 'archived')) { $sql_extra = " AND `archive` = 1 "; $archived = true; } @@ -761,14 +761,14 @@ function contacts_content(App $a) { $searching = false; - if($search) { + if ($search) { $search_hdr = $search; $search_txt = dbesc(protect_sprintf(preg_quote($search))); $searching = true; } $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : ""); - if($nets) + if ($nets) $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets)); $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : ''); @@ -929,7 +929,7 @@ function _contact_detail_for_template($rr){ default: break; } - if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) { + if (($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) { $url = "redir/{$rr['id']}"; $sparkle = ' class="sparkle" '; } @@ -971,7 +971,7 @@ function contact_actions($contact) { $contact_action = array(); // Provide friend suggestion only for Friendica contacts - if($contact['network'] === NETWORK_DFRN) { + if ($contact['network'] === NETWORK_DFRN) { $contact_actions['suggest'] = array( 'label' => t('Suggest friends'), 'url' => 'fsuggest/' . $contact['id'], @@ -981,7 +981,7 @@ function contact_actions($contact) { ); } - if($poll_enabled) { + if ($poll_enabled) { $contact_actions['update'] = array( 'label' => t('Update now'), 'url' => 'contacts/' . $contact['id'] . '/update', diff --git a/mod/content.php b/mod/content.php index 43f3fc2ba..e7e8ca65e 100644 --- a/mod/content.php +++ b/mod/content.php @@ -38,20 +38,18 @@ function content_content(App $a, $update = 0) { $nouveau = false; - if($a->argc > 1) { - for($x = 1; $x < $a->argc; $x ++) { - if(is_a_date_arg($a->argv[$x])) { - if($datequery) + if ($a->argc > 1) { + for ($x = 1; $x < $a->argc; $x ++) { + if (is_a_date_arg($a->argv[$x])) { + if ($datequery) { $datequery2 = escape_tags($a->argv[$x]); - else { + } else { $datequery = escape_tags($a->argv[$x]); $_GET['order'] = 'post'; } - } - elseif($a->argv[$x] === 'new') { + } elseif ($a->argv[$x] === 'new') { $nouveau = true; - } - elseif(intval($a->argv[$x])) { + } elseif (intval($a->argv[$x])) { $group = intval($a->argv[$x]); $def_acl = array('allow_gid' => '<' . $group . '>'); } @@ -81,12 +79,12 @@ function content_content(App $a, $update = 0) { - if(x($_GET,'search') || x($_GET,'file')) + if (x($_GET,'search') || x($_GET,'file')) $nouveau = true; - if($cid) + if ($cid) $def_acl = array('allow_cid' => '<' . intval($cid) . '>'); - if($nets) { + if ($nets) { $r = q("select id from contact where uid = %d and network = '%s' and self = 0", intval(local_user()), dbesc($nets) @@ -94,9 +92,9 @@ function content_content(App $a, $update = 0) { $str = ''; if (dbm::is_result($r)) - foreach($r as $rr) + foreach ($r as $rr) $str .= '<' . $rr['id'] . '>'; - if(strlen($str)) + if (strlen($str)) $def_acl = array('allow_cid' => $str); } @@ -108,13 +106,13 @@ function content_content(App $a, $update = 0) { $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` $sql_options ) "; - if($group) { + if ($group) { $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($group), intval($_SESSION['uid']) ); if (! dbm::is_result($r)) { - if($update) + if ($update) killme(); notice( t('No such group') . EOL ); goaway(App::get_baseurl(true) . '/network'); @@ -122,7 +120,7 @@ function content_content(App $a, $update = 0) { } $contacts = expand_groups(array($group)); - if((is_array($contacts)) && count($contacts)) { + if ((is_array($contacts)) && count($contacts)) { $contact_str = implode(',',$contacts); } else { @@ -135,7 +133,7 @@ function content_content(App $a, $update = 0) { '$title' => sprintf( t('Group: %s'), $r[0]['name']) )) . $o; } - elseif($cid) { + elseif ($cid) { $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d AND `blocked` = 0 AND `pending` = 0 LIMIT 1", @@ -153,10 +151,10 @@ function content_content(App $a, $update = 0) { $sql_extra3 = ''; - if($datequery) { + if ($datequery) { $sql_extra3 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery)))); } - if($datequery2) { + if ($datequery2) { $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); } @@ -164,10 +162,10 @@ function content_content(App $a, $update = 0) { $sql_extra3 = (($nouveau) ? '' : $sql_extra3); $sql_table = "`item`"; - if(x($_GET,'search')) { + if (x($_GET,'search')) { $search = escape_tags($_GET['search']); - if(strpos($search,'#') === 0) { + if (strpos($search,'#') === 0) { $tag = true; $search = substr($search,1); } @@ -175,7 +173,7 @@ function content_content(App $a, $update = 0) { if (get_config('system','only_tag_search')) $tag = true; - if($tag) { + if ($tag) { //$sql_extra = sprintf(" AND `term`.`term` = '%s' AND `term`.`otype` = %d AND `term`.`type` = %d ", // dbesc(protect_sprintf($search)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG)); //$sql_table = "`term` INNER JOIN `item` ON `item`.`id` = `term`.`oid` AND `item`.`uid` = `term`.`uid` "; @@ -192,11 +190,11 @@ function content_content(App $a, $update = 0) { } } - if(strlen($file)) { + if (strlen($file)) { $sql_extra .= file_tag_file_query('item',unxmlify($file)); } - if($conv) { + if ($conv) { $myurl = App::get_baseurl() . '/profile/'. $a->user['nickname']; $myurl = substr($myurl,strpos($myurl,'://')+3); $myurl = str_replace('www.','',$myurl); @@ -211,7 +209,7 @@ function content_content(App $a, $update = 0) { $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); - if($nouveau) { + if ($nouveau) { // "New Item View" - show all items unthreaded in reverse created date order $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, @@ -234,7 +232,7 @@ function content_content(App $a, $update = 0) { // Normal conversation view - if($order === 'post') + if ($order === 'post') $ordering = "`created`"; else $ordering = "`commented`"; @@ -260,8 +258,8 @@ function content_content(App $a, $update = 0) { $parents_str = ''; if (dbm::is_result($r)) { - foreach($r as $rr) - if(! in_array($rr['item_id'],$parents_arr)) + foreach ($r as $rr) + if (! in_array($rr['item_id'],$parents_arr)) $parents_arr[] = $rr['item_id']; $parents_str = implode(', ', $parents_arr); @@ -328,32 +326,32 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { ); } - if($mode === 'network') { + if ($mode === 'network') { $profile_owner = local_user(); $page_writeable = true; } - if($mode === 'profile') { + if ($mode === 'profile') { $profile_owner = $a->profile['profile_uid']; $page_writeable = can_write_wall($a,$profile_owner); } - if($mode === 'notes') { + if ($mode === 'notes') { $profile_owner = local_user(); $page_writeable = true; } - if($mode === 'display') { + if ($mode === 'display') { $profile_owner = $a->profile['uid']; $page_writeable = can_write_wall($a,$profile_owner); } - if($mode === 'community') { + if ($mode === 'community') { $profile_owner = 0; $page_writeable = false; } - if($update) + if ($update) $return_url = $_SESSION['return_url']; else $return_url = $_SESSION['return_url'] = $a->query_string; @@ -378,9 +376,9 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $threads = array(); $threadsid = -1; - if($items && count($items)) { + if ($items && count($items)) { - if($mode === 'network-new' || $mode === 'search' || $mode === 'community') { + if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') { // "New Item View" on network page or search page results // - just loop through the items and format them minimally for display @@ -388,7 +386,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { //$tpl = get_markup_template('search_item.tpl'); $tpl = 'search_item.tpl'; - foreach($items as $item) { + foreach ($items as $item) { $threadsid++; $comment = ''; @@ -397,8 +395,8 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $owner_name = ''; $sparkle = ''; - if($mode === 'search' || $mode === 'community') { - if(((activity_match($item['verb'],ACTIVITY_LIKE)) + if ($mode === 'search' || $mode === 'community') { + if (((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)) || activity_match($item['verb'],ACTIVITY_ATTEND) || activity_match($item['verb'],ACTIVITY_ATTENDNO) @@ -411,20 +409,20 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $nickname = $a->user['nickname']; // prevent private email from leaking. - if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) + if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) continue; $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']); - if($item['author-link'] && (! $item['author-name'])) + if ($item['author-link'] && (! $item['author-name'])) $profile_name = $item['author-link']; $sp = false; $profile_link = best_link_url($item,$sp); - if($profile_link === 'mailbox') + if ($profile_link === 'mailbox') $profile_link = ''; - if($sp) + if ($sp) $sparkle = ' sparkle'; else $profile_link = zrl($profile_link); @@ -442,7 +440,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate)); localize_item($item); - if($mode === 'network-new') + if ($mode === 'network-new') $dropping = true; else $dropping = false; @@ -463,7 +461,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $body = prepare_body($item,true); - if($a->theme['template_engine'] === 'internal') { + if ($a->theme['template_engine'] === 'internal') { $name_e = template_escape($profile_name); $title_e = template_escape($item['title']); $body_e = template_escape($body); @@ -534,20 +532,20 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { // Store the result in the $comments array $comments = array(); - foreach($items as $item) { - if((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) { - if(! x($comments,$item['parent'])) + foreach ($items as $item) { + if ((intval($item['gravity']) == 6) && ($item['id'] != $item['parent'])) { + if (! x($comments,$item['parent'])) $comments[$item['parent']] = 1; else $comments[$item['parent']] += 1; - } elseif(! x($comments,$item['parent'])) + } elseif (! x($comments,$item['parent'])) $comments[$item['parent']] = 0; // avoid notices later on } // map all the like/dislike/attendance activities for each parent item // Store these in the $alike and $dlike arrays - foreach($items as $item) { + foreach ($items as $item) { builtin_activity_puller($item, $conv_responses); } @@ -559,7 +557,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $blowhard_count = 0; - foreach($items as $item) { + foreach ($items as $item) { $comment = ''; $template = $tpl; @@ -569,7 +567,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { // We've already parsed out like/dislike for special treatment. We can ignore them now - if(((activity_match($item['verb'],ACTIVITY_LIKE)) + if (((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE) || activity_match($item['verb'],ACTIVITY_ATTEND) || activity_match($item['verb'],ACTIVITY_ATTENDNO) @@ -585,7 +583,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { // If a single author has more than 3 consecutive top-level posts, squash the remaining ones. // If there are more than two comments, squash all but the last 2. - if($toplevelpost) { + if ($toplevelpost) { $item_writeable = (($item['writable'] || $item['self']) ? true : false); @@ -603,7 +601,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { else { // prevent private email reply to public conversation from leaking. - if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) + if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) continue; $comments_seen ++; @@ -615,7 +613,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $show_comment_box = ((($page_writeable) && ($item_writeable) && ($comments_seen == $comments[$item['parent']])) ? true : false); - if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) { + if (($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) { if (!$comments_collapsed){ $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] ); @@ -626,7 +624,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $comment_firstcollapsed = true; } } - if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) { + if (($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) { $comment_lastcollapsed = true; } @@ -644,9 +642,9 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $osparkle = ''; - if(($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) { + if (($toplevelpost) && (! $item['self']) && ($mode !== 'profile')) { - if($item['wall']) { + if ($item['wall']) { // On the network page, I am the owner. On the display page it will be the profile owner. // This will have been stored in $a->page_contact by our calling page. @@ -659,12 +657,12 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $commentww = 'ww'; } - if((! $item['wall']) && $item['owner-link']) { + if ((! $item['wall']) && $item['owner-link']) { $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link'])); $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link'])); $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']); - if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) { + if ((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) { // The author url doesn't match the owner (typically the contact) // and also doesn't match the contact alias. @@ -682,7 +680,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $template = $wallwall; $commentww = 'ww'; // If it is our contact, use a friendly redirect link - if((link_compare($item['owner-link'],$item['url'])) + if ((link_compare($item['owner-link'],$item['url'])) && ($item['network'] === NETWORK_DFRN)) { $owner_url = $redirect_url; $osparkle = ' sparkle'; @@ -696,8 +694,8 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $likebuttons = ''; $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false); - if($page_writeable) { -/* if($toplevelpost) { */ + if ($page_writeable) { +/* if ($toplevelpost) { */ $likebuttons = array( 'like' => array( t("I like this \x28toggle\x29"), t("like")), 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")), @@ -707,12 +705,12 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $qc = $qcomment = null; - if(in_array('qcomment',$a->plugins)) { + if (in_array('qcomment',$a->plugins)) { $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null); $qcomment = (($qc) ? explode("\n",$qc) : null); } - if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) { + if (($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) { $comment = replace_macros($cmnt_tpl,array( '$return_path' => '', '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''), @@ -751,7 +749,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $drop = ''; $dropping = false; - if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user())) + if ((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user())) $dropping = true; $drop = array( @@ -815,7 +813,7 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']); - if($item['author-link'] && (! $item['author-name'])) + if ($item['author-link'] && (! $item['author-name'])) $profile_name = $item['author-link']; $sp = false; @@ -842,13 +840,14 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { // process action responses - e.g. like/dislike/attend/agree/whatever $response_verbs = array('like'); - if(feature_enabled($profile_owner,'dislike')) + if (feature_enabled($profile_owner,'dislike')) { $response_verbs[] = 'dislike'; - if($item['object-type'] === ACTIVITY_OBJ_EVENT) { + } + if ($item['object-type'] === ACTIVITY_OBJ_EVENT) { $response_verbs[] = 'attendyes'; $response_verbs[] = 'attendno'; $response_verbs[] = 'attendmaybe'; - if($page_writeable) { + if ($page_writeable) { $isevent = true; $attend = array( t('I will attend'), t('I will not attend'), t('I might attend')); } @@ -863,17 +862,20 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $indent = (($toplevelpost) ? '' : ' comment'); $shiny = ""; - if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0) + if (strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0) { $shiny = 'shiny'; + } // localize_item($item); $tags=array(); - foreach(explode(',',$item['tag']) as $tag){ + foreach (explode(',',$item['tag']) as $tag){ $tag = trim($tag); - if ($tag!="") $tags[] = bbcode($tag); + if ($tag!="") { + $tags[] = bbcode($tag); + } } // Build the HTML @@ -881,15 +883,14 @@ function render_content(App $a, $items, $mode, $update, $preview = false) { $body = prepare_body($item,true); //$tmp_item = replace_macros($template, - if($a->theme['template_engine'] === 'internal') { + if ($a->theme['template_engine'] === 'internal') { $body_e = template_escape($body); $text_e = strip_tags(template_escape($body)); $name_e = template_escape($profile_name); $title_e = template_escape($item['title']); $location_e = template_escape($location); $owner_name_e = template_escape($owner_name); - } - else { + } else { $body_e = $body; $text_e = strip_tags($body); $name_e = $profile_name; diff --git a/mod/crepair.php b/mod/crepair.php index ef7908661..c5b4983d5 100644 --- a/mod/crepair.php +++ b/mod/crepair.php @@ -9,7 +9,7 @@ function crepair_init(App $a) { $contact_id = 0; - if(($a->argc == 2) && intval($a->argv[1])) { + if (($a->argc == 2) && intval($a->argv[1])) { $contact_id = intval($a->argv[1]); $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1", intval(local_user()), @@ -109,7 +109,7 @@ function crepair_content(App $a) { $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0); - if($cid) { + if ($cid) { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($cid), intval(local_user()) diff --git a/mod/delegate.php b/mod/delegate.php index 4212ec9b1..f8a0dcb59 100644 --- a/mod/delegate.php +++ b/mod/delegate.php @@ -23,16 +23,16 @@ function delegate_content(App $a) { $id = $a->argv[2]; - $r = q("select `nickname` from user where uid = %d limit 1", + $r = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1", intval($id) ); if (dbm::is_result($r)) { - $r = q("select id from contact where uid = %d and nurl = '%s' limit 1", + $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1", intval(local_user()), dbesc(normalise_link(App::get_baseurl() . '/profile/' . $r[0]['nickname'])) ); if (dbm::is_result($r)) { - q("insert into manage ( uid, mid ) values ( %d , %d ) ", + q("INSERT INTO `manage` ( `uid`, `mid` ) VALUES ( %d , %d ) ", intval($a->argv[2]), intval(local_user()) ); @@ -64,34 +64,40 @@ function delegate_content(App $a) { dbesc($a->user['email']), dbesc($a->user['password']) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $full_managers = $r; + } $delegates = array(); // find everybody that currently has delegated management to this account/page - $r = q("select * from user where uid in ( select uid from manage where mid = %d ) ", + $r = q("SELECT * FROM `user` WHERE `uid` IN ( SELECT `uid` FROM `manage` WHERE `mid` = %d ) ", intval(local_user()) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $delegates = $r; + } $uids = array(); - if(count($full_managers)) - foreach($full_managers as $rr) + if (count($full_managers)) { + foreach ($full_managers as $rr) { $uids[] = $rr['uid']; + } + } - if(count($delegates)) - foreach($delegates as $rr) + if (count($delegates)) { + foreach ($delegates as $rr) { $uids[] = $rr['uid']; + } + } // find every contact who might be a candidate for delegation - $r = q("select nurl from contact where substring_index(contact.nurl,'/',3) = '%s' - and contact.uid = %d and contact.self = 0 and network = '%s' ", + $r = q("SELECT `nurl` FROM `contact` WHERE SUBSTRING_INDEX(`contact`.`nurl`,'/',3) = '%s' + AND `contact`.`uid` = %d AND `contact`.`self` = 0 AND `network` = '%s' ", dbesc(normalise_link(App::get_baseurl())), intval(local_user()), dbesc(NETWORK_DFRN) @@ -116,12 +122,15 @@ function delegate_content(App $a) { // get user records for all potential page delegates who are not already delegates or managers - $r = q("select `uid`, `username`, `nickname` from user where nickname in ( $nicks )"); + $r = q("SELECT `uid`, `username`, `nickname` FROM `user` WHERE `nickname` IN ( $nicks )"); - if (dbm::is_result($r)) - foreach($r as $rr) - if(! in_array($rr['uid'],$uids)) + if (dbm::is_result($r)) { + foreach ($r as $rr) { + if (! in_array($rr['uid'],$uids)) { $potentials[] = $rr; + } + } + } require_once("mod/settings.php"); settings_init($a); diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 7e14610e3..9dd38df34 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -24,7 +24,7 @@ require_once('include/Probe.php'); function dfrn_confirm_post(App $a, $handsfree = null) { - if(is_array($handsfree)) { + if (is_array($handsfree)) { /* * We were called directly from dfrn_request due to automatic friend acceptance. @@ -37,7 +37,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) { } else { - if($a->argc > 1) + if ($a->argc > 1) $node = $a->argv[1]; } @@ -53,11 +53,11 @@ function dfrn_confirm_post(App $a, $handsfree = null) { * */ - if(! x($_POST,'source_url')) { + if (! x($_POST,'source_url')) { $uid = ((is_array($handsfree)) ? $handsfree['uid'] : local_user()); - if(! $uid) { + if (! $uid) { notice( t('Permission denied.') . EOL ); return; } @@ -66,7 +66,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) { intval($uid) ); - if(! $user) { + if (! $user) { notice( t('Profile not found.') . EOL ); return; } @@ -74,7 +74,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) { // These data elements may come from either the friend request notification form or $handsfree array. - if(is_array($handsfree)) { + if (is_array($handsfree)) { logger('Confirm in handsfree mode'); $dfrn_id = $handsfree['dfrn_id']; $intro_id = $handsfree['intro_id']; @@ -99,11 +99,11 @@ function dfrn_confirm_post(App $a, $handsfree = null) { * */ - if(strlen($dfrn_id)) + if (strlen($dfrn_id)) $cid = 0; logger('Confirming request for dfrn_id (issued) ' . $dfrn_id); - if($cid) + if ($cid) logger('Confirming follower with contact_id: ' . $cid); @@ -138,10 +138,10 @@ function dfrn_confirm_post(App $a, $handsfree = null) { $network = ((strlen($contact['issued-id'])) ? NETWORK_DFRN : NETWORK_OSTATUS); - if($contact['network']) + if ($contact['network']) $network = $contact['network']; - if($network === NETWORK_DFRN) { + if ($network === NETWORK_DFRN) { /* * @@ -199,19 +199,19 @@ function dfrn_confirm_post(App $a, $handsfree = null) { openssl_public_encrypt($my_url, $params['source_url'], $site_pubkey); $params['source_url'] = bin2hex($params['source_url']); - if($aes_allow && function_exists('openssl_encrypt')) { + if ($aes_allow && function_exists('openssl_encrypt')) { openssl_public_encrypt($src_aes_key, $params['aes_key'], $site_pubkey); $params['aes_key'] = bin2hex($params['aes_key']); $params['public_key'] = bin2hex(openssl_encrypt($public_key,'AES-256-CBC',$src_aes_key)); } $params['dfrn_version'] = DFRN_PROTOCOL_VERSION ; - if($duplex == 1) + if ($duplex == 1) $params['duplex'] = 1; - if($user[0]['page-flags'] == PAGE_COMMUNITY) + if ($user[0]['page-flags'] == PAGE_COMMUNITY) $params['page'] = 1; - if($user[0]['page-flags'] == PAGE_PRVGROUP) + if ($user[0]['page-flags'] == PAGE_PRVGROUP) $params['page'] = 2; logger('Confirm: posting data to ' . $dfrn_confirm . ': ' . print_r($params,true), LOGGER_DATA); @@ -234,7 +234,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) { $leading_junk = substr($res,0,strpos($res,' NOTIFY_CONFIRM, @@ -743,12 +742,12 @@ function dfrn_confirm_post(App $a, $handsfree = null) { // Send a new friend post if we are allowed to... - if($page && intval(get_pconfig($local_uid,'system','post_joingroup'))) { + if ($page && intval(get_pconfig($local_uid,'system','post_joingroup'))) { $r = q("SELECT `hide-friends` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1", intval($local_uid) ); - if((dbm::is_result($r)) && ($r[0]['hide-friends'] == 0)) { + if ((dbm::is_result($r)) && ($r[0]['hide-friends'] == 0)) { require_once('include/items.php'); @@ -756,7 +755,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) { intval($local_uid) ); - if(count($self)) { + if (dbm::is_result($self)) { $arr = array(); $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), $local_uid); @@ -793,8 +792,9 @@ function dfrn_confirm_post(App $a, $handsfree = null) { $arr['deny_gid'] = $user[0]['deny_gid']; $i = item_store($arr); - if($i) + if ($i) { proc_run(PRIORITY_HIGH, "include/notifier.php", "activity", $i); + } } } diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index d34c959f1..63978386e 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -28,12 +28,12 @@ function dfrn_notify_post(App $a) { $prv = (($page == 2) ? 1 : 0); $writable = (-1); - if($dfrn_version >= 2.21) { + if ($dfrn_version >= 2.21) { $writable = (($perm === 'rw') ? 1 : 0); } $direction = (-1); - if(strpos($dfrn_id,':') == 1) { + if (strpos($dfrn_id,':') == 1) { $direction = intval(substr($dfrn_id,0,1)); $dfrn_id = substr($dfrn_id,2); } @@ -100,14 +100,14 @@ function dfrn_notify_post(App $a) { logger("Remote rino version: ".$rino_remote." for ".$importer["url"], LOGGER_DEBUG); - if((($writable != (-1)) && ($writable != $importer['writable'])) || ($importer['forum'] != $forum) || ($importer['prv'] != $prv)) { + if ((($writable != (-1)) && ($writable != $importer['writable'])) || ($importer['forum'] != $forum) || ($importer['prv'] != $prv)) { q("UPDATE `contact` SET `writable` = %d, forum = %d, prv = %d WHERE `id` = %d", intval(($writable == (-1)) ? $importer['writable'] : $writable), intval($forum), intval($prv), intval($importer['id']) ); - if($writable != (-1)) + if ($writable != (-1)) $importer['writable'] = $writable; $importer['forum'] = $page; } @@ -120,7 +120,7 @@ function dfrn_notify_post(App $a) { logger('dfrn_notify: received notify from ' . $importer['name'] . ' for ' . $importer['username']); logger('dfrn_notify: data: ' . $data, LOGGER_DATA); - if($dissolve == 1) { + if ($dissolve == 1) { /* * Relationship is dissolved permanently @@ -137,7 +137,7 @@ function dfrn_notify_post(App $a) { // If we are setup as a soapbox we aren't accepting input from this person // This behaviour is deactivated since it really doesn't make sense to even disallow comments // The check if someone is a friend or simply a follower is done in a later place so it needn't to be done here - //if($importer['page-flags'] == PAGE_SOAPBOX) + //if ($importer['page-flags'] == PAGE_SOAPBOX) // xml_status(0); $rino = get_config('system','rino_encrypt'); @@ -147,7 +147,7 @@ function dfrn_notify_post(App $a) { logger("Local rino version: ". $rino, LOGGER_DEBUG); - if(strlen($key)) { + if (strlen($key)) { // if local rino is lower than remote rino, abort: should not happen! // but only for $remote_rino > 1, because old code did't send rino version @@ -160,8 +160,8 @@ function dfrn_notify_post(App $a) { logger('rino: md5 raw key: ' . md5($rawkey)); $final_key = ''; - if($dfrn_version >= 2.1) { - if((($importer['duplex']) && strlen($importer['cprvkey'])) || (! strlen($importer['cpubkey']))) { + if ($dfrn_version >= 2.1) { + if ((($importer['duplex']) && strlen($importer['cprvkey'])) || (! strlen($importer['cpubkey']))) { openssl_private_decrypt($rawkey,$final_key,$importer['cprvkey']); } else { @@ -169,7 +169,7 @@ function dfrn_notify_post(App $a) { } } else { - if((($importer['duplex']) && strlen($importer['cpubkey'])) || (! strlen($importer['cprvkey']))) { + if ((($importer['duplex']) && strlen($importer['cpubkey'])) || (! strlen($importer['cprvkey']))) { openssl_public_decrypt($rawkey,$final_key,$importer['cpubkey']); } else { @@ -223,7 +223,7 @@ function dfrn_notify_post(App $a) { function dfrn_notify_content(App $a) { - if(x($_GET,'dfrn_id')) { + if (x($_GET,'dfrn_id')) { // initial communication from external contact, $direction is their direction. // If this is a duplex communication, ours will be the opposite. @@ -237,7 +237,7 @@ function dfrn_notify_content(App $a) { logger('dfrn_notify: new notification dfrn_id=' . $dfrn_id); $direction = (-1); - if(strpos($dfrn_id,':') == 1) { + if (strpos($dfrn_id,':') == 1) { $direction = intval(substr($dfrn_id,0,1)); $dfrn_id = substr($dfrn_id,2); } @@ -298,16 +298,15 @@ function dfrn_notify_content(App $a) { $pub_key = trim($r[0]['pubkey']); $dplx = intval($r[0]['duplex']); - if((($dplx) && (strlen($prv_key))) || ((strlen($prv_key)) && (!(strlen($pub_key))))) { + if ((($dplx) && (strlen($prv_key))) || ((strlen($prv_key)) && (!(strlen($pub_key))))) { openssl_private_encrypt($hash,$challenge,$prv_key); openssl_private_encrypt($id_str,$encrypted_id,$prv_key); - } - elseif(strlen($pub_key)) { + } elseif (strlen($pub_key)) { openssl_public_encrypt($hash,$challenge,$pub_key); openssl_public_encrypt($id_str,$encrypted_id,$pub_key); - } - else + } else { $status = 1; + } $challenge = bin2hex($challenge); $encrypted_id = bin2hex($encrypted_id); @@ -324,10 +323,9 @@ function dfrn_notify_content(App $a) { // if requested rino is higher than enabled local rino, reply with local rino if ($rino_remote < $rino) $rino = $rino_remote; - if((($r[0]['rel']) && ($r[0]['rel'] != CONTACT_IS_SHARING)) || ($r[0]['page-flags'] == PAGE_COMMUNITY)) { + if ((($r[0]['rel']) && ($r[0]['rel'] != CONTACT_IS_SHARING)) || ($r[0]['page-flags'] == PAGE_COMMUNITY)) { $perm = 'rw'; - } - else { + } else { $perm = 'r'; } diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 506f9f162..13d443341 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -20,20 +20,20 @@ function dfrn_poll_init(App $a) { $direction = (-1); - if(strpos($dfrn_id,':') == 1) { + if (strpos($dfrn_id,':') == 1) { $direction = intval(substr($dfrn_id,0,1)); $dfrn_id = substr($dfrn_id,2); } $hidewall = false; - if(($dfrn_id === '') && (! x($_POST,'dfrn_id'))) { - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if (($dfrn_id === '') && (! x($_POST,'dfrn_id'))) { + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { http_status_exit(403); } $user = ''; - if($a->argc > 1) { + if ($a->argc > 1) { $r = q("SELECT `hidewall`,`nickname` FROM `user` WHERE `user`.`nickname` = '%s' LIMIT 1", dbesc($a->argv[1]) ); @@ -51,7 +51,7 @@ function dfrn_poll_init(App $a) { killme(); } - if(($type === 'profile') && (! strlen($sec))) { + if (($type === 'profile') && (! strlen($sec))) { $sql_extra = ''; switch($direction) { @@ -85,13 +85,13 @@ function dfrn_poll_init(App $a) { logger("dfrn_poll: old profile returns " . $s, LOGGER_DATA); - if(strlen($s)) { + if (strlen($s)) { $xml = parse_xml_string($s); - if((int) $xml->status == 1) { + if ((int) $xml->status == 1) { $_SESSION['authenticated'] = 1; - if(! x($_SESSION,'remote')) + if (! x($_SESSION,'remote')) $_SESSION['remote'] = array(); $_SESSION['remote'][] = array('cid' => $r[0]['id'],'uid' => $r[0]['uid'],'url' => $r[0]['url']); @@ -100,7 +100,7 @@ function dfrn_poll_init(App $a) { $_SESSION['visitor_home'] = $r[0]['url']; $_SESSION['visitor_handle'] = $r[0]['addr']; $_SESSION['visitor_visiting'] = $r[0]['uid']; - if(!$quiet) + if (!$quiet) info( sprintf(t('%1$s welcomes %2$s'), $r[0]['username'] , $r[0]['name']) . EOL); // Visitors get 1 day session. $session_id = session_id(); @@ -118,9 +118,9 @@ function dfrn_poll_init(App $a) { } - if($type === 'profile-check' && $dfrn_version < 2.2 ) { + if ($type === 'profile-check' && $dfrn_version < 2.2 ) { - if((strlen($challenge)) && (strlen($sec))) { + if ((strlen($challenge)) && (strlen($sec))) { q("DELETE FROM `profile_check` WHERE `expire` < " . intval(time())); $r = q("SELECT * FROM `profile_check` WHERE `sec` = '%s' ORDER BY `expire` DESC LIMIT 1", @@ -131,7 +131,7 @@ function dfrn_poll_init(App $a) { // NOTREACHED } $orig_id = $r[0]['dfrn_id']; - if(strpos($orig_id, ':')) + if (strpos($orig_id, ':')) $orig_id = substr($orig_id,2); $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", @@ -147,7 +147,7 @@ function dfrn_poll_init(App $a) { $final_dfrn_id = ''; - if(($contact['duplex']) && strlen($contact['prvkey'])) { + if (($contact['duplex']) && strlen($contact['prvkey'])) { openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']); openssl_private_decrypt($challenge,$decoded_challenge,$contact['prvkey']); } @@ -158,10 +158,10 @@ function dfrn_poll_init(App $a) { $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.')); - if(strpos($final_dfrn_id,':') == 1) + if (strpos($final_dfrn_id,':') == 1) $final_dfrn_id = substr($final_dfrn_id,2); - if($final_dfrn_id != $orig_id) { + if ($final_dfrn_id != $orig_id) { logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG); // did not decode properly - cannot trust this site xml_status(3, 'Bad decryption'); @@ -213,9 +213,9 @@ function dfrn_poll_post(App $a) { $dfrn_version = ((x($_POST,'dfrn_version')) ? (float) $_POST['dfrn_version'] : 2.0); $perm = ((x($_POST,'perm')) ? $_POST['perm'] : 'r'); - if($ptype === 'profile-check') { + if ($ptype === 'profile-check') { - if((strlen($challenge)) && (strlen($sec))) { + if ((strlen($challenge)) && (strlen($sec))) { logger('dfrn_poll: POST: profile-check'); @@ -228,7 +228,7 @@ function dfrn_poll_post(App $a) { // NOTREACHED } $orig_id = $r[0]['dfrn_id']; - if(strpos($orig_id, ':')) + if (strpos($orig_id, ':')) $orig_id = substr($orig_id,2); $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", @@ -244,7 +244,7 @@ function dfrn_poll_post(App $a) { $final_dfrn_id = ''; - if(($contact['duplex']) && strlen($contact['prvkey'])) { + if (($contact['duplex']) && strlen($contact['prvkey'])) { openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']); openssl_private_decrypt($challenge,$decoded_challenge,$contact['prvkey']); } @@ -255,10 +255,10 @@ function dfrn_poll_post(App $a) { $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.')); - if(strpos($final_dfrn_id,':') == 1) + if (strpos($final_dfrn_id,':') == 1) $final_dfrn_id = substr($final_dfrn_id,2); - if($final_dfrn_id != $orig_id) { + if ($final_dfrn_id != $orig_id) { logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG); // did not decode properly - cannot trust this site xml_status(3, 'Bad decryption'); @@ -273,7 +273,7 @@ function dfrn_poll_post(App $a) { } $direction = (-1); - if(strpos($dfrn_id,':') == 1) { + if (strpos($dfrn_id,':') == 1) { $direction = intval(substr($dfrn_id,0,1)); $dfrn_id = substr($dfrn_id,2); } @@ -329,7 +329,7 @@ function dfrn_poll_post(App $a) { $contact_id = $r[0]['id']; - if($type === 'reputation' && strlen($url)) { + if ($type === 'reputation' && strlen($url)) { $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1", dbesc($url), intval($owner_uid) @@ -341,7 +341,7 @@ function dfrn_poll_post(App $a) { $reputation = $r[0]['rating']; $text = $r[0]['reason']; - if($r[0]['id'] == $contact_id) { // inquiring about own reputation not allowed + if ($r[0]['id'] == $contact_id) { // inquiring about own reputation not allowed $reputation = 0; $text = ''; } @@ -361,13 +361,13 @@ function dfrn_poll_post(App $a) { // Update the writable flag if it changed logger('dfrn_poll: post request feed: ' . print_r($_POST,true),LOGGER_DATA); - if($dfrn_version >= 2.21) { - if($perm === 'rw') + if ($dfrn_version >= 2.21) { + if ($perm === 'rw') $writable = 1; else $writable = 0; - if($writable != $contact['writable']) { + if ($writable != $contact['writable']) { q("UPDATE `contact` SET `writable` = %d WHERE `id` = %d", intval($writable), intval($contact_id) @@ -395,13 +395,13 @@ function dfrn_poll_content(App $a) { $quiet = ((x($_GET,'quiet')) ? true : false); $direction = (-1); - if(strpos($dfrn_id,':') == 1) { + if (strpos($dfrn_id,':') == 1) { $direction = intval(substr($dfrn_id,0,1)); $dfrn_id = substr($dfrn_id,2); } - if($dfrn_id != '') { + if ($dfrn_id != '') { // initial communication from external contact $hash = random_string(); @@ -409,7 +409,7 @@ function dfrn_poll_content(App $a) { $r = q("DELETE FROM `challenge` WHERE `expire` < " . intval(time())); - if($type !== 'profile') { + if ($type !== 'profile') { $r = q("INSERT INTO `challenge` ( `challenge`, `dfrn-id`, `expire` , `type`, `last_update` ) VALUES( '%s', '%s', '%s', '%s', '%s' ) ", dbesc($hash), @@ -422,7 +422,7 @@ function dfrn_poll_content(App $a) { $sql_extra = ''; switch($direction) { case (-1): - if($type === 'profile') + if ($type === 'profile') $sql_extra = sprintf(" AND ( `dfrn-id` = '%s' OR `issued-id` = '%s' ) ", dbesc($dfrn_id),dbesc($dfrn_id)); else $sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($dfrn_id)); @@ -456,7 +456,7 @@ function dfrn_poll_content(App $a) { $encrypted_id = ''; $id_str = $my_id . '.' . mt_rand(1000,9999); - if(($r[0]['duplex'] && strlen($r[0]['pubkey'])) || (! strlen($r[0]['prvkey']))) { + if (($r[0]['duplex'] && strlen($r[0]['pubkey'])) || (! strlen($r[0]['prvkey']))) { openssl_public_encrypt($hash,$challenge,$r[0]['pubkey']); openssl_public_encrypt($id_str,$encrypted_id,$r[0]['pubkey']); } @@ -474,11 +474,11 @@ function dfrn_poll_content(App $a) { $encrypted_id = ''; } - if(($type === 'profile') && (strlen($sec))) { + if (($type === 'profile') && (strlen($sec))) { // URL reply - if($dfrn_version < 2.2) { + if ($dfrn_version < 2.2) { $s = fetch_url($r[0]['poll'] . '?dfrn_id=' . $encrypted_id . '&type=profile-check' @@ -517,7 +517,7 @@ function dfrn_poll_content(App $a) { logger("dfrn_poll: sec profile: " . $s, LOGGER_DATA); - if(strlen($s) && strstr($s,'sec . ' expecting ' . $sec); - if(((int) $xml->status == 0) && ($xml->challenge == $hash) && ($xml->sec == $sec)) { + if (((int) $xml->status == 0) && ($xml->challenge == $hash) && ($xml->sec == $sec)) { $_SESSION['authenticated'] = 1; - if(! x($_SESSION,'remote')) + if (! x($_SESSION,'remote')) $_SESSION['remote'] = array(); $_SESSION['remote'][] = array('cid' => $r[0]['id'],'uid' => $r[0]['uid'],'url' => $r[0]['url']); $_SESSION['visitor_id'] = $r[0]['id']; $_SESSION['visitor_home'] = $r[0]['url']; $_SESSION['visitor_visiting'] = $r[0]['uid']; - if(!$quiet) + if (!$quiet) info( sprintf(t('%1$s welcomes %2$s'), $r[0]['username'] , $r[0]['name']) . EOL); // Visitors get 1 day session. $session_id = session_id(); diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 52b5eb9f9..a11ea1d9e 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -19,7 +19,7 @@ require_once('include/group.php'); function dfrn_request_init(App $a) { - if($a->argc > 1) + if ($a->argc > 1) $which = $a->argv[1]; profile_load($a,$which); @@ -44,13 +44,13 @@ function dfrn_request_init(App $a) { */ function dfrn_request_post(App $a) { - if(($a->argc != 2) || (! count($a->profile))) { + if (($a->argc != 2) || (! count($a->profile))) { logger('Wrong count of argc or profiles: argc=' . $a->argc . ',profile()=' . count($a->profile)); return; } - if(x($_POST, 'cancel')) { + if (x($_POST, 'cancel')) { goaway(z_root()); } @@ -63,13 +63,13 @@ function dfrn_request_post(App $a) { * */ - if((x($_POST,'localconfirm')) && ($_POST['localconfirm'] == 1)) { + if ((x($_POST,'localconfirm')) && ($_POST['localconfirm'] == 1)) { /* * Ensure this is a valid request */ - if(local_user() && ($a->user['nickname'] == $a->argv[1]) && (x($_POST,'dfrn_url'))) { + if (local_user() && ($a->user['nickname'] == $a->argv[1]) && (x($_POST,'dfrn_url'))) { $dfrn_url = notags(trim($_POST['dfrn_url'])); @@ -80,7 +80,7 @@ function dfrn_request_post(App $a) { $blocked = 1; $pending = 1; - if(x($dfrn_url)) { + if (x($dfrn_url)) { /* * Lookup the contact based on their URL (which is the only unique thing we have at the moment) @@ -92,7 +92,7 @@ function dfrn_request_post(App $a) { ); if (dbm::is_result($r)) { - if(strlen($r[0]['dfrn-id'])) { + if (strlen($r[0]['dfrn-id'])) { /* * We don't need to be here. It has already happened. @@ -105,7 +105,7 @@ function dfrn_request_post(App $a) { $contact_record = $r[0]; } - if(is_array($contact_record)) { + if (is_array($contact_record)) { $r = q("UPDATE `contact` SET `ret-aes` = %d, hidden = %d WHERE `id` = %d", intval($aes_allow), intval($hidden), @@ -187,7 +187,7 @@ function dfrn_request_post(App $a) { ); if (dbm::is_result($r)) { $def_gid = get_default_group(local_user(), $r[0]["network"]); - if(intval($def_gid)) + if (intval($def_gid)) group_add_member(local_user(), '', $r[0]['id'], $def_gid); if (isset($photo)) @@ -249,7 +249,7 @@ function dfrn_request_post(App $a) { * */ - if(! (is_array($a->profile) && count($a->profile))) { + if (! (is_array($a->profile) && count($a->profile))) { notice( t('Profile unavailable.') . EOL); return; } @@ -265,13 +265,13 @@ function dfrn_request_post(App $a) { $pending = 1; - if( x($_POST,'dfrn_url')) { + if ( x($_POST,'dfrn_url')) { /* * Block friend request spam */ - if($maxreq) { + if ($maxreq) { $r = q("SELECT * FROM `intro` WHERE `datetime` > '%s' AND `uid` = %d", dbesc(datetime_convert('UTC','UTC','now - 24 hours')), intval($uid) @@ -300,7 +300,7 @@ function dfrn_request_post(App $a) { ); if (dbm::is_result($r)) { foreach ($r as $rr) { - if(! $rr['rel']) { + if (! $rr['rel']) { q("DELETE FROM `contact` WHERE `id` = %d AND NOT `self`", intval($rr['cid']) ); @@ -325,7 +325,7 @@ function dfrn_request_post(App $a) { ); if (dbm::is_result($r)) { foreach ($r as $rr) { - if(! $rr['rel']) { + if (! $rr['rel']) { q("DELETE FROM `contact` WHERE `id` = %d AND NOT `self`", intval($rr['cid']) ); @@ -340,16 +340,16 @@ function dfrn_request_post(App $a) { $real_name = (x($_POST,'realname') ? notags(trim($_POST['realname'])) : ''); $url = trim($_POST['dfrn_url']); - if(! strlen($url)) { + if (! strlen($url)) { notice( t("Invalid locator") . EOL ); return; } $hcard = ''; - if($email_follow) { + if ($email_follow) { - if(! validate_email($url)) { + if (! validate_email($url)) { notice( t('Invalid email address.') . EOL); return; } @@ -365,10 +365,10 @@ function dfrn_request_post(App $a) { $rel = CONTACT_IS_FOLLOWER; $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); - if(get_config('system','dfrn_only')) + if (get_config('system','dfrn_only')) $mail_disabled = 1; - if(! $mail_disabled) { + if (! $mail_disabled) { $failed = false; $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", intval($uid) @@ -470,18 +470,18 @@ function dfrn_request_post(App $a) { logger('dfrn_request: url: ' . $url . ',network=' . $network, LOGGER_DEBUG); - if($network === NETWORK_DFRN) { + if ($network === NETWORK_DFRN) { $ret = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `self` = 0 LIMIT 1", intval($uid), dbesc($url) ); if (dbm::is_result($ret)) { - if(strlen($ret[0]['issued-id'])) { + if (strlen($ret[0]['issued-id'])) { notice( t('You have already introduced yourself here.') . EOL ); return; } - elseif($ret[0]['rel'] == CONTACT_IS_FRIEND) { + elseif ($ret[0]['rel'] == CONTACT_IS_FRIEND) { notice( sprintf( t('Apparently you are already friends with %s.'), $a->profile['name']) . EOL); return; } @@ -493,7 +493,7 @@ function dfrn_request_post(App $a) { $issued_id = random_string(); - if(is_array($contact_record)) { + if (is_array($contact_record)) { // There is a contact record but no issued-id, so this // is a reciprocal introduction from a known contact $r = q("UPDATE `contact` SET `issued-id` = '%s' WHERE `id` = %d", @@ -718,7 +718,7 @@ function dfrn_request_content(App $a) { return $o; } - elseif((x($_GET,'confirm_key')) && strlen($_GET['confirm_key'])) { + elseif ((x($_GET,'confirm_key')) && strlen($_GET['confirm_key'])) { // we are the requestee and it is now safe to send our user their introduction, // We could just unblock it, but first we have to jump through a few hoops to @@ -738,10 +738,10 @@ function dfrn_request_content(App $a) { $auto_confirm = false; if (dbm::is_result($r)) { - if(($r[0]['page-flags'] != PAGE_NORMAL) && ($r[0]['page-flags'] != PAGE_PRVGROUP)) + if (($r[0]['page-flags'] != PAGE_NORMAL) && ($r[0]['page-flags'] != PAGE_PRVGROUP)) $auto_confirm = true; - if(! $auto_confirm) { + if (! $auto_confirm) { notification(array( 'type' => NOTIFY_INTRO, @@ -759,7 +759,7 @@ function dfrn_request_content(App $a) { )); } - if($auto_confirm) { + if ($auto_confirm) { require_once('mod/dfrn_confirm.php'); $handsfree = array( 'uid' => $r[0]['uid'], @@ -774,7 +774,7 @@ function dfrn_request_content(App $a) { } - if(! $auto_confirm) { + if (! $auto_confirm) { // If we are auto_confirming, this record will have already been nuked // in dfrn_confirm_post() @@ -794,8 +794,8 @@ function dfrn_request_content(App $a) { * Normal web request. Display our user's introduction form. */ - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { - if(! get_config('system','local_block')) { + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if (! get_config('system','local_block')) { notice( t('Public access denied.') . EOL); return; } diff --git a/mod/directory.php b/mod/directory.php index ba48bb392..e49e718a5 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -3,7 +3,7 @@ function directory_init(App $a) { $a->set_pager_itemspage(60); - if(local_user()) { + if (local_user()) { require_once('include/contact_widgets.php'); $a->page['aside'] .= findpeople_widget(); @@ -21,7 +21,7 @@ function directory_init(App $a) { function directory_post(App $a) { - if(x($_POST,'search')) + if (x($_POST,'search')) $a->data['search'] = $_POST['search']; } @@ -32,7 +32,7 @@ function directory_content(App $a) { require_once("mod/proxy.php"); - if((get_config('system','block_public')) && (! local_user()) && (! remote_user()) || + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user()) || (get_config('system','block_local_dir')) && (! local_user()) && (! remote_user())) { notice( t('Public access denied.') . EOL); return; @@ -41,18 +41,18 @@ function directory_content(App $a) { $o = ''; nav_set_selected('directory'); - if(x($a->data,'search')) + if (x($a->data,'search')) $search = notags(trim($a->data['search'])); else $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); $gdirpath = ''; $dirurl = get_config('system','directory'); - if(strlen($dirurl)) { + if (strlen($dirurl)) { $gdirpath = zrl($dirurl,true); } - if($search) { + if ($search) { $search = dbesc($search); $sql_extra = " AND ((`profile`.`name` LIKE '%$search%') OR @@ -110,28 +110,28 @@ function directory_content(App $a) { $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '
' : ''); $details = ''; - if(strlen($rr['locality'])) + if (strlen($rr['locality'])) $details .= $rr['locality']; - if(strlen($rr['region'])) { - if(strlen($rr['locality'])) + if (strlen($rr['region'])) { + if (strlen($rr['locality'])) $details .= ', '; $details .= $rr['region']; } - if(strlen($rr['country-name'])) { - if(strlen($details)) + if (strlen($rr['country-name'])) { + if (strlen($details)) $details .= ', '; $details .= $rr['country-name']; } -// if(strlen($rr['dob'])) { -// if(($years = age($rr['dob'],$rr['timezone'],'')) != 0) +// if (strlen($rr['dob'])) { +// if (($years = age($rr['dob'],$rr['timezone'],'')) != 0) // $details .= '
' . t('Age: ') . $years ; // } -// if(strlen($rr['gender'])) +// if (strlen($rr['gender'])) // $details .= '
' . t('Gender: ') . $rr['gender']; $profile = $rr; - if((x($profile,'address') == 1) + if ((x($profile,'address') == 1) || (x($profile,'locality') == 1) || (x($profile,'region') == 1) || (x($profile,'postal-code') == 1) @@ -146,7 +146,7 @@ function directory_content(App $a) { $about = ((x($profile,'about') == 1) ? t('About:') : False); - if($a->theme['template_engine'] === 'internal') { + if ($a->theme['template_engine'] === 'internal') { $location_e = template_escape($location); } else { @@ -185,8 +185,9 @@ function directory_content(App $a) { unset($profile); unset($location); - if(! $arr['entry']) + if (! $arr['entry']) { continue; + } $entries[] = $arr['entry']; diff --git a/mod/dirfind.php b/mod/dirfind.php index 1b19ad92c..0e5f8a90d 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -166,8 +166,9 @@ function dirfind_content(App $a, $prefix = "") { $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); - if(strlen(get_config('system','directory'))) + if (strlen(get_config('system','directory'))) { $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search)); + } $j = json_decode($x); } diff --git a/mod/editpost.php b/mod/editpost.php index f3746317a..5dc5ec508 100644 --- a/mod/editpost.php +++ b/mod/editpost.php @@ -51,7 +51,7 @@ function editpost_content(App $a) { $tpl = get_markup_template("jot.tpl"); - if(($group) || (is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) + if (($group) || (is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) $lockstate = 'lock'; else $lockstate = 'unlock'; @@ -64,13 +64,13 @@ function editpost_content(App $a) { $mail_enabled = false; $pubmail_enabled = false; - if(! $mail_disabled) { + if (! $mail_disabled) { $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user()) ); if (dbm::is_result($r)) { $mail_enabled = true; - if(intval($r[0]['pubmail'])) + if (intval($r[0]['pubmail'])) $pubmail_enabled = true; } } @@ -78,7 +78,7 @@ function editpost_content(App $a) { // I don't think there's any need for the $jotnets when editing the post, // and including them makes it difficult for the JS-free theme, so let's // disable them -/* if($mail_enabled) { +/* if ($mail_enabled) { $selected = (($pubmail_enabled) ? ' checked="checked" ' : ''); $jotnets .= '
' . t("Post to Email") . '
'; diff --git a/mod/events.php b/mod/events.php index ac0c444cb..2dd79a029 100644 --- a/mod/events.php +++ b/mod/events.php @@ -105,9 +105,9 @@ function events_post(App $a) { goaway($onerror_url); } - if((! $summary) || (! $start)) { + if ((! $summary) || (! $start)) { notice( t('Event title and start time are required.') . EOL); - if(intval($_REQUEST['preview'])) { + if (intval($_REQUEST['preview'])) { echo( t('Event title and start time are required.')); killme(); } @@ -119,27 +119,27 @@ function events_post(App $a) { $c = q("select id from contact where uid = %d and self = 1 limit 1", intval(local_user()) ); - if(count($c)) + if (count($c)) $self = $c[0]['id']; else $self = 0; - if($share) { + if ($share) { $str_group_allow = perms2str($_POST['group_allow']); $str_contact_allow = perms2str($_POST['contact_allow']); $str_group_deny = perms2str($_POST['group_deny']); $str_contact_deny = perms2str($_POST['contact_deny']); // Undo the pseudo-contact of self, since there are real contacts now - if( strpos($str_contact_allow, '<' . $self . '>') !== false ) + if ( strpos($str_contact_allow, '<' . $self . '>') !== false ) { $str_contact_allow = str_replace('<' . $self . '>', '', $str_contact_allow); } // Make sure to set the `private` field as true. This is necessary to // have the posts show up correctly in Diaspora if an event is created // as visible only to self at first, but then edited to display to others. - if( strlen($str_group_allow) or strlen($str_contact_allow) or strlen($str_group_deny) or strlen($str_contact_deny) ) + if ( strlen($str_group_allow) or strlen($str_contact_allow) or strlen($str_group_deny) or strlen($str_contact_deny) ) { $private_event = true; } @@ -173,7 +173,7 @@ function events_post(App $a) { $datarray['created'] = $created; $datarray['edited'] = $edited; - if(intval($_REQUEST['preview'])) { + if (intval($_REQUEST['preview'])) { $html = format_event_html($datarray); echo $html; killme(); @@ -181,7 +181,7 @@ function events_post(App $a) { $item_id = event_store($datarray); - if(! $cid) + if (! $cid) proc_run(PRIORITY_HIGH, "include/notifier.php", "event", $item_id); goaway($_SESSION['return_url']); @@ -248,7 +248,7 @@ function events_content(App $a) { $m = 0; $ignored = ((x($_REQUEST,'ignored')) ? intval($_REQUEST['ignored']) : 0); - if($a->argc > 1) { + if ($a->argc > 1) { if ($a->argc > 2 && $a->argv[1] == 'event') { $mode = 'edit'; $event_id = intval($a->argv[2]); @@ -289,13 +289,13 @@ function events_content(App $a) { $nextyear = $y; $nextmonth = $m + 1; - if($nextmonth > 12) { + if ($nextmonth > 12) { $nextmonth = 1; $nextyear ++; } $prevyear = $y; - if($m > 1) + if ($m > 1) $prevmonth = $m - 1; else { $prevmonth = 12; @@ -371,9 +371,9 @@ function events_content(App $a) { } // Get rid of dashes in key names, Smarty3 can't handle them - foreach($events as $key => $event) { + foreach ($events as $key => $event) { $event_item = array(); - foreach($event['item'] as $k => $v) { + foreach ($event['item'] as $k => $v) { $k = str_replace('-','_',$k); $event_item[$k] = $v; } @@ -405,7 +405,7 @@ function events_content(App $a) { } - if($mode === 'edit' && $event_id) { + if ($mode === 'edit' && $event_id) { $r = q("SELECT * FROM `event` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($event_id), intval(local_user()) @@ -415,19 +415,19 @@ function events_content(App $a) { } // Passed parameters overrides anything found in the DB - if($mode === 'edit' || $mode === 'new') { - if(!x($orig_event)) $orig_event = array(); + if ($mode === 'edit' || $mode === 'new') { + if (!x($orig_event)) $orig_event = array(); // In case of an error the browser is redirected back here, with these parameters filled in with the previous values - if(x($_REQUEST,'nofinish')) $orig_event['nofinish'] = $_REQUEST['nofinish']; - if(x($_REQUEST,'adjust')) $orig_event['adjust'] = $_REQUEST['adjust']; - if(x($_REQUEST,'summary')) $orig_event['summary'] = $_REQUEST['summary']; - if(x($_REQUEST,'description')) $orig_event['description'] = $_REQUEST['description']; - if(x($_REQUEST,'location')) $orig_event['location'] = $_REQUEST['location']; - if(x($_REQUEST,'start')) $orig_event['start'] = $_REQUEST['start']; - if(x($_REQUEST,'finish')) $orig_event['finish'] = $_REQUEST['finish']; + if (x($_REQUEST,'nofinish')) $orig_event['nofinish'] = $_REQUEST['nofinish']; + if (x($_REQUEST,'adjust')) $orig_event['adjust'] = $_REQUEST['adjust']; + if (x($_REQUEST,'summary')) $orig_event['summary'] = $_REQUEST['summary']; + if (x($_REQUEST,'description')) $orig_event['description'] = $_REQUEST['description']; + if (x($_REQUEST,'location')) $orig_event['location'] = $_REQUEST['location']; + if (x($_REQUEST,'start')) $orig_event['start'] = $_REQUEST['start']; + if (x($_REQUEST,'finish')) $orig_event['finish'] = $_REQUEST['finish']; } - if($mode === 'edit' || $mode === 'new') { + if ($mode === 'edit' || $mode === 'new') { $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : ''); $a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : ''); @@ -439,21 +439,24 @@ function events_content(App $a) { $uri = ((x($orig_event)) ? $orig_event['uri'] : ''); - if(! x($orig_event)) + if (! x($orig_event)) { $sh_checked = ''; - else + } else { $sh_checked = (($orig_event['allow_cid'] === '<' . local_user() . '>' && (! $orig_event['allow_gid']) && (! $orig_event['deny_cid']) && (! $orig_event['deny_gid'])) ? '' : ' checked="checked" ' ); + } - if($cid OR ($mode !== 'new')) + if ($cid OR ($mode !== 'new')) { $sh_checked .= ' disabled="disabled" '; + } $sdt = ((x($orig_event)) ? $orig_event['start'] : 'now'); $fdt = ((x($orig_event)) ? $orig_event['finish'] : 'now'); $tz = date_default_timezone_get(); - if(x($orig_event)) + if (x($orig_event)) { $tz = (($orig_event['adjust']) ? date_default_timezone_get() : 'UTC'); + } $syear = datetime_convert('UTC', $tz, $sdt, 'Y'); $smonth = datetime_convert('UTC', $tz, $sdt, 'm'); @@ -470,8 +473,9 @@ function events_content(App $a) { $fminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0); $f = get_config('system','event_input_format'); - if(! $f) + if (! $f) { $f = 'ymd'; + } require_once('include/acl_selectors.php'); diff --git a/mod/fbrowser.php b/mod/fbrowser.php index 9a0e9244c..ae62ce9a3 100644 --- a/mod/fbrowser.php +++ b/mod/fbrowser.php @@ -66,10 +66,9 @@ function fbrowser_content(App $a) { $types = Photo::supportedTypes(); $ext = $types[$rr['type']]; - if($a->theme['template_engine'] === 'internal') { + if ($a->theme['template_engine'] === 'internal') { $filename_e = template_escape($rr['filename']); - } - else { + } else { $filename_e = $rr['filename']; } diff --git a/mod/filer.php b/mod/filer.php index 47c4aa5e4..d2df7f24c 100644 --- a/mod/filer.php +++ b/mod/filer.php @@ -16,7 +16,7 @@ function filer_content(App $a) { logger('filer: tag ' . $term . ' item ' . $item_id); - if($item_id && strlen($term)){ + if ($item_id && strlen($term)){ // file item file_tag_save_file(local_user(),$item_id,$term); } else { diff --git a/mod/friendica.php b/mod/friendica.php index f613dfd39..f1f0a6a0f 100644 --- a/mod/friendica.php +++ b/mod/friendica.php @@ -7,7 +7,7 @@ function friendica_init(App $a) { $register_policy = Array('REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN'); $sql_extra = ''; - if(x($a->config,'admin_nickname')) { + if (x($a->config,'admin_nickname')) { $sql_extra = sprintf(" AND nickname = '%s' ",dbesc($a->config['admin_nickname'])); } if (isset($a->config['admin_email']) && $a->config['admin_email']!=''){ @@ -24,18 +24,18 @@ function friendica_init(App $a) { } $visible_plugins = array(); - if(is_array($a->plugins) && count($a->plugins)) { + if (is_array($a->plugins) && count($a->plugins)) { $r = q("select * from addon where hidden = 0"); if (dbm::is_result($r)) - foreach($r as $rr) + foreach ($r as $rr) $visible_plugins[] = $rr['name']; } Config::load('feature_lock'); $locked_features = array(); - if(is_array($a->config['feature_lock']) && count($a->config['feature_lock'])) { - foreach($a->config['feature_lock'] as $k => $v) { - if($k === 'config_loaded') + if (is_array($a->config['feature_lock']) && count($a->config['feature_lock'])) { + foreach ($a->config['feature_lock'] as $k => $v) { + if ($k === 'config_loaded') continue; $locked_features[$k] = intval($v); } @@ -80,22 +80,24 @@ function friendica_content(App $a) { $o .= '

'; $visible_plugins = array(); - if(is_array($a->plugins) && count($a->plugins)) { + if (is_array($a->plugins) && count($a->plugins)) { $r = q("select * from addon where hidden = 0"); if (dbm::is_result($r)) - foreach($r as $rr) + foreach ($r as $rr) $visible_plugins[] = $rr['name']; } - if(count($visible_plugins)) { + if (count($visible_plugins)) { $o .= '

' . t('Installed plugins/addons/apps:') . '

'; $sorted = $visible_plugins; $s = ''; sort($sorted); - foreach($sorted as $p) { - if(strlen($p)) { - if(strlen($s)) $s .= ', '; + foreach ($sorted as $p) { + if (strlen($p)) { + if (strlen($s)) { + $s .= ', '; + } $s .= $p; } } diff --git a/mod/fsuggest.php b/mod/fsuggest.php index b3d543971..2cd91ea57 100644 --- a/mod/fsuggest.php +++ b/mod/fsuggest.php @@ -29,7 +29,7 @@ function fsuggest_post(App $a) { $note = escape_tags(trim($_POST['note'])); - if($new_contact) { + if ($new_contact) { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($new_contact), intval(local_user()) @@ -80,8 +80,9 @@ function fsuggest_content(App $a) { return; } - if($a->argc != 2) + if ($a->argc != 2) { return; + } $contact_id = intval($a->argv[1]); diff --git a/mod/group.php b/mod/group.php index 2b332e401..640fa7e60 100644 --- a/mod/group.php +++ b/mod/group.php @@ -5,7 +5,7 @@ function validate_members(&$item) { } function group_init(App $a) { - if(local_user()) { + if (local_user()) { require_once('include/group.php'); $a->page['aside'] = group_side('contacts','group','extended',(($a->argc > 1) ? intval($a->argv[1]) : 0)); } @@ -20,7 +20,7 @@ function group_post(App $a) { return; } - if(($a->argc == 2) && ($a->argv[1] === 'new')) { + if (($a->argc == 2) && ($a->argv[1] === 'new')) { check_form_security_token_redirectOnErr('/group/new', 'group_edit'); $name = notags(trim($_POST['groupname'])); @@ -80,10 +80,12 @@ function group_content(App $a) { // Switch to text mode interface if we have more than 'n' contacts or group members $switchtotext = get_pconfig(local_user(),'system','groupedit_image_limit'); - if($switchtotext === false) + if ($switchtotext === false) { $switchtotext = get_config('system','groupedit_image_limit'); - if($switchtotext === false) + } + if ($switchtotext === false) { $switchtotext = 400; + } $tpl = get_markup_template('group_edit.tpl'); @@ -99,8 +101,6 @@ function group_content(App $a) { '$gid' => 'new', '$form_security_token' => get_form_security_token("group_edit"), )); - - } if (($a->argc == 3) && ($a->argv[1] === 'drop')) { @@ -135,8 +135,9 @@ function group_content(App $a) { intval($a->argv[2]), intval(local_user()) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $change = intval($a->argv[2]); + } } if (($a->argc > 1) && (intval($a->argv[1]))) { @@ -153,23 +154,23 @@ function group_content(App $a) { $group = $r[0]; $members = group_get_members($group['id']); $preselected = array(); - if(count($members)) { - foreach($members as $member) + if (count($members)) { + foreach ($members as $member) { $preselected[] = $member['id']; + } } - if($change) { - if(in_array($change,$preselected)) { + if ($change) { + if (in_array($change,$preselected)) { group_rmv_member(local_user(),$group['name'],$change); - } - else { + } else { group_add_member(local_user(),$group['name'],$change); } $members = group_get_members($group['id']); $preselected = array(); - if(count($members)) { - foreach($members as $member) + if (count($members)) { + foreach ($members as $member) $preselected[] = $member['id']; } } @@ -193,8 +194,9 @@ function group_content(App $a) { } - if(! isset($group)) + if (! isset($group)) { return; + } $groupeditor = array( 'label_members' => t('Members'), @@ -206,13 +208,13 @@ function group_content(App $a) { $sec_token = addslashes(get_form_security_token('group_member_change')); $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false); - foreach($members as $member) { - if($member['url']) { + foreach ($members as $member) { + if ($member['url']) { $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;'; $groupeditor['members'][] = micropro($member,true,'mpgroup', $textmode); - } - else + } else { group_rmv_member(local_user(),$group['name'],$member['id']); + } } $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `self` ORDER BY `name` ASC", @@ -221,8 +223,8 @@ function group_content(App $a) { if (dbm::is_result($r)) { $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false); - foreach($r as $member) { - if(! in_array($member['id'],$preselected)) { + foreach ($r as $member) { + if (! in_array($member['id'],$preselected)) { $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;'; $groupeditor['contacts'][] = micropro($member,true,'mpall', $textmode); } @@ -232,7 +234,7 @@ function group_content(App $a) { $context['$groupeditor'] = $groupeditor; $context['$desc'] = t('Click on a contact to add or remove.'); - if($change) { + if ($change) { $tpl = get_markup_template('groupeditor.tpl'); echo replace_macros($tpl, $context); killme(); diff --git a/mod/help.php b/mod/help.php index c380aa391..602653eea 100644 --- a/mod/help.php +++ b/mod/help.php @@ -30,9 +30,10 @@ function help_content(App $a) { $path = ''; // looping through the argv keys bigger than 0 to build // a path relative to /help - for($x = 1; $x < argc(); $x ++) { - if(strlen($path)) + for ($x = 1; $x < argc(); $x ++) { + if (strlen($path)) { $path .= '/'; + } $path .= argv($x); } $title = basename($path); @@ -65,16 +66,22 @@ function help_content(App $a) { $toc="

TOC

    "; $lastlevel=1; $idnum = array(0,0,0,0,0,0,0); - foreach($lines as &$line){ + foreach ($lines as &$line){ if (substr($line,0,2)=="$lastlevel) { + $toc.="
      "; } - if ($level>$lastlevel) $toc.="
        "; $idnum[$level]++; $id = implode("_", array_slice($idnum,1,$level)); $href = App::get_baseurl()."/help/{$filename}#{$id}"; @@ -84,7 +91,7 @@ function help_content(App $a) { } } } - for($k=0;$k<$lastlevel; $k++) $toc.="
      "; + for ($k=0;$k<$lastlevel; $k++) $toc.="
    "; $html = implode("\n",$lines); $a->page['aside'] = $toc.$a->page['aside']; diff --git a/mod/home.php b/mod/home.php index b1708d80a..ae85593dd 100644 --- a/mod/home.php +++ b/mod/home.php @@ -1,6 +1,6 @@ account_type($contact), 'actions' => $actions, ); - if($datatype == "html") { + if ($datatype == "html") { $t = get_markup_template("hovercard.tpl"); $o = replace_macros($t, array( @@ -110,7 +110,7 @@ function get_template_content($template, $root = "") { $filename = $t->filename; // Get the content of the template file - if(file_exists($filename)) { + if (file_exists($filename)) { $content = file_get_contents($filename); return $content; diff --git a/mod/ignored.php b/mod/ignored.php index 0065d51c5..a31171307 100644 --- a/mod/ignored.php +++ b/mod/ignored.php @@ -37,8 +37,11 @@ function ignored_init(App $a) { $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : ''); if ($return_path) { $rand = '_=' . time(); - if(strpos($return_path, '?')) $rand = "&$rand"; - else $rand = "?$rand"; + if (strpos($return_path, '?')) { + $rand = "&$rand"; + } else { + $rand = "?$rand"; + } goaway(App::get_baseurl() . "/" . $return_path . $rand); } diff --git a/mod/install.php b/mod/install.php index fa952a79b..215c00111 100755 --- a/mod/install.php +++ b/mod/install.php @@ -43,11 +43,11 @@ function install_post(App $a) { require_once("include/dba.php"); unset($db); $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true); - /*if(get_db_errno()) { + /*if (get_db_errno()) { unset($db); $db = new dba($dbhost, $dbuser, $dbpass, '', true); - if(! get_db_errno()) { + if (! get_db_errno()) { $r = q("CREATE DATABASE '%s'", dbesc($dbdata) ); @@ -164,7 +164,7 @@ function install_content(App $a) { $db_return_text .= $txt; } - if($db && $db->connected) { + if ($db && $db->connected) { $r = q("SELECT COUNT(*) as `total` FROM `user`"); if (dbm::is_result($r) && $r[0]['total']) { $tpl = get_markup_template('install.tpl'); @@ -360,13 +360,13 @@ function check_php(&$phpath, &$checks) { check_add($checks, t('Command line PHP').($passed?" ($phpath)":""), $passed, false, $help); - if($passed) { + if ($passed) { $cmd = "$phpath -v"; $result = trim(shell_exec($cmd)); $passed2 = ( strpos($result, "(cli)") !== false ); list($result) = explode("\n", $result); $help = ""; - if(!$passed2) { + if (!$passed2) { $help .= t('PHP executable is not the php cli binary (could be cgi-fgci version)'). EOL; $help .= t('Found PHP version: ')."$result"; } @@ -380,7 +380,7 @@ function check_php(&$phpath, &$checks) { $result = trim(shell_exec($cmd)); $passed3 = $result == $str; $help = ""; - if(!$passed3) { + if (!$passed3) { $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL; $help .= t('This is required for message delivery to work.'); } @@ -485,7 +485,7 @@ function check_funcs(&$checks) { $ck_funcs[6]['help'] = t('Error, XML PHP module required but not installed.'); } - /*if((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg'])) + /*if ((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg'])) notice( t('Please see the file "INSTALL.txt".') . EOL);*/ } @@ -589,10 +589,10 @@ function load_database($db) { /* $str = file_get_contents('database.sql'); $arr = explode(';',$str); $errors = false; - foreach($arr as $a) { - if(strlen(trim($a))) { + foreach ($arr as $a) { + if (strlen(trim($a))) { $r = @$db->q(trim($a)); - if(false === $r) { + if (false === $r) { $errors .= t('Errors encountered creating database tables.') . $a . EOL; } } diff --git a/mod/invite.php b/mod/invite.php index f5c60e1ed..fef5ce834 100644 --- a/mod/invite.php +++ b/mod/invite.php @@ -83,7 +83,7 @@ function invite_post(App $a) { $total ++; $current_invites ++; set_pconfig(local_user(),'system','sent_invites',$current_invites); - if($current_invites > $max_invites) { + if ($current_invites > $max_invites) { notice( t('Invitation limit exceeded. Please contact your site administrator.') . EOL); return; } diff --git a/mod/item.php b/mod/item.php index 6da9ce88e..8fb3ecb54 100644 --- a/mod/item.php +++ b/mod/item.php @@ -29,14 +29,14 @@ require_once('include/Contact.php'); function item_post(App $a) { - if((! local_user()) && (! remote_user()) && (! x($_REQUEST,'commenter'))) + if ((! local_user()) && (! remote_user()) && (! x($_REQUEST,'commenter'))) return; require_once('include/security.php'); $uid = local_user(); - if(x($_REQUEST,'dropitems')) { + if (x($_REQUEST,'dropitems')) { $arr_drop = explode(',',$_REQUEST['dropitems']); drop_items($arr_drop); $json = array('success' => 1); @@ -125,7 +125,7 @@ function item_post(App $a) { $parent = $r[0]['id']; // multi-level threading - preserve the info but re-parent to our single level threading - //if(($parid) && ($parid != $parent)) + //if (($parid) && ($parid != $parent)) $thr_parent = $parent_uri; if ($parent_item['contact-id'] && $uid) { @@ -162,7 +162,7 @@ function item_post(App $a) { } } - if($parent) logger('mod_item: item_post parent=' . $parent); + if ($parent) logger('mod_item: item_post parent=' . $parent); $profile_uid = ((x($_REQUEST,'profile_uid')) ? intval($_REQUEST['profile_uid']) : 0); $post_id = ((x($_REQUEST,'post_id')) ? intval($_REQUEST['post_id']) : 0); @@ -189,9 +189,9 @@ function item_post(App $a) { // First check that the parent exists and it is a wall item. - if((x($_REQUEST,'commenter')) && ((! $parent) || (! $parent_item['wall']))) { + if ((x($_REQUEST,'commenter')) && ((! $parent) || (! $parent_item['wall']))) { notice( t('Permission denied.') . EOL) ; - if(x($_REQUEST,'return')) + if (x($_REQUEST,'return')) goaway($return_path); killme(); } @@ -201,9 +201,9 @@ function item_post(App $a) { - if((! can_write_wall($a,$profile_uid)) && (! $allow_moderated)) { + if ((! can_write_wall($a,$profile_uid)) && (! $allow_moderated)) { notice( t('Permission denied.') . EOL) ; - if(x($_REQUEST,'return')) + if (x($_REQUEST,'return')) goaway($return_path); killme(); } @@ -213,7 +213,7 @@ function item_post(App $a) { $orig_post = null; - if($post_id) { + if ($post_id) { $i = q("SELECT * FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($profile_uid), intval($post_id) @@ -232,7 +232,7 @@ function item_post(App $a) { if (dbm::is_result($r)) $user = $r[0]; - if($orig_post) { + if ($orig_post) { $str_group_allow = $orig_post['allow_gid']; $str_contact_allow = $orig_post['allow_cid']; $str_group_deny = $orig_post['deny_gid']; @@ -258,7 +258,7 @@ function item_post(App $a) { // use the user default permissions - as they won't have // been supplied via a form. - if(($api_source) + if (($api_source) && (! array_key_exists('contact_allow',$_REQUEST)) && (! array_key_exists('group_allow',$_REQUEST)) && (! array_key_exists('contact_deny',$_REQUEST)) @@ -295,12 +295,12 @@ function item_post(App $a) { $private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0); - if($user['hidewall']) + if ($user['hidewall']) $private = 2; // If this is a comment, set the permissions from the parent. - if($parent_item) { + if ($parent_item) { // for non native networks use the network of the original post as network of the item if (($parent_item['network'] != NETWORK_DIASPORA) @@ -319,9 +319,9 @@ function item_post(App $a) { // if using the API, we won't see pubmail_enable - figure out if it should be set - if($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) { + if ($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) { $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); - if(! $mail_disabled) { + if (! $mail_disabled) { $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user()) ); @@ -330,17 +330,17 @@ function item_post(App $a) { } } - if(! strlen($body)) { - if($preview) + if (! strlen($body)) { + if ($preview) killme(); info( t('Empty post discarded.') . EOL ); - if(x($_REQUEST,'return')) + if (x($_REQUEST,'return')) goaway($return_path); killme(); } } - if(strlen($categories)) { + if (strlen($categories)) { // get the "fileas" tags for this post $filedas = file_tag_file_to_list($categories, 'file'); } @@ -348,7 +348,7 @@ function item_post(App $a) { $categories_old = $categories; $categories = file_tag_list_to_file(trim($_REQUEST['category']), 'category'); $categories_new = $categories; - if(strlen($filedas)) { + if (strlen($filedas)) { // append the fileas stuff to the new categories list $categories .= file_tag_list_to_file($filedas, 'file'); } @@ -359,21 +359,21 @@ function item_post(App $a) { $self = false; $contact_id = 0; - if((local_user()) && (local_user() == $profile_uid)) { + if ((local_user()) && (local_user() == $profile_uid)) { $self = true; $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($_SESSION['uid'])); } - elseif(remote_user()) { - if(is_array($_SESSION['remote'])) { - foreach($_SESSION['remote'] as $v) { - if($v['uid'] == $profile_uid) { + elseif (remote_user()) { + if (is_array($_SESSION['remote'])) { + foreach ($_SESSION['remote'] as $v) { + if ($v['uid'] == $profile_uid) { $contact_id = $v['cid']; break; } } } - if($contact_id) { + if ($contact_id) { $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", intval($contact_id) ); @@ -387,7 +387,7 @@ function item_post(App $a) { // get contact info for owner - if($profile_uid == local_user()) { + if ($profile_uid == local_user()) { $contact_record = $author; } else { @@ -400,9 +400,9 @@ function item_post(App $a) { $post_type = notags(trim($_REQUEST['type'])); - if($post_type === 'net-comment') { - if($parent_item !== null) { - if($parent_item['wall'] == 1) + if ($post_type === 'net-comment') { + if ($parent_item !== null) { + if ($parent_item['wall'] == 1) $post_type = 'wall-comment'; else $post_type = 'remote-comment'; @@ -423,9 +423,9 @@ function item_post(App $a) { $match = null; - if((! $preview) && preg_match_all("/\[img([\=0-9x]*?)\](.*?)\[\/img\]/",$body,$match)) { + if ((! $preview) && preg_match_all("/\[img([\=0-9x]*?)\](.*?)\[\/img\]/",$body,$match)) { $images = $match[2]; - if(count($images)) { + if (count($images)) { $objecttype = ACTIVITY_OBJ_IMAGE; @@ -472,10 +472,10 @@ function item_post(App $a) { $match = false; - if((! $preview) && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",$body,$match)) { + if ((! $preview) && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",$body,$match)) { $attaches = $match[1]; - if(count($attaches)) { - foreach($attaches as $attach) { + if (count($attaches)) { + foreach ($attaches as $attach) { $r = q("SELECT * FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($profile_uid), intval($attach) @@ -572,24 +572,26 @@ function item_post(App $a) { $private_forum = false; - if(count($tags)) { - foreach($tags as $tag) { + if (count($tags)) { + foreach ($tags as $tag) { - if(strpos($tag,'#') === 0) + if (strpos($tag,'#') === 0) { continue; + } // If we already tagged 'Robert Johnson', don't try and tag 'Robert'. // Robert Johnson should be first in the $tags array $fullnametagged = false; - for($x = 0; $x < count($tagged); $x ++) { - if(stristr($tagged[$x],$tag . ' ')) { + for ($x = 0; $x < count($tagged); $x ++) { + if (stristr($tagged[$x],$tag . ' ')) { $fullnametagged = true; break; } } - if($fullnametagged) + if ($fullnametagged) { continue; + } $success = handle_tag($a, $body, $inform, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag, $network); if ($success['replaced']) { @@ -722,15 +724,16 @@ function item_post(App $a) { $datarray['last-child'] = 1; $datarray['visible'] = 1; - if($orig_post) + if ($orig_post) { $datarray['edit'] = true; + } // Search for hashtags item_body_set_hashtags($datarray); // preview mode - prepare the body for display and send it via json - if($preview) { + if ($preview) { require_once('include/conversation.php'); // We set the datarray ID to -1 because in preview mode the dataray // doesn't have an ID. @@ -744,9 +747,9 @@ function item_post(App $a) { call_hooks('post_local',$datarray); - if(x($datarray,'cancel')) { + if (x($datarray,'cancel')) { logger('mod_item: post cancelled by plugin.'); - if($return_path) { + if ($return_path) { goaway($return_path); } @@ -762,7 +765,7 @@ function item_post(App $a) { // Fill the cache field put_item_in_cache($datarray); - if($orig_post) { + if ($orig_post) { $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `attach` = '%s', `file` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($datarray['title']), dbesc($datarray['body']), @@ -785,7 +788,7 @@ function item_post(App $a) { file_tag_update_pconfig($uid,$categories_old,$categories_new,'category'); proc_run(PRIORITY_HIGH, "include/notifier.php", 'edit_post', $post_id); - if((x($_REQUEST,'return')) && strlen($return_path)) { + if ((x($_REQUEST,'return')) && strlen($return_path)) { logger('return: ' . $return_path); goaway($return_path); } @@ -900,7 +903,7 @@ function item_post(App $a) { // update filetags in pconfig file_tag_update_pconfig($uid,$categories_old,$categories_new,'category'); - if($parent) { + if ($parent) { // This item is the last leaf and gets the comment box, clear any ancestors $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d AND `last-child` AND `id` != %d", @@ -916,7 +919,7 @@ function item_post(App $a) { intval($parent) ); - if($contact_record != $author) { + if ($contact_record != $author) { notification(array( 'type' => NOTIFY_COMMENT, 'notify_flags' => $user['notify-flags'], @@ -948,7 +951,7 @@ function item_post(App $a) { intval($parent), intval($post_id)); - if($contact_record != $author) { + if ($contact_record != $author) { notification(array( 'type' => NOTIFY_WALL, 'notify_flags' => $user['notify-flags'], @@ -957,7 +960,7 @@ function item_post(App $a) { 'to_email' => $user['email'], 'uid' => $user['uid'], 'item' => $datarray, - 'link' => App::get_baseurl().'/display/'.urlencode($datarray['guid']), + 'link' => App::get_baseurl().'/display/'.urlencode($datarray['guid']), 'source_name' => $datarray['author-name'], 'source_link' => $datarray['author-link'], 'source_photo' => $datarray['author-avatar'], @@ -969,12 +972,12 @@ function item_post(App $a) { call_hooks('post_local_end', $datarray); - if(strlen($emailcc) && $profile_uid == local_user()) { + if (strlen($emailcc) && $profile_uid == local_user()) { $erecips = explode(',', $emailcc); - if(count($erecips)) { - foreach($erecips as $recip) { + if (count($erecips)) { + foreach ($erecips as $recip) { $addr = trim($recip); - if(! strlen($addr)) + if (! strlen($addr)) continue; $disclaimer = '
    ' . sprintf( t('This message was sent to you by %s, a member of the Friendica social network.'),$a->user['username']) . '
    '; @@ -1032,8 +1035,9 @@ function item_post(App $a) { function item_post_return($baseurl, $api_source, $return_path) { // figure out how to return, depending on from whence we came - if($api_source) + if ($api_source) { return; + } if ($return_path) { goaway($return_path); @@ -1111,19 +1115,24 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo $r = q("SELECT `alias`, `name` FROM `contact` WHERE `nurl` = '%s' AND `alias` != '' AND `uid` = 0", normalise_link($matches[1])); - if (!$r) + + if (!dbm::is_result($r)) { $r = q("SELECT `alias`, `name` FROM `gcontact` WHERE `nurl` = '%s' AND `alias` != ''", normalise_link($matches[1])); - if ($r) + + } + if (dbm::is_result($r)) { $data = $r[0]; - else + } else { $data = probe_url($matches[1]); + } if ($data["alias"] != "") { $newtag = '@[url='.$data["alias"].']'.$data["name"].'[/url]'; - if(!stristr($str_tags,$newtag)) { - if(strlen($str_tags)) + if (!stristr($str_tags,$newtag)) { + if (strlen($str_tags)) { $str_tags .= ','; + } $str_tags .= $newtag; } } @@ -1155,7 +1164,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo ); // Then check in the contact table for the url - if (!$r) + if (!dbm::is_result($r)) { $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND (`network` != '%s' OR (`notify` != '' AND `alias` != '')) @@ -1164,6 +1173,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo intval($profile_uid), dbesc(NETWORK_OSTATUS) ); + } // Then check in the global contacts for the address if (!$r) @@ -1175,15 +1185,16 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo ); // Then check in the global contacts for the url - if (!$r) + if (!dbm::is_result($r)) { $r = q("SELECT `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `gcontact` WHERE `nurl` = '%s' AND (`network` != '%s' OR (`notify` != '' AND `alias` != '')) LIMIT 1", dbesc(normalise_link($name)), dbesc(NETWORK_OSTATUS) ); + } - if (!$r) { + if (!dbm::is_result($r)) { $probed = probe_url($name); if ($result['network'] != NETWORK_PHANTOM) { update_gcontact($probed); @@ -1204,54 +1215,60 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo } //select someone by attag or nick and the name passed in the current network - if(!$r AND ($network != "")) + if (!dbm::is_result($r) AND ($network != "")) { $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `network` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", dbesc($name), dbesc($name), dbesc($network), intval($profile_uid) ); + } //select someone from this user's contacts by name in the current network - if (!$r AND ($network != "")) + if (!dbm::is_result($r) AND ($network != "")) { $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `network` = '%s' AND `uid` = %d LIMIT 1", dbesc($name), dbesc($network), intval($profile_uid) ); + } //select someone by attag or nick and the name passed in - if(!$r) + if (!dbm::is_result($r)) { $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", dbesc($name), dbesc($name), intval($profile_uid) ); - + } //select someone from this user's contacts by name - if(!$r) + if (!dbm::is_result($r)) { $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", dbesc($name), intval($profile_uid) ); + } } - if ($r) { - if(strlen($inform) AND (isset($r[0]["notify"]) OR isset($r[0]["id"]))) + if (dbm::is_result($r)) { + if (strlen($inform) AND (isset($r[0]["notify"]) OR isset($r[0]["id"]))) { $inform .= ','; + } - if (isset($r[0]["id"])) + if (isset($r[0]["id"])) { $inform .= 'cid:' . $r[0]["id"]; - elseif (isset($r[0]["notify"])) + } elseif (isset($r[0]["notify"])) { $inform .= $r[0]["notify"]; + } $profile = $r[0]["url"]; $alias = $r[0]["alias"]; $newname = $r[0]["nick"]; if (($newname == "") OR (($r[0]["network"] != NETWORK_OSTATUS) AND ($r[0]["network"] != NETWORK_TWITTER) - AND ($r[0]["network"] != NETWORK_STATUSNET) AND ($r[0]["network"] != NETWORK_APPNET))) + AND ($r[0]["network"] != NETWORK_STATUSNET) AND ($r[0]["network"] != NETWORK_APPNET))) { $newname = $r[0]["name"]; + } } //if there is an url for this persons profile @@ -1263,20 +1280,22 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo $newtag = '@[url='.$profile.']'.$newname.'[/url]'; $body = str_replace('@'.$name, $newtag, $body); //append tag to str_tags - if(! stristr($str_tags,$newtag)) { - if(strlen($str_tags)) + if (! stristr($str_tags,$newtag)) { + if (strlen($str_tags)) { $str_tags .= ','; + } $str_tags .= $newtag; } // Status.Net seems to require the numeric ID URL in a mention if the person isn't // subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both. - if(strlen($alias)) { + if (strlen($alias)) { $newtag = '@[url='.$alias.']'.$newname.'[/url]'; - if(! stristr($str_tags,$newtag)) { - if(strlen($str_tags)) + if (! stristr($str_tags,$newtag)) { + if (strlen($str_tags)) { $str_tags .= ','; + } $str_tags .= $newtag; } } diff --git a/mod/like.php b/mod/like.php index 1f6a233f3..7932fc149 100755 --- a/mod/like.php +++ b/mod/like.php @@ -6,20 +6,23 @@ require_once('include/items.php'); require_once('include/like.php'); function like_content(App $a) { - if(! local_user() && ! remote_user()) { + if (! local_user() && ! remote_user()) { return false; } $verb = notags(trim($_GET['verb'])); - if(! $verb) + if (! $verb) { $verb = 'like'; + } $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0); $r = do_like($item_id, $verb); - if (!$r) return; + if (!$r) { + return; + } // See if we've been passed a return path to redirect to $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : ''); @@ -35,10 +38,13 @@ function like_content(App $a) { function like_content_return($baseurl, $return_path) { - if($return_path) { + if ($return_path) { $rand = '_=' . time(); - if(strpos($return_path, '?')) $rand = "&$rand"; - else $rand = "?$rand"; + if (strpos($return_path, '?')) { + $rand = "&$rand"; + } else { + $rand = "?$rand"; + } goaway($baseurl . "/" . $return_path . $rand); } diff --git a/mod/localtime.php b/mod/localtime.php index 535308903..aaa93b4ea 100644 --- a/mod/localtime.php +++ b/mod/localtime.php @@ -6,20 +6,23 @@ require_once('include/datetime.php'); function localtime_post(App $a) { $t = $_REQUEST['time']; - if(! $t) + if (! $t) { $t = 'now'; + } $bd_format = t('l F d, Y \@ g:i A') ; // Friday January 18, 2011 @ 8 AM - if($_POST['timezone']) + if ($_POST['timezone']) { $a->data['mod-localtime'] = datetime_convert('UTC',$_POST['timezone'],$t,$bd_format); + } } function localtime_content(App $a) { $t = $_REQUEST['time']; - if(! $t) + if (! $t) { $t = 'now'; + } $o .= '

    ' . t('Time Conversion') . '

    '; @@ -29,11 +32,13 @@ function localtime_content(App $a) { $o .= '

    ' . sprintf( t('UTC time: %s'), $t) . '

    '; - if($_REQUEST['timezone']) + if ($_REQUEST['timezone']) { $o .= '

    ' . sprintf( t('Current timezone: %s'), $_REQUEST['timezone']) . '

    '; + } - if(x($a->data,'mod-localtime')) + if (x($a->data,'mod-localtime')) { $o .= '

    ' . sprintf( t('Converted localtime: %s'),$a->data['mod-localtime']) . '

    '; + } $o .= ''; diff --git a/mod/lockview.php b/mod/lockview.php index 38a308634..7ced34647 100644 --- a/mod/lockview.php +++ b/mod/lockview.php @@ -11,7 +11,7 @@ function lockview_content(App $a) { $item_id = (($a->argc > 2) ? intval($a->argv[2]) : 0); } - if(! $item_id) + if (! $item_id) killme(); if (!in_array($type, array('item','photo','event'))) @@ -28,13 +28,13 @@ function lockview_content(App $a) { call_hooks('lockview_content', $item); - if($item['uid'] != local_user()) { + if ($item['uid'] != local_user()) { echo t('Remote privacy information not available.') . '
    '; killme(); } - if(($item['private'] == 1) && (! strlen($item['allow_cid'])) && (! strlen($item['allow_gid'])) + if (($item['private'] == 1) && (! strlen($item['allow_cid'])) && (! strlen($item['allow_gid'])) && (! strlen($item['deny_cid'])) && (! strlen($item['deny_gid']))) { echo t('Remote privacy information not available.') . '
    '; @@ -49,39 +49,47 @@ function lockview_content(App $a) { $o = t('Visible to:') . '
    '; $l = array(); - if(count($allowed_groups)) { + if (count($allowed_groups)) { $r = q("SELECT `name` FROM `group` WHERE `id` IN ( %s )", dbesc(implode(', ', $allowed_groups)) ); - if (dbm::is_result($r)) - foreach($r as $rr) + if (dbm::is_result($r)) { + foreach ($r as $rr) { $l[] = '' . $rr['name'] . ''; + } + } } - if(count($allowed_users)) { + if (count($allowed_users)) { $r = q("SELECT `name` FROM `contact` WHERE `id` IN ( %s )", dbesc(implode(', ',$allowed_users)) ); - if (dbm::is_result($r)) - foreach($r as $rr) + if (dbm::is_result($r)) { + foreach ($r as $rr) { $l[] = $rr['name']; + } + } } - if(count($deny_groups)) { + if (count($deny_groups)) { $r = q("SELECT `name` FROM `group` WHERE `id` IN ( %s )", dbesc(implode(', ', $deny_groups)) ); - if (dbm::is_result($r)) - foreach($r as $rr) + if (dbm::is_result($r)) { + foreach ($r as $rr) { $l[] = '' . $rr['name'] . ''; + } + } } - if(count($deny_users)) { + if (count($deny_users)) { $r = q("SELECT `name` FROM `contact` WHERE `id` IN ( %s )", dbesc(implode(', ',$deny_users)) ); - if (dbm::is_result($r)) - foreach($r as $rr) + if (dbm::is_result($r)) { + foreach ($r as $rr) { $l[] = '' . $rr['name'] . ''; + } + } } diff --git a/mod/login.php b/mod/login.php index 8fd28c723..79e245c9b 100644 --- a/mod/login.php +++ b/mod/login.php @@ -1,13 +1,16 @@ config['register_policy'] == REGISTER_CLOSED) ? false : true); } diff --git a/mod/lostpass.php b/mod/lostpass.php index 455a9b1e2..7a927d05a 100644 --- a/mod/lostpass.php +++ b/mod/lostpass.php @@ -7,7 +7,7 @@ require_once('include/text.php'); function lostpass_post(App $a) { $loginame = notags(trim($_POST['login-name'])); - if(! $loginame) + if (! $loginame) goaway(z_root()); $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) AND `verified` = 1 AND `blocked` = 0 LIMIT 1", @@ -31,7 +31,7 @@ function lostpass_post(App $a) { dbesc($new_password_encoded), intval($uid) ); - if($r) + if ($r) info( t('Password reset request issued. Check your email.') . EOL); @@ -79,8 +79,7 @@ function lostpass_post(App $a) { function lostpass_content(App $a) { - - if(x($_GET,'verify')) { + if (x($_GET,'verify')) { $verify = $_GET['verify']; $hash = hash('whirlpool', $verify); diff --git a/mod/manage.php b/mod/manage.php index 4beb8e46c..4835f6fc8 100644 --- a/mod/manage.php +++ b/mod/manage.php @@ -12,8 +12,8 @@ function manage_post(App $a) { $uid = local_user(); $orig_record = $a->user; - if((x($_SESSION,'submanage')) && intval($_SESSION['submanage'])) { - $r = q("select * from user where uid = %d limit 1", + if ((x($_SESSION,'submanage')) && intval($_SESSION['submanage'])) { + $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($_SESSION['submanage']) ); if (dbm::is_result($r)) { @@ -22,34 +22,34 @@ function manage_post(App $a) { } } - $r = q("select * from manage where uid = %d", + $r = q("SELECT * FROM `manage` WHERE `uid` = %d", intval($uid) ); $submanage = $r; $identity = ((x($_POST['identity'])) ? intval($_POST['identity']) : 0); - if(! $identity) + if (! $identity) { return; + } $limited_id = 0; $original_id = $uid; - if(count($submanage)) { - foreach($submanage as $m) { - if($identity == $m['mid']) { + if (count($submanage)) { + foreach ($submanage as $m) { + if ($identity == $m['mid']) { $limited_id = $m['mid']; break; } } } - if($limited_id) { + if ($limited_id) { $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($limited_id) ); - } - else { + } else { $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `email` = '%s' AND `password` = '%s' LIMIT 1", intval($identity), dbesc($orig_record['email']), @@ -70,18 +70,22 @@ function manage_post(App $a) { unset($_SESSION['mobile-theme']); unset($_SESSION['page_flags']); unset($_SESSION['return_url']); - if(x($_SESSION,'submanage')) + if (x($_SESSION,'submanage')) { unset($_SESSION['submanage']); - if(x($_SESSION,'sysmsg')) + } + if (x($_SESSION,'sysmsg')) { unset($_SESSION['sysmsg']); - if(x($_SESSION,'sysmsg_info')) + } + if (x($_SESSION,'sysmsg_info')) { unset($_SESSION['sysmsg_info']); + } require_once('include/security.php'); authenticate_success($r[0],true,true); - if($limited_id) + if ($limited_id) { $_SESSION['submanage'] = $original_id; + } $ret = array(); call_hooks('home_init',$ret); diff --git a/mod/match.php b/mod/match.php index 44f5141ad..baffb3d07 100644 --- a/mod/match.php +++ b/mod/match.php @@ -31,7 +31,7 @@ function match_content(App $a) { if (! dbm::is_result($r)) { return; } - if(! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) { + if (! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) { notice( t('No keywords to match. Please add keywords to your default profile.') . EOL); return; } @@ -39,28 +39,28 @@ function match_content(App $a) { $params = array(); $tags = trim($r[0]['pub_keywords'] . ' ' . $r[0]['prv_keywords']); - if($tags) { + if ($tags) { $params['s'] = $tags; - if($a->pager['page'] != 1) + if ($a->pager['page'] != 1) $params['p'] = $a->pager['page']; - if(strlen(get_config('system','directory'))) + if (strlen(get_config('system','directory'))) $x = post_url(get_server().'/msearch', $params); else $x = post_url(App::get_baseurl() . '/msearch', $params); $j = json_decode($x); - if($j->total) { + if ($j->total) { $a->set_pager_total($j->total); $a->set_pager_itemspage($j->items_page); } - if(count($j->results)) { + if (count($j->results)) { $id = 0; - foreach($j->results as $jj) { + foreach ($j->results as $jj) { $match_nurl = normalise_link($jj->url); $match = q("SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1", intval(local_user()), diff --git a/mod/message.php b/mod/message.php index df5b4709b..3d5a9b5a9 100644 --- a/mod/message.php +++ b/mod/message.php @@ -75,18 +75,18 @@ function message_post(App $a) { // fake it to go back to the input form if no recipient listed - if($norecip) { + if ($norecip) { $a->argc = 2; $a->argv[1] = 'new'; - } - else + } else { goaway($_SESSION['return_url']); + } } // Note: the code in 'item_extract_images' and 'item_redir_and_replace_images' // is identical to the code in include/conversation.php -if(! function_exists('item_extract_images')) { +if (! function_exists('item_extract_images')) { function item_extract_images($body) { $saved_image = array(); @@ -97,26 +97,27 @@ function item_extract_images($body) { $img_start = strpos($orig_body, '[img'); $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false); - while(($img_st_close !== false) && ($img_end !== false)) { + while (($img_st_close !== false) && ($img_end !== false)) { $img_st_close++; // make it point to AFTER the closing bracket $img_end += $img_start; - if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { + if (! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { // This is an embedded image $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close)); $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]'; $cnt++; - } - else + } else { $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]')); + } $orig_body = substr($orig_body, $img_end + strlen('[/img]')); - if($orig_body === false) // in case the body ends on a closing image tag + if ($orig_body === false) {// in case the body ends on a closing image tag $orig_body = ''; + } $img_start = strpos($orig_body, '[img'); $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); @@ -128,13 +129,13 @@ function item_extract_images($body) { return array('body' => $new_body, 'images' => $saved_image); }} -if(! function_exists('item_redir_and_replace_images')) { +if (! function_exists('item_redir_and_replace_images')) { function item_redir_and_replace_images($body, $images, $cid) { $origbody = $body; $newbody = ''; - for($i = 0; $i < count($images); $i++) { + for ($i = 0; $i < count($images); $i++) { $search = '/\[url\=(.*?)\]\[!#saved_image' . $i . '#!\]\[\/url\]' . '/is'; $replace = '[url=' . z_path() . '/redir/' . $cid . '?f=1&url=' . '$1' . '][!#saved_image' . $i . '#!][/url]' ; @@ -181,18 +182,18 @@ function message_content(App $a) { )); - if(($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) { - if(! intval($a->argv[2])) + if (($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) { + if (! intval($a->argv[2])) return; // Check if we should do HTML-based delete confirmation - if($_REQUEST['confirm']) { + if ($_REQUEST['confirm']) { // can't take arguments in its "action" parameter // so add any arguments as hidden inputs $query = explode_querystring($a->query_string); $inputs = array(); - foreach($query['args'] as $arg) { - if(strpos($arg, 'confirm=') === false) { + foreach ($query['args'] as $arg) { + if (strpos($arg, 'confirm=') === false) { $arg_parts = explode('=', $arg); $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]); } @@ -210,12 +211,12 @@ function message_content(App $a) { )); } // Now check how the user responded to the confirmation query - if($_REQUEST['canceled']) { + if ($_REQUEST['canceled']) { goaway($_SESSION['return_url']); } $cmd = $a->argv[1]; - if($cmd === 'drop') { + if ($cmd === 'drop') { $r = q("DELETE FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[2]), intval(local_user()) @@ -245,7 +246,7 @@ function message_content(App $a) { // as we will never again have the info we need to re-create it. // We'll just have to orphan it. - //if($convid) { + //if ($convid) { // q("delete from conv where id = %d limit 1", // intval($convid) // ); @@ -261,7 +262,7 @@ function message_content(App $a) { } - if(($a->argc > 1) && ($a->argv[1] === 'new')) { + if (($a->argc > 1) && ($a->argv[1] === 'new')) { $o .= $header; @@ -284,7 +285,7 @@ function message_content(App $a) { $prename = $preurl = $preid = ''; - if($preselect) { + if ($preselect) { $r = q("SELECT `name`, `url`, `id` FROM `contact` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval(local_user()), intval($a->argv[2]) @@ -373,7 +374,7 @@ function message_content(App $a) { return $o; } - if(($a->argc > 1) && (intval($a->argv[1]))) { + if (($a->argc > 1) && (intval($a->argv[1]))) { $o .= $header; @@ -388,7 +389,7 @@ function message_content(App $a) { $convid = $r[0]['convid']; $sql_extra = sprintf(" and `mail`.`parent-uri` = '%s' ", dbesc($r[0]['parent-uri'])); - if($convid) + if ($convid) $sql_extra = sprintf(" and ( `mail`.`parent-uri` = '%s' OR `mail`.`convid` = '%d' ) ", dbesc($r[0]['parent-uri']), intval($convid) @@ -400,7 +401,7 @@ function message_content(App $a) { intval(local_user()) ); } - if(! count($messages)) { + if (! count($messages)) { notice( t('Message not available.') . EOL ); return $o; } @@ -430,10 +431,11 @@ function message_content(App $a) { $seen = 0; $unknown = false; - foreach($messages as $message) { - if($message['unknown']) + foreach ($messages as $message) { + if ($message['unknown']) { $unknown = true; - if($message['from-url'] == $myprofile) { + } + if ($message['from-url'] == $myprofile) { $from_url = $myprofile; $sparkle = ''; } elseif ($message['contact-id'] != 0) { @@ -446,10 +448,11 @@ function message_content(App $a) { $extracted = item_extract_images($message['body']); - if($extracted['images']) + if ($extracted['images']) { $message['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $message['contact-id']); + } - if($a->theme['template_engine'] === 'internal') { + if ($a->theme['template_engine'] === 'internal') { $from_name_e = template_escape($message['from-name']); $subject_e = template_escape($message['title']); $body_e = template_escape(Smilies::replace(bbcode($message['body']))); @@ -462,23 +465,24 @@ function message_content(App $a) { } $contact = get_contact_details_by_url($message['from-url']); - if (isset($contact["thumb"])) + if (isset($contact["thumb"])) { $from_photo = $contact["thumb"]; - else + } else { $from_photo = $message['from-photo']; + } $mails[] = array( - 'id' => $message['id'], - 'from_name' => $from_name_e, - 'from_url' => $from_url, - 'sparkle' => $sparkle, + 'id' => $message['id'], + 'from_name' => $from_name_e, + 'from_url' => $from_url, + 'sparkle' => $sparkle, 'from_photo' => proxy_url($from_photo, false, PROXY_SIZE_THUMB), - 'subject' => $subject_e, - 'body' => $body_e, - 'delete' => t('Delete message'), - 'to_name' => $to_name_e, - 'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'), - 'ago' => relative_date($message['created']), + 'subject' => $subject_e, + 'body' => $body_e, + 'delete' => t('Delete message'), + 'to_name' => $to_name_e, + 'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'), + 'ago' => relative_date($message['created']), ); $seen = $message['seen']; @@ -490,10 +494,9 @@ function message_content(App $a) { $tpl = get_markup_template('mail_display.tpl'); - if($a->theme['template_engine'] === 'internal') { + if ($a->theme['template_engine'] === 'internal') { $subjtxt_e = template_escape($message['title']); - } - else { + } else { $subjtxt_e = $message['title']; } @@ -548,16 +551,16 @@ function render_messages(array $msg, $t) { $myprofile = App::get_baseurl().'/profile/' . $a->user['nickname']; - foreach($msg as $rr) { + foreach ($msg as $rr) { - if($rr['unknown']) + if ($rr['unknown']) $participants = sprintf( t("Unknown sender - %s"),$rr['from-name']); elseif (link_compare($rr['from-url'], $myprofile)) $participants = sprintf( t("You and %s"), $rr['name']); else $participants = sprintf(t("%s and You"), $rr['from-name']); - if($a->theme['template_engine'] === 'internal') { + if ($a->theme['template_engine'] === 'internal') { $subject_e = template_escape((($rr['mailseen']) ? $rr['title'] : '' . $rr['title'] . '')); $body_e = template_escape($rr['body']); $to_name_e = template_escape($rr['name']); diff --git a/mod/modexp.php b/mod/modexp.php index 4cc952247..0c5a03318 100644 --- a/mod/modexp.php +++ b/mod/modexp.php @@ -4,7 +4,7 @@ require_once('library/asn1.php'); function modexp_init(App $a) { - if($a->argc != 2) + if ($a->argc != 2) killme(); $nick = $a->argv[1]; diff --git a/mod/mood.php b/mod/mood.php index e80a7f097..805c4c45f 100644 --- a/mod/mood.php +++ b/mod/mood.php @@ -14,12 +14,12 @@ function mood_init(App $a) { $uid = local_user(); $verb = notags(trim($_GET['verb'])); - if(! $verb) + if (! $verb) return; $verbs = get_mood_verbs(); - if(! in_array($verb,$verbs)) + if (! in_array($verb,$verbs)) return; $activity = ACTIVITY_MOOD . '#' . urlencode($verb); @@ -30,7 +30,7 @@ function mood_init(App $a) { logger('mood: verb ' . $verb, LOGGER_DEBUG); - if($parent) { + if ($parent) { $r = q("select uri, private, allow_cid, allow_gid, deny_cid, deny_gid from item where id = %d and parent = %d and uid = %d limit 1", intval($parent), @@ -90,7 +90,7 @@ function mood_init(App $a) { $arr['body'] = $action; $item_id = item_store($arr); - if($item_id) { + if ($item_id) { q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d", dbesc(App::get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id), intval($uid), @@ -123,9 +123,11 @@ function mood_content(App $a) { $verbs = get_mood_verbs(); $shortlist = array(); - foreach($verbs as $k => $v) - if($v !== 'NOTRANSLATION') + foreach ($verbs as $k => $v) { + if ($v !== 'NOTRANSLATION') { $shortlist[] = array($k,$v); + } + } $tpl = get_markup_template('mood_content.tpl'); diff --git a/mod/msearch.php b/mod/msearch.php index 277242aff..177ce2688 100644 --- a/mod/msearch.php +++ b/mod/msearch.php @@ -7,7 +7,7 @@ function msearch_post(App $a) { $startrec = (($page+1) * $perpage) - $perpage; $search = $_POST['s']; - if(! strlen($search)) + if (! strlen($search)) killme(); $r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `user`.`hidewall` = 0 AND MATCH `pub_keywords` AGAINST ('%s') ", @@ -26,7 +26,7 @@ function msearch_post(App $a) { ); if (dbm::is_result($r)) { - foreach($r as $rr) + foreach ($r as $rr) $results[] = array( 'name' => $rr['name'], 'url' => App::get_baseurl() . '/profile/' . $rr['nickname'], diff --git a/mod/network.php b/mod/network.php index a1181a74c..d8943a572 100644 --- a/mod/network.php +++ b/mod/network.php @@ -43,11 +43,11 @@ function network_init(App $a) { if ($remember_group) { $net_baseurl .= '/' . $last_sel_groups; // Note that the group number must come before the "/new" tab selection - } elseif($sel_groups !== false) { + } elseif ($sel_groups !== false) { $net_baseurl .= '/' . $sel_groups; } - if($remember_tab) { + if ($remember_tab) { // redirect if current selected tab is '/network' and // last selected tab is _not_ '/network?f=&order=comment'. // and this isn't a date query @@ -81,19 +81,19 @@ function network_init(App $a) { parse_str( $dest_qs, $dest_qa); $net_args = array_merge($net_args, $dest_qa); } - else if($sel_tabs[4] === 'active') { + else if ($sel_tabs[4] === 'active') { // The '/new' tab is selected $net_baseurl .= '/new'; } - if($remember_net) { + if ($remember_net) { $net_args['nets'] = $last_sel_nets; } - else if($sel_nets!==false) { + else if ($sel_nets!==false) { $net_args['nets'] = $sel_nets; } - if($remember_tab || $remember_net || $remember_group) { + if ($remember_tab || $remember_net || $remember_group) { $net_args = array_merge($query_array, $net_args); $net_queries = build_querystring($net_args); @@ -103,7 +103,7 @@ function network_init(App $a) { } } - if(x($_GET['nets']) && $_GET['nets'] === 'all') + if (x($_GET['nets']) && $_GET['nets'] === 'all') unset($_GET['nets']); $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0); @@ -115,12 +115,12 @@ function network_init(App $a) { require_once('include/items.php'); require_once('include/ForumManager.php'); - if(! x($a->page,'aside')) + if (! x($a->page,'aside')) $a->page['aside'] = ''; $search = ((x($_GET,'search')) ? escape_tags($_GET['search']) : ''); - if(x($_GET,'save')) { + if (x($_GET,'save')) { $r = qu("SELECT * FROM `search` WHERE `uid` = %d AND `term` = '%s' LIMIT 1", intval(local_user()), dbesc($search) @@ -132,7 +132,7 @@ function network_init(App $a) { ); } } - if(x($_GET,'remove')) { + if (x($_GET,'remove')) { q("DELETE FROM `search` WHERE `uid` = %d AND `term` = '%s'", intval(local_user()), dbesc($search) @@ -140,7 +140,7 @@ function network_init(App $a) { } // search terms header - if(x($_GET,'search')) { + if (x($_GET,'search')) { $a->page['content'] .= replace_macros(get_markup_template("section_title.tpl"),array( '$title' => sprintf( t('Results for: %s'), $search) )); @@ -157,7 +157,7 @@ function network_init(App $a) { function saved_searches($search) { - if(! feature_enabled(local_user(),'savedsearch')) + if (! feature_enabled(local_user(),'savedsearch')) return ''; $a = get_app(); @@ -232,28 +232,28 @@ function network_query_get_sel_tab(App $a) { $spam_active = ''; $postord_active = ''; - if(($a->argc > 1 && $a->argv[1] === 'new') + if (($a->argc > 1 && $a->argv[1] === 'new') || ($a->argc > 2 && $a->argv[2] === 'new')) { $new_active = 'active'; } - if(x($_GET,'search')) { + if (x($_GET,'search')) { $search_active = 'active'; } - if(x($_GET,'star')) { + if (x($_GET,'star')) { $starred_active = 'active'; } - if(x($_GET,'bmark')) { + if (x($_GET,'bmark')) { $bookmarked_active = 'active'; } - if(x($_GET,'conv')) { + if (x($_GET,'conv')) { $conv_active = 'active'; } - if(x($_GET,'spam')) { + if (x($_GET,'spam')) { $spam_active = 'active'; } @@ -285,7 +285,7 @@ function network_query_get_sel_tab(App $a) { function network_query_get_sel_net() { $network = false; - if(x($_GET,'nets')) { + if (x($_GET,'nets')) { $network = $_GET['nets']; } @@ -295,7 +295,7 @@ function network_query_get_sel_net() { function network_query_get_sel_group(App $a) { $group = false; - if($a->argc >= 2 && is_numeric($a->argv[1])) { + if ($a->argc >= 2 && is_numeric($a->argv[1])) { $group = $a->argv[1]; } @@ -326,20 +326,18 @@ function network_content(App $a, $update = 0) { $nouveau = false; - if($a->argc > 1) { - for($x = 1; $x < $a->argc; $x ++) { - if(is_a_date_arg($a->argv[$x])) { - if($datequery) + if ($a->argc > 1) { + for ($x = 1; $x < $a->argc; $x ++) { + if (is_a_date_arg($a->argv[$x])) { + if ($datequery) { $datequery2 = escape_tags($a->argv[$x]); - else { + } else { $datequery = escape_tags($a->argv[$x]); $_GET['order'] = 'post'; } - } - elseif($a->argv[$x] === 'new') { + } elseif ($a->argv[$x] === 'new') { $nouveau = true; - } - elseif(intval($a->argv[$x])) { + } elseif (intval($a->argv[$x])) { $group = intval($a->argv[$x]); $def_acl = array('allow_gid' => '<' . $group . '>'); } @@ -368,12 +366,12 @@ function network_content(App $a, $update = 0) { - if(x($_GET,'search') || x($_GET,'file')) + if (x($_GET,'search') || x($_GET,'file')) $nouveau = true; - if($cid) + if ($cid) $def_acl = array('allow_cid' => '<' . intval($cid) . '>'); - if($nets) { + if ($nets) { $r = qu("SELECT `id` FROM `contact` WHERE `uid` = %d AND network = '%s' AND `self` = 0", intval(local_user()), dbesc($nets) @@ -381,19 +379,19 @@ function network_content(App $a, $update = 0) { $str = ''; if (dbm::is_result($r)) - foreach($r as $rr) + foreach ($r as $rr) $str .= '<' . $rr['id'] . '>'; - if(strlen($str)) + if (strlen($str)) $def_acl = array('allow_cid' => $str); } set_pconfig(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all')); - if(!$update AND !$rawmode) { + if (!$update AND !$rawmode) { $tabs = network_tabs($a); $o .= $tabs; - if($group) { - if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) { + if ($group) { + if (($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) { notice(sprintf(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.", "Warning: This group contains %s members from a network that doesn't allow non public messages.", $t), $t).EOL); @@ -457,13 +455,13 @@ function network_content(App $a, $update = 0) { $sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : ''); - if($group) { + if ($group) { $r = qu("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($group), intval($_SESSION['uid']) ); if (! dbm::is_result($r)) { - if($update) + if ($update) killme(); notice( t('No such group') . EOL ); goaway('network/0'); @@ -473,7 +471,7 @@ function network_content(App $a, $update = 0) { $contacts = expand_groups(array($group)); $gcontacts = expand_groups(array($group), false, true); - if((is_array($contacts)) && count($contacts)) { + if ((is_array($contacts)) && count($contacts)) { $contact_str_self = ""; $gcontact_str_self = ""; @@ -500,7 +498,7 @@ function network_content(App $a, $update = 0) { )) . $o; } - elseif($cid) { + elseif ($cid) { $r = qu("SELECT `id`,`name`,`network`,`writable`,`nurl`, `forum`, `prv`, `contact-type`, `addr`, `thumb`, `location` FROM `contact` WHERE `id` = %d AND (NOT `blocked` OR `pending`) LIMIT 1", @@ -524,7 +522,7 @@ function network_content(App $a, $update = 0) { 'id' => 'network', )) . $o; - if($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) { + if ($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) { notice( t('Private messages to this person are at risk of public disclosure.') . EOL); } @@ -536,15 +534,15 @@ function network_content(App $a, $update = 0) { } } - if((! $group) && (! $cid) && (! $update) && (! get_config('theme','hide_eventlist'))) { + if ((! $group) && (! $cid) && (! $update) && (! get_config('theme','hide_eventlist'))) { $o .= get_birthdays(); $o .= get_events(); } - if($datequery) { + if ($datequery) { $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery)))); } - if($datequery2) { + if ($datequery2) { $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); } @@ -555,10 +553,10 @@ function network_content(App $a, $update = 0) { $order_mode = "received"; $tag = false; - if(x($_GET,'search')) { + if (x($_GET,'search')) { $search = escape_tags($_GET['search']); - if(strpos($search,'#') === 0) { + if (strpos($search,'#') === 0) { $tag = true; $search = substr($search,1); } @@ -566,7 +564,7 @@ function network_content(App $a, $update = 0) { if (get_config('system','only_tag_search')) $tag = true; - if($tag) { + if ($tag) { $sql_extra = ""; $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", @@ -583,17 +581,17 @@ function network_content(App $a, $update = 0) { $order_mode = "id"; } } - if(strlen($file)) { + if (strlen($file)) { $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user())); $sql_order = "`item`.`id`"; $order_mode = "id"; } - if($conv) + if ($conv) $sql_extra3 .= " AND $sql_table.`mention`"; - if($update) { + if ($update) { // only setup pagination on initial page view $pager_sql = ''; @@ -611,14 +609,14 @@ function network_content(App $a, $update = 0) { // now that we have the user settings, see if the theme forces // a maximum item number which is lower then the user choice - if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) + if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) $itemspage_network = $a->force_max_items; $a->set_pager_itemspage($itemspage_network); $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); } - if($nouveau) { + if ($nouveau) { $simple_update = (($update) ? " AND `item`.`unseen` " : ''); if ($sql_order == "") @@ -640,7 +638,7 @@ function network_content(App $a, $update = 0) { // Normal conversation view - if($order === 'post') { + if ($order === 'post') { $ordering = "`created`"; if ($sql_order == "") $order_mode = "created"; @@ -657,7 +655,7 @@ function network_content(App $a, $update = 0) { $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"])); // Fetch a page full of parent items for this page - if($update) { + if ($update) { if (get_config("system", "like_no_comment")) $sql_extra4 = " AND `item`.`verb` = '".ACTIVITY_POST."'"; else @@ -691,8 +689,8 @@ function network_content(App $a, $update = 0) { $date_offset = ""; if (dbm::is_result($r)) { - foreach($r as $rr) - if(! in_array($rr['item_id'],$parents_arr)) + foreach ($r as $rr) + if (! in_array($rr['item_id'],$parents_arr)) $parents_arr[] = $rr['item_id']; $parents_str = implode(", ", $parents_arr); @@ -730,7 +728,7 @@ function network_content(App $a, $update = 0) { $a->page_offset = $date_offset; - if($parents_str) + if ($parents_str) $update_unseen = ' WHERE uid = ' . intval(local_user()) . ' AND unseen = 1 AND parent IN ( ' . dbesc($parents_str) . ' )'; } @@ -824,7 +822,7 @@ function network_tabs(App $a) { ), ); - if(feature_enabled(local_user(),'personal_tab')) { + if (feature_enabled(local_user(),'personal_tab')) { $tabs[] = array( 'label' => t('Personal'), 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1', @@ -835,7 +833,7 @@ function network_tabs(App $a) { ); } - if(feature_enabled(local_user(),'new_tab')) { + if (feature_enabled(local_user(),'new_tab')) { $tabs[] = array( 'label' => t('New'), 'url' => str_replace('/new', '', $cmd) . ($len_naked_cmd ? '/' : '') . 'new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''), @@ -846,7 +844,7 @@ function network_tabs(App $a) { ); } - if(feature_enabled(local_user(),'link_tab')) { + if (feature_enabled(local_user(),'link_tab')) { $tabs[] = array( 'label' => t('Shared Links'), 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&bmark=1', @@ -857,7 +855,7 @@ function network_tabs(App $a) { ); } - if(feature_enabled(local_user(),'star_posts')) { + if (feature_enabled(local_user(),'star_posts')) { $tabs[] = array( 'label' => t('Starred'), 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1', @@ -869,7 +867,7 @@ function network_tabs(App $a) { } // save selected tab, but only if not in search or file mode - if(!x($_GET,'search') && !x($_GET,'file')) { + if (!x($_GET,'search') && !x($_GET,'file')) { set_pconfig( local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) ); } diff --git a/mod/newmember.php b/mod/newmember.php index a5e41f1e2..eef6b1263 100644 --- a/mod/newmember.php +++ b/mod/newmember.php @@ -47,8 +47,9 @@ function newmember_content(App $a) { $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); - if(! $mail_disabled) + if (! $mail_disabled) { $o .= '
  • ' . '' . t('Importing Emails') . '
    ' . t('Enter your email access information on your Connector Settings page if you wish to import and interact with friends or mailing lists from your email INBOX') . '
  • ' . EOL; + } $o .= '
  • ' . '' . t('Go to Your Contacts Page') . '
    ' . t('Your Contacts page is your gateway to managing friendships and connecting with friends on other networks. Typically you enter their address or site URL in the Add New Contact dialog.') . '
  • ' . EOL; @@ -64,7 +65,7 @@ function newmember_content(App $a) { $o .= '
  • ' . '' . t('Group Your Contacts') . '
    ' . t('Once you have made some friends, organize them into private conversation groups from the sidebar of your Contacts page and then you can interact with each group privately on your Network page.') . '
  • ' . EOL; - if(get_config('system', 'newuser_private')) { + if (get_config('system', 'newuser_private')) { $o .= '
  • ' . '' . t("Why Aren't My Posts Public?") . '
    ' . t("Friendica respects your privacy. By default, your posts will only show up to people you've added as friends. For more information, see the help section from the link above.") . '
  • ' . EOL; } diff --git a/mod/nodeinfo.php b/mod/nodeinfo.php index 6f2049475..ffc494689 100644 --- a/mod/nodeinfo.php +++ b/mod/nodeinfo.php @@ -158,7 +158,7 @@ function nodeinfo_cron() { $plugins = get_config("system","addon"); $plugins_arr = array(); - if($plugins) { + if ($plugins) { $plugins_arr = explode(",",str_replace(" ", "",$plugins)); $idx = array_search($plugin, $plugins_arr); @@ -175,10 +175,10 @@ function nodeinfo_cron() { $last = get_config('nodeinfo','last_calucation'); - if($last) { + if ($last) { // Calculate every 24 hours $next = $last + (24 * 60 * 60); - if($next > time()) { + if ($next > time()) { logger("calculation intervall not reached"); return; } diff --git a/mod/noscrape.php b/mod/noscrape.php index 83ab71ce1..e9655f20b 100644 --- a/mod/noscrape.php +++ b/mod/noscrape.php @@ -2,13 +2,14 @@ function noscrape_init(App $a) { - if($a->argc > 1) + if ($a->argc > 1) { $which = $a->argv[1]; - else + } else { killme(); + } $profile = 0; - if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) { + if ((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) { $which = $a->user['nickname']; $profile = $a->argv[1]; } diff --git a/mod/notes.php b/mod/notes.php index c7cfe8d70..bc80c24da 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -43,7 +43,7 @@ function notes_content(App $a, $update = false) { $o =""; $o .= profile_tabs($a,True); - if(! $update) { + if (! $update) { $o .= '

    ' . t('Personal Notes') . '

    '; $commpage = false; @@ -104,8 +104,9 @@ function notes_content(App $a, $update = false) { $parents_str = ''; if (dbm::is_result($r)) { - foreach($r as $rr) + foreach ($r as $rr) { $parents_arr[] = $rr['item_id']; + } $parents_str = implode(', ', $parents_arr); $r = q("SELECT %s FROM `item` %s diff --git a/mod/notifications.php b/mod/notifications.php index 0c08b66ce..d27228b8f 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -17,10 +17,10 @@ function notifications_post(App $a) { $request_id = (($a->argc > 1) ? $a->argv[1] : 0); - if($request_id === "all") + if ($request_id === "all") return; - if($request_id) { + if ($request_id) { $r = q("SELECT * FROM `intro` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($request_id), @@ -41,11 +41,11 @@ function notifications_post(App $a) { $fid = $r[0]['fid']; - if($_POST['submit'] == t('Discard')) { + if ($_POST['submit'] == t('Discard')) { $r = q("DELETE FROM `intro` WHERE `id` = %d", intval($intro_id) ); - if(! $fid) { + if (! $fid) { // The check for blocked and pending is in case the friendship was already approved // and we just want to get rid of the now pointless notification @@ -57,7 +57,7 @@ function notifications_post(App $a) { } goaway('notifications/intros'); } - if($_POST['submit'] == t('Ignore')) { + if ($_POST['submit'] == t('Ignore')) { $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d", intval($intro_id)); goaway('notifications/intros'); @@ -91,7 +91,7 @@ function notifications_content(App $a) { $startrec = ($page * $perpage) - $perpage; // Get introductions - if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) { + if ( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) { nav_set_selected('introductions'); $notif_header = t('Notifications'); @@ -135,13 +135,13 @@ function notifications_content(App $a) { $notifs['page'] = $a->pager['page']; // Json output - if(intval($json) === 1) + if (intval($json) === 1) json_return_and_die($notifs); $notif_tpl = get_markup_template('notifications.tpl'); // Process the data for template creation - if($notifs['ident'] === 'introductions') { + if ($notifs['ident'] === 'introductions') { $sugg = get_markup_template('suggestions.tpl'); $tpl = get_markup_template("intros.tpl"); @@ -190,8 +190,8 @@ function notifications_content(App $a) { $knowyou = ''; $dfrn_text = ''; - if($it['network'] === NETWORK_DFRN || $it['network'] === NETWORK_DIASPORA) { - if($it['network'] === NETWORK_DFRN) { + if ($it['network'] === NETWORK_DFRN || $it['network'] === NETWORK_DIASPORA) { + if ($it['network'] === NETWORK_DFRN) { $lbl_knowyou = t('Claims to be known to you: '); $knowyou = (($it['knowyou']) ? t('yes') : t('no')); $helptext = t('Shall your connection be bidirectional or not?'); @@ -262,7 +262,7 @@ function notifications_content(App $a) { } } - if($notifs['total'] == 0) + if ($notifs['total'] == 0) info( t('No introductions.') . EOL); // Normal notifications (no introductions) @@ -301,7 +301,7 @@ function notifications_content(App $a) { // It doesn't make sense to show the Show unread / Show all link visible if the user is on the // "Show all" page and there are no notifications. So we will hide it. - if($show == 0 || intval($show) && $notifs['total'] > 0) { + if ($show == 0 || intval($show) && $notifs['total'] > 0) { $notif_show_lnk = array( 'href' => ($show ? 'notifications/'.$notifs['ident'] : 'notifications/'.$notifs['ident'].'?show=all' ), 'text' => ($show ? t('Show unread') : t('Show all')), @@ -309,8 +309,9 @@ function notifications_content(App $a) { } // Output if there aren't any notifications available - if($notifs['total'] == 0) + if ($notifs['total'] == 0) { $notif_nocontent = sprintf( t('No more %s notifications.'), $notifs['ident']); + } } $o .= replace_macros($notif_tpl, array( diff --git a/mod/openid.php b/mod/openid.php index b45cd9797..e11267d81 100644 --- a/mod/openid.php +++ b/mod/openid.php @@ -7,20 +7,20 @@ require_once('library/openid.php'); function openid_content(App $a) { $noid = get_config('system','no_openid'); - if($noid) + if ($noid) goaway(z_root()); logger('mod_openid ' . print_r($_REQUEST,true), LOGGER_DATA); - if((x($_GET,'openid_mode')) && (x($_SESSION,'openid'))) { + if ((x($_GET,'openid_mode')) && (x($_SESSION,'openid'))) { $openid = new LightOpenID; - if($openid->validate()) { + if ($openid->validate()) { $authid = $_REQUEST['openid_identity']; - if(! strlen($authid)) { + if (! strlen($authid)) { logger( t('OpenID protocol error. No ID returned.') . EOL); goaway(z_root()); } @@ -69,10 +69,10 @@ function openid_content(App $a) { if ($k === 'namePerson/friendly') { $nick = notags(trim($v)); } - if($k === 'namePerson/first') { + if ($k === 'namePerson/first') { $first = notags(trim($v)); } - if($k === 'namePerson') { + if ($k === 'namePerson') { $args .= '&username=' . notags(trim($v)); } if ($k === 'contact/email') { diff --git a/mod/parse_url.php b/mod/parse_url.php index 77529714f..0888db101 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -59,7 +59,7 @@ function parse_url_content(App $a) { $redirects = 0; // Fetch the header of the URL $result = z_fetch_url($url, false, $redirects, array("novalidate" => true, "nobody" => true)); - if($result["success"]) { + if ($result["success"]) { // Convert the header fields into an array $hdrs = array(); $h = explode("\n", $result["header"]); @@ -71,7 +71,7 @@ function parse_url_content(App $a) { $type = $hdrs["Content-Type"]; } if ($type) { - if(stripos($type, "image/") !== false) { + if (stripos($type, "image/") !== false) { echo $br . "[img]" . $url . "[/img]" . $br; killme(); } diff --git a/mod/photo.php b/mod/photo.php index 6562599ca..71c92ffe2 100644 --- a/mod/photo.php +++ b/mod/photo.php @@ -36,7 +36,7 @@ function photo_init(App $a) { header('Etag: '.$_SERVER['HTTP_IF_NONE_MATCH']); header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT"); header("Cache-Control: max-age=31536000"); - if(function_exists('header_remove')) { + if (function_exists('header_remove')) { header_remove('Last-Modified'); header_remove('Expires'); header_remove('Cache-Control'); @@ -46,7 +46,7 @@ function photo_init(App $a) { $default = 'images/person-175.jpg'; - if(isset($type)) { + if (isset($type)) { /** @@ -80,23 +80,22 @@ function photo_init(App $a) { $data = $r[0]['data']; $mimetype = $r[0]['type']; } - if(! isset($data)) { + if (! isset($data)) { $data = file_get_contents($default); $mimetype = 'image/jpeg'; } - } - else { + } else { /** * Other photos */ $resolution = 0; - foreach( Photo::supportedTypes() as $m=>$e){ + foreach ( Photo::supportedTypes() as $m=>$e){ $photo = str_replace(".$e",'',$photo); } - if(substr($photo,-2,1) == '-') { + if (substr($photo,-2,1) == '-') { $resolution = intval(substr($photo,-1,1)); $photo = substr($photo,0,-2); } @@ -134,8 +133,8 @@ function photo_init(App $a) { } } - if(! isset($data)) { - if(isset($resolution)) { + if (! isset($data)) { + if (isset($resolution)) { switch($resolution) { case 4: @@ -161,8 +160,8 @@ function photo_init(App $a) { // Resize only if its not a GIF if ($mime != "image/gif") { $ph = new Photo($data, $mimetype); - if($ph->is_valid()) { - if(isset($customres) && $customres > 0 && $customres < 500) { + if ($ph->is_valid()) { + if (isset($customres) && $customres > 0 && $customres < 500) { $ph->scaleImageSquare($customres); } $data = $ph->imageString(); @@ -170,14 +169,14 @@ function photo_init(App $a) { } } - if(function_exists('header_remove')) { + if (function_exists('header_remove')) { header_remove('Pragma'); header_remove('pragma'); } header("Content-type: ".$mimetype); - if($prvcachecontrol) { + if ($prvcachecontrol) { // it is a private photo that they have no permission to view. // tell the browser not to cache it, in case they authenticate diff --git a/mod/photos.php b/mod/photos.php index 27d8499c2..d9530f349 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1356,7 +1356,7 @@ function photos_content(App $a) { intval($owner_uid) ); - if (count($prvnxt)) { + if (dbm::is_result($prvnxt)) { for($z = 0; $z < count($prvnxt); $z++) { if ($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) { $prv = $z - 1; @@ -1374,8 +1374,9 @@ function photos_content(App $a) { } } - if (count($ph) == 1) + if (count($ph) == 1) { $hires = $lores = $ph[0]; + } if (count($ph) > 1) { if ($ph[1]['scale'] == 2) { // original is 640 or less, we can display it directly diff --git a/mod/ping.php b/mod/ping.php index b5330c7b3..35a9b4520 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -216,7 +216,7 @@ function ping_init(App $a) if ($all_events) { $str_now = datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d'); - foreach($ev as $x) { + foreach ($ev as $x) { $bd = false; if ($x['type'] === 'birthday') { $birthdays ++; @@ -486,7 +486,7 @@ function ping_get_notifications($uid) function ping_format_xml_data($data, $sysnotify, $notifs, $sysmsgs, $sysmsgs_info, $groups_unseen, $forums_unseen) { $notifications = array(); - foreach($notifs as $key => $notif) { + foreach ($notifs as $key => $notif) { $notifications[$key . ':note'] = $notif['message']; $notifications[$key . ':@attributes'] = array( diff --git a/mod/poco.php b/mod/poco.php index 30648acab..c5f5427b9 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -157,27 +157,27 @@ function poco_init(App $a) { if (x($_GET,'updatedSince') AND !$global) { $ret['updatedSince'] = false; } + $ret['startIndex'] = (int) $startIndex; $ret['itemsPerPage'] = (int) $itemsPerPage; $ret['totalResults'] = (int) $totalResults; $ret['entry'] = array(); - $fields_ret = array( - 'id' => false, - 'displayName' => false, - 'urls' => false, - 'updated' => false, + 'id' => false, + 'displayName' => false, + 'urls' => false, + 'updated' => false, 'preferredUsername' => false, - 'photos' => false, - 'aboutMe' => false, - 'currentLocation' => false, - 'network' => false, - 'gender' => false, - 'tags' => false, - 'address' => false, - 'contactType' => false, - 'generation' => false + 'photos' => false, + 'aboutMe' => false, + 'currentLocation' => false, + 'network' => false, + 'gender' => false, + 'tags' => false, + 'address' => false, + 'contactType' => false, + 'generation' => false ); if ((! x($_GET,'fields')) || ($_GET['fields'] === '@all')) { @@ -207,14 +207,17 @@ function poco_init(App $a) { if (($rr['about'] == "") AND isset($rr['pabout'])) { $rr['about'] = $rr['pabout']; } + if ($rr['location'] == "") { if (isset($rr['plocation'])) { $rr['location'] = $rr['plocation']; } + if (isset($rr['pregion']) AND ($rr['pregion'] != "")) { if ($rr['location'] != "") { $rr['location'] .= ", "; } + $rr['location'] .= $rr['pregion']; } @@ -292,6 +295,7 @@ function poco_init(App $a) { } else { $entry['updated'] = $rr['updated']; } + $entry['updated'] = date("c", strtotime($entry['updated'])); } if ($fields_ret['photos']) { @@ -345,6 +349,7 @@ function poco_init(App $a) { if ($fields_ret['contactType']) { $entry['contactType'] = intval($rr['contact-type']); } + $ret['entry'][] = $entry; } } else { @@ -353,6 +358,7 @@ function poco_init(App $a) { } else { http_status_exit(500); } + logger("End of poco", LOGGER_DEBUG); if ($format === 'xml') { @@ -367,4 +373,5 @@ function poco_init(App $a) { } else { http_status_exit(500); } + } diff --git a/mod/poke.php b/mod/poke.php index 5161129b3..ea0093e1d 100644 --- a/mod/poke.php +++ b/mod/poke.php @@ -63,7 +63,7 @@ function poke_init(App $a) { $target = $r[0]; - if($parent) { + if ($parent) { $r = q("SELECT `uri`, `private`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` FROM `item` WHERE `id` = %d AND `parent` = %d AND `uid` = %d LIMIT 1", intval($parent), @@ -129,7 +129,7 @@ function poke_init(App $a) { $arr['object'] .= '
' . "\n"; $item_id = item_store($arr); - if($item_id) { + if ($item_id) { //q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d", // dbesc(App::get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id), // intval($uid), @@ -158,7 +158,7 @@ function poke_content(App $a) { $name = ''; $id = ''; - if(intval($_GET['c'])) { + if (intval($_GET['c'])) { $r = q("SELECT `id`,`name` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($_GET['c']), intval(local_user()) @@ -185,9 +185,11 @@ function poke_content(App $a) { $verbs = get_poke_verbs(); $shortlist = array(); - foreach($verbs as $k => $v) - if($v[1] !== 'NOTRANSLATION') + foreach ($verbs as $k => $v) { + if ($v[1] !== 'NOTRANSLATION') { $shortlist[] = array($k,$v[1]); + } + } $tpl = get_markup_template('poke_content.tpl'); diff --git a/mod/post.php b/mod/post.php index c8a88e66c..98a32711c 100644 --- a/mod/post.php +++ b/mod/post.php @@ -16,8 +16,7 @@ function post_post(App $a) { if ($a->argc == 1) { $bulk_delivery = true; - } - else { + } else { $nickname = $a->argv[2]; $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1", @@ -34,15 +33,17 @@ function post_post(App $a) { logger('mod-post: new zot: ' . $xml, LOGGER_DATA); - if(! $xml) + if (! $xml) { http_status_exit(500); + } $msg = zot_decode($importer,$xml); logger('mod-post: decoded msg: ' . print_r($msg,true), LOGGER_DATA); - if(! is_array($msg)) + if (! is_array($msg)) { http_status_exit(500); + } $ret = 0; $ret = zot_incoming($bulk_delivery, $importer,$msg); diff --git a/mod/pretheme.php b/mod/pretheme.php index 6dd6b781a..52e63cef3 100644 --- a/mod/pretheme.php +++ b/mod/pretheme.php @@ -2,16 +2,15 @@ function pretheme_init(App $a) { - if($_REQUEST['theme']) { + if ($_REQUEST['theme']) { $theme = $_REQUEST['theme']; $info = get_theme_info($theme); - if($info) { + if ($info) { // unfortunately there will be no translation for this string $desc = $info['description']; $version = $info['version']; $credits = $info['credits']; - } - else { + } else { $desc = ''; $version = ''; $credits = ''; diff --git a/mod/probe.php b/mod/probe.php index 95f856bfa..3c2497b2f 100644 --- a/mod/probe.php +++ b/mod/probe.php @@ -12,7 +12,7 @@ function probe_content(App $a) { $o .= '

'; - if(x($_GET,'addr')) { + if (x($_GET,'addr')) { $addr = trim($_GET['addr']); $res = probe_url($addr); diff --git a/mod/profile.php b/mod/profile.php index fbce509d2..15f49db53 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -6,17 +6,17 @@ require_once('include/redir.php'); function profile_init(App $a) { - if(! x($a->page,'aside')) + if (! x($a->page,'aside')) { $a->page['aside'] = ''; + } - if($a->argc > 1) + if ($a->argc > 1) { $which = htmlspecialchars($a->argv[1]); - else { + }else { $r = q("select nickname from user where blocked = 0 and account_expired = 0 and account_removed = 0 and verified = 1 order by rand() limit 1"); if (dbm::is_result($r)) { goaway(App::get_baseurl() . '/profile/' . $r[0]['nickname']); - } - else { + } else { logger('profile error: mod_profile ' . $a->query_string, LOGGER_DEBUG); notice( t('Requested profile is not available.') . EOL ); $a->error = 404; @@ -25,11 +25,10 @@ function profile_init(App $a) { } $profile = 0; - if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) { + if ((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) { $which = $a->user['nickname']; $profile = htmlspecialchars($a->argv[1]); - } - else { + } else { auto_redir($a, $which); } @@ -38,7 +37,7 @@ function profile_init(App $a) { $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false); $userblock = (($a->profile['hidewall'] && (! local_user()) && (! remote_user())) ? true : false); - if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY)) { + if ((x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY)) { $a->page['htmlhead'] .= ''; } if (x($a->profile,'openidserver')) { @@ -52,7 +51,7 @@ function profile_init(App $a) { if ((! $blocked) && (! $userblock)) { $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : ''); $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords); - if(strlen($keywords)) + if (strlen($keywords)) $a->page['htmlhead'] .= '' . "\r\n" ; } @@ -262,7 +261,7 @@ function profile_content(App $a, $update = 0) { } // now that we have the user settings, see if the theme forces // a maximum item number which is lower then the user choice - if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) + if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) $itemspage_network = $a->force_max_items; $a->set_pager_itemspage($itemspage_network); @@ -289,8 +288,9 @@ function profile_content(App $a, $update = 0) { $parents_str = ''; if (dbm::is_result($r)) { - foreach($r as $rr) + foreach ($r as $rr) { $parents_arr[] = $rr['item_id']; + } $parents_str = implode(', ', $parents_arr); $items = q(item_query()." AND `item`.`uid` = %d @@ -305,13 +305,13 @@ function profile_content(App $a, $update = 0) { $items = array(); } - if($is_owner && (! $update) && (! get_config('theme','hide_eventlist'))) { + if ($is_owner && (! $update) && (! get_config('theme','hide_eventlist'))) { $o .= get_birthdays(); $o .= get_events(); } - if($is_owner) { + if ($is_owner) { $r = q("UPDATE `item` SET `unseen` = 0 WHERE `wall` = 1 AND `unseen` = 1 AND `uid` = %d", intval(local_user()) diff --git a/mod/profile_photo.php b/mod/profile_photo.php index f9bf60cf5..ea9fc3ea7 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -22,12 +22,12 @@ function profile_photo_post(App $a) { check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo'); - if((x($_POST,'cropfinal')) && ($_POST['cropfinal'] == 1)) { + if ((x($_POST,'cropfinal')) && ($_POST['cropfinal'] == 1)) { // unless proven otherwise $is_default_profile = 1; - if($_REQUEST['profile']) { + if ($_REQUEST['profile']) { $r = q("select id, `is-default` from profile where id = %d and uid = %d limit 1", intval($_REQUEST['profile']), intval(local_user()) @@ -40,14 +40,14 @@ function profile_photo_post(App $a) { // phase 2 - we have finished cropping - if($a->argc != 2) { + if ($a->argc != 2) { notice( t('Image uploaded but image cropping failed.') . EOL ); return; } $image_id = $a->argv[1]; - if(substr($image_id,-2,1) == '-') { + if (substr($image_id,-2,1) == '-') { $scale = substr($image_id,-1,1); $image_id = substr($image_id,0,-2); } @@ -68,7 +68,7 @@ function profile_photo_post(App $a) { $base_image = $r[0]; $im = new Photo($base_image['data'], $base_image['type']); - if($im->is_valid()) { + if ($im->is_valid()) { $im->cropImage(175,$srcX,$srcY,$srcW,$srcH); $r = $im->store(local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 4, $is_default_profile); @@ -95,7 +95,7 @@ function profile_photo_post(App $a) { // If setting for the default profile, unset the profile photo flag from any other photos I own - if($is_default_profile) { + if ($is_default_profile) { $r = q("UPDATE `photo` SET `profile` = 0 WHERE `profile` = 1 AND `resource-id` != '%s' AND `uid` = %d", dbesc($base_image['resource-id']), intval(local_user()) @@ -173,7 +173,7 @@ function profile_photo_post(App $a) { } -if(! function_exists('profile_photo_content')) { +if (! function_exists('profile_photo_content')) { function profile_photo_content(App $a) { if (! local_user()) { @@ -183,10 +183,10 @@ function profile_photo_content(App $a) { $newuser = false; - if($a->argc == 2 && $a->argv[1] === 'new') + if ($a->argc == 2 && $a->argv[1] === 'new') $newuser = true; - if( $a->argv[1]=='use'){ + if ( $a->argv[1]=='use'){ if ($a->argc<3){ notice( t('Permission denied.') . EOL ); return; @@ -206,7 +206,7 @@ function profile_photo_content(App $a) { } $havescale = false; foreach ($r as $rr) { - if($rr['scale'] == 5) + if ($rr['scale'] == 5) $havescale = true; } @@ -245,7 +245,7 @@ function profile_photo_content(App $a) { ); - if(! x($a->config,'imagecrop')) { + if (! x($a->config,'imagecrop')) { $tpl = get_markup_template('profile_photo.tpl'); @@ -283,7 +283,7 @@ function profile_photo_content(App $a) { }} -if(! function_exists('profile_photo_crop_ui_head')) { +if (! function_exists('profile_photo_crop_ui_head')) { function profile_photo_crop_ui_head(App $a, $ph) { $max_length = get_config('system','max_image_length'); if (! $max_length) { diff --git a/mod/profiles.php b/mod/profiles.php index 282217208..b73b969f0 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -10,7 +10,7 @@ function profiles_init(App $a) { return; } - if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) { + if (($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) { $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1", intval($a->argv[2]), intval(local_user()) @@ -46,7 +46,7 @@ function profiles_init(App $a) { - if(($a->argc > 1) && ($a->argv[1] === 'new')) { + if (($a->argc > 1) && ($a->argv[1] === 'new')) { check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't'); @@ -74,13 +74,13 @@ function profiles_init(App $a) { ); info( t('New profile created.') . EOL); - if(count($r3) == 1) + if (count($r3) == 1) goaway('profiles/'.$r3[0]['id']); goaway('profiles'); } - if(($a->argc > 2) && ($a->argv[1] === 'clone')) { + if (($a->argc > 2) && ($a->argv[1] === 'clone')) { check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't'); @@ -93,7 +93,7 @@ function profiles_init(App $a) { intval(local_user()), intval($a->argv[2]) ); - if(! dbm::is_result($r1)) { + if (! dbm::is_result($r1)) { notice( t('Profile unavailable to clone.') . EOL); killme(); return; @@ -126,7 +126,7 @@ function profiles_init(App $a) { } - if(($a->argc > 1) && (intval($a->argv[1]))) { + if (($a->argc > 1) && (intval($a->argv[1]))) { $r = q("SELECT id FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[1]), intval(local_user()) @@ -172,12 +172,12 @@ function profiles_post(App $a) { call_hooks('profile_post', $_POST); - if(($a->argc > 1) && ($a->argv[1] !== "new") && intval($a->argv[1])) { + if (($a->argc > 1) && ($a->argv[1] !== "new") && intval($a->argv[1])) { $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[1]), intval(local_user()) ); - if(! count($orig)) { + if (! count($orig)) { notice( t('Profile not found.') . EOL); return; } @@ -187,7 +187,7 @@ function profiles_post(App $a) { $is_default = (($orig[0]['is-default']) ? 1 : 0); $profile_name = notags(trim($_POST['profile_name'])); - if(! strlen($profile_name)) { + if (! strlen($profile_name)) { notice( t('Profile Name is required.') . EOL); return; } @@ -195,27 +195,27 @@ function profiles_post(App $a) { $dob = $_POST['dob'] ? escape_tags(trim($_POST['dob'])) : '0000-00-00'; // FIXME: Needs to be validated? $y = substr($dob,0,4); - if((! ctype_digit($y)) || ($y < 1900)) + if ((! ctype_digit($y)) || ($y < 1900)) $ignore_year = true; else $ignore_year = false; - if($dob != '0000-00-00') { - if(strpos($dob,'0000-') === 0) { + if ($dob != '0000-00-00') { + if (strpos($dob,'0000-') === 0) { $ignore_year = true; $dob = substr($dob,5); } $dob = datetime_convert('UTC','UTC',(($ignore_year) ? '1900-' . $dob : $dob),(($ignore_year) ? 'm-d' : 'Y-m-d')); - if($ignore_year) + if ($ignore_year) $dob = '0000-' . $dob; } $name = notags(trim($_POST['name'])); - if(! strlen($name)) { + if (! strlen($name)) { $name = '[No Name]'; } - if($orig[0]['name'] != $name) + if ($orig[0]['name'] != $name) $namechanged = true; @@ -234,7 +234,7 @@ function profiles_post(App $a) { $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : ''); - if(! strlen($howlong)) + if (! strlen($howlong)) $howlong = '0000-00-00 00:00:00'; else $howlong = datetime_convert(date_default_timezone_get(),'UTC',$howlong); @@ -243,20 +243,20 @@ function profiles_post(App $a) { $withchanged = false; - if(strlen($with)) { - if($with != strip_tags($orig[0]['with'])) { + if (strlen($with)) { + if ($with != strip_tags($orig[0]['with'])) { $withchanged = true; $prf = ''; $lookup = $with; - if(strpos($lookup,'@') === 0) + if (strpos($lookup,'@') === 0) $lookup = substr($lookup,1); $lookup = str_replace('_',' ', $lookup); - if(strpos($lookup,'@') || (strpos($lookup,'http://'))) { + if (strpos($lookup,'@') || (strpos($lookup,'http://'))) { $newname = $lookup; $links = @Probe::lrdd($lookup); - if(count($links)) { - foreach($links as $link) { - if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') { + if (count($links)) { + foreach ($links as $link) { + if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') { $prf = $link['@attributes']['href']; } } @@ -280,7 +280,7 @@ function profiles_post(App $a) { dbesc($newname), intval(local_user()) ); - if(! $r) { + if (! $r) { $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1", dbesc($lookup), intval(local_user()) @@ -292,9 +292,9 @@ function profiles_post(App $a) { } } - if($prf) { + if ($prf) { $with = str_replace($lookup,'' . $newname . '', $with); - if(strpos($with,'@') === 0) + if (strpos($with,'@') === 0) $with = substr($with,1); } } @@ -333,61 +333,61 @@ function profiles_post(App $a) { $changes = array(); $value = ''; - if($is_default) { - if($marital != $orig[0]['marital']) { + if ($is_default) { + if ($marital != $orig[0]['marital']) { $changes[] = '[color=#ff0000]♥[/color] ' . t('Marital Status'); $value = $marital; } - if($withchanged) { + if ($withchanged) { $changes[] = '[color=#ff0000]♥[/color] ' . t('Romantic Partner'); $value = strip_tags($with); } - if($likes != $orig[0]['likes']) { + if ($likes != $orig[0]['likes']) { $changes[] = t('Likes'); $value = $likes; } - if($dislikes != $orig[0]['dislikes']) { + if ($dislikes != $orig[0]['dislikes']) { $changes[] = t('Dislikes'); $value = $dislikes; } - if($work != $orig[0]['work']) { + if ($work != $orig[0]['work']) { $changes[] = t('Work/Employment'); } - if($religion != $orig[0]['religion']) { + if ($religion != $orig[0]['religion']) { $changes[] = t('Religion'); $value = $religion; } - if($politic != $orig[0]['politic']) { + if ($politic != $orig[0]['politic']) { $changes[] = t('Political Views'); $value = $politic; } - if($gender != $orig[0]['gender']) { + if ($gender != $orig[0]['gender']) { $changes[] = t('Gender'); $value = $gender; } - if($sexual != $orig[0]['sexual']) { + if ($sexual != $orig[0]['sexual']) { $changes[] = t('Sexual Preference'); $value = $sexual; } - if($xmpp != $orig[0]['xmpp']) { + if ($xmpp != $orig[0]['xmpp']) { $changes[] = t('XMPP'); $value = $xmpp; } - if($homepage != $orig[0]['homepage']) { + if ($homepage != $orig[0]['homepage']) { $changes[] = t('Homepage'); $value = $homepage; } - if($interest != $orig[0]['interest']) { + if ($interest != $orig[0]['interest']) { $changes[] = t('Interests'); $value = $interest; } - if($address != $orig[0]['address']) { + if ($address != $orig[0]['address']) { $changes[] = t('Address'); // New address not sent in notifications, potential privacy issues // in case this leaks to unintended recipients. Yes, it's in the public // profile but that doesn't mean we have to broadcast it to everybody. } - if($locality != $orig[0]['locality'] || $region != $orig[0]['region'] + if ($locality != $orig[0]['locality'] || $region != $orig[0]['region'] || $country_name != $orig[0]['country-name']) { $changes[] = t('Location'); $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' '); @@ -520,13 +520,13 @@ function profiles_post(App $a) { function profile_activity($changed, $value) { $a = get_app(); - if(! local_user() || ! is_array($changed) || ! count($changed)) + if (! local_user() || ! is_array($changed) || ! count($changed)) return; - if($a->user['hidewall'] || get_config('system','block_public')) + if ($a->user['hidewall'] || get_config('system','block_public')) return; - if(! get_pconfig(local_user(),'system','post_profilechange')) + if (! get_pconfig(local_user(),'system','post_profilechange')) return; require_once('include/items.php'); @@ -535,7 +535,7 @@ function profile_activity($changed, $value) { intval(local_user()) ); - if(! count($self)) + if (! count($self)) return; $arr = array(); @@ -560,8 +560,8 @@ function profile_activity($changed, $value) { $changes = ''; $t = count($changed); $z = 0; - foreach($changed as $ch) { - if(strlen($changes)) { + foreach ($changed as $ch) { + if (strlen($changes)) { if ($z == ($t - 1)) $changes .= t(' and '); else @@ -573,7 +573,7 @@ function profile_activity($changed, $value) { $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]'; - if($t == 1 && strlen($value)) { + if ($t == 1 && strlen($value)) { $message = sprintf( t('%1$s changed %2$s to “%3$s”'), $A, $changes, $value); $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof); } @@ -611,7 +611,7 @@ function profiles_content(App $a) { $o = ''; - if(($a->argc > 1) && (intval($a->argv[1]))) { + if (($a->argc > 1) && (intval($a->argv[1]))) { $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[1]), intval(local_user()) @@ -623,7 +623,6 @@ function profiles_content(App $a) { require_once('include/profile_selectors.php'); - $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array( '$baseurl' => App::get_baseurl(true), )); @@ -653,7 +652,7 @@ function profiles_content(App $a) { $detailled_profile = (get_pconfig(local_user(),'system','detailled_profile') AND $personal_account); $f = get_config('system','birthday_input_format'); - if(! $f) + if (! $f) $f = 'ymd'; $is_default = (($r[0]['is-default']) ? 1 : 0); @@ -755,7 +754,7 @@ function profiles_content(App $a) { else { //If we don't support multi profiles, don't display this list. - if(!feature_enabled(local_user(),'multi_profiles')){ + if (!feature_enabled(local_user(),'multi_profiles')){ $r = q( "SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1", local_user() diff --git a/mod/profperm.php b/mod/profperm.php index a414d8947..37054fb7c 100644 --- a/mod/profperm.php +++ b/mod/profperm.php @@ -22,7 +22,7 @@ function profperm_content(App $a) { } - if($a->argc < 2) { + if ($a->argc < 2) { notice( t('Invalid profile identifier.') . EOL ); return; } @@ -30,13 +30,13 @@ function profperm_content(App $a) { // Switch to text mod interface if we have more than 'n' contacts or group members $switchtotext = get_pconfig(local_user(),'system','groupedit_image_limit'); - if($switchtotext === false) + if ($switchtotext === false) $switchtotext = get_config('system','groupedit_image_limit'); - if($switchtotext === false) + if ($switchtotext === false) $switchtotext = 400; - if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) { + if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) { $r = q("SELECT `id` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `self` = 0 AND `network` = '%s' AND `id` = %d AND `uid` = %d LIMIT 1", dbesc(NETWORK_DFRN), @@ -48,7 +48,7 @@ function profperm_content(App $a) { } - if(($a->argc > 1) && (intval($a->argv[1]))) { + if (($a->argc > 1) && (intval($a->argv[1]))) { $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1", intval($a->argv[1]), intval(local_user()) @@ -66,13 +66,13 @@ function profperm_content(App $a) { $ingroup = array(); if (dbm::is_result($r)) - foreach($r as $member) + foreach ($r as $member) $ingroup[] = $member['id']; $members = $r; - if($change) { - if(in_array($change,$ingroup)) { + if ($change) { + if (in_array($change,$ingroup)) { q("UPDATE `contact` SET `profile-id` = 0 WHERE `id` = %d AND `uid` = %d", intval($change), intval(local_user()) @@ -96,7 +96,7 @@ function profperm_content(App $a) { $ingroup = array(); if (dbm::is_result($r)) - foreach($r as $member) + foreach ($r as $member) $ingroup[] = $member['id']; } @@ -109,7 +109,7 @@ function profperm_content(App $a) { } $o .= '
'; - if($change) + if ($change) $o = ''; $o .= '
'; @@ -119,8 +119,8 @@ function profperm_content(App $a) { $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false); - foreach($members as $member) { - if($member['url']) { + foreach ($members as $member) { + if ($member['url']) { $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;'; $o .= micropro($member,true,'mpprof', $textmode); } @@ -141,8 +141,8 @@ function profperm_content(App $a) { if (dbm::is_result($r)) { $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false); - foreach($r as $member) { - if(! in_array($member['id'],$ingroup)) { + foreach ($r as $member) { + if (! in_array($member['id'],$ingroup)) { $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;'; $o .= micropro($member,true,'mpprof',$textmode); } @@ -151,7 +151,7 @@ function profperm_content(App $a) { $o .= '
'; - if($change) { + if ($change) { echo $o; killme(); } diff --git a/mod/pubsub.php b/mod/pubsub.php index 2ba1958a2..092461044 100644 --- a/mod/pubsub.php +++ b/mod/pubsub.php @@ -2,7 +2,7 @@ function hub_return($valid,$body) { - if($valid) { + if ($valid) { header($_SERVER["SERVER_PROTOCOL"] . ' 200 ' . 'OK'); echo $body; killme(); @@ -31,7 +31,7 @@ function pubsub_init(App $a) { $nick = (($a->argc > 1) ? notags(trim($a->argv[1])) : ''); $contact_id = (($a->argc > 2) ? intval($a->argv[2]) : 0 ); - if($_SERVER['REQUEST_METHOD'] === 'GET') { + if ($_SERVER['REQUEST_METHOD'] === 'GET') { $hub_mode = ((x($_GET,'hub_mode')) ? notags(trim($_GET['hub_mode'])) : ''); $hub_topic = ((x($_GET,'hub_topic')) ? notags(trim($_GET['hub_topic'])) : ''); @@ -68,7 +68,7 @@ function pubsub_init(App $a) { } if ($hub_topic) - if(! link_compare($hub_topic,$r[0]['poll'])) { + if (! link_compare($hub_topic,$r[0]['poll'])) { logger('pubsub: hub topic ' . $hub_topic . ' != ' . $r[0]['poll']); // should abort but let's humour them. } @@ -78,8 +78,8 @@ function pubsub_init(App $a) { // We must initiate an unsubscribe request with a verify_token. // Don't allow outsiders to unsubscribe us. - if($hub_mode === 'unsubscribe') { - if(! strlen($hub_verify)) { + if ($hub_mode === 'unsubscribe') { + if (! strlen($hub_verify)) { logger('pubsub: bogus unsubscribe'); hub_return(false, ''); } @@ -106,7 +106,7 @@ function pubsub_post(App $a) { logger('pubsub: user-agent: ' . $_SERVER['HTTP_USER_AGENT'] ); logger('pubsub: data: ' . $xml, LOGGER_DATA); -// if(! stristr($xml,' af11... // [hub_topic] => http://friendica.local/dfrn_poll/sazius - if($_SERVER['REQUEST_METHOD'] === 'POST') { + if ($_SERVER['REQUEST_METHOD'] === 'POST') { $hub_mode = post_var('hub_mode'); $hub_callback = post_var('hub_callback'); $hub_verify = post_var('hub_verify'); @@ -81,7 +81,7 @@ function pubsubhubbub_init(App $a) { $contact = $r[0]; // sanity check that topic URLs are the same - if(!link_compare($hub_topic, $contact['poll'])) { + if (!link_compare($hub_topic, $contact['poll'])) { logger('pubsubhubbub: hub topic ' . $hub_topic . ' != ' . $contact['poll']); http_status_exit(404); diff --git a/mod/qsearch.php b/mod/qsearch.php index 8512bea51..efc095a26 100644 --- a/mod/qsearch.php +++ b/mod/qsearch.php @@ -10,12 +10,14 @@ function qsearch_init(App $a) { $search = ((x($_GET,'s')) ? notags(trim(urldecode($_GET['s']))) : ''); - if(! strlen($search)) + if (! strlen($search)) { killme(); + } - if($search) + if ($search) { $search = dbesc($search); + } $results = array(); @@ -25,9 +27,9 @@ function qsearch_init(App $a) { ); if (dbm::is_result($r)) { - - foreach($r as $rr) + foreach ($r as $rr) { $results[] = array( 0, (int) $rr['id'], $rr['name'], '', ''); + } } $sql_extra = ((strlen($search)) ? " AND (`name` REGEXP '$search' OR `nick` REGEXP '$search') " : ""); @@ -40,9 +42,9 @@ function qsearch_init(App $a) { if (dbm::is_result($r)) { - - foreach($r as $rr) + foreach ($r as $rr) { $results[] = array( (int) $rr['id'], 0, $rr['name'],$rr['url'],$rr['photo']); + } } echo json_encode((object) $results); diff --git a/mod/receive.php b/mod/receive.php index 3563f2d70..d11bfdb85 100644 --- a/mod/receive.php +++ b/mod/receive.php @@ -14,19 +14,19 @@ function receive_post(App $a) { $enabled = intval(get_config('system','diaspora_enabled')); - if(! $enabled) { + if (! $enabled) { logger('mod-diaspora: disabled'); http_status_exit(500); } $public = false; - if(($a->argc == 2) && ($a->argv[1] === 'public')) { + if (($a->argc == 2) && ($a->argv[1] === 'public')) { $public = true; } else { - if($a->argc != 3 || $a->argv[1] !== 'users') + if ($a->argc != 3 || $a->argv[1] !== 'users') http_status_exit(500); $guid = $a->argv[2]; @@ -49,7 +49,7 @@ function receive_post(App $a) { logger('mod-diaspora: new salmon ' . $xml, LOGGER_DATA); - if(! $xml) + if (! $xml) http_status_exit(500); logger('mod-diaspora: message is okay', LOGGER_DEBUG); @@ -60,13 +60,13 @@ function receive_post(App $a) { logger('mod-diaspora: decoded msg: ' . print_r($msg,true), LOGGER_DATA); - if(! is_array($msg)) + if (! is_array($msg)) http_status_exit(500); logger('mod-diaspora: dispatching', LOGGER_DEBUG); $ret = 0; - if($public) { + if ($public) { Diaspora::dispatch_public($msg); } else { $ret = Diaspora::dispatch($importer,$msg); diff --git a/mod/redir.php b/mod/redir.php index 12f53900a..32a235de4 100644 --- a/mod/redir.php +++ b/mod/redir.php @@ -8,9 +8,9 @@ function redir_init(App $a) { // traditional DFRN - if( $con_url || (local_user() && $a->argc > 1 && intval($a->argv[1])) ) { + if ( $con_url || (local_user() && $a->argc > 1 && intval($a->argv[1])) ) { - if($con_url) { + if ($con_url) { $con_url = str_replace('https', 'http', $con_url); $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1", @@ -18,7 +18,7 @@ function redir_init(App $a) { intval(local_user()) ); - if((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN)) + if ((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN)) goaway(z_root()); $cid = $r[0]['id']; @@ -31,17 +31,17 @@ function redir_init(App $a) { intval(local_user()) ); - if((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN)) + if ((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN)) goaway(z_root()); } $dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']); - if($r[0]['duplex'] && $r[0]['issued-id']) { + if ($r[0]['duplex'] && $r[0]['issued-id']) { $orig_id = $r[0]['issued-id']; $dfrn_id = '1:' . $orig_id; } - if($r[0]['duplex'] && $r[0]['dfrn-id']) { + if ($r[0]['duplex'] && $r[0]['dfrn-id']) { $orig_id = $r[0]['dfrn-id']; $dfrn_id = '0:' . $orig_id; } diff --git a/mod/register.php b/mod/register.php index 81e8c3ad8..fe799f4c6 100644 --- a/mod/register.php +++ b/mod/register.php @@ -4,7 +4,7 @@ require_once('include/enotify.php'); require_once('include/bbcode.php'); require_once('include/user.php'); -if(! function_exists('register_post')) { +if (! function_exists('register_post')) { function register_post(App $a) { global $lang; @@ -16,9 +16,9 @@ function register_post(App $a) { call_hooks('register_post', $arr); $max_dailies = intval(get_config('system','max_daily_registrations')); - if($max_dailies) { + if ($max_dailies) { $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day"); - if($r && $r[0]['total'] >= $max_dailies) { + if ($r && $r[0]['total'] >= $max_dailies) { return; } } @@ -38,7 +38,7 @@ function register_post(App $a) { default: case REGISTER_CLOSED: - if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) { + if ((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) { notice( t('Permission denied.') . EOL ); return; } @@ -56,14 +56,14 @@ function register_post(App $a) { $result = create_user($arr); - if(! $result['success']) { + if (! $result['success']) { notice($result['message']); return; } $user = $result['user']; - if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) { + if ($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) { $url = App::get_baseurl() . '/profile/' . $user['nickname']; proc_run(PRIORITY_LOW, "include/directory.php", $url); } @@ -73,9 +73,9 @@ function register_post(App $a) { $invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : ''); - if( $a->config['register_policy'] == REGISTER_OPEN ) { + if ( $a->config['register_policy'] == REGISTER_OPEN ) { - if($using_invites && $invite_id) { + if ($using_invites && $invite_id) { q("delete * from register where hash = '%s' limit 1", dbesc($invite_id)); set_pconfig($user['uid'],'system','invites_remaining',$num_invites); } @@ -89,7 +89,7 @@ function register_post(App $a) { $user['username'], $result['password']); - if($res) { + if ($res) { info( t('Registration successful. Please check your email for further instructions.') . EOL ) ; goaway(z_root()); } else { @@ -106,8 +106,8 @@ function register_post(App $a) { goaway(z_root()); } } - elseif($a->config['register_policy'] == REGISTER_APPROVE) { - if(! strlen($a->config['admin_email'])) { + elseif ($a->config['register_policy'] == REGISTER_APPROVE) { + if (! strlen($a->config['admin_email'])) { notice( t('Your registration can not be processed.') . EOL); goaway(z_root()); } @@ -123,7 +123,7 @@ function register_post(App $a) { ); // invite system - if($using_invites && $invite_id) { + if ($using_invites && $invite_id) { q("delete * from register where hash = '%s' limit 1", dbesc($invite_id)); set_pconfig($user['uid'],'system','invites_remaining',$num_invites); } @@ -171,7 +171,7 @@ function register_post(App $a) { -if(! function_exists('register_content')) { +if (! function_exists('register_content')) { function register_content(App $a) { // logged in users can register others (people/pages/groups) @@ -180,29 +180,29 @@ function register_content(App $a) { $block = get_config('system','block_extended_register'); - if(local_user() && ($block)) { + if (local_user() && ($block)) { notice("Permission denied." . EOL); return; } - if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) { + if ((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) { notice("Permission denied." . EOL); return; } $max_dailies = intval(get_config('system','max_daily_registrations')); - if($max_dailies) { + if ($max_dailies) { $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day"); - if($r && $r[0]['total'] >= $max_dailies) { + if ($r && $r[0]['total'] >= $max_dailies) { logger('max daily registrations exceeded.'); notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL); return; } } - if(x($_SESSION,'theme')) + if (x($_SESSION,'theme')) unset($_SESSION['theme']); - if(x($_SESSION,'mobile-theme')) + if (x($_SESSION,'mobile-theme')) unset($_SESSION['mobile-theme']); @@ -215,7 +215,7 @@ function register_content(App $a) { $noid = get_config('system','no_openid'); - if($noid) { + if ($noid) { $oidhtml = ''; $fillwith = ''; $fillext = ''; @@ -232,7 +232,7 @@ function register_content(App $a) { $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.'); - if(get_config('system','publish_all')) { + if (get_config('system','publish_all')) { $profile_publish_reg = ''; } else { diff --git a/mod/regmod.php b/mod/regmod.php index 1983ca089..19fc047cc 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -54,7 +54,7 @@ function user_allow($hash) { pop_lang(); - if($res) { + if ($res) { info( t('Account approved.') . EOL ); return true; } @@ -72,8 +72,9 @@ function user_deny($hash) { dbesc($hash) ); - if(! dbm::is_result($register)) + if (! dbm::is_result($register)) { return false; + } $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($register[0]['uid']) diff --git a/mod/salmon.php b/mod/salmon.php index 69809f523..76ab999b2 100644 --- a/mod/salmon.php +++ b/mod/salmon.php @@ -8,9 +8,9 @@ require_once('include/follow.php'); function salmon_return($val) { - if($val >= 400) + if ($val >= 400) $err = 'Error'; - if($val >= 200 && $val < 300) + if ($val >= 200 && $val < 300) $err = 'OK'; logger('mod-salmon returns ' . $val); @@ -43,14 +43,14 @@ function salmon_post(App $a) { // figure out where in the DOM tree our data is hiding - if($dom->provenance->data) + if ($dom->provenance->data) $base = $dom->provenance; - elseif($dom->env->data) + elseif ($dom->env->data) $base = $dom->env; - elseif($dom->data) + elseif ($dom->data) $base = $dom; - if(! $base) { + if (! $base) { logger('mod-salmon: unable to locate salmon data in xml '); http_status_exit(400); } @@ -88,7 +88,7 @@ function salmon_post(App $a) { $author = ostatus::salmon_author($data,$importer); $author_link = $author["author-link"]; - if(! $author_link) { + if (! $author_link) { logger('mod-salmon: Could not retrieve author URI.'); http_status_exit(400); } @@ -99,7 +99,7 @@ function salmon_post(App $a) { $key = get_salmon_key($author_link,$keyhash); - if(! $key) { + if (! $key) { logger('mod-salmon: Could not retrieve author key.'); http_status_exit(400); } @@ -117,17 +117,17 @@ function salmon_post(App $a) { $verify = rsa_verify($compliant_format,$signature,$pubkey); - if(! $verify) { + if (! $verify) { logger('mod-salmon: message did not verify using protocol. Trying padding hack.'); $verify = rsa_verify($signed_data,$signature,$pubkey); } - if(! $verify) { + if (! $verify) { logger('mod-salmon: message did not verify using padding. Trying old statusnet hack.'); $verify = rsa_verify($stnet_signed_data,$signature,$pubkey); } - if(! $verify) { + if (! $verify) { logger('mod-salmon: Message did not verify. Discarding.'); http_status_exit(400); } @@ -153,9 +153,9 @@ function salmon_post(App $a) { ); if (! dbm::is_result($r)) { logger('mod-salmon: Author unknown to us.'); - if(get_pconfig($importer['uid'],'system','ostatus_autofriend')) { + if (get_pconfig($importer['uid'],'system','ostatus_autofriend')) { $result = new_contact($importer['uid'],$author_link); - if($result['success']) { + if ($result['success']) { $r = q("SELECT * FROM `contact` WHERE `network` = '%s' AND ( `url` = '%s' OR `alias` = '%s') AND `uid` = %d LIMIT 1", dbesc(NETWORK_OSTATUS), @@ -170,7 +170,7 @@ function salmon_post(App $a) { // Have we ignored the person? // If so we can not accept this post. - //if((dbm::is_result($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == CONTACT_IS_FOLLOWER) || ($r[0]['blocked']))) { + //if ((dbm::is_result($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == CONTACT_IS_FOLLOWER) || ($r[0]['blocked']))) { if (dbm::is_result($r) && $r[0]['blocked']) { logger('mod-salmon: Ignoring this author.'); http_status_exit(202); diff --git a/mod/search.php b/mod/search.php index 7d588aa4d..d07385753 100644 --- a/mod/search.php +++ b/mod/search.php @@ -8,7 +8,7 @@ function search_saved_searches() { $o = ''; - if(! feature_enabled(local_user(),'savedsearch')) + if (! feature_enabled(local_user(),'savedsearch')) return $o; $r = q("SELECT `id`,`term` FROM `search` WHERE `uid` = %d", @@ -47,8 +47,8 @@ function search_init(App $a) { $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); - if(local_user()) { - if(x($_GET,'save') && $search) { + if (local_user()) { + if (x($_GET,'save') && $search) { $r = q("SELECT * FROM `search` WHERE `uid` = %d AND `term` = '%s' LIMIT 1", intval(local_user()), dbesc($search) @@ -60,7 +60,7 @@ function search_init(App $a) { ); } } - if(x($_GET,'remove') && $search) { + if (x($_GET,'remove') && $search) { q("DELETE FROM `search` WHERE `uid` = %d AND `term` = '%s' LIMIT 1", intval(local_user()), dbesc($search) @@ -82,19 +82,19 @@ function search_init(App $a) { function search_post(App $a) { - if(x($_POST,'search')) + if (x($_POST,'search')) $a->data['search'] = $_POST['search']; } function search_content(App $a) { - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { notice( t('Public access denied.') . EOL); return; } - if(get_config('system','local_search') AND !local_user()) { + if (get_config('system','local_search') AND !local_user()) { http_status_exit(403, array("title" => t("Public access denied."), "description" => t("Only logged in users are permitted to perform a search."))); @@ -132,13 +132,13 @@ function search_content(App $a) { nav_set_selected('search'); - if(x($a->data,'search')) + if (x($a->data,'search')) $search = notags(trim($a->data['search'])); else $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); $tag = false; - if(x($_GET,'tag')) { + if (x($_GET,'tag')) { $tag = true; $search = ((x($_GET,'tag')) ? notags(trim(rawurldecode($_GET['tag']))) : ''); } @@ -151,18 +151,18 @@ function search_content(App $a) { '$content' => search($search,'search-box','search',((local_user()) ? true : false), false) )); - if(strpos($search,'#') === 0) { + if (strpos($search,'#') === 0) { $tag = true; $search = substr($search,1); } - if(strpos($search,'@') === 0) { + if (strpos($search,'@') === 0) { return dirfind_content($a); } - if(strpos($search,'!') === 0) { + if (strpos($search,'!') === 0) { return dirfind_content($a); } - if(x($_GET,'search-option')) + if (x($_GET,'search-option')) switch($_GET['search-option']) { case 'fulltext': break; @@ -177,7 +177,7 @@ function search_content(App $a) { break; } - if(! $search) + if (! $search) return $o; if (get_config('system','only_tag_search')) @@ -188,7 +188,7 @@ function search_content(App $a) { // OR your own posts if you are a logged in member // No items will be shown if the member has a blocked profile wall. - if($tag) { + if ($tag) { logger("Start tag search for '".$search."'", LOGGER_DEBUG); $r = q("SELECT %s @@ -226,7 +226,7 @@ function search_content(App $a) { } - if($tag) + if ($tag) $title = sprintf( t('Items tagged with: %s'), $search); else $title = sprintf( t('Results for: %s'), $search); diff --git a/mod/settings.php b/mod/settings.php index 4d23621cb..bfc444334 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -47,7 +47,7 @@ function settings_init(App $a) { ), ); - if(get_features()) { + if (get_features()) { $tabs[] = array( 'label' => t('Additional features'), 'url' => 'settings/features', @@ -189,23 +189,23 @@ function settings_post(App $a) { return; } - if(($a->argc > 1) && ($a->argv[1] == 'addon')) { + if (($a->argc > 1) && ($a->argv[1] == 'addon')) { check_form_security_token_redirectOnErr('/settings/addon', 'settings_addon'); call_hooks('plugin_settings_post', $_POST); return; } - if(($a->argc > 1) && ($a->argv[1] == 'connectors')) { + if (($a->argc > 1) && ($a->argv[1] == 'connectors')) { check_form_security_token_redirectOnErr('/settings/connectors', 'settings_connectors'); - if(x($_POST, 'general-submit')) { + if (x($_POST, 'general-submit')) { set_pconfig(local_user(), 'system', 'no_intelligent_shortening', intval($_POST['no_intelligent_shortening'])); set_pconfig(local_user(), 'system', 'ostatus_autofriend', intval($_POST['snautofollow'])); set_pconfig(local_user(), 'ostatus', 'default_group', $_POST['group-selection']); set_pconfig(local_user(), 'ostatus', 'legacy_contact', $_POST['legacy_contact']); - } elseif(x($_POST, 'imap-submit')) { + } elseif (x($_POST, 'imap-submit')) { $mail_server = ((x($_POST,'mail_server')) ? $_POST['mail_server'] : ''); $mail_port = ((x($_POST,'mail_port')) ? $_POST['mail_port'] : ''); @@ -219,10 +219,10 @@ function settings_post(App $a) { $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); - if(get_config('system','dfrn_only')) + if (get_config('system','dfrn_only')) $mail_disabled = 1; - if(! $mail_disabled) { + if (! $mail_disabled) { $failed = false; $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", intval(local_user()) @@ -232,7 +232,7 @@ function settings_post(App $a) { intval(local_user()) ); } - if(strlen($mail_pass)) { + if (strlen($mail_pass)) { $pass = ''; openssl_public_encrypt($mail_pass,$pass,$a->user['pubkey']); q("UPDATE `mailacct` SET `pass` = '%s' WHERE `uid` = %d", @@ -261,18 +261,18 @@ function settings_post(App $a) { $eacct = $r[0]; require_once('include/email.php'); $mb = construct_mailbox_name($eacct); - if(strlen($eacct['server'])) { + if (strlen($eacct['server'])) { $dcrpass = ''; openssl_private_decrypt(hex2bin($eacct['pass']),$dcrpass,$a->user['prvkey']); $mbox = email_connect($mb,$mail_user,$dcrpass); unset($dcrpass); - if(! $mbox) { + if (! $mbox) { $failed = true; notice( t('Failed to connect with email account using the settings provided.') . EOL); } } } - if(! $failed) + if (! $failed) info( t('Email settings updated.') . EOL); } } @@ -283,8 +283,8 @@ function settings_post(App $a) { if (($a->argc > 1) && ($a->argv[1] === 'features')) { check_form_security_token_redirectOnErr('/settings/features', 'settings_features'); - foreach($_POST as $k => $v) { - if(strpos($k,'feature_') === 0) { + foreach ($_POST as $k => $v) { + if (strpos($k,'feature_') === 0) { set_pconfig(local_user(),'feature',substr($k,8),((intval($v)) ? 1 : 0)); } } @@ -320,7 +320,7 @@ function settings_post(App $a) { $itemspage_mobile_network = 100; } - if($mobile_theme !== '') { + if ($mobile_theme !== '') { set_pconfig(local_user(),'system','mobile_theme',$mobile_theme); } @@ -487,7 +487,7 @@ function settings_post(App $a) { $name_change = false; - if($username != $a->user['username']) { + if ($username != $a->user['username']) { $name_change = true; if (strlen($username) > 40) { $err .= t(' Please use a shorter name.'); @@ -511,7 +511,7 @@ function settings_post(App $a) { $err .= t(' Not valid email.'); } // ensure new email is not the admin mail - //if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0)) { + //if ((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0)) { if (x($a->config,'admin_email')) { $adminlist = explode(",", str_replace(" ", "", strtolower($a->config['admin_email']))); if (in_array(strtolower($email), $adminlist)) { @@ -727,7 +727,7 @@ function settings_content(App $a) { return $o; } - if(($a->argc > 3) && ($a->argv[2] === 'delete')) { + if (($a->argc > 3) && ($a->argv[2] === 'delete')) { check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth', 't'); $r = q("DELETE FROM clients WHERE client_id='%s' AND uid=%d", @@ -865,10 +865,10 @@ function settings_content(App $a) { } $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); - if(get_config('system','dfrn_only')) + if (get_config('system','dfrn_only')) $mail_disabled = 1; - if(! $mail_disabled) { + if (! $mail_disabled) { $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", local_user() ); @@ -1176,7 +1176,7 @@ function settings_content(App $a) { } $opt_tpl = get_markup_template("field_yesno.tpl"); - if(get_config('system','publish_all')) { + if (get_config('system','publish_all')) { $profile_in_dir = ''; } else { $profile_in_dir = replace_macros($opt_tpl,array( diff --git a/mod/share.php b/mod/share.php index 36a4d5945..59081ec62 100644 --- a/mod/share.php +++ b/mod/share.php @@ -2,7 +2,7 @@ function share_init(App $a) { $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); - if((! $post_id) || (! local_user())) + if ((! $post_id) || (! local_user())) killme(); $r = q("SELECT item.*, contact.network FROM `item` @@ -12,7 +12,7 @@ function share_init(App $a) { intval($post_id), intval(local_user()) ); - if(! dbm::is_result($r) || ($r[0]['private'] == 1)) + if (! dbm::is_result($r) || ($r[0]['private'] == 1)) killme(); if (strpos($r[0]['body'], "[/share]") !== false) { diff --git a/mod/smilies.php b/mod/smilies.php index 4d8ab6bca..5ca3af14a 100644 --- a/mod/smilies.php +++ b/mod/smilies.php @@ -10,12 +10,11 @@ function smilies_content(App $a) { if ($a->argv[1]==="json"){ $tmp = Smilies::get_list(); $results = array(); - for($i = 0; $i < count($tmp['texts']); $i++) { + for ($i = 0; $i < count($tmp['texts']); $i++) { $results[] = array('text' => $tmp['texts'][$i], 'icon' => $tmp['icons'][$i]); } json_return_and_die($results); - } - else { + } else { return Smilies::replace('',true); } } diff --git a/mod/subthread.php b/mod/subthread.php index 646a4230c..b85f461dc 100644 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -7,7 +7,7 @@ require_once('include/items.php'); function subthread_content(App $a) { - if(! local_user() && ! remote_user()) { + if (! local_user() && ! remote_user()) { return; } @@ -20,7 +20,7 @@ function subthread_content(App $a) { dbesc($item_id) ); - if(! $item_id || (! dbm::is_result($r))) { + if (! $item_id || (! dbm::is_result($r))) { logger('subthread: no item ' . $item_id); return; } @@ -29,13 +29,13 @@ function subthread_content(App $a) { $owner_uid = $item['uid']; - if(! can_write_wall($a,$owner_uid)) { + if (! can_write_wall($a,$owner_uid)) { return; } $remote_owner = null; - if(! $item['wall']) { + if (! $item['wall']) { // The top level post may have been written by somebody on another system $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item['contact-id']), diff --git a/mod/tagger.php b/mod/tagger.php index 50099ac69..0ee2a0143 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -7,7 +7,7 @@ require_once('include/items.php'); function tagger_content(App $a) { - if(! local_user() && ! remote_user()) { + if (! local_user() && ! remote_user()) { return; } @@ -15,7 +15,7 @@ function tagger_content(App $a) { // no commas allowed $term = str_replace(array(',',' '),array('','_'),$term); - if(! $term) + if (! $term) return; $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0); @@ -27,7 +27,7 @@ function tagger_content(App $a) { dbesc($item_id) ); - if(! $item_id || (! dbm::is_result($r))) { + if (! $item_id || (! dbm::is_result($r))) { logger('tagger: no item ' . $item_id); return; } @@ -44,7 +44,7 @@ function tagger_content(App $a) { $blocktags = $r[0]['blocktags']; } - if(local_user() != $owner_uid) + if (local_user() != $owner_uid) return; $r = q("select * from contact where self = 1 and uid = %d limit 1", @@ -146,7 +146,7 @@ EOT; // ); - if(! $item['visible']) { + if (! $item['visible']) { $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d", intval($item['id']), intval($owner_uid) @@ -158,7 +158,7 @@ EOT; intval($item['id']), dbesc($term) ); - if((! $blocktags) && $t[0]['tcount']==0 ) { + if ((! $blocktags) && $t[0]['tcount']==0 ) { /*q("update item set tag = '%s' where id = %d", dbesc($item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . App::get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'), intval($item['id']) @@ -187,18 +187,18 @@ EOT; intval($r[0]['id']), dbesc($term) ); - if(count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){ + if (count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){ q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)", - intval($r[0]['id']), - $term_objtype, - TERM_HASHTAG, - dbesc($term), - dbesc(App::get_baseurl() . '/search?tag=' . $term), - intval($owner_uid) - ); + intval($r[0]['id']), + $term_objtype, + TERM_HASHTAG, + dbesc($term), + dbesc(App::get_baseurl() . '/search?tag=' . $term), + intval($owner_uid) + ); } - /*if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) { + /*if (count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) { q("update item set tag = '%s' where id = %d", dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . App::get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'), intval($r[0]['id']) diff --git a/mod/uexport.php b/mod/uexport.php index cada539bc..9bd3bd138 100644 --- a/mod/uexport.php +++ b/mod/uexport.php @@ -51,9 +51,9 @@ function _uexport_multirow($query) { $result = array(); $r = q($query); if (dbm::is_result($r)) { - foreach($r as $rr){ + foreach ($r as $rr){ $p = array(); - foreach($rr as $k => $v) { + foreach ($rr as $k => $v) { $p[$k] = $v; } $result[] = $p; @@ -66,8 +66,8 @@ function _uexport_row($query) { $result = array(); $r = q($query); if (dbm::is_result($r)) { - foreach($r as $rr) { - foreach($rr as $k => $v) { + foreach ($r as $rr) { + foreach ($rr as $k => $v) { $result[$k] = $v; } } @@ -151,8 +151,8 @@ function uexport_all(App $a) { intval(500) ); /*if (dbm::is_result($r)) { - foreach($r as $rr) - foreach($rr as $k => $v) + foreach ($r as $rr) + foreach ($rr as $k => $v) $item[][$k] = $v; }*/ diff --git a/mod/videos.php b/mod/videos.php index 3828b8f1f..19d5ce940 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -8,10 +8,10 @@ require_once('include/redir.php'); function videos_init(App $a) { - if($a->argc > 1) + if ($a->argc > 1) auto_redir($a, $a->argv[1]); - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { return; } @@ -19,14 +19,15 @@ function videos_init(App $a) { $o = ''; - if($a->argc > 1) { + if ($a->argc > 1) { $nick = $a->argv[1]; $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1", dbesc($nick) ); - if(! count($user)) + if (!dbm::is_result($user)) { return; + } $a->data['user'] = $user[0]; $a->profile_uid = $user[0]['uid']; @@ -52,35 +53,35 @@ function videos_init(App $a) { intval($a->data['user']['uid']) ); - if(count($albums)) { + if (count($albums)) { $a->data['albums'] = $albums; $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true); - if($albums_visible) { + if ($albums_visible) { $o .= ''; }*/ - if(! x($a->page,'aside')) + if (! x($a->page,'aside')) $a->page['aside'] = ''; $a->page['aside'] .= $vcard_widget; @@ -194,7 +195,7 @@ function videos_content(App $a) { // videos/name/video/xxxxx/edit - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { notice( t('Public access denied.') . EOL); return; } @@ -204,7 +205,7 @@ function videos_content(App $a) { require_once('include/security.php'); require_once('include/conversation.php'); - if(! x($a->data,'user')) { + if (! x($a->data,'user')) { notice( t('No videos selected') . EOL ); return; } @@ -217,16 +218,16 @@ function videos_content(App $a) { // Parse arguments // - if($a->argc > 3) { + if ($a->argc > 3) { $datatype = $a->argv[2]; $datum = $a->argv[3]; } - elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) + elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) $datatype = 'upload'; else $datatype = 'summary'; - if($a->argc > 4) + if ($a->argc > 4) $cmd = $a->argv[4]; else $cmd = 'view'; @@ -245,19 +246,19 @@ function videos_content(App $a) { $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false); - if((local_user()) && (local_user() == $owner_uid)) + if ((local_user()) && (local_user() == $owner_uid)) $can_post = true; else { - if($community_page && remote_user()) { - if(is_array($_SESSION['remote'])) { - foreach($_SESSION['remote'] as $v) { - if($v['uid'] == $owner_uid) { + if ($community_page && remote_user()) { + if (is_array($_SESSION['remote'])) { + foreach ($_SESSION['remote'] as $v) { + if ($v['uid'] == $owner_uid) { $contact_id = $v['cid']; break; } } } - if($contact_id) { + if ($contact_id) { $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), @@ -275,17 +276,17 @@ function videos_content(App $a) { // perhaps they're visiting - but not a community page, so they wouldn't have write access - if(remote_user() && (! $visitor)) { + if (remote_user() && (! $visitor)) { $contact_id = 0; - if(is_array($_SESSION['remote'])) { - foreach($_SESSION['remote'] as $v) { - if($v['uid'] == $owner_uid) { + if (is_array($_SESSION['remote'])) { + foreach ($_SESSION['remote'] as $v) { + if ($v['uid'] == $owner_uid) { $contact_id = $v['cid']; break; } } } - if($contact_id) { + if ($contact_id) { $groups = init_groups_visitor($contact_id); $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), @@ -298,14 +299,14 @@ function videos_content(App $a) { } } - if(! $remote_contact) { - if(local_user()) { + if (! $remote_contact) { + if (local_user()) { $contact_id = $_SESSION['cid']; $contact = $a->contact; } } - if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) { + if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) { notice( t('Access to this item is restricted.') . EOL); return; } @@ -323,13 +324,13 @@ function videos_content(App $a) { // - if($datatype === 'upload') { + if ($datatype === 'upload') { return; // no uploading for now // DELETED -- look at mod/photos.php if you want to implement } - if($datatype === 'album') { + if ($datatype === 'album') { return; // no albums for now @@ -337,7 +338,7 @@ function videos_content(App $a) { } - if($datatype === 'video') { + if ($datatype === 'video') { return; // no single video view for now diff --git a/mod/view.php b/mod/view.php index 15b3733b3..a6c482049 100644 --- a/mod/view.php +++ b/mod/view.php @@ -9,8 +9,9 @@ function view_init($a){ if ($a->argc == 4){ $theme = $a->argv[2]; $THEMEPATH = "view/theme/$theme"; - if(file_exists("view/theme/$theme/style.php")) + if (file_exists("view/theme/$theme/style.php")) { require_once("view/theme/$theme/style.php"); + } } killme(); diff --git a/mod/viewcontacts.php b/mod/viewcontacts.php index 5912f6cc7..1001f03cc 100644 --- a/mod/viewcontacts.php +++ b/mod/viewcontacts.php @@ -4,13 +4,13 @@ require_once('include/contact_selectors.php'); function viewcontacts_init(App $a) { - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { return; } nav_set_selected('home'); - if($a->argc > 1) { + if ($a->argc > 1) { $nick = $a->argv[1]; $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1", dbesc($nick) @@ -32,7 +32,7 @@ function viewcontacts_init(App $a) { function viewcontacts_content(App $a) { require_once("mod/proxy.php"); - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { notice( t('Public access denied.') . EOL); return; } @@ -42,7 +42,7 @@ function viewcontacts_content(App $a) { // tabs $o .= profile_tabs($a,$is_owner, $a->data['user']['nickname']); - if(((! count($a->profile)) || ($a->profile['hide-friends']))) { + if (((! count($a->profile)) || ($a->profile['hide-friends']))) { notice( t('Permission denied.') . EOL); return $o; } @@ -90,10 +90,11 @@ function viewcontacts_content(App $a) { $is_owner = ((local_user() && ($a->profile['profile_uid'] == local_user())) ? true : false); - if($is_owner && ($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) + if ($is_owner && ($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) { $url = 'redir/' . $rr['id']; - else + } else { $url = zrl($url); + } $contact_details = get_contact_details_by_url($rr['url'], $a->profile['uid'], $rr); diff --git a/mod/viewsrc.php b/mod/viewsrc.php index a3f0affb5..74652dcca 100644 --- a/mod/viewsrc.php +++ b/mod/viewsrc.php @@ -10,7 +10,7 @@ function viewsrc_content(App $a) { $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); - if(! $item_id) { + if (! $item_id) { $a->error = 404; notice( t('Item not found.') . EOL); return; @@ -25,7 +25,7 @@ function viewsrc_content(App $a) { ); if (dbm::is_result($r)) - if(is_ajax()) { + if (is_ajax()) { echo str_replace("\n",'
',$r[0]['body']); killme(); } else { diff --git a/mod/wall_attach.php b/mod/wall_attach.php index 0fc8b8a6a..932b6241d 100644 --- a/mod/wall_attach.php +++ b/mod/wall_attach.php @@ -7,7 +7,7 @@ function wall_attach_post(App $a) { $r_json = (x($_GET,'response') && $_GET['response']=='json'); - if($a->argc > 1) { + if ($a->argc > 1) { $nick = $a->argv[1]; $r = q("SELECT `user`.*, `contact`.`id` FROM `user` LEFT JOIN `contact` on `user`.`uid` = `contact`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1", dbesc($nick) @@ -36,20 +36,20 @@ function wall_attach_post(App $a) { $page_owner_nick = $r[0]['nickname']; $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false); - if((local_user()) && (local_user() == $page_owner_uid)) + if ((local_user()) && (local_user() == $page_owner_uid)) $can_post = true; else { - if($community_page && remote_user()) { + if ($community_page && remote_user()) { $contact_id = 0; - if(is_array($_SESSION['remote'])) { - foreach($_SESSION['remote'] as $v) { - if($v['uid'] == $page_owner_uid) { + if (is_array($_SESSION['remote'])) { + foreach ($_SESSION['remote'] as $v) { + if ($v['uid'] == $page_owner_uid) { $contact_id = $v['cid']; break; } } } - if($contact_id) { + if ($contact_id) { $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), @@ -62,7 +62,7 @@ function wall_attach_post(App $a) { } } } - if(! $can_post) { + if (! $can_post) { if ($r_json) { echo json_encode(array('error'=>t('Permission denied.'))); killme(); @@ -71,7 +71,7 @@ function wall_attach_post(App $a) { killme(); } - if(! x($_FILES,'userfile')) { + if (! x($_FILES,'userfile')) { if ($r_json) { echo json_encode(array('error'=>t('Invalid request.'))); } @@ -90,7 +90,7 @@ function wall_attach_post(App $a) { * Then Filesize gets <= 0. */ - if($filesize <=0) { + if ($filesize <=0) { $msg = t('Sorry, maybe your upload is bigger than the PHP configuration allows') . EOL .(t('Or - did you try to upload an empty file?')); if ($r_json) { echo json_encode(array('error'=>$msg)); @@ -101,7 +101,7 @@ function wall_attach_post(App $a) { killme(); } - if(($maxfilesize) && ($filesize > $maxfilesize)) { + if (($maxfilesize) && ($filesize > $maxfilesize)) { $msg = sprintf(t('File exceeds size limit of %s'), formatBytes($maxfilesize)); if ($r_json) { echo json_encode(array('error'=>$msg)); @@ -154,7 +154,7 @@ function wall_attach_post(App $a) { @unlink($src); - if(! $r) { + if (! $r) { $msg = t('File upload failed.'); if ($r_json) { echo json_encode(array('error'=>$msg)); diff --git a/mod/wall_upload.php b/mod/wall_upload.php index b793c9e40..85a174cff 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -8,8 +8,8 @@ function wall_upload_post(App $a, $desktopmode = true) { $r_json = (x($_GET,'response') && $_GET['response']=='json'); - if($a->argc > 1) { - if(! x($_FILES,'media')) { + if ($a->argc > 1) { + if (! x($_FILES,'media')) { $nick = $a->argv[1]; $r = q("SELECT `user`.*, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1", dbesc($nick) @@ -44,20 +44,20 @@ function wall_upload_post(App $a, $desktopmode = true) { $page_owner_nick = $r[0]['nickname']; $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false); - if((local_user()) && (local_user() == $page_owner_uid)) + if ((local_user()) && (local_user() == $page_owner_uid)) $can_post = true; else { - if($community_page && remote_user()) { + if ($community_page && remote_user()) { $contact_id = 0; - if(is_array($_SESSION['remote'])) { - foreach($_SESSION['remote'] as $v) { - if($v['uid'] == $page_owner_uid) { + if (is_array($_SESSION['remote'])) { + foreach ($_SESSION['remote'] as $v) { + if ($v['uid'] == $page_owner_uid) { $contact_id = $v['cid']; break; } } } - if($contact_id) { + if ($contact_id) { $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), @@ -72,7 +72,7 @@ function wall_upload_post(App $a, $desktopmode = true) { } - if(! $can_post) { + if (! $can_post) { if ($r_json) { echo json_encode(array('error'=>t('Permission denied.'))); killme(); @@ -81,7 +81,7 @@ function wall_upload_post(App $a, $desktopmode = true) { killme(); } - if(! x($_FILES,'userfile') && ! x($_FILES,'media')){ + if (! x($_FILES,'userfile') && ! x($_FILES,'media')){ if ($r_json) { echo json_encode(array('error'=>t('Invalid request.'))); } @@ -89,13 +89,13 @@ function wall_upload_post(App $a, $desktopmode = true) { } $src = ""; - if(x($_FILES,'userfile')) { + if (x($_FILES,'userfile')) { $src = $_FILES['userfile']['tmp_name']; $filename = basename($_FILES['userfile']['name']); $filesize = intval($_FILES['userfile']['size']); $filetype = $_FILES['userfile']['type']; } - elseif(x($_FILES,'media')) { + elseif (x($_FILES,'media')) { if (is_array($_FILES['media']['tmp_name'])) $src = $_FILES['media']['tmp_name'][0]; else @@ -147,7 +147,7 @@ function wall_upload_post(App $a, $desktopmode = true) { $maximagesize = get_config('system','maximagesize'); - if(($maximagesize) && ($filesize > $maximagesize)) { + if (($maximagesize) && ($filesize > $maximagesize)) { $msg = sprintf( t('Image exceeds size limit of %s'), formatBytes($maximagesize)); if ($r_json) { echo json_encode(array('error'=>$msg)); @@ -182,7 +182,7 @@ function wall_upload_post(App $a, $desktopmode = true) { $imagedata = @file_get_contents($src); $ph = new Photo($imagedata, $filetype); - if(! $ph->is_valid()) { + if (! $ph->is_valid()) { $msg = t('Unable to process image.'); if ($r_json) { echo json_encode(array('error'=>$msg)); @@ -197,9 +197,9 @@ function wall_upload_post(App $a, $desktopmode = true) { @unlink($src); $max_length = get_config('system','max_image_length'); - if(! $max_length) + if (! $max_length) $max_length = MAX_IMAGE_LENGTH; - if($max_length > 0) { + if ($max_length > 0) { $ph->scaleImage($max_length); logger("File upload: Scaling picture to new size ".$max_length, LOGGER_DEBUG); } diff --git a/mod/wallmessage.php b/mod/wallmessage.php index ff90e0dbc..d2fc91097 100644 --- a/mod/wallmessage.php +++ b/mod/wallmessage.php @@ -5,7 +5,7 @@ require_once('include/message.php'); function wallmessage_post(App $a) { $replyto = get_my_url(); - if(! $replyto) { + if (! $replyto) { notice( t('Permission denied.') . EOL); return; } @@ -14,7 +14,7 @@ function wallmessage_post(App $a) { $body = ((x($_REQUEST,'body')) ? escape_tags(trim($_REQUEST['body'])) : ''); $recipient = (($a->argc > 1) ? notags($a->argv[1]) : ''); - if((! $recipient) || (! $body)) { + if ((! $recipient) || (! $body)) { return; } @@ -29,7 +29,7 @@ function wallmessage_post(App $a) { $user = $r[0]; - if(! intval($user['unkmail'])) { + if (! intval($user['unkmail'])) { notice( t('Permission denied.') . EOL); return; } @@ -38,7 +38,7 @@ function wallmessage_post(App $a) { intval($user['uid']) ); - if($r[0]['total'] > $user['cntunkmail']) { + if ($r[0]['total'] > $user['cntunkmail']) { notice( sprintf( t('Number of daily wall messages for %s exceeded. Message failed.', $user['username']))); return; } @@ -69,14 +69,14 @@ function wallmessage_post(App $a) { function wallmessage_content(App $a) { - if(! get_my_url()) { + if (! get_my_url()) { notice( t('Permission denied.') . EOL); return; } $recipient = (($a->argc > 1) ? $a->argv[1] : ''); - if(! $recipient) { + if (! $recipient) { notice( t('No recipient.') . EOL); return; } @@ -93,16 +93,19 @@ function wallmessage_content(App $a) { $user = $r[0]; - if(! intval($user['unkmail'])) { + if (! intval($user['unkmail'])) { notice( t('Permission denied.') . EOL); return; } - $r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1", + $r = q("SELECT COUNT(*) AS `total` FROM `mail` WHERE `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 1 DAY AND `unknown` = 1", intval($user['uid']) ); - if($r[0]['total'] > $user['cntunkmail']) { + if (!dbm::is_result($r)) { + ///@TODO Output message to use of failed query + return; + } elseif ($r[0]['total'] > $user['cntunkmail']) { notice( sprintf( t('Number of daily wall messages for %s exceeded. Message failed.', $user['username']))); return; } diff --git a/mod/webfinger.php b/mod/webfinger.php index eee0580e3..8e54dd275 100644 --- a/mod/webfinger.php +++ b/mod/webfinger.php @@ -11,7 +11,7 @@ function webfinger_content(App $a) { $o .= '

'; - if(x($_GET,'addr')) { + if (x($_GET,'addr')) { $addr = trim($_GET['addr']); $res = Probe::lrdd($addr); $o .= '
';
diff --git a/mod/xrd.php b/mod/xrd.php
index 7b812a7f9..93d7b18b0 100644
--- a/mod/xrd.php
+++ b/mod/xrd.php
@@ -6,14 +6,15 @@ function xrd_init(App $a) {
 
 	$uri = urldecode(notags(trim($_GET['uri'])));
 
-	if(substr($uri,0,4) === 'http') {
+	if (substr($uri,0,4) === 'http') {
 		$acct = false;
 		$name = basename($uri);
 	} else {
 		$acct = true;
 		$local = str_replace('acct:', '', $uri);
-		if(substr($local,0,2) == '//')
+		if (substr($local,0,2) == '//') {
 			$local = substr($local,2);
+		}
 
 		$name = substr($local,0,strpos($local,'@'));
 	}

From 41a36606c6ee92c914acbb7f6d9ea79c0a149088 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roland=20H=C3=A4der?= 
Date: Thu, 26 Jan 2017 16:01:56 +0100
Subject: [PATCH 26/65] added spaces + some curly braces
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder 
---
 include/Contact.php              |  24 +--
 include/DirSearch.php            |   7 +-
 include/ForumManager.php         |  14 +-
 include/NotificationsManager.php |  26 ++--
 include/Probe.php                |  25 ++--
 include/Smilies.php              |  10 +-
 include/acl_selectors.php        |  48 +++---
 include/api.php                  |  64 ++++----
 include/attach.php               |   2 +-
 include/bb2diaspora.php          |   6 +-
 include/bbcode.php               |  46 +++---
 include/cli_startup.php          |   2 +-
 include/contact_widgets.php      |  38 ++---
 include/conversation.php         | 211 +++++++++++++-------------
 include/cron.php                 |  61 ++++----
 include/cronhooks.php            |  10 +-
 include/crypto.php               |  12 +-
 include/datetime.php             |  86 ++++++-----
 include/dba_pdo.php              |  74 ++++-----
 include/dbstructure.php          |   4 +-
 include/dfrn.php                 |  26 ++--
 include/diaspora.php             |  75 +++++-----
 include/discover_poco.php        |   4 +-
 include/email.php                |  22 +--
 include/enotify.php              |   6 +-
 include/event.php                | 105 +++++++------
 include/expire.php               |   7 +-
 include/features.php             |  10 +-
 include/feed.php                 |   5 +-
 include/files.php                |   2 +-
 include/friendica_smarty.php     |  10 +-
 include/group.php                |  40 ++---
 include/identity.php             |  95 ++++++------
 include/items.php                |   8 +-
 include/lock.php                 |  25 ++--
 include/message.php              |  14 +-
 include/nav.php                  |   4 +-
 include/network.php              |  88 +++++------
 include/oauth.php                |   2 +-
 include/oembed.php               |   4 +-
 include/onepoll.php              |   2 +-
 include/ostatus.php              |   8 +-
 include/pgettext.php             |  30 ++--
 include/plugin.php               |  65 ++++----
 include/poller.php               |   8 +-
 include/profile_selectors.php    |   6 +-
 include/pubsubpublish.php        |  12 +-
 include/queue_fn.php             |  11 +-
 include/quoteconvert.php         |   6 +-
 include/redir.php                |  14 +-
 include/salmon.php               |  19 ++-
 include/security.php             |  38 ++---
 include/socgraph.php             |  44 +++---
 include/tags.php                 |  17 ++-
 include/template_processor.php   |   2 +-
 include/text.php                 | 248 +++++++++++++++----------------
 include/threads.php              |  24 ++-
 include/update_gcontact.php      |  22 ++-
 include/user.php                 |  48 +++---
 include/xml.php                  |   2 +-
 60 files changed, 1018 insertions(+), 930 deletions(-)

diff --git a/include/Contact.php b/include/Contact.php
index 9fd61f8d5..de76789e8 100644
--- a/include/Contact.php
+++ b/include/Contact.php
@@ -5,7 +5,7 @@
 // authorisation to do this.
 
 function user_remove($uid) {
-	if(! $uid)
+	if (! $uid)
 		return;
 	logger('Removing user: ' . $uid);
 
@@ -49,7 +49,7 @@ function user_remove($uid) {
 	// Send an update to the directory
 	proc_run(PRIORITY_LOW, "include/directory.php", $r[0]['url']);
 
-	if($uid == local_user()) {
+	if ($uid == local_user()) {
 		unset($_SESSION['authenticated']);
 		unset($_SESSION['uid']);
 		goaway(App::get_baseurl());
@@ -124,10 +124,10 @@ function terminate_friendship($user,$self,$contact) {
 
 function mark_for_death($contact) {
 
-	if($contact['archive'])
+	if ($contact['archive'])
 		return;
 
-	if($contact['term-date'] == '0000-00-00 00:00:00') {
+	if ($contact['term-date'] == '0000-00-00 00:00:00') {
 		q("UPDATE `contact` SET `term-date` = '%s' WHERE `id` = %d",
 				dbesc(datetime_convert()),
 				intval($contact['id'])
@@ -151,7 +151,7 @@ function mark_for_death($contact) {
 		/// Check for contact vitality via probing
 
 		$expiry = $contact['term-date'] . ' + 32 days ';
-		if(datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
+		if (datetime_convert() > datetime_convert('UTC','UTC',$expiry)) {
 
 			// relationship is really truly dead.
 			// archive them rather than delete
@@ -483,7 +483,7 @@ function random_profile() {
 
 function contacts_not_grouped($uid,$start = 0,$count = 0) {
 
-	if(! $count) {
+	if (! $count) {
 		$r = q("select count(*) as total from contact where uid = %d and self = 0 and id not in (select distinct(`contact-id`) from group_member where uid = %d) ",
 			intval($uid),
 			intval($uid)
@@ -775,18 +775,18 @@ function posts_from_contact_url(App $a, $contact_url) {
 function formatted_location($profile) {
 	$location = '';
 
-	if($profile['locality'])
+	if ($profile['locality'])
 		$location .= $profile['locality'];
 
-	if($profile['region'] AND ($profile['locality'] != $profile['region'])) {
-		if($location)
+	if ($profile['region'] AND ($profile['locality'] != $profile['region'])) {
+		if ($location)
 			$location .= ', ';
 
 		$location .= $profile['region'];
 	}
 
-	if($profile['country-name']) {
-		if($location)
+	if ($profile['country-name']) {
+		if ($location)
 			$location .= ', ';
 
 		$location .= $profile['country-name'];
@@ -808,7 +808,7 @@ function account_type($contact) {
 	// "page-flags" is a field in the user table,
 	// "forum" and "prv" are used in the contact table. They stand for PAGE_COMMUNITY and PAGE_PRVGROUP.
 	// "community" is used in the gcontact table and is true if the contact is PAGE_COMMUNITY or PAGE_PRVGROUP.
-	if((isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_COMMUNITY))
+	if ((isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_COMMUNITY))
 		|| (isset($contact['page-flags']) && (intval($contact['page-flags']) == PAGE_PRVGROUP))
 		|| (isset($contact['forum']) && intval($contact['forum']))
 		|| (isset($contact['prv']) && intval($contact['prv']))
diff --git a/include/DirSearch.php b/include/DirSearch.php
index 596860823..da32358c1 100644
--- a/include/DirSearch.php
+++ b/include/DirSearch.php
@@ -20,7 +20,7 @@ class DirSearch {
 	 */
 	public static function global_search_by_name($search, $mode = '') {
 
-		if($search) {
+		if ($search) {
 			// check supported networks
 			if (get_config('system','diaspora_enabled'))
 				$diaspora = NETWORK_DIASPORA;
@@ -33,10 +33,11 @@ class DirSearch {
 				$ostatus = NETWORK_DFRN;
 
 			// check if we search only communities or every contact
-			if($mode === "community")
+			if ($mode === "community") {
 				$extra_sql = " AND `community`";
-			else
+			} else {
 				$extra_sql = "";
+			}
 
 			$search .= "%";
 
diff --git a/include/ForumManager.php b/include/ForumManager.php
index c2a20df29..3fae9f3d8 100644
--- a/include/ForumManager.php
+++ b/include/ForumManager.php
@@ -76,7 +76,7 @@ class ForumManager {
 	 */
 	public static function widget($uid,$cid = 0) {
 
-		if(! intval(feature_enabled(local_user(),'forumlist_widget')))
+		if (! intval(feature_enabled(local_user(),'forumlist_widget')))
 			return;
 
 		$o = '';
@@ -136,7 +136,7 @@ class ForumManager {
 	public static function profile_advanced($uid) {
 
 		$profile = intval(feature_enabled($uid,'forumlist_profile'));
-		if(! $profile)
+		if (! $profile)
 			return;
 
 		$o = '';
@@ -154,13 +154,17 @@ class ForumManager {
 		foreach($contacts as $contact) {
 			$forumlist .= micropro($contact,false,'forumlist-profile-advanced');
 			$total_shown ++;
-			if($total_shown == $show_total)
+
+			if ($total_shown == $show_total) {
 				break;
+			}
 		}
 
-		if(count($contacts) > 0)
+		if (count($contacts) > 0) {
 			$o .= $forumlist;
-			return $o;
+		}
+
+		return $o;
 	}
 
 	/**
diff --git a/include/NotificationsManager.php b/include/NotificationsManager.php
index 611860f9d..c75407993 100644
--- a/include/NotificationsManager.php
+++ b/include/NotificationsManager.php
@@ -81,7 +81,7 @@ class NotificationsManager {
 		}
 		$order_sql = implode(", ", $asOrder);
 
-		if($limit!="")
+		if ($limit!="")
 			$limit = " LIMIT ".$limit;
 
 			$r = q("SELECT * FROM `notify` WHERE `uid` = %d $filter_sql ORDER BY $order_sql $limit",
@@ -369,7 +369,7 @@ class NotificationsManager {
 	private function networkTotal($seen = 0) {
 		$sql_seen = "";
 
-		if($seen === 0)
+		if ($seen === 0)
 			$sql_seen = " AND `item`.`unseen` = 1 ";
 
 		$r = q("SELECT COUNT(*) AS `total`
@@ -406,7 +406,7 @@ class NotificationsManager {
 		$notifs = array();
 		$sql_seen = "";
 
-		if($seen === 0)
+		if ($seen === 0)
 			$sql_seen = " AND `item`.`unseen` = 1 ";
 
 
@@ -445,7 +445,7 @@ class NotificationsManager {
 	private function systemTotal($seen = 0) {
 		$sql_seen = "";
 
-		if($seen === 0)
+		if ($seen === 0)
 			$sql_seen = " AND `seen` = 0 ";
 
 		$r = q("SELECT COUNT(*) AS `total` FROM `notify` WHERE `uid` = %d $sql_seen",
@@ -478,7 +478,7 @@ class NotificationsManager {
 		$notifs = array();
 		$sql_seen = "";
 
-		if($seen === 0)
+		if ($seen === 0)
 			$sql_seen = " AND `seen` = 0 ";
 
 		$r = q("SELECT `id`, `url`, `photo`, `msg`, `date`, `seen` FROM `notify`
@@ -530,7 +530,7 @@ class NotificationsManager {
 		$sql_seen = "";
 		$sql_extra = $this->_personal_sql_extra();
 
-		if($seen === 0)
+		if ($seen === 0)
 			$sql_seen = " AND `item`.`unseen` = 1 ";
 
 		$r = q("SELECT COUNT(*) AS `total`
@@ -569,7 +569,7 @@ class NotificationsManager {
 		$notifs = array();
 		$sql_seen = "";
 
-		if($seen === 0)
+		if ($seen === 0)
 			$sql_seen = " AND `item`.`unseen` = 1 ";
 
 		$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
@@ -608,7 +608,7 @@ class NotificationsManager {
 	private function homeTotal($seen = 0) {
 		$sql_seen = "";
 
-		if($seen === 0)
+		if ($seen === 0)
 			$sql_seen = " AND `item`.`unseen` = 1 ";
 
 		$r = q("SELECT COUNT(*) AS `total` FROM `item`
@@ -644,7 +644,7 @@ class NotificationsManager {
 		$notifs = array();
 		$sql_seen = "";
 
-		if($seen === 0)
+		if ($seen === 0)
 			$sql_seen = " AND `item`.`unseen` = 1 ";
 
 		$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
@@ -682,7 +682,7 @@ class NotificationsManager {
 	private function introTotal($all = false) {
 		$sql_extra = "";
 
-		if(!$all)
+		if (!$all)
 			$sql_extra = " AND `ignore` = 0 ";
 
 		$r = q("SELECT COUNT(*) AS `total` FROM `intro`
@@ -716,7 +716,7 @@ class NotificationsManager {
 		$notifs = array();
 		$sql_extra = "";
 
-		if(!$all)
+		if (!$all)
 			$sql_extra = " AND `ignore` = 0 ";
 
 		/// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact
@@ -761,7 +761,7 @@ class NotificationsManager {
 			// We have to distinguish between these two because they use different data.
 
 			// Contact suggestions
-			if($it['fid']) {
+			if ($it['fid']) {
 
 				$return_addr = bin2hex($this->a->user['nickname'] . '@' . $this->a->get_hostname() . (($this->a->path) ? '/' . $this->a->path : ''));
 
@@ -793,7 +793,7 @@ class NotificationsManager {
 					$it['gnetwork'] = $ret["network"];
 
 				// Don't show these data until you are connected. Diaspora is doing the same.
-				if($it['gnetwork'] === NETWORK_DIASPORA) {
+				if ($it['gnetwork'] === NETWORK_DIASPORA) {
 					$it['glocation'] = "";
 					$it['gabout'] = "";
 					$it['ggender'] = "";
diff --git a/include/Probe.php b/include/Probe.php
index 1b6feb107..ac7fe712f 100644
--- a/include/Probe.php
+++ b/include/Probe.php
@@ -564,15 +564,15 @@ class Probe {
 	 */
 	public static function valid_dfrn($data) {
 		$errors = 0;
-		if(!isset($data['key']))
+		if (!isset($data['key']))
 			$errors ++;
-		if(!isset($data['dfrn-request']))
+		if (!isset($data['dfrn-request']))
 			$errors ++;
-		if(!isset($data['dfrn-confirm']))
+		if (!isset($data['dfrn-confirm']))
 			$errors ++;
-		if(!isset($data['dfrn-notify']))
+		if (!isset($data['dfrn-notify']))
 			$errors ++;
-		if(!isset($data['dfrn-poll']))
+		if (!isset($data['dfrn-poll']))
 			$errors ++;
 		return $errors;
 	}
@@ -1133,15 +1133,17 @@ class Probe {
 			$password = '';
 			openssl_private_decrypt(hex2bin($r[0]['pass']), $password,$x[0]['prvkey']);
 			$mbox = email_connect($mailbox,$r[0]['user'], $password);
-			if(!mbox)
+			if (!$mbox) {
 				return false;
+			}
 		}
 
 		$msgs = email_poll($mbox, $uri);
 		logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
 
-		if (!count($msgs))
+		if (!count($msgs)) {
 			return false;
+		}
 
 		$data = array();
 
@@ -1157,13 +1159,14 @@ class Probe {
 		$data["poll"] = 'email '.random_string();
 
 		$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, '');
-		elseif(stristr($x[0]->to, $uri))
+		} elseif (stristr($x[0]->to, $uri)) {
 			$adr = imap_rfc822_parse_adrlist($x[0]->to, '');
-		if(isset($adr)) {
+		}
+		if (isset($adr)) {
 			foreach($adr as $feadr) {
-				if((strcasecmp($feadr->mailbox, $data["name"]) == 0)
+				if ((strcasecmp($feadr->mailbox, $data["name"]) == 0)
 					&&(strcasecmp($feadr->host, $phost) == 0)
 					&& (strlen($feadr->personal))) {
 
diff --git a/include/Smilies.php b/include/Smilies.php
index d67b92d8b..fd8ea60af 100644
--- a/include/Smilies.php
+++ b/include/Smilies.php
@@ -125,7 +125,7 @@ class Smilies {
 	 * @return string HML Output of the Smilie
 	 */
 	public static function replace($s, $sample = false) {
-		if(intval(get_config('system','no_smilies'))
+		if (intval(get_config('system','no_smilies'))
 			|| (local_user() && intval(get_pconfig(local_user(),'system','no_smilies'))))
 			return $s;
 
@@ -135,7 +135,7 @@ class Smilies {
 		$params = self::get_list();
 		$params['string'] = $s;
 
-		if($sample) {
+		if ($sample) {
 			$s = '
'; for($x = 0; $x < count($params['texts']); $x ++) { $s .= '
' . $params['texts'][$x] . '
' . $params['icons'][$x] . '
'; @@ -170,11 +170,13 @@ class Smilies { * @todo: Rework because it doesn't work correctly */ private function preg_heart($x) { - if(strlen($x[1]) == 1) + if (strlen($x[1]) == 1) { return $x[0]; + } $t = ''; - for($cnt = 0; $cnt < strlen($x[1]); $cnt ++) + for($cnt = 0; $cnt < strlen($x[1]); $cnt ++) { $t .= '<3'; + } $r = str_replace($x[0],$t,$x[0]); return $r; } diff --git a/include/acl_selectors.php b/include/acl_selectors.php index f4b644d68..5eb54edf3 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -35,7 +35,7 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) { if (dbm::is_result($r)) { foreach ($r as $rr) { - if((is_array($preselected)) && in_array($rr['id'], $preselected)) + if ((is_array($preselected)) && in_array($rr['id'], $preselected)) $selected = " selected=\"selected\" "; else $selected = ''; @@ -88,13 +88,13 @@ function contact_selector($selname, $selclass, $preselected = false, $options) { $networks = array(NETWORK_DFRN); break; case 'PRIVATE': - if(is_array($a->user) && $a->user['prvnets']) + if (is_array($a->user) && $a->user['prvnets']) $networks = array(NETWORK_DFRN,NETWORK_MAIL,NETWORK_DIASPORA); else $networks = array(NETWORK_DFRN,NETWORK_FACEBOOK,NETWORK_MAIL, NETWORK_DIASPORA); break; case 'TWO_WAY': - if(is_array($a->user) && $a->user['prvnets']) + if (is_array($a->user) && $a->user['prvnets']) $networks = array(NETWORK_DFRN,NETWORK_MAIL,NETWORK_DIASPORA); else $networks = array(NETWORK_DFRN,NETWORK_FACEBOOK,NETWORK_MAIL,NETWORK_DIASPORA,NETWORK_OSTATUS); @@ -113,14 +113,14 @@ function contact_selector($selname, $selclass, $preselected = false, $options) { $sql_extra = ''; - if($x['mutual']) { + if ($x['mutual']) { $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND)); } - if(intval($x['exclude'])) + if (intval($x['exclude'])) $sql_extra .= sprintf(" AND `id` != %d ", intval($x['exclude'])); - if(is_array($x['networks']) && count($x['networks'])) { + if (is_array($x['networks']) && count($x['networks'])) { for($y = 0; $y < count($x['networks']) ; $y ++) $x['networks'][$y] = "'" . dbesc($x['networks'][$y]) . "'"; $str_nets = implode(',',$x['networks']); @@ -129,7 +129,7 @@ function contact_selector($selname, $selclass, $preselected = false, $options) { $tabindex = (x($options, 'tabindex') ? "tabindex=\"" . $options["tabindex"] . "\"" : ""); - if($x['single']) + if ($x['single']) $o .= "\r\n"; @@ -185,14 +185,14 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p $sql_extra = ''; - if($privmail || $celeb) { + if ($privmail || $celeb) { $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND)); } - if($privmail) + if ($privmail) $sql_extra .= sprintf(" AND `network` IN ('%s' , '%s') ", NETWORK_DFRN, NETWORK_DIASPORA); - elseif($privatenet) + elseif ($privatenet) $sql_extra .= sprintf(" AND `network` IN ('%s' , '%s', '%s', '%s') ", NETWORK_DFRN, NETWORK_MAIL, NETWORK_FACEBOOK, NETWORK_DIASPORA); @@ -204,7 +204,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p } else $hidepreselected = ""; - if($privmail) + if ($privmail) $o .= "\r\n"; @@ -287,7 +287,7 @@ function prune_deadguys($arr) { function get_acl_permissions($user = null) { $allow_cid = $allow_gid = $deny_cid = $deny_gid = false; - if(is_array($user)) { + if (is_array($user)) { $allow_cid = ((strlen($user['allow_cid'])) ? explode('><', $user['allow_cid']) : array() ); $allow_gid = ((strlen($user['allow_gid'])) @@ -318,25 +318,25 @@ function populate_acl($user = null, $show_jotnets = false) { $perms = get_acl_permissions($user); $jotnets = ''; - if($show_jotnets) { + if ($show_jotnets) { $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); $mail_enabled = false; $pubmail_enabled = false; - if(! $mail_disabled) { + if (! $mail_disabled) { $r = q("SELECT `pubmail` FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user()) ); if (dbm::is_result($r)) { $mail_enabled = true; - if(intval($r[0]['pubmail'])) + if (intval($r[0]['pubmail'])) $pubmail_enabled = true; } } if (!$user['hidewall']) { - if($mail_enabled) { + if ($mail_enabled) { $selected = (($pubmail_enabled) ? ' checked="checked" ' : ''); $jotnets .= '
' . t("Post to Email") . '
'; } @@ -379,20 +379,20 @@ function construct_acl_data(App $a, $user) { $user_defaults = get_acl_permissions($user); - if($acl_data['groups']) { + if ($acl_data['groups']) { foreach($acl_data['groups'] as $key=>$group) { // Add a "selected" flag to groups that are posted to by default - if($user_defaults['allow_gid'] && + if ($user_defaults['allow_gid'] && in_array($group['id'], $user_defaults['allow_gid']) && !in_array($group['id'], $user_defaults['deny_gid']) ) $acl_data['groups'][$key]['selected'] = 1; else $acl_data['groups'][$key]['selected'] = 0; } } - if($acl_data['contacts']) { + if ($acl_data['contacts']) { foreach($acl_data['contacts'] as $key=>$contact) { // Add a "selected" flag to groups that are posted to by default - if($user_defaults['allow_cid'] && + if ($user_defaults['allow_cid'] && in_array($contact['id'], $user_defaults['allow_cid']) && !in_array($contact['id'], $user_defaults['deny_cid']) ) $acl_data['contacts'][$key]['selected'] = 1; else @@ -419,8 +419,8 @@ function acl_lookup(App $a, $out_type = 'json') { // For use with jquery.textcomplete for private mail completion - if(x($_REQUEST,'query') && strlen($_REQUEST['query'])) { - if(! $type) + if (x($_REQUEST,'query') && strlen($_REQUEST['query'])) { + if (! $type) $type = 'm'; $search = $_REQUEST['query']; } @@ -546,7 +546,7 @@ function acl_lookup(App $a, $out_type = 'json') { dbesc(NETWORK_STATUSNET) ); } - elseif($type == 'm') { + elseif ($type == 'm') { $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact` WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `network` IN ('%s','%s','%s') @@ -665,7 +665,7 @@ function acl_lookup(App $a, $out_type = 'json') { call_hooks('acl_lookup_end', $results); - if($out_type === 'html') { + if ($out_type === 'html') { $o = array( 'tot' => $results['tot'], 'start' => $results['start'], diff --git a/include/api.php b/include/api.php index 701e527cc..66703bd6c 100644 --- a/include/api.php +++ b/include/api.php @@ -154,9 +154,9 @@ use \Friendica\Core\Config; // workaround for HTTP-auth in CGI mode - if(x($_SERVER,'REDIRECT_REMOTE_USER')) { + if (x($_SERVER,'REDIRECT_REMOTE_USER')) { $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"],6)) ; - if(strlen($userpass)) { + if (strlen($userpass)) { list($name, $password) = explode(':', $userpass); $_SERVER['PHP_AUTH_USER'] = $name; $_SERVER['PHP_AUTH_PW'] = $password; @@ -199,7 +199,7 @@ use \Friendica\Core\Config; call_hooks('authenticate', $addon_auth); - if(($addon_auth['authenticated']) && (count($addon_auth['user_record']))) { + if (($addon_auth['authenticated']) && (count($addon_auth['user_record']))) { $record = $addon_auth['user_record']; } else { @@ -215,7 +215,7 @@ use \Friendica\Core\Config; $record = $r[0]; } - if((! $record) || (! count($record))) { + if ((! $record) || (! count($record))) { logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG); header('WWW-Authenticate: Basic realm="Friendica"'); #header('HTTP/1.0 401 Unauthorized'); @@ -457,7 +457,7 @@ use \Friendica\Core\Config; logger("api_get_user: Fetching user data for user ".$contact_id, LOGGER_DEBUG); // Searching for contact URL - if(!is_null($contact_id) AND (intval($contact_id) == 0)){ + if (!is_null($contact_id) AND (intval($contact_id) == 0)){ $user = dbesc(normalise_link($contact_id)); $url = $user; $extra_query = "AND `contact`.`nurl` = '%s' "; @@ -465,7 +465,7 @@ use \Friendica\Core\Config; } // Searching for contact id with uid = 0 - if(!is_null($contact_id) AND (intval($contact_id) != 0)){ + if (!is_null($contact_id) AND (intval($contact_id) != 0)){ $user = dbesc(api_unique_id_to_url($contact_id)); if ($user == "") @@ -476,7 +476,7 @@ use \Friendica\Core\Config; if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user()); } - if(is_null($user) && x($_GET, 'user_id')) { + if (is_null($user) && x($_GET, 'user_id')) { $user = dbesc(api_unique_id_to_url($_GET['user_id'])); if ($user == "") @@ -486,7 +486,7 @@ use \Friendica\Core\Config; $extra_query = "AND `contact`.`nurl` = '%s' "; if (api_user()!==false) $extra_query .= "AND `contact`.`uid`=".intval(api_user()); } - if(is_null($user) && x($_GET, 'screen_name')) { + if (is_null($user) && x($_GET, 'screen_name')) { $user = dbesc($_GET['screen_name']); $nick = $user; $extra_query = "AND `contact`.`nick` = '%s' "; @@ -496,7 +496,7 @@ use \Friendica\Core\Config; if (is_null($user) AND ($a->argc > (count($called_api)-1)) AND (count($called_api) > 0)){ $argid = count($called_api); list($user, $null) = explode(".",$a->argv[$argid]); - if(is_numeric($user)){ + if (is_numeric($user)){ $user = dbesc(api_unique_id_to_url($user)); if ($user == "") @@ -593,7 +593,7 @@ use \Friendica\Core\Config; } } - if($uinfo[0]['self']) { + if ($uinfo[0]['self']) { if ($uinfo[0]['network'] == "") $uinfo[0]['network'] = NETWORK_DFRN; @@ -648,7 +648,7 @@ use \Friendica\Core\Config; $starred = $r[0]['count']; - if(! $uinfo[0]['self']) { + if (! $uinfo[0]['self']) { $countfriends = 0; $countfollowers = 0; $starred = 0; @@ -923,7 +923,7 @@ use \Friendica\Core\Config; $txt = requestdata('status'); //$txt = urldecode(requestdata('status')); - if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) { + if ((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) { $txt = html2bb_video($txt); $config = HTMLPurifier_Config::createDefault(); @@ -964,9 +964,9 @@ use \Friendica\Core\Config; // logger('api_post: ' . print_r($_POST,true)); - if(requestdata('htmlstatus')) { + if (requestdata('htmlstatus')) { $txt = requestdata('htmlstatus'); - if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) { + if ((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) { $txt = html2bb_video($txt); $config = HTMLPurifier_Config::createDefault(); @@ -989,16 +989,16 @@ use \Friendica\Core\Config; if ($parent == -1) $parent = ""; - if(ctype_digit($parent)) + if (ctype_digit($parent)) $_REQUEST['parent'] = $parent; else $_REQUEST['parent_uri'] = $parent; - if(requestdata('lat') && requestdata('long')) + if (requestdata('lat') && requestdata('long')) $_REQUEST['coord'] = sprintf("%s %s",requestdata('lat'),requestdata('long')); $_REQUEST['profile_uid'] = api_user(); - if($parent) + if ($parent) $_REQUEST['type'] = 'net-comment'; else { // Check for throttling (maximum posts per day, week and month) @@ -1066,11 +1066,11 @@ use \Friendica\Core\Config; $_REQUEST['type'] = 'wall'; } - if(x($_FILES,'media')) { + if (x($_FILES,'media')) { // upload the image if we have one $_REQUEST['hush']='yeah'; //tell wall_upload function to return img info instead of echo $media = wall_upload_post($a); - if(strlen($media)>0) + if (strlen($media)>0) $_REQUEST['body'] .= "\n\n".$media; } @@ -1115,13 +1115,13 @@ use \Friendica\Core\Config; $user_info = api_get_user($a); - if(!x($_FILES,'media')) { + if (!x($_FILES,'media')) { // Output error throw new BadRequestException("No media."); } $media = wall_upload_post($a, false); - if(!$media) { + if (!$media) { // Output error throw new InternalServerErrorException(); } @@ -2641,9 +2641,9 @@ use \Friendica\Core\Config; return false; } - if($qtype == 'friends') + if ($qtype == 'friends') $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND)); - if($qtype == 'followers') + if ($qtype == 'followers') $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND)); // friends and followers only for self @@ -2697,7 +2697,7 @@ use \Friendica\Core\Config; $closed = (($a->config['register_policy'] == REGISTER_CLOSED) ? 'true' : 'false'); $private = ((Config::get('system', 'block_public')) ? 'true' : 'false'); $textlimit = (string) (($a->config['max_import_size']) ? $a->config['max_import_size'] : 200000); - if($a->config['api_import_size']) + if ($a->config['api_import_size']) $texlimit = string($a->config['api_import_size']); $ssl = ((Config::get('system', 'have_ssl')) ? 'true' : 'false'); $sslserver = (($ssl === 'true') ? str_replace('http:','https:',App::get_baseurl()) : ''); @@ -2737,13 +2737,13 @@ use \Friendica\Core\Config; $a = get_app(); - if(! api_user()) throw new ForbiddenException(); + if (! api_user()) throw new ForbiddenException(); $user_info = api_get_user($a); - if($qtype == 'friends') + if ($qtype == 'friends') $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND)); - if($qtype == 'followers') + if ($qtype == 'followers') $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND)); if (!$user_info["self"]) @@ -2967,7 +2967,7 @@ use \Friendica\Core\Config; if ($user_id !="") { $sql_extra .= ' AND `mail`.`contact-id` = ' . intval($user_id); } - elseif($screen_name !=""){ + elseif ($screen_name !=""){ $sql_extra .= " AND `contact`.`nick` = '" . dbesc($screen_name). "'"; } @@ -2978,7 +2978,7 @@ use \Friendica\Core\Config; ); if ($verbose == "true") { // stop execution and return error message if no mails available - if($r == null) { + if ($r == null) { $answer = array('result' => 'error', 'message' => 'no mails available'); return api_format_data("direct_messages_all", $type, array('$result' => $answer)); } @@ -3092,7 +3092,7 @@ use \Friendica\Core\Config; function api_fr_photo_detail($type) { if (api_user()===false) throw new ForbiddenException(); - if(!x($_REQUEST,'photo_id')) throw new BadRequestException("No photo id."); + if (!x($_REQUEST,'photo_id')) throw new BadRequestException("No photo id."); $scale = (x($_REQUEST, 'scale') ? intval($_REQUEST['scale']) : false); $scale_sql = ($scale === false ? "" : sprintf("and scale=%d",intval($scale))); @@ -3183,11 +3183,11 @@ use \Friendica\Core\Config; $dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']); - if($r[0]['duplex'] && $r[0]['issued-id']) { + if ($r[0]['duplex'] && $r[0]['issued-id']) { $orig_id = $r[0]['issued-id']; $dfrn_id = '1:' . $orig_id; } - if($r[0]['duplex'] && $r[0]['dfrn-id']) { + if ($r[0]['duplex'] && $r[0]['dfrn-id']) { $orig_id = $r[0]['dfrn-id']; $dfrn_id = '0:' . $orig_id; } diff --git a/include/attach.php b/include/attach.php index 6b26b1ed6..3232f3e76 100644 --- a/include/attach.php +++ b/include/attach.php @@ -1061,7 +1061,7 @@ function z_mime_content_type($filename) { ); $dot = strpos($filename,'.'); - if($dot !== false) { + if ($dot !== false) { $ext = strtolower(substr($filename,$dot+1)); if (array_key_exists($ext, $mime_types)) { return $mime_types[$ext]; diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index e50999923..eaf418510 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -193,7 +193,7 @@ function unescape_underscores_in_links($m) { function format_event_diaspora($ev) { - if(! ((is_array($ev)) && count($ev))) + if (! ((is_array($ev)) && count($ev))) return ''; $bd_format = t('l F d, Y \@ g:i A') ; // Friday January 18, 2011 @ 8 AM @@ -209,7 +209,7 @@ function format_event_diaspora($ev) { $ev['start'] , $bd_format))) . '](' . App::get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['start'])) . ")\n"; - if(! $ev['nofinish']) + if (! $ev['nofinish']) $o .= t('Finishes:') . ' ' . '[' . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', $ev['finish'] , $bd_format )) @@ -217,7 +217,7 @@ function format_event_diaspora($ev) { $ev['finish'] , $bd_format ))) . '](' . App::get_baseurl() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['finish'])) . ")\n"; - if(strlen($ev['location'])) + if (strlen($ev['location'])) $o .= t('Location:') . bb2diaspora($ev['location']) . "\n"; diff --git a/include/bbcode.php b/include/bbcode.php index 489ef8b2e..46daaae93 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -214,21 +214,21 @@ function bb_unspacefy_and_trim($st) { function bb_find_open_close($s, $open, $close, $occurance = 1) { - if($occurance < 1) + if ($occurance < 1) $occurance = 1; $start_pos = -1; for($i = 1; $i <= $occurance; $i++) { - if( $start_pos !== false) + if ( $start_pos !== false) $start_pos = strpos($s, $open, $start_pos + 1); } - if( $start_pos === false) + if ( $start_pos === false) return false; $end_pos = strpos($s, $close, $start_pos); - if( $end_pos === false) + if ( $end_pos === false) return false; $res = array( 'start' => $start_pos, 'end' => $end_pos ); @@ -238,34 +238,34 @@ function bb_find_open_close($s, $open, $close, $occurance = 1) { function get_bb_tag_pos($s, $name, $occurance = 1) { - if($occurance < 1) + if ($occurance < 1) $occurance = 1; $start_open = -1; for($i = 1; $i <= $occurance; $i++) { - if( $start_open !== false) + if ( $start_open !== false) $start_open = strpos($s, '[' . $name, $start_open + 1); // allow [name= type tags } - if( $start_open === false) + if ( $start_open === false) return false; $start_equal = strpos($s, '=', $start_open); $start_close = strpos($s, ']', $start_open); - if( $start_close === false) + if ( $start_close === false) return false; $start_close++; $end_open = strpos($s, '[/' . $name . ']', $start_close); - if( $end_open === false) + if ( $end_open === false) return false; $res = array( 'start' => array('open' => $start_open, 'close' => $start_close), 'end' => array('open' => $end_open, 'close' => $end_open + strlen('[/' . $name . ']')) ); - if( $start_equal !== false) + if ( $start_equal !== false) $res['start']['equal'] = $start_equal + 1; return $res; @@ -277,12 +277,12 @@ function bb_tag_preg_replace($pattern, $replace, $name, $s) { $occurance = 1; $pos = get_bb_tag_pos($string, $name, $occurance); - while($pos !== false && $occurance < 1000) { + while ($pos !== false && $occurance < 1000) { $start = substr($string, 0, $pos['start']['open']); $subject = substr($string, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']); $end = substr($string, $pos['end']['close']); - if($end === false) + if ($end === false) $end = ''; $subject = preg_replace($pattern, $replace, $subject); @@ -295,7 +295,7 @@ function bb_tag_preg_replace($pattern, $replace, $name, $s) { return $string; } -if(! function_exists('bb_extract_images')) { +if (! function_exists('bb_extract_images')) { function bb_extract_images($body) { $saved_image = array(); @@ -306,12 +306,12 @@ function bb_extract_images($body) { $img_start = strpos($orig_body, '[img'); $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false); - while(($img_st_close !== false) && ($img_end !== false)) { + while (($img_st_close !== false) && ($img_end !== false)) { $img_st_close++; // make it point to AFTER the closing bracket $img_end += $img_start; - if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { + if (! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { // This is an embedded image $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close)); @@ -324,7 +324,7 @@ function bb_extract_images($body) { $orig_body = substr($orig_body, $img_end + strlen('[/img]')); - if($orig_body === false) // in case the body ends on a closing image tag + if ($orig_body === false) // in case the body ends on a closing image tag $orig_body = ''; $img_start = strpos($orig_body, '[img'); @@ -337,7 +337,7 @@ function bb_extract_images($body) { return array('body' => $new_body, 'images' => $saved_image); }} -if(! function_exists('bb_replace_images')) { +if (! function_exists('bb_replace_images')) { function bb_replace_images($body, $images) { $newbody = $body; @@ -619,7 +619,7 @@ function bb_DiasporaLinks($match) { function bb_RemovePictureLinks($match) { $text = Cache::get($match[1]); - if(is_null($text)){ + if (is_null($text)){ $a = get_app(); $stamp1 = microtime(true); @@ -673,7 +673,7 @@ function bb_expand_links($match) { function bb_CleanPictureLinksSub($match) { $text = Cache::get($match[1]); - if(is_null($text)){ + if (is_null($text)){ $a = get_app(); $stamp1 = microtime(true); @@ -724,7 +724,7 @@ function bb_CleanPictureLinks($text) { } function bb_highlight($match) { - if(in_array(strtolower($match[1]),['php','css','mysql','sql','abap','diff','html','perl','ruby', + if (in_array(strtolower($match[1]),['php','css','mysql','sql','abap','diff','html','perl','ruby', 'vbscript','avrc','dtd','java','xml','cpp','python','javascript','js','sh'])) return text_highlight($match[2],strtolower($match[1])); return $match[0]; @@ -814,7 +814,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal $Text = str_replace(array("\r","\n"), array('
','
'), $Text); - if($preserve_nl) + if ($preserve_nl) $Text = str_replace(array("\n","\r"), array('',''),$Text); // Set up the parameters for a URL search string @@ -1132,7 +1132,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal // Summary (e.g. title) is required, earlier revisions only required description (in addition to // start which is always required). Allow desc with a missing summary for compatibility. - if((x($ev,'desc') || x($ev,'summary')) && x($ev,'start')) { + if ((x($ev,'desc') || x($ev,'summary')) && x($ev,'start')) { $sub = format_event_html($ev, $simplehtml); $Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$Text); @@ -1178,7 +1178,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal $regex = '#<([^>]*?)(href)="(?!' . implode('|', $allowed_link_protocols) . ')(.*?)"(.*?)>#ism'; $Text = preg_replace($regex, '<$1$2="javascript:void(0)"$4 class="invalid-href" title="' . t('Invalid link protocol') . '">', $Text); - if($saved_image) { + if ($saved_image) { $Text = bb_replace_images($Text, $saved_image); } diff --git a/include/cli_startup.php b/include/cli_startup.php index 4b66b47a0..557d08c28 100644 --- a/include/cli_startup.php +++ b/include/cli_startup.php @@ -19,7 +19,7 @@ function cli_startup() { require_once("dba.php"); $db = new dba($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); - }; + }; require_once('include/session.php'); diff --git a/include/contact_widgets.php b/include/contact_widgets.php index d077a065e..0f6f46ef6 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -17,9 +17,9 @@ function findpeople_widget() { $a = get_app(); - if(get_config('system','invitation_only')) { + if (get_config('system','invitation_only')) { $x = get_pconfig(local_user(),'system','invites_remaining'); - if($x || is_site_admin()) { + if ($x || is_site_admin()) { $a->page['aside'] .= '' . $inv; @@ -108,7 +108,7 @@ function networks_widget($baseurl,$selected = '') { } } - if(count($nets) < 2) + if (count($nets) < 2) return ''; return replace_macros(get_markup_template('nets.tpl'),array( @@ -173,7 +173,7 @@ function categories_widget($baseurl,$selected = '') { $matches = false; $terms = array(); $cnt = preg_match_all('/<(.*?)>/',$saved,$matches,PREG_SET_ORDER); - if($cnt) { + if ($cnt) { foreach($matches as $mtch) { $unescaped = xmlify(file_tag_decode($mtch[1])); $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : '')); @@ -195,29 +195,29 @@ function common_friends_visitor_widget($profile_uid) { $a = get_app(); - if(local_user() == $profile_uid) + if (local_user() == $profile_uid) return; $cid = $zcid = 0; - if(is_array($_SESSION['remote'])) { + if (is_array($_SESSION['remote'])) { foreach($_SESSION['remote'] as $visitor) { - if($visitor['uid'] == $profile_uid) { + if ($visitor['uid'] == $profile_uid) { $cid = $visitor['cid']; break; } } } - if(! $cid) { - if(get_my_url()) { + if (! $cid) { + if (get_my_url()) { $r = q("select id from contact where nurl = '%s' and uid = %d limit 1", dbesc(normalise_link(get_my_url())), intval($profile_uid) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $cid = $r[0]['id']; - else { + } else { $r = q("select id from gcontact where nurl = '%s' limit 1", 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; + } require_once('include/socgraph.php'); - if($cid) + if ($cid) { $t = count_common_friends($profile_uid,$cid); - else + } else { $t = count_common_friends_zcid($profile_uid,$zcid); - if(! $t) + } + if (! $t) { return; + } - if($cid) + if ($cid) { $r = common_friends($profile_uid,$cid,0,5,true); - else + } else { $r = common_friends_zcid($profile_uid,$zcid,0,5,true); + } return replace_macros(get_markup_template('remote_friends_common.tpl'), array( '$desc' => sprintf( tt("%d contact in common", "%d contacts in common", $t), $t), diff --git a/include/conversation.php b/include/conversation.php index 93c42cd7b..424f60bb4 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -7,7 +7,7 @@ require_once("include/acl_selectors.php"); // Note: the code in 'item_extract_images' and 'item_redir_and_replace_images' // is identical to the code in mod/message.php for 'item_extract_images' and // 'item_redir_and_replace_images' -if(! function_exists('item_extract_images')) { +if (! function_exists('item_extract_images')) { function item_extract_images($body) { $saved_image = array(); @@ -18,12 +18,12 @@ function item_extract_images($body) { $img_start = strpos($orig_body, '[img'); $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false); - while(($img_st_close !== false) && ($img_end !== false)) { + while (($img_st_close !== false) && ($img_end !== false)) { $img_st_close++; // make it point to AFTER the closing bracket $img_end += $img_start; - if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { + if (! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { // This is an embedded image $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close)); @@ -36,7 +36,7 @@ function item_extract_images($body) { $orig_body = substr($orig_body, $img_end + strlen('[/img]')); - if($orig_body === false) // in case the body ends on a closing image tag + if ($orig_body === false) // in case the body ends on a closing image tag $orig_body = ''; $img_start = strpos($orig_body, '[img'); @@ -49,7 +49,7 @@ function item_extract_images($body) { return array('body' => $new_body, 'images' => $saved_image); }} -if(! function_exists('item_redir_and_replace_images')) { +if (! function_exists('item_redir_and_replace_images')) { function item_redir_and_replace_images($body, $images, $cid) { $origbody = $body; @@ -57,7 +57,7 @@ function item_redir_and_replace_images($body, $images, $cid) { $cnt = 1; $pos = get_bb_tag_pos($origbody, 'url', 1); - while($pos !== false && $cnt < 1000) { + while ($pos !== false && $cnt < 1000) { $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is'; $replace = '[url=' . z_path() . '/redir/' . $cid @@ -66,7 +66,7 @@ function item_redir_and_replace_images($body, $images, $cid) { $newbody .= substr($origbody, 0, $pos['start']['open']); $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']); $origbody = substr($origbody, $pos['end']['close']); - if($origbody === false) + if ($origbody === false) $origbody = ''; $subject = preg_replace($search, $replace, $subject); @@ -96,7 +96,7 @@ function item_redir_and_replace_images($body, $images, $cid) { function localize_item(&$item){ $extracted = item_extract_images($item['body']); - if($extracted['images']) + if ($extracted['images']) $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']); $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; @@ -126,7 +126,7 @@ function localize_item(&$item){ } break; default: - if($obj['resource-id']){ + if ($obj['resource-id']){ $post_type = t('photo'); $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m); $rr['plink'] = $m[1]; @@ -137,19 +137,19 @@ function localize_item(&$item){ $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]'; - if(activity_match($item['verb'],ACTIVITY_LIKE)) { + if (activity_match($item['verb'],ACTIVITY_LIKE)) { $bodyverb = t('%1$s likes %2$s\'s %3$s'); } - elseif(activity_match($item['verb'],ACTIVITY_DISLIKE)) { + elseif (activity_match($item['verb'],ACTIVITY_DISLIKE)) { $bodyverb = 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 = t('%1$s attends %2$s\'s %3$s'); } - elseif(activity_match($item['verb'],ACTIVITY_ATTENDNO)) { + elseif (activity_match($item['verb'],ACTIVITY_ATTENDNO)) { $bodyverb = 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 = t('%1$s attends maybe %2$s\'s %3$s'); } $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink); @@ -187,7 +187,7 @@ function localize_item(&$item){ } if (stristr($item['verb'],ACTIVITY_POKE)) { $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1)); - if(! $verb) + if (! $verb) return; if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return; @@ -229,7 +229,7 @@ function localize_item(&$item){ } if (stristr($item['verb'],ACTIVITY_MOOD)) { $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1)); - if(! $verb) + if (! $verb) return; $Aname = $item['author-name']; @@ -262,7 +262,7 @@ function localize_item(&$item){ } break; default: - if($obj['resource-id']){ + if ($obj['resource-id']){ $post_type = t('photo'); $m=array(); preg_match("/\[url=([^]]*)\]/", $obj['body'], $m); $rr['plink'] = $m[1]; @@ -289,7 +289,7 @@ function localize_item(&$item){ $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; $obj = parse_xml_string($xmlhead.$item['object']); - if(strlen($obj->id)) { + if (strlen($obj->id)) { $r = q("select * from item where uri = '%s' and uid = %d limit 1", dbesc($obj->id), intval($item['uid']) @@ -307,16 +307,16 @@ function localize_item(&$item){ } } $matches = null; - if(preg_match_all('/@\[url=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) { + if (preg_match_all('/@\[url=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) { foreach($matches as $mtch) { - if(! strpos($mtch[1],'zrl=')) + if (! strpos($mtch[1],'zrl=')) $item['body'] = str_replace($mtch[0],'@[url=' . zrl($mtch[1]). ']',$item['body']); } } // add zrl's to public images $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is"; - if(preg_match($photo_pattern,$item['body'])) { + if (preg_match($photo_pattern,$item['body'])) { $photo_replace = '[url=' . zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]'; $item['body'] = bb_tag_preg_replace($photo_pattern, $photo_replace, 'url', $item['body']); } @@ -343,9 +343,9 @@ function localize_item(&$item){ function count_descendants($item) { $total = count($item['children']); - if($total > 0) { + if ($total > 0) { foreach($item['children'] as $child) { - if(! visible_activity($child)) + if (! visible_activity($child)) $total --; $total += count_descendants($child); } @@ -361,13 +361,13 @@ function visible_activity($item) { $hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE); foreach($hidden_activities as $act) { - if(activity_match($item['verb'],$act)) { + if (activity_match($item['verb'],$act)) { return false; } } - if(activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) { - if(! (($item['self']) && ($item['uid'] == local_user()))) { + if (activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) { + if (! (($item['self']) && ($item['uid'] == local_user()))) { return false; } } @@ -465,7 +465,7 @@ function item_condition() { * */ -if(!function_exists('conversation')) { +if (!function_exists('conversation')) { function conversation(App $a, $items, $mode, $update, $preview = false) { require_once('include/bbcode.php'); @@ -480,9 +480,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $arr_blocked = null; - if(local_user()) { + if (local_user()) { $str_blocked = get_pconfig(local_user(),'system','blocked'); - if($str_blocked) { + if ($str_blocked) { $arr_blocked = explode(',',$str_blocked); for($x = 0; $x < count($arr_blocked); $x ++) $arr_blocked[$x] = trim($arr_blocked[$x]); @@ -492,10 +492,10 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $previewing = (($preview) ? ' preview ' : ''); - if($mode === 'network') { + if ($mode === 'network') { $profile_owner = local_user(); $page_writeable = true; - if(!$update) { + if (!$update) { // The special div is needed for liveUpdate to kick in for this page. // We only launch liveUpdate if you aren't filtering in some incompatible // way and also you aren't writing a comment (discovered in javascript). @@ -520,14 +520,14 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { . "'; var profile_page = " . $a->pager['page'] . "; \r\n"; } } - else if($mode === 'profile') { + else if ($mode === 'profile') { $profile_owner = $a->profile['profile_uid']; $page_writeable = can_write_wall($a,$profile_owner); - if(!$update) { + if (!$update) { $tab = notags(trim($_GET['tab'])); $tab = ( $tab ? $tab : 'posts' ); - if($tab === 'posts') { + if ($tab === 'posts') { // This is ugly, but we can't pass the profile_uid through the session to the ajax updater, // because browser prefetching might change it on us. We have to deliver it with the page. @@ -537,40 +537,40 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { } } } - else if($mode === 'notes') { + else if ($mode === 'notes') { $profile_owner = local_user(); $page_writeable = true; - if(!$update) { + if (!$update) { $live_update_div = '
' . "\r\n" . "\r\n"; } } - else if($mode === 'display') { + else if ($mode === 'display') { $profile_owner = $a->profile['uid']; $page_writeable = can_write_wall($a,$profile_owner); - if(!$update) { + if (!$update) { $live_update_div = '
' . "\r\n" . ""; } } - else if($mode === 'community') { + else if ($mode === 'community') { $profile_owner = 0; $page_writeable = false; - if(!$update) { + if (!$update) { $live_update_div = '
' . "\r\n" . "\r\n"; } } - else if($mode === 'search') { + else if ($mode === 'search') { $live_update_div = '' . "\r\n"; } $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false); - if($update) + if ($update) $return_url = $_SESSION['return_url']; else $return_url = $_SESSION['return_url'] = $a->query_string; @@ -594,9 +594,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $page_template = get_markup_template("conversation.tpl"); - if($items && count($items)) { + if ($items && count($items)) { - if($mode === 'network-new' || $mode === 'search' || $mode === 'community') { + if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') { // "New Item View" on network page or search page results // - just loop through the items and format them minimally for display @@ -606,15 +606,15 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { foreach($items as $item) { - if($arr_blocked) { + if ($arr_blocked) { $blocked = false; foreach($arr_blocked as $b) { - if($b && link_compare($item['author-link'],$b)) { + if ($b && link_compare($item['author-link'],$b)) { $blocked = true; break; } } - if($blocked) + if ($blocked) continue; } @@ -626,8 +626,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $owner_name = ''; $sparkle = ''; - if($mode === 'search' || $mode === 'community') { - if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) + if ($mode === 'search' || $mode === 'community') { + if (((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent'])) continue; $nickname = $item['nickname']; @@ -636,11 +636,11 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $nickname = $a->user['nickname']; // prevent private email from leaking. - if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) + if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) continue; $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']); - if($item['author-link'] && (! $item['author-name'])) + if ($item['author-link'] && (! $item['author-name'])) $profile_name = $item['author-link']; @@ -669,9 +669,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $sp = false; $profile_link = best_link_url($item,$sp); - if($profile_link === 'mailbox') + if ($profile_link === 'mailbox') $profile_link = ''; - if($sp) + if ($sp) $sparkle = ' sparkle'; else $profile_link = zrl($profile_link); @@ -698,7 +698,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate)); localize_item($item); - if($mode === 'network-new') + if ($mode === 'network-new') $dropping = true; else $dropping = false; @@ -723,7 +723,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { list($categories, $folders) = get_cats_and_terms($item); - if($a->theme['template_engine'] === 'internal') { + if ($a->theme['template_engine'] === 'internal') { $profile_name_e = template_escape($profile_name); $item['title_e'] = template_escape($item['title']); $body_e = template_escape($body); @@ -820,16 +820,16 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $threads = array(); foreach($items as $item) { - if($arr_blocked) { + if ($arr_blocked) { $blocked = false; foreach($arr_blocked as $b) { - if($b && link_compare($item['author-link'],$b)) { + if ($b && link_compare($item['author-link'],$b)) { $blocked = true; break; } } - if($blocked) + if ($blocked) continue; } @@ -839,10 +839,10 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { builtin_activity_puller($item, $conv_responses); // Only add what is visible - if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { + if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { continue; } - if(! visible_activity($item)) { + if (! visible_activity($item)) { continue; } @@ -850,7 +850,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $item['pagedrop'] = $page_dropping; - if($item['id'] == $item['parent']) { + if ($item['id'] == $item['parent']) { $item_object = new Item($item); $conv->add_thread($item_object); } @@ -858,7 +858,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $threads = $conv->get_template_data($conv_responses); - if(!$threads) { + if (!$threads) { logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG); $threads = array(); } @@ -894,8 +894,8 @@ function best_link_url($item,&$sparkle,$ssl_state = false) { $sparkle = true; } } - if(! $best_url) { - if(strlen($item['author-link'])) + if (! $best_url) { + if (strlen($item['author-link'])) $best_url = $item['author-link']; else $best_url = $item['url']; @@ -910,7 +910,7 @@ function item_photo_menu($item) { $ssl_state = false; - if(local_user()) { + if (local_user()) { $ssl_state = true; } @@ -944,7 +944,7 @@ function item_photo_menu($item) $rel = $r[0]['rel']; } - if($sparkle) { + if ($sparkle) { $status_link = $profile_link . '?url=status'; $photos_link = $profile_link . '?url=photos'; $profile_link = $profile_link . '?url=profile'; @@ -1012,7 +1012,7 @@ function item_photo_menu($item) * @param array &$conv_responses (already created with builtin activity structure) * @return void */ -if(! function_exists('builtin_activity_puller')) { +if (! function_exists('builtin_activity_puller')) { function builtin_activity_puller($item, &$conv_responses) { foreach($conv_responses as $mode => $v) { $url = ''; @@ -1039,9 +1039,9 @@ function builtin_activity_puller($item, &$conv_responses) { break; } - if((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) { + if ((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) { $url = $item['author-link']; - if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) { + if ((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) { $url = 'redir/' . $item['contact-id']; $sparkle = ' class="sparkle" '; } @@ -1050,18 +1050,18 @@ function builtin_activity_puller($item, &$conv_responses) { $url = '' . htmlentities($item['author-name']) . ''; - if(! $item['thr-parent']) + if (! $item['thr-parent']) $item['thr-parent'] = $item['parent-uri']; - if(! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l'])) + if (! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l'])) && (is_array($conv_responses[$mode][$item['thr-parent'] . '-l'])))) $conv_responses[$mode][$item['thr-parent'] . '-l'] = array(); // only list each unique author once - if(in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) + if (in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) continue; - if(! isset($conv_responses[$mode][$item['thr-parent']])) + if (! isset($conv_responses[$mode][$item['thr-parent']])) $conv_responses[$mode][$item['thr-parent']] = 1; else $conv_responses[$mode][$item['thr-parent']] ++; @@ -1085,12 +1085,12 @@ function builtin_activity_puller($item, &$conv_responses) { // $id = item id // returns formatted text -if(! function_exists('format_like')) { +if (! function_exists('format_like')) { function format_like($cnt,$arr,$type,$id) { $o = ''; $expanded = ''; - if($cnt == 1) { + if ($cnt == 1) { $likers = $arr[0]; // Phrase if there is only one liker. In other cases it will be uses for the expanded @@ -1114,16 +1114,16 @@ function format_like($cnt,$arr,$type,$id) { } } - if($cnt > 1) { + if ($cnt > 1) { $total = count($arr); - if($total >= MAX_LIKERS) + if ($total >= MAX_LIKERS) $arr = array_slice($arr, 0, MAX_LIKERS - 1); - if($total < MAX_LIKERS) { + if ($total < MAX_LIKERS) { $last = t('and') . ' ' . $arr[count($arr)-1]; $arr2 = array_slice($arr, 0, -1); $str = implode(', ', $arr2) . ' ' . $last; } - if($total >= MAX_LIKERS) { + if ($total >= MAX_LIKERS) { $str = implode(', ', $arr); $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS ); } @@ -1211,17 +1211,17 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) { // Private/public post links for the non-JS ACL form $private_post = 1; - if($_REQUEST['public']) + if ($_REQUEST['public']) $private_post = 0; $query_str = $a->query_string; - if(strpos($query_str, 'public=1') !== false) + if (strpos($query_str, 'public=1') !== false) $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str); // I think $a->query_string may never have ? in it, but I could be wrong // It looks like it's from the index.php?q=[etc] rewrite that the web // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61 - if(strpos($query_str, '?') === false) + if (strpos($query_str, '?') === false) $public_post_link = '?public=1'; else $public_post_link = '&public=1'; @@ -1303,19 +1303,19 @@ function get_item_children($arr, $parent) { $children = array(); $a = get_app(); foreach($arr as $item) { - if($item['id'] != $item['parent']) { - if(get_config('system','thread_allow') && $a->theme_thread_allow) { + if ($item['id'] != $item['parent']) { + if (get_config('system','thread_allow') && $a->theme_thread_allow) { // Fallback to parent-uri if thr-parent is not set $thr_parent = $item['thr-parent']; - if($thr_parent == '') + if ($thr_parent == '') $thr_parent = $item['parent-uri']; - if($thr_parent == $parent['uri']) { + if ($thr_parent == $parent['uri']) { $item['children'] = get_item_children($arr, $item); $children[] = $item; } } - else if($item['parent'] == $parent['id']) { + else if ($item['parent'] == $parent['id']) { $children[] = $item; } } @@ -1327,7 +1327,7 @@ function sort_item_children($items) { $result = $items; usort($result,'sort_thr_created_rev'); foreach($result as $k => $i) { - if(count($result[$k]['children'])) { + if (count($result[$k]['children'])) { $result[$k]['children'] = sort_item_children($result[$k]['children']); } } @@ -1337,14 +1337,14 @@ function sort_item_children($items) { function add_children_to_list($children, &$arr) { foreach($children as $y) { $arr[] = $y; - if(count($y['children'])) + if (count($y['children'])) add_children_to_list($y['children'], $arr); } } function conv_sort($arr,$order) { - if((!(is_array($arr) && count($arr)))) + if ((!(is_array($arr) && count($arr)))) return array(); $parents = array(); @@ -1360,28 +1360,28 @@ function conv_sort($arr,$order) { $arr = $newarr; foreach($arr as $x) - if($x['id'] == $x['parent']) + if ($x['id'] == $x['parent']) $parents[] = $x; - if(stristr($order,'created')) + if (stristr($order,'created')) usort($parents,'sort_thr_created'); - elseif(stristr($order,'commented')) + elseif (stristr($order,'commented')) usort($parents,'sort_thr_commented'); - if(count($parents)) + if (count($parents)) foreach($parents as $i=>$_x) $parents[$i]['children'] = get_item_children($arr, $_x); /*foreach($arr as $x) { - if($x['id'] != $x['parent']) { + if ($x['id'] != $x['parent']) { $p = find_thread_parent_index($parents,$x); - if($p !== false) + if ($p !== false) $parents[$p]['children'][] = $x; } }*/ - if(count($parents)) { + if (count($parents)) { foreach($parents as $k => $v) { - if(count($parents[$k]['children'])) { + if (count($parents[$k]['children'])) { $parents[$k]['children'] = sort_item_children($parents[$k]['children']); /*$y = $parents[$k]['children']; usort($y,'sort_thr_created_rev'); @@ -1391,10 +1391,10 @@ function conv_sort($arr,$order) { } $ret = array(); - if(count($parents)) { + if (count($parents)) { foreach($parents as $x) { $ret[] = $x; - if(count($x['children'])) + if (count($x['children'])) add_children_to_list($x['children'], $ret); /*foreach($x['children'] as $y) $ret[] = $y;*/ @@ -1418,9 +1418,11 @@ function sort_thr_commented($a,$b) { } function find_thread_parent_index($arr,$x) { - foreach($arr as $k => $v) - if($v['id'] == $x['parent']) + foreach($arr as $k => $v) { + if ($v['id'] == $x['parent']) { return $k; + } + } return false; } @@ -1439,12 +1441,11 @@ function get_responses($conv_responses,$response_verbs,$ob,$item) { $ret[$v]['count'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri']] : ''); $ret[$v]['list'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri'] . '-l'] : ''); $ret[$v]['self'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri'] . '-self'] : '0'); - if(count($ret[$v]['list']) > MAX_LIKERS) { + if (count($ret[$v]['list']) > MAX_LIKERS) { $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS); array_push($ret[$v]['list_part'], '' . t('View all') . ''); - } - else { + } else { $ret[$v]['list_part'] = ''; } $ret[$v]['button'] = get_response_button_text($v,$ret[$v]['count']); diff --git a/include/cron.php b/include/cron.php index 059c19992..552121746 100644 --- a/include/cron.php +++ b/include/cron.php @@ -19,12 +19,12 @@ function cron_run(&$argv, &$argc){ $last = get_config('system','last_cron'); $poll_interval = intval(get_config('system','cron_interval')); - if(! $poll_interval) + if (! $poll_interval) $poll_interval = 10; - if($last) { + if ($last) { $next = $last + ($poll_interval * 60); - if($next > time()) { + if ($next > time()) { logger('cron intervall not reached'); return; } @@ -64,7 +64,7 @@ function cron_run(&$argv, &$argc){ $d1 = get_config('system','last_expire_day'); $d2 = intval(datetime_convert('UTC','UTC','now','d')); - if($d2 != intval($d1)) { + if ($d2 != intval($d1)) { update_contact_birthdays(); @@ -171,7 +171,7 @@ function cron_poll_contacts($argc, $argv) { // we are unable to match those posts with a Diaspora GUID and prevent duplicates. $abandon_days = intval(get_config('system','account_abandon_days')); - if($abandon_days < 1) + if ($abandon_days < 1) $abandon_days = 0; $abandon_sql = (($abandon_days) @@ -214,13 +214,13 @@ function cron_poll_contacts($argc, $argv) { $xml = false; - if($manual_id) + if ($manual_id) $contact['last-update'] = '0000-00-00 00:00:00'; - if(in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) + if (in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) $contact['priority'] = 2; - if($contact['subhub'] AND in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) { + if ($contact['subhub'] AND in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) { // We should be getting everything via a hub. But just to be sure, let's check once a day. // (You can make this more or less frequent if desired by setting 'pushpoll_frequency' appropriately) // This also lets us update our subscription to the hub, and add or replace hubs in case it @@ -230,7 +230,7 @@ function cron_poll_contacts($argc, $argv) { $contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3); } - if($contact['priority'] AND !$force) { + if ($contact['priority'] AND !$force) { $update = false; @@ -242,24 +242,24 @@ function cron_poll_contacts($argc, $argv) { switch ($contact['priority']) { case 5: - if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 month")) + if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 month")) $update = true; break; case 4: - if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 week")) + if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 week")) $update = true; break; case 3: - if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) + if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) $update = true; break; case 2: - if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 12 hour")) + if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 12 hour")) $update = true; break; case 1: default: - if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 hour")) + if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 hour")) $update = true; break; } @@ -287,14 +287,16 @@ function cron_clear_cache(App $a) { $last = get_config('system','cache_last_cleared'); - if($last) { + if ($last) { $next = $last + (3600); // Once per hour $clear_cache = ($next <= time()); - } else + } else { $clear_cache = true; + } - if (!$clear_cache) + if (!$clear_cache) { return; + } // clear old cache Cache::clear(); @@ -313,7 +315,9 @@ function cron_clear_cache(App $a) { clear_cache($a->get_basepath(), $a->get_basepath()."/proxy"); $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); } @@ -326,26 +330,30 @@ function cron_clear_cache(App $a) { // Maximum table size in megabyte $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 + } if ($max_tablesize > 0) { // Minimum fragmentation level in percent $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% + } // Optimize some tables that need to be optimized $r = q("SHOW TABLE STATUS"); foreach($r as $table) { // Don't optimize tables that are too large - if ($table["Data_length"] > $max_tablesize) + if ($table["Data_length"] > $max_tablesize) { continue; + } // Don't optimize empty tables - if ($table["Data_length"] == 0) + if ($table["Data_length"] == 0) { continue; + } // Calculate fragmentation $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); // Don't optimize tables that needn't to be optimized - if ($fragmentation < $fragmentation_level) + if ($fragmentation < $fragmentation_level) { continue; + } // So optimize it logger("Optimize Table ".$table["Name"], LOGGER_DEBUG); @@ -414,9 +423,11 @@ function cron_repair_database() { // 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`"); - if (dbm::is_result($r)) - foreach ($r AS $user) + if (dbm::is_result($r)) { + foreach ($r AS $user) { update_gcontact_for_user($user["uid"]); + } + } /// @todo /// - remove thread entries without item diff --git a/include/cronhooks.php b/include/cronhooks.php index bea0f6a19..349cac4f4 100644 --- a/include/cronhooks.php +++ b/include/cronhooks.php @@ -8,23 +8,25 @@ function cronhooks_run(&$argv, &$argc){ require_once('include/datetime.php'); 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]) { logger("Calling cron hook '".$hook[1]."'", LOGGER_DEBUG); call_single_hook($a, $name, $hook, $data); } + } return; } $last = get_config('system', 'last_cronhook'); $poll_interval = intval(get_config('system','cronhook_interval')); - if(! $poll_interval) + if (! $poll_interval) { $poll_interval = 9; + } - if($last) { + if ($last) { $next = $last + ($poll_interval * 60); - if($next > time()) { + if ($next > time()) { logger('cronhook intervall not reached'); return; } diff --git a/include/crypto.php b/include/crypto.php index f5163a9da..5eb0bc6e1 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -12,7 +12,7 @@ function rsa_sign($data,$key,$alg = 'sha256') { openssl_sign($data,$sig,$key,(($alg == 'sha1') ? OPENSSL_ALGO_SHA1 : $alg)); } else { - if(strlen($key) < 1024 || extension_loaded('gmp')) { + if (strlen($key) < 1024 || extension_loaded('gmp')) { require_once('library/phpsec/Crypt/RSA.php'); $rsa = new CRYPT_RSA(); $rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1; @@ -34,7 +34,7 @@ function rsa_verify($data,$sig,$key,$alg = 'sha256') { $verify = openssl_verify($data,$sig,$key,(($alg == 'sha1') ? OPENSSL_ALGO_SHA1 : $alg)); } else { - if(strlen($key) <= 300 || extension_loaded('gmp')) { + if (strlen($key) <= 300 || extension_loaded('gmp')) { require_once('library/phpsec/Crypt/RSA.php'); $rsa = new CRYPT_RSA(); $rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1; @@ -186,7 +186,7 @@ function salmon_key($pubkey) { -if(! function_exists('aes_decrypt')) { +if (! function_exists('aes_decrypt')) { // DEPRECATED IN 3.4.1 function aes_decrypt($val,$ky) { @@ -200,7 +200,7 @@ function aes_decrypt($val,$ky) }} -if(! function_exists('aes_encrypt')) { +if (! function_exists('aes_encrypt')) { // DEPRECATED IN 3.4.1 function aes_encrypt($val,$ky) { @@ -237,12 +237,12 @@ function new_keypair($bits) { ); $conf = get_config('system','openssl_conf_file'); - if($conf) + if ($conf) $openssl_options['config'] = $conf; $result = openssl_pkey_new($openssl_options); - if(empty($result)) { + if (empty($result)) { logger('new_keypair: failed'); return false; } diff --git a/include/datetime.php b/include/datetime.php index 8d4961cd7..d4e902711 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -14,12 +14,12 @@ use \Friendica\Core\Config; * @return int */ function timezone_cmp($a, $b) { - if(strstr($a,'/') && strstr($b,'/')) { + if (strstr($a,'/') && strstr($b,'/')) { if ( t($a) == t($b)) return 0; return ( t($a) < t($b)) ? -1 : 1; } - if(strstr($a,'/')) return -1; - if(strstr($b,'/')) return 1; + if (strstr($a,'/')) return -1; + if (strstr($b,'/')) return 1; if ( t($a) == t($b)) return 0; return ( t($a) < t($b)) ? -1 : 1; @@ -41,21 +41,21 @@ function select_timezone($current = 'America/Los_Angeles') { $continent = ''; foreach($timezone_identifiers as $value) { $ex = explode("/", $value); - if(count($ex) > 1) { - if($ex[0] != $continent) { - if($continent != '') + if (count($ex) > 1) { + if ($ex[0] != $continent) { + if ($continent != '') $o .= ''; $continent = $ex[0]; $o .= ''; } - if(count($ex) > 2) + if (count($ex) > 2) $city = substr($value,strpos($value,'/')+1); else $city = $ex[1]; } else { $city = $ex[0]; - if($continent != t('Miscellaneous')) { + if ($continent != t('Miscellaneous')) { $o .= ''; $continent = t('Miscellaneous'); $o .= ''; @@ -114,11 +114,11 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d // Defaults to UTC if nothing is set, but throws an exception if set to empty string. // Provide some sane defaults regardless. - if($from === '') + if ($from === '') $from = 'UTC'; - if($to === '') + if ($to === '') $to = 'UTC'; - if( ($s === '') || (! is_string($s)) ) + if ( ($s === '') || (! is_string($s)) ) $s = 'now'; // Slight hackish adjustment so that 'zero' datetime actually returns what is intended @@ -126,7 +126,7 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d // add 32 days so that we at least get year 00, and then hack around the fact that // months and days always start with 1. - if(substr($s,0,10) == '0000-00-00') { + if (substr($s,0,10) == '0000-00-00') { $d = new DateTime($s . ' + 32 days', new DateTimeZone('UTC')); return str_replace('1','0',$d->format($fmt)); } @@ -169,9 +169,9 @@ function dob($dob) { list($year,$month,$day) = sscanf($dob,'%4d-%2d-%2d'); $f = get_config('system','birthday_input_format'); - if(! $f) + if (! $f) $f = 'ymd'; - if($dob === '0000-00-00') + if ($dob === '0000-00-00') $value = ''; else $value = (($year) ? datetime_convert('UTC','UTC',$dob,'Y-m-d') : datetime_convert('UTC','UTC',$dob,'m-d')); @@ -279,9 +279,9 @@ function datetimesel($format, $min, $max, $default, $label, $id = 'datetimepicke $o = ''; $dateformat = ''; - if($pickdate) $dateformat .= 'Y-m-d'; - if($pickdate && $picktime) $dateformat .= ' '; - if($picktime) $dateformat .= 'H:i'; + if ($pickdate) $dateformat .= 'Y-m-d'; + if ($pickdate && $picktime) $dateformat .= ' '; + if ($picktime) $dateformat .= 'H:i'; $minjs = $min ? ",minDate: new Date({$min->getTimestamp()}*1000), yearStart: " . $min->format('Y') : ''; $maxjs = $max ? ",maxDate: new Date({$max->getTimestamp()}*1000), yearEnd: " . $max->format('Y') : ''; @@ -290,14 +290,14 @@ function datetimesel($format, $min, $max, $default, $label, $id = 'datetimepicke $defaultdatejs = $default ? ",defaultDate: new Date({$default->getTimestamp()}*1000)" : ''; $pickers = ''; - if(!$pickdate) $pickers .= ',datepicker: false'; - if(!$picktime) $pickers .= ',timepicker: false'; + if (!$pickdate) $pickers .= ',datepicker: false'; + if (!$picktime) $pickers .= ',timepicker: false'; $extra_js = ''; $pickers .= ",dayOfWeekStart: ".$firstDay.",lang:'".$lang."'"; - if($minfrom != '') + if ($minfrom != '') $extra_js .= "\$('#id_$minfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#id_$id').data('xdsoft_datetimepicker').setOptions({minDate: currentDateTime})}})"; - if($maxfrom != '') + if ($maxfrom != '') $extra_js .= "\$('#id_$maxfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#id_$id').data('xdsoft_datetimepicker').setOptions({maxDate: currentDateTime})}})"; $readable_format = $dateformat; @@ -394,11 +394,11 @@ function relative_date($posted_date, $format = null) { * @return int Age in years */ function age($dob,$owner_tz = '',$viewer_tz = '') { - if(! intval($dob)) + if (! intval($dob)) return 0; - if(! $owner_tz) + if (! $owner_tz) $owner_tz = date_default_timezone_get(); - if(! $viewer_tz) + if (! $viewer_tz) $viewer_tz = date_default_timezone_get(); $birthdate = datetime_convert('UTC',$owner_tz,$dob . ' 00:00:00+00:00','Y-m-d'); @@ -407,7 +407,7 @@ function age($dob,$owner_tz = '',$viewer_tz = '') { $curr_month = datetime_convert('UTC',$viewer_tz,'now','m'); $curr_day = datetime_convert('UTC',$viewer_tz,'now','d'); - if(($curr_month < $month) || (($curr_month == $month) && ($curr_day < $day))) + if (($curr_month < $month) || (($curr_month == $month) && ($curr_day < $day))) $year_diff--; return $year_diff; @@ -430,10 +430,10 @@ function get_dim($y,$m) { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); - if($m != 2) + if ($m != 2) return $dim[$m]; - if(((($y % 4) == 0) && (($y % 100) != 0)) || (($y % 400) == 0)) + if (((($y % 4) == 0) && (($y % 100) != 0)) || (($y % 400) == 0)) return 29; return $dim[2]; @@ -486,10 +486,12 @@ function cal($y = 0,$m = 0, $links = false, $class='') { $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y'); $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m'); - if(! $y) + if (! $y) { $y = $thisyear; - if(! $m) + } + if (! $m) { $m = intval($thismonth); + } $dn = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); $f = get_first_dim($y,$m); @@ -498,29 +500,33 @@ function cal($y = 0,$m = 0, $links = false, $class='') { $dow = 0; $started = false; - if(($y == $thisyear) && ($m == $thismonth)) + if (($y == $thisyear) && ($m == $thismonth)) { $tddate = intval(datetime_convert('UTC',date_default_timezone_get(),'now','j')); + } $str_month = day_translate($mtab[$m]); $o = ''; $o .= ""; - for($a = 0; $a < 7; $a ++) + for($a = 0; $a < 7; $a ++) { $o .= ''; + } $o .= ''; - while($d <= $l) { - if(($dow == $f) && (! $started)) + while ($d <= $l) { + if (($dow == $f) && (! $started)) { $started = true; + } $today = (((isset($tddate)) && ($tddate == $d)) ? "class=\"today\" " : ''); $o .= "'; $dow ++; - if(($dow == 7) && ($d <= $l)) { + if (($dow == 7) && ($d <= $l)) { $dow = 0; $o .= ''; } } - if($dow) - for($a = $dow; $a < 7; $a ++) + if ($dow) { + for ($a = $dow; $a < 7; $a ++) { $o .= ''; + } + } $o .= '
$str_month $y
' . mb_substr(day_translate($dn[$a]),0,3,'UTF-8') . '
"; $day = str_replace(' ',' ',sprintf('%2.2d', $d)); - if($started) { - if(is_array($links) && isset($links[$d])) + if ($started) { + if (is_array($links) && isset($links[$d])) { $o .= "$day"; - else + } else { $o .= $day; + } $d ++; } else { @@ -529,14 +535,16 @@ function cal($y = 0,$m = 0, $links = false, $class='') { $o .= '
 
'."\r\n"; diff --git a/include/dba_pdo.php b/include/dba_pdo.php index a44c447af..56692fbb3 100644 --- a/include/dba_pdo.php +++ b/include/dba_pdo.php @@ -34,7 +34,7 @@ $objDDDBLResultHandler->add('PDOStatement', array('HANDLER' => $cloPDOStatementR * */ -if(! class_exists('dba')) { +if (! class_exists('dba')) { class dba { private $debug = 0; @@ -66,9 +66,9 @@ class dba { return; } - if($install) { - if(strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) { - if(! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) { + if ($install) { + if (strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) { + if (! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) { $this->error = sprintf( t('Cannot locate DNS info for database server \'%s\''), $server); $this->connected = false; $this->db = null; @@ -81,13 +81,13 @@ class dba { \DDDBL\connect(); $this->db = \DDDBL\getDB(); - if(\DDDBL\isConnected()) { + if (\DDDBL\isConnected()) { $this->connected = true; } - if(! $this->connected) { + if (! $this->connected) { $this->db = null; - if(! $install) + if (! $install) system_unavailable(); } @@ -109,11 +109,11 @@ class dba { $objPreparedQueryPool = new \DDDBL\DataObjectPool('Query-Definition'); # check if query do not exists till now, if so create its definition - if(!$objPreparedQueryPool->exists($strQueryAlias)) + if (!$objPreparedQueryPool->exists($strQueryAlias)) $objPreparedQueryPool->add($strQueryAlias, array('QUERY' => $sql, 'HANDLER' => $strHandler)); - if((! $this->db) || (! $this->connected)) + if ((! $this->db) || (! $this->connected)) return false; $this->error = ''; @@ -124,7 +124,7 @@ class dba { $r = \DDDBL\get($strQueryAlias); # bad workaround to emulate the bizzare behavior of mysql_query - if(in_array($strSQLType, array('INSERT', 'UPDATE', 'DELETE', 'CREATE', 'DROP', 'SET'))) + if (in_array($strSQLType, array('INSERT', 'UPDATE', 'DELETE', 'CREATE', 'DROP', 'SET'))) $result = true; $intErrorCode = false; @@ -138,7 +138,7 @@ class dba { $a->save_timestamp($stamp1, "database"); - if(x($a->config,'system') && x($a->config['system'],'db_log')) { + if (x($a->config,'system') && x($a->config['system'],'db_log')) { if (($duration > $a->config["system"]["db_loglimit"])) { $duration = round($duration, 3); $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); @@ -149,20 +149,20 @@ class dba { } } - if($intErrorCode) + if ($intErrorCode) $this->error = $intErrorCode; - if(strlen($this->error)) { + if (strlen($this->error)) { logger('dba: ' . $this->error); } - if($this->debug) { + if ($this->debug) { $mesg = ''; - if($result === false) + if ($result === false) $mesg = 'false'; - elseif($result === true) + elseif ($result === true) $mesg = 'true'; else { # this needs fixing, but is a bug itself @@ -182,13 +182,13 @@ class dba { * These usually indicate SQL syntax errors that need to be resolved. */ - if(isset($result) AND ($result === false)) { + if (isset($result) AND ($result === false)) { logger('dba: ' . printable($sql) . ' returned false.' . "\n" . $this->error); - if(file_exists('dbfail.out')) + if (file_exists('dbfail.out')) file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND); } - if(isset($result) AND (($result === true) || ($result === false))) + if (isset($result) AND (($result === true) || ($result === false))) return $result; if ($onlyquery) { @@ -199,7 +199,7 @@ class dba { //$a->save_timestamp($stamp1, "database"); - if($this->debug) + if ($this->debug) logger('dba: ' . printable(print_r($r, true))); return($r); } @@ -223,7 +223,7 @@ class dba { } public function escape($str) { - if($this->db && $this->connected) { + if ($this->db && $this->connected) { $strQuoted = $this->db->quote($str); # this workaround is needed, because quote creates "'" and the beginning and the end # of the string, which is correct. but until now the queries set this delimiter manually, @@ -238,27 +238,27 @@ class dba { } }} -if(! function_exists('printable')) { +if (! function_exists('printable')) { function printable($s) { $s = preg_replace("~([\x01-\x08\x0E-\x0F\x10-\x1F\x7F-\xFF])~",".", $s); $s = str_replace("\x00",'.',$s); - if(x($_SERVER,'SERVER_NAME')) + if (x($_SERVER,'SERVER_NAME')) $s = escape_tags($s); return $s; }} // Procedural functions -if(! function_exists('dbg')) { +if (! function_exists('dbg')) { function dbg($state) { global $db; - if($db) + if ($db) $db->dbg($state); }} -if(! function_exists('dbesc')) { +if (! function_exists('dbesc')) { function dbesc($str) { global $db; - if($db && $db->connected) + if ($db && $db->connected) return($db->escape($str)); else return(str_replace("'","\\'",$str)); @@ -271,17 +271,17 @@ function dbesc($str) { // Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d", // 'user', 1); -if(! function_exists('q')) { +if (! function_exists('q')) { function q($sql) { global $db; $args = func_get_args(); unset($args[0]); - if($db && $db->connected) { + if ($db && $db->connected) { $stmt = @vsprintf($sql,$args); // Disabled warnings //logger("dba: q: $stmt", LOGGER_ALL); - if($stmt === false) + if ($stmt === false) logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true), LOGGER_DEBUG); return $db->q($stmt); } @@ -303,11 +303,11 @@ function q($sql) { * */ -if(! function_exists('dbq')) { +if (! function_exists('dbq')) { function dbq($sql) { global $db; - if($db && $db->connected) + if ($db && $db->connected) $ret = $db->q($sql); else $ret = false; @@ -321,21 +321,21 @@ function dbq($sql) { // cast to int to avoid trouble. -if(! function_exists('dbesc_array_cb')) { +if (! function_exists('dbesc_array_cb')) { function dbesc_array_cb(&$item, $key) { - if(is_string($item)) + if (is_string($item)) $item = dbesc($item); }} -if(! function_exists('dbesc_array')) { +if (! function_exists('dbesc_array')) { function dbesc_array(&$arr) { - if(is_array($arr) && count($arr)) { + if (is_array($arr) && count($arr)) { array_walk($arr,'dbesc_array_cb'); } }} -if(! function_exists('dba_timer')) { +if (! function_exists('dba_timer')) { function dba_timer() { return microtime(true); }} diff --git a/include/dbstructure.php b/include/dbstructure.php index c1ed4bb98..10db66bd6 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -1615,11 +1615,11 @@ function db_definition($charset) { function dbstructure_run(&$argv, &$argc) { global $a, $db; - if(is_null($a)){ + if (is_null($a)){ $a = new App; } - if(is_null($db)) { + if (is_null($db)) { @include(".htconfig.php"); require_once("include/dba.php"); $db = new dba($db_host, $db_user, $db_pass, $db_data); diff --git a/include/dfrn.php b/include/dfrn.php index 0c88d22c4..7d5020425 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -870,7 +870,7 @@ class dfrn { // The signed text contains the content in Markdown, the sender handle and the signatur for the content // It is needed for relayed comments to Diaspora. - if($item['signed_text']) { + if ($item['signed_text']) { $sign = base64_encode(json_encode(array('signed_text' => $item['signed_text'],'signature' => $item['signature'],'signer' => $item['signer']))); xml::add_element($doc, $entry, "dfrn:diaspora_signature", $sign); } @@ -1277,7 +1277,7 @@ class dfrn { $href = ""; $width = 0; foreach ($avatar->attributes AS $attributes) { - /// @TODO Rewrite these similar if() to one switch + /// @TODO Rewrite these similar if () to one switch if ($attributes->name == "href") { $href = $attributes->textContent; } @@ -1836,7 +1836,7 @@ class dfrn { if (edited_timestamp_is_newer($current, $item)) { // do not accept (ignore) an earlier edit than one we currently have. - if(datetime_convert("UTC","UTC",$item["edited"]) < $current["edited"]) + if (datetime_convert("UTC","UTC",$item["edited"]) < $current["edited"]) return(false); $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d", @@ -1887,7 +1887,7 @@ class dfrn { if ($item["parent-uri"] != $item["uri"]) { $community = false; - if($importer["page-flags"] == PAGE_COMMUNITY || $importer["page-flags"] == PAGE_PRVGROUP) { + if ($importer["page-flags"] == PAGE_COMMUNITY || $importer["page-flags"] == PAGE_PRVGROUP) { $sql_extra = ""; $community = true; logger("possible community action"); @@ -1974,7 +1974,7 @@ class dfrn { } } - if($Blink && link_compare($Blink,App::get_baseurl()."/profile/".$importer["nickname"])) { + if ($Blink && link_compare($Blink,App::get_baseurl()."/profile/".$importer["nickname"])) { // send a notification notification(array( @@ -2043,7 +2043,7 @@ class dfrn { return false; } } else { - if(($item["verb"] == ACTIVITY_LIKE) + if (($item["verb"] == ACTIVITY_LIKE) || ($item["verb"] == ACTIVITY_DISLIKE) || ($item["verb"] == ACTIVITY_ATTEND) || ($item["verb"] == ACTIVITY_ATTENDNO) @@ -2122,7 +2122,7 @@ class dfrn { $title = ""; foreach ($links AS $link) { foreach ($link->attributes AS $attributes) { - /// @TODO Rewrite these repeated (same) if() statements to a switch() + /// @TODO Rewrite these repeated (same) if () statements to a switch() if ($attributes->name == "href") { $href = $attributes->textContent; } @@ -2370,7 +2370,7 @@ class dfrn { // When activated, forums don't work. // And: Why should we disallow commenting by followers? // the behaviour is now similar to the Diaspora part. - //if($importer["rel"] == CONTACT_IS_FOLLOWER) { + //if ($importer["rel"] == CONTACT_IS_FOLLOWER) { // logger("Contact ".$importer["id"]." is only follower. Quitting", LOGGER_DEBUG); // return; //} @@ -2492,7 +2492,7 @@ class dfrn { logger("Item was stored with id ".$posted_id, LOGGER_DEBUG); - if(stristr($item["verb"],ACTIVITY_POKE)) + if (stristr($item["verb"],ACTIVITY_POKE)) self::do_poke($item, $importer, $posted_id); } } @@ -2594,7 +2594,7 @@ class dfrn { } } - if($entrytype == DFRN_TOP_LEVEL) { + if ($entrytype == DFRN_TOP_LEVEL) { $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '', `title` = '' WHERE `parent-uri` = '%s' AND `uid` = %d", @@ -2618,7 +2618,7 @@ class dfrn { create_tags_from_itemuri($uri, $importer["uid"]); create_files_from_itemuri($uri, $importer["uid"]); update_thread_uri($uri, $importer["importer_uid"]); - if($item["last-child"]) { + if ($item["last-child"]) { // ensure that last-child is set in case the comment that had it just got wiped. q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ", dbesc(datetime_convert()), @@ -2639,7 +2639,7 @@ class dfrn { } // if this is a relayed delete, propagate it to other recipients - if($entrytype == DFRN_REPLY_RC) { + if ($entrytype == DFRN_REPLY_RC) { logger("Notifying followers about deletion of post ".$item["id"], LOGGER_DEBUG); proc_run(PRIORITY_HIGH, "include/notifier.php","drop", $item["id"]); } @@ -2659,7 +2659,7 @@ class dfrn { if ($xml == "") return; - if($importer["readonly"]) { + if ($importer["readonly"]) { // We aren't receiving stuff from this person. But we will quietly ignore them // rather than a blatant "go away" message. logger('ignoring contact '.$importer["id"]); diff --git a/include/diaspora.php b/include/diaspora.php index eca22092d..6f189f9c0 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -181,7 +181,7 @@ class Diaspora { $children = $basedom->children('https://joindiaspora.com/protocol'); - if($children->header) { + if ($children->header) { $public = true; $author_link = str_replace('acct:','',$children->header->author_id); } else { @@ -217,11 +217,11 @@ class Diaspora { // figure out where in the DOM tree our data is hiding - if($dom->provenance->data) + if ($dom->provenance->data) $base = $dom->provenance; - elseif($dom->env->data) + elseif ($dom->env->data) $base = $dom->env; - elseif($dom->data) + elseif ($dom->data) $base = $dom; if (!$base) { @@ -254,7 +254,7 @@ class Diaspora { $data = base64url_decode($data); - if($public) + if ($public) $inner_decrypted = $data; else { @@ -556,7 +556,7 @@ class Diaspora { logger("Fetching diaspora key for: ".$handle); $r = self::person_by_handle($handle); - if($r) + if ($r) return $r["pubkey"]; return ""; @@ -612,7 +612,7 @@ class Diaspora { */ private static function add_fcontact($arr, $update = false) { - if($update) { + if ($update) { $r = q("UPDATE `fcontact` SET `name` = '%s', `photo` = '%s', @@ -796,7 +796,7 @@ class Diaspora { // perhaps we were already sharing with this person. Now they're sharing with us. // That makes us friends. // Normally this should have handled by getting a request - but this could get lost - if($contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) { + if ($contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) { q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d", intval(CONTACT_IS_FRIEND), intval($contact["id"]), @@ -806,12 +806,12 @@ class Diaspora { logger("defining user ".$contact["nick"]." as friend"); } - if(($contact["blocked"]) || ($contact["readonly"]) || ($contact["archive"])) + if (($contact["blocked"]) || ($contact["readonly"]) || ($contact["archive"])) return false; - if($contact["rel"] == CONTACT_IS_SHARING || $contact["rel"] == CONTACT_IS_FRIEND) + if ($contact["rel"] == CONTACT_IS_SHARING || $contact["rel"] == CONTACT_IS_FRIEND) return true; - if($contact["rel"] == CONTACT_IS_FOLLOWER) - if(($importer["page-flags"] == PAGE_COMMUNITY) OR $is_comment) + if ($contact["rel"] == CONTACT_IS_FOLLOWER) + if (($importer["page-flags"] == PAGE_COMMUNITY) OR $is_comment) return true; // Messages for the global users are always accepted @@ -969,7 +969,7 @@ class Diaspora { logger("Fetch post from ".$source_url, LOGGER_DEBUG); $envelope = fetch_url($source_url); - if($envelope) { + if ($envelope) { logger("Envelope was fetched.", LOGGER_DEBUG); $x = self::verify_magic_envelope($envelope); if (!$x) @@ -985,7 +985,7 @@ class Diaspora { logger("Fetch post from ".$source_url, LOGGER_DEBUG); $x = fetch_url($source_url); - if(!$x) + if (!$x) return false; } @@ -1042,7 +1042,7 @@ class Diaspora { FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", intval($uid), dbesc($guid)); - if(!$r) { + if (!$r) { $result = self::store_by_guid($guid, $contact["url"], $uid); if (!$result) { @@ -1303,7 +1303,7 @@ class Diaspora { } // If we are the origin of the parent we store the original data and notify our followers - if($message_id AND $parent_item["origin"]) { + if ($message_id AND $parent_item["origin"]) { // Formerly we stored the signed text, the signature and the author in different fields. // We now store the raw data so that we are more flexible. @@ -1480,7 +1480,7 @@ class Diaspora { intval($importer["uid"]), dbesc($guid) ); - if($c) + if ($c) $conversation = $c[0]; else { $r = q("INSERT INTO `conv` (`uid`, `guid`, `creator`, `created`, `updated`, `subject`, `recips`) @@ -1493,13 +1493,13 @@ class Diaspora { dbesc($subject), dbesc($participants) ); - if($r) + if ($r) $c = q("SELECT * FROM `conv` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", intval($importer["uid"]), dbesc($guid) ); - if($c) + if ($c) $conversation = $c[0]; } if (!$conversation) { @@ -1637,7 +1637,7 @@ class Diaspora { logger("Stored like ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG); // If we are the origin of the parent we store the original data and notify our followers - if($message_id AND $parent_item["origin"]) { + if ($message_id AND $parent_item["origin"]) { // Formerly we stored the signed text, the signature and the author in different fields. // We now store the raw data so that we are more flexible. @@ -1812,10 +1812,10 @@ class Diaspora { $handle_parts = explode("@", $author); $nick = $handle_parts[0]; - if($name === "") + if ($name === "") $name = $handle_parts[0]; - if( preg_match("|^https?://|", $image_url) === 0) + if ( preg_match("|^https?://|", $image_url) === 0) $image_url = "http://".$handle_parts[1].$image_url; update_contact_avatar($image_url, $importer["uid"], $contact["id"]); @@ -1830,7 +1830,7 @@ class Diaspora { // this is to prevent multiple birthday notifications in a single year // if we already have a stored birthday and the 'm-d' part hasn't changed, preserve the entry, which will preserve the notify year - if(substr($birthday,5) === substr($contact["bd"],5)) + if (substr($birthday,5) === substr($contact["bd"],5)) $birthday = $contact["bd"]; $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `name-date` = '%s', `bd` = '%s', @@ -1876,7 +1876,7 @@ class Diaspora { $a = get_app(); - if($contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) { + if ($contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) { q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d", intval(CONTACT_IS_FRIEND), intval($contact["id"]), @@ -1889,7 +1889,7 @@ class Diaspora { intval($importer["uid"]) ); - if($r && !$r[0]["hide-friends"] && !$contact["hidden"] && intval(get_pconfig($importer["uid"], "system", "post_newfriend"))) { + if ($r && !$r[0]["hide-friends"] && !$contact["hidden"] && intval(get_pconfig($importer["uid"], "system", "post_newfriend"))) { $self = q("SELECT * FROM `contact` WHERE `self` AND `uid` = %d LIMIT 1", intval($importer["uid"]) @@ -1897,7 +1897,7 @@ class Diaspora { // they are not CONTACT_IS_FOLLOWER anymore but that's what we have in the array - if($self && $contact["rel"] == CONTACT_IS_FOLLOWER) { + if ($self && $contact["rel"] == CONTACT_IS_FOLLOWER) { $arr = array(); $arr["uri"] = $arr["parent-uri"] = item_new_uri($a->get_hostname(), $importer["uid"]); @@ -1928,7 +1928,7 @@ class Diaspora { $arr["deny_gid"] = $user[0]["deny_gid"]; $i = item_store($arr); - if($i) + if ($i) proc_run(PRIORITY_HIGH, "include/notifier.php", "activity", $i); } } @@ -2067,12 +2067,12 @@ class Diaspora { $def_gid = get_default_group($importer['uid'], $ret["network"]); - if(intval($def_gid)) + if (intval($def_gid)) group_add_member($importer["uid"], "", $contact_record["id"], $def_gid); update_contact_avatar($ret["photo"], $importer['uid'], $contact_record["id"], true); - if($importer["page-flags"] == PAGE_NORMAL) { + if ($importer["page-flags"] == PAGE_NORMAL) { logger("Sending intra message for author ".$author.".", LOGGER_DEBUG); @@ -2122,7 +2122,7 @@ class Diaspora { ); $u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($importer["uid"])); - if($u) { + if ($u) { logger("Sending share message (Relation: ".$new_relation.") to author ".$author." - Contact: ".$contact_record["id"]." - User: ".$importer["uid"], LOGGER_DEBUG); $ret = self::send_share($u[0], $contact_record); @@ -2748,7 +2748,7 @@ class Diaspora { $a = get_app(); $enabled = intval(get_config("system", "diaspora_enabled")); - if(!$enabled) + if (!$enabled) return 200; $logid = random_string(4); @@ -3087,12 +3087,12 @@ class Diaspora { $body = html_entity_decode(bb2diaspora($body)); // Adding the title - if(strlen($title)) + if (strlen($title)) $body = "## ".html_entity_decode($title)."\n\n".$body; if ($item["attach"]) { $cnt = preg_match_all('/href=\"(.*?)\"(.*?)title=\"(.*?)\"/ism', $item["attach"], $matches, PREG_SET_ORDER); - if(cnt) { + if (cnt) { $body .= "\n".t("Attachments:")."\n"; foreach($matches as $mtch) $body .= "[".$mtch[3]."](".$mtch[1].")\n"; @@ -3632,17 +3632,20 @@ class Diaspora { } $r = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($contact['uid'])); - if(!$r) + if (!dbm::is_result($r)) { return false; + } $contact["uprvkey"] = $r[0]['prvkey']; $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", intval($post_id)); - if (!$r) + if (!dbm::is_result($r)) { 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; + } $message = self::construct_like($r[0], $contact); $message["author_signature"] = self::signature($contact, $message); diff --git a/include/discover_poco.php b/include/discover_poco.php index f0bfb646b..c13f89894 100644 --- a/include/discover_poco.php +++ b/include/discover_poco.php @@ -174,10 +174,10 @@ function discover_directory($search) { $j = json_decode($x); if (count($j->results)) { - foreach($j->results as $jj) { + foreach ($j->results as $jj) { // Check if the contact already exists $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); if (($exists[0]["last_contact"] < $exists[0]["last_failure"]) AND diff --git a/include/email.php b/include/email.php index 42f80c242..ffd93bc25 100644 --- a/include/email.php +++ b/include/email.php @@ -4,7 +4,7 @@ require_once('include/msgclean.php'); require_once('include/quoteconvert.php'); function email_connect($mailbox,$username,$password) { - if(! function_exists('imap_open')) + if (! function_exists('imap_open')) return false; $mbox = @imap_open($mailbox,$username,$password); @@ -14,23 +14,23 @@ function email_connect($mailbox,$username,$password) { function email_poll($mbox,$email_addr) { - if(! ($mbox && $email_addr)) + if (! ($mbox && $email_addr)) return array(); $search1 = @imap_search($mbox,'FROM "' . $email_addr . '"', SE_UID); - if(! $search1) + if (! $search1) $search1 = array(); $search2 = @imap_search($mbox,'TO "' . $email_addr . '"', SE_UID); - if(! $search2) + if (! $search2) $search2 = array(); $search3 = @imap_search($mbox,'CC "' . $email_addr . '"', SE_UID); - if(! $search3) + if (! $search3) $search3 = array(); $search4 = @imap_search($mbox,'BCC "' . $email_addr . '"', SE_UID); - if(! $search4) + if (! $search4) $search4 = array(); $res = array_unique(array_merge($search1,$search2,$search3,$search4)); @@ -57,7 +57,7 @@ function email_msg_headers($mbox,$uid) { $raw_header = str_replace("\r",'',$raw_header); $ret = array(); $h = explode("\n",$raw_header); - if(count($h)) + if (count($h)) foreach($h as $line ) { if (preg_match("/^[a-zA-Z]/", $line)) { $key = substr($line,0,strpos($line,':')); @@ -79,10 +79,10 @@ function email_get_msg($mbox,$uid, $reply) { $struc = (($mbox && $uid) ? @imap_fetchstructure($mbox,$uid,FT_UID) : null); - if(! $struc) + if (! $struc) return $ret; - if(! $struc->parts) { + if (! $struc->parts) { $ret['body'] = email_get_part($mbox,$uid,$struc,0, 'html'); $html = $ret['body']; @@ -210,12 +210,12 @@ function email_header_encode($in_str, $charset) { $need_to_convert = false; for($x = 0; $x < strlen($in_str); $x ++) { - if((ord($in_str[$x]) == 0) || ((ord($in_str[$x]) > 128))) { + if ((ord($in_str[$x]) == 0) || ((ord($in_str[$x]) > 128))) { $need_to_convert = true; } } - if(! $need_to_convert) + if (! $need_to_convert) return $in_str; if ($out_str && $charset) { diff --git a/include/enotify.php b/include/enotify.php index ebc27309d..f86174bd4 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -411,10 +411,12 @@ function notification($params) { $hash = random_string(); $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1", dbesc($hash)); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $dups = true; - } while($dups == true); + } + } while ($dups == true); + /// @TODO One statement is enough $datarray = array(); $datarray['hash'] = $hash; $datarray['name'] = $params['source_name']; diff --git a/include/event.php b/include/event.php index 9e5bafbdb..1aa3abb2f 100644 --- a/include/event.php +++ b/include/event.php @@ -10,7 +10,7 @@ require_once('include/datetime.php'); function format_event_html($ev, $simple = false) { - if(! ((is_array($ev)) && count($ev))) + if (! ((is_array($ev)) && count($ev))) return ''; $bd_format = t('l F d, Y \@ g:i A') ; // Friday January 18, 2011 @ 8 AM @@ -32,10 +32,10 @@ function format_event_html($ev, $simple = false) { $o .= "

".t('Starts:')."

".$event_start."

"; - if(! $ev['nofinish']) + if (! $ev['nofinish']) $o .= "

".t('Finishes:')."

".$event_end."

"; - if(strlen($ev['location'])) + if (strlen($ev['location'])) $o .= "

".t('Location:')."

".$ev['location']."

"; return $o; @@ -53,13 +53,13 @@ function format_event_html($ev, $simple = false) { . '" >'.$event_start . '

' . "\r\n"; - if(! $ev['nofinish']) + if (! $ev['nofinish']) $o .= '

' . t('Finishes:') . ' '.$event_end . '

' . "\r\n"; - if(strlen($ev['location'])){ + if (strlen($ev['location'])){ $o .= '

' . t('Location:') . ' ' . bbcode($ev['location']) . '

' . "\r\n"; @@ -92,26 +92,26 @@ function parse_event($h) { logger('parse_event: parse error: ' . $e); } - if(! $dom) + if (! $dom) return $ret; $items = $dom->getElementsByTagName('*'); foreach($items as $item) { - if(attribute_contains($item->getAttribute('class'), 'vevent')) { + if (attribute_contains($item->getAttribute('class'), 'vevent')) { $level2 = $item->getElementsByTagName('*'); foreach($level2 as $x) { - if(attribute_contains($x->getAttribute('class'),'dtstart') && $x->getAttribute('title')) { + if (attribute_contains($x->getAttribute('class'),'dtstart') && $x->getAttribute('title')) { $ret['start'] = $x->getAttribute('title'); - if(! strpos($ret['start'],'Z')) + if (! strpos($ret['start'],'Z')) $ret['adjust'] = true; } - if(attribute_contains($x->getAttribute('class'),'dtend') && $x->getAttribute('title')) + if (attribute_contains($x->getAttribute('class'),'dtend') && $x->getAttribute('title')) $ret['finish'] = $x->getAttribute('title'); - if(attribute_contains($x->getAttribute('class'),'description')) + if (attribute_contains($x->getAttribute('class'),'description')) $ret['desc'] = $x->textContent; - if(attribute_contains($x->getAttribute('class'),'location')) + if (attribute_contains($x->getAttribute('class'),'location')) $ret['location'] = $x->textContent; } } @@ -119,23 +119,23 @@ function parse_event($h) { // sanitise - if((x($ret,'desc')) && ((strpos($ret['desc'],'<') !== false) || (strpos($ret['desc'],'>') !== false))) { + if ((x($ret,'desc')) && ((strpos($ret['desc'],'<') !== false) || (strpos($ret['desc'],'>') !== false))) { $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); $purifier = new HTMLPurifier($config); $ret['desc'] = html2bbcode($purifier->purify($ret['desc'])); } - if((x($ret,'location')) && ((strpos($ret['location'],'<') !== false) || (strpos($ret['location'],'>') !== false))) { + if ((x($ret,'location')) && ((strpos($ret['location'],'<') !== false) || (strpos($ret['location'],'>') !== false))) { $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); $purifier = new HTMLPurifier($config); $ret['location'] = html2bbcode($purifier->purify($ret['location'])); } - if(x($ret,'start')) + if (x($ret,'start')) $ret['start'] = datetime_convert('UTC','UTC',$ret['start']); - if(x($ret,'finish')) + if (x($ret,'finish')) $ret['finish'] = datetime_convert('UTC','UTC',$ret['finish']); return $ret; @@ -146,22 +146,22 @@ function format_event_bbcode($ev) { $o = ''; - if($ev['summary']) + if ($ev['summary']) $o .= '[event-summary]' . $ev['summary'] . '[/event-summary]'; - if($ev['desc']) + if ($ev['desc']) $o .= '[event-description]' . $ev['desc'] . '[/event-description]'; - if($ev['start']) + if ($ev['start']) $o .= '[event-start]' . $ev['start'] . '[/event-start]'; - if(($ev['finish']) && (! $ev['nofinish'])) + if (($ev['finish']) && (! $ev['nofinish'])) $o .= '[event-finish]' . $ev['finish'] . '[/event-finish]'; - if($ev['location']) + if ($ev['location']) $o .= '[event-location]' . $ev['location'] . '[/event-location]'; - if($ev['adjust']) + if ($ev['adjust']) $o .= '[event-adjust]' . $ev['adjust'] . '[/event-adjust]'; @@ -172,7 +172,7 @@ function format_event_bbcode($ev) { function bbtovcal($s) { $o = ''; $ev = bbtoevent($s); - if($ev['desc']) + if ($ev['desc']) $o = format_event_html($ev); return $o; } @@ -183,22 +183,22 @@ function bbtoevent($s) { $ev = array(); $match = ''; - if(preg_match("/\[event\-summary\](.*?)\[\/event\-summary\]/is",$s,$match)) + if (preg_match("/\[event\-summary\](.*?)\[\/event\-summary\]/is",$s,$match)) $ev['summary'] = $match[1]; $match = ''; - if(preg_match("/\[event\-description\](.*?)\[\/event\-description\]/is",$s,$match)) + if (preg_match("/\[event\-description\](.*?)\[\/event\-description\]/is",$s,$match)) $ev['desc'] = $match[1]; $match = ''; - if(preg_match("/\[event\-start\](.*?)\[\/event\-start\]/is",$s,$match)) + if (preg_match("/\[event\-start\](.*?)\[\/event\-start\]/is",$s,$match)) $ev['start'] = $match[1]; $match = ''; - if(preg_match("/\[event\-finish\](.*?)\[\/event\-finish\]/is",$s,$match)) + if (preg_match("/\[event\-finish\](.*?)\[\/event\-finish\]/is",$s,$match)) $ev['finish'] = $match[1]; $match = ''; - if(preg_match("/\[event\-location\](.*?)\[\/event\-location\]/is",$s,$match)) + if (preg_match("/\[event\-location\](.*?)\[\/event\-location\]/is",$s,$match)) $ev['location'] = $match[1]; $match = ''; - if(preg_match("/\[event\-adjust\](.*?)\[\/event\-adjust\]/is",$s,$match)) + if (preg_match("/\[event\-adjust\](.*?)\[\/event\-adjust\]/is",$s,$match)) $ev['adjust'] = $match[1]; $ev['nofinish'] = (((x($ev, 'start') && $ev['start']) && (!x($ev, 'finish') || !$ev['finish'])) ? 1 : 0); return $ev; @@ -218,7 +218,7 @@ function ev_compare($a,$b) { $date_a = (($a['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$a['start']) : $a['start']); $date_b = (($b['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$b['start']) : $b['start']); - if($date_a === $date_b) + if ($date_a === $date_b) return strcasecmp($a['desc'],$b['desc']); return strcmp($date_a,$date_b); @@ -248,7 +248,7 @@ function event_store($arr) { $arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0); $arr['guid'] = get_guid(32); - if($arr['cid']) + if ($arr['cid']) $c = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($arr['cid']), intval($arr['uid']) @@ -258,13 +258,13 @@ function event_store($arr) { intval($arr['uid']) ); - if(count($c)) + if (count($c)) $contact = $c[0]; // Existing event being modified - if($arr['id']) { + if ($arr['id']) { // has the event actually changed? @@ -272,7 +272,7 @@ function event_store($arr) { intval($arr['id']), intval($arr['uid']) ); - if((! dbm::is_result($r)) || ($r[0]['edited'] === $arr['edited'])) { + if ((! dbm::is_result($r)) || ($r[0]['edited'] === $arr['edited'])) { // Nothing has changed. Grab the item id to return. @@ -412,7 +412,7 @@ function event_store($arr) { // $plink = App::get_baseurl() . '/display/' . $r[0]['nickname'] . '/' . $item_id; - if($item_id) { + if ($item_id) { //q("UPDATE `item` SET `plink` = '%s', `event-id` = %d WHERE `uid` = %d AND `id` = %d", // dbesc($plink), // intval($event['id']), @@ -524,7 +524,7 @@ function event_remove_duplicates($dates) { */ function event_by_id($owner_uid = 0, $event_params, $sql_extra = '') { // ownly allow events if there is a valid owner_id - if($owner_uid == 0) + if ($owner_uid == 0) return; // query for the event by event id @@ -557,7 +557,7 @@ function event_by_id($owner_uid = 0, $event_params, $sql_extra = '') { */ function events_by_date($owner_uid = 0, $event_params, $sql_extra = '') { // ownly allow events if there is a valid owner_id - if($owner_uid == 0) + if ($owner_uid == 0) return; // query for the event by date @@ -614,7 +614,7 @@ function process_events($arr) { $last_date = $d; $edit = ((! $rr['cid']) ? array(App::get_baseurl().'/events/event/'.$rr['id'],t('Edit event'),'','') : null); $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8')); - if(! $title) { + if (! $title) { list($title, $_trash) = explode(" t("Export"), diff --git a/include/expire.php b/include/expire.php index 35b109a50..098125a79 100644 --- a/include/expire.php +++ b/include/expire.php @@ -11,12 +11,13 @@ function expire_run(&$argv, &$argc){ // 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 - if(intval(get_config('system','optimize_items'))) - q("optimize table item"); + if (intval(get_config('system','optimize_items'))) { + q("OPTIMIZE TABLE `item`"); + } logger('expire: start'); diff --git a/include/features.php b/include/features.php index 74c110427..c49680cb8 100644 --- a/include/features.php +++ b/include/features.php @@ -38,7 +38,7 @@ function get_feature_default($feature) { $f = get_features(); foreach($f as $cat) { foreach($cat as $feat) { - if(is_array($feat) && $feat[0] === $feature) + if (is_array($feat) && $feat[0] === $feature) return $feat[3]; } } @@ -116,13 +116,13 @@ function get_features($filtered = true) { // removed any locked features and remove the entire category if this makes it empty - if($filtered) { + if ($filtered) { foreach($arr as $k => $x) { $has_items = false; $kquantity = count($arr[$k]); for($y = 0; $y < $kquantity; $y ++) { - if(is_array($arr[$k][$y])) { - if($arr[$k][$y][4] === false) { + if (is_array($arr[$k][$y])) { + if ($arr[$k][$y][4] === false) { $has_items = true; } else { @@ -130,7 +130,7 @@ function get_features($filtered = true) { } } } - if(! $has_items) { + if (! $has_items) { unset($arr[$k]); } } diff --git a/include/feed.php b/include/feed.php index 295993370..1fb766fcc 100644 --- a/include/feed.php +++ b/include/feed.php @@ -163,7 +163,7 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { $header["contact-id"] = $contact["id"]; - if(!strlen($contact["notify"])) { + if (!strlen($contact["notify"])) { // one way feed - no remote comment ability $header["last-child"] = 0; } @@ -289,8 +289,9 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { $type = $attributes->textContent; } } - if(strlen($item["attach"])) + if (strlen($item["attach"])) { $item["attach"] .= ','; + } $attachments[] = array("link" => $href, "type" => $type, "length" => $length); diff --git a/include/files.php b/include/files.php index 7bff0e346..c20a6d832 100644 --- a/include/files.php +++ b/include/files.php @@ -33,7 +33,7 @@ function create_files_from_item($itemid) { function create_files_from_itemuri($itemuri, $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) create_files_from_item($message["id"]); } diff --git a/include/friendica_smarty.php b/include/friendica_smarty.php index 9ba2d2a74..9a224534e 100644 --- a/include/friendica_smarty.php +++ b/include/friendica_smarty.php @@ -18,7 +18,7 @@ class FriendicaSmarty extends Smarty { // setTemplateDir can be set to an array, which Smarty will parse in order. // The order is thus very important here $template_dirs = array('theme' => "view/theme/$theme/".SMARTY3_TEMPLATE_FOLDER."/"); - if( x($a->theme_info,"extends") ) + if ( x($a->theme_info,"extends") ) $template_dirs = $template_dirs + array('extends' => "view/theme/".$a->theme_info["extends"]."/".SMARTY3_TEMPLATE_FOLDER."/"); $template_dirs = $template_dirs + array('base' => "view/".SMARTY3_TEMPLATE_FOLDER."/"); $this->setTemplateDir($template_dirs); @@ -35,7 +35,7 @@ class FriendicaSmarty extends Smarty { } function parsed($template = '') { - if($template) { + if ($template) { return $this->fetch('string:' . $template); } return $this->fetch('file:' . $this->filename); @@ -48,7 +48,7 @@ class FriendicaSmartyEngine implements ITemplateEngine { static $name ="smarty3"; public function __construct(){ - if(!is_writable('view/smarty3/')){ + if (!is_writable('view/smarty3/')){ echo "ERROR: folder view/smarty3/ must be writable by webserver."; killme(); } } @@ -56,7 +56,7 @@ class FriendicaSmartyEngine implements ITemplateEngine { // ITemplateEngine interface public function replace_macros($s, $r) { $template = ''; - if(gettype($s) === 'string') { + if (gettype($s) === 'string') { $template = $s; $s = new FriendicaSmarty(); } @@ -72,7 +72,7 @@ class FriendicaSmartyEngine implements ITemplateEngine { $r = $arr['vars']; foreach($r as $key=>$value) { - if($key[0] === '$') { + if ($key[0] === '$') { $key = substr($key, 1); } $s->assign($key, $value); diff --git a/include/group.php b/include/group.php index 6332c45da..dee0d30c2 100644 --- a/include/group.php +++ b/include/group.php @@ -4,9 +4,9 @@ function group_add($uid,$name) { $ret = false; - if(x($uid) && x($name)) { + if (x($uid) && x($name)) { $r = group_byname($uid,$name); // check for dups - if($r !== false) { + if ($r !== false) { // This could be a problem. // Let's assume we've just created a group which we once deleted @@ -17,7 +17,7 @@ function group_add($uid,$name) { $z = q("SELECT * FROM `group` WHERE `id` = %d LIMIT 1", intval($r) ); - if(count($z) && $z[0]['deleted']) { + if (count($z) && $z[0]['deleted']) { $r = q("UPDATE `group` SET `deleted` = 0 WHERE `uid` = %d AND `name` = '%s'", intval($uid), dbesc($name) @@ -39,14 +39,14 @@ function group_add($uid,$name) { function group_rmv($uid,$name) { $ret = false; - if(x($uid) && x($name)) { + if (x($uid) && x($name)) { $r = q("SELECT id FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1", intval($uid), dbesc($name) ); if (dbm::is_result($r)) $group_id = $r[0]['id']; - if(! $group_id) + if (! $group_id) return false; // remove group from default posting lists @@ -57,20 +57,20 @@ function group_rmv($uid,$name) { $user_info = $r[0]; $change = false; - if($user_info['def_gid'] == $group_id) { + if ($user_info['def_gid'] == $group_id) { $user_info['def_gid'] = 0; $change = true; } - if(strpos($user_info['allow_gid'], '<' . $group_id . '>') !== false) { + if (strpos($user_info['allow_gid'], '<' . $group_id . '>') !== false) { $user_info['allow_gid'] = str_replace('<' . $group_id . '>', '', $user_info['allow_gid']); $change = true; } - if(strpos($user_info['deny_gid'], '<' . $group_id . '>') !== false) { + if (strpos($user_info['deny_gid'], '<' . $group_id . '>') !== false) { $user_info['deny_gid'] = str_replace('<' . $group_id . '>', '', $user_info['deny_gid']); $change = true; } - if($change) { + if ($change) { q("UPDATE user SET def_gid = %d, allow_gid = '%s', deny_gid = '%s' WHERE uid = %d", intval($user_info['def_gid']), dbesc($user_info['allow_gid']), @@ -100,7 +100,7 @@ function group_rmv($uid,$name) { } function group_byname($uid,$name) { - if((! $uid) || (! strlen($name))) + if ((! $uid) || (! strlen($name))) return false; $r = q("SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1", intval($uid), @@ -113,9 +113,9 @@ function group_byname($uid,$name) { function group_rmv_member($uid,$name,$member) { $gid = group_byname($uid,$name); - if(! $gid) + if (! $gid) return false; - if(! ( $uid && $gid && $member)) + if (! ( $uid && $gid && $member)) return false; $r = q("DELETE FROM `group_member` WHERE `uid` = %d AND `gid` = %d AND `contact-id` = %d", intval($uid), @@ -129,9 +129,9 @@ function group_rmv_member($uid,$name,$member) { function group_add_member($uid,$name,$member,$gid = 0) { - if(! $gid) + if (! $gid) $gid = group_byname($uid,$name); - if((! $gid) || (! $uid) || (! $member)) + if ((! $gid) || (! $uid) || (! $member)) return false; $r = q("SELECT * FROM `group_member` WHERE `uid` = %d AND `gid` = %d AND `contact-id` = %d LIMIT 1", @@ -156,7 +156,7 @@ function group_add_member($uid,$name,$member,$gid = 0) { function group_get_members($gid) { $ret = array(); - if(intval($gid)) { + if (intval($gid)) { $r = q("SELECT `group_member`.`contact-id`, `contact`.* FROM `group_member` INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` WHERE `gid` = %d AND `group_member`.`uid` = %d AND @@ -173,7 +173,7 @@ function group_get_members($gid) { function group_public_members($gid) { $ret = 0; - if(intval($gid)) { + if (intval($gid)) { $r = q("SELECT `contact`.`id` AS `contact-id` FROM `group_member` INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` WHERE `gid` = %d AND `group_member`.`uid` = %d @@ -252,7 +252,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro intval($_SESSION['uid']) ); $member_of = array(); - if($cid) { + if ($cid) { $member_of = groups_containing(local_user(),$cid); } @@ -302,7 +302,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro } function expand_groups($a,$check_dead = false, $use_gcontact = false) { - if(! (is_array($a) && count($a))) + if (! (is_array($a) && count($a))) return array(); $groups = implode(',', $a); $groups = dbesc($groups); @@ -320,7 +320,7 @@ function expand_groups($a,$check_dead = false, $use_gcontact = false) { if (dbm::is_result($r)) foreach($r as $rr) $ret[] = $rr['contact-id']; - if($check_dead AND !$use_gcontact) { + if ($check_dead AND !$use_gcontact) { require_once('include/acl_selectors.php'); $ret = prune_deadguys($ret); } @@ -399,7 +399,7 @@ function get_default_group($uid, $network = "") { return $default_group; $g = q("SELECT `def_gid` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid)); - if($g && intval($g[0]["def_gid"])) + if ($g && intval($g[0]["def_gid"])) $default_group = $g[0]["def_gid"]; return $default_group; diff --git a/include/identity.php b/include/identity.php index ab80c71ce..a85b78e71 100644 --- a/include/identity.php +++ b/include/identity.php @@ -38,7 +38,7 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) { dbesc($nickname) ); - if(!$user && count($user) && !count($profiledata)) { + if (!$user && count($user) && !count($profiledata)) { logger('profile error: ' . $a->query_string, LOGGER_DEBUG); notice( t('Requested account is not available.') . EOL ); $a->error = 404; @@ -47,7 +47,7 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) { $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile); - if(($pdata === false) || (!count($pdata)) && !count($profiledata)) { + if (($pdata === false) || (!count($pdata)) && !count($profiledata)) { logger('profile error: ' . $a->query_string, LOGGER_DEBUG); notice( t('Requested profile is not available.') . EOL ); $a->error = 404; @@ -56,11 +56,11 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) { // fetch user tags if this isn't the default profile - if(!$pdata['is-default']) { + if (!$pdata['is-default']) { $x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1", intval($pdata['profile_uid']) ); - if($x && count($x)) + if ($x && count($x)) $pdata['pub_keywords'] = $x[0]['pub_keywords']; } @@ -88,10 +88,10 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) { require_once($theme_info_file); } - if(! (x($a->page,'aside'))) + if (! (x($a->page,'aside'))) $a->page['aside'] = ''; - if(local_user() && local_user() == $a->profile['uid'] && $profiledata) { + if (local_user() && local_user() == $a->profile['uid'] && $profiledata) { $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array( '$editprofile' => t('Edit profile'), '$profid' => $a->profile['id'] @@ -110,7 +110,7 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) { else $a->page['aside'] .= profile_sidebar($a->profile, $block); - /*if(! $block) + /*if (! $block) $a->page['aside'] .= contact_block();*/ return; @@ -133,9 +133,9 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) { * Includes all available profile data */ function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) { - if(remote_user() && count($_SESSION['remote'])) { + if (remote_user() && count($_SESSION['remote'])) { foreach($_SESSION['remote'] as $visitor) { - if($visitor['uid'] == $uid) { + if ($visitor['uid'] == $uid) { $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1", intval($visitor['cid']) ); @@ -148,7 +148,7 @@ function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) { $r = null; - if($profile) { + if ($profile) { $profile_int = intval($profile); $r = q("SELECT `contact`.`id` AS `contact_id`, `profile`.`uid` AS `profile_uid`, `profile`.*, `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.* @@ -202,7 +202,7 @@ function profile_sidebar($profile, $block = 0) { $address = false; // $pdesc = true; - if((! is_array($profile)) && (! count($profile))) + if ((! is_array($profile)) && (! count($profile))) return $o; $profile['picdate'] = urlencode($profile['picdate']); @@ -219,9 +219,9 @@ function profile_sidebar($profile, $block = 0) { $connect = (($profile['uid'] != local_user()) ? t('Connect') : False); // don't show connect link to authenticated visitors either - if(remote_user() && count($_SESSION['remote'])) { + if (remote_user() && count($_SESSION['remote'])) { foreach($_SESSION['remote'] as $visitor) { - if($visitor['uid'] == $profile['uid']) { + if ($visitor['uid'] == $profile['uid']) { $connect = false; break; } @@ -322,7 +322,7 @@ function profile_sidebar($profile, $block = 0) { // Fetch the account type $account_type = account_type($profile); - if((x($profile,'address') == 1) + if ((x($profile,'address') == 1) || (x($profile,'location') == 1) || (x($profile,'locality') == 1) || (x($profile,'region') == 1) @@ -341,7 +341,7 @@ function profile_sidebar($profile, $block = 0) { $xmpp = ((x($profile,'xmpp') == 1) ? t('XMPP:') : False); - if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) { + if (($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) { $location = $pdesc = $gender = $marital = $homepage = $about = False; } @@ -368,7 +368,7 @@ function profile_sidebar($profile, $block = 0) { if (!$block){ $contact_block = contact_block(); - if(is_array($a->profile) AND !$a->profile['hide-friends']) { + if (is_array($a->profile) AND !$a->profile['hide-friends']) { $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1", intval($a->profile['uid'])); if (dbm::is_result($r)) @@ -406,7 +406,7 @@ function profile_sidebar($profile, $block = 0) { if (isset($p["photo"])) $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL); - if($a->theme['template_engine'] === 'internal') + if ($a->theme['template_engine'] === 'internal') $location = template_escape($location); $tpl = get_markup_template('profile_vcard.tpl'); @@ -445,13 +445,13 @@ function get_birthdays() { $a = get_app(); $o = ''; - if(! local_user() || $a->is_mobile || $a->is_tablet) + if (! local_user() || $a->is_mobile || $a->is_tablet) return $o; // $mobile_detect = new Mobile_Detect(); // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet(); -// if($is_mobile) +// if ($is_mobile) // return $o; $bd_format = t('g A l F d') ; // 8 AM Friday January 18 @@ -479,27 +479,27 @@ function get_birthdays() { $istoday = false; foreach ($r as $rr) { - if(strlen($rr['name'])) + if (strlen($rr['name'])) $total ++; - if((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) + if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) $istoday = true; } $classtoday = $istoday ? ' birthday-today ' : ''; - if($total) { + if ($total) { foreach($r as &$rr) { - if(! strlen($rr['name'])) + if (! strlen($rr['name'])) continue; // avoid duplicates - if(in_array($rr['cid'],$cids)) + if (in_array($rr['cid'],$cids)) continue; $cids[] = $rr['cid']; $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false); $sparkle = ''; $url = $rr['url']; - if($rr['network'] === NETWORK_DFRN) { + if ($rr['network'] === NETWORK_DFRN) { $sparkle = " sparkle"; $url = App::get_baseurl() . '/redir/' . $rr['cid']; } @@ -534,14 +534,14 @@ function get_events() { $a = get_app(); - if(! local_user() || $a->is_mobile || $a->is_tablet) + if (! local_user() || $a->is_mobile || $a->is_tablet) return $o; // $mobile_detect = new Mobile_Detect(); // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet(); -// if($is_mobile) +// if ($is_mobile) // return $o; $bd_format = t('g A l F d') ; // 8 AM Friday January 18 @@ -559,11 +559,11 @@ function get_events() { $now = strtotime('now'); $istoday = false; foreach ($r as $rr) { - if(strlen($rr['name'])) + if (strlen($rr['name'])) $total ++; $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d'); - if($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) + if ($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) $istoday = true; } $classtoday = (($istoday) ? 'event-today' : ''); @@ -573,16 +573,16 @@ function get_events() { foreach($r as &$rr) { $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8')); - if(strlen($title) > 35) + if (strlen($title) > 35) $title = substr($title,0,32) . '... '; $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... '; - if(! $description) + if (! $description) $description = t('[No description]'); $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']); - if(substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) { + if (substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) { $skip++; continue; } @@ -617,7 +617,7 @@ function advanced_profile(App $a) { '$title' => t('Profile') )); - if($a->profile['name']) { + if ($a->profile['name']) { $tpl = get_markup_template('profile_advanced.tpl'); @@ -625,10 +625,10 @@ function advanced_profile(App $a) { $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ; - if($a->profile['gender']) $profile['gender'] = array( t('Gender:'), $a->profile['gender'] ); + if ($a->profile['gender']) $profile['gender'] = array( t('Gender:'), $a->profile['gender'] ); - if(($a->profile['dob']) && ($a->profile['dob'] != '0000-00-00')) { + if (($a->profile['dob']) && ($a->profile['dob'] != '0000-00-00')) { $year_bd_format = t('j F, Y'); $short_bd_format = t('j F'); @@ -642,10 +642,10 @@ function advanced_profile(App $a) { } - if($age = age($a->profile['dob'],$a->profile['timezone'],'')) $profile['age'] = array( t('Age:'), $age ); + if ($age = age($a->profile['dob'],$a->profile['timezone'],'')) $profile['age'] = array( t('Age:'), $age ); - if($a->profile['marital']) $profile['marital'] = array( t('Status:'), $a->profile['marital']); + if ($a->profile['marital']) $profile['marital'] = array( t('Status:'), $a->profile['marital']); /// @TODO Maybe use x() here, plus below? if ($a->profile['with']) { @@ -850,14 +850,14 @@ function profile_tabs($a, $is_owner=False, $nickname=Null){ } function get_my_url() { - if(x($_SESSION,'my_url')) + if (x($_SESSION,'my_url')) return $_SESSION['my_url']; return false; } function zrl_init(App $a) { $tmp_str = get_my_url(); - if(validate_url($tmp_str)) { + if (validate_url($tmp_str)) { // Is it a DDoS attempt? // The check fetches the cached value from gprobe to reduce the load for this system @@ -878,16 +878,20 @@ function zrl_init(App $a) { } function zrl($s,$force = false) { - if(! strlen($s)) + if (! strlen($s)) { return $s; - if((! strpos($s,'/profile/')) && (! $force)) + } + if ((! strpos($s,'/profile/')) && (! $force)) { return $s; - if($force && substr($s,-1,1) !== '/') + } + if ($force && substr($s,-1,1) !== '/') { $s = $s . '/'; + } $achar = strpos($s,'?') ? '&' : '?'; $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; } @@ -907,9 +911,10 @@ function zrl($s,$force = false) { */ function get_theme_uid() { $uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0); - if(local_user()) { - if((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid)) + if (local_user()) { + if ((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid)) { return local_user(); + } } return $uid; diff --git a/include/items.php b/include/items.php index 24eb1b30f..03503f26a 100644 --- a/include/items.php +++ b/include/items.php @@ -60,7 +60,7 @@ function limit_body_size($body) { $img_start = strpos($orig_body, '[img'); $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false); - while(($img_st_close !== false) && ($img_end !== false)) { + while (($img_st_close !== false) && ($img_end !== false)) { $img_st_close++; // make it point to AFTER the closing bracket $img_end += $img_start; @@ -1681,7 +1681,7 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) { $img_start = strpos($orig_body, '[img'); $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); $img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false); - while( ($img_st_close !== false) && ($img_len !== false) ) { + while ( ($img_st_close !== false) && ($img_len !== false) ) { $img_st_close++; // make it point to AFTER the closing bracket $image = substr($orig_body, $img_start + $img_st_close, $img_len); @@ -2179,7 +2179,7 @@ function list_post_dates($uid, $wall) { // Starting with the current month, get the first and last days of every // month down to and including the month of the first post - while(substr($dnow, 0, 7) >= substr($dthen, 0, 7)) { + while (substr($dnow, 0, 7) >= substr($dthen, 0, 7)) { $dyear = intval(substr($dnow,0,4)); $dstart = substr($dnow,0,8) . '01'; $dend = substr($dnow,0,8) . get_dim(intval($dnow),intval(substr($dnow,5))); @@ -2208,7 +2208,7 @@ function posted_dates($uid,$wall) { $ret = array(); // Starting with the current month, get the first and last days of every // month down to and including the month of the first post - while(substr($dnow, 0, 7) >= substr($dthen, 0, 7)) { + while (substr($dnow, 0, 7) >= substr($dthen, 0, 7)) { $dstart = substr($dnow,0,8) . '01'; $dend = substr($dnow,0,8) . get_dim(intval($dnow),intval(substr($dnow,5))); $start_month = datetime_convert('','',$dstart,'Y-m-d'); diff --git a/include/lock.php b/include/lock.php index b3d488a35..a9cd7d643 100644 --- a/include/lock.php +++ b/include/lock.php @@ -2,9 +2,9 @@ // Provide some ability to lock a PHP function so that multiple processes // can't run the function concurrently -if(! function_exists('lock_function')) { +if (! function_exists('lock_function')) { function lock_function($fn_name, $block = true, $wait_sec = 2, $timeout = 30) { - if( $wait_sec == 0 ) + if ( $wait_sec == 0 ) $wait_sec = 2; // don't let the user pick a value that's likely to crash the system $got_lock = false; @@ -16,7 +16,7 @@ function lock_function($fn_name, $block = true, $wait_sec = 2, $timeout = 30) { dbesc($fn_name) ); - if((dbm::is_result($r)) AND (!$r[0]['locked'] OR (strtotime($r[0]['created']) < time() - 3600))) { + if ((dbm::is_result($r)) AND (!$r[0]['locked'] OR (strtotime($r[0]['created']) < time() - 3600))) { q("UPDATE `locks` SET `locked` = 1, `created` = '%s' WHERE `name` = '%s'", dbesc(datetime_convert()), dbesc($fn_name) @@ -34,10 +34,10 @@ function lock_function($fn_name, $block = true, $wait_sec = 2, $timeout = 30) { q("UNLOCK TABLES"); - if(($block) && (! $got_lock)) + if (($block) && (! $got_lock)) sleep($wait_sec); - } while(($block) && (! $got_lock) && ((time() - $start) < $timeout)); + } while (($block) && (! $got_lock) && ((time() - $start) < $timeout)); logger('lock_function: function ' . $fn_name . ' with blocking = ' . $block . ' got_lock = ' . $got_lock . ' time = ' . (time() - $start), LOGGER_DEBUG); @@ -45,28 +45,29 @@ function lock_function($fn_name, $block = true, $wait_sec = 2, $timeout = 30) { }} -if(! function_exists('block_on_function_lock')) { +if (! function_exists('block_on_function_lock')) { function block_on_function_lock($fn_name, $wait_sec = 2, $timeout = 30) { - if( $wait_sec == 0 ) + if ( $wait_sec == 0 ) $wait_sec = 2; // don't let the user pick a value that's likely to crash the system $start = time(); do { $r = q("SELECT locked FROM locks WHERE name = '%s' LIMIT 1", - 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); + } - } while(dbm::is_result($r) && $r[0]['locked'] && ((time() - $start) < $timeout)); + } while (dbm::is_result($r) && $r[0]['locked'] && ((time() - $start) < $timeout)); return; }} -if(! function_exists('unlock_function')) { +if (! function_exists('unlock_function')) { function unlock_function($fn_name) { $r = q("UPDATE `locks` SET `locked` = 0, `created` = '0000-00-00 00:00:00' WHERE `name` = '%s'", dbesc($fn_name) diff --git a/include/message.php b/include/message.php index 3d5d4d33a..b94190ca0 100644 --- a/include/message.php +++ b/include/message.php @@ -9,9 +9,9 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ $a = get_app(); - if(! $recipient) return -1; + if (! $recipient) return -1; - if(! strlen($subject)) + if (! strlen($subject)) $subject = t('[no subject]'); $me = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", @@ -22,7 +22,7 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ intval(local_user()) ); - if(! (count($me) && (count($contact)))) { + if (! (count($me) && (count($contact)))) { return -2; } @@ -34,7 +34,7 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ // look for any existing conversation structure - if(strlen($replyto)) { + if (strlen($replyto)) { $reply = true; $r = q("select convid from mail where uid = %d and ( uri = '%s' or `parent-uri` = '%s' ) limit 1", intval(local_user()), @@ -45,7 +45,7 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ $convid = $r[0]['convid']; } - if(! $convid) { + if (! $convid) { // create a new conversation @@ -78,12 +78,12 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ $convid = $r[0]['id']; } - if(! $convid) { + if (! $convid) { logger('send message: conversation not found.'); return -4; } - if(! strlen($replyto)) { + if (! strlen($replyto)) { $replyto = $convuri; } diff --git a/include/nav.php b/include/nav.php index fe4c50818..b184f1180 100644 --- a/include/nav.php +++ b/include/nav.php @@ -8,7 +8,7 @@ function nav(App $a) { * */ - if(!(x($a->page,'nav'))) + if (!(x($a->page,'nav'))) $a->page['nav'] = ''; $a->page['htmlhead'] .= replace_macros(get_markup_template('nav_head.tpl'), array()); @@ -136,7 +136,7 @@ function nav_info(App $a) if (strlen(get_config('system', 'singleuser'))) { $gdir = get_config('system', 'directory'); - if(strlen($gdir)) { + if (strlen($gdir)) { $gdirpath = zrl($gdir, true); } } elseif (get_config('system', 'community_page_style') == CP_USERS_ON_SERVER) { diff --git a/include/network.php b/include/network.php index f9d35c52c..2ec306472 100644 --- a/include/network.php +++ b/include/network.php @@ -78,7 +78,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { @curl_setopt($ch, CURLOPT_HEADER, true); - if(x($opts,"cookiejar")) { + if (x($opts,"cookiejar")) { curl_setopt($ch, CURLOPT_COOKIEJAR, $opts["cookiejar"]); curl_setopt($ch, CURLOPT_COOKIEFILE, $opts["cookiejar"]); } @@ -101,13 +101,13 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { @curl_setopt($ch, CURLOPT_RANGE, '0-'.$range); } - if(x($opts,'headers')){ + if (x($opts,'headers')){ @curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']); } - if(x($opts,'nobody')){ + if (x($opts,'nobody')){ @curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']); } - if(x($opts,'timeout')){ + if (x($opts,'timeout')){ @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); } else { $curl_time = intval(get_config('system','curl_timeout')); @@ -124,14 +124,14 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { } $prx = get_config('system','proxy'); - if(strlen($prx)) { + if (strlen($prx)) { @curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); @curl_setopt($ch, CURLOPT_PROXY, $prx); $prxusr = @get_config('system','proxyuser'); - if(strlen($prxusr)) + if (strlen($prxusr)) @curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxusr); } - if($binary) + if ($binary) @curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $a->set_curl_code(0); @@ -156,7 +156,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { // Pull out multiple headers, e.g. proxy and continuation headers // allow for HTTP/2.x without fixing code - while(preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/',$base)) { + while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/',$base)) { $chunk = substr($base,0,strpos($base,"\r\n\r\n")+4); $header .= $chunk; $base = substr($base,strlen($chunk)); @@ -166,7 +166,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { $a->set_curl_content_type($curl_info['content_type']); $a->set_curl_headers($header); - if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { + if ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { $new_location_info = @parse_url($curl_info["redirect_url"]); $old_location_info = @parse_url($curl_info["url"]); @@ -179,7 +179,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { if (preg_match('/(Location:|URI:)(.*?)\n/i', $header, $matches)) { $newurl = trim(array_pop($matches)); } - if(strpos($newurl,'/') === 0) + if (strpos($newurl,'/') === 0) $newurl = $old_location_info["scheme"]."://".$old_location_info["host"].$newurl; if (filter_var($newurl, FILTER_VALIDATE_URL)) { $redirects++; @@ -200,7 +200,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { $ret['return_code'] = $rc; $ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false); $ret['redirect_url'] = $url; - if(! $ret['success']) { + if (! $ret['success']) { $ret['error'] = curl_error($ch); $ret['debug'] = $curl_info; logger('z_fetch_url: error: ' . $url . ': ' . $ret['error'], LOGGER_DEBUG); @@ -208,7 +208,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { } $ret['body'] = substr($s,strlen($header)); $ret['header'] = $header; - if(x($opts,'debug')) { + if (x($opts,'debug')) { $ret['debug'] = $curl_info; } @curl_close($ch); @@ -237,7 +237,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) $a = get_app(); $ch = curl_init($url); - if(($redirects > 8) || (! $ch)) + if (($redirects > 8) || (! $ch)) return false; logger("post_url: start ".$url, LOGGER_DATA); @@ -248,7 +248,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) curl_setopt($ch, CURLOPT_POSTFIELDS,$params); curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent()); - if(intval($timeout)) { + if (intval($timeout)) { curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); } else { @@ -256,16 +256,16 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60)); } - if(defined('LIGHTTPD')) { - if(!is_array($headers)) { + if (defined('LIGHTTPD')) { + if (!is_array($headers)) { $headers = array('Expect:'); } else { - if(!in_array('Expect:', $headers)) { + if (!in_array('Expect:', $headers)) { array_push($headers, 'Expect:'); } } } - if($headers) + if ($headers) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $check_cert = get_config('system','verifyssl'); @@ -274,11 +274,11 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); } $prx = get_config('system','proxy'); - if(strlen($prx)) { + if (strlen($prx)) { curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); curl_setopt($ch, CURLOPT_PROXY, $prx); $prxusr = get_config('system','proxyuser'); - if(strlen($prxusr)) + if (strlen($prxusr)) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxusr); } @@ -300,17 +300,17 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) // Pull out multiple headers, e.g. proxy and continuation headers // allow for HTTP/2.x without fixing code - while(preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/',$base)) { + while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/',$base)) { $chunk = substr($base,0,strpos($base,"\r\n\r\n")+4); $header .= $chunk; $base = substr($base,strlen($chunk)); } - if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { + if ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { $matches = array(); preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); $newurl = trim(array_pop($matches)); - if(strpos($newurl,'/') === 0) + if (strpos($newurl,'/') === 0) $newurl = $old_location_info["scheme"] . "://" . $old_location_info["host"] . $newurl; if (filter_var($newurl, FILTER_VALIDATE_URL)) { $redirects++; @@ -341,7 +341,7 @@ function xml_status($st, $message = '') { $xml_message = ((strlen($message)) ? "\t" . xmlify($message) . "\r\n" : ''); - if($st) + if ($st) logger('xml_status returning non_zero: ' . $st . " message=" . $message); header( "Content-type: text/xml" ); @@ -369,12 +369,12 @@ function xml_status($st, $message = '') { */ function http_status_exit($val, $description = array()) { $err = ''; - if($val >= 400) { + if ($val >= 400) { $err = 'Error'; if (!isset($description["title"])) $description["title"] = $err." ".$val; } - if($val >= 200 && $val < 300) + if ($val >= 200 && $val < 300) $err = 'OK'; logger('http_status_exit ' . $val); @@ -400,20 +400,20 @@ function http_status_exit($val, $description = array()) { * @return boolean True if it's a valid URL, fals if something wrong with it */ function validate_url(&$url) { - if(get_config('system','disable_url_validation')) + if (get_config('system','disable_url_validation')) return true; // no naked subdomains (allow localhost for tests) - if(strpos($url,'.') === false && strpos($url,'/localhost/') === false) + if (strpos($url,'.') === false && strpos($url,'/localhost/') === false) return false; - if(substr($url,0,4) != 'http') + if (substr($url,0,4) != 'http') $url = 'http://' . $url; /// @TODO Really supress function outcomes? Why not find them + debug them? $h = @parse_url($url); - if((is_array($h)) && (dns_get_record($h['host'], DNS_A + DNS_CNAME + DNS_PTR) || filter_var($h['host'], FILTER_VALIDATE_IP) )) { + if ((is_array($h)) && (dns_get_record($h['host'], DNS_A + DNS_CNAME + DNS_PTR) || filter_var($h['host'], FILTER_VALIDATE_IP) )) { return true; } @@ -428,14 +428,14 @@ function validate_url(&$url) { */ function validate_email($addr) { - if(get_config('system','disable_email_validation')) + if (get_config('system','disable_email_validation')) return true; - if(! strpos($addr,'@')) + if (! strpos($addr,'@')) return false; $h = substr($addr,strpos($addr,'@') + 1); - if(($h) && (dns_get_record($h, DNS_A + DNS_CNAME + DNS_PTR + DNS_MX) || filter_var($h, FILTER_VALIDATE_IP) )) { + if (($h) && (dns_get_record($h, DNS_A + DNS_CNAME + DNS_PTR + DNS_MX) || filter_var($h, FILTER_VALIDATE_IP) )) { return true; } return false; @@ -454,12 +454,12 @@ function allowed_url($url) { $h = @parse_url($url); - if(! $h) { + if (! $h) { return false; } $str_allowed = get_config('system','allowed_sites'); - if(! $str_allowed) + if (! $str_allowed) return true; $found = false; @@ -468,16 +468,16 @@ function allowed_url($url) { // always allow our own site - if($host == strtolower($_SERVER['SERVER_NAME'])) + if ($host == strtolower($_SERVER['SERVER_NAME'])) return true; $fnmatch = function_exists('fnmatch'); $allowed = explode(',',$str_allowed); - if(count($allowed)) { + if (count($allowed)) { foreach($allowed as $a) { $pat = strtolower(trim($a)); - if(($fnmatch && fnmatch($pat,$host)) || ($pat == $host)) { + if (($fnmatch && fnmatch($pat,$host)) || ($pat == $host)) { $found = true; break; } @@ -499,11 +499,11 @@ function allowed_email($email) { $domain = strtolower(substr($email,strpos($email,'@') + 1)); - if(! $domain) + if (! $domain) return false; $str_allowed = get_config('system','allowed_email'); - if(! $str_allowed) + if (! $str_allowed) return true; $found = false; @@ -511,10 +511,10 @@ function allowed_email($email) { $fnmatch = function_exists('fnmatch'); $allowed = explode(',',$str_allowed); - if(count($allowed)) { + if (count($allowed)) { foreach($allowed as $a) { $pat = strtolower(trim($a)); - if(($fnmatch && fnmatch($pat,$domain)) || ($pat == $domain)) { + if (($fnmatch && fnmatch($pat,$domain)) || ($pat == $domain)) { $found = true; break; } @@ -543,8 +543,8 @@ function avatar_img($email) { function parse_xml_string($s,$strict = true) { /// @todo Move this function to the xml class - if($strict) { - if(! strstr($s,'user = $record; - if(strlen($a->user['timezone'])) { + if (strlen($a->user['timezone'])) { date_default_timezone_set($a->user['timezone']); $a->timezone = $a->user['timezone']; } diff --git a/include/oembed.php b/include/oembed.php index a1945894f..2490e5eca 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -316,7 +316,9 @@ function oembed_html2bbcode($text) { $xattr = "@rel='oembed'";//oe_build_xpath("rel","oembed"); foreach($entries as $e) { $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) ); } else { diff --git a/include/onepoll.php b/include/onepoll.php index 43c4495b6..e6cbd34f4 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -61,7 +61,7 @@ function onepoll_run(&$argv, &$argc){ intval($contact_id) ); - if (! count($contacts)) { + if (! dbm::is_result($contacts)) { return; } diff --git a/include/ostatus.php b/include/ostatus.php index d20e4cb4f..26be15a02 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -411,7 +411,7 @@ class ostatus { foreach ($category->attributes AS $attributes) if ($attributes->name == "term") { $term = $attributes->textContent; - if(strlen($item["tag"])) + if (strlen($item["tag"])) $item["tag"] .= ','; $item["tag"] .= "#[url=".App::get_baseurl()."/search?tag=".$term."]".$term."[/url]"; } @@ -454,7 +454,7 @@ class ostatus { break; case "enclosure": $enclosure = $href; - if(strlen($item["attach"])) + if (strlen($item["attach"])) $item["attach"] .= ','; $item["attach"] .= '[attach]href="'.$href.'" length="'.$length.'" type="'.$type.'" title="'.$title.'"[/attach]'; @@ -1138,7 +1138,7 @@ class ostatus { continue; } - /// @TODO One statment is okay (until if() ) + /// @TODO One statment is okay (until if () ) $arr = array(); $arr["network"] = $details["network"]; $arr["uri"] = $single_conv->id; @@ -2234,7 +2234,7 @@ class ostatus { $owner = $r[0]; - if(!strlen($last_update)) + if (!strlen($last_update)) $last_update = 'now -30 days'; $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s'); diff --git a/include/pgettext.php b/include/pgettext.php index 335869eda..21d95e324 100644 --- a/include/pgettext.php +++ b/include/pgettext.php @@ -14,7 +14,7 @@ use \Friendica\Core\Config; require_once("include/dba.php"); -if(! function_exists('get_browser_language')) { +if (! function_exists('get_browser_language')) { /** * @brief get the prefered language from the HTTP_ACCEPT_LANGUAGE header */ @@ -44,7 +44,7 @@ function get_browser_language() { // check if we have translations for the preferred languages and pick the 1st that has for ($i=0; $ilangsave = $lang; - if($language === $lang) + if ($language === $lang) return; - if(isset($a->strings) && count($a->strings)) { + if (isset($a->strings) && count($a->strings)) { $a->stringsave = $a->strings; } $a->strings = array(); @@ -77,10 +77,10 @@ function push_lang($language) { function pop_lang() { global $lang, $a; - if($lang === $a->langsave) + if ($lang === $a->langsave) return; - if(isset($a->stringsave)) + if (isset($a->stringsave)) $a->strings = $a->stringsave; else $a->strings = array(); @@ -91,7 +91,7 @@ function pop_lang() { // l -if(! function_exists('load_translation_table')) { +if (! function_exists('load_translation_table')) { /** * load string translation table for alternate language * @@ -108,13 +108,13 @@ function load_translation_table($lang) { if ($plugins!==false) { foreach($plugins as $p) { $name = $p['name']; - if(file_exists("addon/$name/lang/$lang/strings.php")) { + if (file_exists("addon/$name/lang/$lang/strings.php")) { include("addon/$name/lang/$lang/strings.php"); } } } - if(file_exists("view/lang/$lang/strings.php")) { + if (file_exists("view/lang/$lang/strings.php")) { include("view/lang/$lang/strings.php"); } @@ -122,27 +122,27 @@ function load_translation_table($lang) { // translate string if translation exists -if(! function_exists('t')) { +if (! function_exists('t')) { function t($s) { $a = get_app(); - if(x($a->strings,$s)) { + if (x($a->strings,$s)) { $t = $a->strings[$s]; return is_array($t)?$t[0]:$t; } return $s; }} -if(! function_exists('tt')){ +if (! function_exists('tt')){ function tt($singular, $plural, $count){ global $lang; $a = get_app(); - if(x($a->strings,$singular)) { + if (x($a->strings,$singular)) { $t = $a->strings[$singular]; $f = 'string_plural_select_' . str_replace('-','_',$lang); - if(! function_exists($f)) + if (! function_exists($f)) $f = 'string_plural_select_default'; $k = $f($count); return is_array($t)?$t[$k]:$t; @@ -158,7 +158,7 @@ function tt($singular, $plural, $count){ // provide a fallback which will not collide with // a function defined in any language file -if(! function_exists('string_plural_select_default')) { +if (! function_exists('string_plural_select_default')) { function string_plural_select_default($n) { return ($n != 1); }} diff --git a/include/plugin.php b/include/plugin.php index 83f6f1ab9..c75441bf9 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -20,7 +20,7 @@ function uninstall_plugin($plugin){ ); @include_once('addon/' . $plugin . '/' . $plugin . '.php'); - if(function_exists($plugin . '_uninstall')) { + if (function_exists($plugin . '_uninstall')) { $func = $plugin . '_uninstall'; $func(); } @@ -36,12 +36,12 @@ if (! function_exists('install_plugin')){ function install_plugin($plugin) { // silently fail if plugin was removed - if(! file_exists('addon/' . $plugin . '/' . $plugin . '.php')) + if (! file_exists('addon/' . $plugin . '/' . $plugin . '.php')) return false; logger("Addons: installing " . $plugin); $t = @filemtime('addon/' . $plugin . '/' . $plugin . '.php'); @include_once('addon/' . $plugin . '/' . $plugin . '.php'); - if(function_exists($plugin . '_install')) { + if (function_exists($plugin . '_install')) { $func = $plugin . '_install'; $func(); @@ -57,7 +57,7 @@ function install_plugin($plugin) { // once most site tables have been updated. // This way the system won't fall over dead during the update. - if(file_exists('addon/' . $plugin . '/.hidden')) { + if (file_exists('addon/' . $plugin . '/.hidden')) { q("UPDATE `addon` SET `hidden` = 1 WHERE `name` = '%s'", dbesc($plugin) ); @@ -73,10 +73,10 @@ function install_plugin($plugin) { // reload all updated plugins -if(! function_exists('reload_plugins')) { +if (! function_exists('reload_plugins')) { function reload_plugins() { $plugins = get_config('system','addon'); - if(strlen($plugins)) { + if (strlen($plugins)) { $r = q("SELECT * FROM `addon` WHERE `installed` = 1"); if (dbm::is_result($r)) @@ -86,25 +86,25 @@ function reload_plugins() { $parr = explode(',',$plugins); - if(count($parr)) { + if (count($parr)) { foreach($parr as $pl) { $pl = trim($pl); $fname = 'addon/' . $pl . '/' . $pl . '.php'; - if(file_exists($fname)) { + if (file_exists($fname)) { $t = @filemtime($fname); foreach($installed as $i) { - if(($i['name'] == $pl) && ($i['timestamp'] != $t)) { + if (($i['name'] == $pl) && ($i['timestamp'] != $t)) { logger('Reloading plugin: ' . $i['name']); @include_once($fname); - if(function_exists($pl . '_uninstall')) { + if (function_exists($pl . '_uninstall')) { $func = $pl . '_uninstall'; $func(); } - if(function_exists($pl . '_install')) { + if (function_exists($pl . '_install')) { $func = $pl . '_install'; $func(); } @@ -142,7 +142,7 @@ function plugin_enabled($plugin) { * @param int $priority A priority (defaults to 0) * @return mixed|bool */ -if(! function_exists('register_hook')) { +if (! function_exists('register_hook')) { function register_hook($hook,$file,$function,$priority=0) { $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1", @@ -170,7 +170,7 @@ function register_hook($hook,$file,$function,$priority=0) { * @param string $function the name of the function that the hook called * @return array */ -if(! function_exists('unregister_hook')) { +if (! function_exists('unregister_hook')) { function unregister_hook($hook,$file,$function) { $r = q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s'", @@ -182,7 +182,7 @@ function unregister_hook($hook,$file,$function) { }} -if(! function_exists('load_hooks')) { +if (! function_exists('load_hooks')) { function load_hooks() { $a = get_app(); $a->hooks = array(); @@ -190,7 +190,7 @@ function load_hooks() { if (dbm::is_result($r)) { foreach ($r as $rr) { - if(! array_key_exists($rr['hook'],$a->hooks)) + if (! array_key_exists($rr['hook'],$a->hooks)) $a->hooks[$rr['hook']] = array(); $a->hooks[$rr['hook']][] = array($rr['file'],$rr['function']); } @@ -244,13 +244,13 @@ function call_single_hook($a, $name, $hook, &$data = null) { //check if an app_menu hook exist for plugin $name. //Return true if the plugin is an app -if(! function_exists('plugin_is_app')) { +if (! function_exists('plugin_is_app')) { function plugin_is_app($name) { $a = get_app(); - if(is_array($a->hooks) && (array_key_exists('app_menu',$a->hooks))) { + if (is_array($a->hooks) && (array_key_exists('app_menu',$a->hooks))) { foreach($a->hooks['app_menu'] as $hook) { - if($hook[0] == 'addon/'.$name.'/'.$name.'.php') + if ($hook[0] == 'addon/'.$name.'/'.$name.'.php') return true; } } @@ -352,9 +352,9 @@ function get_theme_info($theme){ 'unsupported' => false ); - if(file_exists("view/theme/$theme/experimental")) + if (file_exists("view/theme/$theme/experimental")) $info['experimental'] = true; - if(file_exists("view/theme/$theme/unsupported")) + if (file_exists("view/theme/$theme/unsupported")) $info['unsupported'] = true; if (!is_file("view/theme/$theme/theme.php")) return $info; @@ -511,11 +511,11 @@ function service_class_fetch($uid,$property) { $service_class = $r[0]['service_class']; } } - if(! x($service_class)) + if (! x($service_class)) return false; // everything is allowed $arr = get_config('service_class',$service_class); - if(! is_array($arr) || (! count($arr))) + if (! is_array($arr) || (! count($arr))) return false; return((array_key_exists($property,$arr)) ? $arr[$property] : false); @@ -524,12 +524,14 @@ function service_class_fetch($uid,$property) { function upgrade_link($bbcode = false) { $l = get_config('service_class','upgrade_link'); - if(! $l) + if (! $l) { return ''; - if($bbcode) + } + if ($bbcode) { $t = sprintf('[url=%s]' . t('Click here to upgrade.') . '[/url]', $l); - else + } else { $t = sprintf('' . t('Click here to upgrade.') . '
', $l); + } return $t; } @@ -556,13 +558,15 @@ function upgrade_bool_message($bbcode = false) { */ function theme_include($file, $root = '') { // 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 . '/'; + } $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']; - else + } else { $parent = 'NOPATH'; + } $theme = current_theme(); $thname = $theme; $ext = substr($file,strrpos($file,'.')+1); @@ -573,10 +577,11 @@ function theme_include($file, $root = '') { ); 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) - if(strpos($p,'NOPATH') !== false) + if (strpos($p,'NOPATH') !== false) { continue; - if(file_exists($p)) + } elseif (file_exists($p)) { return $p; + } } return ''; } diff --git a/include/poller.php b/include/poller.php index 855400ba6..b9dadb1fc 100644 --- a/include/poller.php +++ b/include/poller.php @@ -17,11 +17,11 @@ require_once("boot.php"); function poller_run($argv, $argc){ global $a, $db; - if(is_null($a)) { + if (is_null($a)) { $a = new App; } - if(is_null($db)) { + if (is_null($db)) { @include(".htconfig.php"); require_once("include/dba.php"); $db = new dba($db_host, $db_user, $db_pass, $db_data); @@ -49,7 +49,7 @@ function poller_run($argv, $argc){ return; } - if(($argc <= 1) OR ($argv[1] != "no_cron")) { + if (($argc <= 1) OR ($argv[1] != "no_cron")) { poller_run_cron(); } @@ -415,7 +415,7 @@ function poller_too_much_workers() { // Decrease the number of workers at higher load $load = current_load(); - if($load) { + if ($load) { $maxsysload = intval(Config::get("system", "maxloadavg", 50)); $maxworkers = $queues; diff --git a/include/profile_selectors.php b/include/profile_selectors.php index 8d29fd099..ad47c0ba6 100644 --- a/include/profile_selectors.php +++ b/include/profile_selectors.php @@ -9,7 +9,7 @@ function gender_selector($current="",$suffix="") { $o .= ""; foreach($select as $selection) { - if($selection !== 'NOTRANSLATION') { + if ($selection !== 'NOTRANSLATION') { $selected = (($selection == $current) ? ' selected="selected" ' : ''); $o .= ""; } @@ -45,7 +45,7 @@ function marital_selector($current="",$suffix="") { $o .= ""; - foreach($select as $selection) { + foreach ($select as $selection) { if ($selection !== 'NOTRANSLATION') { $selected = (($selection == $current) ? ' selected="selected" ' : ''); $o .= ""; @@ -26,7 +26,7 @@ function sexpref_selector($current="",$suffix="") { call_hooks('sexpref_selector', $select); $o .= ""; - foreach($select as $selection) { + foreach ($select as $selection) { if ($selection !== 'NOTRANSLATION') { $selected = (($selection == $current) ? ' selected="selected" ' : ''); $o .= ""; diff --git a/include/salmon.php b/include/salmon.php index 4dd371746..386a1de99 100644 --- a/include/salmon.php +++ b/include/salmon.php @@ -11,13 +11,12 @@ function get_salmon_key($uri,$keyhash) { $arr = Probe::lrdd($uri); if (is_array($arr)) { - foreach($arr as $a) { + foreach ($arr as $a) { if ($a['@attributes']['rel'] === 'magic-public-key') { $ret[] = $a['@attributes']['href']; } } - } - else { + } else { return ''; } diff --git a/include/security.php b/include/security.php index 73733cbd5..6049700a3 100644 --- a/include/security.php +++ b/include/security.php @@ -276,7 +276,7 @@ function permissions_sql($owner_id,$remote_verified = false,$groups = null) { $gs = '<<>>'; // should be impossible to match if (is_array($groups) && count($groups)) { - foreach($groups as $g) + foreach ($groups as $g) $gs .= '|<' . intval($g) . '>'; } @@ -358,7 +358,7 @@ function item_permissions_sql($owner_id,$remote_verified = false,$groups = null) $gs = '<<>>'; // should be impossible to match if (is_array($groups) && count($groups)) { - foreach($groups as $g) + foreach ($groups as $g) $gs .= '|<' . intval($g) . '>'; } @@ -460,7 +460,7 @@ function init_groups_visitor($contact_id) { intval($contact_id) ); if (dbm::is_result($r)) { - foreach($r as $rr) + foreach ($r as $rr) $groups[] = $rr['gid']; } return $groups; diff --git a/include/socgraph.php b/include/socgraph.php index e74c9adf0..ec7446cdc 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -73,7 +73,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { return; $total = 0; - foreach($j->entry as $entry) { + foreach ($j->entry as $entry) { $total ++; $profile_url = ''; @@ -137,7 +137,7 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) { } if (isset($entry->tags)) { - foreach($entry->tags as $tag) { + foreach ($entry->tags as $tag) { $keywords = implode(", ", $tag); } } @@ -1647,20 +1647,22 @@ function poco_discover_federation() { } } - // Currently disabled, since the service isn't available anymore. - // It is not removed since I hope that there will be a successor. - // Discover GNU Social Servers. - //if (!get_config('system','ostatus_disabled')) { - // $serverdata = "http://gstools.org/api/get_open_instances/"; + /* + * Currently disabled, since the service isn't available anymore. + * It is not removed since I hope that there will be a successor. + * Discover GNU Social Servers. + if (!get_config('system','ostatus_disabled')) { + $serverdata = "http://gstools.org/api/get_open_instances/"; - // $result = z_fetch_url($serverdata); - // if ($result["success"]) { - // $servers = json_decode($result["body"]); + $result = z_fetch_url($serverdata); + if ($result["success"]) { + $servers = json_decode($result["body"]); - // foreach($servers->data AS $server) - // poco_check_server($server->instance_address); - // } - //} + foreach($servers->data AS $server) + poco_check_server($server->instance_address); + } + } + */ set_config('poco','last_federation_discovery', time()); } @@ -1749,7 +1751,7 @@ function poco_discover_server_users($data, $server) { foreach ($data->entry AS $entry) { $username = ""; if (isset($entry->urls)) { - foreach($entry->urls as $url) + foreach ($entry->urls as $url) if ($url->type == 'profile') { $profile_url = $url->value; $urlparts = parse_url($profile_url); @@ -1793,7 +1795,7 @@ function poco_discover_server($data, $default_generation = 0) { $name = $entry->displayName; if (isset($entry->urls)) { - foreach($entry->urls as $url) { + foreach ($entry->urls as $url) { if ($url->type == 'profile') { $profile_url = $url->value; continue; diff --git a/include/template_processor.php b/include/template_processor.php index 4fb7f6d8f..252375a06 100644 --- a/include/template_processor.php +++ b/include/template_processor.php @@ -95,7 +95,7 @@ class Template implements ITemplateEngine { * {{ for <$var> as $name }}...{{ endfor }} * {{ for <$var> as $key=>$name }}...{{ endfor }} */ - private function _replcb_for($args) { + private function _replcb_for ($args) { $m = array_map('trim', explode(" as ", $args[2])); $x = explode("=>", $m[1]); if (count($x) == 1) { @@ -109,14 +109,16 @@ class Template implements ITemplateEngine { //$vals = $this->r[$m[0]]; $vals = $this->_get_var($m[0]); $ret = ""; - if (!is_array($vals)) + if (!is_array($vals)) { return $ret; + } foreach ($vals as $k => $v) { $this->_push_stack(); $r = $this->r; $r[$varname] = $v; - if ($keyname != '') + if ($keyname != '') { $r[$keyname] = (($k === 0) ? '0' : $k); + } $ret .= $this->replace($args[3], $r); $this->_pop_stack(); } diff --git a/include/text.php b/include/text.php index 7219526c8..2f2f1b320 100644 --- a/include/text.php +++ b/include/text.php @@ -163,7 +163,7 @@ function autoname($len) { $word = substr($word,0,$len); - foreach($noend as $noe) { + foreach ($noend as $noe) { if ((strlen($word) > 2) && (substr($word,-2) == $noe)) { $word = substr($word,0,-1); break; @@ -188,7 +188,7 @@ function xmlify($str) { /* $buffer = ''; $len = mb_strlen($str); - for($x = 0; $x < $len; $x ++) { + for ($x = 0; $x < $len; $x ++) { $char = mb_substr($str,$x,1); switch( $char ) { @@ -420,7 +420,7 @@ function expand_acl($s) { if (strlen($s)) { $t = str_replace('<','',$s); $a = explode('>',$t); - foreach($a as $aa) { + foreach ($a as $aa) { if (intval($aa)) $ret[] = intval($aa); } @@ -817,7 +817,7 @@ function get_tags($string) { // and #hash tags. if (preg_match_all('/([!#@][^\^ \x0D\x0A,;:?]+)([ \x0D\x0A,;:?]|$)/', $string, $matches)) { - foreach($matches[1] as $match) { + foreach ($matches[1] as $match) { if (strstr($match, ']')) { // we might be inside a bbcode color tag - leave it alone continue; @@ -1249,7 +1249,7 @@ function prepare_body(&$item,$attach = false, $preview = false) { $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`", intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION)); - foreach($taglist as $tag) { + foreach ($taglist as $tag) { if ($tag["url"] == "") $tag["url"] = $searchpath.strtolower($tag["term"]); @@ -1295,12 +1295,12 @@ function prepare_body(&$item,$attach = false, $preview = false) { $arr = explode('[/attach],',$item['attach']); if (count($arr)) { $as .= '
'; - foreach($arr as $r) { + foreach ($arr as $r) { $matches = false; $icon = ''; $cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches, PREG_SET_ORDER); if ($cnt) { - foreach($matches as $mtch) { + foreach ($matches as $mtch) { $mime = $mtch[3]; if ((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) @@ -1475,7 +1475,7 @@ function get_cats_and_terms($item) { $matches = false; $first = true; $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER); if ($cnt) { - foreach($matches as $mtch) { + foreach ($matches as $mtch) { $categories[] = array( 'name' => xmlify(file_tag_decode($mtch[1])), 'url' => "#", @@ -1493,7 +1493,7 @@ function get_cats_and_terms($item) { $matches = false; $first = true; $cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER); if ($cnt) { - foreach($matches as $mtch) { + foreach ($matches as $mtch) { $folders[] = array( 'name' => xmlify(file_tag_decode($mtch[1])), 'url' => "#", @@ -1719,7 +1719,7 @@ function bb_translate_video($s) { $matches = null; $r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER); if ($r) { - foreach($matches as $mtch) { + 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')) @@ -1847,7 +1847,7 @@ function file_tag_list_to_file($list,$type = 'file') { $rbracket = '>'; } - foreach($list_array as $item) { + foreach ($list_array as $item) { if (strlen($item)) { $tag_list .= $lbracket . file_tag_encode(trim($item)) . $rbracket; } @@ -1867,7 +1867,7 @@ function file_tag_file_to_list($file,$type = 'file') { $cnt = preg_match_all('/<(.*?)>/',$file,$matches,PREG_SET_ORDER); } if ($cnt) { - foreach($matches as $mtch) { + foreach ($matches as $mtch) { if (strlen($list)) $list .= ','; $list .= file_tag_decode($mtch[1]); @@ -1906,7 +1906,7 @@ function file_tag_update_pconfig($uid,$file_old,$file_new,$type = 'file') { $new_tags = array(); $check_new_tags = explode(",",file_tag_file_to_list($file_new,$type)); - foreach($check_new_tags as $tag) { + foreach ($check_new_tags as $tag) { if (! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket)) $new_tags[] = $tag; } @@ -1917,12 +1917,12 @@ function file_tag_update_pconfig($uid,$file_old,$file_new,$type = 'file') { $deleted_tags = array(); $check_deleted_tags = explode(",",file_tag_file_to_list($file_old,$type)); - foreach($check_deleted_tags as $tag) { + foreach ($check_deleted_tags as $tag) { if (! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket)) $deleted_tags[] = $tag; } - foreach($deleted_tags as $key => $tag) { + foreach ($deleted_tags as $key => $tag) { $r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d", dbesc($tag), intval(TERM_OBJ_POST), @@ -2039,7 +2039,7 @@ function undo_post_tagging($s) { $matches = null; $cnt = preg_match_all('/([!#@])\[url=(.*?)\](.*?)\[\/url\]/ism',$s,$matches,PREG_SET_ORDER); if ($cnt) { - foreach($matches as $mtch) { + foreach ($matches as $mtch) { $s = str_replace($mtch[0], $mtch[1] . $mtch[3],$s); } } diff --git a/include/xml.php b/include/xml.php index 4aeb56398..911109f0c 100644 --- a/include/xml.php +++ b/include/xml.php @@ -50,7 +50,7 @@ class xml { } } - foreach($array as $key => $value) { + foreach ($array as $key => $value) { if (!isset($element) AND isset($xml)) { $element = $xml; } From c2d8738285d24edad48ff04880f236f802fba4be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Fri, 27 Jan 2017 11:53:56 +0100 Subject: [PATCH 28/65] added spaces (coding convention) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- object/BaseObject.php | 6 +- object/Conversation.php | 25 ++- object/Item.php | 23 ++- tests/contains_attribute_test.php | 82 ++++---- tests/expand_acl_test.php | 198 +++++++++--------- tests/get_tags_test.php | 16 +- tests/template_test.php | 260 ++++++++++++------------ tests/xss_filter_test.php | 16 +- view/theme/frio/php/PHPColors/Color.php | 32 +-- view/theme/frio/theme.php | 4 +- view/theme/frost/theme.php | 4 +- 11 files changed, 336 insertions(+), 330 deletions(-) diff --git a/object/BaseObject.php b/object/BaseObject.php index 2666dc1de..5e0c61f49 100644 --- a/object/BaseObject.php +++ b/object/BaseObject.php @@ -1,6 +1,7 @@ get_mode() == $mode) + if ($this->get_mode() == $mode) return; $a = $this->get_app(); @@ -92,11 +93,11 @@ class Conversation extends BaseObject { */ public function add_thread($item) { $item_id = $item->get_id(); - if(!$item_id) { + if (!$item_id) { logger('[ERROR] Conversation::add_thread : Item has no ID!!', LOGGER_DEBUG); return false; } - if($this->get_thread($item->get_id())) { + if ($this->get_thread($item->get_id())) { logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG); return false; } @@ -104,11 +105,11 @@ class Conversation extends BaseObject { /* * Only add will be displayed */ - if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) { + if ($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) { logger('[WARN] Conversation::add_thread : Thread is a mail ('. $item->get_id() .').', LOGGER_DEBUG); return false; } - if($item->get_data_value('verb') === ACTIVITY_LIKE || $item->get_data_value('verb') === ACTIVITY_DISLIKE) { + if ($item->get_data_value('verb') === ACTIVITY_LIKE || $item->get_data_value('verb') === ACTIVITY_DISLIKE) { logger('[WARN] Conversation::add_thread : Thread is a (dis)like ('. $item->get_id() .').', LOGGER_DEBUG); return false; } @@ -132,13 +133,14 @@ class Conversation extends BaseObject { $i = 0; - foreach($this->threads as $item) { - if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) + foreach ($this->threads as $item) { + if ($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) { continue; + } $item_data = $item->get_template_data($conv_responses); - if(!$item_data) { + if (!$item_data) { logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG); return false; } @@ -156,9 +158,10 @@ class Conversation extends BaseObject { * _ false on failure */ private function get_thread($id) { - foreach($this->threads as $item) { - if($item->get_id() == $id) + foreach ($this->threads as $item) { + if ($item->get_id() == $id) { return $item; + } } return false; diff --git a/object/Item.php b/object/Item.php index b693520b9..ab36069c0 100644 --- a/object/Item.php +++ b/object/Item.php @@ -1,6 +1,7 @@ get_profile_owner(),'commtag')) { + if (feature_enabled($conv->get_profile_owner(),'commtag')) { $tagger = array( 'add' => t("add tag"), 'class' => "", @@ -503,7 +504,7 @@ class Item extends BaseObject { */ protected function set_parent($item) { $parent = $this->get_parent(); - if($parent) { + if ($parent) { $parent->remove_child($this); } $this->parent = $item; @@ -734,9 +735,9 @@ class Item extends BaseObject { $conv = $this->get_conversation(); $this->wall_to_wall = false; - if($this->is_toplevel()) { - if($conv->get_mode() !== 'profile') { - if($this->get_data_value('wall') AND !$this->get_data_value('self')) { + if ($this->is_toplevel()) { + if ($conv->get_mode() !== 'profile') { + if ($this->get_data_value('wall') AND !$this->get_data_value('self')) { // On the network page, I am the owner. On the display page it will be the profile owner. // This will have been stored in $a->page_contact by our calling page. // Put this person as the wall owner of the wall-to-wall notice. @@ -745,7 +746,7 @@ class Item extends BaseObject { $this->owner_photo = $a->page_contact['thumb']; $this->owner_name = $a->page_contact['name']; $this->wall_to_wall = true; - } elseif($this->get_data_value('owner-link')) { + } elseif ($this->get_data_value('owner-link')) { $owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link'))); $alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link'))); diff --git a/tests/contains_attribute_test.php b/tests/contains_attribute_test.php index b0bb06acf..b1e87c17a 100644 --- a/tests/contains_attribute_test.php +++ b/tests/contains_attribute_test.php @@ -1,51 +1,51 @@ assertTrue(attribute_contains($testAttr, "class3")); - $this->assertFalse(attribute_contains($testAttr, "class2")); - } - - /** - * test attribute contains - */ - public function testAttributeContains2() { - $testAttr="class1 not-class2 class3"; - $this->assertTrue(attribute_contains($testAttr, "class3")); - $this->assertFalse(attribute_contains($testAttr, "class2")); - } + /** + * test attribute contains + */ + public function testAttributeContains1() { + $testAttr="class1 notclass2 class3"; + $this->assertTrue(attribute_contains($testAttr, "class3")); + $this->assertFalse(attribute_contains($testAttr, "class2")); + } + + /** + * test attribute contains + */ + public function testAttributeContains2() { + $testAttr="class1 not-class2 class3"; + $this->assertTrue(attribute_contains($testAttr, "class3")); + $this->assertFalse(attribute_contains($testAttr, "class2")); + } /** * test with empty input - */ - public function testAttributeContainsEmpty() { - $testAttr=""; - $this->assertFalse(attribute_contains($testAttr, "class2")); - } + */ + public function testAttributeContainsEmpty() { + $testAttr=""; + $this->assertFalse(attribute_contains($testAttr, "class2")); + } /** * test input with special chars - */ - public function testAttributeContainsSpecialChars() { - $testAttr="--... %\$ä() /(=?}"; - $this->assertFalse(attribute_contains($testAttr, "class2")); + */ + public function testAttributeContainsSpecialChars() { + $testAttr="--... %\$ä() /(=?}"; + $this->assertFalse(attribute_contains($testAttr, "class2")); } } \ No newline at end of file diff --git a/tests/expand_acl_test.php b/tests/expand_acl_test.php index 154bc921d..7059fbc0d 100644 --- a/tests/expand_acl_test.php +++ b/tests/expand_acl_test.php @@ -8,141 +8,141 @@ /** required, it is the file under test */ require_once('include/text.php'); -/** - * TestCase for the expand_acl function - * - * @author Alexander Kampmann - * @package test.util - */ +/** + * TestCase for the expand_acl function + * + * @author Alexander Kampmann + * @package test.util + */ class ExpandAclTest extends PHPUnit_Framework_TestCase { - /** - * test expand_acl, perfect input - */ - public function testExpandAclNormal() { - $text='<1><2><3>'; - $this->assertEquals(array(1, 2, 3), expand_acl($text)); - } + /** + * test expand_acl, perfect input + */ + public function testExpandAclNormal() { + $text='<1><2><3>'; + $this->assertEquals(array(1, 2, 3), expand_acl($text)); + } /** * test with a big number - */ - public function testExpandAclBigNumber() { - $text='<1><'.PHP_INT_MAX.'><15>'; - $this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text)); - } + */ + public function testExpandAclBigNumber() { + $text='<1><'.PHP_INT_MAX.'><15>'; + $this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text)); + } /** * test with a string in it. * * TODO: is this valid input? Otherwise: should there be an exception? - */ - public function testExpandAclString() { - $text="<1><279012>"; - $this->assertEquals(array(1, 279012), expand_acl($text)); - } + */ + public function testExpandAclString() { + $text="<1><279012>"; + $this->assertEquals(array(1, 279012), expand_acl($text)); + } /** * test with a ' ' in it. * * TODO: is this valid input? Otherwise: should there be an exception? - */ - public function testExpandAclSpace() { - $text="<1><279 012><32>"; - $this->assertEquals(array(1, "279", "32"), expand_acl($text)); - } + */ + public function testExpandAclSpace() { + $text="<1><279 012><32>"; + $this->assertEquals(array(1, "279", "32"), expand_acl($text)); + } /** * test empty input - */ - public function testExpandAclEmpty() { - $text=""; - $this->assertEquals(array(), expand_acl($text)); - } + */ + public function testExpandAclEmpty() { + $text=""; + $this->assertEquals(array(), expand_acl($text)); + } /** * test invalid input, no < at all * * TODO: should there be an exception? - */ - public function testExpandAclNoBrackets() { - $text="According to documentation, that's invalid. "; //should be invalid - $this->assertEquals(array(), expand_acl($text)); - } + */ + public function testExpandAclNoBrackets() { + $text="According to documentation, that's invalid. "; //should be invalid + $this->assertEquals(array(), expand_acl($text)); + } - /** - * test invalid input, just open < - * - * TODO: should there be an exception? - */ - public function testExpandAclJustOneBracket1() { - $text="assertEquals(array(), expand_acl($text)); - } + /** + * test invalid input, just open < + * + * TODO: should there be an exception? + */ + public function testExpandAclJustOneBracket1() { + $text="assertEquals(array(), expand_acl($text)); + } - /** - * test invalid input, just close > - * - * TODO: should there be an exception? - */ - public function testExpandAclJustOneBracket2() { - $text="Another invalid> string"; //should be invalid - $this->assertEquals(array(), expand_acl($text)); - } + /** + * test invalid input, just close > + * + * TODO: should there be an exception? + */ + public function testExpandAclJustOneBracket2() { + $text="Another invalid> string"; //should be invalid + $this->assertEquals(array(), expand_acl($text)); + } - /** - * test invalid input, just close > - * - * TODO: should there be an exception? - */ - public function testExpandAclCloseOnly() { - $text="Another> invalid> string>"; //should be invalid - $this->assertEquals(array(), expand_acl($text)); - } + /** + * test invalid input, just close > + * + * TODO: should there be an exception? + */ + public function testExpandAclCloseOnly() { + $text="Another> invalid> string>"; //should be invalid + $this->assertEquals(array(), expand_acl($text)); + } - /** - * test invalid input, just open < - * - * TODO: should there be an exception? - */ - public function testExpandAclOpenOnly() { - $text="assertEquals(array(), expand_acl($text)); - } + /** + * test invalid input, just open < + * + * TODO: should there be an exception? + */ + public function testExpandAclOpenOnly() { + $text="assertEquals(array(), expand_acl($text)); + } - /** - * test invalid input, open and close do not match - * - * TODO: should there be an exception? - */ - public function testExpandAclNoMatching1() { - $text=" invalid "; //should be invalid - $this->assertEquals(array(), expand_acl($text)); - } + /** + * test invalid input, open and close do not match + * + * TODO: should there be an exception? + */ + public function testExpandAclNoMatching1() { + $text=" invalid "; //should be invalid + $this->assertEquals(array(), expand_acl($text)); + } - /** - * test invalid input, open and close do not match - * - * TODO: should there be an exception? - */ - public function testExpandAclNoMatching2() { - $text="<1>2><3>"; + /** + * test invalid input, open and close do not match + * + * TODO: should there be an exception? + */ + public function testExpandAclNoMatching2() { + $text="<1>2><3>"; // The angles are delimiters which aren't important // the important thing is the numeric content, this returns array(1,2,3) currently // we may wish to eliminate 2 from the results, though it isn't harmful // It would be a better test to figure out if there is any ACL input which can // produce this $text and fix that instead. -// $this->assertEquals(array(), expand_acl($text)); +// $this->assertEquals(array(), expand_acl($text)); } - /** - * test invalid input, empty <> - * - * TODO: should there be an exception? Or array(1, 3) + /** + * test invalid input, empty <> + * + * TODO: should there be an exception? Or array(1, 3) * (This should be array(1,3) - mike) - */ - public function testExpandAclEmptyMatch() { - $text="<1><><3>"; - $this->assertEquals(array(1,3), expand_acl($text)); + */ + public function testExpandAclEmptyMatch() { + $text="<1><><3>"; + $this->assertEquals(array(1,3), expand_acl($text)); } } \ No newline at end of file diff --git a/tests/get_tags_test.php b/tests/get_tags_test.php index 79dcb36a7..2d49eac24 100644 --- a/tests/get_tags_test.php +++ b/tests/get_tags_test.php @@ -44,23 +44,23 @@ function q($sql) { $args=func_get_args(); //last parameter is always (in this test) uid, so, it should be 11 - if($args[count($args)-1]!=11) { + if ($args[count($args)-1]!=11) { return; } - if(3==count($args)) { + if (3==count($args)) { //first call in handle_body, id only - if($result[0]['id']==$args[1]) { + if ($result[0]['id']==$args[1]) { return $result; } //second call in handle_body, name - if($result[0]['name']===$args[1]) { + if ($result[0]['name']===$args[1]) { return $result; } } //third call in handle_body, nick or attag - if($result[0]['nick']===$args[2] || $result[0]['attag']===$args[1]) { + if ($result[0]['nick']===$args[2] || $result[0]['attag']===$args[1]) { return $result; } } @@ -108,7 +108,7 @@ class GetTagsTest extends PHPUnit_Framework_TestCase { $inform=''; $str_tags=''; - foreach($tags as $tag) { + foreach ($tags as $tag) { handle_tag($this->a, $text, $inform, $str_tags, 11, $tag); } @@ -197,7 +197,7 @@ class GetTagsTest extends PHPUnit_Framework_TestCase { $inform=''; $str_tags=''; - foreach($tags as $tag) { + foreach ($tags as $tag) { handle_tag($this->a, $text, $inform, $str_tags, 11, $tag); } @@ -257,7 +257,7 @@ class GetTagsTest extends PHPUnit_Framework_TestCase { $inform=''; $str_tags=''; - foreach($tags as $tag) { + foreach ($tags as $tag) { handle_tag($this->a, $text, $inform, $str_tags, 11, $tag); } diff --git a/tests/template_test.php b/tests/template_test.php index 1f9f80531..c6e83572e 100644 --- a/tests/template_test.php +++ b/tests/template_test.php @@ -1,11 +1,11 @@ assertEquals('Hello Anna!', $text); } - public function testSimpleVariableInt() { - $tpl='There are $num new messages!'; - - $text=replace_macros($tpl, array('$num'=>172)); - - $this->assertEquals('There are 172 new messages!', $text); + public function testSimpleVariableInt() { + $tpl='There are $num new messages!'; + + $text=replace_macros($tpl, array('$num'=>172)); + + $this->assertEquals('There are 172 new messages!', $text); } - public function testConditionalElse() { - $tpl='There{{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!'; - + public function testConditionalElse() { + $tpl='There{{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!'; + $text1=replace_macros($tpl, array('$num'=>1)); - $text22=replace_macros($tpl, array('$num'=>22)); - + $text22=replace_macros($tpl, array('$num'=>22)); + $this->assertEquals('There is 1 new message!', $text1); - $this->assertEquals('There are 22 new messages!', $text22); + $this->assertEquals('There are 22 new messages!', $text22); } - public function testConditionalNoElse() { - $tpl='{{ if $num!=0 }}There are $num new messages!{{ endif }}'; - - $text0=replace_macros($tpl, array('$num'=>0)); - $text22=replace_macros($tpl, array('$num'=>22)); - - $this->assertEquals('', $text0); - $this->assertEquals('There are 22 new messages!', $text22); + public function testConditionalNoElse() { + $tpl='{{ if $num!=0 }}There are $num new messages!{{ endif }}'; + + $text0=replace_macros($tpl, array('$num'=>0)); + $text22=replace_macros($tpl, array('$num'=>22)); + + $this->assertEquals('', $text0); + $this->assertEquals('There are 22 new messages!', $text22); } - public function testConditionalFail() { - $tpl='There {{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!'; - - $text1=replace_macros($tpl, array()); - - //$this->assertEquals('There is 1 new message!', $text1); + public function testConditionalFail() { + $tpl='There {{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!'; + + $text1=replace_macros($tpl, array()); + + //$this->assertEquals('There is 1 new message!', $text1); } - public function testSimpleFor() { - $tpl='{{ for $messages as $message }} $message {{ endfor }}'; - - $text=replace_macros($tpl, array('$messages'=>array('message 1', 'message 2'))); - - $this->assertEquals(' message 1 message 2 ', $text); + public function testSimpleFor() { + $tpl='{{ for $messages as $message }} $message {{ endfor }}'; + + $text=replace_macros($tpl, array('$messages'=>array('message 1', 'message 2'))); + + $this->assertEquals(' message 1 message 2 ', $text); } - public function testFor() { - $tpl='{{ for $messages as $message }} from: $message.from to $message.to {{ endfor }}'; - - $text=replace_macros($tpl, array('$messages'=>array(array('from'=>'Mike', 'to'=>'Alex'), array('from'=>'Alex', 'to'=>'Mike')))); - - $this->assertEquals(' from: Mike to Alex from: Alex to Mike ', $text); + public function testFor() { + $tpl='{{ for $messages as $message }} from: $message.from to $message.to {{ endfor }}'; + + $text=replace_macros($tpl, array('$messages'=>array(array('from'=>'Mike', 'to'=>'Alex'), array('from'=>'Alex', 'to'=>'Mike')))); + + $this->assertEquals(' from: Mike to Alex from: Alex to Mike ', $text); } - public function testKeyedFor() { - $tpl='{{ for $messages as $from=>$to }} from: $from to $to {{ endfor }}'; - - $text=replace_macros($tpl, array('$messages'=>array('Mike'=>'Alex', 'Sven'=>'Mike'))); - - $this->assertEquals(' from: Mike to Alex from: Sven to Mike ', $text); + public function testKeyedFor() { + $tpl='{{ for $messages as $from=>$to }} from: $from to $to {{ endfor }}'; + + $text=replace_macros($tpl, array('$messages'=>array('Mike'=>'Alex', 'Sven'=>'Mike'))); + + $this->assertEquals(' from: Mike to Alex from: Sven to Mike ', $text); } - public function testForEmpty() { - $tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}'; - - $text=replace_macros($tpl, array('$messages'=>array())); - - $this->assertEquals('messages: ', $text); + public function testForEmpty() { + $tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}'; + + $text=replace_macros($tpl, array('$messages'=>array())); + + $this->assertEquals('messages: ', $text); } - public function testForWrongType() { - $tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}'; - - $text=replace_macros($tpl, array('$messages'=>11)); - - $this->assertEquals('messages: ', $text); + public function testForWrongType() { + $tpl='messages: {{for $messages as $message}} from: $message.from to $message.to {{ endfor }}'; + + $text=replace_macros($tpl, array('$messages'=>11)); + + $this->assertEquals('messages: ', $text); } - public function testForConditional() { - $tpl='new messages: {{for $messages as $message}}{{ if $message.new }} $message.text{{endif}}{{ endfor }}'; - + public function testForConditional() { + $tpl='new messages: {{for $messages as $message}}{{ if $message.new }} $message.text{{endif}}{{ endfor }}'; + $text=replace_macros($tpl, array('$messages'=>array( array('new'=>true, 'text'=>'new message'), - array('new'=>false, 'text'=>'old message')))); - - $this->assertEquals('new messages: new message', $text); + array('new'=>false, 'text'=>'old message')))); + + $this->assertEquals('new messages: new message', $text); } - public function testConditionalFor() { - $tpl='{{ if $enabled }}new messages:{{for $messages as $message}} $message.text{{ endfor }}{{endif}}'; - + public function testConditionalFor() { + $tpl='{{ if $enabled }}new messages:{{for $messages as $message}} $message.text{{ endfor }}{{endif}}'; + $text=replace_macros($tpl, array('$enabled'=>true, - '$messages'=>array( - array('new'=>true, 'text'=>'new message'), - array('new'=>false, 'text'=>'old message')))); - - $this->assertEquals('new messages: new message old message', $text); + '$messages'=>array( + array('new'=>true, 'text'=>'new message'), + array('new'=>false, 'text'=>'old message')))); + + $this->assertEquals('new messages: new message old message', $text); } - public function testFantasy() { - $tpl='Fantasy: {{fantasy $messages}}'; - - $text=replace_macros($tpl, array('$messages'=>'no no')); - - $this->assertEquals('Fantasy: {{fantasy no no}}', $text); + public function testFantasy() { + $tpl='Fantasy: {{fantasy $messages}}'; + + $text=replace_macros($tpl, array('$messages'=>'no no')); + + $this->assertEquals('Fantasy: {{fantasy no no}}', $text); } - public function testInc() { - $tpl='{{inc field_input.tpl with $field=$myvar}}{{ endinc }}'; - - $text=replace_macros($tpl, array('$myvar'=>array('myfield', 'label', 'value', 'help'))); - + public function testInc() { + $tpl='{{inc field_input.tpl with $field=$myvar}}{{ endinc }}'; + + $text=replace_macros($tpl, array('$myvar'=>array('myfield', 'label', 'value', 'help'))); + $this->assertEquals(" \n" ."
\n" ." \n" ." \n" ." help\n" - ."
\n", $text); + ."
\n", $text); } - public function testIncNoVar() { - $tpl='{{inc field_input.tpl }}{{ endinc }}'; - - $text=replace_macros($tpl, array('$field'=>array('myfield', 'label', 'value', 'help'))); - - $this->assertEquals(" \n
\n \n" - ." \n" - ." help\n" - ."
\n", $text); + public function testIncNoVar() { + $tpl='{{inc field_input.tpl }}{{ endinc }}'; + + $text=replace_macros($tpl, array('$field'=>array('myfield', 'label', 'value', 'help'))); + + $this->assertEquals(" \n
\n \n" + ." \n" + ." help\n" + ."
\n", $text); } - public function testDoubleUse() { - $tpl='Hello $name! {{ if $enabled }} I love you! {{ endif }}'; - - $text=replace_macros($tpl, array('$name'=>'Anna', '$enabled'=>false)); - + public function testDoubleUse() { + $tpl='Hello $name! {{ if $enabled }} I love you! {{ endif }}'; + + $text=replace_macros($tpl, array('$name'=>'Anna', '$enabled'=>false)); + $this->assertEquals('Hello Anna! ', $text); - $tpl='Hey $name! {{ if $enabled }} I hate you! {{ endif }}'; - - $text=replace_macros($tpl, array('$name'=>'Max', '$enabled'=>true)); - - $this->assertEquals('Hey Max! I hate you! ', $text); + $tpl='Hey $name! {{ if $enabled }} I hate you! {{ endif }}'; + + $text=replace_macros($tpl, array('$name'=>'Max', '$enabled'=>true)); + + $this->assertEquals('Hey Max! I hate you! ', $text); } - public function testIncDouble() { + public function testIncDouble() { $tpl='{{inc field_input.tpl with $field=$var1}}{{ endinc }}' - .'{{inc field_input.tpl with $field=$var2}}{{ endinc }}'; - + .'{{inc field_input.tpl with $field=$var2}}{{ endinc }}'; + $text=replace_macros($tpl, array('$var1'=>array('myfield', 'label', 'value', 'help'), - '$var2'=>array('myfield2', 'label2', 'value2', 'help2'))); - - $this->assertEquals(" \n" - ."
\n" - ." \n" - ." \n" - ." help\n" + '$var2'=>array('myfield2', 'label2', 'value2', 'help2'))); + + $this->assertEquals(" \n" + ."
\n" + ." \n" + ." \n" + ." help\n" ."
\n" ." \n" ."
\n" ." \n" ." \n" ." help2\n" - ."
\n", $text); + ."
\n", $text); } } \ No newline at end of file diff --git a/tests/xss_filter_test.php b/tests/xss_filter_test.php index 3fb6ac310..9e779f767 100644 --- a/tests/xss_filter_test.php +++ b/tests/xss_filter_test.php @@ -33,13 +33,13 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase { $this->assertEquals($text, $retext); } - /** - * xmlify and put in a document - */ - public function testXmlifyDocument() { - $tag="I want to break"; + /** + * xmlify and put in a document + */ + public function testXmlifyDocument() { + $tag="I want to break"; $xml=xmlify($tag); - $text=''.$xml.''; + $text=''.$xml.''; $xml_parser=xml_parser_create(); //should be possible to parse it @@ -48,10 +48,10 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase { $this->assertEquals(array('TEXT'=>array(0)), $index); - $this->assertEquals(array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)), + $this->assertEquals(array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)), $values); - xml_parser_free($xml_parser); + xml_parser_free($xml_parser); } /** diff --git a/view/theme/frio/php/PHPColors/Color.php b/view/theme/frio/php/PHPColors/Color.php index d1543036c..91b0180f2 100644 --- a/view/theme/frio/php/PHPColors/Color.php +++ b/view/theme/frio/php/PHPColors/Color.php @@ -33,9 +33,9 @@ class Color { $color = str_replace("#", "", $hex); // Make sure it's 6 digits - if( strlen($color) === 3 ) { + if ( strlen($color) === 3 ) { $color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2]; - } else if( strlen($color) != 6 ) { + } else if ( strlen($color) != 6 ) { throw new Exception("HEX color needs to be 6 or 3 digits long"); } @@ -112,19 +112,19 @@ class Color { */ public static function hslToHex( $hsl = array() ){ // Make sure it's HSL - if(empty($hsl) || !isset($hsl["H"]) || !isset($hsl["S"]) || !isset($hsl["L"]) ) { + if (empty($hsl) || !isset($hsl["H"]) || !isset($hsl["S"]) || !isset($hsl["L"]) ) { throw new Exception("Param was not an HSL array"); } list($H,$S,$L) = array( $hsl['H']/360,$hsl['S'],$hsl['L'] ); - if( $S == 0 ) { + if ( $S == 0 ) { $r = $L * 255; $g = $L * 255; $b = $L * 255; } else { - if($L<0.5) { + if ($L<0.5) { $var_2 = $L*(1+$S); } else { $var_2 = ($L+$S) - ($S*$L); @@ -183,7 +183,7 @@ class Color { */ public static function rgbToHex( $rgb = array() ){ // Make sure it's RGB - if(empty($rgb) || !isset($rgb["R"]) || !isset($rgb["G"]) || !isset($rgb["B"]) ) { + if (empty($rgb) || !isset($rgb["R"]) || !isset($rgb["G"]) || !isset($rgb["B"]) ) { throw new Exception("Param was not an RGB array"); } @@ -244,7 +244,7 @@ class Color { */ public function makeGradient( $amount = self::DEFAULT_ADJUST ) { // Decide which color needs to be made - if( $this->isLight() ) { + if ( $this->isLight() ) { $lightColor = $this->_hex; $darkColor = $this->darken($amount); } else { @@ -387,7 +387,7 @@ class Color { */ private function _darken( $hsl, $amount = self::DEFAULT_ADJUST){ // Check if we were provided a number - if( $amount ) { + if ( $amount ) { $hsl['L'] = ($hsl['L'] * 100) - $amount; $hsl['L'] = ($hsl['L'] < 0) ? 0:$hsl['L']/100; } else { @@ -406,7 +406,7 @@ class Color { */ private function _lighten( $hsl, $amount = self::DEFAULT_ADJUST){ // Check if we were provided a number - if( $amount ) { + if ( $amount ) { $hsl['L'] = ($hsl['L'] * 100) + $amount; $hsl['L'] = ($hsl['L'] > 100) ? 1:$hsl['L']/100; } else { @@ -446,23 +446,23 @@ class Color { * @return int */ private static function _huetorgb( $v1,$v2,$vH ) { - if( $vH < 0 ) { + if ( $vH < 0 ) { $vH += 1; } - if( $vH > 1 ) { + if ( $vH > 1 ) { $vH -= 1; } - if( (6*$vH) < 1 ) { + if ( (6*$vH) < 1 ) { return ($v1 + ($v2 - $v1) * 6 * $vH); } - if( (2*$vH) < 1 ) { + if ( (2*$vH) < 1 ) { return $v2; } - if( (3*$vH) < 2 ) { + if ( (3*$vH) < 2 ) { return ($v1 + ($v2-$v1) * ( (2/3)-$vH ) * 6); } @@ -481,9 +481,9 @@ class Color { $color = str_replace("#", "", $hex); // Make sure it's 6 digits - if( strlen($color) == 3 ) { + if ( strlen($color) == 3 ) { $color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2]; - } else if( strlen($color) != 6 ) { + } else if ( strlen($color) != 6 ) { throw new Exception("HEX color needs to be 6 or 3 digits long"); } diff --git a/view/theme/frio/theme.php b/view/theme/frio/theme.php index 7584e0b37..00c475e30 100644 --- a/view/theme/frio/theme.php +++ b/view/theme/frio/theme.php @@ -78,12 +78,12 @@ function frio_item_photo_links(App $a, &$body_info) { $occurence = 1; $p = bb_find_open_close($body_info['html'], ""); - while($p !== false && ($occurence++ < 500)) { + while ($p !== false && ($occurence++ < 500)) { $link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']); $matches = array(); preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches); - if($matches) { + if ($matches) { // Replace the link for the photo's page with a direct link to the photo itself $newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link); diff --git a/view/theme/frost/theme.php b/view/theme/frost/theme.php index 4c22f0a11..1f2c70c8b 100644 --- a/view/theme/frost/theme.php +++ b/view/theme/frost/theme.php @@ -49,12 +49,12 @@ function frost_item_photo_links(App $a, &$body_info) { $occurence = 1; $p = bb_find_open_close($body_info['html'], ""); - while($p !== false && ($occurence++ < 500)) { + while ($p !== false && ($occurence++ < 500)) { $link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']); $matches = array(); preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches); - if($matches) { + if ($matches) { // Replace the link for the photo's page with a direct link to the photo itself $newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link); From d9c22c7f3e6a4bfff5814b59b266e2d72f0f71be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Fri, 27 Jan 2017 11:58:40 +0100 Subject: [PATCH 29/65] Continued a bit: - converted some else if to elseif (only PHP) - converted some space -> tab (intending) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/Core/PConfig.php | 2 +- include/template_processor.php | 14 ++++++--- mod/notifications.php | 8 ++--- mod/pubsubhubbub.php | 2 +- view/theme/duepuntozero/theme.php | 41 +++++++++++++++---------- view/theme/frio/php/PHPColors/Color.php | 5 +-- 6 files changed, 42 insertions(+), 30 deletions(-) diff --git a/include/Core/PConfig.php b/include/Core/PConfig.php index 6ced9fc75..421a1d5fa 100644 --- a/include/Core/PConfig.php +++ b/include/Core/PConfig.php @@ -44,7 +44,7 @@ class PConfig { $a->config[$uid][$family][$k] = $rr['v']; self::$in_db[$uid][$family][$k] = true; } - } else if ($family != 'config') { + } elseif ($family != 'config') { // Negative caching $a->config[$uid][$family] = "!!"; } diff --git a/include/template_processor.php b/include/template_processor.php index 252375a06..6c1b16592 100644 --- a/include/template_processor.php +++ b/include/template_processor.php @@ -53,8 +53,9 @@ class Template implements ITemplateEngine { private function _get_var($name, $retNoKey = false) { $keys = array_map('trim', explode(".", $name)); - if ($retNoKey && !array_key_exists($keys[0], $this->r)) + if ($retNoKey && !array_key_exists($keys[0], $this->r)) { return KEY_NOT_EXISTS; + } $val = $this->r; foreach ($keys as $k) { $val = (isset($val[$k]) ? $val[$k] : null); @@ -73,14 +74,16 @@ class Template implements ITemplateEngine { if (strpos($args[2], "==") > 0) { list($a, $b) = array_map("trim", explode("==", $args[2])); $a = $this->_get_var($a); - if ($b[0] == "$") + if ($b[0] == "$") { $b = $this->_get_var($b); + } $val = ($a == $b); - } else if (strpos($args[2], "!=") > 0) { + } elseif (strpos($args[2], "!=") > 0) { list($a, $b) = array_map("trim", explode("!=", $args[2])); $a = $this->_get_var($a); - if ($b[0] == "$") + if ($b[0] == "$") { $b = $this->_get_var($b); + } $val = ($a != $b); } else { $val = $this->_get_var($args[2]); @@ -138,8 +141,9 @@ class Template implements ITemplateEngine { $newctx = null; } - if ($tplfile[0] == "$") + if ($tplfile[0] == "$") { $tplfile = $this->_get_var($tplfile); + } $this->_push_stack(); $r = $this->r; diff --git a/mod/notifications.php b/mod/notifications.php index d27228b8f..e9e5081cb 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -100,25 +100,25 @@ function notifications_content(App $a) { $notifs = $nm->introNotifs($all, $startrec, $perpage); // Get the network notifications - } else if (($a->argc > 1) && ($a->argv[1] == 'network')) { + } elseif (($a->argc > 1) && ($a->argv[1] == 'network')) { $notif_header = t('Network Notifications'); $notifs = $nm->networkNotifs($show, $startrec, $perpage); // Get the system notifications - } else if (($a->argc > 1) && ($a->argv[1] == 'system')) { + } elseif (($a->argc > 1) && ($a->argv[1] == 'system')) { $notif_header = t('System Notifications'); $notifs = $nm->systemNotifs($show, $startrec, $perpage); // Get the personal notifications - } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) { + } elseif (($a->argc > 1) && ($a->argv[1] == 'personal')) { $notif_header = t('Personal Notifications'); $notifs = $nm->personalNotifs($show, $startrec, $perpage); // Get the home notifications - } else if (($a->argc > 1) && ($a->argv[1] == 'home')) { + } elseif (($a->argc > 1) && ($a->argv[1] == 'home')) { $notif_header = t('Home Notifications'); $notifs = $nm->homeNotifs($show, $startrec, $perpage); diff --git a/mod/pubsubhubbub.php b/mod/pubsubhubbub.php index 0f797d55b..97f1c9820 100644 --- a/mod/pubsubhubbub.php +++ b/mod/pubsubhubbub.php @@ -32,7 +32,7 @@ function pubsubhubbub_init(App $a) { // check for valid hub_mode if ($hub_mode === 'subscribe') { $subscribe = 1; - } else if ($hub_mode === 'unsubscribe') { + } elseif ($hub_mode === 'unsubscribe') { $subscribe = 0; } else { logger("pubsubhubbub: invalid hub_mode=$hub_mode, ignoring."); diff --git a/view/theme/duepuntozero/theme.php b/view/theme/duepuntozero/theme.php index c674a99d9..d3378e49b 100644 --- a/view/theme/duepuntozero/theme.php +++ b/view/theme/duepuntozero/theme.php @@ -4,23 +4,30 @@ function duepuntozero_init(App $a) { set_template_engine($a, 'smarty3'); - $colorset = get_pconfig( local_user(), 'duepuntozero','colorset'); - if (!$colorset) - $colorset = get_config('duepuntozero', 'colorset'); // user setting have priority, then node settings - if ($colorset) { - if ($colorset == 'greenzero') - $a->page['htmlhead'] .= ''."\n"; - if ($colorset == 'purplezero') - $a->page['htmlhead'] .= ''."\n"; - if ($colorset == 'easterbunny') - $a->page['htmlhead'] .= ''."\n"; - if ($colorset == 'darkzero') - $a->page['htmlhead'] .= ''."\n"; - if ($colorset == 'comix') - $a->page['htmlhead'] .= ''."\n"; - if ($colorset == 'slackr') - $a->page['htmlhead'] .= ''."\n"; - } +$colorset = get_pconfig( local_user(), 'duepuntozero','colorset'); +if (!$colorset) { + $colorset = get_config('duepuntozero', 'colorset'); // user setting have priority, then node settings +} +if ($colorset) { + if ($colorset == 'greenzero') { + $a->page['htmlhead'] .= ''."\n"; + } + if ($colorset == 'purplezero') { + $a->page['htmlhead'] .= ''."\n"; + } + if ($colorset == 'easterbunny') { + $a->page['htmlhead'] .= ''."\n"; + } + if ($colorset == 'darkzero') { + $a->page['htmlhead'] .= ''."\n"; + } + if ($colorset == 'comix') { + $a->page['htmlhead'] .= ''."\n"; + } + if ($colorset == 'slackr') { + $a->page['htmlhead'] .= ''."\n"; + } +} $a->page['htmlhead'] .= <<< EOT \r\n"; } } - else if ($mode === 'profile') { + else if($mode === 'profile') { $profile_owner = $a->profile['profile_uid']; $page_writeable = can_write_wall($a,$profile_owner); - if (!$update) { + if(!$update) { $tab = notags(trim($_GET['tab'])); $tab = ( $tab ? $tab : 'posts' ); - if ($tab === 'posts') { + if($tab === 'posts') { // This is ugly, but we can't pass the profile_uid through the session to the ajax updater, // because browser prefetching might change it on us. We have to deliver it with the page. @@ -539,40 +537,40 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { } } } - else if ($mode === 'notes') { + else if($mode === 'notes') { $profile_owner = local_user(); $page_writeable = true; - if (!$update) { + if(!$update) { $live_update_div = '
' . "\r\n" . "\r\n"; } } - else if ($mode === 'display') { + else if($mode === 'display') { $profile_owner = $a->profile['uid']; $page_writeable = can_write_wall($a,$profile_owner); - if (!$update) { + if(!$update) { $live_update_div = '
' . "\r\n" . ""; } } - else if ($mode === 'community') { + else if($mode === 'community') { $profile_owner = 0; $page_writeable = false; - if (!$update) { + if(!$update) { $live_update_div = '
' . "\r\n" . "\r\n"; } } - else if ($mode === 'search') { + else if($mode === 'search') { $live_update_div = '' . "\r\n"; } $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false); - if ($update) + if($update) $return_url = $_SESSION['return_url']; else $return_url = $_SESSION['return_url'] = $a->query_string; @@ -596,9 +594,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $page_template = get_markup_template("conversation.tpl"); - if ($items && count($items)) { + if($items && count($items)) { - if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') { + if($mode === 'network-new' || $mode === 'search' || $mode === 'community') { // "New Item View" on network page or search page results // - just loop through the items and format them minimally for display @@ -606,17 +604,17 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { // $tpl = get_markup_template('search_item.tpl'); $tpl = 'search_item.tpl'; - foreach ($items as $item) { + foreach($items as $item) { - if ($arr_blocked) { + if($arr_blocked) { $blocked = false; - foreach ($arr_blocked as $b) { - if ($b && link_compare($item['author-link'],$b)) { + foreach($arr_blocked as $b) { + if($b && link_compare($item['author-link'],$b)) { $blocked = true; break; } } - if ($blocked) + if($blocked) continue; } @@ -628,8 +626,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $owner_name = ''; $sparkle = ''; - if ($mode === 'search' || $mode === 'community') { - if (((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) + if($mode === 'search' || $mode === 'community') { + if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent'])) continue; $nickname = $item['nickname']; @@ -638,11 +636,11 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $nickname = $a->user['nickname']; // prevent private email from leaking. - if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) + if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) continue; $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']); - if ($item['author-link'] && (! $item['author-name'])) + if($item['author-link'] && (! $item['author-name'])) $profile_name = $item['author-link']; @@ -654,7 +652,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`", intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION)); - foreach ($taglist as $tag) { + foreach($taglist as $tag) { if ($tag["url"] == "") $tag["url"] = $searchpath.strtolower($tag["term"]); @@ -671,9 +669,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $sp = false; $profile_link = best_link_url($item,$sp); - if ($profile_link === 'mailbox') + if($profile_link === 'mailbox') $profile_link = ''; - if ($sp) + if($sp) $sparkle = ' sparkle'; else $profile_link = zrl($profile_link); @@ -700,7 +698,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate)); localize_item($item); - if ($mode === 'network-new') + if($mode === 'network-new') $dropping = true; else $dropping = false; @@ -725,7 +723,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { list($categories, $folders) = get_cats_and_terms($item); - if ($a->theme['template_engine'] === 'internal') { + if($a->theme['template_engine'] === 'internal') { $profile_name_e = template_escape($profile_name); $item['title_e'] = template_escape($item['title']); $body_e = template_escape($body); @@ -820,18 +818,18 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { // But for now, this array respects the old style, just in case $threads = array(); - foreach ($items as $item) { + foreach($items as $item) { - if ($arr_blocked) { + if($arr_blocked) { $blocked = false; - foreach ($arr_blocked as $b) { + foreach($arr_blocked as $b) { - if ($b && link_compare($item['author-link'],$b)) { + if($b && link_compare($item['author-link'],$b)) { $blocked = true; break; } } - if ($blocked) + if($blocked) continue; } @@ -841,10 +839,10 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { builtin_activity_puller($item, $conv_responses); // Only add what is visible - if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { + if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { continue; } - if (! visible_activity($item)) { + if(! visible_activity($item)) { continue; } @@ -852,7 +850,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $item['pagedrop'] = $page_dropping; - if ($item['id'] == $item['parent']) { + if($item['id'] == $item['parent']) { $item_object = new Item($item); $conv->add_thread($item_object); } @@ -860,7 +858,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $threads = $conv->get_template_data($conv_responses); - if (!$threads) { + if(!$threads) { logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG); $threads = array(); } @@ -896,8 +894,8 @@ function best_link_url($item,&$sparkle,$ssl_state = false) { $sparkle = true; } } - if (! $best_url) { - if (strlen($item['author-link'])) + if(! $best_url) { + if(strlen($item['author-link'])) $best_url = $item['author-link']; else $best_url = $item['url']; @@ -912,7 +910,7 @@ function item_photo_menu($item) { $ssl_state = false; - if (local_user()) { + if(local_user()) { $ssl_state = true; } @@ -946,7 +944,7 @@ function item_photo_menu($item) $rel = $r[0]['rel']; } - if ($sparkle) { + if($sparkle) { $status_link = $profile_link . '?url=status'; $photos_link = $profile_link . '?url=photos'; $profile_link = $profile_link . '?url=profile'; @@ -1014,9 +1012,9 @@ function item_photo_menu($item) * @param array &$conv_responses (already created with builtin activity structure) * @return void */ -if (! function_exists('builtin_activity_puller')) { +if(! function_exists('builtin_activity_puller')) { function builtin_activity_puller($item, &$conv_responses) { - foreach ($conv_responses as $mode => $v) { + foreach($conv_responses as $mode => $v) { $url = ''; $sparkle = ''; @@ -1041,9 +1039,9 @@ function builtin_activity_puller($item, &$conv_responses) { break; } - if ((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) { + if((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) { $url = $item['author-link']; - if ((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) { + if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) { $url = 'redir/' . $item['contact-id']; $sparkle = ' class="sparkle" '; } @@ -1052,18 +1050,18 @@ function builtin_activity_puller($item, &$conv_responses) { $url = '
' . htmlentities($item['author-name']) . ''; - if (! $item['thr-parent']) + if(! $item['thr-parent']) $item['thr-parent'] = $item['parent-uri']; - if (! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l'])) + if(! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l'])) && (is_array($conv_responses[$mode][$item['thr-parent'] . '-l'])))) $conv_responses[$mode][$item['thr-parent'] . '-l'] = array(); // only list each unique author once - if (in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) + if(in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) continue; - if (! isset($conv_responses[$mode][$item['thr-parent']])) + if(! isset($conv_responses[$mode][$item['thr-parent']])) $conv_responses[$mode][$item['thr-parent']] = 1; else $conv_responses[$mode][$item['thr-parent']] ++; @@ -1087,12 +1085,12 @@ function builtin_activity_puller($item, &$conv_responses) { // $id = item id // returns formatted text -if (! function_exists('format_like')) { +if(! function_exists('format_like')) { function format_like($cnt,$arr,$type,$id) { $o = ''; $expanded = ''; - if ($cnt == 1) { + if($cnt == 1) { $likers = $arr[0]; // Phrase if there is only one liker. In other cases it will be uses for the expanded @@ -1116,16 +1114,16 @@ function format_like($cnt,$arr,$type,$id) { } } - if ($cnt > 1) { + if($cnt > 1) { $total = count($arr); - if ($total >= MAX_LIKERS) + if($total >= MAX_LIKERS) $arr = array_slice($arr, 0, MAX_LIKERS - 1); - if ($total < MAX_LIKERS) { + if($total < MAX_LIKERS) { $last = t('and') . ' ' . $arr[count($arr)-1]; $arr2 = array_slice($arr, 0, -1); $str = implode(', ', $arr2) . ' ' . $last; } - if ($total >= MAX_LIKERS) { + if($total >= MAX_LIKERS) { $str = implode(', ', $arr); $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS ); } @@ -1213,17 +1211,17 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) { // Private/public post links for the non-JS ACL form $private_post = 1; - if ($_REQUEST['public']) + if($_REQUEST['public']) $private_post = 0; $query_str = $a->query_string; - if (strpos($query_str, 'public=1') !== false) + if(strpos($query_str, 'public=1') !== false) $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str); // I think $a->query_string may never have ? in it, but I could be wrong // It looks like it's from the index.php?q=[etc] rewrite that the web // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61 - if (strpos($query_str, '?') === false) + if(strpos($query_str, '?') === false) $public_post_link = '?public=1'; else $public_post_link = '&public=1'; @@ -1304,20 +1302,20 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) { function get_item_children($arr, $parent) { $children = array(); $a = get_app(); - foreach ($arr as $item) { - if ($item['id'] != $item['parent']) { - if (get_config('system','thread_allow') && $a->theme_thread_allow) { + foreach($arr as $item) { + if($item['id'] != $item['parent']) { + if(get_config('system','thread_allow') && $a->theme_thread_allow) { // Fallback to parent-uri if thr-parent is not set $thr_parent = $item['thr-parent']; - if ($thr_parent == '') + if($thr_parent == '') $thr_parent = $item['parent-uri']; - if ($thr_parent == $parent['uri']) { + if($thr_parent == $parent['uri']) { $item['children'] = get_item_children($arr, $item); $children[] = $item; } } - else if ($item['parent'] == $parent['id']) { + else if($item['parent'] == $parent['id']) { $children[] = $item; } } @@ -1328,8 +1326,8 @@ function get_item_children($arr, $parent) { function sort_item_children($items) { $result = $items; usort($result,'sort_thr_created_rev'); - foreach ($result as $k => $i) { - if (count($result[$k]['children'])) { + foreach($result as $k => $i) { + if(count($result[$k]['children'])) { $result[$k]['children'] = sort_item_children($result[$k]['children']); } } @@ -1337,16 +1335,16 @@ function sort_item_children($items) { } function add_children_to_list($children, &$arr) { - foreach ($children as $y) { + foreach($children as $y) { $arr[] = $y; - if (count($y['children'])) + if(count($y['children'])) add_children_to_list($y['children'], $arr); } } function conv_sort($arr,$order) { - if ((!(is_array($arr) && count($arr)))) + if((!(is_array($arr) && count($arr)))) return array(); $parents = array(); @@ -1355,40 +1353,35 @@ function conv_sort($arr,$order) { // This is a preparation for having two different items with the same uri in one thread // This will otherwise lead to an endless loop. - foreach ($arr as $x) + foreach($arr as $x) if (!isset($newarr[$x['uri']])) $newarr[$x['uri']] = $x; $arr = $newarr; - foreach ($arr as $x) { - if ($x['id'] == $x['parent']) { - $parents[] = $x; - } - } + foreach($arr as $x) + if($x['id'] == $x['parent']) + $parents[] = $x; - if (stristr($order,'created')) { + if(stristr($order,'created')) usort($parents,'sort_thr_created'); - } elseif (stristr($order,'commented')) { + elseif(stristr($order,'commented')) usort($parents,'sort_thr_commented'); - } - if (count($parents)) { - foreach($parents as $i=>$_x) { + if(count($parents)) + foreach($parents as $i=>$_x) $parents[$i]['children'] = get_item_children($arr, $_x); - } - } - /*foreach ($arr as $x) { - if ($x['id'] != $x['parent']) { + /*foreach($arr as $x) { + if($x['id'] != $x['parent']) { $p = find_thread_parent_index($parents,$x); - if ($p !== false) + if($p !== false) $parents[$p]['children'][] = $x; } }*/ - if (count($parents)) { - foreach ($parents as $k => $v) { - if (count($parents[$k]['children'])) { + if(count($parents)) { + foreach($parents as $k => $v) { + if(count($parents[$k]['children'])) { $parents[$k]['children'] = sort_item_children($parents[$k]['children']); /*$y = $parents[$k]['children']; usort($y,'sort_thr_created_rev'); @@ -1398,12 +1391,12 @@ function conv_sort($arr,$order) { } $ret = array(); - if (count($parents)) { - foreach ($parents as $x) { + if(count($parents)) { + foreach($parents as $x) { $ret[] = $x; - if (count($x['children'])) + if(count($x['children'])) add_children_to_list($x['children'], $ret); - /*foreach ($x['children'] as $y) + /*foreach($x['children'] as $y) $ret[] = $y;*/ } } @@ -1425,11 +1418,9 @@ function sort_thr_commented($a,$b) { } function find_thread_parent_index($arr,$x) { - foreach ($arr as $k => $v) { - if ($v['id'] == $x['parent']) { + foreach($arr as $k => $v) + if($v['id'] == $x['parent']) return $k; - } - } return false; } @@ -1443,16 +1434,17 @@ function render_location_dummy($item) { function get_responses($conv_responses,$response_verbs,$ob,$item) { $ret = array(); - foreach ($response_verbs as $v) { + foreach($response_verbs as $v) { $ret[$v] = array(); $ret[$v]['count'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri']] : ''); $ret[$v]['list'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri'] . '-l'] : ''); $ret[$v]['self'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri'] . '-self'] : '0'); - if (count($ret[$v]['list']) > MAX_LIKERS) { + if(count($ret[$v]['list']) > MAX_LIKERS) { $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS); array_push($ret[$v]['list_part'], '' . t('View all') . ''); - } else { + } + else { $ret[$v]['list_part'] = ''; } $ret[$v]['button'] = get_response_button_text($v,$ret[$v]['count']); @@ -1460,10 +1452,9 @@ function get_responses($conv_responses,$response_verbs,$ob,$item) { } $count = 0; - foreach ($ret as $key) { - if ($key['count'] == true) { + foreach($ret as $key) { + if ($key['count'] == true) $count++; - } } $ret['count'] = $count; diff --git a/include/cron.php b/include/cron.php index 9ab56ff43..ca9b5dff2 100644 --- a/include/cron.php +++ b/include/cron.php @@ -19,12 +19,12 @@ function cron_run(&$argv, &$argc){ $last = get_config('system','last_cron'); $poll_interval = intval(get_config('system','cron_interval')); - if (! $poll_interval) + if(! $poll_interval) $poll_interval = 10; - if ($last) { + if($last) { $next = $last + ($poll_interval * 60); - if ($next > time()) { + if($next > time()) { logger('cron intervall not reached'); return; } @@ -64,7 +64,7 @@ function cron_run(&$argv, &$argc){ $d1 = get_config('system','last_expire_day'); $d2 = intval(datetime_convert('UTC','UTC','now','d')); - if ($d2 != intval($d1)) { + if($d2 != intval($d1)) { update_contact_birthdays(); @@ -126,7 +126,7 @@ function cron_expire_and_remove_users() { // delete user and contact records for recently removed accounts $r = q("SELECT * FROM `user` WHERE `account_removed` AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY"); if ($r) { - foreach ($r as $user) { + foreach($r as $user) { q("DELETE FROM `contact` WHERE `uid` = %d", intval($user['uid'])); q("DELETE FROM `user` WHERE `uid` = %d", intval($user['uid'])); } @@ -171,7 +171,7 @@ function cron_poll_contacts($argc, $argv) { // we are unable to match those posts with a Diaspora GUID and prevent duplicates. $abandon_days = intval(get_config('system','account_abandon_days')); - if ($abandon_days < 1) + if($abandon_days < 1) $abandon_days = 0; $abandon_sql = (($abandon_days) @@ -210,7 +210,7 @@ function cron_poll_contacts($argc, $argv) { continue; } - foreach ($res as $contact) { + foreach($res as $contact) { $xml = false; @@ -232,7 +232,7 @@ function cron_poll_contacts($argc, $argv) { $contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3); } - if ($contact['priority'] AND !$force) { + if($contact['priority'] AND !$force) { $update = false; @@ -244,24 +244,24 @@ function cron_poll_contacts($argc, $argv) { switch ($contact['priority']) { case 5: - if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 month")) + if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 month")) $update = true; break; case 4: - if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 week")) + if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 week")) $update = true; break; case 3: - if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) + if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) $update = true; break; case 2: - if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 12 hour")) + if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 12 hour")) $update = true; break; case 1: default: - if (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 hour")) + if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 hour")) $update = true; break; } @@ -289,16 +289,14 @@ function cron_clear_cache(App $a) { $last = get_config('system','cache_last_cleared'); - if ($last) { + if($last) { $next = $last + (3600); // Once per hour $clear_cache = ($next <= time()); - } else { + } else $clear_cache = true; - } - if (!$clear_cache) { + if (!$clear_cache) return; - } // clear old cache Cache::clear(); @@ -317,9 +315,7 @@ function cron_clear_cache(App $a) { clear_cache($a->get_basepath(), $a->get_basepath()."/proxy"); $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); } @@ -332,30 +328,26 @@ function cron_clear_cache(App $a) { // Maximum table size in megabyte $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 - } if ($max_tablesize > 0) { // Minimum fragmentation level in percent $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% - } // Optimize some tables that need to be optimized $r = q("SHOW TABLE STATUS"); - foreach ($r as $table) { + foreach($r as $table) { // Don't optimize tables that are too large - if ($table["Data_length"] > $max_tablesize) { + if ($table["Data_length"] > $max_tablesize) continue; - } // Don't optimize empty tables - if ($table["Data_length"] == 0) { + if ($table["Data_length"] == 0) continue; - } // Calculate fragmentation $fragmentation = $table["Data_free"] / ($table["Data_length"] + $table["Index_length"]); @@ -363,9 +355,8 @@ function cron_clear_cache(App $a) { logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG); // Don't optimize tables that needn't to be optimized - if ($fragmentation < $fragmentation_level) { + if ($fragmentation < $fragmentation_level) continue; - } // So optimize it logger("Optimize Table ".$table["Name"], LOGGER_DEBUG); @@ -425,11 +416,9 @@ function cron_repair_database() { // 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`"); - if (dbm::is_result($r)) { - foreach ($r AS $user) { + if (dbm::is_result($r)) + foreach ($r AS $user) update_gcontact_for_user($user["uid"]); - } - } /// @todo /// - remove thread entries without item diff --git a/include/cronhooks.php b/include/cronhooks.php index 349cac4f4..bea0f6a19 100644 --- a/include/cronhooks.php +++ b/include/cronhooks.php @@ -8,25 +8,23 @@ function cronhooks_run(&$argv, &$argc){ require_once('include/datetime.php'); 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]) { logger("Calling cron hook '".$hook[1]."'", LOGGER_DEBUG); call_single_hook($a, $name, $hook, $data); } - } return; } $last = get_config('system', 'last_cronhook'); $poll_interval = intval(get_config('system','cronhook_interval')); - if (! $poll_interval) { + if(! $poll_interval) $poll_interval = 9; - } - if ($last) { + if($last) { $next = $last + ($poll_interval * 60); - if ($next > time()) { + if($next > time()) { logger('cronhook intervall not reached'); return; } diff --git a/include/crypto.php b/include/crypto.php index 7c931107c..f5163a9da 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -12,7 +12,7 @@ function rsa_sign($data,$key,$alg = 'sha256') { openssl_sign($data,$sig,$key,(($alg == 'sha1') ? OPENSSL_ALGO_SHA1 : $alg)); } else { - if (strlen($key) < 1024 || extension_loaded('gmp')) { + if(strlen($key) < 1024 || extension_loaded('gmp')) { require_once('library/phpsec/Crypt/RSA.php'); $rsa = new CRYPT_RSA(); $rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1; @@ -34,7 +34,7 @@ function rsa_verify($data,$sig,$key,$alg = 'sha256') { $verify = openssl_verify($data,$sig,$key,(($alg == 'sha1') ? OPENSSL_ALGO_SHA1 : $alg)); } else { - if (strlen($key) <= 300 || extension_loaded('gmp')) { + if(strlen($key) <= 300 || extension_loaded('gmp')) { require_once('library/phpsec/Crypt/RSA.php'); $rsa = new CRYPT_RSA(); $rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1; @@ -186,12 +186,12 @@ function salmon_key($pubkey) { -if (! function_exists('aes_decrypt')) { +if(! function_exists('aes_decrypt')) { // DEPRECATED IN 3.4.1 function aes_decrypt($val,$ky) { $key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; - for ($a=0;$a 1) { - if ($ex[0] != $continent) { - if ($continent != '') + if(count($ex) > 1) { + if($ex[0] != $continent) { + if($continent != '') $o .= ''; $continent = $ex[0]; $o .= ''; } - if (count($ex) > 2) { + if(count($ex) > 2) $city = substr($value,strpos($value,'/')+1); - } else { + else $city = $ex[1]; - } - } else { + } + else { $city = $ex[0]; - if ($continent != t('Miscellaneous')) { + if($continent != t('Miscellaneous')) { $o .= ''; $continent = t('Miscellaneous'); $o .= ''; @@ -114,11 +114,11 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d // Defaults to UTC if nothing is set, but throws an exception if set to empty string. // Provide some sane defaults regardless. - if ($from === '') + if($from === '') $from = 'UTC'; - if ($to === '') + if($to === '') $to = 'UTC'; - if ( ($s === '') || (! is_string($s)) ) + if( ($s === '') || (! is_string($s)) ) $s = 'now'; // Slight hackish adjustment so that 'zero' datetime actually returns what is intended @@ -126,7 +126,7 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d // add 32 days so that we at least get year 00, and then hack around the fact that // months and days always start with 1. - if (substr($s,0,10) == '0000-00-00') { + if(substr($s,0,10) == '0000-00-00') { $d = new DateTime($s . ' + 32 days', new DateTimeZone('UTC')); return str_replace('1','0',$d->format($fmt)); } @@ -169,9 +169,9 @@ function dob($dob) { list($year,$month,$day) = sscanf($dob,'%4d-%2d-%2d'); $f = get_config('system','birthday_input_format'); - if (! $f) + if(! $f) $f = 'ymd'; - if ($dob === '0000-00-00') + if($dob === '0000-00-00') $value = ''; else $value = (($year) ? datetime_convert('UTC','UTC',$dob,'Y-m-d') : datetime_convert('UTC','UTC',$dob,'m-d')); @@ -279,9 +279,9 @@ function datetimesel($format, $min, $max, $default, $label, $id = 'datetimepicke $o = ''; $dateformat = ''; - if ($pickdate) $dateformat .= 'Y-m-d'; - if ($pickdate && $picktime) $dateformat .= ' '; - if ($picktime) $dateformat .= 'H:i'; + if($pickdate) $dateformat .= 'Y-m-d'; + if($pickdate && $picktime) $dateformat .= ' '; + if($picktime) $dateformat .= 'H:i'; $minjs = $min ? ",minDate: new Date({$min->getTimestamp()}*1000), yearStart: " . $min->format('Y') : ''; $maxjs = $max ? ",maxDate: new Date({$max->getTimestamp()}*1000), yearEnd: " . $max->format('Y') : ''; @@ -290,14 +290,14 @@ function datetimesel($format, $min, $max, $default, $label, $id = 'datetimepicke $defaultdatejs = $default ? ",defaultDate: new Date({$default->getTimestamp()}*1000)" : ''; $pickers = ''; - if (!$pickdate) $pickers .= ',datepicker: false'; - if (!$picktime) $pickers .= ',timepicker: false'; + if(!$pickdate) $pickers .= ',datepicker: false'; + if(!$picktime) $pickers .= ',timepicker: false'; $extra_js = ''; $pickers .= ",dayOfWeekStart: ".$firstDay.",lang:'".$lang."'"; - if ($minfrom != '') + if($minfrom != '') $extra_js .= "\$('#id_$minfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#id_$id').data('xdsoft_datetimepicker').setOptions({minDate: currentDateTime})}})"; - if ($maxfrom != '') + if($maxfrom != '') $extra_js .= "\$('#id_$maxfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#id_$id').data('xdsoft_datetimepicker').setOptions({maxDate: currentDateTime})}})"; $readable_format = $dateformat; @@ -394,11 +394,11 @@ function relative_date($posted_date, $format = null) { * @return int Age in years */ function age($dob,$owner_tz = '',$viewer_tz = '') { - if (! intval($dob)) + if(! intval($dob)) return 0; - if (! $owner_tz) + if(! $owner_tz) $owner_tz = date_default_timezone_get(); - if (! $viewer_tz) + if(! $viewer_tz) $viewer_tz = date_default_timezone_get(); $birthdate = datetime_convert('UTC',$owner_tz,$dob . ' 00:00:00+00:00','Y-m-d'); @@ -407,7 +407,7 @@ function age($dob,$owner_tz = '',$viewer_tz = '') { $curr_month = datetime_convert('UTC',$viewer_tz,'now','m'); $curr_day = datetime_convert('UTC',$viewer_tz,'now','d'); - if (($curr_month < $month) || (($curr_month == $month) && ($curr_day < $day))) + if(($curr_month < $month) || (($curr_month == $month) && ($curr_day < $day))) $year_diff--; return $year_diff; @@ -430,10 +430,10 @@ function get_dim($y,$m) { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); - if ($m != 2) + if($m != 2) return $dim[$m]; - if (((($y % 4) == 0) && (($y % 100) != 0)) || (($y % 400) == 0)) + if(((($y % 4) == 0) && (($y % 100) != 0)) || (($y % 400) == 0)) return 29; return $dim[2]; @@ -486,12 +486,10 @@ function cal($y = 0,$m = 0, $links = false, $class='') { $thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y'); $thismonth = datetime_convert('UTC',date_default_timezone_get(),'now','m'); - if (! $y) { + if(! $y) $y = $thisyear; - } - if (! $m) { + if(! $m) $m = intval($thismonth); - } $dn = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); $f = get_first_dim($y,$m); @@ -500,33 +498,29 @@ function cal($y = 0,$m = 0, $links = false, $class='') { $dow = 0; $started = false; - if (($y == $thisyear) && ($m == $thismonth)) { + if(($y == $thisyear) && ($m == $thismonth)) $tddate = intval(datetime_convert('UTC',date_default_timezone_get(),'now','j')); - } $str_month = day_translate($mtab[$m]); $o = ''; $o .= ""; - for ($a = 0; $a < 7; $a ++) { + for($a = 0; $a < 7; $a ++) $o .= ''; - } $o .= ''; - while ($d <= $l) { - if (($dow == $f) && (! $started)) { + while($d <= $l) { + if(($dow == $f) && (! $started)) $started = true; - } $today = (((isset($tddate)) && ($tddate == $d)) ? "class=\"today\" " : ''); $o .= "'; $dow ++; - if (($dow == 7) && ($d <= $l)) { + if(($dow == 7) && ($d <= $l)) { $dow = 0; $o .= ''; } } - if ($dow) { - for ($a = $dow; $a < 7; $a ++) { + if($dow) + for($a = $dow; $a < 7; $a ++) $o .= ''; - } - } $o .= '
$str_month $y
' . mb_substr(day_translate($dn[$a]),0,3,'UTF-8') . '
"; $day = str_replace(' ',' ',sprintf('%2.2d', $d)); - if ($started) { - if (is_array($links) && isset($links[$d])) { + if($started) { + if(is_array($links) && isset($links[$d])) $o .= "$day"; - } else { + else $o .= $day; - } $d ++; } else { @@ -535,16 +529,14 @@ function cal($y = 0,$m = 0, $links = false, $class='') { $o .= '
 
'."\r\n"; diff --git a/include/dba_pdo.php b/include/dba_pdo.php index 56692fbb3..a44c447af 100644 --- a/include/dba_pdo.php +++ b/include/dba_pdo.php @@ -34,7 +34,7 @@ $objDDDBLResultHandler->add('PDOStatement', array('HANDLER' => $cloPDOStatementR * */ -if (! class_exists('dba')) { +if(! class_exists('dba')) { class dba { private $debug = 0; @@ -66,9 +66,9 @@ class dba { return; } - if ($install) { - if (strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) { - if (! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) { + if($install) { + if(strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) { + if(! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) { $this->error = sprintf( t('Cannot locate DNS info for database server \'%s\''), $server); $this->connected = false; $this->db = null; @@ -81,13 +81,13 @@ class dba { \DDDBL\connect(); $this->db = \DDDBL\getDB(); - if (\DDDBL\isConnected()) { + if(\DDDBL\isConnected()) { $this->connected = true; } - if (! $this->connected) { + if(! $this->connected) { $this->db = null; - if (! $install) + if(! $install) system_unavailable(); } @@ -109,11 +109,11 @@ class dba { $objPreparedQueryPool = new \DDDBL\DataObjectPool('Query-Definition'); # check if query do not exists till now, if so create its definition - if (!$objPreparedQueryPool->exists($strQueryAlias)) + if(!$objPreparedQueryPool->exists($strQueryAlias)) $objPreparedQueryPool->add($strQueryAlias, array('QUERY' => $sql, 'HANDLER' => $strHandler)); - if ((! $this->db) || (! $this->connected)) + if((! $this->db) || (! $this->connected)) return false; $this->error = ''; @@ -124,7 +124,7 @@ class dba { $r = \DDDBL\get($strQueryAlias); # bad workaround to emulate the bizzare behavior of mysql_query - if (in_array($strSQLType, array('INSERT', 'UPDATE', 'DELETE', 'CREATE', 'DROP', 'SET'))) + if(in_array($strSQLType, array('INSERT', 'UPDATE', 'DELETE', 'CREATE', 'DROP', 'SET'))) $result = true; $intErrorCode = false; @@ -138,7 +138,7 @@ class dba { $a->save_timestamp($stamp1, "database"); - if (x($a->config,'system') && x($a->config['system'],'db_log')) { + if(x($a->config,'system') && x($a->config['system'],'db_log')) { if (($duration > $a->config["system"]["db_loglimit"])) { $duration = round($duration, 3); $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); @@ -149,20 +149,20 @@ class dba { } } - if ($intErrorCode) + if($intErrorCode) $this->error = $intErrorCode; - if (strlen($this->error)) { + if(strlen($this->error)) { logger('dba: ' . $this->error); } - if ($this->debug) { + if($this->debug) { $mesg = ''; - if ($result === false) + if($result === false) $mesg = 'false'; - elseif ($result === true) + elseif($result === true) $mesg = 'true'; else { # this needs fixing, but is a bug itself @@ -182,13 +182,13 @@ class dba { * These usually indicate SQL syntax errors that need to be resolved. */ - if (isset($result) AND ($result === false)) { + if(isset($result) AND ($result === false)) { logger('dba: ' . printable($sql) . ' returned false.' . "\n" . $this->error); - if (file_exists('dbfail.out')) + if(file_exists('dbfail.out')) file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND); } - if (isset($result) AND (($result === true) || ($result === false))) + if(isset($result) AND (($result === true) || ($result === false))) return $result; if ($onlyquery) { @@ -199,7 +199,7 @@ class dba { //$a->save_timestamp($stamp1, "database"); - if ($this->debug) + if($this->debug) logger('dba: ' . printable(print_r($r, true))); return($r); } @@ -223,7 +223,7 @@ class dba { } public function escape($str) { - if ($this->db && $this->connected) { + if($this->db && $this->connected) { $strQuoted = $this->db->quote($str); # this workaround is needed, because quote creates "'" and the beginning and the end # of the string, which is correct. but until now the queries set this delimiter manually, @@ -238,27 +238,27 @@ class dba { } }} -if (! function_exists('printable')) { +if(! function_exists('printable')) { function printable($s) { $s = preg_replace("~([\x01-\x08\x0E-\x0F\x10-\x1F\x7F-\xFF])~",".", $s); $s = str_replace("\x00",'.',$s); - if (x($_SERVER,'SERVER_NAME')) + if(x($_SERVER,'SERVER_NAME')) $s = escape_tags($s); return $s; }} // Procedural functions -if (! function_exists('dbg')) { +if(! function_exists('dbg')) { function dbg($state) { global $db; - if ($db) + if($db) $db->dbg($state); }} -if (! function_exists('dbesc')) { +if(! function_exists('dbesc')) { function dbesc($str) { global $db; - if ($db && $db->connected) + if($db && $db->connected) return($db->escape($str)); else return(str_replace("'","\\'",$str)); @@ -271,17 +271,17 @@ function dbesc($str) { // Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d", // 'user', 1); -if (! function_exists('q')) { +if(! function_exists('q')) { function q($sql) { global $db; $args = func_get_args(); unset($args[0]); - if ($db && $db->connected) { + if($db && $db->connected) { $stmt = @vsprintf($sql,$args); // Disabled warnings //logger("dba: q: $stmt", LOGGER_ALL); - if ($stmt === false) + if($stmt === false) logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true), LOGGER_DEBUG); return $db->q($stmt); } @@ -303,11 +303,11 @@ function q($sql) { * */ -if (! function_exists('dbq')) { +if(! function_exists('dbq')) { function dbq($sql) { global $db; - if ($db && $db->connected) + if($db && $db->connected) $ret = $db->q($sql); else $ret = false; @@ -321,21 +321,21 @@ function dbq($sql) { // cast to int to avoid trouble. -if (! function_exists('dbesc_array_cb')) { +if(! function_exists('dbesc_array_cb')) { function dbesc_array_cb(&$item, $key) { - if (is_string($item)) + if(is_string($item)) $item = dbesc($item); }} -if (! function_exists('dbesc_array')) { +if(! function_exists('dbesc_array')) { function dbesc_array(&$arr) { - if (is_array($arr) && count($arr)) { + if(is_array($arr) && count($arr)) { array_walk($arr,'dbesc_array_cb'); } }} -if (! function_exists('dba_timer')) { +if(! function_exists('dba_timer')) { function dba_timer() { return microtime(true); }} diff --git a/include/dbstructure.php b/include/dbstructure.php index 0a52a751c..48cc02d2d 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -404,7 +404,7 @@ function db_create_table($name, $fields, $charset, $verbose, $action, $indexes=n $sql_rows = array(); $primary_keys = array(); - foreach ($fields AS $fieldname => $field) { + foreach($fields AS $fieldname => $field) { $sql_rows[] = "`".dbesc($fieldname)."` ".db_field_command($field); if (x($field,'primary') and $field['primary']!=''){ $primary_keys[] = $fieldname; @@ -1621,11 +1621,11 @@ function db_definition($charset) { function dbstructure_run(&$argv, &$argc) { global $a, $db; - if (is_null($a)){ + if(is_null($a)){ $a = new App; } - if (is_null($db)) { + if(is_null($db)) { @include(".htconfig.php"); require_once("include/dba.php"); $db = new dba($db_host, $db_user, $db_pass, $db_data); @@ -1650,7 +1650,7 @@ function dbstructure_run(&$argv, &$argc) { $current = intval(DB_UPDATE_VERSION); // run any left update_nnnn functions in update.php - for ($x = $stored; $x < $current; $x ++) { + for($x = $stored; $x < $current; $x ++) { $r = run_update_function($x); if (!$r) break; } diff --git a/include/dfrn.php b/include/dfrn.php index 9fa19bde6..25f8c9358 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -41,7 +41,6 @@ class dfrn { * @param array $owner Owner record * * @return string DFRN entries - * @todo Add type-hints */ public static function entries($items,$owner) { @@ -50,11 +49,10 @@ class dfrn { $root = self::add_header($doc, $owner, "dfrn:owner", "", false); - if (! count($items)) { + if(! count($items)) return trim($doc->saveXML()); - } - foreach ($items as $item) { + foreach($items as $item) { $entry = self::entry($doc, "text", $item, $owner, $item["entry:comment-allow"], $item["entry:cid"]); $root->appendChild($entry); } @@ -84,17 +82,14 @@ class dfrn { $starred = false; // not yet implemented, possible security issues $converse = false; - if ($public_feed && $a->argc > 2) { - for ($x = 2; $x < $a->argc; $x++) { - if ($a->argv[$x] == 'converse') { + if($public_feed && $a->argc > 2) { + for($x = 2; $x < $a->argc; $x++) { + if($a->argv[$x] == 'converse') $converse = true; - } - if ($a->argv[$x] == 'starred') { + if($a->argv[$x] == 'starred') $starred = true; - } - if ($a->argv[$x] == 'category' && $a->argc > ($x + 1) && strlen($a->argv[$x+1])) { + if($a->argv[$x] == 'category' && $a->argc > ($x + 1) && strlen($a->argv[$x+1])) $category = $a->argv[$x+1]; - } } } @@ -120,7 +115,7 @@ class dfrn { $sql_post_table = ""; - if (! $public_feed) { + if(! $public_feed) { $sql_extra = ''; switch($direction) { @@ -153,13 +148,12 @@ class dfrn { require_once('include/security.php'); $groups = init_groups_visitor($contact['id']); - if (count($groups)) { - for ($x = 0; $x < count($groups); $x ++) + if(count($groups)) { + for($x = 0; $x < count($groups); $x ++) $groups[$x] = '<' . intval($groups[$x]) . '>' ; $gs = implode('|', $groups); - } else { + } else $gs = '<<>>' ; // Impossible to match - } $sql_extra = sprintf(" AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) @@ -174,26 +168,23 @@ class dfrn { ); } - if ($public_feed) { + if($public_feed) $sort = 'DESC'; - } else { + else $sort = 'ASC'; - } - if (! strlen($last_update)) { + if(! strlen($last_update)) $last_update = 'now -30 days'; - } - if (isset($category)) { + if(isset($category)) { $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", dbesc(protect_sprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($owner_id)); //$sql_extra .= file_tag_file_query('item',$category,'category'); } - if ($public_feed) { - if (! $converse) { + if($public_feed) { + if(! $converse) $sql_extra .= " AND `contact`.`self` = 1 "; - } } $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s'); @@ -216,11 +207,6 @@ class dfrn { dbesc($sort) ); - if (!dbm::is_result($r)) { - logger("Query failed to execute, no result returned in " . __FUNCTION__); - killme(); - } - // Will check further below if this actually returned results. // We will provide an empty feed if that is the case. @@ -231,15 +217,13 @@ class dfrn { $alternatelink = $owner['url']; - if (isset($category)) { + if(isset($category)) $alternatelink .= "/category/".$category; - } - if ($public_feed) { + if ($public_feed) $author = "dfrn:owner"; - } else { + else $author = "author"; - } $root = self::add_header($doc, $owner, $author, $alternatelink, true); @@ -254,24 +238,21 @@ class dfrn { return $atom; } - foreach ($items as $item) { + foreach($items as $item) { // prevent private email from leaking. - if ($item['network'] == NETWORK_MAIL) { + if($item['network'] == NETWORK_MAIL) continue; - } // public feeds get html, our own nodes use bbcode - if ($public_feed) { + if($public_feed) { $type = 'html'; // catch any email that's in a public conversation and make sure it doesn't leak - if ($item['private']) { + if($item['private']) continue; - } - } else { + } else $type = 'text'; - } $entry = self::entry($doc, $type, $item, $owner, true); $root->appendChild($entry); @@ -292,7 +273,6 @@ class dfrn { * @param array $owner Owner record * * @return string DFRN mail - * @todo Add type-hints */ public static function mail($item, $owner) { $doc = new DOMDocument('1.0', 'utf-8'); @@ -327,7 +307,6 @@ class dfrn { * @param array $owner Owner record * * @return string DFRN suggestions - * @todo Add type-hints */ public static function fsuggest($item, $owner) { $doc = new DOMDocument('1.0', 'utf-8'); @@ -355,13 +334,12 @@ class dfrn { * @param int $uid User ID * * @return string DFRN relocations - * @todo Add type-hints */ public static function relocate($owner, $uid) { /* get site pubkey. this could be a new installation with no site keys*/ $pubkey = get_config('system','site_pubkey'); - if (! $pubkey) { + if(! $pubkey) { $res = new_keypair(1024); set_config('system','site_prvkey', $res['prvkey']); set_config('system','site_pubkey', $res['pubkey']); @@ -372,9 +350,8 @@ class dfrn { $photos = array(); $ext = Photo::supportedTypes(); - foreach ($rp as $p) { + foreach($rp as $p) $photos[$p['scale']] = app::get_baseurl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']]; - } unset($rp, $ext); @@ -413,13 +390,11 @@ class dfrn { * @param bool $public Is it a header for public posts? * * @return object XML root object - * @todo Add type-hints */ private static function add_header($doc, $owner, $authorelement, $alternatelink = "", $public = false) { - if ($alternatelink == "") { + if ($alternatelink == "") $alternatelink = $owner['url']; - } $root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed'); $doc->appendChild($root); @@ -462,9 +437,8 @@ class dfrn { } // For backward compatibility we keep this element - if ($owner['page-flags'] == PAGE_COMMUNITY) { + if ($owner['page-flags'] == PAGE_COMMUNITY) xml::add_element($doc, $root, "dfrn:community", 1); - } // The former element is replaced by this one xml::add_element($doc, $root, "dfrn:account_type", $owner["account-type"]); @@ -487,7 +461,6 @@ class dfrn { * @param string $authorelement Element name for the author * * @return object XML author object - * @todo Add type-hints */ private static function add_author($doc, $owner, $authorelement, $public) { @@ -495,11 +468,10 @@ class dfrn { $r = q("SELECT `id` FROM `profile` INNER JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE (`hidewall` OR NOT `net-publish`) AND `user`.`uid` = %d", intval($owner['uid'])); - if (dbm::is_result($r)) { + if ($r) $hidewall = true; - } else { + else $hidewall = false; - } $author = $doc->createElement($authorelement); @@ -507,11 +479,10 @@ class dfrn { $uridate = datetime_convert('UTC', 'UTC', $owner['uri-date'].'+00:00', ATOM_TIME); $picdate = datetime_convert('UTC', 'UTC', $owner['avatar-date'].'+00:00', ATOM_TIME); - $attributes = array(); - - if (!$public OR !$hidewall) { + if (!$public OR !$hidewall) $attributes = array("dfrn:updated" => $namdate); - } + else + $attributes = array(); xml::add_element($doc, $author, "name", $owner["name"], $attributes); xml::add_element($doc, $author, "uri", app::get_baseurl().'/profile/'.$owner["nickname"], $attributes); @@ -520,23 +491,20 @@ class dfrn { $attributes = array("rel" => "photo", "type" => "image/jpeg", "media:width" => 175, "media:height" => 175, "href" => $owner['photo']); - if (!$public OR !$hidewall) { + if (!$public OR !$hidewall) $attributes["dfrn:updated"] = $picdate; - } xml::add_element($doc, $author, "link", "", $attributes); $attributes["rel"] = "avatar"; xml::add_element($doc, $author, "link", "", $attributes); - if ($hidewall) { + if ($hidewall) xml::add_element($doc, $author, "dfrn:hide", "true"); - } // The following fields will only be generated if the data isn't meant for a public feed - if ($public) { + if ($public) return $author; - } $birthday = feed_birthday($owner['uid'], $owner['timezone']); @@ -551,7 +519,7 @@ class dfrn { INNER JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `profile`.`is-default` AND NOT `user`.`hidewall` AND `user`.`uid` = %d", intval($owner['uid'])); - if (dbm::is_result($r)) { + if ($r) { $profile = $r[0]; xml::add_element($doc, $author, "poco:displayName", $profile["name"]); @@ -579,9 +547,8 @@ class dfrn { if (trim($profile["pub_keywords"]) != "") { $keywords = explode(",", $profile["pub_keywords"]); - foreach ($keywords AS $keyword) { + foreach ($keywords AS $keyword) xml::add_element($doc, $author, "poco:tags", trim($keyword)); - } } @@ -598,17 +565,14 @@ class dfrn { xml::add_element($doc, $element, "poco:formatted", formatted_location($profile)); - if (trim($profile["locality"]) != "") { + if (trim($profile["locality"]) != "") xml::add_element($doc, $element, "poco:locality", $profile["locality"]); - } - if (trim($profile["region"]) != "") { + if (trim($profile["region"]) != "") xml::add_element($doc, $element, "poco:region", $profile["region"]); - } - if (trim($profile["country-name"]) != "") { + if (trim($profile["country-name"]) != "") xml::add_element($doc, $element, "poco:country", $profile["country-name"]); - } $author->appendChild($element); } @@ -626,7 +590,6 @@ class dfrn { * @param array $items Item elements * * @return object XML author object - * @todo Add type-hints */ private static function add_entry_author($doc, $element, $contact_url, $item) { @@ -667,32 +630,25 @@ class dfrn { * @param string $activity activity value * * @return object XML activity object - * @todo Add type-hints */ private static function create_activity($doc, $element, $activity) { - if ($activity) { + if($activity) { $entry = $doc->createElement($element); $r = parse_xml_string($activity, false); - if (!$r) { + if(!$r) return false; - } - if ($r->type) { + if($r->type) xml::add_element($doc, $entry, "activity:object-type", $r->type); - } - if ($r->id) { + if($r->id) xml::add_element($doc, $entry, "id", $r->id); - } - if ($r->title) { + if($r->title) xml::add_element($doc, $entry, "title", $r->title); - } - - if ($r->link) { - if (substr($r->link,0,1) == '<') { - if (strstr($r->link,'&') && (! strstr($r->link,'&'))) { + if($r->link) { + if(substr($r->link,0,1) == '<') { + if(strstr($r->link,'&') && (! strstr($r->link,'&'))) $r->link = str_replace('&','&', $r->link); - } $r->link = preg_replace('/\/','',$r->link); @@ -701,9 +657,8 @@ class dfrn { if (is_object($data)) { foreach ($data->link AS $link) { $attributes = array(); - foreach ($link->attributes() AS $parameter => $value) { + foreach ($link->attributes() AS $parameter => $value) $attributes[$parameter] = $value; - } xml::add_element($doc, $entry, "link", "", $attributes); } } @@ -712,9 +667,8 @@ class dfrn { xml::add_element($doc, $entry, "link", "", $attributes); } } - if ($r->content) { + if($r->content) xml::add_element($doc, $entry, "content", bbcode($r->content), array("type" => "html")); - } return $entry; } @@ -730,26 +684,23 @@ class dfrn { * @param array $item Item element * * @return object XML attachment object - * @todo Add type-hints */ private static function get_attachment($doc, $root, $item) { $arr = explode('[/attach],',$item['attach']); - if (count($arr)) { - foreach ($arr as $r) { + if(count($arr)) { + foreach($arr as $r) { $matches = false; $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches); - if ($cnt) { + if($cnt) { $attributes = array("rel" => "enclosure", "href" => $matches[1], "type" => $matches[3]); - if (intval($matches[2])) { + if(intval($matches[2])) $attributes["length"] = intval($matches[2]); - } - if (trim($matches[4]) != "") { + if(trim($matches[4]) != "") $attributes["title"] = trim($matches[4]); - } xml::add_element($doc, $root, "link", "", $attributes); } @@ -768,28 +719,25 @@ class dfrn { * @param int $cid Contact ID of the recipient * * @return object XML entry object - * @todo Add type-hints */ private static function entry($doc, $type, $item, $owner, $comment = false, $cid = 0) { $mentioned = array(); - if (!$item['parent']) { + if(!$item['parent']) return; - } - if ($item['deleted']) { + if($item['deleted']) { $attributes = array("ref" => $item['uri'], "when" => datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)); return xml::create_element($doc, "at:deleted-entry", "", $attributes); } $entry = $doc->createElement("entry"); - if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) { + if($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) $body = fix_private_photos($item['body'],$owner['uid'],$item,$cid); - } else { + else $body = $item['body']; - } // Remove the abstract element. It is only locally important. $body = remove_abstract($body); @@ -797,9 +745,8 @@ class dfrn { if ($type == 'html') { $htmlbody = $body; - if ($item['title'] != "") { + if ($item['title'] != "") $htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody; - } $htmlbody = bbcode($htmlbody, false, false, 7); } @@ -810,7 +757,7 @@ class dfrn { $dfrnowner = self::add_entry_author($doc, "dfrn:owner", $item["owner-link"], $item); $entry->appendChild($dfrnowner); - if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) { + if(($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) { $parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"])); $parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']); $attributes = array("ref" => $parent_item, "type" => "text/html", @@ -838,100 +785,78 @@ class dfrn { // "comment-allow" is some old fashioned stuff for old Friendica versions. // It is included in the rewritten code for completeness - if ($comment) { + if ($comment) xml::add_element($doc, $entry, "dfrn:comment-allow", intval($item['last-child'])); - } - if ($item['location']) { + if($item['location']) xml::add_element($doc, $entry, "dfrn:location", $item['location']); - } - if ($item['coord']) { + if($item['coord']) xml::add_element($doc, $entry, "georss:point", $item['coord']); - } - if (($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) { + if(($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) xml::add_element($doc, $entry, "dfrn:private", (($item['private']) ? $item['private'] : 1)); - } - if ($item['extid']) { + if($item['extid']) xml::add_element($doc, $entry, "dfrn:extid", $item['extid']); - } - if ($item['bookmark']) { + if($item['bookmark']) xml::add_element($doc, $entry, "dfrn:bookmark", "true"); - } - if ($item['app']) { + if($item['app']) xml::add_element($doc, $entry, "statusnet:notice_info", "", array("local_id" => $item['id'], "source" => $item['app'])); - } xml::add_element($doc, $entry, "dfrn:diaspora_guid", $item["guid"]); // The signed text contains the content in Markdown, the sender handle and the signatur for the content // It is needed for relayed comments to Diaspora. - if ($item['signed_text']) { + if($item['signed_text']) { $sign = base64_encode(json_encode(array('signed_text' => $item['signed_text'],'signature' => $item['signature'],'signer' => $item['signer']))); xml::add_element($doc, $entry, "dfrn:diaspora_signature", $sign); } xml::add_element($doc, $entry, "activity:verb", construct_verb($item)); - if ($item['object-type'] != "") { + if ($item['object-type'] != "") xml::add_element($doc, $entry, "activity:object-type", $item['object-type']); - } elseif ($item['id'] == $item['parent']) { + elseif ($item['id'] == $item['parent']) xml::add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE); - } else { + else xml::add_element($doc, $entry, "activity:object-type", ACTIVITY_OBJ_COMMENT); - } $actobj = self::create_activity($doc, "activity:object", $item['object']); - if ($actobj) { + if ($actobj) $entry->appendChild($actobj); - } $actarg = self::create_activity($doc, "activity:target", $item['target']); - if ($actarg) { + if ($actarg) $entry->appendChild($actarg); - } $tags = item_getfeedtags($item); - if (count($tags)) { - foreach ($tags as $t) { - if (($type != 'html') OR ($t[0] != "@")) { + if(count($tags)) { + foreach($tags as $t) + if (($type != 'html') OR ($t[0] != "@")) xml::add_element($doc, $entry, "category", "", array("scheme" => "X-DFRN:".$t[0].":".$t[1], "term" => $t[2])); - } - } } - if (count($tags)) { - foreach ($tags as $t) { - if ($t[0] == "@") { + if(count($tags)) + foreach($tags as $t) + if ($t[0] == "@") $mentioned[$t[1]] = $t[1]; - } - } - } foreach ($mentioned AS $mention) { $r = q("SELECT `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'", intval($owner["uid"]), dbesc(normalise_link($mention))); - - if (!dbm::is_result($r)) { - /// @TODO Maybe some logging? - killme(); - } - - if ($r[0]["forum"] OR $r[0]["prv"]) { + if ($r[0]["forum"] OR $r[0]["prv"]) xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_GROUP, "href" => $mention)); - } else { + else xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_PERSON, "href" => $mention)); - } } self::get_attachment($doc, $entry, $item); @@ -948,7 +873,6 @@ class dfrn { * @param bool $dissolve (to be documented) * * @return int Deliver status. -1 means an error. - * @todo Add array type-hint for $owner, $contact */ public static function deliver($owner,$contact,$atom, $dissolve = false) { @@ -956,20 +880,16 @@ class dfrn { $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']); - if ($contact['duplex'] && $contact['dfrn-id']) { + if($contact['duplex'] && $contact['dfrn-id']) $idtosend = '0:' . $orig_id; - } - if ($contact['duplex'] && $contact['issued-id']) { + if($contact['duplex'] && $contact['issued-id']) $idtosend = '1:' . $orig_id; - } + $rino = get_config('system','rino_encrypt'); $rino = intval($rino); - // use RINO1 if mcrypt isn't installed and RINO2 was selected - if ($rino == 2 and !function_exists('mcrypt_create_iv')) { - $rino = 1; - } + if ($rino==2 and !function_exists('mcrypt_create_iv')) $rino=1; logger("Local rino version: ". $rino, LOGGER_DEBUG); @@ -1008,11 +928,10 @@ class dfrn { logger('dfrn_deliver: ' . $xml, LOGGER_DATA); - if (! $xml) { + if(! $xml) return 3; - } - if (strpos($xml,'status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) { + if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) return (($res->status) ? $res->status : 3); - } $postvars = array(); $sent_dfrn_id = hex2bin((string) $res->dfrn_id); @@ -1034,14 +952,13 @@ class dfrn { logger("Remote rino version: ".$rino_remote_version." for ".$contact["url"], LOGGER_DEBUG); - if ($owner['page-flags'] == PAGE_PRVGROUP) { + if($owner['page-flags'] == PAGE_PRVGROUP) $page = 2; - } $final_dfrn_id = ''; - if ($perm) { - if ((($perm == 'rw') && (! intval($contact['writable']))) + if($perm) { + if((($perm == 'rw') && (! intval($contact['writable']))) || (($perm == 'r') && (intval($contact['writable'])))) { q("update contact set writable = %d where id = %d", intval(($perm == 'rw') ? 1 : 0), @@ -1051,7 +968,7 @@ class dfrn { } } - if (($contact['duplex'] && strlen($contact['pubkey'])) + if(($contact['duplex'] && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey'])) || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) { openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']); @@ -1063,11 +980,10 @@ class dfrn { $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.')); - if (strpos($final_dfrn_id,':') == 1) { + if(strpos($final_dfrn_id,':') == 1) $final_dfrn_id = substr($final_dfrn_id,2); - } - if ($final_dfrn_id != $orig_id) { + if($final_dfrn_id != $orig_id) { logger('dfrn_deliver: wrong dfrn_id.'); // did not decode properly - cannot trust this site return 3; @@ -1075,12 +991,11 @@ class dfrn { $postvars['dfrn_id'] = $idtosend; $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; - if ($dissolve) { + if($dissolve) $postvars['dissolve'] = '1'; - } - if ((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) { + if((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) { $postvars['data'] = $atom; $postvars['perm'] = 'rw'; } else { @@ -1090,12 +1005,11 @@ class dfrn { $postvars['ssl_policy'] = $ssl_policy; - if ($page) { + if($page) $postvars['page'] = $page; - } - if ($rino > 0 && $rino_remote_version > 0 && (! $dissolve)) { + if($rino>0 && $rino_remote_version>0 && (! $dissolve)) { logger('rino version: '. $rino_remote_version); switch($rino_remote_version) { @@ -1133,25 +1047,23 @@ class dfrn { $postvars['rino'] = $rino_remote_version; $postvars['data'] = bin2hex($data); - //logger('rino: sent key = ' . $key, LOGGER_DEBUG); + #logger('rino: sent key = ' . $key, LOGGER_DEBUG); - if ($dfrn_version >= 2.1) { - if (($contact['duplex'] && strlen($contact['pubkey'])) + if($dfrn_version >= 2.1) { + if(($contact['duplex'] && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey'])) - || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) { + || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']); - } else { + else openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']); - } } else { - if (($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) { + if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']); - } else { + else openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']); - } } @@ -1176,13 +1088,12 @@ class dfrn { return -10; } - if (strpos($xml,' here? Maybe DateTime (which allows such comparison again) is much safer/correcter if ($contact['term-date'] > NULL_DATE) { logger("dfrn_deliver: $url back from the dead - removing mark for death"); require_once('include/Contact.php'); @@ -1199,7 +1110,7 @@ class dfrn { * * @param array $contact Contact record * @param string $birthday Birthday of the contact - * @todo Add array type-hint for $contact + * */ private static function birthday_event($contact, $birthday) { @@ -1243,7 +1154,6 @@ class dfrn { * @param bool $onlyfetch Should the data only be fetched or should it update the contact record as well * * @return Returns an array with relevant data of the author - * @todo Find good type-hints for all parameter */ private static function fetchauthor($xpath, $context, $importer, $element, $onlyfetch, $xml = "") { @@ -1255,15 +1165,13 @@ class dfrn { `name`, `nick`, `about`, `location`, `keywords`, `xmpp`, `bdyear`, `bd`, `hidden`, `contact-type` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'", intval($importer["uid"]), dbesc(normalise_link($author["link"])), dbesc(NETWORK_STATUSNET)); - - if (dbm::is_result($r)) { + if ($r) { $contact = $r[0]; $author["contact-id"] = $r[0]["id"]; $author["network"] = $r[0]["network"]; } else { - if (!$onlyfetch) { + if (!$onlyfetch) logger("Contact ".$author["link"]." wasn't found for user ".$importer["uid"]." XML: ".$xml, LOGGER_DEBUG); - } $author["contact-id"] = $importer["id"]; $author["network"] = $importer["network"]; @@ -1274,81 +1182,66 @@ class dfrn { $avatarlist = array(); /// @todo check if "avatar" or "photo" would be the best field in the specification $avatars = $xpath->query($element."/atom:link[@rel='avatar']", $context); - foreach ($avatars AS $avatar) { + foreach($avatars AS $avatar) { $href = ""; $width = 0; - foreach ($avatar->attributes AS $attributes) { - /// @TODO Rewrite these similar if () to one switch - if ($attributes->name == "href") { + foreach($avatar->attributes AS $attributes) { + if ($attributes->name == "href") $href = $attributes->textContent; - } - if ($attributes->name == "width") { + if ($attributes->name == "width") $width = $attributes->textContent; - } - if ($attributes->name == "updated") { + if ($attributes->name == "updated") $contact["avatar-date"] = $attributes->textContent; - } } - if (($width > 0) AND ($href != "")) { + if (($width > 0) AND ($href != "")) $avatarlist[$width] = $href; - } } if (count($avatarlist) > 0) { krsort($avatarlist); $author["avatar"] = current($avatarlist); } - if (dbm::is_result($r) AND !$onlyfetch) { + if ($r AND !$onlyfetch) { logger("Check if contact details for contact ".$r[0]["id"]." (".$r[0]["nick"].") have to be updated.", LOGGER_DEBUG); $poco = array("url" => $contact["url"]); // When was the last change to name or uri? $name_element = $xpath->query($element."/atom:name", $context)->item(0); - foreach ($name_element->attributes AS $attributes) { - if ($attributes->name == "updated") { + foreach($name_element->attributes AS $attributes) + if ($attributes->name == "updated") $poco["name-date"] = $attributes->textContent; - } - } $link_element = $xpath->query($element."/atom:link", $context)->item(0); - foreach ($link_element->attributes AS $attributes) { - if ($attributes->name == "updated") { + foreach($link_element->attributes AS $attributes) + if ($attributes->name == "updated") $poco["uri-date"] = $attributes->textContent; - } - } // Update contact data $value = $xpath->evaluate($element."/dfrn:handle/text()", $context)->item(0)->nodeValue; - if ($value != "") { + if ($value != "") $poco["addr"] = $value; - } $value = $xpath->evaluate($element."/poco:displayName/text()", $context)->item(0)->nodeValue; - if ($value != "") { + if ($value != "") $poco["name"] = $value; - } $value = $xpath->evaluate($element."/poco:preferredUsername/text()", $context)->item(0)->nodeValue; - if ($value != "") { + if ($value != "") $poco["nick"] = $value; - } $value = $xpath->evaluate($element."/poco:note/text()", $context)->item(0)->nodeValue; - if ($value != "") { + if ($value != "") $poco["about"] = $value; - } $value = $xpath->evaluate($element."/poco:address/poco:formatted/text()", $context)->item(0)->nodeValue; - if ($value != "") { + if ($value != "") $poco["location"] = $value; - } /// @todo Only search for elements with "poco:type" = "xmpp" $value = $xpath->evaluate($element."/poco:ims/poco:value/text()", $context)->item(0)->nodeValue; - if ($value != "") { + if ($value != "") $poco["xmpp"] = $value; - } /// @todo Add support for the following fields that we don't support by now in the contact table: /// - poco:utcOffset @@ -1364,20 +1257,17 @@ class dfrn { // If the contact isn't searchable then set the contact to "hidden". // Problem: This can be manually overridden by the user. - if ($hide) { + if ($hide) $contact["hidden"] = true; - } // Save the keywords into the contact table $tags = array(); $tagelements = $xpath->evaluate($element."/poco:tags/text()", $context); - foreach ($tagelements AS $tag) { + foreach($tagelements AS $tag) $tags[$tag->nodeValue] = $tag->nodeValue; - } - if (count($tags)) { + if (count($tags)) $poco["keywords"] = implode(", ", $tags); - } // "dfrn:birthday" contains the birthday converted to UTC $old_bdyear = $contact["bdyear"]; @@ -1407,15 +1297,13 @@ class dfrn { $contact = array_merge($contact, $poco); - if ($old_bdyear != $contact["bdyear"]) { + if ($old_bdyear != $contact["bdyear"]) self::birthday_event($contact, $birthday); - } // Get all field names $fields = array(); - foreach ($r[0] AS $field => $data) { + foreach ($r[0] AS $field => $data) $fields[$field] = $data; - } unset($fields["id"]); unset($fields["uid"]); @@ -1426,19 +1314,17 @@ class dfrn { // Update check for this field has to be done differently $datefields = array("name-date", "uri-date"); - foreach ($datefields AS $field) { + foreach ($datefields AS $field) if (strtotime($contact[$field]) > strtotime($r[0][$field])) { logger("Difference for contact ".$contact["id"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$r[0][$field]."'", LOGGER_DEBUG); $update = true; } - } - foreach ($fields AS $field => $data) { + foreach ($fields AS $field => $data) if ($contact[$field] != $r[0][$field]) { logger("Difference for contact ".$contact["id"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$r[0][$field]."'", LOGGER_DEBUG); $update = true; } - } if ($update) { logger("Update contact data for contact ".$contact["id"]." (".$contact["nick"].")", LOGGER_DEBUG); @@ -1480,12 +1366,10 @@ class dfrn { * @param text $element element name * * @return string XML string - * @todo Find good type-hints for all parameter */ private static function transform_activity($xpath, $activity, $element) { - if (!is_object($activity)) { + if (!is_object($activity)) return ""; - } $obj_doc = new DOMDocument("1.0", "utf-8"); $obj_doc->formatOutput = true; @@ -1496,26 +1380,21 @@ class dfrn { xml::add_element($obj_doc, $obj_element, "type", $activity_type); $id = $xpath->query("atom:id", $activity)->item(0); - if (is_object($id)) { + if (is_object($id)) $obj_element->appendChild($obj_doc->importNode($id, true)); - } $title = $xpath->query("atom:title", $activity)->item(0); - if (is_object($title)) { + if (is_object($title)) $obj_element->appendChild($obj_doc->importNode($title, true)); - } $links = $xpath->query("atom:link", $activity); - if (is_object($links)) { - foreach ($links AS $link) { + if (is_object($links)) + foreach ($links AS $link) $obj_element->appendChild($obj_doc->importNode($link, true)); - } - } $content = $xpath->query("atom:content", $activity)->item(0); - if (is_object($content)) { + if (is_object($content)) $obj_element->appendChild($obj_doc->importNode($content, true)); - } $obj_doc->appendChild($obj_element); @@ -1532,13 +1411,11 @@ class dfrn { * @param object $xpath XPath object * @param object $mail mail elements * @param array $importer Record of the importer user mixed with contact of the content - * @todo Find good type-hints for all parameter */ private static function process_mail($xpath, $mail, $importer) { logger("Processing mails"); - /// @TODO Rewrite this to one statement $msg = array(); $msg["uid"] = $importer["importer_uid"]; $msg["from-name"] = $xpath->query("dfrn:sender/dfrn:name/text()", $mail)->item(0)->nodeValue; @@ -1558,7 +1435,7 @@ class dfrn { $r = dbq("INSERT INTO `mail` (`".implode("`, `", array_keys($msg))."`) VALUES (".implode(", ", array_values($msg)).")"); // send notifications. - /// @TODO Arange this mess + $notif_params = array( "type" => NOTIFY_MAIL, "notify_flags" => $importer["notify-flags"], @@ -1585,14 +1462,12 @@ class dfrn { * @param object $xpath XPath object * @param object $suggestion suggestion elements * @param array $importer Record of the importer user mixed with contact of the content - * @todo Find good type-hints for all parameter */ private static function process_suggestion($xpath, $suggestion, $importer) { $a = get_app(); logger("Processing suggestions"); - /// @TODO Rewrite this to one statement $suggest = array(); $suggest["uid"] = $importer["importer_uid"]; $suggest["cid"] = $importer["id"]; @@ -1609,11 +1484,8 @@ class dfrn { dbesc(normalise_link($suggest["url"])), intval($suggest["uid"]) ); - - if (dbm::is_result($r)) { - // Has already friend matching description + if (dbm::is_result($r)) return false; - } // Do we already have an fcontact record for this person? @@ -1631,12 +1503,10 @@ class dfrn { intval($suggest["uid"]), intval($fid) ); - /// @TODO Really abort on valid result??? Maybe missed ! here? - if (dbm::is_result($r)) { + if (dbm::is_result($r)) return false; - } } - if (!$fid) + if(!$fid) $r = q("INSERT INTO `fcontact` (`name`,`url`,`photo`,`request`) VALUES ('%s', '%s', '%s', '%s')", dbesc($suggest["name"]), dbesc($suggest["url"]), @@ -1648,12 +1518,11 @@ class dfrn { dbesc($suggest["name"]), dbesc($suggest["request"]) ); - if (dbm::is_result($r)) { + if (dbm::is_result($r)) $fid = $r[0]["id"]; - } else { + else // database record did not get created. Quietly give up. - killme(); - } + return false; $hash = random_string(); @@ -1695,13 +1564,11 @@ class dfrn { * @param object $xpath XPath object * @param object $relocation relocation elements * @param array $importer Record of the importer user mixed with contact of the content - * @todo Find good type-hints for all parameter */ private static function process_relocation($xpath, $relocation, $importer) { logger("Processing relocations"); - /// @TODO Rewrite this to one statement $relocate = array(); $relocate["uid"] = $importer["importer_uid"]; $relocate["cid"] = $importer["id"]; @@ -1718,23 +1585,18 @@ class dfrn { $relocate["poll"] = $xpath->query("dfrn:poll/text()", $relocation)->item(0)->nodeValue; $relocate["sitepubkey"] = $xpath->query("dfrn:sitepubkey/text()", $relocation)->item(0)->nodeValue; - if (($relocate["avatar"] == "") AND ($relocate["photo"] != "")) { + if (($relocate["avatar"] == "") AND ($relocate["photo"] != "")) $relocate["avatar"] = $relocate["photo"]; - } - if ($relocate["addr"] == "") { + if ($relocate["addr"] == "") $relocate["addr"] = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$3@$2", $relocate["url"]); - } // update contact $r = q("SELECT `photo`, `url` FROM `contact` WHERE `id` = %d AND `uid` = %d;", intval($importer["id"]), intval($importer["importer_uid"])); - - if (!dbm::is_result($r)) { - /// @todo Don't die quietly - killme(); - } + if (!$r) + return false; $old = $r[0]; @@ -1790,9 +1652,8 @@ class dfrn { update_contact_avatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true); - if ($x === false) { + if ($x === false) return false; - } // update items /// @todo This is an extreme performance killer @@ -1807,15 +1668,13 @@ class dfrn { $n, dbesc($f[0]), intval($importer["importer_uid"])); - if (dbm::is_result($r)) { + if ($r) { $x = q("UPDATE `item` SET `%s` = '%s' WHERE `%s` = '%s' AND `uid` = %d", $n, dbesc($f[1]), $n, dbesc($f[0]), intval($importer["importer_uid"])); - - if ($x === false) { - return false; - } + if ($x === false) + return false; } } @@ -1841,7 +1700,7 @@ class dfrn { if (edited_timestamp_is_newer($current, $item)) { // do not accept (ignore) an earlier edit than one we currently have. - if (datetime_convert("UTC","UTC",$item["edited"]) < $current["edited"]) + if(datetime_convert("UTC","UTC",$item["edited"]) < $current["edited"]) return(false); $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d", @@ -1858,13 +1717,12 @@ class dfrn { $changed = true; - if ($entrytype == DFRN_REPLY_RC) { + if ($entrytype == DFRN_REPLY_RC) proc_run(PRIORITY_HIGH, "include/notifier.php","comment-import", $current["id"]); - } } // update last-child if it changes - if ($item["last-child"] AND ($item["last-child"] != $current["last-child"])) { + if($item["last-child"] AND ($item["last-child"] != $current["last-child"])) { $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d", dbesc(datetime_convert()), dbesc($item["parent-uri"]), @@ -1892,13 +1750,12 @@ class dfrn { if ($item["parent-uri"] != $item["uri"]) { $community = false; - if ($importer["page-flags"] == PAGE_COMMUNITY || $importer["page-flags"] == PAGE_PRVGROUP) { + if($importer["page-flags"] == PAGE_COMMUNITY || $importer["page-flags"] == PAGE_PRVGROUP) { $sql_extra = ""; $community = true; logger("possible community action"); - } else { + } else $sql_extra = " AND `contact`.`self` AND `item`.`wall` "; - } // was the top-level post for this action written by somebody on this site? // Specifically, the recipient? @@ -1922,9 +1779,8 @@ class dfrn { dbesc($r[0]["parent-uri"]), intval($importer["importer_uid"]) ); - if (dbm::is_result($r)) { + if (dbm::is_result($r)) $is_a_remote_action = true; - } } // Does this have the characteristics of a community or private group action? @@ -1932,22 +1788,20 @@ class dfrn { // valid community action. Also forum_mode makes it valid for sure. // If neither, it's not. - if ($is_a_remote_action && $community) { - if ((!$r[0]["forum_mode"]) && (!$r[0]["wall"])) { + if($is_a_remote_action && $community) { + if((!$r[0]["forum_mode"]) && (!$r[0]["wall"])) { $is_a_remote_action = false; logger("not a community action"); } } - if ($is_a_remote_action) { + if ($is_a_remote_action) return DFRN_REPLY_RC; - } else { + else return DFRN_REPLY; - } - } else { + } else return DFRN_TOP_LEVEL; - } } @@ -1960,15 +1814,14 @@ class dfrn { */ private static function do_poke($item, $importer, $posted_id) { $verb = urldecode(substr($item["verb"],strpos($item["verb"], "#")+1)); - if (!$verb) { + if(!$verb) return; - } $xo = parse_xml_string($item["object"],false); - if (($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) { + if(($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) { // somebody was poked/prodded. Was it me? - foreach ($xo->link as $l) { + foreach($xo->link as $l) { $atts = $l->attributes(); switch($atts["rel"]) { case "alternate": @@ -1979,7 +1832,7 @@ class dfrn { } } - if ($Blink && link_compare($Blink,App::get_baseurl()."/profile/".$importer["nickname"])) { + if($Blink && link_compare($Blink,App::get_baseurl()."/profile/".$importer["nickname"])) { // send a notification notification(array( @@ -2027,28 +1880,28 @@ class dfrn { // Big question: Do we need these functions? They were part of the "consume_feed" function. // This function once was responsible for DFRN and OStatus. - if (activity_match($item["verb"],ACTIVITY_FOLLOW)) { + if(activity_match($item["verb"],ACTIVITY_FOLLOW)) { logger("New follower"); new_follower($importer, $contact, $item, $nickname); return false; } - if (activity_match($item["verb"],ACTIVITY_UNFOLLOW)) { + if(activity_match($item["verb"],ACTIVITY_UNFOLLOW)) { logger("Lost follower"); lose_follower($importer, $contact, $item); return false; } - if (activity_match($item["verb"],ACTIVITY_REQ_FRIEND)) { + if(activity_match($item["verb"],ACTIVITY_REQ_FRIEND)) { logger("New friend request"); new_follower($importer, $contact, $item, $nickname, true); return false; } - if (activity_match($item["verb"],ACTIVITY_UNFRIEND)) { + if(activity_match($item["verb"],ACTIVITY_UNFRIEND)) { logger("Lost sharer"); lose_sharer($importer, $contact, $item); return false; } } else { - if (($item["verb"] == ACTIVITY_LIKE) + if(($item["verb"] == ACTIVITY_LIKE) || ($item["verb"] == ACTIVITY_DISLIKE) || ($item["verb"] == ACTIVITY_ATTEND) || ($item["verb"] == ACTIVITY_ATTENDNO) @@ -2064,9 +1917,8 @@ class dfrn { dbesc($item["verb"]), dbesc($item["parent-uri"]) ); - if (dbm::is_result($r)) { + if (dbm::is_result($r)) return false; - } $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `author-link` = '%s' AND `verb` = '%s' AND `thr-parent` = '%s' AND NOT `deleted` LIMIT 1", intval($item["uid"]), @@ -2074,31 +1926,28 @@ class dfrn { dbesc($item["verb"]), dbesc($item["parent-uri"]) ); - if (dbm::is_result($r)) { + if (dbm::is_result($r)) return false; - } - } else { + } else $is_like = false; - } - if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { + if(($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { $xo = parse_xml_string($item["object"],false); $xt = parse_xml_string($item["target"],false); - if ($xt->type == ACTIVITY_OBJ_NOTE) { + if($xt->type == ACTIVITY_OBJ_NOTE) { $r = q("SELECT `id`, `tag` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($xt->id), intval($importer["importer_uid"]) ); - if (!dbm::is_result($r)) { - killme(); - } + if (!dbm::is_result($r)) + return false; // extract tag, if not duplicate, add to parent item - if ($xo->content) { - if (!(stristr($r[0]["tag"],trim($xo->content)))) { + if($xo->content) { + if(!(stristr($r[0]["tag"],trim($xo->content)))) { q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d", dbesc($r[0]["tag"] . (strlen($r[0]["tag"]) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]'), intval($r[0]["id"]) @@ -2117,7 +1966,6 @@ class dfrn { * * @param object $links link elements * @param array $item the item record - * @todo Add type-hints */ private static function parse_links($links, &$item) { $rel = ""; @@ -2126,23 +1974,17 @@ class dfrn { $length = "0"; $title = ""; foreach ($links AS $link) { - foreach ($link->attributes AS $attributes) { - /// @TODO Rewrite these repeated (same) if () statements to a switch() - if ($attributes->name == "href") { + foreach($link->attributes AS $attributes) { + if ($attributes->name == "href") $href = $attributes->textContent; - } - if ($attributes->name == "rel") { + if ($attributes->name == "rel") $rel = $attributes->textContent; - } - if ($attributes->name == "type") { + if ($attributes->name == "type") $type = $attributes->textContent; - } - if ($attributes->name == "length") { + if ($attributes->name == "length") $length = $attributes->textContent; - } - if ($attributes->name == "title") { + if ($attributes->name == "title") $title = $attributes->textContent; - } } if (($rel != "") AND ($href != "")) switch($rel) { @@ -2151,9 +1993,8 @@ class dfrn { break; case "enclosure": $enclosure = $href; - if (strlen($item["attach"])) { + if(strlen($item["attach"])) $item["attach"] .= ","; - } $item["attach"] .= '[attach]href="'.$href.'" length="'.$length.'" type="'.$type.'" title="'.$title.'"[/attach]'; break; @@ -2168,7 +2009,6 @@ class dfrn { * @param object $xpath XPath object * @param object $entry entry elements * @param array $importer Record of the importer user mixed with contact of the content - * @todo Add type-hints */ private static function process_entry($header, $xpath, $entry, $importer) { @@ -2219,7 +2059,7 @@ class dfrn { $item["body"] = limit_body_size($item["body"]); /// @todo Do we really need this check for HTML elements? (It was copied from the old function) - if ((strpos($item['body'],'<') !== false) && (strpos($item['body'],'>') !== false)) { + if((strpos($item['body'],'<') !== false) && (strpos($item['body'],'>') !== false)) { $item['body'] = reltoabs($item['body'],$base_url); @@ -2248,24 +2088,21 @@ class dfrn { $item["location"] = $xpath->query("dfrn:location/text()", $entry)->item(0)->nodeValue; $georsspoint = $xpath->query("georss:point", $entry); - if ($georsspoint) { + if ($georsspoint) $item["coord"] = $georsspoint->item(0)->nodeValue; - } $item["private"] = $xpath->query("dfrn:private/text()", $entry)->item(0)->nodeValue; $item["extid"] = $xpath->query("dfrn:extid/text()", $entry)->item(0)->nodeValue; - if ($xpath->query("dfrn:bookmark/text()", $entry)->item(0)->nodeValue == "true") { + if ($xpath->query("dfrn:bookmark/text()", $entry)->item(0)->nodeValue == "true") $item["bookmark"] = true; - } $notice_info = $xpath->query("statusnet:notice_info", $entry); if ($notice_info AND ($notice_info->length > 0)) { - foreach ($notice_info->item(0)->attributes AS $attributes) { - if ($attributes->name == "source") { + foreach($notice_info->item(0)->attributes AS $attributes) { + if ($attributes->name == "source") $item["app"] = strip_tags($attributes->textContent); - } } } @@ -2273,24 +2110,21 @@ class dfrn { // We store the data from "dfrn:diaspora_signature" in a different table, this is done in "item_store" $dsprsig = unxmlify($xpath->query("dfrn:diaspora_signature/text()", $entry)->item(0)->nodeValue); - if ($dsprsig != "") { + if ($dsprsig != "") $item["dsprsig"] = $dsprsig; - } $item["verb"] = $xpath->query("activity:verb/text()", $entry)->item(0)->nodeValue; - if ($xpath->query("activity:object-type/text()", $entry)->item(0)->nodeValue != "") { + if ($xpath->query("activity:object-type/text()", $entry)->item(0)->nodeValue != "") $item["object-type"] = $xpath->query("activity:object-type/text()", $entry)->item(0)->nodeValue; - } $object = $xpath->query("activity:object", $entry)->item(0); $item["object"] = self::transform_activity($xpath, $object, "object"); if (trim($item["object"]) != "") { $r = parse_xml_string($item["object"], false); - if (isset($r->type)) { + if (isset($r->type)) $item["object-type"] = $r->type; - } } $target = $xpath->query("activity:target", $entry)->item(0); @@ -2301,14 +2135,12 @@ class dfrn { foreach ($categories AS $category) { $term = ""; $scheme = ""; - foreach ($category->attributes AS $attributes) { - if ($attributes->name == "term") { + foreach($category->attributes AS $attributes) { + if ($attributes->name == "term") $term = $attributes->textContent; - } - if ($attributes->name == "scheme") { + if ($attributes->name == "scheme") $scheme = $attributes->textContent; - } } if (($term != "") AND ($scheme != "")) { @@ -2317,9 +2149,8 @@ class dfrn { $termhash = array_shift($parts); $termurl = implode(":", $parts); - if (strlen($item["tag"])) { + if(strlen($item["tag"])) $item["tag"] .= ","; - } $item["tag"] .= $termhash."[url=".$termurl."]".$term."[/url]"; } @@ -2330,52 +2161,43 @@ class dfrn { $enclosure = ""; $links = $xpath->query("atom:link", $entry); - if ($links) { + if ($links) self::parse_links($links, $item); - } // Is it a reply or a top level posting? $item["parent-uri"] = $item["uri"]; $inreplyto = $xpath->query("thr:in-reply-to", $entry); - if (is_object($inreplyto->item(0))) { - foreach ($inreplyto->item(0)->attributes AS $attributes) { - if ($attributes->name == "ref") { + if (is_object($inreplyto->item(0))) + foreach($inreplyto->item(0)->attributes AS $attributes) + if ($attributes->name == "ref") $item["parent-uri"] = $attributes->textContent; - } - } - } // Get the type of the item (Top level post, reply or remote reply) $entrytype = self::get_entry_type($importer, $item); // Now assign the rest of the values that depend on the type of the message if (in_array($entrytype, array(DFRN_REPLY, DFRN_REPLY_RC))) { - if (!isset($item["object-type"])) { + if (!isset($item["object-type"])) $item["object-type"] = ACTIVITY_OBJ_COMMENT; - } - if ($item["contact-id"] != $owner["contact-id"]) { + if ($item["contact-id"] != $owner["contact-id"]) $item["contact-id"] = $owner["contact-id"]; - } - if (($item["network"] != $owner["network"]) AND ($owner["network"] != "")) { + if (($item["network"] != $owner["network"]) AND ($owner["network"] != "")) $item["network"] = $owner["network"]; - } - if ($item["contact-id"] != $author["contact-id"]) { + if ($item["contact-id"] != $author["contact-id"]) $item["contact-id"] = $author["contact-id"]; - } - if (($item["network"] != $author["network"]) AND ($author["network"] != "")) { + if (($item["network"] != $author["network"]) AND ($author["network"] != "")) $item["network"] = $author["network"]; - } // This code was taken from the old DFRN code // When activated, forums don't work. // And: Why should we disallow commenting by followers? // the behaviour is now similar to the Diaspora part. - //if ($importer["rel"] == CONTACT_IS_FOLLOWER) { + //if($importer["rel"] == CONTACT_IS_FOLLOWER) { // logger("Contact ".$importer["id"]." is only follower. Quitting", LOGGER_DEBUG); // return; //} @@ -2385,15 +2207,14 @@ class dfrn { $item["type"] = "remote-comment"; $item["wall"] = 1; } elseif ($entrytype == DFRN_TOP_LEVEL) { - if (!isset($item["object-type"])) { + if (!isset($item["object-type"])) $item["object-type"] = ACTIVITY_OBJ_NOTE; - } // Is it an event? if ($item["object-type"] == ACTIVITY_OBJ_EVENT) { logger("Item ".$item["uri"]." seems to contain an event.", LOGGER_DEBUG); $ev = bbtoevent($item["body"]); - if ((x($ev, "desc") || x($ev, "summary")) && x($ev, "start")) { + if((x($ev, "desc") || x($ev, "summary")) && x($ev, "start")) { logger("Event in item ".$item["uri"]." was found.", LOGGER_DEBUG); $ev["cid"] = $importer["id"]; $ev["uid"] = $importer["uid"]; @@ -2406,9 +2227,8 @@ class dfrn { dbesc($item["uri"]), intval($importer["uid"]) ); - if (dbm::is_result($r)) { + if (dbm::is_result($r)) $ev["id"] = $r[0]["id"]; - } $event_id = event_store($ev); logger("Event ".$event_id." was stored", LOGGER_DEBUG); @@ -2426,9 +2246,8 @@ class dfrn { if (dbm::is_result($current)) { if (self::update_content($r[0], $item, $importer, $entrytype)) logger("Item ".$item["uri"]." was updated.", LOGGER_DEBUG); - } else { + else logger("Item ".$item["uri"]." already existed.", LOGGER_DEBUG); - } return; } @@ -2436,7 +2255,7 @@ class dfrn { $posted_id = item_store($item); $parent = 0; - if ($posted_id) { + if($posted_id) { logger("Reply from contact ".$item["contact-id"]." was stored with id ".$posted_id, LOGGER_DEBUG); @@ -2451,7 +2270,7 @@ class dfrn { $parent_uri = $r[0]["parent-uri"]; } - if (!$is_like) { + if(!$is_like) { $r1 = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `uid` = %d AND `parent` = %d", dbesc(datetime_convert()), intval($importer["importer_uid"]), @@ -2465,7 +2284,7 @@ class dfrn { ); } - if ($posted_id AND $parent AND ($entrytype == DFRN_REPLY_RC)) { + if($posted_id AND $parent AND ($entrytype == DFRN_REPLY_RC)) { logger("Notifying followers about comment ".$posted_id, LOGGER_DEBUG); proc_run(PRIORITY_HIGH, "include/notifier.php", "comment-import", $posted_id); } @@ -2473,7 +2292,7 @@ class dfrn { return true; } } else { // $entrytype == DFRN_TOP_LEVEL - if (!link_compare($item["owner-link"],$importer["url"])) { + if(!link_compare($item["owner-link"],$importer["url"])) { // The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery, // but otherwise there's a possible data mixup on the sender's system. // the tgroup delivery code called from item_store will correct it if it's a forum, @@ -2484,7 +2303,7 @@ class dfrn { $item["owner-avatar"] = $importer["thumb"]; } - if (($importer["rel"] == CONTACT_IS_FOLLOWER) && (!tgroup_check($importer["importer_uid"], $item))) { + if(($importer["rel"] == CONTACT_IS_FOLLOWER) && (!tgroup_check($importer["importer_uid"], $item))) { logger("Contact ".$importer["id"]." is only follower and tgroup check was negative.", LOGGER_DEBUG); return; } @@ -2497,7 +2316,7 @@ class dfrn { logger("Item was stored with id ".$posted_id, LOGGER_DEBUG); - if (stristr($item["verb"],ACTIVITY_POKE)) + if(stristr($item["verb"],ACTIVITY_POKE)) self::do_poke($item, $importer, $posted_id); } } @@ -2513,23 +2332,19 @@ class dfrn { logger("Processing deletions"); - foreach ($deletion->attributes AS $attributes) { - if ($attributes->name == "ref") { + foreach($deletion->attributes AS $attributes) { + if ($attributes->name == "ref") $uri = $attributes->textContent; - } - if ($attributes->name == "when") { + if ($attributes->name == "when") $when = $attributes->textContent; - } } - if ($when) { + if ($when) $when = datetime_convert("UTC", "UTC", $when, "Y-m-d H:i:s"); - } else { + else $when = datetime_convert("UTC", "UTC", "now", "Y-m-d H:i:s"); - } - if (!$uri OR !$importer["id"]) { + if (!$uri OR !$importer["id"]) return false; - } /// @todo Only select the used fields $r = q("SELECT `item`.*, `contact`.`self` FROM `item` INNER JOIN `contact` on `item`.`contact-id` = `contact`.`id` @@ -2547,23 +2362,22 @@ class dfrn { $entrytype = self::get_entry_type($importer, $item); - if (!$item["deleted"]) { + if(!$item["deleted"]) logger('deleting item '.$item["id"].' uri='.$uri, LOGGER_DEBUG); - } else { + else return; - } - if ($item["object-type"] == ACTIVITY_OBJ_EVENT) { + if($item["object-type"] == ACTIVITY_OBJ_EVENT) { logger("Deleting event ".$item["event-id"], LOGGER_DEBUG); event_delete($item["event-id"]); } - if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { + if(($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { $xo = parse_xml_string($item["object"],false); $xt = parse_xml_string($item["target"],false); - if ($xt->type == ACTIVITY_OBJ_NOTE) { + if($xt->type == ACTIVITY_OBJ_NOTE) { $i = q("SELECT `id`, `contact-id`, `tag` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($xt->id), intval($importer["importer_uid"]) @@ -2576,18 +2390,15 @@ class dfrn { $author_remove = (($item["origin"] && $item["self"]) ? true : false); $author_copy = (($item["origin"]) ? true : false); - if ($owner_remove && $author_copy) { + if($owner_remove && $author_copy) return; - } - if ($author_remove || $owner_remove) { + if($author_remove || $owner_remove) { $tags = explode(',',$i[0]["tag"]); $newtags = array(); - if (count($tags)) { - foreach ($tags as $tag) { - if (trim($tag) !== trim($xo->body)) { + if(count($tags)) { + foreach($tags as $tag) + if(trim($tag) !== trim($xo->body)) $newtags[] = trim($tag); - } - } } q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d", dbesc(implode(',',$newtags)), @@ -2599,7 +2410,7 @@ class dfrn { } } - if ($entrytype == DFRN_TOP_LEVEL) { + if($entrytype == DFRN_TOP_LEVEL) { $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '', `title` = '' WHERE `parent-uri` = '%s' AND `uid` = %d", @@ -2623,7 +2434,7 @@ class dfrn { create_tags_from_itemuri($uri, $importer["uid"]); create_files_from_itemuri($uri, $importer["uid"]); update_thread_uri($uri, $importer["importer_uid"]); - if ($item["last-child"]) { + if($item["last-child"]) { // ensure that last-child is set in case the comment that had it just got wiped. q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ", dbesc(datetime_convert()), @@ -2644,7 +2455,7 @@ class dfrn { } // if this is a relayed delete, propagate it to other recipients - if ($entrytype == DFRN_REPLY_RC) { + if($entrytype == DFRN_REPLY_RC) { logger("Notifying followers about deletion of post ".$item["id"], LOGGER_DEBUG); proc_run(PRIORITY_HIGH, "include/notifier.php","drop", $item["id"]); } @@ -2664,7 +2475,7 @@ class dfrn { if ($xml == "") return; - if ($importer["readonly"]) { + if($importer["readonly"]) { // We aren't receiving stuff from this person. But we will quietly ignore them // rather than a blatant "go away" message. logger('ignoring contact '.$importer["id"]); @@ -2697,14 +2508,12 @@ class dfrn { // Update the contact table if the data has changed // The "atom:author" is only present in feeds - if ($xpath->query("/atom:feed/atom:author")->length > 0) { + if ($xpath->query("/atom:feed/atom:author")->length > 0) self::fetchauthor($xpath, $doc->firstChild, $importer, "atom:author", false, $xml); - } // Only the "dfrn:owner" in the head section contains all data - if ($xpath->query("/atom:feed/dfrn:owner")->length > 0) { + if ($xpath->query("/atom:feed/dfrn:owner")->length > 0) self::fetchauthor($xpath, $doc->firstChild, $importer, "dfrn:owner", false, $xml); - } logger("Import DFRN message for user ".$importer["uid"]." from contact ".$importer["id"], LOGGER_DEBUG); @@ -2712,50 +2521,43 @@ class dfrn { if ($xpath->query("/atom:feed/dfrn:account_type")->length > 0) { $accounttype = intval($xpath->evaluate("/atom:feed/dfrn:account_type/text()", $context)->item(0)->nodeValue); - if ($accounttype != $importer["contact-type"]) { + if ($accounttype != $importer["contact-type"]) q("UPDATE `contact` SET `contact-type` = %d WHERE `id` = %d", intval($accounttype), intval($importer["id"]) ); - } } // is it a public forum? Private forums aren't supported with this method // This is deprecated since 3.5.1 $forum = intval($xpath->evaluate("/atom:feed/dfrn:community/text()", $context)->item(0)->nodeValue); - if ($forum != $importer["forum"]) { + if ($forum != $importer["forum"]) q("UPDATE `contact` SET `forum` = %d WHERE `forum` != %d AND `id` = %d", intval($forum), intval($forum), intval($importer["id"]) ); - } $mails = $xpath->query("/atom:feed/dfrn:mail"); - foreach ($mails AS $mail) { + foreach ($mails AS $mail) self::process_mail($xpath, $mail, $importer); - } $suggestions = $xpath->query("/atom:feed/dfrn:suggest"); - foreach ($suggestions AS $suggestion) { + foreach ($suggestions AS $suggestion) self::process_suggestion($xpath, $suggestion, $importer); - } $relocations = $xpath->query("/atom:feed/dfrn:relocate"); - foreach ($relocations AS $relocation) { + foreach ($relocations AS $relocation) self::process_relocation($xpath, $relocation, $importer); - } $deletions = $xpath->query("/atom:feed/at:deleted-entry"); - foreach ($deletions AS $deletion) { + foreach ($deletions AS $deletion) self::process_deletion($xpath, $deletion, $importer); - } if (!$sort_by_date) { $entries = $xpath->query("/atom:feed/atom:entry"); - foreach ($entries AS $entry) { + foreach ($entries AS $entry) self::process_entry($header, $xpath, $entry, $importer); - } } else { $newentries = array(); $entries = $xpath->query("/atom:feed/atom:entry"); @@ -2767,9 +2569,8 @@ class dfrn { // Now sort after the publishing date ksort($newentries); - foreach ($newentries AS $entry) { + foreach ($newentries AS $entry) self::process_entry($header, $xpath, $entry, $importer); - } } logger("Import done for user ".$importer["uid"]." from contact ".$importer["id"], LOGGER_DEBUG); } diff --git a/include/diaspora.php b/include/diaspora.php index 12cb9b436..eca22092d 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -45,7 +45,7 @@ class Diaspora { $servers = explode(",", $serverdata); - foreach ($servers AS $server) { + foreach($servers AS $server) { $server = trim($server); $addr = "relay@".str_replace("http://", "", normalise_link($server)); $batch = $server."/receive/public"; @@ -181,7 +181,7 @@ class Diaspora { $children = $basedom->children('https://joindiaspora.com/protocol'); - if ($children->header) { + if($children->header) { $public = true; $author_link = str_replace('acct:','',$children->header->author_id); } else { @@ -217,11 +217,11 @@ class Diaspora { // figure out where in the DOM tree our data is hiding - if ($dom->provenance->data) + if($dom->provenance->data) $base = $dom->provenance; - elseif ($dom->env->data) + elseif($dom->env->data) $base = $dom->env; - elseif ($dom->data) + elseif($dom->data) $base = $dom; if (!$base) { @@ -254,7 +254,7 @@ class Diaspora { $data = base64url_decode($data); - if ($public) + if($public) $inner_decrypted = $data; else { @@ -556,7 +556,7 @@ class Diaspora { logger("Fetching diaspora key for: ".$handle); $r = self::person_by_handle($handle); - if ($r) + if($r) return $r["pubkey"]; return ""; @@ -612,7 +612,7 @@ class Diaspora { */ private static function add_fcontact($arr, $update = false) { - if ($update) { + if($update) { $r = q("UPDATE `fcontact` SET `name` = '%s', `photo` = '%s', @@ -796,7 +796,7 @@ class Diaspora { // perhaps we were already sharing with this person. Now they're sharing with us. // That makes us friends. // Normally this should have handled by getting a request - but this could get lost - if ($contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) { + if($contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) { q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d", intval(CONTACT_IS_FRIEND), intval($contact["id"]), @@ -806,12 +806,12 @@ class Diaspora { logger("defining user ".$contact["nick"]." as friend"); } - if (($contact["blocked"]) || ($contact["readonly"]) || ($contact["archive"])) + if(($contact["blocked"]) || ($contact["readonly"]) || ($contact["archive"])) return false; - if ($contact["rel"] == CONTACT_IS_SHARING || $contact["rel"] == CONTACT_IS_FRIEND) + if($contact["rel"] == CONTACT_IS_SHARING || $contact["rel"] == CONTACT_IS_FRIEND) return true; - if ($contact["rel"] == CONTACT_IS_FOLLOWER) - if (($importer["page-flags"] == PAGE_COMMUNITY) OR $is_comment) + if($contact["rel"] == CONTACT_IS_FOLLOWER) + if(($importer["page-flags"] == PAGE_COMMUNITY) OR $is_comment) return true; // Messages for the global users are always accepted @@ -969,7 +969,7 @@ class Diaspora { logger("Fetch post from ".$source_url, LOGGER_DEBUG); $envelope = fetch_url($source_url); - if ($envelope) { + if($envelope) { logger("Envelope was fetched.", LOGGER_DEBUG); $x = self::verify_magic_envelope($envelope); if (!$x) @@ -985,7 +985,7 @@ class Diaspora { logger("Fetch post from ".$source_url, LOGGER_DEBUG); $x = fetch_url($source_url); - if (!$x) + if(!$x) return false; } @@ -1042,7 +1042,7 @@ class Diaspora { FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", intval($uid), dbesc($guid)); - if (!$r) { + if(!$r) { $result = self::store_by_guid($guid, $contact["url"], $uid); if (!$result) { @@ -1303,7 +1303,7 @@ class Diaspora { } // If we are the origin of the parent we store the original data and notify our followers - if ($message_id AND $parent_item["origin"]) { + if($message_id AND $parent_item["origin"]) { // Formerly we stored the signed text, the signature and the author in different fields. // We now store the raw data so that we are more flexible. @@ -1480,7 +1480,7 @@ class Diaspora { intval($importer["uid"]), dbesc($guid) ); - if ($c) + if($c) $conversation = $c[0]; else { $r = q("INSERT INTO `conv` (`uid`, `guid`, `creator`, `created`, `updated`, `subject`, `recips`) @@ -1493,13 +1493,13 @@ class Diaspora { dbesc($subject), dbesc($participants) ); - if ($r) + if($r) $c = q("SELECT * FROM `conv` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", intval($importer["uid"]), dbesc($guid) ); - if ($c) + if($c) $conversation = $c[0]; } if (!$conversation) { @@ -1507,7 +1507,7 @@ class Diaspora { return; } - foreach ($messages as $mesg) + foreach($messages as $mesg) self::receive_conversation_message($importer, $contact, $data, $msg, $mesg, $conversation); return true; @@ -1637,7 +1637,7 @@ class Diaspora { logger("Stored like ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG); // If we are the origin of the parent we store the original data and notify our followers - if ($message_id AND $parent_item["origin"]) { + if($message_id AND $parent_item["origin"]) { // Formerly we stored the signed text, the signature and the author in different fields. // We now store the raw data so that we are more flexible. @@ -1812,10 +1812,10 @@ class Diaspora { $handle_parts = explode("@", $author); $nick = $handle_parts[0]; - if ($name === "") + if($name === "") $name = $handle_parts[0]; - if ( preg_match("|^https?://|", $image_url) === 0) + if( preg_match("|^https?://|", $image_url) === 0) $image_url = "http://".$handle_parts[1].$image_url; update_contact_avatar($image_url, $importer["uid"], $contact["id"]); @@ -1830,7 +1830,7 @@ class Diaspora { // this is to prevent multiple birthday notifications in a single year // if we already have a stored birthday and the 'm-d' part hasn't changed, preserve the entry, which will preserve the notify year - if (substr($birthday,5) === substr($contact["bd"],5)) + if(substr($birthday,5) === substr($contact["bd"],5)) $birthday = $contact["bd"]; $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `name-date` = '%s', `bd` = '%s', @@ -1876,7 +1876,7 @@ class Diaspora { $a = get_app(); - if ($contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) { + if($contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) { q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d", intval(CONTACT_IS_FRIEND), intval($contact["id"]), @@ -1889,7 +1889,7 @@ class Diaspora { intval($importer["uid"]) ); - if ($r && !$r[0]["hide-friends"] && !$contact["hidden"] && intval(get_pconfig($importer["uid"], "system", "post_newfriend"))) { + if($r && !$r[0]["hide-friends"] && !$contact["hidden"] && intval(get_pconfig($importer["uid"], "system", "post_newfriend"))) { $self = q("SELECT * FROM `contact` WHERE `self` AND `uid` = %d LIMIT 1", intval($importer["uid"]) @@ -1897,7 +1897,7 @@ class Diaspora { // they are not CONTACT_IS_FOLLOWER anymore but that's what we have in the array - if ($self && $contact["rel"] == CONTACT_IS_FOLLOWER) { + if($self && $contact["rel"] == CONTACT_IS_FOLLOWER) { $arr = array(); $arr["uri"] = $arr["parent-uri"] = item_new_uri($a->get_hostname(), $importer["uid"]); @@ -1928,7 +1928,7 @@ class Diaspora { $arr["deny_gid"] = $user[0]["deny_gid"]; $i = item_store($arr); - if ($i) + if($i) proc_run(PRIORITY_HIGH, "include/notifier.php", "activity", $i); } } @@ -2067,12 +2067,12 @@ class Diaspora { $def_gid = get_default_group($importer['uid'], $ret["network"]); - if (intval($def_gid)) + if(intval($def_gid)) group_add_member($importer["uid"], "", $contact_record["id"], $def_gid); update_contact_avatar($ret["photo"], $importer['uid'], $contact_record["id"], true); - if ($importer["page-flags"] == PAGE_NORMAL) { + if($importer["page-flags"] == PAGE_NORMAL) { logger("Sending intra message for author ".$author.".", LOGGER_DEBUG); @@ -2122,7 +2122,7 @@ class Diaspora { ); $u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($importer["uid"])); - if ($u) { + if($u) { logger("Sending share message (Relation: ".$new_relation.") to author ".$author." - Contact: ".$contact_record["id"]." - User: ".$importer["uid"], LOGGER_DEBUG); $ret = self::send_share($u[0], $contact_record); @@ -2748,7 +2748,7 @@ class Diaspora { $a = get_app(); $enabled = intval(get_config("system", "diaspora_enabled")); - if (!$enabled) + if(!$enabled) return 200; $logid = random_string(4); @@ -3087,14 +3087,14 @@ class Diaspora { $body = html_entity_decode(bb2diaspora($body)); // Adding the title - if (strlen($title)) + if(strlen($title)) $body = "## ".html_entity_decode($title)."\n\n".$body; if ($item["attach"]) { $cnt = preg_match_all('/href=\"(.*?)\"(.*?)title=\"(.*?)\"/ism', $item["attach"], $matches, PREG_SET_ORDER); - if (cnt) { + if(cnt) { $body .= "\n".t("Attachments:")."\n"; - foreach ($matches as $mtch) + foreach($matches as $mtch) $body .= "[".$mtch[3]."](".$mtch[1].")\n"; } } @@ -3587,7 +3587,7 @@ class Diaspora { $kw = str_replace(' ',' ',$kw); $arr = explode(' ',$profile['pub_keywords']); if (count($arr)) { - for ($x = 0; $x < 5; $x ++) { + for($x = 0; $x < 5; $x ++) { if (trim($arr[$x])) $tags .= '#'. trim($arr[$x]) .' '; } @@ -3609,7 +3609,7 @@ class Diaspora { "searchable" => $searchable, "tag_string" => $tags); - foreach ($recips as $recip) { + foreach($recips as $recip) { logger("Send updated profile data for user ".$uid." to contact ".$recip["id"], LOGGER_DEBUG); self::build_and_transmit($profile, $recip, "profile", $message, false, "", true); } @@ -3632,20 +3632,17 @@ class Diaspora { } $r = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($contact['uid'])); - if (!dbm::is_result($r)) { + if(!$r) return false; - } $contact["uprvkey"] = $r[0]['prvkey']; $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", intval($post_id)); - if (!dbm::is_result($r)) { + if (!$r) 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; - } $message = self::construct_like($r[0], $contact); $message["author_signature"] = self::signature($contact, $message); diff --git a/include/discover_poco.php b/include/discover_poco.php index dd4e3a7dd..2923cd01f 100644 --- a/include/discover_poco.php +++ b/include/discover_poco.php @@ -189,10 +189,10 @@ function discover_directory($search) { $j = json_decode($x); if (count($j->results)) { - foreach ($j->results as $jj) { + foreach($j->results as $jj) { // Check if the contact already exists $exists = q("SELECT `id`, `last_contact`, `last_failure`, `updated` FROM `gcontact` WHERE `nurl` = '%s'", normalise_link($jj->url)); - if (dbm::is_result($exists)) { + if ($exists) { logger("Profile ".$jj->url." already exists (".$search.")", LOGGER_DEBUG); if (($exists[0]["last_contact"] < $exists[0]["last_failure"]) AND @@ -245,14 +245,12 @@ function gs_search_user($search) { if (!$result["success"]) { return false; } - $contacts = json_decode($result["body"]); if ($contacts->status == 'ERROR') { return false; } - - foreach ($contacts->data AS $user) { + foreach($contacts->data AS $user) { $contact = probe_url($user->site_address."/".$user->name); if ($contact["network"] != NETWORK_PHANTOM) { $contact["about"] = $user->description; diff --git a/include/email.php b/include/email.php index b8d99433e..42f80c242 100644 --- a/include/email.php +++ b/include/email.php @@ -4,7 +4,7 @@ require_once('include/msgclean.php'); require_once('include/quoteconvert.php'); function email_connect($mailbox,$username,$password) { - if (! function_exists('imap_open')) + if(! function_exists('imap_open')) return false; $mbox = @imap_open($mailbox,$username,$password); @@ -14,23 +14,23 @@ function email_connect($mailbox,$username,$password) { function email_poll($mbox,$email_addr) { - if (! ($mbox && $email_addr)) + if(! ($mbox && $email_addr)) return array(); $search1 = @imap_search($mbox,'FROM "' . $email_addr . '"', SE_UID); - if (! $search1) + if(! $search1) $search1 = array(); $search2 = @imap_search($mbox,'TO "' . $email_addr . '"', SE_UID); - if (! $search2) + if(! $search2) $search2 = array(); $search3 = @imap_search($mbox,'CC "' . $email_addr . '"', SE_UID); - if (! $search3) + if(! $search3) $search3 = array(); $search4 = @imap_search($mbox,'BCC "' . $email_addr . '"', SE_UID); - if (! $search4) + if(! $search4) $search4 = array(); $res = array_unique(array_merge($search1,$search2,$search3,$search4)); @@ -57,8 +57,8 @@ function email_msg_headers($mbox,$uid) { $raw_header = str_replace("\r",'',$raw_header); $ret = array(); $h = explode("\n",$raw_header); - if (count($h)) - foreach ($h as $line ) { + if(count($h)) + foreach($h as $line ) { if (preg_match("/^[a-zA-Z]/", $line)) { $key = substr($line,0,strpos($line,':')); $value = substr($line,strpos($line,':')+1); @@ -79,10 +79,10 @@ function email_get_msg($mbox,$uid, $reply) { $struc = (($mbox && $uid) ? @imap_fetchstructure($mbox,$uid,FT_UID) : null); - if (! $struc) + if(! $struc) return $ret; - if (! $struc->parts) { + if(! $struc->parts) { $ret['body'] = email_get_part($mbox,$uid,$struc,0, 'html'); $html = $ret['body']; @@ -94,7 +94,7 @@ function email_get_msg($mbox,$uid, $reply) { else { $text = ''; $html = ''; - foreach ($struc->parts as $ptop => $p) { + foreach($struc->parts as $ptop => $p) { $x = email_get_part($mbox,$uid,$p,$ptop + 1, 'plain'); if ($x) { $text .= $x; @@ -206,16 +206,16 @@ function email_get_part($mbox,$uid,$p,$partno, $subtype) { function email_header_encode($in_str, $charset) { - $out_str = $in_str; + $out_str = $in_str; $need_to_convert = false; - for ($x = 0; $x < strlen($in_str); $x ++) { - if ((ord($in_str[$x]) == 0) || ((ord($in_str[$x]) > 128))) { + for($x = 0; $x < strlen($in_str); $x ++) { + if((ord($in_str[$x]) == 0) || ((ord($in_str[$x]) > 128))) { $need_to_convert = true; } } - if (! $need_to_convert) + if(! $need_to_convert) return $in_str; if ($out_str && $charset) { diff --git a/include/enotify.php b/include/enotify.php index f86174bd4..ebc27309d 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -411,12 +411,10 @@ function notification($params) { $hash = random_string(); $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1", dbesc($hash)); - if (dbm::is_result($r)) { + if (dbm::is_result($r)) $dups = true; - } - } while ($dups == true); + } while($dups == true); - /// @TODO One statement is enough $datarray = array(); $datarray['hash'] = $hash; $datarray['name'] = $params['source_name']; diff --git a/include/event.php b/include/event.php index 7fffdd8a2..ebd4885c9 100644 --- a/include/event.php +++ b/include/event.php @@ -10,7 +10,7 @@ require_once 'include/datetime.php'; function format_event_html($ev, $simple = false) { - if (! ((is_array($ev)) && count($ev))) { + if(! ((is_array($ev)) && count($ev))) { return ''; } @@ -98,26 +98,26 @@ function parse_event($h) { logger('parse_event: parse error: ' . $e); } - if (! $dom) + if(! $dom) return $ret; $items = $dom->getElementsByTagName('*'); - foreach ($items as $item) { - if (attribute_contains($item->getAttribute('class'), 'vevent')) { + foreach($items as $item) { + if(attribute_contains($item->getAttribute('class'), 'vevent')) { $level2 = $item->getElementsByTagName('*'); - foreach ($level2 as $x) { - if (attribute_contains($x->getAttribute('class'),'dtstart') && $x->getAttribute('title')) { + foreach($level2 as $x) { + if(attribute_contains($x->getAttribute('class'),'dtstart') && $x->getAttribute('title')) { $ret['start'] = $x->getAttribute('title'); - if (! strpos($ret['start'],'Z')) + if(! strpos($ret['start'],'Z')) $ret['adjust'] = true; } - if (attribute_contains($x->getAttribute('class'),'dtend') && $x->getAttribute('title')) + if(attribute_contains($x->getAttribute('class'),'dtend') && $x->getAttribute('title')) $ret['finish'] = $x->getAttribute('title'); - if (attribute_contains($x->getAttribute('class'),'description')) + if(attribute_contains($x->getAttribute('class'),'description')) $ret['desc'] = $x->textContent; - if (attribute_contains($x->getAttribute('class'),'location')) + if(attribute_contains($x->getAttribute('class'),'location')) $ret['location'] = $x->textContent; } } @@ -125,23 +125,23 @@ function parse_event($h) { // sanitise - if ((x($ret,'desc')) && ((strpos($ret['desc'],'<') !== false) || (strpos($ret['desc'],'>') !== false))) { + if((x($ret,'desc')) && ((strpos($ret['desc'],'<') !== false) || (strpos($ret['desc'],'>') !== false))) { $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); $purifier = new HTMLPurifier($config); $ret['desc'] = html2bbcode($purifier->purify($ret['desc'])); } - if ((x($ret,'location')) && ((strpos($ret['location'],'<') !== false) || (strpos($ret['location'],'>') !== false))) { + if((x($ret,'location')) && ((strpos($ret['location'],'<') !== false) || (strpos($ret['location'],'>') !== false))) { $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); $purifier = new HTMLPurifier($config); $ret['location'] = html2bbcode($purifier->purify($ret['location'])); } - if (x($ret,'start')) + if(x($ret,'start')) $ret['start'] = datetime_convert('UTC','UTC',$ret['start']); - if (x($ret,'finish')) + if(x($ret,'finish')) $ret['finish'] = datetime_convert('UTC','UTC',$ret['finish']); return $ret; @@ -595,7 +595,7 @@ function event_by_id($owner_uid = 0, $event_params, $sql_extra = '') { */ function events_by_date($owner_uid = 0, $event_params, $sql_extra = '') { // Only allow events if there is a valid owner_id - if ($owner_uid == 0) { + if($owner_uid == 0) { return; } @@ -629,7 +629,7 @@ function events_by_date($owner_uid = 0, $event_params, $sql_extra = '') { * @return array Event array for the template */ function process_events($arr) { - $events = array(); + $events=array(); $last_date = ''; $fmt = t('l, F j'); diff --git a/include/expire.php b/include/expire.php index 098125a79..35b109a50 100644 --- a/include/expire.php +++ b/include/expire.php @@ -11,13 +11,12 @@ function expire_run(&$argv, &$argc){ // 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 - if (intval(get_config('system','optimize_items'))) { - q("OPTIMIZE TABLE `item`"); - } + if(intval(get_config('system','optimize_items'))) + q("optimize table item"); logger('expire: start'); diff --git a/include/features.php b/include/features.php index 07dcced0e..74c110427 100644 --- a/include/features.php +++ b/include/features.php @@ -36,9 +36,9 @@ function feature_enabled($uid, $feature) { */ function get_feature_default($feature) { $f = get_features(); - foreach ($f as $cat) { - foreach ($cat as $feat) { - if (is_array($feat) && $feat[0] === $feature) + foreach($f as $cat) { + foreach($cat as $feat) { + if(is_array($feat) && $feat[0] === $feature) return $feat[3]; } } @@ -116,13 +116,13 @@ function get_features($filtered = true) { // removed any locked features and remove the entire category if this makes it empty - if ($filtered) { - foreach ($arr as $k => $x) { + if($filtered) { + foreach($arr as $k => $x) { $has_items = false; $kquantity = count($arr[$k]); - for ($y = 0; $y < $kquantity; $y ++) { - if (is_array($arr[$k][$y])) { - if ($arr[$k][$y][4] === false) { + for($y = 0; $y < $kquantity; $y ++) { + if(is_array($arr[$k][$y])) { + if($arr[$k][$y][4] === false) { $has_items = true; } else { @@ -130,7 +130,7 @@ function get_features($filtered = true) { } } } - if (! $has_items) { + if(! $has_items) { unset($arr[$k]); } } diff --git a/include/feed.php b/include/feed.php index 317f6bee7..295993370 100644 --- a/include/feed.php +++ b/include/feed.php @@ -163,7 +163,7 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { $header["contact-id"] = $contact["id"]; - if (!strlen($contact["notify"])) { + if(!strlen($contact["notify"])) { // one way feed - no remote comment ability $header["last-child"] = 0; } @@ -280,7 +280,7 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { $type = ""; $title = ""; - foreach ($enclosure->attributes AS $attributes) { + foreach($enclosure->attributes AS $attributes) { if ($attributes->name == "url") { $href = $attributes->textContent; } elseif ($attributes->name == "length") { @@ -289,9 +289,8 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { $type = $attributes->textContent; } } - if (strlen($item["attach"])) { + if(strlen($item["attach"])) $item["attach"] .= ','; - } $attachments[] = array("link" => $href, "type" => $type, "length" => $length); diff --git a/include/files.php b/include/files.php index c20a6d832..7bff0e346 100644 --- a/include/files.php +++ b/include/files.php @@ -33,7 +33,7 @@ function create_files_from_item($itemid) { function create_files_from_itemuri($itemuri, $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) create_files_from_item($message["id"]); } diff --git a/include/friendica_smarty.php b/include/friendica_smarty.php index f497fbee0..9ba2d2a74 100644 --- a/include/friendica_smarty.php +++ b/include/friendica_smarty.php @@ -18,7 +18,7 @@ class FriendicaSmarty extends Smarty { // setTemplateDir can be set to an array, which Smarty will parse in order. // The order is thus very important here $template_dirs = array('theme' => "view/theme/$theme/".SMARTY3_TEMPLATE_FOLDER."/"); - if ( x($a->theme_info,"extends") ) + if( x($a->theme_info,"extends") ) $template_dirs = $template_dirs + array('extends' => "view/theme/".$a->theme_info["extends"]."/".SMARTY3_TEMPLATE_FOLDER."/"); $template_dirs = $template_dirs + array('base' => "view/".SMARTY3_TEMPLATE_FOLDER."/"); $this->setTemplateDir($template_dirs); @@ -35,7 +35,7 @@ class FriendicaSmarty extends Smarty { } function parsed($template = '') { - if ($template) { + if($template) { return $this->fetch('string:' . $template); } return $this->fetch('file:' . $this->filename); @@ -48,7 +48,7 @@ class FriendicaSmartyEngine implements ITemplateEngine { static $name ="smarty3"; public function __construct(){ - if (!is_writable('view/smarty3/')){ + if(!is_writable('view/smarty3/')){ echo "ERROR: folder view/smarty3/ must be writable by webserver."; killme(); } } @@ -56,7 +56,7 @@ class FriendicaSmartyEngine implements ITemplateEngine { // ITemplateEngine interface public function replace_macros($s, $r) { $template = ''; - if (gettype($s) === 'string') { + if(gettype($s) === 'string') { $template = $s; $s = new FriendicaSmarty(); } @@ -71,8 +71,8 @@ class FriendicaSmartyEngine implements ITemplateEngine { call_hooks("template_vars", $arr); $r = $arr['vars']; - foreach ($r as $key=>$value) { - if ($key[0] === '$') { + foreach($r as $key=>$value) { + if($key[0] === '$') { $key = substr($key, 1); } $s->assign($key, $value); diff --git a/include/group.php b/include/group.php index fa0e8f59a..6332c45da 100644 --- a/include/group.php +++ b/include/group.php @@ -4,9 +4,9 @@ function group_add($uid,$name) { $ret = false; - if (x($uid) && x($name)) { + if(x($uid) && x($name)) { $r = group_byname($uid,$name); // check for dups - if ($r !== false) { + if($r !== false) { // This could be a problem. // Let's assume we've just created a group which we once deleted @@ -17,7 +17,7 @@ function group_add($uid,$name) { $z = q("SELECT * FROM `group` WHERE `id` = %d LIMIT 1", intval($r) ); - if (count($z) && $z[0]['deleted']) { + if(count($z) && $z[0]['deleted']) { $r = q("UPDATE `group` SET `deleted` = 0 WHERE `uid` = %d AND `name` = '%s'", intval($uid), dbesc($name) @@ -39,14 +39,14 @@ function group_add($uid,$name) { function group_rmv($uid,$name) { $ret = false; - if (x($uid) && x($name)) { + if(x($uid) && x($name)) { $r = q("SELECT id FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1", intval($uid), dbesc($name) ); if (dbm::is_result($r)) $group_id = $r[0]['id']; - if (! $group_id) + if(! $group_id) return false; // remove group from default posting lists @@ -57,20 +57,20 @@ function group_rmv($uid,$name) { $user_info = $r[0]; $change = false; - if ($user_info['def_gid'] == $group_id) { + if($user_info['def_gid'] == $group_id) { $user_info['def_gid'] = 0; $change = true; } - if (strpos($user_info['allow_gid'], '<' . $group_id . '>') !== false) { + if(strpos($user_info['allow_gid'], '<' . $group_id . '>') !== false) { $user_info['allow_gid'] = str_replace('<' . $group_id . '>', '', $user_info['allow_gid']); $change = true; } - if (strpos($user_info['deny_gid'], '<' . $group_id . '>') !== false) { + if(strpos($user_info['deny_gid'], '<' . $group_id . '>') !== false) { $user_info['deny_gid'] = str_replace('<' . $group_id . '>', '', $user_info['deny_gid']); $change = true; } - if ($change) { + if($change) { q("UPDATE user SET def_gid = %d, allow_gid = '%s', deny_gid = '%s' WHERE uid = %d", intval($user_info['def_gid']), dbesc($user_info['allow_gid']), @@ -100,7 +100,7 @@ function group_rmv($uid,$name) { } function group_byname($uid,$name) { - if ((! $uid) || (! strlen($name))) + if((! $uid) || (! strlen($name))) return false; $r = q("SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1", intval($uid), @@ -113,9 +113,9 @@ function group_byname($uid,$name) { function group_rmv_member($uid,$name,$member) { $gid = group_byname($uid,$name); - if (! $gid) + if(! $gid) return false; - if (! ( $uid && $gid && $member)) + if(! ( $uid && $gid && $member)) return false; $r = q("DELETE FROM `group_member` WHERE `uid` = %d AND `gid` = %d AND `contact-id` = %d", intval($uid), @@ -129,9 +129,9 @@ function group_rmv_member($uid,$name,$member) { function group_add_member($uid,$name,$member,$gid = 0) { - if (! $gid) + if(! $gid) $gid = group_byname($uid,$name); - if ((! $gid) || (! $uid) || (! $member)) + if((! $gid) || (! $uid) || (! $member)) return false; $r = q("SELECT * FROM `group_member` WHERE `uid` = %d AND `gid` = %d AND `contact-id` = %d LIMIT 1", @@ -156,7 +156,7 @@ function group_add_member($uid,$name,$member,$gid = 0) { function group_get_members($gid) { $ret = array(); - if (intval($gid)) { + if(intval($gid)) { $r = q("SELECT `group_member`.`contact-id`, `contact`.* FROM `group_member` INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` WHERE `gid` = %d AND `group_member`.`uid` = %d AND @@ -173,7 +173,7 @@ function group_get_members($gid) { function group_public_members($gid) { $ret = 0; - if (intval($gid)) { + if(intval($gid)) { $r = q("SELECT `contact`.`id` AS `contact-id` FROM `group_member` INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id` WHERE `gid` = %d AND `group_member`.`uid` = %d @@ -252,7 +252,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro intval($_SESSION['uid']) ); $member_of = array(); - if ($cid) { + if($cid) { $member_of = groups_containing(local_user(),$cid); } @@ -302,7 +302,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro } function expand_groups($a,$check_dead = false, $use_gcontact = false) { - if (! (is_array($a) && count($a))) + if(! (is_array($a) && count($a))) return array(); $groups = implode(',', $a); $groups = dbesc($groups); @@ -318,9 +318,9 @@ function expand_groups($a,$check_dead = false, $use_gcontact = false) { $ret = array(); if (dbm::is_result($r)) - foreach ($r as $rr) + foreach($r as $rr) $ret[] = $rr['contact-id']; - if ($check_dead AND !$use_gcontact) { + if($check_dead AND !$use_gcontact) { require_once('include/acl_selectors.php'); $ret = prune_deadguys($ret); } @@ -347,9 +347,8 @@ function groups_containing($uid,$c) { $ret = array(); if (dbm::is_result($r)) { - foreach ($r as $rr) { + foreach($r as $rr) $ret[] = $rr['gid']; - } } return $ret; @@ -400,7 +399,7 @@ function get_default_group($uid, $network = "") { return $default_group; $g = q("SELECT `def_gid` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid)); - if ($g && intval($g[0]["def_gid"])) + if($g && intval($g[0]["def_gid"])) $default_group = $g[0]["def_gid"]; return $default_group; diff --git a/include/html2plain.php b/include/html2plain.php index dc2cb137c..1d5910d83 100644 --- a/include/html2plain.php +++ b/include/html2plain.php @@ -49,7 +49,7 @@ function quotelevel($message, $wraplength = 75) $newlines = array(); $level = 0; - foreach ($lines as $line) {; + foreach($lines as $line) {; $line = trim($line); $startquote = false; while (strpos("*".$line, '[quote]') > 0) { diff --git a/include/identity.php b/include/identity.php index ab38f3dc3..8138e9b04 100644 --- a/include/identity.php +++ b/include/identity.php @@ -38,7 +38,7 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) { dbesc($nickname) ); - if (!$user && count($user) && !count($profiledata)) { + if(!$user && count($user) && !count($profiledata)) { logger('profile error: ' . $a->query_string, LOGGER_DEBUG); notice( t('Requested account is not available.') . EOL ); $a->error = 404; @@ -47,7 +47,7 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) { $pdata = get_profiledata_by_nick($nickname, $user[0]['uid'], $profile); - if (($pdata === false) || (!count($pdata)) && !count($profiledata)) { + if(($pdata === false) || (!count($pdata)) && !count($profiledata)) { logger('profile error: ' . $a->query_string, LOGGER_DEBUG); notice( t('Requested profile is not available.') . EOL ); $a->error = 404; @@ -56,11 +56,11 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) { // fetch user tags if this isn't the default profile - if (!$pdata['is-default']) { + if(!$pdata['is-default']) { $x = q("SELECT `pub_keywords` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1", intval($pdata['profile_uid']) ); - if ($x && count($x)) + if($x && count($x)) $pdata['pub_keywords'] = $x[0]['pub_keywords']; } @@ -88,10 +88,10 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) { require_once($theme_info_file); } - if (! (x($a->page,'aside'))) + if(! (x($a->page,'aside'))) $a->page['aside'] = ''; - if (local_user() && local_user() == $a->profile['uid'] && $profiledata) { + if(local_user() && local_user() == $a->profile['uid'] && $profiledata) { $a->page['aside'] .= replace_macros(get_markup_template('profile_edlink.tpl'),array( '$editprofile' => t('Edit profile'), '$profid' => $a->profile['id'] @@ -110,7 +110,7 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) { else $a->page['aside'] .= profile_sidebar($a->profile, $block); - /*if (! $block) + /*if(! $block) $a->page['aside'] .= contact_block();*/ return; @@ -133,9 +133,9 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) { * Includes all available profile data */ function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) { - if (remote_user() && count($_SESSION['remote'])) { - foreach ($_SESSION['remote'] as $visitor) { - if ($visitor['uid'] == $uid) { + if(remote_user() && count($_SESSION['remote'])) { + foreach($_SESSION['remote'] as $visitor) { + if($visitor['uid'] == $uid) { $r = q("SELECT `profile-id` FROM `contact` WHERE `id` = %d LIMIT 1", intval($visitor['cid']) ); @@ -148,7 +148,7 @@ function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0) { $r = null; - if ($profile) { + if($profile) { $profile_int = intval($profile); $r = q("SELECT `contact`.`id` AS `contact_id`, `profile`.`uid` AS `profile_uid`, `profile`.*, `contact`.`avatar-date` AS picdate, `contact`.`addr`, `user`.* @@ -202,7 +202,7 @@ function profile_sidebar($profile, $block = 0) { $address = false; // $pdesc = true; - if ((! is_array($profile)) && (! count($profile))) + if((! is_array($profile)) && (! count($profile))) return $o; $profile['picdate'] = urlencode($profile['picdate']); @@ -219,9 +219,9 @@ function profile_sidebar($profile, $block = 0) { $connect = (($profile['uid'] != local_user()) ? t('Connect') : False); // don't show connect link to authenticated visitors either - if (remote_user() && count($_SESSION['remote'])) { - foreach ($_SESSION['remote'] as $visitor) { - if ($visitor['uid'] == $profile['uid']) { + if(remote_user() && count($_SESSION['remote'])) { + foreach($_SESSION['remote'] as $visitor) { + if($visitor['uid'] == $profile['uid']) { $connect = false; break; } @@ -322,7 +322,7 @@ function profile_sidebar($profile, $block = 0) { // Fetch the account type $account_type = account_type($profile); - if ((x($profile,'address') == 1) + if((x($profile,'address') == 1) || (x($profile,'location') == 1) || (x($profile,'locality') == 1) || (x($profile,'region') == 1) @@ -341,7 +341,7 @@ function profile_sidebar($profile, $block = 0) { $xmpp = ((x($profile,'xmpp') == 1) ? t('XMPP:') : False); - if (($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) { + if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) { $location = $pdesc = $gender = $marital = $homepage = $about = False; } @@ -368,7 +368,7 @@ function profile_sidebar($profile, $block = 0) { if (!$block){ $contact_block = contact_block(); - if (is_array($a->profile) AND !$a->profile['hide-friends']) { + if(is_array($a->profile) AND !$a->profile['hide-friends']) { $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1", intval($a->profile['uid'])); if (dbm::is_result($r)) @@ -390,7 +390,7 @@ function profile_sidebar($profile, $block = 0) { } $p = array(); - foreach ($profile as $k => $v) { + foreach($profile as $k => $v) { $k = str_replace('-','_',$k); $p[$k] = $v; } @@ -406,7 +406,7 @@ function profile_sidebar($profile, $block = 0) { if (isset($p["photo"])) $p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL); - if ($a->theme['template_engine'] === 'internal') + if($a->theme['template_engine'] === 'internal') $location = template_escape($location); $tpl = get_markup_template('profile_vcard.tpl'); @@ -445,13 +445,13 @@ function get_birthdays() { $a = get_app(); $o = ''; - if (! local_user() || $a->is_mobile || $a->is_tablet) + if(! local_user() || $a->is_mobile || $a->is_tablet) return $o; // $mobile_detect = new Mobile_Detect(); // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet(); -// if ($is_mobile) +// if($is_mobile) // return $o; $bd_format = t('g A l F d') ; // 8 AM Friday January 18 @@ -479,27 +479,27 @@ function get_birthdays() { $istoday = false; foreach ($r as $rr) { - if (strlen($rr['name'])) + if(strlen($rr['name'])) $total ++; - if ((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) + if((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) $istoday = true; } $classtoday = $istoday ? ' birthday-today ' : ''; - if ($total) { - foreach ($r as &$rr) { - if (! strlen($rr['name'])) + if($total) { + foreach($r as &$rr) { + if(! strlen($rr['name'])) continue; // avoid duplicates - if (in_array($rr['cid'],$cids)) + if(in_array($rr['cid'],$cids)) continue; $cids[] = $rr['cid']; $today = (((strtotime($rr['start'] . ' +00:00') < $now) && (strtotime($rr['finish'] . ' +00:00') > $now)) ? true : false); $sparkle = ''; $url = $rr['url']; - if ($rr['network'] === NETWORK_DFRN) { + if($rr['network'] === NETWORK_DFRN) { $sparkle = " sparkle"; $url = App::get_baseurl() . '/redir/' . $rr['cid']; } @@ -534,14 +534,14 @@ function get_events() { $a = get_app(); - if (! local_user() || $a->is_mobile || $a->is_tablet) + if(! local_user() || $a->is_mobile || $a->is_tablet) return $o; // $mobile_detect = new Mobile_Detect(); // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet(); -// if ($is_mobile) +// if($is_mobile) // return $o; $bd_format = t('g A l F d') ; // 8 AM Friday January 18 @@ -559,30 +559,30 @@ function get_events() { $now = strtotime('now'); $istoday = false; foreach ($r as $rr) { - if (strlen($rr['name'])) + if(strlen($rr['name'])) $total ++; $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d'); - if ($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) + if($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) $istoday = true; } $classtoday = (($istoday) ? 'event-today' : ''); $skip = 0; - foreach ($r as &$rr) { + foreach($r as &$rr) { $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8')); - if (strlen($title) > 35) + if(strlen($title) > 35) $title = substr($title,0,32) . '... '; $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... '; - if (! $description) + if(! $description) $description = t('[No description]'); $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']); - if (substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) { + if(substr($strt,0,10) < datetime_convert('UTC',$a->timezone,'now','Y-m-d')) { $skip++; continue; } @@ -617,7 +617,7 @@ function advanced_profile(App $a) { '$title' => t('Profile') )); - if ($a->profile['name']) { + if($a->profile['name']) { $tpl = get_markup_template('profile_advanced.tpl'); @@ -625,10 +625,10 @@ function advanced_profile(App $a) { $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ; - if ($a->profile['gender']) $profile['gender'] = array( t('Gender:'), $a->profile['gender'] ); + if($a->profile['gender']) $profile['gender'] = array( t('Gender:'), $a->profile['gender'] ); - if (($a->profile['dob']) && ($a->profile['dob'] != '0000-00-00')) { + if(($a->profile['dob']) && ($a->profile['dob'] != '0000-00-00')) { $year_bd_format = t('j F, Y'); $short_bd_format = t('j F'); @@ -642,10 +642,10 @@ function advanced_profile(App $a) { } - if ($age = age($a->profile['dob'],$a->profile['timezone'],'')) $profile['age'] = array( t('Age:'), $age ); + if($age = age($a->profile['dob'],$a->profile['timezone'],'')) $profile['age'] = array( t('Age:'), $age ); - if ($a->profile['marital']) $profile['marital'] = array( t('Status:'), $a->profile['marital']); + if($a->profile['marital']) $profile['marital'] = array( t('Status:'), $a->profile['marital']); /// @TODO Maybe use x() here, plus below? if ($a->profile['with']) { @@ -850,14 +850,14 @@ function profile_tabs($a, $is_owner=False, $nickname=Null){ } function get_my_url() { - if (x($_SESSION,'my_url')) + if(x($_SESSION,'my_url')) return $_SESSION['my_url']; return false; } function zrl_init(App $a) { $tmp_str = get_my_url(); - if (validate_url($tmp_str)) { + if(validate_url($tmp_str)) { // Is it a DDoS attempt? // The check fetches the cached value from gprobe to reduce the load for this system @@ -878,20 +878,16 @@ function zrl_init(App $a) { } function zrl($s,$force = false) { - if (! strlen($s)) { + if(! strlen($s)) return $s; - } - if ((! strpos($s,'/profile/')) && (! $force)) { + if((! strpos($s,'/profile/')) && (! $force)) return $s; - } - if ($force && substr($s,-1,1) !== '/') { + if($force && substr($s,-1,1) !== '/') $s = $s . '/'; - } $achar = strpos($s,'?') ? '&' : '?'; $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; } @@ -911,10 +907,9 @@ function zrl($s,$force = false) { */ function get_theme_uid() { $uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0); - if (local_user()) { - if ((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid)) { + if(local_user()) { + if((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid)) return local_user(); - } } return $uid; diff --git a/include/items.php b/include/items.php index 6f9403701..24eb1b30f 100644 --- a/include/items.php +++ b/include/items.php @@ -60,7 +60,7 @@ function limit_body_size($body) { $img_start = strpos($orig_body, '[img'); $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false); - while (($img_st_close !== false) && ($img_end !== false)) { + while(($img_st_close !== false) && ($img_end !== false)) { $img_st_close++; // make it point to AFTER the closing bracket $img_end += $img_start; @@ -1099,7 +1099,7 @@ function item_body_set_hashtags(&$item) { "#$2", $item["body"]); - foreach ($tags as $tag) { + foreach($tags as $tag) { if (strpos($tag,'#') !== 0) continue; @@ -1170,7 +1170,7 @@ function get_item_id($guid, $uid = 0) { function get_item_contact($item,$contacts) { if (! count($contacts) || (! is_array($item))) return false; - foreach ($contacts as $contact) { + foreach($contacts as $contact) { if ($contact['id'] == $item['contact-id']) { return $contact; break; // NOTREACHED @@ -1224,7 +1224,7 @@ function tag_deliver($uid,$item_id) { $cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism',$item['body'],$matches,PREG_SET_ORDER); if ($cnt) { - foreach ($matches as $mtch) { + foreach($matches as $mtch) { if (link_compare($link,$mtch[1]) || link_compare($dlink,$mtch[1])) { $mention = true; logger('tag_deliver: mention found: ' . $mtch[2]); @@ -1681,7 +1681,7 @@ function fix_private_photos($s, $uid, $item = null, $cid = 0) { $img_start = strpos($orig_body, '[img'); $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); $img_len = ($img_start !== false ? strpos(substr($orig_body, $img_start + $img_st_close + 1), '[/img]') : false); - while ( ($img_st_close !== false) && ($img_len !== false) ) { + while( ($img_st_close !== false) && ($img_len !== false) ) { $img_st_close++; // make it point to AFTER the closing bracket $image = substr($orig_body, $img_start + $img_st_close, $img_len); @@ -1810,7 +1810,7 @@ function item_getfeedtags($item) { $matches = false; $cnt = preg_match_all('|\#\[url\=(.*?)\](.*?)\[\/url\]|',$item['tag'],$matches); if ($cnt) { - for ($x = 0; $x < $cnt; $x ++) { + for($x = 0; $x < $cnt; $x ++) { if ($matches[1][$x]) $ret[$matches[2][$x]] = array('#',$matches[1][$x], $matches[2][$x]); } @@ -1818,7 +1818,7 @@ function item_getfeedtags($item) { $matches = false; $cnt = preg_match_all('|\@\[url\=(.*?)\](.*?)\[\/url\]|',$item['tag'],$matches); if ($cnt) { - for ($x = 0; $x < $cnt; $x ++) { + for($x = 0; $x < $cnt; $x ++) { if ($matches[1][$x]) $ret[] = array('@',$matches[1][$x], $matches[2][$x]); } @@ -1876,7 +1876,7 @@ function item_expire($uid, $days, $network = "", $force = false) { logger('expire: # items=' . count($r). "; expire items: $expire_items, expire notes: $expire_notes, expire starred: $expire_starred, expire photos: $expire_photos"); - foreach ($r as $item) { + foreach($r as $item) { // don't expire filed items @@ -1909,7 +1909,7 @@ function drop_items($items) { return; if (count($items)) { - foreach ($items as $item) { + foreach($items as $item) { $owner = drop_item($item,false); if ($owner && ! $uid) $uid = $owner; @@ -1949,7 +1949,7 @@ function drop_item($id,$interactive = true) { // check if logged in user is either the author or owner of this item if (is_array($_SESSION['remote'])) { - foreach ($_SESSION['remote'] as $visitor) { + foreach($_SESSION['remote'] as $visitor) { if ($visitor['uid'] == $item['uid'] && $visitor['cid'] == $item['contact-id']) { $contact_id = $visitor['cid']; break; @@ -1966,7 +1966,7 @@ function drop_item($id,$interactive = true) { // so add any arguments as hidden inputs $query = explode_querystring($a->query_string); $inputs = array(); - foreach ($query['args'] as $arg) { + foreach($query['args'] as $arg) { if (strpos($arg, 'confirm=') === false) { $arg_parts = explode('=', $arg); $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]); @@ -2005,7 +2005,7 @@ function drop_item($id,$interactive = true) { $matches = false; $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER); if ($cnt) { - foreach ($matches as $mtch) { + foreach($matches as $mtch) { file_tag_unsave_file($item['uid'],$item['id'],$mtch[1],true); } } @@ -2014,7 +2014,7 @@ function drop_item($id,$interactive = true) { $cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER); if ($cnt) { - foreach ($matches as $mtch) { + foreach($matches as $mtch) { file_tag_unsave_file($item['uid'],$item['id'],$mtch[1],false); } } @@ -2044,7 +2044,7 @@ function drop_item($id,$interactive = true) { // If item has attachments, drop them - foreach (explode(",",$item['attach']) as $attach){ + foreach(explode(",",$item['attach']) as $attach){ preg_match("|attach/(\d+)|", $attach, $matches); q("DELETE FROM `attach` WHERE `id` = %d AND `uid` = %d", intval($matches[1]), @@ -2179,7 +2179,7 @@ function list_post_dates($uid, $wall) { // Starting with the current month, get the first and last days of every // month down to and including the month of the first post - while (substr($dnow, 0, 7) >= substr($dthen, 0, 7)) { + while(substr($dnow, 0, 7) >= substr($dthen, 0, 7)) { $dyear = intval(substr($dnow,0,4)); $dstart = substr($dnow,0,8) . '01'; $dend = substr($dnow,0,8) . get_dim(intval($dnow),intval(substr($dnow,5))); @@ -2208,7 +2208,7 @@ function posted_dates($uid,$wall) { $ret = array(); // Starting with the current month, get the first and last days of every // month down to and including the month of the first post - while (substr($dnow, 0, 7) >= substr($dthen, 0, 7)) { + while(substr($dnow, 0, 7) >= substr($dthen, 0, 7)) { $dstart = substr($dnow,0,8) . '01'; $dend = substr($dnow,0,8) . get_dim(intval($dnow),intval(substr($dnow,5))); $start_month = datetime_convert('','',$dstart,'Y-m-d'); diff --git a/include/lock.php b/include/lock.php index 64f6319ef..a48b0ad34 100644 --- a/include/lock.php +++ b/include/lock.php @@ -2,9 +2,9 @@ // Provide some ability to lock a PHP function so that multiple processes // can't run the function concurrently -if (! function_exists('lock_function')) { +if(! function_exists('lock_function')) { function lock_function($fn_name, $block = true, $wait_sec = 2, $timeout = 30) { - if ( $wait_sec == 0 ) + if( $wait_sec == 0 ) $wait_sec = 2; // don't let the user pick a value that's likely to crash the system $got_lock = false; @@ -16,7 +16,7 @@ function lock_function($fn_name, $block = true, $wait_sec = 2, $timeout = 30) { dbesc($fn_name) ); - if ((dbm::is_result($r)) AND (!$r[0]['locked'] OR (strtotime($r[0]['created']) < time() - 3600))) { + if((dbm::is_result($r)) AND (!$r[0]['locked'] OR (strtotime($r[0]['created']) < time() - 3600))) { q("UPDATE `locks` SET `locked` = 1, `created` = '%s' WHERE `name` = '%s'", dbesc(datetime_convert()), dbesc($fn_name) @@ -34,10 +34,10 @@ function lock_function($fn_name, $block = true, $wait_sec = 2, $timeout = 30) { q("UNLOCK TABLES"); - if (($block) && (! $got_lock)) + if(($block) && (! $got_lock)) sleep($wait_sec); - } while (($block) && (! $got_lock) && ((time() - $start) < $timeout)); + } while(($block) && (! $got_lock) && ((time() - $start) < $timeout)); logger('lock_function: function ' . $fn_name . ' with blocking = ' . $block . ' got_lock = ' . $got_lock . ' time = ' . (time() - $start), LOGGER_DEBUG); @@ -45,29 +45,28 @@ function lock_function($fn_name, $block = true, $wait_sec = 2, $timeout = 30) { }} -if (! function_exists('block_on_function_lock')) { +if(! function_exists('block_on_function_lock')) { function block_on_function_lock($fn_name, $wait_sec = 2, $timeout = 30) { - if ( $wait_sec == 0 ) + if( $wait_sec == 0 ) $wait_sec = 2; // don't let the user pick a value that's likely to crash the system $start = time(); do { $r = q("SELECT locked FROM locks WHERE name = '%s' LIMIT 1", - 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); - } - } while (dbm::is_result($r) && $r[0]['locked'] && ((time() - $start) < $timeout)); + } while(dbm::is_result($r) && $r[0]['locked'] && ((time() - $start) < $timeout)); return; }} -if (! function_exists('unlock_function')) { +if(! function_exists('unlock_function')) { function unlock_function($fn_name) { $r = q("UPDATE `locks` SET `locked` = 0, `created` = '%s' WHERE `name` = '%s'", dbesc(NULL_DATE), diff --git a/include/message.php b/include/message.php index b94190ca0..3d5d4d33a 100644 --- a/include/message.php +++ b/include/message.php @@ -9,9 +9,9 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ $a = get_app(); - if (! $recipient) return -1; + if(! $recipient) return -1; - if (! strlen($subject)) + if(! strlen($subject)) $subject = t('[no subject]'); $me = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", @@ -22,7 +22,7 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ intval(local_user()) ); - if (! (count($me) && (count($contact)))) { + if(! (count($me) && (count($contact)))) { return -2; } @@ -34,7 +34,7 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ // look for any existing conversation structure - if (strlen($replyto)) { + if(strlen($replyto)) { $reply = true; $r = q("select convid from mail where uid = %d and ( uri = '%s' or `parent-uri` = '%s' ) limit 1", intval(local_user()), @@ -45,7 +45,7 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ $convid = $r[0]['convid']; } - if (! $convid) { + if(! $convid) { // create a new conversation @@ -78,12 +78,12 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){ $convid = $r[0]['id']; } - if (! $convid) { + if(! $convid) { logger('send message: conversation not found.'); return -4; } - if (! strlen($replyto)) { + if(! strlen($replyto)) { $replyto = $convuri; } diff --git a/include/msgclean.php b/include/msgclean.php index de7dacca2..3b5ed5487 100644 --- a/include/msgclean.php +++ b/include/msgclean.php @@ -154,7 +154,7 @@ function removelinebreak($message) $lines = array(); $lineno = 0; - foreach ($arrbody as $i => $line) { + foreach($arrbody as $i => $line) { $currquotelevel = 0; $currline = $line; while ((strlen($currline)>0) and ((substr($currline, 0, 1) == '>') diff --git a/include/nav.php b/include/nav.php index b184f1180..fe4c50818 100644 --- a/include/nav.php +++ b/include/nav.php @@ -8,7 +8,7 @@ function nav(App $a) { * */ - if (!(x($a->page,'nav'))) + if(!(x($a->page,'nav'))) $a->page['nav'] = ''; $a->page['htmlhead'] .= replace_macros(get_markup_template('nav_head.tpl'), array()); @@ -136,7 +136,7 @@ function nav_info(App $a) if (strlen(get_config('system', 'singleuser'))) { $gdir = get_config('system', 'directory'); - if (strlen($gdir)) { + if(strlen($gdir)) { $gdirpath = zrl($gdir, true); } } elseif (get_config('system', 'community_page_style') == CP_USERS_ON_SERVER) { diff --git a/include/network.php b/include/network.php index 5f533ae96..f9d35c52c 100644 --- a/include/network.php +++ b/include/network.php @@ -78,7 +78,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { @curl_setopt($ch, CURLOPT_HEADER, true); - if (x($opts,"cookiejar")) { + if(x($opts,"cookiejar")) { curl_setopt($ch, CURLOPT_COOKIEJAR, $opts["cookiejar"]); curl_setopt($ch, CURLOPT_COOKIEFILE, $opts["cookiejar"]); } @@ -101,13 +101,13 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { @curl_setopt($ch, CURLOPT_RANGE, '0-'.$range); } - if (x($opts,'headers')){ + if(x($opts,'headers')){ @curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']); } - if (x($opts,'nobody')){ + if(x($opts,'nobody')){ @curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']); } - if (x($opts,'timeout')){ + if(x($opts,'timeout')){ @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); } else { $curl_time = intval(get_config('system','curl_timeout')); @@ -124,14 +124,14 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { } $prx = get_config('system','proxy'); - if (strlen($prx)) { + if(strlen($prx)) { @curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); @curl_setopt($ch, CURLOPT_PROXY, $prx); $prxusr = @get_config('system','proxyuser'); - if (strlen($prxusr)) + if(strlen($prxusr)) @curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxusr); } - if ($binary) + if($binary) @curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $a->set_curl_code(0); @@ -156,7 +156,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { // Pull out multiple headers, e.g. proxy and continuation headers // allow for HTTP/2.x without fixing code - while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/',$base)) { + while(preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/',$base)) { $chunk = substr($base,0,strpos($base,"\r\n\r\n")+4); $header .= $chunk; $base = substr($base,strlen($chunk)); @@ -166,7 +166,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { $a->set_curl_content_type($curl_info['content_type']); $a->set_curl_headers($header); - if ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { + if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { $new_location_info = @parse_url($curl_info["redirect_url"]); $old_location_info = @parse_url($curl_info["url"]); @@ -179,7 +179,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { if (preg_match('/(Location:|URI:)(.*?)\n/i', $header, $matches)) { $newurl = trim(array_pop($matches)); } - if (strpos($newurl,'/') === 0) + if(strpos($newurl,'/') === 0) $newurl = $old_location_info["scheme"]."://".$old_location_info["host"].$newurl; if (filter_var($newurl, FILTER_VALIDATE_URL)) { $redirects++; @@ -200,7 +200,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { $ret['return_code'] = $rc; $ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false); $ret['redirect_url'] = $url; - if (! $ret['success']) { + if(! $ret['success']) { $ret['error'] = curl_error($ch); $ret['debug'] = $curl_info; logger('z_fetch_url: error: ' . $url . ': ' . $ret['error'], LOGGER_DEBUG); @@ -208,7 +208,7 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) { } $ret['body'] = substr($s,strlen($header)); $ret['header'] = $header; - if (x($opts,'debug')) { + if(x($opts,'debug')) { $ret['debug'] = $curl_info; } @curl_close($ch); @@ -237,7 +237,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) $a = get_app(); $ch = curl_init($url); - if (($redirects > 8) || (! $ch)) + if(($redirects > 8) || (! $ch)) return false; logger("post_url: start ".$url, LOGGER_DATA); @@ -248,7 +248,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) curl_setopt($ch, CURLOPT_POSTFIELDS,$params); curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent()); - if (intval($timeout)) { + if(intval($timeout)) { curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); } else { @@ -256,16 +256,16 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60)); } - if (defined('LIGHTTPD')) { - if (!is_array($headers)) { + if(defined('LIGHTTPD')) { + if(!is_array($headers)) { $headers = array('Expect:'); } else { - if (!in_array('Expect:', $headers)) { + if(!in_array('Expect:', $headers)) { array_push($headers, 'Expect:'); } } } - if ($headers) + if($headers) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $check_cert = get_config('system','verifyssl'); @@ -274,11 +274,11 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); } $prx = get_config('system','proxy'); - if (strlen($prx)) { + if(strlen($prx)) { curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); curl_setopt($ch, CURLOPT_PROXY, $prx); $prxusr = get_config('system','proxyuser'); - if (strlen($prxusr)) + if(strlen($prxusr)) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxusr); } @@ -300,17 +300,17 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) // Pull out multiple headers, e.g. proxy and continuation headers // allow for HTTP/2.x without fixing code - while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/',$base)) { + while(preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/',$base)) { $chunk = substr($base,0,strpos($base,"\r\n\r\n")+4); $header .= $chunk; $base = substr($base,strlen($chunk)); } - if ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { + if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { $matches = array(); preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); $newurl = trim(array_pop($matches)); - if (strpos($newurl,'/') === 0) + if(strpos($newurl,'/') === 0) $newurl = $old_location_info["scheme"] . "://" . $old_location_info["host"] . $newurl; if (filter_var($newurl, FILTER_VALIDATE_URL)) { $redirects++; @@ -341,7 +341,7 @@ function xml_status($st, $message = '') { $xml_message = ((strlen($message)) ? "\t" . xmlify($message) . "\r\n" : ''); - if ($st) + if($st) logger('xml_status returning non_zero: ' . $st . " message=" . $message); header( "Content-type: text/xml" ); @@ -369,12 +369,12 @@ function xml_status($st, $message = '') { */ function http_status_exit($val, $description = array()) { $err = ''; - if ($val >= 400) { + if($val >= 400) { $err = 'Error'; if (!isset($description["title"])) $description["title"] = $err." ".$val; } - if ($val >= 200 && $val < 300) + if($val >= 200 && $val < 300) $err = 'OK'; logger('http_status_exit ' . $val); @@ -400,20 +400,20 @@ function http_status_exit($val, $description = array()) { * @return boolean True if it's a valid URL, fals if something wrong with it */ function validate_url(&$url) { - if (get_config('system','disable_url_validation')) + if(get_config('system','disable_url_validation')) return true; // no naked subdomains (allow localhost for tests) - if (strpos($url,'.') === false && strpos($url,'/localhost/') === false) + if(strpos($url,'.') === false && strpos($url,'/localhost/') === false) return false; - if (substr($url,0,4) != 'http') + if(substr($url,0,4) != 'http') $url = 'http://' . $url; /// @TODO Really supress function outcomes? Why not find them + debug them? $h = @parse_url($url); - if ((is_array($h)) && (dns_get_record($h['host'], DNS_A + DNS_CNAME + DNS_PTR) || filter_var($h['host'], FILTER_VALIDATE_IP) )) { + if((is_array($h)) && (dns_get_record($h['host'], DNS_A + DNS_CNAME + DNS_PTR) || filter_var($h['host'], FILTER_VALIDATE_IP) )) { return true; } @@ -428,14 +428,14 @@ function validate_url(&$url) { */ function validate_email($addr) { - if (get_config('system','disable_email_validation')) + if(get_config('system','disable_email_validation')) return true; - if (! strpos($addr,'@')) + if(! strpos($addr,'@')) return false; $h = substr($addr,strpos($addr,'@') + 1); - if (($h) && (dns_get_record($h, DNS_A + DNS_CNAME + DNS_PTR + DNS_MX) || filter_var($h, FILTER_VALIDATE_IP) )) { + if(($h) && (dns_get_record($h, DNS_A + DNS_CNAME + DNS_PTR + DNS_MX) || filter_var($h, FILTER_VALIDATE_IP) )) { return true; } return false; @@ -454,12 +454,12 @@ function allowed_url($url) { $h = @parse_url($url); - if (! $h) { + if(! $h) { return false; } $str_allowed = get_config('system','allowed_sites'); - if (! $str_allowed) + if(! $str_allowed) return true; $found = false; @@ -468,16 +468,16 @@ function allowed_url($url) { // always allow our own site - if ($host == strtolower($_SERVER['SERVER_NAME'])) + if($host == strtolower($_SERVER['SERVER_NAME'])) return true; $fnmatch = function_exists('fnmatch'); $allowed = explode(',',$str_allowed); - if (count($allowed)) { - foreach ($allowed as $a) { + if(count($allowed)) { + foreach($allowed as $a) { $pat = strtolower(trim($a)); - if (($fnmatch && fnmatch($pat,$host)) || ($pat == $host)) { + if(($fnmatch && fnmatch($pat,$host)) || ($pat == $host)) { $found = true; break; } @@ -497,25 +497,24 @@ function allowed_url($url) { */ function allowed_email($email) { + $domain = strtolower(substr($email,strpos($email,'@') + 1)); - if (! $domain) { + if(! $domain) return false; - } $str_allowed = get_config('system','allowed_email'); - if (! $str_allowed) { + if(! $str_allowed) return true; - } $found = false; $fnmatch = function_exists('fnmatch'); $allowed = explode(',',$str_allowed); - if (count($allowed)) { - foreach ($allowed as $a) { + if(count($allowed)) { + foreach($allowed as $a) { $pat = strtolower(trim($a)); - if (($fnmatch && fnmatch($pat,$domain)) || ($pat == $domain)) { + if(($fnmatch && fnmatch($pat,$domain)) || ($pat == $domain)) { $found = true; break; } @@ -544,8 +543,8 @@ function avatar_img($email) { function parse_xml_string($s,$strict = true) { /// @todo Move this function to the xml class - if ($strict) { - if (! strstr($s,'user = $record; - if (strlen($a->user['timezone'])) { + if(strlen($a->user['timezone'])) { date_default_timezone_set($a->user['timezone']); $a->timezone = $a->user['timezone']; } diff --git a/include/oembed.php b/include/oembed.php index 06c2520d1..a1945894f 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -314,11 +314,9 @@ function oembed_html2bbcode($text) { $entries = $xpath->query("//span[$xattr]"); $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; - 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) ); } else { diff --git a/include/onepoll.php b/include/onepoll.php index d42521281..5227b61a1 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -61,7 +61,7 @@ function onepoll_run(&$argv, &$argc){ intval($contact_id) ); - if (! dbm::is_result($contacts)) { + if (! count($contacts)) { return; } @@ -437,18 +437,16 @@ function onepoll_run(&$argv, &$argc){ if ($raw_refs) { $refs_arr = explode(' ', $raw_refs); if (count($refs_arr)) { - for ($x = 0; $x < count($refs_arr); $x ++) { + for($x = 0; $x < count($refs_arr); $x ++) $refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'"; - } } $qstr = implode(',',$refs_arr); $r = q("SELECT `uri` , `parent-uri` FROM `item` USE INDEX (`uid_uri`) WHERE `uri` IN ($qstr) AND `uid` = %d LIMIT 1", intval($importer_uid) ); - if (dbm::is_result($r)) { + if (dbm::is_result($r)) $datarray['parent-uri'] = $r[0]['parent-uri']; // Set the parent as the top-level item - //$datarray['parent-uri'] = $r[0]['uri']; - } + // $datarray['parent-uri'] = $r[0]['uri']; } // Decoding the header diff --git a/include/ostatus.php b/include/ostatus.php index 3a8c5ae37..2c4b677a5 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -37,11 +37,9 @@ class ostatus { * @param bool $onlyfetch Only fetch the header without updating the contact entries * * @return array Array of author related entries for the item - * @todo Add type-hints */ private function fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch) { - /// @TODO One statment is enough ... $author = array(); $author["author-link"] = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue; $author["author-name"] = $xpath->evaluate('atom:author/atom:name/text()', $context)->item(0)->nodeValue; @@ -49,41 +47,33 @@ class ostatus { $aliaslink = $author["author-link"]; $alternate = $xpath->query("atom:author/atom:link[@rel='alternate']", $context)->item(0)->attributes; - if (is_object($alternate)) { - /// @TODO foreach () may only later work on objects that have iterator interface implemented, please check this - foreach ($alternate AS $attributes) { - if ($attributes->name == "href") { + if (is_object($alternate)) + foreach($alternate AS $attributes) + if ($attributes->name == "href") $author["author-link"] = $attributes->textContent; - } - } - } $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` IN ('%s', '%s') AND `network` != '%s'", intval($importer["uid"]), dbesc(normalise_link($author["author-link"])), dbesc(normalise_link($aliaslink)), dbesc(NETWORK_STATUSNET)); - if (dbm::is_result($r)) { + if ($r) { $contact = $r[0]; $author["contact-id"] = $r[0]["id"]; - } else { + } else $author["contact-id"] = $contact["id"]; - } $avatarlist = array(); $avatars = $xpath->query("atom:author/atom:link[@rel='avatar']", $context); - foreach ($avatars AS $avatar) { + foreach($avatars AS $avatar) { $href = ""; $width = 0; - foreach ($avatar->attributes AS $attributes) { - if ($attributes->name == "href") { + foreach($avatar->attributes AS $attributes) { + if ($attributes->name == "href") $href = $attributes->textContent; - } - if ($attributes->name == "width") { + if ($attributes->name == "width") $width = $attributes->textContent; - } } - if (($width > 0) AND ($href != "")) { + if (($width > 0) AND ($href != "")) $avatarlist[$width] = $href; - } } if (count($avatarlist) > 0) { krsort($avatarlist); @@ -91,16 +81,15 @@ class ostatus { } $displayname = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue; - if ($displayname != "") { + if ($displayname != "") $author["author-name"] = $displayname; - } $author["owner-name"] = $author["author-name"]; $author["owner-link"] = $author["author-link"]; $author["owner-avatar"] = $author["author-avatar"]; // Only update the contacts if it is an OStatus contact - if (dbm::is_result($r) AND !$onlyfetch AND ($contact["network"] == NETWORK_OSTATUS)) { + if ($r AND !$onlyfetch AND ($contact["network"] == NETWORK_OSTATUS)) { // Update contact data @@ -115,29 +104,24 @@ class ostatus { // $contact["poll"] = $value; $value = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue; - if ($value != "") { + if ($value != "") $contact["alias"] = $value; - } $value = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue; - if ($value != "") { + if ($value != "") $contact["name"] = $value; - } $value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue; - if ($value != "") { + if ($value != "") $contact["nick"] = $value; - } $value = $xpath->evaluate('atom:author/poco:note/text()', $context)->item(0)->nodeValue; - if ($value != "") { + if ($value != "") $contact["about"] = html2bbcode($value); - } $value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue; - if ($value != "") { + if ($value != "") $contact["location"] = $value; - } if (($contact["name"] != $r[0]["name"]) OR ($contact["nick"] != $r[0]["nick"]) OR ($contact["about"] != $r[0]["about"]) OR ($contact["alias"] != $r[0]["alias"]) OR ($contact["location"] != $r[0]["location"])) { @@ -192,16 +176,14 @@ class ostatus { * @param array $importer user record of the importing user * * @return array Array of author related entries for the item - * @todo add type-hints */ public static function salmon_author($xml, $importer) { - if ($xml == "") { + if ($xml == "") return; - } $doc = new DOMDocument(); - $doc->loadXML($xml); + @$doc->loadXML($xml); $xpath = new DomXPath($doc); $xpath->registerNamespace('atom', NAMESPACE_ATOM1); @@ -229,22 +211,20 @@ class ostatus { * @param array $importer user record of the importing user * @param $contact * @param array $hub Called by reference, returns the fetched hub data - * @todo Add missing-type hint + determine type for $contact */ public static function import($xml,$importer,&$contact, &$hub) { /// @todo this function is too long. It has to be split in many parts logger("Import OStatus message", LOGGER_DEBUG); - if ($xml == "") { + if ($xml == "") return; - } //$tempfile = tempnam(get_temppath(), "import"); //file_put_contents($tempfile, $xml); $doc = new DOMDocument(); - $doc->loadXML($xml); + @$doc->loadXML($xml); $xpath = new DomXPath($doc); $xpath->registerNamespace('atom', NAMESPACE_ATOM1); @@ -258,16 +238,13 @@ class ostatus { $gub = ""; $hub_attributes = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0)->attributes; - if (is_object($hub_attributes)) { - foreach ($hub_attributes AS $hub_attribute) { + if (is_object($hub_attributes)) + foreach($hub_attributes AS $hub_attribute) if ($hub_attribute->name == "href") { $hub = $hub_attribute->textContent; logger("Found hub ".$hub, LOGGER_DEBUG); } - } - } - /// @TODO One statement is enough ... $header = array(); $header["uid"] = $importer["uid"]; $header["network"] = NETWORK_OSTATUS; @@ -280,11 +257,10 @@ class ostatus { // depending on that, the first node is different $first_child = $doc->firstChild->tagName; - if ($first_child == "feed") { + if ($first_child == "feed") $entries = $xpath->query('/atom:feed/atom:entry'); - } else { + else $entries = $xpath->query('/atom:entry'); - } $conversation = ""; $conversationlist = array(); @@ -301,18 +277,16 @@ class ostatus { $mention = false; // fetch the author - if ($first_child == "feed") { + if ($first_child == "feed") $author = self::fetchauthor($xpath, $doc->firstChild, $importer, $contact, false); - } else { + else $author = self::fetchauthor($xpath, $entry, $importer, $contact, false); - } $value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue; - if ($value != "") { + if ($value != "") $nickname = $value; - } else { + else $nickname = $author["author-name"]; - } $item = array_merge($header, $author); @@ -321,7 +295,7 @@ class ostatus { $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", intval($importer["uid"]), dbesc($item["uri"])); - if (dbm::is_result($r)) { + if ($r) { logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG); continue; } @@ -332,9 +306,8 @@ class ostatus { if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) OR ($item["object-type"] == ACTIVITY_OBJ_EVENT)) { $item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue; $item["body"] = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue; - } elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) { + } elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) $item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue; - } $item["object"] = $xml; $item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue; @@ -379,9 +352,8 @@ class ostatus { } // http://activitystrea.ms/schema/1.0/rsvp-yes - if (!in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE))) { + if (!in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE))) logger("Unhandled verb ".$item["verb"]." ".print_r($item, true)); - } $item["created"] = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue; $item["edited"] = $xpath->query('atom:updated/text()', $entry)->item(0)->nodeValue; @@ -391,13 +363,11 @@ class ostatus { $inreplyto = $xpath->query('thr:in-reply-to', $entry); if (is_object($inreplyto->item(0))) { - foreach ($inreplyto->item(0)->attributes AS $attributes) { - if ($attributes->name == "ref") { + foreach($inreplyto->item(0)->attributes AS $attributes) { + if ($attributes->name == "ref") $item["parent-uri"] = $attributes->textContent; - } - if ($attributes->name == "href") { + if ($attributes->name == "href") $related = $attributes->textContent; - } } } @@ -408,10 +378,10 @@ class ostatus { $categories = $xpath->query('atom:category', $entry); if ($categories) { foreach ($categories AS $category) { - foreach ($category->attributes AS $attributes) + foreach($category->attributes AS $attributes) if ($attributes->name == "term") { $term = $attributes->textContent; - if (strlen($item["tag"])) + if(strlen($item["tag"])) $item["tag"] .= ','; $item["tag"] .= "#[url=".App::get_baseurl()."/search?tag=".$term."]".$term."[/url]"; } @@ -429,7 +399,7 @@ class ostatus { $length = "0"; $title = ""; foreach ($links AS $link) { - foreach ($link->attributes AS $attributes) { + foreach($link->attributes AS $attributes) { if ($attributes->name == "href") $href = $attributes->textContent; if ($attributes->name == "rel") @@ -441,7 +411,7 @@ class ostatus { if ($attributes->name == "title") $title = $attributes->textContent; } - if (($rel != "") AND ($href != "")) { + if (($rel != "") AND ($href != "")) switch($rel) { case "alternate": $item["plink"] = $href; @@ -454,7 +424,7 @@ class ostatus { break; case "enclosure": $enclosure = $href; - if (strlen($item["attach"])) + if(strlen($item["attach"])) $item["attach"] .= ','; $item["attach"] .= '[attach]href="'.$href.'" length="'.$length.'" type="'.$type.'" title="'.$title.'"[/attach]'; @@ -478,7 +448,6 @@ class ostatus { $mention = true; break; } - } } } @@ -487,16 +456,13 @@ class ostatus { $notice_info = $xpath->query('statusnet:notice_info', $entry); if ($notice_info AND ($notice_info->length > 0)) { - foreach ($notice_info->item(0)->attributes AS $attributes) { - if ($attributes->name == "source") { + foreach($notice_info->item(0)->attributes AS $attributes) { + if ($attributes->name == "source") $item["app"] = strip_tags($attributes->textContent); - } - if ($attributes->name == "local_id") { + if ($attributes->name == "local_id") $local_id = $attributes->textContent; - } - if ($attributes->name == "repeat_of") { + if ($attributes->name == "repeat_of") $repeat_of = $attributes->textContent; - } } } @@ -507,32 +473,24 @@ class ostatus { if (is_object($activityobjects)) { $orig_uri = $xpath->query("activity:object/atom:id", $activityobjects)->item(0)->nodeValue; - if (!isset($orig_uri)) { + if (!isset($orig_uri)) $orig_uri = $xpath->query('atom:id/text()', $activityobjects)->item(0)->nodeValue; - } $orig_links = $xpath->query("activity:object/atom:link[@rel='alternate']", $activityobjects); - if ($orig_links AND ($orig_links->length > 0)) { - foreach ($orig_links->item(0)->attributes AS $attributes) { - if ($attributes->name == "href") { + if ($orig_links AND ($orig_links->length > 0)) + foreach($orig_links->item(0)->attributes AS $attributes) + if ($attributes->name == "href") $orig_link = $attributes->textContent; - } - } - } - if (!isset($orig_link)) { + if (!isset($orig_link)) $orig_link = $xpath->query("atom:link[@rel='alternate']", $activityobjects)->item(0)->nodeValue; - } - if (!isset($orig_link)) { + if (!isset($orig_link)) $orig_link = self::convert_href($orig_uri); - } $orig_body = $xpath->query('activity:object/atom:content/text()', $activityobjects)->item(0)->nodeValue; - - if (!isset($orig_body)) { + if (!isset($orig_body)) $orig_body = $xpath->query('atom:content/text()', $activityobjects)->item(0)->nodeValue; - } $orig_created = $xpath->query('atom:published/text()', $activityobjects)->item(0)->nodeValue; $orig_edited = $xpath->query('atom:updated/text()', $activityobjects)->item(0)->nodeValue; @@ -553,10 +511,8 @@ class ostatus { $item["verb"] = $xpath->query('activity:verb/text()', $activityobjects)->item(0)->nodeValue; $item["object-type"] = $xpath->query('activity:object/activity:object-type/text()', $activityobjects)->item(0)->nodeValue; - - if (!isset($item["object-type"])) { + if (!isset($item["object-type"])) $item["object-type"] = $xpath->query('activity:object-type/text()', $activityobjects)->item(0)->nodeValue; - } } } @@ -584,14 +540,12 @@ class ostatus { intval($importer["uid"]), dbesc($item["parent-uri"])); } } - - if (dbm::is_result($r)) { + if ($r) { $item["type"] = 'remote-comment'; $item["gravity"] = GRAVITY_COMMENT; } - } else { + } else $item["parent-uri"] = $item["uri"]; - } $item_id = self::completion($conversation, $importer["uid"], $item, $self); @@ -614,26 +568,22 @@ class ostatus { public static function convert_href($href) { $elements = explode(":",$href); - if ((count($elements) <= 2) OR ($elements[0] != "tag")) { + if ((count($elements) <= 2) OR ($elements[0] != "tag")) return $href; - } $server = explode(",", $elements[1]); $conversation = explode("=", $elements[2]); - if ((count($elements) == 4) AND ($elements[2] == "post")) { + if ((count($elements) == 4) AND ($elements[2] == "post")) return "http://".$server[0]."/notice/".$elements[3]; - } - if ((count($conversation) != 2) OR ($conversation[1] =="")) { + if ((count($conversation) != 2) OR ($conversation[1] =="")) return $href; - } - if ($elements[3] == "objectType=thread") { + if ($elements[3] == "objectType=thread") return "http://".$server[0]."/conversation/".$conversation[1]; - } else { + else return "http://".$server[0]."/notice/".$conversation[1]; - } return $href; } @@ -706,53 +656,42 @@ class ostatus { * @brief Updates the gcontact table with actor data from the conversation * * @param object $actor The actor object that contains the contact data - * @todo Add type-hint */ private function conv_fetch_actor($actor) { // We set the generation to "3" since the data here is not as reliable as the data we get on other occasions $contact = array("network" => NETWORK_OSTATUS, "generation" => 3); - if (isset($actor->url)) { + if (isset($actor->url)) $contact["url"] = $actor->url; - } - if (isset($actor->displayName)) { + if (isset($actor->displayName)) $contact["name"] = $actor->displayName; - } - if (isset($actor->portablecontacts_net->displayName)) { + if (isset($actor->portablecontacts_net->displayName)) $contact["name"] = $actor->portablecontacts_net->displayName; - } - if (isset($actor->portablecontacts_net->preferredUsername)) { + if (isset($actor->portablecontacts_net->preferredUsername)) $contact["nick"] = $actor->portablecontacts_net->preferredUsername; - } - if (isset($actor->id)) { + if (isset($actor->id)) $contact["alias"] = $actor->id; - } - if (isset($actor->summary)) { + if (isset($actor->summary)) $contact["about"] = $actor->summary; - } - if (isset($actor->portablecontacts_net->note)) { + if (isset($actor->portablecontacts_net->note)) $contact["about"] = $actor->portablecontacts_net->note; - } - if (isset($actor->portablecontacts_net->addresses->formatted)) { + if (isset($actor->portablecontacts_net->addresses->formatted)) $contact["location"] = $actor->portablecontacts_net->addresses->formatted; - } - if (isset($actor->image->url)) { + if (isset($actor->image->url)) $contact["photo"] = $actor->image->url; - } - if (isset($actor->image->width)) { + if (isset($actor->image->width)) $avatarwidth = $actor->image->width; - } if (is_array($actor->status_net->avatarLinks)) foreach ($actor->status_net->avatarLinks AS $avatar) { @@ -779,26 +718,22 @@ class ostatus { if ($conversation_id != "") { $elements = explode(":", $conversation_id); - if ((count($elements) <= 2) OR ($elements[0] != "tag")) { + if ((count($elements) <= 2) OR ($elements[0] != "tag")) return $conversation_id; - } } - if ($self == "") { + if ($self == "") return ""; - } $json = str_replace(".atom", ".json", $self); $raw = fetch_url($json); - if ($raw == "") { + if ($raw == "") return ""; - } $data = json_decode($raw); - if (!is_object($data)) { + if (!is_object($data)) return ""; - } $conversation_id = $data->statusnet_conversation_id; @@ -824,12 +759,11 @@ class ostatus { $contact = q("SELECT `id`, `rel`, `network` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'", $uid, normalise_link($actor), NETWORK_STATUSNET); - if (!dbm::is_result($contact)) { + if (!$contact) $contact = q("SELECT `id`, `rel`, `network` FROM `contact` WHERE `uid` = %d AND `alias` IN ('%s', '%s') AND `network` != '%s'", $uid, $actor, normalise_link($actor), NETWORK_STATUSNET); - } - if (dbm::is_result($contact)) { + if ($contact) { logger("Found contact for url ".$actor, LOGGER_DEBUG); $details["contact_id"] = $contact[0]["id"]; $details["network"] = $contact[0]["network"]; @@ -861,7 +795,6 @@ class ostatus { * @param array $item Data of the item that is to be posted * * @return integer The item id of the posted item array - * @todo Add type-hints */ private function completion($conversation_url, $uid, $item = array(), $self = "") { @@ -894,9 +827,9 @@ class ostatus { (SELECT `oid` FROM `term` WHERE `uid` = %d AND `otype` = %d AND `type` = %d AND `url` = '%s'))", intval($uid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION), dbesc($conversation_url)); */ - if (dbm::is_result($parents)) { + if ($parents) $parent = $parents[0]; - } elseif (count($item) > 0) { + elseif (count($item) > 0) { $parent = $item; $parent["type"] = "remote"; $parent["verb"] = ACTIVITY_POST; @@ -904,11 +837,9 @@ class ostatus { } else { // Preset the parent $r = q("SELECT `id` FROM `contact` WHERE `self` AND `uid`=%d", $uid); - if (!dbm::is_result($r)) { + if (!$r) return(-2); - } - /// @TODO one statement is enough ... $parent = array(); $parent["id"] = 0; $parent["parent"] = 0; @@ -935,24 +866,20 @@ class ostatus { } elseif (!$conv_arr["success"] AND (substr($conv, 0, 8) == "https://")) { $conv = str_replace("https://", "http://", $conv); $conv_as = fetch_url($conv."?page=".$pageno); - } else { + } else $conv_as = $conv_arr["body"]; - } $conv_as = str_replace(',"statusnet:notice_info":', ',"statusnet_notice_info":', $conv_as); $conv_as = json_decode($conv_as); $no_of_items = sizeof($items); - if (is_array($conv_as->items)) { - foreach ($conv_as->items AS $single_item) { + if (@is_array($conv_as->items)) + foreach ($conv_as->items AS $single_item) $items[$single_item->id] = $single_item; - } - } - if ($no_of_items == sizeof($items)) { + if ($no_of_items == sizeof($items)) break; - } $pageno++; @@ -970,20 +897,13 @@ class ostatus { } return($item_stored); - } else { + } else return(-3); - } } $items = array_reverse($items); $r = q("SELECT `nurl` FROM `contact` WHERE `uid` = %d AND `self`", intval($uid)); - - if (!dbm::is_result($r)) { - logger("Failed query, uid=" . intval($uid) ." in " . __FUNCTION__); - killme(); - } - $importer = $r[0]; $new_parent = true; @@ -999,18 +919,15 @@ class ostatus { $mention = false; - if (isset($single_conv->object->id)) { + if (isset($single_conv->object->id)) $single_conv->id = $single_conv->object->id; - } $plink = self::convert_href($single_conv->id); - if (isset($single_conv->object->url)) { + if (isset($single_conv->object->url)) $plink = self::convert_href($single_conv->object->url); - } - if (!isset($single_conv->id)) { + if (@!$single_conv->id) continue; - } logger("Got id ".$single_conv->id, LOGGER_DEBUG); @@ -1029,7 +946,7 @@ class ostatus { (SELECT `parent` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s')) LIMIT 1", intval($uid), dbesc($first_id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); - if (dbm::is_result($new_parents)) { + if ($new_parents) { if ($new_parents[0]["parent"] == $parent["parent"]) { // Option 2: This post is already present inside our thread - but not as thread starter logger("Option 2: uri present in our thread: ".$first_id, LOGGER_DEBUG); @@ -1060,18 +977,16 @@ class ostatus { if (isset($single_conv->context->inReplyTo->id)) { $parent_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", intval($uid), dbesc($single_conv->context->inReplyTo->id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); - if (dbm::is_result($parent_exists)) { + if ($parent_exists) $parent_uri = $single_conv->context->inReplyTo->id; - } } // This is the current way if (isset($single_conv->object->inReplyTo->id)) { $parent_exists = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", intval($uid), dbesc($single_conv->object->inReplyTo->id), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DFRN)); - if (dbm::is_result($parent_exists)) { + if ($parent_exists) $parent_uri = $single_conv->object->inReplyTo->id; - } } $message_exists = q("SELECT `id`, `parent`, `uri` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s') LIMIT 1", @@ -1118,18 +1033,14 @@ class ostatus { continue; } - if (is_array($single_conv->to)) { - foreach ($single_conv->to AS $to) { - if ($importer["nurl"] == normalise_link($to->id)) { + if (is_array($single_conv->to)) + foreach($single_conv->to AS $to) + if ($importer["nurl"] == normalise_link($to->id)) $mention = true; - } - } - } $actor = $single_conv->actor->id; - if (isset($single_conv->actor->url)) { + if (isset($single_conv->actor->url)) $actor = $single_conv->actor->url; - } $details = self::get_actor_details($actor, $uid, $parent["contact-id"]); @@ -1139,7 +1050,6 @@ class ostatus { continue; } - /// @TODO One statment is okay (until if () ) $arr = array(); $arr["network"] = $details["network"]; $arr["uri"] = $single_conv->id; @@ -1150,13 +1060,10 @@ class ostatus { $arr["created"] = $single_conv->published; $arr["edited"] = $single_conv->published; $arr["owner-name"] = $single_conv->actor->displayName; - - if ($arr["owner-name"] == '') { + if ($arr["owner-name"] == '') $arr["owner-name"] = $single_conv->actor->contact->displayName; - } - if ($arr["owner-name"] == '') { + if ($arr["owner-name"] == '') $arr["owner-name"] = $single_conv->actor->portablecontacts_net->displayName; - } $arr["owner-link"] = $actor; $arr["owner-avatar"] = $single_conv->actor->image->url; @@ -1165,17 +1072,17 @@ class ostatus { $arr["author-avatar"] = $single_conv->actor->image->url; $arr["body"] = add_page_info_to_body(html2bbcode($single_conv->content)); - if (isset($single_conv->status_net->notice_info->source)) { + if (isset($single_conv->status_net->notice_info->source)) $arr["app"] = strip_tags($single_conv->status_net->notice_info->source); - } elseif (isset($single_conv->statusnet->notice_info->source)) { + elseif (isset($single_conv->statusnet->notice_info->source)) $arr["app"] = strip_tags($single_conv->statusnet->notice_info->source); - } elseif (isset($single_conv->statusnet_notice_info->source)) { + elseif (isset($single_conv->statusnet_notice_info->source)) $arr["app"] = strip_tags($single_conv->statusnet_notice_info->source); - } elseif (isset($single_conv->provider->displayName)) { + elseif (isset($single_conv->provider->displayName)) $arr["app"] = $single_conv->provider->displayName; - } else { + else $arr["app"] = "OStatus"; - } + $arr["object"] = json_encode($single_conv); $arr["verb"] = $parent["verb"]; @@ -1185,31 +1092,27 @@ class ostatus { // Is it a reshared item? if (isset($single_conv->verb) AND ($single_conv->verb == "share") AND isset($single_conv->object)) { - if (is_array($single_conv->object)) { + if (is_array($single_conv->object)) $single_conv->object = $single_conv->object[0]; - } logger("Found reshared item ".$single_conv->object->id); // $single_conv->object->context->conversation; - if (isset($single_conv->object->object->id)) { + if (isset($single_conv->object->object->id)) $arr["uri"] = $single_conv->object->object->id; - } else { + else $arr["uri"] = $single_conv->object->id; - } - if (isset($single_conv->object->object->url)) { + if (isset($single_conv->object->object->url)) $plink = self::convert_href($single_conv->object->object->url); - } else { + else $plink = self::convert_href($single_conv->object->url); - } - if (isset($single_conv->object->object->content)) { + if (isset($single_conv->object->object->content)) $arr["body"] = add_page_info_to_body(html2bbcode($single_conv->object->object->content)); - } else { + else $arr["body"] = add_page_info_to_body(html2bbcode($single_conv->object->content)); - } $arr["plink"] = $plink; @@ -1217,9 +1120,8 @@ class ostatus { $arr["edited"] = $single_conv->object->published; $arr["author-name"] = $single_conv->object->actor->displayName; - if ($arr["owner-name"] == '') { + if ($arr["owner-name"] == '') $arr["author-name"] = $single_conv->object->actor->contact->displayName; - } $arr["author-link"] = $single_conv->object->actor->url; $arr["author-avatar"] = $single_conv->object->actor->image->url; @@ -1231,24 +1133,20 @@ class ostatus { $arr["coord"] = trim($single_conv->object->location->lat." ".$single_conv->object->location->lon); } - if ($arr["location"] == "") { + if ($arr["location"] == "") unset($arr["location"]); - } - if ($arr["coord"] == "") { + if ($arr["coord"] == "") unset($arr["coord"]); - } // Copy fields from given item array if (isset($item["uri"]) AND (($item["uri"] == $arr["uri"]) OR ($item["uri"] == $single_conv->id))) { $copy_fields = array("owner-name", "owner-link", "owner-avatar", "author-name", "author-link", "author-avatar", "gravity", "body", "object-type", "object", "verb", "created", "edited", "coord", "tag", "title", "attach", "app", "type", "location", "contact-id", "uri"); - foreach ($copy_fields AS $field) { - if (isset($item[$field])) { + foreach ($copy_fields AS $field) + if (isset($item[$field])) $arr[$field] = $item[$field]; - } - } } @@ -1274,9 +1172,8 @@ class ostatus { logger('setting new parent to id '.$newitem); $new_parents = q("SELECT `id`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($uid), intval($newitem)); - if (dbm::is_result($new_parents)) { + if ($new_parents) $parent = $new_parents[0]; - } } } @@ -1311,18 +1208,15 @@ class ostatus { $conversation_url = self::convert_href($conversation_url); $messages = q("SELECT `uid`, `parent`, `created`, `received`, `guid` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); - - if (!dbm::is_result($messages)) { + if (!$messages) return; - } - $message = $messages[0]; // Store conversation url if not done before $conversation = q("SELECT `url` FROM `term` WHERE `uid` = %d AND `oid` = %d AND `otype` = %d AND `type` = %d", intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION)); - if (!dbm::is_result($conversation)) { + if (!$conversation) { $r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`, `url`, `created`, `received`, `guid`) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION), dbesc($message["created"]), dbesc($conversation_url), dbesc($message["created"]), dbesc($message["received"]), dbesc($message["guid"])); @@ -1336,38 +1230,32 @@ class ostatus { * @param array $item The item array of thw post * * @return string The guid if the post is a reshare - * @todo Add type-hints */ private function get_reshared_guid($item) { $body = trim($item["body"]); // Skip if it isn't a pure repeated messages // Does it start with a share? - if (strpos($body, "[share") > 0) { + if (strpos($body, "[share") > 0) return(""); - } // Does it end with a share? - if (strlen($body) > (strrpos($body, "[/share]") + 8)) { + if (strlen($body) > (strrpos($body, "[/share]") + 8)) return(""); - } $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body); // Skip if there is no shared message in there - if ($body == $attributes) { + if ($body == $attributes) return(false); - } $guid = ""; preg_match("/guid='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") { + if ($matches[1] != "") $guid = $matches[1]; - } preg_match('/guid="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") { + if ($matches[1] != "") $guid = $matches[1]; - } return $guid; } @@ -1383,11 +1271,10 @@ class ostatus { $siteinfo = get_attached_data($body); if (($siteinfo["type"] == "photo")) { - if (isset($siteinfo["preview"])) { + if (isset($siteinfo["preview"])) $preview = $siteinfo["preview"]; - } else { + else $preview = $siteinfo["image"]; - } // Is it a remote picture? Then make a smaller preview here $preview = proxy_url($preview, false, PROXY_SIZE_SMALL); @@ -1396,11 +1283,10 @@ class ostatus { $preview = str_replace(array("-0.jpg", "-0.png"), array("-2.jpg", "-2.png"), $preview); $preview = str_replace(array("-1.jpg", "-1.png"), array("-2.jpg", "-2.png"), $preview); - if (isset($siteinfo["url"])) { + if (isset($siteinfo["url"])) $url = $siteinfo["url"]; - } else { + else $url = $siteinfo["image"]; - } $body = trim($siteinfo["text"])." [url]".$url."[/url]\n[img]".$preview."[/img]"; } @@ -1415,7 +1301,6 @@ class ostatus { * @param array $owner Contact data of the poster * * @return object header root element - * @todo Add type-hints */ private function add_header($doc, $owner) { @@ -1475,23 +1360,20 @@ class ostatus { * * @param object $doc XML document * @param object $root XML root element where the hub links are added - * @todo Add type-hints */ public static function hublinks($doc, $root) { $hub = get_config('system','huburl'); $hubxml = ''; - if (strlen($hub)) { + if(strlen($hub)) { $hubs = explode(',', $hub); - if (count($hubs)) { - foreach ($hubs as $h) { + if(count($hubs)) { + foreach($hubs as $h) { $h = trim($h); - if (! strlen($h)) { + if(! strlen($h)) continue; - } - if ($h === '[internal]') { + if ($h === '[internal]') $h = App::get_baseurl() . '/pubsubhubbub'; - } xml::add_element($doc, $root, "link", "", array("href" => $h, "rel" => "hub")); } } @@ -1504,7 +1386,6 @@ class ostatus { * @param object $doc XML document * @param object $root XML root element where the hub links are added * @param array $item Data of the item that is to be posted - * @todo Add type-hints */ private function get_attachment($doc, $root, $item) { $o = ""; @@ -1548,22 +1429,20 @@ class ostatus { $arr = explode('[/attach],',$item['attach']); - if (count($arr)) { - foreach ($arr as $r) { + if(count($arr)) { + foreach($arr as $r) { $matches = false; $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches); - if ($cnt) { + if($cnt) { $attributes = array("rel" => "enclosure", "href" => $matches[1], "type" => $matches[3]); - if (intval($matches[2])) { + if(intval($matches[2])) $attributes["length"] = intval($matches[2]); - } - if (trim($matches[4]) != "") { + if(trim($matches[4]) != "") $attributes["title"] = trim($matches[4]); - } xml::add_element($doc, $root, "link", "", $attributes); } @@ -1578,15 +1457,12 @@ class ostatus { * @param array $owner Contact data of the poster * * @return object author element - * @todo Add type-hints */ private function add_author($doc, $owner) { - $profile = null; $r = q("SELECT `homepage` FROM `profile` WHERE `uid` = %d AND `is-default` LIMIT 1", intval($owner["uid"])); - if (dbm::is_result($r)) { + if ($r) $profile = $r[0]; - } $author = $doc->createElement("author"); xml::add_element($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON); @@ -1654,12 +1530,10 @@ class ostatus { * @param array $item Data of the item that is to be posted * * @return string activity - * @todo Add type-hints */ function construct_verb($item) { - if ($item['verb']) { + if ($item['verb']) return $item['verb']; - } return ACTIVITY_POST; } @@ -1669,12 +1543,10 @@ class ostatus { * @param array $item Data of the item that is to be posted * * @return string Object type - * @todo Add type-hints */ function construct_objecttype($item) { - if (in_array($item['object-type'], array(ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT))) { + if (in_array($item['object-type'], array(ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT))) return $item['object-type']; - }; return ACTIVITY_OBJ_NOTE; } @@ -1712,7 +1584,6 @@ class ostatus { * @param array $contact Array of the contact that is added * * @return object Source element - * @todo Add type-hints */ private function source_entry($doc, $contact) { $source = $doc->createElement("source"); @@ -1737,41 +1608,39 @@ class ostatus { * @param array $owner Contact data of the poster * * @return array Contact array - * @todo Add array type-hint for $owner */ private function contact_entry($url, $owner) { $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` IN (0, %d) ORDER BY `uid` DESC LIMIT 1", dbesc(normalise_link($url)), intval($owner["uid"])); - if (dbm::is_result($r)) { + if ($r) { $contact = $r[0]; $contact["uid"] = -1; - } else { + } + + if (!$r) { $r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1", dbesc(normalise_link($url))); - if (dbm::is_result($r)) { + if ($r) { $contact = $r[0]; $contact["uid"] = -1; $contact["success_update"] = $contact["updated"]; } } - if (!dbm::is_result($r)) { - $contact = $owner; - } + if (!$r) + $contact = owner; if (!isset($contact["poll"])) { $data = probe_url($url); $contact["poll"] = $data["poll"]; - if (!$contact["alias"]) { + if (!$contact["alias"]) $contact["alias"] = $data["alias"]; - } } - if (!isset($contact["alias"])) { + if (!isset($contact["alias"])) $contact["alias"] = $contact["url"]; - } return $contact; } @@ -1786,7 +1655,6 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return object Entry element - * @todo Add type-hints */ private function reshare_entry($doc, $item, $owner, $repeated_guid, $toplevel) { @@ -1799,12 +1667,10 @@ class ostatus { $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' AND NOT `private` AND `network` IN ('%s', '%s', '%s') LIMIT 1", intval($owner["uid"]), dbesc($repeated_guid), dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS)); - - if (!dbm::is_result($r)) { + if ($r) + $repeated_item = $r[0]; + else return false; - } - - $repeated_item = $r[0]; $contact = self::contact_entry($repeated_item['author-link'], $owner); @@ -1855,7 +1721,6 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return object Entry element with "like" - * @todo Add type-hints */ private function like_entry($doc, $item, $owner, $toplevel) { @@ -1893,7 +1758,6 @@ class ostatus { * @param array $contact Contact data of the target * * @return object author element - * @todo Add type-hints */ private function add_person_object($doc, $owner, $contact) { @@ -1940,7 +1804,6 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return object Entry element - * @todo Add type-hints */ private function follow_entry($doc, $item, $owner, $toplevel) { @@ -2003,7 +1866,6 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return object Entry element - * @todo Add type-hints */ private function note_entry($doc, $item, $owner, $toplevel) { @@ -2031,7 +1893,6 @@ class ostatus { * @param bool $toplevel Is it for en entry element (false) or a feed entry (true)? * * @return string The title for the element - * @todo Add type-hints */ private function entry_header($doc, &$entry, $owner, $toplevel) { /// @todo Check if this title stuff is really needed (I guess not) @@ -2067,22 +1928,19 @@ class ostatus { * @param string $title Title for the post * @param string $verb The activity verb * @param bool $complete Add the "status_net" element? - * @todo Add type-hints */ private function entry_content($doc, $entry, $item, $owner, $title, $verb = "", $complete = true) { - if ($verb == "") { + if ($verb == "") $verb = self::construct_verb($item); - } xml::add_element($doc, $entry, "id", $item["uri"]); xml::add_element($doc, $entry, "title", $title); $body = self::format_picture_post($item['body']); - if ($item['title'] != "") { + if ($item['title'] != "") $body = "[b]".$item['title']."[/b]\n\n".$body; - } $body = bbcode($body, false, false, 7); @@ -2108,7 +1966,6 @@ class ostatus { * @param array $item Data of the item that is to be posted * @param array $owner Contact data of the poster * @param $complete - * @todo Add type-hints */ private function entry_footer($doc, $entry, $item, $owner, $complete = true) { @@ -2135,7 +1992,7 @@ class ostatus { $thrparent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `uid` = %d AND `uri` = '%s'", intval($owner["uid"]), dbesc($parent_item)); - if (dbm::is_result($thrparent)) { + if ($thrparent) { $mentioned[$thrparent[0]["author-link"]] = $thrparent[0]["author-link"]; $mentioned[$thrparent[0]["owner-link"]] = $thrparent[0]["owner-link"]; } @@ -2149,13 +2006,10 @@ class ostatus { $tags = item_getfeedtags($item); - if (count($tags)) { - foreach ($tags as $t) { - if ($t[0] == "@") { + if(count($tags)) + foreach($tags as $t) + if ($t[0] == "@") $mentioned[$t[1]] = $t[1]; - } - } - } // Make sure that mentions are accepted (GNU Social has problems with mixing HTTP and HTTPS) $newmentions = array(); @@ -2169,15 +2023,14 @@ class ostatus { $r = q("SELECT `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'", intval($owner["uid"]), dbesc(normalise_link($mention))); - if ($r[0]["forum"] OR $r[0]["prv"]) { + if ($r[0]["forum"] OR $r[0]["prv"]) xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_GROUP, "href" => $mention)); - } else { + else xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_PERSON, "href" => $mention)); - } } if (!$item["private"]) { @@ -2188,13 +2041,10 @@ class ostatus { "href" => "http://activityschema.org/collection/public")); } - if (count($tags)) { - foreach ($tags as $t) { - if ($t[0] != "@") { + if(count($tags)) + foreach($tags as $t) + if ($t[0] != "@") xml::add_element($doc, $entry, "category", "", array("term" => $t[2])); - } - } - } self::get_attachment($doc, $entry, $item); @@ -2235,7 +2085,7 @@ class ostatus { $owner = $r[0]; - if (!strlen($last_update)) + if(!strlen($last_update)) $last_update = 'now -30 days'; $check_date = datetime_convert('UTC','UTC',$last_update,'Y-m-d H:i:s'); diff --git a/include/pgettext.php b/include/pgettext.php index 79b341c0d..335869eda 100644 --- a/include/pgettext.php +++ b/include/pgettext.php @@ -14,7 +14,7 @@ use \Friendica\Core\Config; require_once("include/dba.php"); -if (! function_exists('get_browser_language')) { +if(! function_exists('get_browser_language')) { /** * @brief get the prefered language from the HTTP_ACCEPT_LANGUAGE header */ @@ -44,7 +44,7 @@ function get_browser_language() { // check if we have translations for the preferred languages and pick the 1st that has for ($i=0; $ilangsave = $lang; - if ($language === $lang) + if($language === $lang) return; - if (isset($a->strings) && count($a->strings)) { + if(isset($a->strings) && count($a->strings)) { $a->stringsave = $a->strings; } $a->strings = array(); @@ -77,10 +77,10 @@ function push_lang($language) { function pop_lang() { global $lang, $a; - if ($lang === $a->langsave) + if($lang === $a->langsave) return; - if (isset($a->stringsave)) + if(isset($a->stringsave)) $a->strings = $a->stringsave; else $a->strings = array(); @@ -91,7 +91,7 @@ function pop_lang() { // l -if (! function_exists('load_translation_table')) { +if(! function_exists('load_translation_table')) { /** * load string translation table for alternate language * @@ -106,15 +106,15 @@ function load_translation_table($lang) { // load enabled plugins strings $plugins = q("SELECT name FROM addon WHERE installed=1;"); if ($plugins!==false) { - foreach ($plugins as $p) { + foreach($plugins as $p) { $name = $p['name']; - if (file_exists("addon/$name/lang/$lang/strings.php")) { + if(file_exists("addon/$name/lang/$lang/strings.php")) { include("addon/$name/lang/$lang/strings.php"); } } } - if (file_exists("view/lang/$lang/strings.php")) { + if(file_exists("view/lang/$lang/strings.php")) { include("view/lang/$lang/strings.php"); } @@ -122,27 +122,27 @@ function load_translation_table($lang) { // translate string if translation exists -if (! function_exists('t')) { +if(! function_exists('t')) { function t($s) { $a = get_app(); - if (x($a->strings,$s)) { + if(x($a->strings,$s)) { $t = $a->strings[$s]; return is_array($t)?$t[0]:$t; } return $s; }} -if (! function_exists('tt')){ +if(! function_exists('tt')){ function tt($singular, $plural, $count){ global $lang; $a = get_app(); - if (x($a->strings,$singular)) { + if(x($a->strings,$singular)) { $t = $a->strings[$singular]; $f = 'string_plural_select_' . str_replace('-','_',$lang); - if (! function_exists($f)) + if(! function_exists($f)) $f = 'string_plural_select_default'; $k = $f($count); return is_array($t)?$t[$k]:$t; @@ -158,7 +158,7 @@ function tt($singular, $plural, $count){ // provide a fallback which will not collide with // a function defined in any language file -if (! function_exists('string_plural_select_default')) { +if(! function_exists('string_plural_select_default')) { function string_plural_select_default($n) { return ($n != 1); }} @@ -185,7 +185,7 @@ function get_available_languages() { $strings_file_paths[] = 'view/lang/en/strings.php'; } asort($strings_file_paths); - foreach ($strings_file_paths as $strings_file_path) { + foreach($strings_file_paths as $strings_file_path) { $path_array = explode('/', $strings_file_path); $langs[$path_array[2]] = $path_array[2]; } diff --git a/include/plugin.php b/include/plugin.php index c5364822e..83f6f1ab9 100644 --- a/include/plugin.php +++ b/include/plugin.php @@ -20,7 +20,7 @@ function uninstall_plugin($plugin){ ); @include_once('addon/' . $plugin . '/' . $plugin . '.php'); - if (function_exists($plugin . '_uninstall')) { + if(function_exists($plugin . '_uninstall')) { $func = $plugin . '_uninstall'; $func(); } @@ -36,12 +36,12 @@ if (! function_exists('install_plugin')){ function install_plugin($plugin) { // silently fail if plugin was removed - if (! file_exists('addon/' . $plugin . '/' . $plugin . '.php')) + if(! file_exists('addon/' . $plugin . '/' . $plugin . '.php')) return false; logger("Addons: installing " . $plugin); $t = @filemtime('addon/' . $plugin . '/' . $plugin . '.php'); @include_once('addon/' . $plugin . '/' . $plugin . '.php'); - if (function_exists($plugin . '_install')) { + if(function_exists($plugin . '_install')) { $func = $plugin . '_install'; $func(); @@ -57,7 +57,7 @@ function install_plugin($plugin) { // once most site tables have been updated. // This way the system won't fall over dead during the update. - if (file_exists('addon/' . $plugin . '/.hidden')) { + if(file_exists('addon/' . $plugin . '/.hidden')) { q("UPDATE `addon` SET `hidden` = 1 WHERE `name` = '%s'", dbesc($plugin) ); @@ -73,10 +73,10 @@ function install_plugin($plugin) { // reload all updated plugins -if (! function_exists('reload_plugins')) { +if(! function_exists('reload_plugins')) { function reload_plugins() { $plugins = get_config('system','addon'); - if (strlen($plugins)) { + if(strlen($plugins)) { $r = q("SELECT * FROM `addon` WHERE `installed` = 1"); if (dbm::is_result($r)) @@ -86,25 +86,25 @@ function reload_plugins() { $parr = explode(',',$plugins); - if (count($parr)) { - foreach ($parr as $pl) { + if(count($parr)) { + foreach($parr as $pl) { $pl = trim($pl); $fname = 'addon/' . $pl . '/' . $pl . '.php'; - if (file_exists($fname)) { + if(file_exists($fname)) { $t = @filemtime($fname); - foreach ($installed as $i) { - if (($i['name'] == $pl) && ($i['timestamp'] != $t)) { + foreach($installed as $i) { + if(($i['name'] == $pl) && ($i['timestamp'] != $t)) { logger('Reloading plugin: ' . $i['name']); @include_once($fname); - if (function_exists($pl . '_uninstall')) { + if(function_exists($pl . '_uninstall')) { $func = $pl . '_uninstall'; $func(); } - if (function_exists($pl . '_install')) { + if(function_exists($pl . '_install')) { $func = $pl . '_install'; $func(); } @@ -142,7 +142,7 @@ function plugin_enabled($plugin) { * @param int $priority A priority (defaults to 0) * @return mixed|bool */ -if (! function_exists('register_hook')) { +if(! function_exists('register_hook')) { function register_hook($hook,$file,$function,$priority=0) { $r = q("SELECT * FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s' LIMIT 1", @@ -170,7 +170,7 @@ function register_hook($hook,$file,$function,$priority=0) { * @param string $function the name of the function that the hook called * @return array */ -if (! function_exists('unregister_hook')) { +if(! function_exists('unregister_hook')) { function unregister_hook($hook,$file,$function) { $r = q("DELETE FROM `hook` WHERE `hook` = '%s' AND `file` = '%s' AND `function` = '%s'", @@ -182,7 +182,7 @@ function unregister_hook($hook,$file,$function) { }} -if (! function_exists('load_hooks')) { +if(! function_exists('load_hooks')) { function load_hooks() { $a = get_app(); $a->hooks = array(); @@ -190,7 +190,7 @@ function load_hooks() { if (dbm::is_result($r)) { foreach ($r as $rr) { - if (! array_key_exists($rr['hook'],$a->hooks)) + if(! array_key_exists($rr['hook'],$a->hooks)) $a->hooks[$rr['hook']] = array(); $a->hooks[$rr['hook']][] = array($rr['file'],$rr['function']); } @@ -244,13 +244,13 @@ function call_single_hook($a, $name, $hook, &$data = null) { //check if an app_menu hook exist for plugin $name. //Return true if the plugin is an app -if (! function_exists('plugin_is_app')) { +if(! function_exists('plugin_is_app')) { function plugin_is_app($name) { $a = get_app(); - if (is_array($a->hooks) && (array_key_exists('app_menu',$a->hooks))) { - foreach ($a->hooks['app_menu'] as $hook) { - if ($hook[0] == 'addon/'.$name.'/'.$name.'.php') + if(is_array($a->hooks) && (array_key_exists('app_menu',$a->hooks))) { + foreach($a->hooks['app_menu'] as $hook) { + if($hook[0] == 'addon/'.$name.'/'.$name.'.php') return true; } } @@ -297,7 +297,7 @@ function get_plugin_info($plugin){ if ($r){ $ll = explode("\n", $m[0]); - foreach ( $ll as $l ) { + foreach( $ll as $l ) { $l = trim($l,"\t\n\r */"); if ($l!=""){ list($k,$v) = array_map("trim", explode(":",$l,2)); @@ -352,9 +352,9 @@ function get_theme_info($theme){ 'unsupported' => false ); - if (file_exists("view/theme/$theme/experimental")) + if(file_exists("view/theme/$theme/experimental")) $info['experimental'] = true; - if (file_exists("view/theme/$theme/unsupported")) + if(file_exists("view/theme/$theme/unsupported")) $info['unsupported'] = true; if (!is_file("view/theme/$theme/theme.php")) return $info; @@ -368,7 +368,7 @@ function get_theme_info($theme){ if ($r){ $ll = explode("\n", $m[0]); - foreach ( $ll as $l ) { + foreach( $ll as $l ) { $l = trim($l,"\t\n\r */"); if ($l!=""){ list($k,$v) = array_map("trim", explode(":",$l,2)); @@ -412,7 +412,7 @@ function get_theme_info($theme){ */ function get_theme_screenshot($theme) { $exts = array('.png','.jpg'); - foreach ($exts as $ext) { + foreach($exts as $ext) { if (file_exists('view/theme/' . $theme . '/screenshot' . $ext)) { return(App::get_baseurl() . '/view/theme/' . $theme . '/screenshot' . $ext); } @@ -511,11 +511,11 @@ function service_class_fetch($uid,$property) { $service_class = $r[0]['service_class']; } } - if (! x($service_class)) + if(! x($service_class)) return false; // everything is allowed $arr = get_config('service_class',$service_class); - if (! is_array($arr) || (! count($arr))) + if(! is_array($arr) || (! count($arr))) return false; return((array_key_exists($property,$arr)) ? $arr[$property] : false); @@ -524,14 +524,12 @@ function service_class_fetch($uid,$property) { function upgrade_link($bbcode = false) { $l = get_config('service_class','upgrade_link'); - if (! $l) { + if(! $l) return ''; - } - if ($bbcode) { + if($bbcode) $t = sprintf('[url=%s]' . t('Click here to upgrade.') . '[/url]', $l); - } else { + else $t = sprintf('' . t('Click here to upgrade.') . '
', $l); - } return $t; } @@ -558,15 +556,13 @@ function upgrade_bool_message($bbcode = false) { */ function theme_include($file, $root = '') { // 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 . '/'; - } $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']; - } else { + else $parent = 'NOPATH'; - } $theme = current_theme(); $thname = $theme; $ext = substr($file,strrpos($file,'.')+1); @@ -575,13 +571,12 @@ function theme_include($file, $root = '') { "{$root}view/theme/$parent/$ext/$file", "{$root}view/$ext/$file", ); - 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) - if (strpos($p,'NOPATH') !== false) { + if(strpos($p,'NOPATH') !== false) continue; - } elseif (file_exists($p)) { + if(file_exists($p)) return $p; - } } return ''; } diff --git a/include/poller.php b/include/poller.php index 27f8c7831..5560b3340 100644 --- a/include/poller.php +++ b/include/poller.php @@ -17,11 +17,11 @@ require_once("boot.php"); function poller_run($argv, $argc){ global $a, $db; - if (is_null($a)) { + if(is_null($a)) { $a = new App; } - if (is_null($db)) { + if(is_null($db)) { @include(".htconfig.php"); require_once("include/dba.php"); $db = new dba($db_host, $db_user, $db_pass, $db_data); @@ -49,7 +49,7 @@ function poller_run($argv, $argc){ return; } - if (($argc <= 1) OR ($argv[1] != "no_cron")) { + if(($argc <= 1) OR ($argv[1] != "no_cron")) { poller_run_cron(); } @@ -364,7 +364,7 @@ function poller_kill_stale_workers() { return; } - foreach ($r AS $pid) + foreach ($r AS $pid) { if (!posix_kill($pid["pid"], 0)) { q("UPDATE `workerqueue` SET `executed` = '%s', `pid` = 0 WHERE `pid` = %d", dbesc(NULL_DATE), intval($pid["pid"])); @@ -372,9 +372,8 @@ function poller_kill_stale_workers() { // Kill long running processes // Check if the priority is in a valid range - if (!in_array($pid["priority"], array(PRIORITY_CRITICAL, PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORITY_LOW, PRIORITY_NEGLIGIBLE))) { + if (!in_array($pid["priority"], array(PRIORITY_CRITICAL, PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORITY_LOW, PRIORITY_NEGLIGIBLE))) $pid["priority"] = PRIORITY_MEDIUM; - } // Define the maximum durations $max_duration_defaults = array(PRIORITY_CRITICAL => 360, PRIORITY_HIGH => 10, PRIORITY_MEDIUM => 60, PRIORITY_LOW => 180, PRIORITY_NEGLIGIBLE => 360); @@ -419,7 +418,7 @@ function poller_too_much_workers() { // Decrease the number of workers at higher load $load = current_load(); - if ($load) { + if($load) { $maxsysload = intval(Config::get("system", "maxloadavg", 50)); $maxworkers = $queues; diff --git a/include/post_update.php b/include/post_update.php index 45bcb16d3..f9649961d 100644 --- a/include/post_update.php +++ b/include/post_update.php @@ -68,7 +68,7 @@ function post_update_1192() { } // Set the "gcontact-id" in the item table and add a new gcontact entry if needed - foreach ($item_arr AS $item) { + foreach($item_arr AS $item) { $gcontact_id = get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'], "photo" => $item['author-avatar'], "name" => $item['author-name'])); q("UPDATE `item` SET `gcontact-id` = %d WHERE `uid` = %d AND `author-link` = '%s' AND `gcontact-id` = 0", @@ -204,7 +204,7 @@ function post_update_1198() { } // Set the "gcontact-id" in the item table and add a new gcontact entry if needed - foreach ($item_arr AS $item) { + foreach($item_arr AS $item) { $author_id = get_contact($item["author-link"], 0); $owner_id = get_contact($item["owner-link"], 0); diff --git a/include/profile_selectors.php b/include/profile_selectors.php index af6c0d96c..8d29fd099 100644 --- a/include/profile_selectors.php +++ b/include/profile_selectors.php @@ -8,8 +8,8 @@ function gender_selector($current="",$suffix="") { call_hooks('gender_selector', $select); $o .= ""; - foreach ($select as $selection) { - if ($selection !== 'NOTRANSLATION') { + foreach($select as $selection) { + if($selection !== 'NOTRANSLATION') { $selected = (($selection == $current) ? ' selected="selected" ' : ''); $o .= ""; } @@ -44,8 +44,8 @@ function marital_selector($current="",$suffix="") { call_hooks('marital_selector', $select); $o .= " ' . t("Post to Email") . ''; diff --git a/mod/events.php b/mod/events.php index 19078ab26..60e7b9f39 100644 --- a/mod/events.php +++ b/mod/events.php @@ -112,7 +112,7 @@ function events_post(App $a) { $c = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval(local_user()) ); - if (dbm::is_result($c)) { + if (count($c)) { $self = $c[0]['id']; } else { $self = 0; @@ -126,7 +126,7 @@ function events_post(App $a) { $str_contact_deny = perms2str($_POST['contact_deny']); // Undo the pseudo-contact of self, since there are real contacts now - if (strpos($str_contact_allow, '<' . $self . '>') !== false) { + if (strpos($str_contact_allow, '<' . $self . '>') !== false ) { $str_contact_allow = str_replace('<' . $self . '>', '', $str_contact_allow); } // Make sure to set the `private` field as true. This is necessary to @@ -142,7 +142,7 @@ function events_post(App $a) { $str_group_allow = $str_contact_deny = $str_group_deny = ''; } - /// @TODO One-time array initialization, one large block + $datarray = array(); $datarray['guid'] = get_guid(32); $datarray['start'] = $start; @@ -407,9 +407,7 @@ function events_content(App $a) { // Passed parameters overrides anything found in the DB if ($mode === 'edit' || $mode === 'new') { - if (!x($orig_event)) { - $orig_event = array(); - } + if (!x($orig_event)) {$orig_event = array();} // In case of an error the browser is redirected back here, with these parameters filled in with the previous values if (x($_REQUEST, 'nofinish')) {$orig_event['nofinish'] = $_REQUEST['nofinish'];} if (x($_REQUEST, 'adjust')) {$orig_event['adjust'] = $_REQUEST['adjust'];} diff --git a/mod/fbrowser.php b/mod/fbrowser.php index ae62ce9a3..9a0e9244c 100644 --- a/mod/fbrowser.php +++ b/mod/fbrowser.php @@ -66,9 +66,10 @@ function fbrowser_content(App $a) { $types = Photo::supportedTypes(); $ext = $types[$rr['type']]; - if ($a->theme['template_engine'] === 'internal') { + if($a->theme['template_engine'] === 'internal') { $filename_e = template_escape($rr['filename']); - } else { + } + else { $filename_e = $rr['filename']; } diff --git a/mod/filer.php b/mod/filer.php index d2df7f24c..47c4aa5e4 100644 --- a/mod/filer.php +++ b/mod/filer.php @@ -16,7 +16,7 @@ function filer_content(App $a) { logger('filer: tag ' . $term . ' item ' . $item_id); - if ($item_id && strlen($term)){ + if($item_id && strlen($term)){ // file item file_tag_save_file(local_user(),$item_id,$term); } else { diff --git a/mod/friendica.php b/mod/friendica.php index f1f0a6a0f..f613dfd39 100644 --- a/mod/friendica.php +++ b/mod/friendica.php @@ -7,7 +7,7 @@ function friendica_init(App $a) { $register_policy = Array('REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN'); $sql_extra = ''; - if (x($a->config,'admin_nickname')) { + if(x($a->config,'admin_nickname')) { $sql_extra = sprintf(" AND nickname = '%s' ",dbesc($a->config['admin_nickname'])); } if (isset($a->config['admin_email']) && $a->config['admin_email']!=''){ @@ -24,18 +24,18 @@ function friendica_init(App $a) { } $visible_plugins = array(); - if (is_array($a->plugins) && count($a->plugins)) { + if(is_array($a->plugins) && count($a->plugins)) { $r = q("select * from addon where hidden = 0"); if (dbm::is_result($r)) - foreach ($r as $rr) + foreach($r as $rr) $visible_plugins[] = $rr['name']; } Config::load('feature_lock'); $locked_features = array(); - if (is_array($a->config['feature_lock']) && count($a->config['feature_lock'])) { - foreach ($a->config['feature_lock'] as $k => $v) { - if ($k === 'config_loaded') + if(is_array($a->config['feature_lock']) && count($a->config['feature_lock'])) { + foreach($a->config['feature_lock'] as $k => $v) { + if($k === 'config_loaded') continue; $locked_features[$k] = intval($v); } @@ -80,24 +80,22 @@ function friendica_content(App $a) { $o .= '

'; $visible_plugins = array(); - if (is_array($a->plugins) && count($a->plugins)) { + if(is_array($a->plugins) && count($a->plugins)) { $r = q("select * from addon where hidden = 0"); if (dbm::is_result($r)) - foreach ($r as $rr) + foreach($r as $rr) $visible_plugins[] = $rr['name']; } - if (count($visible_plugins)) { + if(count($visible_plugins)) { $o .= '

' . t('Installed plugins/addons/apps:') . '

'; $sorted = $visible_plugins; $s = ''; sort($sorted); - foreach ($sorted as $p) { - if (strlen($p)) { - if (strlen($s)) { - $s .= ', '; - } + foreach($sorted as $p) { + if(strlen($p)) { + if(strlen($s)) $s .= ', '; $s .= $p; } } diff --git a/mod/fsuggest.php b/mod/fsuggest.php index 2cd91ea57..b3d543971 100644 --- a/mod/fsuggest.php +++ b/mod/fsuggest.php @@ -29,7 +29,7 @@ function fsuggest_post(App $a) { $note = escape_tags(trim($_POST['note'])); - if ($new_contact) { + if($new_contact) { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($new_contact), intval(local_user()) @@ -80,9 +80,8 @@ function fsuggest_content(App $a) { return; } - if ($a->argc != 2) { + if($a->argc != 2) return; - } $contact_id = intval($a->argv[1]); diff --git a/mod/group.php b/mod/group.php index 640fa7e60..2b332e401 100644 --- a/mod/group.php +++ b/mod/group.php @@ -5,7 +5,7 @@ function validate_members(&$item) { } function group_init(App $a) { - if (local_user()) { + if(local_user()) { require_once('include/group.php'); $a->page['aside'] = group_side('contacts','group','extended',(($a->argc > 1) ? intval($a->argv[1]) : 0)); } @@ -20,7 +20,7 @@ function group_post(App $a) { return; } - if (($a->argc == 2) && ($a->argv[1] === 'new')) { + if(($a->argc == 2) && ($a->argv[1] === 'new')) { check_form_security_token_redirectOnErr('/group/new', 'group_edit'); $name = notags(trim($_POST['groupname'])); @@ -80,12 +80,10 @@ function group_content(App $a) { // Switch to text mode interface if we have more than 'n' contacts or group members $switchtotext = get_pconfig(local_user(),'system','groupedit_image_limit'); - if ($switchtotext === false) { + if($switchtotext === false) $switchtotext = get_config('system','groupedit_image_limit'); - } - if ($switchtotext === false) { + if($switchtotext === false) $switchtotext = 400; - } $tpl = get_markup_template('group_edit.tpl'); @@ -101,6 +99,8 @@ function group_content(App $a) { '$gid' => 'new', '$form_security_token' => get_form_security_token("group_edit"), )); + + } if (($a->argc == 3) && ($a->argv[1] === 'drop')) { @@ -135,9 +135,8 @@ function group_content(App $a) { intval($a->argv[2]), intval(local_user()) ); - if (dbm::is_result($r)) { + if (dbm::is_result($r)) $change = intval($a->argv[2]); - } } if (($a->argc > 1) && (intval($a->argv[1]))) { @@ -154,23 +153,23 @@ function group_content(App $a) { $group = $r[0]; $members = group_get_members($group['id']); $preselected = array(); - if (count($members)) { - foreach ($members as $member) { + if(count($members)) { + foreach($members as $member) $preselected[] = $member['id']; - } } - if ($change) { - if (in_array($change,$preselected)) { + if($change) { + if(in_array($change,$preselected)) { group_rmv_member(local_user(),$group['name'],$change); - } else { + } + else { group_add_member(local_user(),$group['name'],$change); } $members = group_get_members($group['id']); $preselected = array(); - if (count($members)) { - foreach ($members as $member) + if(count($members)) { + foreach($members as $member) $preselected[] = $member['id']; } } @@ -194,9 +193,8 @@ function group_content(App $a) { } - if (! isset($group)) { + if(! isset($group)) return; - } $groupeditor = array( 'label_members' => t('Members'), @@ -208,13 +206,13 @@ function group_content(App $a) { $sec_token = addslashes(get_form_security_token('group_member_change')); $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false); - foreach ($members as $member) { - if ($member['url']) { + foreach($members as $member) { + if($member['url']) { $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;'; $groupeditor['members'][] = micropro($member,true,'mpgroup', $textmode); - } else { - group_rmv_member(local_user(),$group['name'],$member['id']); } + else + group_rmv_member(local_user(),$group['name'],$member['id']); } $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `self` ORDER BY `name` ASC", @@ -223,8 +221,8 @@ function group_content(App $a) { if (dbm::is_result($r)) { $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false); - foreach ($r as $member) { - if (! in_array($member['id'],$preselected)) { + foreach($r as $member) { + if(! in_array($member['id'],$preselected)) { $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;'; $groupeditor['contacts'][] = micropro($member,true,'mpall', $textmode); } @@ -234,7 +232,7 @@ function group_content(App $a) { $context['$groupeditor'] = $groupeditor; $context['$desc'] = t('Click on a contact to add or remove.'); - if ($change) { + if($change) { $tpl = get_markup_template('groupeditor.tpl'); echo replace_macros($tpl, $context); killme(); diff --git a/mod/help.php b/mod/help.php index 602653eea..c380aa391 100644 --- a/mod/help.php +++ b/mod/help.php @@ -30,10 +30,9 @@ function help_content(App $a) { $path = ''; // looping through the argv keys bigger than 0 to build // a path relative to /help - for ($x = 1; $x < argc(); $x ++) { - if (strlen($path)) { + for($x = 1; $x < argc(); $x ++) { + if(strlen($path)) $path .= '/'; - } $path .= argv($x); } $title = basename($path); @@ -66,22 +65,16 @@ function help_content(App $a) { $toc="

TOC

    "; $lastlevel=1; $idnum = array(0,0,0,0,0,0,0); - foreach ($lines as &$line){ + foreach($lines as &$line){ if (substr($line,0,2)=="$lastlevel) { - $toc.="
      "; + for($k=$level;$k<$lastlevel; $k++) $toc.="
    "; + for($k=$level+1;$k$lastlevel) $toc.="
      "; $idnum[$level]++; $id = implode("_", array_slice($idnum,1,$level)); $href = App::get_baseurl()."/help/{$filename}#{$id}"; @@ -91,7 +84,7 @@ function help_content(App $a) { } } } - for ($k=0;$k<$lastlevel; $k++) $toc.="
    "; + for($k=0;$k<$lastlevel; $k++) $toc.="
"; $html = implode("\n",$lines); $a->page['aside'] = $toc.$a->page['aside']; diff --git a/mod/home.php b/mod/home.php index ae85593dd..b1708d80a 100644 --- a/mod/home.php +++ b/mod/home.php @@ -1,6 +1,6 @@ account_type($contact), 'actions' => $actions, ); - if ($datatype == "html") { + if($datatype == "html") { $t = get_markup_template("hovercard.tpl"); $o = replace_macros($t, array( @@ -110,7 +110,7 @@ function get_template_content($template, $root = "") { $filename = $t->filename; // Get the content of the template file - if (file_exists($filename)) { + if(file_exists($filename)) { $content = file_get_contents($filename); return $content; diff --git a/mod/ignored.php b/mod/ignored.php index a31171307..0065d51c5 100644 --- a/mod/ignored.php +++ b/mod/ignored.php @@ -37,11 +37,8 @@ function ignored_init(App $a) { $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : ''); if ($return_path) { $rand = '_=' . time(); - if (strpos($return_path, '?')) { - $rand = "&$rand"; - } else { - $rand = "?$rand"; - } + if(strpos($return_path, '?')) $rand = "&$rand"; + else $rand = "?$rand"; goaway(App::get_baseurl() . "/" . $return_path . $rand); } diff --git a/mod/install.php b/mod/install.php old mode 100644 new mode 100755 index 215c00111..fa952a79b --- a/mod/install.php +++ b/mod/install.php @@ -43,11 +43,11 @@ function install_post(App $a) { require_once("include/dba.php"); unset($db); $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true); - /*if (get_db_errno()) { + /*if(get_db_errno()) { unset($db); $db = new dba($dbhost, $dbuser, $dbpass, '', true); - if (! get_db_errno()) { + if(! get_db_errno()) { $r = q("CREATE DATABASE '%s'", dbesc($dbdata) ); @@ -164,7 +164,7 @@ function install_content(App $a) { $db_return_text .= $txt; } - if ($db && $db->connected) { + if($db && $db->connected) { $r = q("SELECT COUNT(*) as `total` FROM `user`"); if (dbm::is_result($r) && $r[0]['total']) { $tpl = get_markup_template('install.tpl'); @@ -360,13 +360,13 @@ function check_php(&$phpath, &$checks) { check_add($checks, t('Command line PHP').($passed?" ($phpath)":""), $passed, false, $help); - if ($passed) { + if($passed) { $cmd = "$phpath -v"; $result = trim(shell_exec($cmd)); $passed2 = ( strpos($result, "(cli)") !== false ); list($result) = explode("\n", $result); $help = ""; - if (!$passed2) { + if(!$passed2) { $help .= t('PHP executable is not the php cli binary (could be cgi-fgci version)'). EOL; $help .= t('Found PHP version: ')."$result"; } @@ -380,7 +380,7 @@ function check_php(&$phpath, &$checks) { $result = trim(shell_exec($cmd)); $passed3 = $result == $str; $help = ""; - if (!$passed3) { + if(!$passed3) { $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL; $help .= t('This is required for message delivery to work.'); } @@ -485,7 +485,7 @@ function check_funcs(&$checks) { $ck_funcs[6]['help'] = t('Error, XML PHP module required but not installed.'); } - /*if ((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg'])) + /*if((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg'])) notice( t('Please see the file "INSTALL.txt".') . EOL);*/ } @@ -589,10 +589,10 @@ function load_database($db) { /* $str = file_get_contents('database.sql'); $arr = explode(';',$str); $errors = false; - foreach ($arr as $a) { - if (strlen(trim($a))) { + foreach($arr as $a) { + if(strlen(trim($a))) { $r = @$db->q(trim($a)); - if (false === $r) { + if(false === $r) { $errors .= t('Errors encountered creating database tables.') . $a . EOL; } } diff --git a/mod/invite.php b/mod/invite.php index fef5ce834..f5c60e1ed 100644 --- a/mod/invite.php +++ b/mod/invite.php @@ -83,7 +83,7 @@ function invite_post(App $a) { $total ++; $current_invites ++; set_pconfig(local_user(),'system','sent_invites',$current_invites); - if ($current_invites > $max_invites) { + if($current_invites > $max_invites) { notice( t('Invitation limit exceeded. Please contact your site administrator.') . EOL); return; } diff --git a/mod/item.php b/mod/item.php index 8fb3ecb54..6da9ce88e 100644 --- a/mod/item.php +++ b/mod/item.php @@ -29,14 +29,14 @@ require_once('include/Contact.php'); function item_post(App $a) { - if ((! local_user()) && (! remote_user()) && (! x($_REQUEST,'commenter'))) + if((! local_user()) && (! remote_user()) && (! x($_REQUEST,'commenter'))) return; require_once('include/security.php'); $uid = local_user(); - if (x($_REQUEST,'dropitems')) { + if(x($_REQUEST,'dropitems')) { $arr_drop = explode(',',$_REQUEST['dropitems']); drop_items($arr_drop); $json = array('success' => 1); @@ -125,7 +125,7 @@ function item_post(App $a) { $parent = $r[0]['id']; // multi-level threading - preserve the info but re-parent to our single level threading - //if (($parid) && ($parid != $parent)) + //if(($parid) && ($parid != $parent)) $thr_parent = $parent_uri; if ($parent_item['contact-id'] && $uid) { @@ -162,7 +162,7 @@ function item_post(App $a) { } } - if ($parent) logger('mod_item: item_post parent=' . $parent); + if($parent) logger('mod_item: item_post parent=' . $parent); $profile_uid = ((x($_REQUEST,'profile_uid')) ? intval($_REQUEST['profile_uid']) : 0); $post_id = ((x($_REQUEST,'post_id')) ? intval($_REQUEST['post_id']) : 0); @@ -189,9 +189,9 @@ function item_post(App $a) { // First check that the parent exists and it is a wall item. - if ((x($_REQUEST,'commenter')) && ((! $parent) || (! $parent_item['wall']))) { + if((x($_REQUEST,'commenter')) && ((! $parent) || (! $parent_item['wall']))) { notice( t('Permission denied.') . EOL) ; - if (x($_REQUEST,'return')) + if(x($_REQUEST,'return')) goaway($return_path); killme(); } @@ -201,9 +201,9 @@ function item_post(App $a) { - if ((! can_write_wall($a,$profile_uid)) && (! $allow_moderated)) { + if((! can_write_wall($a,$profile_uid)) && (! $allow_moderated)) { notice( t('Permission denied.') . EOL) ; - if (x($_REQUEST,'return')) + if(x($_REQUEST,'return')) goaway($return_path); killme(); } @@ -213,7 +213,7 @@ function item_post(App $a) { $orig_post = null; - if ($post_id) { + if($post_id) { $i = q("SELECT * FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($profile_uid), intval($post_id) @@ -232,7 +232,7 @@ function item_post(App $a) { if (dbm::is_result($r)) $user = $r[0]; - if ($orig_post) { + if($orig_post) { $str_group_allow = $orig_post['allow_gid']; $str_contact_allow = $orig_post['allow_cid']; $str_group_deny = $orig_post['deny_gid']; @@ -258,7 +258,7 @@ function item_post(App $a) { // use the user default permissions - as they won't have // been supplied via a form. - if (($api_source) + if(($api_source) && (! array_key_exists('contact_allow',$_REQUEST)) && (! array_key_exists('group_allow',$_REQUEST)) && (! array_key_exists('contact_deny',$_REQUEST)) @@ -295,12 +295,12 @@ function item_post(App $a) { $private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0); - if ($user['hidewall']) + if($user['hidewall']) $private = 2; // If this is a comment, set the permissions from the parent. - if ($parent_item) { + if($parent_item) { // for non native networks use the network of the original post as network of the item if (($parent_item['network'] != NETWORK_DIASPORA) @@ -319,9 +319,9 @@ function item_post(App $a) { // if using the API, we won't see pubmail_enable - figure out if it should be set - if ($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) { + if($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) { $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); - if (! $mail_disabled) { + if(! $mail_disabled) { $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user()) ); @@ -330,17 +330,17 @@ function item_post(App $a) { } } - if (! strlen($body)) { - if ($preview) + if(! strlen($body)) { + if($preview) killme(); info( t('Empty post discarded.') . EOL ); - if (x($_REQUEST,'return')) + if(x($_REQUEST,'return')) goaway($return_path); killme(); } } - if (strlen($categories)) { + if(strlen($categories)) { // get the "fileas" tags for this post $filedas = file_tag_file_to_list($categories, 'file'); } @@ -348,7 +348,7 @@ function item_post(App $a) { $categories_old = $categories; $categories = file_tag_list_to_file(trim($_REQUEST['category']), 'category'); $categories_new = $categories; - if (strlen($filedas)) { + if(strlen($filedas)) { // append the fileas stuff to the new categories list $categories .= file_tag_list_to_file($filedas, 'file'); } @@ -359,21 +359,21 @@ function item_post(App $a) { $self = false; $contact_id = 0; - if ((local_user()) && (local_user() == $profile_uid)) { + if((local_user()) && (local_user() == $profile_uid)) { $self = true; $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($_SESSION['uid'])); } - elseif (remote_user()) { - if (is_array($_SESSION['remote'])) { - foreach ($_SESSION['remote'] as $v) { - if ($v['uid'] == $profile_uid) { + elseif(remote_user()) { + if(is_array($_SESSION['remote'])) { + foreach($_SESSION['remote'] as $v) { + if($v['uid'] == $profile_uid) { $contact_id = $v['cid']; break; } } } - if ($contact_id) { + if($contact_id) { $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", intval($contact_id) ); @@ -387,7 +387,7 @@ function item_post(App $a) { // get contact info for owner - if ($profile_uid == local_user()) { + if($profile_uid == local_user()) { $contact_record = $author; } else { @@ -400,9 +400,9 @@ function item_post(App $a) { $post_type = notags(trim($_REQUEST['type'])); - if ($post_type === 'net-comment') { - if ($parent_item !== null) { - if ($parent_item['wall'] == 1) + if($post_type === 'net-comment') { + if($parent_item !== null) { + if($parent_item['wall'] == 1) $post_type = 'wall-comment'; else $post_type = 'remote-comment'; @@ -423,9 +423,9 @@ function item_post(App $a) { $match = null; - if ((! $preview) && preg_match_all("/\[img([\=0-9x]*?)\](.*?)\[\/img\]/",$body,$match)) { + if((! $preview) && preg_match_all("/\[img([\=0-9x]*?)\](.*?)\[\/img\]/",$body,$match)) { $images = $match[2]; - if (count($images)) { + if(count($images)) { $objecttype = ACTIVITY_OBJ_IMAGE; @@ -472,10 +472,10 @@ function item_post(App $a) { $match = false; - if ((! $preview) && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",$body,$match)) { + if((! $preview) && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",$body,$match)) { $attaches = $match[1]; - if (count($attaches)) { - foreach ($attaches as $attach) { + if(count($attaches)) { + foreach($attaches as $attach) { $r = q("SELECT * FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($profile_uid), intval($attach) @@ -572,26 +572,24 @@ function item_post(App $a) { $private_forum = false; - if (count($tags)) { - foreach ($tags as $tag) { + if(count($tags)) { + foreach($tags as $tag) { - if (strpos($tag,'#') === 0) { + if(strpos($tag,'#') === 0) continue; - } // If we already tagged 'Robert Johnson', don't try and tag 'Robert'. // Robert Johnson should be first in the $tags array $fullnametagged = false; - for ($x = 0; $x < count($tagged); $x ++) { - if (stristr($tagged[$x],$tag . ' ')) { + for($x = 0; $x < count($tagged); $x ++) { + if(stristr($tagged[$x],$tag . ' ')) { $fullnametagged = true; break; } } - if ($fullnametagged) { + if($fullnametagged) continue; - } $success = handle_tag($a, $body, $inform, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag, $network); if ($success['replaced']) { @@ -724,16 +722,15 @@ function item_post(App $a) { $datarray['last-child'] = 1; $datarray['visible'] = 1; - if ($orig_post) { + if($orig_post) $datarray['edit'] = true; - } // Search for hashtags item_body_set_hashtags($datarray); // preview mode - prepare the body for display and send it via json - if ($preview) { + if($preview) { require_once('include/conversation.php'); // We set the datarray ID to -1 because in preview mode the dataray // doesn't have an ID. @@ -747,9 +744,9 @@ function item_post(App $a) { call_hooks('post_local',$datarray); - if (x($datarray,'cancel')) { + if(x($datarray,'cancel')) { logger('mod_item: post cancelled by plugin.'); - if ($return_path) { + if($return_path) { goaway($return_path); } @@ -765,7 +762,7 @@ function item_post(App $a) { // Fill the cache field put_item_in_cache($datarray); - if ($orig_post) { + if($orig_post) { $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `attach` = '%s', `file` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($datarray['title']), dbesc($datarray['body']), @@ -788,7 +785,7 @@ function item_post(App $a) { file_tag_update_pconfig($uid,$categories_old,$categories_new,'category'); proc_run(PRIORITY_HIGH, "include/notifier.php", 'edit_post', $post_id); - if ((x($_REQUEST,'return')) && strlen($return_path)) { + if((x($_REQUEST,'return')) && strlen($return_path)) { logger('return: ' . $return_path); goaway($return_path); } @@ -903,7 +900,7 @@ function item_post(App $a) { // update filetags in pconfig file_tag_update_pconfig($uid,$categories_old,$categories_new,'category'); - if ($parent) { + if($parent) { // This item is the last leaf and gets the comment box, clear any ancestors $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d AND `last-child` AND `id` != %d", @@ -919,7 +916,7 @@ function item_post(App $a) { intval($parent) ); - if ($contact_record != $author) { + if($contact_record != $author) { notification(array( 'type' => NOTIFY_COMMENT, 'notify_flags' => $user['notify-flags'], @@ -951,7 +948,7 @@ function item_post(App $a) { intval($parent), intval($post_id)); - if ($contact_record != $author) { + if($contact_record != $author) { notification(array( 'type' => NOTIFY_WALL, 'notify_flags' => $user['notify-flags'], @@ -960,7 +957,7 @@ function item_post(App $a) { 'to_email' => $user['email'], 'uid' => $user['uid'], 'item' => $datarray, - 'link' => App::get_baseurl().'/display/'.urlencode($datarray['guid']), + 'link' => App::get_baseurl().'/display/'.urlencode($datarray['guid']), 'source_name' => $datarray['author-name'], 'source_link' => $datarray['author-link'], 'source_photo' => $datarray['author-avatar'], @@ -972,12 +969,12 @@ function item_post(App $a) { call_hooks('post_local_end', $datarray); - if (strlen($emailcc) && $profile_uid == local_user()) { + if(strlen($emailcc) && $profile_uid == local_user()) { $erecips = explode(',', $emailcc); - if (count($erecips)) { - foreach ($erecips as $recip) { + if(count($erecips)) { + foreach($erecips as $recip) { $addr = trim($recip); - if (! strlen($addr)) + if(! strlen($addr)) continue; $disclaimer = '
' . sprintf( t('This message was sent to you by %s, a member of the Friendica social network.'),$a->user['username']) . '
'; @@ -1035,9 +1032,8 @@ function item_post(App $a) { function item_post_return($baseurl, $api_source, $return_path) { // figure out how to return, depending on from whence we came - if ($api_source) { + if($api_source) return; - } if ($return_path) { goaway($return_path); @@ -1115,24 +1111,19 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo $r = q("SELECT `alias`, `name` FROM `contact` WHERE `nurl` = '%s' AND `alias` != '' AND `uid` = 0", normalise_link($matches[1])); - - if (!dbm::is_result($r)) { + if (!$r) $r = q("SELECT `alias`, `name` FROM `gcontact` WHERE `nurl` = '%s' AND `alias` != ''", normalise_link($matches[1])); - - } - if (dbm::is_result($r)) { + if ($r) $data = $r[0]; - } else { + else $data = probe_url($matches[1]); - } if ($data["alias"] != "") { $newtag = '@[url='.$data["alias"].']'.$data["name"].'[/url]'; - if (!stristr($str_tags,$newtag)) { - if (strlen($str_tags)) { + if(!stristr($str_tags,$newtag)) { + if(strlen($str_tags)) $str_tags .= ','; - } $str_tags .= $newtag; } } @@ -1164,7 +1155,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo ); // Then check in the contact table for the url - if (!dbm::is_result($r)) { + if (!$r) $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND (`network` != '%s' OR (`notify` != '' AND `alias` != '')) @@ -1173,7 +1164,6 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo intval($profile_uid), dbesc(NETWORK_OSTATUS) ); - } // Then check in the global contacts for the address if (!$r) @@ -1185,16 +1175,15 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo ); // Then check in the global contacts for the url - if (!dbm::is_result($r)) { + if (!$r) $r = q("SELECT `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `gcontact` WHERE `nurl` = '%s' AND (`network` != '%s' OR (`notify` != '' AND `alias` != '')) LIMIT 1", dbesc(normalise_link($name)), dbesc(NETWORK_OSTATUS) ); - } - if (!dbm::is_result($r)) { + if (!$r) { $probed = probe_url($name); if ($result['network'] != NETWORK_PHANTOM) { update_gcontact($probed); @@ -1215,60 +1204,54 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo } //select someone by attag or nick and the name passed in the current network - if (!dbm::is_result($r) AND ($network != "")) { + if(!$r AND ($network != "")) $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `network` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", dbesc($name), dbesc($name), dbesc($network), intval($profile_uid) ); - } //select someone from this user's contacts by name in the current network - if (!dbm::is_result($r) AND ($network != "")) { + if (!$r AND ($network != "")) $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `network` = '%s' AND `uid` = %d LIMIT 1", dbesc($name), dbesc($network), intval($profile_uid) ); - } //select someone by attag or nick and the name passed in - if (!dbm::is_result($r)) { + if(!$r) $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", dbesc($name), dbesc($name), intval($profile_uid) ); - } + //select someone from this user's contacts by name - if (!dbm::is_result($r)) { + if(!$r) $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", dbesc($name), intval($profile_uid) ); - } } - if (dbm::is_result($r)) { - if (strlen($inform) AND (isset($r[0]["notify"]) OR isset($r[0]["id"]))) { + if ($r) { + if(strlen($inform) AND (isset($r[0]["notify"]) OR isset($r[0]["id"]))) $inform .= ','; - } - if (isset($r[0]["id"])) { + if (isset($r[0]["id"])) $inform .= 'cid:' . $r[0]["id"]; - } elseif (isset($r[0]["notify"])) { + elseif (isset($r[0]["notify"])) $inform .= $r[0]["notify"]; - } $profile = $r[0]["url"]; $alias = $r[0]["alias"]; $newname = $r[0]["nick"]; if (($newname == "") OR (($r[0]["network"] != NETWORK_OSTATUS) AND ($r[0]["network"] != NETWORK_TWITTER) - AND ($r[0]["network"] != NETWORK_STATUSNET) AND ($r[0]["network"] != NETWORK_APPNET))) { + AND ($r[0]["network"] != NETWORK_STATUSNET) AND ($r[0]["network"] != NETWORK_APPNET))) $newname = $r[0]["name"]; - } } //if there is an url for this persons profile @@ -1280,22 +1263,20 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo $newtag = '@[url='.$profile.']'.$newname.'[/url]'; $body = str_replace('@'.$name, $newtag, $body); //append tag to str_tags - if (! stristr($str_tags,$newtag)) { - if (strlen($str_tags)) { + if(! stristr($str_tags,$newtag)) { + if(strlen($str_tags)) $str_tags .= ','; - } $str_tags .= $newtag; } // Status.Net seems to require the numeric ID URL in a mention if the person isn't // subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both. - if (strlen($alias)) { + if(strlen($alias)) { $newtag = '@[url='.$alias.']'.$newname.'[/url]'; - if (! stristr($str_tags,$newtag)) { - if (strlen($str_tags)) { + if(! stristr($str_tags,$newtag)) { + if(strlen($str_tags)) $str_tags .= ','; - } $str_tags .= $newtag; } } diff --git a/mod/like.php b/mod/like.php old mode 100644 new mode 100755 index 7932fc149..1f6a233f3 --- a/mod/like.php +++ b/mod/like.php @@ -6,23 +6,20 @@ require_once('include/items.php'); require_once('include/like.php'); function like_content(App $a) { - if (! local_user() && ! remote_user()) { + if(! local_user() && ! remote_user()) { return false; } $verb = notags(trim($_GET['verb'])); - if (! $verb) { + if(! $verb) $verb = 'like'; - } $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0); $r = do_like($item_id, $verb); - if (!$r) { - return; - } + if (!$r) return; // See if we've been passed a return path to redirect to $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : ''); @@ -38,13 +35,10 @@ function like_content(App $a) { function like_content_return($baseurl, $return_path) { - if ($return_path) { + if($return_path) { $rand = '_=' . time(); - if (strpos($return_path, '?')) { - $rand = "&$rand"; - } else { - $rand = "?$rand"; - } + if(strpos($return_path, '?')) $rand = "&$rand"; + else $rand = "?$rand"; goaway($baseurl . "/" . $return_path . $rand); } diff --git a/mod/localtime.php b/mod/localtime.php index aaa93b4ea..535308903 100644 --- a/mod/localtime.php +++ b/mod/localtime.php @@ -6,23 +6,20 @@ require_once('include/datetime.php'); function localtime_post(App $a) { $t = $_REQUEST['time']; - if (! $t) { + if(! $t) $t = 'now'; - } $bd_format = t('l F d, Y \@ g:i A') ; // Friday January 18, 2011 @ 8 AM - if ($_POST['timezone']) { + if($_POST['timezone']) $a->data['mod-localtime'] = datetime_convert('UTC',$_POST['timezone'],$t,$bd_format); - } } function localtime_content(App $a) { $t = $_REQUEST['time']; - if (! $t) { + if(! $t) $t = 'now'; - } $o .= '

' . t('Time Conversion') . '

'; @@ -32,13 +29,11 @@ function localtime_content(App $a) { $o .= '

' . sprintf( t('UTC time: %s'), $t) . '

'; - if ($_REQUEST['timezone']) { + if($_REQUEST['timezone']) $o .= '

' . sprintf( t('Current timezone: %s'), $_REQUEST['timezone']) . '

'; - } - if (x($a->data,'mod-localtime')) { + if(x($a->data,'mod-localtime')) $o .= '

' . sprintf( t('Converted localtime: %s'),$a->data['mod-localtime']) . '

'; - } $o .= ''; diff --git a/mod/lockview.php b/mod/lockview.php index 7ced34647..38a308634 100644 --- a/mod/lockview.php +++ b/mod/lockview.php @@ -11,7 +11,7 @@ function lockview_content(App $a) { $item_id = (($a->argc > 2) ? intval($a->argv[2]) : 0); } - if (! $item_id) + if(! $item_id) killme(); if (!in_array($type, array('item','photo','event'))) @@ -28,13 +28,13 @@ function lockview_content(App $a) { call_hooks('lockview_content', $item); - if ($item['uid'] != local_user()) { + if($item['uid'] != local_user()) { echo t('Remote privacy information not available.') . '
'; killme(); } - if (($item['private'] == 1) && (! strlen($item['allow_cid'])) && (! strlen($item['allow_gid'])) + if(($item['private'] == 1) && (! strlen($item['allow_cid'])) && (! strlen($item['allow_gid'])) && (! strlen($item['deny_cid'])) && (! strlen($item['deny_gid']))) { echo t('Remote privacy information not available.') . '
'; @@ -49,47 +49,39 @@ function lockview_content(App $a) { $o = t('Visible to:') . '
'; $l = array(); - if (count($allowed_groups)) { + if(count($allowed_groups)) { $r = q("SELECT `name` FROM `group` WHERE `id` IN ( %s )", dbesc(implode(', ', $allowed_groups)) ); - if (dbm::is_result($r)) { - foreach ($r as $rr) { + if (dbm::is_result($r)) + foreach($r as $rr) $l[] = '' . $rr['name'] . ''; - } - } } - if (count($allowed_users)) { + if(count($allowed_users)) { $r = q("SELECT `name` FROM `contact` WHERE `id` IN ( %s )", dbesc(implode(', ',$allowed_users)) ); - if (dbm::is_result($r)) { - foreach ($r as $rr) { + if (dbm::is_result($r)) + foreach($r as $rr) $l[] = $rr['name']; - } - } } - if (count($deny_groups)) { + if(count($deny_groups)) { $r = q("SELECT `name` FROM `group` WHERE `id` IN ( %s )", dbesc(implode(', ', $deny_groups)) ); - if (dbm::is_result($r)) { - foreach ($r as $rr) { + if (dbm::is_result($r)) + foreach($r as $rr) $l[] = '' . $rr['name'] . ''; - } - } } - if (count($deny_users)) { + if(count($deny_users)) { $r = q("SELECT `name` FROM `contact` WHERE `id` IN ( %s )", dbesc(implode(', ',$deny_users)) ); - if (dbm::is_result($r)) { - foreach ($r as $rr) { + if (dbm::is_result($r)) + foreach($r as $rr) $l[] = '' . $rr['name'] . ''; - } - } } diff --git a/mod/login.php b/mod/login.php index 79e245c9b..8fd28c723 100644 --- a/mod/login.php +++ b/mod/login.php @@ -1,16 +1,13 @@ config['register_policy'] == REGISTER_CLOSED) ? false : true); } diff --git a/mod/lostpass.php b/mod/lostpass.php index 7a927d05a..455a9b1e2 100644 --- a/mod/lostpass.php +++ b/mod/lostpass.php @@ -7,7 +7,7 @@ require_once('include/text.php'); function lostpass_post(App $a) { $loginame = notags(trim($_POST['login-name'])); - if (! $loginame) + if(! $loginame) goaway(z_root()); $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) AND `verified` = 1 AND `blocked` = 0 LIMIT 1", @@ -31,7 +31,7 @@ function lostpass_post(App $a) { dbesc($new_password_encoded), intval($uid) ); - if ($r) + if($r) info( t('Password reset request issued. Check your email.') . EOL); @@ -79,7 +79,8 @@ function lostpass_post(App $a) { function lostpass_content(App $a) { - if (x($_GET,'verify')) { + + if(x($_GET,'verify')) { $verify = $_GET['verify']; $hash = hash('whirlpool', $verify); diff --git a/mod/manage.php b/mod/manage.php index 4835f6fc8..4beb8e46c 100644 --- a/mod/manage.php +++ b/mod/manage.php @@ -12,8 +12,8 @@ function manage_post(App $a) { $uid = local_user(); $orig_record = $a->user; - if ((x($_SESSION,'submanage')) && intval($_SESSION['submanage'])) { - $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", + if((x($_SESSION,'submanage')) && intval($_SESSION['submanage'])) { + $r = q("select * from user where uid = %d limit 1", intval($_SESSION['submanage']) ); if (dbm::is_result($r)) { @@ -22,34 +22,34 @@ function manage_post(App $a) { } } - $r = q("SELECT * FROM `manage` WHERE `uid` = %d", + $r = q("select * from manage where uid = %d", intval($uid) ); $submanage = $r; $identity = ((x($_POST['identity'])) ? intval($_POST['identity']) : 0); - if (! $identity) { + if(! $identity) return; - } $limited_id = 0; $original_id = $uid; - if (count($submanage)) { - foreach ($submanage as $m) { - if ($identity == $m['mid']) { + if(count($submanage)) { + foreach($submanage as $m) { + if($identity == $m['mid']) { $limited_id = $m['mid']; break; } } } - if ($limited_id) { + if($limited_id) { $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($limited_id) ); - } else { + } + else { $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `email` = '%s' AND `password` = '%s' LIMIT 1", intval($identity), dbesc($orig_record['email']), @@ -70,22 +70,18 @@ function manage_post(App $a) { unset($_SESSION['mobile-theme']); unset($_SESSION['page_flags']); unset($_SESSION['return_url']); - if (x($_SESSION,'submanage')) { + if(x($_SESSION,'submanage')) unset($_SESSION['submanage']); - } - if (x($_SESSION,'sysmsg')) { + if(x($_SESSION,'sysmsg')) unset($_SESSION['sysmsg']); - } - if (x($_SESSION,'sysmsg_info')) { + if(x($_SESSION,'sysmsg_info')) unset($_SESSION['sysmsg_info']); - } require_once('include/security.php'); authenticate_success($r[0],true,true); - if ($limited_id) { + if($limited_id) $_SESSION['submanage'] = $original_id; - } $ret = array(); call_hooks('home_init',$ret); diff --git a/mod/match.php b/mod/match.php index baffb3d07..44f5141ad 100644 --- a/mod/match.php +++ b/mod/match.php @@ -31,7 +31,7 @@ function match_content(App $a) { if (! dbm::is_result($r)) { return; } - if (! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) { + if(! $r[0]['pub_keywords'] && (! $r[0]['prv_keywords'])) { notice( t('No keywords to match. Please add keywords to your default profile.') . EOL); return; } @@ -39,28 +39,28 @@ function match_content(App $a) { $params = array(); $tags = trim($r[0]['pub_keywords'] . ' ' . $r[0]['prv_keywords']); - if ($tags) { + if($tags) { $params['s'] = $tags; - if ($a->pager['page'] != 1) + if($a->pager['page'] != 1) $params['p'] = $a->pager['page']; - if (strlen(get_config('system','directory'))) + if(strlen(get_config('system','directory'))) $x = post_url(get_server().'/msearch', $params); else $x = post_url(App::get_baseurl() . '/msearch', $params); $j = json_decode($x); - if ($j->total) { + if($j->total) { $a->set_pager_total($j->total); $a->set_pager_itemspage($j->items_page); } - if (count($j->results)) { + if(count($j->results)) { $id = 0; - foreach ($j->results as $jj) { + foreach($j->results as $jj) { $match_nurl = normalise_link($jj->url); $match = q("SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1", intval(local_user()), diff --git a/mod/message.php b/mod/message.php index 3d5a9b5a9..9e9669146 100644 --- a/mod/message.php +++ b/mod/message.php @@ -75,18 +75,18 @@ function message_post(App $a) { // fake it to go back to the input form if no recipient listed - if ($norecip) { + if($norecip) { $a->argc = 2; $a->argv[1] = 'new'; - } else { - goaway($_SESSION['return_url']); } + else + goaway($_SESSION['return_url']); } // Note: the code in 'item_extract_images' and 'item_redir_and_replace_images' // is identical to the code in include/conversation.php -if (! function_exists('item_extract_images')) { +if(! function_exists('item_extract_images')) { function item_extract_images($body) { $saved_image = array(); @@ -97,27 +97,26 @@ function item_extract_images($body) { $img_start = strpos($orig_body, '[img'); $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false); - while (($img_st_close !== false) && ($img_end !== false)) { + while(($img_st_close !== false) && ($img_end !== false)) { $img_st_close++; // make it point to AFTER the closing bracket $img_end += $img_start; - if (! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { + if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { // This is an embedded image $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close)); $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]'; $cnt++; - } else { - $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]')); } + else + $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]')); $orig_body = substr($orig_body, $img_end + strlen('[/img]')); - if ($orig_body === false) {// in case the body ends on a closing image tag + if($orig_body === false) // in case the body ends on a closing image tag $orig_body = ''; - } $img_start = strpos($orig_body, '[img'); $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); @@ -129,13 +128,13 @@ function item_extract_images($body) { return array('body' => $new_body, 'images' => $saved_image); }} -if (! function_exists('item_redir_and_replace_images')) { +if(! function_exists('item_redir_and_replace_images')) { function item_redir_and_replace_images($body, $images, $cid) { $origbody = $body; $newbody = ''; - for ($i = 0; $i < count($images); $i++) { + for($i = 0; $i < count($images); $i++) { $search = '/\[url\=(.*?)\]\[!#saved_image' . $i . '#!\]\[\/url\]' . '/is'; $replace = '[url=' . z_path() . '/redir/' . $cid . '?f=1&url=' . '$1' . '][!#saved_image' . $i . '#!][/url]' ; @@ -182,18 +181,18 @@ function message_content(App $a) { )); - if (($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) { - if (! intval($a->argv[2])) + if(($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) { + if(! intval($a->argv[2])) return; // Check if we should do HTML-based delete confirmation - if ($_REQUEST['confirm']) { + if($_REQUEST['confirm']) { // can't take arguments in its "action" parameter // so add any arguments as hidden inputs $query = explode_querystring($a->query_string); $inputs = array(); - foreach ($query['args'] as $arg) { - if (strpos($arg, 'confirm=') === false) { + foreach($query['args'] as $arg) { + if(strpos($arg, 'confirm=') === false) { $arg_parts = explode('=', $arg); $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]); } @@ -211,12 +210,12 @@ function message_content(App $a) { )); } // Now check how the user responded to the confirmation query - if ($_REQUEST['canceled']) { + if($_REQUEST['canceled']) { goaway($_SESSION['return_url']); } $cmd = $a->argv[1]; - if ($cmd === 'drop') { + if($cmd === 'drop') { $r = q("DELETE FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[2]), intval(local_user()) @@ -246,15 +245,14 @@ function message_content(App $a) { // as we will never again have the info we need to re-create it. // We'll just have to orphan it. - //if ($convid) { + //if($convid) { // q("delete from conv where id = %d limit 1", // intval($convid) // ); //} - if ($r) { + if($r) info( t('Conversation removed.') . EOL ); - } } //goaway(App::get_baseurl(true) . '/message' ); goaway($_SESSION['return_url']); @@ -262,7 +260,7 @@ function message_content(App $a) { } - if (($a->argc > 1) && ($a->argv[1] === 'new')) { + if(($a->argc > 1) && ($a->argv[1] === 'new')) { $o .= $header; @@ -285,7 +283,7 @@ function message_content(App $a) { $prename = $preurl = $preid = ''; - if ($preselect) { + if($preselect) { $r = q("SELECT `name`, `url`, `id` FROM `contact` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval(local_user()), intval($a->argv[2]) @@ -374,7 +372,7 @@ function message_content(App $a) { return $o; } - if (($a->argc > 1) && (intval($a->argv[1]))) { + if(($a->argc > 1) && (intval($a->argv[1]))) { $o .= $header; @@ -389,7 +387,7 @@ function message_content(App $a) { $convid = $r[0]['convid']; $sql_extra = sprintf(" and `mail`.`parent-uri` = '%s' ", dbesc($r[0]['parent-uri'])); - if ($convid) + if($convid) $sql_extra = sprintf(" and ( `mail`.`parent-uri` = '%s' OR `mail`.`convid` = '%d' ) ", dbesc($r[0]['parent-uri']), intval($convid) @@ -401,7 +399,7 @@ function message_content(App $a) { intval(local_user()) ); } - if (! count($messages)) { + if(! count($messages)) { notice( t('Message not available.') . EOL ); return $o; } @@ -431,11 +429,10 @@ function message_content(App $a) { $seen = 0; $unknown = false; - foreach ($messages as $message) { - if ($message['unknown']) { + foreach($messages as $message) { + if($message['unknown']) $unknown = true; - } - if ($message['from-url'] == $myprofile) { + if($message['from-url'] == $myprofile) { $from_url = $myprofile; $sparkle = ''; } elseif ($message['contact-id'] != 0) { @@ -448,11 +445,10 @@ function message_content(App $a) { $extracted = item_extract_images($message['body']); - if ($extracted['images']) { + if($extracted['images']) $message['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $message['contact-id']); - } - if ($a->theme['template_engine'] === 'internal') { + if($a->theme['template_engine'] === 'internal') { $from_name_e = template_escape($message['from-name']); $subject_e = template_escape($message['title']); $body_e = template_escape(Smilies::replace(bbcode($message['body']))); @@ -465,24 +461,23 @@ function message_content(App $a) { } $contact = get_contact_details_by_url($message['from-url']); - if (isset($contact["thumb"])) { + if (isset($contact["thumb"])) $from_photo = $contact["thumb"]; - } else { + else $from_photo = $message['from-photo']; - } $mails[] = array( - 'id' => $message['id'], - 'from_name' => $from_name_e, - 'from_url' => $from_url, - 'sparkle' => $sparkle, + 'id' => $message['id'], + 'from_name' => $from_name_e, + 'from_url' => $from_url, + 'sparkle' => $sparkle, 'from_photo' => proxy_url($from_photo, false, PROXY_SIZE_THUMB), - 'subject' => $subject_e, - 'body' => $body_e, - 'delete' => t('Delete message'), - 'to_name' => $to_name_e, - 'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'), - 'ago' => relative_date($message['created']), + 'subject' => $subject_e, + 'body' => $body_e, + 'delete' => t('Delete message'), + 'to_name' => $to_name_e, + 'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'), + 'ago' => relative_date($message['created']), ); $seen = $message['seen']; @@ -494,9 +489,10 @@ function message_content(App $a) { $tpl = get_markup_template('mail_display.tpl'); - if ($a->theme['template_engine'] === 'internal') { + if($a->theme['template_engine'] === 'internal') { $subjtxt_e = template_escape($message['title']); - } else { + } + else { $subjtxt_e = $message['title']; } @@ -551,16 +547,16 @@ function render_messages(array $msg, $t) { $myprofile = App::get_baseurl().'/profile/' . $a->user['nickname']; - foreach ($msg as $rr) { + foreach($msg as $rr) { - if ($rr['unknown']) + if($rr['unknown']) $participants = sprintf( t("Unknown sender - %s"),$rr['from-name']); elseif (link_compare($rr['from-url'], $myprofile)) $participants = sprintf( t("You and %s"), $rr['name']); else $participants = sprintf(t("%s and You"), $rr['from-name']); - if ($a->theme['template_engine'] === 'internal') { + if($a->theme['template_engine'] === 'internal') { $subject_e = template_escape((($rr['mailseen']) ? $rr['title'] : '' . $rr['title'] . '')); $body_e = template_escape($rr['body']); $to_name_e = template_escape($rr['name']); diff --git a/mod/modexp.php b/mod/modexp.php index 0c5a03318..4cc952247 100644 --- a/mod/modexp.php +++ b/mod/modexp.php @@ -4,7 +4,7 @@ require_once('library/asn1.php'); function modexp_init(App $a) { - if ($a->argc != 2) + if($a->argc != 2) killme(); $nick = $a->argv[1]; diff --git a/mod/mood.php b/mod/mood.php index 805c4c45f..e80a7f097 100644 --- a/mod/mood.php +++ b/mod/mood.php @@ -14,12 +14,12 @@ function mood_init(App $a) { $uid = local_user(); $verb = notags(trim($_GET['verb'])); - if (! $verb) + if(! $verb) return; $verbs = get_mood_verbs(); - if (! in_array($verb,$verbs)) + if(! in_array($verb,$verbs)) return; $activity = ACTIVITY_MOOD . '#' . urlencode($verb); @@ -30,7 +30,7 @@ function mood_init(App $a) { logger('mood: verb ' . $verb, LOGGER_DEBUG); - if ($parent) { + if($parent) { $r = q("select uri, private, allow_cid, allow_gid, deny_cid, deny_gid from item where id = %d and parent = %d and uid = %d limit 1", intval($parent), @@ -90,7 +90,7 @@ function mood_init(App $a) { $arr['body'] = $action; $item_id = item_store($arr); - if ($item_id) { + if($item_id) { q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d", dbesc(App::get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id), intval($uid), @@ -123,11 +123,9 @@ function mood_content(App $a) { $verbs = get_mood_verbs(); $shortlist = array(); - foreach ($verbs as $k => $v) { - if ($v !== 'NOTRANSLATION') { + foreach($verbs as $k => $v) + if($v !== 'NOTRANSLATION') $shortlist[] = array($k,$v); - } - } $tpl = get_markup_template('mood_content.tpl'); diff --git a/mod/msearch.php b/mod/msearch.php index 177ce2688..277242aff 100644 --- a/mod/msearch.php +++ b/mod/msearch.php @@ -7,7 +7,7 @@ function msearch_post(App $a) { $startrec = (($page+1) * $perpage) - $perpage; $search = $_POST['s']; - if (! strlen($search)) + if(! strlen($search)) killme(); $r = q("SELECT COUNT(*) AS `total` FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid` WHERE `is-default` = 1 AND `user`.`hidewall` = 0 AND MATCH `pub_keywords` AGAINST ('%s') ", @@ -26,7 +26,7 @@ function msearch_post(App $a) { ); if (dbm::is_result($r)) { - foreach ($r as $rr) + foreach($r as $rr) $results[] = array( 'name' => $rr['name'], 'url' => App::get_baseurl() . '/profile/' . $rr['nickname'], diff --git a/mod/network.php b/mod/network.php index d8943a572..a1181a74c 100644 --- a/mod/network.php +++ b/mod/network.php @@ -43,11 +43,11 @@ function network_init(App $a) { if ($remember_group) { $net_baseurl .= '/' . $last_sel_groups; // Note that the group number must come before the "/new" tab selection - } elseif ($sel_groups !== false) { + } elseif($sel_groups !== false) { $net_baseurl .= '/' . $sel_groups; } - if ($remember_tab) { + if($remember_tab) { // redirect if current selected tab is '/network' and // last selected tab is _not_ '/network?f=&order=comment'. // and this isn't a date query @@ -81,19 +81,19 @@ function network_init(App $a) { parse_str( $dest_qs, $dest_qa); $net_args = array_merge($net_args, $dest_qa); } - else if ($sel_tabs[4] === 'active') { + else if($sel_tabs[4] === 'active') { // The '/new' tab is selected $net_baseurl .= '/new'; } - if ($remember_net) { + if($remember_net) { $net_args['nets'] = $last_sel_nets; } - else if ($sel_nets!==false) { + else if($sel_nets!==false) { $net_args['nets'] = $sel_nets; } - if ($remember_tab || $remember_net || $remember_group) { + if($remember_tab || $remember_net || $remember_group) { $net_args = array_merge($query_array, $net_args); $net_queries = build_querystring($net_args); @@ -103,7 +103,7 @@ function network_init(App $a) { } } - if (x($_GET['nets']) && $_GET['nets'] === 'all') + if(x($_GET['nets']) && $_GET['nets'] === 'all') unset($_GET['nets']); $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0); @@ -115,12 +115,12 @@ function network_init(App $a) { require_once('include/items.php'); require_once('include/ForumManager.php'); - if (! x($a->page,'aside')) + if(! x($a->page,'aside')) $a->page['aside'] = ''; $search = ((x($_GET,'search')) ? escape_tags($_GET['search']) : ''); - if (x($_GET,'save')) { + if(x($_GET,'save')) { $r = qu("SELECT * FROM `search` WHERE `uid` = %d AND `term` = '%s' LIMIT 1", intval(local_user()), dbesc($search) @@ -132,7 +132,7 @@ function network_init(App $a) { ); } } - if (x($_GET,'remove')) { + if(x($_GET,'remove')) { q("DELETE FROM `search` WHERE `uid` = %d AND `term` = '%s'", intval(local_user()), dbesc($search) @@ -140,7 +140,7 @@ function network_init(App $a) { } // search terms header - if (x($_GET,'search')) { + if(x($_GET,'search')) { $a->page['content'] .= replace_macros(get_markup_template("section_title.tpl"),array( '$title' => sprintf( t('Results for: %s'), $search) )); @@ -157,7 +157,7 @@ function network_init(App $a) { function saved_searches($search) { - if (! feature_enabled(local_user(),'savedsearch')) + if(! feature_enabled(local_user(),'savedsearch')) return ''; $a = get_app(); @@ -232,28 +232,28 @@ function network_query_get_sel_tab(App $a) { $spam_active = ''; $postord_active = ''; - if (($a->argc > 1 && $a->argv[1] === 'new') + if(($a->argc > 1 && $a->argv[1] === 'new') || ($a->argc > 2 && $a->argv[2] === 'new')) { $new_active = 'active'; } - if (x($_GET,'search')) { + if(x($_GET,'search')) { $search_active = 'active'; } - if (x($_GET,'star')) { + if(x($_GET,'star')) { $starred_active = 'active'; } - if (x($_GET,'bmark')) { + if(x($_GET,'bmark')) { $bookmarked_active = 'active'; } - if (x($_GET,'conv')) { + if(x($_GET,'conv')) { $conv_active = 'active'; } - if (x($_GET,'spam')) { + if(x($_GET,'spam')) { $spam_active = 'active'; } @@ -285,7 +285,7 @@ function network_query_get_sel_tab(App $a) { function network_query_get_sel_net() { $network = false; - if (x($_GET,'nets')) { + if(x($_GET,'nets')) { $network = $_GET['nets']; } @@ -295,7 +295,7 @@ function network_query_get_sel_net() { function network_query_get_sel_group(App $a) { $group = false; - if ($a->argc >= 2 && is_numeric($a->argv[1])) { + if($a->argc >= 2 && is_numeric($a->argv[1])) { $group = $a->argv[1]; } @@ -326,18 +326,20 @@ function network_content(App $a, $update = 0) { $nouveau = false; - if ($a->argc > 1) { - for ($x = 1; $x < $a->argc; $x ++) { - if (is_a_date_arg($a->argv[$x])) { - if ($datequery) { + if($a->argc > 1) { + for($x = 1; $x < $a->argc; $x ++) { + if(is_a_date_arg($a->argv[$x])) { + if($datequery) $datequery2 = escape_tags($a->argv[$x]); - } else { + else { $datequery = escape_tags($a->argv[$x]); $_GET['order'] = 'post'; } - } elseif ($a->argv[$x] === 'new') { + } + elseif($a->argv[$x] === 'new') { $nouveau = true; - } elseif (intval($a->argv[$x])) { + } + elseif(intval($a->argv[$x])) { $group = intval($a->argv[$x]); $def_acl = array('allow_gid' => '<' . $group . '>'); } @@ -366,12 +368,12 @@ function network_content(App $a, $update = 0) { - if (x($_GET,'search') || x($_GET,'file')) + if(x($_GET,'search') || x($_GET,'file')) $nouveau = true; - if ($cid) + if($cid) $def_acl = array('allow_cid' => '<' . intval($cid) . '>'); - if ($nets) { + if($nets) { $r = qu("SELECT `id` FROM `contact` WHERE `uid` = %d AND network = '%s' AND `self` = 0", intval(local_user()), dbesc($nets) @@ -379,19 +381,19 @@ function network_content(App $a, $update = 0) { $str = ''; if (dbm::is_result($r)) - foreach ($r as $rr) + foreach($r as $rr) $str .= '<' . $rr['id'] . '>'; - if (strlen($str)) + if(strlen($str)) $def_acl = array('allow_cid' => $str); } set_pconfig(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all')); - if (!$update AND !$rawmode) { + if(!$update AND !$rawmode) { $tabs = network_tabs($a); $o .= $tabs; - if ($group) { - if (($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) { + if($group) { + if(($t = group_public_members($group)) && (! get_pconfig(local_user(),'system','nowarn_insecure'))) { notice(sprintf(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.", "Warning: This group contains %s members from a network that doesn't allow non public messages.", $t), $t).EOL); @@ -455,13 +457,13 @@ function network_content(App $a, $update = 0) { $sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : ''); - if ($group) { + if($group) { $r = qu("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($group), intval($_SESSION['uid']) ); if (! dbm::is_result($r)) { - if ($update) + if($update) killme(); notice( t('No such group') . EOL ); goaway('network/0'); @@ -471,7 +473,7 @@ function network_content(App $a, $update = 0) { $contacts = expand_groups(array($group)); $gcontacts = expand_groups(array($group), false, true); - if ((is_array($contacts)) && count($contacts)) { + if((is_array($contacts)) && count($contacts)) { $contact_str_self = ""; $gcontact_str_self = ""; @@ -498,7 +500,7 @@ function network_content(App $a, $update = 0) { )) . $o; } - elseif ($cid) { + elseif($cid) { $r = qu("SELECT `id`,`name`,`network`,`writable`,`nurl`, `forum`, `prv`, `contact-type`, `addr`, `thumb`, `location` FROM `contact` WHERE `id` = %d AND (NOT `blocked` OR `pending`) LIMIT 1", @@ -522,7 +524,7 @@ function network_content(App $a, $update = 0) { 'id' => 'network', )) . $o; - if ($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) { + if($r[0]['network'] === NETWORK_OSTATUS && $r[0]['writable'] && (! get_pconfig(local_user(),'system','nowarn_insecure'))) { notice( t('Private messages to this person are at risk of public disclosure.') . EOL); } @@ -534,15 +536,15 @@ function network_content(App $a, $update = 0) { } } - if ((! $group) && (! $cid) && (! $update) && (! get_config('theme','hide_eventlist'))) { + if((! $group) && (! $cid) && (! $update) && (! get_config('theme','hide_eventlist'))) { $o .= get_birthdays(); $o .= get_events(); } - if ($datequery) { + if($datequery) { $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery)))); } - if ($datequery2) { + if($datequery2) { $sql_extra3 .= protect_sprintf(sprintf(" AND $sql_table.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); } @@ -553,10 +555,10 @@ function network_content(App $a, $update = 0) { $order_mode = "received"; $tag = false; - if (x($_GET,'search')) { + if(x($_GET,'search')) { $search = escape_tags($_GET['search']); - if (strpos($search,'#') === 0) { + if(strpos($search,'#') === 0) { $tag = true; $search = substr($search,1); } @@ -564,7 +566,7 @@ function network_content(App $a, $update = 0) { if (get_config('system','only_tag_search')) $tag = true; - if ($tag) { + if($tag) { $sql_extra = ""; $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", @@ -581,17 +583,17 @@ function network_content(App $a, $update = 0) { $order_mode = "id"; } } - if (strlen($file)) { + if(strlen($file)) { $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ", dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user())); $sql_order = "`item`.`id`"; $order_mode = "id"; } - if ($conv) + if($conv) $sql_extra3 .= " AND $sql_table.`mention`"; - if ($update) { + if($update) { // only setup pagination on initial page view $pager_sql = ''; @@ -609,14 +611,14 @@ function network_content(App $a, $update = 0) { // now that we have the user settings, see if the theme forces // a maximum item number which is lower then the user choice - if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) + if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) $itemspage_network = $a->force_max_items; $a->set_pager_itemspage($itemspage_network); $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); } - if ($nouveau) { + if($nouveau) { $simple_update = (($update) ? " AND `item`.`unseen` " : ''); if ($sql_order == "") @@ -638,7 +640,7 @@ function network_content(App $a, $update = 0) { // Normal conversation view - if ($order === 'post') { + if($order === 'post') { $ordering = "`created`"; if ($sql_order == "") $order_mode = "created"; @@ -655,7 +657,7 @@ function network_content(App $a, $update = 0) { $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"])); // Fetch a page full of parent items for this page - if ($update) { + if($update) { if (get_config("system", "like_no_comment")) $sql_extra4 = " AND `item`.`verb` = '".ACTIVITY_POST."'"; else @@ -689,8 +691,8 @@ function network_content(App $a, $update = 0) { $date_offset = ""; if (dbm::is_result($r)) { - foreach ($r as $rr) - if (! in_array($rr['item_id'],$parents_arr)) + foreach($r as $rr) + if(! in_array($rr['item_id'],$parents_arr)) $parents_arr[] = $rr['item_id']; $parents_str = implode(", ", $parents_arr); @@ -728,7 +730,7 @@ function network_content(App $a, $update = 0) { $a->page_offset = $date_offset; - if ($parents_str) + if($parents_str) $update_unseen = ' WHERE uid = ' . intval(local_user()) . ' AND unseen = 1 AND parent IN ( ' . dbesc($parents_str) . ' )'; } @@ -822,7 +824,7 @@ function network_tabs(App $a) { ), ); - if (feature_enabled(local_user(),'personal_tab')) { + if(feature_enabled(local_user(),'personal_tab')) { $tabs[] = array( 'label' => t('Personal'), 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1', @@ -833,7 +835,7 @@ function network_tabs(App $a) { ); } - if (feature_enabled(local_user(),'new_tab')) { + if(feature_enabled(local_user(),'new_tab')) { $tabs[] = array( 'label' => t('New'), 'url' => str_replace('/new', '', $cmd) . ($len_naked_cmd ? '/' : '') . 'new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''), @@ -844,7 +846,7 @@ function network_tabs(App $a) { ); } - if (feature_enabled(local_user(),'link_tab')) { + if(feature_enabled(local_user(),'link_tab')) { $tabs[] = array( 'label' => t('Shared Links'), 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&bmark=1', @@ -855,7 +857,7 @@ function network_tabs(App $a) { ); } - if (feature_enabled(local_user(),'star_posts')) { + if(feature_enabled(local_user(),'star_posts')) { $tabs[] = array( 'label' => t('Starred'), 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1', @@ -867,7 +869,7 @@ function network_tabs(App $a) { } // save selected tab, but only if not in search or file mode - if (!x($_GET,'search') && !x($_GET,'file')) { + if(!x($_GET,'search') && !x($_GET,'file')) { set_pconfig( local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) ); } diff --git a/mod/newmember.php b/mod/newmember.php index eef6b1263..a5e41f1e2 100644 --- a/mod/newmember.php +++ b/mod/newmember.php @@ -47,9 +47,8 @@ function newmember_content(App $a) { $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); - if (! $mail_disabled) { + if(! $mail_disabled) $o .= '
  • ' . '' . t('Importing Emails') . '
    ' . t('Enter your email access information on your Connector Settings page if you wish to import and interact with friends or mailing lists from your email INBOX') . '
  • ' . EOL; - } $o .= '
  • ' . '' . t('Go to Your Contacts Page') . '
    ' . t('Your Contacts page is your gateway to managing friendships and connecting with friends on other networks. Typically you enter their address or site URL in the Add New Contact dialog.') . '
  • ' . EOL; @@ -65,7 +64,7 @@ function newmember_content(App $a) { $o .= '
  • ' . '' . t('Group Your Contacts') . '
    ' . t('Once you have made some friends, organize them into private conversation groups from the sidebar of your Contacts page and then you can interact with each group privately on your Network page.') . '
  • ' . EOL; - if (get_config('system', 'newuser_private')) { + if(get_config('system', 'newuser_private')) { $o .= '
  • ' . '' . t("Why Aren't My Posts Public?") . '
    ' . t("Friendica respects your privacy. By default, your posts will only show up to people you've added as friends. For more information, see the help section from the link above.") . '
  • ' . EOL; } diff --git a/mod/nodeinfo.php b/mod/nodeinfo.php index ffc494689..6f2049475 100644 --- a/mod/nodeinfo.php +++ b/mod/nodeinfo.php @@ -158,7 +158,7 @@ function nodeinfo_cron() { $plugins = get_config("system","addon"); $plugins_arr = array(); - if ($plugins) { + if($plugins) { $plugins_arr = explode(",",str_replace(" ", "",$plugins)); $idx = array_search($plugin, $plugins_arr); @@ -175,10 +175,10 @@ function nodeinfo_cron() { $last = get_config('nodeinfo','last_calucation'); - if ($last) { + if($last) { // Calculate every 24 hours $next = $last + (24 * 60 * 60); - if ($next > time()) { + if($next > time()) { logger("calculation intervall not reached"); return; } diff --git a/mod/noscrape.php b/mod/noscrape.php index e9655f20b..83ab71ce1 100644 --- a/mod/noscrape.php +++ b/mod/noscrape.php @@ -2,14 +2,13 @@ function noscrape_init(App $a) { - if ($a->argc > 1) { + if($a->argc > 1) $which = $a->argv[1]; - } else { + else killme(); - } $profile = 0; - if ((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) { + if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) { $which = $a->user['nickname']; $profile = $a->argv[1]; } diff --git a/mod/notes.php b/mod/notes.php index bc80c24da..c7cfe8d70 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -43,7 +43,7 @@ function notes_content(App $a, $update = false) { $o =""; $o .= profile_tabs($a,True); - if (! $update) { + if(! $update) { $o .= '

    ' . t('Personal Notes') . '

    '; $commpage = false; @@ -104,9 +104,8 @@ function notes_content(App $a, $update = false) { $parents_str = ''; if (dbm::is_result($r)) { - foreach ($r as $rr) { + foreach($r as $rr) $parents_arr[] = $rr['item_id']; - } $parents_str = implode(', ', $parents_arr); $r = q("SELECT %s FROM `item` %s diff --git a/mod/notifications.php b/mod/notifications.php index e9e5081cb..0c08b66ce 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -17,10 +17,10 @@ function notifications_post(App $a) { $request_id = (($a->argc > 1) ? $a->argv[1] : 0); - if ($request_id === "all") + if($request_id === "all") return; - if ($request_id) { + if($request_id) { $r = q("SELECT * FROM `intro` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($request_id), @@ -41,11 +41,11 @@ function notifications_post(App $a) { $fid = $r[0]['fid']; - if ($_POST['submit'] == t('Discard')) { + if($_POST['submit'] == t('Discard')) { $r = q("DELETE FROM `intro` WHERE `id` = %d", intval($intro_id) ); - if (! $fid) { + if(! $fid) { // The check for blocked and pending is in case the friendship was already approved // and we just want to get rid of the now pointless notification @@ -57,7 +57,7 @@ function notifications_post(App $a) { } goaway('notifications/intros'); } - if ($_POST['submit'] == t('Ignore')) { + if($_POST['submit'] == t('Ignore')) { $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d", intval($intro_id)); goaway('notifications/intros'); @@ -91,7 +91,7 @@ function notifications_content(App $a) { $startrec = ($page * $perpage) - $perpage; // Get introductions - if ( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) { + if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) { nav_set_selected('introductions'); $notif_header = t('Notifications'); @@ -100,25 +100,25 @@ function notifications_content(App $a) { $notifs = $nm->introNotifs($all, $startrec, $perpage); // Get the network notifications - } elseif (($a->argc > 1) && ($a->argv[1] == 'network')) { + } else if (($a->argc > 1) && ($a->argv[1] == 'network')) { $notif_header = t('Network Notifications'); $notifs = $nm->networkNotifs($show, $startrec, $perpage); // Get the system notifications - } elseif (($a->argc > 1) && ($a->argv[1] == 'system')) { + } else if (($a->argc > 1) && ($a->argv[1] == 'system')) { $notif_header = t('System Notifications'); $notifs = $nm->systemNotifs($show, $startrec, $perpage); // Get the personal notifications - } elseif (($a->argc > 1) && ($a->argv[1] == 'personal')) { + } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) { $notif_header = t('Personal Notifications'); $notifs = $nm->personalNotifs($show, $startrec, $perpage); // Get the home notifications - } elseif (($a->argc > 1) && ($a->argv[1] == 'home')) { + } else if (($a->argc > 1) && ($a->argv[1] == 'home')) { $notif_header = t('Home Notifications'); $notifs = $nm->homeNotifs($show, $startrec, $perpage); @@ -135,13 +135,13 @@ function notifications_content(App $a) { $notifs['page'] = $a->pager['page']; // Json output - if (intval($json) === 1) + if(intval($json) === 1) json_return_and_die($notifs); $notif_tpl = get_markup_template('notifications.tpl'); // Process the data for template creation - if ($notifs['ident'] === 'introductions') { + if($notifs['ident'] === 'introductions') { $sugg = get_markup_template('suggestions.tpl'); $tpl = get_markup_template("intros.tpl"); @@ -190,8 +190,8 @@ function notifications_content(App $a) { $knowyou = ''; $dfrn_text = ''; - if ($it['network'] === NETWORK_DFRN || $it['network'] === NETWORK_DIASPORA) { - if ($it['network'] === NETWORK_DFRN) { + if($it['network'] === NETWORK_DFRN || $it['network'] === NETWORK_DIASPORA) { + if($it['network'] === NETWORK_DFRN) { $lbl_knowyou = t('Claims to be known to you: '); $knowyou = (($it['knowyou']) ? t('yes') : t('no')); $helptext = t('Shall your connection be bidirectional or not?'); @@ -262,7 +262,7 @@ function notifications_content(App $a) { } } - if ($notifs['total'] == 0) + if($notifs['total'] == 0) info( t('No introductions.') . EOL); // Normal notifications (no introductions) @@ -301,7 +301,7 @@ function notifications_content(App $a) { // It doesn't make sense to show the Show unread / Show all link visible if the user is on the // "Show all" page and there are no notifications. So we will hide it. - if ($show == 0 || intval($show) && $notifs['total'] > 0) { + if($show == 0 || intval($show) && $notifs['total'] > 0) { $notif_show_lnk = array( 'href' => ($show ? 'notifications/'.$notifs['ident'] : 'notifications/'.$notifs['ident'].'?show=all' ), 'text' => ($show ? t('Show unread') : t('Show all')), @@ -309,9 +309,8 @@ function notifications_content(App $a) { } // Output if there aren't any notifications available - if ($notifs['total'] == 0) { + if($notifs['total'] == 0) $notif_nocontent = sprintf( t('No more %s notifications.'), $notifs['ident']); - } } $o .= replace_macros($notif_tpl, array( diff --git a/mod/openid.php b/mod/openid.php index e11267d81..b45cd9797 100644 --- a/mod/openid.php +++ b/mod/openid.php @@ -7,20 +7,20 @@ require_once('library/openid.php'); function openid_content(App $a) { $noid = get_config('system','no_openid'); - if ($noid) + if($noid) goaway(z_root()); logger('mod_openid ' . print_r($_REQUEST,true), LOGGER_DATA); - if ((x($_GET,'openid_mode')) && (x($_SESSION,'openid'))) { + if((x($_GET,'openid_mode')) && (x($_SESSION,'openid'))) { $openid = new LightOpenID; - if ($openid->validate()) { + if($openid->validate()) { $authid = $_REQUEST['openid_identity']; - if (! strlen($authid)) { + if(! strlen($authid)) { logger( t('OpenID protocol error. No ID returned.') . EOL); goaway(z_root()); } @@ -69,10 +69,10 @@ function openid_content(App $a) { if ($k === 'namePerson/friendly') { $nick = notags(trim($v)); } - if ($k === 'namePerson/first') { + if($k === 'namePerson/first') { $first = notags(trim($v)); } - if ($k === 'namePerson') { + if($k === 'namePerson') { $args .= '&username=' . notags(trim($v)); } if ($k === 'contact/email') { diff --git a/mod/parse_url.php b/mod/parse_url.php index 0888db101..77529714f 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -59,7 +59,7 @@ function parse_url_content(App $a) { $redirects = 0; // Fetch the header of the URL $result = z_fetch_url($url, false, $redirects, array("novalidate" => true, "nobody" => true)); - if ($result["success"]) { + if($result["success"]) { // Convert the header fields into an array $hdrs = array(); $h = explode("\n", $result["header"]); @@ -71,7 +71,7 @@ function parse_url_content(App $a) { $type = $hdrs["Content-Type"]; } if ($type) { - if (stripos($type, "image/") !== false) { + if(stripos($type, "image/") !== false) { echo $br . "[img]" . $url . "[/img]" . $br; killme(); } diff --git a/mod/photo.php b/mod/photo.php index 71c92ffe2..6562599ca 100644 --- a/mod/photo.php +++ b/mod/photo.php @@ -36,7 +36,7 @@ function photo_init(App $a) { header('Etag: '.$_SERVER['HTTP_IF_NONE_MATCH']); header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT"); header("Cache-Control: max-age=31536000"); - if (function_exists('header_remove')) { + if(function_exists('header_remove')) { header_remove('Last-Modified'); header_remove('Expires'); header_remove('Cache-Control'); @@ -46,7 +46,7 @@ function photo_init(App $a) { $default = 'images/person-175.jpg'; - if (isset($type)) { + if(isset($type)) { /** @@ -80,22 +80,23 @@ function photo_init(App $a) { $data = $r[0]['data']; $mimetype = $r[0]['type']; } - if (! isset($data)) { + if(! isset($data)) { $data = file_get_contents($default); $mimetype = 'image/jpeg'; } - } else { + } + else { /** * Other photos */ $resolution = 0; - foreach ( Photo::supportedTypes() as $m=>$e){ + foreach( Photo::supportedTypes() as $m=>$e){ $photo = str_replace(".$e",'',$photo); } - if (substr($photo,-2,1) == '-') { + if(substr($photo,-2,1) == '-') { $resolution = intval(substr($photo,-1,1)); $photo = substr($photo,0,-2); } @@ -133,8 +134,8 @@ function photo_init(App $a) { } } - if (! isset($data)) { - if (isset($resolution)) { + if(! isset($data)) { + if(isset($resolution)) { switch($resolution) { case 4: @@ -160,8 +161,8 @@ function photo_init(App $a) { // Resize only if its not a GIF if ($mime != "image/gif") { $ph = new Photo($data, $mimetype); - if ($ph->is_valid()) { - if (isset($customres) && $customres > 0 && $customres < 500) { + if($ph->is_valid()) { + if(isset($customres) && $customres > 0 && $customres < 500) { $ph->scaleImageSquare($customres); } $data = $ph->imageString(); @@ -169,14 +170,14 @@ function photo_init(App $a) { } } - if (function_exists('header_remove')) { + if(function_exists('header_remove')) { header_remove('Pragma'); header_remove('pragma'); } header("Content-type: ".$mimetype); - if ($prvcachecontrol) { + if($prvcachecontrol) { // it is a private photo that they have no permission to view. // tell the browser not to cache it, in case they authenticate diff --git a/mod/photos.php b/mod/photos.php index 910d03d00..27d8499c2 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1345,11 +1345,10 @@ function photos_content(App $a) { // The query leads to a really intense used index. // By now we hide it if someone wants to. if (!Config::get('system', 'no_count', false)) { - if ($_GET['order'] === 'posted') { + if ($_GET['order'] === 'posted') $order = 'ASC'; - } else { + else $order = 'DESC'; - } $prvnxt = qu("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0 $sql_extra ORDER BY `created` $order ", @@ -1357,17 +1356,15 @@ function photos_content(App $a) { intval($owner_uid) ); - if (dbm::is_result($prvnxt)) { + if (count($prvnxt)) { for($z = 0; $z < count($prvnxt); $z++) { if ($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) { $prv = $z - 1; $nxt = $z + 1; - if ($prv < 0) { + if ($prv < 0) $prv = count($prvnxt) - 1; - } - if ($nxt >= count($prvnxt)) { + if ($nxt >= count($prvnxt)) $nxt = 0; - } break; } } @@ -1377,9 +1374,8 @@ function photos_content(App $a) { } } - if (count($ph) == 1) { + if (count($ph) == 1) $hires = $lores = $ph[0]; - } if (count($ph) > 1) { if ($ph[1]['scale'] == 2) { // original is 640 or less, we can display it directly diff --git a/mod/ping.php b/mod/ping.php index 35a9b4520..b5330c7b3 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -216,7 +216,7 @@ function ping_init(App $a) if ($all_events) { $str_now = datetime_convert('UTC', $a->timezone, 'now', 'Y-m-d'); - foreach ($ev as $x) { + foreach($ev as $x) { $bd = false; if ($x['type'] === 'birthday') { $birthdays ++; @@ -486,7 +486,7 @@ function ping_get_notifications($uid) function ping_format_xml_data($data, $sysnotify, $notifs, $sysmsgs, $sysmsgs_info, $groups_unseen, $forums_unseen) { $notifications = array(); - foreach ($notifs as $key => $notif) { + foreach($notifs as $key => $notif) { $notifications[$key . ':note'] = $notif['message']; $notifications[$key . ':@attributes'] = array( diff --git a/mod/poco.php b/mod/poco.php index c5f5427b9..30648acab 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -157,27 +157,27 @@ function poco_init(App $a) { if (x($_GET,'updatedSince') AND !$global) { $ret['updatedSince'] = false; } - $ret['startIndex'] = (int) $startIndex; $ret['itemsPerPage'] = (int) $itemsPerPage; $ret['totalResults'] = (int) $totalResults; $ret['entry'] = array(); + $fields_ret = array( - 'id' => false, - 'displayName' => false, - 'urls' => false, - 'updated' => false, + 'id' => false, + 'displayName' => false, + 'urls' => false, + 'updated' => false, 'preferredUsername' => false, - 'photos' => false, - 'aboutMe' => false, - 'currentLocation' => false, - 'network' => false, - 'gender' => false, - 'tags' => false, - 'address' => false, - 'contactType' => false, - 'generation' => false + 'photos' => false, + 'aboutMe' => false, + 'currentLocation' => false, + 'network' => false, + 'gender' => false, + 'tags' => false, + 'address' => false, + 'contactType' => false, + 'generation' => false ); if ((! x($_GET,'fields')) || ($_GET['fields'] === '@all')) { @@ -207,17 +207,14 @@ function poco_init(App $a) { if (($rr['about'] == "") AND isset($rr['pabout'])) { $rr['about'] = $rr['pabout']; } - if ($rr['location'] == "") { if (isset($rr['plocation'])) { $rr['location'] = $rr['plocation']; } - if (isset($rr['pregion']) AND ($rr['pregion'] != "")) { if ($rr['location'] != "") { $rr['location'] .= ", "; } - $rr['location'] .= $rr['pregion']; } @@ -295,7 +292,6 @@ function poco_init(App $a) { } else { $entry['updated'] = $rr['updated']; } - $entry['updated'] = date("c", strtotime($entry['updated'])); } if ($fields_ret['photos']) { @@ -349,7 +345,6 @@ function poco_init(App $a) { if ($fields_ret['contactType']) { $entry['contactType'] = intval($rr['contact-type']); } - $ret['entry'][] = $entry; } } else { @@ -358,7 +353,6 @@ function poco_init(App $a) { } else { http_status_exit(500); } - logger("End of poco", LOGGER_DEBUG); if ($format === 'xml') { @@ -373,5 +367,4 @@ function poco_init(App $a) { } else { http_status_exit(500); } - } diff --git a/mod/poke.php b/mod/poke.php index ea0093e1d..5161129b3 100644 --- a/mod/poke.php +++ b/mod/poke.php @@ -63,7 +63,7 @@ function poke_init(App $a) { $target = $r[0]; - if ($parent) { + if($parent) { $r = q("SELECT `uri`, `private`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` FROM `item` WHERE `id` = %d AND `parent` = %d AND `uid` = %d LIMIT 1", intval($parent), @@ -129,7 +129,7 @@ function poke_init(App $a) { $arr['object'] .= '' . "\n"; $item_id = item_store($arr); - if ($item_id) { + if($item_id) { //q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d", // dbesc(App::get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id), // intval($uid), @@ -158,7 +158,7 @@ function poke_content(App $a) { $name = ''; $id = ''; - if (intval($_GET['c'])) { + if(intval($_GET['c'])) { $r = q("SELECT `id`,`name` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($_GET['c']), intval(local_user()) @@ -185,11 +185,9 @@ function poke_content(App $a) { $verbs = get_poke_verbs(); $shortlist = array(); - foreach ($verbs as $k => $v) { - if ($v[1] !== 'NOTRANSLATION') { + foreach($verbs as $k => $v) + if($v[1] !== 'NOTRANSLATION') $shortlist[] = array($k,$v[1]); - } - } $tpl = get_markup_template('poke_content.tpl'); diff --git a/mod/post.php b/mod/post.php index 98a32711c..c8a88e66c 100644 --- a/mod/post.php +++ b/mod/post.php @@ -16,7 +16,8 @@ function post_post(App $a) { if ($a->argc == 1) { $bulk_delivery = true; - } else { + } + else { $nickname = $a->argv[2]; $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1", @@ -33,17 +34,15 @@ function post_post(App $a) { logger('mod-post: new zot: ' . $xml, LOGGER_DATA); - if (! $xml) { + if(! $xml) http_status_exit(500); - } $msg = zot_decode($importer,$xml); logger('mod-post: decoded msg: ' . print_r($msg,true), LOGGER_DATA); - if (! is_array($msg)) { + if(! is_array($msg)) http_status_exit(500); - } $ret = 0; $ret = zot_incoming($bulk_delivery, $importer,$msg); diff --git a/mod/pretheme.php b/mod/pretheme.php index 52e63cef3..6dd6b781a 100644 --- a/mod/pretheme.php +++ b/mod/pretheme.php @@ -2,15 +2,16 @@ function pretheme_init(App $a) { - if ($_REQUEST['theme']) { + if($_REQUEST['theme']) { $theme = $_REQUEST['theme']; $info = get_theme_info($theme); - if ($info) { + if($info) { // unfortunately there will be no translation for this string $desc = $info['description']; $version = $info['version']; $credits = $info['credits']; - } else { + } + else { $desc = ''; $version = ''; $credits = ''; diff --git a/mod/probe.php b/mod/probe.php index 3c2497b2f..95f856bfa 100644 --- a/mod/probe.php +++ b/mod/probe.php @@ -12,7 +12,7 @@ function probe_content(App $a) { $o .= '

    '; - if (x($_GET,'addr')) { + if(x($_GET,'addr')) { $addr = trim($_GET['addr']); $res = probe_url($addr); diff --git a/mod/profile.php b/mod/profile.php index 15f49db53..fbce509d2 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -6,17 +6,17 @@ require_once('include/redir.php'); function profile_init(App $a) { - if (! x($a->page,'aside')) { + if(! x($a->page,'aside')) $a->page['aside'] = ''; - } - if ($a->argc > 1) { + if($a->argc > 1) $which = htmlspecialchars($a->argv[1]); - }else { + else { $r = q("select nickname from user where blocked = 0 and account_expired = 0 and account_removed = 0 and verified = 1 order by rand() limit 1"); if (dbm::is_result($r)) { goaway(App::get_baseurl() . '/profile/' . $r[0]['nickname']); - } else { + } + else { logger('profile error: mod_profile ' . $a->query_string, LOGGER_DEBUG); notice( t('Requested profile is not available.') . EOL ); $a->error = 404; @@ -25,10 +25,11 @@ function profile_init(App $a) { } $profile = 0; - if ((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) { + if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) { $which = $a->user['nickname']; $profile = htmlspecialchars($a->argv[1]); - } else { + } + else { auto_redir($a, $which); } @@ -37,7 +38,7 @@ function profile_init(App $a) { $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false); $userblock = (($a->profile['hidewall'] && (! local_user()) && (! remote_user())) ? true : false); - if ((x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY)) { + if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY)) { $a->page['htmlhead'] .= ''; } if (x($a->profile,'openidserver')) { @@ -51,7 +52,7 @@ function profile_init(App $a) { if ((! $blocked) && (! $userblock)) { $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : ''); $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords); - if (strlen($keywords)) + if(strlen($keywords)) $a->page['htmlhead'] .= '' . "\r\n" ; } @@ -261,7 +262,7 @@ function profile_content(App $a, $update = 0) { } // now that we have the user settings, see if the theme forces // a maximum item number which is lower then the user choice - if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) + if(($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) $itemspage_network = $a->force_max_items; $a->set_pager_itemspage($itemspage_network); @@ -288,9 +289,8 @@ function profile_content(App $a, $update = 0) { $parents_str = ''; if (dbm::is_result($r)) { - foreach ($r as $rr) { + foreach($r as $rr) $parents_arr[] = $rr['item_id']; - } $parents_str = implode(', ', $parents_arr); $items = q(item_query()." AND `item`.`uid` = %d @@ -305,13 +305,13 @@ function profile_content(App $a, $update = 0) { $items = array(); } - if ($is_owner && (! $update) && (! get_config('theme','hide_eventlist'))) { + if($is_owner && (! $update) && (! get_config('theme','hide_eventlist'))) { $o .= get_birthdays(); $o .= get_events(); } - if ($is_owner) { + if($is_owner) { $r = q("UPDATE `item` SET `unseen` = 0 WHERE `wall` = 1 AND `unseen` = 1 AND `uid` = %d", intval(local_user()) diff --git a/mod/profile_photo.php b/mod/profile_photo.php index ea9fc3ea7..f9bf60cf5 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -22,12 +22,12 @@ function profile_photo_post(App $a) { check_form_security_token_redirectOnErr('/profile_photo', 'profile_photo'); - if ((x($_POST,'cropfinal')) && ($_POST['cropfinal'] == 1)) { + if((x($_POST,'cropfinal')) && ($_POST['cropfinal'] == 1)) { // unless proven otherwise $is_default_profile = 1; - if ($_REQUEST['profile']) { + if($_REQUEST['profile']) { $r = q("select id, `is-default` from profile where id = %d and uid = %d limit 1", intval($_REQUEST['profile']), intval(local_user()) @@ -40,14 +40,14 @@ function profile_photo_post(App $a) { // phase 2 - we have finished cropping - if ($a->argc != 2) { + if($a->argc != 2) { notice( t('Image uploaded but image cropping failed.') . EOL ); return; } $image_id = $a->argv[1]; - if (substr($image_id,-2,1) == '-') { + if(substr($image_id,-2,1) == '-') { $scale = substr($image_id,-1,1); $image_id = substr($image_id,0,-2); } @@ -68,7 +68,7 @@ function profile_photo_post(App $a) { $base_image = $r[0]; $im = new Photo($base_image['data'], $base_image['type']); - if ($im->is_valid()) { + if($im->is_valid()) { $im->cropImage(175,$srcX,$srcY,$srcW,$srcH); $r = $im->store(local_user(), 0, $base_image['resource-id'],$base_image['filename'], t('Profile Photos'), 4, $is_default_profile); @@ -95,7 +95,7 @@ function profile_photo_post(App $a) { // If setting for the default profile, unset the profile photo flag from any other photos I own - if ($is_default_profile) { + if($is_default_profile) { $r = q("UPDATE `photo` SET `profile` = 0 WHERE `profile` = 1 AND `resource-id` != '%s' AND `uid` = %d", dbesc($base_image['resource-id']), intval(local_user()) @@ -173,7 +173,7 @@ function profile_photo_post(App $a) { } -if (! function_exists('profile_photo_content')) { +if(! function_exists('profile_photo_content')) { function profile_photo_content(App $a) { if (! local_user()) { @@ -183,10 +183,10 @@ function profile_photo_content(App $a) { $newuser = false; - if ($a->argc == 2 && $a->argv[1] === 'new') + if($a->argc == 2 && $a->argv[1] === 'new') $newuser = true; - if ( $a->argv[1]=='use'){ + if( $a->argv[1]=='use'){ if ($a->argc<3){ notice( t('Permission denied.') . EOL ); return; @@ -206,7 +206,7 @@ function profile_photo_content(App $a) { } $havescale = false; foreach ($r as $rr) { - if ($rr['scale'] == 5) + if($rr['scale'] == 5) $havescale = true; } @@ -245,7 +245,7 @@ function profile_photo_content(App $a) { ); - if (! x($a->config,'imagecrop')) { + if(! x($a->config,'imagecrop')) { $tpl = get_markup_template('profile_photo.tpl'); @@ -283,7 +283,7 @@ function profile_photo_content(App $a) { }} -if (! function_exists('profile_photo_crop_ui_head')) { +if(! function_exists('profile_photo_crop_ui_head')) { function profile_photo_crop_ui_head(App $a, $ph) { $max_length = get_config('system','max_image_length'); if (! $max_length) { diff --git a/mod/profiles.php b/mod/profiles.php index 3d7e9fd96..4e82ceaac 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -10,7 +10,7 @@ function profiles_init(App $a) { return; } - if (($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) { + if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) { $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1", intval($a->argv[2]), intval(local_user()) @@ -34,9 +34,8 @@ function profiles_init(App $a) { intval($a->argv[2]), intval(local_user()) ); - if ($r) { + if($r) info(t('Profile deleted.').EOL); - } goaway('profiles'); return; // NOTREACHED @@ -46,7 +45,7 @@ function profiles_init(App $a) { - if (($a->argc > 1) && ($a->argv[1] === 'new')) { + if(($a->argc > 1) && ($a->argv[1] === 'new')) { check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't'); @@ -74,13 +73,13 @@ function profiles_init(App $a) { ); info( t('New profile created.') . EOL); - if (count($r3) == 1) + if(count($r3) == 1) goaway('profiles/'.$r3[0]['id']); goaway('profiles'); } - if (($a->argc > 2) && ($a->argv[1] === 'clone')) { + if(($a->argc > 2) && ($a->argv[1] === 'clone')) { check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't'); @@ -93,7 +92,7 @@ function profiles_init(App $a) { intval(local_user()), intval($a->argv[2]) ); - if (! dbm::is_result($r1)) { + if(! dbm::is_result($r1)) { notice( t('Profile unavailable to clone.') . EOL); killme(); return; @@ -126,7 +125,7 @@ function profiles_init(App $a) { } - if (($a->argc > 1) && (intval($a->argv[1]))) { + if(($a->argc > 1) && (intval($a->argv[1]))) { $r = q("SELECT id FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[1]), intval(local_user()) @@ -172,12 +171,12 @@ function profiles_post(App $a) { call_hooks('profile_post', $_POST); - if (($a->argc > 1) && ($a->argv[1] !== "new") && intval($a->argv[1])) { + if(($a->argc > 1) && ($a->argv[1] !== "new") && intval($a->argv[1])) { $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[1]), intval(local_user()) ); - if (! count($orig)) { + if(! count($orig)) { notice( t('Profile not found.') . EOL); return; } @@ -187,7 +186,7 @@ function profiles_post(App $a) { $is_default = (($orig[0]['is-default']) ? 1 : 0); $profile_name = notags(trim($_POST['profile_name'])); - if (! strlen($profile_name)) { + if(! strlen($profile_name)) { notice( t('Profile Name is required.') . EOL); return; } @@ -195,27 +194,27 @@ function profiles_post(App $a) { $dob = $_POST['dob'] ? escape_tags(trim($_POST['dob'])) : '0000-00-00'; // FIXME: Needs to be validated? $y = substr($dob,0,4); - if ((! ctype_digit($y)) || ($y < 1900)) + if((! ctype_digit($y)) || ($y < 1900)) $ignore_year = true; else $ignore_year = false; - if ($dob != '0000-00-00') { - if (strpos($dob,'0000-') === 0) { + if($dob != '0000-00-00') { + if(strpos($dob,'0000-') === 0) { $ignore_year = true; $dob = substr($dob,5); } $dob = datetime_convert('UTC','UTC',(($ignore_year) ? '1900-' . $dob : $dob),(($ignore_year) ? 'm-d' : 'Y-m-d')); - if ($ignore_year) + if($ignore_year) $dob = '0000-' . $dob; } $name = notags(trim($_POST['name'])); - if (! strlen($name)) { + if(! strlen($name)) { $name = '[No Name]'; } - if ($orig[0]['name'] != $name) + if($orig[0]['name'] != $name) $namechanged = true; @@ -234,7 +233,7 @@ function profiles_post(App $a) { $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : ''); - if (! strlen($howlong)) { + if(! strlen($howlong)) { $howlong = NULL_DATE; } else { $howlong = datetime_convert(date_default_timezone_get(),'UTC',$howlong); @@ -243,34 +242,34 @@ function profiles_post(App $a) { $withchanged = false; - if (strlen($with)) { - if ($with != strip_tags($orig[0]['with'])) { + if(strlen($with)) { + if($with != strip_tags($orig[0]['with'])) { $withchanged = true; $prf = ''; $lookup = $with; - if (strpos($lookup,'@') === 0) { + if(strpos($lookup,'@') === 0) $lookup = substr($lookup,1); - } $lookup = str_replace('_',' ', $lookup); - if (strpos($lookup,'@') || (strpos($lookup,'http://'))) { + if(strpos($lookup,'@') || (strpos($lookup,'http://'))) { $newname = $lookup; - /// @TODO Maybe kill those error/debugging-surpressing @ characters $links = @Probe::lrdd($lookup); - if (count($links)) { - foreach ($links as $link) { - if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') { + if(count($links)) { + foreach($links as $link) { + if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') { $prf = $link['@attributes']['href']; } } } - } else { + } + else { $newname = $lookup; -/* if (strstr($lookup,' ')) { +/* if(strstr($lookup,' ')) { $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", dbesc($newname), intval(local_user()) ); - } else { + } + else { $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1", dbesc($lookup), intval(local_user()) @@ -281,7 +280,7 @@ function profiles_post(App $a) { dbesc($newname), intval(local_user()) ); - if (! $r) { + if(! $r) { $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1", dbesc($lookup), intval(local_user()) @@ -293,9 +292,9 @@ function profiles_post(App $a) { } } - if ($prf) { + if($prf) { $with = str_replace($lookup,'' . $newname . '', $with); - if (strpos($with,'@') === 0) + if(strpos($with,'@') === 0) $with = substr($with,1); } } @@ -334,61 +333,61 @@ function profiles_post(App $a) { $changes = array(); $value = ''; - if ($is_default) { - if ($marital != $orig[0]['marital']) { + if($is_default) { + if($marital != $orig[0]['marital']) { $changes[] = '[color=#ff0000]♥[/color] ' . t('Marital Status'); $value = $marital; } - if ($withchanged) { + if($withchanged) { $changes[] = '[color=#ff0000]♥[/color] ' . t('Romantic Partner'); $value = strip_tags($with); } - if ($likes != $orig[0]['likes']) { + if($likes != $orig[0]['likes']) { $changes[] = t('Likes'); $value = $likes; } - if ($dislikes != $orig[0]['dislikes']) { + if($dislikes != $orig[0]['dislikes']) { $changes[] = t('Dislikes'); $value = $dislikes; } - if ($work != $orig[0]['work']) { + if($work != $orig[0]['work']) { $changes[] = t('Work/Employment'); } - if ($religion != $orig[0]['religion']) { + if($religion != $orig[0]['religion']) { $changes[] = t('Religion'); $value = $religion; } - if ($politic != $orig[0]['politic']) { + if($politic != $orig[0]['politic']) { $changes[] = t('Political Views'); $value = $politic; } - if ($gender != $orig[0]['gender']) { + if($gender != $orig[0]['gender']) { $changes[] = t('Gender'); $value = $gender; } - if ($sexual != $orig[0]['sexual']) { + if($sexual != $orig[0]['sexual']) { $changes[] = t('Sexual Preference'); $value = $sexual; } - if ($xmpp != $orig[0]['xmpp']) { + if($xmpp != $orig[0]['xmpp']) { $changes[] = t('XMPP'); $value = $xmpp; } - if ($homepage != $orig[0]['homepage']) { + if($homepage != $orig[0]['homepage']) { $changes[] = t('Homepage'); $value = $homepage; } - if ($interest != $orig[0]['interest']) { + if($interest != $orig[0]['interest']) { $changes[] = t('Interests'); $value = $interest; } - if ($address != $orig[0]['address']) { + if($address != $orig[0]['address']) { $changes[] = t('Address'); // New address not sent in notifications, potential privacy issues // in case this leaks to unintended recipients. Yes, it's in the public // profile but that doesn't mean we have to broadcast it to everybody. } - if ($locality != $orig[0]['locality'] || $region != $orig[0]['region'] + if($locality != $orig[0]['locality'] || $region != $orig[0]['region'] || $country_name != $orig[0]['country-name']) { $changes[] = t('Location'); $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' '); @@ -474,12 +473,11 @@ function profiles_post(App $a) { intval(local_user()) ); - if ($r) { + if($r) info( t('Profile updated.') . EOL); - } - if ($namechanged && $is_default) { + if($namechanged && $is_default) { $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d", dbesc($name), dbesc(datetime_convert()), @@ -491,7 +489,7 @@ function profiles_post(App $a) { ); } - if ($is_default) { + if($is_default) { $location = formatted_location(array("locality" => $locality, "region" => $region, "country-name" => $country_name)); q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `self` AND `uid` = %d", @@ -521,13 +519,13 @@ function profiles_post(App $a) { function profile_activity($changed, $value) { $a = get_app(); - if (! local_user() || ! is_array($changed) || ! count($changed)) + if(! local_user() || ! is_array($changed) || ! count($changed)) return; - if ($a->user['hidewall'] || get_config('system','block_public')) + if($a->user['hidewall'] || get_config('system','block_public')) return; - if (! get_pconfig(local_user(),'system','post_profilechange')) + if(! get_pconfig(local_user(),'system','post_profilechange')) return; require_once('include/items.php'); @@ -536,7 +534,7 @@ function profile_activity($changed, $value) { intval(local_user()) ); - if (! count($self)) + if(! count($self)) return; $arr = array(); @@ -561,8 +559,8 @@ function profile_activity($changed, $value) { $changes = ''; $t = count($changed); $z = 0; - foreach ($changed as $ch) { - if (strlen($changes)) { + foreach($changed as $ch) { + if(strlen($changes)) { if ($z == ($t - 1)) $changes .= t(' and '); else @@ -574,7 +572,7 @@ function profile_activity($changed, $value) { $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]'; - if ($t == 1 && strlen($value)) { + if($t == 1 && strlen($value)) { $message = sprintf( t('%1$s changed %2$s to “%3$s”'), $A, $changes, $value); $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof); } @@ -612,7 +610,7 @@ function profiles_content(App $a) { $o = ''; - if (($a->argc > 1) && (intval($a->argv[1]))) { + if(($a->argc > 1) && (intval($a->argv[1]))) { $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[1]), intval(local_user()) @@ -654,7 +652,7 @@ function profiles_content(App $a) { $detailled_profile = (get_pconfig(local_user(),'system','detailled_profile') AND $personal_account); $f = get_config('system','birthday_input_format'); - if (! $f) + if(! $f) $f = 'ymd'; $is_default = (($r[0]['is-default']) ? 1 : 0); @@ -756,7 +754,7 @@ function profiles_content(App $a) { else { //If we don't support multi profiles, don't display this list. - if (!feature_enabled(local_user(),'multi_profiles')){ + if(!feature_enabled(local_user(),'multi_profiles')){ $r = q( "SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1", local_user() diff --git a/mod/profperm.php b/mod/profperm.php index 37054fb7c..a414d8947 100644 --- a/mod/profperm.php +++ b/mod/profperm.php @@ -22,7 +22,7 @@ function profperm_content(App $a) { } - if ($a->argc < 2) { + if($a->argc < 2) { notice( t('Invalid profile identifier.') . EOL ); return; } @@ -30,13 +30,13 @@ function profperm_content(App $a) { // Switch to text mod interface if we have more than 'n' contacts or group members $switchtotext = get_pconfig(local_user(),'system','groupedit_image_limit'); - if ($switchtotext === false) + if($switchtotext === false) $switchtotext = get_config('system','groupedit_image_limit'); - if ($switchtotext === false) + if($switchtotext === false) $switchtotext = 400; - if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) { + if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) { $r = q("SELECT `id` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `self` = 0 AND `network` = '%s' AND `id` = %d AND `uid` = %d LIMIT 1", dbesc(NETWORK_DFRN), @@ -48,7 +48,7 @@ function profperm_content(App $a) { } - if (($a->argc > 1) && (intval($a->argv[1]))) { + if(($a->argc > 1) && (intval($a->argv[1]))) { $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1", intval($a->argv[1]), intval(local_user()) @@ -66,13 +66,13 @@ function profperm_content(App $a) { $ingroup = array(); if (dbm::is_result($r)) - foreach ($r as $member) + foreach($r as $member) $ingroup[] = $member['id']; $members = $r; - if ($change) { - if (in_array($change,$ingroup)) { + if($change) { + if(in_array($change,$ingroup)) { q("UPDATE `contact` SET `profile-id` = 0 WHERE `id` = %d AND `uid` = %d", intval($change), intval(local_user()) @@ -96,7 +96,7 @@ function profperm_content(App $a) { $ingroup = array(); if (dbm::is_result($r)) - foreach ($r as $member) + foreach($r as $member) $ingroup[] = $member['id']; } @@ -109,7 +109,7 @@ function profperm_content(App $a) { } $o .= '
    '; - if ($change) + if($change) $o = ''; $o .= '
    '; @@ -119,8 +119,8 @@ function profperm_content(App $a) { $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false); - foreach ($members as $member) { - if ($member['url']) { + foreach($members as $member) { + if($member['url']) { $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;'; $o .= micropro($member,true,'mpprof', $textmode); } @@ -141,8 +141,8 @@ function profperm_content(App $a) { if (dbm::is_result($r)) { $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false); - foreach ($r as $member) { - if (! in_array($member['id'],$ingroup)) { + foreach($r as $member) { + if(! in_array($member['id'],$ingroup)) { $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;'; $o .= micropro($member,true,'mpprof',$textmode); } @@ -151,7 +151,7 @@ function profperm_content(App $a) { $o .= '
    '; - if ($change) { + if($change) { echo $o; killme(); } diff --git a/mod/pubsub.php b/mod/pubsub.php index 092461044..2ba1958a2 100644 --- a/mod/pubsub.php +++ b/mod/pubsub.php @@ -2,7 +2,7 @@ function hub_return($valid,$body) { - if ($valid) { + if($valid) { header($_SERVER["SERVER_PROTOCOL"] . ' 200 ' . 'OK'); echo $body; killme(); @@ -31,7 +31,7 @@ function pubsub_init(App $a) { $nick = (($a->argc > 1) ? notags(trim($a->argv[1])) : ''); $contact_id = (($a->argc > 2) ? intval($a->argv[2]) : 0 ); - if ($_SERVER['REQUEST_METHOD'] === 'GET') { + if($_SERVER['REQUEST_METHOD'] === 'GET') { $hub_mode = ((x($_GET,'hub_mode')) ? notags(trim($_GET['hub_mode'])) : ''); $hub_topic = ((x($_GET,'hub_topic')) ? notags(trim($_GET['hub_topic'])) : ''); @@ -68,7 +68,7 @@ function pubsub_init(App $a) { } if ($hub_topic) - if (! link_compare($hub_topic,$r[0]['poll'])) { + if(! link_compare($hub_topic,$r[0]['poll'])) { logger('pubsub: hub topic ' . $hub_topic . ' != ' . $r[0]['poll']); // should abort but let's humour them. } @@ -78,8 +78,8 @@ function pubsub_init(App $a) { // We must initiate an unsubscribe request with a verify_token. // Don't allow outsiders to unsubscribe us. - if ($hub_mode === 'unsubscribe') { - if (! strlen($hub_verify)) { + if($hub_mode === 'unsubscribe') { + if(! strlen($hub_verify)) { logger('pubsub: bogus unsubscribe'); hub_return(false, ''); } @@ -106,7 +106,7 @@ function pubsub_post(App $a) { logger('pubsub: user-agent: ' . $_SERVER['HTTP_USER_AGENT'] ); logger('pubsub: data: ' . $xml, LOGGER_DATA); -// if (! stristr($xml,' af11... // [hub_topic] => http://friendica.local/dfrn_poll/sazius - if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if($_SERVER['REQUEST_METHOD'] === 'POST') { $hub_mode = post_var('hub_mode'); $hub_callback = post_var('hub_callback'); $hub_verify = post_var('hub_verify'); @@ -32,7 +32,7 @@ function pubsubhubbub_init(App $a) { // check for valid hub_mode if ($hub_mode === 'subscribe') { $subscribe = 1; - } elseif ($hub_mode === 'unsubscribe') { + } else if ($hub_mode === 'unsubscribe') { $subscribe = 0; } else { logger("pubsubhubbub: invalid hub_mode=$hub_mode, ignoring."); @@ -81,7 +81,7 @@ function pubsubhubbub_init(App $a) { $contact = $r[0]; // sanity check that topic URLs are the same - if (!link_compare($hub_topic, $contact['poll'])) { + if(!link_compare($hub_topic, $contact['poll'])) { logger('pubsubhubbub: hub topic ' . $hub_topic . ' != ' . $contact['poll']); http_status_exit(404); diff --git a/mod/qsearch.php b/mod/qsearch.php index efc095a26..8512bea51 100644 --- a/mod/qsearch.php +++ b/mod/qsearch.php @@ -10,14 +10,12 @@ function qsearch_init(App $a) { $search = ((x($_GET,'s')) ? notags(trim(urldecode($_GET['s']))) : ''); - if (! strlen($search)) { + if(! strlen($search)) killme(); - } - if ($search) { + if($search) $search = dbesc($search); - } $results = array(); @@ -27,9 +25,9 @@ function qsearch_init(App $a) { ); if (dbm::is_result($r)) { - foreach ($r as $rr) { + + foreach($r as $rr) $results[] = array( 0, (int) $rr['id'], $rr['name'], '', ''); - } } $sql_extra = ((strlen($search)) ? " AND (`name` REGEXP '$search' OR `nick` REGEXP '$search') " : ""); @@ -42,9 +40,9 @@ function qsearch_init(App $a) { if (dbm::is_result($r)) { - foreach ($r as $rr) { + + foreach($r as $rr) $results[] = array( (int) $rr['id'], 0, $rr['name'],$rr['url'],$rr['photo']); - } } echo json_encode((object) $results); diff --git a/mod/receive.php b/mod/receive.php index d11bfdb85..3563f2d70 100644 --- a/mod/receive.php +++ b/mod/receive.php @@ -14,19 +14,19 @@ function receive_post(App $a) { $enabled = intval(get_config('system','diaspora_enabled')); - if (! $enabled) { + if(! $enabled) { logger('mod-diaspora: disabled'); http_status_exit(500); } $public = false; - if (($a->argc == 2) && ($a->argv[1] === 'public')) { + if(($a->argc == 2) && ($a->argv[1] === 'public')) { $public = true; } else { - if ($a->argc != 3 || $a->argv[1] !== 'users') + if($a->argc != 3 || $a->argv[1] !== 'users') http_status_exit(500); $guid = $a->argv[2]; @@ -49,7 +49,7 @@ function receive_post(App $a) { logger('mod-diaspora: new salmon ' . $xml, LOGGER_DATA); - if (! $xml) + if(! $xml) http_status_exit(500); logger('mod-diaspora: message is okay', LOGGER_DEBUG); @@ -60,13 +60,13 @@ function receive_post(App $a) { logger('mod-diaspora: decoded msg: ' . print_r($msg,true), LOGGER_DATA); - if (! is_array($msg)) + if(! is_array($msg)) http_status_exit(500); logger('mod-diaspora: dispatching', LOGGER_DEBUG); $ret = 0; - if ($public) { + if($public) { Diaspora::dispatch_public($msg); } else { $ret = Diaspora::dispatch($importer,$msg); diff --git a/mod/redir.php b/mod/redir.php index 32a235de4..12f53900a 100644 --- a/mod/redir.php +++ b/mod/redir.php @@ -8,9 +8,9 @@ function redir_init(App $a) { // traditional DFRN - if ( $con_url || (local_user() && $a->argc > 1 && intval($a->argv[1])) ) { + if( $con_url || (local_user() && $a->argc > 1 && intval($a->argv[1])) ) { - if ($con_url) { + if($con_url) { $con_url = str_replace('https', 'http', $con_url); $r = q("SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1", @@ -18,7 +18,7 @@ function redir_init(App $a) { intval(local_user()) ); - if ((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN)) + if((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN)) goaway(z_root()); $cid = $r[0]['id']; @@ -31,17 +31,17 @@ function redir_init(App $a) { intval(local_user()) ); - if ((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN)) + if((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN)) goaway(z_root()); } $dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']); - if ($r[0]['duplex'] && $r[0]['issued-id']) { + if($r[0]['duplex'] && $r[0]['issued-id']) { $orig_id = $r[0]['issued-id']; $dfrn_id = '1:' . $orig_id; } - if ($r[0]['duplex'] && $r[0]['dfrn-id']) { + if($r[0]['duplex'] && $r[0]['dfrn-id']) { $orig_id = $r[0]['dfrn-id']; $dfrn_id = '0:' . $orig_id; } diff --git a/mod/register.php b/mod/register.php index fe799f4c6..81e8c3ad8 100644 --- a/mod/register.php +++ b/mod/register.php @@ -4,7 +4,7 @@ require_once('include/enotify.php'); require_once('include/bbcode.php'); require_once('include/user.php'); -if (! function_exists('register_post')) { +if(! function_exists('register_post')) { function register_post(App $a) { global $lang; @@ -16,9 +16,9 @@ function register_post(App $a) { call_hooks('register_post', $arr); $max_dailies = intval(get_config('system','max_daily_registrations')); - if ($max_dailies) { + if($max_dailies) { $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day"); - if ($r && $r[0]['total'] >= $max_dailies) { + if($r && $r[0]['total'] >= $max_dailies) { return; } } @@ -38,7 +38,7 @@ function register_post(App $a) { default: case REGISTER_CLOSED: - if ((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) { + if((! x($_SESSION,'authenticated') && (! x($_SESSION,'administrator')))) { notice( t('Permission denied.') . EOL ); return; } @@ -56,14 +56,14 @@ function register_post(App $a) { $result = create_user($arr); - if (! $result['success']) { + if(! $result['success']) { notice($result['message']); return; } $user = $result['user']; - if ($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) { + if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) { $url = App::get_baseurl() . '/profile/' . $user['nickname']; proc_run(PRIORITY_LOW, "include/directory.php", $url); } @@ -73,9 +73,9 @@ function register_post(App $a) { $invite_id = ((x($_POST,'invite_id')) ? notags(trim($_POST['invite_id'])) : ''); - if ( $a->config['register_policy'] == REGISTER_OPEN ) { + if( $a->config['register_policy'] == REGISTER_OPEN ) { - if ($using_invites && $invite_id) { + if($using_invites && $invite_id) { q("delete * from register where hash = '%s' limit 1", dbesc($invite_id)); set_pconfig($user['uid'],'system','invites_remaining',$num_invites); } @@ -89,7 +89,7 @@ function register_post(App $a) { $user['username'], $result['password']); - if ($res) { + if($res) { info( t('Registration successful. Please check your email for further instructions.') . EOL ) ; goaway(z_root()); } else { @@ -106,8 +106,8 @@ function register_post(App $a) { goaway(z_root()); } } - elseif ($a->config['register_policy'] == REGISTER_APPROVE) { - if (! strlen($a->config['admin_email'])) { + elseif($a->config['register_policy'] == REGISTER_APPROVE) { + if(! strlen($a->config['admin_email'])) { notice( t('Your registration can not be processed.') . EOL); goaway(z_root()); } @@ -123,7 +123,7 @@ function register_post(App $a) { ); // invite system - if ($using_invites && $invite_id) { + if($using_invites && $invite_id) { q("delete * from register where hash = '%s' limit 1", dbesc($invite_id)); set_pconfig($user['uid'],'system','invites_remaining',$num_invites); } @@ -171,7 +171,7 @@ function register_post(App $a) { -if (! function_exists('register_content')) { +if(! function_exists('register_content')) { function register_content(App $a) { // logged in users can register others (people/pages/groups) @@ -180,29 +180,29 @@ function register_content(App $a) { $block = get_config('system','block_extended_register'); - if (local_user() && ($block)) { + if(local_user() && ($block)) { notice("Permission denied." . EOL); return; } - if ((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) { + if((! local_user()) && ($a->config['register_policy'] == REGISTER_CLOSED)) { notice("Permission denied." . EOL); return; } $max_dailies = intval(get_config('system','max_daily_registrations')); - if ($max_dailies) { + if($max_dailies) { $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day"); - if ($r && $r[0]['total'] >= $max_dailies) { + if($r && $r[0]['total'] >= $max_dailies) { logger('max daily registrations exceeded.'); notice( t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL); return; } } - if (x($_SESSION,'theme')) + if(x($_SESSION,'theme')) unset($_SESSION['theme']); - if (x($_SESSION,'mobile-theme')) + if(x($_SESSION,'mobile-theme')) unset($_SESSION['mobile-theme']); @@ -215,7 +215,7 @@ function register_content(App $a) { $noid = get_config('system','no_openid'); - if ($noid) { + if($noid) { $oidhtml = ''; $fillwith = ''; $fillext = ''; @@ -232,7 +232,7 @@ function register_content(App $a) { $realpeople = ''; // t('Members of this network prefer to communicate with real people who use their real names.'); - if (get_config('system','publish_all')) { + if(get_config('system','publish_all')) { $profile_publish_reg = ''; } else { diff --git a/mod/regmod.php b/mod/regmod.php index 19fc047cc..1983ca089 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -54,7 +54,7 @@ function user_allow($hash) { pop_lang(); - if ($res) { + if($res) { info( t('Account approved.') . EOL ); return true; } @@ -72,9 +72,8 @@ function user_deny($hash) { dbesc($hash) ); - if (! dbm::is_result($register)) { + if(! dbm::is_result($register)) return false; - } $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($register[0]['uid']) diff --git a/mod/repair_ostatus.php b/mod/repair_ostatus.php old mode 100644 new mode 100755 diff --git a/mod/salmon.php b/mod/salmon.php index 76ab999b2..69809f523 100644 --- a/mod/salmon.php +++ b/mod/salmon.php @@ -8,9 +8,9 @@ require_once('include/follow.php'); function salmon_return($val) { - if ($val >= 400) + if($val >= 400) $err = 'Error'; - if ($val >= 200 && $val < 300) + if($val >= 200 && $val < 300) $err = 'OK'; logger('mod-salmon returns ' . $val); @@ -43,14 +43,14 @@ function salmon_post(App $a) { // figure out where in the DOM tree our data is hiding - if ($dom->provenance->data) + if($dom->provenance->data) $base = $dom->provenance; - elseif ($dom->env->data) + elseif($dom->env->data) $base = $dom->env; - elseif ($dom->data) + elseif($dom->data) $base = $dom; - if (! $base) { + if(! $base) { logger('mod-salmon: unable to locate salmon data in xml '); http_status_exit(400); } @@ -88,7 +88,7 @@ function salmon_post(App $a) { $author = ostatus::salmon_author($data,$importer); $author_link = $author["author-link"]; - if (! $author_link) { + if(! $author_link) { logger('mod-salmon: Could not retrieve author URI.'); http_status_exit(400); } @@ -99,7 +99,7 @@ function salmon_post(App $a) { $key = get_salmon_key($author_link,$keyhash); - if (! $key) { + if(! $key) { logger('mod-salmon: Could not retrieve author key.'); http_status_exit(400); } @@ -117,17 +117,17 @@ function salmon_post(App $a) { $verify = rsa_verify($compliant_format,$signature,$pubkey); - if (! $verify) { + if(! $verify) { logger('mod-salmon: message did not verify using protocol. Trying padding hack.'); $verify = rsa_verify($signed_data,$signature,$pubkey); } - if (! $verify) { + if(! $verify) { logger('mod-salmon: message did not verify using padding. Trying old statusnet hack.'); $verify = rsa_verify($stnet_signed_data,$signature,$pubkey); } - if (! $verify) { + if(! $verify) { logger('mod-salmon: Message did not verify. Discarding.'); http_status_exit(400); } @@ -153,9 +153,9 @@ function salmon_post(App $a) { ); if (! dbm::is_result($r)) { logger('mod-salmon: Author unknown to us.'); - if (get_pconfig($importer['uid'],'system','ostatus_autofriend')) { + if(get_pconfig($importer['uid'],'system','ostatus_autofriend')) { $result = new_contact($importer['uid'],$author_link); - if ($result['success']) { + if($result['success']) { $r = q("SELECT * FROM `contact` WHERE `network` = '%s' AND ( `url` = '%s' OR `alias` = '%s') AND `uid` = %d LIMIT 1", dbesc(NETWORK_OSTATUS), @@ -170,7 +170,7 @@ function salmon_post(App $a) { // Have we ignored the person? // If so we can not accept this post. - //if ((dbm::is_result($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == CONTACT_IS_FOLLOWER) || ($r[0]['blocked']))) { + //if((dbm::is_result($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == CONTACT_IS_FOLLOWER) || ($r[0]['blocked']))) { if (dbm::is_result($r) && $r[0]['blocked']) { logger('mod-salmon: Ignoring this author.'); http_status_exit(202); diff --git a/mod/search.php b/mod/search.php index d07385753..7d588aa4d 100644 --- a/mod/search.php +++ b/mod/search.php @@ -8,7 +8,7 @@ function search_saved_searches() { $o = ''; - if (! feature_enabled(local_user(),'savedsearch')) + if(! feature_enabled(local_user(),'savedsearch')) return $o; $r = q("SELECT `id`,`term` FROM `search` WHERE `uid` = %d", @@ -47,8 +47,8 @@ function search_init(App $a) { $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); - if (local_user()) { - if (x($_GET,'save') && $search) { + if(local_user()) { + if(x($_GET,'save') && $search) { $r = q("SELECT * FROM `search` WHERE `uid` = %d AND `term` = '%s' LIMIT 1", intval(local_user()), dbesc($search) @@ -60,7 +60,7 @@ function search_init(App $a) { ); } } - if (x($_GET,'remove') && $search) { + if(x($_GET,'remove') && $search) { q("DELETE FROM `search` WHERE `uid` = %d AND `term` = '%s' LIMIT 1", intval(local_user()), dbesc($search) @@ -82,19 +82,19 @@ function search_init(App $a) { function search_post(App $a) { - if (x($_POST,'search')) + if(x($_POST,'search')) $a->data['search'] = $_POST['search']; } function search_content(App $a) { - if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { notice( t('Public access denied.') . EOL); return; } - if (get_config('system','local_search') AND !local_user()) { + if(get_config('system','local_search') AND !local_user()) { http_status_exit(403, array("title" => t("Public access denied."), "description" => t("Only logged in users are permitted to perform a search."))); @@ -132,13 +132,13 @@ function search_content(App $a) { nav_set_selected('search'); - if (x($a->data,'search')) + if(x($a->data,'search')) $search = notags(trim($a->data['search'])); else $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); $tag = false; - if (x($_GET,'tag')) { + if(x($_GET,'tag')) { $tag = true; $search = ((x($_GET,'tag')) ? notags(trim(rawurldecode($_GET['tag']))) : ''); } @@ -151,18 +151,18 @@ function search_content(App $a) { '$content' => search($search,'search-box','search',((local_user()) ? true : false), false) )); - if (strpos($search,'#') === 0) { + if(strpos($search,'#') === 0) { $tag = true; $search = substr($search,1); } - if (strpos($search,'@') === 0) { + if(strpos($search,'@') === 0) { return dirfind_content($a); } - if (strpos($search,'!') === 0) { + if(strpos($search,'!') === 0) { return dirfind_content($a); } - if (x($_GET,'search-option')) + if(x($_GET,'search-option')) switch($_GET['search-option']) { case 'fulltext': break; @@ -177,7 +177,7 @@ function search_content(App $a) { break; } - if (! $search) + if(! $search) return $o; if (get_config('system','only_tag_search')) @@ -188,7 +188,7 @@ function search_content(App $a) { // OR your own posts if you are a logged in member // No items will be shown if the member has a blocked profile wall. - if ($tag) { + if($tag) { logger("Start tag search for '".$search."'", LOGGER_DEBUG); $r = q("SELECT %s @@ -226,7 +226,7 @@ function search_content(App $a) { } - if ($tag) + if($tag) $title = sprintf( t('Items tagged with: %s'), $search); else $title = sprintf( t('Results for: %s'), $search); diff --git a/mod/settings.php b/mod/settings.php index a626e67f5..5c9c439e0 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -47,7 +47,7 @@ function settings_init(App $a) { ), ); - if (get_features()) { + if(get_features()) { $tabs[] = array( 'label' => t('Additional features'), 'url' => 'settings/features', @@ -189,23 +189,23 @@ function settings_post(App $a) { return; } - if (($a->argc > 1) && ($a->argv[1] == 'addon')) { + if(($a->argc > 1) && ($a->argv[1] == 'addon')) { check_form_security_token_redirectOnErr('/settings/addon', 'settings_addon'); call_hooks('plugin_settings_post', $_POST); return; } - if (($a->argc > 1) && ($a->argv[1] == 'connectors')) { + if(($a->argc > 1) && ($a->argv[1] == 'connectors')) { check_form_security_token_redirectOnErr('/settings/connectors', 'settings_connectors'); - if (x($_POST, 'general-submit')) { + if(x($_POST, 'general-submit')) { set_pconfig(local_user(), 'system', 'no_intelligent_shortening', intval($_POST['no_intelligent_shortening'])); set_pconfig(local_user(), 'system', 'ostatus_autofriend', intval($_POST['snautofollow'])); set_pconfig(local_user(), 'ostatus', 'default_group', $_POST['group-selection']); set_pconfig(local_user(), 'ostatus', 'legacy_contact', $_POST['legacy_contact']); - } elseif (x($_POST, 'imap-submit')) { + } elseif(x($_POST, 'imap-submit')) { $mail_server = ((x($_POST,'mail_server')) ? $_POST['mail_server'] : ''); $mail_port = ((x($_POST,'mail_port')) ? $_POST['mail_port'] : ''); @@ -219,10 +219,10 @@ function settings_post(App $a) { $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); - if (get_config('system','dfrn_only')) + if(get_config('system','dfrn_only')) $mail_disabled = 1; - if (! $mail_disabled) { + if(! $mail_disabled) { $failed = false; $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", intval(local_user()) @@ -232,7 +232,7 @@ function settings_post(App $a) { intval(local_user()) ); } - if (strlen($mail_pass)) { + if(strlen($mail_pass)) { $pass = ''; openssl_public_encrypt($mail_pass,$pass,$a->user['pubkey']); q("UPDATE `mailacct` SET `pass` = '%s' WHERE `uid` = %d", @@ -261,18 +261,18 @@ function settings_post(App $a) { $eacct = $r[0]; require_once('include/email.php'); $mb = construct_mailbox_name($eacct); - if (strlen($eacct['server'])) { + if(strlen($eacct['server'])) { $dcrpass = ''; openssl_private_decrypt(hex2bin($eacct['pass']),$dcrpass,$a->user['prvkey']); $mbox = email_connect($mb,$mail_user,$dcrpass); unset($dcrpass); - if (! $mbox) { + if(! $mbox) { $failed = true; notice( t('Failed to connect with email account using the settings provided.') . EOL); } } } - if (! $failed) + if(! $failed) info( t('Email settings updated.') . EOL); } } @@ -283,8 +283,8 @@ function settings_post(App $a) { if (($a->argc > 1) && ($a->argv[1] === 'features')) { check_form_security_token_redirectOnErr('/settings/features', 'settings_features'); - foreach ($_POST as $k => $v) { - if (strpos($k,'feature_') === 0) { + foreach($_POST as $k => $v) { + if(strpos($k,'feature_') === 0) { set_pconfig(local_user(),'feature',substr($k,8),((intval($v)) ? 1 : 0)); } } @@ -320,7 +320,7 @@ function settings_post(App $a) { $itemspage_mobile_network = 100; } - if ($mobile_theme !== '') { + if($mobile_theme !== '') { set_pconfig(local_user(),'system','mobile_theme',$mobile_theme); } @@ -364,45 +364,41 @@ function settings_post(App $a) { call_hooks('settings_post', $_POST); - if ((x($_POST,'password')) || (x($_POST,'confirm'))) { + if((x($_POST,'password')) || (x($_POST,'confirm'))) { $newpass = $_POST['password']; $confirm = $_POST['confirm']; $oldpass = hash('whirlpool', $_POST['opassword']); $err = false; - if ($newpass != $confirm ) { + if($newpass != $confirm ) { notice( t('Passwords do not match. Password unchanged.') . EOL); $err = true; } - if ((! x($newpass)) || (! x($confirm))) { + if((! x($newpass)) || (! x($confirm))) { notice( t('Empty passwords are not allowed. Password unchanged.') . EOL); $err = true; - } + } - // check if the old password was supplied correctly before - // changing it to the new value - $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user())); - if (!dbm::is_result($r)) { - /// @todo Don't quit silently here - killme(); - } elseif ( $oldpass != $r[0]['password'] ) { - notice( t('Wrong password.') . EOL); - $err = true; - } + // check if the old password was supplied correctly before + // changing it to the new value + $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user())); + if( $oldpass != $r[0]['password'] ) { + notice( t('Wrong password.') . EOL); + $err = true; + } - if (! $err) { + if(! $err) { $password = hash('whirlpool',$newpass); $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d", dbesc($password), intval(local_user()) ); - if ($r) { + if($r) info( t('Password changed.') . EOL); - } else { + else notice( t('Password update failed. Please try again.') . EOL); - } } } @@ -446,41 +442,32 @@ function settings_post(App $a) { $notify = 0; - if (x($_POST,'notify1')) { + if(x($_POST,'notify1')) $notify += intval($_POST['notify1']); - } - if (x($_POST,'notify2')) { + if(x($_POST,'notify2')) $notify += intval($_POST['notify2']); - } - if (x($_POST,'notify3')) { + if(x($_POST,'notify3')) $notify += intval($_POST['notify3']); - } - if (x($_POST,'notify4')) { + if(x($_POST,'notify4')) $notify += intval($_POST['notify4']); - } - if (x($_POST,'notify5')) { + if(x($_POST,'notify5')) $notify += intval($_POST['notify5']); - } - if (x($_POST,'notify6')) { + if(x($_POST,'notify6')) $notify += intval($_POST['notify6']); - } - if (x($_POST,'notify7')) { + if(x($_POST,'notify7')) $notify += intval($_POST['notify7']); - } - if (x($_POST,'notify8')) { + if(x($_POST,'notify8')) $notify += intval($_POST['notify8']); - } // Adjust the page flag if the account type doesn't fit to the page flag. - if (($account_type == ACCOUNT_TYPE_PERSON) AND !in_array($page_flags, array(PAGE_NORMAL, PAGE_SOAPBOX, PAGE_FREELOVE))) { + if (($account_type == ACCOUNT_TYPE_PERSON) AND !in_array($page_flags, array(PAGE_NORMAL, PAGE_SOAPBOX, PAGE_FREELOVE))) $page_flags = PAGE_NORMAL; - } elseif (($account_type == ACCOUNT_TYPE_ORGANISATION) AND !in_array($page_flags, array(PAGE_SOAPBOX))) { + elseif (($account_type == ACCOUNT_TYPE_ORGANISATION) AND !in_array($page_flags, array(PAGE_SOAPBOX))) $page_flags = PAGE_SOAPBOX; - } elseif (($account_type == ACCOUNT_TYPE_NEWS) AND !in_array($page_flags, array(PAGE_SOAPBOX))) { + elseif (($account_type == ACCOUNT_TYPE_NEWS) AND !in_array($page_flags, array(PAGE_SOAPBOX))) $page_flags = PAGE_SOAPBOX; - } elseif (($account_type == ACCOUNT_TYPE_COMMUNITY) AND !in_array($page_flags, array(PAGE_COMMUNITY, PAGE_PRVGROUP))) { + elseif (($account_type == ACCOUNT_TYPE_COMMUNITY) AND !in_array($page_flags, array(PAGE_COMMUNITY, PAGE_PRVGROUP))) $page_flags = PAGE_COMMUNITY; - } $email_changed = false; @@ -488,17 +475,15 @@ function settings_post(App $a) { $name_change = false; - if ($username != $a->user['username']) { + if($username != $a->user['username']) { $name_change = true; - if (strlen($username) > 40) { + if(strlen($username) > 40) $err .= t(' Please use a shorter name.'); - } - if (strlen($username) < 3) { + if(strlen($username) < 3) $err .= t(' Name too short.'); - } } - if ($email != $a->user['email']) { + if($email != $a->user['email']) { $email_changed = true; // check for the correct password $r = q("SELECT `password` FROM `user`WHERE `uid` = %d LIMIT 1", intval(local_user())); @@ -508,12 +493,11 @@ function settings_post(App $a) { $email = $a->user['email']; } // check the email is valid - if (! valid_email($email)) { + if(! valid_email($email)) $err .= t(' Not valid email.'); - } // ensure new email is not the admin mail - //if ((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0)) { - if (x($a->config,'admin_email')) { + //if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0)) { + if(x($a->config,'admin_email')) { $adminlist = explode(",", str_replace(" ", "", strtolower($a->config['admin_email']))); if (in_array(strtolower($email), $adminlist)) { $err .= t(' Cannot change to that email.'); @@ -522,13 +506,14 @@ function settings_post(App $a) { } } - if (strlen($err)) { + if(strlen($err)) { notice($err . EOL); return; } - if ($timezone != $a->user['timezone'] && strlen($timezone)) { - date_default_timezone_set($timezone); + if($timezone != $a->user['timezone']) { + if(strlen($timezone)) + date_default_timezone_set($timezone); } $str_group_allow = perms2str($_POST['group_allow']); @@ -541,17 +526,17 @@ function settings_post(App $a) { // If openid has changed or if there's an openid but no openidserver, try and discover it. - if ($openid != $a->user['openid'] || (strlen($openid) && (! strlen($openidserver)))) { + if($openid != $a->user['openid'] || (strlen($openid) && (! strlen($openidserver)))) { $tmp_str = $openid; - if (strlen($tmp_str) && validate_url($tmp_str)) { + if(strlen($tmp_str) && validate_url($tmp_str)) { logger('updating openidserver'); require_once('library/openid.php'); $open_id_obj = new LightOpenID; $open_id_obj->identity = $openid; $openidserver = $open_id_obj->discover($open_id_obj->identity); - } else { - $openidserver = ''; } + else + $openidserver = ''; } set_pconfig(local_user(),'expire','items', $expire_items); @@ -567,13 +552,14 @@ function settings_post(App $a) { set_pconfig(local_user(),'system','email_textonly', $email_textonly); - if ($page_flags == PAGE_PRVGROUP) { + if($page_flags == PAGE_PRVGROUP) { $hidewall = 1; - if ((! $str_contact_allow) && (! $str_group_allow) && (! $str_contact_deny) && (! $str_group_deny)) { - if ($def_gid) { + if((! $str_contact_allow) && (! $str_group_allow) && (! $str_contact_deny) && (! $str_group_deny)) { + if($def_gid) { info( t('Private forum has no privacy permissions. Using default privacy group.'). EOL); $str_group_allow = '<' . $def_gid . '>'; - } else { + } + else { notice( t('Private forum has no privacy permissions and no default privacy group.') . EOL); } } @@ -613,9 +599,8 @@ function settings_post(App $a) { dbesc($language), intval(local_user()) ); - if ($r) { + if($r) info( t('Settings updated.') . EOL); - } // clear session language unset($_SESSION['language']); @@ -634,7 +619,7 @@ function settings_post(App $a) { ); - if ($name_change) { + if($name_change) { q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s' WHERE `uid` = %d AND `self`", dbesc($username), dbesc(datetime_convert()), @@ -684,6 +669,8 @@ function settings_content(App $a) { return; } + + if (($a->argc > 1) && ($a->argv[1] === 'oauth')) { if (($a->argc > 2) && ($a->argv[2] === 'add')) { @@ -728,7 +715,7 @@ function settings_content(App $a) { return $o; } - if (($a->argc > 3) && ($a->argv[2] === 'delete')) { + if(($a->argc > 3) && ($a->argv[2] === 'delete')) { check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth', 't'); $r = q("DELETE FROM clients WHERE client_id='%s' AND uid=%d", @@ -866,10 +853,10 @@ function settings_content(App $a) { } $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); - if (get_config('system','dfrn_only')) + if(get_config('system','dfrn_only')) $mail_disabled = 1; - if (! $mail_disabled) { + if(! $mail_disabled) { $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", local_user() ); @@ -1177,7 +1164,7 @@ function settings_content(App $a) { } $opt_tpl = get_markup_template("field_yesno.tpl"); - if (get_config('system','publish_all')) { + if(get_config('system','publish_all')) { $profile_in_dir = ''; } else { $profile_in_dir = replace_macros($opt_tpl,array( diff --git a/mod/share.php b/mod/share.php index 59081ec62..36a4d5945 100644 --- a/mod/share.php +++ b/mod/share.php @@ -2,7 +2,7 @@ function share_init(App $a) { $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); - if ((! $post_id) || (! local_user())) + if((! $post_id) || (! local_user())) killme(); $r = q("SELECT item.*, contact.network FROM `item` @@ -12,7 +12,7 @@ function share_init(App $a) { intval($post_id), intval(local_user()) ); - if (! dbm::is_result($r) || ($r[0]['private'] == 1)) + if(! dbm::is_result($r) || ($r[0]['private'] == 1)) killme(); if (strpos($r[0]['body'], "[/share]") !== false) { diff --git a/mod/smilies.php b/mod/smilies.php index 5ca3af14a..4d8ab6bca 100644 --- a/mod/smilies.php +++ b/mod/smilies.php @@ -10,11 +10,12 @@ function smilies_content(App $a) { if ($a->argv[1]==="json"){ $tmp = Smilies::get_list(); $results = array(); - for ($i = 0; $i < count($tmp['texts']); $i++) { + for($i = 0; $i < count($tmp['texts']); $i++) { $results[] = array('text' => $tmp['texts'][$i], 'icon' => $tmp['icons'][$i]); } json_return_and_die($results); - } else { + } + else { return Smilies::replace('',true); } } diff --git a/mod/subthread.php b/mod/subthread.php index b85f461dc..646a4230c 100644 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -7,7 +7,7 @@ require_once('include/items.php'); function subthread_content(App $a) { - if (! local_user() && ! remote_user()) { + if(! local_user() && ! remote_user()) { return; } @@ -20,7 +20,7 @@ function subthread_content(App $a) { dbesc($item_id) ); - if (! $item_id || (! dbm::is_result($r))) { + if(! $item_id || (! dbm::is_result($r))) { logger('subthread: no item ' . $item_id); return; } @@ -29,13 +29,13 @@ function subthread_content(App $a) { $owner_uid = $item['uid']; - if (! can_write_wall($a,$owner_uid)) { + if(! can_write_wall($a,$owner_uid)) { return; } $remote_owner = null; - if (! $item['wall']) { + if(! $item['wall']) { // The top level post may have been written by somebody on another system $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item['contact-id']), diff --git a/mod/tagger.php b/mod/tagger.php index 0ee2a0143..50099ac69 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -7,7 +7,7 @@ require_once('include/items.php'); function tagger_content(App $a) { - if (! local_user() && ! remote_user()) { + if(! local_user() && ! remote_user()) { return; } @@ -15,7 +15,7 @@ function tagger_content(App $a) { // no commas allowed $term = str_replace(array(',',' '),array('','_'),$term); - if (! $term) + if(! $term) return; $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0); @@ -27,7 +27,7 @@ function tagger_content(App $a) { dbesc($item_id) ); - if (! $item_id || (! dbm::is_result($r))) { + if(! $item_id || (! dbm::is_result($r))) { logger('tagger: no item ' . $item_id); return; } @@ -44,7 +44,7 @@ function tagger_content(App $a) { $blocktags = $r[0]['blocktags']; } - if (local_user() != $owner_uid) + if(local_user() != $owner_uid) return; $r = q("select * from contact where self = 1 and uid = %d limit 1", @@ -146,7 +146,7 @@ EOT; // ); - if (! $item['visible']) { + if(! $item['visible']) { $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d", intval($item['id']), intval($owner_uid) @@ -158,7 +158,7 @@ EOT; intval($item['id']), dbesc($term) ); - if ((! $blocktags) && $t[0]['tcount']==0 ) { + if((! $blocktags) && $t[0]['tcount']==0 ) { /*q("update item set tag = '%s' where id = %d", dbesc($item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . App::get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'), intval($item['id']) @@ -187,18 +187,18 @@ EOT; intval($r[0]['id']), dbesc($term) ); - if (count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){ + if(count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){ q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)", - intval($r[0]['id']), - $term_objtype, - TERM_HASHTAG, - dbesc($term), - dbesc(App::get_baseurl() . '/search?tag=' . $term), - intval($owner_uid) - ); + intval($r[0]['id']), + $term_objtype, + TERM_HASHTAG, + dbesc($term), + dbesc(App::get_baseurl() . '/search?tag=' . $term), + intval($owner_uid) + ); } - /*if (count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) { + /*if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) { q("update item set tag = '%s' where id = %d", dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . App::get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'), intval($r[0]['id']) diff --git a/mod/uexport.php b/mod/uexport.php index 9bd3bd138..cada539bc 100644 --- a/mod/uexport.php +++ b/mod/uexport.php @@ -51,9 +51,9 @@ function _uexport_multirow($query) { $result = array(); $r = q($query); if (dbm::is_result($r)) { - foreach ($r as $rr){ + foreach($r as $rr){ $p = array(); - foreach ($rr as $k => $v) { + foreach($rr as $k => $v) { $p[$k] = $v; } $result[] = $p; @@ -66,8 +66,8 @@ function _uexport_row($query) { $result = array(); $r = q($query); if (dbm::is_result($r)) { - foreach ($r as $rr) { - foreach ($rr as $k => $v) { + foreach($r as $rr) { + foreach($rr as $k => $v) { $result[$k] = $v; } } @@ -151,8 +151,8 @@ function uexport_all(App $a) { intval(500) ); /*if (dbm::is_result($r)) { - foreach ($r as $rr) - foreach ($rr as $k => $v) + foreach($r as $rr) + foreach($rr as $k => $v) $item[][$k] = $v; }*/ diff --git a/mod/videos.php b/mod/videos.php index 19d5ce940..3828b8f1f 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -8,10 +8,10 @@ require_once('include/redir.php'); function videos_init(App $a) { - if ($a->argc > 1) + if($a->argc > 1) auto_redir($a, $a->argv[1]); - if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { return; } @@ -19,15 +19,14 @@ function videos_init(App $a) { $o = ''; - if ($a->argc > 1) { + if($a->argc > 1) { $nick = $a->argv[1]; $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1", dbesc($nick) ); - if (!dbm::is_result($user)) { + if(! count($user)) return; - } $a->data['user'] = $user[0]; $a->profile_uid = $user[0]['uid']; @@ -53,35 +52,35 @@ function videos_init(App $a) { intval($a->data['user']['uid']) ); - if (count($albums)) { + if(count($albums)) { $a->data['albums'] = $albums; $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true); - if ($albums_visible) { + if($albums_visible) { $o .= ''; }*/ - if (! x($a->page,'aside')) + if(! x($a->page,'aside')) $a->page['aside'] = ''; $a->page['aside'] .= $vcard_widget; @@ -195,7 +194,7 @@ function videos_content(App $a) { // videos/name/video/xxxxx/edit - if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { notice( t('Public access denied.') . EOL); return; } @@ -205,7 +204,7 @@ function videos_content(App $a) { require_once('include/security.php'); require_once('include/conversation.php'); - if (! x($a->data,'user')) { + if(! x($a->data,'user')) { notice( t('No videos selected') . EOL ); return; } @@ -218,16 +217,16 @@ function videos_content(App $a) { // Parse arguments // - if ($a->argc > 3) { + if($a->argc > 3) { $datatype = $a->argv[2]; $datum = $a->argv[3]; } - elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) + elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) $datatype = 'upload'; else $datatype = 'summary'; - if ($a->argc > 4) + if($a->argc > 4) $cmd = $a->argv[4]; else $cmd = 'view'; @@ -246,19 +245,19 @@ function videos_content(App $a) { $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false); - if ((local_user()) && (local_user() == $owner_uid)) + if((local_user()) && (local_user() == $owner_uid)) $can_post = true; else { - if ($community_page && remote_user()) { - if (is_array($_SESSION['remote'])) { - foreach ($_SESSION['remote'] as $v) { - if ($v['uid'] == $owner_uid) { + if($community_page && remote_user()) { + if(is_array($_SESSION['remote'])) { + foreach($_SESSION['remote'] as $v) { + if($v['uid'] == $owner_uid) { $contact_id = $v['cid']; break; } } } - if ($contact_id) { + if($contact_id) { $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), @@ -276,17 +275,17 @@ function videos_content(App $a) { // perhaps they're visiting - but not a community page, so they wouldn't have write access - if (remote_user() && (! $visitor)) { + if(remote_user() && (! $visitor)) { $contact_id = 0; - if (is_array($_SESSION['remote'])) { - foreach ($_SESSION['remote'] as $v) { - if ($v['uid'] == $owner_uid) { + if(is_array($_SESSION['remote'])) { + foreach($_SESSION['remote'] as $v) { + if($v['uid'] == $owner_uid) { $contact_id = $v['cid']; break; } } } - if ($contact_id) { + if($contact_id) { $groups = init_groups_visitor($contact_id); $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), @@ -299,14 +298,14 @@ function videos_content(App $a) { } } - if (! $remote_contact) { - if (local_user()) { + if(! $remote_contact) { + if(local_user()) { $contact_id = $_SESSION['cid']; $contact = $a->contact; } } - if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) { + if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) { notice( t('Access to this item is restricted.') . EOL); return; } @@ -324,13 +323,13 @@ function videos_content(App $a) { // - if ($datatype === 'upload') { + if($datatype === 'upload') { return; // no uploading for now // DELETED -- look at mod/photos.php if you want to implement } - if ($datatype === 'album') { + if($datatype === 'album') { return; // no albums for now @@ -338,7 +337,7 @@ function videos_content(App $a) { } - if ($datatype === 'video') { + if($datatype === 'video') { return; // no single video view for now diff --git a/mod/view.php b/mod/view.php index a6c482049..15b3733b3 100644 --- a/mod/view.php +++ b/mod/view.php @@ -9,9 +9,8 @@ function view_init($a){ if ($a->argc == 4){ $theme = $a->argv[2]; $THEMEPATH = "view/theme/$theme"; - if (file_exists("view/theme/$theme/style.php")) { + if(file_exists("view/theme/$theme/style.php")) require_once("view/theme/$theme/style.php"); - } } killme(); diff --git a/mod/viewcontacts.php b/mod/viewcontacts.php index 1001f03cc..5912f6cc7 100644 --- a/mod/viewcontacts.php +++ b/mod/viewcontacts.php @@ -4,13 +4,13 @@ require_once('include/contact_selectors.php'); function viewcontacts_init(App $a) { - if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { return; } nav_set_selected('home'); - if ($a->argc > 1) { + if($a->argc > 1) { $nick = $a->argv[1]; $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1", dbesc($nick) @@ -32,7 +32,7 @@ function viewcontacts_init(App $a) { function viewcontacts_content(App $a) { require_once("mod/proxy.php"); - if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { notice( t('Public access denied.') . EOL); return; } @@ -42,7 +42,7 @@ function viewcontacts_content(App $a) { // tabs $o .= profile_tabs($a,$is_owner, $a->data['user']['nickname']); - if (((! count($a->profile)) || ($a->profile['hide-friends']))) { + if(((! count($a->profile)) || ($a->profile['hide-friends']))) { notice( t('Permission denied.') . EOL); return $o; } @@ -90,11 +90,10 @@ function viewcontacts_content(App $a) { $is_owner = ((local_user() && ($a->profile['profile_uid'] == local_user())) ? true : false); - if ($is_owner && ($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) { + if($is_owner && ($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) $url = 'redir/' . $rr['id']; - } else { + else $url = zrl($url); - } $contact_details = get_contact_details_by_url($rr['url'], $a->profile['uid'], $rr); diff --git a/mod/viewsrc.php b/mod/viewsrc.php index 74652dcca..a3f0affb5 100644 --- a/mod/viewsrc.php +++ b/mod/viewsrc.php @@ -10,7 +10,7 @@ function viewsrc_content(App $a) { $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); - if (! $item_id) { + if(! $item_id) { $a->error = 404; notice( t('Item not found.') . EOL); return; @@ -25,7 +25,7 @@ function viewsrc_content(App $a) { ); if (dbm::is_result($r)) - if (is_ajax()) { + if(is_ajax()) { echo str_replace("\n",'
    ',$r[0]['body']); killme(); } else { diff --git a/mod/wall_attach.php b/mod/wall_attach.php index 932b6241d..0fc8b8a6a 100644 --- a/mod/wall_attach.php +++ b/mod/wall_attach.php @@ -7,7 +7,7 @@ function wall_attach_post(App $a) { $r_json = (x($_GET,'response') && $_GET['response']=='json'); - if ($a->argc > 1) { + if($a->argc > 1) { $nick = $a->argv[1]; $r = q("SELECT `user`.*, `contact`.`id` FROM `user` LEFT JOIN `contact` on `user`.`uid` = `contact`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1", dbesc($nick) @@ -36,20 +36,20 @@ function wall_attach_post(App $a) { $page_owner_nick = $r[0]['nickname']; $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false); - if ((local_user()) && (local_user() == $page_owner_uid)) + if((local_user()) && (local_user() == $page_owner_uid)) $can_post = true; else { - if ($community_page && remote_user()) { + if($community_page && remote_user()) { $contact_id = 0; - if (is_array($_SESSION['remote'])) { - foreach ($_SESSION['remote'] as $v) { - if ($v['uid'] == $page_owner_uid) { + if(is_array($_SESSION['remote'])) { + foreach($_SESSION['remote'] as $v) { + if($v['uid'] == $page_owner_uid) { $contact_id = $v['cid']; break; } } } - if ($contact_id) { + if($contact_id) { $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), @@ -62,7 +62,7 @@ function wall_attach_post(App $a) { } } } - if (! $can_post) { + if(! $can_post) { if ($r_json) { echo json_encode(array('error'=>t('Permission denied.'))); killme(); @@ -71,7 +71,7 @@ function wall_attach_post(App $a) { killme(); } - if (! x($_FILES,'userfile')) { + if(! x($_FILES,'userfile')) { if ($r_json) { echo json_encode(array('error'=>t('Invalid request.'))); } @@ -90,7 +90,7 @@ function wall_attach_post(App $a) { * Then Filesize gets <= 0. */ - if ($filesize <=0) { + if($filesize <=0) { $msg = t('Sorry, maybe your upload is bigger than the PHP configuration allows') . EOL .(t('Or - did you try to upload an empty file?')); if ($r_json) { echo json_encode(array('error'=>$msg)); @@ -101,7 +101,7 @@ function wall_attach_post(App $a) { killme(); } - if (($maxfilesize) && ($filesize > $maxfilesize)) { + if(($maxfilesize) && ($filesize > $maxfilesize)) { $msg = sprintf(t('File exceeds size limit of %s'), formatBytes($maxfilesize)); if ($r_json) { echo json_encode(array('error'=>$msg)); @@ -154,7 +154,7 @@ function wall_attach_post(App $a) { @unlink($src); - if (! $r) { + if(! $r) { $msg = t('File upload failed.'); if ($r_json) { echo json_encode(array('error'=>$msg)); diff --git a/mod/wall_upload.php b/mod/wall_upload.php index 85a174cff..1f71f36b6 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -8,8 +8,8 @@ function wall_upload_post(App $a, $desktopmode = true) { $r_json = (x($_GET,'response') && $_GET['response']=='json'); - if ($a->argc > 1) { - if (! x($_FILES,'media')) { + if($a->argc > 1) { + if(! x($_FILES,'media')) { $nick = $a->argv[1]; $r = q("SELECT `user`.*, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1", dbesc($nick) @@ -44,20 +44,20 @@ function wall_upload_post(App $a, $desktopmode = true) { $page_owner_nick = $r[0]['nickname']; $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false); - if ((local_user()) && (local_user() == $page_owner_uid)) + if((local_user()) && (local_user() == $page_owner_uid)) $can_post = true; else { - if ($community_page && remote_user()) { + if($community_page && remote_user()) { $contact_id = 0; - if (is_array($_SESSION['remote'])) { - foreach ($_SESSION['remote'] as $v) { - if ($v['uid'] == $page_owner_uid) { + if(is_array($_SESSION['remote'])) { + foreach($_SESSION['remote'] as $v) { + if($v['uid'] == $page_owner_uid) { $contact_id = $v['cid']; break; } } } - if ($contact_id) { + if($contact_id) { $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), @@ -72,7 +72,7 @@ function wall_upload_post(App $a, $desktopmode = true) { } - if (! $can_post) { + if(! $can_post) { if ($r_json) { echo json_encode(array('error'=>t('Permission denied.'))); killme(); @@ -81,7 +81,7 @@ function wall_upload_post(App $a, $desktopmode = true) { killme(); } - if (! x($_FILES,'userfile') && ! x($_FILES,'media')){ + if(! x($_FILES,'userfile') && ! x($_FILES,'media')){ if ($r_json) { echo json_encode(array('error'=>t('Invalid request.'))); } @@ -89,13 +89,13 @@ function wall_upload_post(App $a, $desktopmode = true) { } $src = ""; - if (x($_FILES,'userfile')) { + if(x($_FILES,'userfile')) { $src = $_FILES['userfile']['tmp_name']; $filename = basename($_FILES['userfile']['name']); $filesize = intval($_FILES['userfile']['size']); $filetype = $_FILES['userfile']['type']; } - elseif (x($_FILES,'media')) { + elseif(x($_FILES,'media')) { if (is_array($_FILES['media']['tmp_name'])) $src = $_FILES['media']['tmp_name'][0]; else @@ -147,7 +147,7 @@ function wall_upload_post(App $a, $desktopmode = true) { $maximagesize = get_config('system','maximagesize'); - if (($maximagesize) && ($filesize > $maximagesize)) { + if(($maximagesize) && ($filesize > $maximagesize)) { $msg = sprintf( t('Image exceeds size limit of %s'), formatBytes($maximagesize)); if ($r_json) { echo json_encode(array('error'=>$msg)); @@ -182,7 +182,7 @@ function wall_upload_post(App $a, $desktopmode = true) { $imagedata = @file_get_contents($src); $ph = new Photo($imagedata, $filetype); - if (! $ph->is_valid()) { + if(! $ph->is_valid()) { $msg = t('Unable to process image.'); if ($r_json) { echo json_encode(array('error'=>$msg)); @@ -197,9 +197,9 @@ function wall_upload_post(App $a, $desktopmode = true) { @unlink($src); $max_length = get_config('system','max_image_length'); - if (! $max_length) + if(! $max_length) $max_length = MAX_IMAGE_LENGTH; - if ($max_length > 0) { + if($max_length > 0) { $ph->scaleImage($max_length); logger("File upload: Scaling picture to new size ".$max_length, LOGGER_DEBUG); } @@ -215,7 +215,7 @@ function wall_upload_post(App $a, $desktopmode = true) { $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, $defperm); - if (! $r) { + if(! $r) { $msg = t('Image upload failed.'); if ($r_json) { echo json_encode(array('error'=>$msg)); @@ -225,20 +225,18 @@ function wall_upload_post(App $a, $desktopmode = true) { killme(); } - if ($width > 640 || $height > 640) { + if($width > 640 || $height > 640) { $ph->scaleImage(640); $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 1, 0, $defperm); - if ($r) { + if($r) $smallest = 1; - } } - if ($width > 320 || $height > 320) { + if($width > 320 || $height > 320) { $ph->scaleImage(320); $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 2, 0, $defperm); - if ($r AND ($smallest == 0)) { + if($r AND ($smallest == 0)) $smallest = 2; - } } $basename = basename($filename); @@ -246,7 +244,7 @@ function wall_upload_post(App $a, $desktopmode = true) { if (!$desktopmode) { $r = q("SELECT `id`, `datasize`, `width`, `height`, `type` FROM `photo` WHERE `resource-id` = '%s' ORDER BY `width` DESC LIMIT 1", $hash); - if (!dbm::is_result($r)) { + if (!$r){ if ($r_json) { echo json_encode(array('error'=>'')); killme(); diff --git a/mod/wallmessage.php b/mod/wallmessage.php index d2fc91097..ff90e0dbc 100644 --- a/mod/wallmessage.php +++ b/mod/wallmessage.php @@ -5,7 +5,7 @@ require_once('include/message.php'); function wallmessage_post(App $a) { $replyto = get_my_url(); - if (! $replyto) { + if(! $replyto) { notice( t('Permission denied.') . EOL); return; } @@ -14,7 +14,7 @@ function wallmessage_post(App $a) { $body = ((x($_REQUEST,'body')) ? escape_tags(trim($_REQUEST['body'])) : ''); $recipient = (($a->argc > 1) ? notags($a->argv[1]) : ''); - if ((! $recipient) || (! $body)) { + if((! $recipient) || (! $body)) { return; } @@ -29,7 +29,7 @@ function wallmessage_post(App $a) { $user = $r[0]; - if (! intval($user['unkmail'])) { + if(! intval($user['unkmail'])) { notice( t('Permission denied.') . EOL); return; } @@ -38,7 +38,7 @@ function wallmessage_post(App $a) { intval($user['uid']) ); - if ($r[0]['total'] > $user['cntunkmail']) { + if($r[0]['total'] > $user['cntunkmail']) { notice( sprintf( t('Number of daily wall messages for %s exceeded. Message failed.', $user['username']))); return; } @@ -69,14 +69,14 @@ function wallmessage_post(App $a) { function wallmessage_content(App $a) { - if (! get_my_url()) { + if(! get_my_url()) { notice( t('Permission denied.') . EOL); return; } $recipient = (($a->argc > 1) ? $a->argv[1] : ''); - if (! $recipient) { + if(! $recipient) { notice( t('No recipient.') . EOL); return; } @@ -93,19 +93,16 @@ function wallmessage_content(App $a) { $user = $r[0]; - if (! intval($user['unkmail'])) { + if(! intval($user['unkmail'])) { notice( t('Permission denied.') . EOL); return; } - $r = q("SELECT COUNT(*) AS `total` FROM `mail` WHERE `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 1 DAY AND `unknown` = 1", + $r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1", intval($user['uid']) ); - if (!dbm::is_result($r)) { - ///@TODO Output message to use of failed query - return; - } elseif ($r[0]['total'] > $user['cntunkmail']) { + if($r[0]['total'] > $user['cntunkmail']) { notice( sprintf( t('Number of daily wall messages for %s exceeded. Message failed.', $user['username']))); return; } diff --git a/mod/webfinger.php b/mod/webfinger.php index 8e54dd275..eee0580e3 100644 --- a/mod/webfinger.php +++ b/mod/webfinger.php @@ -11,7 +11,7 @@ function webfinger_content(App $a) { $o .= '

    '; - if (x($_GET,'addr')) { + if(x($_GET,'addr')) { $addr = trim($_GET['addr']); $res = Probe::lrdd($addr); $o .= '
    ';
    diff --git a/mod/xrd.php b/mod/xrd.php
    index 93d7b18b0..7b812a7f9 100644
    --- a/mod/xrd.php
    +++ b/mod/xrd.php
    @@ -6,15 +6,14 @@ function xrd_init(App $a) {
     
     	$uri = urldecode(notags(trim($_GET['uri'])));
     
    -	if (substr($uri,0,4) === 'http') {
    +	if(substr($uri,0,4) === 'http') {
     		$acct = false;
     		$name = basename($uri);
     	} else {
     		$acct = true;
     		$local = str_replace('acct:', '', $uri);
    -		if (substr($local,0,2) == '//') {
    +		if(substr($local,0,2) == '//')
     			$local = substr($local,2);
    -		}
     
     		$name = substr($local,0,strpos($local,'@'));
     	}
    diff --git a/object/BaseObject.php b/object/BaseObject.php
    index 5e0c61f49..2666dc1de 100644
    --- a/object/BaseObject.php
    +++ b/object/BaseObject.php
    @@ -1,7 +1,6 @@
     get_mode() == $mode)
    +		if($this->get_mode() == $mode)
     			return;
     
     		$a = $this->get_app();
    @@ -93,11 +92,11 @@ class Conversation extends BaseObject {
     	 */
     	public function add_thread($item) {
     		$item_id = $item->get_id();
    -		if (!$item_id) {
    +		if(!$item_id) {
     			logger('[ERROR] Conversation::add_thread : Item has no ID!!', LOGGER_DEBUG);
     			return false;
     		}
    -		if ($this->get_thread($item->get_id())) {
    +		if($this->get_thread($item->get_id())) {
     			logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG);
     			return false;
     		}
    @@ -105,11 +104,11 @@ class Conversation extends BaseObject {
     		/*
     		 * Only add will be displayed
     		 */
    -		if ($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) {
    +		if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) {
     			logger('[WARN] Conversation::add_thread : Thread is a mail ('. $item->get_id() .').', LOGGER_DEBUG);
     			return false;
     		}
    -		if ($item->get_data_value('verb') === ACTIVITY_LIKE || $item->get_data_value('verb') === ACTIVITY_DISLIKE) {
    +		if($item->get_data_value('verb') === ACTIVITY_LIKE || $item->get_data_value('verb') === ACTIVITY_DISLIKE) {
     			logger('[WARN] Conversation::add_thread : Thread is a (dis)like ('. $item->get_id() .').', LOGGER_DEBUG);
     			return false;
     		}
    @@ -133,14 +132,13 @@ class Conversation extends BaseObject {
     
     		$i = 0;
     
    -		foreach ($this->threads as $item) {
    -			if ($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) {
    +		foreach($this->threads as $item) {
    +			if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid'))
     				continue;
    -			}
     
     			$item_data = $item->get_template_data($conv_responses);
     
    -			if (!$item_data) {
    +			if(!$item_data) {
     				logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG);
     				return false;
     			}
    @@ -158,10 +156,9 @@ class Conversation extends BaseObject {
     	 *      _ false on failure
     	 */
     	private function get_thread($id) {
    -		foreach ($this->threads as $item) {
    -			if ($item->get_id() == $id) {
    +		foreach($this->threads as $item) {
    +			if($item->get_id() == $id)
     				return $item;
    -			}
     		}
     
     		return false;
    diff --git a/object/Item.php b/object/Item.php
    index ab36069c0..b693520b9 100644
    --- a/object/Item.php
    +++ b/object/Item.php
    @@ -1,7 +1,6 @@
     get_profile_owner(),'commtag')) {
    +				if(feature_enabled($conv->get_profile_owner(),'commtag')) {
     					$tagger = array(
     						'add'   => t("add tag"),
     						'class' => "",
    @@ -504,7 +503,7 @@ class Item extends BaseObject {
     	 */
     	protected function set_parent($item) {
     		$parent = $this->get_parent();
    -		if ($parent) {
    +		if($parent) {
     			$parent->remove_child($this);
     		}
     		$this->parent = $item;
    @@ -735,9 +734,9 @@ class Item extends BaseObject {
     		$conv = $this->get_conversation();
     		$this->wall_to_wall = false;
     
    -		if ($this->is_toplevel()) {
    -			if ($conv->get_mode() !== 'profile') {
    -				if ($this->get_data_value('wall') AND !$this->get_data_value('self')) {
    +		if($this->is_toplevel()) {
    +			if($conv->get_mode() !== 'profile') {
    +				if($this->get_data_value('wall') AND !$this->get_data_value('self')) {
     					// On the network page, I am the owner. On the display page it will be the profile owner.
     					// This will have been stored in $a->page_contact by our calling page.
     					// Put this person as the wall owner of the wall-to-wall notice.
    @@ -746,7 +745,7 @@ class Item extends BaseObject {
     					$this->owner_photo = $a->page_contact['thumb'];
     					$this->owner_name = $a->page_contact['name'];
     					$this->wall_to_wall = true;
    -				} elseif ($this->get_data_value('owner-link')) {
    +				} elseif($this->get_data_value('owner-link')) {
     
     					$owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link')));
     					$alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link')));
    diff --git a/testargs.php b/testargs.php
    index a0ddea345..a6042f8eb 100644
    --- a/testargs.php
    +++ b/testargs.php
    @@ -15,8 +15,7 @@
      */
     
     
    -if (($_SERVER["argc"] > 1) && isset($_SERVER["argv"][1])) {
    +if(($_SERVER["argc"] > 1) && isset($_SERVER["argv"][1]))
     	echo $_SERVER["argv"][1];
    -} else {
    +else
     	echo '';
    -}
    diff --git a/tests/contains_attribute_test.php b/tests/contains_attribute_test.php
    index b1e87c17a..b0bb06acf 100644
    --- a/tests/contains_attribute_test.php
    +++ b/tests/contains_attribute_test.php
    @@ -1,51 +1,51 @@
     assertTrue(attribute_contains($testAttr, "class3"));
    -		$this->assertFalse(attribute_contains($testAttr, "class2"));
    -	}
    -	
    -	/**
    -	 * test attribute contains
    -	 */
    -	public function testAttributeContains2() {
    -		$testAttr="class1 not-class2 class3";
    -		$this->assertTrue(attribute_contains($testAttr, "class3"));
    -		$this->assertFalse(attribute_contains($testAttr, "class2"));
    -	}
    +	/**
    +	 * test attribute contains
    +	 */
    +	public function testAttributeContains1() {
    +		$testAttr="class1 notclass2 class3";
    +		$this->assertTrue(attribute_contains($testAttr, "class3"));
    +		$this->assertFalse(attribute_contains($testAttr, "class2"));
    +	}
    +	
    +	/**
    +	 * test attribute contains
    +	 */
    +	public function testAttributeContains2() {
    +		$testAttr="class1 not-class2 class3";
    +		$this->assertTrue(attribute_contains($testAttr, "class3"));
    +		$this->assertFalse(attribute_contains($testAttr, "class2"));
    +	}
     	
     	/**
     	 * test with empty input
    -	 */
    -	public function testAttributeContainsEmpty() {
    -		$testAttr="";
    -		$this->assertFalse(attribute_contains($testAttr, "class2"));
    -	}
    +	 */
    +	public function testAttributeContainsEmpty() {
    +		$testAttr="";
    +		$this->assertFalse(attribute_contains($testAttr, "class2"));
    +	}
     	
     	/**
     	 * test input with special chars
    -	 */
    -	public function testAttributeContainsSpecialChars() {
    -		$testAttr="--... %\$ä() /(=?}";
    -		$this->assertFalse(attribute_contains($testAttr, "class2"));
    +	 */
    +	public function testAttributeContainsSpecialChars() {
    +		$testAttr="--... %\$ä() /(=?}";
    +		$this->assertFalse(attribute_contains($testAttr, "class2"));
     	}
     }
    \ No newline at end of file
    diff --git a/tests/expand_acl_test.php b/tests/expand_acl_test.php
    index 7059fbc0d..154bc921d 100644
    --- a/tests/expand_acl_test.php
    +++ b/tests/expand_acl_test.php
    @@ -8,141 +8,141 @@
     /** required, it is the file under test */
     require_once('include/text.php');
     
    -/**
    - * TestCase for the expand_acl function
    - *
    - * @author Alexander Kampmann
    - * @package test.util
    - */
    +/**
    + * TestCase for the expand_acl function
    + *
    + * @author Alexander Kampmann
    + * @package test.util
    + */
     class ExpandAclTest extends PHPUnit_Framework_TestCase {
     	
    -	/**
    -	 * test expand_acl, perfect input
    -	 */
    -	public function testExpandAclNormal() {
    -		$text='<1><2><3>';
    -		$this->assertEquals(array(1, 2, 3), expand_acl($text));
    -	}
    +	/**
    +	 * test expand_acl, perfect input
    +	 */
    +	public function testExpandAclNormal() {
    +		$text='<1><2><3>';
    +		$this->assertEquals(array(1, 2, 3), expand_acl($text));
    +	}
     	
     	/**
     	 * test with a big number
    -	 */
    -	public function testExpandAclBigNumber() {
    -		$text='<1><'.PHP_INT_MAX.'><15>';
    -		$this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text));
    -	}
    +	 */
    +	public function testExpandAclBigNumber() {
    +		$text='<1><'.PHP_INT_MAX.'><15>';
    +		$this->assertEquals(array(1, PHP_INT_MAX, 15), expand_acl($text));
    +	}
     	
     	/**
     	 * test with a string in it. 
     	 * 
     	 * TODO: is this valid input? Otherwise: should there be an exception?
    -	 */
    -	public function testExpandAclString() {
    -		$text="<1><279012>"; 
    -		$this->assertEquals(array(1, 279012), expand_acl($text));
    -	}
    +	 */
    +	public function testExpandAclString() {
    +		$text="<1><279012>"; 
    +		$this->assertEquals(array(1, 279012), expand_acl($text));
    +	}
     	
     	/**
     	 * test with a ' ' in it. 
     	 * 
     	 * TODO: is this valid input? Otherwise: should there be an exception?
    -	 */
    -	public function testExpandAclSpace() {
    -		$text="<1><279 012><32>"; 
    -		$this->assertEquals(array(1, "279", "32"), expand_acl($text));
    -	}
    +	 */
    +	public function testExpandAclSpace() {
    +		$text="<1><279 012><32>"; 
    +		$this->assertEquals(array(1, "279", "32"), expand_acl($text));
    +	}
     	
     	/**
     	 * test empty input
    -	 */
    -	public function testExpandAclEmpty() {
    -		$text=""; 
    -		$this->assertEquals(array(), expand_acl($text));
    -	}
    +	 */
    +	public function testExpandAclEmpty() {
    +		$text=""; 
    +		$this->assertEquals(array(), expand_acl($text));
    +	}
     	
     	/**
     	 * test invalid input, no < at all
     	 * 
     	 * TODO: should there be an exception?
    -	 */
    -	public function testExpandAclNoBrackets() {
    -		$text="According to documentation, that's invalid. "; //should be invalid
    -		$this->assertEquals(array(), expand_acl($text));
    -	}
    +	 */
    +	public function testExpandAclNoBrackets() {
    +		$text="According to documentation, that's invalid. "; //should be invalid
    +		$this->assertEquals(array(), expand_acl($text));
    +	}
     	
    -	/**
    -	 * test invalid input, just open <
    -	 *
    -	 * TODO: should there be an exception?
    -	 */
    -	public function testExpandAclJustOneBracket1() {
    -		$text="assertEquals(array(), expand_acl($text));
    -	}
    +	/**
    +	 * test invalid input, just open <
    +	 *
    +	 * TODO: should there be an exception?
    +	 */
    +	public function testExpandAclJustOneBracket1() {
    +		$text="assertEquals(array(), expand_acl($text));
    +	}
     	
    -	/**
    -	 * test invalid input, just close >
    -	 *
    -	 * TODO: should there be an exception?
    -	 */
    -	public function testExpandAclJustOneBracket2() {
    -		$text="Another invalid> string"; //should be invalid
    -		$this->assertEquals(array(), expand_acl($text));
    -	}
    +	/**
    +	 * test invalid input, just close >
    +	 *
    +	 * TODO: should there be an exception?
    +	 */
    +	public function testExpandAclJustOneBracket2() {
    +		$text="Another invalid> string"; //should be invalid
    +		$this->assertEquals(array(), expand_acl($text));
    +	}
     	
    -	/**
    -	 * test invalid input, just close >
    -	 *
    -	 * TODO: should there be an exception?
    -	 */
    -	public function testExpandAclCloseOnly() {
    -		$text="Another> invalid> string>"; //should be invalid
    -		$this->assertEquals(array(), expand_acl($text));
    -	}
    +	/**
    +	 * test invalid input, just close >
    +	 *
    +	 * TODO: should there be an exception?
    +	 */
    +	public function testExpandAclCloseOnly() {
    +		$text="Another> invalid> string>"; //should be invalid
    +		$this->assertEquals(array(), expand_acl($text));
    +	}
     	
    -	/**
    -	 * test invalid input, just open <
    -	 *
    -	 * TODO: should there be an exception?
    -	 */
    -	public function testExpandAclOpenOnly() {
    -		$text="assertEquals(array(), expand_acl($text));
    -	}
    +	/**
    +	 * test invalid input, just open <
    +	 *
    +	 * TODO: should there be an exception?
    +	 */
    +	public function testExpandAclOpenOnly() {
    +		$text="assertEquals(array(), expand_acl($text));
    +	}
     	
    -	/**
    -	 * test invalid input, open and close do not match
    -	 *
    -	 * TODO: should there be an exception?
    -	 */
    -	public function testExpandAclNoMatching1() {
    -		$text=" invalid "; //should be invalid
    -		$this->assertEquals(array(), expand_acl($text));
    -	}
    +	/**
    +	 * test invalid input, open and close do not match
    +	 *
    +	 * TODO: should there be an exception?
    +	 */
    +	public function testExpandAclNoMatching1() {
    +		$text=" invalid "; //should be invalid
    +		$this->assertEquals(array(), expand_acl($text));
    +	}
     	
    -	/**
    -	 * test invalid input, open and close do not match
    -	 *
    -	 * TODO: should there be an exception?
    -	 */
    -	public function testExpandAclNoMatching2() {
    -		$text="<1>2><3>";
    +	/**
    +	 * test invalid input, open and close do not match
    +	 *
    +	 * TODO: should there be an exception?
    +	 */
    +	public function testExpandAclNoMatching2() {
    +		$text="<1>2><3>";
     // The angles are delimiters which aren't important
     // the important thing is the numeric content, this returns array(1,2,3) currently
     // we may wish to eliminate 2 from the results, though it isn't harmful
     // It would be a better test to figure out if there is any ACL input which can
     // produce this $text and fix that instead.
    -//		$this->assertEquals(array(), expand_acl($text));
    +//		$this->assertEquals(array(), expand_acl($text));
     	}
     	
    -	/**
    -	 * test invalid input, empty <>
    -	 *
    -	 * TODO: should there be an exception? Or array(1, 3)
    +	/**
    +	 * test invalid input, empty <>
    +	 *
    +	 * TODO: should there be an exception? Or array(1, 3)
     	 * (This should be array(1,3) - mike)
    -	 */
    -	public function testExpandAclEmptyMatch() {
    -		$text="<1><><3>";
    -		$this->assertEquals(array(1,3), expand_acl($text));
    +	 */
    +	public function testExpandAclEmptyMatch() {
    +		$text="<1><><3>";
    +		$this->assertEquals(array(1,3), expand_acl($text));
     	}
     }
    \ No newline at end of file
    diff --git a/tests/get_tags_test.php b/tests/get_tags_test.php
    index 2d49eac24..79dcb36a7 100644
    --- a/tests/get_tags_test.php
    +++ b/tests/get_tags_test.php
    @@ -44,23 +44,23 @@ function q($sql) {
     	$args=func_get_args(); 
     
     	//last parameter is always (in this test) uid, so, it should be 11
    -	if ($args[count($args)-1]!=11) {
    +	if($args[count($args)-1]!=11) {
     		return; 
     	}
     	
     	
    -	if (3==count($args)) {
    +	if(3==count($args)) {
     		//first call in handle_body, id only
    -		if ($result[0]['id']==$args[1]) {
    +		if($result[0]['id']==$args[1]) {
     			return $result; 
     		}
     		//second call in handle_body, name
    -		if ($result[0]['name']===$args[1]) {
    +		if($result[0]['name']===$args[1]) {
     			return $result;
     		}
     	}
     	//third call in handle_body, nick or attag
    -	if ($result[0]['nick']===$args[2] || $result[0]['attag']===$args[1]) {
    +	if($result[0]['nick']===$args[2] || $result[0]['attag']===$args[1]) {
     		return $result;
     	}
     }
    @@ -108,7 +108,7 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
     
     		$inform=''; 
     		$str_tags='';
    -		foreach ($tags as $tag) {
    +		foreach($tags as $tag) {
     			handle_tag($this->a, $text, $inform, $str_tags, 11, $tag);
     		}
     
    @@ -197,7 +197,7 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
     
     		$inform='';
     		$str_tags='';
    -		foreach ($tags as $tag) {
    +		foreach($tags as $tag) {
     			handle_tag($this->a, $text, $inform, $str_tags, 11, $tag);
     		}
     		
    @@ -257,7 +257,7 @@ class GetTagsTest extends PHPUnit_Framework_TestCase {
     		
     		$inform='';
     		$str_tags='';
    -		foreach ($tags as $tag) {
    +		foreach($tags as $tag) {
     			handle_tag($this->a, $text, $inform, $str_tags, 11, $tag);
     		}
     		
    diff --git a/tests/template_test.php b/tests/template_test.php
    index c6e83572e..1f9f80531 100644
    --- a/tests/template_test.php
    +++ b/tests/template_test.php
    @@ -1,11 +1,11 @@
     assertEquals('Hello Anna!', $text);
     	}
     
    -	public function testSimpleVariableInt() {
    -		$tpl='There are $num new messages!';
    -
    -		$text=replace_macros($tpl, array('$num'=>172));
    -
    -		$this->assertEquals('There are 172 new messages!', $text);
    +	public function testSimpleVariableInt() {
    +		$tpl='There are $num new messages!';
    +
    +		$text=replace_macros($tpl, array('$num'=>172));
    +
    +		$this->assertEquals('There are 172 new messages!', $text);
     	}
     
    -	public function testConditionalElse() {
    -		$tpl='There{{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!';
    -
    +	public function testConditionalElse() {
    +		$tpl='There{{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!';
    +
     		$text1=replace_macros($tpl, array('$num'=>1));
    -		$text22=replace_macros($tpl, array('$num'=>22));
    -
    +		$text22=replace_macros($tpl, array('$num'=>22));
    +
     		$this->assertEquals('There is 1 new message!', $text1);
    -		$this->assertEquals('There are 22 new messages!', $text22);
    +		$this->assertEquals('There are 22 new messages!', $text22);
     	}
     
    -	public function testConditionalNoElse() {
    -		$tpl='{{ if $num!=0 }}There are $num new messages!{{ endif }}';
    -
    -		$text0=replace_macros($tpl, array('$num'=>0));
    -		$text22=replace_macros($tpl, array('$num'=>22));
    -
    -		$this->assertEquals('', $text0);
    -		$this->assertEquals('There are 22 new messages!', $text22);
    +	public function testConditionalNoElse() {
    +		$tpl='{{ if $num!=0 }}There are $num new messages!{{ endif }}';
    +
    +		$text0=replace_macros($tpl, array('$num'=>0));
    +		$text22=replace_macros($tpl, array('$num'=>22));
    +
    +		$this->assertEquals('', $text0);
    +		$this->assertEquals('There are 22 new messages!', $text22);
     	}
     
    -	public function testConditionalFail() {
    -		$tpl='There {{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!';
    -
    -		$text1=replace_macros($tpl, array());
    -
    -		//$this->assertEquals('There is 1 new message!', $text1);
    +	public function testConditionalFail() {
    +		$tpl='There {{ if $num!=1 }} are $num new messages{{ else }} is 1 new message{{ endif }}!';
    +
    +		$text1=replace_macros($tpl, array());
    +
    +		//$this->assertEquals('There is 1 new message!', $text1);
     	}
     
    -	public function testSimpleFor() {
    -		$tpl='{{ for $messages as $message }} $message {{ endfor }}';
    -
    -		$text=replace_macros($tpl, array('$messages'=>array('message 1', 'message 2')));
    -
    -		$this->assertEquals(' message 1  message 2 ', $text);
    +	public function testSimpleFor() {
    +		$tpl='{{ for $messages as $message }} $message {{ endfor }}';
    +
    +		$text=replace_macros($tpl, array('$messages'=>array('message 1', 'message 2')));
    +
    +		$this->assertEquals(' message 1  message 2 ', $text);
     	}
     
    -	public function testFor() {
    -		$tpl='{{ for $messages as $message }} from: $message.from to $message.to {{ endfor }}';
    -
    -		$text=replace_macros($tpl, array('$messages'=>array(array('from'=>'Mike', 'to'=>'Alex'), array('from'=>'Alex', 'to'=>'Mike'))));
    -
    -		$this->assertEquals(' from: Mike to Alex  from: Alex to Mike ', $text);
    +	public function testFor() {
    +		$tpl='{{ for $messages as $message }} from: $message.from to $message.to {{ endfor }}';
    +
    +		$text=replace_macros($tpl, array('$messages'=>array(array('from'=>'Mike', 'to'=>'Alex'), array('from'=>'Alex', 'to'=>'Mike'))));
    +
    +		$this->assertEquals(' from: Mike to Alex  from: Alex to Mike ', $text);
     	}
     	
    -	public function testKeyedFor() {
    -		$tpl='{{ for $messages as $from=>$to }} from: $from to $to {{ endfor }}';
    -	
    -		$text=replace_macros($tpl, array('$messages'=>array('Mike'=>'Alex', 'Sven'=>'Mike')));
    -	
    -		$this->assertEquals(' from: Mike to Alex  from: Sven to Mike ', $text);
    +	public function testKeyedFor() {
    +		$tpl='{{ for $messages as $from=>$to }} from: $from to $to {{ endfor }}';
    +	
    +		$text=replace_macros($tpl, array('$messages'=>array('Mike'=>'Alex', 'Sven'=>'Mike')));
    +	
    +		$this->assertEquals(' from: Mike to Alex  from: Sven to Mike ', $text);
     	}
     
    -	public function testForEmpty() {
    -		$tpl='messages: {{for $messages as $message}} from: $message.from to $message.to  {{ endfor }}';
    -
    -		$text=replace_macros($tpl, array('$messages'=>array()));
    -
    -		$this->assertEquals('messages: ', $text);
    +	public function testForEmpty() {
    +		$tpl='messages: {{for $messages as $message}} from: $message.from to $message.to  {{ endfor }}';
    +
    +		$text=replace_macros($tpl, array('$messages'=>array()));
    +
    +		$this->assertEquals('messages: ', $text);
     	}
     
    -	public function testForWrongType() {
    -		$tpl='messages: {{for $messages as $message}} from: $message.from to $message.to  {{ endfor }}';
    -
    -		$text=replace_macros($tpl, array('$messages'=>11));
    -
    -		$this->assertEquals('messages: ', $text);
    +	public function testForWrongType() {
    +		$tpl='messages: {{for $messages as $message}} from: $message.from to $message.to  {{ endfor }}';
    +
    +		$text=replace_macros($tpl, array('$messages'=>11));
    +
    +		$this->assertEquals('messages: ', $text);
     	}
     
    -	public function testForConditional() {
    -		$tpl='new messages: {{for $messages as $message}}{{ if $message.new }} $message.text{{endif}}{{ endfor }}';
    -
    +	public function testForConditional() {
    +		$tpl='new messages: {{for $messages as $message}}{{ if $message.new }} $message.text{{endif}}{{ endfor }}';
    +
     		$text=replace_macros($tpl, array('$messages'=>array(
     				array('new'=>true, 'text'=>'new message'),
    -				array('new'=>false, 'text'=>'old message'))));
    -
    -		$this->assertEquals('new messages:  new message', $text);
    +				array('new'=>false, 'text'=>'old message'))));
    +
    +		$this->assertEquals('new messages:  new message', $text);
     	}
     	
    -	public function testConditionalFor() {
    -		$tpl='{{ if $enabled }}new messages:{{for $messages as $message}} $message.text{{ endfor }}{{endif}}';
    -	
    +	public function testConditionalFor() {
    +		$tpl='{{ if $enabled }}new messages:{{for $messages as $message}} $message.text{{ endfor }}{{endif}}';
    +	
     		$text=replace_macros($tpl, array('$enabled'=>true, 
    -				'$messages'=>array(
    -				array('new'=>true, 'text'=>'new message'),
    -				array('new'=>false, 'text'=>'old message'))));
    -	
    -		$this->assertEquals('new messages: new message old message', $text);
    +				'$messages'=>array(
    +				array('new'=>true, 'text'=>'new message'),
    +				array('new'=>false, 'text'=>'old message'))));
    +	
    +		$this->assertEquals('new messages: new message old message', $text);
     	}
     
    -	public function testFantasy() {
    -		$tpl='Fantasy: {{fantasy $messages}}';
    -
    -		$text=replace_macros($tpl, array('$messages'=>'no no'));
    -
    -		$this->assertEquals('Fantasy: {{fantasy no no}}', $text);
    +	public function testFantasy() {
    +		$tpl='Fantasy: {{fantasy $messages}}';
    +
    +		$text=replace_macros($tpl, array('$messages'=>'no no'));
    +
    +		$this->assertEquals('Fantasy: {{fantasy no no}}', $text);
     	}
     
    -	public function testInc() {
    -		$tpl='{{inc field_input.tpl with $field=$myvar}}{{ endinc }}';
    -
    -		$text=replace_macros($tpl, array('$myvar'=>array('myfield', 'label', 'value', 'help')));
    -
    +	public function testInc() {
    +		$tpl='{{inc field_input.tpl with $field=$myvar}}{{ endinc }}';
    +
    +		$text=replace_macros($tpl, array('$myvar'=>array('myfield', 'label', 'value', 'help')));
    +
     		$this->assertEquals("	\n"
     				."	
    \n" ." \n" ." \n" ." help\n" - ."
    \n", $text); + ."
    \n", $text); } - public function testIncNoVar() { - $tpl='{{inc field_input.tpl }}{{ endinc }}'; - - $text=replace_macros($tpl, array('$field'=>array('myfield', 'label', 'value', 'help'))); - - $this->assertEquals(" \n
    \n \n" - ." \n" - ." help\n" - ."
    \n", $text); + public function testIncNoVar() { + $tpl='{{inc field_input.tpl }}{{ endinc }}'; + + $text=replace_macros($tpl, array('$field'=>array('myfield', 'label', 'value', 'help'))); + + $this->assertEquals(" \n
    \n \n" + ." \n" + ." help\n" + ."
    \n", $text); } - public function testDoubleUse() { - $tpl='Hello $name! {{ if $enabled }} I love you! {{ endif }}'; - - $text=replace_macros($tpl, array('$name'=>'Anna', '$enabled'=>false)); - + public function testDoubleUse() { + $tpl='Hello $name! {{ if $enabled }} I love you! {{ endif }}'; + + $text=replace_macros($tpl, array('$name'=>'Anna', '$enabled'=>false)); + $this->assertEquals('Hello Anna! ', $text); - $tpl='Hey $name! {{ if $enabled }} I hate you! {{ endif }}'; - - $text=replace_macros($tpl, array('$name'=>'Max', '$enabled'=>true)); - - $this->assertEquals('Hey Max! I hate you! ', $text); + $tpl='Hey $name! {{ if $enabled }} I hate you! {{ endif }}'; + + $text=replace_macros($tpl, array('$name'=>'Max', '$enabled'=>true)); + + $this->assertEquals('Hey Max! I hate you! ', $text); } - public function testIncDouble() { + public function testIncDouble() { $tpl='{{inc field_input.tpl with $field=$var1}}{{ endinc }}' - .'{{inc field_input.tpl with $field=$var2}}{{ endinc }}'; - + .'{{inc field_input.tpl with $field=$var2}}{{ endinc }}'; + $text=replace_macros($tpl, array('$var1'=>array('myfield', 'label', 'value', 'help'), - '$var2'=>array('myfield2', 'label2', 'value2', 'help2'))); - - $this->assertEquals(" \n" - ."
    \n" - ." \n" - ." \n" - ." help\n" + '$var2'=>array('myfield2', 'label2', 'value2', 'help2'))); + + $this->assertEquals(" \n" + ."
    \n" + ." \n" + ." \n" + ." help\n" ."
    \n" ." \n" ."
    \n" ." \n" ." \n" ." help2\n" - ."
    \n", $text); + ."
    \n", $text); } } \ No newline at end of file diff --git a/tests/xss_filter_test.php b/tests/xss_filter_test.php index 9e779f767..3fb6ac310 100644 --- a/tests/xss_filter_test.php +++ b/tests/xss_filter_test.php @@ -33,13 +33,13 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase { $this->assertEquals($text, $retext); } - /** - * xmlify and put in a document - */ - public function testXmlifyDocument() { - $tag="I want to break"; + /** + * xmlify and put in a document + */ + public function testXmlifyDocument() { + $tag="I want to break"; $xml=xmlify($tag); - $text=''.$xml.''; + $text=''.$xml.''; $xml_parser=xml_parser_create(); //should be possible to parse it @@ -48,10 +48,10 @@ class AntiXSSTest extends PHPUnit_Framework_TestCase { $this->assertEquals(array('TEXT'=>array(0)), $index); - $this->assertEquals(array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)), + $this->assertEquals(array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)), $values); - xml_parser_free($xml_parser); + xml_parser_free($xml_parser); } /** diff --git a/update.php b/update.php index d54063ba7..3bce49268 100644 --- a/update.php +++ b/update.php @@ -37,7 +37,7 @@ define('UPDATE_VERSION' , 1216); */ -/// @TODO These old updates need to have UPDATE_SUCCESS returned on success? + function update_1000() { q("ALTER TABLE `item` DROP `like`, DROP `dislike` "); @@ -148,7 +148,7 @@ function update_1014() { if (dbm::is_result($r)) { foreach ($r as $rr) { $ph = new Photo($rr['data']); - if ($ph->is_valid()) { + if($ph->is_valid()) { $ph->scaleImage(48); $ph->store($rr['uid'],$rr['contact-id'],$rr['resource-id'],$rr['filename'],$rr['album'],6,(($rr['profile']) ? 1 : 0)); } @@ -157,15 +157,14 @@ function update_1014() { $r = q("SELECT * FROM `contact` WHERE 1"); if (dbm::is_result($r)) { foreach ($r as $rr) { - if (stristr($rr['thumb'],'avatar')) { + if(stristr($rr['thumb'],'avatar')) q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d", dbesc(str_replace('avatar','micro',$rr['thumb'])), intval($rr['id'])); - } else { + else q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d", dbesc(str_replace('5.jpg','6.jpg',$rr['thumb'])), intval($rr['id'])); - } } } } @@ -309,9 +308,9 @@ function update_1030() { function update_1031() { // Repair any bad links that slipped into the item table $r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' "); - if (dbm::is_result($r)) { + if($r && dbm::is_result($r)) { foreach ($r as $rr) { - if (strstr($rr['object'],'type="http')) { + if(strstr($rr['object'],'type="http')) { q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d", dbesc(str_replace('type="http','href="http',$rr['object'])), intval($rr['id']) @@ -369,11 +368,13 @@ function update_1036() { } function update_1037() { + q("ALTER TABLE `contact` CHANGE `lrdd` `alias` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL "); + } function update_1038() { - q("ALTER TABLE `item` ADD `plink` CHAR( 255 ) NOT NULL AFTER `target` "); + q("ALTER TABLE `item` ADD `plink` CHAR( 255 ) NOT NULL AFTER `target` "); } function update_1039() { @@ -530,12 +531,9 @@ function update_1065() { } function update_1066() { - $r = q("ALTER TABLE `item` ADD `received` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `edited` "); - - /// @TODO Decide to use dbm::is_result() here, what does $r include? - if ($r) { + $r = q("ALTER TABLE `item` ADD `received` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00' AFTER `edited` "); + if($r) q("ALTER TABLE `item` ADD INDEX ( `received` ) "); - } $r = q("UPDATE `item` SET `received` = `edited` WHERE 1"); } @@ -597,11 +595,10 @@ function update_1074() { q("ALTER TABLE `user` ADD `hidewall` TINYINT( 1) NOT NULL DEFAULT '0' AFTER `blockwall` "); $r = q("SELECT `uid` FROM `profile` WHERE `is-default` = 1 AND `hidewall` = 1"); if (dbm::is_result($r)) { - foreach ($r as $rr) { + foreach($r as $rr) q("UPDATE `user` SET `hidewall` = 1 WHERE `uid` = %d", intval($rr['uid']) ); - } } q("ALTER TABLE `profile` DROP `hidewall`"); } @@ -617,9 +614,8 @@ function update_1075() { $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1", dbesc($guid) ); - if (!dbm::is_result($x)) { + if(! count($x)) $found = false; - } } while ($found == true ); q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d", @@ -688,19 +684,14 @@ function update_1082() { q("ALTER TABLE `photo` ADD `guid` CHAR( 64 ) NOT NULL AFTER `contact-id`, ADD INDEX ( `guid` ) "); // make certain the following code is only executed once - - $r = q("SELECT `id` FROM `photo` WHERE `guid` != '' LIMIT 1"); - - if (dbm::is_result($r)) { + $r = q("select `id` from `photo` where `guid` != '' limit 1"); + if (dbm::is_result($r)) return; - } - $r = q("SELECT distinct(`resource-id`) FROM `photo` WHERE 1 group by `id`"); - if (dbm::is_result($r)) { foreach ($r as $rr) { $guid = get_guid(); - q("UPDATE `photo` SET `guid` = '%s' WHERE `resource-id` = '%s'", + q("update `photo` set `guid` = '%s' where `resource-id` = '%s'", dbesc($guid), dbesc($rr['resource-id']) ); @@ -745,13 +736,11 @@ function update_1087() { $x = q("SELECT max(`created`) AS `cdate` FROM `item` WHERE `parent` = %d LIMIT 1", intval($rr['id']) ); - - if (dbm::is_result($x)) { + if(count($x)) q("UPDATE `item` SET `commented` = '%s' WHERE `id` = %d", dbesc($x[0]['cdate']), intval($rr['id']) ); - } } } } @@ -860,14 +849,14 @@ function update_1099() { function update_1100() { q("ALTER TABLE `contact` ADD `nurl` CHAR( 255 ) NOT NULL AFTER `url` "); - q("ALTER TABLE `contact` ADD INDEX (`nurl`) "); + q("alter table contact add index (`nurl`) "); require_once('include/text.php'); - $r = q("SELECT `id`, `url` FROM `contact` WHERE `url` != '' AND `nurl` = '' "); + $r = q("select id, url from contact where url != '' and nurl = '' "); if (dbm::is_result($r)) { foreach ($r as $rr) { - q("UPDATE `contact` SET `nurl` = '%s' WHERE `id` = %d", + q("update contact set nurl = '%s' where id = %d", dbesc(normalise_link($rr['url'])), intval($rr['id']) ); @@ -897,7 +886,6 @@ function update_1102() { function update_1103() { -/// @TODO Commented out: // q("ALTER TABLE `item` ADD INDEX ( `wall` ) "); q("ALTER TABLE `item` ADD FULLTEXT ( `tag` ) "); q("ALTER TABLE `contact` ADD INDEX ( `pending` ) "); @@ -1043,11 +1031,9 @@ function update_1120() { $r = q("describe item"); if (dbm::is_result($r)) { - foreach ($r as $rr) { - if ($rr['Field'] == 'spam') { + foreach($r as $rr) + if($rr['Field'] == 'spam') return; - } - } } q("ALTER TABLE `item` ADD `spam` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` , ADD INDEX (`spam`) "); @@ -1081,16 +1067,16 @@ function update_1121() { } function update_1122() { - q("ALTER TABLE `notify` ADD `hash` CHAR( 64 ) NOT NULL AFTER `id` , +q("ALTER TABLE `notify` ADD `hash` CHAR( 64 ) NOT NULL AFTER `id` , ADD INDEX ( `hash` ) "); } function update_1123() { - set_config('system','allowed_themes','dispy,quattro,testbubble,vier,darkbubble,darkzero,duepuntozero,greenzero,purplezero,quattro-green,slackr'); +set_config('system','allowed_themes','dispy,quattro,testbubble,vier,darkbubble,darkzero,duepuntozero,greenzero,purplezero,quattro-green,slackr'); } function update_1124() { - q("ALTER TABLE `item` ADD INDEX (`author-name`) "); +q("alter table item add index (`author-name`) "); } function update_1125() { @@ -1102,7 +1088,7 @@ function update_1125() { `receiver-uid` INT NOT NULL, INDEX ( `master-parent-item` ), INDEX ( `receiver-uid` ) - ) DEFAULT CHARSET=utf8"); + ) ENGINE = MyISAM DEFAULT CHARSET=utf8"); } function update_1126() { @@ -1121,12 +1107,12 @@ function update_1127() { INDEX ( `spam` ), INDEX ( `ham` ), INDEX ( `term` ) - ) DEFAULT CHARSET=utf8"); + ) ENGINE = MyISAM DEFAULT CHARSET=utf8"); } function update_1128() { - q("ALTER TABLE `spam` ADD `date` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `term` "); + q("alter table spam add `date` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00' AFTER `term` "); } function update_1129() { @@ -1147,14 +1133,14 @@ function update_1132() { `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `username` CHAR( 255 ) NOT NULL, INDEX ( `username` ) -) "); +) ENGINE = MYISAM "); } function update_1133() { - q("ALTER TABLE `user` ADD `unkmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocktags` , ADD INDEX ( `unkmail` ) "); - q("ALTER TABLE `user` ADD `cntunkmail` INT NOT NULL DEFAULT '10' AFTER `unkmail` , ADD INDEX ( `cntunkmail` ) "); - q("ALTER TABLE `mail` ADD `unknown` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `replied` , ADD INDEX ( `unknown` ) "); +q("ALTER TABLE `user` ADD `unkmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocktags` , ADD INDEX ( `unkmail` ) "); +q("ALTER TABLE `user` ADD `cntunkmail` INT NOT NULL DEFAULT '10' AFTER `unkmail` , ADD INDEX ( `cntunkmail` ) "); +q("ALTER TABLE `mail` ADD `unknown` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `replied` , ADD INDEX ( `unknown` ) "); } function update_1134() { @@ -1181,38 +1167,38 @@ function update_1136() { // order in reverse so that we save the newest entry - $r = q("SELECT * FROM `config` WHERE 1 ORDER BY `id` DESC"); + $r = q("select * from config where 1 order by id desc"); if (dbm::is_result($r)) { foreach ($r as $rr) { $found = false; - foreach ($arr as $x) { - if ($x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { + foreach($arr as $x) { + if($x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { $found = true; - q("DELETE FROM `config` WHERE `id` = %d", + q("delete from config where id = %d", intval($rr['id']) ); } } - if (! $found) { + if(! $found) { $arr[] = $rr; } } } $arr = array(); - $r = q("SELECT * FROM `pconfig` WHERE 1 ORDER BY `id` DESC"); + $r = q("select * from pconfig where 1 order by id desc"); if (dbm::is_result($r)) { foreach ($r as $rr) { $found = false; - foreach ($arr as $x) { - if ($x['uid'] == $rr['uid'] && $x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { + foreach($arr as $x) { + if($x['uid'] == $rr['uid'] && $x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { $found = true; - q("DELETE FROM `pconfig` WHERE `id` = %d", + q("delete from pconfig where id = %d", intval($rr['id']) ); } } - if (! $found) { + if(! $found) { $arr[] = $rr; } } @@ -1224,153 +1210,114 @@ function update_1136() { function update_1137() { - q("ALTER TABLE `item_id` DROP `face` , DROP `dspr` , DROP `twit` , DROP `stat` "); - q("ALTER TABLE `item_id` ADD `sid` CHAR( 255 ) NOT NULL AFTER `uid` , ADD `service` CHAR( 255 ) NOT NULL AFTER `sid` , ADD INDEX (`sid`), ADD INDEX ( `service`) "); + q("alter table item_id DROP `face` , DROP `dspr` , DROP `twit` , DROP `stat` "); + q("ALTER TABLE `item_id` ADD `sid` CHAR( 255 ) NOT NULL AFTER `uid` , ADD `service` CHAR( 255 ) NOT NULL AFTER `sid` , add index (`sid`), add index ( `service`) "); } function update_1138() { - q("ALTER TABLE `contact` ADD `archive` TINYINT(1) NOT NULL DEFAULT '0' AFTER `hidden`, ADD INDEX (`archive`)"); + q("alter table contact add archive tinyint(1) not null default '0' after hidden, add index (archive)"); } function update_1139() { - $r = q("ALTER TABLE `user` ADD `account_removed` TINYINT(1) NOT NULL DEFAULT '0' AFTER `expire`, ADD INDEX(`account_removed`)"); - - if ($r) { - return UPDATE_SUCCESS ; - } - - return UPDATE_FAILED ; + $r = q("alter table user add account_removed tinyint(1) not null default '0' after expire, add index(account_removed) "); + if(! $r) + return UPDATE_FAILED ; + return UPDATE_SUCCESS ; } function update_1140() { - $r = q("ALTER TABLE `addon` ADD `hidden` TINYINT(1) NOT NULL DEFAULT '0' AFTER `installed`, ADD INDEX(`hidden`) "); - - if ($r) { - return UPDATE_SUCCESS ; - } - - return UPDATE_FAILED ; + $r = q("alter table addon add hidden tinyint(1) not null default '0' after installed, add index(hidden) "); + if(! $r) + return UPDATE_FAILED ; + return UPDATE_SUCCESS ; } function update_1141() { - $r = q("ALTER TABLE `glink` ADD `zcid` INT(11) NOT NULL AFTER `gcid`, ADD INDEX(`zcid`) "); - - if ($r) { - return UPDATE_SUCCESS ; - } - - return UPDATE_FAILED ; + $r = q("alter table glink add zcid int(11) not null after gcid, add index(zcid) "); + if(! $r) + return UPDATE_FAILED ; + return UPDATE_SUCCESS ; } function update_1142() { - $r = q("ALTER TABLE `user` ADD `service_class` CHAR(32) NOT NULL AFTER `expire_notification_sent`, ADD INDEX(`service_class`) "); - - if ($r) { - return UPDATE_SUCCESS ; - } - - return UPDATE_FAILED ; + $r = q("alter table user add service_class char(32) not null after expire_notification_sent, add index(service_class) "); + if(! $r) + return UPDATE_FAILED ; + return UPDATE_SUCCESS ; } function update_1143() { - $r = q("ALTER TABLE `user` ADD `def_gid` INT(11) NOT NULL DEFAULT '0' AFTER `service_class`"); - - if ($r) { - return UPDATE_SUCCESS ; - } - - return UPDATE_FAILED ; + $r = q("alter table user add def_gid int(11) not null default '0' after service_class"); + if(! $r) + return UPDATE_FAILED ; + return UPDATE_SUCCESS ; } function update_1144() { - $r = q("ALTER TABLE `contact` ADD `prv` TINYINT(1) NOT NULL DEFAULT '0' AFTER `forum`"); - - if ($r) { - return UPDATE_SUCCESS ; - } - - return UPDATE_FAILED ; + $r = q("alter table contact add prv tinyint(1) not null default '0' after forum"); + if(! $r) + return UPDATE_FAILED ; + return UPDATE_SUCCESS ; } function update_1145() { - $r = q("ALTER TABLE `profile` ADD `howlong` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `with`"); - - if ($r) { - return UPDATE_SUCCESS ; - } - - return UPDATE_FAILED ; + $r = q("alter table profile add howlong datetime not null default '0001-01-01 00:00:00' after `with`"); + if(! $r) + return UPDATE_FAILED ; + return UPDATE_SUCCESS ; } function update_1146() { - $r = q("ALTER TABLE `profile` ADD `hometown` CHAR(255) NOT NULL AFTER `country-name`, ADD INDEX ( `hometown` ) "); - - if ($r) { - return UPDATE_SUCCESS ; - } - - return UPDATE_FAILED ; + $r = q("alter table profile add hometown char(255) not null after `country-name`, add index ( `hometown` ) "); + if(! $r) + return UPDATE_FAILED ; + return UPDATE_SUCCESS ; } function update_1147() { $r1 = q("ALTER TABLE `sign` ALTER `iid` SET DEFAULT '0'"); $r2 = q("ALTER TABLE `sign` ADD `retract_iid` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `iid`"); $r3 = q("ALTER TABLE `sign` ADD INDEX ( `retract_iid` )"); - - if ($r1 && $r2 && $r3) { - return UPDATE_SUCCESS ; - } - - return UPDATE_FAILED ; + if((! $r1) || (! $r2) || (! $r3)) + return UPDATE_FAILED ; + return UPDATE_SUCCESS ; } function update_1148() { - $r = q("ALTER TABLE `photo` ADD `type` CHAR(128) NOT NULL DEFAULT 'image/jpeg' AFTER `filename`"); - - if ($r) { - return UPDATE_SUCCESS ; - } - - return UPDATE_FAILED ; + $r = q("ALTER TABLE photo ADD type CHAR(128) NOT NULL DEFAULT 'image/jpeg' AFTER filename"); + if (!$r) + return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1149() { - $r1 = q("ALTER TABLE `profile` ADD `likes` TEXT NOT NULL AFTER `prv_keywords`"); - $r2 = q("ALTER TABLE `profile` ADD `dislikes` TEXT NOT NULL AFTER `likes`"); - - if ($r1 && $r2) { - return UPDATE_SUCCESS; - } - - return UPDATE_FAILED; + $r1 = q("ALTER TABLE profile ADD likes text NOT NULL after prv_keywords"); + $r2 = q("ALTER TABLE profile ADD dislikes text NOT NULL after likes"); + if (! ($r1 && $r2)) + return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1150() { - $r = q("ALTER TABLE `event` ADD `summary` TEXT NOT NULL AFTER `finish`, ADD INDEX ( `uid` ), ADD INDEX ( `cid` ), ADD INDEX ( `uri` ), ADD INDEX ( `start` ), ADD INDEX ( `finish` ), ADD INDEX ( `type` ), ADD INDEX ( `adjust` ) "); - - if ($r) { - return UPDATE_SUCCESS ; - } - - return UPDATE_FAILED ; + $r = q("ALTER TABLE event ADD summary text NOT NULL after finish, add index ( uid ), add index ( cid ), add index ( uri ), add index ( `start` ), add index ( finish ), add index ( `type` ), add index ( adjust ) "); + if(! $r) + return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1151() { - $r = q("CREATE TABLE IF NOT EXISTS `locks` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `name` CHAR( 128 ) NOT NULL , - `locked` TINYINT( 1 ) NOT NULL DEFAULT '0' - ) DEFAULT CHARSET=utf8 "); - - if ($r) { - return UPDATE_SUCCESS ; - } - - return UPDATE_FAILED ; + $r = q("CREATE TABLE IF NOT EXISTS locks ( + id INT NOT NULL AUTO_INCREMENT PRIMARY KEY , + name CHAR( 128 ) NOT NULL , + locked TINYINT( 1 ) NOT NULL DEFAULT '0' + ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); + if (!$r) + return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1152() { @@ -1385,33 +1332,24 @@ function update_1152() { KEY `otype` ( `otype` ), KEY `type` ( `type` ), KEY `term` ( `term` ) - ) DEFAULT CHARSET=utf8 "); - - if ($r) { - return UPDATE_SUCCESS; - } - - return UPDATE_FAILED; + ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); + if (!$r) + return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1153() { $r = q("ALTER TABLE `hook` ADD `priority` INT(11) UNSIGNED NOT NULL DEFAULT '0'"); - if ($r) { - return UPDATE_SUCCESS; - } - - return UPDATE_FAILED; + if(!$r) return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1154() { $r = q("ALTER TABLE `event` ADD `ignore` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `adjust` , ADD INDEX ( `ignore` )"); - if ($r) { - return UPDATE_SUCCESS; - } - - return UPDATE_FAILED; + if(!$r) return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1155() { @@ -1419,9 +1357,8 @@ function update_1155() { $r2 = q("ALTER TABLE `item_id` ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST"); $r3 = q("ALTER TABLE `item_id` ADD INDEX ( `iid` ) "); - if ($r1 && $r2 && $r3) { + if($r1 && $r2 && $r3) return UPDATE_SUCCESS; - } return UPDATE_FAILED; } @@ -1430,15 +1367,12 @@ function update_1156() { $r = q("ALTER TABLE `photo` ADD `datasize` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `width` , ADD INDEX ( `datasize` ) "); - if ($r) { - return UPDATE_SUCCESS; - } - - return UPDATE_FAILED; + if(!$r) return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1157() { - $r = q("CREATE TABLE IF NOT EXISTS `dsprphotoq` ( + $r = q("CREATE TABLE IF NOT EXISTS `dsprphotoq` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `uid` int(11) NOT NULL, `msg` mediumtext NOT NULL, @@ -1447,11 +1381,8 @@ function update_1157() { ) ENGINE=MyISAM DEFAULT CHARSET=utf8" ); - if ($r) { + if($r) return UPDATE_SUCCESS; - } - - return UPDATE_FAILED; } function update_1158() { @@ -1464,9 +1395,8 @@ function update_1158() { $r = q("CREATE INDEX event_id ON item(`event-id`)"); set_config('system', 'maintenance', 0); - if ($r) { + if($r) return UPDATE_SUCCESS; - } return UPDATE_FAILED; } @@ -1477,11 +1407,10 @@ function update_1159() { ADD INDEX (`uid`), ADD INDEX (`aid`)"); - if ($r) { - return UPDATE_SUCCESS; - } + if(!$r) + return UPDATE_FAILED; - return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1160() { @@ -1494,21 +1423,19 @@ function update_1160() { $r = q("ALTER TABLE `item` ADD `mention` TINYINT(1) NOT NULL DEFAULT '0', ADD INDEX (`mention`)"); set_config('system', 'maintenance', 0); - if ($r) { - return UPDATE_SUCCESS; - } + if(!$r) + return UPDATE_FAILED; - return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1161() { $r = q("ALTER TABLE `pconfig` ADD INDEX (`cat`)"); - if ($r) { - return UPDATE_SUCCESS; - } + if(!$r) + return UPDATE_FAILED; - return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1162() { @@ -1524,12 +1451,10 @@ function update_1163() { $r = q("ALTER TABLE `item` ADD `network` char(32) NOT NULL"); set_config('system', 'maintenance', 0); + if(!$r) + return UPDATE_FAILED; - if ($r) { - return UPDATE_SUCCESS; - } - - return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1164() { set_config('system', 'maintenance', 1); @@ -1586,21 +1511,19 @@ function update_1164() { function update_1165() { $r = q("CREATE TABLE IF NOT EXISTS `push_subscriber` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `uid` INT NOT NULL, - `callback_url` CHAR( 255 ) NOT NULL, - `topic` CHAR( 255 ) NOT NULL, - `nickname` CHAR( 255 ) NOT NULL, - `push` INT NOT NULL, - `last_update` DATETIME NOT NULL, - `secret` CHAR( 255 ) NOT NULL - ) DEFAULT CHARSET=utf8 "); + `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + `uid` INT NOT NULL, + `callback_url` CHAR( 255 ) NOT NULL, + `topic` CHAR( 255 ) NOT NULL, + `nickname` CHAR( 255 ) NOT NULL, + `push` INT NOT NULL, + `last_update` DATETIME NOT NULL, + `secret` CHAR( 255 ) NOT NULL + ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); + if (!$r) + return UPDATE_FAILED; - if ($r) { - return UPDATE_SUCCESS; - } - - return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1166() { @@ -1611,33 +1534,27 @@ function update_1166() { `name` CHAR(255) NOT NULL, `avatar` CHAR(255) NOT NULL, INDEX (`url`) - ) DEFAULT CHARSET=utf8 "); + ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); + if (!$r) + return UPDATE_FAILED; - if ($r) { - return UPDATE_SUCCESS; - } - - return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1167() { $r = q("ALTER TABLE `contact` ADD `notify_new_posts` TINYINT(1) NOT NULL DEFAULT '0'"); + if (!$r) + return UPDATE_FAILED; - if ($r) { - return UPDATE_SUCCESS; - } - - return UPDATE_FAILED; + return UPDATE_SUCCESS; } function update_1168() { $r = q("ALTER TABLE `contact` ADD `fetch_further_information` TINYINT(1) NOT NULL DEFAULT '0'"); + if (!$r) + return UPDATE_FAILED; - if ($r) { - return UPDATE_SUCCESS ; - } - - return UPDATE_FAILED ; + return UPDATE_SUCCESS; } function update_1169() { @@ -1675,10 +1592,8 @@ function update_1169() { KEY `uid_created` (`uid`,`created`), KEY `uid_commented` (`uid`,`commented`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); - - if (!$r) { + if (!$r) return UPDATE_FAILED; - } proc_run(PRIORITY_LOW, "include/threadupdate.php"); @@ -1756,7 +1671,7 @@ function update_1190() { $plugins = get_config('system','addon'); $plugins_arr = array(); - if ($plugins) { + if($plugins) { $plugins_arr = explode(",",str_replace(" ", "",$plugins)); $idx = array_search($plugin, $plugins_arr); @@ -1784,22 +1699,19 @@ function update_1190() { $key = $rr['k']; $value = $rr['v']; - if ($key === 'randomise') { + if ($key === 'randomise') del_pconfig($uid,$family,$key); - } if ($key === 'show_on_profile') { - if ($value) { + if ($value) set_pconfig($uid,feature,forumlist_profile,$value); - } del_pconfig($uid,$family,$key); } if ($key === 'show_on_network') { - if ($value) { + if ($value) set_pconfig($uid,feature,forumlist_widget,$value); - } del_pconfig($uid,$family,$key); } diff --git a/util/db_update.php b/util/db_update.php index 7718162f6..32b44e6d0 100644 --- a/util/db_update.php +++ b/util/db_update.php @@ -24,7 +24,7 @@ echo "Old DB VERSION: " . $build . "\n"; echo "New DB VERSION: " . DB_UPDATE_VERSION . "\n"; -if ($build != DB_UPDATE_VERSION) { +if($build != DB_UPDATE_VERSION) { echo "Updating database..."; check_db($a); echo "Done\n"; diff --git a/util/docblox_errorchecker.php b/util/docblox_errorchecker.php index a7d1ecce1..af4c76444 100644 --- a/util/docblox_errorchecker.php +++ b/util/docblox_errorchecker.php @@ -33,7 +33,7 @@ */ function namesList($fileset) { $fsparam=""; - foreach ($fileset as $file) { + foreach($fileset as $file) { $fsparam=$fsparam.",".$file; } return $fsparam; @@ -50,7 +50,7 @@ function namesList($fileset) { function runs($fileset) { $fsParam=namesList($fileset); exec('docblox -t phpdoc_out -f '.$fsParam); - if (file_exists("phpdoc_out/index.html")) { + if(file_exists("phpdoc_out/index.html")) { echo "\n Subset ".$fsParam." is okay. \n"; exec('rm -r phpdoc_out'); return true; @@ -79,7 +79,7 @@ function reduce($fileset, $ps) { //filter working subsets... $parts=array_filter($parts, "runs"); //melt remaining parts together - if (is_array($parts)) { + if(is_array($parts)) { return array_reduce($parts, "array_merge", array()); } return array(); @@ -94,17 +94,17 @@ $dirstack=array(); $filelist=array(); //loop over all files in $dir -while ($dh=opendir($dir)) { - while ($file=readdir($dh)) { - if (is_dir($dir."/".$file)) { +while($dh=opendir($dir)) { + while($file=readdir($dh)) { + if(is_dir($dir."/".$file)) { //add to directory stack - if ($file!=".." && $file!=".") { + if($file!=".." && $file!=".") { array_push($dirstack, $dir."/".$file); echo "dir ".$dir."/".$file."\n"; } } else { //test if it is a source file and add to filelist - if (substr($file, strlen($file)-4)==".php") { + if(substr($file, strlen($file)-4)==".php") { array_push($filelist, $dir."/".$file); echo $dir."/".$file."\n"; } @@ -115,7 +115,7 @@ while ($dh=opendir($dir)) { } //check the entire set -if (runs($filelist)) { +if(runs($filelist)) { echo "I can not detect a problem. \n"; exit; } @@ -128,15 +128,15 @@ do { echo $i."/".count($fileset)." elements remaining. \n"; $res=reduce($res, count($res)/2); shuffle($res); -} while (count($res)<$i); +} while(count($res)<$i); //check one file after another $needed=array(); -while (count($res)!=0) { +while(count($res)!=0) { $file=array_pop($res); - if (runs(array_merge($res, $needed))) { + if(runs(array_merge($res, $needed))) { echo "needs: ".$file." and file count ".count($needed); array_push($needed, $file); } diff --git a/util/extract.php b/util/extract.php index 3eb332d4f..90127f3c1 100644 --- a/util/extract.php +++ b/util/extract.php @@ -6,7 +6,7 @@ $files = array_merge($files,glob('mod/*'),glob('include/*'),glob('addon/*/*')); - foreach ($files as $file) { + foreach($files as $file) { $str = file_get_contents($file); $pat = '| t\(([^\)]*)\)|'; @@ -16,14 +16,14 @@ preg_match_all($patt, $str, $matchestt); - if (count($matches)){ - foreach ($matches[1] as $match) { - if (! in_array($match,$arr)) + if(count($matches)){ + foreach($matches[1] as $match) { + if(! in_array($match,$arr)) $arr[] = $match; } } - if (count($matchestt)){ - foreach ($matchestt[1] as $match) { + if(count($matchestt)){ + foreach($matchestt[1] as $match) { $matchtkns = preg_split("|[ \t\r\n]*,[ \t\r\n]*|",$match); if (count($matchtkns)==3 && !in_array($matchtkns,$arr)){ $arr[] = $matchtkns; @@ -41,26 +41,23 @@ function string_plural_select($n){ '; - foreach ($arr as $a) { + foreach($arr as $a) { if (is_array($a)){ - if (substr($a[1],0,1) == '$') { + if(substr($a[1],0,1) == '$') continue; - } $s .= '$a->strings[' . $a[0] . "] = array(\n"; $s .= "\t0 => ". $a[0]. ",\n"; $s .= "\t1 => ". $a[1]. ",\n"; $s .= ");\n"; } else { - if (substr($a,0,1) == '$') { - continue; - } + if(substr($a,0,1) == '$') + continue; $s .= '$a->strings[' . $a . '] = '. $a . ';' . "\n"; } } $zones = timezone_identifiers_list(); - foreach ($zones as $zone) { + foreach($zones as $zone) $s .= '$a->strings[\'' . $zone . '\'] = \'' . $zone . '\';' . "\n"; - } - + echo $s; \ No newline at end of file diff --git a/util/php2po.php b/util/php2po.php index 8bc4ce8c6..2e888008c 100644 --- a/util/php2po.php +++ b/util/php2po.php @@ -10,7 +10,7 @@ DEFINE("NORM_REGEXP", "|[\\\]|"); - if (! class_exists('App')) { + if(! class_exists('App')) { class TmpA { public $strings = Array(); } @@ -68,7 +68,7 @@ } $infile = file($phpfile); - foreach ($infile as $l) { + foreach($infile as $l) { $l = trim($l); if (startsWith($l, 'function string_plural_select_')) { $lang = str_replace( 'function string_plural_select_' , '', str_replace( '($n){','', $l) ); @@ -94,7 +94,7 @@ $norm_base_msgids = array(); $base_f = file("util/messages.po") or die("No base messages.po\n"); $_f = 0; $_mid = ""; $_mids = array(); - foreach ( $base_f as $l) { + foreach( $base_f as $l) { $l = trim($l); //~ print $l."\n"; @@ -165,7 +165,7 @@ } $warnings = ""; - foreach ($a->strings as $key=>$str) { + foreach($a->strings as $key=>$str) { $msgid = massage_string($key); if (preg_match("|%[sd0-9](\$[sn])*|", $msgid)) { diff --git a/util/po2php.php b/util/po2php.php index 86c41236e..30d77342b 100644 --- a/util/po2php.php +++ b/util/po2php.php @@ -12,11 +12,10 @@ function po2php_run(&$argv, &$argc) { $pofile = $argv[1]; $outfile = dirname($pofile)."/strings.php"; - if (strstr($outfile,'util')) { + if(strstr($outfile,'util')) $lang = 'en'; - } else { + else $lang = str_replace('-','_',basename(dirname($pofile))); - } @@ -42,45 +41,34 @@ function po2php_run(&$argv, &$argc) { foreach ($infile as $l) { $l = str_replace('\"', DQ_ESCAPE, $l); $len = strlen($l); - if ($l[0]=="#") { - $l=""; - } - if (substr($l,0,15) == '"Plural-Forms: '){ + if ($l[0]=="#") $l=""; + if (substr($l,0,15)=='"Plural-Forms: '){ $match=Array(); preg_match("|nplurals=([0-9]*); *plural=(.*)[;\\\\]|", $l, $match); $cond = str_replace('n','$n',$match[2]); // define plural select function if not already defined $fnname = 'string_plural_select_' . $lang; - $out .= 'if (! function_exists("'.$fnname.'")) {'."\n"; + $out .= 'if(! function_exists("'.$fnname.'")) {'."\n"; $out .= 'function '. $fnname . '($n){'."\n"; $out .= ' return '.$cond.';'."\n"; $out .= '}}'."\n"; } - if ($k!="" && substr($l,0,7) == "msgstr "){ - if ($ink) { - $ink = False; - $out .= '$a->strings["'.$k.'"] = '; - } - if ($inv) { - $inv = False; - $out .= '"'.$v.'"'; - } + + + + if ($k!="" && substr($l,0,7)=="msgstr "){ + if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; } + if ($inv) { $inv = False; $out .= '"'.$v.'"'; } $v = substr($l,8,$len-10); $v = preg_replace_callback($escape_s_exp,'escape_s',$v); $inv = True; //$out .= $v; } - if ($k!="" && substr($l,0,7) == "msgstr["){ - if ($ink) { - $ink = False; - $out .= '$a->strings["'.$k.'"] = '; - } - if ($inv) { - $inv = False; - $out .= '"'.$v.'"'; - } + if ($k!="" && substr($l,0,7)=="msgstr["){ + if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; } + if ($inv) { $inv = False; $out .= '"'.$v.'"'; } if (!$arr) { $arr=True; @@ -96,6 +84,7 @@ function po2php_run(&$argv, &$argc) { if (substr($l,0,6)=="msgid_") { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }; + if ($ink) { $k .= trim($l,"\"\r\n"); $k = preg_replace_callback($escape_s_exp,'escape_s',$k); @@ -103,14 +92,9 @@ function po2php_run(&$argv, &$argc) { } if (substr($l,0,6)=="msgid "){ - if ($inv) { - $inv = False; - $out .= '"'.$v.'"'; - } - if ($k != "") { - $out .= $arr?");\n":";\n"; - } - $arr = False; + if ($inv) { $inv = False; $out .= '"'.$v.'"'; } + if ($k!="") $out .= $arr?");\n":";\n"; + $arr=False; $k = str_replace("msgid ","",$l); if ($k != '""' ) { $k = trim($k,"\"\r\n"); @@ -131,13 +115,8 @@ function po2php_run(&$argv, &$argc) { } - if ($inv) { - $inv = False; - $out .= '"'.$v.'"'; - } - if ($k!="") { - $out .= $arr?");\n":";\n"; - } + if ($inv) { $inv = False; $out .= '"'.$v.'"'; } + if ($k!="") $out .= $arr?");\n":";\n"; $out = str_replace(DQ_ESCAPE, '\"', $out); file_put_contents($outfile, $out); diff --git a/util/typo.php b/util/typo.php index c45be483c..d68ac2ac9 100644 --- a/util/typo.php +++ b/util/typo.php @@ -1,58 +1,59 @@ config,'php_path')) { - $phpath = $a->config['php_path']; -} else { - $phpath = 'php'; -} + if(x($a->config,'php_path')) + $phpath = $a->config['php_path']; + else + $phpath = 'php'; -echo "Directory: mod\n"; -$files = glob('mod/*.php'); -foreach ($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); -} -echo "Directory: include\n"; -$files = glob('include/*.php'); -foreach ($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); -} - -echo "Directory: object\n"; -$files = glob('object/*.php'); -foreach ($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); -} - -echo "Directory: addon\n"; -$dirs = glob('addon/*'); - -foreach ($dirs as $dir) { - $addon = basename($dir); - $files = glob($dir . '/' . $addon . '.php'); - foreach ($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); + echo "Directory: mod\n"; + $files = glob('mod/*.php'); + foreach($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); } -} -echo "String files\n"; + echo "Directory: include\n"; + $files = glob('include/*.php'); + foreach($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); + } -echo 'util/strings.php' . "\n"; -passthru("$phpath -l util/strings.php", $ret); $ret===0 or die(); + echo "Directory: object\n"; + $files = glob('object/*.php'); + foreach($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); + } -$files = glob('view/lang/*/strings.php'); -foreach ($files as $file) { - passthru("$phpath -l $file", $ret); $ret===0 or die(); -} + echo "Directory: addon\n"; + $dirs = glob('addon/*'); + + foreach($dirs as $dir) { + $addon = basename($dir); + $files = glob($dir . '/' . $addon . '.php'); + foreach($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); + } + } + + + echo "String files\n"; + + echo 'util/strings.php' . "\n"; + passthru("$phpath -l util/strings.php", $ret); $ret===0 or die(); + + $files = glob('view/lang/*/strings.php'); + foreach($files as $file) { + passthru("$phpath -l $file", $ret); $ret===0 or die(); + } diff --git a/view/smarty3/.gitignore b/view/smarty3/.gitignore old mode 100644 new mode 100755 diff --git a/view/theme/duepuntozero/theme.php b/view/theme/duepuntozero/theme.php index d3378e49b..c674a99d9 100644 --- a/view/theme/duepuntozero/theme.php +++ b/view/theme/duepuntozero/theme.php @@ -4,30 +4,23 @@ function duepuntozero_init(App $a) { set_template_engine($a, 'smarty3'); -$colorset = get_pconfig( local_user(), 'duepuntozero','colorset'); -if (!$colorset) { - $colorset = get_config('duepuntozero', 'colorset'); // user setting have priority, then node settings -} -if ($colorset) { - if ($colorset == 'greenzero') { - $a->page['htmlhead'] .= ''."\n"; - } - if ($colorset == 'purplezero') { - $a->page['htmlhead'] .= ''."\n"; - } - if ($colorset == 'easterbunny') { - $a->page['htmlhead'] .= ''."\n"; - } - if ($colorset == 'darkzero') { - $a->page['htmlhead'] .= ''."\n"; - } - if ($colorset == 'comix') { - $a->page['htmlhead'] .= ''."\n"; - } - if ($colorset == 'slackr') { - $a->page['htmlhead'] .= ''."\n"; - } -} + $colorset = get_pconfig( local_user(), 'duepuntozero','colorset'); + if (!$colorset) + $colorset = get_config('duepuntozero', 'colorset'); // user setting have priority, then node settings + if ($colorset) { + if ($colorset == 'greenzero') + $a->page['htmlhead'] .= ''."\n"; + if ($colorset == 'purplezero') + $a->page['htmlhead'] .= ''."\n"; + if ($colorset == 'easterbunny') + $a->page['htmlhead'] .= ''."\n"; + if ($colorset == 'darkzero') + $a->page['htmlhead'] .= ''."\n"; + if ($colorset == 'comix') + $a->page['htmlhead'] .= ''."\n"; + if ($colorset == 'slackr') + $a->page['htmlhead'] .= ''."\n"; + } $a->page['htmlhead'] .= <<< EOT