Пример #1
0
 /**
  * Create the results based on a list of ids return from the search implmentation
  *
  * @param vB_Current_User $user
  * @param vB_Search_Criteria criteria for the search
  * @return vB_Search_Results
  */
 public static function create_from_array($user, $result_array)
 {
     global $vbulletin;
     $results = new vB_Search_Results();
     $results->user = $user;
     $results->criteria = vB_Search_Core::create_criteria(vB_Search_Core::SEARCH_ADVANCED);
     $results->criteria->set_grouped(vB_Search_Core::GROUP_NO);
     $sanitized_results = array();
     foreach ($result_array as $result) {
         //if we only have the type and the id, add a dummy group id.
         //we won't use it, but the code expects it.
         if (count($result) == 2) {
             $result[] = 0;
         }
         $sanitized_results[] = $result;
     }
     $results->results = $sanitized_results;
     //move log_search call after get_results to allow for any changes to the $criteria
     //object that might be made by the searchcontroller
     $results->searchid = $results->log_search();
     $results->dateline = TIMENOW;
     $results->cache_results();
     $searchtime = 0;
     //todo: do we need to set $results->searchtime here as well?
     $results->searchtime = $searchtime;
     $results->complete_search($searchtime);
     return $results;
 }
Пример #2
0
 public function output()
 {
     global $vbulletin, $db;
     $vbulletin->input->clean_array_gpc('r', array('userids' => TYPE_STR, 'contenttypeids' => TYPE_STR));
     $vbulletin->GPC['userids'] = convert_urlencoded_unicode($vbulletin->GPC['userids']);
     $userids = $vbulletin->GPC['userids'];
     $vbulletin->GPC['contenttypeids'] = convert_urlencoded_unicode($vbulletin->GPC['contenttypeids']);
     $contenttypeids = $vbulletin->GPC['contenttypeids'];
     require_once DIR . "/vb/search/core.php";
     require_once DIR . "/vb/legacy/currentuser.php";
     require_once DIR . "/vb/search/resultsview.php";
     require_once DIR . "/vb/search/searchtools.php";
     $search_core = vB_Search_Core::get_instance();
     $current_user = new vB_Legacy_CurrentUser();
     if (!$vbulletin->options['enablesearches']) {
         return $this->error('searchdisabled');
     }
     $criteria = $search_core->create_criteria(vB_Search_Core::SEARCH_ADVANCED);
     $userids_a = explode(',', $userids);
     $contenttypeids_a = explode(',', $contenttypeids);
     if (empty($userids_a)) {
         return $this->error('invalidid');
     }
     $criteria->add_userid_filter($userids_a, vB_Search_Core::GROUP_NO);
     if (!empty($contenttypeids_a)) {
         $criteria->add_contenttype_filter($contenttypeids_a);
     }
     $results = null;
     if (!($vbulletin->debug or $vbulletin->GPC_exists['nocache'] and $vbulletin->GPC['nocache'])) {
         $results = vB_Search_Results::create_from_cache($current_user, $criteria);
     }
     if (!$results) {
         $results = vB_Search_Results::create_from_criteria($current_user, $criteria);
     }
     return array("response" => array("errormessage" => "search"), "show" => array("searchid" => $results->get_searchid()));
 }
Пример #3
0
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db)) {
    exit;
}
// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################
$vbulletin->db->query_write("\n\tDELETE FROM " . TABLE_PREFIX . "session\n\tWHERE lastactivity < " . intval(TIMENOW - $vbulletin->options['cookietimeout']) . "\n");
$vbulletin->db->query_write("\n\tDELETE FROM " . TABLE_PREFIX . "cpsession\n\tWHERE dateline < " . ($vbulletin->options['timeoutcontrolpanel'] ? intval(TIMENOW - $vbulletin->options['cookietimeout']) : TIMENOW - 3600) . "\n");
require_once DIR . '/vb/search/results.php';
vB_Search_Results::clean();
// expired lost passwords and email confirmations after 4 days
$vbulletin->db->query_write("\n\tDELETE FROM " . TABLE_PREFIX . "useractivation\n\tWHERE dateline < " . (TIMENOW - 345600) . " AND\n\t(type = 1 OR (type = 0 and usergroupid = 2))\n");
// old forum/thread read marking data
$vbulletin->db->query_write("\n\tDELETE FROM " . TABLE_PREFIX . "threadread\n\tWHERE readtime < " . (TIMENOW - $vbulletin->options['markinglimit'] * 86400));
$vbulletin->db->query_write("\n\tDELETE FROM " . TABLE_PREFIX . "forumread\n\tWHERE readtime < " . (TIMENOW - $vbulletin->options['markinglimit'] * 86400));
$vbulletin->db->query_write("\n\tDELETE FROM " . TABLE_PREFIX . "groupread\n\tWHERE readtime < " . (TIMENOW - $vbulletin->options['markinglimit'] * 86400));
$vbulletin->db->query_write("\n\tDELETE FROM " . TABLE_PREFIX . "discussionread\n\tWHERE readtime < " . (TIMENOW - $vbulletin->options['markinglimit'] * 86400));
// delete expired thread redirects
$threads = $vbulletin->db->query_read("\n\tSELECT threadid\n\tFROM " . TABLE_PREFIX . "threadredirect\n\tWHERE expires < " . TIMENOW . "\n");
while ($thread = $vbulletin->db->fetch_array($threads)) {
    $thread['open'] = 10;
    $threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_SILENT, 'threadpost');
    $threadman->set_existing($thread);
    $threadman->delete(false, true, NULL, false);
    unset($threadman);
Пример #4
0
	/**
	 * This sets up the search parameters, gets the query results,
	 * and renders them
	 *
	 * @param array $config
	 * @return string
	 */
	private function getResults($config)
	{
		include_once DIR . '/includes/functions_misc.php';
		$search_core = vB_Search_Core::get_instance();

		//first see if we can get cached results
		$hashkey = $this->getHash();
		$cache_data = vB_Cache::instance()->read($hashkey, false, false);
		if ($cache_data)
		{

			//If there are no id's, we're done.
			if (empty($cache_data['ids']))
			{
				return false;
			}

			$controller = vB_Search_Core::get_instance()->get_search_type_from_id($config['contenttypeid']);

			if (method_exists($controller, 'create_array'))
			{
				$results = $controller->create_array($cache_data['ids']);
			}
			else if(method_exists($controller, 'create_item'))
			{
				$results = array();
				foreach ($cache_data['ids'] as $resultid)
				{
					$result = $controller->create_item($resultid);
					if ($result)
					{
						$results[] = $result;
					}
				}
			}
			else
			{
				return false;
			}
			return array('results' => $results, 'criteria' => $cache_data['criteria']);
		}

		$rst = vB::$vbulletin->db->query_read("SELECT relationid FROM "
		. TABLE_PREFIX . "userlist WHERE friend='yes' AND userid = "
		. vB::$vbulletin->userinfo['userid']
		);

		if (!$rst)
		{
			return false;
		}
		$userids = array();

		while($row = vB::$vbulletin->db->fetch_row($rst))
		{
			$userids[] = $row[0];
		}

		//If there are no friends there's no friend information.
		if (! count($userids))
		{
			return '';
		}

		if ($config['contenttypeid'] == null)
		{
			$config['contenttypeid']= array();
		}
		else if (!is_array($config['contenttypeid']))
		{
			$config['contenttypeid'] = array($config['contenttypeid']);
		}

		if (!count($userids))
		{
			new vB_Phrase('global', 'your_friends_list_is_empty');
		}

		$criteria = vB_Search_Core::get_instance()->create_criteria(vB_Search_Core::SEARCH_ADVANCED);
		$criteria->add_contenttype_filter($config['contenttypeid']);
		$criteria->set_advanced_typeid($contenttypeid);

		$criteria->add_userid_filter($userids, false);
		$criteria->set_grouped(vB_Search_Core::GROUP_NO);
		$timelimit = TIMENOW - (86400 * $config['days']);
		$criteria->add_date_filter(vB_Search_Core::OP_GT, $timelimit);
		$criteria->set_sort('dateline', 'desc');
		$current_user = new vB_Legacy_CurrentUser();
		$results = vB_Search_Results::create_from_cache($current_user, $criteria);

		if (!$results)
		{
			$results = vB_Search_Results::create_from_criteria($current_user, $criteria);
		}

		if (empty($results))
		{
			return false;
		}

		$page_results = $results->get_page(1, $config['count'], 1);
		//prepare types for render
		$items_by_type = array();
		foreach ($page_results as $item)
		{
			$typeid = $item->get_contenttype();

			if ($typeid)
			{
				$items_by_type[$typeid][] =  $item;
				$ids[] = $item->get_id();
			}
		}

		foreach ($items_by_type as $contenttype => $items)
		{
			$type = vB_Search_Core::get_instance()->get_search_type_from_id($contenttype);
			$type->prepare_render($results->get_user(), $items);

		}

		vB_Cache::instance()->write($hashkey, array('ids' => $ids,
			'criteria' =>$criteria), $this->cache_ttl,
				'widget_config_' . $this->widget->getId());

		return array('results' => $page_results, 'criteria' => $criteria);
	}
Пример #5
0
	$errors = $criteria->get_errors();

	if ($errors)
	{
		standard_error(fetch_error($errors[0]));
	}
	$results = null;

	if (!($vbulletin->debug AND $vbulletin->GPC_exists['nocache'] AND $vbulletin->GPC['nocache']))
	{
		$results = vB_Search_Results::create_from_cache($current_user, $criteria);
	}

	if (!$results)
	{
		$results = vB_Search_Results::create_from_criteria($current_user, $criteria);
	}

	($hook = vBulletinHook::fetch_hook('search_finduser_complete')) ? eval($hook) : false;

	$vbulletin->url = 'search.php?' . $vbulletin->session->vars['sessionurl'] . "searchid=" . $results->get_searchid();
	eval(print_standard_redirect('search'));
}

// #############################################################################
if ($_POST['do'] == 'doprefs')
{
	$vbulletin->input->clean_array_gpc('r',
		$globals
	);
Пример #6
0
    if (!$vbulletin->GPC['tag']) {
        standard_error(fetch_error('invalidid', $vbphrase['tag'], $vbulletin->options['contactuslink']));
    }
    $search_core = vB_Search_Core::get_instance();
    $current_user = new vB_Legacy_CurrentUser();
    $criteria = $search_core->create_criteria(vB_Search_Core::SEARCH_TAG);
    $criteria->add_tag_filter($vbulletin->GPC['tag']);
    $errors = $criteria->get_errors();
    if ($errors) {
        standard_error(fetch_error($errors[0]));
    }
    $results = null;
    $searchstart = microtime();
    if (!($vbulletin->GPC_exists['nocache'] and $vbulletin->GPC['nocache'])) {
        $results = vB_Search_Results::create_from_cache($current_user, $criteria);
    }
    if (!$results) {
        $results = vB_Search_Results::create_from_criteria($current_user, $criteria, $search_core->get_tag_search_controller());
    }
    $base = 'tags.php?' . $vbulletin->session->vars['sessionurl'] . 'tag=' . $vbulletin->GPC['tag'] . '&amp;pp=' . $perpage;
    $navbits = array('search.php' . $vbulletin->session->vars['sessionurl_q'] => $vbphrase['search_forums']);
    $view = new vb_Search_Resultsview($results);
    $view->showpage($vbulletin->GPC['pagenumber'], $vbulletin->GPC['perpage'], $base, $navbits);
    exit;
}
/*======================================================================*\
|| ####################################################################
|| # Downloaded: 23:48, Wed Mar 24th 2010
|| # CVS: $RCSfile$ - $Revision: 32878 $
|| ####################################################################
\*======================================================================*/
Пример #7
0
function do_process_search(&$searchid, &$reterrors)
{
    global $vbulletin, $db, $vbphrase, $search_core, $search_type, $globals, $current_user;
    if (!$vbulletin->options['enablesearches']) {
        $searchid = -1;
        $reterrors[] = 'searchdisabled';
        return;
    }
    $errors = array();
    ($hook = vBulletinHook::fetch_hook('search_before_process')) ? eval($hook) : false;
    ($hook = vBulletinHook::fetch_hook('search_process_start')) ? eval($hook) : false;
    if (!$vbulletin->options['threadtagging']) {
        //  tagging disabled, don't let them search on it
        $vbulletin->GPC['tag'] = '';
    }
    if ($vbulletin->GPC['userid'] and $userinfo = fetch_userinfo($vbulletin->GPC['userid'])) {
        $vbulletin->GPC_exists['searchuser'] = true;
        $vbulletin->GPC['searchuser'] = unhtmlspecialchars($userinfo['username']);
    }
    if ($vbulletin->GPC['searchthreadid']) {
        $vbulletin->GPC['sortby'] = 'dateline';
        $vbulletin->GPC['sortorder'] = 'ASC';
        $vbulletin->GPC['showposts'] = true;
        $vbulletin->GPC['starteronly'] = false;
        $vbulletin->GPC['titleonly'] = false;
    }
    // if searching for only a tag, we must show results as threads
    if ($vbulletin->GPC['tag'] and empty($vbulletin->GPC['query']) and empty($vbulletin->GPC['searchuser'])) {
        $vbulletin->GPC['showposts'] = false;
    }
    //do this even if the hv check fails to make sure that the user sees any errors
    //nothing worse then typing in a capcha five times only to get a message saying
    //fix something and type it in again.
    if ($vbulletin->GPC['contenttypeid'] and !is_array($vbulletin->GPC['contenttypeid'])) {
        $criteria = $search_core->create_criteria(vB_Search_Core::SEARCH_ADVANCED);
        $criteria->set_advanced_typeid($vbulletin->GPC['contenttypeid']);
    } else {
        $criteria = $search_core->create_criteria(vB_Search_Core::SEARCH_COMMON);
    }
    set_criteria_from_vbform($current_user, $criteria);
    $search_type->add_advanced_search_filters($criteria, $vbulletin);
    //caputure the search form values for backreferencing
    $searchterms = array();
    foreach ($globals as $varname => $value) {
        if (!$vbulletin->GPC_exists[$varname] or in_array($value, array(TYPE_ARRAY, TYPE_ARRAY_NOHTML)) and !is_array($vbulletin->GPC[$varname])) {
            continue;
        }
        $searchterms[$varname] = $vbulletin->GPC[$varname];
    }
    $criteria->set_search_terms($searchterms);
    $errors = array_merge($errors, $criteria->get_errors());
    if ($errors) {
        return;
    }
    $results = null;
    if (!($vbulletin->debug and $vbulletin->GPC_exists['nocache'] and $vbulletin->GPC['nocache'])) {
        $results = vB_Search_Results::create_from_cache($current_user, $criteria);
    }
    if (!$results) {
        $results = vB_Search_Results::create_from_criteria($current_user, $criteria);
    }
    $searchid = $results->get_searchid();
}
Пример #8
0
	/**
	 * This does the actual work of creating the navigation elements. This needs some
	 * styling, but we'll do that later.
	 * We use the existing search functionality. It's already all there, we just need
	 * to
	 *
	 * @return string;
	 */
	protected function makeResults($config)
	{
		include_once DIR . '/includes/functions_misc.php';
		$search_core = vB_Search_Core::get_instance();

		if (! intval($config['days']))
		{
			$config['days'] = 1;
		}

		$timelimit = TIMENOW - (86400 * $config['days']);

		if ($config['recent_type'] == 'mostrated')
		{
			vB::$vbulletin->GPC_exists['votenum'] = true;
			vB::$vbulletin->GPC['votenum'] = 1;
		}
		else if ($config['recent_type'] == 'bestrated')
		{
			vB::$vbulletin->GPC_exists['votetotal'] = true;
			vB::$vbulletin->GPC['votetotal'] = 1;
		}

		$hashkey = $this->getHash($this->widget->getId());
		$page = vB_Cache::instance()->read($hashkey, true, true);

		$current_user = new vB_Legacy_CurrentUser();
		$criteria = $search_core->create_criteria('advanced');
		$contenttypeid = $search_core->get_contenttypeid('vBForum',	'Post');
		$criteria->add_contenttype_filter($contenttypeid);
		$criteria->set_advanced_typeid($contenttypeid);

		if (intval($config['min_replies']) > 0)
		{
			$criteria->add_filter('replycount', vB_Search_Core::OP_GT, $config['min_replies'], true);
		}

		if ($config['forumchoice'])
		{
			$criteria->add_forumid_filter($config['forumchoice'], $config['childforums']);
		}
		$criteria->set_grouped(vB_Search_Core::GROUP_YES);

		if (! $page)
		{
			$search_type = vB_Search_Core::get_instance()->get_search_type_from_id($contenttypeid);
			$search_type->add_advanced_search_filters($criteria, vB::$vbulletin);

			$config['count'] = min(max(intval($config['count']),1), 20);

			switch($config['recent_type'])
				//We'll make 'active' the default.
			{
				case 'recent' :
					$criteria->set_sort('lastpost', 'desc');
					$criteria->add_filter('lastpost', vB_Search_Core::OP_GT, $timelimit, true );
					break;
				case 'viewed' :
					$criteria->set_sort('views', 'desc');
					$criteria->add_filter('lastpost', vB_Search_Core::OP_GT, $timelimit, true );
					break;
				case 'most' :
					$criteria->set_sort('votenum', 'desc');
					$criteria->add_filter('votenum', vB_Search_Core::OP_GT, 1, true );
					break;
				case 'best' :
					$criteria->set_sort('votetotal', 'desc');
					$criteria->add_filter('votetotal', vB_Search_Core::OP_GT, 1, true );
					break;
				default :
					$criteria->set_sort('replycount', 'desc');
					$criteria->add_date_filter(vB_Search_Core::OP_GT, $timelimit);
					break;
			} // switch

			$results = vB_Search_Results::create_from_cache($current_user, $criteria);

			if (!$results)
			{
				$results = vB_Search_Results::create_from_criteria($current_user, $criteria);
			}
			$page = $results->get_page(1, $config['count'], 0);
			vB_Cache::instance()->write($hashkey,
			   $page, $this->cache_ttl, $this->getCacheEvent());
		}

		return $this->renderResult($config, $page, $criteria, $current_user);
	}
Пример #9
0
################################## Feed selected posts to search.php #################
if ($_POST['do'] == 'viewpost')
{
	require_once(DIR . '/vb/search/core.php');
	require_once(DIR . '/vb/search/results.php');
	require_once(DIR . '/vb/legacy/currentuser.php');

	$typeid = vB_Search_Core::get_instance()->get_contenttypeid('vBForum', 'Post');
	$result_array = array();
	foreach (explode(",", $postids) AS $id)
	{
		$result_array[] = array($typeid, $id);
	}

	$results = vB_Search_Results::create_from_array(new vB_Legacy_CurrentUser(), $result_array);
	$vbulletin->url = 'search.php?' . $vbulletin->session->vars['sessionurl'] .
		"searchid=" . $results->get_searchid();
	eval(print_standard_redirect('search'));
}

// ############################### Empty Thread Cookie ###############################
if ($_POST['do'] == 'clearthread')
{
	setcookie('vbulletin_inlinethread', '', TIMENOW - 3600, '/');

	($hook = vBulletinHook::fetch_hook('inlinemod_clearthread')) ? eval($hook) : false;

	eval(print_standard_redirect('redirect_inline_threadlist_cleared', true, $forceredirect));
}
Пример #10
0
	/**
	 * This sets up the search parameters, gets the query results,
	 * and renders them
	 *
	 * @param array $config
	 * @return string
	 */
	private function getResults($config)
	{
		include_once DIR . '/includes/functions_misc.php';
		$search_core = vB_Search_Core::get_instance();

		//first see if we can get cached results
		$hashkey = $this->getHash();
		$cache_data = vB_Cache::instance()->read($hashkey, false, false);
		if ( $cache_data)
		{
			//If there are no id's, we're done.
			if (empty($cache_data['ids']))
			{
				return false;
			}
			//We have a content type and an array of id's. We need to build the result
			//objects.
			$controller = vB_Search_Core::get_instance()->get_search_type_from_id($cache_data['contenttypeid']);


			if (method_exists($controller, 'create_array'))
			{
				$results = $controller->create_array($cache_data['ids']);
			}
			else if(method_exists($controller, 'create_item'))
			{
				$results = array();
				foreach ($cache_data['ids'] as $resultid)
				{
					$result = $controller->create_item($resultid);
					if ($result)
					{
						$results[] = $result;
					}
				}
			}
			else
			{
				return false;
			}
			return array('results' => $results, 'criteria' => $cache_data['criteria']);
		}

		//First set the contenttype, if appropriate.
		if (! intval($config['days']))
		{
			$config['days'] = 7;
		}

		if (! intval($config['count']))
		{
			$config['count'] = 10;
		}

		if (isset($config['contenttypeid']) AND $config['contenttypeid'])
		{
			$contenttypeid = $config['contenttypeid'];
			$criteria = $search_core->create_criteria(vB_Search_Core::SEARCH_ADVANCED);
			//It's important to figure whether we need to group or not. We group for blogentries and posts
			$criteria->set_grouped( vB_Search_Core::GROUP_NO);
			$search_type = vB_Search_Core::get_instance()->get_search_type_from_id($contenttypeid);
			$criteria->set_advanced_typeid($contenttypeid);
			$criteria->add_contenttype_filter($contenttypeid);

			//Ugly hack, but we need to do this if the content type is blogentry.
			if (vB_Types::instance()->getContentTypeID('vBBlog_BlogEntry') == $contenttypeid )
			{
				vB::$vbulletin->GPC['ignorecomments'] = true;
			}

		}
		else if ((isset($config['forumchoice']) AND count($config['forumchoice']) AND $config['forumchoice'][0])
			OR (isset($config['prefixchoice']) AND count($config['prefixchoice']) AND $config['prefixchoice'][0]))
		{
			$contenttypeid = vB_Types::instance()->getContentTypeID('vBForum_Post');
			$search_type = vB_Search_Core::get_instance()->get_search_type_from_id($contenttypeid);
			$criteria = $search_core->create_criteria($contenttypeid);
			$criteria->set_advanced_typeid($contenttypeid);
			$criteria->add_contenttype_filter($contenttypeid);
			$criteria->set_grouped(vB_Search_Core::GROUP_NO);
		}
		else if ((isset($config['group']) AND $config['group'] != '')
			OR (isset($config['cat']) AND count($config['cat']) AND $config['cat'][0]))
		{
			//We haven't gotten a specific content type, and we won't work without one,
			// so assume we're showing visitor messages.
			$contenttypeid = vB_Types::instance()->getContentTypeID('vBForum_SocialGroupMessage');
			$search_type = vB_Search_Core::get_instance()->get_search_type_from_id($contenttypeid);
			$criteria = $search_core->create_criteria($contenttypeid);
			$criteria->set_advanced_typeid($contenttypeid);
			$criteria->add_contenttype_filter($contenttypeid);
		}
		else
		{
			return $vbphrase['widget_needs_configuration'];
		}


		//tag applies to several types. Let's do that next.
		if (isset($config['tag']) AND ($config['tag'] != '') )
		{
			$criteria->add_tag_filter($config['tag']);
		}

		//now set the content-type specific items.
		if ((isset($config['forumchoice']) AND count($config['forumchoice']) AND $config['forumchoice'][0])
			 AND $contenttypeid == vB_Types::instance()->getContentTypeID('vBForum_Post'))
		{
			$criteria->add_forumid_filter($config['forumchoice'], $config['childforums']);
		}
		else
		{
			$criteria->add_excludeforumid_filter(vB::$vbulletin->options['vbcmsforumid']);
		}

		if ((isset($config['prefixchoice']) AND count($config['prefixchoice']) AND $config['prefixchoice'][0])
			 AND $contenttypeid == vB_Types::instance()->getContentTypeID('vBForum_Post'))
		{
				$criteria->add_filter('prefix', vB_Search_Core::OP_EQ, $config['prefixchoice'], true);
		}

		if ((isset($config['cat']) AND count($config['cat']) AND $config['cat'][0]) AND $contenttypeid == vB_Types::instance()->getContentTypeID('vBForum_SocialGroup'))
		{
			$criteria->add_filter('sgcategory', vB_Search_Core::OP_EQ, $config['cat'], true);
		}

		if (isset($config['group']) AND ($config['group'] != '') AND $contenttypeid == vB_Types::instance()->getContentTypeID('vBForum_SocialGroupMessage'))
		{
			$criteria->add_filter('socialgroup', vB_Search_Core::OP_EQ, $config['group'], true);
		}
		else if ((isset($config['cat']) AND count($config['cat']) AND $config['cat'][0]) AND $contenttypeid == vB_Types::instance()->getContentTypeID('vBForum_SocialGroupMessage'))
		{
			$criteria->add_filter('sgcategoryid', vB_Search_Core::OP_EQ, $config['cat'], true);
		}

		$search_type->add_advanced_search_filters($criteria, vB::$vbulletin);

		$current_user = new vB_Legacy_CurrentUser();

		$timelimit = TIMENOW - (86400 * $config['days']);
		$criteria->add_date_filter(vB_Search_Core::OP_GT, $timelimit);

		if ($config['username'] AND $config['username'] != '')
		{
			$criteria->add_user_filter($config['username'], true, true);
		}
		else if ($config['friends'])
		{
			$friends = $this->getFriends($current_user->getField('userid'));

			if (count($friends))
			{
				$criteria->add_userid_filter($friends, false);
			}
			else
			{
				return '';
			}
		}

		if ($config['keywords'] AND $config['keywords'] != '')
		{
			$criteria->add_keyword_filter($config['keywords'], false);
		}


		$criteria->set_sort('dateline', 'desc');

		$results = vB_Search_Results::create_from_cache($current_user, $criteria);

		if (!$results)
		{
			$results = vB_Search_Results::create_from_criteria($current_user, $criteria);
		}

		$page_results = $results->get_page(1, $config['count'], 1);
		//prepare types for render
		$items_by_type = array();
		foreach ($page_results as $item)
		{
			$typeid = $item->get_contenttype();

			if ($typeid)
			{
				$items_by_type[$typeid][] =  $item;
				$ids[] = $item->get_id();
			}
		}

		foreach ($items_by_type as $contenttype => $items)
		{
			$type = vB_Search_Core::get_instance()->get_search_type_from_id($contenttype);
			$type->prepare_render($results->get_user(), $items);
		}
		vB_Cache::instance()->write($hashkey,array('contenttypeid' => $contenttypeid,
			'ids' => $ids, 'criteria' =>$criteria), $this->cache_ttl,
			$this->getCacheEvent());

		return array('results' => $page_results, 'criteria' => $criteria);

	}
Пример #11
0
function do_search_finduser()
{
    global $vbulletin, $search_core, $search_type, $current_user;
    $vbulletin->input->clean_array_gpc('r', array('type' => TYPE_ARRAY_NOHTML, 'userid' => TYPE_UINT, 'starteronly' => TYPE_BOOL, 'forumchoice' => TYPE_ARRAY, 'childforums' => TYPE_BOOL, 'postuserid' => TYPE_UINT, 'searchthreadid' => TYPE_UINT, 'pagenumber' => TYPE_INT, 'perpage' => TYPE_INT));
    $vbulletin->GPC['prefixchoice'] = array();
    $vbulletin->GPC_exists['prefixchoice'] = true;
    if (!$current_user->hasPermission('forumpermissions', 'cansearch')) {
        $threads[]['error'] = ERR_NO_PERMISSION;
        return array('threads' => $threads, 'total_threads' => 1);
    }
    if (!$vbulletin->options['enablesearches']) {
        $threads[]['error'] = strip_tags(fetch_error('searchdisabled'));
        return array('threads' => $threads, 'total_threads' => 1);
    }
    // valid user id?
    if (!$vbulletin->GPC['userid']) {
        if (!$vbulletin->userinfo['userid']) {
            json_error(ERR_INVALID_USER);
        }
        $vbulletin->GPC['userid'] = $vbulletin->userinfo['userid'];
        $vbulletin->GPC_exists['userid'] = true;
    }
    // valid user id?
    if (!$vbulletin->GPC['userid'] and !$vbulletin->GPC['postuserid']) {
        json_error(ERR_INVALID_USER);
    }
    //default to posts
    if (!$vbulletin->GPC_exists['contenttypeid']) {
        $vbulletin->GPC['contenttypeid'] = vB_Types::instance()->getContentTypeID('vBForum_Post');
        $vbulletin->GPC_exists['contenttypeid'] = true;
    }
    if ($vbulletin->GPC['contenttypeid'] and !is_array($vbulletin->GPC['contenttypeid'])) {
        $criteria = $search_core->create_criteria(vB_Search_Core::SEARCH_ADVANCED);
        $criteria->set_advanced_typeid($vbulletin->GPC['contenttypeid']);
    } else {
        $criteria = $search_core->create_criteria(vB_Search_Core::SEARCH_COMMON);
    }
    set_criteria_from_vbform($current_user, $criteria);
    $search_type->add_advanced_search_filters($criteria, $vbulletin);
    $criteria->set_sort($criteria->switch_field('dateline'), 'desc');
    $errors = $criteria->get_errors();
    if ($errors) {
        json_error($errors[0]);
    }
    $results = null;
    if (!($vbulletin->debug and $vbulletin->GPC_exists['nocache'] and $vbulletin->GPC['nocache'])) {
        $results = vB_Search_Results::create_from_cache($current_user, $criteria);
    }
    if (!$results) {
        $results = vB_Search_Results::create_from_criteria($current_user, $criteria);
    }
    $searchid = $results->get_searchid();
    if ($searchid != -1) {
        return do_showresults($searchid, $vbulletin->GPC['pagenumber'], $vbulletin->GPC['perpage']);
    } else {
        return array('threads' => array(), 'total_threads' => 0);
    }
}
Пример #12
0
	private static function getNewBlogs($user)
	{
		global $vbulletin;
		global $vbphrase;
		if (! file_exists(DIR . '/packages/vbblog/search/searchcontroller/newblogentry.php')
			or ! (vB_Search_Core::get_instance()->get_cansearch('vBBlog', 'BlogEntry') ))
		{
			return;
		}
		include_once DIR . '/packages/vbblog/search/searchcontroller/newblogentry.php' ;
		require_once DIR . '/vb/search/core.php' ;
		require_once DIR . '/vb/search/criteria.php' ;
		require_once DIR . '/includes/functions_databuild.php' ;
		//We can use the existing new structures to create this feed. We don't
		// have to, we could do a direct sql query. But this structure is tested
		// and we know it handles permissions properly.
		//First we need a criteria object
		fetch_phrase_group('vbcms');
		$criteria = vB_Search_Core::get_instance()->create_criteria(vB_Search_Core::SEARCH_NEW);
		//Set the count, which may have been passed to us.
		$max_count = 10;

		if ($vbulletin->GPC_exists['count'] AND intval($vbulletin->GPC['count'])
			and intval($vbulletin->GPC['count']) < 21)
		{
			$max_count = intval($vbulletin->GPC['count']);
		}

		//Do we get a user? If so, limit the query.
		if ($vbulletin->GPC_exists['userid'] AND intval($vbulletin->GPC['userid']))
		{
			$criteria->add_userid_filter($vbulletin->GPC['userid'], true);
		}
		else if ($vbulletin->GPC_exists['searchuser'])
		{
			$criteria->add_user_filter($vbulletin->GPC['searchuser'], true);
		}

		//and set the date limit
		if ($vbulletin->GPC_exists['days'] AND intval($vbulletin->GPC['days'] ))
		{
			$datelimit = TIMENOW - ( intval($vbulletin->GPC['days']) * 86400);
		}
		else
		{
			$datelimit = TIMENOW - ( 3 * 86400);
		}
		$criteria->add_newitem_filter($datelimit, null, null);
		$search_controller = new vBBlog_Search_SearchController_NewBlogEntry;
		$results = vB_Search_Results::create_from_cache($user, $criteria, $search_controller);

		if (! $results = vB_Search_Results::create_from_cache($user, $criteria, $search_controller))
		{
			$results = vB_Search_Results::create_from_criteria($user, $criteria, $search_controller);
		}
		$page = $results->get_page(1, $max_count, 1);
		$headers = array(
			'title' => $vbulletin->options['hometitle'] ,
			'link' => $vbulletin->options['bburl'],
			'description' => construct_phrase($vbphrase['recent_blogs_from_x'], $vbulletin->options['hometitle']) ,
			'language' => 'en-us',
			'updated' => date('Y-m-d\TH:i:s', TIMENOW),
			'lastBuildDate' => date('Y-m-d\TH:i:s', TIMENOW)
		);
		$items= array();

		if (count($page))
		{
			$parser = new vBCms_BBCode_HTML(vB::$vbulletin, vBCms_BBCode_HTML::fetchCmsTags());
			foreach ($page as $result)
			{
				if ($blog = $result->get_record())
				{
					$items[] = array(
						'title' => $blog['title'],
						'summary' => $parser->get_preview($blog['pagetext'], 800),
						'link' => $vbulletin->options['bburl'] . '/blog.php?blogid='
							. $blog['blogid'],
						'author' => 'noreply@noreply.com-' . $blog['username']);
				}
			}
		}
		return self::makeXml($headers, null, $items);
	}
Пример #13
0
	/**
	 * This does the actual work of creating the navigation elements. T
	 * We use the existing search functionality. It's already all there, we just need
	 * to
	 *
	 * @return string;
	 */
	private function makeResults($config)
	{
		include_once DIR . '/includes/functions_misc.php';
		$search_core = vB_Search_Core::get_instance();

		$hashkey = $this->getHash($this->widget->getId());
		$data = vB_Cache::instance()->read($hashkey, true, true);
		if (!$data)
		{
			$criteria = $search_core->create_criteria($search_core->get_search_type('vBForum',
				'Post'));
			$contenttypeid = $search_core->get_contenttypeid('vBForum',	'Post');
			$criteria->add_contenttype_filter($contenttypeid);
			$criteria->set_advanced_typeid($contenttypeid);

			if ($config['ids'])
			{
				$criteria->add_group_filter( explode(",", $config['ids']));
				$criteria->set_grouped(vB_Search_Core::GROUP_YES);

			}
			else
			{
				if ($config['forumchoice'])
				{
					$criteria->add_forumid_filter($config['forumchoice'], $config['childforums']);
				}

				if ($config['days'])
				{
					$timelimit = TIMENOW - (86400 * $config['days']);
					$criteria->add_date_filter(vB_Search_Core::OP_GT, $timelimit);
				}

				$criteria->add_filter('pollid', vB_Search_Core::OP_GT, 1, true);

				$search_type = vB_Search_Core::get_instance()->get_search_type_from_id($contenttypeid);
				$search_type->add_advanced_search_filters($criteria, vB::$vbulletin);
				$criteria->set_grouped(vB_Search_Core::GROUP_YES);

			}

			//Set the configuration parameters
			if (! intval($config['count']))
			{
				$config['count'] = 5;
			}

			if (intval($config['count']) > 12)
			{
				$config['count'] = 5;
			}

			if (!isset($config['template_name']) OR ($config['template_name'] == ''))
			{
				$config['template_name'] = 'vbcms_widget_poll_page';
			}

			if (!isset($config['detail_template']) OR ($config['detail_template'] == ''))
			{
				$config['detail_template'] = 'vbcms_widget_poll_resultdetail';
			}


			$criteria->set_sort('dateline', 'desc');
			$current_user = new vB_Legacy_CurrentUser();
			$results = vB_Search_Results::create_from_cache($current_user, $criteria);

			if (!$results)
			{
				$results = vB_Search_Results::create_from_criteria($current_user, $criteria);
			}

			$page = $results->get_page(1, $config['count'], 0);

			if (count($page))
			{
				$threads = array();
				foreach ($page as $result)
				{
					$threads[] = $result->get_thread()->get_field('threadid');
				}
				$where = implode(', ', $threads);
				$sql = "SELECT p.question, p.options,
				p.votes, t.threadid FROM " . TABLE_PREFIX . "poll p INNER JOIN " . TABLE_PREFIX . "thread t
	 			ON t.pollid = p.pollid WHERE t.threadid IN ( " . $where . ");";


				if ($rst = vB::$vbulletin->db->query_read($sql))
				{
					$data = array();
					require_once(DIR . '/includes/class_bbcode_alt.php');
					while ($row = vB::$vbulletin->db->fetch_array($rst))
					{
						$this_item = array();
						$options = explode('|||', $row['options'] );
						$votes = explode('|||', $row['votes'] );
						$this_item['totalvotes'] = 0;
						for($i = 0; $i < count($votes); $i++)
						{
							$this_item['totalvotes'] += $votes[$i];
						}
						$detail = array();
						$parser = new vB_BbCodeParser_Wysiwyg(vB::$vbulletin, fetch_tag_list('', true), true);
						for ($i = 0; $i < count($options); $i++)
						{
							$this_option = $parser->do_parse($options[$i]);
							$percent = ($this_item['totalvotes'] != 0) ? $votes[$i] / $this_item['totalvotes'] * 100 : 0;

							$detail[] = array(
								'option'        => $this_option,
								'votes'         => $votes[$i],
								'percent'       => vb_number_format($percent, 2),
								'percentraw'    => $percent,
								'number'        => $i + 1,
								'graphicnumber' => (($i + 1) % 6) + 1,
							);
						}
						$detailview = new vBCms_View_Widget($config['detail_template']);
						$detailview->resultdetail = $detail;
						$this_item['resultdetail'] = $detailview->render();
						$this_item['threadid'] = $row['threadid'];
						$this_item['question'] = $row['question'];
						$data[$row['threadid']] = $this_item;
					}

					if (!isset($config['template_name']) OR ($config['template_name'] == ''))
					{
						$config['template_name'] = 'vbcms_widget_poll_page';
					}
				}
			}

			vB_Cache::instance()->write($hashkey,
			   $data, $this->cache_ttl);
		}
		// Create view
		$view = new vBCms_View_Widget($config['template_name']);
		$view->poll_data = $data;
		$view->class = $this->widget->getClass();
		$view->title = $this->widget->getTitle();
		$view->description = $this->widget->getDescription();
		if (empty($view->poll_data))
		{
			$view->setDisplayView(false);
		}

		return $view;
	}