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

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

OK thanks for the help...

The plugin to allow PHP is called 'Product : Let PHP Live!' and looks like this:
Code:
if (!function_exists('let_php_live')) {
  function let_php_live($matches) {
	  $starter = $matches[1] ;
		$code = str_replace(array('\'', '\"'), array('\\\'', '"'), $matches[2]) ;
	
		return $starter == '<?=' ? "\".eval('return $code;').\"" : "\".eval('ob_start();$code;return ob_get_clean();').\"" ;
	}
}

$template = preg_replace_callback('/(<\?=|<\?php|<\?)(.*)\?>/Us', 'let_php_live', $template);
Seems to work OK or did...
The template I'm using is a custom one, see below:
Code:
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>$vboptions[bbtitle]</title>
$headinclude
</head>
<body>
$header

$navbar

<table cellpadding="2" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<td width="100%"><img style="float:left" src="images/7ox10header.gif" border="0" /></td>
</table><br />
<div class="rounded-corners-forum">
<?
$cacheFile = 'top10.txt';

if ( (file_exists($cacheFile)) && ((fileatime($cacheFile) + 86400) > time()) )
{
    $content = file_get_contents($cacheFile);
} else
{
    ob_start();
    // write top10.txt file
    
$record = 1;
if (($handle = fopen("ftp://***", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
echo "<div class=\"cheatpagenation\"> </div><br /><div class=\"top10list\"><font color=grey>#0".$record." : </font><font color=white>".str_replace ("Umbra.PermaScore:Add(", " ", $data[0])."</font>_<font color=grey>KILLS-( <font color=CadetBlue>{$data[2]}</font><font color=grey> )_DEATHS-( <font color=FireBrick>{$data[3]}</font> <font color=grey>)_SUICIDES-( <font color=FireBrick>{$data[6]}</font> <font color=grey>)_HEADSHOTS-( <font color=CadetBlue>{$data[4]}</font> <font color=grey>)_DUELWINS-( <font color=Tomato>{$data[7]}</font> <font color=grey>)_LEVEL-( <font color=GoldenRod>{$data[9]}</font> <font color=grey>)</font></div>\n";
        $record++;
        if ($record > 100) { break; }
    }
    fclose($handle);
    }

    $content = ob_get_contents();
    ob_end_clean();
    file_put_contents($cacheFile,$content);
}

//    require_once('top10pagenation.php');
    $safe_functions[] = 'paginateRecords';
    $page=$_GET['page'];
    echo paginateRecords('top10.txt',$page);
    echo "<div class=\"cheatfooter\">TOP 100 UPDATED AUTOMATICALLY EVERY DAY</div>";
?>

</div><br />
<table cellpadding="2" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<td width="100%" align="left"><img src="images/top10.png" border="0" /></td>

<tr>
	<td class="shameheader"><font face="customfont4">&nbsp;&nbsp;? 7OX-10 PLAYERS - ( TOP 100 LISTED )</font></td>

</tr>

</table>

$footer
</body>
</html>

On my forum I just link to my php file which calls up my template:
Code:
<?php

error_reporting(E_ALL & ~E_NOTICE);

define('NO_REGISTER_GLOBALS', 1);

define('THIS_SCRIPT', 'top10');

$phrasegroups = array();

$specialtemplates = array();

$globaltemplates = array('top10',);

$actiontemplates = array();

require('global.php');

eval('$navbar = "' . fetch_template('navbar') . '";');

eval('print_output("' . fetch_template('top10') . '");');

?>
I've got that plugin with the custom-functions I want installed and there's no errors there, but my php top10 page is pure white at the moment, nothing shown... so dunno what to try next actually, but thanks for the help thus far.

--------------- Added [DATE]1406390365[/DATE] at [TIME]1406390365[/TIME] ---------------

Adding the hooks etc seems to work... just blank output

Code:
//    require_once('top10pagenation.php');
//    $page=$_GET['page'];
//  echo paginateRecords('top10.txt',$page);
That function when included from that file seemed relative to that $page variable on the next line down and so the echo was easy, but because the now safe function is running all the time for some reason the $page line isn't relative to that function anymore... and so balks and echos nothing... not sure.
Reply With Quote
  #12  
Old 07-26-2014, 05:25 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

* Removed *
Reply With Quote
  #13  
Old 07-26-2014, 09:05 PM
b6gm6n's Avatar
b6gm6n b6gm6n is offline
 
Join Date: Aug 2002
Location: UK
Posts: 691
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Lovely... would you believe I was going along similar lines...

Anyway, if you could clear a few things up... I've followed everything here and it's very clear, getting a good understanding, I have one more template/php-file to do like this and I'll apply your enlightening way to that also...

Right, well it's working, kinda... I can see what's happening, top10.php seems fine, template is fine, when called I see my forum header, the outout header and graphic and the footer graphic and then the forum footer itself, but nothing inbetween...

What I'm doing as you would of guessed is reading a file from ftp, putting a 100 lines of it into a text file/flat-file and then trying to read it out nicely... seems like the fault of the 'top10.txt' which checking now is zero bytes, so it's making the file, putting nothing into it and then reading nothing out, so it's either my ftp url which I'm sure is right or line 94 of the top10.php which is:

Code:
$ftpurl = "./top10records.txt";
Before it was actually connecting via ftp and making the file for reading, so that line above would that need the full ftp url? I'm reading a text file (well a lua file) the ftpurl line is similar to this:

Code:
$ftpurl     = "ftp://username:password@88.88.88.88/Data_PermaScore.lua";            // Your FTP uri
almost there old boy... but yeah I did think of putting everything into my php file and using a string to output it all, but you have done a much nicer job and I'll follow this way in future, thanks ever so for helping me.
Reply With Quote
  #14  
Old 07-26-2014, 11:08 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Remove that line it is a typo. That was for my local test data. I will remove it from the message above, sorry.

Most of your html code could have easily been placed into the template. Which would have made it easier to code, once you get the hang of things.
Reply With Quote
  #15  
Old 07-26-2014, 11:18 PM
b6gm6n's Avatar
b6gm6n b6gm6n is offline
 
Join Date: Aug 2002
Location: UK
Posts: 691
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, Done...

I'm still trying to work out why it's creating a zero-byte 'top10.txt' file and putting nothing into it for reading... hmmm so I'm getting an output of zilch, Can't see anything obvious...

EDIT, ahh right, removed the top10.txt and it worked, showing records... but all of them

Up to 95 records before it breaks... no pagenation

Example shown:
Code:
#0 1 : 'kkk-'_KILLS-( 51370)_DEATHS-( 22963)_SUICIDES-( 3444)_HEADSHOTS-( 1261)_DUELWINS-( 3)_LEVEL-( 89)
I was using the underscore _ to split the data
Reply With Quote
  #16  
Old 07-26-2014, 11:24 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you can attach a copy of the data file and your CSS then I can check it out further. Just capture the raw CSV, not the cache file.
Reply With Quote
  #17  
Old 07-26-2014, 11:32 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

See the attachment for my test output. This was before I posted the code here.
Attached Images
File Type: jpg Capture.JPG (62.8 KB, 0 views)
Reply With Quote
  #18  
Old 07-27-2014, 12:00 AM
b6gm6n's Avatar
b6gm6n b6gm6n is offline
 
Join Date: Aug 2002
Location: UK
Posts: 691
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by tbworld View Post
See the attachment for my test output. This was before I posted the code here.

OK, well I changed the line:
Code:
if ($record > 50)
Just to see what happens and it shows the pagination now, but see the screeny

On page one, at the bottom the first two records are repeated after the fifty shown, then if you press next which works, page two shows again all records and the next two at the bottom are record 3 and 4 and so it go's on hopefully we're getting there, thanks ever so for this help.
Attached Images
File Type: jpg Dwm-2014-07-27-01-56-09-36.jpg (146.1 KB, 0 views)
Reply With Quote
  #19  
Old 07-27-2014, 01:03 AM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The problem I think is in $numrecs. I changed the variable only at posting time for consistency. It should be $numRecs. So you might want to change all $numrecs to $numRecs. There should be two.

I will get a chance to take a look at this, later this evening.
Reply With Quote
  #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
Reply


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 11:10 PM.


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.08144 seconds
  • Memory Usage 2,311KB
  • Queries Executed 12 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (9)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (2)postbit_attachment
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (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_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • 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
  • 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
  • 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
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete