]> git.mxchange.org Git - friendica.git/blobdiff - object/Item.php
Merge pull request #3904 from annando/worker-space2
[friendica.git] / object / Item.php
index b693520b93d8cb2e932af589a6b5da94cb51a46a..80bbf255dd8eae6a7b43efc95775ea13e359941d 100644 (file)
@@ -2,9 +2,13 @@
 if(class_exists('Item'))
        return;
 
+use Friendica\Core\Config;
+use Friendica\Core\PConfig;
+use Friendica\Database\DBM;
+use Friendica\Protocol\Diaspora;
+
 require_once('object/BaseObject.php');
 require_once('include/text.php');
-require_once('include/diaspora.php');
 require_once('boot.php');
 
 /**
@@ -52,7 +56,7 @@ class Item extends BaseObject {
                $ssl_state = ((local_user()) ? true : false);
                $this->redirect_url = 'redir/' . $this->get_data_value('cid') ;
 
-               if (get_config('system','thread_allow') && $a->theme_thread_allow && !$this->is_toplevel()) {
+               if (Config::get('system','thread_allow') && $a->theme_thread_allow && !$this->is_toplevel()) {
                        $this->threaded = true;
                }
 
@@ -68,6 +72,11 @@ class Item extends BaseObject {
                                        continue;
                                }
 
+                               // You can always comment on Diaspora items
+                               if (($item['network'] == NETWORK_DIASPORA) && (local_user() == $item['uid'])) {
+                                       $item['writable'] = true;
+                               }
+
                                $item['pagedrop'] = $data['pagedrop'];
                                $child = new Item($item);
                                $this->add_child($child);
@@ -91,7 +100,12 @@ class Item extends BaseObject {
 
                $item = $this->get_data();
                $edited = false;
-               if (strcmp($item['created'], $item['edited'])<>0) {
+               // If the time between "created" and "edited" differs we add
+               // a notice that the post was edited.
+               // Note: In some networks reshared items seem to have (sometimes) a difference
+               // between creation time and edit time of a second. Thats why we add the notice
+               // only if the difference is more than 1 second.
+               if (strtotime($item['edited']) - strtotime($item['created']) > 1) {
                        $edited = array(
                                'label'    => t('This entry was edited'),
                                'date'     => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'),
@@ -112,7 +126,7 @@ class Item extends BaseObject {
 
                $conv = $this->get_conversation();
 
-               $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
+               $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
                        || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
                        ? t('Private Message')
                        : false);
@@ -158,7 +172,7 @@ class Item extends BaseObject {
                        $profile_link = zrl($profile_link);
                }
 
-               if (!isset($item['author-thumb']) OR ($item['author-thumb'] == "")) {
+               if (!isset($item['author-thumb']) || ($item['author-thumb'] == "")) {
                        $author_contact = get_contact_details_by_url($item['author-link'], $conv->get_profile_owner());
                        if ($author_contact["thumb"]) {
                                $item['author-thumb'] = $author_contact["thumb"];
@@ -167,7 +181,7 @@ class Item extends BaseObject {
                        }
                }
 
-               if (!isset($item['owner-thumb']) OR ($item['owner-thumb'] == "")) {
+               if (!isset($item['owner-thumb']) || ($item['owner-thumb'] == "")) {
                        $owner_contact = get_contact_details_by_url($item['owner-link'], $conv->get_profile_owner());
                        if ($owner_contact["thumb"]) {
                                $item['owner-thumb'] = $owner_contact["thumb"];
@@ -180,7 +194,6 @@ class Item extends BaseObject {
                call_hooks('render_location',$locate);
                $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
 
-               $searchpath = "search?tag=";
                $tags=array();
                $hashtags = array();
                $mentions = array();
@@ -242,17 +255,14 @@ class Item extends BaseObject {
                                        'classundo' => (($item['starred']) ? "" : "hidden"),
                                        'starred'   =>  t('starred'),
                                );
-                               $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1",
-                                       intval($item['uid']),
-                                       intval($item['id'])
-                               );
-                               if (dbm::is_result($r)) {
+                               $r = dba::select('thread', array('ignored'), array('uid' => $item['uid'], 'iid' => $item['id']), array('limit' => 1));
+                               if (DBM::is_result($r)) {
                                        $ignore = array(
                                                'do'        => t("ignore thread"),
                                                'undo'      => t("unignore thread"),
                                                'toggle'    => t("toggle ignore status"),
-                                               'classdo'   => (($r[0]['ignored']) ? "hidden" : ""),
-                                               'classundo' => (($r[0]['ignored']) ? "" : "hidden"),
+                                               'classdo'   => (($r['ignored']) ? "hidden" : ""),
+                                               'classundo' => (($r['ignored']) ? "" : "hidden"),
                                                'ignored'   =>  t('ignored'),
                                        );
                                }
@@ -310,28 +320,16 @@ class Item extends BaseObject {
                // Disable features that aren't available in several networks
 
                /// @todo Add NETWORK_DIASPORA when it will pass this information
-               if (!in_array($item["item_network"], array(NETWORK_DFRN)) AND isset($buttons["dislike"])) {
+               if (!in_array($item["item_network"], array(NETWORK_DFRN)) && isset($buttons["dislike"])) {
                        unset($buttons["dislike"],$isevent);
                        $tagger = '';
                }
 
-               if (($item["item_network"] == NETWORK_FEED) AND isset($buttons["like"])) {
-                       unset($buttons["like"]);
-               }
-
-               if (($item["item_network"] == NETWORK_MAIL) AND isset($buttons["like"])) {
-                       unset($buttons["like"]);
-               }
-
-               // Diaspora isn't able to do likes on comments - but Hubzilla does
-               /// @todo When Diaspora will pass this information we will remove these lines
-               if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND
-                       !Diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) {
+               if (($item["item_network"] == NETWORK_FEED) && isset($buttons["like"])) {
                        unset($buttons["like"]);
                }
 
-               // Facebook can like comments - but it isn't programmed in the connector yet.
-               if (($item["item_network"] == NETWORK_FACEBOOK) AND ($indent == 'comment') AND isset($buttons["like"])) {
+               if (($item["item_network"] == NETWORK_MAIL) && isset($buttons["like"])) {
                        unset($buttons["like"]);
                }
 
@@ -397,6 +395,9 @@ class Item extends BaseObject {
                        'edited'          => $edited,
                        'network'         => $item["item_network"],
                        'network_name'    => network_to_name($item['item_network'], $profile_link),
+                       'received'        => $item['received'],
+                       'commented'       => $item['commented'],
+                       'created_date'    => $item['created'],
                );
 
                $arr = array('item' => $item, 'output' => $tmp_item);
@@ -666,7 +667,7 @@ class Item extends BaseObject {
         */
        private function get_comment_box($indent) {
                $a = $this->get_app();
-               if (!$this->is_toplevel() && !(get_config('system','thread_allow') && $a->theme_thread_allow)) {
+               if (!$this->is_toplevel() && !(Config::get('system','thread_allow') && $a->theme_thread_allow)) {
                        return '';
                }
 
@@ -685,7 +686,7 @@ class Item extends BaseObject {
                         * This should be better if done by a hook
                         */
                        if (in_array('qcomment',$a->plugins)) {
-                               $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
+                               $qc = ((local_user()) ? PConfig::get(local_user(),'qcomment','words') : null);
                                $qcomment = (($qc) ? explode("\n",$qc) : null);
                        }
                        $comment_box = replace_macros($template,array(
@@ -736,7 +737,7 @@ class Item extends BaseObject {
 
                if($this->is_toplevel()) {
                        if($conv->get_mode() !== 'profile') {
-                               if($this->get_data_value('wall') AND !$this->get_data_value('self')) {
+                               if($this->get_data_value('wall') && !$this->get_data_value('self')) {
                                        // On the network page, I am the owner. On the display page it will be the profile owner.
                                        // This will have been stored in $a->page_contact by our calling page.
                                        // Put this person as the wall owner of the wall-to-wall notice.
@@ -754,20 +755,20 @@ class Item extends BaseObject {
                                        if ((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
 
                                                // The author url doesn't match the owner (typically the contact)
-                                               // and also doesn't match the contact alias. 
-                                               // The name match is a hack to catch several weird cases where URLs are 
+                                               // and also doesn't match the contact alias.
+                                               // The name match is a hack to catch several weird cases where URLs are
                                                // all over the park. It can be tricked, but this prevents you from
                                                // seeing "Bob Smith to Bob Smith via Wall-to-wall" and you know darn
-                                               // well that it's the same Bob Smith. 
+                                               // well that it's the same Bob Smith.
 
-                                               // But it could be somebody else with the same name. It just isn't highly likely. 
+                                               // But it could be somebody else with the same name. It just isn't highly likely.
 
 
                                                $this->owner_photo = $this->get_data_value('owner-avatar');
                                                $this->owner_name = $this->get_data_value('owner-name');
                                                $this->wall_to_wall = true;
                                                // If it is our contact, use a friendly redirect link
-                                               if ((link_compare($this->get_data_value('owner-link'),$this->get_data_value('url'))) 
+                                               if ((link_compare($this->get_data_value('owner-link'),$this->get_data_value('url')))
                                                        && ($this->get_data_value('network') === NETWORK_DFRN)) {
                                                        $this->owner_url = $this->get_redirect_url();
                                                } else {
@@ -807,5 +808,3 @@ class Item extends BaseObject {
        }
 
 }
-/// @TODO These are discouraged and should be removed:
-?>