View Single Post
  #2  
Old 07-13-2012, 03:15 AM
Sarteck's Avatar
Sarteck Sarteck is offline
 
Join Date: Mar 2008
Posts: 304
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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($vbulletinfetch_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;">&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
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 &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:
PHP Code:
  require_once(DIR '/includes/class_bbcode.php'); 
  
$parser = new vB_BbcodeParser($vbulletinfetch_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.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01396 seconds
  • Memory Usage 1,854KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_html
  • (2)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete