function list_dir($root) { global $script_path; $files = array(); $dirs = array(); $dir = opendir($root); while (($entry = readdir($dir)) !== false) { if (in_excludes($entry)) { continue; } $full_path = join_paths($root, $entry); if (is_dir($full_path) && $full_path != $script_path) { $dirs[] = $entry; } if (is_file($full_path)) { $files[] = array("name" => $entry, "size" => big_filesize($full_path), "path" => $full_path); } } closedir($dir); sort($files); sort($dirs); reset($files); reset($dirs); return array($files, $dirs); }
function initialize_logger($name) { if (!IN_DEBUG) { return; } global $logger; Logger::configure(array('rootLogger' => array('appenders' => array('default')), 'appenders' => array('default' => array('class' => 'LoggerAppenderRollingFile', 'layout' => array('class' => 'LoggerLayoutPattern', "params" => array("ConversionPattern" => "%d{ISO8601} [%p] %m (at %F line %L)%n")), 'params' => array('file' => join_paths(QWP_LOG_DIR, $name . '.log'), 'append' => true, 'MaxFileSize' => '10MB', 'MaxBackupIndex' => '3'))))); $logger = Logger::getRootLogger(); }
function get_partial_path($name, $partials_base_dir = 'partials', $extension = 'php') { // Replace periods in the name with the directory separator if the developer used dot notation $name = str_replace('.', DIRECTORY_SEPARATOR, $name); // By default, it should just be the extension without the period // If the period was included by accident, remove it if ($extension[0] === '.') { $extension = substr($extension, 1); } return join_paths(get_template_directory(), $partials_base_dir, $name . '.' . $extension); }
function qwp_create_dialog_with_file($dialog_id, $options, $file_name) { global $QWP_DIALOGS; if (!isset($QWP_DIALOGS)) { $QWP_DIALOGS = array(); } if (!isset($options['url']) && !isset($options['content'])) { $options['tmpl'] = $dialog_id; } $QWP_DIALOGS[$dialog_id] = $options; global $MODULE_ROOT; require_once join_paths($MODULE_ROOT, $file_name . '.php'); }
function __autoload($sClassName) { foreach ($_ENV['SETTINGS']['INCLUDE_DIRS'] as $sIncludeDir) { $sFileName = join_paths(getcwd(), "server/{$sIncludeDir}/class.{$sClassName}.php"); if (file_exists($sFileName)) { require_once $sFileName; if (!class_exists($sClassName, false)) { throw new Exception("Class {$sClassName} could not be loaded, check syntax errors"); } return; } } throw new Exception("Class {$sClassName} is not found"); }
<?php /*! * qwp: https://github.com/steem/qwp * * Copyright (c) 2015 Steem * Released under the MIT license */ define('QWP_TOOLS_ROOT', dirname(__FILE__)); define('QWP_ROOT', QWP_TOOLS_ROOT . '/..'); require_once QWP_ROOT . '/include/common.php'; if (count($argv) > 1) { $object = $argv[1]; $template = file_get_contents(join_paths(QWP_ROOT, 'modules', 'users', 'home.js.php')); $template = str_replace('user', $object, $template); $template = str_replace('User', camel_case($object), $template); file_put_contents(join_paths(QWP_TOOLS_ROOT, $object . '.js.php'), $template); } else { echo_line('please specify the object name, eg. user'); }
/** * Called on a fully-resolved URL before returning it. * Once all aliases in a URL have been expanded, it is expanded to the root if * {@link $resolve_to_root} is True. URLs beginning with a {@link $local_anchor} * or a domain are not expanded (both can be resolved without a relative context). * @see _can_have_root() * @param string $url * @param boolean $root_override Overrides {@link $resolve_to_root} if set to {@link Force_root_on}. * @return string * @access private */ protected function _finalize_url($url, $root_override) { if ($this->_needs_root($url, $root_override)) { $url = join_paths($this->root_url, $url, $this->_url_options); } if (isset($this->_parent_resources)) { $url = $this->_parent_resources->_finalize_url($url, $root_override); } return $url; }
/** * Append a url to the current one * Handles separate merging and resolves all '..' marks * @param string $url */ public function append($url) { $opts = $this->options(); $is_file = is_file_name($url, $opts); $this->_text = join_paths($this->_text, $url, $opts); if (!$is_file && !$this->ends_with_delimiter()) { $this->_text .= $opts->path_delimiter; } }
echo $db->authorizeKey($options["hash"]); } else { if ($task === "addUser") { $db = new \mfoley\StudentSQL("students.db"); echo $db->addKey($options["userID"]); } else { if ($task === "generateQR") { $db = new \mfoley\StudentSQL("students.db"); $outfile = $options["outputDir"]; $array = $db->getAll(); $filenames = []; foreach ($array as $str) { array_push($filenames, base64_decode($str)); } if (!is_dir($outfile)) { echo "Path does not exist or is not a directory\n\t" . $outfile . "\n"; die; } else { if (!is_writeable($outfile)) { echo "Path could not be written to.\n\t" . $outfile . "\n"; die; } } include 'qr/qrlib.php'; # Generates a png QR code for each user to exist in the database for ($i = 0; $i < count($array); $i += 1) { QRcode::png($array[$i], join_paths($outfile, $filenames[$i] . ".png")); } } } }
</ul> <form class="navbar-form navbar-right"> <input type="text" class="form-control" placeholder="Search..."> </form> </div> </div> </nav> <?php if (qwp_tmpl_has_sub_modules($MODULE[0])) { ?> <div class="container-fluid"> <div class="row"> <div class="col-sm-3 col-md-2 sidebar"> <ul class="nav nav-sidebar"> <?php if (file_exists(join_paths($MODULE_ROOT, 'home.php'))) { ?> <li class="<?php echo $PAGE ? '' : 'active'; ?> "><a href="<?php echo qwp_uri_current_home(); ?> "><?php EL('Dashboard'); ?> <span class="sr-only">(current)</span></a></li> <?php } ?> <?php
* lms is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jorani. If not, see <http://www.gnu.org/licenses/>. * * @copyright Copyright (c) 2014 - 2015 Benjamin BALET */ //Utility script that converts PHP array i18n files to a POT file //Include all translation files $files = scandir('english/'); foreach ($files as $file) { if ($file != '.' && $file != '..' && $file != 'index.html') { $path = join_paths("english", $file); include $path; } } $strings = array(); //Array of unique strings //File content $messages = 'msgid ""' . PHP_EOL; $messages .= 'msgstr ""' . PHP_EOL; $messages .= '"Project-Id-Version: Jorani\\n"' . PHP_EOL; $messages .= '"POT-Creation-Date: \\n"' . PHP_EOL; $messages .= '"PO-Revision-Date: \\n"' . PHP_EOL; $messages .= '"Last-Translator: \\n"' . PHP_EOL; $messages .= '"Language-Team: Jorani <*****@*****.**>\\n"' . PHP_EOL; $messages .= '"MIME-Version: 1.0\\n"' . PHP_EOL; $messages .= '"Content-Type: text/plain; charset=UTF-8\\n"' . PHP_EOL;
function process_file_upload() { global $UPLOAD_DIR; if (!is_dir($UPLOAD_DIR)) { mkdir($UPLOAD_DIR); } header('Content-Type: application/json'); $protocol = empty($_SERVER['HTTPS']) ? 'http://' : 'https://'; $ext = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); $upload_name = randomish() . '.' . $ext; $upload_file = join_paths($UPLOAD_DIR, $upload_name); $public_url = $protocol . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . "/?i=" . $upload_name; if (move_uploaded_file($_FILES['file']['tmp_name'], $upload_file)) { jecho(["public_url" => $public_url]); } else { jecho(['error' => "Unable to process file upload"]); } }
private function _test_join_paths() { $this->_check_equal('/a/b/c/d/', join_paths('/a/', 'b/././c/d/')); $this->_check_equal('a/b/c/d/', join_paths('a/', 'b/././c/d/')); $this->_check_equal('/a/b/c/d', join_paths('/a/', 'b/././c/d')); $this->_check_equal('/a/b/c/d/', join_paths('/a', 'b/././c/d/')); $this->_check_equal('a/b/c/d/', join_paths('a', 'b/././c/d/')); $this->_check_equal('/a/b/c/d', join_paths('/a', 'b/././c/d')); $this->_check_equal('/a/b/c/d/', join_paths('/a', '/b/././c/d/')); $this->_check_equal('a/b/c/d/', join_paths('a', '/b/././c/d/')); $this->_check_equal('/a/b/c/d', join_paths('/a', '/b/././c/d')); $this->_check_equal('/a/b/c/d/', join_paths('/a/', '/b/././c/d/')); $this->_check_equal('a/b/c/d/', join_paths('a/', '/b/././c/d/')); $this->_check_equal('/a/b/c/d', join_paths('/a/', '/b/././c/d')); $this->_check_equal('/a/b/c/d/', join_paths('/a/b/c/', '../../b/././c/d/')); $this->_check_equal('a/b/c/d/', join_paths('a/b/c/', '../../b/././c/d/')); $this->_check_equal('/a/b/c/d', join_paths('/a/b/c/', '../../b/././c/d')); $this->_check_equal('/a/b/c/d/', join_paths('/a/b/c', '../../b/././c/d/')); $this->_check_equal('a/b/c/d/', join_paths('a/b/c', '../../b/././c/d/')); $this->_check_equal('/a/b/c/d', join_paths('/a/b/c', '../../b/././c/d')); }
$paths = array(); foreach (func_get_args() as $arg) { if ($arg !== '') { $paths[] = $arg; } } return preg_replace('#/+#', '/', join('/', $paths)); } $source = filter_input(INPUT_GET, 'source'); $name = filter_input(INPUT_GET, 'name'); if (is_null($source)) { die('Missing "source".'); } else { if (is_null($name)) { die('Missing "name".'); } } $path = join_paths($jsonObject->backend->file_store->directory, 'temp', $source); if (!file_exists($path)) { die('File not found.'); } header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $name . '"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($path)); readfile($path); unlink($path); die;
function rename_files_with_suffix($src, $dst, $suffix) { $files = scandir($src); foreach ($files as $file) { if (is_dot_dir($file) || !ends_with($file, $suffix)) { continue; } $src_file = join_paths($src, $file); if (file_exists($src_file)) { @rename($src_file, join_paths($dst, $file)); } } }
function process_directory($path, $fn, $recurse) { $dhandle = opendir($path); $files = array(); if ($dhandle) { while (false !== ($fname = readdir($dhandle))) { if ($fname != '.' && $fname != '..') { $subpath = join_paths($path, $fname); if (is_dir($subpath) && $recurse) { // Ignore subdirectories for now. process_directory($subpath, $fn, $recurse); } else { $fn($subpath); } } } closedir($dhandle); } }
function qwp_get_logo() { $img = 'img/logo.png'; $file_path = join_paths(QWP_ROOT, $img); return file_exists($file_path) ? "<img src='{$img}'> " : ''; }
/** * Return the list of files for the given path. * @param string $base_path Must be a full path. * @param string $path_to_prepend Prepended to each file. * @param bool $recurse If true, include all sub-folders. * @param FILE_OPTIONS $opts * @return string[] */ function file_list_for($base_path, $path_to_prepend = '', $recurse = false, $opts = NULL) { if (!isset($opts)) { $opts = global_file_options(); } $base_path = ensure_ends_with_delimiter($base_path, $opts); $Result = array(); if ($handle = @opendir($base_path)) { while (($name = readdir($handle)) != false) { if ($name[0] != '.') { if (is_dir(join_paths($base_path, $name))) { if ($recurse) { $Result = array_merge($Result, file_list_for(join_paths($base_path, $name, $opts), join_paths($path_to_prepend, $name, $opts), $recurse, $opts)); } } else { $Result[] = join_paths($path_to_prepend, $name); } } } closedir($handle); } return $Result; }
// CREATE MAIN JOBS FOLDER $JOBS_FOLDER = $TEMP_DIR . $PATH_SEPERATOR . "jobs"; if (!file_exists($JOBS_FOLDER)) { logger("\t" . "CREATING JOB FOLDER\n"); mkdir($JOBS_FOLDER); } // IF JOB_FOLDER ALREADY EXISTS, CLEAN IT UP $JOB_FOLDER = $JOBS_FOLDER . $PATH_SEPERATOR . $JID; if (file_exists($JOB_FOLDER)) { $LIST_OF_FILES = array(); if ($handle = opendir($JOB_FOLDER)) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { //$LIST_OF_FILES[]=$entry; try { $delete_file = join_paths($JOB_FOLDER, $entry); if (is_dir($delete_file)) { delTree($delete_file); } else { unlink($delete_file); } } catch (Exception $e) { } } } closedir($handle); } // end if (dir) try { @rmdir($JOB_FOLDER); } catch (Exception $e) {
$target_langcode = "km"; //Include all translation files from source language (eg english) $files = scandir($source_lang . '/'); foreach ($files as $file) { if ($file != '.' && $file != '..' && $file != 'index.html') { $path = join_paths($source_lang, $file); include $path; } } $source = $lang; unset($lang); //Include all translation files from target language (eg khmer) $files = scandir($target_lang . '/'); foreach ($files as $file) { if ($file != '.' && $file != '..' && $file != 'index.html') { $path = join_paths($target_lang, $file); include $path; } } //Get prettier variable names, eg. : $target = $lang; unset($lang); //$source['Leave Management System'] = 'Leave Management System'; //$target['Leave Management System'] = 'Gestion des demandes de congé'; $strings = array(); //Array of unique strings //File content $messages = '# ' . PHP_EOL; $messages = '# Translation strings (' . $target_lang . ') from CI source file' . PHP_EOL; $messages = '# ' . PHP_EOL; $messages = 'msgid ""' . PHP_EOL;
function get_user_file_path() { return join_paths(sys_get_temp_dir(), 'user.txt'); }
* @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0 * @link https://github.com/bbalet/jorani * @since 0.3.0 */ require "POParser.php"; $target = "vietnamese"; $copyright = "<?php\n/**\n * Translation file\n * @copyright Copyright (c) 2014-2016 Benjamin BALET\n * @license http://opensource.org/licenses/AGPL-3.0 AGPL-3.0\n * @link https://github.com/bbalet/jorani\n * @since 0.4.5\n * @author See list on Transifex https://www.transifex.com/jorani/\n */\n\n"; //Load and parse the PO file $parser = new POParser(); $messages = $parser->parse($target . '.po'); $lenPO = count($messages[1]); //Scan all translation files $files = scandir($target); foreach ($files as $file) { if (strpos($file, 'php') !== false) { $path = join_paths($target, $file); $ci18n = file_get_contents($path); //Analyse CI i18n files containing the translations (key/value) //$lang['calendar_individual_title'] = 'My calendar'; $pattern = "\$lang\\['(.*)'\\] = '(.*)';\$"; $out = array(); preg_match_all($pattern, $ci18n, $out, PREG_PATTERN_ORDER); $lenI18N = count($out[0]); for ($jj = 0; $jj < $lenI18N; $jj++) { for ($ii = 0; $ii < $lenPO; $ii++) { $po2ci = str_replace('\\"', '"', $messages[1][$ii]['msgid']); $po2ci = str_replace("'", '\'', $po2ci); if ($out[2][$jj] != '') { if (strcmp($po2ci, $out[2][$jj]) == 0) { $po2ci = str_replace('\\"', '"', $messages[1][$ii]['msgstr']); $po2ci = str_replace("'", '\'', $po2ci);
is by example. See the <a href="http://earthli.com/software/webcore/documentation.php">documentation</a> for more information.</p> <p>The requested URL is always shown first; if a page uses one or more WebCore templates, those are shown afterwards.</p> <?php if (is_file($file_name)) { $class_name = $Page->final_class_name('HIGHLIGHTER', 'webcore/util/highlighter.php'); /** @var HIGHLIGHTER $highlighter */ $highlighter = new $class_name($Page); $page_text = $highlighter->file_as_html($file_name); $template_texts = array(); $text_to_search = $page_text; $template_start = strpos($text_to_search, Start_of_template); while ($template_start !== false) { $template_end = strpos($text_to_search, End_of_template, $template_start); $template_name = substr($text_to_search, $template_start, $template_end - $template_start + strlen(End_of_template)); $template_file_name = join_paths($Env->library_path, $template_name); if (@is_file($template_file_name)) { $text_to_search = $highlighter->file_as_html($template_file_name); $template_texts[$template_name] = $text_to_search; } $template_start = strpos($text_to_search, Start_of_template, $template_end); } if (sizeof($template_texts)) { ?> <p>Source for: <span class="field"><?php echo $page_name; ?> </span></p> <p>Uses WebCore template(s):</p> <ul> <?php
/** * Set the edition. */ public function set_edition($edition) { $this->edition = $edition; $this->downloads_dir = join_paths(array($this->downloads_dir, $edition->slug)); $this->downloads_url = join_paths(array($this->downloads_url, $edition->slug)); }
$failed_msg .= $item; $failed_msg .= "</ul>"; $failed_msg .= "to"; $failed_msg .= "<ul>"; $failed_msg .= $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName(); $failed_msg .= "</ul>"; $failed_msg .= getTranslation("Might be a permissions problem.", $settings); } else { // successfully copied file } } } } // DELETE TEMP DIR if (!$failed) { $dir = join_paths($BIN_DIR, "tmp"); $it = new RecursiveDirectoryIterator($dir); $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); foreach ($files as $file) { if ($file->getFilename() === '.' || $file->getFilename() === '..') { continue; } if ($file->isDir()) { rmdir($file->getRealPath()); } else { unlink($file->getRealPath()); } } rmdir($dir); } }
$iterator = new RecursiveIteratorIterator($directory); $regex = new RegexIterator($iterator, '/^.+\\.php$/i', RecursiveRegexIterator::GET_MATCH); foreach ($regex as $file) { //echo 'Examing ' .$file[0] . PHP_EOL; $content = file_get_contents($file[0]); //Search for all possible i18n key foreach ($lang as $key => $message) { //$usage = "lang('" . $key . "')"; if (strpos($content, $key) !== false) { //Remove the message from the array as it is used unset($lang[$key]); } } } echo "Iterate through the controllers of the application..." . PHP_EOL; $path = realpath(join_paths(dirname(getcwd()), 'controllers')); echo $path . PHP_EOL; $directory = new RecursiveDirectoryIterator($path); $iterator = new RecursiveIteratorIterator($directory); $regex = new RegexIterator($iterator, '/^.+\\.php$/i', RecursiveRegexIterator::GET_MATCH); foreach ($regex as $file) { //echo 'Examing ' .$file[0] . PHP_EOL; $content = file_get_contents($file[0]); //Search for all possible i18n key foreach ($lang as $key => $message) { //$usage = "lang('" . $key . "')"; if (strpos($content, $key) !== false) { //Remove the message from the array as it is used unset($lang[$key]); } }
function qwp_initialize() { global $MODULE, $USER, $MODULE_ROOT, $MODULE_URI, $SUPER_MODULE_ROOT, $IS_SUB_MODULE; initialize_logger('qwp'); $USER = null; initialize_request(); if (!$MODULE) { $MODULE = DEFAULT_MODULE; } $MODULE_URI = $MODULE; $MODULE = explode('-', $MODULE); if (!qwp_is_module_name_valid()) { return false; } $MODULE_ROOT = join_paths(QWP_MODULE_ROOT, implode('/', $MODULE)); require_once QWP_MODULE_ROOT . '/bootstrap.php'; $SUPER_MODULE_ROOT = join_paths(QWP_MODULE_ROOT, $MODULE[0]); $IS_SUB_MODULE = $MODULE_ROOT != $SUPER_MODULE_ROOT; return qwp_custom_initialize_check(); }