function load_element($name) { global $elements, $prefs; if (empty($elements[$name])) { return false; } if (!empty($elements[$name]['loaded'])) { return true; } extract($elements[$name]); $dir = abspath(elements_dir); $file = secpath($name . '.php', $dir); if ($file == false) { trigger_error("path for element '{$name}' is invalid ({$dir})", E_USER_ERROR); } if (!is_file($file) or !is_readable($file)) { trigger_error("{$file} is inaccessible", E_USER_ERROR); } $style = secpath($name . '.css', $dir); if (is_file($style) && is_readable($style)) { $elements[$name]['stylesheet'] = elements_dir . '/' . $name . '.css'; } $elements[$name]['loaded'] = 1; return include_once $file; }
public function getScanDir($resolve = true) { $scandir = $this->getParam("CSV:basedir", "var/import"); if (!isabspath($scandir)) { $scandir = abspath($scandir, Magmi_Config::getInstance()->getMagentoDir(), $resolve); } return $scandir; }
public function write(Page $page) { $file = abspath('app/pages.php'); $buffer = "<?php\n"; $buffer .= "/** This file has been generated automatically by Builder interface */\n"; $buffer .= '$metadata = ' . var_export($data, true) . ";\n"; $buffer .= "?>"; $ok = file_put_contents($file, $buffer); return $ok; }
public static function checkDbTables() { // database tables installer if (!\Meta\Db::tableExists('db_migrations')) { // import the whole initial databse file \Meta\Db::execute(file_get_contents(abspath('sql/database.sql'))); Flash::success(t('Database imported.')); redirect(page_home()); } }
public static function pageFile() { return abspath('app/pages.php'); }
checkvalue($ac['CHMENABLED']); checking("for PHP executable"); if ($ac['PHP'] == '' || $ac['PHP'] == 'no') { $ac['PHP'] = find_file($php_bin_names); } else { if (file_exists($cygwin_php_bat)) { $ac['PHP'] = $cygwin_php_bat; } } if ($ac['PHP'] == '') { checkerror("Could not find a PHP executable. Use --with-php=/path/to/php."); } if (!file_exists($ac['PHP']) || !is_executable($ac['PHP'])) { checkerror("PHP executable is invalid - how are you running configure? " . "Use --with-php=/path/to/php."); } $ac['PHP'] = abspath($ac['PHP']); checkvalue($ac['PHP']); checking("for language to build"); if ($ac['LANG'] == '') { checkerror("Using '--with-lang=' or '--without-lang' is just going to cause trouble."); } else { if ($ac['LANG'] == 'yes') { $ac['LANG'] = 'en'; } } if ($ac["LANG"] == "en") { $ac["TRANSLATION_ONLY_INCL_BEGIN"] = "<!--"; $ac["TRANSLATION_ONLY_INCL_END"] = "-->"; } checkvalue($ac['LANG']); checking("whether the language is supported");
public function findImageFile($ivalue) { // do no try to find remote image if (is_remote_path($ivalue)) { return $ivalue; } // if existing, return it directly if (realpath($ivalue)) { return $ivalue; } // ok , so it's a relative path $imgfile = false; $scandirs = explode(";", $this->getParam("IMG:sourcedir")); $cscandirs = count($scandirs); // iterate on image sourcedirs, trying to resolve file name based on input value and current source dir for ($i = 0; $i < $cscandirs && $imgfile === false; $i++) { $sd = $scandirs[$i]; // scandir is relative, use mdh if ($sd[0] != "/") { $sd = $this->_mdh->getMagentoDir() . "/" . $sd; } $imgfile = abspath($ivalue, $sd, true); } return $imgfile; }
function secpath($path, $pfx = txpath) { // similar to abspath, but the result must reside within $pfx $abs = abspath($path, $pfx); $p = realpath($pfx); if (substr($abs, 0, strlen($p)) == $p) { return $abs; } return false; }
public static function getFilesPath() { return abspath('files/'); }
function render($template, $vars = array()) { $file = abspath('views/' . $template); if (!file_exists($file)) { throw new \Exception('Template not found: ' . basename($file)); } extract($vars); ob_start(); include $file; return ob_get_clean(); }
public function checkErrors() { // check template if ($this->templateFile) { $file = abspath('views/' . $this->templateFile); if (!file_exists($file)) { throw new \Exception(t("The template '{$this->templateFile}' not found.")); } } // sql query errors if ($this->query) { $error = \Meta\Builder::sqlError($this->query); if ($error) { throw new \Exception($error); } } parent::checkErrors(); }
// /a/b/12/34 $a = trim($a, "/"); // a/b/c/d $b = trim($b, "/"); // a/b/12/34 $a = explode("/", $a); // array("a", "b", "c", "d") $b = explode("/", $b); // array("a", "b", "12", "34") //合并上面代码相当于 $a = explode("/", trim(dirname($a), "/")); $num = max(count($a), count($b)); for ($i = 0; $i < $num; $i++) { if ($a[$i] == $b[$i]) { unset($a[$i]); unset($b[$i]); } else { break; } } //$a = array("c", "d"); //$b = array("12", "34"); //第二步:回到同级目录, 进入另一个目录 $path = str_repeat("../", count($b)) . implode("/", $a); // ../../c/d return $path; } $a = "/a/b/c/d/e/w/f/e.php"; $b = "/a/b/12/34/100/c.php"; // ../../c/d echo abspath($a, $b);