function actionDefault()
 {
     // Test the formatting of filesizes
     $filesizes = array('1152921504606846977', '1125899906842625', '1099511627777', '75715455455', '1048577', '6543', '42');
     // Format the filesizes
     foreach ($filesizes as $filesize) {
         YDDebugUtil::dump(YDStringUtil::formatFileSize($filesize), 'Formatting filesize: ' . $filesize);
     }
     // Test the formatDate function
     YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'date'), 'Formatting date - date');
     YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'time'), 'Formatting date - time');
     YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'datetime'), 'Formatting date - datetime');
     YDDebugUtil::dump(YDStringUtil::formatDate(time(), '%x'), 'Formatting date - %x');
     // Test the encode string function
     $string = 'Pieter Claerhout @ creo.com "générales obsolète"';
     YDDebugUtil::dump(YDStringUtil::encodeString($string), 'Encoding: ' . $string);
     // Test the truncate function
     YDDebugUtil::dump(YDStringUtil::truncate($string), 'Truncate (default): ' . $string);
     YDDebugUtil::dump(YDStringUtil::truncate($string, 20), 'Truncate (20): ' . $string);
     YDDebugUtil::dump(YDStringUtil::truncate($string, 20, ' [more]'), 'Truncate (20/more): ' . $string);
     YDDebugUtil::dump(YDStringUtil::truncate($string, 20, ' [more]', true), 'Truncate (20/more/true): ' . $string);
     // Test the normalizing of newlines
     $string = "line1\nline2\rline3\r\nline4";
     YDDebugUtil::dump(explode("\n", $string), 'Original string');
     YDDebugUtil::dump(explode(YD_CRLF, YDStringUtil::normalizeNewlines($string)), 'normalizeNewlines');
     // Test the normalizing of newlines
     $string = "  line1  \n  line2  \r  line3  \r\n  line4  ";
     YDDebugUtil::dump(YDStringUtil::removeWhiteSpace($string), 'removeWhiteSpace');
 }
 /**
  *	This is the function we use for finishing the request.
  *
  *	@internal
  */
 function finish()
 {
     // Mark that the request is processed
     define('YD_REQ_PROCESSED', 1);
     // Stop the timer
     $elapsed = $GLOBALS['timer']->getElapsed();
     // Total size of include files
     $includeFiles = get_included_files();
     // Calculate the total size
     $includeFilesSize = 0;
     $includeFilesWithSize = array();
     foreach ($includeFiles as $key => $includeFile) {
         $includeFilesSize += filesize($includeFile);
         $includeFilesWithSize[filesize($includeFile)] = realpath($includeFile);
     }
     $includeFilesSize = YDStringUtil::formatFileSize($includeFilesSize);
     // Sort the list of include files by file size
     krsort($includeFilesWithSize);
     // Convert to a string
     $includeFiles = array();
     foreach ($includeFilesWithSize as $size => $file) {
         array_push($includeFiles, YDStringUtil::formatFileSize($size) . "\t  " . $file);
     }
     // Show debugging info if needed
     if (YD_DEBUG == 1) {
         // Create the debug messages
         $debug = "\n\n";
         $debug .= 'Processing time: ' . $elapsed . ' ms' . "\n\n";
         $debug .= 'Total size include files: ' . $includeFilesSize . "\n\n";
         $debug .= 'Included files: ' . "\n\n\t" . implode("\n\t", $includeFiles) . "\n\n";
         // If there is a database instance
         $debug .= 'Number of SQL queries: ' . sizeof($GLOBALS['YD_SQL_QUERY']) . "\n\n";
         // Add the queries if any
         if (sizeof($GLOBALS['YD_SQL_QUERY']) > 0) {
             $debug .= 'Executed SQL queries: ' . "\n\n";
             foreach ($GLOBALS['YD_SQL_QUERY'] as $key => $query) {
                 $debug .= "\t" . ($key + 1) . ': ' . trim($query) . "\n\n";
             }
         }
         // Output the debug message
         YDDebugUtil::debug($debug);
     } else {
         // Short version
         echo "\n" . '<!-- ' . $elapsed . ' ms / ' . $includeFilesSize . ' -->';
     }
     // Stop the execution of the request
     die;
 }
/**
 *	@internal
 */
function YDTemplate_modifier_fmtfileize($size)
{
    return YDStringUtil::formatFileSize($size);
}
Ejemplo n.º 4
0
 function _getTotalSizeAndCountAsText($pattern)
 {
     $res = $this->_getTotalSizeAndCount($pattern);
     return sprintf('(%s %s, %s)', $res[0], t('items'), YDStringUtil::formatFileSize($res[1]));
 }
Ejemplo n.º 5
0
 /**
  *	This is the function we use for finishing the request.
  *
  *	@internal
  */
 function finish()
 {
     // Mark that the request is processed
     define('YD_REQ_PROCESSED', 1);
     // Stop the timer
     $GLOBALS['timer']->finish();
     // Output visible debug info as a comment
     if (YDConfig::get('YD_DEBUG') == 1) {
         // Total size of include files
         $includeFiles = get_included_files();
         // Calculate the total size
         $includeFilesSize = 0;
         $includeFilesWithSize = array();
         foreach ($includeFiles as $key => $includeFile) {
             if (is_file($includeFile)) {
                 $includeFilesSize += filesize($includeFile);
                 $includeFilesWithSize[filesize($includeFile)] = realpath($includeFile);
             }
         }
         $includeFilesSize = YDStringUtil::formatFileSize($includeFilesSize);
         // Sort the list of include files by file size
         krsort($includeFilesWithSize);
         // Convert to a string
         $includeFiles = array();
         foreach ($includeFilesWithSize as $size => $file) {
             array_push($includeFiles, YDStringUtil::formatFileSize($size) . "\t  " . realpath($file));
         }
         // Create the debug messages
         $debug = YD_CRLF . YD_CRLF . YD_FW_NAMEVERS . ' DEBUG INFORMATION ' . YD_CRLF . YD_CRLF;
         // Create the timings report
         $debug .= 'PROCESSING TIME:' . YD_CRLF . YD_CRLF;
         $debug .= "    Elapsed\t  Diff\t  Marker" . YD_CRLF;
         $timings = $GLOBALS['timer']->getReport();
         foreach ($timings as $timing) {
             $debug .= "    " . $timing[0] . ' ms' . "\t  " . $timing[1] . ' ms' . "\t  " . $timing[2] . YD_CRLF;
         }
         $debug .= YD_CRLF;
         // Create the include file details
         $debug .= 'INCLUDED FILES (' . sizeof($includeFiles) . ' files - ' . $includeFilesSize . ')' . YD_CRLF . YD_CRLF;
         $debug .= "    " . implode("\n    ", $includeFiles) . YD_CRLF . YD_CRLF;
         // Add the queries if any
         if (sizeof($GLOBALS['YD_SQL_QUERY']) > 0) {
             $debug .= 'EXECUTED SQL QUERIES (' . sizeof($GLOBALS['YD_SQL_QUERY']) . ' queries)' . YD_CRLF . YD_CRLF;
             foreach ($GLOBALS['YD_SQL_QUERY'] as $key => $query) {
                 $debug .= "    " . '---- SQL QUERY ' . ($key + 1) . ' ----' . YD_CRLF;
                 foreach (explode(YD_CRLF, trim($query['trace'])) as $line) {
                     $debug .= "    " . rtrim($line) . YD_CRLF;
                 }
                 $debug .= YD_CRLF . "    SQL Query:" . YD_CRLF;
                 foreach (explode(YD_CRLF, trim($query['sql'])) as $line) {
                     $debug .= "        " . rtrim($line) . YD_CRLF;
                 }
                 $debug .= YD_CRLF . "    Query Time: " . $query['time'] . ' ms' . YD_CRLF;
                 $debug .= YD_CRLF;
             }
         }
         // Output the debug message
         YDDebugUtil::debug($debug);
     }
     // Output visible debug info
     if (YDConfig::get('YD_DEBUG') == 2) {
         // Total size of include files
         $includeFiles = get_included_files();
         // Calculate the total size
         $includeFilesSize = 0;
         $includeFilesWithSize = array();
         foreach ($includeFiles as $key => $includeFile) {
             if (is_file($includeFile)) {
                 $includeFilesSize += filesize($includeFile);
                 $includeFilesWithSize[filesize($includeFile)] = realpath($includeFile);
             }
         }
         $includeFilesSize = YDStringUtil::formatFileSize($includeFilesSize);
         // Sort the list of include files by file size
         krsort($includeFilesWithSize);
         // Get the timing report
         $timings = $GLOBALS['timer']->getReport();
         // The font to use for the debug output
         $font = ' style="font-family: Arial, Helvetica, sans-serif; text-align: left; vertical-align: top;"';
         // Include the needed libraries
         $debug = '';
         // Create the output
         $debug .= '<br clear="all"/><hr size="1"/>';
         $debug .= '<p ' . $font . '><b>' . YD_FW_NAMEVERS . ' Debug Information</b></p>';
         // Add the processing time
         $debug .= '<p ' . $font . '><i>Processing time</i></p>';
         $debug .= '<dd><p><table width="90%" border="1" cellspacing="0" cellpadding="2">';
         $debug .= sprintf('<tr><th %s>Elapsed</th><th %s>Diff</th><th %s>Marker</th></tr>', $font, $font, $font);
         foreach ($timings as $timing) {
             $debug .= sprintf('<tr><td %s>%s ms</td><td %s>%s ms</td><td %s>%s</td></tr>', $font, $timing[0], $font, $timing[1], $font, $timing[2]);
         }
         $debug .= '</table></p></dd>';
         // Add the included files
         $debug .= '<p ' . $font . '><i>Included files (' . $includeFilesSize . ')</i></p>';
         $debug .= '<dd><p><table width="90%" border="1" cellspacing="0" cellpadding="2">';
         $debug .= sprintf('<tr><th %s>File</th><th %s>Size</th></tr>', $font, $font);
         foreach ($includeFilesWithSize as $size => $file) {
             $debug .= sprintf('<tr><td %s>%s</td><td %s>%s</td></tr>', $font, realpath($file), $font, YDStringUtil::formatFileSize($size));
         }
         $debug .= '</table></p></dd>';
         // Add the query log
         if (sizeof($GLOBALS['YD_SQL_QUERY']) > 0) {
             $debug .= '<script src="' . YD_SELF_SCRIPT . '?do=JsShMain"></script>';
             $debug .= '<script src="' . YD_SELF_SCRIPT . '?do=JsShSql"></script>';
             $debug .= '<link rel="stylesheet" href="' . YD_SELF_SCRIPT . '?do=CssShStyle" type="text/css" />';
             $debug .= sprintf('<p ' . $font . '><i>SQL Query Log (%s queries)</i></p>', sizeof($GLOBALS['YD_SQL_QUERY']));
             $debug .= '<dd><p><table width="90%" border="1" cellspacing="0" cellpadding="2">';
             $debug .= sprintf('<tr><th %s>Query #</th><th %s>Trace</th><th %s>SQL Statement</th><th %s>Elapsed</th></tr>', $font, $font, $font, $font);
             foreach ($GLOBALS['YD_SQL_QUERY'] as $key => $query) {
                 $debug .= sprintf('<tr><td width="5%%" %s>%s</td><td width="15%%" %s>%s ms</td><td width="40%%" %s><pre>%s</pre></td><td width="40%%" %s><pre class="sh_sql">%s</pre></td></tr>', $font, $key, $font, $query['time'], $font, $query['trace'], $font, $query['sql']);
             }
             $debug .= '</table></p></dd>';
             $debug .= '<script>sh_highlightDocument();</script>';
             $debug .= '<script>sh_highlightDocument();</script>';
         }
         // Add the elapsed time
         $debug .= '<p ' . $font . '><i>Elapsed Time</i></p>';
         $debug .= '<dd><p>' . $GLOBALS['timer']->getElapsed() . ' ms</p></dd>';
         // Output the debug message
         echo $debug;
     }
     // Add the elapsed time
     die(YD_CRLF . '<!-- ' . $GLOBALS['timer']->getElapsed() . ' ms -->');
 }
 /**
  *	This is the function we use for finishing the request.
  *
  *	@internal
  */
 function finish()
 {
     // Mark that the request is processed
     define('YD_REQ_PROCESSED', 1);
     // Stop the timer
     $GLOBALS['timer']->finish();
     // Show debugging info if needed
     if (YDConfig::get('YD_DEBUG') == 1 || YDConfig::get('YD_DEBUG') == 2) {
         // Total size of include files
         $includeFiles = get_included_files();
         // Calculate the total size
         $includeFilesSize = 0;
         $includeFilesWithSize = array();
         foreach ($includeFiles as $key => $includeFile) {
             $includeFilesSize += filesize($includeFile);
             $includeFilesWithSize[filesize($includeFile)] = realpath($includeFile);
         }
         $includeFilesSize = YDStringUtil::formatFileSize($includeFilesSize);
         // Sort the list of include files by file size
         krsort($includeFilesWithSize);
         // Convert to a string
         $includeFiles = array();
         foreach ($includeFilesWithSize as $size => $file) {
             array_push($includeFiles, YDStringUtil::formatFileSize($size) . "\t  " . realpath($file));
         }
         // Create the debug messages
         $debug = YD_CRLF . YD_CRLF;
         // Create the timings report
         $debug .= 'Processing time(s):' . YD_CRLF . YD_CRLF;
         $debug .= "\tElapsed\t  Diff\t  Marker" . YD_CRLF;
         $timings = $GLOBALS['timer']->getReport();
         foreach ($timings as $timing) {
             $debug .= "\t" . $timing[0] . ' ms' . "\t  " . $timing[1] . ' ms' . "\t  " . $timing[2] . YD_CRLF;
         }
         $debug .= YD_CRLF;
         // Create the include file details
         $debug .= 'Total size include files: ' . $includeFilesSize . YD_CRLF . YD_CRLF;
         $debug .= 'Included files: ' . YD_CRLF . YD_CRLF . "\t" . implode("\n\t", $includeFiles) . YD_CRLF . YD_CRLF;
         // Create the list of include directories
         $debug .= 'Includes search path:' . YD_CRLF . YD_CRLF;
         foreach (explode(YD_PATHDELIM, ini_get('include_path')) as $path) {
             if (realpath($path)) {
                 $debug .= "\t" . realpath($path) . YD_CRLF;
             } else {
                 $debug .= "\t" . $path . YD_CRLF;
             }
         }
         $debug .= YD_CRLF;
         // If there is a database instance
         $debug .= 'Number of SQL queries: ' . sizeof($GLOBALS['YD_SQL_QUERY']) . YD_CRLF . YD_CRLF;
         // Add the queries if any
         if (sizeof($GLOBALS['YD_SQL_QUERY']) > 0) {
             $debug .= 'Executed SQL queries: ' . YD_CRLF . YD_CRLF;
             foreach ($GLOBALS['YD_SQL_QUERY'] as $key => $query) {
                 $debug .= "\t" . ($key + 1) . ': ' . trim($query) . YD_CRLF . YD_CRLF;
             }
         }
         // Output the debug message
         YDDebugUtil::debug($debug);
     }
     // Add the elapsed time
     $elapsed = $elapsed = $GLOBALS['timer']->getElapsed();
     echo YD_CRLF . '<!-- ' . $elapsed . ' ms -->';
     // Stop the execution of the request
     die;
 }