/** * Get data in a form usable by a conversation template * * Returns: * _ The data requested on success * _ false on failure */ public function get_template_data($conv_responses, $thread_level = 1) { $result = array(); $a = $this->get_app(); $item = $this->get_data(); $commentww = ''; $sparkle = ''; $buttons = ''; $dropping = false; $star = false; $isstarred = "unstarred icon-star-empty"; $indent = ''; $osparkle = ''; $total_children = $this->count_descendants(); $unseen_comments = $item['real_uid'] ? 0 : $this->count_unseen_descendants(); $conv = $this->get_conversation(); $observer = $conv->get_observer(); $lock = $item['item_private'] == 1 || $item['uid'] == local_channel() && (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) ? t('Private Message') : false; $shareable = $conv->get_profile_owner() == local_channel() && local_channel() && $item['item_private'] != 1 ? true : false; // allow an exemption for sharing stuff from your private feeds if ($item['author']['xchan_network'] === 'rss') { $shareable = true; } $mode = $conv->get_mode(); if (local_channel() && $observer['xchan_hash'] === $item['author_xchan']) { $edpost = array($a->get_baseurl($ssl_state) . "/editpost/" . $item['id'], t("Edit")); } else { $edpost = false; } if ($observer['xchan_hash'] == $this->get_data_value('author_xchan') || $observer['xchan_hash'] == $this->get_data_value('owner_xchan') || $this->get_data_value('uid') == local_channel()) { $dropping = true; } if (array_key_exists('real_uid', $item)) { $edpost = false; $dropping = false; } if ($dropping) { $drop = array('dropping' => $dropping, 'delete' => t('Delete')); } // FIXME if ($observer_is_pageowner) { $multidrop = array('select' => t('Select')); } $filer = $conv->get_profile_owner() == local_channel() && !array_key_exists('real_uid', $item) ? t("Save to Folder") : false; $profile_avatar = $item['author']['xchan_photo_m']; $profile_link = chanlink_url($item['author']['xchan_url']); $profile_name = $item['author']['xchan_name']; $location = format_location($item); $isevent = false; $attend = null; $canvote = false; // process action responses - e.g. like/dislike/attend/agree/whatever $response_verbs = array('like'); if (feature_enabled($conv->get_profile_owner(), 'dislike')) { $response_verbs[] = 'dislike'; } if ($item['obj_type'] === ACTIVITY_OBJ_EVENT) { $response_verbs[] = 'attendyes'; $response_verbs[] = 'attendno'; $response_verbs[] = 'attendmaybe'; if ($this->is_commentable()) { $isevent = true; $attend = array(t('I will attend'), t('I will not attend'), t('I might attend')); } } $consensus = intval($item['item_consensus']) ? true : false; if ($consensus) { $response_verbs[] = 'agree'; $response_verbs[] = 'disagree'; $response_verbs[] = 'abstain'; if ($this->is_commentable()) { $conlabels = array(t('I agree'), t('I disagree'), t('I abstain')); $canvote = true; } } if (!feature_enabled($conv->get_profile_owner(), 'dislike')) { unset($conv_responses['dislike']); } $responses = get_responses($conv_responses, $response_verbs, $this, $item); $like_count = x($conv_responses['like'], $item['mid']) ? $conv_responses['like'][$item['mid']] : ''; $like_list = x($conv_responses['like'], $item['mid']) ? $conv_responses['like'][$item['mid'] . '-l'] : ''; if (count($like_list) > MAX_LIKERS) { $like_list_part = array_slice($like_list, 0, MAX_LIKERS); array_push($like_list_part, '<a href="#" data-toggle="modal" data-target="#likeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>'); } else { $like_list_part = ''; } $like_button_label = tt('Like', 'Likes', $like_count, 'noun'); if (feature_enabled($conv->get_profile_owner(), 'dislike')) { $dislike_count = x($conv_responses['dislike'], $item['mid']) ? $conv_responses['dislike'][$item['mid']] : ''; $dislike_list = x($conv_responses['dislike'], $item['mid']) ? $conv_responses['dislike'][$item['mid'] . '-l'] : ''; $dislike_button_label = tt('Dislike', 'Dislikes', $dislike_count, 'noun'); if (count($dislike_list) > MAX_LIKERS) { $dislike_list_part = array_slice($dislike_list, 0, MAX_LIKERS); array_push($dislike_list_part, '<a href="#" data-toggle="modal" data-target="#dislikeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>'); } else { $dislike_list_part = ''; } } $showlike = x($conv_responses['like'], $item['mid']) ? format_like($conv_responses['like'][$item['mid']], $conv_responses['like'][$item['mid'] . '-l'], 'like', $item['mid']) : ''; $showdislike = x($conv_responses['dislike'], $item['mid']) && feature_enabled($conv->get_profile_owner(), 'dislike') ? format_like($conv_responses['dislike'][$item['mid']], $conv_responses['dislike'][$item['mid'] . '-l'], 'dislike', $item['mid']) : ''; /* * 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_toplevel()) { // FIXME check this permission if ($conv->get_profile_owner() == local_channel() && !array_key_exists('real_uid', $item)) { // FIXME we don't need all this stuff, some can be done in the template $star = array('do' => t("Add Star"), 'undo' => t("Remove Star"), 'toggle' => t("Toggle Star Status"), 'classdo' => intval($item['item_starred']) ? "hidden" : "", 'classundo' => intval($item['item_starred']) ? "" : "hidden", 'isstarred' => intval($item['item_starred']) ? "starred icon-star" : "unstarred icon-star-empty", 'starred' => t('starred')); } } else { $indent = 'comment'; } $verified = intval($item['item_verified']) ? t('Message signature validated') : ''; $forged = $item['sig'] && !intval($item['item_verified']) ? t('Message signature incorrect') : ''; $unverified = ''; // (($this->is_wall_to_wall() && (! intval($item['item_verified']))) ? t('Message cannot be verified') : ''); // FIXME - check this permission if ($conv->get_profile_owner() == local_channel()) { $tagger = array('tagit' => t("Add Tag"), 'classtagger' => ""); } $has_bookmarks = false; if (is_array($item['term'])) { foreach ($item['term'] as $t) { if ($t['type'] == TERM_BOOKMARK) { $has_bookmarks = true; } } } $has_event = false; if ($item['obj_type'] === ACTIVITY_OBJ_EVENT && $conv->get_profile_owner() == local_channel()) { $has_event = true; } if ($this->is_commentable()) { $like = array(t("I like this (toggle)"), t("like")); $dislike = array(t("I don't like this (toggle)"), t("dislike")); } if ($shareable) { $share = array(t('Share This'), t('share')); } $dreport = ''; $keep_reports = intval(get_config('system', 'expire_delivery_reports')); if ($keep_reports === 0) { $keep_reports = 30; } if (!get_config('system', 'disable_dreport') && strcmp(datetime_convert('UTC', 'UTC', $item['created']), datetime_convert('UTC', 'UTC', "now - {$keep_reports} days")) > 0) { $dreport = t('Delivery Report'); } 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); // $viewthread (below) is only valid in list mode. If this is a channel page, build the thread viewing link // since we can't depend on llink or plink pointing to the right local location. $owner_address = substr($item['owner']['xchan_addr'], 0, strpos($item['owner']['xchan_addr'], '@')); $viewthread = $item['llink']; if ($conv->get_mode() === 'channel') { $viewthread = z_root() . '/channel/' . $owner_address . '?f=&mid=' . $item['mid']; } $comment_count_txt = sprintf(tt('%d comment', '%d comments', $total_children), $total_children); $list_unseen_txt = $unseen_comments ? sprintf('%d unseen', $unseen_comments) : ''; $children = $this->get_children(); $has_tags = $body['tags'] || $body['categories'] || $body['mentions'] || $body['attachments'] || $body['folders'] ? true : false; $tmp_item = array('template' => $this->get_template(), 'mode' => $mode, 'type' => implode("", array_slice(explode("/", $item['verb']), -1)), 'body' => $body['html'], 'tags' => $body['tags'], 'categories' => $body['categories'], 'mentions' => $body['mentions'], 'attachments' => $body['attachments'], 'folders' => $body['folders'], 'text' => strip_tags($body['html']), 'id' => $this->get_id(), 'mid' => $item['mid'], 'isevent' => $isevent, 'attend' => $attend, 'consensus' => $consensus, 'conlabels' => $conlabels, 'canvote' => $canvote, 'linktitle' => sprintf(t('View %s\'s profile - %s'), $profile_name, $item['author']['xchan_addr']), 'olinktitle' => sprintf(t('View %s\'s profile - %s'), $this->get_owner_name(), $item['owner']['xchan_addr']), 'llink' => $item['llink'], 'viewthread' => $viewthread, 'to' => t('to'), 'via' => t('via'), 'wall' => t('Wall-to-Wall'), 'vwall' => t('via Wall-To-Wall:'), 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), 'dreport' => $dreport, 'name' => $profile_name, 'thumb' => $profile_avatar, 'osparkle' => $osparkle, 'sparkle' => $sparkle, 'title' => $item['title'], 'title_tosource' => get_pconfig($conv->get_profile_owner(), 'system', 'title_tosource'), 'ago' => relative_date($item['created']), 'app' => $item['app'], 'str_app' => sprintf(t('from %s'), $item['app']), 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'c'), 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), 'editedtime' => $item['edited'] != $item['created'] ? sprintf(t('last edited: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : '', 'expiretime' => $item['expires'] !== NULL_DATE ? sprintf(t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')) : '', 'lock' => $lock, 'verified' => $verified, 'unverified' => $unverified, 'forged' => $forged, 'location' => $location, 'indent' => $indent, 'owner_url' => $this->get_owner_url(), 'owner_photo' => $this->get_owner_photo(), 'owner_name' => $this->get_owner_name(), 'photo' => $body['photo'], 'event' => $body['event'], 'has_tags' => $has_tags, 'like' => $like, 'dislike' => feature_enabled($conv->get_profile_owner(), 'dislike') ? $dislike : '', 'share' => $share, 'rawmid' => $item['mid'], 'plink' => get_plink($item), 'edpost' => $edpost, 'star' => feature_enabled($conv->get_profile_owner(), 'star_posts') ? $star : '', 'tagger' => feature_enabled($conv->get_profile_owner(), 'commtag') ? $tagger : '', 'filer' => feature_enabled($conv->get_profile_owner(), 'filing') ? $filer : '', 'bookmark' => $conv->get_profile_owner() == local_channel() && local_channel() && $has_bookmarks ? t('Save Bookmarks') : '', 'addtocal' => $has_event ? t('Add to Calendar') : '', 'drop' => $drop, 'multidrop' => feature_enabled($conv->get_profile_owner(), 'multi_delete') ? $multidrop : '', 'unseen_comments' => $unseen_comments, 'comment_count' => $total_children, 'comment_count_txt' => $comment_count_txt, 'list_unseen_txt' => $list_unseen_txt, 'markseen' => t('Mark all seen'), 'responses' => $responses, 'like_count' => $like_count, 'like_list' => $like_list, 'like_list_part' => $like_list_part, 'like_button_label' => $like_button_label, 'like_modal_title' => t('Likes', 'noun'), 'dislike_modal_title' => t('Dislikes', 'noun'), 'dislike_count' => feature_enabled($conv->get_profile_owner(), 'dislike') ? $dislike_count : '', 'dislike_list' => feature_enabled($conv->get_profile_owner(), 'dislike') ? $dislike_list : '', 'dislike_list_part' => feature_enabled($conv->get_profile_owner(), 'dislike') ? $dislike_list_part : '', 'dislike_button_label' => feature_enabled($conv->get_profile_owner(), 'dislike') ? $dislike_button_label : '', 'modal_dismiss' => t('Close'), 'showlike' => $showlike, 'showdislike' => $showdislike, 'comment' => $this->get_comment_box($indent), 'previewing' => $conv->is_preview() ? ' preview ' : '', 'wait' => t('Please wait'), 'thread_level' => $thread_level); $arr = array('item' => $item, 'output' => $tmp_item); call_hooks('display_item', $arr); $result = $arr['output']; $result['children'] = array(); $nb_children = count($children); $visible_comments = get_config('system', 'expanded_comments'); if ($visible_comments === false) { $visible_comments = 3; } if ($this->get_display_mode() === 'normal' && $nb_children > 0) { foreach ($children as $child) { $result['children'][] = $child->get_template_data($conv_responses, $thread_level + 1); } // Collapse if ($nb_children > $visible_comments || $thread_level > 1) { $result['children'][0]['comment_firstcollapsed'] = true; $result['children'][0]['num_comments'] = $comment_count_txt; $result['children'][0]['hide_text'] = t('[+] show all'); if ($thread_level > 1) { $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true; } else { $result['children'][$nb_children - ($visible_comments + 1)]['comment_lastcollapsed'] = true; } } } $result['private'] = $item['item_private']; $result['toplevel'] = $this->is_toplevel() ? 'toplevel_item' : ''; if ($this->is_threaded()) { $result['flatten'] = false; $result['threaded'] = true; } else { $result['flatten'] = true; $result['threaded'] = false; } return $result; }
function print_education() { $text = ""; global $con; $result = mysqli_query($con, "SELECT degree, field_of_study, school, city, region, country, start_date, finish_date, description FROM profile_education WHERE pid = " . $this->id . " ORDER BY finish_date DESC, start_date DESC"); if ($result) { while ($job = mysqli_fetch_array($result)) { $text .= "<div class='education'>"; $text .= "<div class='education-title'><span class='education-role'>" . $job['field_of_study'] . " " . $job['degree'] . "</span>"; if ($job['school'] != "") { $text .= " at <span class='org'>" . $job['school'] . "</span>"; } $text .= "</div>"; $location = format_location($job['city'], $job['region'], $job['country']); if ($location[0] != "") { $text .= "<p class='city-wrapper'><span class='city-label'>" . $location[0] . "</span><span class='city'>" . $location[1] . "</span></p>"; } if ($job['start_date'] !== $job['finish_date']) { $text .= "<p class='period-wrapper'><span class='period-label'>" . __("Period") . "</span><span class='period'>" . format_dates($job['start_date'], $job['finish_date']) . "</span></p>"; } else { $text .= "<p class='period-wrapper'><span class='period-label'>" . __("Date") . "</span><span class='period'>" . format_date($job['start_date']) . "</span></p>"; } $text .= $job['description']; $text .= "</div>"; } } return $text; }
/** * @brief "Render" a conversation or list of items for HTML display. * * There are two major forms of display: * - Sequential or unthreaded ("New Item View" or search results) * - conversation view * * The $mode parameter decides between the various renderings and also * figures out how to determine page owner and other contextual items * that are based on unique features of the calling module. * * @param App &$a * @param array $items * @param string $mode * @param boolean $update * @param string $page_mode default traditional * @param string $prepared_item * @return string */ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $prepared_item = '') { $content_html = ''; $o = ''; require_once 'bbcode.php'; $ssl_state = local_channel() ? true : false; if (local_channel()) { load_pconfig(local_channel(), ''); } $arr_blocked = null; if (local_channel()) { $str_blocked = get_pconfig(local_channel(), 'system', 'blocked'); } if (!local_channel() && $mode == 'network') { $sys = get_sys_channel(); $id = $sys['channel_id']; $str_blocked = get_pconfig($id, 'system', 'blocked'); } if ($str_blocked) { $arr_blocked = explode(',', $str_blocked); for ($x = 0; $x < count($arr_blocked); $x++) { $arr_blocked[$x] = trim($arr_blocked[$x]); } } $profile_owner = 0; $page_writeable = false; $live_update_div = ''; $preview = $page_mode === 'preview' ? true : false; $previewing = $preview ? ' preview ' : ''; if ($mode === 'network') { $profile_owner = local_channel(); $page_writeable = true; if (!$update) { // The special div is needed for liveUpdate to kick in for this page. // We only launch liveUpdate if you aren't filtering in some incompatible // way and also you aren't writing a comment (discovered in javascript). $live_update_div = '<div id="live-network"></div>' . "\r\n" . "<script> var profile_uid = " . $_SESSION['uid'] . "; var netargs = '" . substr($a->cmd, 8) . '?f=' . (x($_GET, 'cid') ? '&cid=' . $_GET['cid'] : '') . (x($_GET, 'search') ? '&search=' . $_GET['search'] : '') . (x($_GET, 'star') ? '&star=' . $_GET['star'] : '') . (x($_GET, 'order') ? '&order=' . $_GET['order'] : '') . (x($_GET, 'bmark') ? '&bmark=' . $_GET['bmark'] : '') . (x($_GET, 'liked') ? '&liked=' . $_GET['liked'] : '') . (x($_GET, 'conv') ? '&conv=' . $_GET['conv'] : '') . (x($_GET, 'spam') ? '&spam=' . $_GET['spam'] : '') . (x($_GET, 'nets') ? '&nets=' . $_GET['nets'] : '') . (x($_GET, 'cmin') ? '&cmin=' . $_GET['cmin'] : '') . (x($_GET, 'cmax') ? '&cmax=' . $_GET['cmax'] : '') . (x($_GET, 'file') ? '&file=' . $_GET['file'] : '') . (x($_GET, 'uri') ? '&uri=' . $_GET['uri'] : '') . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; } } elseif ($mode === 'channel') { $profile_owner = $a->profile['profile_uid']; $page_writeable = $profile_owner == local_channel(); if (!$update) { $tab = notags(trim($_GET['tab'])); if ($tab === 'posts') { // This is ugly, but we can't pass the profile_uid through the session to the ajax updater, // because browser prefetching might change it on us. We have to deliver it with the page. $live_update_div = '<div id="live-channel"></div>' . "\r\n" . "<script> var profile_uid = " . $a->profile['profile_uid'] . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; } } } elseif ($mode === 'display') { $profile_owner = local_channel(); $page_writeable = false; $live_update_div = '<div id="live-display"></div>' . "\r\n"; } elseif ($mode === 'page') { $profile_owner = $a->profile['uid']; $page_writeable = $profile_owner == local_channel(); $live_update_div = '<div id="live-page"></div>' . "\r\n"; } elseif ($mode === 'search') { $live_update_div = '<div id="live-search"></div>' . "\r\n"; } elseif ($mode === 'photos') { $profile_onwer = $a->profile['profile_uid']; $page_writeable = $profile_owner == local_channel(); $live_update_div = '<div id="live-photos"></div>' . "\r\n"; // for photos we've already formatted the top-level item (the photo) $content_html = $a->data['photo_html']; } $page_dropping = local_channel() && local_channel() == $profile_owner ? true : false; if (!feature_enabled($profile_owner, 'multi_delete')) { $page_dropping = false; } $channel = $a->get_channel(); $observer = $a->get_observer(); if ($update) { $return_url = $_SESSION['return_url']; } else { $return_url = $_SESSION['return_url'] = $a->query_string; } load_contact_links(local_channel()); $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview); call_hooks('conversation_start', $cb); $items = $cb['items']; $conv_responses = array('like' => array('title' => t('Likes', 'title')), 'dislike' => array('title' => t('Dislikes', 'title')), 'agree' => array('title' => t('Agree', 'title')), 'disagree' => array('title' => t('Disagree', 'title')), 'abstain' => array('title' => t('Abstain', 'title')), 'attendyes' => array('title' => t('Attending', 'title')), 'attendno' => array('title' => t('Not attending', 'title')), 'attendmaybe' => array('title' => t('Might attend', 'title'))); // array with html for each thread (parent+comments) $threads = array(); $threadsid = -1; $page_template = get_markup_template("conversation.tpl"); if ($items) { if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') { // "New Item View" on network page or search page results // - just loop through the items and format them minimally for display //$tpl = get_markup_template('search_item.tpl'); $tpl = 'search_item.tpl'; foreach ($items as $item) { if ($arr_blocked) { $blocked = false; foreach ($arr_blocked as $b) { if ($b && $item['author_xchan'] == $b) { $blocked = true; break; } } if ($blocked) { continue; } } $threadsid++; $comment = ''; $owner_url = ''; $owner_photo = ''; $owner_name = ''; $sparkle = ''; if ($mode === 'search' || $mode === 'community') { if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && $item['id'] != $item['parent']) { continue; } $nickname = $item['nickname']; } else { $nickname = $a->user['nickname']; } $profile_name = strlen($item['author-name']) ? $item['author-name'] : $item['name']; if ($item['author-link'] && !$item['author-name']) { $profile_name = $item['author-link']; } $tags = array(); $hashtags = array(); $mentions = array(); $sp = false; $profile_link = best_link_url($item, $sp); if ($sp) { $sparkle = ' sparkle'; } else { $profile_link = zid($profile_link); } $normalised = normalise_link(strlen($item['author-link']) ? $item['author-link'] : $item['url']); $profile_name = $item['author']['xchan_name']; $profile_link = $item['author']['xchan_url']; $profile_avatar = $item['author']['xchan_photo_m']; $location = format_location($item); localize_item($item); if ($mode === 'network-new') { $dropping = true; } else { $dropping = false; } $drop = array('pagedropping' => $page_dropping, 'dropping' => $dropping, 'select' => t('Select'), 'delete' => t('Delete')); $star = false; $isstarred = "unstarred icon-star-empty"; $lock = $item['item_private'] || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid']) ? t('Private Message') : false; $likebuttons = false; $shareable = false; $verified = $item['item_flags'] & ITEM_VERIFIED ? t('Message signature validated') : ''; $forged = $item['sig'] && !($item['item_flags'] & ITEM_VERIFIED) ? t('Message signature incorrect') : ''; $unverified = ''; $tags = array(); $terms = get_terms_oftype($item['term'], array(TERM_HASHTAG, TERM_MENTION, TERM_UNKNOWN)); if (count($terms)) { foreach ($terms as $tag) { $tags[] = format_term_for_display($tag); } } $body = prepare_body($item, true); $tmp_item = array('template' => $tpl, 'toplevel' => 'toplevel_item', 'mode' => $mode, 'id' => $preview ? 'P0' : $item['item_id'], 'linktitle' => sprintf(t('View %s\'s profile @ %s'), $profile_name, $profile_url), 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), 'name' => $profile_name, 'sparkle' => $sparkle, 'lock' => $lock, 'thumb' => $profile_avatar, 'title' => $item['title'], 'body' => $body, 'tags' => $tags, 'hashtags' => $hashtags, 'mentions' => $mentions, 'verified' => $verified, 'unverified' => $unverified, 'forged' => $forged, 'txt_cats' => t('Categories:'), 'txt_folders' => t('Filed under:'), 'has_cats' => count($categories) ? 'true' : '', 'has_folders' => count($folders) ? 'true' : '', 'categories' => $categories, 'folders' => $folders, 'text' => strip_tags($body), 'ago' => relative_date($item['created']), 'app' => $item['app'], 'str_app' => sprintf(t(' from %s'), $item['app']), 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'c'), 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), 'editedtime' => $item['edited'] != $item['created'] ? sprintf(t('last edited: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : '', 'expiretime' => $item['expires'] !== NULL_DATE ? sprintf(t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')) : '', 'location' => $location, 'indent' => '', 'owner_name' => $owner_name, 'owner_url' => $owner_url, 'owner_photo' => $owner_photo, 'plink' => get_plink($item, false), 'edpost' => false, 'isstarred' => $isstarred, 'star' => $star, 'drop' => $drop, 'vote' => $likebuttons, 'like' => '', 'dislike' => '', 'comment' => '', 'conv' => $preview ? '' : array('href' => z_root() . '/display/' . $item['mid'], 'title' => t('View in context')), 'previewing' => $previewing, 'wait' => t('Please wait'), 'thread_level' => 1); $arr = array('item' => $item, 'output' => $tmp_item); call_hooks('display_item', $arr); // $threads[$threadsid]['id'] = $item['item_id']; $threads[] = $arr['output']; } } else { // Normal View // logger('conv: items: ' . print_r($items,true)); require_once 'include/ConversationObject.php'; require_once 'include/ItemObject.php'; $conv = new Conversation($mode, $preview, $prepared_item); // In the display mode we don't have a profile owner. if ($mode === 'display' && $items) { $conv->set_profile_owner($items[0]['uid']); } // get all the topmost parents // 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) { // Check for any blocked authors if ($arr_blocked) { $blocked = false; foreach ($arr_blocked as $b) { if ($b && $item['author_xchan'] == $b) { $blocked = true; break; } } if ($blocked) { continue; } } // Check all the kids too if ($arr_blocked && $item['children']) { for ($d = 0; $d < count($item['children']); $d++) { foreach ($arr_blocked as $b) { if ($b && $item['children'][$d]['author_xchan'] == $b) { $item['children'][$d]['author_blocked'] = true; } } } } builtin_activity_puller($item, $conv_responses); if (!visible_activity($item)) { continue; } $item['pagedrop'] = $page_dropping; if ($item['id'] == $item['parent']) { $item_object = new Item($item); $conv->add_thread($item_object); if ($page_mode === 'list') { $item_object->set_template('conv_list.tpl'); $item_object->set_display_mode('list'); } } } $threads = $conv->get_template_data($conv_responses); if (!$threads) { logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG); $threads = array(); } } } if ($page_mode === 'traditional' || $page_mode === 'preview') { $page_template = get_markup_template("threaded_conversation.tpl"); } elseif ($update) { $page_template = get_markup_template("convobj.tpl"); } else { $page_template = get_markup_template("conv_frame.tpl"); $threads = null; } // if($page_mode === 'preview') // logger('preview: ' . print_r($threads,true)); // Do not un-comment if smarty3 is in use // logger('page_template: ' . $page_template); // logger('nouveau: ' . print_r($threads,true)); $o .= replace_macros($page_template, array('$baseurl' => $a->get_baseurl($ssl_state), '$photo_item' => $content_html, '$live_update' => $live_update_div, '$remove' => t('remove'), '$mode' => $mode, '$user' => $a->user, '$threads' => $threads, '$wait' => t('Loading...'), '$dropping' => $page_dropping ? t('Delete Selected Items') : False)); return $o; }
/** * Get data in a form usable by a conversation template * * Returns: * _ The data requested on success * _ false on failure */ public function get_template_data($alike, $dlike, $thread_level = 1) { $t1 = dba_timer(); $result = array(); $a = $this->get_app(); $item = $this->get_data(); $commentww = ''; $sparkle = ''; $buttons = ''; $dropping = false; $star = false; $isstarred = "unstarred icon-star-empty"; $indent = ''; $osparkle = ''; $total_children = $this->count_descendants(); $conv = $this->get_conversation(); $observer = $conv->get_observer(); $lock = $item['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; $shareable = $conv->get_profile_owner() == local_user() && $item['item_private'] != 1 ? true : false; // allow an exemption for sharing stuff from your private feeds if ($item['author']['xchan_network'] === 'rss') { $shareable = true; } $mode = $conv->get_mode(); if (local_user() && $observer['xchan_hash'] === $item['author_xchan']) { $edpost = array($a->get_baseurl($ssl_state) . "/editpost/" . $item['id'], t("Edit")); } else { $edpost = false; } if ($observer['xchan_hash'] == $this->get_data_value('author_xchan') || $observer['xchan_hash'] == $this->get_data_value('owner_xchan') || $this->get_data_value('uid') == local_user()) { $dropping = true; } if ($dropping) { $drop = array('dropping' => $dropping, 'delete' => t('Delete')); } // FIXME if ($observer_is_pageowner) { $multidrop = array('select' => t('Select')); } $filer = $conv->get_profile_owner() == local_user() ? t("Save to Folder") : false; $profile_avatar = $item['author']['xchan_photo_m']; $profile_link = chanlink_url($item['author']['xchan_url']); $profile_name = $item['author']['xchan_name']; $location = format_location($item); $like_count = x($alike, $item['mid']) ? $alike[$item['mid']] : ''; $like_list = x($alike, $item['mid']) ? $alike[$item['mid'] . '-l'] : ''; if (count($like_list) > MAX_LIKERS) { $like_list_part = array_slice($like_list, 0, MAX_LIKERS); array_push($like_list_part, '<a href="#" data-toggle="modal" data-target="#likeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>'); } else { $like_list_part = ''; } $like_button_label = tt('Like', 'Likes', $like_count, 'noun'); if (feature_enabled($conv->get_profile_owner(), 'dislike')) { $dislike_count = x($dlike, $item['mid']) ? $dlike[$item['mid']] : ''; $dislike_list = x($dlike, $item['mid']) ? $dlike[$item['mid'] . '-l'] : ''; $dislike_button_label = tt('Dislike', 'Dislikes', $dislike_count, 'noun'); if (count($dislike_list) > MAX_LIKERS) { $dislike_list_part = array_slice($dislike_list, 0, MAX_LIKERS); array_push($dislike_list_part, '<a href="#" data-toggle="modal" data-target="#dislikeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>'); } else { $dislike_list_part = ''; } } $showlike = x($alike, $item['mid']) ? format_like($alike[$item['mid']], $alike[$item['mid'] . '-l'], 'like', $item['mid']) : ''; $showdislike = x($dlike, $item['mid']) && feature_enabled($conv->get_profile_owner(), 'dislike') ? format_like($dlike[$item['mid']], $dlike[$item['mid'] . '-l'], 'dislike', $item['mid']) : ''; /* * 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_toplevel()) { // FIXME check this permission if ($conv->get_profile_owner() == local_user()) { // FIXME we don't need all this stuff, some can be done in the template $star = array('do' => t("Add Star"), 'undo' => t("Remove Star"), 'toggle' => t("Toggle Star Status"), 'classdo' => $item['item_flags'] & ITEM_STARRED ? "hidden" : "", 'classundo' => $item['item_flags'] & ITEM_STARRED ? "" : "hidden", 'isstarred' => $item['item_flags'] & ITEM_STARRED ? "starred icon-star" : "unstarred icon-star-empty", 'starred' => t('starred')); } } else { $indent = 'comment'; } $verified = $item['item_flags'] & ITEM_VERIFIED ? t('Message is verified') : ''; $unverified = ''; // (($this->is_wall_to_wall() && (! ($item['item_flags'] & ITEM_VERIFIED))) ? t('Message cannot be verified') : ''); // FIXME - check this permission if ($conv->get_profile_owner() == local_user()) { $tagger = array('tagit' => t("Add Tag"), 'classtagger' => ""); } $has_bookmarks = false; if (is_array($item['term'])) { foreach ($item['term'] as $t) { if ($t['type'] == TERM_BOOKMARK) { $has_bookmarks = true; } } } $has_event = false; if ($item['obj_type'] === ACTIVITY_OBJ_EVENT && $conv->get_profile_owner() == local_user()) { $has_event = true; } if ($this->is_commentable()) { $like = array(t("I like this (toggle)"), t("like")); $dislike = array(t("I don't like this (toggle)"), t("dislike")); } if ($shareable) { $share = array(t('Share This'), t('share')); } if (strcmp(datetime_convert('UTC', 'UTC', $item['created']), datetime_convert('UTC', 'UTC', 'now - 12 hours')) > 0) { $indent .= ' shiny'; } $t2 = dba_timer(); localize_item($item); $t3 = dba_timer(); $body = prepare_body($item, true); $t4 = dba_timer(); $tmp_item = array('template' => $this->get_template(), 'mode' => $mode, 'type' => implode("", array_slice(explode("/", $item['verb']), -1)), 'tags' => array(), 'body' => $body, 'text' => strip_tags($body), 'id' => $this->get_id(), 'linktitle' => sprintf(t('View %s\'s profile - %s'), $profile_name, $item['author']['xchan_addr']), 'olinktitle' => sprintf(t('View %s\'s profile - %s'), $this->get_owner_name(), $item['owner']['xchan_addr']), 'to' => t('to'), 'via' => t('via'), 'wall' => t('Wall-to-Wall'), 'vwall' => t('via Wall-To-Wall:'), 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), 'name' => $profile_name, 'thumb' => $profile_avatar, 'osparkle' => $osparkle, 'sparkle' => $sparkle, 'title' => $item['title'], 'ago' => relative_date($item['created']), 'app' => $item['app'], 'str_app' => sprintf(t(' from %s'), $item['app']), 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'c'), 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), 'editedtime' => $item['edited'] != $item['created'] ? sprintf(t('last edited: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : '', 'expiretime' => $item['expires'] !== NULL_DATE ? sprintf(t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')) : '', 'lock' => $lock, 'verified' => $verified, 'unverified' => $unverified, 'location' => $location, 'indent' => $indent, 'owner_url' => $this->get_owner_url(), 'owner_photo' => $this->get_owner_photo(), 'owner_name' => $this->get_owner_name(), 'like' => $like, 'dislike' => feature_enabled($conv->get_profile_owner(), 'dislike') ? $dislike : '', 'share' => $share, 'rawmid' => $item['mid'], 'plink' => get_plink($item), 'edpost' => feature_enabled($conv->get_profile_owner(), 'edit_posts') ? $edpost : '', 'star' => feature_enabled($conv->get_profile_owner(), 'star_posts') ? $star : '', 'tagger' => feature_enabled($conv->get_profile_owner(), 'commtag') ? $tagger : '', 'filer' => feature_enabled($conv->get_profile_owner(), 'filing') ? $filer : '', 'bookmark' => $conv->get_profile_owner() == local_user() && $has_bookmarks ? t('Save Bookmarks') : '', 'addtocal' => $has_event ? t('Add to Calendar') : '', 'drop' => $drop, 'multidrop' => feature_enabled($conv->get_profile_owner(), 'multi_delete') ? $multidrop : '', 'like_count' => $like_count, 'like_list' => $like_list, 'like_list_part' => $like_list_part, 'like_button_label' => $like_button_label, 'like_modal_title' => t('Likes', 'noun'), 'dislike_modal_title' => t('Dislikes', 'noun'), 'dislike_count' => feature_enabled($conv->get_profile_owner(), 'dislike') ? $dislike_count : '', 'dislike_list' => feature_enabled($conv->get_profile_owner(), 'dislike') ? $dislike_list : '', 'dislike_list_part' => feature_enabled($conv->get_profile_owner(), 'dislike') ? $dislike_list_part : '', 'dislike_button_label' => feature_enabled($conv->get_profile_owner(), 'dislike') ? $dislike_button_label : '', 'modal_dismiss' => t('Close'), 'showlike' => $showlike, 'showdislike' => $showdislike, 'comment' => $this->get_comment_box($indent), 'previewing' => $conv->is_preview() ? ' preview ' : '', 'wait' => t('Please wait'), 'thread_level' => $thread_level); $t5 = dba_timer(); $arr = array('item' => $item, 'output' => $tmp_item); call_hooks('display_item', $arr); $result = $arr['output']; $result['children'] = array(); $children = $this->get_children(); $nb_children = count($children); if ($nb_children > 0) { foreach ($children as $child) { $result['children'][] = $child->get_template_data($alike, $dlike, $thread_level + 1); } // Collapse if ($nb_children > 2 || $thread_level > 1) { $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 all'); if ($thread_level > 1) { $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true; } else { $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true; } } } $result['private'] = $item['item_private']; $result['toplevel'] = $this->is_toplevel() ? 'toplevel_item' : ''; if ($this->is_threaded()) { $result['flatten'] = false; $result['threaded'] = true; } else { $result['flatten'] = true; $result['threaded'] = false; } $t6 = dba_timer(); // profiler($t1,$t2,'t2'); // profiler($t2,$t3,'t3'); // profiler($t3,$t4,'t4'); // profiler($t4,$t5,'t5'); // profiler($t5,$t6,'t6'); // profiler($t1,$t6,'item total'); return $result; }