Changeset 258


Ignore:
Timestamp:
May 20, 2007 7:00:12 PM (17 years ago)
Author:
quinn
Message:

Added fileExistsIncludePath function, minor mods.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Utilities.inc.php

    r257 r258  
    157157   
    158158    foreach ($words as $w) {
    159         $search[] = '/\b(' . preg_quote($w) . ')\b/i';
    160         $replace[] = '<span class="' . $class . '">$1</span>';
    161     }
    162 
    163     return preg_replace($search, $replace, $text);
     159        if ('' != trim($w)) {
     160            $search[] = '/\b(' . preg_quote($w) . ')\b/i';
     161            $replace[] = '<span class="' . $class . '">$1</span>';
     162        }
     163    }
     164
     165    return empty($replace) ? $text : preg_replace($search, $replace, $text);
    164166}
    165167
     
    247249 * @since   29 Mar 2006 13:48:49
    248250 */
    249 function truncate($str, $len, $where='middle')
     251function truncate($str, $len, $where='middle', $delim='&hellip;')
    250252{
    251253    if ($len <= 3 || mb_strlen($str) <= 3) {
     
    256258    switch ($where) {
    257259    case 'start' :
    258         return preg_replace(array(sprintf('/^.{4,}(.{%s})$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array('...$1', '...'), $str);
     260        return preg_replace(array(sprintf('/^.{4,}(.{%s})$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array($delim . '$1', $delim), $str);
    259261        break;
    260262    default :
    261263    case 'middle' :
    262         return preg_replace(array(sprintf('/^(.{%s}).{4,}(.{%s})$/sU', $part1, $part2), '/\s*\.{3,}\s*/sU'), array('$1...$2', '...'), $str);
     264        return preg_replace(array(sprintf('/^(.{%s}).{4,}(.{%s})$/sU', $part1, $part2), '/\s*\.{3,}\s*/sU'), array('$1' . $delim . '$2', $delim), $str);
    263265        break;   
    264266    case 'end' :
    265         return preg_replace(array(sprintf('/^(.{%s}).{4,}$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array('$1...', '...'), $str);
     267        return preg_replace(array(sprintf('/^(.{%s}).{4,}$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array('$1' . $delim, $delim), $str);
    266268        break;   
    267269    }
     
    350352
    351353/**
    352  * Returns stats of a file from the include path.
     354 * Tests the existance of a file anywhere in the include path.
    353355 *
    354356 * @param   string  $file   File in include path.
    355  * @param   mixded  $stat   Which statistic to return (or null to return all).
    356  * @return  mixed   Value of requested key from fstat(), or false on error.
     357 * @return  mixed           False if file not found, the path of the file if it is found.
    357358 * @author  Quinn Comendant <quinn@strangecode.com>
    358359 * @since   03 Dec 2005 14:23:26
    359360 */
     361function fileExistsIncludePath($file)
     362{
     363    $app =& App::getInstance();
     364   
     365    foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) {
     366        $fullpath = $path . DIRECTORY_SEPARATOR . $file;
     367        if (file_exists($fullpath)) {
     368            $app->logMsg(sprintf('Found file "%s" at path: %s', $file, $fullpath), LOG_DEBUG, __FILE__, __LINE__);
     369            return $fullpath;
     370        } else {
     371            $app->logMsg(sprintf('File "%s" not found in include_path: %s', $file, get_include_path()), LOG_DEBUG, __FILE__, __LINE__);
     372            return false;
     373        }
     374    }
     375}
     376
     377/**
     378 * Returns stats of a file from the include path.
     379 *
     380 * @param   string  $file   File in include path.
     381 * @param   mixed   $stat   Which statistic to return (or null to return all).
     382 * @return  mixed           Value of requested key from fstat(), or false on error.
     383 * @author  Quinn Comendant <quinn@strangecode.com>
     384 * @since   03 Dec 2005 14:23:26
     385 */
    360386function statIncludePath($file, $stat=null)
    361387{
    362388    // Open file pointer read-only using include path.
    363389    if ($fp = fopen($file, 'r', true)) {
    364         // File opend successfully, get stats.
     390        // File opened successfully, get stats.
    365391        $stats = fstat($fp);
    366392        fclose($fp);
Note: See TracChangeset for help on using the changeset viewer.