includes/functions.php
changeset 770 62fed244fa1c
parent 766 d6690840e331
child 798 ddfc1b554a08
equal deleted inserted replaced
769:1946d845bb25 770:62fed244fa1c
   715   foreach($arr2 as $k => $v)
   715   foreach($arr2 as $k => $v)
   716   {
   716   {
   717     $arr3[$k] = $v;
   717     $arr3[$k] = $v;
   718   }
   718   }
   719   return $arr3;
   719   return $arr3;
       
   720 }
       
   721 
       
   722 /**
       
   723  * Looks at all values in an array and casts them to integers if they are strings with digits. Recursive.
       
   724  * @param array Array to process
       
   725  * @return array
       
   726  */
       
   727 
       
   728 function integerize_array($arr)
       
   729 {
       
   730   if ( !is_array($arr) )
       
   731     return $arr;
       
   732   
       
   733   foreach ( $arr as &$val )
       
   734   {
       
   735     if ( is_string($val) && ctype_digit($val) && strlen($val) < 10 )
       
   736     {
       
   737       $val = intval($val);
       
   738     }
       
   739     else if ( is_array($val) )
       
   740     {
       
   741       $val = integerize_array($val);
       
   742     }
       
   743   }
       
   744   return $arr;
   720 }
   745 }
   721 
   746 
   722 // Convert IP address to hex string
   747 // Convert IP address to hex string
   723 // Input:  127.0.0.1  (string)
   748 // Input:  127.0.0.1  (string)
   724 // Output: 0x7f000001 (string)
   749 // Output: 0x7f000001 (string)
  2874   global $db, $session, $paths, $template, $plugins; // Common objects
  2899   global $db, $session, $paths, $template, $plugins; // Common objects
  2875   // First, replace spaces with underscores
  2900   // First, replace spaces with underscores
  2876   $page_id = str_replace(' ', '_', $page_id);
  2901   $page_id = str_replace(' ', '_', $page_id);
  2877 
  2902 
  2878   // Exception for userpages for IP addresses
  2903   // Exception for userpages for IP addresses
  2879   if ( is_valid_ip($page_id) )
  2904   $pid_ip_check = ( is_object($paths) ) ? preg_replace('+^' . preg_quote($paths->nslist['User']) . '+', '', $page_id) : $page_id;
       
  2905   if ( is_valid_ip($pid_ip_check) )
  2880   {
  2906   {
  2881     return $page_id;
  2907     return $page_id;
  2882   }
  2908   }
  2883 
  2909 
  2884   preg_match_all('/\.[A-Fa-f0-9][A-Fa-f0-9]/', $page_id, $matches);
  2910   preg_match_all('/\.[A-Fa-f0-9][A-Fa-f0-9]/', $page_id, $matches);