From 6ef86e1fff072911165f66bdd8a4c5e98d90e27e Mon Sep 17 00:00:00 2001 From: Domovoy Date: Fri, 10 Aug 2012 17:46:39 +0200 Subject: [PATCH 01/55] New objects: Conversation and Item --- include/conversation.php | 18 +- object/Conversation.php | 399 +++++++++++++++++++++++++++++++++++++++ object/Item.php | 57 ++++++ 3 files changed, 471 insertions(+), 3 deletions(-) create mode 100644 object/Conversation.php create mode 100644 object/Item.php diff --git a/include/conversation.php b/include/conversation.php index 3c4ff2908..8468c7229 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -834,18 +834,30 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { // Normal View $page_template = get_markup_template("threaded_conversation.tpl"); + require_once('object/Conversation.php'); + require_once('object/Item.php'); + + $conv = new Conversation(); + // get all the topmost parents - // this shouldn't be needed, as we should have only them in ou array + // this shouldn't be needed, as we should have only them in our array // But for now, this array respects the old style, just in case $threads = array(); foreach($items as $item) { if($item['id'] == $item['parent']) { - $threads[] = $item; + // $threads[] = $item; + $item_object = new Item($item); + $conv->add_thread($item_object); } } - $threads = prepare_threads_body($a, $threads, $cmnt_tpl, $page_writeable, $mode, $profile_owner); + //$threads = prepare_threads_body($a, $threads, $cmnt_tpl, $page_writeable, $mode, $profile_owner); + $threads = $conv->get_template_data($a, $cmnt_tpl, $page_writeable, $mode, $profile_owner); + if(!$threads) { + logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG); + $threads = array(); + } } } diff --git a/object/Conversation.php b/object/Conversation.php new file mode 100644 index 000000000..4154dd9cb --- /dev/null +++ b/object/Conversation.php @@ -0,0 +1,399 @@ +get_id(); + if(!$item_id) { + logger('[ERROR] Conversation::add_thread : Item has no ID!!', LOGGER_DEBUG); + return false; + } + if($this->get_thread($item->get_id())) { + logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG); + return false; + } + $this->threads[] = $item; + return end($this->threads); + } + + /** + * Get data in a form usable by a conversation template + * + * We should find a way to avoid using those arguments (at least most of them) + * + * Returns: + * _ The data requested on success + * _ false on failure + */ + public function get_template_data($a, $cmnt_tpl, $page_writeable, $mode, $profile_owner) { + $result = array(); + + /*foreach($this->threads as $item) { + $item_data = $item->get_template_data(); + if(!$item_data) { + logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG); + return false; + } + $result[] = $item_data; + }*/ + + /* + * This should be moved on the item object; + */ + $threads = array(); + foreach($this->threads as $item) { + $threads[] = $item->get_data(); + } + return $this->prepare_threads_body($a, $threads, $cmnt_tpl, $page_writeable, $mode, $profile_owner); + + return $result; + } + + /** + * Get a thread based on its item id + * + * Returns: + * _ The found item on success + * _ false on failure + */ + private function get_thread($id) { + foreach($this->threads as $item) { + if($item->get_id() == $id) + return $item; + } + + return false; + } + + /** + * Recursively prepare a thread for HTML + */ + + private function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $profile_owner, $thread_level=1) { + $result = array(); + + $wall_template = 'wall_thread.tpl'; + $wallwall_template = 'wallwall_thread.tpl'; + $items_seen = 0; + $nb_items = count($items); + + $total_children = $nb_items; + + foreach($items as $item) { + // prevent private email reply to public conversation from leaking. + if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { + // Don't count it as a visible item + $nb_items--; + continue; + } + + $items_seen++; + + $alike = array(); + $dlike = array(); + $comment = ''; + $template = $wall_template; + $commentww = ''; + $sparkle = ''; + $owner_url = $owner_photo = $owner_name = ''; + $buttons = ''; + $dropping = false; + $star = false; + $isstarred = "unstarred"; + $photo = $item['photo']; + $thumb = $item['thumb']; + $indent = ''; + $osparkle = ''; + $lastcollapsed = false; + $firstcollapsed = false; + $total_children += count_descendants($item); + + $toplevelpost = (($item['id'] == $item['parent']) ? true : false); + $item_writeable = (($item['writable'] || $item['self']) ? true : false); + $show_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false); + $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); + $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ; + $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false); + if(local_user() && link_compare($a->contact['url'],$item['author-link'])) + $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())) + $dropping = true; + + $drop = array( + 'dropping' => $dropping, + 'select' => t('Select'), + 'delete' => t('Delete'), + ); + + $filer = (($profile_owner == local_user()) ? t("save to folder") : false); + + $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true); + $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']); + if($item['author-link'] && (! $item['author-name'])) + $profile_name = $item['author-link']; + + $sp = false; + $profile_link = best_link_url($item,$sp); + if($profile_link === 'mailbox') + $profile_link = ''; + if($sp) + $sparkle = ' sparkle'; + else + $profile_link = zrl($profile_link); + + $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']); + if(($normalised != 'mailbox') && (x($a->contacts,$normalised))) + $profile_avatar = $a->contacts[$normalised]['thumb']; + else + $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb)); + + $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => ''); + call_hooks('render_location',$locate); + $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate)); + + $tags=array(); + foreach(explode(',',$item['tag']) as $tag){ + $tag = trim($tag); + if ($tag!="") $tags[] = bbcode($tag); + } + + like_puller($a,$item,$alike,'like'); + like_puller($a,$item,$dlike,'dislike'); + + $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : ''); + $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : ''); + + if($toplevelpost) { + if((! $item['self']) && ($mode !== 'profile')) { + if($item['wall']) { + + // 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. + + $owner_url = zrl($a->page_contact['url']); + $owner_photo = $a->page_contact['thumb']; + $owner_name = $a->page_contact['name']; + $template = $wallwall_template; + $commentww = 'ww'; + } + } + else if($item['owner-link']) { + + $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link'])); + $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link'])); + $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']); + 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 + // 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. + + // But it could be somebody else with the same name. It just isn't highly likely. + + + $owner_url = $item['owner-link']; + $owner_photo = $item['owner-avatar']; + $owner_name = $item['owner-name']; + $template = $wallwall_template; + $commentww = 'ww'; + // If it is our contact, use a friendly redirect link + if((link_compare($item['owner-link'],$item['url'])) + && ($item['network'] === NETWORK_DFRN)) { + $owner_url = $redirect_url; + $osparkle = ' sparkle'; + } + else + $owner_url = zrl($owner_url); + } + } + if($profile_owner == local_user()) { + $isstarred = (($item['starred']) ? "starred" : "unstarred"); + + $star = array( + 'do' => t("add star"), + 'undo' => t("remove star"), + 'toggle' => t("toggle star status"), + 'classdo' => (($item['starred']) ? "hidden" : ""), + 'classundo' => (($item['starred']) ? "" : "hidden"), + 'starred' => t('starred'), + 'tagger' => t("add tag"), + 'classtagger' => "", + ); + } + } else { + $indent = 'comment'; + // Collapse comments + if(($nb_items > 2) || ($thread_level > 2)) { + if($items_seen == 1) { + $firstcollapsed = true; + } + if($thread_level > 2) { + if($items_seen == $nb_items) + $lastcollapsed = true; + } + else if($items_seen == ($nb_items - 2)) { + $lastcollapsed = true; + } + } + } + + if($page_writeable) { + $buttons = array( + 'like' => array( t("I like this \x28toggle\x29"), t("like")), + 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")), + ); + if ($shareable) $buttons['share'] = array( t('Share this'), t('share')); + + + if($show_comment_box) { + $qc = $qcomment = null; + + if(in_array('qcomment',$a->plugins)) { + $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null); + $qcomment = (($qc) ? explode("\n",$qc) : null); + } + $comment = replace_macros($cmnt_tpl,array( + '$return_path' => '', + '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''), + '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'), + '$id' => $item['item_id'], + '$parent' => $item['item_id'], + '$qcomment' => $qcomment, + '$profile_uid' => $profile_owner, + '$mylink' => $a->contact['url'], + '$mytitle' => t('This is you'), + '$myphoto' => $a->contact['thumb'], + '$comment' => t('Comment'), + '$submit' => t('Submit'), + '$edbold' => t('Bold'), + '$editalic' => t('Italic'), + '$eduline' => t('Underline'), + '$edquote' => t('Quote'), + '$edcode' => t('Code'), + '$edimg' => t('Image'), + '$edurl' => t('Link'), + '$edvideo' => t('Video'), + '$preview' => t('Preview'), + '$sourceapp' => t($a->sourcename), + '$ww' => (($mode === 'network') ? $commentww : '') + )); + } + } + + if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0) + $indent .= ' shiny'; + + localize_item($item); + + $body = prepare_body($item,true); + + $tmp_item = array( + // collapse comments in template. I don't like this much... + 'comment_firstcollapsed' => $firstcollapsed, + 'comment_lastcollapsed' => $lastcollapsed, + // template to use to render item (wall, walltowall, search) + 'template' => $template, + + 'type' => implode("",array_slice(explode("/",$item['verb']),-1)), + 'tags' => $tags, + 'body' => template_escape($body), + 'text' => strip_tags(template_escape($body)), + 'id' => $item['item_id'], + 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])), + 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $owner_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])), + 'to' => t('to'), + 'wall' => t('Wall-to-Wall'), + 'vwall' => t('via Wall-To-Wall:'), + 'profile_url' => $profile_link, + 'item_photo_menu' => item_photo_menu($item), + 'name' => template_escape($profile_name), + 'thumb' => $profile_avatar, + 'osparkle' => $osparkle, + 'sparkle' => $sparkle, + 'title' => template_escape($item['title']), + 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), + 'lock' => $lock, + 'location' => template_escape($location), + 'indent' => $indent, + 'owner_url' => $owner_url, + 'owner_photo' => $owner_photo, + 'owner_name' => template_escape($owner_name), + 'plink' => get_plink($item), + 'edpost' => $edpost, + 'isstarred' => $isstarred, + 'star' => $star, + 'filer' => $filer, + 'drop' => $drop, + 'vote' => $buttons, + 'like' => $like, + 'dislike' => $dislike, + 'comment' => $comment, + 'previewing' => $previewing, + 'wait' => t('Please wait'), + ); + + $arr = array('item' => $item, 'output' => $tmp_item); + call_hooks('display_item', $arr); + + $item_result = $arr['output']; + if($firstcollapsed) { + $item_result['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children ); + $item_result['hide_text'] = t('show more'); + } + + $item_result['children'] = array(); + if(count($item['children'])) { + $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $page_writeable, $mode, $profile_owner, ($thread_level + 1)); + } + $item_result['private'] = $item['private']; + $item_result['toplevel'] = ($toplevelpost ? 'toplevel_item' : ''); + + /* + * I don't like this very much... + */ + if(get_config('system','thread_allow')) { + $item_result['flatten'] = false; + $item_result['threaded'] = true; + } + else { + $item_result['flatten'] = true; + $item_result['threaded'] = false; + if(!$toplevelpost) { + $item_result['comment'] = false; + } + } + + $result[] = $item_result; + } + + return $result; + } +} +?> diff --git a/object/Item.php b/object/Item.php new file mode 100644 index 000000000..0f474e5de --- /dev/null +++ b/object/Item.php @@ -0,0 +1,57 @@ +data = $data; + } + + /** + * Get the item ID + * + * Returns: + * _ the ID on success + * _ false on failure + */ + public function get_id() { + if(!x($this->data['id'])) { + logger('[ERROR] Item::get_id : Item has no ID!!', LOGGER_DEBUG); + return false; + } + + return $this->data['id']; + } + + /** + * Get data in a form usable by a conversation template + * + * Returns: + * _ The data requested on success + * _ false on failure + */ + public function get_template_data() { + $result = array(); + + + + return $result; + } + + /** + * Get raw data + * + * We shouldn't need this + */ + public function get_data() { + return $this->data; + } +} +?> From 75d355a2aa23a208864e40e3901b3fa431887dc7 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Fri, 10 Aug 2012 19:57:39 +0200 Subject: [PATCH 02/55] Rendering is now done by Item objects --- include/conversation.php | 5 +- index.php | 2 + object/BaseObject.php | 37 ++++ object/Conversation.php | 347 ++---------------------------------- object/Item.php | 372 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 413 insertions(+), 350 deletions(-) create mode 100644 object/BaseObject.php diff --git a/include/conversation.php b/include/conversation.php index 8468c7229..7d9dfa1e7 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -837,7 +837,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { require_once('object/Conversation.php'); require_once('object/Item.php'); - $conv = new Conversation(); + $conv = new Conversation($mode); // get all the topmost parents // this shouldn't be needed, as we should have only them in our array @@ -853,11 +853,12 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { } //$threads = prepare_threads_body($a, $threads, $cmnt_tpl, $page_writeable, $mode, $profile_owner); - $threads = $conv->get_template_data($a, $cmnt_tpl, $page_writeable, $mode, $profile_owner); + $threads = $conv->get_template_data($cmnt_tpl); if(!$threads) { logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG); $threads = array(); } + logger('[DEBUG] conversation : $threads = '. print_r($threads, true), LOGGER_DEBUG); } } diff --git a/index.php b/index.php index c9b7f34d7..eaa7295e2 100644 --- a/index.php +++ b/index.php @@ -13,8 +13,10 @@ */ require_once('boot.php'); +require_once('object/BaseObject.php'); $a = new App; +BaseObject::set_app($a); /** * diff --git a/object/BaseObject.php b/object/BaseObject.php new file mode 100644 index 000000000..14f0d8fd0 --- /dev/null +++ b/object/BaseObject.php @@ -0,0 +1,37 @@ + diff --git a/object/Conversation.php b/object/Conversation.php index 4154dd9cb..0ce016649 100644 --- a/object/Conversation.php +++ b/object/Conversation.php @@ -2,6 +2,8 @@ if(class_exists('Conversation')) return; +require_once('boot.php'); +require_once('object/BaseObject.php'); require_once('object/Item.php'); require_once('include/text.php'); @@ -10,8 +12,13 @@ require_once('include/text.php'); * * We should think about making this a SPL Iterator */ -class Conversation { +class Conversation extends BaseObject { private $threads = array(); + private $mode = null; + + public function __construct($mode) { + $this->mode = $mode; + } /** * Add a thread to the conversation @@ -43,26 +50,19 @@ class Conversation { * _ The data requested on success * _ false on failure */ - public function get_template_data($a, $cmnt_tpl, $page_writeable, $mode, $profile_owner) { + public function get_template_data($cmnt_tpl) { $result = array(); - /*foreach($this->threads as $item) { - $item_data = $item->get_template_data(); + foreach($this->threads as $item) { + if($item->get_network() === NETWORK_MAIL && local_user() != $item->get_uid()) + continue; + $item_data = $item->get_template_data($cmnt_tpl, $this->mode); if(!$item_data) { logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG); return false; } $result[] = $item_data; - }*/ - - /* - * This should be moved on the item object; - */ - $threads = array(); - foreach($this->threads as $item) { - $threads[] = $item->get_data(); } - return $this->prepare_threads_body($a, $threads, $cmnt_tpl, $page_writeable, $mode, $profile_owner); return $result; } @@ -75,325 +75,12 @@ class Conversation { * _ false on failure */ private function get_thread($id) { - foreach($this->threads as $item) { - if($item->get_id() == $id) - return $item; - } - - return false; - } - - /** - * Recursively prepare a thread for HTML - */ - - private function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $profile_owner, $thread_level=1) { - $result = array(); - - $wall_template = 'wall_thread.tpl'; - $wallwall_template = 'wallwall_thread.tpl'; - $items_seen = 0; - $nb_items = count($items); - - $total_children = $nb_items; - - foreach($items as $item) { - // prevent private email reply to public conversation from leaking. - if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { - // Don't count it as a visible item - $nb_items--; - continue; - } - - $items_seen++; - - $alike = array(); - $dlike = array(); - $comment = ''; - $template = $wall_template; - $commentww = ''; - $sparkle = ''; - $owner_url = $owner_photo = $owner_name = ''; - $buttons = ''; - $dropping = false; - $star = false; - $isstarred = "unstarred"; - $photo = $item['photo']; - $thumb = $item['thumb']; - $indent = ''; - $osparkle = ''; - $lastcollapsed = false; - $firstcollapsed = false; - $total_children += count_descendants($item); - - $toplevelpost = (($item['id'] == $item['parent']) ? true : false); - $item_writeable = (($item['writable'] || $item['self']) ? true : false); - $show_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false); - $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); - $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ; - $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false); - if(local_user() && link_compare($a->contact['url'],$item['author-link'])) - $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())) - $dropping = true; - - $drop = array( - 'dropping' => $dropping, - 'select' => t('Select'), - 'delete' => t('Delete'), - ); - - $filer = (($profile_owner == local_user()) ? t("save to folder") : false); - - $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true); - $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']); - if($item['author-link'] && (! $item['author-name'])) - $profile_name = $item['author-link']; - - $sp = false; - $profile_link = best_link_url($item,$sp); - if($profile_link === 'mailbox') - $profile_link = ''; - if($sp) - $sparkle = ' sparkle'; - else - $profile_link = zrl($profile_link); - - $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']); - if(($normalised != 'mailbox') && (x($a->contacts,$normalised))) - $profile_avatar = $a->contacts[$normalised]['thumb']; - else - $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb)); - - $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => ''); - call_hooks('render_location',$locate); - $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate)); - - $tags=array(); - foreach(explode(',',$item['tag']) as $tag){ - $tag = trim($tag); - if ($tag!="") $tags[] = bbcode($tag); - } - - like_puller($a,$item,$alike,'like'); - like_puller($a,$item,$dlike,'dislike'); - - $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : ''); - $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : ''); - - if($toplevelpost) { - if((! $item['self']) && ($mode !== 'profile')) { - if($item['wall']) { - - // 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. - - $owner_url = zrl($a->page_contact['url']); - $owner_photo = $a->page_contact['thumb']; - $owner_name = $a->page_contact['name']; - $template = $wallwall_template; - $commentww = 'ww'; - } - } - else if($item['owner-link']) { - - $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link'])); - $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link'])); - $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']); - 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 - // 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. - - // But it could be somebody else with the same name. It just isn't highly likely. - - - $owner_url = $item['owner-link']; - $owner_photo = $item['owner-avatar']; - $owner_name = $item['owner-name']; - $template = $wallwall_template; - $commentww = 'ww'; - // If it is our contact, use a friendly redirect link - if((link_compare($item['owner-link'],$item['url'])) - && ($item['network'] === NETWORK_DFRN)) { - $owner_url = $redirect_url; - $osparkle = ' sparkle'; - } - else - $owner_url = zrl($owner_url); - } - } - if($profile_owner == local_user()) { - $isstarred = (($item['starred']) ? "starred" : "unstarred"); - - $star = array( - 'do' => t("add star"), - 'undo' => t("remove star"), - 'toggle' => t("toggle star status"), - 'classdo' => (($item['starred']) ? "hidden" : ""), - 'classundo' => (($item['starred']) ? "" : "hidden"), - 'starred' => t('starred'), - 'tagger' => t("add tag"), - 'classtagger' => "", - ); - } - } else { - $indent = 'comment'; - // Collapse comments - if(($nb_items > 2) || ($thread_level > 2)) { - if($items_seen == 1) { - $firstcollapsed = true; - } - if($thread_level > 2) { - if($items_seen == $nb_items) - $lastcollapsed = true; - } - else if($items_seen == ($nb_items - 2)) { - $lastcollapsed = true; - } - } - } - - if($page_writeable) { - $buttons = array( - 'like' => array( t("I like this \x28toggle\x29"), t("like")), - 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")), - ); - if ($shareable) $buttons['share'] = array( t('Share this'), t('share')); - - - if($show_comment_box) { - $qc = $qcomment = null; - - if(in_array('qcomment',$a->plugins)) { - $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null); - $qcomment = (($qc) ? explode("\n",$qc) : null); - } - $comment = replace_macros($cmnt_tpl,array( - '$return_path' => '', - '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''), - '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'), - '$id' => $item['item_id'], - '$parent' => $item['item_id'], - '$qcomment' => $qcomment, - '$profile_uid' => $profile_owner, - '$mylink' => $a->contact['url'], - '$mytitle' => t('This is you'), - '$myphoto' => $a->contact['thumb'], - '$comment' => t('Comment'), - '$submit' => t('Submit'), - '$edbold' => t('Bold'), - '$editalic' => t('Italic'), - '$eduline' => t('Underline'), - '$edquote' => t('Quote'), - '$edcode' => t('Code'), - '$edimg' => t('Image'), - '$edurl' => t('Link'), - '$edvideo' => t('Video'), - '$preview' => t('Preview'), - '$sourceapp' => t($a->sourcename), - '$ww' => (($mode === 'network') ? $commentww : '') - )); - } - } - - if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0) - $indent .= ' shiny'; - - localize_item($item); - - $body = prepare_body($item,true); - - $tmp_item = array( - // collapse comments in template. I don't like this much... - 'comment_firstcollapsed' => $firstcollapsed, - 'comment_lastcollapsed' => $lastcollapsed, - // template to use to render item (wall, walltowall, search) - 'template' => $template, - - 'type' => implode("",array_slice(explode("/",$item['verb']),-1)), - 'tags' => $tags, - 'body' => template_escape($body), - 'text' => strip_tags(template_escape($body)), - 'id' => $item['item_id'], - 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])), - 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $owner_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])), - 'to' => t('to'), - 'wall' => t('Wall-to-Wall'), - 'vwall' => t('via Wall-To-Wall:'), - 'profile_url' => $profile_link, - 'item_photo_menu' => item_photo_menu($item), - 'name' => template_escape($profile_name), - 'thumb' => $profile_avatar, - 'osparkle' => $osparkle, - 'sparkle' => $sparkle, - 'title' => template_escape($item['title']), - 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), - 'lock' => $lock, - 'location' => template_escape($location), - 'indent' => $indent, - 'owner_url' => $owner_url, - 'owner_photo' => $owner_photo, - 'owner_name' => template_escape($owner_name), - 'plink' => get_plink($item), - 'edpost' => $edpost, - 'isstarred' => $isstarred, - 'star' => $star, - 'filer' => $filer, - 'drop' => $drop, - 'vote' => $buttons, - 'like' => $like, - 'dislike' => $dislike, - 'comment' => $comment, - 'previewing' => $previewing, - 'wait' => t('Please wait'), - ); - - $arr = array('item' => $item, 'output' => $tmp_item); - call_hooks('display_item', $arr); - - $item_result = $arr['output']; - if($firstcollapsed) { - $item_result['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children ); - $item_result['hide_text'] = t('show more'); - } - - $item_result['children'] = array(); - if(count($item['children'])) { - $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $page_writeable, $mode, $profile_owner, ($thread_level + 1)); - } - $item_result['private'] = $item['private']; - $item_result['toplevel'] = ($toplevelpost ? 'toplevel_item' : ''); - - /* - * I don't like this very much... - */ - if(get_config('system','thread_allow')) { - $item_result['flatten'] = false; - $item_result['threaded'] = true; - } - else { - $item_result['flatten'] = true; - $item_result['threaded'] = false; - if(!$toplevelpost) { - $item_result['comment'] = false; - } - } - - $result[] = $item_result; + foreach($this->threads as $item) { + if($item->get_id() == $id) + return $item; } - return $result; + return false; } } ?> diff --git a/object/Item.php b/object/Item.php index 0f474e5de..fbdb1a220 100644 --- a/object/Item.php +++ b/object/Item.php @@ -2,32 +2,23 @@ if(class_exists('Item')) return; +require_once('object/BaseObject.php'); require_once('include/text.php'); /** * An item */ -class Item { +class Item extends BaseObject { private $data = array(); + private $template = null; + private $available_templates = array( + 'wall' => 'wall_thread.tpl', + 'wall2wall' => 'wallwall_thread.tpl' + ); public function __construct($data) { $this->data = $data; - } - - /** - * Get the item ID - * - * Returns: - * _ the ID on success - * _ false on failure - */ - public function get_id() { - if(!x($this->data['id'])) { - logger('[ERROR] Item::get_id : Item has no ID!!', LOGGER_DEBUG); - return false; - } - - return $this->data['id']; + $this->template = $this->available_templates['wall']; } /** @@ -37,13 +28,332 @@ class Item { * _ The data requested on success * _ false on failure */ - public function get_template_data() { + public function get_template_data($cmnt_tpl, $mode) { $result = array(); + $a = $this->get_app(); + + $page_writeable = false; + $profile_owner = 0; + + switch($mode) { + case 'network': + case 'notes': + $profile_owner = local_user(); + $page_writeable = true; + break; + case 'profile': + $profile_owner = $a->profile['profile_uid']; + $page_writeable = can_write_wall($a,$profile_owner); + break; + case 'display': + $profile_owner = $a->profile['uid']; + $page_writeable = can_write_wall($a,$profile_owner); + break; + default: + logger('[ERROR] Item::prepare_threads_body : Unhandled mode ('. $mode .').', LOGGER_DEBUG); + return false; + break; + } + + $item = $this->get_data(); + + $alike = array(); + $dlike = array(); + $template = $this->available_templates['wall']; + $comment = ''; + $commentww = ''; + $sparkle = ''; + $owner_url = $owner_photo = $owner_name = ''; + $buttons = ''; + $dropping = false; + $star = false; + $isstarred = "unstarred"; + $photo = $item['photo']; + $thumb = $item['thumb']; + $indent = ''; + $osparkle = ''; + $lastcollapsed = false; + $firstcollapsed = false; + $total_children += count_descendants($item); + + $toplevelpost = (($item['id'] == $item['parent']) ? true : false); + $item_writeable = (($item['writable'] || $item['self']) ? true : false); + $show_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false); + $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); + $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ; + $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false); + if(local_user() && link_compare($a->contact['url'],$item['author-link'])) + $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())) + $dropping = true; + + $drop = array( + 'dropping' => $dropping, + 'select' => t('Select'), + 'delete' => t('Delete'), + ); + $filer = (($profile_owner == local_user()) ? t("save to folder") : false); + + $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true); + $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']); + if($item['author-link'] && (! $item['author-name'])) + $profile_name = $item['author-link']; + + $sp = false; + $profile_link = best_link_url($item,$sp); + if($profile_link === 'mailbox') + $profile_link = ''; + if($sp) + $sparkle = ' sparkle'; + else + $profile_link = zrl($profile_link); + + $normalised = normalise_link((strlen($item['author-link'])) ? $item['author-link'] : $item['url']); + if(($normalised != 'mailbox') && (x($a->contacts,$normalised))) + $profile_avatar = $a->contacts[$normalised]['thumb']; + else + $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb)); + + $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => ''); + call_hooks('render_location',$locate); + $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate)); + + $tags=array(); + foreach(explode(',',$item['tag']) as $tag){ + $tag = trim($tag); + if ($tag!="") $tags[] = bbcode($tag); + } + + like_puller($a,$item,$alike,'like'); + like_puller($a,$item,$dlike,'dislike'); + + $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : ''); + $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : ''); + + if($toplevelpost) { + if((! $item['self']) && ($mode !== 'profile')) { + if($item['wall']) { + + // 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. + + $owner_url = zrl($a->page_contact['url']); + $owner_photo = $a->page_contact['thumb']; + $owner_name = $a->page_contact['name']; + $template = $this->available_templates['wall2wall']; + $commentww = 'ww'; + } + } + else if($item['owner-link']) { + + $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link'])); + $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link'])); + $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']); + 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 + // 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. + + // But it could be somebody else with the same name. It just isn't highly likely. + + + $owner_url = $item['owner-link']; + $owner_photo = $item['owner-avatar']; + $owner_name = $item['owner-name']; + $template = $this->available_templates['wall2wall']; + $commentww = 'ww'; + // If it is our contact, use a friendly redirect link + if((link_compare($item['owner-link'],$item['url'])) + && ($item['network'] === NETWORK_DFRN)) { + $owner_url = $redirect_url; + $osparkle = ' sparkle'; + } + else + $owner_url = zrl($owner_url); + } + } + if($profile_owner == local_user()) { + $isstarred = (($item['starred']) ? "starred" : "unstarred"); + + $star = array( + 'do' => t("add star"), + 'undo' => t("remove star"), + 'toggle' => t("toggle star status"), + 'classdo' => (($item['starred']) ? "hidden" : ""), + 'classundo' => (($item['starred']) ? "" : "hidden"), + 'starred' => t('starred'), + 'tagger' => t("add tag"), + 'classtagger' => "", + ); + } + } else { + $indent = 'comment'; + // Collapse comments + if(($nb_items > 2) || ($thread_level > 2)) { + if($items_seen == 1) { + $firstcollapsed = true; + } + if($thread_level > 2) { + if($items_seen == $nb_items) + $lastcollapsed = true; + } + else if($items_seen == ($nb_items - 2)) { + $lastcollapsed = true; + } + } + } + + if($page_writeable) { + $buttons = array( + 'like' => array( t("I like this \x28toggle\x29"), t("like")), + 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")), + ); + if ($shareable) $buttons['share'] = array( t('Share this'), t('share')); + + + if($show_comment_box) { + $qc = $qcomment = null; + + if(in_array('qcomment',$a->plugins)) { + $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null); + $qcomment = (($qc) ? explode("\n",$qc) : null); + } + $comment = replace_macros($cmnt_tpl,array( + '$return_path' => '', + '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''), + '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'), + '$id' => $item['item_id'], + '$parent' => $item['item_id'], + '$qcomment' => $qcomment, + '$profile_uid' => $profile_owner, + '$mylink' => $a->contact['url'], + '$mytitle' => t('This is you'), + '$myphoto' => $a->contact['thumb'], + '$comment' => t('Comment'), + '$submit' => t('Submit'), + '$edbold' => t('Bold'), + '$editalic' => t('Italic'), + '$eduline' => t('Underline'), + '$edquote' => t('Quote'), + '$edcode' => t('Code'), + '$edimg' => t('Image'), + '$edurl' => t('Link'), + '$edvideo' => t('Video'), + '$preview' => t('Preview'), + '$sourceapp' => t($a->sourcename), + '$ww' => (($mode === 'network') ? $commentww : '') + )); + } + } + + if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0) + $indent .= ' shiny'; + + localize_item($item); + + $body = prepare_body($item,true); + + $tmp_item = array( + // collapse comments in template. I don't like this much... + 'comment_firstcollapsed' => $firstcollapsed, + 'comment_lastcollapsed' => $lastcollapsed, + // template to use to render item (wall, walltowall, search) + 'template' => $template, + + 'type' => implode("",array_slice(explode("/",$item['verb']),-1)), + 'tags' => $tags, + 'body' => template_escape($body), + 'text' => strip_tags(template_escape($body)), + 'id' => $item['item_id'], + 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])), + 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $owner_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])), + 'to' => t('to'), + 'wall' => t('Wall-to-Wall'), + 'vwall' => t('via Wall-To-Wall:'), + 'profile_url' => $profile_link, + 'item_photo_menu' => item_photo_menu($item), + 'name' => template_escape($profile_name), + 'thumb' => $profile_avatar, + 'osparkle' => $osparkle, + 'sparkle' => $sparkle, + 'title' => template_escape($item['title']), + 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), + 'lock' => $lock, + 'location' => template_escape($location), + 'indent' => $indent, + 'owner_url' => $owner_url, + 'owner_photo' => $owner_photo, + 'owner_name' => template_escape($owner_name), + 'plink' => get_plink($item), + 'edpost' => $edpost, + 'isstarred' => $isstarred, + 'star' => $star, + 'filer' => $filer, + 'drop' => $drop, + 'vote' => $buttons, + 'like' => $like, + 'dislike' => $dislike, + 'comment' => $comment, + 'previewing' => $previewing, + 'wait' => t('Please wait'), + ); + + $arr = array('item' => $item, 'output' => $tmp_item); + call_hooks('display_item', $arr); + + $item_result = $arr['output']; + if($firstcollapsed) { + $item_result['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children ); + $item_result['hide_text'] = t('show more'); + } + + $item_result['children'] = array(); + if(count($item['children'])) { + $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $page_writeable, $mode, $profile_owner, ($thread_level + 1)); + } + $item_result['private'] = $item['private']; + $item_result['toplevel'] = ($toplevelpost ? 'toplevel_item' : ''); + + if(get_config('system','thread_allow')) { + $item_result['flatten'] = false; + $item_result['threaded'] = true; + } + else { + $item_result['flatten'] = true; + $item_result['threaded'] = false; + if(!$toplevelpost) { + $item_result['comment'] = false; + } + } + + $result = $item_result; return $result; } + + public function get_id() { + return $this->get_data_value('id'); + } + + public function get_network() { + return $this->get_data_value('network'); + } + + public function get_uid() { + return $this->get_data_value('uid'); + } /** * Get raw data @@ -53,5 +363,31 @@ class Item { public function get_data() { return $this->data; } + + /** + * Get a data value + * + * Returns: + * _ value on success + * _ false on failure + */ + private function get_data_value($name) { + if(!x($this->data[$name])) { + logger('[ERROR] Item::get_data_value : Item has no value name "'. $name .'".', LOGGER_DEBUG); + return false; + } + + return $this->data[$name]; + } + + /** + * Set the mode we'll be displayed on + */ + private function set_mode($mode) { + if($this->get_mode() == $mode) + return; + + + } } ?> From f1731b3cec5f95be59faca44678841877597ab8c Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 11 Aug 2012 15:44:47 +0200 Subject: [PATCH 03/55] New methods on Item: set|get_mode, get_profile_owner, is_page_writeable --- object/Item.php | 89 ++++++++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/object/Item.php b/object/Item.php index fbdb1a220..796f9cae6 100644 --- a/object/Item.php +++ b/object/Item.php @@ -15,6 +15,9 @@ class Item extends BaseObject { 'wall' => 'wall_thread.tpl', 'wall2wall' => 'wallwall_thread.tpl' ); + private $mode = null; + private $page_writeable = false; + private $profile_owner = 0; public function __construct($data) { $this->data = $data; @@ -33,28 +36,7 @@ class Item extends BaseObject { $a = $this->get_app(); - $page_writeable = false; - $profile_owner = 0; - - switch($mode) { - case 'network': - case 'notes': - $profile_owner = local_user(); - $page_writeable = true; - break; - case 'profile': - $profile_owner = $a->profile['profile_uid']; - $page_writeable = can_write_wall($a,$profile_owner); - break; - case 'display': - $profile_owner = $a->profile['uid']; - $page_writeable = can_write_wall($a,$profile_owner); - break; - default: - logger('[ERROR] Item::prepare_threads_body : Unhandled mode ('. $mode .').', LOGGER_DEBUG); - return false; - break; - } + $this->set_mode($mode); $item = $this->get_data(); @@ -79,13 +61,13 @@ class Item extends BaseObject { $toplevelpost = (($item['id'] == $item['parent']) ? true : false); $item_writeable = (($item['writable'] || $item['self']) ? true : false); - $show_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false); + $show_comment_box = ((($this->is_page_writeable()) && ($item_writeable)) ? true : false); $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); $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ; - $shareable = ((($profile_owner == local_user()) && ($item['private'] != 1)) ? true : false); + $shareable = ((($this->get_profile_owner() == local_user()) && ($item['private'] != 1)) ? true : false); if(local_user() && link_compare($a->contact['url'],$item['author-link'])) $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit")); else @@ -99,7 +81,7 @@ class Item extends BaseObject { 'delete' => t('Delete'), ); - $filer = (($profile_owner == local_user()) ? t("save to folder") : false); + $filer = (($this->get_profile_owner() == local_user()) ? t("save to folder") : false); $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true); $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']); @@ -138,7 +120,7 @@ class Item extends BaseObject { $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : ''); if($toplevelpost) { - if((! $item['self']) && ($mode !== 'profile')) { + if((! $item['self']) && ($this->get_mode() !== 'profile')) { if($item['wall']) { // On the network page, I am the owner. On the display page it will be the profile owner. @@ -184,7 +166,7 @@ class Item extends BaseObject { $owner_url = zrl($owner_url); } } - if($profile_owner == local_user()) { + if($this->get_profile_owner() == local_user()) { $isstarred = (($item['starred']) ? "starred" : "unstarred"); $star = array( @@ -215,7 +197,7 @@ class Item extends BaseObject { } } - if($page_writeable) { + if($this->is_page_writeable()) { $buttons = array( 'like' => array( t("I like this \x28toggle\x29"), t("like")), 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")), @@ -232,12 +214,12 @@ class Item extends BaseObject { } $comment = replace_macros($cmnt_tpl,array( '$return_path' => '', - '$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''), - '$type' => (($mode === 'profile') ? 'wall-comment' : 'net-comment'), + '$jsreload' => (($this->get_mode() === 'display') ? $_SESSION['return_url'] : ''), + '$type' => (($this->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'), '$id' => $item['item_id'], '$parent' => $item['item_id'], '$qcomment' => $qcomment, - '$profile_uid' => $profile_owner, + '$profile_uid' => $this->get_profile_owner(), '$mylink' => $a->contact['url'], '$mytitle' => t('This is you'), '$myphoto' => $a->contact['thumb'], @@ -253,7 +235,7 @@ class Item extends BaseObject { '$edvideo' => t('Video'), '$preview' => t('Preview'), '$sourceapp' => t($a->sourcename), - '$ww' => (($mode === 'network') ? $commentww : '') + '$ww' => (($this->get_mode() === 'network') ? $commentww : '') )); } } @@ -321,7 +303,7 @@ class Item extends BaseObject { $item_result['children'] = array(); if(count($item['children'])) { - $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $page_writeable, $mode, $profile_owner, ($thread_level + 1)); + $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $this->is_page_writeable(), $this->get_mode(), $this->get_profile_owner(), ($thread_level + 1)); } $item_result['private'] = $item['private']; $item_result['toplevel'] = ($toplevelpost ? 'toplevel_item' : ''); @@ -387,7 +369,46 @@ class Item extends BaseObject { if($this->get_mode() == $mode) return; - + switch($mode) { + case 'network': + case 'notes': + $this->profile_owner = local_user(); + $this->page_writeable = true; + break; + case 'profile': + $this->profile_owner = $a->profile['profile_uid']; + $this->page_writeable = can_write_wall($a,$this->profile_owner); + break; + case 'display': + $this->profile_owner = $a->profile['uid']; + $this->page_writeable = can_write_wall($a,$this->profile_owner); + break; + default: + logger('[ERROR] Item::set_mode : Unhandled mode ('. $mode .').', LOGGER_DEBUG); + return false; + break; + } + } + + /** + * Get mode + */ + private function get_mode() { + return $this->mode; + } + + /** + * Get profile owner + */ + private function get_profile_owner() { + return $this->profile_owner; + } + + /** + * Get page writable + */ + private function is_page_writeable() { + return $this->page_writeable; } } ?> From 56cae53e509cc88f0c714e9e1a3699a4ed214636 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 11 Aug 2012 16:56:10 +0200 Subject: [PATCH 04/55] Item: new methods get|set_template --- object/Conversation.php | 4 ++-- object/Item.php | 32 +++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/object/Conversation.php b/object/Conversation.php index 0ce016649..6675a0053 100644 --- a/object/Conversation.php +++ b/object/Conversation.php @@ -50,13 +50,13 @@ class Conversation extends BaseObject { * _ The data requested on success * _ false on failure */ - public function get_template_data($cmnt_tpl) { + public function get_template_data($cmnt_tpl, $alike, $dlike) { $result = array(); foreach($this->threads as $item) { if($item->get_network() === NETWORK_MAIL && local_user() != $item->get_uid()) continue; - $item_data = $item->get_template_data($cmnt_tpl, $this->mode); + $item_data = $item->get_template_data($cmnt_tpl, $this->mode, $alike, $dlike); if(!$item_data) { logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG); return false; diff --git a/object/Item.php b/object/Item.php index 796f9cae6..b96b7e44f 100644 --- a/object/Item.php +++ b/object/Item.php @@ -4,6 +4,7 @@ if(class_exists('Item')) require_once('object/BaseObject.php'); require_once('include/text.php'); +require_once('boot.php'); /** * An item @@ -21,7 +22,7 @@ class Item extends BaseObject { public function __construct($data) { $this->data = $data; - $this->template = $this->available_templates['wall']; + $this->set_template('wall'); } /** @@ -31,7 +32,7 @@ class Item extends BaseObject { * _ The data requested on success * _ false on failure */ - public function get_template_data($cmnt_tpl, $mode) { + public function get_template_data($cmnt_tpl, $mode, $alike, $dlike) { $result = array(); $a = $this->get_app(); @@ -40,9 +41,6 @@ class Item extends BaseObject { $item = $this->get_data(); - $alike = array(); - $dlike = array(); - $template = $this->available_templates['wall']; $comment = ''; $commentww = ''; $sparkle = ''; @@ -130,7 +128,7 @@ class Item extends BaseObject { $owner_url = zrl($a->page_contact['url']); $owner_photo = $a->page_contact['thumb']; $owner_name = $a->page_contact['name']; - $template = $this->available_templates['wall2wall']; + $this->set_template('wall2wall'); $commentww = 'ww'; } } @@ -154,7 +152,7 @@ class Item extends BaseObject { $owner_url = $item['owner-link']; $owner_photo = $item['owner-avatar']; $owner_name = $item['owner-name']; - $template = $this->available_templates['wall2wall']; + $this->set_template('wall2wall'); $commentww = 'ww'; // If it is our contact, use a friendly redirect link if((link_compare($item['owner-link'],$item['url'])) @@ -252,7 +250,7 @@ class Item extends BaseObject { 'comment_firstcollapsed' => $firstcollapsed, 'comment_lastcollapsed' => $lastcollapsed, // template to use to render item (wall, walltowall, search) - 'template' => $template, + 'template' => $this->get_template(), 'type' => implode("",array_slice(explode("/",$item['verb']),-1)), 'tags' => $tags, @@ -303,7 +301,7 @@ class Item extends BaseObject { $item_result['children'] = array(); if(count($item['children'])) { - $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $this->is_page_writeable(), $this->get_mode(), $this->get_profile_owner(), ($thread_level + 1)); + $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $this->is_page_writeable(), $this->get_mode(), $this->get_profile_owner(), $alike, $dlike, ($thread_level + 1)); } $item_result['private'] = $item['private']; $item_result['toplevel'] = ($toplevelpost ? 'toplevel_item' : ''); @@ -410,5 +408,21 @@ class Item extends BaseObject { private function is_page_writeable() { return $this->page_writeable; } + + /** + * Set template + */ + private function set_template($name) { + if(!x($this->available_templates, $name)) + return false; + $this->template = $this->available_templates[$name]; + } + + /** + * Get template + */ + private function get_template() { + return $this->template; + } } ?> From 1ffca59a9ed95bb7bd9c6bf69d8e4392f497da0d Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 11 Aug 2012 17:04:07 +0200 Subject: [PATCH 05/55] Item: new method get_thumb --- object/Item.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/object/Item.php b/object/Item.php index b96b7e44f..c92b5e19e 100644 --- a/object/Item.php +++ b/object/Item.php @@ -49,8 +49,6 @@ class Item extends BaseObject { $dropping = false; $star = false; $isstarred = "unstarred"; - $photo = $item['photo']; - $thumb = $item['thumb']; $indent = ''; $osparkle = ''; $lastcollapsed = false; @@ -99,7 +97,7 @@ class Item extends BaseObject { if(($normalised != 'mailbox') && (x($a->contacts,$normalised))) $profile_avatar = $a->contacts[$normalised]['thumb']; else - $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($thumb)); + $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($this->get_thumb())); $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => ''); call_hooks('render_location',$locate); @@ -334,6 +332,10 @@ class Item extends BaseObject { public function get_uid() { return $this->get_data_value('uid'); } + + public function get_thumb() { + return $this->get_data_value('thumb'); + } /** * Get raw data @@ -352,7 +354,7 @@ class Item extends BaseObject { * _ false on failure */ private function get_data_value($name) { - if(!x($this->data[$name])) { + if(!x($this->data, $name)) { logger('[ERROR] Item::get_data_value : Item has no value name "'. $name .'".', LOGGER_DEBUG); return false; } @@ -413,8 +415,10 @@ class Item extends BaseObject { * Set template */ private function set_template($name) { - if(!x($this->available_templates, $name)) + if(!x($this->available_templates, $name)) { + logger('[ERROR] Item::set_template : Template not available ("'. $name .'").', LOGGER_DEBUG); return false; + } $this->template = $this->available_templates[$name]; } From 531801ff50a20c2b5360cdc005d62e037733dbb6 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 11 Aug 2012 17:09:35 +0200 Subject: [PATCH 06/55] Item: new method is_toplevel --- object/Item.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/object/Item.php b/object/Item.php index c92b5e19e..c89fd7ad7 100644 --- a/object/Item.php +++ b/object/Item.php @@ -19,10 +19,12 @@ class Item extends BaseObject { private $mode = null; private $page_writeable = false; private $profile_owner = 0; + private $toplevel = false; public function __construct($data) { $this->data = $data; $this->set_template('wall'); + $this->toplevel = ($this->get_id() == $this->get_parent()); } /** @@ -55,7 +57,6 @@ class Item extends BaseObject { $firstcollapsed = false; $total_children += count_descendants($item); - $toplevelpost = (($item['id'] == $item['parent']) ? true : false); $item_writeable = (($item['writable'] || $item['self']) ? true : false); $show_comment_box = ((($this->is_page_writeable()) && ($item_writeable)) ? true : false); $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) @@ -115,7 +116,7 @@ class Item extends BaseObject { $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : ''); $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : ''); - if($toplevelpost) { + if($this->is_toplevel()) { if((! $item['self']) && ($this->get_mode() !== 'profile')) { if($item['wall']) { @@ -302,7 +303,7 @@ class Item extends BaseObject { $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $this->is_page_writeable(), $this->get_mode(), $this->get_profile_owner(), $alike, $dlike, ($thread_level + 1)); } $item_result['private'] = $item['private']; - $item_result['toplevel'] = ($toplevelpost ? 'toplevel_item' : ''); + $item_result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : ''); if(get_config('system','thread_allow')) { $item_result['flatten'] = false; @@ -311,7 +312,7 @@ class Item extends BaseObject { else { $item_result['flatten'] = true; $item_result['threaded'] = false; - if(!$toplevelpost) { + if(!$htis->is_toplevel()) { $item_result['comment'] = false; } } @@ -336,6 +337,10 @@ class Item extends BaseObject { public function get_thumb() { return $this->get_data_value('thumb'); } + + public function get_parent() { + return $this->get_data_value('parent'); + } /** * Get raw data @@ -428,5 +433,12 @@ class Item extends BaseObject { private function get_template() { return $this->template; } + + /** + * Check if this is a toplevel post + */ + private function is_toplevel() { + return $this->toplevel; + } } ?> From adbe126d1058ee6f2aaba5bb409adecea9b99ef6 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 11 Aug 2012 17:15:19 +0200 Subject: [PATCH 07/55] Item: new method is_writeable --- object/Item.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/object/Item.php b/object/Item.php index c89fd7ad7..1a88fe36b 100644 --- a/object/Item.php +++ b/object/Item.php @@ -20,11 +20,13 @@ class Item extends BaseObject { private $page_writeable = false; private $profile_owner = 0; private $toplevel = false; + private $writeable = false; public function __construct($data) { $this->data = $data; $this->set_template('wall'); $this->toplevel = ($this->get_id() == $this->get_parent()); + $this->writeable = ($this->get_data_value('writeable') || $this->get_data_value('self')); } /** @@ -57,8 +59,7 @@ class Item extends BaseObject { $firstcollapsed = false; $total_children += count_descendants($item); - $item_writeable = (($item['writable'] || $item['self']) ? true : false); - $show_comment_box = ((($this->is_page_writeable()) && ($item_writeable)) ? true : false); + $show_comment_box = ((($this->is_page_writeable()) && ($this->is_writeable())) ? true : false); $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') @@ -440,5 +441,12 @@ class Item extends BaseObject { private function is_toplevel() { return $this->toplevel; } + + /** + * Check if this is writeable + */ + private function is_writeable() { + return $this->writeable; + } } ?> From e6c55de07010feb137512964ea76d3515157c45e Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 11 Aug 2012 17:39:11 +0200 Subject: [PATCH 08/55] Item: parent/children relationship. get_parent now returns an Item (or null) --- object/Item.php | 83 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/object/Item.php b/object/Item.php index 1a88fe36b..882567894 100644 --- a/object/Item.php +++ b/object/Item.php @@ -21,12 +21,20 @@ class Item extends BaseObject { private $profile_owner = 0; private $toplevel = false; private $writeable = false; + private $children = array(); + private $parent = null; public function __construct($data) { $this->data = $data; $this->set_template('wall'); - $this->toplevel = ($this->get_id() == $this->get_parent()); + $this->toplevel = ($this->get_id() == $this->get_data_value('parent')); $this->writeable = ($this->get_data_value('writeable') || $this->get_data_value('self')); + + // Prepare the children + foreach($data['children'] as $item) { + $child = new Item($item); + $this->add_child($child); + } } /** @@ -338,9 +346,76 @@ class Item extends BaseObject { public function get_thumb() { return $this->get_data_value('thumb'); } - - public function get_parent() { - return $this->get_data_value('parent'); + + /** + * Add a child item + */ + public function add_child($item) { + $item_id = $item->get_id(); + if(!$item_id) { + logger('[ERROR] Item::add_child : Item has no ID!!', LOGGER_DEBUG); + return false; + } + if($this->get_child($item->get_id())) { + logger('[WARN] Item::add_child : Item already exists ('. $item->get_id() .').', LOGGER_DEBUG); + return false; + } + $item->set_parent($this); + $this->children[] = $item; + return end($this->children); + } + + /** + * Get a child by its ID + */ + public function get_child($id) { + foreach($this->get_children() as $child) { + if($child->get_id() == $id) + return $child; + } + return null; + } + + /** + * Get all ou children + */ + public function get_children() { + return $this->children; + } + + /** + * Set our parent + */ + protected function set_parent($item) { + $parent = $this->get_parent(); + if($parent) { + $parent->remove_child($this); + } + $this->parent = $item; + } + + /** + * Remove a child + */ + public function remove_child($item) { + $id = $item->get_id(); + foreach($this->get_children() as $key => $child) { + if($child->get_id() == $id) { + unset($this->children[$key]); + // Reindex the array, in order to make sure there won't be any trouble on loops using count() + $this->children = array_values($this->children); + return true; + } + } + logger('[WARN] Item::remove_child : Item is not a child ('. $id .').', LOGGER_DEBUG); + return false; + } + + /** + * Get parent item + */ + protected function get_parent() { + return $this->parent; } /** From 7c2ed027ff8385ba1618fcde7bcff95803708843 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 11 Aug 2012 17:48:07 +0200 Subject: [PATCH 09/55] Item: new method count_descendants --- object/Item.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/object/Item.php b/object/Item.php index 882567894..a9115ee08 100644 --- a/object/Item.php +++ b/object/Item.php @@ -65,7 +65,7 @@ class Item extends BaseObject { $osparkle = ''; $lastcollapsed = false; $firstcollapsed = false; - $total_children += count_descendants($item); + $total_children = $this->count_descendants(); $show_comment_box = ((($this->is_page_writeable()) && ($this->is_writeable())) ? true : false); $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) @@ -523,5 +523,19 @@ class Item extends BaseObject { private function is_writeable() { return $this->writeable; } + + /** + * Count the total of our descendants + */ + private function count_descendants() { + $children = $this->get_children(); + $total = count($children); + if($total > 0) { + foreach($children as $child) { + $total += $child->count_descendants(); + } + } + return $total; + } } ?> From 1c36d14673c057cb8b49621b0d50d3fd4811f1f9 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 11 Aug 2012 17:51:25 +0200 Subject: [PATCH 10/55] Got of the get_* function about data, use get_data_value instead (except for get_id, which is very conveniant). --- object/Conversation.php | 2 +- object/Item.php | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/object/Conversation.php b/object/Conversation.php index 6675a0053..a42e6d038 100644 --- a/object/Conversation.php +++ b/object/Conversation.php @@ -54,7 +54,7 @@ class Conversation extends BaseObject { $result = array(); foreach($this->threads as $item) { - if($item->get_network() === NETWORK_MAIL && local_user() != $item->get_uid()) + if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) continue; $item_data = $item->get_template_data($cmnt_tpl, $this->mode, $alike, $dlike); if(!$item_data) { diff --git a/object/Item.php b/object/Item.php index a9115ee08..8deabb1b6 100644 --- a/object/Item.php +++ b/object/Item.php @@ -107,7 +107,7 @@ class Item extends BaseObject { if(($normalised != 'mailbox') && (x($a->contacts,$normalised))) $profile_avatar = $a->contacts[$normalised]['thumb']; else - $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($this->get_thumb())); + $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $a->get_cached_avatar_image($this->get_data_value('thumb'))); $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => ''); call_hooks('render_location',$locate); @@ -334,18 +334,6 @@ class Item extends BaseObject { public function get_id() { return $this->get_data_value('id'); } - - public function get_network() { - return $this->get_data_value('network'); - } - - public function get_uid() { - return $this->get_data_value('uid'); - } - - public function get_thumb() { - return $this->get_data_value('thumb'); - } /** * Add a child item @@ -434,7 +422,7 @@ class Item extends BaseObject { * _ value on success * _ false on failure */ - private function get_data_value($name) { + public function get_data_value($name) { if(!x($this->data, $name)) { logger('[ERROR] Item::get_data_value : Item has no value name "'. $name .'".', LOGGER_DEBUG); return false; From 9b6e99a6ba1b502470e99f83575997fea822b01f Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 11 Aug 2012 18:12:35 +0200 Subject: [PATCH 11/55] mode is handled by Conversation --- object/Conversation.php | 58 ++++++++++++++++++++- object/Item.php | 109 ++++++++++++++++------------------------ 2 files changed, 99 insertions(+), 68 deletions(-) diff --git a/object/Conversation.php b/object/Conversation.php index a42e6d038..ca2ed2bb8 100644 --- a/object/Conversation.php +++ b/object/Conversation.php @@ -15,9 +15,62 @@ require_once('include/text.php'); class Conversation extends BaseObject { private $threads = array(); private $mode = null; + private $writeable = false; + private $profile_owner = 0; public function __construct($mode) { - $this->mode = $mode; + $this->set_mode($mode); + } + + /** + * Set the mode we'll be displayed on + */ + private function set_mode($mode) { + if($this->get_mode() == $mode) + return; + + $a = $this->get_app(); + + switch($mode) { + case 'network': + case 'notes': + $this->profile_owner = local_user(); + $this->writeable = true; + break; + case 'profile': + $this->profile_owner = $a->profile['profile_uid']; + $this->writeable = can_write_wall($a,$this->profile_owner); + break; + case 'display': + $this->profile_owner = $a->profile['uid']; + $this->writeable = can_write_wall($a,$this->profile_owner); + break; + default: + logger('[ERROR] Conversation::set_mode : Unhandled mode ('. $mode .').', LOGGER_DEBUG); + return false; + break; + } + } + + /** + * Get mode + */ + public function get_mode() { + return $this->mode; + } + + /** + * Check if page is writeable + */ + public function is_writeable() { + return $this->writeable; + } + + /** + * Get profile owner + */ + public function get_profile_owner() { + return $this->profile_owner; } /** @@ -37,6 +90,7 @@ class Conversation extends BaseObject { logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG); return false; } + $item->set_conversation($this); $this->threads[] = $item; return end($this->threads); } @@ -56,7 +110,7 @@ class Conversation extends BaseObject { foreach($this->threads as $item) { if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) continue; - $item_data = $item->get_template_data($cmnt_tpl, $this->mode, $alike, $dlike); + $item_data = $item->get_template_data($cmnt_tpl, $alike, $dlike); if(!$item_data) { logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG); return false; diff --git a/object/Item.php b/object/Item.php index 8deabb1b6..be07a3db9 100644 --- a/object/Item.php +++ b/object/Item.php @@ -16,13 +16,11 @@ class Item extends BaseObject { 'wall' => 'wall_thread.tpl', 'wall2wall' => 'wallwall_thread.tpl' ); - private $mode = null; - private $page_writeable = false; - private $profile_owner = 0; private $toplevel = false; private $writeable = false; private $children = array(); private $parent = null; + private $conversation = null; public function __construct($data) { $this->data = $data; @@ -44,13 +42,11 @@ class Item extends BaseObject { * _ The data requested on success * _ false on failure */ - public function get_template_data($cmnt_tpl, $mode, $alike, $dlike) { + public function get_template_data($cmnt_tpl, $alike, $dlike) { $result = array(); $a = $this->get_app(); - $this->set_mode($mode); - $item = $this->get_data(); $comment = ''; @@ -67,13 +63,15 @@ class Item extends BaseObject { $firstcollapsed = false; $total_children = $this->count_descendants(); - $show_comment_box = ((($this->is_page_writeable()) && ($this->is_writeable())) ? true : false); + $conv = $this->get_conversation(); + + $show_comment_box = ((($conv->is_writeable()) && ($this->is_writeable())) ? true : false); $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); $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ; - $shareable = ((($this->get_profile_owner() == local_user()) && ($item['private'] != 1)) ? true : false); + $shareable = ((($conv->get_profile_owner() == local_user()) && ($item['private'] != 1)) ? true : false); if(local_user() && link_compare($a->contact['url'],$item['author-link'])) $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit")); else @@ -87,7 +85,7 @@ class Item extends BaseObject { 'delete' => t('Delete'), ); - $filer = (($this->get_profile_owner() == local_user()) ? t("save to folder") : false); + $filer = (($conv->get_profile_owner() == local_user()) ? t("save to folder") : false); $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true); $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']); @@ -126,7 +124,7 @@ class Item extends BaseObject { $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : ''); if($this->is_toplevel()) { - if((! $item['self']) && ($this->get_mode() !== 'profile')) { + if((! $item['self']) && ($conv->get_mode() !== 'profile')) { if($item['wall']) { // On the network page, I am the owner. On the display page it will be the profile owner. @@ -172,7 +170,7 @@ class Item extends BaseObject { $owner_url = zrl($owner_url); } } - if($this->get_profile_owner() == local_user()) { + if($conv->get_profile_owner() == local_user()) { $isstarred = (($item['starred']) ? "starred" : "unstarred"); $star = array( @@ -203,7 +201,7 @@ class Item extends BaseObject { } } - if($this->is_page_writeable()) { + if($conv->is_writeable()) { $buttons = array( 'like' => array( t("I like this \x28toggle\x29"), t("like")), 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")), @@ -220,12 +218,12 @@ class Item extends BaseObject { } $comment = replace_macros($cmnt_tpl,array( '$return_path' => '', - '$jsreload' => (($this->get_mode() === 'display') ? $_SESSION['return_url'] : ''), - '$type' => (($this->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'), + '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''), + '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'), '$id' => $item['item_id'], '$parent' => $item['item_id'], '$qcomment' => $qcomment, - '$profile_uid' => $this->get_profile_owner(), + '$profile_uid' => $conv->get_profile_owner(), '$mylink' => $a->contact['url'], '$mytitle' => t('This is you'), '$myphoto' => $a->contact['thumb'], @@ -241,7 +239,7 @@ class Item extends BaseObject { '$edvideo' => t('Video'), '$preview' => t('Preview'), '$sourceapp' => t($a->sourcename), - '$ww' => (($this->get_mode() === 'network') ? $commentww : '') + '$ww' => (($conv->get_mode() === 'network') ? $commentww : '') )); } } @@ -309,7 +307,7 @@ class Item extends BaseObject { $item_result['children'] = array(); if(count($item['children'])) { - $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $this->is_page_writeable(), $this->get_mode(), $this->get_profile_owner(), $alike, $dlike, ($thread_level + 1)); + $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $conv->is_writeable(), $conv->get_mode(), $conv->get_profile_owner(), $alike, $dlike, ($thread_level + 1)); } $item_result['private'] = $item['private']; $item_result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : ''); @@ -380,6 +378,15 @@ class Item extends BaseObject { $parent->remove_child($this); } $this->parent = $item; + $this->set_conversation($item->get_conversation()); + } + + /** + * Remove our parent + */ + protected function remove_parent() { + $this->parent = null; + $this->conversation = null; } /** @@ -389,6 +396,7 @@ class Item extends BaseObject { $id = $item->get_id(); foreach($this->get_children() as $key => $child) { if($child->get_id() == $id) { + $child->remove_parent(); unset($this->children[$key]); // Reindex the array, in order to make sure there won't be any trouble on loops using count() $this->children = array_values($this->children); @@ -406,6 +414,24 @@ class Item extends BaseObject { return $this->parent; } + /** + * set conversation + */ + public function set_conversation($conv) { + $this->conversation = $conv; + + // Set it on our children too + foreach($this->get_children() as $child) + $child->set_conversation($conv); + } + + /** + * get conversation + */ + public function get_conversation() { + return $this->conversation; + } + /** * Get raw data * @@ -431,55 +457,6 @@ class Item extends BaseObject { return $this->data[$name]; } - /** - * Set the mode we'll be displayed on - */ - private function set_mode($mode) { - if($this->get_mode() == $mode) - return; - - switch($mode) { - case 'network': - case 'notes': - $this->profile_owner = local_user(); - $this->page_writeable = true; - break; - case 'profile': - $this->profile_owner = $a->profile['profile_uid']; - $this->page_writeable = can_write_wall($a,$this->profile_owner); - break; - case 'display': - $this->profile_owner = $a->profile['uid']; - $this->page_writeable = can_write_wall($a,$this->profile_owner); - break; - default: - logger('[ERROR] Item::set_mode : Unhandled mode ('. $mode .').', LOGGER_DEBUG); - return false; - break; - } - } - - /** - * Get mode - */ - private function get_mode() { - return $this->mode; - } - - /** - * Get profile owner - */ - private function get_profile_owner() { - return $this->profile_owner; - } - - /** - * Get page writable - */ - private function is_page_writeable() { - return $this->page_writeable; - } - /** * Set template */ From 5084cff8f482663a33fb0793b3bf4d68287b3533 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 11 Aug 2012 19:23:18 +0200 Subject: [PATCH 12/55] Should fix the like problem --- object/Item.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/object/Item.php b/object/Item.php index be07a3db9..b78d9b220 100644 --- a/object/Item.php +++ b/object/Item.php @@ -116,9 +116,6 @@ class Item extends BaseObject { $tag = trim($tag); if ($tag!="") $tags[] = bbcode($tag); } - - like_puller($a,$item,$alike,'like'); - like_puller($a,$item,$dlike,'dislike'); $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : ''); $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : ''); From 91edb06bcb7bcd86eaaf814bd00971d841f9e06a Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 11 Aug 2012 19:58:57 +0200 Subject: [PATCH 13/55] prepare_threads_body is not used by Item anymore --- object/Item.php | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/object/Item.php b/object/Item.php index b78d9b220..7aaec5c46 100644 --- a/object/Item.php +++ b/object/Item.php @@ -42,7 +42,7 @@ class Item extends BaseObject { * _ The data requested on success * _ false on failure */ - public function get_template_data($cmnt_tpl, $alike, $dlike) { + public function get_template_data($cmnt_tpl, $alike, $dlike, $thread_level=1) { $result = array(); $a = $this->get_app(); @@ -183,19 +183,6 @@ class Item extends BaseObject { } } else { $indent = 'comment'; - // Collapse comments - if(($nb_items > 2) || ($thread_level > 2)) { - if($items_seen == 1) { - $firstcollapsed = true; - } - if($thread_level > 2) { - if($items_seen == $nb_items) - $lastcollapsed = true; - } - else if($items_seen == ($nb_items - 2)) { - $lastcollapsed = true; - } - } } if($conv->is_writeable()) { @@ -297,15 +284,28 @@ class Item extends BaseObject { call_hooks('display_item', $arr); $item_result = $arr['output']; - if($firstcollapsed) { - $item_result['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children ); - $item_result['hide_text'] = t('show more'); - } $item_result['children'] = array(); - if(count($item['children'])) { - $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $conv->is_writeable(), $conv->get_mode(), $conv->get_profile_owner(), $alike, $dlike, ($thread_level + 1)); + $children = $this->get_children(); + $nb_children = count($children); + if($nb_children > 0) { + foreach($this->get_children() as $child) { + $item_result['children'][] = $child->get_template_data($cmnt_tpl, $alike, $dlike, $thread_level + 1); + } + // Collapse + if(($nb_children > 2) || ($thread_level > 1)) { + $item_result['children'][0]['comment_firstcollapsed'] = true; + $item_result['children'][0]['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children ); + $item_result['children'][0]['hide_text'] = t('show more'); + if($thread_level > 1) { + $item_result['children'][$nb_children - 1]['comment_lastcollapsed'] = true; + } + else { + $item_result['children'][$nb_children - 3]['comment_lastcollapsed'] = true; + } + } } + $item_result['private'] = $item['private']; $item_result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : ''); From d603f7667886bb96517cf8c3f4ed1a643ce2774d Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sun, 12 Aug 2012 15:39:21 +0200 Subject: [PATCH 14/55] Some fix on forgotten or useless vars --- object/Conversation.php | 1 + object/Item.php | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/object/Conversation.php b/object/Conversation.php index ca2ed2bb8..634a09397 100644 --- a/object/Conversation.php +++ b/object/Conversation.php @@ -50,6 +50,7 @@ class Conversation extends BaseObject { return false; break; } + $this->mode = $mode; } /** diff --git a/object/Item.php b/object/Item.php index 7aaec5c46..5ed2e2e74 100644 --- a/object/Item.php +++ b/object/Item.php @@ -59,8 +59,6 @@ class Item extends BaseObject { $isstarred = "unstarred"; $indent = ''; $osparkle = ''; - $lastcollapsed = false; - $firstcollapsed = false; $total_children = $this->count_descendants(); $conv = $this->get_conversation(); @@ -236,9 +234,6 @@ class Item extends BaseObject { $body = prepare_body($item,true); $tmp_item = array( - // collapse comments in template. I don't like this much... - 'comment_firstcollapsed' => $firstcollapsed, - 'comment_lastcollapsed' => $lastcollapsed, // template to use to render item (wall, walltowall, search) 'template' => $this->get_template(), From 71f11a9a32ed169b7954bf4ead1eb6e506c71f87 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sun, 12 Aug 2012 16:02:47 +0200 Subject: [PATCH 15/55] Item: new method get_comment_box --- include/conversation.php | 2 +- object/Conversation.php | 4 +- object/Item.php | 105 ++++++++++++++++++++++++--------------- 3 files changed, 68 insertions(+), 43 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 06d06cb5a..8cab95af3 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -870,7 +870,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { } } - $threads = $conv->get_template_data($cmnt_tpl, $alike, $dlike); + $threads = $conv->get_template_data($alike, $dlike); if(!$threads) { logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG); $threads = array(); diff --git a/object/Conversation.php b/object/Conversation.php index 634a09397..d8d14589d 100644 --- a/object/Conversation.php +++ b/object/Conversation.php @@ -105,13 +105,13 @@ class Conversation extends BaseObject { * _ The data requested on success * _ false on failure */ - public function get_template_data($cmnt_tpl, $alike, $dlike) { + public function get_template_data($alike, $dlike) { $result = array(); foreach($this->threads as $item) { if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) continue; - $item_data = $item->get_template_data($cmnt_tpl, $alike, $dlike); + $item_data = $item->get_template_data($alike, $dlike); if(!$item_data) { logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG); return false; diff --git a/object/Item.php b/object/Item.php index 5ed2e2e74..84a74be52 100644 --- a/object/Item.php +++ b/object/Item.php @@ -16,6 +16,7 @@ class Item extends BaseObject { 'wall' => 'wall_thread.tpl', 'wall2wall' => 'wallwall_thread.tpl' ); + private $comment_box_template = 'comment_item.tpl'; private $toplevel = false; private $writeable = false; private $children = array(); @@ -42,14 +43,13 @@ class Item extends BaseObject { * _ The data requested on success * _ false on failure */ - public function get_template_data($cmnt_tpl, $alike, $dlike, $thread_level=1) { + public function get_template_data($alike, $dlike, $thread_level=1) { $result = array(); $a = $this->get_app(); $item = $this->get_data(); - $comment = ''; $commentww = ''; $sparkle = ''; $owner_url = $owner_photo = $owner_name = ''; @@ -63,7 +63,6 @@ class Item extends BaseObject { $conv = $this->get_conversation(); - $show_comment_box = ((($conv->is_writeable()) && ($this->is_writeable())) ? true : false); $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') @@ -189,41 +188,6 @@ class Item extends BaseObject { 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")), ); if ($shareable) $buttons['share'] = array( t('Share this'), t('share')); - - - if($show_comment_box) { - $qc = $qcomment = null; - - if(in_array('qcomment',$a->plugins)) { - $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null); - $qcomment = (($qc) ? explode("\n",$qc) : null); - } - $comment = replace_macros($cmnt_tpl,array( - '$return_path' => '', - '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''), - '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'), - '$id' => $item['item_id'], - '$parent' => $item['item_id'], - '$qcomment' => $qcomment, - '$profile_uid' => $conv->get_profile_owner(), - '$mylink' => $a->contact['url'], - '$mytitle' => t('This is you'), - '$myphoto' => $a->contact['thumb'], - '$comment' => t('Comment'), - '$submit' => t('Submit'), - '$edbold' => t('Bold'), - '$editalic' => t('Italic'), - '$eduline' => t('Underline'), - '$edquote' => t('Quote'), - '$edcode' => t('Code'), - '$edimg' => t('Image'), - '$edurl' => t('Link'), - '$edvideo' => t('Video'), - '$preview' => t('Preview'), - '$sourceapp' => t($a->sourcename), - '$ww' => (($conv->get_mode() === 'network') ? $commentww : '') - )); - } } if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0) @@ -270,7 +234,7 @@ class Item extends BaseObject { 'vote' => $buttons, 'like' => $like, 'dislike' => $dislike, - 'comment' => $comment, + 'comment' => $this->get_comment_box($commentww), 'previewing' => $previewing, 'wait' => t('Please wait'), ); @@ -285,7 +249,7 @@ class Item extends BaseObject { $nb_children = count($children); if($nb_children > 0) { foreach($this->get_children() as $child) { - $item_result['children'][] = $child->get_template_data($cmnt_tpl, $alike, $dlike, $thread_level + 1); + $item_result['children'][] = $child->get_template_data($alike, $dlike, $thread_level + 1); } // Collapse if(($nb_children > 2) || ($thread_level > 1)) { @@ -494,5 +458,66 @@ class Item extends BaseObject { } return $total; } + + /** + * Get the template for the comment box + */ + private function get_comment_box_template() { + return $this->comment_box_template; + } + + /** + * Get the comment box + * + * Returns: + * _ The comment box string (empty if no comment box) + * _ false on failure + */ + private function get_comment_box($ww) { + $comment_box = ''; + $conv = $this->get_conversation(); + $template = get_markup_template($this->get_comment_box_template()); + + if($conv->is_writeable() && $this->is_writeable()) { + $a = $this->get_app(); + $qc = $qcomment = null; + + /* + * Hmmm, code depending on the presence of a particular plugin? + * 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); + $qcomment = (($qc) ? explode("\n",$qc) : null); + } + $comment_box = replace_macros($template,array( + '$return_path' => '', + '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''), + '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'), + '$id' => $this->get_id(), + '$parent' => $this->get_id(), + '$qcomment' => $qcomment, + '$profile_uid' => $conv->get_profile_owner(), + '$mylink' => $a->contact['url'], + '$mytitle' => t('This is you'), + '$myphoto' => $a->contact['thumb'], + '$comment' => t('Comment'), + '$submit' => t('Submit'), + '$edbold' => t('Bold'), + '$editalic' => t('Italic'), + '$eduline' => t('Underline'), + '$edquote' => t('Quote'), + '$edcode' => t('Code'), + '$edimg' => t('Image'), + '$edurl' => t('Link'), + '$edvideo' => t('Video'), + '$preview' => t('Preview'), + '$sourceapp' => t($a->sourcename), + '$ww' => (($conv->get_mode() === 'network') ? $ww : '') + )); + } + + return $comment_box; + } } ?> From 9f57afe160a026d499501d44a9d61d51c92bc8c4 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sun, 12 Aug 2012 16:18:53 +0200 Subject: [PATCH 16/55] Item: new method get_redirect_url --- object/Item.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/object/Item.php b/object/Item.php index 84a74be52..3a2b1fd83 100644 --- a/object/Item.php +++ b/object/Item.php @@ -22,13 +22,19 @@ class Item extends BaseObject { private $children = array(); private $parent = null; private $conversation = null; + private $redirect_url = null; public function __construct($data) { + $a = $this->get_app(); + $this->data = $data; $this->set_template('wall'); $this->toplevel = ($this->get_id() == $this->get_data_value('parent')); $this->writeable = ($this->get_data_value('writeable') || $this->get_data_value('self')); + $ssl_state = ((local_user()) ? true : false); + $this->redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $this->get_data_value('cid') ; + // Prepare the children foreach($data['children'] as $item) { $child = new Item($item); @@ -67,7 +73,6 @@ class Item extends BaseObject { || strlen($item['deny_cid']) || strlen($item['deny_gid'])))) ? t('Private Message') : false); - $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ; $shareable = ((($conv->get_profile_owner() == local_user()) && ($item['private'] != 1)) ? true : false); if(local_user() && link_compare($a->contact['url'],$item['author-link'])) $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit")); @@ -157,7 +162,7 @@ class Item extends BaseObject { // If it is our contact, use a friendly redirect link if((link_compare($item['owner-link'],$item['url'])) && ($item['network'] === NETWORK_DFRN)) { - $owner_url = $redirect_url; + $owner_url = $this->get_redirect_url(); $osparkle = ' sparkle'; } else @@ -205,7 +210,7 @@ class Item extends BaseObject { 'tags' => $tags, 'body' => template_escape($body), 'text' => strip_tags(template_escape($body)), - 'id' => $item['item_id'], + 'id' => $this->get_id(), 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])), 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $owner_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])), 'to' => t('to'), @@ -519,5 +524,9 @@ class Item extends BaseObject { return $comment_box; } + + private function get_redirect_url() { + return $this->redirect_url; + } } ?> From 4e4774ff4ffca4ec31de3c92117eb53508739423 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sun, 12 Aug 2012 16:26:37 +0200 Subject: [PATCH 17/55] Improved get_comment_box --- object/Item.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/object/Item.php b/object/Item.php index 3a2b1fd83..0ddafff2a 100644 --- a/object/Item.php +++ b/object/Item.php @@ -36,9 +36,11 @@ class Item extends BaseObject { $this->redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $this->get_data_value('cid') ; // Prepare the children - foreach($data['children'] as $item) { - $child = new Item($item); - $this->add_child($child); + if(count($data['children'])) { + foreach($data['children'] as $item) { + $child = new Item($item); + $this->add_child($child); + } } } @@ -280,9 +282,6 @@ class Item extends BaseObject { else { $item_result['flatten'] = true; $item_result['threaded'] = false; - if(!$htis->is_toplevel()) { - $item_result['comment'] = false; - } } $result = $item_result; @@ -479,6 +478,10 @@ class Item extends BaseObject { * _ false on failure */ private function get_comment_box($ww) { + if(!$this->is_toplevel() && !get_config('system','thread_allow')) { + return ''; + } + $comment_box = ''; $conv = $this->get_conversation(); $template = get_markup_template($this->get_comment_box_template()); From c8cf87efc419a21b1e546d25d5d25205e7e0ec9d Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sun, 12 Aug 2012 16:32:02 +0200 Subject: [PATCH 18/55] rename $item_result to $result --- object/Item.php | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/object/Item.php b/object/Item.php index 0ddafff2a..ecf7aba59 100644 --- a/object/Item.php +++ b/object/Item.php @@ -249,42 +249,40 @@ class Item extends BaseObject { $arr = array('item' => $item, 'output' => $tmp_item); call_hooks('display_item', $arr); - $item_result = $arr['output']; + $result = $arr['output']; - $item_result['children'] = array(); + $result['children'] = array(); $children = $this->get_children(); $nb_children = count($children); if($nb_children > 0) { foreach($this->get_children() as $child) { - $item_result['children'][] = $child->get_template_data($alike, $dlike, $thread_level + 1); + $result['children'][] = $child->get_template_data($alike, $dlike, $thread_level + 1); } // Collapse if(($nb_children > 2) || ($thread_level > 1)) { - $item_result['children'][0]['comment_firstcollapsed'] = true; - $item_result['children'][0]['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children ); - $item_result['children'][0]['hide_text'] = t('show more'); + $result['children'][0]['comment_firstcollapsed'] = true; + $result['children'][0]['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children ); + $result['children'][0]['hide_text'] = t('show more'); if($thread_level > 1) { - $item_result['children'][$nb_children - 1]['comment_lastcollapsed'] = true; + $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true; } else { - $item_result['children'][$nb_children - 3]['comment_lastcollapsed'] = true; + $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true; } } } - $item_result['private'] = $item['private']; - $item_result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : ''); + $result['private'] = $item['private']; + $result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : ''); if(get_config('system','thread_allow')) { - $item_result['flatten'] = false; - $item_result['threaded'] = true; + $result['flatten'] = false; + $result['threaded'] = true; } else { - $item_result['flatten'] = true; - $item_result['threaded'] = false; + $result['flatten'] = true; + $result['threaded'] = false; } - - $result = $item_result; return $result; } From b1a801fe611dd79a7ecfea7f84369027c60da845 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sun, 12 Aug 2012 17:20:38 +0200 Subject: [PATCH 19/55] Item: new methods check_wall_to_wall, is_wall_to_wall, get_owner_url, get_owner_photo, get_owner_name --- object/Item.php | 152 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 101 insertions(+), 51 deletions(-) diff --git a/object/Item.php b/object/Item.php index ecf7aba59..57a7ec0b2 100644 --- a/object/Item.php +++ b/object/Item.php @@ -23,6 +23,10 @@ class Item extends BaseObject { private $parent = null; private $conversation = null; private $redirect_url = null; + private $owner_url = ''; + private $owner_photo = ''; + private $owner_name = ''; + private $wall_to_wall = false; public function __construct($data) { $a = $this->get_app(); @@ -60,7 +64,6 @@ class Item extends BaseObject { $commentww = ''; $sparkle = ''; - $owner_url = $owner_photo = $owner_name = ''; $buttons = ''; $dropping = false; $star = false; @@ -124,53 +127,16 @@ class Item extends BaseObject { $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : ''); $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : ''); + /* + * We should avoid doing this all the time, but it depends on the conversation mode + * And the conv mode may change when we change the conv, or it changes its mode + * Maybe we should establish a way to be notified about conversation changes + */ + $this->check_wall_to_wall(); + if($this->is_wall_to_wall() && ($this->get_owner_url() == $this->get_redirect_url())) + $osparkle = ' sparkle'; + if($this->is_toplevel()) { - if((! $item['self']) && ($conv->get_mode() !== 'profile')) { - if($item['wall']) { - - // 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. - - $owner_url = zrl($a->page_contact['url']); - $owner_photo = $a->page_contact['thumb']; - $owner_name = $a->page_contact['name']; - $this->set_template('wall2wall'); - $commentww = 'ww'; - } - } - else if($item['owner-link']) { - - $owner_linkmatch = (($item['owner-link']) && link_compare($item['owner-link'],$item['author-link'])); - $alias_linkmatch = (($item['alias']) && link_compare($item['alias'],$item['author-link'])); - $owner_namematch = (($item['owner-name']) && $item['owner-name'] == $item['author-name']); - 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 - // 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. - - // But it could be somebody else with the same name. It just isn't highly likely. - - - $owner_url = $item['owner-link']; - $owner_photo = $item['owner-avatar']; - $owner_name = $item['owner-name']; - $this->set_template('wall2wall'); - $commentww = 'ww'; - // If it is our contact, use a friendly redirect link - if((link_compare($item['owner-link'],$item['url'])) - && ($item['network'] === NETWORK_DFRN)) { - $owner_url = $this->get_redirect_url(); - $osparkle = ' sparkle'; - } - else - $owner_url = zrl($owner_url); - } - } if($conv->get_profile_owner() == local_user()) { $isstarred = (($item['starred']) ? "starred" : "unstarred"); @@ -214,7 +180,7 @@ class Item extends BaseObject { 'text' => strip_tags(template_escape($body)), 'id' => $this->get_id(), 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])), - 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $owner_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])), + 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $this->get_owner_name(), ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])), 'to' => t('to'), 'wall' => t('Wall-to-Wall'), 'vwall' => t('via Wall-To-Wall:'), @@ -229,9 +195,9 @@ class Item extends BaseObject { 'lock' => $lock, 'location' => template_escape($location), 'indent' => $indent, - 'owner_url' => $owner_url, - 'owner_photo' => $owner_photo, - 'owner_name' => template_escape($owner_name), + 'owner_url' => $this->get_owner_url(), + 'owner_photo' => $this->get_owner_photo(), + 'owner_name' => template_escape($this->get_owner_name()), 'plink' => get_plink($item), 'edpost' => $edpost, 'isstarred' => $isstarred, @@ -376,6 +342,8 @@ class Item extends BaseObject { * set conversation */ public function set_conversation($conv) { + $previous_mode = ($this->conversation ? $this->conversation->get_mode() : ''); + $this->conversation = $conv; // Set it on our children too @@ -483,6 +451,9 @@ class Item extends BaseObject { $comment_box = ''; $conv = $this->get_conversation(); $template = get_markup_template($this->get_comment_box_template()); + $ww = ''; + if( ($conv->get_mode() === 'network') && $this->is_wall_to_wall() ) + $ww = 'ww'; if($conv->is_writeable() && $this->is_writeable()) { $a = $this->get_app(); @@ -529,5 +500,84 @@ class Item extends BaseObject { private function get_redirect_url() { return $this->redirect_url; } + + /** + * Check if we are a wall to wall item and set the relevant properties + */ + protected function check_wall_to_wall() { + $a = $this->get_app(); + $conv = $this->get_conversation(); + $this->wall_to_wall = false; + + if($this->is_toplevel()) { + if( (! $this->get_data_value('self')) && ($conv->get_mode() !== 'profile')) { + if($this->get_data_value('wall')) { + + // 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. + + $this->owner_url = zrl($a->page_contact['url']); + $this->owner_photo = $a->page_contact['thumb']; + $this->owner_name = $a->page_contact['name']; + $this->set_template('wall2wall'); + $this->wall_to_wall = true; + } + } + else if($this->get_data_value('owner-link')) { + + $owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link'))); + $alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link'))); + $owner_namematch = (($this->get_data_value('owner-name')) && $this->get_data_value('owner-name') == $this->get_data_value('author-name')); + 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 + // 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. + + // 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->set_template('wall2wall'); + $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'))) + && ($this->get_data_value('network') === NETWORK_DFRN)) { + $this->owner_url = $this->get_redirect_url(); + } + else + $this->owner_url = zrl($this->get_data_value('owner-link')); + } + } + } + + if(!$this->wall_to_wall) { + $this->set_template('wall'); + $this->owner_url = ''; + $this->owner_photo = ''; + $this->owner_name = ''; + } + } + + private function is_wall_to_wall() { + return $this->wall_to_wall; + } + + private function get_owner_url() { + return $this->owner_url; + } + + private function get_owner_photo() { + return $this->owner_photo; + } + + private function get_owner_name() { + return $this->owner_name; + } } ?> From d4f44b15304eba0f2365d177471299beec192796 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sun, 12 Aug 2012 17:34:02 +0200 Subject: [PATCH 20/55] Some fixes --- object/Item.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/object/Item.php b/object/Item.php index 57a7ec0b2..0639e4db7 100644 --- a/object/Item.php +++ b/object/Item.php @@ -133,6 +133,7 @@ class Item extends BaseObject { * Maybe we should establish a way to be notified about conversation changes */ $this->check_wall_to_wall(); + if($this->is_wall_to_wall() && ($this->get_owner_url() == $this->get_redirect_url())) $osparkle = ' sparkle'; @@ -171,7 +172,6 @@ class Item extends BaseObject { $body = prepare_body($item,true); $tmp_item = array( - // template to use to render item (wall, walltowall, search) 'template' => $this->get_template(), 'type' => implode("",array_slice(explode("/",$item['verb']),-1)), @@ -207,7 +207,7 @@ class Item extends BaseObject { 'vote' => $buttons, 'like' => $like, 'dislike' => $dislike, - 'comment' => $this->get_comment_box($commentww), + 'comment' => $this->get_comment_box(), 'previewing' => $previewing, 'wait' => t('Please wait'), ); @@ -221,7 +221,7 @@ class Item extends BaseObject { $children = $this->get_children(); $nb_children = count($children); if($nb_children > 0) { - foreach($this->get_children() as $child) { + foreach($children as $child) { $result['children'][] = $child->get_template_data($alike, $dlike, $thread_level + 1); } // Collapse @@ -443,7 +443,7 @@ class Item extends BaseObject { * _ The comment box string (empty if no comment box) * _ false on failure */ - private function get_comment_box($ww) { + private function get_comment_box() { if(!$this->is_toplevel() && !get_config('system','thread_allow')) { return ''; } From 82d779a33b287699cb1e543d384445422e50710f Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sun, 12 Aug 2012 17:46:02 +0200 Subject: [PATCH 21/55] Conversation and Item now handles (dis)like as they should --- include/conversation.php | 9 +++++++++ object/Conversation.php | 12 ++++++++++++ object/Item.php | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/include/conversation.php b/include/conversation.php index 19ca0dc4c..2c1c27469 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -862,9 +862,18 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $threads = array(); foreach($items as $item) { + // Can we put this after the visibility check? like_puller($a,$item,$alike,'like'); like_puller($a,$item,$dlike,'dislike'); + // Only add what is visible + if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { + continue; + } + if($item['verb'] === ACTIVITY_LIKE || $item['verb'] === ACTIVITY_DISLIKE) { + continue; + } + if($item['id'] == $item['parent']) { $item_object = new Item($item); $conv->add_thread($item_object); diff --git a/object/Conversation.php b/object/Conversation.php index d8d14589d..b9b0cb74c 100644 --- a/object/Conversation.php +++ b/object/Conversation.php @@ -91,6 +91,18 @@ class Conversation extends BaseObject { logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG); return false; } + + /* + * Only add will be displayed + */ + if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) { + logger('[WARN] Conversation::add_thread : Thread is a mail ('. $item->get_id() .').', LOGGER_DEBUG); + return false; + } + if($item->get_data_value('verb') === ACTIVITY_LIKE || $item->get_data_value('verb') === ACTIVITY_DISLIKE) { + logger('[WARN] Conversation::add_thread : Thread is a (dis)like ('. $item->get_id() .').', LOGGER_DEBUG); + return false; + } $item->set_conversation($this); $this->threads[] = $item; return end($this->threads); diff --git a/object/Item.php b/object/Item.php index 0639e4db7..7f883b41d 100644 --- a/object/Item.php +++ b/object/Item.php @@ -42,6 +42,15 @@ class Item extends BaseObject { // Prepare the children if(count($data['children'])) { foreach($data['children'] as $item) { + /* + * Only add will be displayed + */ + if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { + continue; + } + if($item['verb'] === ACTIVITY_LIKE || $item['verb'] === ACTIVITY_DISLIKE) { + continue; + } $child = new Item($item); $this->add_child($child); } @@ -270,6 +279,18 @@ class Item extends BaseObject { logger('[WARN] Item::add_child : Item already exists ('. $item->get_id() .').', LOGGER_DEBUG); return false; } + /* + * Only add will be displayed + */ + if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) { + logger('[WARN] Item::add_child : Item is a mail ('. $item->get_id() .').', LOGGER_DEBUG); + return false; + } + if($item->get_data_value('verb') === ACTIVITY_LIKE || $item->get_data_value('verb') === ACTIVITY_DISLIKE) { + logger('[WARN] Item::add_child : Item is a (dis)like ('. $item->get_id() .').', LOGGER_DEBUG); + return false; + } + $item->set_parent($this); $this->children[] = $item; return end($this->children); From cc4361fddf6c77839a7e252a3bcbf2ea48a86f90 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sun, 12 Aug 2012 20:11:14 +0200 Subject: [PATCH 22/55] Problem with comment box, debug. --- object/Item.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/object/Item.php b/object/Item.php index 7f883b41d..2505b8aee 100644 --- a/object/Item.php +++ b/object/Item.php @@ -477,6 +477,8 @@ class Item extends BaseObject { $ww = 'ww'; if($conv->is_writeable() && $this->is_writeable()) { + logger('[DEBUG] Item::get_comment_box : Comment box is visible.', LOGGER_DEBUG); + $a = $this->get_app(); $qc = $qcomment = null; @@ -514,6 +516,9 @@ class Item extends BaseObject { '$ww' => (($conv->get_mode() === 'network') ? $ww : '') )); } + else { + logger('[DEBUG] Item::get_comment_box : Comment box is NOT visible. Conv: '. ($conv->is_writeable() ? 'yes' : 'no') .' Item: '. ($this->is_writeable() ? 'yes' : 'no'), LOGGER_DEBUG); + } return $comment_box; } From 429870015fc9b1d94b24234152ad236f433e7f5a Mon Sep 17 00:00:00 2001 From: Domovoy Date: Fri, 17 Aug 2012 16:20:28 +0200 Subject: [PATCH 23/55] Comments on friends are back (stupid typo) --- include/conversation.php | 1 - object/Item.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 2c1c27469..e45495a44 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -885,7 +885,6 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG); $threads = array(); } - logger('[DEBUG] conversation : $threads = '. print_r($threads, true), LOGGER_DEBUG); } } diff --git a/object/Item.php b/object/Item.php index 2505b8aee..933b9825a 100644 --- a/object/Item.php +++ b/object/Item.php @@ -34,7 +34,7 @@ class Item extends BaseObject { $this->data = $data; $this->set_template('wall'); $this->toplevel = ($this->get_id() == $this->get_data_value('parent')); - $this->writeable = ($this->get_data_value('writeable') || $this->get_data_value('self')); + $this->writeable = ($this->get_data_value('writable') || $this->get_data_value('self')); $ssl_state = ((local_user()) ? true : false); $this->redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $this->get_data_value('cid') ; From 441c6d79e36e389e1cc747c99eeeabdee34c5233 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Fri, 17 Aug 2012 16:40:41 +0200 Subject: [PATCH 24/55] Use correct english --- object/Conversation.php | 14 +++++++------- object/Item.php | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/object/Conversation.php b/object/Conversation.php index b9b0cb74c..f4f9c0972 100644 --- a/object/Conversation.php +++ b/object/Conversation.php @@ -15,7 +15,7 @@ require_once('include/text.php'); class Conversation extends BaseObject { private $threads = array(); private $mode = null; - private $writeable = false; + private $writable = false; private $profile_owner = 0; public function __construct($mode) { @@ -35,15 +35,15 @@ class Conversation extends BaseObject { case 'network': case 'notes': $this->profile_owner = local_user(); - $this->writeable = true; + $this->writable = true; break; case 'profile': $this->profile_owner = $a->profile['profile_uid']; - $this->writeable = can_write_wall($a,$this->profile_owner); + $this->writable = can_write_wall($a,$this->profile_owner); break; case 'display': $this->profile_owner = $a->profile['uid']; - $this->writeable = can_write_wall($a,$this->profile_owner); + $this->writable = can_write_wall($a,$this->profile_owner); break; default: logger('[ERROR] Conversation::set_mode : Unhandled mode ('. $mode .').', LOGGER_DEBUG); @@ -61,10 +61,10 @@ class Conversation extends BaseObject { } /** - * Check if page is writeable + * Check if page is writable */ - public function is_writeable() { - return $this->writeable; + public function is_writable() { + return $this->writable; } /** diff --git a/object/Item.php b/object/Item.php index 933b9825a..01e117ff7 100644 --- a/object/Item.php +++ b/object/Item.php @@ -18,7 +18,7 @@ class Item extends BaseObject { ); private $comment_box_template = 'comment_item.tpl'; private $toplevel = false; - private $writeable = false; + private $writable = false; private $children = array(); private $parent = null; private $conversation = null; @@ -34,7 +34,7 @@ class Item extends BaseObject { $this->data = $data; $this->set_template('wall'); $this->toplevel = ($this->get_id() == $this->get_data_value('parent')); - $this->writeable = ($this->get_data_value('writable') || $this->get_data_value('self')); + $this->writable = ($this->get_data_value('writable') || $this->get_data_value('self')); $ssl_state = ((local_user()) ? true : false); $this->redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $this->get_data_value('cid') ; @@ -165,7 +165,7 @@ class Item extends BaseObject { $indent = 'comment'; } - if($conv->is_writeable()) { + if($conv->is_writable()) { $buttons = array( 'like' => array( t("I like this \x28toggle\x29"), t("like")), 'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")), @@ -430,10 +430,10 @@ class Item extends BaseObject { } /** - * Check if this is writeable + * Check if this is writable */ - private function is_writeable() { - return $this->writeable; + private function is_writable() { + return $this->writable; } /** @@ -476,7 +476,7 @@ class Item extends BaseObject { if( ($conv->get_mode() === 'network') && $this->is_wall_to_wall() ) $ww = 'ww'; - if($conv->is_writeable() && $this->is_writeable()) { + if($conv->is_writable() && $this->is_writable()) { logger('[DEBUG] Item::get_comment_box : Comment box is visible.', LOGGER_DEBUG); $a = $this->get_app(); @@ -517,7 +517,7 @@ class Item extends BaseObject { )); } else { - logger('[DEBUG] Item::get_comment_box : Comment box is NOT visible. Conv: '. ($conv->is_writeable() ? 'yes' : 'no') .' Item: '. ($this->is_writeable() ? 'yes' : 'no'), LOGGER_DEBUG); + logger('[DEBUG] Item::get_comment_box : Comment box is NOT visible. Conv: '. ($conv->is_writable() ? 'yes' : 'no') .' Item: '. ($this->is_writable() ? 'yes' : 'no'), LOGGER_DEBUG); } return $comment_box; From 17f9fcaec960644d0168da769abd81ec774c56dd Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 18 Aug 2012 17:17:33 +0200 Subject: [PATCH 25/55] Checks done on topmost parent in local_delivery, closes #10 --- include/items.php | 40 +++++++++++++++++++++++++--------------- object/Item.php | 7 +------ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/include/items.php b/include/items.php index 8de6f7cc8..a2b0fe053 100755 --- a/include/items.php +++ b/include/items.php @@ -2617,22 +2617,32 @@ function local_delivery($importer,$data) { // Specifically, the recipient? $is_a_remote_comment = false; - - // POSSIBLE CLEANUP --> Why select so many fields when only forum_mode and wall are used? - $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `item`.`forum_mode`,`item`.`origin`,`item`.`wall`, - `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item` - LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `item`.`uri` = '%s' AND (`item`.`parent-uri` = '%s' or `item`.`thr-parent` = '%s') - AND `item`.`uid` = %d - $sql_extra + $top_uri = $parent_uri; + + $r = q("select `item`.`parent-uri` from `item` + WHERE `item`.`uri` = '%s' LIMIT 1", - dbesc($parent_uri), - dbesc($parent_uri), - dbesc($parent_uri), - intval($importer['importer_uid']) + dbesc($parent_uri) ); - if($r && count($r)) - $is_a_remote_comment = true; + if($r && count($r)) { + $top_uri = $r[0]['parent-uri']; + + // POSSIBLE CLEANUP --> Why select so many fields when only forum_mode and wall are used? + $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `item`.`forum_mode`,`item`.`origin`,`item`.`wall`, + `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item` + LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + WHERE `item`.`uri` = '%s' AND (`item`.`parent-uri` = '%s' or `item`.`thr-parent` = '%s') + AND `item`.`uid` = %d + $sql_extra + LIMIT 1", + dbesc($top_uri), + dbesc($top_uri), + dbesc($top_uri), + intval($importer['importer_uid']) + ); + if($r && count($r)) + $is_a_remote_comment = true; + } // Does this have the characteristics of a community or private group comment? // If it's a reply to a wall post on a community/prvgroup page it's a @@ -2936,7 +2946,7 @@ function local_delivery($importer,$data) { if(!x($datarray['type']) || $datarray['type'] != 'activity') { $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0", - dbesc($parent_uri), + dbesc($top_uri), intval($importer['importer_uid']) ); diff --git a/object/Item.php b/object/Item.php index 01e117ff7..bfd2db711 100644 --- a/object/Item.php +++ b/object/Item.php @@ -396,7 +396,7 @@ class Item extends BaseObject { * _ false on failure */ public function get_data_value($name) { - if(!x($this->data, $name)) { + if(!isset($this->data[$name])) { logger('[ERROR] Item::get_data_value : Item has no value name "'. $name .'".', LOGGER_DEBUG); return false; } @@ -477,8 +477,6 @@ class Item extends BaseObject { $ww = 'ww'; if($conv->is_writable() && $this->is_writable()) { - logger('[DEBUG] Item::get_comment_box : Comment box is visible.', LOGGER_DEBUG); - $a = $this->get_app(); $qc = $qcomment = null; @@ -516,9 +514,6 @@ class Item extends BaseObject { '$ww' => (($conv->get_mode() === 'network') ? $ww : '') )); } - else { - logger('[DEBUG] Item::get_comment_box : Comment box is NOT visible. Conv: '. ($conv->is_writable() ? 'yes' : 'no') .' Item: '. ($this->is_writable() ? 'yes' : 'no'), LOGGER_DEBUG); - } return $comment_box; } From 8efe4077d3ac2db458de54eda532227f1b52dda1 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 18 Aug 2012 17:36:38 +0200 Subject: [PATCH 26/55] Correct identification of wall-to-wall items (see friendica/friendica@96b9cda43df132ae9d71c6c867504fc29f5a621) --- object/Item.php | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/object/Item.php b/object/Item.php index bfd2db711..b1656ed05 100644 --- a/object/Item.php +++ b/object/Item.php @@ -544,35 +544,35 @@ class Item extends BaseObject { $this->set_template('wall2wall'); $this->wall_to_wall = true; } - } - else if($this->get_data_value('owner-link')) { + else if($this->get_data_value('owner-link')) { - $owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link'))); - $alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link'))); - $owner_namematch = (($this->get_data_value('owner-name')) && $this->get_data_value('owner-name') == $this->get_data_value('author-name')); - if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) { + $owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link'))); + $alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link'))); + $owner_namematch = (($this->get_data_value('owner-name')) && $this->get_data_value('owner-name') == $this->get_data_value('author-name')); + 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 - // 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. + // 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 + // 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. - // 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->set_template('wall2wall'); - $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'))) - && ($this->get_data_value('network') === NETWORK_DFRN)) { - $this->owner_url = $this->get_redirect_url(); + $this->owner_photo = $this->get_data_value('owner-avatar'); + $this->owner_name = $this->get_data_value('owner-name'); + $this->set_template('wall2wall'); + $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'))) + && ($this->get_data_value('network') === NETWORK_DFRN)) { + $this->owner_url = $this->get_redirect_url(); + } + else + $this->owner_url = zrl($this->get_data_value('owner-link')); } - else - $this->owner_url = zrl($this->get_data_value('owner-link')); } } } From fd29ab9629af6a310ef38d4b229069535880c48c Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 18 Aug 2012 17:49:07 +0200 Subject: [PATCH 27/55] Add ability for themes to prevent threading (see friendica/friendica@5e09fc31f51ee1cc207afb3d0771094eac5ed85b) --- object/Item.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/object/Item.php b/object/Item.php index b1656ed05..17b2cbe7b 100644 --- a/object/Item.php +++ b/object/Item.php @@ -216,7 +216,7 @@ class Item extends BaseObject { 'vote' => $buttons, 'like' => $like, 'dislike' => $dislike, - 'comment' => $this->get_comment_box(), + 'comment' => $this->get_comment_box($indent), 'previewing' => $previewing, 'wait' => t('Please wait'), ); @@ -250,7 +250,7 @@ class Item extends BaseObject { $result['private'] = $item['private']; $result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : ''); - if(get_config('system','thread_allow')) { + if(get_config('system','thread_allow') && $a->theme_thread_allow) { $result['flatten'] = false; $result['threaded'] = true; } @@ -464,7 +464,7 @@ class Item extends BaseObject { * _ The comment box string (empty if no comment box) * _ false on failure */ - private function get_comment_box() { + private function get_comment_box($indent) { if(!$this->is_toplevel() && !get_config('system','thread_allow')) { return ''; } @@ -510,6 +510,7 @@ class Item extends BaseObject { '$edurl' => t('Link'), '$edvideo' => t('Video'), '$preview' => t('Preview'), + '$indent' => $indent, '$sourceapp' => t($a->sourcename), '$ww' => (($conv->get_mode() === 'network') ? $ww : '') )); From b558dbbdb282aeedbca501bfa8a314e322722863 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Sat, 18 Aug 2012 17:56:38 +0200 Subject: [PATCH 28/55] add 'thread_level' to $item array (friendica/friendica@fc07f50fd8d2972009bebb3c974cbcbee321c642) --- object/Item.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/object/Item.php b/object/Item.php index 17b2cbe7b..ce4caa9cb 100644 --- a/object/Item.php +++ b/object/Item.php @@ -219,6 +219,7 @@ class Item extends BaseObject { 'comment' => $this->get_comment_box($indent), 'previewing' => $previewing, 'wait' => t('Please wait'), + 'thread_level' => $thread_level ); $arr = array('item' => $item, 'output' => $tmp_item); @@ -280,7 +281,7 @@ class Item extends BaseObject { return false; } /* - * Only add will be displayed + * Only add what will be displayed */ if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) { logger('[WARN] Item::add_child : Item is a mail ('. $item->get_id() .').', LOGGER_DEBUG); From 3e5c711a7215f53166ac5bfed6e738b452675de1 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Thu, 23 Aug 2012 10:54:21 +0200 Subject: [PATCH 29/55] Sync objects with upstream --- object/Item.php | 14 ++++++++++++-- view/wall_thread.tpl | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/object/Item.php b/object/Item.php index ce4caa9cb..be959dcb3 100644 --- a/object/Item.php +++ b/object/Item.php @@ -27,6 +27,7 @@ class Item extends BaseObject { private $owner_photo = ''; private $owner_name = ''; private $wall_to_wall = false; + private $threaded = false; public function __construct($data) { $a = $this->get_app(); @@ -39,6 +40,9 @@ class Item extends BaseObject { $ssl_state = ((local_user()) ? true : false); $this->redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $this->get_data_value('cid') ; + if(get_config('system','thread_allow') && $a->theme_thread_allow) + $this->threaded = true; + // Prepare the children if(count($data['children'])) { foreach($data['children'] as $item) { @@ -200,6 +204,7 @@ class Item extends BaseObject { 'osparkle' => $osparkle, 'sparkle' => $sparkle, 'title' => template_escape($item['title']), + 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), 'lock' => $lock, 'location' => template_escape($location), @@ -251,7 +256,7 @@ class Item extends BaseObject { $result['private'] = $item['private']; $result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : ''); - if(get_config('system','thread_allow') && $a->theme_thread_allow) { + if($this->is_threaded()) { $result['flatten'] = false; $result['threaded'] = true; } @@ -267,6 +272,10 @@ class Item extends BaseObject { return $this->get_data_value('id'); } + public function is_threaded() { + return $this->threaded; + } + /** * Add a child item */ @@ -490,7 +499,8 @@ class Item extends BaseObject { $qcomment = (($qc) ? explode("\n",$qc) : null); } $comment_box = replace_macros($template,array( - '$return_path' => '', + '$return_path' => '', + '$threaded' => $this->is_threaded(), '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''), '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'), '$id' => $this->get_id(), diff --git a/view/wall_thread.tpl b/view/wall_thread.tpl index f64f2e44a..373f01ec8 100644 --- a/view/wall_thread.tpl +++ b/view/wall_thread.tpl @@ -93,10 +93,12 @@ {{ inc $item.template }}{{ endinc }} {{ endfor }} +{{ if $item.comment }} {{ if $item.flatten }}
$item.comment
{{ endif }} +{{ endif }} {{if $item.comment_lastcollapsed}}{{endif}} From c8ba00d7980a2fab2f19fb47e6e44581896972c2 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Thu, 23 Aug 2012 10:56:22 +0200 Subject: [PATCH 30/55] Toplevel items a treaded as non-threaded ones (comment-box is at the bottom) --- object/Item.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/object/Item.php b/object/Item.php index be959dcb3..c7b40070d 100644 --- a/object/Item.php +++ b/object/Item.php @@ -40,7 +40,7 @@ class Item extends BaseObject { $ssl_state = ((local_user()) ? true : false); $this->redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $this->get_data_value('cid') ; - if(get_config('system','thread_allow') && $a->theme_thread_allow) + if(get_config('system','thread_allow') && $a->theme_thread_allow && !$this->is_toplevel()) $this->threaded = true; // Prepare the children From 5dd3e8a990214fb1e4bae6ae8294709cc70f1c05 Mon Sep 17 00:00:00 2001 From: Domovoy Date: Thu, 23 Aug 2012 13:09:35 +0200 Subject: [PATCH 31/55] One click comments on threaded items. comment-wwedit-wrapper and wall-item-outside-wrapper get the additional class "threaded" when applicable. --- view/comment_item.tpl | 9 ++++----- view/theme/darkzero/style.css | 20 +++++++++++++++----- view/theme/darkzero/theme.php | 18 +++++++++++++----- view/theme/duepuntozero/comment_item.tpl | 11 +++++------ view/theme/duepuntozero/style.css | 18 +++++++++++++++--- view/theme/duepuntozero/theme.php | 14 +++++++++++--- view/wall_thread.tpl | 4 ++++ 7 files changed, 67 insertions(+), 27 deletions(-) diff --git a/view/comment_item.tpl b/view/comment_item.tpl index 98173aa30..3de24ca8d 100644 --- a/view/comment_item.tpl +++ b/view/comment_item.tpl @@ -1,10 +1,9 @@ + {{ if $threaded }} +
+ {{ else }}
- {{ if $threaded }} - $comment -