]> git.mxchange.org Git - friendica.git/blobdiff - object/Item.php
Merge pull request #475 from pixelroot/master
[friendica.git] / object / Item.php
index 86b792cffb9ec3f25506c8f628a579c4f03bdda2..7fa3fed2d3ab77b57a5555115da258670179b9a1 100644 (file)
@@ -28,6 +28,7 @@ class Item extends BaseObject {
        private $owner_name = '';
        private $wall_to_wall = false;
        private $threaded = false;
+       private $visiting = false;
 
        public function __construct($data) {
                $a = $this->get_app();
@@ -35,6 +36,16 @@ class Item extends BaseObject {
                $this->data = $data;
                $this->set_template('wall');
                $this->toplevel = ($this->get_id() == $this->get_data_value('parent'));
+
+               if(is_array($_SESSION['remote'])) {
+                       foreach($_SESSION['remote'] as $visitor) {
+                               if($visitor['cid'] == $this->get_data_value('contact-id')) {
+                                       $this->visiting = true;
+                                       break;
+                               }
+                       }
+               }
+               
                $this->writable = ($this->get_data_value('writable') || $this->get_data_value('self'));
 
                $ssl_state = ((local_user()) ? true : false);
@@ -65,8 +76,8 @@ class Item extends BaseObject {
         * Get data in a form usable by a conversation template
         *
         * Returns:
-        *              _ The data requested on success
-        *              _ false on failure
+        *      _ The data requested on success
+        *      _ false on failure
         */
        public function get_template_data($alike, $dlike, $thread_level=1) {
                $result = array();
@@ -96,7 +107,7 @@ class Item extends BaseObject {
                        $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
                else
                        $edpost = false;
-               if((intval($item['contact-id']) && $item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
+               if(($this->get_data_value('uid') == local_user()) || $this->is_visiting())
                        $dropping = true;
 
                $drop = array(
@@ -119,7 +130,7 @@ class Item extends BaseObject {
                if($sp)
                        $sparkle = ' sparkle';
                else
-                       $profile_link = zrl($profile_link);                                     
+                       $profile_link = zrl($profile_link);                 
 
                $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']);
                if(($normalised != 'mailbox') && (x($a->contacts,$normalised)))
@@ -222,7 +233,7 @@ class Item extends BaseObject {
                        'like' => $like,
                        'dislike' => $dislike,
                        'comment' => $this->get_comment_box($indent),
-                       'previewing' => $previewing,
+                       'previewing' => ($conv->is_preview() ? ' preview ' : ''),
                        'wait' => t('Please wait'),
                        'thread_level' => $thread_level
                );
@@ -402,8 +413,8 @@ class Item extends BaseObject {
         * Get a data value
         *
         * Returns:
-        *              _ value on success
-        *              _ false on failure
+        *      _ value on success
+        *      _ false on failure
         */
        public function get_data_value($name) {
                if(!isset($this->data[$name])) {
@@ -443,6 +454,13 @@ class Item extends BaseObject {
         * Check if this is writable
         */
        private function is_writable() {
+               $conv = $this->get_conversation();
+
+               if($conv) {
+                       // This will allow us to comment on wall-to-wall items owned by our friends
+                       // and community forums even if somebody else wrote the post.
+                       return ($this->writable || ($this->is_visiting() && $conv->get_mode() == 'profile'));
+               }
                return $this->writable;
        }
 
@@ -471,8 +489,8 @@ class Item extends BaseObject {
         * Get the comment box
         *
         * Returns:
-        *              _ The comment box string (empty if no comment box)
-        *              _ false on failure
+        *      _ The comment box string (empty if no comment box)
+        *      _ false on failure
         */
        private function get_comment_box($indent) {
                if(!$this->is_toplevel() && !get_config('system','thread_allow')) {
@@ -590,44 +608,6 @@ class Item extends BaseObject {
                }
 
                if(!$this->wall_to_wall) {
-                       // Fallback, check if can find a @ tag
-                       $tags = $this->get_data_value('tag');
-                       if(strpos($tags, '@[url') !== FALSE) {
-                               // We have at least one @ tag
-                               $matches = array();
-                               preg_match_all('/\@\[url=([^\]]+)\]([^\[]+)\[\/url\]/', $tags, $matches, PREG_SET_ORDER);
-
-                               $r = null;
-                               foreach($matches as $wall) {
-                                       $uri = $wall[1];
-                                       $r = q("SELECT `url`,`name`,`photo` FROM `contact` WHERE `url`='%s' LIMIT 1",
-                                               dbesc($uri)
-                                       );
-
-                                       if(count($r)) {
-                                               $this->owner_url = zrl($r[0]['url']);
-                                               $this->owner_name = $r[0]['name'];
-                                               $this->owner_photo = $r[0]['photo'];
-                                               $this->set_template('wall2wall');
-                                               $this->wall_to_wall = true;
-                                               break;
-                                       }
-                               }
-
-                               if(!$this->wall_to_wall) {
-                                       // We found no matching contact in the database, just do the best we can (we'll only miss the photo)
-                                       $this->owner_url = zrl($matches[0][1]);
-                                       $this->owner_name = $matches[0][2];
-                                       // Use the nosign
-                                       $this->owner_photo = $a->get_baseurl .'/images/nosign.jpg';
-                                       $this->set_template('wall2wall');
-                                       $this->wall_to_wall = true;
-                               }
-                       }
-               }
-
-               if(!$this->wall_to_wall) {
-                       // Definitely not wall to wall
                        $this->set_template('wall');
                        $this->owner_url = '';
                        $this->owner_photo = '';
@@ -650,5 +630,9 @@ class Item extends BaseObject {
        private function get_owner_name() {
                return $this->owner_name;
        }
+
+       private function is_visiting() {
+               return $this->visiting;
+       }
 }
 ?>