1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

"Discussion preview" displaying latest post's content

Discussion in 'XenForo Questions and Support' started by attilakristo, Sep 28, 2011.

  1. attilakristo

    attilakristo New Member

    Hi fellow XenForo brothers/sisters :)

    I'm total new to XenForo, just bought it a few weeks earlier.
    May I ask if you know about a way to have the "discussion preview" display a preview of the latest/most fresh message instead of showing a part of the original (first) message of a thread?

    By "discussion preview", I mean this text-box: http://cl.ly/2W0D2z0I2F3A3F0F3K2v
    Based on my small research, it's an overlay. Right ?:)

    Thanks in advance for any advice/thoughts.

    Cheers,
    Attila
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    I've moved your thread to the correct forum for support.

    You will need to associate your forum account with your license before you can post in the customer forums.

    You can do so here: http://xenforo.com/customers/forum-users
     
  3. attilakristo

    attilakristo New Member

    Thanks! Done.

    So, I'd like to ask for opinions about the above, whether it's possible or not :) Thanks!
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    This requires a code change:

    library/XenForo/ControllerPublic/Thread.php

    Replace the red code:

    Code:
    	public function actionPreview()
    	{
    		$threadId = $this->_input->filterSingle('thread_id', XenForo_Input::UINT);
    
    		$visitor = XenForo_Visitor::getInstance();
    
    		$ftpHelper = $this->getHelper('ForumThreadPost');
    		list($thread, $forum) = $ftpHelper->assertThreadValidAndViewable($threadId);
    
    		$threadModel = $this->_getThreadModel();
    		$postModel = $this->_getPostModel();
    
    		if ($threadModel->isRedirect($thread))
    		{
    			return $this->responseView('XenForo_ViewPublic_Thread_Preview', '', array('post' => false));
    		}
    
    		$post = $postModel->getPostById($thread['first_post_id'], array(
    			'join' => XenForo_Model_Post::FETCH_USER
    		));
    		if ($post['thread_id'] != $threadId || !$postModel->canViewPost($post, $thread, $forum))
    		{
    			return $this->responseView('XenForo_ViewPublic_Thread_Preview', '', array('post' => false));
    		}
    
    		$viewParams = array(
    			'post' => $post,
    			'thread' => $thread,
    			'forum' => $forum
    		);
    
    		return $this->responseView('XenForo_ViewPublic_Thread_Preview', 'thread_list_item_preview', $viewParams);
    	}
    
    like so:

    Code:
    	public function actionPreview()
    	{
    		$threadId = $this->_input->filterSingle('thread_id', XenForo_Input::UINT);
    
    		$visitor = XenForo_Visitor::getInstance();
    
    		$ftpHelper = $this->getHelper('ForumThreadPost');
    		list($thread, $forum) = $ftpHelper->assertThreadValidAndViewable($threadId);
    
    		$threadModel = $this->_getThreadModel();
    		$postModel = $this->_getPostModel();
    
    		if ($threadModel->isRedirect($thread))
    		{
    			return $this->responseView('XenForo_ViewPublic_Thread_Preview', '', array('post' => false));
    		}
    
    		$post = $postModel->getPostById($thread['last_post_id'], array(
    			'join' => XenForo_Model_Post::FETCH_USER
    		));
    		if ($post['thread_id'] != $threadId || !$postModel->canViewPost($post, $thread, $forum))
    		{
    			return $this->responseView('XenForo_ViewPublic_Thread_Preview', '', array('post' => false));
    		}
    
    		$viewParams = array(
    			'post' => $post,
    			'thread' => $thread,
    			'forum' => $forum
    		);
    
    		return $this->responseView('XenForo_ViewPublic_Thread_Preview', 'thread_list_item_preview', $viewParams);
    	}
    
    Keep in mind that file edits like this are overwritten when you upgrade. If you are familiar with the addon system then you can turn it into an addon.
     
  5. samtheman

    samtheman New Member

    How would you turn that into an add-on? You'd have to overwrite actionPreview correct and basically copy and paste the full function from above? Which then might not be compatible when you upgrade?
     
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Correct.

    You could also override _getPostModel() in that controller to return a different model with a different getPostById() function, but that would affect all actions in the thread controller. It's probably better to just override actionPreview().

    Sorry. Just thinking out loud.
     

Share This Page