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

Reply
 
Thread Tools Display Modes
  #1  
Old 03-23-2011, 05:02 AM
zeroality zeroality is offline
 
Join Date: Jul 2006
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default creating a custom plugin for news on header but not working

I searched for a few terms but couldn't really find anything helpful. I've been trying for the past couple hours trying to get this to work. I'm trying to pull thread information from the latest one posted in our News forum and display bits of it in the HEADER template.

I've also tried putting the same code in FORUMHOME template in case it was something associated with the hook I chose but still does not work. I did something very similar to this on vBulletin 3.x (used the plugin code and called it via $news1_title, etc) but seems I'm missing something here.

Also would like to note that this is pretty much ripped straight from my external news script, which I posted here for viewing (since I'm not using it on the site atm): http://pokemontopaz.net/sandbox/

Plugin code (using forumhome_complete hook):
Code:
$postchars = 250;

 $news1 = $db->query_first('SELECT title,threadid,views,replycount,postusername,postuserid,dateline FROM ' . TABLE_PREFIX . 'thread WHERE 1 AND forumid = 4 ORDER BY dateline DESC  LIMIT 0 , 1');
 $news1_title = "<a href=\"forums/showthread.php?"  . $vbulletin->session->vars['sessionurl'] . "t=$news1[threadid]\">$news1[title]</a>";
 $news1_readmore = "<a href=\"forums/showthread.php?"  . $vbulletin->session->vars['sessionurl'] . "t=$news1[threadid]\">[Read More]</a>";
 $news1_comment = "<a href=\"forums/newreply.php?do=newreply&noquote=1&"  . $vbulletin->session->vars['sessionurl'] . "t=$news1[threadid]\">[Post Comment]</a>";
 $news1_replies = "$news1[replycount]";
 $news1_views = "$news1[views]";
 $news1_post = $db->query_first('SELECT pagetext FROM ' . TABLE_PREFIX . 'post WHERE 1 AND threadid = ' . $news1[threadid] . ' ORDER BY dateline ASC  LIMIT 0 , 1');
 $news1_postfull = "$news1_post[pagetext]";
 $news1_postshort = substr($news1_post[pagetext],0,$postchars);
 $news1_date = vbdate($vbulletin->options['dateformat'], $news1['dateline']);
 $news1_time = vbdate($vbulletin->options['timeformat'], $news1['dateline']);
 $news1_posturl = "<a href=\"forums/member.php?" . $news1[postuserid] . "\">" . $news1[postusername] . "</a>";
Code in header template:
Code:
  <div id="lugianewscontent">
    <h3>$news1_title by $news1_posturl on $news1_date</h3>
    <p>$news1_postshort... [$news1_readmore]</p>
    <p>Replies: $news1_replies - Views: $news1_views $news1_comment</p>
  </div>
Reply With Quote
  #2  
Old 03-24-2011, 05:57 AM
MoMan MoMan is offline
 
Join Date: Oct 2005
Location: USA
Posts: 301
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The problem is that the header has already been parsed by the time forumhome_complete is called. You'll want do so something like this in forumhome_complete:

PHP Code:

$text 
"<div id="lugianewscontent">
    <h3>
$news1_title by $news1_posturl on $news1_date</h3>
    <p>
$news1_postshort... [$news1_readmore]</p>
    <p>Replies: 
$news1_replies - Views: $news1_views $news1_comment</p>
  </div>"
;

$vbulletin->templatecache['header'] .= eval($text); 
Ideally, $text should be placed in a template so you can just call fetch_template.
Reply With Quote
  #3  
Old 03-25-2011, 12:14 AM
zeroality zeroality is offline
 
Join Date: Jul 2006
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Alright, I appreciate you getting me started. I also took a look at this guide and have made a little more progress.

I've hit a complete wall though and am unsure on how to proceed now.

I created a template as you suggested (auto_news). I have two plugins now.

One is using the cache_templates hook and has:
Code:
$cache[] = 'auto_news';
The other is still using forumhome_complete and is below:
Code:
$postchars = 250;

 $news1 = $db->query_first('SELECT title,threadid,views,replycount,postusername,postuserid,dateline FROM ' . TABLE_PREFIX . 'thread WHERE 1 AND forumid = 4 ORDER BY dateline DESC  LIMIT 0 , 1');
 $news1_title = "<a href=\"forums/showthread.php?"  . $vbulletin->session->vars['sessionurl'] . "t=$news1[threadid]\">$news1[title]</a>";
 $news1_readmore = "<a href=\"forums/showthread.php?"  . $vbulletin->session->vars['sessionurl'] . "t=$news1[threadid]\">[Read More]</a>";
 $news1_comment = "<a href=\"forums/newreply.php?do=newreply&noquote=1&"  . $vbulletin->session->vars['sessionurl'] . "t=$news1[threadid]\">[Post Comment]</a>";
 $news1_replies = "$news1[replycount]";
 $news1_views = "$news1[views]";
 $news1_post = $db->query_first('SELECT pagetext FROM ' . TABLE_PREFIX . 'post WHERE 1 AND threadid = ' . $news1[threadid] . ' ORDER BY dateline ASC  LIMIT 0 , 1');
 $news1_postfull = "$news1_post[pagetext]";
 $news1_postshort = substr($news1_post[pagetext],0,$postchars);
 $news1_date = vbdate($vbulletin->options['dateformat'], $news1['dateline']);
 $news1_time = vbdate($vbulletin->options['timeformat'], $news1['dateline']);
 $news1_posturl = "<a href=\"forums/member.php?" . $news1[postuserid] . "\">" . $news1[postusername] . "</a>";

 $vbulletin->templatecache['header'] .= eval(auto_news);
auto_news template has:
Code:
<h3>$news1_title by $news1_posturl on $news1_date</h3>
<p>$news1_postshort... [$news1_readmore]</p>
<p>Replies: $news1_replies - Views: $news1_views $news1_comment</p>

The div container is in the header template and I put {vb:raw auto_news} within the tags but it doesn't seem to be working.

What am I missing? I can't figure it out...
Reply With Quote
  #4  
Old 03-25-2011, 12:38 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

the syntax in your template is all wrong - see this https://vborg.vbsupport.ru/showthread.php?t=221560 .

The way you are rendering the template is wrong - see this https://vborg.vbsupport.ru/showthread.php?t=228078 (or just read the code in the vbulletin files).

What text are you ending up with using your current code? It would really help to know so we know where you are going wrong. When I have problems and need to troubleshoot, I totally simplify it all. Template code - <div> Hello! </div> - does it work? If not, you aren't getting the template called correctly. If it does work, put one variable in it - {vb:var testing} - and in the plugin put $testing = "Hello"; and see if that works. Just keep going at it that way to figure out where your problem is.
Reply With Quote
  #5  
Old 04-05-2011, 03:35 AM
zeroality zeroality is offline
 
Join Date: Jul 2006
Posts: 187
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry, I haven't had the time to get back to this but I'm trying again now.

I think I fixed my plugin code and my problem exists in calling the template. I've gone over the guide and I'm still unsure on how to call the template code to execute within the header template.

I took your suggestion and simplified it all.

testplugin code:
Code:
$test = "hello";

$templater = vB_Template::create('testplate');
$templater->register('test', $test);
$templater->render();

$vbulletin->templatecache['header'] .= eval('testplate');
I'm using eval(testplate) because I have it set on the forumhome_complete hook, as covered in a previous post.

testplate code:
Code:
<p>{vb:var test}</p>
header code portion:
Code:
  <div id="lugianewscontent">
    {vb:var testplate}
  </div>
What am I doing wrong? The guide is a bit confusing so I did my best to follow it.

The end result is nothing at all. The lugianews div is simply blank. No error, no text, nothing.
Reply With Quote
  #6  
Old 04-05-2011, 05:30 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't understand what you think this line does:
PHP Code:
$vbulletin->templatecache['header'] .= eval('testplate'); 
And you probably want to assign this to a variable:
PHP Code:
$templater->render(); 
PHP Code:
$myvar $templater->render(); 
and then preregister it for use in a template:
PHP Code:
vB_Template::preRegister('TEMPLATENAME', array('myvar' => $myvar)); 
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 02:00 PM.


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.14212 seconds
  • Memory Usage 2,231KB
  • Queries Executed 13 (?)
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
  • (8)bbcode_code
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)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_postinfo_query
  • fetch_postinfo
  • 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