View Full Version : Code help
solboy
01-09-2010, 08:25 PM
......
Lynne
01-09-2010, 08:52 PM
Is this code *you* wrote? And if not, do you have permission from the author to post it? If not, you may NOT post it here.
solboy
01-09-2010, 09:02 PM
Is this code *you* wrote? And if not, do you have permission from the author to post it? If not, you may NOT post it here.
I own this mod. I paid to have it created for vb. 3.8.
Look around and see if it's anywhere on this board or anywhere else unless I posted it. If you can assist then I would be very happy.
Lynne
01-09-2010, 09:08 PM
Most likely what you need to change are the templates and the syntax to render the templates. Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide (https://vborg.vbsupport.ru/showthread.php?t=228078)
solboy
01-09-2010, 09:13 PM
Most likely what you need to change are the templates and the syntax to render the templates. Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide (https://vborg.vbsupport.ru/showthread.php?t=228078)
Thanks. I know of this and I have tried. This is as far as I got:
<?xml version="1.0" encoding="ISO-8859-1"?>
<product productid="pblatestthreads" active="1">
<title>PB Latest Threads</title>
<description>Show the latest threads with transition effects.</description>
<version>1.0</version>
<url />
<versioncheckurl />
<dependencies>
</dependencies>
<codes>
</codes>
<templates>
<template name="pb_latestthreads_area" templatetype="template" date="1237182817" username="admin" version="1.0"><![CDATA[<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
<td class="tcat">Latest Threads</td>
</tr>
<tr>
<td class="alt1">
<div id='mid'>
<div id='slideshow'>
<div class="pbslide_container">
<div class="pbslide_inner" >
$pblatest_bigblocks
</div>
<div class="pbslide_bottombar">
$pblatest_smallblocks
</div>
</div><br/>
<script type="text/javascript">
var timeouts=new Array();
var curframe=1;
var start_frame=1;
var end_frame=$pblimit;
var oldframe=$pblimit;
var TimeToFade = 700;
var delay=5000;
pbstart_slideshow(delay);
</script>
</div>
</div>
</td>
</tr>
</table>
]]></template>
<template name="pb_latestthreads_bigblock" templatetype="template" date="1237182417" username="admin" version="1.0"><![CDATA[ <div class="pbslide_innerbox" $pbstyle id="pbslide$pbcount">
<div class="pbslide_innercontent" >
<a href="showthread.php?t=$pbthreadid">$pbthreadtitle</a><br/>
<span>by $pbthreadstarter - $pbthreaddate</span><br/>
$pbpagetext
</div>
</div>]]></template>
<template name="pb_latestthreads_smallblock" templatetype="template" date="1237420070" username="admin" version="1.0"><![CDATA[ <div class="pbslide_titles">
<img $pbimage id="pbslide_b$pbcount" style="border:0;padding:0px;margin:0px;" alt=""/>
<a href="showthread.php?goto=newpost&t=$pbthreadid" class="smallfont" title="$pbpagetext">$pbthreadtitle2</a>
- Last Post: $pblastposttime by $pblastposter >> Replies: $pbreplies >> Views: $pbviews
</div>]]></template>
</templates>
<plugins>
<plugin active="1" executionorder="5">
<title>pb_latestthreads_cache</title>
<hookname>cache_templates</hookname>
<phpcode><![CDATA[global $globaltemplates;
$globaltemplates = array_merge($globaltemplates, array('pb_latestthreads_bigblock','pb_latestthread s_smallblock','pb_latestthreads_area'));]]></phpcode>
</plugin>
<plugin active="1" executionorder="5">
<title>pb_latestthreads_global</title>
<hookname>global_setup_complete</hookname>
<phpcode><![CDATA[global $vbulletin;
$pbwhere=$vbulletin->options['pb_latest_whereto'];
if($pbwhere==0 or ($pbwhere==1 and THIS_SCRIPT=='index')or ($pbwhere==2 and THIS_SCRIPT=='forumdisplay') or ($pbwhere==3 and((THIS_SCRIPT=='index')or (THIS_SCRIPT=='forumdisplay')))){
$pbforumids=$forumids;
// forum permissions
$pbforumpermissions = array();
foreach($vbulletin->forumcache AS $pbforum)
{
$pbforumpermissions[$pbforum["forumid"]] = fetch_permissions($pbforum['forumid']);
if ((!($pbforumpermissions[$pbforum["forumid"]] & $vbulletin->bf_ugp_forumpermissions['canview'])) OR (!($pbforum['options'] & $vbulletin->bf_misc_forumoptions['active']) AND !$vbulletin->options['showprivateforums'] AND !in_array($vbulletin->userinfo['usergroupid'], array(5,6,7))))
{
$pbforumids .= ','.$pbforum['forumid'];
}
}
if ($vbulletin->options['pbslide_exclude']!='' and isset($vbulletin->options['pbslide_exclude']))
{
$pbforumids .= ','.$vbulletin->options['pbslide_exclude'];
}
$pbforumids = substr($pbforumids, 1);
if ($pbforumids!='')
{
$pblatest_and = "thread.forumid NOT IN($pbforumids)";
$pblatest_and_1 = "forum.forumid NOT IN($pbforumids)";
}
// converts options to nice variables
$pblimit = $vbulletin->options['pbslide_numthreads'];
// query to get the last posts
$pbquery = $vbulletin->db->query_read("
SELECT
thread.forumid as forumid, thread.visible, thread.title as thread_title, thread.threadid as threadid, thread.postusername as username, thread.postuserid as userid, thread.dateline as date, thread.lastposter as lastposter, thread.lastpost as lastpost, thread.replycount as replies, thread.views as views,
forum.title as forum_title,
post.postid, post.pagetext as pagetext
FROM " . TABLE_PREFIX . "post as post
LEFT JOIN " . TABLE_PREFIX . "thread as thread on (thread.firstpostid = post.postid)
LEFT JOIN " . TABLE_PREFIX . "forum as forum on (thread.forumid = forum.forumid)
WHERE thread.visible = 1 AND $pblatest_and AND $pblatest_and_1
ORDER BY thread.lastpost DESC
LIMIT $pblimit"
);
// reset variables
$pbcount = 0;
$pblatest_bigblocks = '';
$pblatest_smallblocks='';
while ($pbrow = $vbulletin->db->fetch_array($pbquery))
{
// allow to use alternate color in rows
// strips the bbcode out of the post
$pbrow['pagetext'] = strip_bbcode($pbrow['pagetext'], $stripquotes = true, $fast_and_dirty = false, $showlinks = true);
// adds the cutoff ... with substr
$pbrow['pagetext'] = substr($pbrow['pagetext'], 0, $vbulletin->options['pbslide_cutoff']) . '...';
$pbthreadtitle2 = substr($pbrow['thread_title'], 0, $vbulletin->options['pbslide_cutoff_titles']) . '...';
// convert pagetext to nice looking variable
$pbpagetext = $pbrow['pagetext'];
$pbthreadstarter = $pbrow['username'];
$pbuserid = $pbrow['userid'];
$pbforumid = $pbrow['forumid'];
$pbthreadid = $pbrow['threadid'];
$pbforumtitle = $pbrow['forum_title'];
$pbthreadtitle = $pbrow['thread_title'];
$pbthreaddate = vbdate($vbulletin->options['dateformat'], $pbrow['date'], true)." at ".vbdate($vbulletin->options['timeformat'], $pbrow['date']);
$pblastposttime = vbdate($vbulletin->options['dateformat'], $pbrow['lastpost'], true)." at ".vbdate($vbulletin->options['timeformat'], $pbrow['lastpost']);
$pblastposter=$pbrow['lastposter'];
$pbviews=$pbrow['views'];
$pbreplies=$pbrow['replies'];
// increments the counter +1
$show['latest_break'] = $pbcount++;
if($pbcount==1){
$pbstyle="";
$pbimage="src=\"images/button.png\"";
}
else{
$pbstyle="style=\"display:none;opacity:0;filter:alpha(opacity =0)\"";
$pbimage="src=\"images/button2.png\"";
}
//eval('$pblatest_bigblocks .= "' . fetch_template('pb_latestthreads_bigblock') . '";');
$templater->register('pb_latestthreads_bigblock', $pblatest_bigblocks);
$pblatest_bigblocks = $templater->render();
//eval('$pblatest_smallblocks .= "' . fetch_template('pb_latestthreads_smallblock') . '";');
templater->register('pb_latestthreads_smallblock', $pblatest_smallblocks);
$pblatest_smallblocks = $templater->render();
}
// free the query
$vbulletin->db->free_result($pbquery);
//eval('$PBLatestThreads = "' . fetch_template('pb_latestthreads_area') . '";');
$templater = vB_Template::create('mytemplate');
$templater->register('pb_latestthreads_area', $PBLatestThreads);
$PBLatestThreads = $templater->render();
}
else{
$PBLatestThreads ='';
}]]></phpcode>
</plugin>
</plugins>
<phrases>
<phrasetype name="vBulletin Settings" fieldname="vbsettings">
<phrase name="setting_pb_latest_whereto_desc" date="1239304462" username="admin" version="1.0"><![CDATA[Where do you want to display the latest threads.]]></phrase>
<phrase name="setting_pb_latest_whereto_title" date="1239304462" username="admin" version="1.0"><![CDATA[Where to show?]]></phrase>
<phrase name="setting_pbslide_cutoff_desc" date="1237179560" username="admin" version="1.0"><![CDATA[Number of characters before the pagetext gets off]]></phrase>
<phrase name="setting_pbslide_cutoff_title" date="1237179560" username="admin" version="1.0"><![CDATA[Post text cutoff]]></phrase>
<phrase name="setting_pbslide_cutoff_titles_desc" date="1237179573" username="admin" version="1.0"><![CDATA[The amount of characters displayed before thread titles are cutoff.]]></phrase>
<phrase name="setting_pbslide_cutoff_titles_title" date="1237179573" username="admin" version="1.0"><![CDATA[Title Cutoff]]></phrase>
<phrase name="setting_pbslide_exclude_desc" date="1237179585" username="admin" version="1.0"><![CDATA[Put the forum ID's of the forums you want to exclude seperated by commas]]></phrase>
<phrase name="setting_pbslide_exclude_title" date="1237179585" username="admin" version="1.0"><![CDATA[Exclude Forums]]></phrase>
<phrase name="setting_pbslide_numthreads_desc" date="1237183072" username="admin" version="1.0"><![CDATA[The number of threads to display.]]></phrase>
<phrase name="setting_pbslide_numthreads_title" date="1237183072" username="admin" version="1.0"><![CDATA[Number of Threads]]></phrase>
<phrase name="settinggroup_pbslide_latestthreads" date="1237175444" username="admin" version="1.0"><![CDATA[PB Latest Threads]]></phrase>
</phrasetype>
</phrases>
<options>
<settinggroup name="pbslide_latestthreads" displayorder="65535">
<setting varname="pbslide_exclude" displayorder="10">
<datatype>free</datatype>
<defaultvalue>1</defaultvalue>
</setting>
<setting varname="pbslide_cutoff" displayorder="20">
<datatype>number</datatype>
<defaultvalue>100</defaultvalue>
</setting>
<setting varname="pbslide_cutoff_titles" displayorder="30">
<datatype>number</datatype>
<defaultvalue>20</defaultvalue>
</setting>
<setting varname="pbslide_numthreads" displayorder="40">
<datatype>number</datatype>
<defaultvalue>5</defaultvalue>
</setting>
<setting varname="pb_latest_whereto" displayorder="50">
<datatype>free</datatype>
<optioncode>select:piped
0|Everywhere
1|ForumHome Only
2|ForumDisplay Only
3|ForumDisplay and ForumHome</optioncode>
</setting>
</settinggroup>
</options>
<helptopics>
</helptopics>
<cronentries>
</cronentries>
<faqentries>
</faqentries>
</product>
Maybe you can see what I did wrong or what I missed.
Lynne
01-09-2010, 09:25 PM
You also need to change the template syntax as noted in the article here:
In the template you know will be able to use the registered variables/arrays in this way:
{vb:raw my_var}
{vb:raw my_array.key1}
{vb:raw my_array.key2.key21}
solboy
01-09-2010, 09:32 PM
You also need to change the template syntax as noted in the article here:
Thanks allot. Forgive me for being a novice but I have no idea where those are to go in the code or what to change.
Lynne
01-09-2010, 09:44 PM
They are variables. So, instead of $my_variable, you would use {vb:raw my_variable}
solboy
01-09-2010, 09:48 PM
They are variables. So, instead of $my_variable, you would use {vb:raw my_variable}
Ok thanks. Let me see what I can do.
--------------- Added 1263084199 at 1263084199 ---------------
I tried all that I can. It's not working. can someone make the edits needed for me and post it here please?
--------------- Added 1263084258 at 1263084258 ---------------
You also need to change the template syntax as noted in the article here:
Thanks for your help but this looks like it's notworking for me. I just don't know how.
cellarius
01-10-2010, 05:41 AM
In the code given above, I see lots of variables used in the template that are not registered, like $pbstyle, $pbthreadid, $pbthreadtitle etc. Basically none of the variables you use in the template are registered. Please read the tutorial Lynne linked you to again, especially the part about "Save into a variable for later use in custom template".
For $threadid for example, you need to register the variable for your bigblock template and for your smallblock template:
$templater->register('pb_latestthreads_bigblock', $pblatest_bigblocks);
$templater->register('threadid', $threadid);
$pblatest_bigblocks .= $templater->render(); What I changed: Added the $templater->register line to register $threadid. Added the dot in the last line before the =, since this is in a while-loop and you don't want the result to be overwritten every time, but added. Note how you had that point in your old eval, too.
Now you can call $threadid in your template pb_latestthreads_bigblock by inserting {vb:raw threadid}.
To be able to call the variable you saved the template into ($pblatest_bigblock) in your pb_latestthreads_area template, you again need to register it:
Your code there:
$templater = vB_Template::create('mytemplate');
$templater->register('pb_latestthreads_area', $PBLatestThreads);
$PBLatestThreads = $templater->render(); This cannot work. Note how you did not insert the template name (it still reads mytemplate!) in first line. Then, in second line, you don't register an existing variable you want to use in the template, but try to register the variable you want to save the template into. This makes no sense: You don't want to call that template inside that very template. Here you would register the variable you saved the bigblocks template into, to be able to call it in the latestthreads area template. Furthermore, you need to decide where you want to call this last template, the area template. If you want to show the contents of your latestthreads_area template on forumhome, for example, you'd need to preregister it for that.
IT would look something like that:
$templater = vB_Template::create('pb_latestthreads_area'); // create the template
$templater->register('pblatest_bigblocks', $pblatest_bigblocks); // register $pblatest_bigblocks to be able to use {vb:raw pblatest_bigblocks} in template pb_latestthreads_area
$templatevalues['PBLatestThreads'] = $templater->render(); // rendering template into a variable suitable for preregistering for use in existing template
vB_Template::preRegister('FORUMHOME', $templatevalues); // preregister variable from line above to be able to use {vb:raw PBLatestThreads} on forumhomeI would like to advice you to first go with some simple hello world examples to learn the logic of registering templates. Your construction is quite complicated to start with. If you want to look at a code example, download my social groups on forum home mod - it uses basically the same construction.
Basically:
- bigblock template: register every variable you want to use inside this template, save into variable
- smallblock template: register every variable you want to use inside this template, save into variable
- area template: register every variable you want to use inside this template, including the variables you saved bigblock and smallblock templates into; save area template into variable, then preregister this variable for use in existing template
solboy
01-10-2010, 12:16 PM
Thanks cellarius for your reply. I think I may have to hire a programmer for this.
masterross
02-10-2010, 09:20 PM
Thx a lot Cellarius!
Just a little correction. Code should looks like this:
$templater = vB_Template::create('pb_latestthreads_area'); // create the template
$templater->register('pblatest_bigblocks', $pblatest_bigblocks); // register $pblatest_bigblocks to be able to use {vb:raw pblatest_bigblocks} in template pb_latestthreads_area
$templatevalues['pb_latestthreads_area'] = $templater->render(); // rendering template into a variable suitable for preregistering for use in existing template
vB_Template::preRegister('FORUMHOME', $templatevalues); // preregister variable from line above to be able to use {vb:raw pb_latestthreads_area} on forumhome
cellarius
02-11-2010, 05:17 AM
And what should be corrected in your version of the code? The only thing you changed is the name of the variable, which you lowercased and inserted some underscores. Of course, you can name your variables whatever you want within the limits given by php. But there is no rule, not even a convention in php to use only lowercase variable names and add underscores (http://www.tizag.com/phpT/variable.php), so why should using the camelcase variable names the original poster came up with be incorrect?
masterross
02-11-2010, 07:55 AM
The var in vB_Template::create and $templatevalues should be the same and without string ($)
cellarius
02-11-2010, 09:24 AM
You're correct with the $, that is indeed a typo I missed. Thanks for pointing this out. But the vars in the method call and the array do not have to be the same by any means. The first one is the name of the template that's being called, the second one the variable that can be accessed later on. It can make sense to name them the same, but that's not mandatory. In my code I was using the template names and variables the original poster was using. This was not my choice, but I stuck to it to make things not even more difficult.
Sarcoth
02-11-2010, 02:53 PM
Just a note to solboy. I initially had a problem understanding the new template rendering system. I spent time going over numerous mods and over cellarius' thread on the subject. I actually keep a handy print out of that thread which I still look over often. I now feel comfort in the "new way" and it is easy to learn via trial and error. If something isn't working, register another variable. Now, it looks so simple to me...except for a couple problems I'm still having. :)
masterross
02-17-2010, 06:15 PM
@ cellarius (https://vborg.vbsupport.ru/member.php?u=109187),
Can you help me with this?
https://vborg.vbsupport.ru/showthread.php?t=236031
I cant handle auto template editing :(
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.