Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.3 RN Issues
Author Message
meotoo
Hangin' Around



Joined: Aug 04, 2009
Posts: 36

PostPosted: Wed Aug 19, 2009 1:25 pm Reply with quote

Hello all,

First of all, i was not sure about where to post this my-two-cents post about certain fixes i did to my php-nuke install, but i think thats the right place, sorry if it is not, and yes... i said php-nuke but i think the same fixes can be applyed to RN, also i dunno exactly where i should report php-nuke issues todays...

Well, my first fix is to the file includes/counter.php (i guess i do not need to explain it Wink:

Code:


if(strpos( $_SERVER["HTTP_USER_AGENT"],"Firefox") !== false) $browser = "FireFox";
elseif(strpos( $_SERVER["HTTP_USER_AGENT"],"MSIE") !== false) $browser = "MSIE";
elseif(strpos( $_SERVER["HTTP_USER_AGENT"],"Lynx") !== false) $browser = "Lynx";
elseif(strpos( $_SERVER["HTTP_USER_AGENT"],"Opera") !== false) $browser = "Opera";
elseif(strpos( $_SERVER["HTTP_USER_AGENT"],"WebTV") !== false) $browser = "WebTV";
elseif(strpos( $_SERVER["HTTP_USER_AGENT"],"Konqueror") !== false) $browser = "Konqueror";
elseif(strpos( $_SERVER['HTTP_USER_AGENT'],'Chrome') !== false) $browser = 'Chrome';
elseif(strpos( $_SERVER['HTTP_USER_AGENT'],'Safari') !== false) $browser = 'Safari';
elseif(preg_match('!bot|Google|Slurp|Scooter|Spider|Infoseek|craw|larbin|alexa|ask!i', $_SERVER['HTTP_USER_AGENT'])) $browser = "Bot";
elseif(preg_match('!Nav|Gold|X11|Mozilla|Netscape!', $_SERVER['HTTP_USER_AGENT'])) $browser = "Netscape";
else $browser = "Other";

/* Get the Operating System data */

if(strpos( $_SERVER["HTTP_USER_AGENT"],"Win") !== false) $os = "Windows";
elseif(strpos( $_SERVER["HTTP_USER_AGENT"],"Linux") !== false) $os = "Linux";
elseif((strpos( $_SERVER["HTTP_USER_AGENT"],"Mac") !== false) || (strpos( $_SERVER["HTTP_USER_AGENT"],"PPC") !== false)) $os = "Mac";
elseif(strpos( $_SERVER["HTTP_USER_AGENT"],"FreeBSD") !== false) $os = "FreeBSD";
elseif(strpos( $_SERVER["HTTP_USER_AGENT"],"SunOS") !== false) $os = "SunOS";
elseif(strpos( $_SERVER["HTTP_USER_AGENT"],"IRIX") !== false) $os = "IRIX";
elseif(strpos( $_SERVER["HTTP_USER_AGENT"],"BeOS") !== false) $os = "BeOS";
elseif(strpos( $_SERVER["HTTP_USER_AGENT"],"OS/2") !== false) $os = "OS/2";
elseif(strpos( $_SERVER["HTTP_USER_AGENT"],"AIX") !== false) $os = "AIX";
else $os = "Other";


I benchmark'ed it and it's 20% faster, also i think ereg() usage should be replaced everywhere..


Next fix is to the stripos_clone() function which is broken while running under PHP5, OPEN mainfile.php and FIND:

Code:
$return = stripos($haystack, $needle, $offset=0);


And, replace it with:

Code:
$return = stripos($haystack, $needle, $offset);


I also think adding a plain stripos() function while running under PHP4 would be a good idea, but we'll assume almost nobody is using that version nowadays...


I'm using the php-nuke 8.1 distro from NukeScripts(tm), and noticed (after some headaches) $display_errors variable is used in the wrong place, causing php errors not showing even when enabled from the admin's preferences, i just had to move the following piece of code...

Code:


// Error reporting, to be set in config.php
error_reporting(E_ALL^E_NOTICE);
if($display_errors AND is_admin($admin)) {
  @ini_set('display_errors', 1);
} else {
  @ini_set('display_errors', 0);
}


...to be just before:

Code:
if (!defined('FORUM_ADMIN')) {


because it was before the sql query to obtain the nuke config, where $display_errors was not set yet. and as you have noticed, i've added is_admin() usage so that only admins can see errors.

Well, my 2cents for now, if you find it useful let me know it and i'll post more Wink

Gretz.
 
View user's profile Send private message Visit poster's website
Palbin
Site Admin



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

PostPosted: Wed Aug 19, 2009 4:34 pm Reply with quote

Thanks for taking the time to offer your insight. We are aware of the deprecation of ereg() and have an open issue to replace all instances of it. This will probably not be complete for the 2.4 release, but this shouldn't be a problem for any user unless they are using PHP 6.

Issues 2 & 3 are not found in RN, but are good advice Wink

_________________
"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
meotoo







PostPosted: Wed Aug 19, 2009 5:21 pm Reply with quote

Palbin wrote:
Thanks for taking the time to offer your insight. We are aware of the deprecation of ereg() and have an open issue to replace all instances of it. This will probably not be complete for the 2.4 release, but this shouldn't be a problem for any user unless they are using PHP 6.


just did this right now on a quick&dirty way.. it should be easy than replacing each occurence Smile

Code:


if($phpver >= '6.0')
{
   if(!function_exists('ereg'))
   {
      function ereg_stub( $pattern, $string, &$regs=null, $case=true )
      {
         $rc = preg_match('#'.str_replace('#','\\#',$pattern).'#'.($case ? '':'i'),$string,$mt);
         
         if( $rc != 0 )
         {
            if(!is_null($regs))
            {
               $regs = $mt;
            }
            else
            {
               unset($mt);
            }
            
            return true;
         }
         
         return false;
      }
      
      function ereg( $pattern, $string, &$regs=null )
      {
         return ereg_stub( $pattern, $string, $regs );
      }
      function eregi( $pattern, $string, &$regs=null )
      {
         return ereg_stub( $pattern, $string, $regs, true );
      }
   }
}


Palbin wrote:

Issues 2 & 3 are not found in RN, but are good advice Wink


The following code comes from RN 2.30.02, the issue 2 is there Wink

Code:


// We want to use the function stripos,
// but thats only available since PHP5.
// So we cloned the function...
if(!function_exists('stripos')) {
    function stripos_clone($haystack, $needle, $offset=0) {
        $return = @strpos(strtoupper($haystack), strtoupper($needle), $offset);
        if ($return === false) {
            return false;
        } else {
            return true;
        }
    }
} else {
// But when this is PHP5, we use the original function
    function stripos_clone($haystack, $needle, $offset=0) {
        $return = stripos($haystack, $needle, $offset=0); // <------ HERE ****
        if ($return === false) {
            return false;
        } else {
            return true;
        }
    }
}
 
Palbin







PostPosted: Wed Aug 19, 2009 7:12 pm Reply with quote

meotoo wrote:

The following code comes from RN 2.30.02, the issue 2 is there Wink

Code:


// We want to use the function stripos,
// but thats only available since PHP5.
// So we cloned the function...
if(!function_exists('stripos')) {
    function stripos_clone($haystack, $needle, $offset=0) {
        $return = @strpos(strtoupper($haystack), strtoupper($needle), $offset);
        if ($return === false) {
            return false;
        } else {
            return true;
        }
    }
} else {
// But when this is PHP5, we use the original function
    function stripos_clone($haystack, $needle, $offset=0) {
        $return = stripos($haystack, $needle, $offset=0); // <------ HERE ****
        if ($return === false) {
            return false;
        } else {
            return true;
        }
    }
}


I don't see why that wouldn't work.
 
meotoo







PostPosted: Sun Aug 23, 2009 8:09 am Reply with quote

Palbin wrote:
I don't see why that wouldn't work.


Shocked

run the following code and you'll notice:

function lol($value) { echo $value=0; }
lol('666');


It should obviously output "666" but it will wrongly output "0"
 
Palbin







PostPosted: Sun Aug 23, 2009 10:56 am Reply with quote

I think i see what you are saying now. You can't specify a "custom offset" in php 5 because you will always get 0.

It works kind of you just can't find multiple occurrences Wink

I have made an issue in our bug tracking script for the team to look at.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> v2.3 RN Issues

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 ©