Changeset 12325

Show
Ignore:
Timestamp:
07/27/11 02:51:38 (2 years ago)
Author:
mbrevda
Message:

remove unused code, add pretty json function

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/trunk/amp_conf/htdocs/admin/libraries/php-upgrade/upgrade.php

    r10286 r12325  
    21522152} 
    21532153 
    2154  
    2155  
    2156  
    2157  
    2158 /** 
    2159  *                                   ------------------------------ 4.4 --- 
    2160  * @group 4_4 
    2161  * @since 4.4 
    2162  * 
    2163  * PHP 4.4 is a bugfix and backporting version created after PHP 5. It went 
    2164  * mostly unchanged, but changes a few language semantics (e.g. references). 
    2165  * 
    2166  * @emulated 
    2167  *    PHP_INT_SIZE 
    2168  *    PHP_INT_MAX 
    2169  *    SORT_LOCALE_STRING 
    2170  * 
    2171  */ 
    2172  
    2173 if (!defined("PHP_INT_SIZE")) { define("PHP_INT_SIZE", 4); } 
    2174 if (!defined("PHP_INT_MAX")) { define("PHP_INT_MAX", 2147483647); } 
    2175 if (!defined("SORT_LOCALE_STRING")) { define("SORT_LOCALE_STRING", 5); } 
    2176  
    2177  
    2178  
    2179  
    2180  
    2181  
    2182 /** 
    2183  *                                   ------------------------------ 4.3 --- 
    2184  * @group 4_3 
    2185  * @since 4.3 
    2186  * 
    2187  *  Additions in 4.3 version of PHP interpreter. 
    2188  * 
    2189  * @emulated 
    2190  *    file_get_contents 
    2191  *    array_key_exists 
    2192  *    array_intersect_assoc 
    2193  *    array_diff_assoc 
    2194  *    html_entity_decode 
    2195  *    str_word_count 
    2196  *    str_shuffle 
    2197  *    get_include_path 
    2198  *    set_include_path 
    2199  *    restore_include_path 
    2200  *    fnmatch 
    2201  *    FNM_PATHNAME 
    2202  *    FNM_NOESCAPE 
    2203  *    FNM_PERIOD 
    2204  *    FNM_LEADING_DIR 
    2205  *    FNM_CASEFOLD 
    2206  *    FNM_EXTMATCH 
    2207  *    glob 
    2208  *    GLOB_MARK 
    2209  *    GLOB_NOSORT 
    2210  *    GLOB_NOCHECK 
    2211  *    GLOB_NOESCAPE 
    2212  *    GLOB_BRACE 
    2213  *    GLOB_ONLYDIR 
    2214  *    GLOB_NOCASE 
    2215  *    GLOB_DOTS 
    2216  *    __FUNCTION__ 
    2217  *    PATH_SEPARATOR 
    2218  *    PHP_SHLIB_SUFFIX 
    2219  *    PHP_SAPI 
    2220  *    PHP_PREFIX 
    2221  * 
    2222  * @missing 
    2223  *    sha1_file 
    2224  *    sha1 - too much code, and has been reimplemented elsewhere 
    2225  * 
    2226  * @unimplementable 
    2227  *    money_format 
    2228  * 
    2229  */ 
    2230  
    2231  
    2232 /** 
    2233  * simplified file read-at-once function 
    2234  * 
    2235  * @param  string  $filename   
    2236  * @param  integer $use_include_path  (optional) 
    2237  * @return string 
    2238  */ 
    2239 if (!function_exists("file_get_contents")) { 
    2240    function file_get_contents($filename, $use_include_path=1) { 
    2241  
    2242       #-- open file, let fopen() report error 
    2243       $f = fopen($filename, "rb", $use_include_path); 
    2244       if (!$f) { return; } 
    2245  
    2246       #-- read max 2MB 
    2247       $content = fread($f, 1<<21); 
    2248       fclose($f); 
    2249       return($content); 
    2250    } 
    2251 } 
    2252  
    2253  
    2254  
    2255 /** 
    2256  * shell-like filename matching (* and ? globbing characters) 
    2257  * 
    2258  * @param  string $pattern  glob-pattern with *s and ?s 
    2259  * @param  string $fn       filename to match it against (without path) 
    2260  * @param integer $flags    (optional) 
    2261  * @return bool 
    2262  */ 
    2263 if (!function_exists("fnmatch")) { 
    2264  
    2265    #-- associated constants 
    2266    if (!defined("FNM_PATHNAME")) { define("FNM_PATHNAME", 1<<0); }  // no wildcard ever matches a "/" 
    2267    if (!defined("FNM_NOESCAPE")) { define("FNM_NOESCAPE", 1<<1); }  // backslash can't escape meta chars 
    2268    if (!defined("FNM_PERIOD")) { define("FNM_PERIOD",   1<<2); }  // leading dot must be given explicit 
    2269    if (!defined("FNM_LEADING_DIR")) { define("FNM_LEADING_DIR", 1<<3); }  // not in PHP 
    2270    if (!defined("FNM_CASEFOLD")) { define("FNM_CASEFOLD", 0x50); }  // match case-insensitive 
    2271    if (!defined("FNM_EXTMATCH")) { define("FNM_EXTMATCH", 1<<5); }  // not in PHP 
    2272     
    2273    #-- implementation 
    2274    function fnmatch($pattern, $fn, $flags=0x0000) { 
    2275        
    2276       #-- 'hidden' files 
    2277       if ($flags & FNM_PERIOD) { 
    2278          if (($fn[0] == ".") && ($pattern[0] != ".")) { 
    2279             return(false);    // abort early 
    2280          } 
    2281       } 
    2282  
    2283       #-- case-insensitivity 
    2284       $rxci = ""; 
    2285       if ($flags & FNM_CASEFOLD) { 
    2286          $rxci = "i"; 
    2287       } 
    2288       #-- handline of pathname separators (/) 
    2289       $wild = "."; 
    2290       if ($flags & FNM_PATHNAME) { 
    2291          $wild = "[^/".DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR."]"; 
    2292       } 
    2293  
    2294       #-- check for cached regular expressions 
    2295       static $cmp = array(); 
    2296       if (isset($cmp["$pattern+$flags"])) { 
    2297          $rx = $cmp["$pattern+$flags"]; 
    2298       } 
    2299  
    2300       #-- convert filename globs into regex 
    2301       else { 
    2302          $rx = preg_quote($pattern); 
    2303          $rx = strtr($rx, array( 
    2304             "\\*"=>"$wild*?", "\\?"=>"$wild", "\\["=>"[", "\\]"=>"]", 
    2305          )); 
    2306          $rx = "{^" . $rx . "$}" . $rxci; 
    2307           
    2308          #-- cache 
    2309          if (count($cmp) >= 50) { 
    2310             $cmp = array();   // free 
    2311          } 
    2312          $cmp["$pattern+$flags"] = $rx; 
    2313       } 
    2314        
    2315       #-- compare 
    2316       return(preg_match($rx, $fn)); 
    2317    } 
    2318 } 
    2319  
    2320  
    2321 /** 
    2322  * file search and name matching (with shell patterns) 
    2323  * 
    2324  * @param  string  $pattern   search pattern and path ../* string 
    2325  * @param  integer $flags (optional) 
    2326  * @return array 
    2327  */ 
    2328 if (!function_exists("glob")) { 
    2329  
    2330    #-- introduced constants 
    2331    if (!defined("GLOB_MARK")) { define("GLOB_MARK", 1<<0); } 
    2332    if (!defined("GLOB_NOSORT")) { define("GLOB_NOSORT", 1<<1); } 
    2333    if (!defined("GLOB_NOCHECK")) { define("GLOB_NOCHECK", 1<<2); } 
    2334    if (!defined("GLOB_NOESCAPE")) { define("GLOB_NOESCAPE", 1<<3); } 
    2335    if (!defined("GLOB_BRACE")) { define("GLOB_BRACE", 1<<4); } 
    2336    if (!defined("GLOB_ONLYDIR")) { define("GLOB_ONLYDIR", 1<<5); } 
    2337    if (!defined("GLOB_NOCASE")) { define("GLOB_NOCASE", 1<<6); } 
    2338    if (!defined("GLOB_DOTS")) { define("GLOB_DOTS", 1<<7); } 
    2339    // unlikely to work under Win(?), without replacing the explode() with 
    2340    // a preg_split() incorporating the native DIRECTORY_SEPARATOR as well 
    2341  
    2342    #-- implementation 
    2343    function glob($pattern, $flags=0x0000) { 
    2344       $ls = array(); 
    2345       $rxci = ($flags & GLOB_NOCASE) ? "i" : ""; 
    2346 #echo "\n=> glob($pattern)...\n"; 
    2347        
    2348       #-- transform glob pattern into regular expression 
    2349       #   (similar to fnmatch() but still different enough to require a second func) 
    2350       if ($pattern) { 
    2351  
    2352          #-- look at each directory/fn spec part separately 
    2353          $parts2 = explode("/", $pattern); 
    2354          $pat = preg_quote($pattern); 
    2355          $pat = strtr($pat, array("\\*"=>".*?", "\\?"=>".?")); 
    2356          if ($flags ^ GLOB_NOESCAPE) { 
    2357             // uh, oh, ouuch - the above is unclean enough... 
    2358          } 
    2359          if ($flags ^ GLOB_BRACE) { 
    2360             $pat = preg_replace("/\{(.+?)\}/e", 'strtr("[$1]", ",", "")', $pat); 
    2361          } 
    2362          $parts = explode("/", $pat); 
    2363 #echo "parts == ".implode(" // ", $parts) . "\n"; 
    2364          $lasti = count($parts) - 1; 
    2365          $dn = ""; 
    2366          foreach ($parts as $i=>$p) { 
    2367  
    2368             #-- basedir included (yet no pattern matching necessary) 
    2369             if (!strpos($p, "*?") && (strpos($p, ".?")===false)) { 
    2370                $dn .= $parts2[$i] . ($i!=$lasti ? "/" : ""); 
    2371 #echo "skip:$i, cause no pattern matching char found -> only a basedir spec\n"; 
    2372                continue; 
    2373             } 
    2374              
    2375             #-- start reading dir + match filenames against current pattern 
    2376             if ($dh = opendir($dn ?$dn:'.')) { 
    2377                $with_dot = ($p[1]==".") || ($flags & GLOB_DOTS); 
    2378 #echo "part:$i:$p\n"; 
    2379 #echo "reading dir \"$dn\"\n"; 
    2380                while ($fn = readdir($dh)) { 
    2381                   if (preg_match("\007^$p$\007$rxci", $fn)) { 
    2382  
    2383                      #-- skip over 'hidden' files 
    2384                      if (($fn[0] == ".") && !$with_dot) { 
    2385                         continue; 
    2386                      } 
    2387  
    2388                      #-- add filename only if last glob/pattern part 
    2389                      if ($i==$lasti) { 
    2390                         if (is_dir("$dn$fn")) { 
    2391                            if ($flags & GLOB_ONLYDIR) { 
    2392                               continue; 
    2393                            } 
    2394                            if ($flags & GLOB_MARK) { 
    2395                               $fn .= "/"; 
    2396                            } 
    2397                         } 
    2398 #echo "adding '$fn' for dn=$dn to list\n"; 
    2399                         $ls[] = "$dn$fn"; 
    2400                      } 
    2401  
    2402                      #-- initiate a subsearch, merge result list in 
    2403                      elseif (is_dir("$dn$fn")) { 
    2404                         // add reamaining search patterns to current basedir 
    2405                         $remaind = implode("/", array_slice($parts2, $i+1)); 
    2406                         $ls = array_merge($ls, glob("$dn$fn/$remaind", $flags)); 
    2407                      } 
    2408                   } 
    2409                } 
    2410                closedir($dh); 
    2411  
    2412                #-- prevent scanning a 2nd part/dir in same glob() instance: 
    2413                break;   
    2414             } 
    2415  
    2416             #-- given dirname doesn't exist 
    2417             else { 
    2418                return($ls); 
    2419             } 
    2420  
    2421          }// foreach $parts 
    2422       } 
    2423  
    2424       #-- return result list 
    2425       if (!$ls && ($flags & GLOB_NOCHECK)) { 
    2426          $ls[] = $pattern; 
    2427       } 
    2428       if ($flags ^ GLOB_NOSORT) { 
    2429          sort($ls); 
    2430       } 
    2431 #print_r($ls); 
    2432 #echo "<=\n"; 
    2433       return($ls); 
    2434    } 
    2435 } //@FIX: fully comment, remove debugging code (- as soon as it works ;) 
    2436  
    2437  
    2438  
    2439 /** 
    2440  * redundant alias for isset() 
    2441  *  
    2442  */ 
    2443 if (!function_exists("array_key_exists")) { 
    2444    function array_key_exists($key, $search) { 
    2445       return isset($search[$key]); 
    2446    } 
    2447 } 
    2448  
    2449  
    2450 /** 
    2451  * who could need that? 
    2452  *  
    2453  */ 
    2454 if (!function_exists("array_intersect_assoc")) { 
    2455    function array_intersect_assoc( /*array, array, array...*/ ) { 
    2456  
    2457       #-- parameters, prepare 
    2458       $in = func_get_args(); 
    2459       $cmax = count($in); 
    2460       $whatsleftover = array(); 
    2461        
    2462       #-- walk through each array pair 
    2463       #   (take first as checklist) 
    2464       foreach ($in[0] as $i => $v) { 
    2465          for ($c = 1; $c < $cmax; $c++) { 
    2466             #-- remove entry, as soon as it isn't present 
    2467             #   in one of the other arrays 
    2468             if (!isset($in[$c][$i]) || (@$in[$c][$i] !== $v)) { 
    2469                continue 2; 
    2470             } 
    2471          } 
    2472          #-- it was found in all other arrays 
    2473          $whatsleftover[$i] = $v; 
    2474       } 
    2475       return $whatsleftover; 
    2476    } 
    2477 } 
    2478  
    2479  
    2480 /** 
    2481  * the opposite of the above 
    2482  *  
    2483  */ 
    2484 if (!function_exists("array_diff_assoc")) { 
    2485    function array_diff_assoc( /*array, array, array...*/ ) { 
    2486  
    2487       #-- params 
    2488       $in = func_get_args(); 
    2489       $diff = array(); 
    2490        
    2491       #-- compare each array with primary/first 
    2492       foreach ($in[0] as $i=>$v) { 
    2493          for ($c=1; $c<count($in); $c++) { 
    2494             #-- skip as soon as it matches with entry in another array 
    2495             if (isset($in[$c][$i]) && ($in[$c][$i] == $v)) { 
    2496                continue 2; 
    2497             } 
    2498          } 
    2499          #-- else 
    2500          $diff[$i] = $v; 
    2501       } 
    2502       return $diff; 
    2503    } 
    2504 } 
    2505  
    2506  
    2507 /** 
    2508  * opposite of htmlentities 
    2509  *  
    2510  */ 
    2511 if (!function_exists("html_entity_decode")) { 
    2512    function html_entity_decode($string, $quote_style=ENT_COMPAT, $charset="ISO-8859-1") { 
    2513       //@FIX: we fall short on anything other than Latin-1 
    2514       $y = array_flip(get_html_translation_table(HTML_ENTITIES, $quote_style)); 
    2515       return strtr($string, $y); 
    2516    } 
    2517 } 
    2518  
    2519  
    2520 /** 
    2521  * extracts single words from a string 
    2522  *  
    2523  */ 
    2524 if (!function_exists("str_word_count")) { 
    2525    function str_word_count($string, $result=0) { 
    2526     
    2527       #-- let someone else do the work 
    2528       preg_match_all('/([\w](?:[-\'\w]?[\w]+)*)/', $string, $uu); 
    2529  
    2530       #-- return full word list 
    2531       if ($result == 1) { 
    2532          return($uu[1]); 
    2533       } 
    2534        
    2535       #-- array() of $pos=>$word entries 
    2536       elseif ($result >= 2) { 
    2537          $r = array(); 
    2538          $l = 0; 
    2539          foreach ($uu[1] as $word) { 
    2540             $l = strpos($string, $word, $l); 
    2541             $r[$l] = $word; 
    2542             $l += strlen($word);  // speed up next search 
    2543          } 
    2544          return($r); 
    2545       } 
    2546  
    2547       #-- only count 
    2548       else { 
    2549          return(count($uu[1])); 
    2550       } 
    2551    } 
    2552 } 
    2553  
    2554  
    2555 /** 
    2556  * creates a permutation of the given strings characters 
    2557  * (let's hope the random number generator was alread initialized) 
    2558  *  
    2559  */ 
    2560 if (!function_exists("str_shuffle")) { 
    2561    function str_shuffle($str) { 
    2562       $r = ""; 
    2563  
    2564       #-- cut string down with every iteration 
    2565       while (strlen($str)) { 
    2566          $n = strlen($str) - 1; 
    2567          if ($n) { 
    2568             $n = rand(0, $n);   // glibcs` rand is ok since 2.1 at least 
    2569          } 
    2570           
    2571          #-- cut out elected char, add to result string 
    2572          $r .= $str{$n}; 
    2573          $str = substr($str, 0, $n) . substr($str, $n + 1); 
    2574       } 
    2575       return($r); 
    2576    } 
    2577 } 
    2578  
    2579  
    2580 /** 
    2581  * simple shorthands 
    2582  *  
    2583  */ 
    2584 if (!function_exists("get_include_path")) { 
    2585    function get_include_path() { 
    2586       return(get_cfg_var("include_path")); 
    2587    } 
    2588    function set_include_path($new) { 
    2589       return ini_set("include_path", $new); 
    2590    } 
    2591    function restore_include_path() { 
    2592       ini_restore("include_path"); 
    2593    } 
    2594 } 
    2595  
    2596  
    2597 #-- constants for 4.3 
    2598    if (!defined("PATH_SEPARATOR")) { define("PATH_SEPARATOR", ((DIRECTORY_SEPARATOR=='\\') ? ';' :':')); } 
    2599    if (!defined("PHP_SHLIB_SUFFIX")) { define("PHP_SHLIB_SUFFIX", ((DIRECTORY_SEPARATOR=='\\') ? 'dll' :'so')); } 
    2600    if (!defined("PHP_SAPI")) { define("PHP_SAPI", php_sapi_name()); } 
    2601    if (!defined("__FUNCTION__")) { define("__FUNCTION__", NULL); }   // empty string would signalize main() 
    2602  
    2603  
    2604 #-- not identical to what PHP reports (it seems to `which` for itself) 
    2605 if (!defined("PHP_PREFIX") && isset($_ENV["_"])) { define("PHP_PREFIX", substr($_ENV["_"], 0, strpos($_ENV["_"], "bin/"))); } 
    2606  
    2607  
    2608  
    2609  
    2610  
    2611  
    2612 /** 
    2613  *                                   ------------------------------ 4.2 --- 
    2614  * @group 4_2 
    2615  * @since 4.2 
    2616  * 
    2617  * 
    2618  *  Functions added in PHP 4.2 interpreters. 
    2619  * 
    2620  * 
    2621  * @emulated 
    2622  *   str_rot13 
    2623  *   array_change_key_case 
    2624  *   array_fill 
    2625  *   array_chunk 
    2626  *   md5_file 
    2627  *   is_a 
    2628  *   fmod 
    2629  *   floatval 
    2630  *   is_infinite 
    2631  *   is_nan 
    2632  *   is_finite 
    2633  *   var_export 
    2634  *   strcoll 
    2635  * @missing 
    2636  *   ... 
    2637  * 
    2638  *   almost complete!? 
    2639  * 
    2640  * 
    2641  */ 
    2642  
    2643  
    2644 /** 
    2645  * shy away from this function - it was broken in all PHP4.2 releases, 
    2646  * and our emulation here won't change that 
    2647  * 
    2648  * @param  string $str   
    2649  * @return string 
    2650  */ 
    2651 if (!function_exists("str_rot13")) { 
    2652    function str_rot13($str) { 
    2653       static $from = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 
    2654       static $to = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"; 
    2655       return strtr($str, $from, $to); 
    2656    } 
    2657 } 
    2658  
    2659  
    2660 /** 
    2661  * changes case of textual index keys 
    2662  * 
    2663  * @param  array $array   
    2664  * @param  int   $case 
    2665  * @return array 
    2666  */ 
    2667 if (!function_exists("array_change_key_case")) { 
    2668     
    2669    #-- introduced constants 
    2670    if (!defined("CASE_LOWER")) { define("CASE_LOWER", 0); } 
    2671    if (!defined("CASE_UPPER")) { define("CASE_UPPER", 1); } 
    2672     
    2673    #-- implementation 
    2674    function array_change_key_case($array, $case=CASE_LOWER) { 
    2675     
    2676       #-- loop through 
    2677       foreach ($array as $i=>$v) { 
    2678          #-- do anything for strings only 
    2679          if (is_string($i)) { 
    2680             unset($array[$i]); 
    2681             $i = ($case==CASE_LOWER) ? strtolower($i) : strtoupper($i); 
    2682             $array[$i] = $v; 
    2683          } 
    2684          // non-recursive       
    2685       } 
    2686       return($array); 
    2687    } 
    2688 } 
    2689  
    2690  
    2691 /** 
    2692  * create fixed-length array made up of $value data 
    2693  *  
    2694  */ 
    2695 if (!function_exists("array_fill")) { 
    2696    function array_fill($start_index, $num, $value) { 
    2697  
    2698       #-- params 
    2699       $r = array(); 
    2700       $i = $start_index; 
    2701       $end = $num + $start_index; 
    2702        
    2703       #-- append 
    2704       for (; $i < $end; $i++) 
    2705       { 
    2706          $r[$i] = $value; 
    2707       } 
    2708       return($r); 
    2709    } 
    2710 } 
    2711  
    2712  
    2713 /** 
    2714  * split an array into evenly sized parts 
    2715  *  
    2716  */ 
    2717 if (!function_exists("array_chunk")) { 
    2718    function array_chunk($input, $size, $preserve_keys=false) { 
    2719     
    2720       #-- array for chunked output 
    2721       $r = array(); 
    2722       $n = -1;  // chunk index 
    2723        
    2724       #-- enum input array blocks 
    2725       foreach ($input as $i=>$v) { 
    2726        
    2727          #-- new chunk 
    2728          if (($n < 0) || (count($r[$n]) == $size)) { 
    2729             $n++; 
    2730             $r[$n] = array(); 
    2731          } 
    2732           
    2733          #-- add input value into current [$n] chunk 
    2734          if ($preserve_keys) { 
    2735             $r[$n][$i] = $v; 
    2736          } 
    2737          else { 
    2738             $r[$n][] = $v; 
    2739          } 
    2740       } 
    2741       return($r); 
    2742    } 
    2743 } 
    2744  
    2745  
    2746 /** 
    2747  * convenience wrapper 
    2748  *  
    2749  */ 
    2750 if (!function_exists("md5_file")) { 
    2751    function md5_file($filename, $raw_output=false) { 
    2752  
    2753       #-- read file, apply hash function 
    2754       $r = md5(file_get_contents($filename, "rb")); 
    2755           
    2756       #-- transform? and return 
    2757       if ($raw_output) { 
    2758          $r = pack("H*", $r); 
    2759       } 
    2760       return $r; 
    2761    } 
    2762 } 
    2763  
    2764  
    2765 /** 
    2766  * object type checking 
    2767  *  
    2768  */ 
    2769 if (!function_exists("is_a")) { 
    2770    function is_a($obj, $classname) { 
    2771     
    2772       #-- lowercase everything for comparison 
    2773       $classnaqme = strtolower($classname); 
    2774       $obj_class =  strtolower(get_class($obj)); 
    2775        
    2776       #-- two possible checks 
    2777       return ($obj_class == $classname) or is_subclass_of($obj, $classname); 
    2778    } 
    2779 } 
    2780  
    2781  
    2782 /** 
    2783  * floating point modulo 
    2784  *  
    2785  */ 
    2786 if (!function_exists("fmod")) { 
    2787    function fmod($x, $y) { 
    2788       $r = $x / $y; 
    2789       $r -= (int)$r; 
    2790       $r *= $y; 
    2791       return($r); 
    2792    } 
    2793 } 
    2794  
    2795  
    2796 /** 
    2797  * makes float variable from string 
    2798  * 
    2799  * @param  string 
    2800  * @return float 
    2801  */ 
    2802 if (!function_exists("floatval")) { 
    2803    function floatval($str) { 
    2804       $str = ltrim($str); 
    2805       return (float)$str; 
    2806    } 
    2807 } 
    2808  
    2809  
    2810 /** 
    2811  * floats 
    2812  * 
    2813  */ 
    2814 if (!function_exists("is_infinite")) { 
    2815  
    2816    #-- constants as-is 
    2817    if (!defined("NAN")) { define("NAN", "NAN"); } 
    2818    if (!defined("INF")) { define("INF", "INF"); }   // there is also "-INF" 
    2819     
    2820    #-- simple checks 
    2821    function is_infinite($f) { 
    2822       $s = (string)$f; 
    2823       return(  ($s=="INF") || ($s=="-INF")  ); 
    2824    } 
    2825    function is_nan($f) { 
    2826       $s = (string)$f; 
    2827       return(  $s=="NAN"  ); 
    2828    } 
    2829    function is_finite($f) { 
    2830       $s = (string)$f; 
    2831       return(  !strpos($s, "N")  ); 
    2832    } 
    2833 } 
    2834  
    2835  
    2836 /** 
    2837  * throws value-instantiation PHP-code for given variable 
    2838  * 
    2839  * @compat 
    2840  *    output differentiates from native PHP version, 
    2841  *    but functions identically 
    2842  * 
    2843  * @param  mixed $var   
    2844  * @param  mixed $return  (optional) false 
    2845  * @param  string $indent  (optional) "" 
    2846  * @param  string $output  (optional) "" 
    2847  * @return mixed 
    2848  */ 
    2849 if (!function_exists("var_export")) { 
    2850    function var_export($var, $return=false, $indent="", $output="") { 
    2851  
    2852       #-- output as in-class variable definitions 
    2853       if (is_object($var)) { 
    2854          $output = get_class($var) . "::_set_state(array(\n"; 
    2855          foreach (((array)$var) as $id=>$var) { 
    2856             $output .= "  '\$$id' => " . var_export($var, true) . ",\n"; 
    2857          } 
    2858          $output .= "));"; 
    2859       } 
    2860        
    2861       #-- array constructor 
    2862       elseif (is_array($var)) { 
    2863          foreach ($var as $id=>$next) { 
    2864             if ($output) $output .= ",\n"; 
    2865                     else $output = "array(\n"; 
    2866             $output .= $indent . '  ' 
    2867                     . (is_numeric($id) ? $id : '"'.addslashes($id).'"') 
    2868                     . ' => ' . var_export($next, true, "$indent  "); 
    2869          } 
    2870          if (empty($output)) $output = "array("; 
    2871          $output .= "\n{$indent})"; 
    2872        #if ($indent == "") $output .= ";"; 
    2873       } 
    2874        
    2875       #-- literals 
    2876       elseif (is_numeric($var)) { 
    2877          $output = "$var"; 
    2878       } 
    2879       elseif (is_bool($var)) { 
    2880          $output = $var ? "true" : "false"; 
    2881       } 
    2882       else { 
    2883          $output = "'" . preg_replace("/([\\\\\'])/", '\\\\$1', $var) . "'"; 
    2884       } 
    2885  
    2886       #-- done 
    2887       if ($return) { 
    2888          return($output); 
    2889       } 
    2890       else { 
    2891          print($output); 
    2892       } 
    2893    } 
    2894 } 
    2895  
    2896  
    2897 /** 
    2898  * @stub 
    2899  * @since existed since PHP 4.0.5, but under Win32 first since 4.3.2 
    2900  *  
    2901  * strcmp() variant that respects locale setting, 
    2902  * 
    2903  * @param  string $str1   
    2904  * @param  string $str2   
    2905  * @return string 
    2906  */ 
    2907 if (!function_exists("strcoll")) { 
    2908    function strcoll($str1, $str2) { 
    2909       return strcmp($str1, $str2); 
    2910    } 
    2911 } 
    2912  
    2913  
    2914  
    2915  
    2916  
    2917 /** 
    2918  *                                   ------------------------------ 4.1 --- 
    2919  * @group 4_1 
    2920  * @since 4.1 
    2921  * 
    2922  * 
    2923  * See also "ext/math41.php" for some more (rarely used mathematical funcs). 
    2924  * 
    2925  * 
    2926  * @emulated 
    2927  *   diskfreespace 
    2928  *   disktotalspace 
    2929  *   vprintf 
    2930  *   vsprintf 
    2931  *   import_request_variables 
    2932  *   hypot 
    2933  *   log1p 
    2934  *   expm1 
    2935  *   sinh 
    2936  *   cosh 
    2937  *   tanh 
    2938  *   asinh 
    2939  *   acosh 
    2940  *   atanh 
    2941  *   mhash 
    2942  *   mhash_count 
    2943  *   mhash_get_hash_name 
    2944  *   mhash_get_block_size 
    2945  * @missing 
    2946  *   nl_langinfo - unimpl? 
    2947  *   getmygid 
    2948  *   version_compare 
    2949  * 
    2950  */ 
    2951  
    2952  
    2953  
    2954  
    2955 /** 
    2956  * aliases (an earlier fallen attempt to unify PHP function names) 
    2957  *  
    2958  */ 
    2959 if (!function_exists("diskfreespace")) { 
    2960    function diskfreespace() { 
    2961       return disk_free_sapce(); 
    2962    } 
    2963    function disktotalspace() { 
    2964       return disk_total_sapce(); 
    2965    } 
    2966 } 
    2967  
    2968  
    2969 /** 
    2970  * variable count of arguments (in array list) printf variant 
    2971  * 
    2972  * @param  string $format   
    2973  * @param  mixed  $args 
    2974  * @output 
    2975  */ 
    2976 if (!function_exists("vprintf")) { 
    2977    function vprintf($format, $args=NULL) { 
    2978       call_user_func_array("fprintf", func_get_args()); 
    2979    } 
    2980 } 
    2981  
    2982  
    2983 /** 
    2984  * same as above, but doesn't output directly and returns formatted string 
    2985  * 
    2986  * @param  string $format 
    2987  * @param  mixed  $args 
    2988  * @return string 
    2989  */ 
    2990 if (!function_exists("vsprintf")) { 
    2991    function vsprintf($format, $args=NULL) { 
    2992       $args = array_merge(array($format), array_values((array)$args)); 
    2993       return call_user_func_array("sprintf", $args); 
    2994    } 
    2995 } 
    2996  
    2997  
    2998 /** 
    2999  * @extended 
    3000  * 
    3001  * can be used to simulate a register_globals=on environment 
    3002  * 
    3003  * @param  string $types   order of GET,POST,COOKIE variables 
    3004  * @param  string $pfix    prefix for imported variable names 
    3005  * @global $GLOBALS 
    3006  */ 
    3007 if (!function_exists("import_request_variables")) { 
    3008    function import_request_variables($types="GPC", $pfix="") { 
    3009        
    3010       #-- associate abbreviations to global var names 
    3011       $alias = array( 
    3012          "G" => "_GET", 
    3013          "P" => "_POST", 
    3014          "C" => "_COOKIE", 
    3015          "S" => "_SERVER",   // non-standard 
    3016          "E" => "_ENV",      // non-standard 
    3017       ); 
    3018  
    3019       #-- alias long names (PHP < 4.0.6)    //@FIXME: does that belong here? 
    3020       if (!isset($_REQUEST)) { 
    3021          $_GET = & $HTTP_GET_VARS; 
    3022          $_POST = & $HTTP_POST_VARS; 
    3023          $_COOKIE = & $HTTP_COOKIE_VARS; 
    3024       } 
    3025        
    3026       #-- copy 
    3027       foreach (str_split($types, 1) as $c) { 
    3028          if ($FROM = $alias[strtoupper($c)]) { 
    3029             foreach ($$FROM as $key=>$val) { 
    3030                if (!isset($GLOBALS[$pfix.$key])) { 
    3031                   $GLOBALS[$pfix . $key] = $val; 
    3032                } 
    3033             } 
    3034          } 
    3035       } 
    3036       // done 
    3037    } 
    3038 } 
    3039  
    3040  
    3041 // a few mathematical functions follow 
    3042 // (wether we should really emulate them is a different question) 
    3043  
    3044 #-- me has no idea what this function means 
    3045 if (!function_exists("hypot")) { 
    3046    function hypot($num1, $num2) { 
    3047       return sqrt($num1*$num1 + $num2*$num2);  // as per PHP manual ;) 
    3048    } 
    3049 } 
    3050  
    3051 #-- more accurate logarithm func, but we cannot simulate it 
    3052 #   (too much work, too slow in PHP) 
    3053 if (!function_exists("log1p")) { 
    3054    function log1p($x) { 
    3055       return(  log(1+$x)  ); 
    3056    } 
    3057    #-- same story for: 
    3058    function expm1($x) { 
    3059       return(  exp($x)-1  ); 
    3060    } 
    3061 } 
    3062  
    3063 #-- as per PHP manual 
    3064 if (!function_exists("sinh")) { 
    3065    function sinh($f) { 
    3066       return(  (exp($f) - exp(-$f)) / 2  ); 
    3067    } 
    3068    function cosh($f) { 
    3069       return(  (exp($f) + exp(-$f)) / 2  ); 
    3070    } 
    3071    function tanh($f) { 
    3072       return(  sinh($f) / cosh($f)  );   // ok, that one makes sense again :) 
    3073    } 
    3074 } 
    3075  
    3076 #-- these look a bit more complicated 
    3077 if (!function_exists("asinh")) { 
    3078    function asinh($x) { 
    3079       return(  log($x + sqrt($x*$x+1))  ); 
    3080    } 
    3081    function acosh($x) { 
    3082       return(  log($x + sqrt($x*$x-1))  ); 
    3083    } 
    3084    function atanh($x) { 
    3085       return(  log1p( 2*$x / (1-$x) ) / 2  ); 
    3086    } 
    3087 } 
    3088  
    3089  
    3090  
    3091  
    3092 /** 
    3093  * HMAC from RFC2104, but see also PHP_Compat or Crypt_HMAC 
    3094  * 
    3095  * @param  string $hashtype  which encoding functions to use 
    3096  * @param  string $text      plaintext to hash 
    3097  * @param  string $key       key data 
    3098  * @return string            hash 
    3099  */ 
    3100 if (!function_exists("mhash")) { 
    3101  
    3102    #-- constants 
    3103    if (!defined("MHASH_CRC32")) { define("MHASH_CRC32", 0); } 
    3104    if (!defined("MHASH_MD5")) { define("MHASH_MD5", 1); }       // RFC1321 
    3105    if (!defined("MHASH_SHA1")) { define("MHASH_SHA1", 2); }      // RFC3174 
    3106    if (!defined("MHASH_TIGER")) { define("MHASH_TIGER", 7); } 
    3107    if (!defined("MHASH_MD4")) { define("MHASH_MD4", 16); }      // RFC1320 
    3108    if (!defined("MHASH_SHA256")) { define("MHASH_SHA256", 17); } 
    3109    if (!defined("MHASH_ADLER32")) { define("MHASH_ADLER32", 18); } 
    3110     
    3111    #-- implementation 
    3112    function mhash($hashtype, $text, $key) { 
    3113     
    3114       #-- hash function 
    3115       if (!($func = mhash_get_hash_name($hashtype)) || !function_exists($func)) { 
    3116          return trigger_error("mhash: cannot use hash algorithm #$hashtype/$func", E_USER_ERROR); 
    3117       } 
    3118       if (!$key) { 
    3119          trigger_error("mhash: called without key", E_USER_WARNING); 
    3120       } 
    3121        
    3122       #-- params 
    3123       $bsize = mhash_get_block_size($hashtype);   // fixed size, 64 
    3124  
    3125       #-- pad key 
    3126       if (strlen($key) > $bsize) {  // hash key, when it's too long 
    3127          $key = $func($key);  
    3128          $key = pack("H*", $key);   // binarify 
    3129       } 
    3130       $key = str_pad($key, $bsize, "\0");  // fill up with NULs (1) 
    3131        
    3132       #-- prepare inner and outer padding stream 
    3133       $ipad = str_pad("", $bsize, "6");   // %36 
    3134       $opad = str_pad("", $bsize, "\\");  // %5C 
    3135        
    3136       #-- call hash func    // php can XOR strings for us 
    3137       $dgst = pack("H*",  $func(  ($key ^ $ipad)  .  $text  ));  // (2,3,4) 
    3138       $dgst = pack("H*",  $func(  ($key ^ $opad)  .  $dgst  ));  // (5,6,7) 
    3139       return($dgst); 
    3140    } 
    3141     
    3142    #-- return which hash functions are implemented 
    3143    function mhash_count() { 
    3144       return(MHASH_SHA1); 
    3145    } 
    3146     
    3147    #-- map numeric identifier to hash function name 
    3148    function mhash_get_hash_name($i) { 
    3149       static $hash_funcs = array( 
    3150           MHASH_CRC32 => "crc32",   // would need dechex()ing in main func? 
    3151           MHASH_MD5 => "md5", 
    3152           MHASH_SHA1 => "sha1", 
    3153       ); 
    3154       return(strtoupper($hash_funcs[$i])); 
    3155    } 
    3156     
    3157    #-- static value 
    3158    function mhash_get_block_size($i) { 
    3159       return(64); 
    3160    } 
    3161 } 
    3162  
    3163  
    3164  
    3165  
    3166  
    3167 /** 
    3168  * 
    3169  * @group REMOVED_STUFF 
    3170  * @since unknown 
    3171  * @until unknown 
    3172  * 
    3173  * 
    3174  * @emulated 
    3175  *    ... 
    3176  * 
    3177  * @missing 
    3178  *    leak  - occupy a given amount of memory 
    3179  * 
    3180  */ 
    3181  
    3182  
    3183  
    3184  
    3185  
    3186 /** 
    3187  * 
    3188  * group PRE_4_1 
    3189  * since 4.0 
    3190  * since 3.0 
    3191  * 
    3192  * 
    3193  * @emulated 
    3194  *    ... 
    3195  * 
    3196  * 
    3197  * No need to implement anything below that, because such old versions 
    3198  * will be incompatbile anyhow (- none of the newer superglobals known). 
    3199  * 
    3200  * but see also "ext/old" 
    3201  * 
    3202  */ 
    3203  
    3204  
    32052154?> 
  • freepbx/trunk/amp_conf/htdocs/admin/libraries/utility.functions.php

    r12223 r12325  
    424424    if (is_array($add)) { 
    425425      if (isset($add['command'])) { 
    426         $cron_add['minute']   = isset($add['minute']) ? $add['minute']  : '*'; 
    427         $cron_add['hour']   = isset($add['hour']) ? $add['hour']    : '*'; 
    428         $cron_add['dom']    = isset($add['dom'])  ? $add['dom']   : '*'; 
    429         $cron_add['month']    = isset($add['month'])  ? $add['month']   : '*'; 
    430         $cron_add['dow']    = isset($add['dow'])  ? $add['dow']   : '*'; 
     426        //see if we have a one word event such as daily, weekly, anually, etc 
     427        if (isset($add['event'])) { 
     428          $cron_add['event'] = '@' . trim($add['event'], '@'); 
     429        } else { 
     430          $cron_add['minute']   = isset($add['minute']) ? $add['minute']  : '*'; 
     431          $cron_add['hour']   = isset($add['hour']) ? $add['hour']    : '*'; 
     432          $cron_add['dom']    = isset($add['dom'])  ? $add['dom']   : '*'; 
     433          $cron_add['month']    = isset($add['month'])  ? $add['month']   : '*'; 
     434          $cron_add['dow']    = isset($add['dow'])  ? $add['dow']   : '*'; 
     435        } 
    431436        $cron_add['command']  = $add['command']; 
    432437        $cron_add = implode(' ', $cron_add); 
     
    448453  //write out crontab 
    449454  $exec = '/bin/echo "' . implode("\n", $cron_out) . '" | /usr/bin/crontab ' . $cron_user . '-'; 
     455  //dbug('writing crontab', $exec); 
    450456  exec($exec, $out_arr, $ret); 
    451457 
     
    525531      } 
    526532} 
     533 
     534//this function can print a json object in a "pretty" (i.e. human-readbale) format 
     535function json_print_pretty($json, $indent = "\t") { 
     536  $f      = ''; 
     537  $len    = strlen($json); 
     538  $depth    = 0; 
     539  $newline  = false; 
     540 
     541  for ($i = 0; $i < $len; ++$i) { 
     542    if ($newline) { 
     543      $f .= "\n"; 
     544      $f .= str_repeat($indent, $depth); 
     545      $newline = false; 
     546    } 
     547 
     548    $c = $json[$i]; 
     549    if ($c == '{' || $c == '[') { 
     550      $f .= $c; 
     551      $depth++; 
     552      $newline = true; 
     553    } else if ($c == '}' || $c == ']') { 
     554      $depth--; 
     555      $f .= "\n"; 
     556      $f .= str_repeat($indent, $depth); 
     557      $f .= $c; 
     558    } else if ($c == '"') { 
     559      $s = $i; 
     560      do { 
     561        $c = $json[++$i]; 
     562        if ($c == '\\') { 
     563          $i += 2; 
     564          $c = $json[$i]; 
     565        } 
     566      } while ($c != '"'); 
     567      $f .= substr($json, $s, $i-$s+1); 
     568    } else if ($c == ':') { 
     569      $f .= ': '; 
     570    } else if ($c == ',') { 
     571      $f .= ','; 
     572      $newline = true; 
     573    } else { 
     574      $f .= $c; 
     575    } 
     576  } 
     577  return $f; 
     578}