Ejemplo n.º 1
0
 /**
  * Search text in files using regexps (recursively through folders).
  * Assumes egrep is available if not on windows
  */
 static function searchInFiles($searchtext, $cachedir, $is_regexp = true)
 {
     //$fileHandler = eZClusterFileHandler::instance();
     $result = array();
     if (eZSys::osType() != 'win32') {
         if ($is_regexp) {
             exec('egrep -s -R -l "' . str_replace('"', '\\"', $searchtext) . "\" \"{$cachedir}\"", $result);
         } else {
             exec('fgrep -s -R -l "' . str_replace('"', '\\"', $searchtext) . "\" \"{$cachedir}\"", $result);
         }
     } else {
         $files = @scandir($cachedir);
         if ($files === false) {
             return array();
         }
         foreach ($files as $file) {
             if ($file != '.' && $file != '..') {
                 if (is_dir($cachedir . '/' . $file)) {
                     $result = array_merge($result, sysInfoTools::searchInFiles($searchtext, $cachedir . '/' . $file, $is_regexp));
                 } else {
                     $txt = @file_get_contents($cachedir . '/' . $file);
                     /// @todo escape properly #
                     if ($is_regexp) {
                         if (preg_match("#" . $searchtext . "#", $txt)) {
                             $result[] = $cachedir . '/' . $file;
                         }
                     } else {
                         if (strpos($txt, $searchtext) !== false) {
                             $result[] = $cachedir . '/' . $file;
                         }
                     }
                     $txt = false;
                     // free memory asap
                 }
             }
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
foreach ($cacheList as $cacheItem) {
    if ($cacheItem['path'] != false && $cacheItem['enabled']) {
        $cacheDirsList[$cacheItem['id']] = $cacheItem['path'];
        $cacheDirsList2[$cacheItem['id']] = false;
    }
}
if ($http->hasPostVariable('SearchText') && $http->hasPostVariable('SearchCaches')) {
    $ini = eZINI::instance();
    $cachedir = eZSys::cacheDirectory();
    //$cachedir .= "/" .$ini->variable( 'ContentSettings', 'CacheDir' );
    $searchtext = $http->postVariable('SearchText');
    $is_regexp = $http->hasPostVariable('SearchType') && $http->postVariable('SearchType') == 'Regexp';
    foreach ($http->postVariable('SearchCaches') as $cache) {
        if (array_key_exists($cache, $cacheDirsList)) {
            // take care: this is hardcoded from knowledge of cache structure...
            if ($cacheDirsList[$cache] == 'var/cache/ini') {
                $filelist = array_merge($filelist, sysInfoTools::searchInFiles($searchtext, eZSys::siteDir() . '/' . $cacheDirsList[$cache], $is_regexp));
            } else {
                $filelist = array_merge($filelist, sysInfoTools::searchInFiles($searchtext, $cachedir . '/' . $cacheDirsList[$cache], $is_regexp));
            }
            $cacheDirsList2[$cache] = true;
        }
    }
    //print_r($filelist);
}
$tpl->setVariable('filelist', $filelist);
$tpl->setVariable('list_count', count($filelist));
$tpl->setVariable('searchtext', $searchtext);
$tpl->setVariable('cachelist', $cacheDirsList2);
$tpl->setVariable('deletedfiles', $deletedfiles);
$tpl->setVariable('is_regexp', $is_regexp);