public function render($current_user, $criteria, $template_name = '') { global $vbulletin, $vbphrase, $show; require_once DIR . '/includes/functions_forumdisplay.php'; require_once DIR . '/includes/functions_misc.php'; require_once DIR . '/includes/functions_user.php'; fetch_phrase_group('search'); if (!strlen($template_name)) { $template_name = 'search_results_postbit'; } /* Post is not a good name for this array, however its what it used to be called (when it wasn't such a bad name) and changing it makes it certain that a lot of hooks are going to break. */ $post = array(); $thread = $this->post->get_thread(); $forum = $thread->get_forum(); $this->set_replydata($this->post->get_field('threadid'), $this->post->get_field('postid'), $current_user); if ($this->replydata['mylastpost'] > 0) { $post_statusicon[] = 'dot'; } if (!$thread->get_field('open')) { $post_statusicon[] = 'lock'; } if ($this->replydata['lastread'] < $thread->get_field('lastpost')) { $post_statusicon[] = 'new'; } if (!count($post_statusicon)) { $post_statusicon[] = 'old'; } $post_statusicon = implode('_', $post_statusicon); $post['postid'] = $this->post->get_field('postid'); $post['postdateline'] = $this->post->get_field('dateline'); $post['posttitle'] = vB_Search_Searchtools::stripHtmlTags(htmlspecialchars_decode($this->post->get_display_title())); if (empty($post['posttitle'])) { $post['posttitle'] = $vbphrase['view_post']; } $post['visible'] = $this->post->get_field('visible'); $post['attach'] = $this->post->get_field('attach'); $post['highlight'] = $criteria->get_highlights(); $post['userid'] = $this->post->get_field('userid'); $post['username'] = $this->post->get_field('username'); $post['threadid'] = $thread->get_field('threadid'); $post['threadtitle'] = $thread->get_field('title'); $post['threadiconid'] = $thread->get_field('iconid'); $post['replycount'] = $thread->get_field('replycount'); $post['views'] = $thread->get_field('views') > 0 ? $thread->get_field('views') : $thread->get_field('replycount') + 1; $post['firstpostid'] = $thread->get_field('firstpostid'); $post['prefixid'] = $thread->get_field('prefixid'); $post['taglist'] = $thread->get_field('taglist'); $post['pollid'] = $thread->get_field('pollid'); $post['sticky'] = $thread->get_field('sticky'); $post['open'] = $thread->get_field('open'); $post['lastpost'] = $thread->get_field('lastpost'); $post['forumid'] = $thread->get_field('forumid'); $post['thread_visible'] = $thread->get_field('visible'); $post['forumtitle'] = $forum->get_field('title'); $post['posticonid'] = $this->post->get_field('iconid'); $post['allowicons'] = $forum->allow_icons(); $post['posticonpath'] = $this->post->get_icon_path(); $post['posticontitle'] = $this->post->get_icon_title(); $post['posticon'] = $post['allowicons'] and $post['posticonpath']; $lastread = $forum->get_last_read_by_current_user($current_user); if ($current_user->hasForumPermission($forum->get_field('forumid'), 'canviewthreads')) { if (defined('VB_API') and VB_API === true) { $post['pagetext'] = $this->post->get_field('pagetext'); $post['message_plain'] = build_message_plain($post['pagetext']); } else { $post['pagetext'] = nl2br($this->post->get_summary(200)); } } $show['deleted'] = false; if ($current_user->isModerator()) { $log = $this->post->get_deletion_log_array(); if ($log['userid']) { $post['del_phrase'] = $vbphrase['message_deleted_by_x']; } else { $log = $thread->get_deletion_log_array(); if (!$log['userid']) { $post['del_phrase'] = $vbphrase['thread_deleted_by_x']; $log = false; } } if ($log) { $post['del_username'] = $log['username']; $post['del_userid'] = $log['userid']; $post['del_reason'] = $log['reason']; $show['deleted'] = true; } } $post['prefixid'] = $thread->get_field('prefixid'); if ($post['prefixid']) { $post['prefix_plain_html'] = htmlspecialchars_uni($vbphrase["prefix_{$post['prefixid']}_title_plain"]); $post['prefix_rich'] = $vbphrase["prefix_{$post['prefixid']}_title_rich"]; } else { $post['prefix_plain_html'] = ''; $post['prefix_rich'] = ''; } $show['disabled'] = !$this->can_inline_mod($current_user); $postuser = $this->post->get_record(); $post = process_thread_array($post, $lastread, $post['allowicons']); ($hook = vBulletinHook::fetch_hook('search_results_postbit')) ? eval($hook) : false; $template = vB_Template::create($template_name); $template->register('post', $post); $template->register('userinfo', $postuser); $template->register('threadinfo', $thread->get_record()); $template->register('dateline', $this->post->get_field('dateline')); if ($vbulletin->options['avatarenabled']) { $template->register('avatar', fetch_avatar_from_record($this->post->get_record(), true)); } $pageinfo_thread = array(); $pageinfo_post = array('p' => $post['postid']); if (!empty($post['highlight'])) { $pageinfo_post['highlight'] = urlencode(implode(' ', $post['highlight'])); $pageinfo_thread['highlight'] = urlencode(implode(' ', $post['highlight'])); } $template->register('pageinfo_post', $pageinfo_post); $template->register('pageinfo_thread', $pageinfo_thread); $template->register('post_statusicon', $post_statusicon); return $template->render(); }
/** * Template method. Calls all the appropriate methods to build a post and then evaluates the template. * * @param array Post information * * @return string HTML for the post */ function construct_postbit(&$post) { global $ad_location; $this->post =& $post; $thread =& $this->thread; $forum =& $this->forum; // make sure we can display this post if ($this->is_displayable() == false) { return ''; } global $show, $vbphrase; global $spacer_open, $spacer_close; global $bgclass, $altbgclass; exec_switch_bg(); $template_hook = array(); ($hook = vBulletinHook::fetch_hook('postbit_display_start')) ? eval($hook) : false; // put together each part of the post $this->prep_post_start(); $this->process_date_status(); $this->process_edit_info(); $this->process_icon(); $this->process_ip(); if (!empty($this->post['userid'])) { $this->process_registered_user(); $this->process_im_icons(); } else { $this->process_unregistered_user(); } if ($this->post['avatarurl'] and $this->post['avwidth'] and $this->post['avheight']) { $this->post['avwidth'] = 'width="' . $this->post['avwidth'] . '"'; $this->post['avheight'] = 'height="' . $this->post['avheight'] . '"'; } else { $this->post['avwidth'] = ''; $this->post['avheight'] = ''; } $this->bbcode_parser->containerid = $this->post['postid']; if (defined('VB_API') and VB_API === true) { if (!$post['pagetext']) { $post['pagetext'] = $post['message']; // PM doesn't have $post['pagetext'] } $post['message_plain'] = build_message_plain($post['pagetext']); $post['message_bbcode'] = $post['pagetext']; } $this->parse_bbcode(); $this->process_attachments(); // finish prepping the post $this->prep_post_end(); $pageinfo_post = array('p' => $post['postid']); if ($this->templatename != 'postbit') { $pageinfo_post['viewfull'] = 1; } // execute hook ($hook = vBulletinHook::fetch_hook('postbit_display_complete')) ? eval($hook) : false; $show['last_ad'] = $show['first_ad'] = $show['first_adsense'] = false; if ($post['isfirstshown']) { //this does not appear to be an ad slot, rather it appears to be some shim html //that needs to be rendered if the firstpost google ad is included. $template = vB_Template::create('ad_showthread_firstpost_sig'); $template->register('adsense_pub_id', $this->registry->adsense_pub_id); $template->register('adsense_host_id', $this->registry->adsense_host_id); $ad_location['ad_showthread_firstpost_sig'] = $template->render(); $template = vB_Template::create('ad_showthread_firstpost_start'); $template->register('adsense_pub_id', $this->registry->adsense_pub_id); $template->register('adsense_host_id', $this->registry->adsense_host_id); $ad_location['ad_showthread_firstpost_start'] = trim($template->render(true)); if ($ad_location['ad_showthread_firstpost_start']) { $show['first_ad'] = true; } if ($ad_location['thread_first_post_content'] = trim(vB_Template::create('ad_thread_first_post_content')->render(true)) and !preg_match('#^<div id="ad_thread_first_post_content">.+</div>$#si', $ad_location['thread_first_post_content'])) { $ad_location['thread_first_post_content'] = ''; } } else { if ($post['islastshown'] and $ad_location['thread_last_post_content'] = trim(vB_Template::create('ad_thread_last_post_content')->render(true)) and !preg_match('#^<div id="ad_thread_last_post_content">.+</div>$#si', $ad_location['thread_last_post_content'])) { $ad_location['thread_last_post_content'] = ''; } } if (!empty($ad_location['thread_first_post_content']) and $post['isfirstshown']) { $show['first_ad'] = true; } if (!empty($ad_location['thread_last_post_content'])) { $show['last_ad'] = true; } // prepare the member action drop-down menu // pass the local template hook so that each drop-down gets its own hook (per-postbit) $memberaction_dropdown = construct_memberaction_dropdown($post, $template_hook); // evaluate template $postid =& $post['postid']; $templater = vB_Template::create($this->template_prefix . $this->templatename); if ($this->add_promote_links and $this->registry->products['vbcms']) { if (!isset($this->registry->userinfo['permissions']['cms'])) { vBCMS_Permissions::getUserPerms(); } if ($this->registry->userinfo['permissions']['cms']['canpublish'][0] != -1) { $templater->register('promote_sectionid', $this->registry->userinfo['permissions']['cms']['canpublish'][0]); $templater->register('articletypeid', vB_Types::instance()->getContentTypeID('vBCms_Article')); $query = 'contenttypeid=' . vB_Types::instance()->getContentTypeID('vBCms_Article') . '&postid=' . $post['postid'] . '&parentid=1'; $promote_url = vB_Route::create('vBCms_Route_Content', '1/addcontent/')->getCurrentURL(null, null, $query); $templater->register('promote_url', $promote_url); } } $templater->register('ad_location', $ad_location); $templater->register('memberaction_dropdown', $memberaction_dropdown); $templater->register('pageinfo_post', $pageinfo_post); $templater->register('post', $post); $templater->register('postid', $postid); $templater->register('template_hook', $template_hook); $templater->register('reputationdisplay', $post['reputationdisplay']); $templater->register('thread', $thread); $postbit = $templater->render(); $templater = vB_Template::create('postbit_wrapper'); $templater->register('post', $post); $templater->register('postbit', $postbit); $templater->register('postbit_type', $this->templatename == 'postbit_legacy' ? 'postbit' : $this->templatename); $templater->register('spacer_close', $spacer_close); $templater->register('spacer_open', $spacer_open); $retval = $templater->render(); return $retval; }