Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
	/**
	 * Fetches the array of posts
	 *
	 * @return array				- the post information
	 */
	private function getPosts()
	{
		require_once DIR . "/includes/functions_user.php";
		require_once DIR . "/includes/class_bbcode.php";
		$datecut = TIMENOW - ($this->config['days'] * 86400);

		if (empty(vB::$vbulletin->userinfo['forumpermissions']))
		{
			require_once DIR . "/includes/functions.php";
			cache_permissions($userinfo);
		}
		$postarray = array();
		//we have some existing settings with config['forumchoice'] set to 0=> ''; That's no good
		if (empty($this->config['forumchoice']))
		{
			$this->config['forumchoice'] = array();
		}
		else if (is_array($this->config['forumchoice']) AND ($this->config['forumchoice'][0] == '') )
		{
			unset($this->config['forumchoice'][0]);
		}

		if (is_array($this->config['forumchoice']) AND in_array('subscribed', $this->config['forumchoice']))
		{
			$subscribejoin = " LEFT JOIN " . TABLE_PREFIX .	"subscribeforum AS subscribeforum
				ON (subscribeforum.forumid = forum.forumid AND subscribeforum.userid = " . vB::$vbulletin->userinfo['userid'] .
			" ) ";
		}
		else
		{
			$subscribejoin = '';

		}
		$forumids = array_keys(vB::$vbulletin->forumcache);
		foreach ($forumids AS $forumid)
		{
			$forumperms =& vB::$vbulletin->userinfo['forumpermissions']["$forumid"];
			if ($forumperms & vB::$vbulletin->bf_ugp_forumpermissions['canview']
				AND ($forumperms & vB::$vbulletin->bf_ugp_forumpermissions['canviewothers'])
				AND (($forumperms & vB::$vbulletin->bf_ugp_forumpermissions['canviewthreads']))
				AND verify_forum_password($forumid, vB::$vbulletin->forumcache["$forumid"]['password'], false)
				)
			{
					//Don't include the comments forum.
				if (vB::$vbulletin->options['vbcmsforumid'] AND (intval(vB::$vbulletin->options['vbcmsforumid']) == intval($forumid)))
				{
					continue;
				}
				//Or, if the user selected forums, anything not on the list.
				else if (! empty($this->config['forumchoice']) AND !in_array($forumid, $this->config['forumchoice']))
				{
					continue;
				}
				$forumchoice[] = $forumid;
			}
		}

		if (!empty($forumchoice) )
		{
			$forumsql = " AND (" . (empty($subscribejoin) ? '' : "subscribeforum.forumid IS NOT NULL OR ") . " thread.forumid IN(" . implode(',', $forumchoice) . ")";
			$associatedthread = (vB::$vbulletin->options['vbcmsforumid'] ?
					" AND (thread.forumid <> " . vB::$vbulletin->options['vbcmsforumid'] . ") )" : '');
		}
		else if (! empty($subscribejoin))
		{
			$forumsql = " AND subscribeforum.forumid IS NOT NULL ";
		}
		else
		{
			return $postarray;
		}

		$posts = vB::$vbulletin->db->query_read_slave($sql = "
			SELECT post.dateline, post.pagetext, post.allowsmilie, post.postid,
				thread.threadid, thread.title, thread.prefixid, post.attach, thread.replycount,
				forum.forumid, post.title AS posttitle, post.dateline AS postdateline,
				user.userid, user.username
				" . (vB::$vbulletin->options['avatarenabled'] ? ",avatar.avatarpath,
				(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,
				customavatar.width AS avwidth,customavatar.height AS avheight" : "") .
		 "	FROM " . TABLE_PREFIX . "post AS post
			JOIN " . TABLE_PREFIX . "thread AS thread ON (thread.threadid = post.threadid)
			JOIN " . TABLE_PREFIX . "forum AS forum ON(forum.forumid = thread.forumid)
			LEFT JOIN " . TABLE_PREFIX . "user AS user ON (post.userid = user.userid)
			" . (vB::$vbulletin->options['avatarenabled'] ? "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)" : "") . "
			$subscribejoin
			WHERE 1=1
				$forumsql
				$associatedthread
				AND thread.visible = 1
				AND post.visible = 1
				AND thread.open <> 10
				AND post.dateline > $datecut
				$globalignore
				" . ($this->userinfo['ignorelist'] ? "AND post.userid NOT IN (" . implode(',', explode(' ', $this->userinfo['ignorelist'])) . ")": '') . "
			ORDER BY post.dateline DESC
			LIMIT 0," . intval($this->config['count']) . "
		");

		$parser = new vB_BbCodeParser(vB::$vbulletin, fetch_tag_list());
		$optionval = vB::$vbulletin->bf_misc_forumoptions['allowhtml'];
		while ($post = vB::$vbulletin->db->fetch_array($posts))
		{
			$post['title'] = fetch_trimmed_title($post['title'], $this->config['newposts_titlemaxchars']);

			$allow_html = ((vB::$vbulletin->forumcache[$post['forumid']]['options'] & $optionval) AND $this->config['allow_html'] ? 1 : 0);
			$post['previewtext'] = fetch_censored_text($parser->get_preview($post['pagetext'], $this->default_previewlen, $allow_html));
			$post['pagetext'] = fetch_censored_text($parser->do_parse($post['pagetext'], $allow_html));

			$post['url'] = fetch_seo_url('thread', $post, array('p' => $post['postid'])) . '#post' . $post['postid'];
			$post['newposturl'] = fetch_seo_url('thread', $post, array('goto' => 'newpost'));
			$post['date'] = vbdate(vB::$vbulletin->options['dateformat'], $post['dateline'], true);
			$post['time'] = vbdate(vB::$vbulletin->options['timeformat'], $post['dateline']);

			if (intval($post['userid']) AND vB::$vbulletin->options['avatarenabled'])
			{
				$avatar = fetch_avatar_from_record($post);
			}
			else
			{
				$avatar = false;
			}

			$post['avatarurl'] = isset($avatar[0]) ? $avatar[0] : false;
			unset($avatar);
			$postarray[$post['postid']] = $post;
		}

		return $postarray;

	}
Exemplo n.º 3
0
 public function render($current_user, $criteria, $template_name = '')
 {
     require_once DIR . '/includes/functions_forumdisplay.php';
     require_once DIR . '/includes/functions_user.php';
     global $vbulletin, $show;
     if (!strlen($template_name)) {
         $template_name = 'search_threadbit';
     }
     $show['forumlink'] = true;
     // threadbit_deleted conditionals
     $show['threadtitle'] = true;
     $show['viewthread'] = true;
     $show['managethread'] = true;
     ($hook = vBulletinHook::fetch_hook('search_results_thread_start')) ? eval($hook) : false;
     //thread isn't a great name for this, but it stays consistant with
     //previous use and what will be expected in the hook.
     $thread = $this->thread->get_record();
     $this->set_replydata($thread['threadid'], $current_user);
     // get info from thread
     $thread['postid'] = $thread['threadid'];
     $thread['threadtitle'] = $thread['title'];
     $thread['threadiconid'] = $thread['iconid'];
     $thread['postdateline'] = $thread['lastpost'];
     $thread['issubscribed'] = $this->thread->is_subscribed($current_user);
     $thread['threadread'] = $this->thread->get_lastread($current_user);
     /*
     	This used to be precalculated by forum, but it doesn't look expensive enough to want to
     	bother with that.  If that turns out to be wrong we'll need to do some kind of
     	caching.
     */
     $forum = $this->thread->get_forum();
     if (!$current_user->hasForumPermission($forum->get_field('forumid'), 'canviewthreads')) {
         unset($thread['preview']);
     }
     //set the correct status
     if ($this->replydata['mylastpost'] > 0) {
         $post_statusicon[] = 'dot';
     }
     if (!$thread['open']) {
         $post_statusicon[] = 'lock';
     }
     if ($this->replydata['lastread'] < $thread['lastpost']) {
         $post_statusicon[] = 'new';
     }
     if (!count($post_statusicon)) {
         $post_statusicon[] = 'old';
     }
     $post_statusicon = implode('_', $post_statusicon);
     $show['deletereason'] = false;
     if ($thread['visible'] == 2) {
         $log = $this->thread->get_deletion_log_array();
         $thread['del_username'] = $log['username'];
         $thread['del_userid'] = $log['userid'];
         $thread['del_reason'] = $log['reason'];
         $thread['deletedcount']++;
         $show['deletereason'] = !empty($thread['del_reason']);
     } else {
         if ($thread['visible'] == 0) {
             $thread['hiddencount']++;
         }
     }
     $thread['highlight'] = $criteria->get_highlights();
     $show['moderated'] = ($thread['hiddencount'] > 0 and $current_user->canModerateForum($thread['forumid'], 'canmoderateposts'));
     $show['deletedthread'] = ($thread['deletedcount'] > 0 and ($current_user->canModerateForum($thread['forumid']) or $current_user->hasForumPermission($thread['forumid'], 'canseedelnotice')));
     $show['disabled'] = !$this->can_inline_mod($current_user);
     $lastread = $forum->get_last_read_by_current_user($current_user);
     /*	This uses $dotthreads which is built by calling fetch_dot_threads_array() in search/type/thread.php
     		The data is very similar to data we now have, and at some point this call could probably be eliminated. */
     $thread = process_thread_array($thread, $lastread);
     ($hook = vBulletinHook::fetch_hook('search_results_threadbit')) ? eval($hook) : false;
     $pageinfo = $pageinfo_lastpost = $pageinfo_firstpost = $pageinfo_lastpage = array();
     if ($show['pagenavmore']) {
         $pageinfo_lastpage['page'] = $thread['totalpages'];
     }
     $pageinfo_lastpost['p'] = $thread['lastpostid'];
     $pageinfo_newpost['goto'] = 'newpost';
     $pageinfo_thread = array();
     if (!empty($thread['highlight'])) {
         $pageinfo_thread['highlight'] = urlencode(implode(' ', $thread['highlight']));
         $pageinfo_newpost['highlight'] = urlencode(implode(' ', $thread['highlight']));
         $pageinfo_lastpost['highlight'] = urlencode(implode(' ', $thread['highlight']));
         $pageinfo_firstpost['highlight'] = urlencode(implode(' ', $thread['highlight']));
     }
     // Work out if unread below notification needed
     if ($criteria->get_searchtype() == vB_Search_Core::SEARCH_NEW and $criteria->get_sort() == 'groupdateline' and $show['below_unread'] == 0 and $thread['lastpost'] < $vbulletin->userinfo['lastvisit']) {
         $show['below_unread'] = $criteria->get_search_term('searchdate') == 'lastvisit' ? 1 : 2;
     }
     if ($vbulletin->options['avatarenabled']) {
         $thread['lastpost_avatar'] = fetch_avatar_from_record($thread, true);
         $thread['firstpost_avatar'] = fetch_avatar_from_record($thread, true, 'postuserid', 'first_');
     }
     ($hook = vBulletinHook::fetch_hook('search_results_thread_process')) ? eval($hook) : false;
     $template = vB_Template::create($template_name);
     $template->register('post_statusicon', $post_statusicon);
     $template->register('pageinfo_firstpost', $pageinfo_firstpost);
     $template->register('pageinfo_lastpost', $pageinfo_lastpost);
     $template->register('pageinfo_lastpage', $pageinfo_lastpage);
     $template->register('pageinfo_newpost', $pageinfo_newpost);
     $template->register('pageinfo', $pageinfo_thread);
     $template->register('dateformat', $vbulletin->options['dateformat']);
     $template->register('timeformat', $vbulletin->options['timeformat']);
     $template->register('postdateline', $thread['lastpost']);
     $userinfo = array('userid' => $thread['postuserid'], 'username' => $thread['postusername']);
     $template->register('avatar', $thread['lastpost_avatar']);
     $template->register('userinfo', $userinfo);
     $template->register('show', $show);
     $template->register('thread', $thread);
     if ($show['below_unread'] > 0) {
         // flag as shown.
         $show['below_unread'] = -1;
     }
     ($hook = vBulletinHook::fetch_hook('search_results_thread_complete')) ? eval($hook) : false;
     return $template->render();
 }
Exemplo n.º 4
0
function process_thread_array($thread, $lastread = -1, $allowicons = -1, $fetchavatar = false)
{
    global $vbphrase, $foruminfo, $vbulletin;
    global $newthreads, $dotthreads, $perpage, $ignore, $show;
    static $pperpage, $perm_cache;
    if ($pperpage == 0) {
        // lets calculate posts per page
        // the following code should be left just in case we plan to use this function in showthread at some point
        if (THIS_SCRIPT != 'showthread') {
            $pperpage = sanitize_maxposts();
        } else {
            $pperpage = sanitize_maxposts($perpage);
        }
    }
    // init value for the inline moderation checkbox
    $thread['checkbox_value'] = 0;
    if (can_moderate($thread['forumid'], 'caneditthreads') or $thread['open'] and $thread['postuserid'] == $vbulletin->userinfo['userid'] and $forumperms = fetch_permissions($thread['forumid']) and $forumperms & $vbulletin->bf_ugp_forumpermissions['caneditpost'] and (!$vbulletin->options['editthreadtitlelimit'] or $thread['dateline'] + $vbulletin->options['editthreadtitlelimit'] * 60 > TIMENOW)) {
        $thread['title_editable'] = true;
        $show['ajax_js'] = true;
    }
    if ($thread['open'] != 10 and (can_moderate($thread['forumid'], 'canopenclose') or $thread['postuserid'] == $vbulletin->userinfo['userid'] and $forumperms = fetch_permissions($thread['forumid']) and $forumperms & $vbulletin->bf_ugp_forumpermissions['canopenclose'])) {
        $thread['openclose_editable'] = true;
        $show['ajax_js'] = true;
    }
    /*if ($thread['postuserid'] == $vbulletin->userinfo['userid'])
    	{
    		$forumperms = fetch_permissions($thread['forumid']);
    		if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canopenclose'])
    		{
    			$thread['openclose_editable'] .= "<div><strong>Own thread</strong></div>";
    		}
    	}*/
    if ($fetchavatar) {
        require_once DIR . '/includes/functions_user.php';
        $avatar = fetch_avatar_from_record($thread, true, 'userid', 'api_');
        $thread['avatarurl'] = $avatar[0];
        $avatarinfo = parse_subsstring_array($thread, 'api_');
        $avatarinfo['adminavatar'] = $avatarinfo['adminoptions'] & $vbulletin->bf_misc_adminoptions['adminavatar'];
        if (!isset($perm_cache["{$avatarinfo['userid']}"])) {
            $perm_cache["{$avatarinfo['userid']}"] = cache_permissions($avatarinfo, false);
        } else {
            $avatarinfo['permissions'] =& $perm_cache["{$avatarinfo['userid']}"];
        }
        if (empty($thread['avatarurl']) or $vbulletin->userinfo['userid'] > 0 and !$vbulletin->userinfo['showavatars'] or !$avatarinfo['avatarid'] and !($perm_cache["{$avatarinfo['userid']}"]['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canuseavatar']) and !$avatarinfo['adminavatar']) {
            $show['avatar'] = false;
        } else {
            $show['avatar'] = true;
        }
    }
    if ($allowicons == -1) {
        $allowicons = $vbulletin->forumcache["{$thread['forumid']}"]['options'] & $vbulletin->bf_misc_forumoptions['allowicons'];
    }
    if ($lastread == -1) {
        $lastread = $vbulletin->userinfo['lastvisit'];
    }
    $show['rexpires'] = $show['rmanage'] = $show['threadmoved'] = $show['paperclip'] = $show['unsubscribe'] = false;
    // thread forumtitle
    if (empty($thread['forumtitle'])) {
        $thread['forumtitle'] = $vbulletin->forumcache["{$thread['forumid']}"]['title'];
    }
    $thread['forumtitleclean'] = $vbulletin->forumcache["{$thread['forumid']}"]['title_clean'];
    // word wrap title
    if ($vbulletin->options['wordwrap'] != 0) {
        $thread['threadtitle'] = fetch_word_wrapped_string($thread['threadtitle']);
    }
    $thread['threadtitle'] = fetch_censored_text($thread['threadtitle']);
    if ($thread['prefixid']) {
        $thread['prefix_plain_html'] = htmlspecialchars_uni($vbphrase["prefix_{$thread['prefixid']}_title_plain"]);
        $thread['prefix_rich'] = $vbphrase["prefix_{$thread['prefixid']}_title_rich"];
    } else {
        $thread['prefix_plain_html'] = '';
        $thread['prefix_rich'] = '';
    }
    // format thread preview if there is one
    if ($ignore["{$thread['postuserid']}"]) {
        $thread['preview'] = '';
    } else {
        if (isset($thread['preview'])) {
            if ($vbulletin->options['threadpreview'] > 0) {
                $thread['preview'] = strip_quotes($thread['preview']);
                $thread['preview'] = htmlspecialchars_uni(fetch_censored_text(fetch_trimmed_title(strip_bbcode($thread['preview'], false, true, true, true), $vbulletin->options['threadpreview'])));
            } else {
                unset($thread['preview']);
            }
        }
    }
    // thread last reply date/time
    $thread['lastpostdate'] = vbdate($vbulletin->options['dateformat'], $thread['lastpost'], true);
    $thread['lastposttime'] = vbdate($vbulletin->options['timeformat'], $thread['lastpost']);
    // post reply date/time (for search results as posts mainly)
    if ($thread['postdateline']) {
        $thread['postdate'] = vbdate($vbulletin->options['dateformat'], $thread['postdateline'], true);
        $thread['posttime'] = vbdate($vbulletin->options['timeformat'], $thread['postdateline']);
    } else {
        $thread['postdate'] = '';
        $thread['posttime'] = '';
    }
    // get the thread starting date and time if applicable
    if ($thread['dateline']) {
        $thread['startdate'] = vbdate($vbulletin->options['dateformat'], $thread['dateline'], true);
        $thread['starttime'] = vbdate($vbulletin->options['timeformat'], $thread['dateline']);
    } else {
        $thread['startdate'] = '';
        $thread['starttime'] = '';
    }
    // non magical thread status
    if (2 == $thread['visible']) {
        $thread['status']['deleted'] = 'deleted';
    } else {
        if (!$thread['visible']) {
            $thread['status']['moderated'] = 'moderated';
        }
    }
    // thread not moved
    if ($thread['open'] != 10) {
        // allow ratings?
        if ($foruminfo['allowratings']) {
            // show votes?
            if ($thread['votenum'] and $thread['votenum'] >= $vbulletin->options['showvotes']) {
                $thread['voteavg'] = vb_number_format($thread['votetotal'] / $thread['votenum'], 2);
                $thread['rating'] = intval(round($thread['votetotal'] / $thread['votenum']));
            } else {
                $thread['rating'] = 0;
            }
        } else {
            $thread['rating'] = 0;
            $thread['votenum'] = 0;
        }
        // moderated thread?
        if (!$thread['visible']) {
            $thread['moderatedprefix'] = $vbphrase['moderated_thread_prefix'];
            $thread['checkbox_value'] += THREAD_FLAG_INVISIBLE;
        } else {
            $thread['moderatedprefix'] = '';
        }
        // deleted thread?
        if ($thread['visible'] == 2) {
            $thread['checkbox_value'] += THREAD_FLAG_DELETED;
            $thread['del_reason'] = fetch_censored_text($thread['del_reason']);
        }
        // sticky thread?
        if ($thread['sticky']) {
            $show['sticky'] = true;
            $thread['typeprefix'] = $vbphrase['sticky_thread_prefix'];
            $thread['checkbox_value'] += THREAD_FLAG_STICKY;
        } else {
            $show['sticky'] = false;
            $thread['typeprefix'] = '';
        }
        // thread contains poll?
        if ($thread['pollid'] != 0) {
            $thread['typeprefix'] .= $vbphrase['poll_thread_prefix'];
            $thread['checkbox_value'] += THREAD_FLAG_POLL;
        }
        // multipage nav
        $thread['totalposts'] = $thread['replycount'] + 1;
        $total =& $thread['totalposts'];
        if (($vbulletin->options['allowthreadedmode'] == 0 or $vbulletin->userinfo['threadedmode'] == 0 and empty($vbulletin->GPC[COOKIE_PREFIX . 'threadedmode']) or $vbulletin->GPC[COOKIE_PREFIX . 'threadedmode'] == 'linear') and $thread['totalposts'] > $pperpage and $vbulletin->options['linktopages']) {
            $thread['totalpages'] = ceil($thread['totalposts'] / $pperpage);
            #$address2 = "$thread[highlight]";
            $curpage = 0;
            $thread['pagenav'] = '';
            $show['pagenavmore'] = false;
            while ($curpage++ < $thread['totalpages']) {
                if ($vbulletin->options['maxmultipage'] and $curpage > $vbulletin->options['maxmultipage']) {
                    $lastpageinfo = array('page' => $thread['totalpages']);
                    if ($thread['highlight']) {
                        $lastpageinfo['highlight'] = urlencode(implode(' ', $thread['highlight']));
                    }
                    $thread['lastpagelink'] = fetch_seo_url('thread', $thread, $lastpageinfo, 'threadid', 'threadtitle');
                    $show['pagenavmore'] = true;
                    break;
                }
                $pageinfo = array('page' => $curpage);
                if ($thread['highlight']) {
                    $pageinfo['highlight'] = urlencode(implode(' ', $thread['highlight']));
                }
                $pagenumbers = fetch_start_end_total_array($curpage, $pperpage, $thread['totalposts']);
                $templater = vB_Template::create('threadbit_pagelink');
                $templater->register('curpage', $curpage);
                $templater->register('pageinfo', $pageinfo);
                $templater->register('thread', $thread);
                $thread['pagenav'] .= ' ' . $templater->render();
            }
        } else {
            $thread['pagenav'] = '';
        }
        // allow thread icons?
        if ($allowicons) {
            // get icon from icon cache
            if ($thread['threadiconid']) {
                $thread['threadiconpath'] = $vbulletin->iconcache["{$thread['threadiconid']}"]['iconpath'];
                $thread['threadicontitle'] = $vbulletin->iconcache["{$thread['threadiconid']}"]['title'];
            }
            // show poll icon
            if ($thread['pollid'] != 0) {
                $show['threadicon'] = true;
                $thread['threadiconpath'] = vB_Template_Runtime::fetchStyleVar('imgdir_misc') . "/poll_posticon.gif";
                $thread['threadicontitle'] = $vbphrase['poll'];
            } else {
                if ($thread['threadiconpath']) {
                    $show['threadicon'] = true;
                } else {
                    if (!empty($vbulletin->options['showdeficon'])) {
                        $show['threadicon'] = true;
                        $thread['threadiconpath'] = $vbulletin->options['showdeficon'];
                        $thread['threadicontitle'] = '';
                    } else {
                        $show['threadicon'] = false;
                        $thread['threadiconpath'] = '';
                        $thread['threadicontitle'] = '';
                    }
                }
            }
        } else {
            $show['threadicon'] = false;
            $thread['threadiconpath'] = '';
            $thread['threadicontitle'] = '';
        }
        // thread has attachment?
        if ($thread['attach'] > 0) {
            $show['paperclip'] = true;
            $thread['checkbox_value'] += THREAD_FLAG_ATTACH;
        }
        // folder icon generation
        $thread['status'] = array();
        // show dot folder?
        if ($vbulletin->userinfo['userid'] and $vbulletin->options['showdots'] and $dotthreads["{$thread['threadid']}"]) {
            $thread['status']['dot'] = 'dot';
            $thread['dot_count'] = $dotthreads["{$thread['threadid']}"]['count'];
            $thread['dot_lastpost'] = $dotthreads["{$thread['threadid']}"]['lastpost'];
        }
        // show hot folder?
        if ($vbulletin->options['usehotthreads'] and ($thread['replycount'] >= $vbulletin->options['hotnumberposts'] and $vbulletin->options['hotnumberposts'] > 0 or $thread['views'] >= $vbulletin->options['hotnumberviews'] and $vbulletin->options['hotnumberviews'] > 0)) {
            $thread['status']['hot'] = 'hot';
        }
        // show locked folder?
        if (!$thread['open']) {
            $thread['status']['lock'] = 'lock';
            $thread['checkbox_value'] += THREAD_FLAG_CLOSED;
        }
        // show new folder?
        if ($thread['lastpost'] > $lastread) {
            if ($vbulletin->options['threadmarking'] and $thread['threadread']) {
                $threadview = $thread['threadread'];
            } else {
                $threadview = intval(fetch_bbarray_cookie('thread_lastview', $thread['threadid']));
            }
            if ($thread['lastpost'] > $threadview) {
                $thread['status']['new'] = 'new';
                $show['gotonewpost'] = true;
            } else {
                $newthreads--;
                $show['gotonewpost'] = false;
            }
        } else {
            $show['gotonewpost'] = false;
        }
        // format numbers nicely
        $thread['replycount'] = vb_number_format($thread['replycount']);
        $thread['views'] = vb_number_format($thread['views']);
        $thread['realthreadid'] = $thread['threadid'];
    } else {
        // thread has been moved, lets delete if required!
        if (can_moderate($thread['forumid'])) {
            if ($thread['expires']) {
                if ($thread['expires'] <= TIMENOW) {
                    $threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_STANDARD, 'threadpost');
                    $threadman->set_existing($thread);
                    $threadman->delete(false, true, NULL, false);
                    unset($threadman);
                }
                $show['rexpires'] = true;
                $thread['expiredate'] = vbdate($vbulletin->options['dateformat'], $thread['expires']);
                $thread['expiretime'] = vbdate($vbulletin->options['timeformat'], $thread['expires']);
            }
            $show['rmanage'] = can_moderate($thread['forumid'], 'canmanagethreads');
        }
        $thread['realthreadid'] = $thread['threadid'];
        $thread['redirectthreadid'] = $thread['threadid'];
        $thread['threadid'] = $thread['pollid'];
        $thread['replycount'] = '-';
        $thread['views'] = '-';
        $show['threadicon'] = false;
        $thread['status'] = array();
        // VB_API relies on thread redirects to fully reflect the read status of the redirected thread
        if ($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid'] and defined('VB_API') and VB_API === true) {
            if ($lastpost = $vbulletin->db->query_first("\n\t\t\t\tSELECT thread.forumid, thread.lastpost, threadread.readtime AS threadread\n\t\t\t\tFROM " . TABLE_PREFIX . "thread AS thread\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "threadread AS threadread ON (threadread.threadid = thread.threadid AND threadread.userid = {$vbulletin->userinfo['userid']})\n\t\t\t\tWHERE thread.threadid = {$thread['pollid']}\n\t\t\t")) {
                $forumread = $vbulletin->forumcache["{$lastpost['forumid']}"]['forumread'];
                $lastread = max($forumread, TIMENOW - $vbulletin->options['markinglimit'] * 86400);
                if ($lastpost['lastpost'] > $lastread) {
                    if ($lastpost['threadread']) {
                        $threadview = $lastpost['threadread'];
                    }
                    if ($lastpost['lastpost'] > $threadview) {
                        $thread['status']['new'] = 'new';
                    }
                }
            } else {
                $thread['status']['new'] = $thread['lastpost'] > $lastread ? 'new' : false;
            }
        } else {
            $thread['status']['new'] = $thread['lastpost'] > $lastread ? 'new' : false;
        }
        $thread['status']['moved'] = 'moved';
        $thread['pagenav'] = '';
        $thread['movedprefix'] = $vbphrase['moved_thread_prefix'];
        $thread['rating'] = 0;
        $thread['votenum'] = 0;
        $show['gotonewpost'] = false;
        $thread['showpagenav'] = false;
        $show['sticky'] = false;
        $show['threadmoved'] = true;
    }
    $show['subscribed'] = iif($thread['issubscribed'], true, false);
    $show['pagenav'] = iif($thread['pagenav'] != '', true, false);
    $show['guestuser'] = iif(!$thread['postuserid'], true, false);
    $show['threadrating'] = iif($thread['rating'] > 0, true, false);
    $show['threadcount'] = iif($thread['dot_count'], true, false);
    $show['taglist'] = ($vbulletin->options['threadtagging'] and !empty($thread['taglist']));
    ($hook = vBulletinHook::fetch_hook('threadbit_process')) ? eval($hook) : false;
    $thread['statusstring'] = implode(' ', $thread['status']);
    return $thread;
}
Exemplo n.º 5
0
	private function getThreads()
	{
		$datecut = TIMENOW - ($this->config['days'] * 86400);

		if (empty(vB::$vbulletin->userinfo['forumpermissions']))
		{
			require_once DIR . "/includes/functions.php";
			cache_permissions($userinfo);
		}

		switch (intval($this->config['threads_type']))
		{
			case 0:
				$ordersql = " thread.dateline DESC";
				$datecutoffsql = " AND thread.dateline > $datecut";
				break;
			case 1:
				$ordersql = " thread.lastpost DESC";
				$datecutoffsql = " AND thread.lastpost > $datecut";
				break;
			case 2:
				$ordersql = " thread.replycount DESC";
				$datecutoffsql = " AND thread.dateline > $datecut";
				break;
			case 3:
				$ordersql = " thread.views DESC";
				$datecutoffsql = " AND thread.dateline > $datecut";
				break;
		}

		//we have some existing settings with config['forumchoice'] set to 0=> ''; That's no good
		if (empty($this->config['forumchoice']))
		{
			$this->config['forumchoice'] = array();
		}
		else if (is_array($this->config['forumchoice']) AND ($this->config['forumchoice'][0] == '') )
		{
			unset($this->config['forumchoice'][0]);
		}
		$subscribejoin = '';

		if (in_array('subscribed', $this->config['forumchoice']))
		{
			$subscribejoin = " INNER JOIN " . TABLE_PREFIX .	"subscribeforum AS subscribeforum
				ON (subscribeforum.forumid = forum.forumid AND subscribeforum.userid = " . vB::$vbulletin->userinfo['userid'] .
			" ) ";
		}

		$forumsql = '';
		$forumids = array_keys(vB::$vbulletin->forumcache);
		$forumchoice = array();
		foreach ($forumids AS $forumid)
		{
			$forumperms =& vB::$vbulletin->userinfo['forumpermissions']["$forumid"];
			if ($forumperms & vB::$vbulletin->bf_ugp_forumpermissions['canview']
				AND ($forumperms & vB::$vbulletin->bf_ugp_forumpermissions['canviewothers'])
				AND (($forumperms & vB::$vbulletin->bf_ugp_forumpermissions['canviewthreads']))
				AND verify_forum_password($forumid, vB::$vbulletin->forumcache["$forumid"]['password'], false)
				)
			{
				//Don't include the comments forum.
				if (vB::$vbulletin->options['vbcmsforumid'] AND (intval(vB::$vbulletin->options['vbcmsforumid']) == intval($forumid)))
				{
					continue;
				}
				//Or, if the user selected forums, anything not on the list.
				else if (! empty($this->config['forumchoice']) AND !in_array($forumid, $this->config['forumchoice']))
				{
					continue;
				}
				$forumchoice[] = $forumid;
			}
		}
		$threadarray = array();
		if (!empty($forumchoice) )
		{
			$forumsql = " AND (" . (empty($subscribejoin) ? '' : "subscribeforum.forumid IS NOT NULL OR ") .
				" thread.forumid IN(" . implode(',', $forumchoice) . ")";
			$associatedthread = (vB::$vbulletin->options['vbcmsforumid'] ?
					" AND (thread.forumid <> " . vB::$vbulletin->options['vbcmsforumid'] . ") )" : '');
		}
		else if (! empty($subscribejoin))
		{
			$forumsql = " AND subscribeforum.forumid IS NOT NULL ";
		}
		else
		{
			return $threadarray;
		}


		// remove threads from users on the global ignore list if user is not a moderator
		$globalignore = '';
		if (trim(vB::$vbulletin->options['globalignore']) != '')
		{
			require_once(DIR . '/includes/functions_bigthree.php');
			if ($Coventry = fetch_coventry('string'))
			{
				$globalignore = "AND thread.postuserid NOT IN ($Coventry) ";
			}
		}
				// query last threads from visible / chosen forums
		$threads = vB::$vbulletin->db->query_read_slave($sql = "
			SELECT thread.threadid, thread.title, thread.prefixid, post.attach, post.userid AS postuserid, post.username AS postusername,
				thread.postusername, thread.dateline, thread.lastpostid, thread.lastpost, thread.lastposterid, thread.lastposter, thread.replycount,
				forum.forumid, forum.title_clean as forumtitle,
				post.pagetext AS message, post.allowsmilie, post.postid,
				user.userid, user.username, thread.lastposter AS lastpostername
				" . (vB::$vbulletin->options['avatarenabled'] ? ",avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight" : "") . "
			FROM " . TABLE_PREFIX . "thread AS thread
			INNER JOIN " . TABLE_PREFIX . "forum AS forum ON(forum.forumid = thread.forumid)
			LEFT JOIN " . TABLE_PREFIX . "post AS post ON (post.postid = thread.firstpostid)
			LEFT JOIN " . TABLE_PREFIX . "user AS user ON (thread.postuserid = user.userid)
			" . (vB::$vbulletin->options['avatarenabled'] ? "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)" : "") . "
			$subscribejoin
			WHERE 1=1
				$forumsql
				AND thread.visible = 1
				AND post.visible = 1
				AND open <> 10
				$datecutoffsql
				$globalignore
				$associatedthread
				" . ($this->userinfo['ignorelist'] ? "AND thread.postuserid NOT IN (" . implode(',', explode(' ', $this->userinfo['ignorelist'])) . ")": '') . "
			ORDER BY $ordersql
			LIMIT 0," . intval($this->config['count']) . "
		");

		require_once(DIR . '/includes/class_bbcode.php');
		$parser = new vB_BbCodeParser(vB::$vbulletin, fetch_tag_list());
		$optionval = vB::$vbulletin->bf_misc_forumoptions['allowhtml'];
		while ($thread = vB::$vbulletin->db->fetch_array($threads))
		{
			$thread['title'] = fetch_trimmed_title($thread['title'], $this->config['threads_titlemaxchars']);

			$thread['url'] = fetch_seo_url('thread', $thread);
			$thread['newposturl'] = fetch_seo_url('thread', $thread, array('goto' => 'newpost'));
			$thread['lastposturl'] = fetch_seo_url('thread', $thread, array('p' => $thread['lastpostid'])) . '#post' . $thread['lastpostid'];
			$thread['date'] = vbdate(vB::$vbulletin->options['dateformat'], $thread['dateline'], true);
			$thread['time'] = vbdate(vB::$vbulletin->options['timeformat'], $thread['dateline']);

			$thread['lastpostdate'] = vbdate(vB::$vbulletin->options['dateformat'], $thread['lastpost'], true);
			$thread['lastposttime'] = vbdate(vB::$vbulletin->options['timeformat'], $thread['lastpost']);
			$forumid = $thread['forumid'];
			$allow_html = ((vB::$vbulletin->forumcache[$forumid]['options'] & $optionval) AND $this->config['allow_html'] ? 1 : 0);
			$thread['previewtext'] = fetch_censored_text($parser->get_preview($thread['message'], $this->default_previewlen, $allow_html));
			$thread['pagetext'] = fetch_censored_text($parser->do_parse($thread['message'], $allow_html));

			// get avatar
			if (intval($thread['userid']) AND vB::$vbulletin->options['avatarenabled'])
			{
				$avatar = fetch_avatar_from_record($thread);
			}

			if (!isset($avatar))
			{
				$avatar = false;
			}
			$thread['avatarurl'] = isset($avatar[0]) ?$avatar[0] : false;
			unset($avatar);
			$threadarray[$thread['threadid']] = $thread;
		}

		return $threadarray;

	}
Exemplo n.º 6
0
 public function render($current_user, $criteria, $template_name = '')
 {
     require_once DIR . "/includes/functions_socialgroup.php";
     require_once DIR . "/includes/class_groupmessage.php";
     global $vbulletin;
     $user = vB_Legacy_User::createFromIdCached($this->message->getPostUserId(), FETCH_USERINFO_AVATAR);
     $item = $this->message->getInfo();
     if (strlen($template_name)) {
         if ($record = vB::$vbulletin->db->query_first("SELECT gm.*, gr.groupid,\n\t\t\tdisc.discussionid, starter.postuserid AS poststarterid, starter.postusername AS poststarter,\n\t\t\tdisc.firstpostid, starter.title AS firsttitle, gr.groupid, gr.name AS groupname\n\t\t\t" . (vB::$vbulletin->options['avatarenabled'] ? ", avatar.avatarpath, user.userid, user.username,\n\t\t\t\tcustomavatar.userid AS hascustomavatar, customavatar.dateline AS avatardateline,\n\t\t\t\tcustomavatar.width AS avwidth,customavatar.height AS avheight, user.avatarrevision" : "") . " FROM " . TABLE_PREFIX . "groupmessage AS gm\n INNER JOIN " . TABLE_PREFIX . "discussion AS disc ON disc.discussionid = gm.discussionid\n INNER JOIN " . TABLE_PREFIX . "socialgroup AS gr ON gr.groupid = disc.groupid\n INNER JOIN " . TABLE_PREFIX . "groupmessage AS starter ON starter.gmid = disc.firstpostid\n\t\t\t\t" . (vB::$vbulletin->options['avatarenabled'] ? "\nLEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid =starter.postuserid) \nLEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON (avatar.avatarid = user.avatarid) \nLEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)" : "") . "\n\t\t\t\tWHERE gm.gmid = " . $item['gmid'])) {
             $item = array_merge($item, $record);
         }
         if (!$this->bbcode_parser) {
             $this->bbcode_parser = new vB_BbCodeParser(vB::$vbulletin, fetch_tag_list());
         }
         $item['previewtext'] = fetch_censored_text($this->bbcode_parser->get_preview($item['pagetext'], 200));
         $template = vB_Template::create($template_name);
         $template->register('item', $item);
         $template->register('dateformat', $vbulletin->options['dateformat']);
         $template->register('timeformat', $vbulletin->options['timeformat']);
         if ($vbulletin->options['sg_enablesocialgroupicons']) {
             $template->register('socialgroupicon_url', fetch_socialgroupicon_url($item['groupid'], true));
         }
         if (vB::$vbulletin->options['avatarenabled']) {
             $template->register('avatar', fetch_avatar_from_record($item, true));
         }
         return $template->render();
     }
     $item = array_merge($item, $user->get_record());
     $item['hascustom'] = $item['hascustomavatar'];
     $item['issearch'] = true;
     $group = $this->message->getDiscussion()->getSocialGroup();
     if ($group->has_modperm('canviewdeleted', $current_user)) {
         $dellog = $this->message->getDeletionLogArray();
         $item['del_username'] = $dellog['username'];
         $item['del_userid'] = $dellog['userid'];
         $item['del_reason'] = $dellog['reason'];
     }
     //I'm not sure what these are for, but they exist in the template so we should
     //make sure they are set.  The main message display code does not appear to
     //set them.
     global $show;
     $show['group'] = false;
     $show['discussion'] = false;
     //If we want to create our own template, then we need
     $factory = new vB_Group_Bit_Factory($vbulletin);
     //this gets lookup up by the bit anyway.  Not sure why we need to pass it.
     $group = array();
     $bit = $factory->create($item, $group);
     //unfortunately the bit render can set the $show['inlinemod'] variable which we are
     //currently using across all templates to handle the inline mod settings.  We should
     //probably rely on something a little less global but that's not in the cards right now.
     //make sure that we honor the starting value and restore it when we are done.
     $inlinemod = $show['inlinemod'];
     $bit->show_moderation_tools($inlinemod);
     $text = $bit->construct();
     $show['inlinemod'] = $inlinemod;
     //todo this is ugly and invalid html.  We need to get the message_list
     //id out of here and convert the css to use a class for that formatting
     //but lets wait until we figure out what the new look and feel is going
     //do to or for us.
     return $text;
 }
Exemplo n.º 7
0
 /**
  * vBForum_Search_Result_VisitorMessage::render()
  *
  * @param string $current_user
  * @param object $criteria
  * @return
  */
 public function render($current_user, $criteria, $template_name = '')
 {
     require_once DIR . '/includes/functions_user.php';
     if (!strlen($template_name)) {
         $template_name = 'search_results_visitormessage';
     }
     //TODO- create a template and pass it the necessary information
     //TODO- check vbphrase and see what we have to add.
     //TODO- figure if we are passing the right parameters. I suspect not.
     global $show;
     $template = vB_Template::create($template_name);
     $template->register('messagetext', vB_Search_Searchtools::getSummary($this->message['pagetext'], 100));
     //The template is out with the variables fromid and toid. It should just be
     // from and to, but we need to get out a simple patch.
     $from = array('userid' => $this->message['postuserid'], 'username' => $this->message['postusername']);
     $to = array('userid' => $this->message['userid'], 'username' => $this->message['username']);
     $template->register('vmid', $this->message['vmid']);
     $template->register('to', $this->message['username']);
     $template->register('from', $this->message['postusername']);
     $template->register('fromid', $from);
     $template->register('toid', $to);
     $template->register('sentdate', vbdate(vB::$vbulletin->options['dateformat'], $this->message['dateline'], true));
     $template->register('senttime', vbdate(vB::$vbulletin->options['timeformat'], $this->message['dateline']));
     if (vB::$vbulletin->options['avatarenabled']) {
         $template->register('avatar', fetch_avatar_from_record($this->message, true, 'postuserid'));
     }
     return $template->render();
 }