protected function findFiles($root, $checksums, $type, $path, $mode) { $finder = new FileFinder($root); $finder->setGenerateChecksums($checksums)->excludePath("./exclude")->excludePath("subdir.txt")->withType($type)->withPath($path)->withSuffix('txt')->setForceMode($mode); $files = $finder->find(); return $files; }
public static function getPatchList() { $root = dirname(phutil_get_library_root('phabricator')); // Find the patch files $patches_dir = $root . '/resources/sql/patches/'; $finder = new FileFinder($patches_dir); $results = $finder->find(); $versions = array(); $patches = array(); foreach ($results as $path) { $matches = array(); if (!preg_match('/(\\d+)\\..*\\.(sql|php)$/', $path, $matches)) { continue; } $version = (int) $matches[1]; $patches[] = array('version' => $version, 'path' => $patches_dir . $path); if (empty($versions[$version])) { $versions[$version] = true; } else { throw new Exception("Two patches have version {$version}!"); } } // Files are in some 'random' order returned by the operating system // We need to apply them in proper order $patches = isort($patches, 'version'); return $patches; }
function WikiDB_backend_PearDB($dbparams) { // Find and include PEAR's DB.php. maybe we should force our private version again... // if DB would have exported its version number, it would be easier. @(require_once 'DB/common.php'); // Either our local pear copy or the system one // check the version! $name = check_php_version(5) ? "escapeSimple" : strtolower("escapeSimple"); // TODO: apparently some Pear::Db version adds LIMIT 1,0 to getOne(), // which is invalid for "select version()" if (!in_array($name, get_class_methods("DB_common"))) { $finder = new FileFinder(); $dir = dirname(__FILE__) . "/../../pear"; $finder->_prepend_to_include_path($dir); include_once "{$dir}/DB/common.php"; // use our version instead. if (!in_array($name, get_class_methods("DB_common"))) { $pearFinder = new PearFileFinder("lib/pear"); $pearFinder->includeOnce('DB.php'); } else { include_once "{$dir}/DB.php"; } } else { include_once "DB.php"; } // Install filter to handle bogus error notices from buggy DB.php's. // TODO: check the Pear_DB version, but how? if (DEBUG) { global $ErrorManager; $ErrorManager->pushErrorHandler(new WikiMethodCb($this, '_pear_notice_filter')); $this->_pearerrhandler = true; } // Open connection to database $this->_dsn = $dbparams['dsn']; $this->_dbparams = $dbparams; $this->_lock_count = 0; // persistent is usually a DSN option: we override it with a config value. // phptype://username:password@hostspec/database?persistent=false $dboptions = array('persistent' => DATABASE_PERSISTENT, 'debug' => 2); //if (preg_match('/^pgsql/', $this->_dsn)) $dboptions['persistent'] = false; $this->_dbh = DB::connect($this->_dsn, $dboptions); $dbh =& $this->_dbh; if (DB::isError($dbh)) { trigger_error(sprintf("Can't connect to database: %s", $this->_pear_error_message($dbh)), isset($dbparams['_tryroot_from_upgrade']) ? E_USER_WARNING : E_USER_ERROR); if (isset($dbparams['_tryroot_from_upgrade'])) { return; } } $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, array($this, '_pear_error_callback')); $dbh->setFetchMode(DB_FETCHMODE_ASSOC); $prefix = isset($dbparams['prefix']) ? $dbparams['prefix'] : ''; $this->_table_names = array('page_tbl' => $prefix . 'page', 'version_tbl' => $prefix . 'version', 'link_tbl' => $prefix . 'link', 'recent_tbl' => $prefix . 'recent', 'nonempty_tbl' => $prefix . 'nonempty'); $page_tbl = $this->_table_names['page_tbl']; $version_tbl = $this->_table_names['version_tbl']; $this->page_tbl_fields = "{$page_tbl}.id AS id, {$page_tbl}.pagename AS pagename, {$page_tbl}.hits AS hits"; $this->version_tbl_fields = "{$version_tbl}.version AS version, {$version_tbl}.mtime AS mtime, " . "{$version_tbl}.minor_edit AS minor_edit, {$version_tbl}.content AS content, {$version_tbl}.versiondata AS versiondata"; $this->_expressions = array('maxmajor' => "MAX(CASE WHEN minor_edit=0 THEN version END)", 'maxminor' => "MAX(CASE WHEN minor_edit<>0 THEN version END)", 'maxversion' => "MAX(version)", 'notempty' => "<>''", 'iscontent' => "content<>''"); }
public function buildFileContentHashes() { $files = array(); $root = $this->getConfiguration()->getProjectRoot(); $finder = new FileFinder($root . '/src'); $finder->excludePath('*/.*')->withSuffix('js')->withType('f')->setGenerateChecksums(true); foreach ($finder->find() as $path => $hash) { $path = Filesystem::readablePath($path, $root); $files[$path] = $hash; } return $files; }
/** * run! * (non-PHPdoc) * @see FileFinder#run() */ public function run() { parent::run(); foreach ($this->_file_path_maper as $key => $value) { $this->stat_lines_by_filepath($key); } }
/** * provides default parameters for the FileFinder::find() method * * @see FileFinder::find() * @return An array with the new locales found in the disk */ function find() { // first find the new ones parent::find(Locales::getAvailableLocales(), "locale_*.php"); // and then return them, if any return $this->getNew(); }
public static function Find_Js_Css() { $cssfinder = new FileFinder(); $css = $cssfinder->FindEm("css/", "*.{css}"); $jsfinder = new FileFinder(); $js = $jsfinder->FindEm("js/", "*.{js}"); $resources = ' <?php foreach ($css as $cssnr => $cssvalue): ?> <link rel="stylesheet" type="text/css" href="<?=$cssvalue?>"> <?php endforeach ?> <?php foreach ($js as $jsnr => $jsvalue): ?> <script src="<?=$jsvalue?>"> </script> <?php endforeach ?> '; return $resources; }
/** * @see FileFinder::find() * @return An array with the ids of the new template sets */ function find($currentTemplates = null) { // if no parameter, then use the list of default global templates if ($currentTemplates == null) { $currentTemplates = TemplateSets::getGlobalTemplates(); } // call the parent method after the preparations parent::find($currentTemplates); // and return any new templates return $this->getNew(); }
function LoadFileOrDir(&$request) { $source = $request->getArg('source'); $finder = new FileFinder(); $source = $finder->slashifyPath($source); $page = rawurldecode(basename($source)); StartLoadDump($request, fmt("Loading '%s'", HTML(dirname($source), dirname($source) ? "/" : "", WikiLink($page, 'auto')))); echo "<dl>\n"; LoadAny($request, $source); echo "</dl>\n"; EndLoadDump($request); }
/** * Prefixes with DATA_PATH and slashify */ function NormalizeWebFileName($file) { static $finder; if (!isset($finder)) { $finder = new FileFinder(); } if (defined("DATA_PATH")) { $wikipath = DATA_PATH; $wikipath = $finder->_strip_last_pathchar($wikipath); if (!$file) { return $finder->forcePathSlashes($wikipath); } else { return $finder->forcePathSlashes($wikipath . '/' . $file); } } else { return $finder->forcePathSlashes($file); } }
/** * @return array of WikiPages */ public function getPages() { $self = $this; return Lazy::init($this->_pages, function () use($self) { $pages = array(); foreach (FileFinder::find($self->path, ['fileExt' => WikiRepository::getAvailableFileTypes()]) as $file) { $pages[] = $self->getPageByName($file, false); } return $pages; }); }
function _getMapFromFile($filename) { if (defined('WARN_NONPUBLIC_INTERWIKIMAP') and WARN_NONPUBLIC_INTERWIKIMAP) { $error_html = sprintf(_("Loading InterWikiMap from external file %s."), $filename); trigger_error($error_html, E_USER_NOTICE); } if (!file_exists($filename)) { $finder = new FileFinder(); $filename = $finder->findFile(INTERWIKI_MAP_FILE); } @($fd = fopen($filename, "rb")); @($data = fread($fd, filesize($filename))); @fclose($fd); return $data; }
function perform() { global $Tables; global $Inserts; $createDb = $this->_request->getValue("createDatabase"); // only check for errors in case the database table should already exist! if (!$createDb) { $connectionEsablished = false; // Lets check the 'everything is fine' case first.. $this->_db = connectDb(); if ($this->_db) { $connectionEsablished = true; } else { $connectionEsablished = false; $message = "There was an error selecting the database. Please verify the database was already created or check the 'Create database' checkbox."; } // We were unable to connect to the db and select the right db.. lets try // just to connect.. maybe the database needs to be created (even though the // user did not check the appropriate box). if (!$connectionEsablished) { $this->_db = connectDb(true, false); if (!$this->_db) { $message = "There was an error connecting to the database. Please check your settings."; } } if (!$connectionEsablished) { $this->_view = new WizardView("step1"); $this->setDbConfigValues($this->_view); $this->_view->setErrorMessage($message); $this->setCommonData(true); return false; } } $config = new ConfigFileStorage(); $this->_database = $config->getValue("db_database"); $this->_dbPrefix = $config->getValue("db_prefix"); // create the database if ($createDb) { $this->_db = connectDb(false, false); if (!$this->_db->Execute("CREATE DATABASE " . $this->_database)) { $message = "Error creating the database: " . $this->_db->ErrorMsg(); $this->_view = new WizardView("step1"); $this->setDbConfigValues($this->_view); $this->_view->setErrorMessage($message); $this->setCommonData(true); return false; } else { $message = "Database created successfully.<br/>"; } } // reconnect using the new database. $config = new ConfigFileStorage(); $this->_db->Connect($config->getValue("db_host"), $config->getValue("db_username"), $config->getValue("db_password"), $config->getValue("db_database")); // create the tables $errors = false; foreach ($Tables as $table) { $query = str_replace("{dbprefix}", $this->_dbPrefix, $table["code"]); if ($this->_db->Execute($query)) { $message .= "Table <strong>" . $table["desc"] . "</strong> created successfully.<br/>"; } else { $message .= "Error creating table: " . $this->_db->ErrorMsg() . "<br/>"; $errors = true; } } if ($errors) { $message = "There was an error creating the tables in the database. Please make sure that the user chosen to connect to the database has enough permissions to create tables.<br/><br/>{$message}"; $this->_view = new WizardView("step1"); $this->_view->setErrorMessage($message); $this->setDbConfigValues($this->_view); $this->setCommonData(); return false; } // try to guess the url where plog is running // try to guess the url where plog is running $httpProtocol = array_key_exists("HTTPS", $_SERVER) && $_SERVER["HTTPS"] == "on" ? "https://" : "http://"; $httpHost = $_SERVER["HTTP_HOST"]; $requestUrl = $_SERVER["REQUEST_URI"]; $requestUrl = str_replace("/wizard.php", "", $requestUrl); $plogUrl = $httpProtocol . $httpHost . $requestUrl; // Find some of the tools we are going to need (last one is for os x, with fink installed) // TBD: support for Windows specific directories $folders = array("/bin/", "/usr/bin/", "/usr/local/bin/", "/sw/bin/"); $finder = new FileFinder(); $pathToUnzip = $finder->findBinary("unzip", $folders); $pathToTar = $finder->findBinary("tar", $folders); $pathToGzip = $finder->findBinary("gzip", $folders); $pathToBzip2 = $finder->findBinary("bzip2", $folders); $pathToConvert = $finder->findBinary("convert", $folders); // and execute some insert's foreach ($Inserts as $insert) { $query = str_replace("{dbprefix}", $this->_dbPrefix, $insert); $query = str_replace("{plog_base_url}", $plogUrl, $query); // replace also the placeholders for the paths to the tools $query = str_replace("{path_to_tar}", $pathToTar, $query); $query = str_replace("{path_to_unzip}", $pathToUnzip, $query); $query = str_replace("{path_to_bz2}", $pathToBzip2, $query); $query = str_replace("{path_to_gzip}", $pathToGzip, $query); $query = str_replace("{path_to_convert}", $pathToConvert, $query); $query = str_replace("{path_to_convert}", $pathToConvert, $query); if (!$this->_db->Execute($query)) { $message .= "Error executing code: " . $this->_db->ErrorMsg() . "<br/>"; $errors = true; } } // // show some information regarding the helper tools we're going to need // and wether they were found or not // $message .= "<br/><b>-- Helper tools --</b><br/>"; if ($pathToTar == "") { $message .= "The helper tool 'tar' was not found<br/>"; } else { $message .= "The helper tool 'tar' was found in {$pathToTar}<br/>"; } if ($pathToGzip == "") { $message .= "The helper tool 'gzip' was not found<br/>"; } else { $message .= "The helper tool 'gzip' was found in {$pathToGzip}<br/>"; } if ($pathToUnzip == "") { $message .= "The helper tool 'unzip' was not found<br/>"; } else { $message .= "The helper tool 'unzip' was found in {$pathToUnzip}<br/>"; } if ($pathToBzip2 == "") { $message .= "The helper tool 'bzip2' was not found<br/>"; } else { $message .= "The helper tool 'bzip2' was found in {$pathToTar}<br/>"; } if ($pathToConvert == "") { $message .= "The helper tool 'convert' (from the ImageMagick package) was not found<br/>"; } else { $message .= "The helper tool 'convert' (from the ImageMagick package) was found in {$pathToConvert}<br/>"; } if ($errors) { $this->_view = new WizardView("step1"); $this->setDbConfigValues($this->_view); $message = "There was an error initializing some of the tables. Please make sure that the user chosen to connect to the database has enough permissions to add records to the database.<br/><br/>{$message}"; $this->_view->setErrorMessage($message); $this->setCommonData(); } else { $this->_view = new WizardView("step2"); $this->_view->setValue("message", $message); } // Scan for locales $locales = new Locales(); // find all the new locales that we have not yet stored $f = new LocaleFinder(); $newLocaleCodes = $f->find(); foreach ($newLocaleCodes as $newLocaleCode) { $res = $locales->addLocale($newLocaleCode); } return true; }
<?php require_once dirname(__FILE__) . '/FileFinder.php'; $root = 'C:\\Photos'; $finder = new FileFinder($root, array('jpg'), array(), true); $finder->run(); $finder->sort('asc'); $i = 766; foreach ($finder->get_file_path_maper() as $key => $value) { $file_name = 'IMG' . str_pad($i, 4, '0', STR_PAD_LEFT) . 'A.jpg'; $new_file_path = $root . DIRECTORY_SEPARATOR . $file_name; echo 'file_path = ' . $new_file_path . "\n"; rename($key, $new_file_path); $i++; } echo 'count = ' . count($finder->get_file_path_maper());
public function testNotFound() { $ff = new FileFinder(__DIR__ . '/*.php'); $result = $ff->find('not-found.txt'); $this->assertNull($result); }
public function testFindFilePathWithExtensionWithoutTree() { $fileFinder = new FileFinder(false, $this->tmp, $this->filePathBase); $this->assertEquals($this->filePath, $fileFinder->getFilePath()); }
protected function getFinder() { $finder = new FileFinder(dirname(__FILE__) . '/data'); $finder->excludePath('./exclude')->excludePath('subdir.txt'); return $finder; }
<?php session_start(); //var_dump(phpinfo()); ////////// Automatisch zoeken naar klasses.... function __autoload($classname) { require_once "class/" . $classname . ".php"; } ////////// Automatisch zoeken naar css en javascript $cssfinder = new FileFinder(); $css = $cssfinder->FindEm("../css/", "*.{css}"); $jsfinder = new FileFinder(); $js = $jsfinder->FindEm("../js/", "*.{js}"); $imgfinder = new FileFinder(); $images = $imgfinder->FindEm("img/thumb/", "*.{jpg, jpeg, png, gif}"); $_SESSION["images"] = $images; ////////// Initialisatie Variablen $thumb = ""; $currentpage = basename($_SERVER["PHP_SELF"]); $X = new W_DebugHelper(); if (isset($_POST["wijzig"])) { var_dump($_POST); var_dump($_FILES); $pic = new PictureHandler(); $filepath = $pic->getPicture($_FILES["file"]); var_dump($pic->getFilename()); $thumb = $pic->resize(basename($filepath), $filepath); header("location: index.php"); } ?>
session_start(); ////////// Automatisch zoeken naar klasses.... function __autoload($classname) { require_once "../class/" . $classname . ".php"; } if (!isset($_POST["toonArtikels"])) { $_POST["toonArtikels"] = 0; } if (!isset($_POST["toonUsers"])) { $_POST["toonUsers"] = 0; } ////////// Automatisch zoeken naar css en javascript $cssfinder = new FileFinder(); $css = $cssfinder->FindEm("../css/", "*.{css}"); $jsfinder = new FileFinder(); $js = $jsfinder->FindEm("../js/", "*.{js}"); ////////// Make connection to database ////////// Init Variables $currentpage = basename($_SERVER["PHP_SELF"]); $X = new W_DebugHelper(); // Artikels ophalen... $connection = new W_DatabaseHelper("cms"); $querystring = "SELECT * FROM artikel"; $resultset = $connection->query($querystring); $querystring = "SELECT * FROM users"; $userset = $connection->query($querystring); if (isset($_POST["toggleArtikels"])) { if ($_POST["toonArtikels"] == 1) { $_POST["toonArtikels"] = 0; unset($_POST["toggleArtikels"]);
function update_locale($loc) { // $LANG or DEFAULT_LANGUAGE is too less information, at least on unix for // setlocale(), for bindtextdomain() to succeed. $setlocale = guessing_setlocale(LC_ALL, $loc); // [56ms] if (!$setlocale) { // system has no locale for this language, so gettext might fail $setlocale = FileFinder::_get_lang(); list($setlocale, ) = split('_', $setlocale, 2); $setlocale = guessing_setlocale(LC_ALL, $setlocale); // try again if (!$setlocale) { $setlocale = $loc; } } // Try to put new locale into environment (so any // programs we run will get the right locale.) if (!function_exists('bindtextdomain')) { // Reinitialize translation array. global $locale; $locale = array(); // do reinit to purge PHP's static cache [43ms] if ($lcfile = FindLocalizedFile("LC_MESSAGES/phpwiki.php", 'missing_ok', 'reinit')) { include $lcfile; } } else { // If PHP is in safe mode, this is not allowed, // so hide errors... @putenv("LC_ALL={$setlocale}"); @putenv("LANG={$loc}"); @putenv("LANGUAGE={$loc}"); } // To get the POSIX character classes in the PCRE's (e.g. // [[:upper:]]) to match extended characters (e.g. GrüßGott), we have // to set the locale, using setlocale(). // // The problem is which locale to set? We would like to recognize all // upper-case characters in the iso-8859-1 character set as upper-case // characters --- not just the ones which are in the current $LANG. // // As it turns out, at least on my system (Linux/glibc-2.2) as long as // you setlocale() to anything but "C" it works fine. (I'm not sure // whether this is how it's supposed to be, or whether this is a bug // in the libc...) // // We don't currently use the locale setting for anything else, so for // now, just set the locale to US English. // // FIXME: Not all environments may support en_US? We should probably // have a list of locales to try. if (setlocale(LC_CTYPE, 0) == 'C') { $x = setlocale(LC_CTYPE, 'en_US.' . $GLOBALS['charset']); } else { $x = setlocale(LC_CTYPE, $setlocale); } return $loc; }
<?php function __autoload($classname) { require_once "class/" . $classname . ".php"; } $finder = new FileFinder(); $images = $finder->FindEm("img/", "*.{jpg, jpeg, png, gif}"); ?> <!DOCTYPE html> <html> <head> <title></title> <style> img{ max-width : 29%; } </style> </head> <body> <?php foreach ($images as $key => $value) { ?> <img src="<?php echo $value; ?> " alt="picture number <?php echo $value;
<?php function __autoload($classname) { require_once "class/" . $classname . ".php"; } /* $imgfinder = new FileFinder(); $images = $imgfinder->FindEm("img/", "*.{jpg, jpeg, png, gif}"); */ $jsfinder = new FileFinder(); $js = $jsfinder->FindEm("js/", "*.{js}"); $cssfinder = new FileFinder(); $css = $cssfinder->FindEm("css/", "*.{css}"); $messageContainer = ''; $querystring = "\n\t\t\t\t\n\t\t\t\tSELECT * FROM `bieren` INNER JOIN brouwers \n\t\t\t\tON bieren.brouwernr = brouwers.brouwernr\n\t\t\t\tWHERE bieren.naam like 'du%' AND brouwers.brnaam LIKE '%a%'\n\t\t\t\t\n\t\t\t\t"; try { $connectie = new PDO('mysql:host=localhost;dbname=bieren', 'root', ''); // Connectie maken $messageContainer = 'connectie OK.'; try { $query = $connectie->prepare($querystring); // Een query uitvoeren $query->execute(); $resultset = array(); while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $resultset[] = $row; } // var_dump($resultset); } catch (PDOexception $e) { throw new Exception("Error Processing Request", 1);
/** * @return \DOMDocument */ private function createLog() { $params = $this->logParams; $out = new \DOMDocument(); $out->preserveWhiteSpace = true; $out->appendChild($out->createElement("testsuites")); $rootSuite = $out->createElement("testsuite"); $out->documentElement->appendChild($rootSuite); foreach ($params as $param) { $rootSuite->setAttribute($param, "0"); } /** @var \DOMElement[] $outSuites */ $outSuites = []; foreach ($this->finder->getSuites() as $suite) { $outSuite = $out->createElement("testsuite"); $outSuite->setAttribute("name", $suite); $outSuites[] = $outSuite; $br = $out->createTextNode("\n "); $rootSuite->appendChild($br); $rootSuite->appendChild($outSuite); } $totalSuites = []; foreach ($this->logsFileList as $file) { $d = new \DOMDocument(); $d->load($file); $suites = $d->getElementsByTagName("testsuite")->item(0); // no tests in file if (!$suites) { continue; } $children = $suites->childNodes; for ($i = 0; $i < $children->length; $i++) { /** @var \DOMElement $node */ $node = $children->item($i); if ($node->nodeName == "testsuite") { $file = str_replace(dirname(realpath($this->params->getConfigPath())) . "/", "", $node->getAttribute("file")); $id = $this->finder->getSuiteIdByFile($file); $newNode = $out->importNode($node, true); if (is_int($id)) { $outSuite = $outSuites[$id]; } else { $outSuite = $rootSuite; } $br = $out->createTextNode("\n "); $outSuite->appendChild($br); $outSuite->appendChild($newNode); foreach ($params as $param) { if (!isset($totalSuites[$id][$param])) { $totalSuites[$id][$param] = 0; } $totalSuites[$id][$param] += (double) $node->getAttribute($param); } } } } $overall = []; foreach ($totalSuites as $suite) { foreach ($params as $param) { if (!isset($overall[$param])) { $overall[$param] = 0; } $overall[$param] += $suite[$param]; } } foreach ($overall as $param => $value) { $rootSuite->setAttribute($param, $value); } return $out; }