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 Code:
<?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
HTML Code:
<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;"> </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
HTML Code:
<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 & 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:
PHP 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 [DATE]1342153095[/DATE] at [TIME]1342153095[/TIME] ---------------
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.