View Single Post
  #20  
Old 07-27-2014, 08:17 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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="&nbsp --- Cached --- &nbsp ( " .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="&nbsp --- Cache Written --- &nbsp ( " .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) . "\">&lt;&lt; Previous</a>&nbsp;";            
    }
    for ( $i = 1;  $i <= $numpages; $i++) {
        if ($i != $page) {
            $out_pagination .= "<a href=\"{$server_self}?page=" .$i. "\">" .$i. "</a>&nbsp;";
        } else {
            $out_pagination .= $i . "&nbsp;";
        }
    }
    if ($page < $numpages) {
            $out_pagination .= "&nbsp; <a href=\"{$server_self}?page=" . htmlspecialchars_uni($page+1) . "\">Next &gt;&gt;</a>";            
    }

     
   $navbits = construct_navbits($navbits);
   eval('$navbar      = "' . fetch_template('navbar') . '";');
   eval('print_output("'  . fetch_template('top10')  . '");');
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01290 seconds
  • Memory Usage 1,799KB
  • 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
  • (1)bbcode_code
  • (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