Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:51 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06682 seconds
  • Memory Usage 2,978KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (16)bbcode_code
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (20)post_thanks_box
  • (2)post_thanks_box_bit
  • (20)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (20)post_thanks_postbit_info
  • (20)postbit
  • (2)postbit_attachment
  • (20)postbit_onlinestatus
  • (20)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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_threadedmode.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_attachment
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete