Esempio n. 1
0
 public function testAll($testDir)
 {
     // Iterate across this dir for files matching *_test.php
     $directory = new RecursiveDirectoryIterator($testDir);
     $iterator = new RecursiveIteratorIterator($directory);
     $regex = new RegexIterator($iterator, '/^.+_test\\.php$/i', RecursiveRegexIterator::GET_MATCH);
     $regex->next();
     while ($regex->valid()) {
         $item = $regex->current();
         require_once $item[0];
         $regex->next();
     }
 }
Esempio n. 2
0
 protected static function readCommands($incHidden = false)
 {
     static $commands = array();
     static $hidden = array();
     if (!$commands) {
         $projectRoot = Meshing_Utils::getProjectRoot();
         $consoleRoot = $projectRoot . Meshing_Utils::getPaths()->getPathMeshingCommands();
         $directory = new RecursiveDirectoryIterator($consoleRoot);
         $iterator = new RecursiveIteratorIterator($directory);
         $regex = new RegexIterator($iterator, '/^.+\\.php$/i', RecursiveRegexIterator::GET_MATCH);
         $regex->next();
         $i++;
         while ($regex->valid()) {
             // For safety!
             if ($i > 50) {
                 break;
             }
             // Get the full pathname of the class
             $item = $regex->current();
             $item = $item[0];
             // Strip out the full path bit, and generally tidy
             $item = str_replace($consoleRoot . DIRECTORY_SEPARATOR, '', $item);
             $item = str_replace('.php', '', $item);
             $className = 'Meshing_Console_Command_' . str_replace(DIRECTORY_SEPARATOR, '_', $item);
             $item = strtolower(str_replace(DIRECTORY_SEPARATOR, ':', $item));
             // Classes without this method are not commands at all
             $realCommand = method_exists($className, 'getDescription');
             // We consult a special method to determine whether to show the command
             if ($realCommand) {
                 $cmdClass = new $className();
                 $commands[$className] = $item;
                 if ($cmdClass->isHiddenCommand()) {
                     $hidden[] = $className;
                 }
             }
             $regex->next();
         }
         // Preserve the keys when sorting
         asort($commands);
     }
     // Strip out hidden commands
     if (!$incHidden) {
         foreach ($hidden as $removeClass) {
             unset($commands[$removeClass]);
         }
     }
     return $commands;
 }
Esempio n. 3
0
 /**
  * @test
  * @group QA
  * @dataProvider dirs_to_parse
  */
 function some_files_are_missing_the_copyright_statement($dir)
 {
     $Directory = new RecursiveDirectoryIterator($dir);
     $Iterator = new RecursiveIteratorIterator($Directory);
     $Regex = new RegexIterator($Iterator, '/\\.php$/i', RecursiveRegexIterator::GET_MATCH);
     $result = array();
     $Regex->next();
     while ($Regex->valid()) {
         $path = $Regex->getPathname();
         $copy = 'Copyright (c) 2015 Gregory Vinčić, The MIT License (MIT)';
         if (!$this->file_contains($path, $copy)) {
             $result[] = $path;
         }
         $Regex->next();
     }
     $this->assertEquals('', implode("\n", $result));
 }
Esempio n. 4
0
 /**
  * Return all template files of a particular group as array
  *
  * @param string
  * @param integer
  *
  * @return array
  * @throws Exception
  */
 public static function getTemplateGroupInFolders($prefix, $folders)
 {
     $templates = array();
     // Find all matching templates
     foreach ($folders as $sourceName => $folder) {
         $iterator = new RecursiveDirectoryIterator($folder, RecursiveDirectoryIterator::SKIP_DOTS | RecursiveDirectoryIterator::UNIX_PATHS);
         $iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::LEAVES_ONLY);
         $iterator = new RegexIterator($iterator, '~(^|/)' . preg_quote($prefix, '~') . '.*\\.twig$~i');
         /** @var RecursiveDirectoryIterator|RecursiveIteratorIterator|RegexIterator $iterator */
         $iterator->next();
         while ($iterator->accept()) {
             $templateName = $iterator->getSubPathname();
             $templateName = preg_replace('#\\.[^\\.]+\\.twig$#', '', $templateName);
             $templates[$sourceName][$templateName] = $templateName;
             uksort($templates[$sourceName], 'strnatcasecmp');
             $iterator->next();
         }
     }
     uksort($templates, 'strnatcasecmp');
     return $templates;
 }
        echo '>' . $this->_valeur . '</div>' . PHP_EOL;
    }
}
?>

<style>
    .vert{ color: green; margin-left: 25px; }
    .bleu{color: blue; }
</style>
<h2>Mon Filtre avec while</h2>

<?php 
$DirectoryIterator = new MonDI('./');
//print_r($DirectoryIterator);
$Iterator_iterator = new MonFilter($DirectoryIterator);
$Iterator_iterator->rewind();
while ($Iterator_iterator->valid()) {
    $Iterator_iterator->afficher_valeur();
    $Iterator_iterator->next();
}
echo '<h2>RegexIterator avec while</h2>';
$RegexIterator = new RegexIterator($DirectoryIterator, '#rep#');
$RegexIterator->rewind();
while ($RegexIterator->valid()) {
    echo $RegexIterator->current()->getFilename() . '<br />';
    $RegexIterator->next();
}
echo '<h2>RegexIterator avec foreach</h2>';
foreach ($RegexIterator as $Resultat) {
    echo $Resultat . '<br />';
}
Esempio n. 6
0
        $subpath = $it->getSubPath();
        $subpath_highlighted = $subpath ? '<span class="label">' . $subpath . '/</span>' : '';
        $subpath_file = $it->getSubPathName();
        $filename = preg_replace('#^' . $subpath . '\\' . DS . '#', '', $subpath_file);
        $pi = pathinfo($it->key());
        $ext = $pi['extension'];
        $file_type = isset($ext_badge[$ext]) ? '<span class="badge badge-' . $ext_badge[$ext] . '">' . $ext . '</span> ' : '<span class="badge">---</span> ';
        $btns_handle_class = isset($ext_badge[$ext]) ? '<span class="badge badge-' . $ext_badge[$ext] . '">' . $ext . '</span> ' : '<span class="badge">---</span> ';
        $btn_allowed = isset($file_code_btns[$filename]) ? array_keys($file_code_btns[$filename]) : array();
        echo '
						' . $file_type . (!isset($file_tip_extra[$filename]) ? '<img src="components/com_flexicontent/assets/images/tick_f2.png" alt="Edit file">' : '<img src="components/com_flexicontent/assets/images/comment.png" data-placement="bottom" class="' . $tip_class . '" title="' . $file_tip_extra[$filename] . '" alt="Edit file"/>') . '
						<a href="javascript:;" class="' . $tip_class . '" data-placement="right" onclick="load_layout_file(\'' . addslashes($this->layout->name) . '\', \'' . addslashes($it->getSubPathName()) . '\', \'0\', \'' . implode($btn_allowed, ' ') . '\'); return false;"
						title="' . (isset($file_tip[$filename]) ? $file_tip[$filename] : $ext . ' file') . '">' . $subpath_highlighted . $filename . '</a>';
        echo "<br/>";
    }
    $it->next();
}
?>
			</div>

			<div id="layout-fileeditor-container" class="span8" style="margin:0.5%;">
				<span class="fcsep_level0" style="margin:0 0 12px 0; background-color:#333; ">
					<span id="layout_edit_name_container" class="label label-info"><?php 
echo JText::_('FLEXI_NO_FILE_LOADED');
?>
</span>
				</span>
				<div class="fcclear"></div>
				<div id="ajax-system-message-container">
				</div>
				<div class="fcclear"></div>
 /**
  * Method to get files having the given extensions from a given folder
  *
  * @access private
  * @return integer
  * @since 1.0
  */
 function getFilesFromPath($itemid, $fieldid, $append_item = 1, $append_field = 0, $folder_param_name = 'dir', $exts = 'bmp,csv,doc,docx,gif,ico,jpg,jpeg,odg,odp,ods,odt,pdf,png,ppt,pptx,swf,txt,xcf,xls,xlsx,zip,ics')
 {
     $app = JFactory::getApplication();
     $option = JRequest::getVar('option');
     $imageexts = array('jpg', 'gif', 'png', 'bmp', 'jpeg');
     // Common image extensions
     $gallery_folder = $this->getFieldFolderPath($itemid, $fieldid, $append_item, $append_field, $folder_param_name);
     //echo $gallery_folder ."<br />";
     // Create folder for current language
     if (!is_dir($gallery_folder)) {
         mkdir($gallery_folder, $mode = 0755, $recursive = true);
     }
     // Get file list according to filtering
     $exts = preg_replace("/[\\s]*,[\\s]*/", '|', $exts);
     $it = new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($gallery_folder)), '#(.*\\.)(' . $exts . ')#i');
     $it->rewind();
     // Get file information
     $rows = array();
     $i = 1;
     while ($it->valid()) {
         if ($it->isDot()) {
             $it->next();
             continue;
         }
         $filesubpath = $it->getSubPathName();
         // filename including the folder subpath
         $filepath = $it->key();
         $pinfo = pathinfo($filepath);
         $row = new stdClass();
         $row->ext = $pinfo['extension'];
         $row->filename = $filesubpath;
         //$pinfo['filename'].".".$pinfo['extension'];
         $row->size = sprintf("%.0f KB", filesize($filepath) / 1024);
         $row->altname = $pinfo['filename'];
         $row->uploader = '-';
         $row->uploaded = date("F d Y H:i:s.", filectime($filepath));
         $row->id = $i;
         if (in_array(strtolower($row->ext), $imageexts)) {
             $row->icon = JURI::root() . "components/com_flexicontent/assets/images/mime-icon-16/image.png";
         } elseif (file_exists(JPATH_SITE . "/components/com_flexicontent/assets/images/mime-icon-16/" . $row->ext . ".png")) {
             $row->icon = JURI::root() . "components/com_flexicontent/assets/images/mime-icon-16/" . $row->ext . ".png";
         } else {
             $row->icon = JURI::root() . "components/com_flexicontent/assets/images/mime-icon-16/unknown.png";
         }
         $rows[] = $row;
         $i++;
         $it->next();
     }
     return $rows;
 }
Esempio n. 8
0
 /**
  * WpMenuPages constructor.
  *
  * @param string        $pluginBaseFile  Absolute path to plugin main file
  * @param array|Options $options         An instance of {@link Options} or an array with default options
  * @param string        $optionsBaseName In case the $options param is an array this should be a string
  *                                       defining the name of the options array as stored in DB
  *
  * @throws \InvalidArgumentException If $pluginBaseFile is empty or pointing to non readable file
  * @throws \InvalidArgumentException If $options isn't an instance of {@link Options} and is not an array
  *                                   and $optionsBaseName is empty
  * @throws \Exception If symlinks are used and couldn't resolve $pluginBaseFile path
  * @since  1.0.0
  * @author Panagiotis Vagenas <*****@*****.**>
  */
 public function __construct($pluginBaseFile, $options, $optionsBaseName = '')
 {
     if (empty($pluginBaseFile) || !file_exists($pluginBaseFile) || !is_readable($pluginBaseFile)) {
         throw new \InvalidArgumentException('Invalid argument $pluginBaseFile in ' . __METHOD__);
     }
     $pluginBaseFile = wp_normalize_path($pluginBaseFile);
     $pluginIsSymlink = strpos($pluginBaseFile, ABSPATH) !== 0;
     $pagesIsSymlink = strpos(__FILE__, ABSPATH) !== 0;
     if ($pluginIsSymlink) {
         $pluginFolderName = dirname(plugin_basename($pluginBaseFile));
         $this->pluginBasePath = trailingslashit(WP_PLUGIN_DIR) . $pluginFolderName;
         $this->pluginBaseFile = trailingslashit($this->pluginBasePath) . basename($pluginBaseFile);
     } else {
         $this->pluginBasePath = dirname($pluginBaseFile);
         $this->pluginBaseFile = realpath($pluginBaseFile);
     }
     if ($pagesIsSymlink) {
         $this->basePath = dirname(dirname(dirname(__FILE__)));
         $this->basePathRelToPlugin = str_replace($this->pluginBasePath, '', $this->basePath);
         $dirItr = new \RecursiveDirectoryIterator($this->pluginBasePath, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS | \RecursiveDirectoryIterator::SKIP_DOTS);
         $itr = new \RecursiveIteratorIterator($dirItr);
         $res = new \RegexIterator($itr, '/WpMenuPages\\.php/', \RecursiveIteratorIterator::LEAVES_ONLY);
         $res->next();
         /** @var \SplFileInfo $wpMenuPagesFile */
         $wpMenuPagesFile = $res->current();
         if (!$wpMenuPagesFile instanceof \SplFileInfo) {
             // TODO Message
             throw new \Exception('Something went awfully wrong!');
         }
         $this->basePath = dirname(dirname($wpMenuPagesFile->getPath()));
     } else {
         $this->basePath = dirname(dirname(dirname(__FILE__)));
     }
     $this->basePathRelToPlugin = str_replace($this->pluginBasePath, '', $this->basePath);
     if ($options instanceof Options) {
         $this->options = $options;
     } elseif (is_array($options) && !empty($optionsBaseName)) {
         $this->options = Options::getInstance($optionsBaseName, $options);
     } else {
         throw new \InvalidArgumentException('Invalid argument $options in ' . __METHOD__);
     }
     add_action('admin_init', function () {
         $this->pluginMetaData = get_plugin_data($this->pluginBaseFile);
     });
 }
Esempio n. 9
0
 /**
  * Find templates/resources for the given path.
  *
  * <p><strong>Example:</strong></p>
  *
  * <p>Find all styles in a particular folder (<em>style</em>).</p>
  * <code><pre>
  *   $styles = $this->find('style', '/css/');
  *   foreach ($styles as $name => $url) {
  *    echo '<link rel="stylesheet" type="text/css" href="'.$url.'"/>';
  *   }
  * </pre></code>
  *
  * <p>Alternatively, using the build in $resource manager, it would look like this:</p>
  * <code><pre>
  *   $styles = $this->find('style', '/css/');
  *   foreach ($styles as $name => $url) {
  *    $resourceManager->cssFile($name);
  *   }
  * </pre></code>
  *
  * @param string path The base path, relative to the template/resource path.
  * @param string regexp Optional filter expression; default is <code>null</code> for none.
  * @param string type The resource type; default is <code>View::RESOURCE</code>.
  * @return array A map of matching filenames.
  */
 public function find($path, $regexp = null, $type = View::RESOURCE)
 {
     list($path, $type) = $this->resolveType($path, $type);
     $locations = $this->getLocationsFor($type);
     // iterate in ascending priority, so the more important come first
     $files = array();
     foreach ($locations as $location) {
         $base = $location . '/' . $path;
         if (file_exists($base) && is_dir($base)) {
             $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($base));
             if (null != $regexp) {
                 $it = new \RegexIterator($it, $regexp, \RegexIterator::MATCH);
             }
             for ($it->rewind(); $it->valid(); $it->next()) {
                 $name = str_replace(array($base, '\\'), array('', '/'), $it->current()->getPathname());
                 $files[] = $name;
             }
         }
     }
     return $files;
 }