Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> RavenNuke(tm) v2.5x
Author Message
AndyB
Worker
Worker



Joined: Jun 03, 2004
Posts: 231
Location: Torrevieja, Spain

PostPosted: Wed Apr 11, 2012 12:53 pm Reply with quote

Ok;

I may have mentioned this in another post; I've put it here in case anyone else has the issue.

This is causing issues on some blocks; first up are blocks based on random images (in this case, Amazon) that then go off to the relevant site.

Original Code below: (I've removed a lot of the legal stuff in this instance for clarity- they exist in my blocks as and when required)
Code:
<?php


if (eregi("block-Amazon.php",$_SERVER['SCRIPT_NAME'])) {
    Header("Location: index.php");
    die();
}

$amazon_id = "TELLING";

mt_srand((double)microtime()*1000000);
$imgs = dir('images/amazon');
while ($file = $imgs->read()) {
    if (eregi("gif", $file) || eregi("jpg", $file)) {
   $imglist .= "$file ";
    }
}
closedir($imgs->handle);
$imglist = explode(" ", $imglist);
$a = sizeof($imglist)-2;
$random = mt_rand(0, $a);
$image = $imglist[$random];
$asin = explode(".", $image);
$content = "<br><center><a href=\"http://www.amazon.co.uk/exec/obidos/ASIN/$asin[0]/$amazon_id\" target=\"_blank\">";
$content .= "<img src=\"images/amazon/$image\" border=\"0\" alt=\"\"><br><br></center>";

?>


eregi is deprecated; a quick search of the interweb suggests it's been replaced with preg_match ......

Suggestions/ link to a tutorial? I did try messing / "tweaking" the code, but failed (so far)- if I manage to find a solution before a reply, I'll post it up..... Wink

Incidentally, I use a couple of variations of the above block- Amazon, Cafepress and somewhere else, if memory serves.....
 
View user's profile Send private message
AndyB







PostPosted: Wed Apr 11, 2012 1:17 pm Reply with quote

OK;

updated complete code that appears to work on my test site- you will need to change your own specifics, obviously. Complete code (excluding my amazon ID)
Code:
<?php


/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fbc@mandrakesoft.com)         */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

if (preg_match("/block-Amazon.php/",$_SERVER['SCRIPT_NAME'])) {
    Header("Location: ../../../index.php");
    die();
}

/***************************************************************/
/* To use this block you only need to download .jpg or .gif    */
/* images from amazon.com and copy them to the /images/amazon  */
/* directory, then edit the $amazon_id variable to fit your ID */
/* of the Associates program. If you don't change the ID, all  */
/* the comissions ($) will go to my account! You're adviced.   */
/* But if you want to help PHP-Nuke project, you can leave the */
/* $amazon_id variable intact.                                 */
/*                                                             */
/* You need to know that any image in the amazon's directory   */
/* has the same ASIN name as its filename given by Amazon. If  */
/* you don't know what this is, leave it as is or disable it.  */
/***************************************************************/

$amazon_id = "PUT_YOUR_AMAZON_ID_HERE";

mt_srand((double)microtime()*1000000);
$imgs = dir('images/amazon');
while ($file = $imgs->read()) {
    if (preg_match("/gif/", $file) || preg_match("/jpg/", $file)) {
   $imglist .= "$file ";
    }
}
closedir($imgs->handle);
$imglist = explode(" ", $imglist);
$a = sizeof($imglist)-2;
$random = mt_rand(0, $a);
$image = $imglist[$random];
$asin = explode(".", $image);
$content = "<br><center><a href=\"http://www.amazon.co.uk/exec/obidos/ASIN/$asin[0]/$amazon_id\" target=\"_blank\">";
$content .= "<img src=\"images/amazon/$image\" border=\"0\" alt=\"\"><br><br></center>";

?>


I hope it helps (I'll probably re-visit it at some point) Rolling Eyes Laughing Laughing

Quote:
Look Ma!- I coded something! Cool Laughing Laughing Laughing Laughing
 
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Wed Apr 11, 2012 3:46 pm Reply with quote

We mist these couple instances. They will be corrected in the next release. Thanks.

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
nuken
RavenNuke(tm) Development Team



Joined: Mar 11, 2007
Posts: 2024
Location: North Carolina

PostPosted: Wed Apr 11, 2012 3:49 pm Reply with quote

Those are not included blocks with the distro.

_________________
Tricked Out News 
View user's profile Send private message Send e-mail Visit poster's website
hicuxunicorniobestbuildpc
The Mouse Is Extension Of Arm



Joined: Aug 13, 2009
Posts: 1122

PostPosted: Fri Apr 13, 2012 3:54 am Reply with quote

I don't think your changes are correct.

This codes

Code:
if (eregi("block-Amazon.php",$_SERVER['SCRIPT_NAME'])) {

    Header("Location: index.php");
    die();
}


Replace with

Code:
if (preg_replace("/block-Amazon.php/i",$_SERVER['SCRIPT_NAME'])) {

    Header("Location: index.php");
    die();
}


This

Code:
if (eregi("gif", $file) || eregi("jpg", $file)) {

   $imglist .= "$file ";


Replace with

Code:
if (preg_replace("/gif/i", $file) || preg_replace("/jpg/i", $file)) {

   $imglist .= "$file ";


Info

str_ireplace() - Case-insensitive version of str_replace.
substr_replace() - Replace text within a portion of a string
preg_replace() - Perform a regular expression search and replace
strtr() - Translate characters or replace substrings
 
View user's profile Send private message
AndyB







PostPosted: Fri Apr 13, 2012 8:40 am Reply with quote

Would preg_match not be ok? It appears to be working on my test box....?

Thanks

Andy
 
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Fri Apr 13, 2012 10:26 am Reply with quote

Correct AndyB. I don't believe you were trying to do a "replace", only a "search", therefore, I believe preg_match is fine.

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
nuken







PostPosted: Fri Apr 13, 2012 12:33 pm Reply with quote

You could also just use this:

Code:


if ( !defined('BLOCK_FILE') ) {
    Header("Location: ../index.php");
    die();
}
 
montego







PostPosted: Sat Apr 14, 2012 8:30 am Reply with quote

Yes, that is the best approach for the first set of code at the top. I believe preg_match() still to be an acceptable choice on the other checks in the code.

Given the other checks are really straight-forward finding of a simple needle in a haystack, the best performing replacement on the other eregi's would be the PHP function stripos. However, make sure you test specifically for FALSE (see the note down the page some on the tertiary operator).
 
hicuxunicorniobestbuildpc







PostPosted: Sun Apr 15, 2012 3:18 am Reply with quote

Sorry guys, preg_match could be good too.

preg_filter — Perform a regular expression search and replace
preg_grep — Return array entries that match the pattern
preg_last_error — Returns the error code of the last PCRE regex execution
preg_match_all — Perform a global regular expression match
preg_match — Perform a regular expression match
preg_quote — Quote regular expression characters
preg_replace_callback — Perform a regular expression search and replace using a callback
preg_replace — Perform a regular expression search and replace
preg_split — Split string by a regular expression


Nice sheet with all regex
[ Only registered users can see links on this board! Get registered or login! ]
 
montego







PostPosted: Mon Apr 16, 2012 8:52 pm Reply with quote

It really depends on what needs to be done. preg_replace is used to find a "needle" within the "haystack" and replace it with a "thimble", but the original eregi functions were not of the replace type is all. Laughing

Nice summary.
 
AndyB







PostPosted: Tue Apr 17, 2012 3:32 pm Reply with quote

So. In short- is my code ok? It 's for an updated Amazon block- shows a random image from a (local) directory and when clicked, goes through to the product page on Amazon. (Likewise for a Cafepress one)- if any good, maybe worth adding to future releases giving an option for people to attempt to generate funding from their site? (Or is it the first one needs replacing, the others are ok?)
 
montego







PostPosted: Fri Apr 20, 2012 9:12 am Reply with quote

AndyB, I would change the first one, the initial check of BLOCK_FILE, but then all your others are fine IMO.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> RavenNuke(tm) v2.5x

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©