Example #1
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;
	}