From 830af774d314df8bdc760ae2093cd40229a32802 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 01/91] 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 | 233 +++++++++++++++++++++++++++---------------- mod/dfrn_confirm.php | 13 +-- mod/profiles.php | 5 +- update.php | 2 +- util/po2php.php | 2 +- 5 files changed, 159 insertions(+), 96 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 25f8c9358..eadc37455 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,7 +1130,7 @@ 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 4e82ceaac..378900a88 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -263,13 +263,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 3bce49268..106bf4b86 100644 --- a/update.php +++ b/update.php @@ -310,7 +310,7 @@ function update_1031() { $r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' "); 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']) 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 ddb5a8ea78985f37ff45adf6bf6262e1774c21f9 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 02/91] 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 | 437 ++++++++++++++++++++++++++++++----------------- 1 file changed, 282 insertions(+), 155 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index eadc37455..8b230f03d 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); @@ -2307,10 +2419,11 @@ class dfrn { // Update content if 'updated' changes if (dbm::is_result($current)) { - if (self::update_content($r[0], $item, $importer, $entrytype)) + 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 f173322539fe17eb151550db6f16b0f271e80f2d 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 03/91] 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 | 458 ++++++++++++++++++++++++++++++--------------------- index.php | 87 +++++----- testargs.php | 5 +- update.php | 4 +- 4 files changed, 317 insertions(+), 237 deletions(-) diff --git a/boot.php b/boot.php index 6f036d846..12b68cb6a 100644 --- a/boot.php +++ b/boot.php @@ -560,12 +560,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', ); @@ -654,7 +654,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') || @@ -662,12 +662,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 @@ -675,7 +675,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; } @@ -711,7 +711,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) === '~') { @@ -742,11 +741,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'; @@ -760,8 +758,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; /* @@ -793,14 +792,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); } @@ -864,7 +866,7 @@ class App { function set_baseurl($url) { $parsed = @parse_url($url); - if($parsed) { + if ($parsed) { $this->scheme = $parsed['scheme']; $hostname = $parsed['host']; @@ -876,7 +878,7 @@ class App { } if (file_exists(".htpreconfig.php")) { - @include(".htpreconfig.php"); + include(".htpreconfig.php"); } if (get_config('config', 'hostname') != '') { @@ -890,8 +892,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; } @@ -926,44 +929,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); @@ -985,8 +993,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!!!! @@ -1022,13 +1031,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'", @@ -1083,7 +1092,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"; @@ -1112,7 +1121,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]; @@ -1141,7 +1150,7 @@ class App { switch($engine) { case 'smarty3': - if(is_writable('view/smarty3/')) + if (is_writable('view/smarty3/')) $this->theme['template_engine'] = 'smarty3'; break; default: @@ -1159,8 +1168,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); @@ -1242,8 +1252,9 @@ class App { array_shift($trace); $callstack = array(); - foreach ($trace AS $func) + foreach ($trace AS $func) { $callstack[] = $func["function"]; + } return implode(", ", $callstack); } @@ -1265,31 +1276,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); + } } /** @@ -1302,13 +1315,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(); @@ -1333,13 +1348,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(); @@ -1362,6 +1379,7 @@ class App { // This should prevent the forking of masses of workers. $cachekey = "app:proc_run:started"; $result = Cache::get($cachekey); + /// @TODO maybe merge these both into one if() ? if (!is_null($result)) { if ((time() - $result) < 10) { return; @@ -1375,16 +1393,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__))); - + } } /** @@ -1461,17 +1480,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; @@ -1499,8 +1518,9 @@ function clean_urls() { function z_path() { $base = App::get_baseurl(); - if(! clean_urls()) + if (! clean_urls()) { $base .= '/?q='; + } return $base; } @@ -1525,8 +1545,9 @@ function z_root() { * @return string */ function absurl($path) { - if(strpos($path,'/') === 0) + if (strpos($path,'/') === 0) { return z_path() . $path; + } return $path; } @@ -1542,12 +1563,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'); + } } @@ -1566,10 +1588,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; } @@ -1580,13 +1604,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. @@ -1596,12 +1621,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()); @@ -1609,15 +1635,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 @@ -1628,9 +1657,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; + } } } } @@ -1640,7 +1671,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. @@ -1651,8 +1682,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 @@ -1660,7 +1692,7 @@ function run_update_function($x) { $func = 'update_' . $x; $retval = $func(); - if($retval) { + if ($retval) { //send the administrator an e-mail update_fail( $x, @@ -1693,39 +1725,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); } } @@ -1785,10 +1818,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) )); @@ -1800,29 +1832,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'), )); @@ -1836,8 +1868,9 @@ function login($register = false, $hiddens=false) { */ function killme() { - if (!get_app()->is_backend()) + if (!get_app()->is_backend()) { session_write_close(); + } exit; } @@ -1846,8 +1879,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(); @@ -1895,8 +1929,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; } @@ -1909,9 +1944,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; + } } /** @@ -1924,12 +1962,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; + } } @@ -1991,8 +2033,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"); @@ -2015,12 +2058,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) { @@ -2033,12 +2077,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"); @@ -2055,20 +2101,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(); @@ -2089,38 +2137,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? } @@ -2137,8 +2191,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'); } @@ -2167,8 +2222,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) @@ -2176,13 +2232,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); } } @@ -2200,8 +2257,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; } @@ -2216,16 +2273,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&"; @@ -2237,7 +2294,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 { @@ -2246,13 +2303,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); @@ -2271,7 +2329,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"]; @@ -2283,7 +2343,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; @@ -2292,8 +2352,9 @@ function random_digits($digits) { function get_server() { $server = get_config("system", "directory"); - if ($server == "") + if ($server == "") { $server = "http://dir.friendi.ca"; + } return($server); } @@ -2301,8 +2362,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); @@ -2324,24 +2386,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); } @@ -2351,8 +2418,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)) { @@ -2363,7 +2431,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); } @@ -2455,7 +2523,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]); @@ -2467,37 +2535,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]); } @@ -2518,8 +2591,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 106bf4b86..1668df6eb 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)); } @@ -1671,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); From f5227c016d8ff4945e981a3aabf249d5ab96a305 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 20:48:48 +0100 Subject: [PATCH 04/91] replaced some tabs -> spaces + added curly braces #3254 Signed-off-by: Roland Haeder --- boot.php | 121 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 71 insertions(+), 50 deletions(-) diff --git a/boot.php b/boot.php index 12b68cb6a..cf14fdd86 100644 --- a/boot.php +++ b/boot.php @@ -669,6 +669,7 @@ class App { 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 * or in a sub-directory and adjust accordingly @@ -677,10 +678,12 @@ class App { $path = trim(dirname($_SERVER['SCRIPT_NAME']),'/\\'); if (isset($path) && strlen($path) && ($path != $this->path)) $this->path = $path; + } } - if ($hostname != "") + if ($hostname != "") { $this->hostname = $hostname; + } if (is_array($_SERVER["argv"]) && $_SERVER["argc"]>1 && substr(end($_SERVER["argv"]), 0, 4)=="http" ) { $this->set_baseurl(array_pop($_SERVER["argv"]) ); @@ -1090,11 +1093,12 @@ class App { * @param string $name */ function register_template_engine($class, $name = '') { - if ($name===""){ + /// @TODO Really === and not just == ? + if ($name === "") { $v = get_class_vars( $class ); if (x($v,"name")) $name = $v['name']; } - if ($name===""){ + if ($name === "") { echo "template engine $class cannot be registered without a name.\n"; killme(); } @@ -1110,8 +1114,9 @@ class App { * @param strin $name Template engine name * @return object Template Engine instance */ - function template_engine($name = ''){ - if ($name!=="") { + function template_engine($name = '') { + /// @TODO really type-check included? + if ($name !== "") { $template_engine = $name; } else { $template_engine = 'smarty3'; @@ -1276,27 +1281,26 @@ class App { * @return bool Is it a known backend? */ function is_backend() { - 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", - ); + $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"; if (in_array($this->module, $backend)) { return(true); @@ -1404,6 +1408,7 @@ class App { } else { proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__))); } + } /** @@ -1777,8 +1782,9 @@ function get_guid($size=16, $prefix = "") { $prefix = hash("crc32", $a->get_hostname()); } - while (strlen($prefix) < ($size - 13)) + while (strlen($prefix) < ($size - 13)) { $prefix .= mt_rand(); + } if ($size >= 24) { $prefix = substr($prefix, 0, $size - 22); @@ -1822,7 +1828,7 @@ function login($register = false, $hiddens=false) { $tpl = get_markup_template("logout.tpl"); } else { $a->page['htmlhead'] .= replace_macros(get_markup_template("login_head.tpl"),array( - '$baseurl' => $a->get_baseurl(true) + '$baseurl' => $a->get_baseurl(true) )); $tpl = get_markup_template("login.tpl"); @@ -1912,11 +1918,11 @@ function public_contact() { if (x($_SESSION, 'my_address')) { // Local user $public_contact_id = intval(get_contact($_SESSION['my_address'], 0)); - } else if (x($_SESSION, 'visitor_home')) { + } elseif (x($_SESSION, 'visitor_home')) { // Remote user $public_contact_id = intval(get_contact($_SESSION['visitor_home'], 0)); } - } else if (!x($_SESSION, 'authenticated')) { + } elseif (!x($_SESSION, 'authenticated')) { $public_contact_id = false; } @@ -2175,7 +2181,6 @@ function current_theme(){ } /// @TODO No final return statement? - } /** @@ -2257,9 +2262,10 @@ 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; } @@ -2271,21 +2277,24 @@ function is_site_admin() { * * @return string */ -function build_querystring($params, $name=null) { +function build_querystring($params, $name = null) { $ret = ""; - foreach ($params as $key=>$val) { + foreach ($params as $key => $val) { if (is_array($val)) { - if ($name==null) { + /// @TODO maybe not compare against null, use is_null() + if ($name == null) { $ret .= build_querystring($val, $key); } else { $ret .= build_querystring($val, $name."[$key]"); } } else { $val = urlencode($val); - if ($name!=null) { - $ret.=$name."[$key]"."=$val&"; + /// @TODO maybe not compare against null, use is_null() + if ($name != null) { + /// @TODO two string concated, can be merged to one + $ret .= $name . "[$key]" . "=$val&"; } else { - $ret.= "$key=$val&"; + $ret .= "$key=$val&"; } } } @@ -2303,7 +2312,8 @@ function explode_querystring($query) { } $args = explode('&', substr($query, $arg_st)); - foreach ($args as $k=>$arg) { + foreach ($args as $k => $arg) { + /// @TODO really compare type-safe here? if ($arg === '') { unset($args[$k]); } @@ -2332,7 +2342,9 @@ function curPageURL() { 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"]; } else { @@ -2344,6 +2356,7 @@ function curPageURL() { function random_digits($digits) { $rn = ''; for ($i = 0; $i < $digits; $i++) { + /// @TODO rand() is different to mt_rand() and maybe lesser "random" $rn .= rand(0,9); } return $rn; @@ -2366,9 +2379,9 @@ function get_cachefile($file, $writemode = true) { return(""); } - $subfolder = $cache."/".substr($file, 0, 2); + $subfolder = $cache . "/" . substr($file, 0, 2); - $cachepath = $subfolder."/".$file; + $cachepath = $subfolder . "/" . $file; if ($writemode) { if (!is_dir($subfolder)) { @@ -2377,6 +2390,7 @@ function get_cachefile($file, $writemode = true) { } } + /// @TODO no need to put braces here return($cachepath); } @@ -2497,8 +2511,10 @@ function get_temppath() { if (($temppath != "") AND App::directory_usable($temppath)) { // To avoid any interferences with other systems we create our own directory $new_temppath .= "/".$a->get_hostname(); - if (!is_dir($new_temppath)) + if (!is_dir($new_temppath)) { + /// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method? mkdir($new_temppath); + } if (App::directory_usable($new_temppath)) { // The new path is usable, we are happy @@ -2519,6 +2535,7 @@ function get_temppath() { function set_template_engine(App $a, $engine = 'internal') { /// @note This function is no longer necessary, but keep it as a wrapper to the class method /// to avoid breaking themes again unnecessarily +/// @TODO maybe output a warning here so the theme developer can see it? PHP won't show such warnings like Java does. $a->set_template_engine($engine); } @@ -2617,20 +2634,24 @@ function infinite_scroll_data($module) { AND ($module == "network") AND ($_GET["mode"] != "minimal")) { // get the page number - if (is_string($_GET["page"])) + if (is_string($_GET["page"])) { $pageno = $_GET["page"]; - else + } else { $pageno = 1; + } $reload_uri = ""; // try to get the uri from which we load the content - foreach ($_GET AS $param => $value) - if (($param != "page") AND ($param != "q")) - $reload_uri .= "&".$param."=".urlencode($value); + foreach ($_GET AS $param => $value) { + if (($param != "page") AND ($param != "q")) { + $reload_uri .= "&" . $param . "=" . urlencode($value); + } + } - if (($a->page_offset != "") AND !strstr($reload_uri, "&offset=")) - $reload_uri .= "&offset=".urlencode($a->page_offset); + if (($a->page_offset != "") AND !strstr($reload_uri, "&offset=")) { + $reload_uri .= "&offset=" . urlencode($a->page_offset); + } $arr = array("pageno" => $pageno, "reload_uri" => $reload_uri); From 221cfa8c22b724228ed24618569cabcae582d331 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 21:39:03 +0100 Subject: [PATCH 05/91] added curly braces #3254 Signed-off-by: Roland Haeder --- util/po2php.php | 98 +++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 39 deletions(-) diff --git a/util/po2php.php b/util/po2php.php index 5d3429796..4b801a6de 100644 --- a/util/po2php.php +++ b/util/po2php.php @@ -12,12 +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))); - - + } if (!file_exists($pofile)){ print "Unable to find '$pofile'\n"; @@ -26,14 +25,14 @@ function po2php_run(&$argv, &$argc) { print "Out to '$outfile'\n"; - $out="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; + $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; $out .= "array(\n"; } - $match=Array(); + $match = array(); preg_match("|\[([0-9]*)\] (.*)|", $l, $match); $out .= "\t". preg_replace_callback($escape_s_exp,'escape_s',$match[1]) @@ -91,10 +101,15 @@ function po2php_run(&$argv, &$argc) { //$out .= '$a->strings['.$k.'] = '; } - if (substr($l,0,6)=="msgid "){ - if ($inv) { $inv = False; $out .= '"'.$v.'"'; } - if ($k!="") $out .= $arr?");\n":";\n"; - $arr=False; + if (substr($l, 0, 6) == "msgid ") { + 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"); @@ -102,27 +117,32 @@ function po2php_run(&$argv, &$argc) { $k = ""; } - $k = preg_replace_callback($escape_s_exp,'escape_s',$k); - $ink = True; + $k = preg_replace_callback($escape_s_exp, 'escape_s', $k); + $ink = true; } - if ($inv && substr($l,0,6)!="msgstr") { - $v .= trim($l,"\"\r\n"); - $v = preg_replace_callback($escape_s_exp,'escape_s',$v); + if ($inv && substr($l, 0, 6) != "msgstr") { + $v .= trim($l, "\"\r\n"); + $v = preg_replace_callback($escape_s_exp, 'escape_s', $v); //$out .= '$a->strings['.$k.'] = '; } } - 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); } -if (array_search(__file__,get_included_files())===0){ - po2php_run($_SERVER["argv"],$_SERVER["argc"]); +if (array_search(__FILE__, get_included_files()) === 0) { + po2php_run($_SERVER["argv"],$_SERVER["argc"]); } From 47602577f38992bb9d5f428553dfabb97709924f Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 21:45:00 +0100 Subject: [PATCH 06/91] Opps, missed one ... Signed-off-by: Roland Haeder --- boot.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boot.php b/boot.php index cf14fdd86..3070005d4 100644 --- a/boot.php +++ b/boot.php @@ -675,8 +675,8 @@ class App { * or in a sub-directory and adjust accordingly */ - $path = trim(dirname($_SERVER['SCRIPT_NAME']),'/\\'); - if (isset($path) && strlen($path) && ($path != $this->path)) + $path = trim(dirname($_SERVER['SCRIPT_NAME']), '/\\'); + if (isset($path) && strlen($path) && ($path != $this->path)) { $this->path = $path; } } From f85e6d2aacd9071047b86cd7b45c73c532218057 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 21:46:49 +0100 Subject: [PATCH 07/91] No parantheses here + no @ (which surpresses warnings and such) #3254 Signed-off-by: Roland Haeder --- boot.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/boot.php b/boot.php index 3070005d4..e660cb3ed 100644 --- a/boot.php +++ b/boot.php @@ -611,8 +611,9 @@ class App { $hostname = ""; - if (file_exists(".htpreconfig.php")) - @include(".htpreconfig.php"); + if (file_exists(".htpreconfig.php")) { + include ".htpreconfig.php"; + } $this->timezone = ((x($default_timezone)) ? $default_timezone : 'UTC'); @@ -881,7 +882,7 @@ class App { } if (file_exists(".htpreconfig.php")) { - include(".htpreconfig.php"); + include ".htpreconfig.php"; } if (get_config('config', 'hostname') != '') { From 9521f39ebea7603098e4f96f5edb6c85a40fc646 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 22:08:33 +0100 Subject: [PATCH 08/91] added more spaces #3254 Signed-off-by: Roland Haeder --- boot.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/boot.php b/boot.php index e660cb3ed..a3f25d059 100644 --- a/boot.php +++ b/boot.php @@ -896,8 +896,8 @@ class App { } function get_hostname() { - if (get_config('config','hostname') != "") { - $this->hostname = get_config('config','hostname'); + if (get_config('config', 'hostname') != "") { + $this->hostname = get_config('config', 'hostname'); } return $this->hostname; @@ -908,7 +908,7 @@ class App { } function set_path($p) { - $this->path = trim(trim($p),'/'); + $this->path = trim(trim($p), '/'); } function get_path() { @@ -943,8 +943,8 @@ class App { // 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']; } From 480871d371f8f1235240fe6b439f04d4d391b5a8 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 22:10:37 +0100 Subject: [PATCH 09/91] removed no longer old stuff, let's don't stuff code with commented-out code Signed-off-by: Roland Haeder --- boot.php | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/boot.php b/boot.php index a3f25d059..87fce11ec 100644 --- a/boot.php +++ b/boot.php @@ -1032,29 +1032,6 @@ class App { function get_cached_avatar_image($avatar_image){ return $avatar_image; - - // 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]) - 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]){ - $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'", - $common_filename); - if (! dbm::is_result($r)) { - $this->cached_profile_image[$avatar_image] = $avatar_image; - } else { - $this->cached_profile_picdate[$common_filename] = "?rev=".urlencode($r[0]['picdate']); - $this->cached_profile_image[$avatar_image] = $avatar_image.$this->cached_profile_picdate[$common_filename]; - } - } - return $this->cached_profile_image[$avatar_image]; - */ } From 11d3fd163a8e42df0d8d09f79e2a24ee2cf0d7d8 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 22:12:51 +0100 Subject: [PATCH 10/91] yet another one removed, thanks to @Hypolite for CR Signed-off-by: Roland Haeder --- boot.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/boot.php b/boot.php index 87fce11ec..4101469dd 100644 --- a/boot.php +++ b/boot.php @@ -1128,18 +1128,6 @@ class App { function set_template_engine($engine = 'smarty3') { $this->theme['template_engine'] = $engine; - /* - $this->theme['template_engine'] = 'smarty3'; - - switch($engine) { - case 'smarty3': - if (is_writable('view/smarty3/')) - $this->theme['template_engine'] = 'smarty3'; - break; - default: - break; - } - */ } function get_template_ldelim($engine = 'smarty3') { From 843b7a003ccac424827c2327ae8412153715e098 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 22:16:04 +0100 Subject: [PATCH 11/91] closed internal TODO, merged 2 if() to one + added spaces Signed-off-by: Roland Haeder --- boot.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/boot.php b/boot.php index 4101469dd..5df8c6c4d 100644 --- a/boot.php +++ b/boot.php @@ -1349,12 +1349,11 @@ class App { // This should prevent the forking of masses of workers. $cachekey = "app:proc_run:started"; $result = Cache::get($cachekey); - /// @TODO maybe merge these both into one if() ? - if (!is_null($result)) { - if ((time() - $result) < 10) { - return; - } + + if (!is_null($result) AND (time() - $result) < 10) { + return; } + // Set the timestamp of the last proc_run Cache::set($cachekey, time(), CACHE_MINUTE); @@ -1363,16 +1362,17 @@ class App { // add baseurl to args. cli scripts can't construct it $args[] = $this->get_baseurl(); + /// @TODO let's replace these with a foreach($key => $value) loop for ($x = 0; $x < count($args); $x ++) { $args[$x] = escapeshellarg($args[$x]); } - $cmdline = implode($args," "); + $cmdline = implode($args, " "); - if (get_config('system','proc_windows')) { - proc_close(proc_open('cmd /c start /b ' . $cmdline,array(),$foo,dirname(__FILE__))); + if (get_config('system', 'proc_windows')) { + proc_close(proc_open('cmd /c start /b ' . $cmdline, array(), $foo, dirname(__FILE__))); } else { - proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__))); + proc_close(proc_open($cmdline . " &", array(), $foo, dirname(__FILE__))); } } From dad6a61be4b7d23bcf5c19dd782e80aa4886b3a3 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 22:19:10 +0100 Subject: [PATCH 12/91] it is space-season ... ;-) #3254 Signed-off-by: Roland Haeder --- include/dfrn.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 8b230f03d..f0b702edd 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -689,15 +689,15 @@ class dfrn { } if ($r->link) { - if (substr($r->link,0,1) == '<') { - if (strstr($r->link,'&') && (! strstr($r->link,'&'))) { - $r->link = str_replace('&','&', $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); + $r->link = preg_replace('/\/', '', $r->link); // XML does need a single element as root element so we add a dummy element here - $data = parse_xml_string("".$r->link."", false); + $data = parse_xml_string("" . $r->link . "", false); if (is_object($data)) { foreach ($data->link AS $link) { $attributes = array(); From 16c405b387960dc2899b3b1a3c8fdf02bf480e8f Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 22:22:18 +0100 Subject: [PATCH 13/91] more spaces added (CR by @Hypolite) Signed-off-by: Roland Haeder --- mod/dfrn_notify.php | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index d34c959f1..e9ccf4195 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -143,7 +143,7 @@ function dfrn_notify_post(App $a) { $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); @@ -290,24 +290,24 @@ function dfrn_notify_content(App $a) { logger("Remote rino version: ".$rino_remote." for ".$r[0]["url"], LOGGER_DEBUG); - $challenge = ''; + $challenge = ''; $encrypted_id = ''; - $id_str = $my_id . '.' . mt_rand(1000,9999); + $id_str = $my_id . '.' . mt_rand(1000,9999); $prv_key = trim($r[0]['prvkey']); $pub_key = trim($r[0]['pubkey']); - $dplx = intval($r[0]['duplex']); + $dplx = intval($r[0]['duplex']); - 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)) { - openssl_public_encrypt($hash,$challenge,$pub_key); - openssl_public_encrypt($id_str,$encrypted_id,$pub_key); - } - else + 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)) { + openssl_public_encrypt($hash, $challenge, $pub_key); + openssl_public_encrypt($id_str, $encrypted_id, $pub_key); + } else { + /// @TODO these kind of else-blocks are making the code harder to understand $status = 1; + } $challenge = bin2hex($challenge); $encrypted_id = bin2hex($encrypted_id); @@ -316,18 +316,22 @@ function dfrn_notify_content(App $a) { $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; + /// @TODO Define a code-standard: and/AND/&& are around + if ($rino == 2 and !function_exists('mcrypt_create_iv')) { + $rino = 1; + } logger("Local rino version: ". $rino, LOGGER_DEBUG); // if requested rino is lower than enabled local rino, lower local rino version // if requested rino is higher than enabled local rino, reply with local rino - if ($rino_remote < $rino) $rino = $rino_remote; + if ($rino_remote < $rino) { + $rino = $rino_remote; + } if((($r[0]['rel']) && ($r[0]['rel'] != CONTACT_IS_SHARING)) || ($r[0]['page-flags'] == PAGE_COMMUNITY)) { $perm = 'rw'; - } - else { + } else { $perm = 'r'; } From 09ab141404a4d9ddf30ec100006fb204a2848ebc Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 22:26:07 +0100 Subject: [PATCH 14/91] better comment added by @Hypolite Signed-off-by: Roland Haeder --- include/dfrn.php | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index f0b702edd..aa8c0b5ec 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -1608,7 +1608,14 @@ class dfrn { dbesc(normalise_link($suggest["url"])), intval($suggest["uid"]) ); - /// @TODO Really abort on valid result??? Maybe missed ! here? + + /* + * The valid result means the friend we're about to send a friend + * suggestion already has them in their contact, which means no further + * action is required. + * + * @see https://github.com/friendica/friendica/pull/3254#discussion_r107315246 + */ if (dbm::is_result($r)) { return false; } @@ -1629,30 +1636,33 @@ class dfrn { intval($suggest["uid"]), intval($fid) ); + /// @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"]), - dbesc($suggest["photo"]), - dbesc($suggest["request"]) - ); + dbesc($suggest["name"]), + dbesc($suggest["url"]), + dbesc($suggest["photo"]), + dbesc($suggest["request"]) + ); + } $r = q("SELECT `id` FROM `fcontact` WHERE `url` = '%s' AND `name` = '%s' AND `request` = '%s' LIMIT 1", dbesc($suggest["url"]), dbesc($suggest["name"]), dbesc($suggest["request"]) ); - if (dbm::is_result($r)) { - $fid = $r[0]["id"]; - } else { + + // This way a useless else-block is being spared, resulting in easier code. + if (!dbm::is_result($r)) { // database record did not get created. Quietly give up. killme(); } + $fid = $r[0]["id"]; $hash = random_string(); From d8eee2be554441ef825249ec89d6fa4ad95c6f11 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 22:33:12 +0100 Subject: [PATCH 15/91] added curely branches + reverted back to old behaviour (may come back one day) Signed-off-by: Roland Haeder --- include/dfrn.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/dfrn.php b/include/dfrn.php index aa8c0b5ec..71ffd886b 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -1740,7 +1740,12 @@ class dfrn { intval($importer["importer_uid"])); if (!dbm::is_result($r)) { + /* + * @TODO maybe one day: + logger("Query failed to execute, no result returned in " . __FUNCTION__); killme(); + */ + return false; } $old = $r[0]; From 66366b2804fb3f94016663b107a32993ae084dfa Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 22:43:46 +0100 Subject: [PATCH 16/91] added more spaces and curely braces killed ?> as it is discouraged Signed-off-by: Roland Haeder --- include/dfrn.php | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 71ffd886b..1e6cc6e71 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -2037,28 +2037,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) @@ -2331,7 +2331,7 @@ class dfrn { $item["tag"] .= ","; } - $item["tag"] .= $termhash."[url=".$termurl."]".$term."[/url]"; + $item["tag"] .= $termhash . "[url=" . $termurl . "]" . $term . "[/url]"; } } } @@ -2381,6 +2381,7 @@ class dfrn { $item["network"] = $author["network"]; } + /// @TODO maybe remove this old-lost code then? // This code was taken from the old DFRN code // When activated, forums don't work. // And: Why should we disallow commenting by followers? @@ -2405,6 +2406,7 @@ class dfrn { $ev = bbtoevent($item["body"]); if ((x($ev, "desc") || x($ev, "summary")) && x($ev, "start")) { logger("Event in item ".$item["uri"]." was found.", LOGGER_DEBUG); + /// @TODO Mixure of "/' ahead ... $ev["cid"] = $importer["id"]; $ev["uid"] = $importer["uid"]; $ev["uri"] = $item["uri"]; @@ -2654,7 +2656,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"]); } @@ -2671,10 +2673,11 @@ class dfrn { */ public static function import($xml,$importer, $sort_by_date = false) { - if ($xml == "") + 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"]); @@ -2707,35 +2710,40 @@ 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); + logger("Import DFRN message for user " . $importer["uid"] . " from contact " . $importer["id"], LOGGER_DEBUG); // The account type is new since 3.5.1 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"]) { + /// @TODO this way is the norm or putting ); at the end of the line? 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) { @@ -2780,4 +2788,3 @@ class dfrn { logger("Import done for user ".$importer["uid"]." from contact ".$importer["id"], LOGGER_DEBUG); } } -?> From f94a10bf00de699a5f3d22ea74665053a5661175 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 22:49:05 +0100 Subject: [PATCH 17/91] old behaviour restored Signed-off-by: Roland Haeder --- include/dfrn.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/dfrn.php b/include/dfrn.php index 1e6cc6e71..1e1b82e39 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -2103,7 +2103,12 @@ class dfrn { ); if (!dbm::is_result($r)) { + /* + * @TODO maybe one day: + logger("Query failed to execute, no result returned in " . __FUNCTION__); killme(); + */ + return false; } // extract tag, if not duplicate, add to parent item @@ -2551,7 +2556,7 @@ class dfrn { intval($importer["id"]) ); if (!dbm::is_result($r)) { - logger("Item with uri ".$uri." from contact ".$importer["id"]." for user ".$importer["uid"]." wasn't found.", LOGGER_DEBUG); + logger("Item with uri " . $uri . " from contact " . $importer["id"] . " for user " . $importer["uid"] . " wasn't found.", LOGGER_DEBUG); return; } else { From e4ad359f5a91a01fa18d3ad09ca6bc868e9c373c Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 22:51:52 +0100 Subject: [PATCH 18/91] added curely braces + TODO for maybe avoiding multi-lined if() blocks as it confuses #3254 Signed-off-by: Roland Haeder --- include/dfrn.php | 7 ++++--- include/ostatus.php | 26 +++++++++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 1e1b82e39..34cd33c33 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -2159,8 +2159,8 @@ class dfrn { $title = $attributes->textContent; } } - if (($rel != "") AND ($href != "")) - switch($rel) { + if (($rel != "") AND ($href != "")) { + switch ($rel) { case "alternate": $item["plink"] = $href; break; @@ -2170,9 +2170,10 @@ class dfrn { $item["attach"] .= ","; } - $item["attach"] .= '[attach]href="'.$href.'" length="'.$length.'" type="'.$type.'" title="'.$title.'"[/attach]'; + $item["attach"] .= '[attach]href="' . $href . '" length="' . $length . '" type="' . $type . '" title="' . $title . '"[/attach]'; break; } + } } } diff --git a/include/ostatus.php b/include/ostatus.php index 2c4b677a5..6061ef9e1 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -411,43 +411,51 @@ class ostatus { if ($attributes->name == "title") $title = $attributes->textContent; } - if (($rel != "") AND ($href != "")) - switch($rel) { + if (($rel != "") AND ($href != "")) { + switch ($rel) { case "alternate": $item["plink"] = $href; + /// @TODO These multi-lines can confuse, let's avoid them if (($item["object-type"] == ACTIVITY_OBJ_QUESTION) OR - ($item["object-type"] == ACTIVITY_OBJ_EVENT)) + ($item["object-type"] == ACTIVITY_OBJ_EVENT)) { $item["body"] .= add_page_info($href); + } break; case "ostatus:conversation": $conversation = $href; 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]'; + $item["attach"] .= '[attach]href="' . $href . '" length="' . $length . '" type="' . $type . '" title="' . $title . '"[/attach]'; break; case "related": if ($item["object-type"] != ACTIVITY_OBJ_BOOKMARK) { - if (!isset($item["parent-uri"])) + if (!isset($item["parent-uri"])) { $item["parent-uri"] = $href; + } - if ($related == "") + if ($related == "") { $related = $href; - } else + } + } else { $item["body"] .= add_page_info($href); + } break; case "self": $self = $href; break; case "mentioned": // Notification check - if ($importer["nurl"] == normalise_link($href)) + if ($importer["nurl"] == normalise_link($href)) { $mention = true; + } break; } + } } } From 247093090256d3a9af7e0788772aa88297f06059 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 23:01:04 +0100 Subject: [PATCH 19/91] Continued #3254: - thrown out old lost-code - add curly braces (not curely ;-) ) and spaces - exit is not a keyword, it is a function, so use () here Signed-off-by: Roland Haeder --- index.php | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/index.php b/index.php index d3310ba1a..326d8dc2f 100644 --- a/index.php +++ b/index.php @@ -417,24 +417,8 @@ if (stristr( implode("",$_SESSION['sysmsg']), t('Permission denied'))) { * */ -/*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')) { - $a->page['content'] = "
{$_SESSION['sysmsg_info']}
\r\n" - . ((x($a->page,'content')) ? $a->page['content'] : ''); - $_SESSION['sysmsg_info']=""; - unset($_SESSION['sysmsg_info']); -}*/ - - - call_hooks('page_end', $a->page['content']); - /** * * Add the navigation (menu) template @@ -489,7 +473,6 @@ if (isset($_GET["mode"]) AND (($_GET["mode"] == "raw") OR ($_GET["mode"] == "min $list = $xpath->query("//*[contains(@id,'tread-wrapper-')]"); /* */ foreach ($list as $item) { - $item = $target->importNode($item, true); // And then append it to the target @@ -520,7 +503,7 @@ header("Content-type: text/html; charset=utf-8"); // to load another page template than the default one // The page templates are located in /view/php/ or in the theme directory if (isset($_GET["mode"])) { - $template = theme_include($_GET["mode"].'.php'); + $template = theme_include($_GET["mode"].'.php'); } // If there is no page template use the default page template @@ -530,6 +513,7 @@ if (!$template) { require_once($template); -if (!$a->is_backend()) +if (!$a->is_backend()) { session_write_close(); -exit; +} +exit(); From c4b82133e96a38809e99f767e7a151a3df5f4bc5 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 23:05:53 +0100 Subject: [PATCH 20/91] added more curly braces + spaces for #3254 Signed-off-by: Roland Haeder --- mod/profiles.php | 109 ++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 58 deletions(-) diff --git a/mod/profiles.php b/mod/profiles.php index 378900a88..0aea67202 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -260,26 +260,14 @@ function profiles_post(App $a) { } } } - } - else { + } else { $newname = $lookup; -/* if (strstr($lookup,' ')) { - $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", - dbesc($newname), - intval(local_user()) - ); - } else { - $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1", - dbesc($lookup), - intval(local_user()) - ); - }*/ $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", dbesc($newname), intval(local_user()) ); - if(! $r) { + if (! dbm::is_result($r)) { $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1", dbesc($lookup), intval(local_user()) @@ -291,10 +279,11 @@ function profiles_post(App $a) { } } - if($prf) { - $with = str_replace($lookup,'' . $newname . '', $with); - if(strpos($with,'@') === 0) - $with = substr($with,1); + if ($prf) { + $with = str_replace($lookup,'' . $newname . '', $with); + if (strpos($with,'@') === 0) { + $with = substr($with, 1); + } } } else @@ -332,61 +321,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)) ? ', ' : ' '); @@ -472,11 +461,13 @@ function profiles_post(App $a) { intval(local_user()) ); - if($r) + /// @TODO decide to use dbm::is_result() here and check $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()), @@ -488,7 +479,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", @@ -518,14 +509,17 @@ 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'); @@ -533,8 +527,9 @@ function profile_activity($changed, $value) { intval(local_user()) ); - if(! count($self)) + if (! dbm::is_result($self)) { return; + } $arr = array(); @@ -558,12 +553,13 @@ function profile_activity($changed, $value) { $changes = ''; $t = count($changed); $z = 0; - foreach($changed as $ch) { - if(strlen($changes)) { - if ($z == ($t - 1)) + foreach ($changed as $ch) { + if (strlen($changes)) { + if ($z == ($t - 1)) { $changes .= t(' and '); - else + } else { $changes .= ', '; + } } $z ++; $changes .= $ch; @@ -571,12 +567,12 @@ 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); - } - else + } else { $message = sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes); + } $arr['body'] = $message; @@ -609,7 +605,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()) @@ -656,7 +652,7 @@ function profiles_content(App $a) { $is_default = (($r[0]['is-default']) ? 1 : 0); $tpl = get_markup_template("profile_edit.tpl"); - $o .= replace_macros($tpl,array( + $o .= replace_macros($tpl, array( '$personal_account' => $personal_account, '$detailled_profile' => $detailled_profile, @@ -665,7 +661,7 @@ function profiles_content(App $a) { t('Show more profile fields:'), //Label $detailled_profile, //Value '', //Help string - array(t('No'),t('Yes')) //Off - On strings + array(t('No'), t('Yes')) //Off - On strings ), '$multi_profiles' => feature_enabled(local_user(),'multi_profiles'), @@ -747,15 +743,11 @@ function profiles_content(App $a) { call_hooks('profile_edit', $arr); return $o; - } + } else { - //Profiles list. - else { - - //If we don't support multi profiles, don't display this list. - if(!feature_enabled(local_user(),'multi_profiles')){ - $r = q( - "SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1", + // If we don't support multi profiles, don't display this list. + if (!feature_enabled(local_user(),'multi_profiles')){ + $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1", local_user() ); if (dbm::is_result($r)){ @@ -766,6 +758,7 @@ function profiles_content(App $a) { $r = q("SELECT * FROM `profile` WHERE `uid` = %d", local_user()); + if (dbm::is_result($r)) { $tpl = get_markup_template('profile_entry.tpl'); From a410f86e9cc2faa1f84853604657d870a9ed10e5 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 23:07:29 +0100 Subject: [PATCH 21/91] Continued with #3254: - added curly braces + spaces - converted multiple single-line comments to one multi-line comment Signed-off-by: Roland Haeder --- update.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/update.php b/update.php index 1668df6eb..8404f5bf2 100644 --- a/update.php +++ b/update.php @@ -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", @@ -326,22 +326,23 @@ function update_1032() { function update_1033() { q("CREATE TABLE IF NOT EXISTS `cache` ( - `k` CHAR( 255 ) NOT NULL PRIMARY KEY , - `v` TEXT NOT NULL, - `updated` DATETIME NOT NULL - ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); + `k` CHAR( 255 ) NOT NULL PRIMARY KEY , + `v` TEXT NOT NULL, + `updated` DATETIME NOT NULL + ) DEFAULT CHARSET=utf8 "); } function update_1034() { - // If you have any of these parent-less posts they can cause problems, and - // we need to delete them. You can't see them anyway. - // Legitimate items will usually get re-created on the next - // pull from the hub. - // But don't get rid of a post that may have just come in - // and may not yet have the parent id set. - + /* + * If you have any of these parent-less posts they can cause problems, and + * we need to delete them. You can't see them anyway. + * Legitimate items will usually get re-created on the next + * pull from the hub. + * But don't get rid of a post that may have just come in + * and may not yet have the parent id set. + */ q("DELETE FROM `item` WHERE `parent` = 0 AND `created` < UTC_TIMESTAMP() - INTERVAL 2 MINUTE"); } From db1c2e40416ac1add2e9d10de4c87c4c5a3d8bf2 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 23 Mar 2017 23:37:58 +0100 Subject: [PATCH 22/91] fixed comment and explained one Signed-off-by: Roland Haeder --- include/dfrn.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 34cd33c33..9413b4d3a 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -1637,7 +1637,13 @@ class dfrn { intval($fid) ); - /// @TODO Really abort on valid result??? Maybe missed ! here? + /* + * The valid result means the friend we're about to send a friend + * suggestion already has them in their contact, which means no further + * action is required. + * + * @see https://github.com/friendica/friendica/pull/3254#discussion_r107315246 + */ if (dbm::is_result($r)) { return false; } @@ -1656,7 +1662,10 @@ class dfrn { dbesc($suggest["request"]) ); - // This way a useless else-block is being spared, resulting in easier code. + /* + * If no record in fcontact is found, below INSERT statement will not + * link an introduction to it. + */ if (!dbm::is_result($r)) { // database record did not get created. Quietly give up. killme(); From d45e79dfe95c150d6846ecbdca271bd5577cefc5 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 24 Mar 2017 20:39:00 +0100 Subject: [PATCH 23/91] Continued: - converted multiple single-line comments into one multi-line comment (please stop abusing programming languages!) - added more TODO tags for type-hints (upcoming rewrite) - opps, one space was only fixed in develop branch, not in this PR branch Signed-off-by: Roland Haeder --- include/dfrn.php | 111 +++++++++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 47 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 9413b4d3a..887dba9a1 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -967,8 +967,8 @@ class dfrn { $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); @@ -976,7 +976,7 @@ class dfrn { $ssl_val = intval(get_config('system','ssl_policy')); $ssl_policy = ''; - switch($ssl_val){ + switch ($ssl_val) { case SSL_POLICY_FULL: $ssl_policy = 'full'; break; @@ -1095,13 +1095,13 @@ class dfrn { } - 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) { + switch ($rino_remote_version) { case 1: // Deprecated rino version! - $key = substr(random_string(),0,16); + $key = substr(random_string(), 0, 16); $data = aes_encrypt($postvars['data'],$key); break; case 2: @@ -1298,19 +1298,19 @@ class dfrn { } 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); + 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); + $name_element = $xpath->query($element . "/atom:name", $context)->item(0); 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); + $link_element = $xpath->query($element . "/atom:link", $context)->item(0); foreach ($link_element->attributes AS $attributes) { if ($attributes->name == "updated") { $poco["uri-date"] = $attributes->textContent; @@ -1318,33 +1318,33 @@ class dfrn { } // Update contact data - $value = $xpath->evaluate($element."/dfrn:handle/text()", $context)->item(0)->nodeValue; + $value = $xpath->evaluate($element . "/dfrn:handle/text()", $context)->item(0)->nodeValue; if ($value != "") { $poco["addr"] = $value; } - $value = $xpath->evaluate($element."/poco:displayName/text()", $context)->item(0)->nodeValue; + $value = $xpath->evaluate($element . "/poco:displayName/text()", $context)->item(0)->nodeValue; if ($value != "") { $poco["name"] = $value; } - $value = $xpath->evaluate($element."/poco:preferredUsername/text()", $context)->item(0)->nodeValue; + $value = $xpath->evaluate($element . "/poco:preferredUsername/text()", $context)->item(0)->nodeValue; if ($value != "") { $poco["nick"] = $value; } - $value = $xpath->evaluate($element."/poco:note/text()", $context)->item(0)->nodeValue; + $value = $xpath->evaluate($element . "/poco:note/text()", $context)->item(0)->nodeValue; if ($value != "") { $poco["about"] = $value; } - $value = $xpath->evaluate($element."/poco:address/poco:formatted/text()", $context)->item(0)->nodeValue; + $value = $xpath->evaluate($element . "/poco:address/poco:formatted/text()", $context)->item(0)->nodeValue; 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; + $value = $xpath->evaluate($element . "/poco:ims/poco:value/text()", $context)->item(0)->nodeValue; if ($value != "") { $poco["xmpp"] = $value; } @@ -1357,9 +1357,9 @@ class dfrn { /// - poco:country // If the "hide" element is present then the profile isn't searchable. - $hide = intval($xpath->evaluate($element."/dfrn:hide/text()", $context)->item(0)->nodeValue == "true"); + $hide = intval($xpath->evaluate($element . "/dfrn:hide/text()", $context)->item(0)->nodeValue == "true"); - logger("Hidden status for contact ".$contact["url"].": ".$hide, LOGGER_DEBUG); + logger("Hidden status for contact " . $contact["url"] . ": " . $hide, LOGGER_DEBUG); // If the contact isn't searchable then set the contact to "hidden". // Problem: This can be manually overridden by the user. @@ -1369,7 +1369,7 @@ class dfrn { // Save the keywords into the contact table $tags = array(); - $tagelements = $xpath->evaluate($element."/poco:tags/text()", $context); + $tagelements = $xpath->evaluate($element . "/poco:tags/text()", $context); foreach ($tagelements AS $tag) { $tags[$tag->nodeValue] = $tag->nodeValue; } @@ -1381,7 +1381,7 @@ class dfrn { // "dfrn:birthday" contains the birthday converted to UTC $old_bdyear = $contact["bdyear"]; - $birthday = $xpath->evaluate($element."/dfrn:birthday/text()", $context)->item(0)->nodeValue; + $birthday = $xpath->evaluate($element . "/dfrn:birthday/text()", $context)->item(0)->nodeValue; if (strtotime($birthday) > time()) { $bd_timestamp = strtotime($birthday); @@ -1390,7 +1390,7 @@ class dfrn { } // "poco:birthday" is the birthday in the format "yyyy-mm-dd" - $value = $xpath->evaluate($element."/poco:birthday/text()", $context)->item(0)->nodeValue; + $value = $xpath->evaluate($element . "/poco:birthday/text()", $context)->item(0)->nodeValue; if (!in_array($value, array("", "0000-00-00"))) { $bdyear = date("Y"); @@ -1427,20 +1427,20 @@ class dfrn { $datefields = array("name-date", "uri-date"); 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); + 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) { 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); + 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); + logger("Update contact data for contact " . $contact["id"] . " (" . $contact["nick"] . ")", LOGGER_DEBUG); q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', `addr` = '%s', `keywords` = '%s', `bdyear` = '%s', `bd` = '%s', `hidden` = %d, @@ -1456,10 +1456,12 @@ class dfrn { update_contact_avatar($author["avatar"], $importer["uid"], $contact["id"], (strtotime($contact["avatar-date"]) > strtotime($r[0]["avatar-date"]))); - // The generation is a sign for the reliability of the provided data. - // It is used in the socgraph.php to prevent that old contact data - // that was relayed over several servers can overwrite contact - // data that we received directly. + /* + * The generation is a sign for the reliability of the provided data. + * It is used in the socgraph.php to prevent that old contact data + * that was relayed over several servers can overwrite contact + * data that we received directly. + */ $poco["generation"] = 2; $poco["photo"] = $author["avatar"]; @@ -1811,6 +1813,7 @@ class dfrn { update_contact_avatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true); + /// @TODO decide to use dbm::is_result() here if ($x === false) { return false; } @@ -1822,7 +1825,7 @@ class dfrn { 'author-link' => array($old["url"], $relocate["url"]), //'owner-avatar' => array($old["photo"], $relocate["photo"]), //'author-avatar' => array($old["photo"], $relocate["photo"]), - ); + ); foreach ($fields as $n=>$f) { $r = q("SELECT `id` FROM `item` WHERE `%s` = '%s' AND `uid` = %d LIMIT 1", $n, dbesc($f[0]), @@ -1833,8 +1836,11 @@ class dfrn { $n, dbesc($f[1]), $n, dbesc($f[0]), intval($importer["importer_uid"])); - if ($x === false) + + /// @TODO decide to use dbm::is_result() here + if ($x === false) { return false; + } } } @@ -1853,6 +1859,7 @@ class dfrn { * @param array $item the new item record * @param array $importer Record of the importer user mixed with contact of the content * @param int $entrytype Is it a toplevel entry, a comment or a relayed comment? + * @todo set proper type-hints (array?) */ private static function update_content($current, $item, $importer, $entrytype) { $changed = false; @@ -1860,8 +1867,9 @@ 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", dbesc($item["title"]), @@ -1906,12 +1914,13 @@ class dfrn { * @param array $item the new item record * * @return int Is it a toplevel entry, a comment or a relayed comment? + * @todo set proper type-hints (array?) */ private static function get_entry_type($importer, $item) { 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"); @@ -1946,11 +1955,14 @@ class dfrn { } } - // Does this have the characteristics of a community or private group action? - // If it's an action to a wall post on a community/prvgroup page it's a - // valid community action. Also forum_mode makes it valid for sure. - // If neither, it's not. + /* + * Does this have the characteristics of a community or private group action? + * If it's an action to a wall post on a community/prvgroup page it's a + * valid community action. Also forum_mode makes it valid for sure. + * If neither, it's not. + */ + /// @TODO Maybe merge these if() blocks into one? if ($is_a_remote_action && $community) { if ((!$r[0]["forum_mode"]) && (!$r[0]["wall"])) { $is_a_remote_action = false; @@ -1963,7 +1975,6 @@ class dfrn { } else { return DFRN_REPLY; } - } else { return DFRN_TOP_LEVEL; } @@ -1976,6 +1987,7 @@ class dfrn { * @param array $item the new item record * @param array $importer Record of the importer user mixed with contact of the content * @param int $posted_id The record number of item record that was just posted + * @todo set proper type-hints (array?) */ private static function do_poke($item, $importer, $posted_id) { $verb = urldecode(substr($item["verb"],strpos($item["verb"], "#")+1)); @@ -1989,7 +2001,7 @@ class dfrn { // somebody was poked/prodded. Was it me? foreach ($xo->link as $l) { $atts = $l->attributes(); - switch($atts["rel"]) { + switch ($atts["rel"]) { case "alternate": $Blink = $atts["href"]; break; @@ -1998,7 +2010,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( @@ -2032,6 +2044,7 @@ class dfrn { * @param bool $is_like Is the verb a "like"? * * @return bool Should the processing of the entries be continued? + * @todo set proper type-hints (array?) */ private static function process_verbs($entrytype, $importer, &$item, &$is_like) { @@ -2141,7 +2154,7 @@ class dfrn { * * @param object $links link elements * @param array $item the item record - * @todo Add type-hints + * @todo set proper type-hints */ private static function parse_links($links, &$item) { $rel = ""; @@ -2501,10 +2514,12 @@ class dfrn { } } else { // $entrytype == DFRN_TOP_LEVEL 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, - // but we're going to unconditionally correct it here so that the post will always be owned by our contact. + /* + * 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, + * but we're going to unconditionally correct it here so that the post will always be owned by our contact. + */ logger('Correcting item owner.', LOGGER_DEBUG); $item["owner-name"] = $importer["senderName"]; $item["owner-link"] = $importer["url"]; @@ -2535,6 +2550,7 @@ class dfrn { * @param object $xpath XPath object * @param object $deletion deletion elements * @param array $importer Record of the importer user mixed with contact of the content + * @todo set proper type-hints */ private static function process_deletion($xpath, $deletion, $importer) { @@ -2617,7 +2633,7 @@ class dfrn { } } q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d", - dbesc(implode(',',$newtags)), + dbesc(implode(',', $newtags)), intval($i[0]["id"]) ); create_tags_from_item($i[0]["id"]); @@ -2626,7 +2642,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", @@ -2672,7 +2688,7 @@ class dfrn { // if this is a relayed delete, propagate it to other recipients if ($entrytype == DFRN_REPLY_RC) { - logger("Notifying followers about deletion of post ".$item["id"], LOGGER_DEBUG); + logger("Notifying followers about deletion of post " . $item["id"], LOGGER_DEBUG); proc_run(PRIORITY_HIGH, "include/notifier.php","drop", $item["id"]); } } @@ -2685,6 +2701,7 @@ class dfrn { * @param text $xml The DFRN message * @param array $importer Record of the importer user mixed with contact of the content * @param bool $sort_by_date Is used when feeds are polled + * @todo set proper type-hints */ public static function import($xml,$importer, $sort_by_date = false) { @@ -2800,6 +2817,6 @@ class dfrn { self::process_entry($header, $xpath, $entry, $importer); } } - logger("Import done for user ".$importer["uid"]." from contact ".$importer["id"], LOGGER_DEBUG); + logger("Import done for user " . $importer["uid"] . " from contact " . $importer["id"], LOGGER_DEBUG); } } From ccd1e2cc6a894d93ff3f6e3d1bfcc591702cbdf6 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 24 Mar 2017 20:50:10 +0100 Subject: [PATCH 24/91] fixed parser error Signed-off-by: Roland Haeder --- boot.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/boot.php b/boot.php index 5df8c6c4d..05e117282 100644 --- a/boot.php +++ b/boot.php @@ -665,10 +665,10 @@ class App { $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']; } /* @@ -676,6 +676,7 @@ class App { * or in a sub-directory and adjust accordingly */ + /// @TODO This kind of escaping breaks syntax-highlightning on CoolEdit (Midnight Commander) $path = trim(dirname($_SERVER['SCRIPT_NAME']), '/\\'); if (isset($path) && strlen($path) && ($path != $this->path)) { $this->path = $path; @@ -686,11 +687,12 @@ class App { $this->hostname = $hostname; } - if (is_array($_SERVER["argv"]) && $_SERVER["argc"]>1 && substr(end($_SERVER["argv"]), 0, 4)=="http" ) { - $this->set_baseurl(array_pop($_SERVER["argv"]) ); + if (is_array($_SERVER["argv"]) && $_SERVER["argc"] > 1 && substr(end($_SERVER["argv"]), 0, 4) == "http" ) { + $this->set_baseurl(array_pop($_SERVER["argv"])); $_SERVER["argc"] --; } + /// @TODO no longer needed? #set_include_path("include/$this->hostname" . PATH_SEPARATOR . get_include_path()); if ((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,9) === "pagename=") { From b5b3451b31b7a45595345baf77e78a144426cc5c Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 24 Mar 2017 20:57:52 +0100 Subject: [PATCH 25/91] Continued: - marked commented-out code as possible old-lost - added more curly braces - used more dbm::is_result() where SELECT is stated - ! added quotes in array element, else (here) >thumb< (without quotes) is considered as a constant and causes an E_NOTICE Signed-off-by: Roland Haeder --- mod/install.php | 1 + mod/manage.php | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/mod/install.php b/mod/install.php index fa952a79b..f58345e3a 100755 --- a/mod/install.php +++ b/mod/install.php @@ -485,6 +485,7 @@ function check_funcs(&$checks) { $ck_funcs[6]['help'] = t('Error, XML PHP module required but not installed.'); } + /// @TODO old-lost code here? /*if((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg'])) notice( t('Please see the file "INSTALL.txt".') . EOL);*/ } diff --git a/mod/manage.php b/mod/manage.php index 4beb8e46c..10fc7c7e6 100644 --- a/mod/manage.php +++ b/mod/manage.php @@ -72,16 +72,19 @@ function manage_post(App $a) { unset($_SESSION['return_url']); 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); + authenticate_success($r[0], true, true); - if($limited_id) + if ($limited_id) { $_SESSION['submanage'] = $original_id; + } $ret = array(); call_hooks('home_init',$ret); @@ -113,26 +116,32 @@ function manage_content(App $a) { dbesc($id['uid']) ); - $identities[$key][thumb] = $thumb[0][thumb]; + $identities[$key]['thumb'] = $thumb[0]['thumb']; - $identities[$key]['selected'] = (($id['nickname'] === $a->user['nickname']) ? true : false); + $identities[$key]['selected'] = ($id['nickname'] === $a->user['nickname']); $notifications = 0; $r = q("SELECT DISTINCT(`parent`) FROM `notify` WHERE `uid` = %d AND NOT `seen` AND NOT (`type` IN (%d, %d))", intval($id['uid']), intval(NOTIFY_INTRO), intval(NOTIFY_MAIL)); - if ($r) + + if (dbm::is_result($r)) { $notifications = sizeof($r); + } $r = q("SELECT DISTINCT(`convid`) FROM `mail` WHERE `uid` = %d AND NOT `seen`", intval($id['uid'])); - if ($r) + + if (dbm::is_result($r)) { $notifications = $notifications + sizeof($r); + } $r = q("SELECT COUNT(*) AS `introductions` FROM `intro` WHERE NOT `blocked` AND NOT `ignore` AND `uid` = %d", intval($id['uid'])); - if ($r) + + if (dbm::is_result($r)) { $notifications = $notifications + $r[0]["introductions"]; + } $identities[$key]['notifications'] = $notifications; } From 0e19fdfc71954889be54a08ea100fe24a88d753c Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 24 Mar 2017 21:05:08 +0100 Subject: [PATCH 26/91] removed parentheses + added TODO about a small rewrite Signed-off-by: Roland Haeder --- boot.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/boot.php b/boot.php index 05e117282..1e936a2c6 100644 --- a/boot.php +++ b/boot.php @@ -253,7 +253,6 @@ define ( 'NETWORK_PHANTOM', 'unkn'); // Place holder * and existing allocations MUST NEVER BE CHANGED * OR RE-ASSIGNED! You may only add to them. */ - $netgroup_ids = array( NETWORK_DFRN => (-1), NETWORK_ZOT => (-2), @@ -503,6 +502,7 @@ function startup() { */ class App { + /// @TODO decide indending as a colorful mixure is ahead ... public $module_loaded = false; public $query_string; public $config; @@ -810,11 +810,11 @@ class App { $basepath = $_SERVER["PWD"]; } - return($basepath); + return $basepath; } function get_scheme() { - return($this->scheme); + return $this->scheme; } /** @@ -1048,7 +1048,7 @@ class App { // Is the function called statically? if (!(isset($this) && get_class($this) == __CLASS__)) { - return(self::$a->remove_baseurl($orig_url)); + return self::$a->remove_baseurl($orig_url); } // Remove the hostname from the url if it is an internal link @@ -1233,11 +1233,11 @@ class App { } function get_useragent() { - return(FRIENDICA_PLATFORM." '".FRIENDICA_CODENAME."' ".FRIENDICA_VERSION."-".DB_UPDATE_VERSION."; ".$this->get_baseurl()); + return (FRIENDICA_PLATFORM." '".FRIENDICA_CODENAME."' ".FRIENDICA_VERSION."-".DB_UPDATE_VERSION."; ".$this->get_baseurl()); } function is_friendica_app() { - return($this->is_friendica_app); + return $this->is_friendica_app; } /** @@ -1249,6 +1249,7 @@ class App { * @return bool Is it a known backend? */ function is_backend() { + /// @Should be made static to speedup things $backend = array(); $backend[] = "_well_known"; $backend[] = "api"; @@ -1270,6 +1271,7 @@ class App { $backend[] = "statistics_json"; $backend[] = "xrd"; + /// @TODO Maybe rewrite this part: return (in_array() || $this->backend); ? if (in_array($this->module, $backend)) { return(true); } else { @@ -2359,7 +2361,7 @@ function get_cachefile($file, $writemode = true) { } /// @TODO no need to put braces here - return($cachepath); + return $cachepath; } function clear_cache($basepath = "", $path = "") { @@ -2511,7 +2513,7 @@ function set_template_engine(App $a, $engine = 'internal') { if (!function_exists('exif_imagetype')) { function exif_imagetype($file) { $size = getimagesize($file); - return($size[2]); + return $size[2]; } } From 084dbd68593bebcbc1ed2a94258618be941f6945 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 24 Mar 2017 21:08:03 +0100 Subject: [PATCH 27/91] Continued: - some spaces added - removed parentheses as requested by @Hypolite - added really important TODO as remote-inclusion is not what you want Signed-off-by: Roland Haeder --- index.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 326d8dc2f..3108e57cf 100644 --- a/index.php +++ b/index.php @@ -496,14 +496,14 @@ if (isset($_GET["mode"]) AND ($_GET["mode"] == "raw")) { $page = $a->page; $profile = $a->profile; -header("X-Friendica-Version: ".FRIENDICA_VERSION); +header("X-Friendica-Version: " . FRIENDICA_VERSION); header("Content-type: text/html; charset=utf-8"); // We use $_GET["mode"] for special page templates. So we will check if we have // to load another page template than the default one // The page templates are located in /view/php/ or in the theme directory if (isset($_GET["mode"])) { - $template = theme_include($_GET["mode"].'.php'); + $template = theme_include($_GET["mode"] . '.php'); } // If there is no page template use the default page template @@ -511,7 +511,8 @@ if (!$template) { $template = theme_include("default.php"); } -require_once($template); +/// @TODO Looks unsafe (remote-inclusion), is maybe not but theme_include() uses file_exists() but does not escape anything +require_once $template; if (!$a->is_backend()) { session_write_close(); From c0be733d6d5318f333514430a5b1ad11821d2f3d Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 24 Mar 2017 21:15:14 +0100 Subject: [PATCH 28/91] Opps, became lazy here, thanks to @Hypolite finding it. Signed-off-by: Roland Haeder --- mod/dfrn_notify.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index e9ccf4195..caa27b869 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -143,7 +143,9 @@ function dfrn_notify_post(App $a) { $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); From daa32d49cf3c35f6549d7df2e7c746b993e3351f Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 24 Mar 2017 21:17:00 +0100 Subject: [PATCH 29/91] killme() does the same here + added curly braces Signed-off-by: Roland Haeder --- boot.php | 2 +- index.php | 20 ++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/boot.php b/boot.php index 1e936a2c6..a00fa5c50 100644 --- a/boot.php +++ b/boot.php @@ -1848,7 +1848,7 @@ function killme() { session_write_close(); } - exit; + exit(); } /** diff --git a/index.php b/index.php index 3108e57cf..19f283039 100644 --- a/index.php +++ b/index.php @@ -466,6 +466,7 @@ if (isset($_GET["mode"]) AND (($_GET["mode"] == "raw") OR ($_GET["mode"] == "min $content = mb_convert_encoding($a->page["content"], 'HTML-ENTITIES', "UTF-8"); + /// @TODO one day, kill those error-surpressing @ stuff, or PHP should ban it @$doc->loadHTML($content); $xpath = new DomXPath($doc); @@ -486,11 +487,7 @@ if (isset($_GET["mode"]) AND ($_GET["mode"] == "raw")) { echo substr($target->saveHTML(), 6, -8); - if (!$a->is_backend()) { - session_write_close(); - } - exit; - + killme(); } $page = $a->page; @@ -499,9 +496,11 @@ $profile = $a->profile; header("X-Friendica-Version: " . FRIENDICA_VERSION); header("Content-type: text/html; charset=utf-8"); -// We use $_GET["mode"] for special page templates. So we will check if we have -// to load another page template than the default one -// The page templates are located in /view/php/ or in the theme directory +/* + * We use $_GET["mode"] for special page templates. So we will check if we have + * to load another page template than the default one. + * The page templates are located in /view/php/ or in the theme directory. + */ if (isset($_GET["mode"])) { $template = theme_include($_GET["mode"] . '.php'); } @@ -514,7 +513,4 @@ if (!$template) { /// @TODO Looks unsafe (remote-inclusion), is maybe not but theme_include() uses file_exists() but does not escape anything require_once $template; -if (!$a->is_backend()) { - session_write_close(); -} -exit(); +killme(); From be717649a4c2d7da7804ddaaba21523b90b14b0a Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 24 Mar 2017 22:33:57 +0100 Subject: [PATCH 30/91] added more curly braces/spaces Signed-off-by: Roland Haeder --- mod/profiles.php | 60 ++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/mod/profiles.php b/mod/profiles.php index 0aea67202..dbbdfc83f 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -171,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 (! dbm::is_result($orig)) { notice( t('Profile not found.') . EOL); return; } @@ -186,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; } @@ -194,18 +194,21 @@ 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 + } 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 = substr($dob, 5); } - $dob = datetime_convert('UTC','UTC',(($ignore_year) ? '1900-' . $dob : $dob),(($ignore_year) ? 'm-d' : 'Y-m-d')); - if($ignore_year) + $dob = datetime_convert('UTC', 'UTC', (($ignore_year) ? '1900-' . $dob : $dob), (($ignore_year) ? 'm-d' : 'Y-m-d')); + + if ($ignore_year) { $dob = '0000-' . $dob; + } } $name = notags(trim($_POST['name'])); @@ -214,10 +217,9 @@ function profiles_post(App $a) { $name = '[No Name]'; } - if($orig[0]['name'] != $name) + if ($orig[0]['name'] != $name) { $namechanged = true; - - + } $pdesc = notags(trim($_POST['pdesc'])); $gender = notags(trim($_POST['gender'])); @@ -242,20 +244,21 @@ 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) - $lookup = substr($lookup,1); + 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,16 +283,17 @@ function profiles_post(App $a) { } if ($prf) { - $with = str_replace($lookup,'' . $newname . '', $with); - if (strpos($with,'@') === 0) { + $with = str_replace($lookup, '' . $newname . '', $with); + if (strpos($with, '@') === 0) { $with = substr($with, 1); } } - } - else + } else { $with = $orig[0]['with']; + } } + /// @TODO Not flexible enough for later expansion, let's have more OOP here $sexual = notags(trim($_POST['sexual'])); $xmpp = notags(trim($_POST['xmpp'])); $homepage = notags(trim($_POST['homepage'])); @@ -463,7 +467,7 @@ function profiles_post(App $a) { /// @TODO decide to use dbm::is_result() here and check $r if ($r) { - info( t('Profile updated.') . EOL); + info(t('Profile updated.') . EOL); } @@ -513,11 +517,11 @@ function profile_activity($changed, $value) { 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; } From caad9f5214f9f8c94e487629007b0f33c1b2008d Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 24 Mar 2017 22:36:13 +0100 Subject: [PATCH 31/91] added more spaces (CR request) Signed-off-by: Roland Haeder --- mod/profiles.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mod/profiles.php b/mod/profiles.php index dbbdfc83f..ccd6cb2c7 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -321,7 +321,7 @@ function profiles_post(App $a) { $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0); - set_pconfig(local_user(),'system','detailled_profile', (($_POST['detailled_profile'] == 1) ? 1: 0)); + set_pconfig(local_user(),'system', 'detailled_profile', (($_POST['detailled_profile'] == 1) ? 1: 0)); $changes = array(); $value = ''; @@ -496,7 +496,7 @@ function profiles_post(App $a) { // Update global directory in background $url = $_SESSION['my_url']; - if ($url && strlen(get_config('system','directory'))) { + if ($url && strlen(get_config('system', 'directory'))) { proc_run(PRIORITY_LOW, "include/directory.php", $url); } @@ -648,11 +648,12 @@ function profiles_content(App $a) { $personal_account = !(in_array($a->user["page-flags"], array(PAGE_COMMUNITY, PAGE_PRVGROUP))); - $detailled_profile = (get_pconfig(local_user(),'system','detailled_profile') AND $personal_account); + $detailled_profile = (get_pconfig(local_user(),'system', 'detailled_profile') AND $personal_account); - $f = get_config('system','birthday_input_format'); - if(! $f) + $f = get_config('system', 'birthday_input_format'); + if (! $f) { $f = 'ymd'; + } $is_default = (($r[0]['is-default']) ? 1 : 0); $tpl = get_markup_template("profile_edit.tpl"); From 239dfea4e63061bb2e7c31ce058f74ac10d46a5a Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 24 Mar 2017 22:40:25 +0100 Subject: [PATCH 32/91] it is space-time! ;-) Signed-off-by: Roland Haeder --- mod/profiles.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mod/profiles.php b/mod/profiles.php index ccd6cb2c7..233b276a3 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -321,7 +321,7 @@ function profiles_post(App $a) { $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0); - set_pconfig(local_user(),'system', 'detailled_profile', (($_POST['detailled_profile'] == 1) ? 1: 0)); + set_pconfig(local_user(), 'system', 'detailled_profile', (($_POST['detailled_profile'] == 1) ? 1: 0)); $changes = array(); $value = ''; @@ -648,7 +648,7 @@ function profiles_content(App $a) { $personal_account = !(in_array($a->user["page-flags"], array(PAGE_COMMUNITY, PAGE_PRVGROUP))); - $detailled_profile = (get_pconfig(local_user(),'system', 'detailled_profile') AND $personal_account); + $detailled_profile = (get_pconfig(local_user(), 'system', 'detailled_profile') AND $personal_account); $f = get_config('system', 'birthday_input_format'); if (! $f) { @@ -669,10 +669,10 @@ function profiles_content(App $a) { array(t('No'), t('Yes')) //Off - On strings ), - '$multi_profiles' => feature_enabled(local_user(),'multi_profiles'), + '$multi_profiles' => feature_enabled(local_user(), 'multi_profiles'), '$form_security_token' => get_form_security_token("profile_edit"), '$form_security_token_photo' => get_form_security_token("profile_photo"), - '$profile_clone_link' => ((feature_enabled(local_user(),'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone") : ""), + '$profile_clone_link' => ((feature_enabled(local_user(), 'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone") : ""), '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"), '$profile_action' => t('Profile Actions'), @@ -751,13 +751,13 @@ 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() ); - if (dbm::is_result($r)){ + if (dbm::is_result($r)) { //Go to the default profile. - goaway('profiles/'.$r[0]['id']); + goaway('profiles/' . $r[0]['id']); } } From 566cfb8418196bc0afd1d54cc6bf2deddf1ab027 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 24 Mar 2017 22:44:18 +0100 Subject: [PATCH 33/91] space-time season continues ... Signed-off-by: Roland Haeder --- util/po2php.php | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/util/po2php.php b/util/po2php.php index 4b801a6de..199d79ed3 100644 --- a/util/po2php.php +++ b/util/po2php.php @@ -18,7 +18,7 @@ function po2php_run(&$argv, &$argc) { $lang = str_replace('-','_',basename(dirname($pofile))); } - if (!file_exists($pofile)){ + if (!file_exists($pofile)) { print "Unable to find '$pofile'\n"; return; } @@ -34,7 +34,7 @@ function po2php_run(&$argv, &$argc) { $ink = false; $inv = false; $escape_s_exp = '|[^\\\\]\$[a-z]|'; - function escape_s($match){ + function escape_s($match) { return str_replace('$','\$',$match[0]); } foreach ($infile as $l) { @@ -43,19 +43,19 @@ function po2php_run(&$argv, &$argc) { if ($l[0] == "#") { $l = ""; } - if (substr($l,0,15) == '"Plural-Forms: ') { + if (substr($l, 0, 15) == '"Plural-Forms: ') { $match = array(); preg_match("|nplurals=([0-9]*); *plural=(.*)[;\\\\]|", $l, $match); - $cond = str_replace('n','$n',$match[2]); + $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 .= 'function '. $fnname . '($n){'."\n"; - $out .= ' return '.$cond.';'."\n"; - $out .= '}}'."\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 ($k != "" && substr($l, 0, 7) == "msgstr ") { if ($ink) { $ink = false; $out .= '$a->strings["' . $k . '"] = '; @@ -92,8 +92,10 @@ function po2php_run(&$argv, &$argc) { .preg_replace_callback($escape_s_exp,'escape_s',$match[2]) .",\n"; } - if (substr($l,0,6)=="msgid_") { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }; - + if (substr($l, 0, 6) == "msgid_") { + $ink = false; + $out .= '$a->strings["' . $k . '"] = '; + } if ($ink) { $k .= trim($l,"\"\r\n"); @@ -107,12 +109,13 @@ function po2php_run(&$argv, &$argc) { $out .= '"'.$v.'"'; } if ($k != "") { - $out .= $arr?");\n":";\n"; + /// @TODO Maybe add parentheses here? + $out .= $arr ? ");\n" : ";\n"; } $arr = false; $k = str_replace("msgid ","",$l); - if ($k != '""' ) { - $k = trim($k,"\"\r\n"); + if ($k != '""') { + $k = trim($k, "\"\r\n"); } else { $k = ""; } From 689b81171ec1ee156ccd6111c062b4777054a531 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 12:43:07 +0100 Subject: [PATCH 34/91] added spaces, removed parentheses. there is more ahead than just this one. Signed-off-by: Roland Haeder --- index.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.php b/index.php index 19f283039..19eb5bff7 100644 --- a/index.php +++ b/index.php @@ -37,7 +37,7 @@ $install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false // Only load config if found, don't surpress errors if (!$install) { - include(".htconfig.php"); + include ".htconfig.php"; } /** @@ -46,11 +46,11 @@ if (!$install) { * */ -require_once("include/dba.php"); +require_once "include/dba.php"; if (!$install) { $db = new dba($db_host, $db_user, $db_pass, $db_data, $install); - unset($db_host, $db_user, $db_pass, $db_data); + unset($db_host, $db_user, $db_pass, $db_data); /** * Load configs from db. Overwrite configs from .htconfig.php @@ -59,13 +59,13 @@ if (!$install) { Config::load(); if ($a->max_processes_reached() OR $a->maxload_reached()) { - header($_SERVER["SERVER_PROTOCOL"].' 503 Service Temporarily Unavailable'); + header($_SERVER["SERVER_PROTOCOL"] . ' 503 Service Temporarily Unavailable'); header('Retry-After: 120'); - header('Refresh: 120; url='.App::get_baseurl()."/".$a->query_string); + header('Refresh: 120; url=' . App::get_baseurl() . "/" . $a->query_string); die("System is currently unavailable. Please try again later"); } - if (get_config('system','force_ssl') AND ($a->get_scheme() == "http") AND + if (get_config('system', 'force_ssl') AND ($a->get_scheme() == "http") AND (intval(get_config('system','ssl_policy')) == SSL_POLICY_FULL) AND (substr(App::get_baseurl(), 0, 8) == "https://")) { header("HTTP/1.1 302 Moved Temporarily"); From 506af8b556015a13251344cb7739b896e30cc0e9 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 12:47:31 +0100 Subject: [PATCH 35/91] changed "and" -> && according to CR Signed-off-by: Roland Haeder --- mod/dfrn_notify.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index caa27b869..e8a08661d 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -143,7 +143,7 @@ function dfrn_notify_post(App $a) { $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')) { + if ($rino == 2 && !function_exists('mcrypt_create_iv')) { $rino = 1; } @@ -319,7 +319,7 @@ function dfrn_notify_content(App $a) { $rino = intval($rino); // use RINO1 if mcrypt isn't installed and RINO2 was selected /// @TODO Define a code-standard: and/AND/&& are around - if ($rino == 2 and !function_exists('mcrypt_create_iv')) { + if ($rino == 2 && !function_exists('mcrypt_create_iv')) { $rino = 1; } From a70a2381c98671d778e514f7bf495a44fe44d576 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 12:49:09 +0100 Subject: [PATCH 36/91] removed old-lost code Signed-off-by: Roland Haeder --- boot.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/boot.php b/boot.php index a00fa5c50..782b2e798 100644 --- a/boot.php +++ b/boot.php @@ -692,9 +692,6 @@ class App { $_SERVER["argc"] --; } - /// @TODO no longer needed? - #set_include_path("include/$this->hostname" . PATH_SEPARATOR . get_include_path()); - if ((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,9) === "pagename=") { $this->query_string = substr($_SERVER['QUERY_STRING'],9); // removing trailing / - maybe a nginx problem From bd4cee8c2188ed6a9784a36c96d68ecd707b3c4b Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 12:53:01 +0100 Subject: [PATCH 37/91] added spaces/curly braces and TODO for better using trim() Signed-off-by: Roland Haeder --- boot.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/boot.php b/boot.php index 782b2e798..57d265711 100644 --- a/boot.php +++ b/boot.php @@ -655,12 +655,13 @@ class App { $this->scheme = 'http'; - if ((x($_SERVER,'HTTPS') && $_SERVER['HTTPS']) || + /// @TODO x() should be better used here ... + 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') || (x($_SERVER['FRONT_END_HTTPS']) && $_SERVER['FRONT_END_HTTPS'] == 'on') || - (x($_SERVER,'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) // XXX: reasonable assumption, but isn't this hardcoding too much? + (x($_SERVER, 'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) // XXX: reasonable assumption, but isn't this hardcoding too much? ) { $this->scheme = 'https'; } @@ -692,22 +693,26 @@ class App { $_SERVER["argc"] --; } - if ((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,9) === "pagename=") { + if ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 9) === "pagename=") { $this->query_string = substr($_SERVER['QUERY_STRING'],9); // removing trailing / - maybe a nginx problem - if (substr($this->query_string, 0, 1) == "/") + /// @TODO can be shortened by trim($str, '/') ! + if (substr($this->query_string, 0, 1) == "/") { $this->query_string = substr($this->query_string, 1); - } elseif ((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=") { + } + } elseif ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 2) === "q=") { $this->query_string = substr($_SERVER['QUERY_STRING'],2); // removing trailing / - maybe a nginx problem - if (substr($this->query_string, 0, 1) == "/") + /// @TODO can be shortened by trim($str, '/') ! + if (substr($this->query_string, 0, 1) == "/") { $this->query_string = substr($this->query_string, 1); + } } - if (x($_GET,'pagename')) { - $this->cmd = trim($_GET['pagename'],'/\\'); - } elseif (x($_GET,'q')) { - $this->cmd = trim($_GET['q'],'/\\'); + if (x($_GET, 'pagename')) { + $this->cmd = trim($_GET['pagename'], '/\\'); + } elseif (x($_GET, 'q')) { + $this->cmd = trim($_GET['q'], '/\\'); } @@ -715,9 +720,8 @@ class App { $this->query_string = str_replace($this->cmd."&",$this->cmd."?", $this->query_string); // unix style "homedir" - - if (substr($this->cmd,0,1) === '~') { - $this->cmd = 'profile/' . substr($this->cmd,1); + if (substr($this->cmd, 0, 1) === '~') { + $this->cmd = 'profile/' . substr($this->cmd, 1); } // Diaspora style profile url From d64dafec636dca15c374d0af616c2b1a4b9a7b4a Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 12:55:13 +0100 Subject: [PATCH 38/91] removed parentheses and indended it for better readability Signed-off-by: Roland Haeder --- boot.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/boot.php b/boot.php index 57d265711..0efd4a206 100644 --- a/boot.php +++ b/boot.php @@ -1234,7 +1234,12 @@ class App { } function get_useragent() { - return (FRIENDICA_PLATFORM." '".FRIENDICA_CODENAME."' ".FRIENDICA_VERSION."-".DB_UPDATE_VERSION."; ".$this->get_baseurl()); + return + FRIENDICA_PLATFORM . " '" . + FRIENDICA_CODENAME . "' " . + FRIENDICA_VERSION . "-" . + DB_UPDATE_VERSION . "; " . + $this->get_baseurl(); } function is_friendica_app() { From 1514fdaead46043823d297f546a54234a5883a1e Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 12:59:37 +0100 Subject: [PATCH 39/91] rewrote to static approach and if() condition can be simplified. Signed-off-by: Roland Haeder --- boot.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/boot.php b/boot.php index 0efd4a206..2a6e9b4ca 100644 --- a/boot.php +++ b/boot.php @@ -1255,8 +1255,7 @@ class App { * @return bool Is it a known backend? */ function is_backend() { - /// @Should be made static to speedup things - $backend = array(); + static $backend = array(); $backend[] = "_well_known"; $backend[] = "api"; $backend[] = "dfrn_notify"; @@ -1277,12 +1276,8 @@ class App { $backend[] = "statistics_json"; $backend[] = "xrd"; - /// @TODO Maybe rewrite this part: return (in_array() || $this->backend); ? - if (in_array($this->module, $backend)) { - return(true); - } else { - return($this->backend); - } + // Check if current module is in backend or backend flag is set + return (in_array($this->module, self::$backend) || $this->backend); } /** From 2f5c796886495e21c09e4fbe550525dd90650689 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:01:41 +0100 Subject: [PATCH 40/91] removed TODO, one day this all needs refacturizing ... Signed-off-by: Roland Haeder --- include/dfrn.php | 2 -- mod/profiles.php | 1 - 2 files changed, 3 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 887dba9a1..1064d7bd8 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -1813,7 +1813,6 @@ class dfrn { update_contact_avatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true); - /// @TODO decide to use dbm::is_result() here if ($x === false) { return false; } @@ -1837,7 +1836,6 @@ class dfrn { $n, dbesc($f[0]), intval($importer["importer_uid"])); - /// @TODO decide to use dbm::is_result() here if ($x === false) { return false; } diff --git a/mod/profiles.php b/mod/profiles.php index 233b276a3..a034f670e 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -465,7 +465,6 @@ function profiles_post(App $a) { intval(local_user()) ); - /// @TODO decide to use dbm::is_result() here and check $r if ($r) { info(t('Profile updated.') . EOL); } From 47ae5a9a4762794b36ffaa296b5bac266ad0f4f4 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:07:19 +0100 Subject: [PATCH 41/91] removed parentheses, added curly ... Signed-off-by: Roland Haeder --- include/dfrn.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/dfrn.php b/include/dfrn.php index 1064d7bd8..ca2c2393e 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -1866,7 +1866,7 @@ class dfrn { // do not accept (ignore) an earlier edit than one we currently have. if (datetime_convert("UTC","UTC",$item["edited"]) < $current["edited"]) { - return(false); + return false; } $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d", From fd468f20fd4f5bc54db3659a8567301007c0c1cc Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:08:38 +0100 Subject: [PATCH 42/91] merged 2 if() into one, closes internal TODO Signed-off-by: Roland Haeder --- include/dfrn.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index ca2c2393e..877b529ba 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -1961,11 +1961,9 @@ class dfrn { */ /// @TODO Maybe merge these if() blocks into one? - 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 && $community && (!$r[0]["forum_mode"]) && (!$r[0]["wall"])) { + $is_a_remote_action = false; + logger("not a community action"); } if ($is_a_remote_action) { From c1287df6556ad8e285d82455f5fb7d050b5db5ce Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:12:25 +0100 Subject: [PATCH 43/91] removed old-lost code + internal TODO closed Signed-off-by: Roland Haeder --- mod/install.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mod/install.php b/mod/install.php index f58345e3a..6db79dca2 100755 --- a/mod/install.php +++ b/mod/install.php @@ -484,10 +484,6 @@ function check_funcs(&$checks) { $ck_funcs[6]['status'] = false; $ck_funcs[6]['help'] = t('Error, XML PHP module required but not installed.'); } - - /// @TODO old-lost code here? - /*if((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg'])) - notice( t('Please see the file "INSTALL.txt".') . EOL);*/ } From 67707247c81ac8f5a259806d6e1334dbf70d50ff Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:14:50 +0100 Subject: [PATCH 44/91] Continued: - added curly braces/spaces - changed lower-case SQL keywords to upper-case - used dbm::is_result() instead of count() (avoids warning in case of false is returned) Signed-off-by: Roland Haeder --- mod/manage.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/mod/manage.php b/mod/manage.php index 10fc7c7e6..e85561acf 100644 --- a/mod/manage.php +++ b/mod/manage.php @@ -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 (dbm::is_result($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,12 +70,13 @@ 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']); } From e503141b0c9cd3c48d467be7fc15c289cc930d31 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:18:28 +0100 Subject: [PATCH 45/91] added spaces and curly braces Signed-off-by: Roland Haeder --- mod/profiles.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mod/profiles.php b/mod/profiles.php index a034f670e..708179692 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -193,14 +193,14 @@ 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); + $y = substr($dob, 0, 4); if ((! ctype_digit($y)) || ($y < 1900)) { $ignore_year = true; } else { $ignore_year = false; } if ($dob != '0000-00-00') { - if (strpos($dob,'0000-') === 0) { + if (strpos($dob, '0000-') === 0) { $ignore_year = true; $dob = substr($dob, 5); } @@ -235,10 +235,10 @@ 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); + $howlong = datetime_convert(date_default_timezone_get(), 'UTC', $howlong); } // linkify the relationship target if applicable @@ -249,7 +249,7 @@ function profiles_post(App $a) { $withchanged = true; $prf = ''; $lookup = $with; - if (strpos($lookup,'@') === 0) { + if (strpos($lookup, '@') === 0) { $lookup = substr($lookup, 1); } $lookup = str_replace('_',' ', $lookup); From 177a0c8320e53e52f7771ec23cdc4296e023ef8c Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:22:39 +0100 Subject: [PATCH 46/91] Continued: - used dbm::is_result() to avoid E_WARNING when false is returned - added curly braces + some spaces Signed-off-by: Roland Haeder --- mod/profiles.php | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/mod/profiles.php b/mod/profiles.php index 708179692..b73c46e71 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,24 +34,22 @@ function profiles_init(App $a) { intval($a->argv[2]), intval(local_user()) ); - if($r) + if (dbm::is_result($r)) { info(t('Profile deleted.').EOL); + } goaway('profiles'); return; // NOTREACHED } - - - - - 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'); $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", intval(local_user())); - $num_profiles = count($r0); + + $num_profiles = (dbm::is_result($r0) ? count($r0) : 0); $name = t('Profile-') . ($num_profiles + 1); @@ -73,19 +71,21 @@ function profiles_init(App $a) { ); info( t('New profile created.') . EOL); - if(count($r3) == 1) - goaway('profiles/'.$r3[0]['id']); + if (dbm::is_result($r3) && 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'); $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", intval(local_user())); - $num_profiles = count($r0); + + $num_profiles = (dbm::is_result($r0) ? count($r0) : 0); $name = t('Profile-') . ($num_profiles + 1); $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1", @@ -116,8 +116,9 @@ function profiles_init(App $a) { dbesc($name) ); info( t('New profile created.') . EOL); - if ((dbm::is_result($r3)) && (count($r3) == 1)) + if ((dbm::is_result($r3)) && (count($r3) == 1)) { goaway('profiles/'.$r3[0]['id']); + } goaway('profiles'); @@ -125,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()) @@ -136,7 +137,7 @@ function profiles_init(App $a) { return; } - profile_load($a,$a->user['nickname'],$r[0]['id']); + profile_load($a,$a->user['nickname'], $r[0]['id']); } @@ -144,15 +145,16 @@ function profiles_init(App $a) { } function profile_clean_keywords($keywords) { - $keywords = str_replace(","," ",$keywords); + $keywords = str_replace(",", " ", $keywords); $keywords = explode(" ", $keywords); $cleaned = array(); foreach ($keywords as $keyword) { $keyword = trim(strtolower($keyword)); $keyword = trim($keyword, "#"); - if ($keyword != "") + if ($keyword != "") { $cleaned[] = $keyword; + } } $keywords = implode(", ", $cleaned); @@ -213,7 +215,7 @@ function profiles_post(App $a) { $name = notags(trim($_POST['name'])); - if(! strlen($name)) { + if (! strlen($name)) { $name = '[No Name]'; } From 1d48801d70100378d22a9f3858249f16e988c4f8 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:25:33 +0100 Subject: [PATCH 47/91] Continued: - added spaces - made a code block even Signed-off-by: Roland Haeder --- util/po2php.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/util/po2php.php b/util/po2php.php index 199d79ed3..f26e93e51 100644 --- a/util/po2php.php +++ b/util/po2php.php @@ -86,10 +86,11 @@ function po2php_run(&$argv, &$argc) { } $match = array(); preg_match("|\[([0-9]*)\] (.*)|", $l, $match); - $out .= "\t". - preg_replace_callback($escape_s_exp,'escape_s',$match[1]) - ." => " - .preg_replace_callback($escape_s_exp,'escape_s',$match[2]) .",\n"; + $out .= "\t" + . preg_replace_callback($escape_s_exp, 'escape_s', $match[1]) + . " => " + . preg_replace_callback($escape_s_exp, 'escape_s', $match[2]) + . ",\n"; } if (substr($l, 0, 6) == "msgid_") { @@ -99,7 +100,7 @@ function po2php_run(&$argv, &$argc) { if ($ink) { $k .= trim($l,"\"\r\n"); - $k = preg_replace_callback($escape_s_exp,'escape_s',$k); + $k = preg_replace_callback($escape_s_exp, 'escape_s', $k); //$out .= '$a->strings['.$k.'] = '; } From b830d839f0ad886cd861ccd5f5b45fa853845b8e Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:27:38 +0100 Subject: [PATCH 48/91] added a space Signed-off-by: Roland Haeder --- util/po2php.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/po2php.php b/util/po2php.php index f26e93e51..34142c669 100644 --- a/util/po2php.php +++ b/util/po2php.php @@ -99,7 +99,7 @@ function po2php_run(&$argv, &$argc) { } if ($ink) { - $k .= trim($l,"\"\r\n"); + $k .= trim($l, "\"\r\n"); $k = preg_replace_callback($escape_s_exp, 'escape_s', $k); //$out .= '$a->strings['.$k.'] = '; } @@ -107,14 +107,14 @@ function po2php_run(&$argv, &$argc) { if (substr($l, 0, 6) == "msgid ") { if ($inv) { $inv = false; - $out .= '"'.$v.'"'; + $out .= '"' . $v . '"'; } if ($k != "") { /// @TODO Maybe add parentheses here? $out .= $arr ? ");\n" : ";\n"; } $arr = false; - $k = str_replace("msgid ","",$l); + $k = str_replace("msgid ", "", $l); if ($k != '""') { $k = trim($k, "\"\r\n"); } else { From 48a1d97f4697cf57a9a12aad9d1d3db49f5f3b62 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:30:12 +0100 Subject: [PATCH 49/91] closed internal TODO, added parentheses as this is a minimized if/else block Signed-off-by: Roland Haeder --- util/po2php.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util/po2php.php b/util/po2php.php index 34142c669..75442406a 100644 --- a/util/po2php.php +++ b/util/po2php.php @@ -110,8 +110,7 @@ function po2php_run(&$argv, &$argc) { $out .= '"' . $v . '"'; } if ($k != "") { - /// @TODO Maybe add parentheses here? - $out .= $arr ? ");\n" : ";\n"; + $out .= ($arr) ? ");\n" : ";\n"; } $arr = false; $k = str_replace("msgid ", "", $l); From 83dec2f8151138acfc6c1ae166c232a2ecd612f6 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:33:15 +0100 Subject: [PATCH 50/91] fixed indending + closed own internal todo: better usage of x() removed todo Signed-off-by: Roland Haeder --- boot.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/boot.php b/boot.php index 2a6e9b4ca..474cb8205 100644 --- a/boot.php +++ b/boot.php @@ -655,14 +655,14 @@ class App { $this->scheme = 'http'; - /// @TODO x() should be better used here ... + 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') || - (x($_SERVER['FRONT_END_HTTPS']) && $_SERVER['FRONT_END_HTTPS'] == 'on') || - (x($_SERVER, 'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) // XXX: reasonable assumption, but isn't this hardcoding too much? - ) { + (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') || + (x($_SERVER, 'FRONT_END_HTTPS') && $_SERVER['FRONT_END_HTTPS'] == 'on') || + (x($_SERVER, 'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) // XXX: reasonable assumption, but isn't this hardcoding too much? + ) { $this->scheme = 'https'; } @@ -1367,7 +1367,6 @@ class App { // add baseurl to args. cli scripts can't construct it $args[] = $this->get_baseurl(); - /// @TODO let's replace these with a foreach($key => $value) loop for ($x = 0; $x < count($args); $x ++) { $args[$x] = escapeshellarg($args[$x]); } From 6d5826e1880d2b4c21ea3044c6931d59027e8576 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:37:15 +0100 Subject: [PATCH 51/91] PHP5 does not support native type-hints, except `array` + used dbm::is_result() Signed-off-by: Roland Haeder --- include/dfrn.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 877b529ba..9192e9430 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -216,13 +216,10 @@ 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. + /* + * Will check further below if this actually returned results. + * We will provide an empty feed if that is the case. + */ $items = $r; @@ -243,10 +240,10 @@ class dfrn { $root = self::add_header($doc, $owner, $author, $alternatelink, true); - // This hook can't work anymore + /// @TODO This hook can't work anymore // call_hooks('atom_feed', $atom); - if (!count($items) OR $onlyheader) { + if (!dbm::is_result($items) OR $onlyheader) { $atom = trim($doc->saveXML()); call_hooks('atom_feed_end', $atom); From 89bd080e7ec815ffc7e327c5512587a339ab6a94 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:40:43 +0100 Subject: [PATCH 52/91] don't kill when no result is found, this may break communication, thanks to @annando explaining it Signed-off-by: Roland Haeder --- include/dfrn.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 9192e9430..555fa57f2 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -915,12 +915,7 @@ 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"]) { + if (dbm::is_result($r) AND ($r[0]["forum"] OR $r[0]["prv"])) { xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned", "ostatus:object-type" => ACTIVITY_OBJ_GROUP, "href" => $mention)); From a391ab9a9937b71a07ec26ab57ba70c13857b294 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:46:28 +0100 Subject: [PATCH 53/91] was a bit confusing for me or I was not sleeping to much ... Signed-off-by: Roland Haeder --- include/dfrn.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 555fa57f2..4593380d1 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -1743,11 +1743,7 @@ class dfrn { intval($importer["importer_uid"])); if (!dbm::is_result($r)) { - /* - * @TODO maybe one day: logger("Query failed to execute, no result returned in " . __FUNCTION__); - killme(); - */ return false; } @@ -2113,11 +2109,7 @@ class dfrn { ); if (!dbm::is_result($r)) { - /* - * @TODO maybe one day: logger("Query failed to execute, no result returned in " . __FUNCTION__); - killme(); - */ return false; } From 4d731dd83871c4e9907bec40a863605fd6e0e39a Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 13:56:56 +0100 Subject: [PATCH 54/91] Convention: - comment blocks with 2 stars at beinging are doc-tags, with only star is a regular multi-line comment - added curly braces + spaces - removed TODO, there needs to be a way of writing this better than using @ Signed-off-by: Roland Haeder --- index.php | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/index.php b/index.php index 19eb5bff7..349e1cc60 100644 --- a/index.php +++ b/index.php @@ -336,6 +336,7 @@ if ($a->module_loaded) { $func = str_replace('-','_',current_theme()) . '_init'; $func($a); } +/// @TODO commented out? old-lost again? :-) // 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')) { @@ -376,27 +377,25 @@ if ($a->module_loaded) { /* * Create the page head after setting the language - * and getting any auth credentials + * and getting any auth credentials. * * Moved init_pagehead() and init_page_end() to after * all the module functions have executed so that all - * theme choices made by the modules can take effect + * theme choices made by the modules can take effect. */ $a->init_pagehead(); -/** +/* * Build the page ending -- this is stuff that goes right before * the closing tag */ - $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']; } @@ -404,35 +403,35 @@ if (isset($homebase)) { $a->page['content'] .= ''; } +<<<<<<< HEAD // 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. +======= +/* + * 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. + */ +>>>>>>> 29f1028... Convention: if (stristr( implode("",$_SESSION['sysmsg']), t('Permission denied'))) { header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.')); } -/** - * +/* * Report anything which needs to be communicated in the notification area (before the main body) - * */ - call_hooks('page_end', $a->page['content']); -/** - * +/* * Add the navigation (menu) template - * */ - if ($a->module != 'install' && $a->module != 'maintenance') { nav($a); } -/** +/* * 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']) { $link = 'toggle_mobile?address=' . curPageURL(); From 006b4b88b2a90cdf63229191fc3ed5462e14c9e8 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 14:07:26 +0100 Subject: [PATCH 55/91] Continued: - added curly braces/spaces - converted multiple single-line comments into one multi-line comment Signed-off-by: Roland Haeder --- mod/dfrn_notify.php | 67 ++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index e8a08661d..5f4fc3a1f 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -28,14 +28,14 @@ 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) { - $direction = intval(substr($dfrn_id,0,1)); - $dfrn_id = substr($dfrn_id,2); + if (strpos($dfrn_id, ':') == 1) { + $direction = intval(substr($dfrn_id, 0, 1)); + $dfrn_id = substr($dfrn_id, 2); } $r = q("SELECT * FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s' LIMIT 1", @@ -70,9 +70,11 @@ function dfrn_notify_post(App $a) { break; // NOTREACHED } - // be careful - $importer will contain both the contact information for the contact - // sending us the post, and also the user information for the person receiving it. - // since they are mixed together, it is easy to get them confused. + /* + * be careful - $importer will contain both the contact information for the contact + * sending us the post, and also the user information for the person receiving it. + * since they are mixed together, it is easy to get them confused. + */ $r = q("SELECT `contact`.*, `contact`.`uid` AS `importer_uid`, `contact`.`pubkey` AS `cpubkey`, @@ -100,15 +102,16 @@ 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 +123,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 @@ -133,7 +136,7 @@ function dfrn_notify_post(App $a) { } - + /// @TODO remove this old-lost code then? // 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 @@ -149,7 +152,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 @@ -162,19 +165,16 @@ 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 { + } else { openssl_public_decrypt($rawkey,$final_key,$importer['cpubkey']); } - } - else { - if((($importer['duplex']) && strlen($importer['cpubkey'])) || (! strlen($importer['cprvkey']))) { + } else { + if ((($importer['duplex']) && strlen($importer['cpubkey'])) || (! strlen($importer['cprvkey']))) { openssl_public_decrypt($rawkey,$final_key,$importer['cpubkey']); - } - else { + } else { openssl_private_decrypt($rawkey,$final_key,$importer['cprvkey']); } } @@ -184,19 +184,23 @@ function dfrn_notify_post(App $a) { switch($rino_remote) { case 0: case 1: - // we got a key. old code send only the key, without RINO version. - // we assume RINO 1 if key and no RINO version + /* + * we got a key. old code send only the key, without RINO version. + * we assume RINO 1 if key and no RINO version + */ $data = aes_decrypt(hex2bin($data),$final_key); break; case 2: try { $data = Crypto::decrypt(hex2bin($data),$final_key); } catch (InvalidCiphertext $ex) { // VERY IMPORTANT - // Either: - // 1. The ciphertext was modified by the attacker, - // 2. The key is wrong, or - // 3. $ciphertext is not a valid ciphertext or was corrupted. - // Assume the worst. + /* + * Either: + * 1. The ciphertext was modified by the attacker, + * 2. The key is wrong, or + * 3. $ciphertext is not a valid ciphertext or was corrupted. + * Assume the worst. + */ logger('The ciphertext has been tampered with!'); xml_status(0,'The ciphertext has been tampered with!'); } catch (Ex\CryptoTestFailed $ex) { @@ -227,8 +231,10 @@ function dfrn_notify_content(App $a) { 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. + /* + * initial communication from external contact, $direction is their direction. + * If this is a duplex communication, ours will be the opposite. + */ $dfrn_id = notags(trim($_GET['dfrn_id'])); $dfrn_version = (float) $_GET['dfrn_version']; @@ -318,7 +324,6 @@ function dfrn_notify_content(App $a) { $rino = get_config('system','rino_encrypt'); $rino = intval($rino); // use RINO1 if mcrypt isn't installed and RINO2 was selected - /// @TODO Define a code-standard: and/AND/&& are around if ($rino == 2 && !function_exists('mcrypt_create_iv')) { $rino = 1; } From 73ee28521281ba3abe1096bf49eb5a3d0e959d61 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 14:32:49 +0100 Subject: [PATCH 56/91] rewrote for() loop to foreach() + added curly braces/spaces Signed-off-by: Roland Haeder --- index.php | 10 ++----- mod/photos.php | 78 +++++++++++++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/index.php b/index.php index 349e1cc60..8560f8c27 100644 --- a/index.php +++ b/index.php @@ -395,7 +395,7 @@ $a->init_page_end(); // If you're just visiting, let javascript take you home if (x($_SESSION, 'visitor_home')) { $homebase = $_SESSION['visitor_home']; -] elseif (local_user()) { +} elseif (local_user()) { $homebase = 'profile/' . $a->user['nickname']; } @@ -403,17 +403,11 @@ if (isset($homebase)) { $a->page['content'] .= ''; } -<<<<<<< HEAD -// 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. - -======= /* * 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. */ ->>>>>>> 29f1028... Convention: -if (stristr( implode("",$_SESSION['sysmsg']), t('Permission denied'))) { +if (stristr(implode("", $_SESSION['sysmsg']), t('Permission denied'))) { header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.')); } diff --git a/mod/photos.php b/mod/photos.php index 27d8499c2..4b3dc46b7 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1325,16 +1325,17 @@ function photos_content(App $a) { dbesc($datum) ); - if (! count($ph)) { + if (! dbm::is_result($ph)) { $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1", intval($owner_uid), dbesc($datum) ); - if (count($ph)) - notice( t('Permission denied. Access to this item may be restricted.')); - else - notice( t('Photo not available') . EOL ); + if (dbm::is_result($ph)) { + notice(t('Permission denied. Access to this item may be restricted.')); + } else { + notice(t('Photo not available') . EOL ); + } return; } @@ -1356,15 +1357,17 @@ function photos_content(App $a) { intval($owner_uid) ); - if (count($prvnxt)) { - for($z = 0; $z < count($prvnxt); $z++) { - if ($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) { + if (dbm::is_result($prvnxt)) { + foreach ($prvnxt as $z => $entry) { + if ($entry['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; } } @@ -1387,8 +1390,8 @@ function photos_content(App $a) { } $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']); - $tools = Null; - $lock = Null; + $tools = null; + $lock = null; if ($can_post && ($ph[0]['uid'] == $owner_uid)) { $tools = array( @@ -1426,8 +1429,9 @@ function photos_content(App $a) { 'filename' => $hires['filename'], ); - if ($nextlink) + if ($nextlink) { $nextlink = array($nextlink, ''); + } // Do we have an item for this photo? @@ -1444,8 +1448,9 @@ function photos_content(App $a) { $map = null; - if (count($linked_items)) { + if (dbm::is_result($linked_items)) { $link_item = $linked_items[0]; + $r = qu("SELECT COUNT(*) AS `total` FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0 @@ -1458,8 +1463,9 @@ function photos_content(App $a) { ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $a->set_pager_total($r[0]['total']); + } $r = qu("SELECT `item`.*, `item`.`id` AS `item_id`, @@ -1493,15 +1499,16 @@ function photos_content(App $a) { } } - $tags=Null; + $tags = null; if (count($linked_items) && strlen($link_item['tag'])) { $arr = explode(',',$link_item['tag']); // parse tags and add links $tag_str = ''; foreach ($arr as $t) { - if (strlen($tag_str)) + if (strlen($tag_str)) { $tag_str .= ', '; + } $tag_str .= bbcode($t); } $tags = array(t('Tags: '), $tag_str); @@ -1518,21 +1525,25 @@ function photos_content(App $a) { // 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) + /* + * 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) { $public_post_link = '?public=1'; - else + } else { $public_post_link = '&public=1'; - + } if ($a->theme['template_engine'] === 'internal') { $album_e = template_escape($ph[0]['album']); @@ -1596,6 +1607,7 @@ function photos_content(App $a) { $comments = ''; if (! dbm::is_result($r)) { + /// @TODO merge into one if() ? if ($can_post || can_write_wall($a,$owner_uid)) { if ($link_item['last-child']) { $comments .= replace_macros($cmnt_tpl,array( @@ -1630,8 +1642,6 @@ function photos_content(App $a) { 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title')) ); - - // display comments if (dbm::is_result($r)) { @@ -1642,8 +1652,7 @@ function photos_content(App $a) { $like = ((x($conv_responses['like'],$link_item['uri'])) ? format_like($conv_responses['like'][$link_item['uri']],$conv_responses['like'][$link_item['uri'] . '-l'],'like',$link_item['id']) : ''); $dislike = ((x($conv_responses['dislike'],$link_item['uri'])) ? format_like($conv_responses['dislike'][$link_item['uri']],$conv_responses['dislike'][$link_item['uri'] . '-l'],'dislike',$link_item['id']) : ''); - - + /// @TODO merge into one if() ? if ($can_post || can_write_wall($a,$owner_uid)) { if ($link_item['last-child']) { $comments .= replace_macros($cmnt_tpl,array( @@ -1675,7 +1684,7 @@ function photos_content(App $a) { if (((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent'])) continue; - $redirect_url = 'redir/' . $item['cid'] ; + $redirect_url = 'redir/' . $item['cid']; if (local_user() && ($item['contact-uid'] == local_user()) @@ -1694,8 +1703,6 @@ function photos_content(App $a) { $profile_link = $profile_url; - - $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user())); $drop = array( 'dropping' => $dropping, @@ -1704,7 +1711,6 @@ function photos_content(App $a) { 'delete' => t('Delete'), ); - if ($a->theme['template_engine'] === 'internal') { $name_e = template_escape($profile_name); $title_e = template_escape($item['title']); @@ -1729,10 +1735,10 @@ function photos_content(App $a) { '$comment' => $comment )); - if ($can_post || can_write_wall($a,$owner_uid)) { - + /// @TODO merge into one if() ? + if ($can_post || can_write_wall($a, $owner_uid)) { if ($item['last-child']) { - $comments .= replace_macros($cmnt_tpl,array( + $comments .= replace_macros($cmnt_tpl, array( '$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', From fccdc63964cb484b8fbcd0f64451295ce9032193 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 14:56:23 +0100 Subject: [PATCH 57/91] Opps, fixed parser error. indending was confusing here + added much more curly braces Signed-off-by: Roland Haeder --- include/dfrn.php | 7 +- mod/photos.php | 211 ++++++++++++++++++++++++++++------------------- 2 files changed, 127 insertions(+), 91 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index 4593380d1..d9012fe70 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -1129,10 +1129,9 @@ class dfrn { 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']))) - + 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 { openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']); diff --git a/mod/photos.php b/mod/photos.php index 4b3dc46b7..e4548bb46 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -14,8 +14,9 @@ use \Friendica\Core\Config; function photos_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())) { return; @@ -29,8 +30,9 @@ function photos_init(App $a) { dbesc($nick) ); - if (! count($user)) + if (! dbm::is_result($user)) { return; + } $a->data['user'] = $user[0]; $a->profile_uid = $user[0]['uid']; @@ -59,8 +61,9 @@ function photos_init(App $a) { if ($albums) { $a->data['albums'] = $albums; - if ($albums_visible) + if ($albums_visible) { $ret['success'] = true; + } $ret['albums'] = array(); foreach ($albums as $k => $album) { @@ -80,24 +83,26 @@ function photos_init(App $a) { $albums = $ret; - if (local_user() && $a->data['user']['uid'] == local_user()) + if (local_user() && $a->data['user']['uid'] == local_user()) { $can_post = true; + } if ($albums['success']) { - $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'),array( + $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'), array( '$nick' => $a->data['user']['nickname'], '$title' => t('Photo Albums'), - '$recent' => t('Recent Photos'), + '$recent' => t('Recent Photos'), '$albums' => $albums['albums'], '$baseurl' => z_root(), - '$upload' => array( t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'), + '$upload' => array(t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'), '$can_post' => $can_post )); } - if (! x($a->page,'aside')) + if (! x($a->page, 'aside')) { $a->page['aside'] = ''; + } $a->page['aside'] .= $vcard_widget; $a->page['aside'] .= $photo_albums_widget; @@ -130,9 +135,9 @@ function photos_post(App $a) { $page_owner_uid = $a->data['user']['uid']; $community_page = (($a->data['user']['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 { + } else { if ($community_page && remote_user()) { $contact_id = 0; if (is_array($_SESSION['remote'])) { @@ -295,8 +300,9 @@ function photos_post(App $a) { // send the notification upstream/downstream as the case may be - if ($rr['visible']) + if ($rr['visible']) { proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id); + } } } @@ -371,8 +377,9 @@ function photos_post(App $a) { // Update the photo albums cache photo_albums($page_owner_uid, true); - if ($i[0]['visible']) + if ($i[0]['visible']) { proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id); + } } } @@ -394,15 +401,16 @@ function photos_post(App $a) { $resource_id = $a->argv[2]; - if (! strlen($albname)) + if (! strlen($albname)) { $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y'); + } if ((x($_POST,'rotate') !== false) && ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) { logger('rotate'); - $r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1", + $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0 LIMIT 1", dbesc($resource_id), intval($page_owner_uid) ); @@ -415,7 +423,7 @@ function photos_post(App $a) { $width = $ph->getWidth(); $height = $ph->getHeight(); - $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0", + $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0", dbesc($ph->imageString()), intval($height), intval($width), @@ -428,7 +436,7 @@ function photos_post(App $a) { $width = $ph->getWidth(); $height = $ph->getHeight(); - $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1", + $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 1", dbesc($ph->imageString()), intval($height), intval($width), @@ -442,7 +450,7 @@ function photos_post(App $a) { $width = $ph->getWidth(); $height = $ph->getHeight(); - $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2", + $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 2", dbesc($ph->imageString()), intval($height), intval($width), @@ -458,7 +466,7 @@ function photos_post(App $a) { dbesc($resource_id), intval($page_owner_uid) ); - if (count($p)) { + if (dbm::is_result($p)) { $ext = $phototypes[$p[0]['type']]; $r = q("UPDATE `photo` SET `desc` = '%s', `album` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d", dbesc($desc), @@ -470,6 +478,7 @@ function photos_post(App $a) { dbesc($resource_id), intval($page_owner_uid) ); + // Update the photo albums cache if album name was changed if ($albname !== $origaname) { photo_albums($page_owner_uid, true); @@ -479,8 +488,9 @@ function photos_post(App $a) { /* Don't make the item visible if the only change was the album name */ $visibility = 0; - if ($p[0]['desc'] !== $desc || strlen($rawtags)) + if ($p[0]['desc'] !== $desc || strlen($rawtags)) { $visibility = 1; + } if (! $item_id) { @@ -540,16 +550,18 @@ function photos_post(App $a) { // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag $x = substr($rawtags,0,1); - if ($x !== '@' && $x !== '#') + if ($x !== '@' && $x !== '#') { $rawtags = '#' . $rawtags; + } $taginfo = array(); $tags = get_tags($rawtags); if (count($tags)) { foreach ($tags as $tag) { - if (isset($profile)) + if (isset($profile)) { unset($profile); + } if (strpos($tag,'@') === 0) { $name = substr($tag,1); if ((strpos($name,'@')) || (strpos($name,'http://'))) { @@ -557,13 +569,15 @@ function photos_post(App $a) { $links = @Probe::lrdd($name); if (count($links)) { foreach ($links as $link) { - if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') + if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') { $profile = $link['@attributes']['href']; + } if ($link['@attributes']['rel'] === 'salmon') { $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']); - if (strlen($inform)) + if (strlen($inform)) { $inform .= ','; - $inform .= $salmon; + } + $inform .= $salmon; } } } @@ -572,8 +586,9 @@ function photos_post(App $a) { $newname = $name; $alias = ''; $tagcid = 0; - if (strrpos($newname,'+')) - $tagcid = intval(substr($newname,strrpos($newname,'+') + 1)); + if (strrpos($newname,'+')) { + $tagcid = intval(substr($newname,strrpos($newname, '+') + 1)); + } if ($tagcid) { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", @@ -589,7 +604,7 @@ function photos_post(App $a) { intval($page_owner_uid) ); - if (! $r) { + if (! dbm::is_result($r)) { //select someone by attag or nick and the name passed in $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", dbesc($name), @@ -598,6 +613,7 @@ function photos_post(App $a) { ); } } + /// @TODO maybe old-lost code to be removed /* elseif (strstr($name,'_') || strstr($name,' ')) { $newname = str_replace('_',' ',$name); $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", @@ -615,19 +631,22 @@ function photos_post(App $a) { $newname = $r[0]['name']; $profile = $r[0]['url']; $notify = 'cid:' . $r[0]['id']; - if (strlen($inform)) + if (strlen($inform)) { $inform .= ','; + } $inform .= $notify; } } if ($profile) { - if (substr($notify,0,4) === 'cid:') - $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'); - else - $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'); - if (strlen($str_tags)) + if (substr($notify,0,4) === 'cid:') { + $taginfo[] = array($newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'); + } else { + $taginfo[] = array($newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'); + } + if (strlen($str_tags)) { $str_tags .= ','; - $profile = str_replace(',','%2c',$profile); + } + $profile = str_replace(',', '%2c', $profile); $str_tags .= '@[url='.$profile.']'.$newname.'[/url]'; } } elseif (strpos($tag,'#') === 0) { @@ -638,13 +657,15 @@ function photos_post(App $a) { } $newtag = $old_tag; - if (strlen($newtag) && strlen($str_tags)) + if (strlen($newtag) && strlen($str_tags)) { $newtag .= ','; + } $newtag .= $str_tags; $newinform = $old_inform; - if (strlen($newinform) && strlen($inform)) + if (strlen($newinform) && strlen($inform)) { $newinform .= ','; + } $newinform .= $inform; $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d", @@ -707,8 +728,9 @@ function photos_post(App $a) { $arr['object'] = '' . ACTIVITY_OBJ_PERSON . '' . $tagged[0] . '' . $tagged[1] . '/' . $tagged[0] . ''; $arr['object'] .= '' . xmlify('' . "\n"); - if ($tagged[3]) + if ($tagged[3]) { $arr['object'] .= xmlify('' . "\n"); + } $arr['object'] .= '' . "\n"; $arr['target'] = '' . ACTIVITY_OBJ_IMAGE . '' . $p[0]['desc'] . '' @@ -720,9 +742,7 @@ function photos_post(App $a) { proc_run(PRIORITY_HIGH, "include/notifier.php", "tag", $item_id); } } - } - } goaway($_SESSION['photo_return']); return; // NOTREACHED @@ -745,33 +765,34 @@ function photos_post(App $a) { logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG); if (! strlen($album)) { - if (strlen($newalbum)) + if (strlen($newalbum)) { $album = $newalbum; - else + } else { $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y'); + } } - /** - * + /* * We create a wall item for every photo, but we don't want to * overwhelm the data stream with a hundred newly uploaded photos. * So we will make the first photo uploaded to this album in the last several hours * visible by default, the rest will become visible over time when and if * they acquire comments, likes, dislikes, and/or tags - * */ $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ", dbesc($album), intval($page_owner_uid) ); - if ((! dbm::is_result($r)) || ($album == t('Profile Photos'))) + if ((! dbm::is_result($r)) || ($album == t('Profile Photos'))) { $visible = 1; - else + } else { $visible = 0; + } - if (intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true') + if (intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true') { $visible = 0; + } $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow']))); $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow']))); @@ -793,7 +814,9 @@ function photos_post(App $a) { $filesize = intval($_FILES['userfile']['size']); $type = $_FILES['userfile']['type']; } - if ($type=="") $type=guess_image_type($filename); + if ($type == "") { + $type = guess_image_type($filename); + } logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG); @@ -823,7 +846,7 @@ function photos_post(App $a) { $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit'); if ($limit) { - $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", + $r = q("SELECT SUM(OCTET_LENGTH(`data`)) AS `total` FROM `photo` WHERE `uid` = %d AND `scale` = 0 AND `album` != 'Contact Photos'", intval($a->data['user']['uid']) ); $size = $r[0]['total']; @@ -852,10 +875,12 @@ function photos_post(App $a) { @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); + } $width = $ph->getWidth(); $height = $ph->getHeight(); @@ -891,6 +916,7 @@ function photos_post(App $a) { $lat = $lon = null; + /// @TODO merge these 2 if() into one? if ($exif && $exif['GPS']) { if (feature_enabled($channel_id,'photo_location')) { $lat = getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']); @@ -900,8 +926,9 @@ function photos_post(App $a) { $arr = array(); - if ($lat && $lon) + if ($lat && $lon) { $arr['coord'] = $lat . ' ' . $lon; + } $arr['guid'] = get_guid(32); $arr['uid'] = $page_owner_uid; @@ -934,20 +961,21 @@ function photos_post(App $a) { // Update the photo albums cache photo_albums($page_owner_uid, true); - if ($visible) + if ($visible) { proc_run(PRIORITY_HIGH, "include/notifier.php", 'wall-new', $item_id); + } call_hooks('photo_post_end',intval($item_id)); - // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook - // if they do not wish to be redirected + /* + * addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook + * if they do not wish to be redirected + */ goaway($_SESSION['photo_return']); // NOTREACHED } - - function photos_content(App $a) { // URLs: @@ -965,7 +993,6 @@ function photos_content(App $a) { return; } - require_once('include/bbcode.php'); require_once('include/security.php'); require_once('include/conversation.php'); @@ -986,15 +1013,17 @@ function photos_content(App $a) { 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 + } else { $datatype = 'summary'; + } - if ($a->argc > 4) + if ($a->argc > 4) { $cmd = $a->argv[4]; - else + } else { $cmd = 'view'; + } // // Setup permissions structures @@ -1010,9 +1039,9 @@ function photos_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 { + } else { if ($community_page && remote_user()) { if (is_array($_SESSION['remote'])) { foreach ($_SESSION['remote'] as $v) { @@ -1063,6 +1092,7 @@ function photos_content(App $a) { } } + /// @TODO merge these 2 if() into one? if (! $remote_contact) { if (local_user()) { $contact_id = $_SESSION['cid']; @@ -1089,7 +1119,7 @@ function photos_content(App $a) { if ($datatype === 'upload') { if (! ($can_post)) { - notice( t('Permission denied.')); + notice(t('Permission denied.')); return; } @@ -1103,8 +1133,9 @@ function photos_content(App $a) { $albumselect .= ''; if (count($a->data['albums'])) { foreach ($a->data['albums'] as $album) { - if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos'))) + if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos'))) { continue; + } $selected = (($selname === $album['album']) ? ' selected="selected" ' : ''); $albumselect .= ''; } @@ -1116,7 +1147,6 @@ function photos_content(App $a) { 'addon_text' => $uploader, 'default_upload' => true); - call_hooks('photo_upload_form',$ret); $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array()); @@ -1128,31 +1158,34 @@ function photos_content(App $a) { $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit'); if ($limit !== false) { - $r = q("select sum(datasize) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", + $r = q("SELECT SUM(`datasize`) AS `total` FROM `photo` WHERE `uid` = %d AND `scale` = 0 AND `album` != 'Contact Photos'", intval($a->data['user']['uid']) ); - $usage_message = sprintf( t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 ); + $usage_message = sprintf(t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 ); } // 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) + /* + * 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) { $public_post_link = '?public=1'; - else + } else { $public_post_link = '&public=1'; - - + } $tpl = get_markup_template('photos_upload.tpl'); @@ -1213,10 +1246,12 @@ function photos_content(App $a) { $a->set_pager_itemspage(20); } - if ($_GET['order'] === 'posted') + /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it? + if ($_GET['order'] === 'posted') { $order = 'ASC'; - else + } else { $order = 'DESC'; + } $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s' AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d", @@ -1226,7 +1261,7 @@ function photos_content(App $a) { intval($a->pager['itemspage']) ); - //edit album name + // edit album name if ($cmd === 'edit') { if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) { if ($can_post) { @@ -1249,6 +1284,7 @@ function photos_content(App $a) { } } } else { + /// @TODO merge else+if into elseif and 2 into one? if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) { if ($can_post) { $edit = array(t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'); @@ -1256,20 +1292,22 @@ function photos_content(App $a) { } } - if ($_GET['order'] === 'posted') + if ($_GET['order'] === 'posted') { $order = array(t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album)); - else + } else { $order = array(t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted'); + } $photos = array(); if (dbm::is_result($r)) $twist = 'rotright'; foreach ($r as $rr) { - if ($twist == 'rotright') + if ($twist == 'rotright') { $twist = 'rotleft'; - else + } else { $twist = 'rotright'; + } $ext = $phototypes[$rr['type']]; @@ -1310,10 +1348,9 @@ function photos_content(App $a) { } - /** + /* * Display one photo */ - if ($datatype === 'image') { //$o = ''; From 0e6b00942592ee328eb0df182326edeb688e9c6b Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 14:57:40 +0100 Subject: [PATCH 58/91] fixed another parser error, opps Signed-off-by: Roland Haeder --- include/update_gcontact.php | 4 +++- mod/photos.php | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/update_gcontact.php b/include/update_gcontact.php index 08d4149a7..2719044a1 100644 --- a/include/update_gcontact.php +++ b/include/update_gcontact.php @@ -21,11 +21,13 @@ function update_gcontact_run(&$argv, &$argc){ $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id)); - if (!$r) + if (!dbm::_is_result($r)) { return; + } if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) return; + } $data = probe_url($r[0]["url"]); diff --git a/mod/photos.php b/mod/photos.php index e4548bb46..a54aff326 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -638,7 +638,7 @@ function photos_post(App $a) { } } if ($profile) { - if (substr($notify,0,4) === 'cid:') { + if (substr($notify, 0, 4) === 'cid:') { $taginfo[] = array($newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'); } else { $taginfo[] = array($newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'); @@ -1427,8 +1427,8 @@ function photos_content(App $a) { } $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']); - $tools = null; - $lock = null; + $tools = null; + $lock = null; if ($can_post && ($ph[0]['uid'] == $owner_uid)) { $tools = array( From 952f2218ed21a0af1ba0acecded8b6da5efd1bd2 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 15:12:24 +0100 Subject: [PATCH 59/91] there is already $this->backend around, needs renaming Signed-off-by: Roland Haeder --- boot.php | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/boot.php b/boot.php index 474cb8205..92acb1b24 100644 --- a/boot.php +++ b/boot.php @@ -1255,29 +1255,29 @@ class App { * @return bool Is it a known backend? */ function is_backend() { - static $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 $backends = array(); + $backends[] = "_well_known"; + $backends[] = "api"; + $backends[] = "dfrn_notify"; + $backends[] = "fetch"; + $backends[] = "hcard"; + $backends[] = "hostxrd"; + $backends[] = "nodeinfo"; + $backends[] = "noscrape"; + $backends[] = "p"; + $backends[] = "poco"; + $backends[] = "post"; + $backends[] = "proxy"; + $backends[] = "pubsub"; + $backends[] = "pubsubhubbub"; + $backends[] = "receive"; + $backends[] = "rsd_xml"; + $backends[] = "salmon"; + $backends[] = "statistics_json"; + $backends[] = "xrd"; // Check if current module is in backend or backend flag is set - return (in_array($this->module, self::$backend) || $this->backend); + return (in_array($this->module, self::$backends) || $this->backend); } /** From 66f5e104b162c9d5dca44cf4ea0a423bdec5da29 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 15:13:28 +0100 Subject: [PATCH 60/91] and without self:: ;-( Signed-off-by: Roland Haeder --- boot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot.php b/boot.php index 92acb1b24..1d6772b17 100644 --- a/boot.php +++ b/boot.php @@ -1277,7 +1277,7 @@ class App { $backends[] = "xrd"; // Check if current module is in backend or backend flag is set - return (in_array($this->module, self::$backends) || $this->backend); + return (in_array($this->module, $backends) || $this->backend); } /** From 33fa1e79af1a7fe7a5af30ae8788136a1d3999a1 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 18:32:11 +0100 Subject: [PATCH 61/91] some spaces ... Signed-off-by: Roland Haeder --- include/update_gcontact.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/update_gcontact.php b/include/update_gcontact.php index 2719044a1..d90b98711 100644 --- a/include/update_gcontact.php +++ b/include/update_gcontact.php @@ -2,11 +2,11 @@ use \Friendica\Core\Config; -function update_gcontact_run(&$argv, &$argc){ +function update_gcontact_run(&$argv, &$argc) { global $a; - require_once('include/Scrape.php'); - require_once('include/socgraph.php'); + require_once 'include/Scrape.php'; + require_once 'include/socgraph.php'; logger('update_gcontact: start'); From 9ddb032bf217f333671b5b4b54bf397207df6caa Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 18:32:33 +0100 Subject: [PATCH 62/91] strange that this curly brace didn't make it in. now it is, thanks to @annando Signed-off-by: Roland Haeder --- include/update_gcontact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/update_gcontact.php b/include/update_gcontact.php index d90b98711..221c0829f 100644 --- a/include/update_gcontact.php +++ b/include/update_gcontact.php @@ -25,7 +25,7 @@ function update_gcontact_run(&$argv, &$argc) { return; } - if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) + if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) { return; } From b97561e0c40c081bbab4a20b57aa57f5f5570057 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 21:19:52 +0100 Subject: [PATCH 63/91] added spaces Signed-off-by: Roland Haeder --- boot.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/boot.php b/boot.php index 1d6772b17..0ed33ad7e 100644 --- a/boot.php +++ b/boot.php @@ -694,7 +694,7 @@ class App { } if ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 9) === "pagename=") { - $this->query_string = substr($_SERVER['QUERY_STRING'],9); + $this->query_string = substr($_SERVER['QUERY_STRING'], 9); // removing trailing / - maybe a nginx problem /// @TODO can be shortened by trim($str, '/') ! if (substr($this->query_string, 0, 1) == "/") { @@ -717,7 +717,7 @@ class App { // fix query_string - $this->query_string = str_replace($this->cmd."&",$this->cmd."?", $this->query_string); + $this->query_string = str_replace($this->cmd . "&", $this->cmd . "?", $this->query_string); // unix style "homedir" if (substr($this->cmd, 0, 1) === '~') { @@ -725,14 +725,12 @@ class App { } // Diaspora style profile url - if (substr($this->cmd,0,2) === 'u/') { $this->cmd = 'profile/' . substr($this->cmd,2); } /* - * * Break the URL path into C style argc/argv style arguments for our * modules. Given "http://example.com/module/arg1/arg2", $this->argc * will be 3 (integer) and $this->argv will contain: @@ -743,12 +741,11 @@ class App { * * There will always be one argument. If provided a naked domain * URL, $this->argv[0] is set to "home". - * */ - $this->argv = explode('/',$this->cmd); + $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 { @@ -762,9 +759,10 @@ class App { * pagination */ - $this->pager['page'] = ((x($_GET,'page') && intval($_GET['page']) > 0) ? intval($_GET['page']) : 1); + $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) { $this->pager['start'] = 0; } From fda99e39c147d97e038e1bd8e141a7ea5c64a3ec Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 25 Mar 2017 21:21:50 +0100 Subject: [PATCH 64/91] used ltrim() for removing (any) trailing space Signed-off-by: Roland Haeder --- boot.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/boot.php b/boot.php index 0ed33ad7e..c9d3045ca 100644 --- a/boot.php +++ b/boot.php @@ -695,18 +695,14 @@ class App { if ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 9) === "pagename=") { $this->query_string = substr($_SERVER['QUERY_STRING'], 9); + // removing trailing / - maybe a nginx problem - /// @TODO can be shortened by trim($str, '/') ! - if (substr($this->query_string, 0, 1) == "/") { - $this->query_string = substr($this->query_string, 1); - } + $this->query_string = lrim($this->query_string, '/'); } elseif ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 2) === "q=") { $this->query_string = substr($_SERVER['QUERY_STRING'],2); + // removing trailing / - maybe a nginx problem - /// @TODO can be shortened by trim($str, '/') ! - if (substr($this->query_string, 0, 1) == "/") { - $this->query_string = substr($this->query_string, 1); - } + $this->query_string = lrim($this->query_string, '/'); } if (x($_GET, 'pagename')) { From 0ac1af7300edf9d9f5df7fae75f578b8de0f7333 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 30 Mar 2017 20:22:03 +0200 Subject: [PATCH 65/91] spaces added according code convention and CR + fixed tzpo in function name (opps) Signed-off-by: Roland Haeder --- boot.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boot.php b/boot.php index c9d3045ca..3bf85b14f 100644 --- a/boot.php +++ b/boot.php @@ -699,10 +699,10 @@ class App { // removing trailing / - maybe a nginx problem $this->query_string = lrim($this->query_string, '/'); } elseif ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 2) === "q=") { - $this->query_string = substr($_SERVER['QUERY_STRING'],2); + $this->query_string = substr($_SERVER['QUERY_STRING'], 2); // removing trailing / - maybe a nginx problem - $this->query_string = lrim($this->query_string, '/'); + $this->query_string = ltrim($this->query_string, '/'); } if (x($_GET, 'pagename')) { From 32da3b2f58607868800794d85f1f07d313537e23 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 30 Mar 2017 20:24:55 +0200 Subject: [PATCH 66/91] removed commented-out by CR request + it is ... SPACE TIME! ;-) Signed-off-by: Roland Haeder --- index.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/index.php b/index.php index 8560f8c27..ebc65cdb0 100644 --- a/index.php +++ b/index.php @@ -66,10 +66,10 @@ if (!$install) { } if (get_config('system', 'force_ssl') AND ($a->get_scheme() == "http") AND - (intval(get_config('system','ssl_policy')) == SSL_POLICY_FULL) AND + (intval(get_config('system', 'ssl_policy')) == SSL_POLICY_FULL) AND (substr(App::get_baseurl(), 0, 8) == "https://")) { header("HTTP/1.1 302 Moved Temporarily"); - header("Location: ".App::get_baseurl()."/".$a->query_string); + header("Location: " . App::get_baseurl() . "/" . $a->query_string); exit(); } @@ -336,14 +336,6 @@ if ($a->module_loaded) { $func = str_replace('-','_',current_theme()) . '_init'; $func($a); } -/// @TODO commented out? old-lost again? :-) -// 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')) { -// $func = str_replace('-','_',$a->theme_info["extends"]) . '_init'; -// $func($a); -// } -// } if (($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error) && (function_exists($a->module . '_post')) From e0f4d2204991b7c53268bfa9d0ec855db387ffe3 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 30 Mar 2017 20:26:36 +0200 Subject: [PATCH 67/91] removed old-lost code by CR request + spaces added ... Signed-off-by: Roland Haeder --- mod/dfrn_notify.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index 5f4fc3a1f..84d589a21 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -136,21 +136,14 @@ function dfrn_notify_post(App $a) { } - /// @TODO remove this old-lost code then? - // 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) - // xml_status(0); - - $rino = get_config('system','rino_encrypt'); + $rino = get_config('system', 'rino_encrypt'); $rino = intval($rino); // use RINO1 if mcrypt isn't installed and RINO2 was selected if ($rino == 2 && !function_exists('mcrypt_create_iv')) { $rino = 1; } - logger("Local rino version: ". $rino, LOGGER_DEBUG); + logger("Local rino version: " . $rino, LOGGER_DEBUG); if (strlen($key)) { From 9c056d0bf0a8102b021d8c96d21e7fe1484d0677 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 30 Mar 2017 20:30:23 +0200 Subject: [PATCH 68/91] it is ... SPACE TIME! ;-) Signed-off-by: Roland Haeder --- mod/dfrn_notify.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index 84d589a21..ddb6afe4e 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -160,15 +160,15 @@ function dfrn_notify_post(App $a) { if ($dfrn_version >= 2.1) { if ((($importer['duplex']) && strlen($importer['cprvkey'])) || (! strlen($importer['cpubkey']))) { - openssl_private_decrypt($rawkey,$final_key,$importer['cprvkey']); + openssl_private_decrypt($rawkey, $final_key, $importer['cprvkey']); } else { - openssl_public_decrypt($rawkey,$final_key,$importer['cpubkey']); + openssl_public_decrypt($rawkey, $final_key, $importer['cpubkey']); } } else { if ((($importer['duplex']) && strlen($importer['cpubkey'])) || (! strlen($importer['cprvkey']))) { - openssl_public_decrypt($rawkey,$final_key,$importer['cpubkey']); + openssl_public_decrypt($rawkey, $final_key, $importer['cpubkey']); } else { - openssl_private_decrypt($rawkey,$final_key,$importer['cprvkey']); + openssl_private_decrypt($rawkey, $final_key, $importer['cprvkey']); } } @@ -181,11 +181,11 @@ function dfrn_notify_post(App $a) { * we got a key. old code send only the key, without RINO version. * we assume RINO 1 if key and no RINO version */ - $data = aes_decrypt(hex2bin($data),$final_key); + $data = aes_decrypt(hex2bin($data), $final_key); break; case 2: try { - $data = Crypto::decrypt(hex2bin($data),$final_key); + $data = Crypto::decrypt(hex2bin($data), $final_key); } catch (InvalidCiphertext $ex) { // VERY IMPORTANT /* * Either: @@ -195,13 +195,13 @@ function dfrn_notify_post(App $a) { * Assume the worst. */ logger('The ciphertext has been tampered with!'); - xml_status(0,'The ciphertext has been tampered with!'); + xml_status(0, 'The ciphertext has been tampered with!'); } catch (Ex\CryptoTestFailed $ex) { logger('Cannot safely perform dencryption'); - xml_status(0,'CryptoTestFailed'); + xml_status(0, 'CryptoTestFailed'); } catch (Ex\CannotPerformOperation $ex) { logger('Cannot safely perform decryption'); - xml_status(0,'Cannot safely perform decryption'); + xml_status(0, 'Cannot safely perform decryption'); } break; default: From d0917598888930ab083ab6a52ce72334fa2992c8 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 30 Mar 2017 20:33:38 +0200 Subject: [PATCH 69/91] space to the rescue ... ;-) CR request Signed-off-by: Roland Haeder --- include/dfrn.php | 2 +- mod/dfrn_notify.php | 2 +- mod/photos.php | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/dfrn.php b/include/dfrn.php index d9012fe70..83d76a0ae 100644 --- a/include/dfrn.php +++ b/include/dfrn.php @@ -955,7 +955,7 @@ class dfrn { $idtosend = '1:' . $orig_id; } - $rino = get_config('system','rino_encrypt'); + $rino = get_config('system', 'rino_encrypt'); $rino = intval($rino); // use RINO1 if mcrypt isn't installed and RINO2 was selected diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index ddb6afe4e..ddbc9219b 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -314,7 +314,7 @@ function dfrn_notify_content(App $a) { $encrypted_id = bin2hex($encrypted_id); - $rino = get_config('system','rino_encrypt'); + $rino = get_config('system', 'rino_encrypt'); $rino = intval($rino); // use RINO1 if mcrypt isn't installed and RINO2 was selected if ($rino == 2 && !function_exists('mcrypt_create_iv')) { diff --git a/mod/photos.php b/mod/photos.php index a54aff326..376f8ec7c 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -18,7 +18,7 @@ function photos_init(App $a) { 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; } @@ -562,9 +562,9 @@ function photos_post(App $a) { if (isset($profile)) { unset($profile); } - if (strpos($tag,'@') === 0) { + if (strpos($tag, '@') === 0) { $name = substr($tag,1); - if ((strpos($name,'@')) || (strpos($name,'http://'))) { + if ((strpos($name, '@')) || (strpos($name, 'http://'))) { $newname = $name; $links = @Probe::lrdd($name); if (count($links)) { @@ -573,7 +573,7 @@ function photos_post(App $a) { $profile = $link['@attributes']['href']; } if ($link['@attributes']['rel'] === 'salmon') { - $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']); + $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']); if (strlen($inform)) { $inform .= ','; } @@ -581,13 +581,13 @@ function photos_post(App $a) { } } } - $taginfo[] = array($newname,$profile,$salmon); + $taginfo[] = array($newname, $profile, $salmon); } else { $newname = $name; $alias = ''; $tagcid = 0; - if (strrpos($newname,'+')) { - $tagcid = intval(substr($newname,strrpos($newname, '+') + 1)); + if (strrpos($newname, '+')) { + $tagcid = intval(substr($newname, strrpos($newname, '+') + 1)); } if ($tagcid) { @@ -649,9 +649,9 @@ function photos_post(App $a) { $profile = str_replace(',', '%2c', $profile); $str_tags .= '@[url='.$profile.']'.$newname.'[/url]'; } - } elseif (strpos($tag,'#') === 0) { + } elseif (strpos($tag, '#') === 0) { $tagname = substr($tag, 1); - $str_tags .= '#[url='.App::get_baseurl()."/search?tag=".$tagname.']'.$tagname.'[/url]'; + $str_tags .= '#[url=' . App::get_baseurl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]'; } } } @@ -988,7 +988,7 @@ function photos_content(App $a) { // photos/name/image/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; } From 3d595c4dcc57e163400c01129f45d5e99eca16b7 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 30 Mar 2017 21:32:12 +0200 Subject: [PATCH 70/91] Continued a bit: - added spaces / curly braces - converted multiple single-line comments into one multi-line comment - used more dbm::is_result() - include/require are no functions, let's not abuse them ... Signed-off-by: Roland Haeder --- mod/item.php | 405 ++++++++++++++++++++++++++------------------------- 1 file changed, 209 insertions(+), 196 deletions(-) diff --git a/mod/item.php b/mod/item.php index 6da9ce88e..1f8071998 100644 --- a/mod/item.php +++ b/mod/item.php @@ -1,43 +1,44 @@ 1); echo json_encode($json); @@ -45,34 +46,31 @@ function item_post(App $a) { } call_hooks('post_local_start', $_REQUEST); -// logger('postinput ' . file_get_contents('php://input')); + // logger('postinput ' . file_get_contents('php://input')); logger('postvars ' . print_r($_REQUEST,true), LOGGER_DATA); - $api_source = ((x($_REQUEST,'api_source') && $_REQUEST['api_source']) ? true : false); + $api_source = ((x($_REQUEST, 'api_source') && $_REQUEST['api_source']) ? true : false); - $message_id = ((x($_REQUEST,'message_id') && $api_source) ? strip_tags($_REQUEST['message_id']) : ''); + $message_id = ((x($_REQUEST, 'message_id') && $api_source) ? strip_tags($_REQUEST['message_id']) : ''); - $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : ''); - $preview = ((x($_REQUEST,'preview')) ? intval($_REQUEST['preview']) : 0); + $return_path = ((x($_REQUEST, 'return')) ? $_REQUEST['return'] : ''); + $preview = ((x($_REQUEST, 'preview')) ? intval($_REQUEST['preview']) : 0); - - // Check for doubly-submitted posts, and reject duplicates - // Note that we have to ignore previews, otherwise nothing will post - // after it's been previewed - if (!$preview && x($_REQUEST['post_id_random'])) { - if (x($_SESSION['post-random']) && $_SESSION['post-random'] == $_REQUEST['post_id_random']) { + /* + * Check for doubly-submitted posts, and reject duplicates + * Note that we have to ignore previews, otherwise nothing will post + * after it's been previewed + */ + if (!$preview && x($_REQUEST, 'post_id_random')) { + if (x($_SESSION, 'post-random') && $_SESSION['post-random'] == $_REQUEST['post_id_random']) { logger("item post: duplicate post", LOGGER_DEBUG); item_post_return(App::get_baseurl(), $api_source, $return_path); - } - else { + } else { $_SESSION['post-random'] = $_REQUEST['post_id_random']; } } - /** - * Is this a reply to something? - */ - + // Is this a reply to something? $parent = ((x($_REQUEST,'parent')) ? intval($_REQUEST['parent']) : 0); $parent_uri = ((x($_REQUEST,'parent_uri')) ? trim($_REQUEST['parent_uri']) : ''); @@ -133,8 +131,9 @@ function item_post(App $a) { intval($parent_item['contact-id']), intval($uid) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $parent_contact = $r[0]; + } // If the contact id doesn't fit with the contact, then set the contact to null $thrparent = q("SELECT `author-link`, `network` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($thr_parent)); @@ -153,16 +152,20 @@ function item_post(App $a) { $parent_contact["addr"] = $probed_contact["addr"]; } } - logger('no contact found: '.print_r($thrparent, true), LOGGER_DEBUG); - } else - logger('parent contact: '.print_r($parent_contact, true), LOGGER_DEBUG); + logger('no contact found: ' . print_r($thrparent, true), LOGGER_DEBUG); + } else { + logger('parent contact: ' . print_r($parent_contact, true), LOGGER_DEBUG); + } - if ($parent_contact["nick"] == "") + if ($parent_contact["nick"] == "") { $parent_contact["nick"] = $parent_contact["name"]; + } } } - 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,22 +192,23 @@ 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']))) { - notice( t('Permission denied.') . EOL) ; - if(x($_REQUEST,'return')) + if ((x($_REQUEST, 'commenter')) && ((! $parent) || (! $parent_item['wall']))) { + notice(t('Permission denied.') . EOL) ; + if (x($_REQUEST, 'return')) { goaway($return_path); + } killme(); } - // Now check that it is a page_type of PAGE_BLOG, and that valid personal details - // have been provided, and run any anti-spam plugins - - - - if((! can_write_wall($a,$profile_uid)) && (! $allow_moderated)) { - notice( t('Permission denied.') . EOL) ; - if(x($_REQUEST,'return')) + /* + * Now check that it is a page_type of PAGE_BLOG, and that valid personal details + * have been provided, and run any anti-spam plugins + */ + if ((! can_write_wall($a, $profile_uid)) && (! $allow_moderated)) { + notice(t('Permission denied.') . EOL) ; + if (x($_REQUEST, 'return')) { goaway($return_path); + } killme(); } @@ -213,7 +217,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) @@ -229,10 +233,11 @@ function item_post(App $a) { $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($profile_uid) ); - if (dbm::is_result($r)) + 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']; @@ -254,11 +259,13 @@ function item_post(App $a) { } else { - // if coming from the API and no privacy settings are set, - // use the user default permissions - as they won't have - // been supplied via a form. + /* + * if coming from the API and no privacy settings are set, + * 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)) @@ -267,8 +274,7 @@ function item_post(App $a) { $str_contact_allow = $user['allow_cid']; $str_group_deny = $user['deny_gid']; $str_contact_deny = $user['deny_cid']; - } - else { + } else { // use the posted permissions @@ -287,26 +293,25 @@ function item_post(App $a) { $network = notags(trim($_REQUEST['network'])); $guid = get_guid(32); - item_add_language_opt($_REQUEST); $postopts = $_REQUEST['postopts'] ? $_REQUEST['postopts'] : ""; - $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) AND ($parent_item['network'] != NETWORK_OSTATUS) - AND ($network == "")) + AND ($network == "")) { $network = $parent_item['network']; + } $str_contact_allow = $parent_item['allow_cid']; $str_group_allow = $parent_item['allow_gid']; @@ -315,32 +320,35 @@ function item_post(App $a) { $private = $parent_item['private']; } - $pubmail_enable = ((x($_REQUEST,'pubmail_enable') && intval($_REQUEST['pubmail_enable']) && (! $private)) ? 1 : 0); + $pubmail_enable = ((x($_REQUEST, 'pubmail_enable') && intval($_REQUEST['pubmail_enable']) && (! $private)) ? 1 : 0); // 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()) ); - if (dbm::is_result($r) && intval($r[0]['pubmail'])) + if (dbm::is_result($r) && intval($r[0]['pubmail'])) { $pubmail_enabled = true; + } } } - if(! strlen($body)) { - if($preview) + if (! strlen($body)) { + if ($preview) { killme(); - info( t('Empty post discarded.') . EOL ); - if(x($_REQUEST,'return')) + } + info(t('Empty post discarded.') . EOL ); + 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 +356,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 +367,20 @@ 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,30 +394,28 @@ function item_post(App $a) { // get contact info for owner - if($profile_uid == local_user()) { + if ($profile_uid == local_user()) { $contact_record = $author; - } - else { + } else { $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($profile_uid) ); - if (dbm::is_result($r)) + if (dbm::is_result($r)) { $contact_record = $r[0]; + } } $post_type = notags(trim($_REQUEST['type'])); - if($post_type === 'net-comment') { - if($parent_item !== null) { - if($parent_item['wall'] == 1) - $post_type = 'wall-comment'; - else - $post_type = 'remote-comment'; + if ($post_type === 'net-comment' && $parent_item !== null) { + if ($parent_item['wall'] == 1) { + $post_type = 'wall-comment'; + } else { + $post_type = 'remote-comment'; } } - /** - * + /* * When a photo was uploaded into the message using the (profile wall) ajax * uploader, The permissions are initially set to disallow anybody but the * owner from seeing it. This is because the permissions may not yet have been @@ -418,14 +423,13 @@ function item_post(App $a) { * appropriately. But we didn't know the final permissions on the post until * now. So now we'll look for links of uploaded messages that are in the * post and set them to the same permissions as the post itself. - * */ $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; @@ -466,16 +470,15 @@ function item_post(App $a) { } - /** + /* * Next link in any attachment references we find in the post. */ - $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) @@ -499,7 +502,7 @@ function item_post(App $a) { $bookmark = 0; $data = get_attachment_data($body); - if (preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) OR isset($data["type"])) { + if (preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) OR isset($data["type"])) { $objecttype = ACTIVITY_OBJ_BOOKMARK; $bookmark = 1; } @@ -507,46 +510,39 @@ function item_post(App $a) { $body = bb_translate_video($body); - /** - * Fold multi-line [code] sequences - */ - - $body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body); + // Fold multi-line [code] sequences + $body = preg_replace('/\[\/code\]\s*\[code\]/ism', "\n", $body); $body = scale_external_images($body,false); - // Setting the object type if not defined before if (!$objecttype) { $objecttype = ACTIVITY_OBJ_NOTE; // Default value require_once("include/plaintext.php"); $objectdata = get_attached_data($body); - if ($post["type"] == "link") + if ($post["type"] == "link") { $objecttype = ACTIVITY_OBJ_BOOKMARK; - elseif ($post["type"] == "video") + } elseif ($post["type"] == "video") { $objecttype = ACTIVITY_OBJ_VIDEO; - elseif ($post["type"] == "photo") + } elseif ($post["type"] == "photo") { $objecttype = ACTIVITY_OBJ_IMAGE; + } } - /** - * Look for any tags and linkify them - */ - + // Look for any tags and linkify them $str_tags = ''; $inform = ''; - $tags = get_tags($body); - /** + /* * add a statusnet style reply tag if the original post was from there * and we are replying, and there isn't one already */ if ($parent AND ($parent_contact['network'] == NETWORK_OSTATUS)) { - $contact = '@[url='.$parent_contact['url'].']'.$parent_contact['nick'].'[/url]'; + $contact = '@[url=' . $parent_contact['url'] . ']' . $parent_contact['nick'] . '[/url]'; if (!in_array($contact,$tags)) { $body = $contact.' '.$body; @@ -557,39 +553,43 @@ function item_post(App $a) { $toplevel_parent = q("SELECT `contact`.* FROM `contact` INNER JOIN `item` ON `item`.`contact-id` = `contact`.`id` AND `contact`.`url` = `item`.`author-link` WHERE `item`.`id` = `item`.`parent` AND `item`.`parent` = %d", intval($parent)); - if ($toplevel_parent) - $toplevel_contact = '@'.$toplevel_parent[0]['nick'].'+'.$toplevel_parent[0]['id']; - else { + if (dbm::is_result($toplevel_parent)) { + $toplevel_contact = '@' . $toplevel_parent[0]['nick'] . '+' . $toplevel_parent[0]['id']; + } else { $toplevel_parent = q("SELECT `author-link`, `author-name` FROM `item` WHERE `id` = `parent` AND `parent` = %d", intval($parent)); $toplevel_contact = '@[url='.$toplevel_parent[0]['author-link'].']'.$toplevel_parent[0]['author-name'].'[/url]'; } - if (!in_array($toplevel_contact,$tags)) + if (!in_array($toplevel_contact, $tags)) [ $tags[] = $toplevel_contact; + } } $tagged = array(); $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 - + /* + * 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']) { @@ -668,11 +668,11 @@ function item_post(App $a) { $datarray['owner-name'] = $contact_record['name']; $datarray['owner-link'] = $contact_record['url']; $datarray['owner-avatar'] = $contact_record['thumb']; - $datarray["owner-id"] = get_contact($datarray["owner-link"], 0); + $datarray['owner-id'] = get_contact($datarray['owner-link'], 0); $datarray['author-name'] = $author['name']; $datarray['author-link'] = $author['url']; $datarray['author-avatar'] = $author['thumb']; - $datarray["author-id"] = get_contact($datarray["author-link"], 0); + $datarray['author-id'] = get_contact($datarray['author-link'], 0); $datarray['created'] = datetime_convert(); $datarray['edited'] = datetime_convert(); $datarray['commented'] = datetime_convert(); @@ -707,30 +707,29 @@ function item_post(App $a) { "photo" => $datarray['author-avatar'], "name" => $datarray['author-name'])); $datarray['object'] = $object; - /** + /* * These fields are for the convenience of plugins... * 'self' if true indicates the owner is posting on their own wall * If parent is 0 it is a top-level post. */ - $datarray['parent'] = $parent; $datarray['self'] = $self; // $datarray['prvnets'] = $user['prvnets']; $datarray['parent-uri'] = ($parent == 0) ? $uri : $parent_item['uri']; - $datarray['plink'] = App::get_baseurl().'/display/'.urlencode($datarray['guid']); + $datarray['plink'] = App::get_baseurl() . '/display/' . urlencode($datarray['guid']); $datarray['last-child'] = 1; $datarray['visible'] = 1; - if($orig_post) - $datarray['edit'] = true; + 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. @@ -741,12 +740,11 @@ function item_post(App $a) { killme(); } - 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 +760,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,13 +783,14 @@ 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); } killme(); - } else + } else { $post_id = 0; + } q("COMMIT"); q("START TRANSACTION;"); @@ -869,7 +868,7 @@ function item_post(App $a) { dbesc($datarray['plink']), intval($datarray['last-child']), intval($datarray['visible']) - ); + ); if (dbm::is_result($r)) { $r = q("SELECT LAST_INSERT_ID() AS `item-id`"); @@ -900,7 +899,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 +915,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'], @@ -925,7 +924,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'], @@ -948,7 +947,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 +956,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,21 +968,22 @@ 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']) . '
'; $disclaimer .= sprintf( t('You may visit them online at %s'), App::get_baseurl() . '/profile/' . $a->user['nickname']) . EOL; $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL; if (!$datarray['title']=='') { - $subject = email_header_encode($datarray['title'],'UTF-8'); + $subject = email_header_encode($datarray['title'], 'UTF-8'); } else { - $subject = email_header_encode('[Friendica]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']),'UTF-8'); + $subject = email_header_encode('[Friendica]' . ' ' . sprintf( t('%s posted an update.'), $a->user['username']), 'UTF-8'); } $link = '' . $a->user['username'] . '

'; $html = prepare_body($datarray); @@ -1032,8 +1032,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); @@ -1094,9 +1095,9 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo $r = null; //is it a person tag? - if (strpos($tag,'@') === 0) { + if (strpos($tag, '@') === 0) { //is it already replaced? - if (strpos($tag,'[url=')) { + if (strpos($tag, '[url=')) { //append tag to str_tags if (!stristr($str_tags,$tag)) { if (strlen($str_tags)) { @@ -1111,19 +1112,22 @@ 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)) + $newtag = '@[url=' . $data["alias"] . ']' . $data["name"] . '[/url]'; + if (!stristr($str_tags, $newtag)) { + if (strlen($str_tags)) { $str_tags .= ','; + } $str_tags .= $newtag; } } @@ -1133,7 +1137,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo } $stat = false; //get the person's name - $name = substr($tag,1); + $name = substr($tag, 1); // Sometimes the tag detection doesn't seem to work right // This is some workaround @@ -1141,7 +1145,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo $name = $nameparts[0]; // Try to detect the contact in various ways - if ((strpos($name,'@')) || (strpos($name,'http://'))) { + if ((strpos($name, '@')) || (strpos($name, 'http://'))) { // Is it in format @user@domain.tld or @http://domain.tld/...? // First check the contact table for the address @@ -1155,7 +1159,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,26 +1168,29 @@ 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) + if (!dbm::is_result($r)) { $r = q("SELECT `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `gcontact` WHERE `addr` = '%s' AND (`network` != '%s' OR (`notify` != '' AND `alias` != '')) LIMIT 1", dbesc($name), dbesc(NETWORK_OSTATUS) ); + } // 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); @@ -1203,8 +1210,8 @@ 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 != "")) + // select someone by attag or nick and the name passed in the current 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), @@ -1213,70 +1220,76 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo ); //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) + // select someone by attag or nick and the name passed in + 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) + // select someone from this user's contacts by name + 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 if (isset($profile) AND ($newname != "")) { $replaced = true; - //create profile link + // create profile link $profile = str_replace(',','%2c',$profile); $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)) + // append tag to 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; } } From 5bc2ebb267f4dc49957838f5feba16c5bc0fc796 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 30 Mar 2017 21:36:34 +0200 Subject: [PATCH 71/91] Please use x() correctly: Signed-off-by: Roland Haeder --- mod/admin.php | 16 ++++++++-------- mod/network.php | 28 ++++++++++++++++------------ view/theme/vier/theme.php | 27 ++++++++++++++------------- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index b1bc8de5f..79fcebf47 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -2017,22 +2017,22 @@ function admin_page_features_post(App $a) { $features = get_features(false); foreach ($features as $fname => $fdata) { - foreach (array_slice($fdata,1) as $f) { + foreach (array_slice($fdata, 1) as $f) { $feature = $f[0]; - $feature_state = 'feature_'.$feature; - $featurelock = 'featurelock_'.$feature; + $feature_state = 'feature_' . $feature; + $featurelock = 'featurelock_' . $feature; - if (x($_POST[$feature_state])) { - $val = intval($_POST['feature_'.$feature]); + if (x($_POST, $feature_state)) { + $val = intval($_POST[$feature_state]); } else { $val = 0; } set_config('feature',$feature,$val); - if (x($_POST[$featurelock])) { - set_config('feature_lock',$feature,$val); + if (x($_POST, $featurelock)) { + set_config('feature_lock', $feature, $val); } else { - del_config('feature_lock',$feature); + del_config('feature_lock', $feature); } } } diff --git a/mod/network.php b/mod/network.php index a1181a74c..d2c77f19d 100644 --- a/mod/network.php +++ b/mod/network.php @@ -6,7 +6,7 @@ function network_init(App $a) { } $is_a_date_query = false; - if (x($_GET['cid']) && intval($_GET['cid']) != 0) { + if (x($_GET, 'cid') && intval($_GET['cid']) != 0) { $cid = $_GET['cid']; } @@ -103,24 +103,27 @@ function network_init(App $a) { } } - if(x($_GET['nets']) && $_GET['nets'] === 'all') + // If nets is set to all, unset it + 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); set_pconfig(local_user(), 'network.view', 'group.selected', $group_id); - require_once('include/group.php'); - require_once('include/contact_widgets.php'); - require_once('include/items.php'); - require_once('include/ForumManager.php'); + require_once 'include/group.php'; + require_once 'include/contact_widgets.php'; + 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']) : ''); + $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 +135,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 +143,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,8 +160,9 @@ 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(); diff --git a/view/theme/vier/theme.php b/view/theme/vier/theme.php index a35afa719..50e8cd377 100644 --- a/view/theme/vier/theme.php +++ b/view/theme/vier/theme.php @@ -213,8 +213,9 @@ function vier_community_info() { require_once('include/ForumManager.php'); - if (x($_GET['cid']) && intval($_GET['cid']) != 0) + if (x($_GET, 'cid') && intval($_GET['cid']) != 0) { $cid = $_GET['cid']; + } //sort by last updated item $lastitem = true; @@ -227,18 +228,18 @@ function vier_community_info() { $id = 0; - foreach($contacts as $contact) { + foreach ($contacts as $contact) { $selected = (($cid == $contact['id']) ? ' forum-selected' : ''); $entry = array( - 'url' => 'network?f=&cid=' . $contact['id'], + 'url' => 'network?f=&cid=' . $contact['id'], 'external_url' => 'redir/' . $contact['id'], - 'name' => $contact['name'], - 'cid' => $contact['id'], - 'selected' => $selected, - 'micro' => App::remove_baseurl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)), - 'id' => ++$id, + 'name' => $contact['name'], + 'cid' => $contact['id'], + 'selected' => $selected, + 'micro' => App::remove_baseurl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)), + 'id' => ++$id, ); $entries[] = $entry; } @@ -247,12 +248,12 @@ function vier_community_info() { $tpl = get_markup_template('widget_forumlist_right.tpl'); $page .= replace_macros($tpl,array( - '$title' => t('Forums'), - '$forums' => $entries, - '$link_desc' => t('External link to forum'), - '$total' => $total, + '$title' => t('Forums'), + '$forums' => $entries, + '$link_desc' => t('External link to forum'), + '$total' => $total, '$visible_forums' => $visible_forums, - '$showmore' => t('show more'), + '$showmore' => t('show more'), )); $aside['$page'] = $page; From f998438d430d8f5081e09c0511528b61e7aa753b Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 30 Mar 2017 21:38:22 +0200 Subject: [PATCH 72/91] removed old-lost code by CR request Signed-off-by: Roland Haeder --- mod/photos.php | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index 376f8ec7c..478c954aa 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -613,20 +613,7 @@ function photos_post(App $a) { ); } } - /// @TODO maybe old-lost code to be removed -/* elseif (strstr($name,'_') || strstr($name,' ')) { - $newname = str_replace('_',' ',$name); - $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", - dbesc($newname), - intval($page_owner_uid) - ); - } else { - $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", - dbesc($name), - dbesc($name), - intval($page_owner_uid) - ); - }*/ + if (dbm::is_result($r)) { $newname = $r[0]['name']; $profile = $r[0]['url']; From 6b8f581897febed81c830586565747525c2b2156 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 30 Mar 2017 21:42:00 +0200 Subject: [PATCH 73/91] added spaces Signed-off-by: Roland Haeder --- mod/photos.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index 478c954aa..ddef07000 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -781,10 +781,10 @@ function photos_post(App $a) { $visible = 0; } - $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow']))); - $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow']))); - $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny']))); - $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny']))); + $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',', $_REQUEST['group_allow']))); + $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',', $_REQUEST['contact_allow']))); + $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',', $_REQUEST['group_deny']))); + $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',', $_REQUEST['contact_deny']))); $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''); @@ -830,7 +830,7 @@ function photos_post(App $a) { $imagedata = @file_get_contents($src); - $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit'); + $limit = service_class_fetch($a->data['user']['uid'], 'photo_upload_limit'); if ($limit) { $r = q("SELECT SUM(OCTET_LENGTH(`data`)) AS `total` FROM `photo` WHERE `uid` = %d AND `scale` = 0 AND `album` != 'Contact Photos'", @@ -1142,7 +1142,7 @@ function photos_content(App $a) { )); $usage_message = ''; - $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit'); + $limit = service_class_fetch($a->data['user']['uid'], 'photo_upload_limit'); if ($limit !== false) { $r = q("SELECT SUM(`datasize`) AS `total` FROM `photo` WHERE `uid` = %d AND `scale` = 0 AND `album` != 'Contact Photos'", @@ -1526,7 +1526,7 @@ function photos_content(App $a) { $tags = null; if (count($linked_items) && strlen($link_item['tag'])) { - $arr = explode(',',$link_item['tag']); + $arr = explode(',', $link_item['tag']); // parse tags and add links $tag_str = ''; foreach ($arr as $t) { @@ -1673,8 +1673,8 @@ function photos_content(App $a) { builtin_activity_puller($item, $conv_responses); } - $like = ((x($conv_responses['like'],$link_item['uri'])) ? format_like($conv_responses['like'][$link_item['uri']],$conv_responses['like'][$link_item['uri'] . '-l'],'like',$link_item['id']) : ''); - $dislike = ((x($conv_responses['dislike'],$link_item['uri'])) ? format_like($conv_responses['dislike'][$link_item['uri']],$conv_responses['dislike'][$link_item['uri'] . '-l'],'dislike',$link_item['id']) : ''); + $like = ((x($conv_responses['like'],$link_item['uri'])) ? format_like($conv_responses['like'][$link_item['uri']],$conv_responses['like'][$link_item['uri'] . '-l'], 'like',$link_item['id']) : ''); + $dislike = ((x($conv_responses['dislike'],$link_item['uri'])) ? format_like($conv_responses['dislike'][$link_item['uri']],$conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike',$link_item['id']) : ''); /// @TODO merge into one if() ? if ($can_post || can_write_wall($a,$owner_uid)) { From 2a480df6fac9dfe2b671f37fa86152ae92d501d5 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 30 Mar 2017 21:44:32 +0200 Subject: [PATCH 74/91] added spaces + removed parentheses (include/require are no functions) Signed-off-by: Roland Haeder --- mod/photos.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index ddef07000..1467dff34 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1,14 +1,14 @@ orient($src); @unlink($src); - $max_length = get_config('system','max_image_length'); + $max_length = get_config('system', 'max_image_length'); if (! $max_length) { $max_length = MAX_IMAGE_LENGTH; } From de5125a4c72309d5b167916e905eed1cad8d2679 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 30 Mar 2017 21:45:35 +0200 Subject: [PATCH 75/91] merged 2 if() into one as requested by CR Signed-off-by: Roland Haeder --- mod/photos.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index 1467dff34..92682f443 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1271,11 +1271,8 @@ function photos_content(App $a) { } } } else { - /// @TODO merge else+if into elseif and 2 into one? - if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) { - if ($can_post) { - $edit = array(t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'); - } + if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos')) && $can_post) { + $edit = array(t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'); } } From 192f6d7cf43be08b5ac873d0bfbd84494eef3e2f Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 30 Mar 2017 21:48:46 +0200 Subject: [PATCH 76/91] merged 2 if() into one three times Signed-off-by: Roland Haeder --- mod/photos.php | 117 +++++++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 63 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index 92682f443..0f021d55a 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1628,27 +1628,24 @@ function photos_content(App $a) { $comments = ''; if (! dbm::is_result($r)) { - /// @TODO merge into one if() ? - if ($can_post || can_write_wall($a,$owner_uid)) { - if ($link_item['last-child']) { - $comments .= replace_macros($cmnt_tpl,array( - '$return_path' => '', - '$jsreload' => $return_url, - '$type' => 'wall-comment', - '$id' => $link_item['id'], - '$parent' => $link_item['id'], - '$profile_uid' => $owner_uid, - '$mylink' => $contact['url'], - '$mytitle' => t('This is you'), - '$myphoto' => $contact['thumb'], - '$comment' => t('Comment'), - '$submit' => t('Submit'), - '$preview' => t('Preview'), - '$sourceapp' => t($a->sourcename), - '$ww' => '', - '$rand_num' => random_digits(12) - )); - } + if (($can_post || can_write_wall($a,$owner_uid)) && $link_item['last-child']) { + $comments .= replace_macros($cmnt_tpl,array( + '$return_path' => '', + '$jsreload' => $return_url, + '$type' => 'wall-comment', + '$id' => $link_item['id'], + '$parent' => $link_item['id'], + '$profile_uid' => $owner_uid, + '$mylink' => $contact['url'], + '$mytitle' => t('This is you'), + '$myphoto' => $contact['thumb'], + '$comment' => t('Comment'), + '$submit' => t('Submit'), + '$preview' => t('Preview'), + '$sourceapp' => t($a->sourcename), + '$ww' => '', + '$rand_num' => random_digits(12) + )); } } @@ -1673,27 +1670,24 @@ function photos_content(App $a) { $like = ((x($conv_responses['like'],$link_item['uri'])) ? format_like($conv_responses['like'][$link_item['uri']],$conv_responses['like'][$link_item['uri'] . '-l'], 'like',$link_item['id']) : ''); $dislike = ((x($conv_responses['dislike'],$link_item['uri'])) ? format_like($conv_responses['dislike'][$link_item['uri']],$conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike',$link_item['id']) : ''); - /// @TODO merge into one if() ? - if ($can_post || can_write_wall($a,$owner_uid)) { - if ($link_item['last-child']) { - $comments .= replace_macros($cmnt_tpl,array( - '$return_path' => '', - '$jsreload' => $return_url, - '$type' => 'wall-comment', - '$id' => $link_item['id'], - '$parent' => $link_item['id'], - '$profile_uid' => $owner_uid, - '$mylink' => $contact['url'], - '$mytitle' => t('This is you'), - '$myphoto' => $contact['thumb'], - '$comment' => t('Comment'), - '$submit' => t('Submit'), - '$preview' => t('Preview'), - '$sourceapp' => t($a->sourcename), - '$ww' => '', - '$rand_num' => random_digits(12) - )); - } + if (($can_post || can_write_wall($a, $owner_uid)) && $link_item['last-child']) { + $comments .= replace_macros($cmnt_tpl,array( + '$return_path' => '', + '$jsreload' => $return_url, + '$type' => 'wall-comment', + '$id' => $link_item['id'], + '$parent' => $link_item['id'], + '$profile_uid' => $owner_uid, + '$mylink' => $contact['url'], + '$mytitle' => t('This is you'), + '$myphoto' => $contact['thumb'], + '$comment' => t('Comment'), + '$submit' => t('Submit'), + '$preview' => t('Preview'), + '$sourceapp' => t($a->sourcename), + '$ww' => '', + '$rand_num' => random_digits(12) + )); } @@ -1756,27 +1750,24 @@ function photos_content(App $a) { '$comment' => $comment )); - /// @TODO merge into one if() ? - if ($can_post || can_write_wall($a, $owner_uid)) { - if ($item['last-child']) { - $comments .= replace_macros($cmnt_tpl, array( - '$return_path' => '', - '$jsreload' => $return_url, - '$type' => 'wall-comment', - '$id' => $item['item_id'], - '$parent' => $item['parent'], - '$profile_uid' => $owner_uid, - '$mylink' => $contact['url'], - '$mytitle' => t('This is you'), - '$myphoto' => $contact['thumb'], - '$comment' => t('Comment'), - '$submit' => t('Submit'), - '$preview' => t('Preview'), - '$sourceapp' => t($a->sourcename), - '$ww' => '', - '$rand_num' => random_digits(12) - )); - } + if (($can_post || can_write_wall($a, $owner_uid)) && $item['last-child']) { + $comments .= replace_macros($cmnt_tpl, array( + '$return_path' => '', + '$jsreload' => $return_url, + '$type' => 'wall-comment', + '$id' => $item['item_id'], + '$parent' => $item['parent'], + '$profile_uid' => $owner_uid, + '$mylink' => $contact['url'], + '$mytitle' => t('This is you'), + '$myphoto' => $contact['thumb'], + '$comment' => t('Comment'), + '$submit' => t('Submit'), + '$preview' => t('Preview'), + '$sourceapp' => t($a->sourcename), + '$ww' => '', + '$rand_num' => random_digits(12) + )); } } } From 16415520e7e538bd8da3993f9b429b51d64fc5b2 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 30 Mar 2017 21:50:19 +0200 Subject: [PATCH 77/91] it is space-time! ;-) Signed-off-by: Roland Haeder --- boot.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boot.php b/boot.php index 3bf85b14f..b83f494dd 100644 --- a/boot.php +++ b/boot.php @@ -721,8 +721,8 @@ class App { } // Diaspora style profile url - if (substr($this->cmd,0,2) === 'u/') { - $this->cmd = 'profile/' . substr($this->cmd,2); + if (substr($this->cmd, 0, 2) === 'u/') { + $this->cmd = 'profile/' . substr($this->cmd, 2); } From 0bc15efef627d4e4fe1bc5c2b7ee9e697c3127ee Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 30 Mar 2017 21:51:31 +0200 Subject: [PATCH 78/91] whoops, parser error fixed Signed-off-by: Roland Haeder --- mod/item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/item.php b/mod/item.php index 1f8071998..c4508aca6 100644 --- a/mod/item.php +++ b/mod/item.php @@ -560,7 +560,7 @@ function item_post(App $a) { $toplevel_contact = '@[url='.$toplevel_parent[0]['author-link'].']'.$toplevel_parent[0]['author-name'].'[/url]'; } - if (!in_array($toplevel_contact, $tags)) [ + if (!in_array($toplevel_contact, $tags)) { $tags[] = $toplevel_contact; } } From 5db963a8356ac34b07f2471b24ecddbe0efc296f Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 31 Mar 2017 20:05:15 +0200 Subject: [PATCH 79/91] fixed parser error Signed-off-by: Roland Haeder --- boot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot.php b/boot.php index b83f494dd..f65829ed1 100644 --- a/boot.php +++ b/boot.php @@ -697,7 +697,7 @@ class App { $this->query_string = substr($_SERVER['QUERY_STRING'], 9); // removing trailing / - maybe a nginx problem - $this->query_string = lrim($this->query_string, '/'); + $this->query_string = ltrim($this->query_string, '/'); } elseif ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 2) === "q=") { $this->query_string = substr($_SERVER['QUERY_STRING'], 2); From d98ac6b42d29912a163db6ee0b6318c1e3d33a78 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 31 Mar 2017 20:30:21 +0200 Subject: [PATCH 80/91] Continued a bit: - removed parentheses from include/require as they are no functions - added type-hint for $a which is unused btw. Signed-off-by: Roland Haeder --- mod/item.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mod/item.php b/mod/item.php index c4508aca6..9e6b3283c 100644 --- a/mod/item.php +++ b/mod/item.php @@ -33,7 +33,7 @@ function item_post(App $a) { return; } - require_once('include/security.php'); + require_once 'include/security.php'; $uid = local_user(); @@ -142,7 +142,7 @@ function item_post(App $a) { $parent_contact = get_contact_details_by_url($thrparent[0]["author-link"]); if (!isset($parent_contact["nick"])) { - require_once("include/Scrape.php"); + require_once 'include/Scrape.php'; $probed_contact = probe_url($thrparent[0]["author-link"]); if ($probed_contact["network"] != NETWORK_FEED) { $parent_contact = $probed_contact; @@ -518,7 +518,7 @@ function item_post(App $a) { // Setting the object type if not defined before if (!$objecttype) { $objecttype = ACTIVITY_OBJ_NOTE; // Default value - require_once("include/plaintext.php"); + require_once 'include/plaintext.php'; $objectdata = get_attached_data($body); if ($post["type"] == "link") { @@ -730,7 +730,7 @@ function item_post(App $a) { // preview mode - prepare the body for display and send it via json if ($preview) { - require_once('include/conversation.php'); + require_once 'include/conversation.php'; // We set the datarray ID to -1 because in preview mode the dataray // doesn't have an ID. $datarray["id"] = -1; @@ -988,7 +988,7 @@ function item_post(App $a) { $link = '' . $a->user['username'] . '

'; $html = prepare_body($datarray); $message = '' . $link . $html . $disclaimer . ''; - include_once('include/html2plain.php'); + include_once 'include/html2plain.php'; $params = array ( 'fromName' => $a->user['username'], 'fromEmail' => $a->user['email'], @@ -1041,7 +1041,7 @@ function item_post_return($baseurl, $api_source, $return_path) { } $json = array('success' => 1); - if (x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload'])) { + if (x($_REQUEST, 'jsreload') && strlen($_REQUEST['jsreload'])) { $json['reload'] = $baseurl . '/' . $_REQUEST['jsreload']; } @@ -1059,7 +1059,7 @@ function item_content(App $a) { return; } - require_once('include/security.php'); + require_once 'include/security.php'; $o = ''; if (($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) { @@ -1087,9 +1087,9 @@ function item_content(App $a) { * * @return boolean true if replaced, false if not replaced */ -function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "") { - require_once("include/Scrape.php"); - require_once("include/socgraph.php"); +function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "") { + require_once 'include/Scrape.php'; + require_once 'include/socgraph.php'; $replaced = false; $r = null; @@ -1099,7 +1099,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo //is it already replaced? if (strpos($tag, '[url=')) { //append tag to str_tags - if (!stristr($str_tags,$tag)) { + if (!stristr($str_tags, $tag)) { if (strlen($str_tags)) { $str_tags .= ','; } From 6db3d72ee3710d310e8f745b3dac961afbebe371 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 31 Mar 2017 20:32:52 +0200 Subject: [PATCH 81/91] added spaces (space-time!) and TODO that x() is maybe proper way? Signed-off-by: Roland Haeder --- mod/item.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mod/item.php b/mod/item.php index 9e6b3283c..e7bae3495 100644 --- a/mod/item.php +++ b/mod/item.php @@ -264,12 +264,12 @@ function item_post(App $a) { * use the user default permissions - as they won't have * been supplied via a form. */ - + /// @TODO use x($_REQUEST, 'foo') here if (($api_source) - && (! array_key_exists('contact_allow',$_REQUEST)) - && (! array_key_exists('group_allow',$_REQUEST)) - && (! array_key_exists('contact_deny',$_REQUEST)) - && (! array_key_exists('group_deny',$_REQUEST))) { + && (! array_key_exists('contact_allow', $_REQUEST)) + && (! array_key_exists('group_allow', $_REQUEST)) + && (! array_key_exists('contact_deny', $_REQUEST)) + && (! array_key_exists('group_deny', $_REQUEST))) { $str_group_allow = $user['allow_gid']; $str_contact_allow = $user['allow_cid']; $str_group_deny = $user['deny_gid']; From 8824da8962396b89aa42c885242bc2b4852a8eba Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 31 Mar 2017 20:36:01 +0200 Subject: [PATCH 82/91] Continued a bit: - recommended way is to use foreach() instead of own looping through arrays - even when you need the index: $value) { // Handle $key/$value somehow } ?> Signed-off-by: Roland Haeder --- mod/item.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mod/item.php b/mod/item.php index e7bae3495..bcf7a4b46 100644 --- a/mod/item.php +++ b/mod/item.php @@ -513,7 +513,7 @@ function item_post(App $a) { // Fold multi-line [code] sequences $body = preg_replace('/\[\/code\]\s*\[code\]/ism', "\n", $body); - $body = scale_external_images($body,false); + $body = scale_external_images($body, false); // Setting the object type if not defined before if (!$objecttype) { @@ -545,7 +545,7 @@ function item_post(App $a) { $contact = '@[url=' . $parent_contact['url'] . ']' . $parent_contact['nick'] . '[/url]'; if (!in_array($contact,$tags)) { - $body = $contact.' '.$body; + $body = $contact . ' ' . $body; $tags[] = $contact; } @@ -557,7 +557,7 @@ function item_post(App $a) { $toplevel_contact = '@' . $toplevel_parent[0]['nick'] . '+' . $toplevel_parent[0]['id']; } else { $toplevel_parent = q("SELECT `author-link`, `author-name` FROM `item` WHERE `id` = `parent` AND `parent` = %d", intval($parent)); - $toplevel_contact = '@[url='.$toplevel_parent[0]['author-link'].']'.$toplevel_parent[0]['author-name'].'[/url]'; + $toplevel_contact = '@[url=' . $toplevel_parent[0]['author-link'] . ']' . $toplevel_parent[0]['author-name'] . '[/url]'; } if (!in_array($toplevel_contact, $tags)) { @@ -581,8 +581,8 @@ function item_post(App $a) { * Robert Johnson should be first in the $tags array */ $fullnametagged = false; - for ($x = 0; $x < count($tagged); $x ++) { - if (stristr($tagged[$x],$tag . ' ')) { + foreach ($tagged as $nextTag) { + if (stristr($nextTag, $tag . ' ')) { $fullnametagged = true; break; } From 8bdc906013461464b475c4f10918adff8730dea6 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 31 Mar 2017 20:41:32 +0200 Subject: [PATCH 83/91] Continued a bit: - added 'array' type-hint which is valid for many versions back - added spaces as requested by CR - removed $a = get_app(); call, $a was no longer needed here Signed-off-by: Roland Haeder --- include/items.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/include/items.php b/include/items.php index 24eb1b30f..c2b3d7d1f 100644 --- a/include/items.php +++ b/include/items.php @@ -1496,17 +1496,19 @@ function item_is_remote_self($contact, &$datarray) { return true; } -function new_follower($importer,$contact,$datarray,$item,$sharing = false) { +function new_follower($importer, $contact, $datarray, $item, $sharing = false) { $url = notags(trim($datarray['author-link'])); $name = notags(trim($datarray['author-name'])); $photo = notags(trim($datarray['author-avatar'])); if (is_object($item)) { $rawtag = $item->get_item_tags(NAMESPACE_ACTIVITY,'actor'); - if ($rawtag && $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']) + if ($rawtag && $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']) { $nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']; - } else + } + } else { $nick = $item; + } if (is_array($contact)) { if (($contact['network'] == NETWORK_OSTATUS && $contact['rel'] == CONTACT_IS_SHARING) @@ -1544,11 +1546,9 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { update_contact_avatar($photo, $importer["uid"], $contact_record["id"], true); } - $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($importer['uid']) ); - $a = get_app(); if (dbm::is_result($r) AND !in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) { @@ -1567,8 +1567,9 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { $def_gid = get_default_group($importer['uid'], $contact_record["network"]); - if (intval($def_gid)) - group_add_member($importer['uid'],'',$contact_record['id'],$def_gid); + if (intval($def_gid)) { + group_add_member($importer['uid'], '', $contact_record['id'], $def_gid); + } if (($r[0]['notify-flags'] & NOTIFY_INTRO) && in_array($r[0]['page-flags'], array(PAGE_NORMAL))) { @@ -1599,7 +1600,7 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) { } } -function lose_follower($importer,$contact,$datarray = array(),$item = "") { +function lose_follower($importer, $contact, array $datarray = array(), $item = "") { if (($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_SHARING)) { q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d", @@ -1611,7 +1612,7 @@ function lose_follower($importer,$contact,$datarray = array(),$item = "") { } } -function lose_sharer($importer,$contact,$datarray = array(),$item = "") { +function lose_sharer($importer, $contact, array $datarray = array(), $item = "") { if (($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_FOLLOWER)) { q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d", @@ -1623,7 +1624,7 @@ function lose_sharer($importer,$contact,$datarray = array(),$item = "") { } } -function subscribe_to_hub($url,$importer,$contact,$hubmode = 'subscribe') { +function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') { $a = get_app(); From eab654dd65ed8008891caa2f632649f2fcfba852 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 31 Mar 2017 20:44:38 +0200 Subject: [PATCH 84/91] $tagged is being initialized but not written to until the foreach() loop is being executed. Maybe here is old-lost code anyway? Signed-off-by: Roland Haeder --- mod/item.php | 1 + 1 file changed, 1 insertion(+) diff --git a/mod/item.php b/mod/item.php index bcf7a4b46..3c5fcd9ab 100644 --- a/mod/item.php +++ b/mod/item.php @@ -581,6 +581,7 @@ function item_post(App $a) { * Robert Johnson should be first in the $tags array */ $fullnametagged = false; + /// @TODO $tagged is initialized above if() block and is not filled, maybe old-lost code? foreach ($tagged as $nextTag) { if (stristr($nextTag, $tag . ' ')) { $fullnametagged = true; From 9cfcf8f7ca7a602591666ed2b87b205768a3d515 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 31 Mar 2017 20:47:23 +0200 Subject: [PATCH 85/91] added spaces, marked in todos.txt as usual Signed-off-by: Roland Haeder --- mod/item.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/mod/item.php b/mod/item.php index 3c5fcd9ab..34079fa9d 100644 --- a/mod/item.php +++ b/mod/item.php @@ -29,7 +29,7 @@ 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; } @@ -71,8 +71,8 @@ function item_post(App $a) { } // Is this a reply to something? - $parent = ((x($_REQUEST,'parent')) ? intval($_REQUEST['parent']) : 0); - $parent_uri = ((x($_REQUEST,'parent_uri')) ? trim($_REQUEST['parent_uri']) : ''); + $parent = ((x($_REQUEST, 'parent')) ? intval($_REQUEST['parent']) : 0); + $parent_uri = ((x($_REQUEST, 'parent_uri')) ? trim($_REQUEST['parent_uri']) : ''); $parent_item = null; $parent_contact = null; @@ -85,7 +85,7 @@ function item_post(App $a) { $objecttype = ACTIVITY_OBJ_COMMENT; - if (! x($_REQUEST,'type')) { + if (! x($_REQUEST, 'type')) { $_REQUEST['type'] = 'net-comment'; } @@ -114,7 +114,7 @@ function item_post(App $a) { if (! dbm::is_result($r)) { notice( t('Unable to locate original post.') . EOL); - if (x($_REQUEST,'return')) { + if (x($_REQUEST, 'return')) { goaway($return_path); } killme(); @@ -167,11 +167,11 @@ function item_post(App $a) { 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); - $app = ((x($_REQUEST,'source')) ? strip_tags($_REQUEST['source']) : ''); - $extid = ((x($_REQUEST,'extid')) ? strip_tags($_REQUEST['extid']) : ''); - $object = ((x($_REQUEST,'object')) ? $_REQUEST['object'] : ''); + $profile_uid = ((x($_REQUEST, 'profile_uid')) ? intval($_REQUEST['profile_uid']) : 0); + $post_id = ((x($_REQUEST, 'post_id')) ? intval($_REQUEST['post_id']) : 0); + $app = ((x($_REQUEST, 'source')) ? strip_tags($_REQUEST['source']) : ''); + $extid = ((x($_REQUEST, 'extid')) ? strip_tags($_REQUEST['extid']) : ''); + $object = ((x($_REQUEST, 'object')) ? $_REQUEST['object'] : ''); // Check for multiple posts with the same message id (when the post was created via API) if (($message_id != '') AND ($profile_uid != 0)) { @@ -648,7 +648,7 @@ function item_post(App $a) { // even if the post arrived via API we are considering that it // originated on this site by default for determining relayability. - $origin = ((x($_REQUEST,'origin')) ? intval($_REQUEST['origin']) : 1); + $origin = ((x($_REQUEST, 'origin')) ? intval($_REQUEST['origin']) : 1); $notify_type = (($parent) ? 'comment-new' : 'wall-new' ); @@ -750,7 +750,7 @@ function item_post(App $a) { } $json = array('cancel' => 1); - if (x($_REQUEST,'jsreload') && strlen($_REQUEST['jsreload'])) { + if (x($_REQUEST, 'jsreload') && strlen($_REQUEST['jsreload'])) { $json['reload'] = App::get_baseurl() . '/' . $_REQUEST['jsreload']; } @@ -784,7 +784,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); } From 07a0d300c34e46e12b4bcd6312797bdedeb8557b Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 31 Mar 2017 20:49:43 +0200 Subject: [PATCH 86/91] added space, marked rest 86 occurrences in todos.txt Signed-off-by: Roland Haeder --- mod/item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/item.php b/mod/item.php index 34079fa9d..7f0f48c05 100644 --- a/mod/item.php +++ b/mod/item.php @@ -977,7 +977,7 @@ function item_post(App $a) { 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']) + $disclaimer = '
' . sprintf( t('This message was sent to you by %s, a member of the Friendica social network.'), $a->user['username']) . '
'; $disclaimer .= sprintf( t('You may visit them online at %s'), App::get_baseurl() . '/profile/' . $a->user['nickname']) . EOL; $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL; From 44a137a8debb437e90813cd282142841c4edbf27 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 31 Mar 2017 20:51:18 +0200 Subject: [PATCH 87/91] Continued a bit: - converted multiple single-line comments into one multi-line comment - added spaces (space-time!) Signed-off-by: Roland Haeder --- mod/item.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mod/item.php b/mod/item.php index 7f0f48c05..677406be3 100644 --- a/mod/item.php +++ b/mod/item.php @@ -1201,9 +1201,9 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n } } else { $r = false; - if (strrpos($name,'+')) { + if (strrpos($name, '+')) { // Is it in format @nick+number? - $tagcid = intval(substr($name,strrpos($name,'+') + 1)); + $tagcid = intval(substr($name, strrpos($name, '+') + 1)); $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($tagcid), @@ -1276,18 +1276,20 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n $newtag = '@[url='.$profile.']'.$newname.'[/url]'; $body = str_replace('@'.$name, $newtag, $body); // append tag to str_tags - if (! stristr($str_tags,$newtag)) { + 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. + /* + * 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)) { - $newtag = '@[url='.$alias.']'.$newname.'[/url]'; - if (! stristr($str_tags,$newtag)) { + $newtag = '@[url=' . $alias . ']' . $newname . '[/url]'; + if (! stristr($str_tags, $newtag)) { if (strlen($str_tags)) { $str_tags .= ','; } From 18ca141f5c56f962b4fb228c99871b2b831aa189 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 31 Mar 2017 20:52:32 +0200 Subject: [PATCH 88/91] space-time! Signed-off-by: Roland Haeder --- mod/item.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mod/item.php b/mod/item.php index 677406be3..79633cdc1 100644 --- a/mod/item.php +++ b/mod/item.php @@ -1272,9 +1272,9 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n $replaced = true; // create profile link - $profile = str_replace(',','%2c',$profile); - $newtag = '@[url='.$profile.']'.$newname.'[/url]'; - $body = str_replace('@'.$name, $newtag, $body); + $profile = str_replace(',', '%2c', $profile); + $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)) { From d4e67338d8b60a0e2cced92e22ec930a2cdb360f Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 31 Mar 2017 20:55:50 +0200 Subject: [PATCH 89/91] space-time contines ... Signed-off-by: Roland Haeder --- mod/photos.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index 0f021d55a..32665c818 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1098,7 +1098,7 @@ function photos_content(App $a) { // tabs $is_owner = (local_user() && (local_user() == $owner_uid)); - $o .= profile_tabs($a,$is_owner, $a->data['user']['nickname']); + $o .= profile_tabs($a, $is_owner, $a->data['user']['nickname']); /** * Display upload form @@ -1616,8 +1616,8 @@ function photos_content(App $a) { $likebuttons = ''; - if ($can_post || can_write_wall($a,$owner_uid)) { - $likebuttons = replace_macros($like_tpl,array( + if ($can_post || can_write_wall($a, $owner_uid)) { + $likebuttons = replace_macros($like_tpl, array( '$id' => $link_item['id'], '$likethis' => t("I like this \x28toggle\x29"), '$nolike' => (feature_enabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''), @@ -1628,8 +1628,8 @@ function photos_content(App $a) { $comments = ''; if (! dbm::is_result($r)) { - if (($can_post || can_write_wall($a,$owner_uid)) && $link_item['last-child']) { - $comments .= replace_macros($cmnt_tpl,array( + if (($can_post || can_write_wall($a, $owner_uid)) && $link_item['last-child']) { + $comments .= replace_macros($cmnt_tpl, array( '$return_path' => '', '$jsreload' => $return_url, '$type' => 'wall-comment', @@ -1777,9 +1777,10 @@ function photos_content(App $a) { $response_verbs = array('like'); - if (feature_enabled($owner_uid,'dislike')) + if (feature_enabled($owner_uid, 'dislike')) { $response_verbs[] = 'dislike'; - $responses = get_responses($conv_responses,$response_verbs,'',$link_item); + } + $responses = get_responses($conv_responses,$response_verbs, '', $link_item); $photo_tpl = get_markup_template('photo_view.tpl'); @@ -1789,7 +1790,7 @@ function photos_content(App $a) { $like_e = template_escape($like); $dislike_e = template_escape($dislike); } else { - $album_e = array($album_link,$ph[0]['album']); + $album_e = array($album_link, $ph[0]['album']); $tags_e = $tags; $like_e = $like; $dislike_e = $dislike; @@ -1816,11 +1817,11 @@ function photos_content(App $a) { '$paginate' => $paginate, )); - $a->page['htmlhead'] .= "\n".''."\n"; - $a->page['htmlhead'] .= ''."\n"; - $a->page['htmlhead'] .= ''."\n"; - $a->page['htmlhead'] .= ''."\n"; - $a->page['htmlhead'] .= ''."\n"; + $a->page['htmlhead'] .= "\n" . '' . "\n"; + $a->page['htmlhead'] .= '' . "\n"; + $a->page['htmlhead'] .= '' . "\n"; + $a->page['htmlhead'] .= '' . "\n"; + $a->page['htmlhead'] .= '' . "\n"; return $o; } From 60552260e1ea446e097ba2e6b7a4d7cec6fcd33b Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 31 Mar 2017 21:04:08 +0200 Subject: [PATCH 90/91] Continued with CR: - added spaces as requested - removed parentheses from include/require calls as they are no functions Signed-off-by: Roland Haeder --- mod/photos.php | 4 ++-- view/theme/vier/theme.php | 48 +++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/mod/photos.php b/mod/photos.php index 32665c818..ddf081467 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1667,8 +1667,8 @@ function photos_content(App $a) { builtin_activity_puller($item, $conv_responses); } - $like = ((x($conv_responses['like'],$link_item['uri'])) ? format_like($conv_responses['like'][$link_item['uri']],$conv_responses['like'][$link_item['uri'] . '-l'], 'like',$link_item['id']) : ''); - $dislike = ((x($conv_responses['dislike'],$link_item['uri'])) ? format_like($conv_responses['dislike'][$link_item['uri']],$conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike',$link_item['id']) : ''); + $like = ((x($conv_responses['like'], $link_item['uri'])) ? format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like',$link_item['id']) : ''); + $dislike = ((x($conv_responses['dislike'], $link_item['uri'])) ? format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike',$link_item['id']) : ''); if (($can_post || can_write_wall($a, $owner_uid)) && $link_item['last-child']) { $comments .= replace_macros($cmnt_tpl,array( diff --git a/view/theme/vier/theme.php b/view/theme/vier/theme.php index 50e8cd377..a42dfe6e1 100644 --- a/view/theme/vier/theme.php +++ b/view/theme/vier/theme.php @@ -9,9 +9,9 @@ * Description: "Vier" is a very compact and modern theme. It uses the font awesome font library: http://fortawesome.github.com/Font-Awesome/ */ -require_once("include/plugin.php"); -require_once("include/socgraph.php"); -require_once("mod/proxy.php"); +require_once "include/plugin.php"; +require_once "include/socgraph.php"; +require_once "mod/proxy.php"; function vier_init(App $a) { @@ -101,8 +101,9 @@ EOT; } // Hide the left menu bar + /// @TODO maybe move this static array out where it should belong? if (($a->page['aside'] == "") AND in_array($a->argv[0], array("community", "events", "help", "manage", "notifications", - "probe", "webfinger", "login", "invite", "credits"))) { + "probe", "webfinger", "login", "invite", "credits"))) { $a->page['htmlhead'] .= ""; } } @@ -110,13 +111,15 @@ EOT; function get_vier_config($key, $default = false, $admin = false) { if (local_user() AND !$admin) { $result = get_pconfig(local_user(), "vier", $key); - if ($result !== false) + if ($result !== false) { return $result; + } } $result = get_config("vier", $key); - if ($result !== false) + if ($result !== false) { return $result; + } return $default; } @@ -131,7 +134,7 @@ function vier_community_info() { $show_friends = get_vier_config("show_friends", 1); $show_lastusers = get_vier_config("show_lastusers", 1); - //get_baseurl + // get_baseurl $url = App::get_baseurl($ssl_state); $aside['$url'] = $url; @@ -161,7 +164,7 @@ function vier_community_info() { // last 9 users if ($show_lastusers) { - $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 "); + $publish = (get_config('system', 'publish_all') ? '' : " AND `publish` = 1 "); $order = " ORDER BY `register_date` DESC "; $tpl = get_markup_template('ch_directory_item.tpl'); @@ -191,12 +194,12 @@ function vier_community_info() { //right_aside FIND FRIENDS if ($show_friends AND local_user()) { $nv = array(); - $nv['title'] = Array("", t('Find Friends'), "", ""); - $nv['directory'] = Array('directory', t('Local Directory'), "", ""); + $nv['title'] = array("", t('Find Friends'), "", ""); + $nv['directory'] = array('directory', t('Local Directory'), "", ""); $nv['global_directory'] = Array(get_server(), t('Global Directory'), "", ""); - $nv['match'] = Array('match', t('Similar Interests'), "", ""); - $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", ""); - $nv['invite'] = Array('invite', t('Invite Friends'), "", ""); + $nv['match'] = array('match', t('Similar Interests'), "", ""); + $nv['suggest'] = array('suggest', t('Friend Suggestions'), "", ""); + $nv['invite'] = array('invite', t('Invite Friends'), "", ""); $nv['search'] = '
@@ -211,7 +214,7 @@ function vier_community_info() { //Community_Pages at right_aside if ($show_pages AND local_user()) { - require_once('include/ForumManager.php'); + require_once 'include/ForumManager.php'; if (x($_GET, 'cid') && intval($_GET['cid']) != 0) { $cid = $_GET['cid']; @@ -247,7 +250,7 @@ function vier_community_info() { $tpl = get_markup_template('widget_forumlist_right.tpl'); - $page .= replace_macros($tpl,array( + $page .= replace_macros($tpl, array( '$title' => t('Forums'), '$forums' => $entries, '$link_desc' => t('External link to forum'), @@ -259,9 +262,9 @@ function vier_community_info() { $aside['$page'] = $page; } } - //END Community Page + // END Community Page - //helpers + // helpers if ($show_helpers) { $r = array(); @@ -284,14 +287,14 @@ function vier_community_info() { foreach ($r AS $index => $helper) $r[$index]["url"] = zrl($helper["url"]); - $r[] = Array("url" => "help/Quick-Start-guide", "name" => t("Quick Start")); + $r[] = array("url" => "help/Quick-Start-guide", "name" => t("Quick Start")); $tpl = get_markup_template('ch_helpers.tpl'); if ($r) { $helpers = array(); - $helpers['title'] = Array("", t('Help'), "", ""); + $helpers['title'] = array("", t('Help'), "", ""); $aside['$helpers_items'] = array(); @@ -306,9 +309,9 @@ function vier_community_info() { $aside['$helpers'] = $helpers; } } - //end helpers + // end helpers - //connectable services + // connectable services if ($show_services) { /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo) @@ -346,6 +349,7 @@ function vier_community_info() { $r[] = array("photo" => "images/googleplus.png", "name" => "Google+"); } + /// @TODO old-lost code (and below)? //if (plugin_enabled("ijpost")) { // $r[] = array("photo" => "images/", "name" => ""); //} @@ -383,7 +387,7 @@ function vier_community_info() { if (dbm::is_result($r)) { $con_services = array(); - $con_services['title'] = Array("", t('Connect Services'), "", ""); + $con_services['title'] = array("", t('Connect Services'), "", ""); $aside['$con_services'] = $con_services; foreach ($r as $rr) { From 3cea176ef238c8d30b0fd74ca86bb73bb00d8bc5 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 1 Apr 2017 21:46:57 +0200 Subject: [PATCH 91/91] added spaces + used x () Signed-off-by: Roland Haeder --- boot.php | 2 +- mod/item.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/boot.php b/boot.php index f65829ed1..5f65572d5 100644 --- a/boot.php +++ b/boot.php @@ -1450,7 +1450,7 @@ function get_app() { */ function x($s,$k = NULL) { if ($k != NULL) { - if ((is_array($s)) && (array_key_exists($k,$s))) { + if ((is_array($s)) && (array_key_exists($k, $s))) { if ($s[$k]) { return (int) 1; } diff --git a/mod/item.php b/mod/item.php index 79633cdc1..8bf922d97 100644 --- a/mod/item.php +++ b/mod/item.php @@ -325,8 +325,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)) { - $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1); + $mail_disabled = ((function_exists('imap_open') && (! get_config('system', 'imap_disabled'))) ? 0 : 1); if (! $mail_disabled) { + /// @TODO Check if only pubmail is loaded, * loads all columns $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user()) ); @@ -372,7 +373,7 @@ function item_post(App $a) { $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($_SESSION['uid'])); } elseif(remote_user()) { - if (is_array($_SESSION['remote'])) { + if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) { foreach ($_SESSION['remote'] as $v) { if ($v['uid'] == $profile_uid) { $contact_id = $v['cid']; @@ -544,7 +545,7 @@ function item_post(App $a) { if ($parent AND ($parent_contact['network'] == NETWORK_OSTATUS)) { $contact = '@[url=' . $parent_contact['url'] . ']' . $parent_contact['nick'] . '[/url]'; - if (!in_array($contact,$tags)) { + if (!in_array($contact, $tags)) { $body = $contact . ' ' . $body; $tags[] = $contact; }