Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-11-2012, 02:20 PM
Sarteck's Avatar
Sarteck Sarteck is offline
 
Join Date: Mar 2008
Posts: 304
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default CMS articles from multiple forums

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?
Reply With Quote
  #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
  #3  
Old 07-20-2012, 06:03 PM
Sarteck's Avatar
Sarteck Sarteck is offline
 
Join Date: Mar 2008
Posts: 304
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just wanted to bump this, see if anyone's got any input.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:42 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03489 seconds
  • Memory Usage 2,229KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_html
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete