PDA

View Full Version : CMS articles from multiple forums


Sarteck
07-11-2012, 02:20 PM
All right, I'm not sure if this is already a feature, or if there's a modification out there that does this, so please point me in the right direction if either are true. I'm still new to (and very confused by) this CMS stuff, so please bear with me. This may have been answered previously, but I'm not really sure what I'm Searching for, so I couldn't find the answer.



What I would like is a CMS page with two columns.

The column on the left would contain a preview of the first post of each of the newest 10 threads in a forum (we'll call it "Forum1"), just like how regular Articles appear in the CMS.

The column on the right would contain a preview of the first post of each of the newest 10 threads in "Forum2."

Each Article would allow Comments to be posted on it. Comments would show up in the threads as regular posts and (vice versa) posts made in the threads would show up as Comments in the Articles.



I do understand that Articles do have their own forum, but I'd actually like each section of Articles to have its own forum.

Ideally, new threads posted in these forums would automatically become Articles, but if I have to manually "Promote" it to an Article, that's okay by me.



Is this possible? Is this already a feature that I just don't see somewhere?

Sarteck
07-13-2012, 03:15 AM
After a bunch of searching with no result, I decided to try and tackle this on my own.

Here is the full (so far) code I am using:

<?php

function create_cms_block($head,$body,$foot=false)
{
if (!is_array($head)) {$head = array('content' => $head);}
if (!is_array($body)) {$body = array('content' => $body);}
if ($foot) {if (!is_array($foot)) {$foot = array('content' => $foot);}}

$templater = vB_Template::create('custom_cms_block');
$templater->register('head', $head);
$templater->register('body', $body);
$templater->register('foot', $foot);
$output = $templater->render();
return $output;
}

function create_forum_article_widget($forumid)
{
$foruminfo = fetch_foruminfo($forumid);
if (!$foruminfo) {return '';}
$threadinfos = get_latest_threads_in_forum($forumid);
if (!$threadinfos) {return '';}
$articles = array();
foreach ($threadinfos AS $threadinfo) {$articles[] = create_article_block_from_threadinfo($threadinfo,$ numchars);}
$body = array(); $body['content'] = '<div style="clear:both;">'.implode('</div><div style="padding-top:30px;clear:both;">',$articles).'</div>';
$head = array(); $head['content'] = $foruminfo['title'];
return create_cms_block($head,$body);
}


function get_latest_threads_in_forum($forumid)
{
// Gets some thread info and some post info (from first post in thread)
global $vbulletin;
$query = sprintf("
SELECT thread.threadid, thread.title, thread.firstpostid, thread.postuserid, thread.dateline, post.pagetext
FROM ".TABLE_PREFIX."thread AS thread
LEFT JOIN ".TABLE_PREFIX."post AS post ON (thread.firstpostid=post.postid)
WHERE forumid=%d",$forumid);
$result = $vbulletin->db->query_read($query);
while ($row = $vbulletin->db->fetch_array($result))
{
$info = array(
'threadid' => $row['threadid'],
'title' => $row['title'],
'postid' => $row['firstpostid'],
'userid' => $row['postuserid'],
'dateline' => $row['dateline'],
'content' => $row['pagetext']
);
$threads[] = $info;
}
return $threads;
}

function create_article_block_from_threadinfo($threadinfo,$ numchars=false)
{
// $threadinfo is array, includes threadID, title, postID, userID, dateline, and content of first post
global $vbulletin;
$titlebit = '<a href="showthread.php?'.$threadinfo['threadid'].'">'.htmlspecialchars($threadinfo['title']).'</a>';
$userinfo = fetch_userinfo($threadinfo['userid']);
$authorbit = '<a href="member.php?'.$userinfo['userid'].'">'.$userinfo['musername'].'</a>';
$datebit = vbdate($vbulletin->options['dateformat'], $threadinfo['dateline'], 1) . ' ' . vbdate($vbulletin->options['timeformat'], $threadinfo['dateline']);

if (!$numchars) {$numchars = $vbulletin->options['default_cms_previewlength'];}
require_once(DIR . '/includes/class_bbcode.php');
$parser = new vB_BbcodeParser($vbulletin, fetch_tag_list());
$parser->default_previewlen = $numchars;
$previewtext = $parser->get_preview($threadinfo['content']);
$preview_chopped = $parser->createdsnippet;

$templater = vB_Template::create('custom_cms_article');
$templater->register('titlebit', $titlebit);
$templater->register('authorbit', $authorbit);
$templater->register('datebit', $datebit);
$templater->register('previewtext', $previewtext);
$templater->register('preview_chopped', $preview_chopped);
$output = $templater->render();
return $output;
}

?>



Here are the two templates used by the code:

custom_cms_block
<div class="block">
<h2 class="blockhead">{vb:raw head.content}</h2>
<div class="blockbody settings_form_border">
<div class="blockrow">
{vb:raw body.content}
<div style="clear:both;">&nbsp; </div>
</div>
</div>
<vb:if condition="$foot">
<div class="blockfoot actionbuttons settings_form_border">
{vb:raw foot.content}
</div>
</vb:if>
</div>

custom_cms_article
<div class="article_preview">
<div class="title">
<h3 class="article_preview">{vb:raw titlebit}</h3>
</div>
<div class="cms_article_username">by {vb:raw authorbit} on {vb:raw datebit}</div>
<div class="fullwidth article_preview_contents showpreviewonly restore">
<div class="cms_article_txt_content postcontainer">
{vb:raw previewtext}
<vb:if condition="$preview_chopped">...</vb:if>
</div>
</div>
<div class="fullwidth">
<span class="cms_article_readmore">Full topic &amp; replies: <img src="{vb:stylevar imgdir_cms}/read_more-{vb:stylevar right}.png" alt="{vb:rawphrase read_more_phrase}" /> {vb:raw titlebit}</span>
</div>
</div>




------------------------------------------------------------------


This is working okay (although there's a lot I'd like to add), except for the previews cenerated by the following code:
require_once(DIR . '/includes/class_bbcode.php');
$parser = new vB_BbcodeParser($vbulletin, fetch_tag_list());
$parser->default_previewlen = $numchars;
$previewtext = $parser->get_preview($threadinfo['content']);It doesn't allow tags that I wished it would allow (images, quotes, etc.) like the real Articles do.

I am pretty lost on where to find the function that parses the previews for the Articles. Could someone kindly point me in the right direction? I'll share mah code with y'all when it's done :P

--------------- Added 1342153095 at 1342153095 ---------------

Ah, and um, since this thread has turned to something more befitting the programming forum, if one of the Staff would like to move it there, that's fine.

Sarteck
07-20-2012, 06:03 PM
Just wanted to bump this, see if anyone's got any input.