/**
  * Executes this task.
  */
 public function main()
 {
     if ($this->path === null) {
         throw new BuildException('The path attribute must be specified');
     }
     $check = new AgaviModuleFilesystemCheck();
     $check->setConfigDirectory($this->project->getProperty('module.config.directory'));
     $check->setPath($this->path->getAbsolutePath());
     if (!$check->check()) {
         throw new BuildException('The path attribute must be a valid module base directory');
     }
     /* We don't know whether the module is configured or not here, so load the
      * values we want properly. */
     $this->tryLoadAgavi();
     $this->tryBootstrapAgavi();
     require_once AgaviConfigCache::checkConfig(sprintf('%s/%s/module.xml', $this->path->getAbsolutePath(), (string) $this->project->getProperty('module.config.directory')));
     $actionPath = AgaviToolkit::expandVariables(AgaviToolkit::expandDirectives(AgaviConfig::get(sprintf('modules.%s.agavi.action.path', strtolower($this->path->getName())), '%core.module_dir%/${moduleName}/actions/${actionName}Action.class.php')), array('moduleName' => $this->path->getName()));
     $pattern = '#^' . AgaviToolkit::expandVariables(str_replace('\\$\\{actionName\\}', '${actionName}', preg_quote($actionPath, '#')), array('actionName' => '(?P<action_name>.*?)')) . '$#';
     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path->getAbsolutePath()));
     for (; $iterator->valid(); $iterator->next()) {
         $rdi = $iterator->getInnerIterator();
         if ($rdi->isDot() || !$rdi->isFile()) {
             continue;
         }
         $file = $rdi->getPathname();
         if (preg_match($pattern, $file, $matches)) {
             $this->log(str_replace(DIRECTORY_SEPARATOR, '.', $matches['action_name']));
         }
     }
 }
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $behaviors = ArrayHelper::merge(parent::behaviors(), ['authenticator' => ['class' => CompositeAuth::className(), 'authMethods' => [['class' => HttpBearerAuth::className()], ['class' => QueryParamAuth::className(), 'tokenParam' => 'accessToken']]], 'exceptionFilter' => ['class' => ErrorToExceptionFilter::className()], 'corsFilter' => ['class' => \backend\rest\filters\Cors::className(), 'cors' => ['Origin' => ['*'], 'Access-Control-Request-Method' => ['POST', 'PUT', 'OPTIONS', 'PATCH', 'DELETE'], 'Access-Control-Request-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link'], 'Access-Control-Allow-Credentials' => true, 'Access-Control-Max-Age' => 3600, 'Access-Control-Expose-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link'], 'Access-Control-Allow-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link']]]]);
     if (isset(\Yii::$app->params['httpCacheActive']) and \Yii::$app->params['httpCacheActive']) {
         $params = \Yii::$app->getRequest()->getQueryParams();
         unset($params['accessToken']);
         $behaviors['httpCache'] = ['class' => HttpCache::className(), 'params' => $params, 'lastModified' => function ($action, $params) {
             $q = new \yii\db\Query();
             $class = $this->modelClass;
             if (in_array('updated_at', $class::getTableSchema()->getColumnNames())) {
                 return strtotime($q->from($class::tableName())->max('updated_at'));
             }
             if (in_array('modified', $class::getTableSchema()->getColumnNames())) {
                 return strtotime($q->from($class::tableName())->max('modified'));
             }
             return null;
         }, 'etagSeed' => function (Action $action, $params) {
             $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($params));
             $keys = array();
             foreach ($iterator as $key => $value) {
                 // Build long key name based on parent keys
                 for ($i = $iterator->getDepth() - 1; $i >= 0; $i--) {
                     $key = $iterator->getSubIterator($i)->key() . '_' . $key;
                     if (!is_array($iterator->getSubIterator($i)->current())) {
                         $value = $iterator->getSubIterator($i)->current() . '_' . $value;
                     }
                 }
                 $keys[] = $key . '-' . $value;
             }
             $uniqueId = implode('-', $keys);
             return $uniqueId;
         }];
     }
     return $behaviors;
 }
 /**
  * <pre>Converts a Doctrine array graph of the form:
  * .array
  * .  0 =>
  * .    array
  * .      'id' => '1'
  * .      'PersonaDomicilio' =>
  * .        array
  * .          0 =>
  * .            array
  * .              'id' => '1'
  * To a XML representation.
  * 
  * @param array $array The array to convert to XML
  * 
  * @return DOMDocument <pre> The XML with following structure:
  * . &lt;result&gt;
  * .   &lt;rootTable_Collection&gt;
  * .     &lt;rootTable&gt;
  * .       &lt;id&gt;&lt;/id&gt;
  * .       &lt;field1&gt;&lt;/field1&gt;
  * .       &lt;relatedTable_Collection&gt;
  * .         &lt;relatedTable&gt;
  * .         &lt;/relatedTable&gt;
  * .         &lt;relatedTable&gt;
  * .        &lt;/relatedTable&gt;
  * .         ::
  * .       &lt;/relatedTable_Collection&gt;
  * .     &lt;/rootTable&gt;
  * .     &lt;rootTable&gt;
  * .       ::
  * .     &lt;/rootTable&gt;
  * .     ::
  * .   &lt;/rootTable_Collection&gt;
  * . &lt;result&gt;
  * </pre>
  */
 public function arrayToXml(array $array)
 {
     $result = new DOMDocument();
     $rootNode = $result->createElement('result');
     $result->appendChild($rootNode);
     $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array), RecursiveIteratorIterator::SELF_FIRST);
     $prevLvl = 0;
     $component[$prevLvl] = $this->_queryComponents[$this->_rootAlias]['table']->getComponentName();
     $obj = $result->createElement($component[$prevLvl] . '_Collection');
     $rootNode->appendChild($obj);
     foreach ($iterator as $k => $val) {
         $depth = $iterator->getDepth();
         if ($depth < $prevLvl) {
             for ($i = 0; $i < $prevLvl - $depth; $i++) {
                 $obj = $obj->parentNode;
             }
         }
         if (!is_array($val)) {
             $son = $result->createElement($k, $val);
             $obj->appendChild($son);
         } else {
             if (is_numeric($k)) {
                 $son = $result->createElement($component[$depth]);
             } else {
                 $component[$depth + 1] = $k;
                 $son = $result->createElement($k . '_Collection');
             }
             $obj->appendChild($son);
             !empty($val) && ($obj = $son);
         }
         $prevLvl = $depth;
     }
     return $result;
 }
function get_directory_list($settings = false)
{
    $directory = !empty($settings['dir']) ? $settings['dir'] : CLIENT_DIR . "/";
    $array = array();
    $array['dirs'] = array();
    $array['host'] = array();
    $array['root'] = array();
    if (!is_dir($directory)) {
        return false;
    }
    $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST);
    // Loop through directories
    while ($dir->valid()) {
        try {
            $file = $dir->current();
            ob_start();
            echo $file;
            $data = ob_get_contents();
            ob_end_clean();
            $data = trim($data);
            if (basename($data) != '.' && basename($data) != '..') {
                $array['host'][] = $data;
                $array['root'][] = str_replace(ROOT_DIR, "", $data);
                if (is_dir($data) && !in_array($data . "/", $array['dirs'])) {
                    $array['dirs'][] = $data . "/";
                }
            }
            unset($data);
            $dir->next();
        } catch (UnexpectedValueException $e) {
            continue;
        }
    }
    return isset($array) ? $array : false;
}
Exemple #5
0
 /**
  * Media files are just copied over w/o any additional processing
  *
  * @return \Phrozn\Site
  */
 private function processMedia()
 {
     $projectDir = $this->getProjectDir();
     $outputDir = $this->getOutputDir();
     $dir = new \RecursiveDirectoryIterator($projectDir . '/media');
     $it = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($it as $item) {
         $baseName = $item->getBaseName();
         if ($item->isFile()) {
             $inputFile = $item->getRealPath();
             $path = $it->getSubPath();
             $outputFile = $outputDir . '/media/' . $path . (!empty($path) ? '/' : '') . basename($inputFile);
             // copy media files
             try {
                 $destinationDir = dirname($outputFile);
                 if (!is_dir($destinationDir)) {
                     mkdir($destinationDir, 0777, true);
                 }
                 if (!copy($inputFile, $outputFile)) {
                     throw new \Exception(sprintf('Failed transfering "%s" from media folder', $inputFile));
                 }
                 $inputFile = str_replace(getcwd(), '.', $inputFile);
                 $outputFile = str_replace(getcwd(), '.', realpath($outputFile));
                 $this->getOutputter()->stdout('%b' . $outputFile . '%n copied');
             } catch (\Exception $e) {
                 $this->getOutputter()->stderr($inputFile . ': ' . $e->getMessage());
             }
         }
     }
 }
 /**
  * Get Test Files
  *
  * @param null $directory
  * @param null $excludes
  * @return array
  */
 public static function getTestFiles($directory = null, $excludes = null)
 {
     if (is_array($directory)) {
         $files = array();
         foreach ($directory as $d) {
             $files = array_merge($files, self::getTestFiles($d, $excludes));
         }
         return array_unique($files);
     }
     if ($excludes !== null) {
         $excludes = self::getTestFiles((array) $excludes);
     }
     if ($directory === null || $directory !== realpath($directory)) {
         $basePath = App::pluginPath('DebugKit') . 'Test' . DS . 'Case' . DS;
         $directory = str_replace(DS . DS, DS, $basePath . $directory);
     }
     $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
     $files = array();
     while ($it->valid()) {
         if (!$it->isDot()) {
             $file = $it->key();
             if (preg_match('|Test\\.php$|', $file) && $file !== __FILE__ && !preg_match('|^All.+?\\.php$|', basename($file)) && ($excludes === null || !in_array($file, $excludes))) {
                 $files[] = $file;
             }
         }
         $it->next();
     }
     return $files;
 }
 /**
  * @param $target
  * @return array
  */
 public function locate($target)
 {
     $paths = [];
     $target = sprintf("%s/%s", self::RESOURCE_SUFFIX, $target);
     foreach ($this->locations as $location) {
         if (!is_dir($location)) {
             continue;
         }
         $location = realpath($location);
         $dir = new \RecursiveDirectoryIterator($location, \FilesystemIterator::FOLLOW_SYMLINKS);
         $filter = new \RecursiveCallbackFilterIterator($dir, function (\SplFileInfo $current) use(&$paths, $target) {
             $fileName = strtolower($current->getFilename());
             if ($this->isExcluded($fileName) || $current->isFile()) {
                 return false;
             }
             if (!is_dir($current->getPathname() . '/Resources')) {
                 return true;
             } else {
                 $file = $current->getPathname() . sprintf("/Resources/%s", $target);
                 if (is_file($file)) {
                     $paths[] = $file;
                 }
                 return false;
             }
         });
         $iterator = new \RecursiveIteratorIterator($filter);
         $iterator->rewind();
     }
     return $paths;
 }
 protected function assertDirContentsEquals($expDir, $actDir)
 {
     if (!file_exists($expDir)) {
         throw new RuntimeException("Expected dir not found: " . $expDir);
     }
     if (!file_exists($actDir)) {
         throw new RuntimeException("Actual dir not found: " . $actDir);
     }
     $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($expDir));
     $expFiles = array();
     while ($dir->valid()) {
         if (!$dir->isDot()) {
             array_push($expFiles, $dir->getSubPathName());
         }
         $dir->next();
     }
     $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($actDir));
     $actFiles = array();
     while ($dir->valid()) {
         if (!$dir->isDot()) {
             array_push($actFiles, $dir->getSubPathName());
         }
         $dir->next();
     }
     $this->assertEquals($expFiles, $actFiles);
     foreach ($expFiles as $key => $value) {
         $expFile = file_get_contents($expDir . DIRECTORY_SEPARATOR . $value);
         $actFile = file_get_contents($expDir . DIRECTORY_SEPARATOR . $actFiles[$key]);
         $this->assertEquals($expFile, $actFile);
     }
 }
Exemple #9
0
 protected function parseCfg()
 {
     $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->data));
     $cfg = array();
     foreach ($iterator as $key => $value) {
         for ($i = $iterator->getDepth() - 1; $i >= 0; $i--) {
             $key = $iterator->getSubIterator($i)->key() . '.' . $key;
         }
         $cfg[$key] = $value;
     }
     foreach ($cfg as $key => $value) {
         if (is_string($value)) {
             if ($count = preg_match_all('({{(.*?)}})', $value, $matches)) {
                 for ($i = 0; $i < $count; $i++) {
                     $cfg[$key] = str_replace($matches[0][$i], $cfg[$matches[1][$i]], $value);
                 }
             }
             foreach ($this->valueParsers as $valueParser) {
                 $cfg[$key] = $valueParser($cfg[$key]);
             }
             $temp =& $this->data;
             $exploded = explode('.', $key);
             foreach ($exploded as $segment) {
                 $temp =& $temp[$segment];
             }
             $temp = $cfg[$key];
             unset($temp);
         }
     }
 }
 /**
  * Recursively copy assets from the source directory to the destination
  * directory in the web space, omitting source files.
  *
  * @param  Filesystem        $fs
  * @param  string            $from_directory the source
  * @param  string            $to_directory   the destination
  * @throws \RuntimeException if a problem occurs.
  */
 protected function copyAssets(Filesystem $fs, $from_directory, $to_directory)
 {
     Tlog::getInstance()->addDebug("Copying assets from {$from_directory} to {$to_directory}");
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($from_directory, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
     $fs->mkdir($to_directory, 0777);
     /** @var \RecursiveDirectoryIterator $iterator */
     foreach ($iterator as $item) {
         if ($item->isDir()) {
             $dest_dir = $to_directory . DS . $iterator->getSubPathName();
             if (!is_dir($dest_dir)) {
                 if ($fs->exists($dest_dir)) {
                     $fs->remove($dest_dir);
                 }
                 $fs->mkdir($dest_dir, 0777);
             }
         } elseif (!$this->isSourceFile($item)) {
             // We don't copy source files
             $dest_file = $to_directory . DS . $iterator->getSubPathName();
             if ($fs->exists($dest_file)) {
                 $fs->remove($dest_file);
             }
             $fs->copy($item, $dest_file);
         }
     }
 }
 public function testBuildPhar()
 {
     if (defined('HHVM_VERSION')) {
         $this->markTestSkipped('Building the phar does not work on HHVM.');
     }
     $target = dirname(self::$pharPath);
     $fs = new Filesystem();
     $fs->removeDirectory($target);
     $fs->ensureDirectoryExists($target);
     chdir($target);
     $it = new \RecursiveDirectoryIterator(__DIR__ . '/../../../', \RecursiveDirectoryIterator::SKIP_DOTS);
     $ri = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($ri as $file) {
         $targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
         if ($file->isDir()) {
             $fs->ensureDirectoryExists($targetPath);
         } else {
             copy($file->getPathname(), $targetPath);
         }
     }
     $proc = new Process('php ' . escapeshellarg('./bin/compile'), $target);
     $exitcode = $proc->run();
     if ($exitcode !== 0 || trim($proc->getOutput())) {
         $this->fail($proc->getOutput());
     }
     $this->assertTrue(file_exists(self::$pharPath));
 }
Exemple #12
0
function copyOldVersion()
{
    if (!is_dir(PATH)) {
        echo 'Creating new oldVersion dir...<br>';
        mkdir(PATH);
    }
    $source = "../";
    $dest = PATH;
    // Set a stream context timeout for file reading
    $context = stream_context_create(array('http' => array('timeout' => 60)));
    echo 'Moving current ICEcoder files...<br>';
    foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
        if (strpos($source . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), "oldVersion") == false) {
            // Don't move backups, plugins or .git away
            $testPath = $source . DIRECTORY_SEPARATOR . $iterator->getSubPathName();
            $testPath = str_replace("\\", "/", $testPath);
            if (strpos($testPath, "/backups/") == false && strpos($testPath, "/plugins/") == false && strpos($testPath, "/.git/") == false) {
                if ($item->isDir()) {
                    mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755);
                } else {
                    rename($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
                }
            }
        }
    }
    $icv_url = "https://icecoder.net/latest-version.txt";
    echo 'Detecting current version of ICEcoder...<br>';
    $icvInfo = getData($icv_url, 'curl', 'Sorry, couldn\'t figure out latest version.');
    echo 'Latest version of ICEcoder is ' . $icvInfo . '<br>';
    openZipNew($icvInfo);
}
Exemple #13
0
	public function rmdir($path) {
		if (!$this->isDeletable($path)) {
			return false;
		}
		try {
			$it = new \RecursiveIteratorIterator(
				new \RecursiveDirectoryIterator($this->getSourcePath($path)),
				\RecursiveIteratorIterator::CHILD_FIRST
			);
			/**
			 * RecursiveDirectoryIterator on an NFS path isn't iterable with foreach
			 * This bug is fixed in PHP 5.5.9 or before
			 * See #8376
			 */
			$it->rewind();
			while ($it->valid()) {
				/**
				 * @var \SplFileInfo $file
				 */
				$file = $it->current();
				if (in_array($file->getBasename(), array('.', '..'))) {
					$it->next();
					continue;
				} elseif ($file->isDir()) {
					rmdir($file->getPathname());
				} elseif ($file->isFile() || $file->isLink()) {
					unlink($file->getPathname());
				}
				$it->next();
			}
			return rmdir($this->getSourcePath($path));
		} catch (\UnexpectedValueException $e) {
			return false;
		}
	}
    /**
     * Constructor.
     *
     * @param \RecursiveIteratorIterator $iterator    The Iterator to filter
     * @param int                        $minDepth    The min depth
     * @param int                        $maxDepth    The max depth
     */
    public function __construct(\RecursiveIteratorIterator $iterator, $minDepth = 0, $maxDepth = INF)
    {
        $this->minDepth = $minDepth;
        $iterator->setMaxDepth(INF === $maxDepth ? -1 : $maxDepth);

        parent::__construct($iterator);
    }
 /**
  * {@inheritdoc}
  *
  * @see \Symfony\Component\Console\Command\Command::execute()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $assets = $this->getContainer()->getParameter('asf_layout.assets');
     $this->tinymce_config = $assets['tinymce'];
     $dest_dir = $input->getArgument('target_dir') ? $input->getArgument('target_dir') : null;
     if (is_null($dest_dir) && isset($this->tinymce_config['customize']['dest_dir'])) {
         $dest_dir = $this->tinymce_config['customize']['dest_dir'];
     }
     $exclude_files = $input->getOption('exclude_files') ? $input->getOption('exclude_files') : $this->tinymce_config['customize']['exclude_files'];
     $src_dir = sprintf('%s', $this->tinymce_config['tinymce_dir']);
     $fs = new Filesystem();
     try {
         if (!$fs->exists($dest_dir)) {
             $fs->mkdir($dest_dir);
         }
     } catch (IOException $e) {
         $output->writeln(sprintf('<error>Could not create directory %s.</error>', $dest_dir));
         return;
     }
     if (false === file_exists($src_dir)) {
         $output->writeln(sprintf('<error>Source directory "%s" does not exist. Did you install TinyMCE ? ' . 'Don\'t forget to specify the path to TinyMCE folder in ' . '"asf_layout.assets.tinymce.tinymce_dir".</error>', $src_dir));
         return;
     }
     foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($src_dir, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
         if ($item->isDir() && !in_array($item->getBasename(), $exclude_files)) {
             $fs->mkdir($dest_dir . '/' . $iterator->getSubPathName());
         } elseif (!in_array($item->getBasename(), $exclude_files)) {
             $fs->copy($item, $dest_dir . '/' . $iterator->getSubPathName());
         }
     }
     $output->writeln(sprintf('[OK] TinyMCE files was successfully copied in "%s".', $dest_dir));
 }
Exemple #16
0
 public function copy($target)
 {
     $result = false;
     $encoded = $this->encodePath($target);
     $dir = dirname($encoded);
     if (!is_dir($encoded)) {
         $result = mkdir($encoded, 0755, true);
     }
     if (is_dir($encoded)) {
         $result = true;
         // needed for empty directories
         $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->_encoded), \RecursiveIteratorIterator::SELF_FIRST);
         foreach ($iterator as $f) {
             if ($f->isDir()) {
                 $path = $encoded . '/' . $iterator->getSubPathName();
                 if (!is_dir($path)) {
                     $result = mkdir($path);
                 }
             } else {
                 $result = copy($f, $encoded . '/' . $iterator->getSubPathName());
             }
             if ($result === false) {
                 break;
             }
         }
     }
     if ($result) {
         $this->setPath($target);
     }
     return $result;
 }
Exemple #17
0
 /**
  * Creates an iterator with settings
  * Resets class-wide results
  *
  * @param  $items  array
  *
  * @return object  \RecursiveIteratorIterator
  */
 protected function _createIterator(array $items)
 {
     $this->result = [];
     $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($items));
     $iterator->setMaxDepth($this->max_depth);
     return $iterator;
 }
 /**
  * @see	\wcf\page\IPage::readData()
  */
 public function readData()
 {
     parent::readData();
     // stats
     if (LINKLIST_ENABLE_STATISTICS) {
         $this->stats = array_merge(StatsCacheBuilder::getInstance()->getData(), UserStatsCacheBuilder::getInstance()->getData());
     }
     // get categories
     $categoryTree = new LinklistCategoryNodeTree('de.incendium.linklist.category');
     $this->categoryList = $categoryTree->getIterator();
     $this->categoryList->setMaxDepth(0);
     // get featured entries
     $this->featuredEntryList = new AccessibleEntryList();
     $this->featuredEntryList->getConditionBuilder()->add('entry.isFeatured = ?', array(1));
     $this->featuredEntryList->sqlLimit = 10;
     $this->featuredEntryList->sqlOrderBy = 'RAND()';
     $this->featuredEntryList->readObjects();
     // remove default breadcrumb entry and set current page as 'website'
     if (WCF::isLandingPage()) {
         MetaTagHandler::getInstance()->addTag('og:url', 'og:url', LinkHandler::getInstance()->getLink('Linklist', array('application' => 'linklist')), true);
         MetaTagHandler::getInstance()->addTag('og:type', 'og:type', 'website', true);
         MetaTagHandler::getInstance()->addTag('og:title', 'og:title', WCF::getLanguage()->get(PAGE_TITLE), true);
         MetaTagHandler::getInstance()->addTag('og:description', 'og:description', WCF::getLanguage()->get(PAGE_DESCRIPTION), true);
     }
 }
 /**
  * Executes this task.
  */
 public function main()
 {
     if ($this->property === null) {
         throw new BuildException('The property attribute must be specified');
     }
     if ($this->path === null) {
         throw new BuildException('The path attribute must be specified');
     }
     $check = new AgaviModuleFilesystemCheck();
     $check->setConfigDirectory($this->project->getProperty('module.directory.config'));
     $check->setPath($this->path->getAbsolutePath());
     if (!$check->check()) {
         throw new BuildException('The path attribute must be a valid module base directory');
     }
     $actions = array();
     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path->getAbsolutePath() . DIRECTORY_SEPARATOR . $this->project->getProperty('module.directory.actions')));
     for (; $iterator->valid(); $iterator->next()) {
         $rdi = $iterator->getInnerIterator();
         if ($rdi->isDot() || !$rdi->isFile()) {
             continue;
         }
         $file = $rdi->getSubpathname();
         if (preg_match('#Action\\.class\\.php$#', $file)) {
             $actions[] = str_replace(DIRECTORY_SEPARATOR, '.', substr($file, 0, -16));
         }
     }
     $list = new AgaviArraytostringTransform();
     $list->setInput($actions);
     $list->setDelimiter(' ');
     $this->project->setUserProperty($this->property, $list->transform());
 }
Exemple #20
0
function copyFile($source, $dest)
{
    $is_dot = array('.', '..');
    if (is_dir($source)) {
        if (version_compare((double) phpversion(), (double) '5.3', '<')) {
            $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
        } else {
            $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST);
        }
        foreach ($iterator as $file) {
            if (version_compare((double) phpversion(), (double) '5.2.17', '<=')) {
                if (in_array($file->getBasename(), $is_dot)) {
                    continue;
                }
            } elseif (version_compare((double) phpversion(), (double) '5.3', '<')) {
                if ($file->isDot()) {
                    continue;
                }
            }
            if ($file->isDir()) {
                mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), true);
            } else {
                copy($file, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
            }
        }
        unset($iterator, $file);
    } else {
        copy($source, $dest);
    }
    return true;
}
 /**
  * Copies a file or directory.
  * @return void
  * @throws Nette\IOException
  */
 public static function copy($source, $dest, $overwrite = TRUE)
 {
     if (stream_is_local($source) && !file_exists($source)) {
         throw new Nette\IOException("File or directory '{$source}' not found.");
     } elseif (!$overwrite && file_exists($dest)) {
         throw new Nette\InvalidStateException("File or directory '{$dest}' already exists.");
     } elseif (is_dir($source)) {
         static::createDir($dest);
         foreach (new \FilesystemIterator($dest) as $item) {
             static::delete($item);
         }
         foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
             if ($item->isDir()) {
                 static::createDir($dest . '/' . $iterator->getSubPathName());
             } else {
                 static::copy($item, $dest . '/' . $iterator->getSubPathName());
             }
         }
     } else {
         static::createDir(dirname($dest));
         if (@stream_copy_to_stream(fopen($source, 'r'), fopen($dest, 'w')) === FALSE) {
             // @ is escalated to exception
             throw new Nette\IOException("Unable to copy file '{$source}' to '{$dest}'.");
         }
     }
 }
Exemple #22
0
 private static function unlinkDirectory($path)
 {
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST);
     $iterator->rewind();
     $files = array();
     $directories = array();
     foreach ($iterator as $path => $directory) {
         if (is_file($path)) {
             $files[] = $path;
         } elseif (is_dir($path)) {
             $directories[] = $path;
         }
     }
     // Remove the files, then the directories
     foreach ($files as $filePath) {
         self::unlinkFile($filePath);
     }
     foreach ($directories as $dirPath) {
         rmdir($dirPath);
     }
     // Finally, remove the path itself
     if (is_dir($path)) {
         rmdir($path);
     }
 }
 private function copyTemplates()
 {
     // check if there's a /templates in plugin directory
     $source_path = ROOT_PATH . 'plugins/' . $this->getName() . '/templates';
     if (!file_exists($source_path)) {
         return;
     }
     // create directory in /templates/plugins/ if not exists
     $plugin_template_path = ROOT_PATH . 'templates/plugins/' . $this->getName();
     if (!file_exists($plugin_template_path)) {
         mkdir($plugin_template_path);
     }
     // copy static files to that directory
     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source_path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $item) {
         $path = $plugin_template_path . '/' . $iterator->getSubPathName();
         if ($item->isDir()) {
             if (!file_exists($path)) {
                 mkdir($path);
             }
         } else {
             copy($item, $path);
         }
     }
 }
 /**
  * Constructor.
  *
  * @param \RecursiveIteratorIterator $iterator    The Iterator to filter
  * @param array                      $comparators An array of \NumberComparator instances
  */
 public function __construct(\RecursiveIteratorIterator $iterator, array $comparators)
 {
     $minDepth = 0;
     $maxDepth = INF;
     foreach ($comparators as $comparator) {
         switch ($comparator->getOperator()) {
             case '>':
                 $minDepth = $comparator->getTarget() + 1;
                 break;
             case '>=':
                 $minDepth = $comparator->getTarget();
                 break;
             case '<':
                 $maxDepth = $comparator->getTarget() - 1;
                 break;
             case '<=':
                 $maxDepth = $comparator->getTarget();
                 break;
             default:
                 $minDepth = $maxDepth = $comparator->getTarget();
         }
     }
     $this->minDepth = $minDepth;
     $iterator->setMaxDepth(INF === $maxDepth ? -1 : $maxDepth);
     parent::__construct($iterator);
 }
Exemple #25
0
 public function reorder(Request $req, Response $res)
 {
     if (!$req->isPost()) {
         throw new \Chalk\Exception("Reorder action only accepts POST requests");
     }
     if (!$req->nodeData) {
         return $res->redirect($this->url(array('action' => 'index')));
     }
     $data = json_decode($req->nodeData);
     $structure = $this->em('Chalk\\Core\\Structure')->id($req->structure);
     $nodes = $this->em('Chalk\\Core\\Structure\\Node')->all(['structure' => $structure]);
     $map = [];
     foreach ($nodes as $node) {
         $map[$node->id] = $node;
     }
     $it = new \RecursiveIteratorIterator(new Iterator($data), \RecursiveIteratorIterator::SELF_FIRST);
     $stack = [];
     foreach ($it as $i => $value) {
         array_splice($stack, $it->getDepth(), count($stack), array($value));
         $depth = $it->getDepth();
         $parent = $depth > 0 ? $stack[$depth - 1] : $structure->root;
         $node = $map[$value->id];
         $node->parent->children->removeElement($node);
         $node->parent = $map[$parent->id];
         $node->sort = $i;
     }
     $this->em->flush();
     $this->notify("Content was moved successfully", 'positive');
     if (isset($req->redirect)) {
         return $res->redirect($req->redirect);
     } else {
         return $res->redirect($this->url(array('action' => 'index')));
     }
 }
 public function buildIndex()
 {
     $iterator = new RecursiveIteratorIterator(new contentTreeRecursiveIterator($this->toc), RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $topic) {
         $path = ltrim($iterator->getPath() . '/' . $topic['href'], '\\/');
         $this->indexPage($path, $topic['title']);
     }
 }
 /**
  * A convenience method to dump the page rows.
  */
 private function showPageItems()
 {
     $tree = PagePeer::retrieveTree();
     $iterator = new RecursiveIteratorIterator($tree, RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $item) {
         /* @var        $item Page */
         echo str_repeat('- ', $iterator->getDepth()), $item->getId(), ': ', $item->getTitle(), ' [', $item->getLeftValue(), ':', $item->getRightValue(), ']' . "\n";
     }
 }
 /**
  * Parse a tarball of .gcov files.
  **/
 public function Parse($handle)
 {
     global $CDASH_BACKUP_DIRECTORY;
     // This function receives an open file handle, but we really just need
     // the path to this file so that we can extract it.
     $meta_data = stream_get_meta_data($handle);
     $filename = $meta_data["uri"];
     fclose($handle);
     // Create a new directory where we can extract our tarball.
     $pathParts = pathinfo($filename);
     $dirName = $CDASH_BACKUP_DIRECTORY . "/" . $pathParts['filename'];
     mkdir($dirName);
     // Extract the tarball.
     $phar = new PharData($filename);
     $phar->extractTo($dirName);
     // Find the data.json file and extract the source directory from it.
     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirName), RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($iterator as $fileinfo) {
         if ($fileinfo->getFilename() == "data.json") {
             $jsonContents = file_get_contents($fileinfo->getRealPath());
             $jsonDecoded = json_decode($jsonContents, true);
             if (is_null($jsonDecoded) || !array_key_exists("Source", $jsonDecoded) || !array_key_exists("Binary", $jsonDecoded)) {
                 $this->DeleteDirectory($dirName);
                 return false;
             }
             $this->SourceDirectory = $jsonDecoded['Source'];
             $this->BinaryDirectory = $jsonDecoded['Binary'];
             break;
         }
     }
     if (empty($this->SourceDirectory) || empty($this->BinaryDirectory)) {
         $this->DeleteDirectory($dirName);
         return false;
     }
     // Check if any Labels.json files were included
     $iterator->rewind();
     foreach ($iterator as $fileinfo) {
         if ($fileinfo->getFilename() == "Labels.json") {
             $this->ParseLabelsFile($fileinfo);
         }
     }
     // Recursively search for .gcov files and parse them.
     $iterator->rewind();
     foreach ($iterator as $fileinfo) {
         if (pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION) == "gcov") {
             $this->ParseGcovFile($fileinfo);
         }
     }
     // Insert coverage summary (removing any old results first)
     //$this->CoverageSummary->RemoveAll();
     $this->CoverageSummary->Insert();
     $this->CoverageSummary->ComputeDifference();
     // Delete the directory when we're done.
     $this->DeleteDirectory($dirName);
     return true;
 }
Exemple #29
0
 private function _get_rit()
 {
     $config = (array) Kohana::$config->load('finder');
     $config = Arr::merge($config, $this->filter);
     Finder_Filter_Iterator::$config = $config;
     $this->dit = new Finder_Filter_Iterator($this->dit);
     $rit = new RecursiveIteratorIterator($this->dit, RecursiveIteratorIterator::SELF_FIRST);
     $rit->setMaxDepth($this->max_depth);
     return $rit;
 }
 private function _loopFiles($directory)
 {
     $files = array();
     $iterator = new \RecursiveIteratorIterator($directory);
     $iterator->setMaxDepth($this->depth);
     foreach ($iterator as $info) {
         if (!in_array($info->getFilename(), $this->ignoreFiles)) {
             $fileNameLength = strlen($info->getFileName());
             $extLength = strlen($info->getExtension());
             $folders = explode("/", $info->getPathname());
             $parentFolder = false;
             if (count($folders) > 1) {
                 $parentFolder = $folders[count($folders) - 2];
             }
             $name = substr($info->getFilename(), 0, $fileNameLength - $extLength - 1);
             $file = new DirectoryContents_FileModel();
             $file->name = $name;
             $file->niceName = $this->_generateNiceName($name);
             $file->fileName = $info->getFileName();
             $file->path = $info->getPathname();
             $file->parentFolder = $parentFolder;
             $file->niceParentFolder = $parentFolder ? $this->_generateNiceName($parentFolder) : $parentFolder;
             $file->extension = $info->getExtension();
             $file->size = $info->getSize();
             $file->created = $info->getCtime();
             $file->modified = $info->getMtime();
             $files[] = $file;
         }
     }
     return $files;
 }