Exemple #1
0
 /**
  * Compacta todos os arquivos .php de um diretório removendo comentários,
  * espaços e quebras de linhas desnecessárias.
  * motivos de desempenho e segurança esse método so interage em um diretório
  * de cada vez.
  *
  * @param string $directoryPath
  * @param string $newFilesDirectory
  * @param string $newFilesPrefix
  * @param string $newFilesSufix
  */
 public static function cleanDir($directoryPath, $newFilesDirectory = "packed", $newFilesPrefix = "", $newFilesSufix = "")
 {
     $dir = new DirectoryIterator($directoryPath);
     mkdir($directoryPath . "/{$newFilesDirectory}/");
     while ($dir->valid()) {
         if (!$dir->isDir() and !$dir->isDot() and substr($dir->getFilename(), -3, 3) == 'php') {
             $str = self::cleanFile($dir->getPathname());
             $fp = fopen($dir->getPath() . "/packed/" . $newFilesPrefix . $dir->getFilename() . $newFilesSufix, "w");
             fwrite($fp, $str);
             fclose($fp);
             echo $dir->getPathname() . ' - Renomeado com sucesso <br />';
         }
         $dir->next();
     }
 }
 /**
  * Returns the data of the current cache entry pointed to by the cache entry
  * iterator.
  *
  * @return mixed
  * @api
  */
 public function current()
 {
     if ($this->cacheFilesIterator === NULL) {
         $this->rewind();
     }
     return file_get_contents($this->cacheFilesIterator->getPathname());
 }
 protected function ProcessFile(DirectoryIterator $pParent, DirectoryIterator $pNode)
 {
     $oldname = $pNode->getPathname();
     $newname = $pParent->getPath() . '\\' . $this->GetLastFolderName($pParent->getPath()) . '.dds';
     rename($oldname, $newname);
     echo '<p>rename <b>' . $oldname . '</b> to <b>' . $newname . '<br/></p>';
 }
 /**
  * Returns the data of the current cache entry pointed to by the cache entry
  * iterator.
  *
  * @return mixed
  * @api
  */
 public function current()
 {
     if ($this->cacheFilesIterator === null) {
         $this->rewind();
     }
     $pathAndFilename = $this->cacheFilesIterator->getPathname();
     return $this->readCacheFile($pathAndFilename);
 }
 private function compileFile(\DirectoryIterator $file)
 {
     $tag = file_get_contents($file->getPathname());
     $tagName = $file->getBasename('.html');
     $jsFunc = $this->extractJsFunction($tag, $tagName);
     $tagHtml = $this->removeJsFromTag($tag, $tagName);
     $tagHtml = str_replace('"', '\\"', $tagHtml);
     $tagHtml = preg_replace("/\r|\n/", "", $tagHtml);
     return 'riot.tag("' . $tagName . '", "' . $tagHtml . '", ' . $jsFunc . ');';
 }
 /**
  * Returns the data of the current cache entry pointed to by the cache entry
  * iterator.
  *
  * @return mixed
  * @api
  */
 public function current()
 {
     if ($this->cacheFilesIterator === null) {
         $this->rewind();
     }
     $pathAndFilename = $this->cacheFilesIterator->getPathname();
     $lock = new Lock($pathAndFilename, false);
     $result = file_get_contents($pathAndFilename);
     $lock->release();
     return $result;
 }
 /**
  * @param DirectoryIterator $file
  */
 private function addFromFile(DirectoryIterator $file)
 {
     $match = preg_match('/([^.]+)-custom.definition.json/', $file->getFilename(), $matches);
     if (!$match) {
         return;
     }
     $dictionaryName = $matches[1];
     $translations = $this->loadTranslations($file->getPathname());
     foreach ($translations as $translationName => $translations) {
         $this->includeTranslation($dictionaryName, $translationName, $translations);
     }
 }
Exemple #8
0
 private static function load_plugin(ContextManager $context, DirectoryIterator $plugin_path)
 {
     $plugin_load_file = $plugin_path->getPathname() . DIRECTORY_SEPARATOR . 'init.php';
     if ($plugin_path->isDir() && is_file($plugin_load_file) && (require $plugin_load_file)) {
         $class = Plugins::plugin_class_name($plugin_path);
         try {
             $klass = new ReflectionClass($class);
             Plugins::add($klass->newInstance($context));
             $context->logger()->debugf('%s --> %s', str_replace(MEDICK_PATH, '${' . $context->config()->application_name() . '}', $plugin_load_file), $class);
         } catch (ReflectionException $rfEx) {
             $context->logger()->warn('failed to load plugin `' . $plugin_path->getFilename() . '`: ' . $rfEx->getMessage());
         }
     }
 }
 /**
  * Scan the files in the configured path for controllers
  *
  * To dynamically scan controllers from the source files
  * use PHP Reflection to find the controllers.
  *
  * The returning result is an array of Admin_Model_DbRow_Controller elements
  *
  * @return array
  */
 public function getControllers()
 {
     $resources = array();
     $directory = new DirectoryIterator($this->path);
     $CcFilter = new Zend_Filter_Word_CamelCaseToDash();
     while ($directory->valid()) {
         if ($directory->isFile() && !in_array($directory->getFilename(), $this->skip, TRUE)) {
             // load the file
             require_once $directory->getPathname();
             $reflect = new Zend_Reflection_File($directory->getPathName());
             $name = substr($reflect->getClass()->getName(), strrpos($reflect->getClass()->getName(), "_") + 1);
             $controller = new Admin_Model_DbRow_Controller(array('moduleName' => 'webdesktop', 'controllerName' => strtolower($name), 'virtual' => 1));
             $resources[] = $controller;
         }
         $directory->next();
     }
     return $resources;
 }
/**
 * Iterates over a directory and returns file objects.
 *
 * @param string $dir
 * @param mixed $filter
 * @param bool $recursive defaults to false
 * @param bool $addDirs return directories as well as files - defaults to false
 * @return array
 *
 */
function getFilesInDir($dir, $filter = '', $recursive = false, $addDirs = false)
{
    $res = array();
    $dirIterator = new DirectoryIterator($dir);
    while ($dirIterator->valid()) {
        if (!$dirIterator->isDot()) {
            $file = $dirIterator->getPathname();
            $isDir = is_dir($file);
            if (!$isDir || $addDirs) {
                if (empty($filter) || fnmatch($filter, $file)) {
                    $res[] = $file;
                }
            }
            if ($isDir && $recursive) {
                $res = array_merge($res, getFilesInDir($file, $filter = '', $recursive));
            }
        }
        $dirIterator->next();
    }
    return $res;
}
/**
 * Iteratively remove/delete a directory and its contents
 *
 * @param DirectoryIterator $path base directory (inclusive) to recursively delete.
 */
function recursivelyDeleteDirectory(DirectoryIterator $path)
{
    // echo $path . " being deleted?";
    if ($path->isDir()) {
        $directory = new DirectoryIterator($path->getPath() . DIRECTORY_SEPARATOR . $path->getFilename());
        // For each element within this directory, delete it or recurse into next directory
        foreach ($directory as $object) {
            if (!$object->isDot()) {
                if ($object->isDir()) {
                    recursivelyDeleteDirectory($object);
                } else {
                    unlink($object->getPathname());
                }
            }
        }
        rmdir($path->getPathname());
    } else {
        // Not a directory...
        // Do nothing
    }
}
Exemple #12
0
function getDirInfo($dir)
{
    $iterator = new DirectoryIterator($dir);
    #先输出文件夹
    while ($iterator->valid()) {
        if ($iterator->isDir() && $iterator->getFilename() != '.' && $iterator->getFilename() != '..' && $iterator->getFilename() != '.git') {
            echo '<li class="flist filedir"><i class="fa fa-folder-open"></i> ' . $iterator->getFilename();
            echo '<ul class="dirlist">';
            getDirInfo($iterator->getPathname());
            echo '</ul></li>';
        }
        $iterator->next();
    }
    #再输出文件
    $iterator->Rewind();
    while ($iterator->valid()) {
        if ($iterator->isFile()) {
            echo '<li class="flist file"><i class="fa fa-file-text"></i> ' . $iterator->getFilename() . '</li>';
        }
        $iterator->next();
    }
}
 /**
  * Removes the given directory recursive.
  *
  * @param DirectoryIterator $it The context directory iterator.
  *
  * @return void
  */
 private static function deleteDirectoryRecursive(DirectoryIterator $it)
 {
     foreach ($it as $file) {
         if ($it->isDot()) {
             continue;
         } else {
             if ($it->isDir()) {
                 self::deleteDirectoryRecursive($it->getChildren());
                 rmdir($it->getPathname());
             } else {
                 unlink($it->getPathname());
             }
         }
     }
 }
Exemple #14
0
			</div>
		</div>
	</form>
</div>

<pre>
<?php 
if ($_POST) {
    $path = $_POST['path'];
    $ext = isset($_POST['ext']) ? $_POST['ext'] : 'zip';
    echo $path . PHP_EOL;
    $dir = new DirectoryIterator($path);
    $batch = '';
    while ($dir->valid()) {
        if ($dir->isDir() && !$dir->isDot()) {
            $source_dir = $dir->getPathname();
            $dest_file = $source_dir . '.' . $ext;
            $command = "7z a \"{$dest_file}\" \"{$source_dir}\\*\" -tzip -mx0" . PHP_EOL;
            echo $command;
            $batch .= $command;
        }
        $dir->next();
    }
    $final = $path . '\\' . 'zip.bat';
    echo $final . PHP_EOL;
    var_dump(file_put_contents($final, $batch));
}
?>
</pre>
<?php 
include '_footer.php';
Exemple #15
0
<div class="container-fluid full-height">
    <div class="row full-height">
        <div class="col-md-12 full-height main-frame-container">
            <div class="panel panel-primary main-frame">
                <div class="panel-heading">Package Manager</div>
                <div class="panel-body">
                    <div class="file-detail full-height col-md-4"></div>
                    <div class="file-manager scroll-pane full-height col-md-12">
                        <?php 
$files_array = array();
$dir = new DirectoryIterator(dirname(__FILE__) . "/packages");
while ($dir->valid()) {
    if (!$dir->isDot() && $dir->isDir()) {
        // sort key, ie. modified timestamp
        $key = $dir->getCTime();
        $data = array($dir->getFilename(), dirsize($dir->getPathname()));
        $files_array[$key] = $data;
    }
    $dir->next();
}
ksort($files_array);
$files_array = array_reverse($files_array, true);
foreach ($files_array as $key => $fileinfo) {
    ?>
                                <div class="dir-item" data-package="<?php 
    echo $fileinfo[0];
    ?>
"><a href="?package=<?php 
    echo $fileinfo[0];
    ?>
" onClick="return false;">
 /**
  * Does garbage collection
  *
  * @return void
  * @api
  */
 public function collectGarbage()
 {
     if ($this->frozen === TRUE) {
         return;
     }
     for ($directoryIterator = new \DirectoryIterator($this->cacheDirectory); $directoryIterator->valid(); $directoryIterator->next()) {
         if ($directoryIterator->isDot()) {
             continue;
         }
         if ($this->isCacheFileExpired($directoryIterator->getPathname())) {
             $this->remove($directoryIterator->getBasename($this->cacheEntryFileExtension));
         }
     }
 }
    }
    return $haystack;
}
function stripSpaces($haystack)
{
    return preg_replace('/\\s+/u', ' ', $haystack[0]);
}
function stripSpacesNewline($haystack)
{
    return preg_replace('/\\s+/u', ' ', $haystack[0]) . "\n";
}
$dir = new DirectoryIterator($path);
$pages = array();
while ($dir->valid()) {
    if (!$dir->isDot() && substr($dir->getFilename(), -3) == 'xml') {
        array_push($pages, $dir->getPathname());
    }
    $dir->next();
}
asort($pages);
foreach ($pages as $key => $wikipage) {
    $tmp = processIncludes(file_get_contents($wikipage));
    $tmp = preg_replace_callback('/(?:<para>\\s*)+(.+?)<\\/para>/si', 'stripSpaces', $tmp);
    $tmp = preg_replace_callback('/(?:<note>\\s*)+(.+?)<\\/note>/si', 'stripSpaces', $tmp);
    $tmp = preg_replace_callback('/(?:<tip>\\s*)+(.+?)<\\/tip>/si', 'stripSpaces', $tmp);
    $tmp = preg_replace_callback('/(?:<thead>\\s*)+(.+?)<\\/thead>/si', 'stripSpaces', $tmp);
    $tmp = preg_replace_callback('/(?:<tbody>\\s*)+(.+?)<\\/tbody>/si', 'stripSpaces', $tmp);
    $tmp = preg_replace_callback('/(?:<tip>\\s*)+(.+?)<\\/tip>/si', 'stripSpaces', $tmp);
    $tmp = preg_replace_callback('/(?:<listitem>\\s*)+(.+?)<\\/listitem>/si', 'stripSpaces', $tmp);
    $tmp = preg_replace_callback('/(?:<row>\\s*)+(.+?)<\\/row>/si', 'stripSpacesNewLine', $tmp);
    $data = '<chapter>';
 public function buildTableRow(DirectoryIterator $file, $includeParentDirectoryDots = true)
 {
     if (!$file->isDot() && substr($file->getFilename(), 0, 1) == '.' && Administration::instance()->Configuration->get('show-hidden', 'filemanager') != 'yes') {
         return;
     } elseif ($file->isDot() && !$includeParentDirectoryDots && $file->getFilename() == '..') {
         return;
     } elseif ($file->getFilename() == '.') {
         return;
     }
     $relpath = str_replace($this->getStartLocation() == '' ? DOCROOT : DOCROOT . $this->getStartLocation(), NULL, $file->getPathname());
     if (!$file->isDir()) {
         //if(File::fileType($file->getFilename()) == self::CODE)
         //	$download_uri = self::baseURL() . 'edit/?file=' . urlencode($relpath);
         //else
         $download_uri = self::baseURL() . 'download/?file=' . urlencode($relpath);
     } else {
         $download_uri = self::baseURL() . 'properties/?file=' . urlencode($relpath) . '/';
     }
     if (!$file->isDot()) {
         $td1 = Widget::TableData(Widget::Anchor($file->getFilename(), self::baseURL() . ($file->isDir() ? 'browse' . $relpath . '/' : 'properties/?file=' . urlencode($relpath)), NULL, 'file-type ' . ($file->isDir() ? 'folder' : File::fileType($file->getFilename()))));
         //$group = (function_exists('posix_getgrgid') ? posix_getgrgid($file->getGroup()) : $file->getGroup());
         //$owner = (function_exists('posix_getpwuid') ? posix_getpwuid($file->getOwner()) : $file->getOwner());
         $group = $file->getGroup();
         $owner = $file->getOwner();
         $td3 = Widget::TableData(File::getOctalPermission($file->getPerms()) . ' <span class="inactive">' . File::getReadablePerm($file->getPerms()), NULL, NULL, NULL, array('title' => (isset($owner['name']) ? $owner['name'] : $owner) . ', ' . (isset($group['name']) ? $group['name'] : $group)) . '</span>');
         $td4 = Widget::TableData(DateTimeObj::get(__SYM_DATETIME_FORMAT__, $file->getMTime()));
         if ($file->isWritable()) {
             if ($file->isDir()) {
                 $td5 = Widget::TableData(Widget::Anchor('Edit', $download_uri));
             } else {
                 $td5 = Widget::TableData(Widget::Anchor('Download', $download_uri));
             }
         } else {
             $td5 = Widget::TableData('-', 'inactive');
         }
     } else {
         $td1 = Widget::TableData(Widget::Anchor('&crarr;', self::baseURL() . 'browse' . $relpath . '/'));
         $td3 = Widget::TableData('-', 'inactive');
         $td4 = Widget::TableData('-', 'inactive');
         $td5 = Widget::TableData('-', 'inactive');
     }
     $td2 = Widget::TableData($file->isDir() ? '-' : General::formatFilesize($file->getSize()), $file->isDir() ? 'inactive' : NULL);
     $startlocation = DOCROOT . $this->getStartLocation();
     if (!$file->isDot()) {
         $td5->appendChild(Widget::Input('items[' . str_replace($startlocation, '', $file->getPathname()) . ($file->isDir() ? '/' : NULL) . ']', NULL, 'checkbox'));
     }
     return Widget::TableRow(array($td1, $td2, $td3, $td4, $td5));
 }
    /**
     * Entity/Model
     * @param DirectoryIterator $fileInfo
     */
    private function patchEntityModel(\DirectoryIterator $fileInfo)
    {
        if ($fileInfo->isFile()) {
            $filePath = $fileInfo->getPathname();
            $content = file_get_contents($filePath);
            $imeplements = ['\\Common\\CoreBundle\\Type\\EntityInterface'];
            if (preg_match('#(abstract class [^\\\\]*?\\s+?implements\\s+?)(.*)#', $content, $m)) {
                $m = explode(',', $m[2]);
                array_walk($m, 'trim');
                $imeplements = array_merge($imeplements, $m);
            }
            if (preg_match('/toArray/', $content)) {
                $imeplements[] = '\\Common\\CoreBundle\\Type\\ArraybleInterface';
            }
            $imeplements = array_values($imeplements);
            $imeplements = array_map('trim', $imeplements);
            $imeplements = implode(', ', $imeplements);
            $content = preg_replace("#(abstract class [^\\\\]*?)(\\s+?implements\\s+?)(.*)(\n\\{)#", '\\1\\4', $content);
            $content = preg_replace("/(abstract class .*?)(\n\\{)/", '\\1 implements ' . $imeplements . '\\2', $content);
            if (preg_match('/Type\\\\/', $content)) {
                $content = preg_replace('#\\\\Common\\\\CoreBundle\\\\Type#', 'Type', $content);
                $content = preg_replace('/namespace (.*?);/', 'namespace \\1;' . "\n\n" . 'use Common\\CoreBundle\\Type;', $content);
            }
            $isObservable = (bool) strpos($imeplements, 'ObservableInterface');
            $contentMap = ['/\\\\DateInterval/' => 'Type\\DateInterval', '/\\?\\s+?(\\$this->.*?)->format\\(\'Y-m-d\'\\)\\s+?:/' => '? \\1->format(Type\\Date::DEFAULT_FORMAT) :', '/\\?\\s+?(\\$this->.*?)->format\\(\'Y-m-d H:i:s\'\\)\\s+?:/' => '? \\1->format(Type\\DateTime::DEFAULT_FORMAT) :', '/\\?\\s+?(\\$this->.*?)->format\\(\'Y-m-d H:i:s\\.u\'\\)\\s+?:/' => '? Type\\DateTime::_foramt(\\1) :', '/\\?\\s+?(\\$this->.*?)->format\\(\'P%yY%mM%dDT%hH%iI%sS\'\\)\\s+?:/' => '? \\1->format(null) :', '/(\\s+)(\\*)(\\s+)\\n/' => '\\1\\2' . "\n"];
            if ($isObservable) {
                $contentMap['/(abstract class .*?)(\\n\\{)/'] = '\\1\\2' . <<<PHP

    use Type\\ModelTrait;
    use Type\\ObservableTrait;

PHP;
            } else {
                $contentMap['/(abstract class .*?)(\\n\\{)/'] = '\\1\\2' . <<<PHP

    use Type\\ModelTrait;

PHP;
            }
            $from = array_keys($contentMap);
            $to = array_values($contentMap);
            $content = preg_replace($from, $to, $content);
            $content = preg_replace("/(use .*?;)\n{2}(use .*?;)/", '\\1' . "\n" . '\\2', $content);
            file_put_contents($filePath, $content);
            if ($isObservable) {
                $this->removeObservable($filePath);
            }
        }
    }
Exemple #20
0
function disney_zip()
{
    $input = 'D:\\Comic\\!Disney';
    $output = 'D:\\Temp\\Disney';
    $dir = new DirectoryIterator($input);
    while ($dir->valid()) {
        if ($dir->isDir() && !$dir->isDot()) {
            $author = $dir->getFilename();
            $author_path = $output . '/' . $author;
            if (!is_dir($author_path)) {
                mkdir($author_path);
            }
            $bat = "cd {$dir->getPathname()}" . PHP_EOL;
            $dir_comic = new DirectoryIterator($dir->getPathname());
            while ($dir_comic->valid()) {
                if ($dir_comic->isDir() && !$dir_comic->isDot()) {
                    $comic = $dir_comic->getFilename();
                    $comic_path = $author_path . '/' . $comic;
                    $bat .= "7z a \"{$comic_path}.zip\" \".\\{$comic}\\*\" -tzip -mx0" . PHP_EOL;
                }
                $dir_comic->next();
            }
            echo $bat;
        }
        $dir->next();
    }
}
Exemple #21
0
}
echo "<br>";
$editedOutputIterator = new DirectoryIterator($appRoot . trim(Config::_EDITED_CONVERTED_FILEDIR, '/') . DS);
while ($editedOutputIterator->valid()) {
    $fname = $editedOutputIterator->getFilename();
    if ($fname != '.' && $fname != '..' && $editedOutputIterator->getMTime() + $maxAgeFiles < time()) {
        echo $editedOutputIterator->getPathname() . "<br>";
        //unlink($editedOutputIterator->getPathname());
    }
    $editedOutputIterator->next();
}
echo "<br>";
$tempVidsIterator = new DirectoryIterator($appRoot . trim(Config::_TEMPVIDDIR, '/') . DS);
while ($tempVidsIterator->valid()) {
    $fname = $tempVidsIterator->getFilename();
    if ($fname != '.' && $fname != '..' && $tempVidsIterator->getMTime() + $maxAgeFiles < time()) {
        echo $tempVidsIterator->getPathname() . "<br>";
        //unlink($tempVidsIterator->getPathname());
    }
    $tempVidsIterator->next();
}
echo "<br>";
$logsIterator = new DirectoryIterator($appRoot . trim(Config::_LOGSDIR, '/') . DS);
while ($logsIterator->valid()) {
    $fname = $logsIterator->getFilename();
    if ($fname != '.' && $fname != '..' && $logsIterator->getMTime() + $maxAgeFiles < time()) {
        echo $logsIterator->getPathname() . "<br>";
        //unlink($logsIterator->getPathname());
    }
    $logsIterator->next();
}
 /**
  * {@inheritDoc}
  */
 protected function determinePresentFiles($language)
 {
     $iterator = new \DirectoryIterator($this->getDestinationBasePath() . DIRECTORY_SEPARATOR . $language);
     $files = array();
     while ($iterator->valid()) {
         if (!$iterator->isDot() && $iterator->isFile() && $this->isValidDestinationFile($iterator->getPathname())) {
             $files[] = $iterator->getFilename();
         }
         $iterator->next();
     }
     return $files;
 }
Exemple #23
0
function files($path, $recursive = false)
{
    $it = new DirectoryIterator($path);
    $files = array();
    while ($it->valid()) {
        if (is_file($it->getPathname()) && !$it->isDot() && $it->getFilename() != '.git') {
            $files[] = $recursive ? $it->getPathname() : $it->getFilename();
        } elseif (is_dir($it->getPathname()) && !$it->isDot() && $it->getFilename() != '.git' && $recursive) {
            $files = array_merge($files, files($it->getPathname(), $recursive));
        }
        $it->next();
    }
    return $files;
}
Exemple #24
0
 /**
  * Get icon pack data
  *
  * @since  0.1.0
  * @access protected
  * @param  DirectoryIterator $pack_dir Icon pack directory object.
  * @return array Icon pack data array or FALSE.
  */
 protected function get_pack_data(DirectoryIterator $pack_dir)
 {
     $pack_dirname = $pack_dir->getFilename();
     $pack_path = $pack_dir->getPathname();
     $cache_id = "icon_picker_fontpack_{$pack_dirname}";
     $cache_data = get_transient($cache_id);
     $config_file = "{$pack_path}/config.json";
     if (false !== $cache_data && $cache_data['version'] === $pack_dir->getMTime()) {
         return $cache_data;
     }
     // Make sure the config file exists and is readable.
     if (!is_readable($config_file)) {
         trigger_error(sprintf(esc_html($this->messages['no_config']), '<code>config.json</code>', sprintf('<code>%s</code>', esc_html($pack_path))));
         return false;
     }
     $config = json_decode(file_get_contents($config_file), true);
     $errors = json_last_error();
     if (!empty($errors)) {
         trigger_error(sprintf(esc_html($this->messages['config_error']), sprintf('<code>%s/config.json</code>', esc_html($pack_path))));
         return false;
     }
     $keys = array('name', 'glyphs', 'css_prefix_text');
     $items = array();
     // Check each required config.
     foreach ($keys as $key) {
         if (empty($config[$key])) {
             trigger_error(sprintf(esc_html($this->messages['invalid']), sprintf('<code><em>%s</em></code>', esc_html($key)), esc_html($config_file)));
             return false;
         }
     }
     // Bail if no glyphs found.
     if (!is_array($config['glyphs']) || empty($config['glyphs'])) {
         return false;
     }
     foreach ($config['glyphs'] as $glyph) {
         if (!empty($glyph['css'])) {
             $items[] = array('id' => $config['css_prefix_text'] . $glyph['css'], 'name' => $glyph['css']);
         }
     }
     if (empty($items)) {
         return false;
     }
     $pack_data = array('id' => "pack-{$config['name']}", 'name' => sprintf(__('Pack: %s', 'icon-picker'), $config['name']), 'version' => $pack_dir->getMTime(), 'items' => $items, 'stylesheet_uri' => "{$this->url}/{$pack_dirname}/css/{$config['name']}.css", 'dir' => "{$this->dir}/{$pack_dirname}", 'url' => "{$this->url}/{$pack_dirname}");
     set_transient($cache_id, $pack_data, DAY_IN_SECONDS);
     return $pack_data;
 }
Exemple #25
0
 /**
  * Does garbage collection
  *
  * @return void
  * @api
  */
 public function collectGarbage()
 {
     if ($this->frozen === TRUE) {
         return;
     }
     for ($directoryIterator = new \DirectoryIterator($this->cacheDirectory); $directoryIterator->valid(); $directoryIterator->next()) {
         if ($directoryIterator->isDot()) {
             continue;
         }
         if ($this->isCacheFileExpired($directoryIterator->getPathname())) {
             $cacheEntryFileExtensionLength = strlen($this->cacheEntryFileExtension);
             if ($cacheEntryFileExtensionLength > 0) {
                 $this->remove(substr($directoryIterator->getFilename(), 0, -$cacheEntryFileExtensionLength));
             } else {
                 $this->remove($directoryIterator->getFilename());
             }
         }
     }
 }
Exemple #26
0
 /**
  * Delete old cached files based on cache time and cache gc probability set
  * in the config file.
  */
 private function clean_cache()
 {
     //gc probability
     $gc = rand(1, Kohana::config($this->type . '.cache_gc'));
     if ($gc != 1) {
         return FALSE;
     }
     $cache = new DirectoryIterator(Kohana::config($this->type . '.cache_folder'));
     while ($cache->valid()) {
         // if file is past maximum cache settings delete file
         $cached = date('U', $cache->getMTime());
         $max = time() + Kohana::config($this->type . '.cache_clean_time');
         if ($cache->isFile() and $cached > $max) {
             unlink($cache->getPathname());
         }
         $cache->next();
     }
 }
Exemple #27
0
 /**
  * @param string $src_dir
  * @param string $dst_dir
  *
  * @throws \Exception
  */
 protected static function copyHooksDir($src_dir, $dst_dir)
 {
     $fs = new Filesystem();
     $fs->mirror($src_dir, $dst_dir, null, ['override' => true]);
     $file = new \DirectoryIterator($src_dir);
     $mask = umask();
     while ($file->valid()) {
         if ($file->isFile() && is_executable($file->getPathname())) {
             $fs->chmod("{$dst_dir}/" . $file->getBasename(), 0777, $mask);
         }
         $file->next();
     }
 }
Exemple #28
0
 /**
  * Получить очередную пару файлов для слияния.
  *
  * @param \DirectoryIterator $files
  * @param $suffix
  * @return array
  */
 protected function nextPair(\DirectoryIterator $files, $suffix)
 {
     $res = [];
     while ($files->valid() && count($res) < 2) {
         $fileSuffix = substr($files->current(), -strlen($suffix));
         if (strcmp($fileSuffix, $suffix) == 0) {
             $res[] = $files->getPathname();
         }
         $files->next();
     }
     return array_pad($res, 2, null);
 }
/**
 * Automatically find and create drush aliases on the server.
 * @param  array $aliases  array of drush aliases
 */
function _elmsln_alises_build_server(&$aliases, &$authorities = array())
{
    // static cache assembled aliases as this can get tripped often
    static $pulledaliases = array();
    static $pulledauthorities = array();
    static $config = array();
    // check for pervasive cache if static is empty
    if (empty($pulledaliases)) {
        // assumption here is that it lives where we expect
        // change this line if that's not the case though we really don't
        // support changes to that part of the install routine
        $cfg = file_get_contents('/var/www/elmsln/config/scripts/drush-create-site/config.cfg');
        $lines = explode("\n", $cfg);
        // read each line of the config file
        foreach ($lines as $line) {
            // make sure this line isn't a comment and has a = in it
            if (strpos($line, '#') !== 0 && strpos($line, '=')) {
                $tmp = explode('=', $line);
                // ensure we have 2 settings before doing this
                if (count($tmp) == 2) {
                    // never pass around the dbsu
                    if (!in_array($tmp[0], array('dbsu', 'dbsupw'))) {
                        // strip encapsulation if it exists
                        $config[$tmp[0]] = str_replace('"', '', str_replace("'", '', $tmp[1]));
                    }
                }
            }
        }
        // support the fact that $elmsln is used to reference in many bash vars
        foreach ($config as $key => $value) {
            if (strpos($value, '$elmsln') !== FALSE) {
                $config[$key] = str_replace('$elmsln', $config['elmsln'], $value);
            }
        }
        // base address of all domains
        $address = $config['address'];
        // your web root
        $root = $config['stacks'] . '/';
        // calculate the stacks we have
        $stacks = array();
        $stackfinder = new DirectoryIterator("{$root}");
        while ($stackfinder->valid()) {
            // Look for directories that are stacks
            if ($stackfinder->isDir() && !$stackfinder->isDot() && !$stackfinder->isLink()) {
                $stacks[] = $stackfinder->getBasename();
            }
            $stackfinder->next();
        }
        // loop through known stacks
        foreach ($stacks as $stack) {
            // step through sites directory assuming it isn't the 'default'
            if ($stack != 'default' && is_dir("{$root}{$stack}/sites/{$stack}")) {
                try {
                    $stackdir = new DirectoryIterator("{$root}{$stack}/sites/{$stack}");
                    while ($stackdir->valid()) {
                        // Look for directories containing a 'settings.php' file
                        if ($stackdir->isDir() && !$stackdir->isDot() && !$stackdir->isLink()) {
                            $group = $stackdir->getBasename();
                            // only include stack if it has things we can step through
                            // this helps avoid issues of unused stacks throwing errors
                            if (file_exists("{$root}{$stack}/sites/{$stack}/{$group}")) {
                                // build root alias for the stack
                                $pulledauthorities[$stack] = array('root' => $root . $stack, 'uri' => "{$stack}.{$address}");
                                // step through sites directory
                                if (is_dir("{$root}{$stack}/sites/{$stack}/{$group}")) {
                                    $site = new DirectoryIterator("{$root}{$stack}/sites/{$stack}/{$group}");
                                    while ($site->valid()) {
                                        // Look for directories containing a 'settings.php' file
                                        if ($site->isDir() && !$site->isDot() && !$site->isLink()) {
                                            if (file_exists($site->getPathname() . '/settings.php')) {
                                                // Add site alias
                                                $basename = $site->getBasename();
                                                // test that this isn't actually something like coursename = host
                                                if ($basename == $config['host'] && !is_dir("{$root}{$stack}/sites/{$stack}/{$group}/{$group}")) {
                                                    $pulledaliases["{$stack}.{$basename}"] = array('root' => $root . $stack, 'uri' => "{$stack}.{$address}");
                                                } else {
                                                    $pulledaliases["{$stack}.{$basename}"] = array('root' => $root . $stack, 'uri' => "{$stack}.{$address}.{$basename}");
                                                }
                                            }
                                        }
                                        $site->next();
                                    }
                                }
                            }
                        }
                        $stackdir->next();
                    }
                } catch (Exception $e) {
                    // that tool doesn't have a directory, oh well
                }
            }
        }
    }
    $aliases = $pulledaliases;
    $authorities = $pulledauthorities;
    return $config;
}
Exemple #30
0
 /**
  * Process file
  *
  * @param int $directoryID
  * @param DirectoryIterator $entries
  */
 protected final function _processFile($directoryID, DirectoryIterator $entries)
 {
     $scanID = $this->_scanRow->scanID;
     // Load row when exists
     $fileRow = $this->_fileTable->fetchRow(array('directoryID' => $directoryID, 'name' => $entries->getFilename()));
     // Already scanned
     if ($fileRow && $fileRow->lastScanID == $scanID) {
         return;
     }
     $pathname = $entries->getPathname();
     // Data
     $data = array('modifyDate' => $this->_normalizeDate($entries->getMTime()), 'owner' => $this->_normalizeUser($entries->getOwner()), 'group' => $this->_normalizeGroup($entries->getGroup()), 'permissions' => $entries->getPerms(), 'size' => $entries->getSize(), 'linkTarget' => $entries->isLink() ? $entries->getLinkTarget() : null);
     // Content
     $contentHash = null;
     if (!$entries->isLink() && ($this->_alwaysCheckContent || !$fileRow || $fileRow->modifyDate != $data['modifyDate'] || $fileRow->size != $data['size'])) {
         // Non-accessible file
         if (!is_readable($pathname)) {
             $this->_log(self::LOG_ERROR, "\t{$pathname} cannot be read.");
             if ($fileRow) {
                 $contentHash = $fileRow->contentHash;
             }
         } else {
             $contentHash = md5_file($pathname);
         }
     }
     // Transaction
     $this->_db->beginTransaction();
     // New row
     if ($newRow = !$fileRow) {
         fwrite(STDOUT, "\t{$pathname} is new.\n");
         $fileRow = $this->_createFileRow(array('directoryID' => $directoryID, 'name' => $entries->getFilename()) + $data);
     }
     // Store values
     $oldValues = $fileRow->toArray();
     // Content
     if ($fileRow->contentHash != $contentHash) {
         $data['contentHash'] = $contentHash;
         if ($this->_storagePath) {
             $data['storedAs'] = $this->_copyFile($fileRow->fileID, $entries);
         }
     }
     // Update row
     $this->_updateFileRow($pathname, $fileRow, $data);
     $fileRow->lastScanID = $scanID;
     $fileRow->save();
     // Scan row update
     $this->_scanRow->lastOperationDate = new SeekR_Expression('NOW()');
     $this->_scanRow->save();
     // Transaction
     $this->_db->commit();
 }