Author |
Message |
AndyB
Worker
![Worker Worker](modules/Forums/images/ranks/3stars.gif)
![](modules/Forums/images/avatars/50e5906d503900b86d7c3.jpg)
Joined: Jun 03, 2004
Posts: 231
Location: Torrevieja, Spain
|
Posted:
Wed Apr 11, 2012 12:53 pm |
|
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.....
Incidentally, I use a couple of variations of the above block- Amazon, Cafepress and somewhere else, if memory serves..... |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
AndyB
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Wed Apr 11, 2012 1:17 pm |
|
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)
Quote: | Look Ma!- I coded something! |
|
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Palbin
Site Admin
![](modules/Forums/images/avatars/Dilbert/Dilbert_-_Dogbert_King.gif)
Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania
|
Posted:
Wed Apr 11, 2012 3:46 pm |
|
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. |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
nuken
RavenNuke(tm) Development Team
![](modules/Forums/images/avatars/3234de284ee21bd39eecd.jpg)
Joined: Mar 11, 2007
Posts: 2024
Location: North Carolina
|
Posted:
Wed Apr 11, 2012 3:49 pm |
|
Those are not included blocks with the distro. |
_________________ Only registered users can see links on this board! Get registered or login! |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
hicuxunicorniobestbuildpc
The Mouse Is Extension Of Arm
![](modules/Forums/images/avatars/5ed231554a8492e2e09da.gif)
Joined: Aug 13, 2009
Posts: 1123
|
Posted:
Fri Apr 13, 2012 3:54 am |
|
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 |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
AndyB
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Fri Apr 13, 2012 8:40 am |
|
Would preg_match not be ok? It appears to be working on my test box....?
Thanks
Andy |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
montego
Site Admin
![](modules/Forums/images/avatars/0c0adf824792d6d341ef4.gif)
Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Fri Apr 13, 2012 10:26 am |
|
Correct AndyB. I don't believe you were trying to do a "replace", only a "search", therefore, I believe preg_match is fine. |
_________________ Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
nuken
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Fri Apr 13, 2012 12:33 pm |
|
You could also just use this:
Code:
if ( !defined('BLOCK_FILE') ) {
Header("Location: ../index.php");
die();
}
|
|
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
montego
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sat Apr 14, 2012 8:30 am |
|
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 Only registered users can see links on this board! Get registered or login!. However, make sure you test specifically for FALSE (see the note down the page some on the tertiary operator). |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
hicuxunicorniobestbuildpc
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Apr 15, 2012 3:18 am |
|
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
http://www.bitcetera.com/page_attachments/0000/0030/regex_in_a_nutshell.pdf |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
montego
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Mon Apr 16, 2012 8:52 pm |
|
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.
Nice summary. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
AndyB
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Tue Apr 17, 2012 3:32 pm |
|
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?) |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
montego
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Fri Apr 20, 2012 9:12 am |
|
AndyB, I would change the first one, the initial check of BLOCK_FILE, but then all your others are fine IMO. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
|