public function getPlugins() { $output = array(); $it = new DirectoryIterator(BASE . 'plugins/'); while ($it->valid()) { $xml_path = $it->getPath() . $it->getFilename() . '/'; $xml_file = $xml_path . "plugin.xml"; if ($it->isReadable() && $it->isDir() && file_exists($xml_file)) { $output[] = new PapyrinePlugin($xml_path); } $it->next(); } return $output; }
protected function method1($dir, $padLength = 0) { $thisDir = new \DirectoryIterator($dir); foreach ($thisDir as $value) { if ($thisDir->isDot()) { // Skip the dot directories continue; } else { if ($thisDir->isDir()) { if ($thisDir->isReadable()) { // if this is a new directory AND we have permission to read it, recurse into it. echo str_repeat(' ', $padLength * 2) . $value . "\\\n"; $this->method1($dir . '/' . $value, $padLength + 1); } } else { // output the file echo str_repeat(' ', $padLength * 2) . $value . "\n"; } } } return; }
/** * @param null $location * @return bool */ public function exists($location = NULL) { if (!$location) { $location = $this->location; } $di = new \DirectoryIterator($location); return $di->isReadable(); }
/** * Directory iterator * * @param string $fullpath - full path to the director we wish to iterate * @return array - numerical index of returned pages */ private function dirIterator($fullpath) { $it = new DirectoryIterator($fullpath); while ($it->valid()) { if (!$it->isDot() && $it->isFile() && $it->isReadable() && substr($it->getFilename(), -4, 4) == '.php') { $files[] = $it->getFilename(); } $it->next(); } return $files; }
} $home = $_SERVER['HOME']; $account_user = $_SERVER['LOGNAME']; $begin_script = time(); function label($text) { return "\n[" . date('r') . "] " . $text . "\n"; } echo "#################################################\n"; echo "### Starting dreamhost account backup process ###\n"; echo "### " . date('r') . " ###\n"; echo "#################################################\n"; try { // Check if we can read/write to mysql subdir chosen $mysql_arquives = new DirectoryIterator($home . '/' . $backups_dir . '/' . $mysql_subdir); if (!$mysql_arquives->isReadable() || !$mysql_arquives->isWritable()) { throw new RuntimeException('No read or write access.'); } } catch (RuntimeException $e) { exit("Please make sure you provide a valid folder for the arquives, with read and write access.\n"); } // Return an array with stdClass objects from API commands function request_api($cmd) { $api_key = $_SERVER['argv'][1]; $xml = new SimpleXMLElement('https://api.dreamhost.com/?key=' . $api_key . '&cmd=' . $cmd . '&format=xml', null, true); if ((string) $xml->result != 'success') { exit("Request for '{$cmd}' unsuccessful.\n"); } // Use json decode/encode to convert the SimpleXMLElement objects into stdClass objects return json_decode(json_encode($xml->xpath('/dreamhost/data')));