From f66cb9b0a3f46b481a8fc99559fd7f6f074254da 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 1/9] 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 --- src/Protocol/DFRN.php | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index b66e1d5bfa..913097d1d3 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -63,7 +63,7 @@ class DFRN * @param array $owner Owner record * * @return string DFRN entries - * @todo Add type-hints + * @todo Find proper type-hints */ public static function entries($items, $owner) { @@ -96,6 +96,7 @@ class DFRN * @param boolean $onlyheader Output only the header without content? (Default is "no") * * @return string DFRN feed entries + * @todo Find proper type-hints */ public static function feed($dfrn_id, $owner_nick, $last_update, $direction = 0, $onlyheader = false) { @@ -120,8 +121,6 @@ class DFRN } } - - // default permissions - anonymous user $sql_extra = " AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' "; @@ -134,6 +133,8 @@ class DFRN ); if (! DBM::is_result($r)) { + if (! dbm::is_result($r)) { + logger(sprintf('No contact found for nickname=%d', $owner_nick), LOGGER_WARNING); killme(); } @@ -169,6 +170,7 @@ class DFRN ); if (! DBM::is_result($r)) { + logger(sprintf('No contact found for uid=%d', $owner_id), LOGGER_WARNING); killme(); } @@ -177,8 +179,9 @@ class DFRN $groups = Group::getIdsByContactId($contact['id']); if (count($groups)) { - for ($x = 0; $x < count($groups); $x ++) + for ($x = 0; $x < count($groups); $x ++) { $groups[$x] = '<' . intval($groups[$x]) . '>' ; + } $gs = implode('|', $groups); } else { $gs = '<<>>' ; // Impossible to match @@ -397,7 +400,7 @@ class DFRN * @param array $owner Owner record * * @return string DFRN mail - * @todo Add type-hints + * @todo Find proper type-hints */ public static function mail($item, $owner) { @@ -433,7 +436,7 @@ class DFRN * @param array $owner Owner record * * @return string DFRN suggestions - * @todo Add type-hints + * @todo Find proper type-hints */ public static function fsuggest($item, $owner) { @@ -462,7 +465,7 @@ class DFRN * @param int $uid User ID * * @return string DFRN relocations - * @todo Add type-hints + * @todo Find proper type-hints */ public static function relocate($owner, $uid) { @@ -524,7 +527,7 @@ class DFRN * @param bool $public Is it a header for public posts? * * @return object XML root object - * @todo Add type-hints + * @todo Find proper type-hints */ private static function addHeader($doc, $owner, $authorelement, $alternatelink = "", $public = false) { @@ -600,7 +603,7 @@ class DFRN * @param boolean $public boolean * * @return object XML author object - * @todo Add type-hints + * @todo Find proper type-hints */ private static function addAuthor($doc, $owner, $authorelement, $public) { @@ -744,7 +747,7 @@ class DFRN * @param array $item Item elements * * @return object XML author object - * @todo Add type-hints + * @todo Find proper type-hints */ private static function addEntryAuthor($doc, $element, $contact_url, $item) { @@ -785,7 +788,7 @@ class DFRN * @param string $activity activity value * * @return object XML activity object - * @todo Add type-hints + * @todo Find proper type-hints */ private static function createActivity($doc, $element, $activity) { @@ -796,12 +799,15 @@ class DFRN if (!$r) { return false; } + if ($r->type) { XML::addElement($doc, $entry, "activity:object-type", $r->type); } + if ($r->id) { XML::addElement($doc, $entry, "id", $r->id); } + if ($r->title) { XML::addElement($doc, $entry, "title", $r->title); } @@ -848,7 +854,7 @@ class DFRN * @param array $item Item element * * @return object XML attachment object - * @todo Add type-hints + * @todo Find proper type-hints */ private static function getAttachment($doc, $root, $item) { @@ -888,7 +894,7 @@ class DFRN * @param bool $single If set, the entry is created as an XML document with a single "entry" element * * @return object XML entry object - * @todo Add type-hints + * @todo Find proper type-hints */ private static function entry($doc, $type, $item, $owner, $comment = false, $cid = 0, $single = false) { @@ -1289,7 +1295,6 @@ class DFRN $postvars['dissolve'] = '1'; } - if ((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) { $postvars['data'] = $atom; $postvars['perm'] = 'rw'; From cf9fa51f2f12d969f3c45c22649268b70d2cf7dd 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 2/9] 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 --- src/Protocol/DFRN.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 913097d1d3..c464c14c2a 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -1581,7 +1581,7 @@ class DFRN $href = ""; $width = 0; foreach ($avatar->attributes as $attributes) { - /// @TODO Rewrite these similar if () to one switch + /// @TODO Rewrite these similar if() to one switch if ($attributes->name == "href") { $href = $attributes->textContent; } @@ -2801,6 +2801,7 @@ class DFRN { logger("Processing deletions"); $uri = null; + foreach ($deletion->attributes as $attributes) { if ($attributes->name == "ref") { $uri = $attributes->textContent; From 5debcbb5a6c7d82b5429e411e1fc3ecfce191f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 26 Jan 2017 15:23:30 +0100 Subject: [PATCH 3/9] added spaces + some curly braces + some usage of dbm::is_result() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/_well_known.php | 5 +++-- mod/admin.php | 1 + mod/events.php | 1 + mod/poco.php | 2 +- mod/share.php | 17 +++++++++-------- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/mod/_well_known.php b/mod/_well_known.php index 782dc7a1b1..89097c0ff0 100644 --- a/mod/_well_known.php +++ b/mod/_well_known.php @@ -43,7 +43,8 @@ function wk_social_relay() $tags = []; if ($scope == SR_SCOPE_TAGS) { - $server_tags = Config::get('system', 'relay_server_tags'); + + $server_tags = get_config('system', 'relay_server_tags'); $tagitems = explode(",", $server_tags); /// @todo Check if it was better to use "strtolower" on the tags @@ -52,7 +53,7 @@ function wk_social_relay() $tags[$tag] = $tag; } - if (Config::get('system', 'relay_user_tags')) { + if (get_config('system', 'relay_user_tags')) { $terms = q("SELECT DISTINCT(`term`) FROM `search`"); foreach ($terms AS $term) { diff --git a/mod/admin.php b/mod/admin.php index 1447dbaf18..39416dae54 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -2162,6 +2162,7 @@ function admin_page_themes(App $a) } $readme = null; + if (is_file("view/theme/$theme/README.md")) { $readme = Markdown::convert(file_get_contents("view/theme/$theme/README.md"), false); } elseif (is_file("view/theme/$theme/README")) { diff --git a/mod/events.php b/mod/events.php index cad440f164..bbd6337c37 100644 --- a/mod/events.php +++ b/mod/events.php @@ -433,6 +433,7 @@ function events_content(App $a) { if (x($_REQUEST, 'location')) {$orig_event['location'] = $_REQUEST['location'];} if (x($_REQUEST, 'start')) {$orig_event['start'] = $_REQUEST['start'];} if (x($_REQUEST, 'finish')) {$orig_event['finish'] = $_REQUEST['finish'];} + if (x($_REQUEST,'finish')) $orig_event['finish'] = $_REQUEST['finish']; $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : ''); $a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : ''); diff --git a/mod/poco.php b/mod/poco.php index 0728020ecc..183d7acd12 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -43,8 +43,8 @@ function poco_init(App $a) { echo json_encode($ret); killme(); } + if ($a->argc > 1 && $a->argv[1] === '@global') { - // List of all profiles that this server recently had data from $global = true; $update_limit = date(DateTimeFormat::MYSQL, time() - 30 * 86400); } diff --git a/mod/share.php b/mod/share.php index f67dd3d200..ed9b5f9d17 100644 --- a/mod/share.php +++ b/mod/share.php @@ -23,10 +23,11 @@ function share_init(App $a) { } else { $o = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']); - if ($r[0]['title']) + if ($r[0]['title']) { $o .= '[b]'.$r[0]['title'].'[/b]'."\n"; + } $o .= $r[0]['body']; - $o.= "[/share]"; + $o .= "[/share]"; } echo $o; @@ -34,17 +35,17 @@ function share_init(App $a) { } function share_header($author, $profile, $avatar, $guid, $posted, $link) { - $header = "[share author='".str_replace(["'", "[", "]"], ["'", "[", "]"], $author). - "' profile='".str_replace(["'", "[", "]"], ["'", "[", "]"], $profile). - "' avatar='".str_replace(["'", "[", "]"], ["'", "[", "]"], $avatar); + $header = "[share author='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $author). + "' profile='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $profile). + "' avatar='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $avatar); if ($guid) { - $header .= "' guid='".str_replace(["'", "[", "]"], ["'", "[", "]"], $guid); + $header .= "' guid='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $guid); } if ($posted) { - $header .= "' posted='".str_replace(["'", "[", "]"], ["'", "[", "]"], $posted); + $header .= "' posted='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $posted); } - $header .= "' link='".str_replace(["'", "[", "]"], ["'", "[", "]"], $link)."']"; + $header .= "' link='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $link)."']"; return $header; } From 3191fee76362b0fe9b5b188e9ef8bcd73a5f8a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Sun, 13 May 2018 10:02:47 +0200 Subject: [PATCH 4/9] Ops, one to much ... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- src/Protocol/DFRN.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index c464c14c2a..5a0151c1ca 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -132,7 +132,6 @@ class DFRN dbesc($owner_nick) ); - if (! DBM::is_result($r)) { if (! dbm::is_result($r)) { logger(sprintf('No contact found for nickname=%d', $owner_nick), LOGGER_WARNING); killme(); From 594f946ad68cc0ab8a9a18c6778298c9976318cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Sun, 13 May 2018 10:04:49 +0200 Subject: [PATCH 5/9] No extra empty line here MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/_well_known.php | 1 - 1 file changed, 1 deletion(-) diff --git a/mod/_well_known.php b/mod/_well_known.php index 89097c0ff0..4f247abef8 100644 --- a/mod/_well_known.php +++ b/mod/_well_known.php @@ -43,7 +43,6 @@ function wk_social_relay() $tags = []; if ($scope == SR_SCOPE_TAGS) { - $server_tags = get_config('system', 'relay_server_tags'); $tagitems = explode(",", $server_tags); From 8d9547777e3c4a37405c4a11f8aad1b63b514ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Sun, 13 May 2018 10:05:31 +0200 Subject: [PATCH 6/9] Ops, was redundant here. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/events.php | 1 - 1 file changed, 1 deletion(-) diff --git a/mod/events.php b/mod/events.php index bbd6337c37..cad440f164 100644 --- a/mod/events.php +++ b/mod/events.php @@ -433,7 +433,6 @@ function events_content(App $a) { if (x($_REQUEST, 'location')) {$orig_event['location'] = $_REQUEST['location'];} if (x($_REQUEST, 'start')) {$orig_event['start'] = $_REQUEST['start'];} if (x($_REQUEST, 'finish')) {$orig_event['finish'] = $_REQUEST['finish'];} - if (x($_REQUEST,'finish')) $orig_event['finish'] = $_REQUEST['finish']; $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : ''); $a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : ''); From 445cc1cb99b244482141723c724f769c37cca32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Sun, 13 May 2018 10:06:43 +0200 Subject: [PATCH 7/9] Fixes: - brought back comment (ops) - DBM is the class name (not dbm) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/poco.php | 1 + src/Protocol/DFRN.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mod/poco.php b/mod/poco.php index 183d7acd12..671551f832 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -45,6 +45,7 @@ function poco_init(App $a) { } if ($a->argc > 1 && $a->argv[1] === '@global') { + // List of all profiles that this server recently had data from $global = true; $update_limit = date(DateTimeFormat::MYSQL, time() - 30 * 86400); } diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 5a0151c1ca..0f9cbeafab 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -132,7 +132,7 @@ class DFRN dbesc($owner_nick) ); - if (! dbm::is_result($r)) { + if (! DBM::is_result($r)) { logger(sprintf('No contact found for nickname=%d', $owner_nick), LOGGER_WARNING); killme(); } From 87dbe0352142200330b4414f292efe4658c5fb18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Sun, 13 May 2018 10:20:15 +0200 Subject: [PATCH 8/9] reverted back ... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/_well_known.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/_well_known.php b/mod/_well_known.php index 4f247abef8..782dc7a1b1 100644 --- a/mod/_well_known.php +++ b/mod/_well_known.php @@ -43,7 +43,7 @@ function wk_social_relay() $tags = []; if ($scope == SR_SCOPE_TAGS) { - $server_tags = get_config('system', 'relay_server_tags'); + $server_tags = Config::get('system', 'relay_server_tags'); $tagitems = explode(",", $server_tags); /// @todo Check if it was better to use "strtolower" on the tags @@ -52,7 +52,7 @@ function wk_social_relay() $tags[$tag] = $tag; } - if (get_config('system', 'relay_user_tags')) { + if (Config::get('system', 'relay_user_tags')) { $terms = q("SELECT DISTINCT(`term`) FROM `search`"); foreach ($terms AS $term) { From 99440f3c56d1a87aa5aa357d68e371c726f6ba0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Sun, 13 May 2018 14:20:15 +0200 Subject: [PATCH 9/9] Beatification: - added space after curly braces (MrPetovan) - added TODO for possible rewrite candidate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- mod/share.php | 7 +++++++ src/Protocol/DFRN.php | 1 + 2 files changed, 8 insertions(+) diff --git a/mod/share.php b/mod/share.php index ed9b5f9d17..555273443c 100644 --- a/mod/share.php +++ b/mod/share.php @@ -5,6 +5,7 @@ use Friendica\Database\DBM; function share_init(App $a) { $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); + if (!$post_id || !local_user()) { killme(); } @@ -14,9 +15,11 @@ function share_init(App $a) { WHERE `item`.`id` = %d LIMIT 1", intval($post_id) ); + if (!DBM::is_result($r) || ($r[0]['private'] == 1)) { killme(); } + if (strpos($r[0]['body'], "[/share]") !== false) { $pos = strpos($r[0]['body'], "[share"); $o = substr($r[0]['body'], $pos); @@ -26,6 +29,7 @@ function share_init(App $a) { if ($r[0]['title']) { $o .= '[b]'.$r[0]['title'].'[/b]'."\n"; } + $o .= $r[0]['body']; $o .= "[/share]"; } @@ -34,6 +38,7 @@ function share_init(App $a) { killme(); } +/// @TODO Rewrite to handle over whole record array function share_header($author, $profile, $avatar, $guid, $posted, $link) { $header = "[share author='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $author). "' profile='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $profile). @@ -42,9 +47,11 @@ function share_header($author, $profile, $avatar, $guid, $posted, $link) { if ($guid) { $header .= "' guid='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $guid); } + if ($posted) { $header .= "' posted='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $posted); } + $header .= "' link='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $link)."']"; return $header; diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 0f9cbeafab..00bb91f8de 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -181,6 +181,7 @@ class DFRN for ($x = 0; $x < count($groups); $x ++) { $groups[$x] = '<' . intval($groups[$x]) . '>' ; } + $gs = implode('|', $groups); } else { $gs = '<<>>' ; // Impossible to match