Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Just display discussions

edited June 2009 in Vanilla 1.0 Help
I'm doing a vanilla install (ps love the script :D) for a friend and I need to just display the discussions and not the header or the sidebar etc. Just the comments. Is there anyway to just include it in? Or just access one page through an iframe (ew) ? Thanks.

Comments

  • There's a plugin to temporarily hide the sidebar, but I don't think that's what you want. How would people navigate?
  • Well, what I want to do is just display the most recent discussions in an iframe on the main layout. Then, if the user clicks a discussion, they will be taken to the full-blown layout of the forums. It's just so people can see the more recent forum posts.
  • If your main page has a way to show RSS feeds, that works pretty well.
  • Hm... Wouldn't it just be easier to include a file from somewhere?
  • Given the way Vanilla is constructed, it's not very easy to hack chunks out of it without a really good idea of how it's put together.
  • As mentioned earlier, where is this plugin to hide the sidebar?
  • I'm pretty sure it's one of the ones that comes with 0.9.2
  • edited March 2006
    Yeah. It's called the panelhider. I'm not sure if its available with 0.9.2.6...cant remember if he took it out for 0.9.3 or before. Seriously though RSS would be your easiest choice; alternatively you could just write a query to pull the latest discussion info from your database and display it on your homepage since you'll have DB access. That seems to have been the choice made by most people who wanted forum info outside the forum.
  • MarkMark Vanilla Staff
    edited March 2006
    It sounds like what you really want is to write a query for the vanilla database and just display those records in your site. Do you have any programming experience at all?

    We can tell you exactly what the query should be, but you really should know how to display the records yourself.
  • NickENickE New
    edited March 2006
    You're probably going to go for parsing your own feeds anyways, but if you felt like getting your hands a tad dirty for a gain in efficiency then you could use something along these lines. (include it then call GetRecentDiscussions([number to display [preview len]]))
    <?php
    
    $VanillaDir = './'; //(relative) path to your vanilla installation
    
    include($VanillaDir.'appg/settings.php');
    include_once(sgLIBRARY.'Vanilla.Discussion.class.php');
    include_once(sgLIBRARY.'Vanilla.Comment.class.php');
    include($VanillaDir.'appg/init_ajax.php');
    
    function GetPreview($Text, $Len)
    {
    	if(strlen($Text) <= $Len) return $Text;
    	
    	//first check to see if we can seperate paragraphs
    	for($i = $Len; $Text[$i] != "\n" && $Text[$i] != "\r" && $i > 0; $i--) ;
    	if($i > 0) return substr($Text, 0, $i) . ' ...';
    	
    	//now try punctuation
    	for($i = $Len; !ctype_punct($Text[$i]) && $i >= 0; $i--) ;
    	if($i > 0) return substr($Text, 0, $i) . ' ...';
    	
    	//and lastly, any spaces
    	for($i = $Len; !ctype_space($Text[$i]) && $i >= 0; $i--) ;
    	if($i > 0) return substr($Text, 0, $i) . ' ...';
    	
    	//if none of the above, just return a substring
    	return substr($Text, 0, $Len) . ' ...';
    }
    
    function GetRecentDiscussions($Number = 10, $Preview = 50)
    {
    	global $Context, $VanillaDir;
    	
    	$s = $Context->ObjectFactory->NewContextObject($Context, 'SqlBuilder');
    	$s->SetMainTable('Discussion', 't');
    	$s->AddSelect(array('DiscussionID', 'DateCreated', 'Name', 'AuthUserID', 'DateLastActive', 'LastUserID'), 't');
    	
    	$s->AddJoin('User', 'lu', 'UserID', 't', 'LastUserID', 'left join');
    	$s->AddSelect('Name', 'lu', 'LastUserName');
    	
    	$s->AddJoin('User', 'u', 'UserID', 't', 'AuthUserID', 'left join');
    	$s->AddSelect('Name', 'u', 'AuthUserName');
    	
    	$s->AddJoin('Comment', 'c', 'CommentID', 't', 'FirstCommentID', 'left join');
    	$s->AddSelect('Body', 'c');
    	
    	$s->AddJoin('Category', 'cg', 'CategoryID', 't', 'CategoryID', 'left join');
    	$s->AddSelect('CategoryID', 'cg');
    	$s->AddSelect('Name', 'cg', 'Category');
    	
    	if($Context->Session->UserID > 0)
    		$s->AddJoin('CategoryRoleBlock', 'crb', 'CategoryID and crb.RoleID = '.$Context->Session->User->RoleID, 't', 'CategoryID', 'left join');
    	else
    		$s->AddJoin('CategoryRoleBlock', 'crb', 'CategoryID and crb.RoleID = 1', 't', 'CategoryID', 'left join');
    	
    	$s->AddWhere('coalesce(crb.Blocked, 0)', '0', '=', 'and', '', 0, 0);
    	$s->AddWhere('t.WhisperUserID', 0, '=', 'and', '', 1, 1);
    	$s->AddWhere('t.WhisperUserID', 0, '=', 'or', '' , 0);
    	$s->AddWhere('t.WhisperUserID', 'null', 'is', 'or', '' , 0);
    	$s->EndWhereGroup();
    	
    	$s->AddOrderBy('DateLastActive', 't', 'desc');
    	$s->AddLimit(0, $Number);
    	
    	$Data = $Context->Database->Select($Context, $s, 'Extension', 'GetRecentDiscussions', 'An error occurred while retrieving discussions.');
    	
    	while($Row = $Context->Database->GetRow($Data))
    	{
    		/*
    			available indexes, for modification:
    			CategoryID, Category, DiscussionID, Discussion, AuthUserID, AuthUserName, LastUserID, LastUserName, 
    			Body, Name, DateCreated, DateLastActive
    		*/
    		echo('
    			<dl class="DiscussionPreview">
    				<dt><a href="'.$VanillaDir.'comments.php?DiscussionID='.$Row['DiscussionID'].'">'.FormatStringForDisplay($Row['Name']).'</a></dt>
    				<dd class="Label">Category</dd>
    				<dd class="Item"><a href="'.$VanillaDir.'?CategoryID='.$Row['CategoryID'].'">'.FormatStringForDisplay($Row['Category']).'</a></dd>
    				<dd class="Label">Author</dd>
    				<dd class="Item"><a href="'.$VanillaDir.'account.php?u='.$Row['AuthUserID'].'">'.FormatStringForDisplay($Row['AuthUserName']).'</a></dd>
    				<dd class="Label">Last Active</dd>
    				<dd class="Item">'.TimeDiff(UnixTimestamp($Row['DateLastActive']), mktime()).'</dd>
    				<dd class="Label">Last Post By</dd>
    				<dd class="Item"><a href="'.$VanillaDir.'account.php?u='.$Row['LastUserID'].'">'.FormatStringForDisplay($Row['LastUserName']).'</a></dd>
    				<dd class="PreviewText">'.FormatStringForDisplay(GetPreview($Row['Body'], $Preview)).'</dd>
    			</dl>');
    	}
    	
    	return 0;
    }
    
    ?>
    And I can post the actual query in readible form as well if you want; couldn't include it in this post because of the character limit.
  • would this still work..?
  • I'm looking for something like this for ages, but is isn't working porperly. He says it cant find the includes files, "but they are there" so i cant locate the problem. Is this stil working for the latest vanilla version?
Sign In or Register to comment.