Ejemplo n.º 1
0
 /**
  * Create object from and existing record
  *
  * @param int $foruminfo
  * @return vB_Legacy_Thread
  */
 public static function create_from_record($threadinfo)
 {
     $thread = new vB_Legacy_Thread();
     $current_user = new vB_Legacy_CurrentUser();
     if (array_key_exists('subscribethreadid', $threadinfo)) {
         $thread->subscribed[$current_user->getField('userid')] = (bool) $threadinfo['subscribethreadid'];
         unset($threadinfo['subscribethreadid']);
     }
     if (array_key_exists('readtime', $threadinfo)) {
         $thread->lastread[$current_user->getField('userid')] = $threadinfo['readtime'];
         unset($threadinfo['readtime']);
     }
     $thread->set_record($threadinfo);
     return $thread;
 }
Ejemplo n.º 2
0
	/**
	 * Index a thread
	 *
	 * By default this will look up all of the posts in a thread and calls the core
	 * indexer for each one
	 *
	 * @param int $id the thread id
	 */
	public function index_thread($id)
	{
		global $vbulletin;

		$thread = vB_Legacy_Thread::create_from_id($id);
		
		// make sure thread comes from the CMS comment forum 
		if ($thread->get_field('forumid') != $vbulletin->options['vbcmsforumid'])
		{
			return;
		}

		$set = $vbulletin->db->query_read("
			SELECT post.* FROM " . TABLE_PREFIX . "post AS post WHERE threadid = " . intval($id)
		);

		$indexer = vB_Search_Core::get_instance()->get_core_indexer();
		while ($row = $vbulletin->db->fetch_array($set))
		{
			$post = vB_Legacy_Post::create_from_record($row, $thread);
			$fields = $this->post_to_indexfields($post);
			if ($fields)
			{
				$indexer->index($fields);
			}
		}
	}
Ejemplo n.º 3
0
 public static function create($id)
 {
     require_once DIR . '/vb/legacy/thread.php';
     if ($thread = vB_Legacy_Thread::create_from_id($id)) {
         $item = new vBForum_Search_Result_Thread();
         $item->thread = $thread;
         $item->set_data($id);
         return $item;
     }
     //if we get here,  the id must be invalid.
     require_once DIR . '/vb/search/result/null.php';
     return new vB_Search_Result_Null();
 }
Ejemplo n.º 4
0
 public function fetch_validated_list($user, $ids, $gids)
 {
     require_once DIR . '/includes/functions_forumlist.php';
     cache_moderators();
     $list = array_fill_keys($ids, false);
     foreach (vB_Legacy_Thread::create_array($ids) as $key => $thread) {
         $item = vBForum_Search_Result_Thread::create_from_thread($thread);
         if ($item->can_search($user)) {
             $list[$key] = $item;
         }
     }
     $retval = array('list' => $list, 'groups_rejected' => $rejected_groups);
     ($hook = vBulletinHook::fetch_hook('search_validated_list')) ? eval($hook) : false;
     return $retval;
 }
Ejemplo n.º 5
0
 public function group_data_change($id)
 {
     $thread = vB_Legacy_Thread::create_from_id($id);
     if (!$thread) {
         //skip non existant threads.
         return;
     }
     $fields['groupdateline'] = $thread->get_field('lastpost');
     $fields['grouptitle'] = $thread->get_field('title');
     $fields['groupuserid'] = $thread->get_field('postuserid');
     $fields['groupusername'] = $thread->get_field('postusername');
     $fields['groupcontenttypeid'] = $this->groupcontenttypeid;
     $fields['groupid'] = $thread->get_field('threadid');
     $indexer = vB_Search_Core::get_instance()->get_core_indexer();
     $indexer->group_data_change($fields);
 }
Ejemplo n.º 6
0
 /**
  * Get the thread containing the post
  *
  * @return vB_Legacy_Thread
  */
 public function get_thread()
 {
     if (is_null($this->thread)) {
         $this->thread = vB_Legacy_Thread::create_from_id($this->get_field('threadid'));
     }
     return $this->thread;
 }
Ejemplo n.º 7
0
	public static function canViewThread($nodeid, $user)
	{
		require_once DIR . '/vb/legacy/thread.php';

		if (! $row = vB::$vbulletin->db->query_first("SELECT nodeinfo.associatedthreadid
		AS threadid, thread.forumid FROM " . TABLE_PREFIX . "cms_nodeinfo
		AS nodeinfo LEFT JOIN " . TABLE_PREFIX . "thread AS thread
		ON thread.threadid = nodeinfo.associatedthreadid
		WHERE	nodeinfo.nodeid = $nodeid;" ))
		{
			return false;
		}

		//we have to worry about people deleting the thread or the forum. Annoying.
		if (intval($row['associatedthreadid']) AND ! intval($row['forumid']))
		{
			$this->repaircomments($record['associatedthreadid']);
			return false;
		}

		// Trust me, it's just a temp fix -- Xiaoyu
		global $thread;
		$thread = vB_Legacy_Thread::create_from_id($row['threadid']);
		if (!$thread)
		{
			return false;
		}

		if (!$thread->can_view($user))
		{
			return false;
		}

		$can_moderate_forums = $user->canModerateForum($thread->get_field('forumid'));
		$can_moderate_posts = $user->canModerateForum($thread->get_field('forumid'), 'canmoderateposts');
		$is_coventry = false;

		if (!$can_moderate_forums)
		{
			//this is cached.  Should be fast.
			require_once (DIR . '/includes/functions_bigthree.php');
			$conventry = fetch_coventry();

			$is_coventry = (in_array($user->get_field('userid'), $conventry));

		}

		if (! $can_moderate_forums AND $is_coventry)
		{
			return false;
		}

		// If we got here, the user can at least see the thread. We still have
		// to check the individual records;
		return array('can_moderate_forums' => $can_moderate_forums,
		'is_coventry' => $is_coventry,
		'can_moderate_posts' => $can_moderate_posts);
	}
Ejemplo n.º 8
0
	/**
	 * Gets the associated thread for commenting on this content.
	 *
	 * @return vB_Legacy_Thread
	 */
	protected function getAssociatedThread()
	{

		// Get the thread
		// Resolve the thread id
		if (intval(vB::$vbulletin->options['vbcmsforumid'])  AND intval($this->content->getSetPublish())
			AND intval($this->content->getComments_Enabled()))
		{
			$threadid = $this->content->getAssociatedThreadId();

			if (!$threadid)
			{
				$threadid = $this->associateThread();

				//If we failed here, there's something wrong. Probably the forum id is invalid.
				if (!$threadid)
				{
					return false;
				}
			}

			//Verify that the thread is active.
			$thread = vB_Legacy_Thread::create_from_id($threadid);

			if (!$thread)
			{
				//Try again
				$threadid = $this->associateThread();

				//If we failed here, there's something wrong. Probably the forum id is invalid.
				if (!$threadid)
				{
					return false;
				}
				$thread = vB_Legacy_Thread::create_from_id($threadid);

				if (!$thread)
				{
					return false;
				}
			}
			//If we got here, we have a valid thread.
			if (! $thread->get_field('visible'))
			{
				require_once DIR . '/includes/functions_databuild.php';
				undelete_thread($threadid);
			}
		}

		return $thread;
	}
Ejemplo n.º 9
0
	/**
	* Performs additional queries or tasks after saving.
	*
	* @param mixed								- The save result
	* @param bool $deferred						- Save was deferred
	* @param bool $replace						- Save used REPLACE
	* @param bool $ignore						- Save used IGNORE if inserting
	* @return bool								- Whether the save can be considered a success
	*/
	protected function postSave($result, $deferred, $replace, $ignore)
	{
		//First let's handle the configuration.
		if (isset($this->set_fields['config']))
		{
			if ($this->isUpdating())
			{
				$this->assertItem();
				$id = $this->item->getNodeId();
			}
			else
			{
				if (!$this->primary_id)
				{
					throw (new vB_Exception_DM('No primary id available for setting the node config in DM \'' . get_class($this) . '\''));
				}

				$id = $this->primary_id;
			}

			// delete the old config
			vB::$db->query_write(
				'DELETE FROM ' . TABLE_PREFIX . 'cms_nodeconfig
				 WHERE nodeid = ' . $id);

			// build the sql
			$sql = 'INSERT INTO ' . TABLE_PREFIX . 'cms_nodeconfig (nodeid, name, value, serialized) VALUES ';
			$values = array();

			// write the new config
			foreach ($this->set_fields['config'] AS $cvar => $value)
			{
				if (is_resource($value))
				{
					throw (new vB_Exception_DM('Trying to set a resource as a node config value'));
				}

				if (is_object($value) OR is_array($value))
				{
					$serialized = true;
					$value = serialize($value);
				}
				else
				{
					$serialized = false;
				}

				$values[] = '(' . $id . ', \'' . vB::$db->escape_string($cvar) . '\',\'' . vB::$db->escape_string($value) . '\',\'' . intval($serialized) . '\')';
			}
			// insert config
			vB::$db->insert_multiple($sql, $values, true);

		}

		//and set permissionsfrom the parent. Let's do this so we fix any close records.
		$nodeid = (isset($this->set_fields['nodeid']) ? $this->set_fields['nodeid'] : $this->primary_id);
		$parents = array();
		if (intval($this->set_fields['permissionsfrom']))
		{
			$permissionsfrom = $this->set_fields['permissionsfrom'];
		}
		else
		{
			//we'll pull from our parent.
			$rst = vB::$vbulletin->db->query_read("SELECT parent.nodeid, parent.parentnode,
				parent.permissionsfrom, parent.nodeleft, parent.noderight
				FROM " . TABLE_PREFIX . "cms_node AS node INNER JOIN " . TABLE_PREFIX .
				"cms_node AS parent ON (node.nodeleft >= parent.nodeleft AND node.nodeleft <=parent.noderight)
				WHERE node.nodeid = $nodeid
				ORDER BY parent.nodeleft DESC");
			while($record = vB::$vbulletin->db->fetch_array($rst))
			{
				$parents[] = $record;
				if (intval($record['permissionsfrom']))
				{
					$permissionsfrom = $record['permissionsfrom'];
					if (intval($record['permissionsfrom']) != intval($nodeid))
					{
						break;
					}
				}
			}
			//either we found a parent with a permissionsfrom, or we hit the top- which is
			// just as good.
			vB::$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "cms_node SET permissionsfrom = " .
				$permissionsfrom . " WHERE nodeid = $nodeid" ) ;

		}
		foreach ($parents as $parent)
		{
			vB::$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "cms_node SET permissionsfrom = " .
				$permissionsfrom . " WHERE parentnode = " . $parent['nodeid'] .

				" AND IFNULL(permissionsfrom, 0) = 0") ;
		}

		if (isset($this->set_fields['navigation']))
		{
			$nodeid = intval((isset($this->set_fields['nodeid']) ? $this->set_fields['nodeid'] : $this->item->getNodeId()));

			// if there is array for navigation menu, it means we are not inheriting from parent
			// so we must add/modify the record in the navigation table for this node
			if (is_array($this->set_fields['navigation']))
			{
				vB::$vbulletin->db->query_write("
					REPLACE INTO " . TABLE_PREFIX . "cms_navigation
					SET nodeid = $nodeid,
						nodelist = '" . implode(',', $this->set_fields['navigation']) . "'
				");
			}

			// if this is not an array, it means the drop-down was selected to inherit from parent
			// so delete any record in the navigation table for this node
			else
			{
				vB::$vbulletin->db->query_write("
					DELETE FROM " . TABLE_PREFIX . "cms_navigation
					WHERE nodeid = $nodeid
				");
			}

		}

		if (isset($this->set_fields['setpublish']) OR isset($this->set_fields['navigation']))
		{
				// clear the navbar cache
			vB_Cache::instance()->event(array(vBCms_NavBar::GLOBAL_CACHE_EVENT,
				vBCms_NavBar::getCacheEventId($this->item->getNodeId()),
				$this->item->getCacheEvents(), $this->item->getContentCacheEvent()));
			vB_Cache::instance()->cleanNow();
			$nav_node = new vBCms_Item_Content($this->item->getNodeId(), vBCms_Item_Content::INFO_NAVIGATION);
			// reload the navbar for the page
			vBCms_NavBar::prepareNavBar($nav_node, true);
			unset($nav_node);
		}
		else if ($this->item)
		{
			vB_Cache::instance()->event(array($this->item->getCacheEvents(),
				$this->item->getContentCacheEvent()));
		}

		//Let's set the thread status, if there is one.
		//If we get called from dm/rate.php or somewhere like that, we skip this section
		if ($this->isUpdating() AND in_array('comments_enabled', $this->set_fields) AND
			isset($this->set_fields['comments_enabled']))
		{
			$record = vB::$vbulletin->db->query_first("SELECT info.associatedthreadid, thread.forumid FROM " .
				TABLE_PREFIX . "cms_nodeinfo AS info INNER JOIN " .
				TABLE_PREFIX . "thread AS thread ON thread.threadid = info.associatedthreadid
				WHERE info.nodeid = ". $this->item->getNodeId() );

			if ($record['associatedthreadid'])
			{
				require_once DIR . '/includes/functions_databuild.php';
				$thread = vB_Legacy_Thread::create_from_id($record['associatedthreadid']);

				if ($thread)
				{
					if (intval($this->set_fields['comments_enabled']))
					{
						//We need to ensure comments are enabled.
						$visible = $thread->get_field('visible');
						if ( intval($visible) != 1)
						{
							undelete_thread($record['associatedthreadid']);
						}

						//If the title has been updated in the article, update the thread title.
						if (($thread->getField('title') != '') AND isset($this->set_fields['title'])
							AND ($thread->getField('title') != $this->set_fields['title']))
						{
							$sql = "UPDATE " . TABLE_PREFIX . "thread SET title = '" .
								vB::$db->escape_string($this->set_fields['title']) .
								"' WHERE threadid = " . $record['associatedthreadid'];
							vB::$db->query_write($sql);
						}
					}
					else
					{
						//We need to hide the thread.
						$thread->soft_delete(new vB_Legacy_CurrentUser(), '', true);
					}

				}
				build_thread_counters($record['associatedthreadid']);
				build_forum_counters($record['forumid']);
			}
		}

		parent::postSave($result, $deferred, $replace, $ignore);
		//we should never return false if we got here.
		$result = (intval($result) ? $result : true);

		return $result;
	}
Ejemplo n.º 10
0
	/**
	 * Index a thread
	 *
	 * By default this will look up all of the posts in a thread and calls the core
	 * indexer for each one
	 *
	 * @param int $id the thread id
	 */
	public function index_thread($id)
	{
		throw new Exception ('should not be here');
		global $vbulletin;

		$thread = vB_Legacy_Thread::create_from_id($id);

		$set = $vbulletin->db->query_read("
			SELECT post.* FROM " . TABLE_PREFIX . "post AS post WHERE threadid = " . intval($id)
		);

		$indexer = vB_Search_Core::get_instance()->get_core_indexer();
		while ($row = $vbulletin->db->fetch_array($set))
		{
			$post = vB_Legacy_Post::create_from_record($row, $thread);
			$fields = $this->post_to_indexfields($post);
			if ($fields)
			{
				$indexer->index($fields);
			}
		}
	}
Ejemplo n.º 11
0
 /**
  * vBForum_Search_Type_Post::listUi()
  *This function generates the search elements for the user to search for posts
  * @param mixed $prefs : the array of user preferences / propogated form values.
  * @param mixed $contenttypeid : the content type for which we are going to
  *    search
  * @param array registers : any additional elements to be registered. These are
  * 	just passed to the template
  * @param string $template_name : name of the template to use for display. We have
  *		a default template.
  * @return $html: complete html for the search elements
  */
 public function listUi($prefs = null, $contenttypeid = null, $registers = null, $template_name = null)
 {
     global $vbulletin, $vbphrase;
     if (!isset($template_name)) {
         $template_name = 'search_input_post';
     }
     if (!isset($contenttypeid)) {
         $contenttypeid = $this->get_contenttypeid();
     }
     $template = vB_Template::create($template_name);
     if ($prefs['searchthreadid']) {
         if ($thread = vB_Legacy_Thread::create_from_id($prefs['searchthreadid'])) {
             $template->register('thread_title', $thread->get_field('title'));
         }
     }
     $template->register('securitytoken', $vbulletin->userinfo['securitytoken']);
     $template->register('contenttypeid', $contenttypeid);
     $template->register('search_forum_options', $this->showForumOptions($prefs['forumchoice']));
     $prefix_selected = array('anythread' => (empty($prefs['prefixchoice']) or in_array('', $prefs['prefixchoice'])) ? 'selected="selected"' : '', 'anyprefix' => ($prefs['prefixchoice'] and in_array('-2', $prefs['prefixchoice'])) ? 'selected="selected"' : '', 'none' => ($prefs['prefixchoice'] and in_array('-1', $prefs['prefixchoice'])) ? 'selected="selected"' : '');
     $template->register('prefix_selected', $prefix_selected);
     $template->register('search_prefix_options', vB_Search_Searchtools::getPrefixOptions($prefs['prefixchoice'], false));
     $this->setPrefs($template, $prefs, array('select' => array('sortby', 'order', 'forumchoice', 'prefixchoice', 'titleonly', 'starteronly', 'searchdate', 'beforeafter'), 'cb' => array('childforums', 'exactname', 'nocache'), 'value' => array('query', 'searchuser', 'tag', 'searchthreadid'), 'rb' => array('showposts')));
     vB_Search_Searchtools::searchIntroRegisterHumanVerify($template);
     if (isset($registers) and is_array($registers)) {
         foreach ($registers as $key => $value) {
             $template->register($key, htmlspecialchars_uni($value));
         }
     }
     ($hook = vBulletinHook::fetch_hook('search_listui_complete')) ? eval($hook) : false;
     return $template->render();
 }