Due to the possible exploits of the original code, it was easier to just write new code. I tried to keep things compatible with your existing code so that it would not be too difficult for you to modify.
I will post the main code here and your proprietary templates in a PM. Updating your HTML should be much easier now that this is using the vb3 conventions.
top10 -- Main template
top19bits -- Row data bits
Let me know when you get it running, I would like to see the finished product.
Code:
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('CSRF_PROTECTION', true);
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array('top10', 'top10bit');
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
// Configuration
define('TBWORLD_DIAG', true); // Cache Diagnostics - False for normal operation
$ftpurl = "ftp://***";
$cachefile = "top10.txt";
$cachetime = 86400;
$cachefunc = 'filemtime'; // 'filemtime' or 'fileatime'
$ftpmaxrecs = 90; // Maximum FTP records to process
$perpage = 10; // Records per-page
$cachetime = 10; // Cachetime in seconds
$vbulletin->input->clean_array_gpc('g', array(
'page' => TYPE_UINT,
));
$page = $vbulletin->GPC['page'];
//--------------------------------------------------------------------------------------------------------
// TBWORLD NOTERS::
// Some Unix filesystems can be mounted with atime updates disabled to increase the performance.
// Currently using "filemtime" as default, if caching is not working try "fileatime"
// See configuration "$cachefunc" above
//---------------------------------------------------------------------------------------------------------
if ((file_exists($cachefile)) && ((call_user_func($cachefunc, $cachefile) + $cachetime) > time()))
{
if (TBWORLD_DIAG===true) $out_diag="  --- Cached ---   ( " .htmlspecialchars_uni($cachefile)." ) accessed ... " . date("H:i:s", call_user_func($cachefunc, $cachefile));
$cache_data = json_decode(file_get_contents($cachefile));
}
else
{
if (TBWORLD_DIAG===true) $out_diag="  --- Cache Written ---   ( " .htmlspecialchars_uni($cachefile)." ) ... " .date("H:i:s");
$record = 0;
if (($fh = fopen($ftpurl,"r")) !== FALSE) {
// I would have prefered the variable name 'datarow' instead of 'data', but that is what you
// were currently using in your templates.
while (($data = fgetcsv($fh, 1000, ",")) !== FALSE)
{
$record++;
$nofields = count($data);
// 0 1x 2 3 4 5x 6 7 8x 9 10x 11x 12x 13x
// Umbra.PermaScore:Add('EloSidzej-PL-', '288124117', 51370, 22963, 1261, 481, 3444, 3, 462968, 89, '20140715', 19121, 9666, 6120);
$data[0] = str_replace("Umbra.PermaScore:Add('", " ", $data[0]);
$data[0] = rtrim($data[0], "'");
$data = array_map('trim', $data);
$data = array_map('htmlspecialchars_uni', $data);
$cache_data[] = $data; // datarow processed
if ($record >= $ftpmaxrecs) { break; }
}
fclose($fh);
}
//-----------------------------------------------------------------------------------
// If for some reason the cache cannot be written, then the routine
// falls back to a cacheless mode.
//-----------------------------------------------------------------------------------
file_put_contents($cachefile, json_encode($cache_data), LOCK_EX);
}
// Page Count
if (empty($record)) $record = count($cache_data);
$numpages = $record/$perpage;
// Page pointer bounds check
if( !preg_match("/^\d{1,2}$/", $page) || $page < 1 || $page > $numpages) {
$page=1;
}
//-----------------------------------------------
// Output Top10bits Template (data-bits) ----
//-----------------------------------------------
$page_data = array_slice($cache_data, ($page-1) * $perpage, $perpage); unset($cache_data);
foreach ($page_data as $key => $data) {
$record = $key + ($page * $perpage);
eval('$out_top10bit .= "' .fetch_template('top10bit'). '";');
}
unset($page_data, $data);
//---------------------------
// Output Pagination ----
//---------------------------
$server_self = ""; // Empty attribute method (Safer Method)
//$server_self = htmlspecialchars_uni($_SERVER['PHP_SELF']);
//$server_self = htmlspecialchars($_SERVER["PHP_SELF"], ENT_QUOTES, "utf-8");
$out_pagination ="";
if ( $page > 1 ) {
$out_pagination .= "<a href=\"{$server_self}?page=" . htmlspecialchars_uni($page-1) . "\"><< Previous</a> ";
}
for ( $i = 1; $i <= $numpages; $i++) {
if ($i != $page) {
$out_pagination .= "<a href=\"{$server_self}?page=" .$i. "\">" .$i. "</a> ";
} else {
$out_pagination .= $i . " ";
}
}
if ($page < $numpages) {
$out_pagination .= " <a href=\"{$server_self}?page=" . htmlspecialchars_uni($page+1) . "\">Next >></a>";
}
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('top10') . '");');