]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #3528 from Hypolite/task/replace-explicit-php-logical-operators
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Fri, 9 Jun 2017 05:44:19 +0000 (07:44 +0200)
committerGitHub <noreply@github.com>
Fri, 9 Jun 2017 05:44:19 +0000 (07:44 +0200)
Replace explicit php logical operators

1  2 
include/acl_selectors.php
include/dfrn.php
mod/display.php

index ee5ad7fcc85cbc32d3619c45335ed05d94a3771e,665ed17bdf4e3be8a8bfdd8991ce9602aa6d7130..6f08523ca97dffded9ea03eb61229859667e9e45
@@@ -209,7 -209,7 +209,7 @@@ function contact_select($selname, $selc
  
        $tabindex = ($tabindex > 0 ? "tabindex=\"$tabindex\"" : "");
  
-       if ($privmail AND $preselected) {
+       if ($privmail && $preselected) {
                $sql_extra .= " AND `id` IN (".implode(",", $preselected).")";
                $hidepreselected = ' style="display: none;"';
        } else {
  
        $o .= "</select>\r\n";
  
-       if ($privmail AND $preselected) {
+       if ($privmail && $preselected) {
                $o .= implode(", ", $receiverlist);
        }
  
@@@ -388,9 -388,6 +388,9 @@@ function populate_acl($user = null, $sh
  }
  
  function construct_acl_data(App $a, $user) {
 +      // This function is now deactivated. It seems as if the generated data isn't used anywhere.
 +      /// @todo Remove this function and all function calls before releasing Friendica 3.5.3
 +      return;
  
        // Get group and contact information for html ACL selector
        $acl_data = acl_lookup($a, 'html');
diff --combined include/dfrn.php
index a8f7644ff7dbf955b2c1b50237b1d8457bcaebcc,1b97f39a2d939b404c273eb6759f07ac4f84e552..bc62de6ed9e60333262a48917b4b5a4cb550ac87
@@@ -245,7 -245,7 +245,7 @@@ class dfrn 
                /// @TODO This hook can't work anymore
                //      call_hooks('atom_feed', $atom);
  
-               if (!dbm::is_result($items) OR $onlyheader) {
+               if (!dbm::is_result($items) || $onlyheader) {
                        $atom = trim($doc->saveXML());
  
                        call_hooks('atom_feed_end', $atom);
                return $atom;
        }
  
 +      /**
 +       * @brief Generate an atom entry for a given item id
 +       *
 +       * @param int $item_id The item id
 +       *
 +       * @return string DFRN feed entry
 +       */
 +      public static function itemFeed($item_id) {
 +              $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
 +                      `contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`,
 +                      `contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
 +                      `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
 +                      `sign`.`signed_text`, `sign`.`signature`, `sign`.`signer`
 +                      FROM `item`
 +                      STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
 +                              AND (NOT `contact`.`blocked` OR `contact`.`pending`)
 +                      LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
 +                      WHERE `item`.`id` = %d AND `item`.`visible` AND NOT `item`.`moderated` AND `item`.`parent` != 0
 +                      AND `item`.`wall` AND NOT `item`.`private`",
 +                      intval($item_id)
 +              );
 +
 +              if (!dbm::is_result($r)) {
 +                      killme();
 +              }
 +
 +              $item = $r[0];
 +
 +              $r = q("SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`, `user`.`account-type`
 +                      FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
 +                      WHERE `contact`.`self` AND `user`.`uid` = %d LIMIT 1",
 +                      intval($item['uid'])
 +              );
 +
 +              if (!dbm::is_result($r)) {
 +                      killme();
 +              }
 +
 +              $owner = $r[0];
 +
 +              $doc = new DOMDocument('1.0', 'utf-8');
 +              $doc->formatOutput = true;
 +
 +              $alternatelink = $owner['url'];
 +
 +              $root = self::add_header($doc, $owner, 'dfrn:owner', $alternatelink, true);
 +
 +              $type = 'html';
 +
 +              $entry = self::entry($doc, $type, $item, $owner, true);
 +              $root->appendChild($entry);
 +
 +              $atom = trim($doc->saveXML());
 +              return $atom;
 +      }
 +
        /**
         * @brief Create XML text for DFRN mails
         *
  
                $attributes = array();
  
-               if (!$public OR !$hidewall) {
+               if (!$public || !$hidewall) {
                        $attributes = array("dfrn:updated" => $namdate);
                }
  
                $attributes = array("rel" => "photo", "type" => "image/jpeg",
                                        "media:width" => 175, "media:height" => 175, "href" => $owner['photo']);
  
-               if (!$public OR !$hidewall) {
+               if (!$public || !$hidewall) {
                        $attributes["dfrn:updated"] = $picdate;
                }
  
  
                if (count($tags)) {
                        foreach ($tags as $t) {
-                               if (($type != 'html') OR ($t[0] != "@")) {
+                               if (($type != 'html') || ($t[0] != "@")) {
                                        xml::add_element($doc, $entry, "category", "", array("scheme" => "X-DFRN:".$t[0].":".$t[1], "term" => $t[2]));
                                }
                        }
                                intval($owner["uid"]),
                                dbesc(normalise_link($mention)));
  
-                       if (dbm::is_result($r) AND ($r[0]["forum"] OR $r[0]["prv"])) {
+                       if (dbm::is_result($r) && ($r[0]["forum"] || $r[0]["prv"])) {
                                xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned",
                                                                                        "ostatus:object-type" => ACTIVITY_OBJ_GROUP,
                                                                                        "href" => $mention));
                                        $contact["avatar-date"] = $attributes->textContent;
                                }
                        }
-                       if (($width > 0) AND ($href != "")) {
+                       if (($width > 0) && ($href != "")) {
                                $avatarlist[$width] = $href;
                        }
                }
                        $author["avatar"] = current($avatarlist);
                }
  
-               if (dbm::is_result($r) AND !$onlyfetch) {
+               if (dbm::is_result($r) && !$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"]);
                $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"] == "") && ($relocate["photo"] != "")) {
                        $relocate["avatar"] = $relocate["photo"];
                }
  
                }
  
                // update last-child if it changes
-               if ($item["last-child"] AND ($item["last-child"] != $current["last-child"])) {
+               if ($item["last-child"] && ($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"]),
                                        $title = $attributes->textContent;
                                }
                        }
-                       if (($rel != "") AND ($href != "")) {
+                       if (($rel != "") && ($href != "")) {
                                switch ($rel) {
                                        case "alternate":
                                                $item["plink"] = $href;
                );
  
                // Is there an existing item?
-               if (dbm::is_result($current) AND edited_timestamp_is_newer($current[0], $item) AND
+               if (dbm::is_result($current) && edited_timestamp_is_newer($current[0], $item) &&
                        (datetime_convert("UTC","UTC",$item["edited"]) < $current[0]["edited"])) {
                        logger("Item ".$item["uri"]." already existed.", LOGGER_DEBUG);
                        return;
                }
  
                $notice_info = $xpath->query("statusnet:notice_info", $entry);
-               if ($notice_info AND ($notice_info->length > 0)) {
+               if ($notice_info && ($notice_info->length > 0)) {
                        foreach ($notice_info->item(0)->attributes AS $attributes) {
                                if ($attributes->name == "source") {
                                        $item["app"] = strip_tags($attributes->textContent);
                                        }
                                }
  
-                               if (($term != "") AND ($scheme != "")) {
+                               if (($term != "") && ($scheme != "")) {
                                        $parts = explode(":", $scheme);
-                                       if ((count($parts) >= 4) AND (array_shift($parts) == "X-DFRN")) {
+                                       if ((count($parts) >= 4) && (array_shift($parts) == "X-DFRN")) {
                                                $termhash = array_shift($parts);
                                                $termurl = implode(":", $parts);
  
                                $item["contact-id"] = $owner["contact-id"];
                        }
  
-                       if (($item["network"] != $owner["network"]) AND ($owner["network"] != "")) {
+                       if (($item["network"] != $owner["network"]) && ($owner["network"] != "")) {
                                $item["network"] = $owner["network"];
                        }
  
                                $item["contact-id"] = $author["contact-id"];
                        }
  
-                       if (($item["network"] != $author["network"]) AND ($author["network"] != "")) {
+                       if (($item["network"] != $author["network"]) && ($author["network"] != "")) {
                                $item["network"] = $author["network"];
                        }
  
                                        );
                                }
  
-                               if ($posted_id AND $parent AND ($entrytype == DFRN_REPLY_RC)) {
+                               if ($posted_id && $parent && ($entrytype == DFRN_REPLY_RC)) {
                                        logger("Notifying followers about comment ".$posted_id, LOGGER_DEBUG);
                                        proc_run(PRIORITY_HIGH, "include/notifier.php", "comment-import", $posted_id);
                                }
                        $when = datetime_convert("UTC", "UTC", "now", "Y-m-d H:i:s");
                }
  
-               if (!$uri OR !$importer["id"]) {
+               if (!$uri || !$importer["id"]) {
                        return false;
                }
  
diff --combined mod/display.php
index 365b657615b699acae192f3bf62ae823408cb1d6,c4cf381e93f49fb2f65c0388ed515a954a7f04b7..a9816b06cea4f582da32327406da37bc2352ce21
@@@ -2,8 -2,6 +2,8 @@@
  
  use Friendica\App;
  
 +require_once('include/dfrn.php');
 +
  function display_init(App $a) {
  
        if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
        $nick = (($a->argc > 1) ? $a->argv[1] : '');
        $profiledata = array();
  
 +      if ($a->argc == 3) {
 +              if (substr($a->argv[2], -5) == '.atom') {
 +                      $item_id = substr($a->argv[2], 0, -5);
 +                      $xml = dfrn::itemFeed($item_id);
 +                      header("Content-type: application/atom+xml");
 +                      echo $xml;
 +                      http_status_exit(($xml) ? 200 : 500);
 +              }
 +      }
 +
        // If there is only one parameter, then check if this parameter could be a guid
        if ($a->argc == 2) {
                $nick = "";
@@@ -71,7 -59,7 +71,7 @@@
                                        WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
                                                AND `id` = %d", $r[0]["parent"]);
                        }
-                       if (($itemuid != local_user()) AND local_user()) {
+                       if (($itemuid != local_user()) && local_user()) {
                                // Do we know this contact but we haven't got this item?
                                // Copy the wohle thread to our local storage so that we can interact.
                                // We really should change this need for the future since it scales very bad.
@@@ -141,11 -129,11 +141,11 @@@ function display_fetchauthor($a, $item
  
        // Skip if it isn't a pure repeated messages
        // Does it start with a share?
-       if (!$skip AND strpos($body, "[share") > 0) {
+       if (!$skip && strpos($body, "[share") > 0) {
                $skip = true;
        }
        // Does it end with a share?
-       if (!$skip AND (strlen($body) > (strrpos($body, "[/share]") + 8))) {
+       if (!$skip && (strlen($body) > (strrpos($body, "[/share]") + 8))) {
                $skip = true;
        }
        if (!$skip) {
@@@ -221,6 -209,9 +221,6 @@@ function display_content(App $a, $updat
  
        $o = '';
  
 -      $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
 -
 -
        if ($update) {
                $nick = $_REQUEST['nick'];
        } else {
                }
        }
  
-       if ($item_id AND !is_numeric($item_id)) {
+       if ($item_id && !is_numeric($item_id)) {
                $r = qu("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
                        dbesc($item_id), intval($a->profile['uid']));
                if (dbm::is_result($r)) {
                return;
        }
  
 +      // We are displaying an "alternate" link if that post was public. See issue 2864
 +      $items = q("SELECT `id` FROM `item` WHERE `id` = %d AND NOT `private` AND `wall`", intval($item_id));
 +      if (dbm::is_result($items)) {
 +              $alternate = App::get_baseurl().'/display/'.$nick.'/'.$item_id.'.atom';
 +      } else {
 +              $alternate = '';
 +      }
 +
 +      $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'),
 +                              array('$alternate' => $alternate));
  
        $groups = array();