View Single Post
  #9  
Old 07-25-2014, 11:12 PM
b6gm6n's Avatar
b6gm6n b6gm6n is offline
 
Join Date: Aug 2002
Location: UK
Posts: 691
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
Other than using variables to build the output html, in general you cannot put php in a template. The exception is in a conditon (i.e <if condition="....), and then you can only put what would go in a php 'if' statement, and you can only use the "safe" functions.

But I don't think that's what you want. It looks to me like you are trying to call your custom function to do some formatting, in which case you would want to use a plugin. Your code would then create one or more variables and you'd use them in a template.

So, which hook location should you use? It depends on what you're trying to do. Hooks are just places in the vbulletin scripts where addon code can be called, so you need to find one in a location that's allows you to do what you want to do.
Got ya... might need a little help, I'm getting there, I've created a plugin with that function, see below:

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<plugins>
	<plugin active="1" executionorder="9" product="vbulletin">
		<title>paginateRecords</title>
		<hookname>template_safe_functions</hookname>
		<phpcode><![CDATA[function paginateRecords($dataFile,$page,$numRecs=10){



    $output='';



    // validate data file



    (file_exists($dataFile))?$data=(file

    ($dataFile)):die('Data file not valid.');



    // validate number of records per page



    (is_int($numRecs)&&$numRecs>0)?$numRecs=$numRecs:die

    ('Invalid number of records '.$numRecs);



    // calculate total of records



    $numPages=ceil(count($data)/$numRecs);



    // validate page pointer



    if(!preg_match("/^\d{1,2}$/",$page)

    ||$page<1||$page>$numPages){



    $page=1;



    }



    // retrieve records from flat file



    $data=array_slice($data,($page-1)*$numRecs,$numRecs);



    // append records to output



    foreach($data as $row){



    $columns=explode('_',$row);



    foreach($columns as $column){



    $output.=$column.'&nbsp;';



    }



    $output.='<br />';



    }



    // create previous link

    $output.='<div class="cheatpagenation">';

    if($page>1){

    $output.='<a href="'.$_SERVER['PHP_SELF'].'?page='.

    ($page-1).'">&lt;&lt; Previous</a>&nbsp;';



    }



    // create intermediate links



    for($i=1;$i<=$numPages;$i++){



    ($i!=$page)?$output.='<a href="'.$_SERVER

    ['PHP_SELF'].'?page='.$i.'">'.$i.'</a>&nbsp;':$output.=$i.'&nbsp;';



    }



    // create next link



    if($page<$numPages){



    $output.='&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?page='.

    ($page+1).'">Next &gt;&gt;</a></div>';

    }



    // return final output



    return $output;



    }]]></phpcode>
	</plugin>
</plugins>
no errors, in my template which I can save now shows nothing on the page itself, just a white screen...

My template (incidentally I have php plugin which allows me to use php in templates, so for the 'echo' statement I'm hoping is all ok)

Code:
//    require_once('top10pagenation.php');
    $page=$_GET['page'];
    echo paginateRecords('top10.txt',$page);
So I'm getting there, do I need to call the hook/function in a different way within my custom template? please advise, thank you
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01063 seconds
  • Memory Usage 1,780KB
  • 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_code
  • (1)bbcode_quote
  • (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