Quote:
Originally Posted by kh99
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.' ';
}
$output.='<br />';
}
// create previous link
$output.='<div class="cheatpagenation">';
if($page>1){
$output.='<a href="'.$_SERVER['PHP_SELF'].'?page='.
($page-1).'"><< Previous</a> ';
}
// create intermediate links
for($i=1;$i<=$numPages;$i++){
($i!=$page)?$output.='<a href="'.$_SERVER
['PHP_SELF'].'?page='.$i.'">'.$i.'</a> ':$output.=$i.' ';
}
// create next link
if($page<$numPages){
$output.=' <a href="'.$_SERVER['PHP_SELF'].'?page='.
($page+1).'">Next >></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