Пример #1
0
/** @file */
function format_notification($item)
{
    $ret = '';
    require_once 'include/conversation.php';
    // Call localize_item with the "brief" flag to get a one line status for activities.
    // This should set $item['localized'] to indicate we have a brief summary.
    localize_item($item);
    if ($item_localize) {
        $itemem_text = $item['localize'];
    } else {
        $itemem_text = $item['item_thread_top'] ? t('created a new post') : sprintf(t('commented on %s\'s post'), $item['owner']['xchan_name']);
    }
    // convert this logic into a json array just like the system notifications
    return array('notify_link' => $item['llink'], 'name' => $item['author']['xchan_name'], 'url' => $item['author']['xchan_url'], 'photo' => $item['author']['xchan_photo_s'], 'when' => relative_date($item['created']), 'class' => intval($item['item_unseen']) ? 'notify-unseen' : 'notify-seen', 'message' => strip_tags(bbcode($itemem_text)));
}
Пример #2
0
function api_format_items($r, $user_info)
{
    //logger('api_format_items: ' . print_r($r,true));
    //logger('api_format_items: ' . print_r($user_info,true));
    $a = get_app();
    $ret = array();
    if (!$r) {
        return $ret;
    }
    foreach ($r as $item) {
        localize_item($item);
        $status_user = $item['author_xchan'] == $user_info['guid'] ? $user_info : api_item_get_user($a, $item);
        if (array_key_exists('status', $status_user)) {
            unset($status_user['status']);
        }
        if ($item['parent'] != $item['id']) {
            $r = q("select id from item where parent= %d and id < %d order by id desc limit 1", intval($item['parent']), intval($item['id']));
            if ($r) {
                $in_reply_to_status_id = $r[0]['id'];
            } else {
                $in_reply_to_status_id = $item['parent'];
            }
            xchan_query($r, true);
            $in_reply_to_screen_name = $r[0]['author']['xchan_name'];
            $in_reply_to_user_id = $r[0]['author']['abook_id'];
        } else {
            $in_reply_to_screen_name = '';
            $in_reply_to_user_id = 0;
            $in_reply_to_status_id = 0;
        }
        unobscure($item);
        // Workaround for ostatus messages where the title is identically to the body
        $statusbody = trim(html2plain(prepare_text($item['body'], $item['mimetype']), 0));
        $statustitle = trim($item['title']);
        if ($statustitle != '' and strpos($statusbody, $statustitle) !== false) {
            $statustext = trim($statusbody);
        } else {
            $statustext = trim($statustitle . "\n\n" . $statusbody);
        }
        $status = array('text' => $statustext, 'truncated' => False, 'created_at' => api_date($item['created']), 'in_reply_to_status_id' => $in_reply_to_status_id, 'source' => $item['app'] ? $item['app'] : 'web', 'id' => intval($item['id']), 'in_reply_to_user_id' => $in_reply_to_user_id, 'in_reply_to_screen_name' => $in_reply_to_screen_name, 'geo' => '', 'favorited' => intval($item['item_starred']) ? true : false, 'user' => $status_user, 'statusnet_html' => trim(prepare_text($item['body'], $item['mimetype'])), 'statusnet_conversation_id' => $item['parent']);
        // Seesmic doesn't like the following content
        if ($_SERVER['HTTP_USER_AGENT'] != 'Seesmic') {
            $status2 = array('updated' => api_date($item['edited']), 'published' => api_date($item['created']), 'message_id' => $item['mid'], 'url' => $item['plink'], 'coordinates' => $item['coord'], 'place' => $item['location'], 'contributors' => '', 'annotations' => '', 'entities' => '', 'objecttype' => $item['obj_type'] ? $item['obj_type'] : ACTIVITY_OBJ_NOTE, 'verb' => $item['verb'] ? $item['verb'] : ACTIVITY_POST, 'self' => $a->get_baseurl() . "/api/statuses/show/" . $item['id'] . "." . $type, 'edit' => $a->get_baseurl() . "/api/statuses/show/" . $item['id'] . "." . $type);
            $status = array_merge($status, $status2);
        }
        $ret[] = $status;
    }
    return $ret;
}
Пример #3
0
 /**
  * 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;
 }
Пример #4
0
 function conversation(&$a, $items, $mode, $update, $preview = false)
 {
     require_once 'include/bbcode.php';
     require_once 'mod/proxy.php';
     $ssl_state = local_user() ? true : false;
     $profile_owner = 0;
     $page_writeable = false;
     $live_update_div = '';
     $arr_blocked = null;
     if (local_user()) {
         $str_blocked = get_pconfig(local_user(), '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]);
             }
         }
     }
     $previewing = $preview ? ' preview ' : '';
     if ($mode === 'network') {
         $profile_owner = local_user();
         $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'] : '') . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
         }
     } else {
         if ($mode === 'profile') {
             $profile_owner = $a->profile['profile_uid'];
             $page_writeable = can_write_wall($a, $profile_owner);
             if (!$update) {
                 $tab = notags(trim($_GET['tab']));
                 $tab = $tab ? $tab : 'posts';
                 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-profile"></div>' . "\r\n" . "<script> var profile_uid = " . $a->profile['profile_uid'] . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
                 }
             }
         } else {
             if ($mode === 'notes') {
                 $profile_owner = local_user();
                 $page_writeable = true;
                 if (!$update) {
                     $live_update_div = '<div id="live-notes"></div>' . "\r\n" . "<script> var profile_uid = " . local_user() . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
                 }
             } else {
                 if ($mode === 'display') {
                     $profile_owner = $a->profile['uid'];
                     $page_writeable = can_write_wall($a, $profile_owner);
                     if (!$update) {
                         $live_update_div = '<div id="live-display"></div>' . "\r\n" . "<script> var profile_uid = " . $_SESSION['uid'] . ";" . " var profile_page = 1; </script>";
                     }
                 } else {
                     if ($mode === 'community') {
                         $profile_owner = 0;
                         $page_writeable = false;
                         if (!$update) {
                             $live_update_div = '<div id="live-community"></div>' . "\r\n" . "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
                         }
                     } else {
                         if ($mode === 'search') {
                             $live_update_div = '<div id="live-search"></div>' . "\r\n";
                         }
                     }
                 }
             }
         }
     }
     $page_dropping = local_user() && local_user() == $profile_owner ? true : false;
     if ($update) {
         $return_url = $_SESSION['return_url'];
     } else {
         $return_url = $_SESSION['return_url'] = $a->query_string;
     }
     load_contact_links(local_user());
     $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
     call_hooks('conversation_start', $cb);
     $items = $cb['items'];
     $cmnt_tpl = get_markup_template('comment_item.tpl');
     $hide_comments_tpl = get_markup_template('hide_comments.tpl');
     $alike = array();
     $dlike = array();
     // array with html for each thread (parent+comments)
     $threads = array();
     $threadsid = -1;
     $page_template = get_markup_template("conversation.tpl");
     if ($items && count($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 && link_compare($item['author-link'], $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'];
                 }
                 // prevent private email from leaking.
                 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
                     continue;
                 }
                 $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();
                 $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`", intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));
                 foreach ($taglist as $tag) {
                     if ($tag["url"] == "") {
                         $tag["url"] = $searchpath . strtolower($tag["term"]);
                     }
                     if ($tag["type"] == TERM_HASHTAG) {
                         $hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
                         $prefix = "#";
                     } elseif ($tag["type"] == TERM_MENTION) {
                         $mentions[] = "@<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
                         $prefix = "@";
                     }
                     $tags[] = $prefix . "<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
                 }
                 /*foreach(explode(',',$item['tag']) as $tag){
                 			$tag = trim($tag);
                 			if ($tag!="") {
                 				$t = bbcode($tag);
                 				$tags[] = $t;
                 				if($t[0] == '#')
                 					$hashtags[] = $t;
                 				elseif($t[0] == '@')
                 					$mentions[] = $t;
                 			}
                 		}*/
                 $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']) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['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);
                 localize_item($item);
                 if ($mode === 'network-new') {
                     $dropping = true;
                 } else {
                     $dropping = false;
                 }
                 $drop = array('dropping' => $dropping, 'pagedrop' => $page_dropping, 'select' => t('Select'), 'delete' => t('Delete'));
                 $star = false;
                 $isstarred = "unstarred";
                 $lock = false;
                 $likebuttons = false;
                 $shareable = false;
                 $body = prepare_body($item, true, $preview);
                 list($categories, $folders) = get_cats_and_terms($item);
                 if ($a->theme['template_engine'] === 'internal') {
                     $profile_name_e = template_escape($profile_name);
                     $item['title_e'] = template_escape($item['title']);
                     $body_e = template_escape($body);
                     $tags_e = template_escape($tags);
                     $hashtags_e = template_escape($hashtags);
                     $mentions_e = template_escape($mentions);
                     $location_e = template_escape($location);
                     $owner_name_e = template_escape($owner_name);
                 } else {
                     $profile_name_e = $profile_name;
                     $item['title_e'] = $item['title'];
                     $body_e = $body;
                     $tags_e = $tags;
                     $hashtags_e = $hashtags;
                     $mentions_e = $mentions;
                     $location_e = $location;
                     $owner_name_e = $owner_name;
                 }
                 $tmp_item = array('template' => $tpl, 'id' => $preview ? 'P0' : $item['item_id'], 'network' => $item['item_network'], 'linktitle' => sprintf(t('View %s\'s profile @ %s'), $profile_name, strlen($item['author-link']) ? $item['author-link'] : $item['url']), 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), 'name' => $profile_name_e, 'sparkle' => $sparkle, 'lock' => $lock, 'thumb' => proxy_url($profile_avatar), 'title' => $item['title_e'], 'body' => $body_e, 'tags' => $tags_e, 'hashtags' => $hashtags_e, 'mentions' => $mentions_e, '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_e), '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']), 'location' => $location_e, 'indent' => '', 'owner_name' => $owner_name_e, 'owner_url' => $owner_url, 'owner_photo' => proxy_url($owner_photo), 'plink' => get_plink($item), 'edpost' => false, 'isstarred' => $isstarred, 'star' => $star, 'drop' => $drop, 'vote' => $likebuttons, 'like' => '', 'dislike' => '', 'comment' => '', 'conv' => $preview ? '' : array('href' => $a->get_baseurl($ssl_state) . '/display/' . $item['guid'], '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[$threadsid]['network'] = $item['item_network'];
                 $threads[$threadsid]['items'] = array($arr['output']);
             }
         } else {
             // Normal View
             $page_template = get_markup_template("threaded_conversation.tpl");
             require_once 'object/Conversation.php';
             require_once 'object/Item.php';
             $conv = new Conversation($mode, $preview);
             // 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) {
                 if ($arr_blocked) {
                     $blocked = false;
                     foreach ($arr_blocked as $b) {
                         if ($b && link_compare($item['author-link'], $b)) {
                             $blocked = true;
                             break;
                         }
                     }
                     if ($blocked) {
                         continue;
                     }
                 }
                 // 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 (!visible_activity($item)) {
                     continue;
                 }
                 call_hooks('display_item', $arr);
                 $item['pagedrop'] = $page_dropping;
                 if ($item['id'] == $item['parent']) {
                     $item_object = new Item($item);
                     $conv->add_thread($item_object);
                 }
             }
             $threads = $conv->get_template_data($alike, $dlike);
             if (!$threads) {
                 logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
                 $threads = array();
             }
         }
     }
     $o = replace_macros($page_template, array('$baseurl' => $a->get_baseurl($ssl_state), '$return_path' => $a->query_string, '$live_update' => $live_update_div, '$remove' => t('remove'), '$mode' => $mode, '$user' => $a->user, '$threads' => $threads, '$dropping' => $page_dropping && feature_enabled(local_user(), 'multi_delete') ? t('Delete Selected Items') : False));
     return $o;
 }
Пример #5
0
 function conversation(&$a, $items, $mode, $update, $preview = false)
 {
     require_once 'bbcode.php';
     $ssl_state = local_user() ? true : false;
     $profile_owner = 0;
     $page_writeable = false;
     $previewing = $preview ? ' preview ' : '';
     if ($mode === 'network') {
         $profile_owner = local_user();
         $page_writeable = true;
     }
     if ($mode === 'profile') {
         $profile_owner = $a->profile['profile_uid'];
         $page_writeable = can_write_wall($a, $profile_owner);
     }
     if ($mode === 'notes') {
         $profile_owner = local_user();
         $page_writeable = true;
     }
     if ($mode === 'display') {
         $profile_owner = $a->profile['uid'];
         $page_writeable = can_write_wall($a, $profile_owner);
     }
     if ($mode === 'community') {
         $profile_owner = 0;
         $page_writeable = false;
     }
     if ($update) {
         $return_url = $_SESSION['return_url'];
     } else {
         $return_url = $_SESSION['return_url'] = $a->query_string;
     }
     load_contact_links(local_user());
     $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
     call_hooks('conversation_start', $cb);
     $items = $cb['items'];
     $cmnt_tpl = get_markup_template('comment_item.tpl');
     $tpl = 'wall_item.tpl';
     $wallwall = 'wallwall_item.tpl';
     $hide_comments_tpl = get_markup_template('hide_comments.tpl');
     $alike = array();
     $dlike = array();
     // array with html for each thread (parent+comments)
     $threads = array();
     $threadsid = -1;
     if ($items && count($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) {
                 $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'];
                 }
                 // prevent private email from leaking.
                 if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
                     continue;
                 }
                 $profile_name = strlen($item['author-name']) ? $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']) ? $item['author-avatar'] : $item['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);
                 localize_item($item);
                 if ($mode === 'network-new') {
                     $dropping = true;
                 } else {
                     $dropping = false;
                 }
                 $drop = array('dropping' => $dropping, 'select' => t('Select'), 'delete' => t('Delete'));
                 $star = false;
                 $isstarred = "unstarred";
                 $lock = false;
                 $likebuttons = false;
                 $shareable = false;
                 $body = prepare_body($item, true);
                 //$tmp_item = replace_macros($tpl,array(
                 $tmp_item = array('template' => $tpl, 'id' => $preview ? 'P0' : $item['item_id'], 'linktitle' => sprintf(t('View %s\'s profile @ %s'), $profile_name, strlen($item['author-link']) ? $item['author-link'] : $item['url']), 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), 'name' => template_escape($profile_name), 'sparkle' => $sparkle, 'lock' => $lock, 'thumb' => $profile_avatar, 'title' => template_escape($item['title']), 'body' => template_escape($body), 'text' => strip_tags(template_escape($body)), 'ago' => $item['app'] ? sprintf(t('%s from %s'), relative_date($item['created']), $item['app']) : relative_date($item['created']), 'location' => template_escape($location), 'indent' => '', 'owner_name' => template_escape($owner_name), 'owner_url' => $owner_url, 'owner_photo' => $owner_photo, 'plink' => get_plink($item), 'edpost' => false, 'isstarred' => $isstarred, 'star' => $star, 'drop' => $drop, 'vote' => $likebuttons, 'like' => '', 'dislike' => '', 'comment' => '', 'conv' => $preview ? '' : array('href' => $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title' => t('View in context')), 'previewing' => $previewing, 'wait' => t('Please wait'));
                 $arr = array('item' => $item, 'output' => $tmp_item);
                 call_hooks('display_item', $arr);
                 $threads[$threadsid]['id'] = $item['item_id'];
                 $threads[$threadsid]['items'] = array($arr['output']);
             }
         } else {
             // Normal View
             // Figure out how many comments each parent has
             // (Comments all have gravity of 6)
             // Store the result in the $comments array
             $comments = array();
             foreach ($items as $item) {
                 if (intval($item['gravity']) == 6 && $item['id'] != $item['parent']) {
                     if (!x($comments, $item['parent'])) {
                         $comments[$item['parent']] = 1;
                     } else {
                         $comments[$item['parent']] += 1;
                     }
                 } elseif (!x($comments, $item['parent'])) {
                     $comments[$item['parent']] = 0;
                 }
                 // avoid notices later on
             }
             // map all the like/dislike activities for each parent item
             // Store these in the $alike and $dlike arrays
             foreach ($items as $item) {
                 like_puller($a, $item, $alike, 'like');
                 like_puller($a, $item, $dlike, 'dislike');
             }
             $comments_collapsed = false;
             $comments_seen = 0;
             $comment_lastcollapsed = false;
             $comment_firstcollapsed = false;
             $blowhard = 0;
             $blowhard_count = 0;
             foreach ($items as $item) {
                 $comment = '';
                 $template = $tpl;
                 $commentww = '';
                 $sparkle = '';
                 $owner_url = $owner_photo = $owner_name = '';
                 // We've already parsed out like/dislike for special treatment. We can ignore them now
                 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && $item['id'] != $item['parent']) {
                     continue;
                 }
                 $toplevelpost = $item['id'] == $item['parent'] ? true : false;
                 $toplevelprivate = false;
                 // Take care of author collapsing and comment collapsing
                 // (author collapsing is currently disabled)
                 // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
                 // If there are more than two comments, squash all but the last 2.
                 if ($toplevelpost) {
                     $toplevelprivate = $toplevelpost && $item['private'] ? true : false;
                     $item_writeable = $item['writable'] || $item['self'] ? true : false;
                     $comments_seen = 0;
                     $comments_collapsed = false;
                     $comment_lastcollapsed = false;
                     $comment_firstcollapsed = false;
                     $threadsid++;
                     $threads[$threadsid]['id'] = $item['item_id'];
                     $threads[$threadsid]['private'] = $item['private'];
                     $threads[$threadsid]['items'] = array();
                 } else {
                     // prevent private email reply to public conversation from leaking.
                     if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
                         continue;
                     }
                     $comments_seen++;
                     $comment_lastcollapsed = false;
                     $comment_firstcollapsed = false;
                 }
                 $override_comment_box = $page_writeable && $item_writeable ? true : false;
                 $show_comment_box = $page_writeable && $item_writeable && $comments_seen == $comments[$item['parent']] ? true : false;
                 if ($comments[$item['parent']] > 2 && $comments_seen <= $comments[$item['parent']] - 2 && $item['gravity'] == 6) {
                     if (!$comments_collapsed) {
                         $threads[$threadsid]['num_comments'] = sprintf(tt('%d comment', '%d comments', $comments[$item['parent']]), $comments[$item['parent']]);
                         $threads[$threadsid]['hide_text'] = t('show more');
                         $comments_collapsed = true;
                         $comment_firstcollapsed = true;
                     }
                 }
                 if ($comments[$item['parent']] > 2 && $comments_seen == $comments[$item['parent']] - 1) {
                     $comment_lastcollapsed = true;
                 }
                 $redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'];
                 $lock = $item['private'] || $item['uid'] == local_user() && (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) ? t('Private Message') : false;
                 // Top-level wall post not written by the wall owner (wall-to-wall)
                 // First figure out who owns it.
                 $osparkle = '';
                 if ($toplevelpost && !$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;
                         $commentww = 'ww';
                     }
                     if (!$item['wall'] && $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;
                             $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);
                             }
                         }
                     }
                 }
                 $likebuttons = '';
                 $shareable = $profile_owner == local_user() && !$item['private'] ? true : false;
                 //($mode != 'display') &&
                 if ($page_writeable) {
                     if ($toplevelpost) {
                         $likebuttons = array('like' => array(t("I like this (toggle)"), t("like")), 'dislike' => array(t("I don't like this (toggle)"), t("dislike")));
                         if ($shareable) {
                             $likebuttons['share'] = array(t('Share this'), t('share'));
                         }
                     }
                     $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;
                     }
                     if ($show_comment_box || $show_comment_box == false && $override_comment_box == false && $item['last-child']) {
                         $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['parent'], '$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'), '$ww' => $mode === 'network' ? $commentww : ''));
                     }
                 }
                 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;
                 }
                 $drop = '';
                 $dropping = 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'));
                 $star = false;
                 $filer = false;
                 $isstarred = "unstarred";
                 if ($profile_owner == local_user()) {
                     if ($toplevelpost) {
                         $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' => "");
                     }
                     $filer = t("save to folder");
                 }
                 $photo = $item['photo'];
                 $thumb = $item['thumb'];
                 // Post was remotely authored.
                 $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'] : $thumb;
                 }
                 $like = x($alike, $item['id']) ? format_like($alike[$item['id']], $alike[$item['id'] . '-l'], 'like', $item['id']) : '';
                 $dislike = x($dlike, $item['id']) ? format_like($dlike[$item['id']], $dlike[$item['id'] . '-l'], 'dislike', $item['id']) : '';
                 $locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
                 call_hooks('render_location', $locate);
                 $location = strlen($locate['html']) ? $locate['html'] : render_location_google($locate);
                 $indent = $toplevelpost ? '' : ' comment';
                 if (strcmp(datetime_convert('UTC', 'UTC', $item['created']), datetime_convert('UTC', 'UTC', 'now - 12 hours')) > 0) {
                     $indent .= ' shiny';
                 }
                 //
                 localize_item($item);
                 $tags = array();
                 foreach (explode(',', $item['tag']) as $tag) {
                     $tag = trim($tag);
                     if ($tag != "") {
                         $tags[] = bbcode($tag);
                     }
                 }
                 // Build the HTML
                 $body = prepare_body($item, true);
                 //$tmp_item = replace_macros($template,
                 $tmp_item = array('comment_firstcollapsed' => $comment_firstcollapsed, 'comment_lastcollapsed' => $comment_lastcollapsed, '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'), $profile_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' => $likebuttons, 'like' => $like, 'dislike' => $dislike, 'comment' => $comment, 'previewing' => $previewing, 'wait' => t('Please wait'));
                 $arr = array('item' => $item, 'output' => $tmp_item);
                 call_hooks('display_item', $arr);
                 $threads[$threadsid]['items'][] = $arr['output'];
             }
         }
     }
     $page_template = get_markup_template("conversation.tpl");
     $o = replace_macros($page_template, array('$baseurl' => $a->get_baseurl($ssl_state), '$mode' => $mode, '$user' => $a->user, '$threads' => $threads, '$dropping' => $dropping ? t('Delete Selected Items') : False));
     return $o;
 }
Пример #6
0
/**
 * @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;
}
Пример #7
0
function api_format_items($r, $user_info, $filter_user = false)
{
    $a = get_app();
    $ret = array();
    foreach ($r as $item) {
        api_share_as_retweet($item);
        localize_item($item);
        $status_user = api_item_get_user($a, $item);
        // Look if the posts are matching if they should be filtered by user id
        if ($filter_user and $status_user["id"] != $user_info["id"]) {
            continue;
        }
        if ($item['thr-parent'] != $item['uri']) {
            $r = q("SELECT id FROM item WHERE uid=%d AND uri='%s' LIMIT 1", intval(api_user()), dbesc($item['thr-parent']));
            if ($r) {
                $in_reply_to_status_id = intval($r[0]['id']);
            } else {
                $in_reply_to_status_id = intval($item['parent']);
            }
            $in_reply_to_status_id_str = (string) intval($item['parent']);
            $in_reply_to_screen_name = NULL;
            $in_reply_to_user_id = NULL;
            $in_reply_to_user_id_str = NULL;
            $r = q("SELECT `author-link` FROM item WHERE uid=%d AND id=%d LIMIT 1", intval(api_user()), intval($in_reply_to_status_id));
            if ($r) {
                $r = q("SELECT * FROM unique_contacts WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link'])));
                if ($r) {
                    if ($r[0]['nick'] == "") {
                        $r[0]['nick'] = api_get_nick($r[0]["url"]);
                    }
                    $in_reply_to_screen_name = $r[0]['nick'] ? $r[0]['nick'] : $r[0]['name'];
                    $in_reply_to_user_id = intval($r[0]['id']);
                    $in_reply_to_user_id_str = (string) intval($r[0]['id']);
                }
            }
        } else {
            $in_reply_to_screen_name = NULL;
            $in_reply_to_user_id = NULL;
            $in_reply_to_status_id = NULL;
            $in_reply_to_user_id_str = NULL;
            $in_reply_to_status_id_str = NULL;
        }
        $converted = api_convert_item($item);
        $status = array('text' => $converted["text"], 'truncated' => False, 'created_at' => api_date($item['created']), 'in_reply_to_status_id' => $in_reply_to_status_id, 'in_reply_to_status_id_str' => $in_reply_to_status_id_str, 'source' => $item['app'] ? $item['app'] : 'web', 'id' => intval($item['id']), 'id_str' => (string) intval($item['id']), 'in_reply_to_user_id' => $in_reply_to_user_id, 'in_reply_to_user_id_str' => $in_reply_to_user_id_str, 'in_reply_to_screen_name' => $in_reply_to_screen_name, 'geo' => NULL, 'favorited' => $item['starred'] ? true : false, 'user' => $status_user, 'statusnet_html' => $converted["html"], 'statusnet_conversation_id' => $item['parent']);
        if (count($converted["attachments"]) > 0) {
            $status["attachments"] = $converted["attachments"];
        }
        if (count($converted["entities"]) > 0) {
            $status["entities"] = $converted["entities"];
        }
        if ($item['item_network'] != "" and $status["source"] == 'web') {
            $status["source"] = network_to_name($item['item_network'], $user_info['url']);
        } else {
            if ($item['item_network'] != "" and network_to_name($item['item_network'], $user_info['url']) != $status["source"]) {
                $status["source"] = trim($status["source"] . ' (' . network_to_name($item['item_network'], $user_info['url']) . ')');
            }
        }
        // Retweets are only valid for top postings
        // It doesn't work reliable with the link if its a feed
        $IsRetweet = $item['owner-link'] != $item['author-link'];
        if ($IsRetweet) {
            $IsRetweet = ($item['owner-name'] != $item['author-name'] or $item['owner-avatar'] != $item['author-avatar']);
        }
        if ($IsRetweet and $item["id"] == $item["parent"]) {
            $retweeted_status = $status;
            $retweeted_status["user"] = api_get_user($a, $item["author-link"]);
            $status["retweeted_status"] = $retweeted_status;
        }
        // "uid" and "self" are only needed for some internal stuff, so remove it from here
        unset($status["user"]["uid"]);
        unset($status["user"]["self"]);
        if ($item["coord"] != "") {
            $coords = explode(' ', $item["coord"]);
            if (count($coords) == 2) {
                $status["geo"] = array('type' => 'Point', 'coordinates' => array((double) $coords[0], (double) $coords[1]));
            }
        }
        $ret[] = $status;
    }
    return $ret;
}
Пример #8
0
/**
 * @brief
 *
 * @param array $params an assoziative array with:
 *  * \e string \b from_xchan sender xchan hash
 *  * \e string \b to_xchan recipient xchan hash
 *  * \e array \b item an assoziative array
 *  * \e int \b type one of the NOTIFY_* constants from boot.php
 *  * \e string \b link
 *  * \e string \b parent_mid
 *  * \e string \b otype
 *  * \e string \b verb
 *  * \e string \b activity
 */
function notification($params)
{
    logger('notification: entry', LOGGER_DEBUG);
    // throw a small amount of entropy into the system to breakup duplicates arriving at the same precise instant.
    usleep(mt_rand(0, 10000));
    $a = get_app();
    if ($params['from_xchan']) {
        $x = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($params['from_xchan']));
    }
    if ($params['to_xchan']) {
        $y = q("select channel.*, account.* from channel left join account on channel_account_id = account_id\n\t\t\twhere channel_hash = '%s' and channel_removed = 0 limit 1", dbesc($params['to_xchan']));
    }
    if ($x & $y) {
        $sender = $x[0];
        $recip = $y[0];
    } else {
        logger('notification: no sender or recipient.');
        logger('sender: ' . $params['from_xchan']);
        logger('recip: ' . $params['to_xchan']);
        return;
    }
    // from here on everything is in the recipients language
    push_lang($recip['account_language']);
    // should probably have a channel language
    $banner = t('$Projectname Notification');
    $product = t('$projectname');
    // PLATFORM_NAME;
    $siteurl = $a->get_baseurl(true);
    $thanks = t('Thank You,');
    $sitename = get_config('system', 'sitename');
    $site_admin = sprintf(t('%s Administrator'), $sitename);
    $sender_name = $product;
    $hostname = $a->get_hostname();
    if (strpos($hostname, ':')) {
        $hostname = substr($hostname, 0, strpos($hostname, ':'));
    }
    // Do not translate 'noreply' as it must be a legal 7-bit email address
    $sender_email = 'noreply' . '@' . $hostname;
    $additional_mail_header = "";
    if (array_key_exists('item', $params)) {
        require_once 'include/conversation.php';
        // if it's a normal item...
        if (array_key_exists('verb', $params['item'])) {
            // localize_item() alters the original item so make a copy first
            $i = $params['item'];
            logger('calling localize');
            localize_item($i);
            $title = $i['title'];
            $body = $i['body'];
            $private = $i['item_private'] || intval($i['item_obscured']);
        } else {
            $title = $params['item']['title'];
            $body = $params['item']['body'];
        }
    } else {
        $title = $body = '';
    }
    // e.g. "your post", "David's photo", etc.
    $possess_desc = t('%s <!item_type!>');
    if ($params['type'] == NOTIFY_MAIL) {
        logger('notification: mail');
        $subject = sprintf(t('[Hubzilla:Notify] New mail received at %s'), $sitename);
        $preamble = sprintf(t('%1$s, %2$s sent you a new private message at %3$s.'), $recip['channel_name'], $sender['xchan_name'], $sitename);
        $epreamble = sprintf(t('%1$s sent you %2$s.'), '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', '[zrl=$itemlink]' . t('a private message') . '[/zrl]');
        $sitelink = t('Please visit %s to view and/or reply to your private messages.');
        $tsitelink = sprintf($sitelink, $siteurl . '/mail/' . $params['item']['id']);
        $hsitelink = sprintf($sitelink, '<a href="' . $siteurl . '/mail/' . $params['item']['id'] . '">' . $sitename . '</a>');
        $itemlink = $siteurl . '/mail/' . $params['item']['id'];
    }
    if ($params['type'] == NOTIFY_COMMENT) {
        //		logger("notification: params = " . print_r($params, true), LOGGER_DEBUG);
        $itemlink = $params['link'];
        // ignore like/unlike activity on posts - they probably require a sepearate notification preference
        if (array_key_exists('item', $params) && !visible_activity($params['item'])) {
            return;
        }
        $parent_mid = $params['parent_mid'];
        // Check to see if there was already a notify for this post.
        // If so don't create a second notification
        $p = null;
        $p = q("select id from notify where link = '%s' and uid = %d limit 1", dbesc($params['link']), intval($recip['channel_id']));
        if ($p) {
            logger('notification: comment already notified');
            pop_lang();
            return;
        }
        // if it's a post figure out who's post it is.
        $p = null;
        if ($params['otype'] === 'item' && $parent_mid) {
            $p = q("select * from item where mid = '%s' and uid = %d limit 1", dbesc($parent_mid), intval($recip['channel_id']));
        }
        xchan_query($p);
        $item_post_type = item_post_type($p[0]);
        //		$private = $p[0]['item_private'];
        $parent_id = $p[0]['id'];
        $parent_item = $p[0];
        //$possess_desc = str_replace('<!item_type!>',$possess_desc);
        // "a post"
        $dest_str = sprintf(t('%1$s, %2$s commented on [zrl=%3$s]a %4$s[/zrl]'), $recip['channel_name'], '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', $itemlink, $item_post_type);
        // "George Bull's post"
        if ($p) {
            $dest_str = sprintf(t('%1$s, %2$s commented on [zrl=%3$s]%4$s\'s %5$s[/zrl]'), $recip['channel_name'], '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', $itemlink, $p[0]['author']['xchan_name'], $item_post_type);
        }
        // "your post"
        if ($p[0]['owner']['xchan_name'] == $p[0]['author']['xchan_name'] && intval($p[0]['item_wall'])) {
            $dest_str = sprintf(t('%1$s, %2$s commented on [zrl=%3$s]your %4$s[/zrl]'), $recip['channel_name'], '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', $itemlink, $item_post_type);
        }
        // Some mail softwares relies on subject field for threading.
        // So, we cannot have different subjects for notifications of the same thread.
        // Before this we have the name of the replier on the subject rendering
        // differents subjects for messages on the same thread.
        $subject = sprintf(t('[Hubzilla:Notify] Comment to conversation #%1$d by %2$s'), $parent_id, $sender['xchan_name']);
        $preamble = sprintf(t('%1$s, %2$s commented on an item/conversation you have been following.'), $recip['channel_name'], $sender['xchan_name']);
        $epreamble = $dest_str;
        $sitelink = t('Please visit %s to view and/or reply to the conversation.');
        $tsitelink = sprintf($sitelink, $siteurl);
        $hsitelink = sprintf($sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
    }
    if ($params['type'] == NOTIFY_WALL) {
        $subject = sprintf(t('[Hubzilla:Notify] %s posted to your profile wall'), $sender['xchan_name']);
        $preamble = sprintf(t('%1$s, %2$s posted to your profile wall at %3$s'), $recip['channel_name'], $sender['xchan_name'], $sitename);
        $epreamble = sprintf(t('%1$s, %2$s posted to [zrl=%3$s]your wall[/zrl]'), $recip['channel_name'], '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', $params['link']);
        $sitelink = t('Please visit %s to view and/or reply to the conversation.');
        $tsitelink = sprintf($sitelink, $siteurl);
        $hsitelink = sprintf($sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
        $itemlink = $params['link'];
    }
    if ($params['type'] == NOTIFY_TAGSELF) {
        $p = null;
        $p = q("select id from notify where link = '%s' and uid = %d limit 1", dbesc($params['link']), intval($recip['channel_id']));
        if ($p) {
            logger('enotify: tag: already notified about this post');
            pop_lang();
            return;
        }
        $subject = sprintf(t('[Hubzilla:Notify] %s tagged you'), $sender['xchan_name']);
        $preamble = sprintf(t('%1$s, %2$s tagged you at %3$s'), $recip['channel_name'], $sender['xchan_name'], $sitename);
        $epreamble = sprintf(t('%1$s, %2$s [zrl=%3$s]tagged you[/zrl].'), $recip['channel_name'], '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', $params['link']);
        $sitelink = t('Please visit %s to view and/or reply to the conversation.');
        $tsitelink = sprintf($sitelink, $siteurl);
        $hsitelink = sprintf($sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
        $itemlink = $params['link'];
    }
    if ($params['type'] == NOTIFY_POKE) {
        $subject = sprintf(t('[Hubzilla:Notify] %1$s poked you'), $sender['xchan_name']);
        $preamble = sprintf(t('%1$s, %2$s poked you at %3$s'), $recip['channel_name'], $sender['xchan_name'], $sitename);
        $epreamble = sprintf(t('%1$s, %2$s [zrl=%2$s]poked you[/zrl].'), $recip['channel_name'], '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', $params['link']);
        $subject = str_replace('poked', t($params['activity']), $subject);
        $preamble = str_replace('poked', t($params['activity']), $preamble);
        $epreamble = str_replace('poked', t($params['activity']), $epreamble);
        $sitelink = t('Please visit %s to view and/or reply to the conversation.');
        $tsitelink = sprintf($sitelink, $siteurl);
        $hsitelink = sprintf($sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
        $itemlink = $params['link'];
    }
    if ($params['type'] == NOTIFY_TAGSHARE) {
        $subject = sprintf(t('[Hubzilla:Notify] %s tagged your post'), $sender['xchan_name']);
        $preamble = sprintf(t('%1$s, %2$s tagged your post at %3$s'), $recip['channel_name'], $sender['xchan_name'], $sitename);
        $epreamble = sprintf(t('%1$s, %2$s tagged [zrl=%3$s]your post[/zrl]'), $recip['channel_name'], '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', $itemlink);
        $sitelink = t('Please visit %s to view and/or reply to the conversation.');
        $tsitelink = sprintf($sitelink, $siteurl);
        $hsitelink = sprintf($sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
        $itemlink = $params['link'];
    }
    if ($params['type'] == NOTIFY_INTRO) {
        $subject = sprintf(t('[Hubzilla:Notify] Introduction received'));
        $preamble = sprintf(t('%1$s, you\'ve received an new connection request from \'%2$s\' at %3$s'), $recip['channel_name'], $sender['xchan_name'], $sitename);
        $epreamble = sprintf(t('%1$s, you\'ve received [zrl=%2$s]a new connection request[/zrl] from %3$s.'), $recip['channel_name'], $itemlink, '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]');
        $body = sprintf(t('You may visit their profile at %s'), $sender['xchan_url']);
        $sitelink = t('Please visit %s to approve or reject the connection request.');
        $tsitelink = sprintf($sitelink, $siteurl);
        $hsitelink = sprintf($sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
        $itemlink = $params['link'];
    }
    if ($params['type'] == NOTIFY_SUGGEST) {
        $subject = sprintf(t('[Hubzilla:Notify] Friend suggestion received'));
        $preamble = sprintf(t('%1$s, you\'ve received a friend suggestion from \'%2$s\' at %3$s'), $recip['channel_name'], $sender['xchan_name'], $sitename);
        $epreamble = sprintf(t('%1$s, you\'ve received [zrl=%2$s]a friend suggestion[/zrl] for %3$s from %4$s.'), $recip['channel_name'], $itemlink, '[zrl=' . $params['item']['url'] . ']' . $params['item']['name'] . '[/zrl]', '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]');
        $body = t('Name:') . ' ' . $params['item']['name'] . "\n";
        $body .= t('Photo:') . ' ' . $params['item']['photo'] . "\n";
        $body .= sprintf(t('You may visit their profile at %s'), $params['item']['url']);
        $sitelink = t('Please visit %s to approve or reject the suggestion.');
        $tsitelink = sprintf($sitelink, $siteurl);
        $hsitelink = sprintf($sitelink, '<a href="' . $siteurl . '">' . $sitename . '</a>');
        $itemlink = $params['link'];
    }
    if ($params['type'] == NOTIFY_CONFIRM) {
        // ?
    }
    if ($params['type'] == NOTIFY_SYSTEM) {
        // ?
    }
    $h = array('params' => $params, 'subject' => $subject, 'preamble' => $preamble, 'epreamble' => $epreamble, 'body' => $body, 'sitelink' => $sitelink, 'sitename' => $sitename, 'tsitelink' => $tsitelink, 'hsitelink' => $hsitelink, 'itemlink' => $itemlink, 'sender' => $sender, 'recipient' => $recip);
    call_hooks('enotify', $h);
    $subject = $h['subject'];
    $preamble = $h['preamble'];
    $epreamble = $h['epreamble'];
    $body = $h['body'];
    $sitelink = $h['sitelink'];
    $tsitelink = $h['tsitelink'];
    $hsitelink = $h['hsitelink'];
    $itemlink = $h['itemlink'];
    require_once 'include/html2bbcode.php';
    do {
        $dups = false;
        $hash = random_string();
        $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1", dbesc($hash));
        if (count($r)) {
            $dups = true;
        }
    } while ($dups === true);
    $datarray = array();
    $datarray['hash'] = $hash;
    $datarray['sender_hash'] = $sender['xchan_hash'];
    $datarray['name'] = $sender['xchan_name'];
    $datarray['url'] = $sender['xchan_url'];
    $datarray['photo'] = $sender['xchan_photo_s'];
    $datarray['date'] = datetime_convert();
    $datarray['aid'] = $recip['channel_account_id'];
    $datarray['uid'] = $recip['channel_id'];
    $datarray['link'] = $itemlink;
    $datarray['parent'] = $parent_mid;
    $datarray['parent_item'] = $parent_item;
    $datarray['type'] = $params['type'];
    $datarray['verb'] = $params['verb'];
    $datarray['otype'] = $params['otype'];
    $datarray['abort'] = false;
    $datarray['item'] = $params['item'];
    call_hooks('enotify_store', $datarray);
    if ($datarray['abort']) {
        pop_lang();
        return;
    }
    // create notification entry in DB
    $seen = 0;
    // Mark some notifications as seen right away
    // Note! The notification have to be created, because they are used to send emails
    // So easiest solution to hide them from Notices is to mark them as seen right away.
    // Another option would be to not add them to the DB, and change how emails are handled (probably would be better that way)
    $always_show_in_notices = get_pconfig($recip['channel_id'], 'system', 'always_show_in_notices');
    if (!$always_show_in_notices) {
        if ($params['type'] == NOTIFY_WALL || $params['type'] == NOTIFY_MAIL || $params['type'] == NOTIFY_INTRO) {
            $seen = 1;
        }
    }
    $r = q("insert into notify (hash,name,url,photo,date,aid,uid,link,parent,seen,type,verb,otype)\n\t\tvalues('%s','%s','%s','%s','%s',%d,%d,'%s','%s',%d,%d,'%s','%s')", dbesc($datarray['hash']), dbesc($datarray['name']), dbesc($datarray['url']), dbesc($datarray['photo']), dbesc($datarray['date']), intval($datarray['aid']), intval($datarray['uid']), dbesc($datarray['link']), dbesc($datarray['parent']), intval($seen), intval($datarray['type']), dbesc($datarray['verb']), dbesc($datarray['otype']));
    $r = q("select id from notify where hash = '%s' and uid = %d limit 1", dbesc($hash), intval($recip['channel_id']));
    if ($r) {
        $notify_id = $r[0]['id'];
    } else {
        logger('notification not found.');
        pop_lang();
        return;
    }
    $itemlink = $a->get_baseurl() . '/notify/view/' . $notify_id;
    $msg = str_replace('$itemlink', $itemlink, $epreamble);
    // wretched hack, but we don't want to duplicate all the preamble variations and we also don't want to screw up a translation
    if (($a->language === 'en' || !$a->language) && strpos($msg, ', ')) {
        $msg = substr($msg, strpos($msg, ', ') + 1);
    }
    $r = q("update notify set msg = '%s' where id = %d and uid = %d", dbesc($msg), intval($notify_id), intval($datarray['uid']));
    // send email notification if notification preferences permit
    require_once 'bbcode.php';
    if (intval($recip['channel_notifyflags']) & intval($params['type']) || $params['type'] == NOTIFY_SYSTEM) {
        logger('notification: sending notification email');
        $hn = get_pconfig($recip['channel_id'], 'system', 'email_notify_host');
        if ($hn && !stristr(get_app()->get_hostname(), $hn)) {
            // this isn't the email notification host
            pop_lang();
            return;
        }
        $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r", "\\n"), array("", "\n"), $body))), ENT_QUOTES, 'UTF-8'));
        $htmlversion = bbcode(stripslashes(str_replace(array("\\r", "\\n"), array("", "<br />\n"), $body)));
        // use $_SESSION['zid_override'] to force zid() to use
        // the recipient address instead of the current observer
        $_SESSION['zid_override'] = $recip['channel_address'] . '@' . get_app()->get_hostname();
        $_SESSION['zrl_override'] = z_root() . '/channel/' . $recip['channel_address'];
        $textversion = zidify_links($textversion);
        $htmlversion = zidify_links($htmlversion);
        // unset when done to revert to normal behaviour
        unset($_SESSION['zid_override']);
        unset($_SESSION['zrl_override']);
        $datarray = array();
        $datarray['banner'] = $banner;
        $datarray['product'] = $product;
        $datarray['preamble'] = $preamble;
        $datarray['sitename'] = $sitename;
        $datarray['siteurl'] = $siteurl;
        $datarray['type'] = $params['type'];
        $datarray['parent'] = $params['parent_mid'];
        $datarray['source_name'] = $sender['xchan_name'];
        $datarray['source_link'] = $sender['xchan_url'];
        $datarray['source_photo'] = $sender['xchan_photo_s'];
        $datarray['uid'] = $recip['channel_id'];
        $datarray['username'] = $recip['channel_name'];
        $datarray['hsitelink'] = $hsitelink;
        $datarray['tsitelink'] = $tsitelink;
        $datarray['hitemlink'] = '<a href="' . $itemlink . '">' . $itemlink . '</a>';
        $datarray['titemlink'] = $itemlink;
        $datarray['thanks'] = $thanks;
        $datarray['site_admin'] = $site_admin;
        $datarray['title'] = stripslashes($title);
        $datarray['htmlversion'] = $htmlversion;
        $datarray['textversion'] = $textversion;
        $datarray['subject'] = $subject;
        $datarray['headers'] = $additional_mail_header;
        $datarray['email_secure'] = false;
        call_hooks('enotify_mail', $datarray);
        // Default to private - don't disclose message contents over insecure channels (such as email)
        // Might be interesting to use GPG,PGP,S/MIME encryption instead
        // but we'll save that for a clever plugin developer to implement
        $private_activity = false;
        if (!$datarray['email_secure']) {
            switch ($params['type']) {
                case NOTIFY_WALL:
                case NOTIFY_TAGSELF:
                case NOTIFY_POKE:
                case NOTIFY_COMMENT:
                    if (!$private) {
                        break;
                    }
                    $private_activity = true;
                case NOTIFY_MAIL:
                    $datarray['textversion'] = $datarray['htmlversion'] = $datarray['title'] = '';
                    $datarray['subject'] = preg_replace('/' . preg_quote(t('[Hubzilla:Notify]')) . '/', '$0*', $datarray['subject']);
                    break;
                default:
                    break;
            }
        }
        if ($private_activity && intval(get_pconfig($datarray['uid'], 'system', 'ignore_private_notifications'))) {
            pop_lang();
            return;
        }
        // load the template for private message notifications
        $tpl = get_markup_template('email_notify_html.tpl');
        $email_html_body = replace_macros($tpl, array('$banner' => $datarray['banner'], '$product' => $datarray['product'], '$preamble' => $datarray['preamble'], '$sitename' => $datarray['sitename'], '$siteurl' => $datarray['siteurl'], '$source_name' => $datarray['source_name'], '$source_link' => $datarray['source_link'], '$source_photo' => $datarray['source_photo'], '$username' => $datarray['to_name'], '$hsitelink' => $datarray['hsitelink'], '$hitemlink' => $datarray['hitemlink'], '$thanks' => $datarray['thanks'], '$site_admin' => $datarray['site_admin'], '$title' => $datarray['title'], '$htmlversion' => $datarray['htmlversion']));
        // load the template for private message notifications
        $tpl = get_markup_template('email_notify_text.tpl');
        $email_text_body = replace_macros($tpl, array('$banner' => $datarray['banner'], '$product' => $datarray['product'], '$preamble' => $datarray['preamble'], '$sitename' => $datarray['sitename'], '$siteurl' => $datarray['siteurl'], '$source_name' => $datarray['source_name'], '$source_link' => $datarray['source_link'], '$source_photo' => $datarray['source_photo'], '$username' => $datarray['to_name'], '$tsitelink' => $datarray['tsitelink'], '$titemlink' => $datarray['titemlink'], '$thanks' => $datarray['thanks'], '$site_admin' => $datarray['site_admin'], '$title' => $datarray['title'], '$textversion' => $datarray['textversion']));
        //		logger('text: ' . $email_text_body);
        // use the EmailNotification library to send the message
        enotify::send(array('fromName' => $sender_name, 'fromEmail' => $sender_email, 'replyTo' => $sender_email, 'toEmail' => $recip['account_email'], 'messageSubject' => $datarray['subject'], 'htmlVersion' => $email_html_body, 'textVersion' => $email_text_body, 'additionalMailHeader' => $datarray['headers']));
    }
    pop_lang();
}
Пример #9
0
/**
 * "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.
 *
 */
function conversation(&$a, $items, $mode, $update, $preview = false)
{
    require_once 'bbcode.php';
    $profile_owner = 0;
    $page_writeable = false;
    if ($mode === 'network') {
        $profile_owner = local_user();
        $page_writeable = true;
    }
    if ($mode === 'profile') {
        $profile_owner = $a->profile['profile_uid'];
        $page_writeable = can_write_wall($a, $profile_owner);
    }
    if ($mode === 'notes') {
        $profile_owner = local_user();
        $page_writeable = true;
    }
    if ($mode === 'display') {
        $profile_owner = $a->profile['uid'];
        $page_writeable = can_write_wall($a, $profile_owner);
    }
    if ($mode === 'community') {
        $profile_owner = 0;
        $page_writeable = false;
    }
    if ($update) {
        $return_url = $_SESSION['return_url'];
    } else {
        $return_url = $_SESSION['return_url'] = $a->cmd;
    }
    load_contact_links(local_user());
    $cmnt_tpl = get_markup_template('comment_item.tpl');
    $tpl = get_markup_template('wall_item.tpl');
    $wallwall = get_markup_template('wallwall_item.tpl');
    $hide_comments_tpl = get_markup_template('hide_comments.tpl');
    $alike = array();
    $dlike = array();
    // array with html for each thread (parent+comments)
    $threads = array();
    $threadsid = -1;
    if (count($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');
            foreach ($items as $item) {
                $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'];
                }
                $sp = false;
                $profile_link = best_link_url($item, $sp);
                if ($sp) {
                    $sparkle = ' sparkle';
                }
                if ($profile_link === 'mailbox') {
                    $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']) ? $item['author-avatar'] : $item['thumb'];
                }
                $location = $item['location'] ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '';
                $coord = $item['coord'] ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '';
                if ($coord) {
                    if ($location) {
                        $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
                    } else {
                        $location = '<span class="smalltext">' . $coord . '</span>';
                    }
                }
                localize_item($item);
                if ($mode === 'network-new') {
                    $dropping = true;
                } else {
                    $dropping = false;
                }
                $drop = array('dropping' => $dropping, 'select' => t('Select'), 'delete' => t('Delete'));
                $star = false;
                $isstarred = "unstarred";
                $lock = false;
                $likebuttons = false;
                $shareable = false;
                $body = prepare_body($item, true);
                $tmp_item = replace_macros($tpl, array('$id' => $item['item_id'], '$linktitle' => sprintf(t('View %s\'s profile @ %s'), $profile_name, strlen($item['author-link']) ? $item['author-link'] : $item['url']), '$profile_url' => $profile_link, '$item_photo_menu' => item_photo_menu($item), '$name' => template_escape($profile_name), '$sparkle' => $sparkle, '$lock' => $lock, '$thumb' => $profile_avatar, '$title' => template_escape($item['title']), '$body' => template_escape($body), '$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' => '', '$owner_name' => template_escape($owner_name), '$owner_url' => $owner_url, '$owner_photo' => $owner_photo, '$plink' => get_plink($item), '$edpost' => false, '$isstarred' => $isstarred, '$star' => $star, '$drop' => $drop, '$vote' => $likebuttons, '$like' => '', '$dislike' => '', '$comment' => '', '$conv' => $preview ? '' : array('href' => $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'], 'title' => t('View in context')), '$wait' => t('Please wait')));
                $arr = array('item' => $item, 'output' => $tmp_item);
                call_hooks('display_item', $arr);
                $threads[$threadsid]['id'] = $item['item_id'];
                $threads[$threadsid]['html'] .= $arr['output'];
            }
        } else {
            // Normal View
            // Figure out how many comments each parent has
            // (Comments all have gravity of 6)
            // Store the result in the $comments array
            $comments = array();
            foreach ($items as $item) {
                if (intval($item['gravity']) == 6 && $item['id'] != $item['parent']) {
                    if (!x($comments, $item['parent'])) {
                        $comments[$item['parent']] = 1;
                    } else {
                        $comments[$item['parent']] += 1;
                    }
                }
            }
            // map all the like/dislike activities for each parent item
            // Store these in the $alike and $dlike arrays
            foreach ($items as $item) {
                like_puller($a, $item, $alike, 'like');
                like_puller($a, $item, $dlike, 'dislike');
            }
            $comments_collapsed = false;
            $blowhard = 0;
            $blowhard_count = 0;
            foreach ($items as $item) {
                $comment = '';
                $template = $tpl;
                $commentww = '';
                $sparkle = '';
                $owner_url = $owner_photo = $owner_name = '';
                // We've already parsed out like/dislike for special treatment. We can ignore them now
                if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && $item['id'] != $item['parent']) {
                    continue;
                }
                $toplevelpost = $item['id'] == $item['parent'] ? true : false;
                $toplevelprivate = false;
                // Take care of author collapsing and comment collapsing
                // If a single author has more than 3 consecutive top-level posts, squash the remaining ones.
                // If there are more than two comments, squash all but the last 2.
                if ($toplevelpost) {
                    $toplevelprivate = $toplevelpost && $item['private'] ? true : false;
                    $item_writeable = $item['writable'] || $item['self'] ? true : false;
                    /*if($blowhard == $item['cid'] && (! $item['self']) && ($mode != 'profile') && ($mode != 'notes')) {
                    			$blowhard_count ++;
                    			if($blowhard_count == 3) {
                    				$o .= '<div class="icollapse-wrapper fakelink" id="icollapse-wrapper-' . $item['parent'] 
                    					. '" onclick="openClose(' . '\'icollapse-' . $item['parent'] . '\'); $(\'#icollapse-wrapper-' . $item['parent'] . '\').hide();" >' 
                    					. t('See more posts like this') . '</div>' . '<div class="icollapse" id="icollapse-' 
                    					. $item['parent'] . '" style="display: none;" >';
                    			}
                    		}
                    		else {
                    			$blowhard = $item['cid'];					
                    			if($blowhard_count >= 3)
                    				$o .= '</div>';
                    			$blowhard_count = 0;
                    		}*/
                    $comments_seen = 0;
                    $comments_collapsed = false;
                    $threadsid++;
                    $threads[$threadsid]['id'] = $item['item_id'];
                    $threads[$threadsid]['html'] = "";
                } else {
                    // prevent private email from leaking into public conversation
                    if (!$toplevelpost && !toplevelprivate && $item['private'] && $profile_owner != local_user()) {
                        continue;
                    }
                    $comments_seen++;
                }
                $override_comment_box = $page_writeable && $item_writeable ? true : false;
                $show_comment_box = $page_writeable && $item_writeable && $comments_seen == $comments[$item['parent']] ? true : false;
                if ($comments[$item['parent']] > 2 && $comments_seen <= $comments[$item['parent']] - 2 && $item['gravity'] == 6) {
                    if (!$comments_collapsed) {
                        // IMPORTANT: the closing </div> in the hide_comments template
                        // is supplied below in code.
                        $threads[$threadsid]['html'] .= replace_macros($hide_comments_tpl, array('$id' => $item['parent'], '$num_comments' => sprintf(tt('%d comment', '%d comments', $comments[$item['parent']]), $comments[$item['parent']]), '$display' => 'none', '$hide_text' => t('show more')));
                        $comments_collapsed = true;
                    }
                }
                if ($comments[$item['parent']] > 2 && $comments_seen == $comments[$item['parent']] - 1) {
                    $threads[$threadsid]['html'] .= '</div>';
                }
                $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'];
                $lock = $item['private'] || $item['uid'] == local_user() && (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) ? t('Private Message') : false;
                // Top-level wall post not written by the wall owner (wall-to-wall)
                // First figure out who owns it.
                $osparkle = '';
                if ($toplevelpost && !$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 on the left of the wall-to-wall notice.
                        $owner_url = $a->page_contact['url'];
                        $owner_photo = $a->page_contact['thumb'];
                        $owner_name = $a->page_contact['name'];
                        $template = $wallwall;
                        $commentww = 'ww';
                    }
                    if (!$item['wall'] && strlen($item['owner-link']) && $item['owner-link'] != $item['author-link']) {
                        // Could be anybody.
                        $owner_url = $item['owner-link'];
                        $owner_photo = $item['owner-avatar'];
                        $owner_name = $item['owner-name'];
                        $template = $wallwall;
                        $commentww = 'ww';
                        // If it is our contact, use a friendly redirect link
                        if (link_compare($item['owner-link'], $item['url']) && $item['network'] === 'dfrn') {
                            $owner_url = $redirect_url;
                            $osparkle = ' sparkle';
                        }
                    }
                }
                $likebuttons = '';
                $shareable = $profile_owner == local_user() && $mode != 'display' && !$item['private'] ? true : false;
                if ($page_writeable) {
                    if ($toplevelpost) {
                        $likebuttons = array('like' => array(t("I like this (toggle)"), t("like")), 'dislike' => array(t("I don't like this (toggle)"), t("dislike")));
                        if ($shareable) {
                            $likebuttons['share'] = array(t('Share this'), t('share'));
                        }
                    }
                    if ($show_comment_box || $show_comment_box == false && $override_comment_box == false && $item['last-child']) {
                        $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['parent'], '$profile_uid' => $profile_owner, '$mylink' => $a->contact['url'], '$mytitle' => t('This is you'), '$myphoto' => $a->contact['thumb'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), '$ww' => $mode === 'network' ? $commentww : ''));
                    }
                }
                $edpost = $profile_owner == local_user() && $toplevelpost && intval($item['wall']) == 1 || $mode === 'notes' ? array($a->get_baseurl() . "/editpost/" . $item['id'], t("Edit")) : False;
                $drop = '';
                $dropping = 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'));
                $star = false;
                $isstarred = "unstarred";
                if ($profile_owner == local_user() && $toplevelpost) {
                    $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' => "");
                }
                $photo = $item['photo'];
                $thumb = $item['thumb'];
                // Post was remotely authored.
                $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 ($sp) {
                    $sparkle = ' sparkle';
                }
                if ($profile_link === 'mailbox') {
                    $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'] : $thumb;
                }
                $like = x($alike, $item['id']) ? format_like($alike[$item['id']], $alike[$item['id'] . '-l'], 'like', $item['id']) : '';
                $dislike = x($dlike, $item['id']) ? format_like($dlike[$item['id']], $dlike[$item['id'] . '-l'], 'dislike', $item['id']) : '';
                $location = $item['location'] ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '';
                $coord = $item['coord'] ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '';
                if ($coord) {
                    if ($location) {
                        $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
                    } else {
                        $location = '<span class="smalltext">' . $coord . '</span>';
                    }
                }
                $indent = $toplevelpost ? '' : ' comment';
                if (strcmp(datetime_convert('UTC', 'UTC', $item['created']), datetime_convert('UTC', 'UTC', 'now - 12 hours')) > 0) {
                    $indent .= ' shiny';
                }
                //
                localize_item($item);
                $tags = array();
                foreach (explode(',', $item['tag']) as $tag) {
                    $tag = trim($tag);
                    if ($tag != "") {
                        $tags[] = bbcode($tag);
                    }
                }
                // Build the HTML
                $body = prepare_body($item, true);
                $tmp_item = replace_macros($template, array('$type' => implode("", array_slice(split("/", $item['verb']), -1)), '$tags' => $tags, '$body' => 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'), $profile_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, '$drop' => $drop, '$vote' => $likebuttons, '$like' => $like, '$dislike' => $dislike, '$comment' => $comment, '$wait' => t('Please wait')));
                $arr = array('item' => $item, 'output' => $tmp_item);
                call_hooks('display_item', $arr);
                $threads[$threadsid]['html'] .= $arr['output'];
            }
        }
    }
    $page_template = get_markup_template("conversation.tpl");
    $o .= replace_macros($page_template, array('$threads' => $threads, '$dropping' => $dropping ? t('Delete Selected Items') : False));
    return $o;
}
Пример #10
0
function api_format_items($r, $user_info)
{
    //logger('api_format_items: ' . print_r($r,true));
    //logger('api_format_items: ' . print_r($user_info,true));
    $a = get_app();
    $ret = array();
    foreach ($r as $item) {
        localize_item($item);
        $status_user = $item['cid'] == $user_info['id'] ? $user_info : api_item_get_user($a, $item);
        $status = array('created_at' => api_date($item['created']), 'published' => api_date($item['created']), 'updated' => api_date($item['edited']), 'id' => intval($item['id']), 'message_id' => $item['uri'], 'text' => strip_tags(bbcode($item['body'])), 'statusnet_html' => bbcode($item['body']), 'source' => $item['app'] ? $item['app'] : 'web', 'url' => $item['plink'] != '' ? $item['plink'] : $item['author-link'], 'truncated' => False, 'in_reply_to_status_id' => $item['parent'] != $item['id'] ? intval($item['parent']) : '', 'in_reply_to_user_id' => '', 'favorited' => $item['starred'] ? true : false, 'in_reply_to_screen_name' => '', 'geo' => '', 'coordinates' => $item['coord'], 'place' => $item['location'], 'contributors' => '', 'annotations' => '', 'entities' => '', 'user' => $status_user, 'objecttype' => $item['object-type'] ? $item['object-type'] : ACTIVITY_OBJ_NOTE, 'verb' => $item['verb'] ? $item['verb'] : ACTIVITY_POST, 'self' => $a->get_baseurl() . "/api/statuses/show/" . $item['id'] . "." . $type, 'edit' => $a->get_baseurl() . "/api/statuses/show/" . $item['id'] . "." . $type);
        $ret[] = $status;
    }
    return $ret;
}
Пример #11
0
 /**
  * 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)
 {
     require_once "mod/proxy.php";
     $result = array();
     $a = $this->get_app();
     $item = $this->get_data();
     $edited = false;
     if (strcmp($item['created'], $item['edited']) != 0) {
         $edited = array('label' => t('This entry was edited'), 'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'), 'relative' => relative_date($item['edited']));
     }
     $commentww = '';
     $sparkle = '';
     $buttons = '';
     $dropping = false;
     $star = false;
     $ignore = false;
     $isstarred = "unstarred";
     $indent = '';
     $shiny = '';
     $osparkle = '';
     $total_children = $this->count_descendants();
     $conv = $this->get_conversation();
     $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;
     $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 {
         $edpost = false;
     }
     if ($this->get_data_value('uid') == local_user() || $this->is_visiting()) {
         $dropping = true;
     }
     $drop = array('dropping' => $dropping, 'pagedrop' => feature_enabled($conv->get_profile_owner(), 'multi_delete') ? $item['pagedrop'] : '', 'select' => t('Select'), 'delete' => t('Delete'));
     $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'];
     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($this->get_data_value('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);
     $searchpath = $a->get_baseurl() . "/search?tag=";
     $tags = array();
     $hashtags = array();
     $mentions = array();
     /*foreach(explode(',',$item['tag']) as $tag){
     			$tag = trim($tag);
     			if ($tag!="") {
     				$t = bbcode($tag);
     				$tags[] = $t;
     				if($t[0] == '#')
     					$hashtags[] = $t;
     				elseif($t[0] == '@')
     					$mentions[] = $t;
     			}
     		}*/
     $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 ($conv->get_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'));
             $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1", intval($item['uid']), intval($item['id']));
             if (count($r)) {
                 $ignore = array('do' => t("ignore thread"), 'undo' => t("unignore thread"), 'toggle' => t("toggle ignore status"), 'classdo' => $r[0]['ignored'] ? "hidden" : "", 'classundo' => $r[0]['ignored'] ? "" : "hidden", 'ignored' => t('ignored'));
             }
             $tagger = '';
             if (feature_enabled($conv->get_profile_owner(), 'commtag')) {
                 $tagger = array('add' => t("add tag"), 'class' => "");
             }
         }
     } else {
         $indent = 'comment';
     }
     if ($conv->is_writable()) {
         $buttons = array('like' => array(t("I like this (toggle)"), t("like")), 'dislike' => feature_enabled($conv->get_profile_owner(), 'dislike') ? array(t("I don't like this (toggle)"), t("dislike")) : '');
         if ($shareable) {
             $buttons['share'] = array(t('Share this'), t('share'));
         }
     }
     if (strcmp(datetime_convert('UTC', 'UTC', $item['created']), datetime_convert('UTC', 'UTC', 'now - 12 hours')) > 0) {
         $shiny = 'shiny';
     }
     localize_item($item);
     if ($item["postopts"] and !get_config("system", "suppress_language")) {
         //$langdata = explode(";", $item["postopts"]);
         //$langstr = substr($langdata[0], 5)." (".round($langdata[1]*100, 1)."%)";
         $langstr = "";
         if (substr($item["postopts"], 0, 5) == "lang=") {
             $postopts = substr($item["postopts"], 5);
             $languages = explode(":", $postopts);
             if (sizeof($languages) == 1) {
                 $languages = array();
                 $languages[] = $postopts;
             }
             foreach ($languages as $language) {
                 $langdata = explode(";", $language);
                 if ($langstr != "") {
                     $langstr .= ", ";
                 }
                 //$langstr .= $langdata[0]." (".round($langdata[1]*100, 1)."%)";
                 $langstr .= round($langdata[1] * 100, 1) . "% " . $langdata[0];
             }
         }
     }
     $body = prepare_body($item, true);
     list($categories, $folders) = get_cats_and_terms($item);
     if ($a->theme['template_engine'] === 'internal') {
         $body_e = template_escape($body);
         $text_e = strip_tags(template_escape($body));
         $name_e = template_escape($profile_name);
         $title_e = template_escape($item['title']);
         $location_e = template_escape($location);
         $owner_name_e = template_escape($this->get_owner_name());
     } else {
         $body_e = $body;
         $text_e = strip_tags($body);
         $name_e = $profile_name;
         $title_e = $item['title'];
         $location_e = $location;
         $owner_name_e = $this->get_owner_name();
     }
     // Disable features that aren't available in several networks
     if ($item["item_network"] != "dfrn" and isset($buttons["dislike"])) {
         unset($buttons["dislike"]);
         $tagger = '';
     }
     if ($item["item_network"] == "feed" and isset($buttons["like"])) {
         unset($buttons["like"]);
     }
     if ($item["item_network"] == "mail" and isset($buttons["like"])) {
         unset($buttons["like"]);
     }
     if ($item["item_network"] == "dspr" and $indent == 'comment' and isset($buttons["like"])) {
         unset($buttons["like"]);
     }
     // Facebook can like comments - but it isn't programmed in the connector yet.
     if ($item["item_network"] == "face" and $indent == 'comment' and isset($buttons["like"])) {
         unset($buttons["like"]);
     }
     $tmp_item = array('template' => $this->get_template(), 'type' => implode("", array_slice(explode("/", $item['verb']), -1)), 'tags' => $item['tags'], 'hashtags' => $item['hashtags'], 'mentions' => $item['mentions'], 'txt_cats' => t('Categories:'), 'txt_folders' => t('Filed under:'), 'has_cats' => count($categories) ? 'true' : '', 'has_folders' => count($folders) ? 'true' : '', 'categories' => $categories, 'folders' => $folders, 'body' => $body_e, 'text' => $text_e, 'id' => $this->get_id(), 'guid' => $item['guid'], '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'), $this->get_owner_name(), strlen($item['owner-link']) ? $item['owner-link'] : $item['url']), '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' => $name_e, 'thumb' => proxy_url($profile_avatar), 'osparkle' => $osparkle, 'sparkle' => $sparkle, 'title' => $title_e, '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']), 'app' => $item['app'], 'created' => relative_date($item['created']), 'lock' => $lock, 'location' => $location_e, 'indent' => $indent, 'shiny' => $shiny, 'owner_url' => $this->get_owner_url(), 'owner_photo' => proxy_url($this->get_owner_photo()), 'owner_name' => $owner_name_e, 'plink' => get_plink($item), 'edpost' => feature_enabled($conv->get_profile_owner(), 'edit_posts') ? $edpost : '', 'isstarred' => $isstarred, 'star' => feature_enabled($conv->get_profile_owner(), 'star_posts') ? $star : '', 'ignore' => feature_enabled($conv->get_profile_owner(), 'ignore_posts') ? $ignore : '', 'tagger' => $tagger, 'filer' => feature_enabled($conv->get_profile_owner(), 'filing') ? $filer : '', 'drop' => $drop, 'vote' => $buttons, 'like' => $like, 'dislike' => $dislike, 'switchcomment' => t('Comment'), 'comment' => $this->get_comment_box($indent), 'previewing' => $conv->is_preview() ? ' preview ' : '', 'wait' => t('Please wait'), 'thread_level' => $thread_level, 'postopts' => $langstr, 'edited' => $edited, 'network' => $item["item_network"], 'network_name' => network_to_name($item['item_network']));
     $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]['hidden_comments_num'] = $total_children;
             $result['children'][0]['hidden_comments_text'] = tt('comment', 'comments', $total_children);
             $result['children'][0]['hide_text'] = t('show more');
             if ($thread_level > 1) {
                 $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
             } else {
                 $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true;
             }
         }
     }
     if ($this->is_toplevel()) {
         $result['total_comments_num'] = "{$total_children}";
         $result['total_comments_text'] = tt('comment', 'comments', $total_children);
     }
     $result['private'] = $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;
 }
Пример #12
0
function api_format_items($r, $user_info)
{
    //logger('api_format_items: ' . print_r($r,true));
    //logger('api_format_items: ' . print_r($user_info,true));
    $a = get_app();
    $ret = array();
    foreach ($r as $item) {
        localize_item($item);
        $status_user = $item['cid'] == $user_info['id'] ? $user_info : api_item_get_user($a, $item);
        if ($item['parent'] != $item['id']) {
            $r = q("select id from item where parent=%s and id<%s order by id desc limit 1", intval($item['parent']), intval($item['id']));
            if ($r) {
                $in_reply_to_status_id = $r[0]['id'];
            } else {
                $in_reply_to_status_id = $item['parent'];
            }
            $r = q("select `item`.`contact-id`, `contact`.nick, `item`.`author-name` from item, contact\n\t\t\t\t\twhere `contact`.`id` = `item`.`contact-id` and `item`.id=%d", intval($in_reply_to_status_id));
            $in_reply_to_screen_name = $r[0]['author-name'];
            $in_reply_to_user_id = $r[0]['contact-id'];
        } else {
            $in_reply_to_screen_name = '';
            $in_reply_to_user_id = 0;
            $in_reply_to_status_id = 0;
        }
        // Workaround for ostatus messages where the title is identically to the body
        $statusbody = trim(html2plain(bbcode($item['body'], false, false, true), 0));
        $statustitle = trim($item['title']);
        if ($statustitle != '' and strpos($statusbody, $statustitle) !== false) {
            $statustext = trim($statusbody);
        } else {
            $statustext = trim($statustitle . "\n\n" . $statusbody);
        }
        if ($item["network"] == NETWORK_FEED and strlen($statustext) > 1000) {
            $statustext = substr($statustext, 0, 1000) . "... \n" . $item["plink"];
        }
        $status = array('text' => $statustext, 'truncated' => False, 'created_at' => api_date($item['created']), 'in_reply_to_status_id' => $in_reply_to_status_id, 'source' => $item['app'] ? $item['app'] : 'web', 'id' => intval($item['id']), 'in_reply_to_user_id' => $in_reply_to_user_id, 'in_reply_to_screen_name' => $in_reply_to_screen_name, 'geo' => '', 'favorited' => $item['starred'] ? true : false, 'user' => $status_user, 'statusnet_html' => trim(bbcode($item['body'])), 'statusnet_conversation_id' => $item['parent']);
        // Seesmic doesn't like the following content
        if ($_SERVER['HTTP_USER_AGENT'] != 'Seesmic') {
            $status2 = array('updated' => api_date($item['edited']), 'published' => api_date($item['created']), 'message_id' => $item['uri'], 'url' => $item['plink'] != '' ? $item['plink'] : $item['author-link'], 'coordinates' => $item['coord'], 'place' => $item['location'], 'contributors' => '', 'annotations' => '', 'entities' => '', 'objecttype' => $item['object-type'] ? $item['object-type'] : ACTIVITY_OBJ_NOTE, 'verb' => $item['verb'] ? $item['verb'] : ACTIVITY_POST, 'self' => $a->get_baseurl() . "/api/statuses/show/" . $item['id'] . "." . $type, 'edit' => $a->get_baseurl() . "/api/statuses/show/" . $item['id'] . "." . $type);
            $status = array_merge($status, $status2);
        }
        $ret[] = $status;
    }
    return $ret;
}
Пример #13
0
function api_format_items($r, $user_info, $filter_user = false)
{
    $a = get_app();
    $ret = array();
    foreach ($r as $item) {
        api_share_as_retweet($a, api_user(), $item);
        localize_item($item);
        $status_user = api_item_get_user($a, $item);
        // Look if the posts are matching if they should be filtered by user id
        if ($filter_user and $status_user["id"] != $user_info["id"]) {
            continue;
        }
        if ($item['thr-parent'] != $item['uri']) {
            $r = q("SELECT id FROM item WHERE uid=%d AND uri='%s' LIMIT 1", intval(api_user()), dbesc($item['thr-parent']));
            if ($r) {
                $in_reply_to_status_id = intval($r[0]['id']);
            } else {
                $in_reply_to_status_id = intval($item['parent']);
            }
            $in_reply_to_status_id_str = (string) intval($item['parent']);
            $in_reply_to_screen_name = NULL;
            $in_reply_to_user_id = NULL;
            $in_reply_to_user_id_str = NULL;
            $r = q("SELECT `author-link` FROM item WHERE uid=%d AND id=%d LIMIT 1", intval(api_user()), intval($in_reply_to_status_id));
            if ($r) {
                $r = q("SELECT * FROM unique_contacts WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link'])));
                if ($r) {
                    if ($r[0]['nick'] == "") {
                        $r[0]['nick'] = api_get_nick($r[0]["url"]);
                    }
                    $in_reply_to_screen_name = $r[0]['nick'] ? $r[0]['nick'] : $r[0]['name'];
                    $in_reply_to_user_id = intval($r[0]['id']);
                    $in_reply_to_user_id_str = (string) intval($r[0]['id']);
                }
            }
        } else {
            $in_reply_to_screen_name = NULL;
            $in_reply_to_user_id = NULL;
            $in_reply_to_status_id = NULL;
            $in_reply_to_user_id_str = NULL;
            $in_reply_to_status_id_str = NULL;
        }
        // Workaround for ostatus messages where the title is identically to the body
        //$statusbody = trim(html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 5, true), 0));
        $html = bbcode(api_clean_plain_items($item['body']), false, false, 2, true);
        $statusbody = trim(html2plain($html, 0));
        $statustitle = trim($item['title']);
        if ($statustitle != '' and strpos($statusbody, $statustitle) !== false) {
            $statustext = trim($statusbody);
        } else {
            $statustext = trim($statustitle . "\n\n" . $statusbody);
        }
        if ($item["network"] == NETWORK_FEED and strlen($statustext) > 1000) {
            $statustext = substr($statustext, 0, 1000) . "... \n" . $item["plink"];
        }
        $status = array('text' => $statustext, 'truncated' => False, 'created_at' => api_date($item['created']), 'in_reply_to_status_id' => $in_reply_to_status_id, 'in_reply_to_status_id_str' => $in_reply_to_status_id_str, 'source' => $item['app'] ? $item['app'] : 'web', 'id' => intval($item['id']), 'id_str' => (string) intval($item['id']), 'in_reply_to_user_id' => $in_reply_to_user_id, 'in_reply_to_user_id_str' => $in_reply_to_user_id_str, 'in_reply_to_screen_name' => $in_reply_to_screen_name, 'geo' => NULL, 'favorited' => $item['starred'] ? true : false, 'user' => $status_user, 'statusnet_html' => trim(bbcode($item['body'], false, false)), 'statusnet_conversation_id' => $item['parent']);
        if ($item['title'] != "") {
            $status['statusnet_html'] = "<h4>" . bbcode($item['title']) . "</h4>\n" . $status['statusnet_html'];
        }
        $entities = api_get_entitities($status['text'], $item['body']);
        if (count($entities) > 0) {
            $status['entities'] = $entities;
        }
        if ($item['item_network'] != "" and $status["source"] == 'web') {
            $status["source"] = network_to_name($item['item_network']);
        } else {
            if ($item['item_network'] != "" and network_to_name($item['item_network']) != $status["source"]) {
                $status["source"] = trim($status["source"] . ' (' . network_to_name($item['item_network']) . ')');
            }
        }
        // Retweets are only valid for top postings
        // It doesn't work reliable with the link if its a feed
        $IsRetweet = $item['owner-link'] != $item['author-link'];
        if ($IsRetweet) {
            $IsRetweet = ($item['owner-name'] != $item['author-name'] or $item['owner-avatar'] != $item['author-avatar']);
        }
        if ($IsRetweet and $item["id"] == $item["parent"]) {
            $retweeted_status = $status;
            $retweeted_status["user"] = api_get_user($a, $item["author-link"]);
            $status["retweeted_status"] = $retweeted_status;
        }
        // "uid" and "self" are only needed for some internal stuff, so remove it from here
        unset($status["user"]["uid"]);
        unset($status["user"]["self"]);
        // 'geo' => array('type' => 'Point',
        //                   'coordinates' => array((float) $notice->lat,
        //                                          (float) $notice->lon));
        $ret[] = $status;
    }
    return $ret;
}
Пример #14
0
 /**
  * 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;
 }