function build($path = false) { if ($path === false) { $path = $this->root; } $dir = new Dir($path); if (!$dir->handle) { $this->error = 'Failed to read directory: ' . $path; return false; } echo '<ul>'; foreach ($dir->read_all() as $file) { if (strpos($file, '.') === 0 || in_array($file, array('CVS', 'PEAR', 'Ext', 'pix', 'install', 'data', 'lang', 'modes.php', 'images.php', 'access.php')) || preg_match('/\\.(jpg|gif|png|css|js)$/i', $file)) { continue; } if (in_array($path . '/' . $file, $this->except) || in_array($file, $this->except)) { continue; } echo '<li>' . $path . '/' . $file . '</li>'; if (@is_dir($path . '/' . $file)) { if (!$this->build($path . '/' . $file)) { $dir->close(); return false; } } elseif (@is_file($path . '/' . $file) && preg_match('/\\.(' . join('|', array_keys($this->extensions)) . ')$/i', $file, $regs)) { if ($file == 'settings.php' && strstr($path, 'forms')) { $regs[1] = 'settings'; } elseif ($file == 'translate.ini.php') { $regs[1] = 'db'; } elseif (strstr($path, 'conf/collections')) { $regs[1] = 'collection'; } elseif ($file == 'config.ini.php') { $regs[1] = 'config'; } elseif ($file == 'settings.ini.php') { $regs[1] = 'settings'; } if (!$this->{$this->extensions[$regs[1]]}($path . '/' . $file, $this->getContents($path . '/' . $file))) { $dir->close(); return false; } } // else it's not a type of file we know how to parse } echo '</ul>'; $dir->close(); return true; }
} } // open log file $log = fopen('inc/app/scheduler/log/scheduler.log', 'a'); $tasks = array(); if ($task == 'all') { // run all of the tasks loader_import('saf.File.Directory'); $dir = new Dir('inc/app/scheduler/tasks'); foreach ($dir->readAll() as $file) { if (strpos($file, '.') === 0 || $file == 'CVS' || in_array($file, $skip) || !@is_dir('inc/app/scheduler/tasks/' . $file)) { continue; } $tasks[] = $file; } $dir->close(); } elseif (empty($task) || $task == 'help') { // display scheduler help loader_import('saf.File.Directory'); $dir = new Dir('inc/app/scheduler/tasks'); foreach ($dir->readAll() as $file) { if (strpos($file, '.') === 0 || $file == 'CVS' || in_array($file, $skip) || !@is_dir('inc/app/scheduler/tasks/' . $file)) { continue; } $tasks[] = $file; } echo <<<END Sitellite Scheduler Abstract:
/** * Returns the display HTML for this widget. The optional * parameter determines whether or not to automatically display the widget * nicely, or whether to simply return the widget (for use in a template). * * @access public * @param boolean $generate_html * @return string * */ function display($generate_html = 0) { $_dl = new MF_Widget_select('MF_' . $this->name . '_DIRLIST'); $_dl->extra = $this->extra; $dir = new Dir($this->directory); if ($this->recursive == 0) { $list = $dir->read_all(); $goodlist = array(); $dir->close(); foreach ($list as $file) { if (!eregi('^\\.ht', $file) && (eregi('\\.(' . join('|', $this->extensions) . ')$', $file) || count($this->extensions) == 0) && $file != '.' && $file != '..') { $goodlist[$file] = $file; } } } else { $goodlist = array(); // recurse $list = $dir->find('*', $this->directory, 1); for ($i = 0; $i < count($list); $i++) { if (!@is_dir($list[$i]) && !eregi('^\\.ht', $list[$i]) && (eregi('\\.(' . join('|', $this->extensions) . ')$', $list[$i]) || count($this->extensions) == 0) && $list[$i] != '.' && $list[$i] != '..') { $list[$i] = preg_replace('/^' . preg_quote($this->directory . '/', '/') . '/', '', $list[$i]); $goodlist[$list[$i]] = $list[$i]; } } } $_dl->setValues($goodlist); $_dl->data_value = $this->data_value_DIRLIST; $_dirlist = new MF_Widget_hidden($this->name); $data = ''; if ($this->show_viewbutton) { global $intl; $data .= '<script language="JavaScript"> <!-- function ' . $this->name . '_preview (name, params, formname) { // get src from form widget path = "' . $this->web_path . '/' . '" + document.forms[formname].elements[name].options[document.forms[formname].elements[name].selectedIndex].value; pop = window.open (\'\', name, params); pop.document.open (); pop.document.write (\'<link rel="stylesheet" type="text/css" href="css/site.css" />\'); pop.document.write (\'<div align="center">\'); pop.document.write (\'<img src="\' + path + \'" alt="\' + name + \'" border="0" />\'); pop.document.write (\'<br /><br /><a href="#" onclick="window.close ()">' . $intl->get('Close Window') . '</a></div>\'); } // --> </script>'; $showbutton = ' <a href="#" onclick="' . $this->name . '_preview (\'MF_' . $this->name . '_DIRLIST\', \'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,dependent=no,fullscreen=no,width=300,height=300,top=50,left=160\', \'' . $this->formname . '\')">' . $intl->get('Preview') . '</a>'; } else { $showbutton = ''; } if ($generate_html) { $data .= $_dirlist->display(0) . "\n"; $data .= "\t<tr>\n\t\t<td>" . '<label for="' . $this->name . '"' . $this->invalid() . '>' . $this->display_value . "</label></td>\n\t\t<td>" . $_dl->display(0) . $showbutton . "</td>\n\t</tr>\n"; } else { $data .= $_dirlist->display(0); $data .= $_dl->display(0); $data .= $showbutton; } return $data; }
/** * Returns a list of collection names for use in looping * through multiple collections at a time. Called as a * static method, ie. Rex::getCollections (). * * @return array */ function getCollections() { loader_import('saf.File.Directory'); $dir = new Dir('inc/app/cms/conf/collections'); $list = array(); foreach ($dir->readAll() as $file) { if (strpos($file, '.') === 0 || !strstr($file, '.php')) { continue; } $list[] = str_replace('.php', '', $file); } $dir->close(); return $list; }
/** * Searches a directory or directories (recursively) for a file * that contains a given string or pattern. Note: this method requires * the saf.File class. * * @access public * @param string $string * @param string $basedir * @param boolean $recursive * @param boolean $regex * @return array * */ function findInFiles($string, $basedir, $recursive = 0, $regex = 0) { $dir = new Dir($basedir); $res = array(); $files = $dir->read_all(); //echo "evaluating $basedir...\n"; foreach ($files as $file) { if ($file == '.' || $file == '..') { continue; } //echo "trying file $file...\n"; if (is_file($basedir . '/' . $file) && File::contains($string, $regex, $basedir . '/' . $file)) { array_push($res, $basedir . '/' . $file); } //exit; if ($recursive && is_dir($basedir . '/' . $file)) { $new_res = Dir::find_in_files($string, $basedir . '/' . $file, $recursive, $regex); // add $new_res to $res foreach ($new_res as $n) { array_push($res, $n); } } } $dir->close(); return $res; }