Ignore:
Timestamp:
11/17/09 09:02:41 (15 years ago)
Author:
amuller
Message:

Ticket #597 - melhoria no modulo gerenciador de arquivos

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/filemanager/tp/dompdf/include/functions.inc.php

    r1575 r1654  
    3434 * @copyright 2004 Benj Carson 
    3535 * @author Benj Carson <benjcarson@digitaljunkies.ca> 
     36 * @contributor Helmut Tischer <htischer@weihenstephan.org> 
    3637 * @package dompdf 
    3738 * @version 0.5.1 
    38  */ 
    39  
    40 /* $Id: functions.inc.php,v 1.11 2006/07/07 21:31:03 benjcarson Exp $ */ 
     39 * 
     40 * Changes 
     41 * @contributor Helmut Tischer <htischer@weihenstephan.org> 
     42 * @version 0.5.1.htischer.20090507 
     43 * - trailing slash of base_path in build_url is no longer optional when 
     44 *   required. This allows paths not ending in a slash, e.g. on dynamically 
     45 *   created sites with page id in the url parameters. 
     46 * @version 20090601 
     47 * - fix windows paths 
     48 * @version 20090610 
     49 * - relax windows path syntax, use uniform path delimiter. Used for background images. 
     50 */ 
     51 
     52/* $Id: functions.inc.php 187 2009-10-20 19:09:52Z eclecticgeek@gmail.com $ */ 
    4153 
    4254/** 
     
    95107 * @param string $url 
    96108 * @return string 
     109 * 
     110 * Initially the trailing slash of $base_path was optional, and conditionally appended. 
     111 * However on dynamically created sites, where the page is given as url parameter, 
     112 * the base path might not end with an url. 
     113 * Therefore do not append a slash, and **require** the $base_url to ending in a slash 
     114 * when needed. 
     115 * Vice versa, on using the local file system path of a file, make sure that the slash 
     116 * is appended (o.k. also for Windows) 
    97117 */ 
    98118function build_url($protocol, $host, $base_path, $url) { 
    99   if ( mb_strlen($url) == 0 ) 
    100     return $protocol . $host . rtrim($base_path, "/\\") . "/"; 
     119  if ( mb_strlen($url) == 0 ) { 
     120    //return $protocol . $host . rtrim($base_path, "/\\") . "/"; 
     121    return $protocol . $host . $base_path; 
     122  } 
    101123 
    102124  // Is the url already fully qualified? 
     
    106128  $ret = $protocol; 
    107129 
    108   if ( !in_array(mb_strtolower($protocol), array("http://", "https://", 
    109                                                  "ftp://", "ftps://")) ) { 
    110     // We ignore the host for local file access, and run the path through 
    111     // realpath() 
    112     $host = ""; 
    113     $base_path = realpath($base_path); 
    114   } 
    115    
    116   if ( $url{0} === "/" ) 
     130  if (!in_array(mb_strtolower($protocol), array("http://", "https://", "ftp://", "ftps://"))) { 
     131    //On Windows local file, an abs path can begin also with a '\' or a drive letter and colon 
     132    //drive: followed by a relative path would be a drive specific default folder. 
     133    //not known in php app code, treat as abs path 
     134    //($url{1} !== ':' || ($url{2}!=='\\' && $url{2}!=='/')) 
     135    if ($url{0} !== '/' && (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' || ($url{0} != '\\' && $url{1} !== ':'))) { 
     136      // For rel path and local acess we ignore the host, and run the path through realpath() 
     137      $ret .= dompdf_realpath($base_path).'/'; 
     138    } 
     139    $ret .= $url; 
     140    return $ret; 
     141  } 
     142 
     143  //remote urls with backslash in html/css are not really correct, but lets be genereous 
     144  if ( $url{0} === '/' || $url{0} === '\\' ) { 
    117145    // Absolute path 
    118146    $ret .= $host . $url; 
    119   else { 
     147  } else { 
    120148    // Relative path 
    121  
    122     $base_path = $base_path !== "" ? rtrim($base_path, "/\\") . "/" : ""; 
     149    //$base_path = $base_path !== "" ? rtrim($base_path, "/\\") . "/" : ""; 
    123150    $ret .= $host . $base_path . $url; 
    124151  } 
     
    276303 
    277304/** 
     305 * Canonicalize a path without checking if the file exists 
     306 * 
     307 * @param  string $path The path to canonicalize 
     308 * @return string The canonical path, or null if the path is invalid (e.g. /../../foo) 
     309 */ 
     310function dompdf_realpath($path) { 
     311  // If the path is relative, prepend the current directory 
     312  if ( strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ) { 
     313    if ( $path{0} == '/' || $path{0} == '\\' ) { 
     314      $path = substr(getcwd(),0,2) . $path; 
     315    } else if ($path{1} != ':' ) { 
     316      $path = getcwd() . DIRECTORY_SEPARATOR . $path; 
     317    } 
     318  } else if ($path{0} != '/') { 
     319    $path = getcwd() . DIRECTORY_SEPARATOR . $path; 
     320  } 
     321  $path = strtr( $path, DIRECTORY_SEPARATOR == "\\" ? "/" : DIRECTORY_SEPARATOR , DIRECTORY_SEPARATOR); 
     322 
     323  $parts = explode(DIRECTORY_SEPARATOR, $path); 
     324  $path = array(); 
     325 
     326  $i = 0; 
     327  foreach ($parts as $dir) { 
     328 
     329    if ( $dir == "." ) 
     330      continue; 
     331 
     332    if ( $dir == ".." ) { 
     333      $i--; 
     334      if ( $i < 0 ) 
     335        $i = 0; 
     336 
     337      unset($path[$i]); 
     338      continue; 
     339    } 
     340 
     341    if ( $dir == "" ) 
     342      continue; 
     343 
     344    $path[$i] = $dir; 
     345    $i++; 
     346  } 
     347 
     348  return (DIRECTORY_SEPARATOR === '/' ? DIRECTORY_SEPARATOR : NULL) . join(DIRECTORY_SEPARATOR, $path); 
     349} 
     350 
     351/** 
    278352 * mb_string compatibility 
    279353 */ 
    280354 
     355if ( !function_exists("mb_convert_encoding") ) { 
     356  function mb_convert_encoding($data, $to_encoding, $from_encoding='UTF-8') { 
     357    if (str_replace('-', '', strtolower($to_encoding)) == 'utf8') { 
     358      return utf8_encode($data); 
     359    } else { 
     360      return utf8_decode($data); 
     361    } 
     362  } 
     363} 
     364 
     365if ( !function_exists("mb_detect_encoding") ) { 
     366  function mb_detect_encoding($data, $encoding_list=array('iso-8859-1'), $strict=false) { 
     367    return 'iso-8859-1'; 
     368  } 
     369} 
     370 
     371if ( !function_exists("mb_internal_encoding") ) { 
     372  function mb_internal_encoding($encoding=NULL) { 
     373    if (isset($encoding)) { 
     374      return true; 
     375    } else { 
     376      return 'iso-8859-1'; 
     377    } 
     378  } 
     379} 
     380 
    281381if ( !function_exists("mb_strlen") ) { 
    282   function mb_strlen($str) { 
     382  function mb_strlen($str, $encoding='iso-8859-1') { 
    283383    return strlen($str); 
    284384  } 
     
    297397} 
    298398 
     399if ( !function_exists("mb_strtolower") ) { 
     400  function mb_strtolower($str) { 
     401    return strtolower($str); 
     402  } 
     403} 
     404 
     405if ( !function_exists("mb_strtoupper") ) { 
     406  function mb_strtoupper($str) { 
     407    return strtoupper($str); 
     408  } 
     409} 
     410 
    299411if ( !function_exists("mb_substr") ) { 
    300   function mb_substr($str, $start, $length = null) { 
     412  function mb_substr($str, $start, $length=null, $encoding='iso-8859-1') { 
    301413    if ( is_null($length) ) 
    302414      return substr($str, $start); 
     
    306418} 
    307419 
    308 if ( !function_exists("mb_strtolower") ) { 
    309   function mb_strtolower($str) { 
    310     return strtolower($str); 
    311   } 
    312 } 
    313  
    314 if ( !function_exists("mb_strtoupper") ) { 
    315   function mb_strtoupper($str) { 
    316     return strtoupper($str); 
    317   } 
    318 } 
    319  
    320420if ( !function_exists("mb_substr_count") ) { 
    321421  function mb_substr_count($haystack, $needle) { 
     
    323423  } 
    324424} 
    325  
    326425 
    327426/** 
     
    355454 
    356455/** 
     456 * Print a useful backtrace 
     457 */ 
     458function bt() { 
     459  $bt = debug_backtrace(); 
     460 
     461  array_shift($bt); // remove actual bt() call 
     462  echo "\n"; 
     463 
     464  $i = 0; 
     465  foreach ($bt as $call) { 
     466    $file = basename($call["file"]) . " (" . $call["line"] . ")"; 
     467    if ( isset($call["class"]) ) { 
     468      $func = $call["class"] . "->" . $call["function"] . "()"; 
     469    } else { 
     470      $func = $call["function"] . "()"; 
     471    } 
     472 
     473    echo "#" . str_pad($i, 2, " ", STR_PAD_RIGHT) . ": " . str_pad($file.":", 42) . " $func\n"; 
     474    $i++; 
     475  } 
     476  echo "\n"; 
     477} 
     478 
     479/** 
     480 * Print debug messages 
     481 * 
     482 * @param string $type  The type of debug messages to print 
     483 */ 
     484function dompdf_debug($type, $msg) { 
     485  global $_DOMPDF_DEBUG_TYPES; 
     486  global $_dompdf_show_warnings; 
     487  global $_dompdf_debug; 
     488  if ( isset($_DOMPDF_DEBUG_TYPES[$type]) && ($_dompdf_show_warnings || $_dompdf_debug) ) { 
     489    $arr = debug_backtrace(); 
     490 
     491    echo basename($arr[0]["file"]) . " (" . $arr[0]["line"] ."): " . $arr[1]["function"] . ": "; 
     492    pre_r($msg); 
     493  } 
     494} 
     495 
     496/** 
    357497 * Dump memory usage 
    358498 */ 
     499if ( !function_exists("print_memusage") ) { 
    359500function print_memusage() { 
    360501  global $memusage; 
     
    373514  echo ("\n" . str_pad("Total:", 40) . memory_get_usage()) . "\n"; 
    374515} 
     516} 
    375517 
    376518/** 
    377519 * Initialize memory profiling code 
    378520 */ 
     521if ( !function_exists("enable_mem_profile") ) { 
    379522function enable_mem_profile() { 
    380523    global $memusage; 
    381524    $memusage = array("Startup" => memory_get_usage()); 
    382525    register_shutdown_function("print_memusage"); 
    383   } 
     526} 
     527} 
    384528 
    385529/** 
     
    388532 * @param string $location a meaningful location 
    389533 */ 
     534if ( !function_exists("mark_memusage") ) { 
    390535function mark_memusage($location) { 
    391536  global $memusage; 
     
    393538    $memusage[$location] = memory_get_usage(); 
    394539} 
    395  
    396  
     540} 
     541 
     542/** 
     543 * Find the current system temporary directory 
     544 * 
     545 * @link http://us.php.net/manual/en/function.sys-get-temp-dir.php#85261 
     546 */ 
     547if ( !function_exists('sys_get_temp_dir')) { 
     548  function sys_get_temp_dir() { 
     549    if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); } 
     550    if (!empty($_ENV['TMPDIR'])) { return realpath( $_ENV['TMPDIR']); } 
     551    if (!empty($_ENV['TEMP'])) { return realpath( $_ENV['TEMP']); } 
     552    $tempfile=tempnam(uniqid(rand(),TRUE),''); 
     553    if (file_exists($tempfile)) { 
     554    unlink($tempfile); 
     555    return realpath(dirname($tempfile)); 
     556    } 
     557  } 
     558} 
    397559?> 
Note: See TracChangeset for help on using the changeset viewer.