/** * @param $fields */ public static function OnAfterIBlockUpdate($fields) { $code = $fields['CODE']; $file = \TAO::localDir("cache/infoblock/{$code}.php"); if (is_file($file)) { unlink($file); } }
/** * */ public static final function run() { $c = 0; self::$actions = array(); self::$options = array(); $argv = $GLOBALS['argv']; foreach ($argv as $arg) { $arg = trim($arg); if (preg_match('{^--([^\\s=]+)=(.*)}', $arg, $m)) { self::$options[$m[1]] = $m[2]; } else { if (preg_match('{^--([^\\s=]+)}', $arg, $m)) { self::$options[$m[1]] = true; } else { if ($c == 0) { self::$script = $arg; } else { self::$actions[$c - 1] = $arg; } $c++; } } } foreach (self::$actions as $action) { $dir = \TAO::localDir('lib/CLI'); if (is_dir($dir)) { $dir = dir($dir); while ($entry = $dir->read()) { if (preg_match('{^(.+)\\.php$}', $entry, $m)) { $class = '\\App\\CLI\\' . $m[1]; $object = new $class(); $object->runAction($action); } } } foreach (\TAO::bundles() as $bundle) { $bundle->cli($action, self::$options); } if (isset(self::$handlers[$action])) { $cb = self::$handlers[$action]; if (is_string($cb)) { $cb = array($cb, $action); } if (is_callable($cb)) { call_user_func($cb, self::$options); } } } }
/** * @param $name * @param string $domain * @param bool|false $lang * @return string */ public static function t($name, $domain = 'messages', $lang = false) { if (!$lang) { $lang = \TAO::getCurrentLang(); } $key = "{$domain}.{$lang}"; if (!isset(self::$data[$key])) { self::$data[$key] = array(); $file = "lang/{$key}.php"; self::mergeLangData(self::$data[$key], \TAO::taoDir($file)); foreach (\TAO::bundles() as $bundle) { self::mergeLangData(self::$data[$key], $bundle->filePath($file)); } self::mergeLangData(self::$data[$key], \TAO::localDir($file)); } return isset(self::$data[$key][$name]) ? self::$data[$key][$name] : "[lang:{$domain}/{$lang}/{$name}]"; }
/** * @param array $cfg */ public static function init($cfg = array()) { foreach ($cfg as $k => $v) { self::$config[$k] = $v; } if (isset($GLOBALS['TAO_INITED'])) { return; } $GLOBALS['TAO_INITED'] = true; $cfgFile = \TAO::localDir('.config.php'); if (is_file($cfgFile)) { $extraConfig = (include $cfgFile); self::$config = \TAO::mergeArgs(self::$config, $extraConfig); } self::initAdmin(); if (self::$config['fs_pages']) { self::addBundle('FSPages'); } if (self::$config['elements']) { self::addBundle('Elements'); } \TAO\Auth::init(); AddEventHandler("main", "OnBeforeProlog", function () { }); }
/** * @param $file * @return bool|string */ public function staticPagePath($file) { $path = \TAO::localDir("pages/{$file}"); return is_file($path) ? $path : false; }
/** * @param $args * @param bool|false $name * @return bool|string */ public function templateForArgs($args, $name = false) { $tpl = isset($args['template']) ? $args['template'] : false; if (!$tpl || !is_file($tpl)) { $tpl = isset($args['mode']) ? $args['mode'] : false; } if (isset($args['view_name'])) { $name = $args['view_name']; } if (!$tpl || !is_file($tpl)) { if ($name) { $tpl = \TAO::localDir("views/{$name}.phtml"); } } if (!is_file($tpl)) { if ($name) { $tpl = \TAO::taoDir("views/{$name}.phtml"); } } return $tpl; }
/** * @param $file * @return string */ public function localPath($file) { $file = trim($file, '/'); return \TAO::localDir("bundles/{$this->name}/{$file}"); }
/** * @param $file * @return bool|string */ public function viewPath($file) { return \TAO::filePath(array(\TAO::localDir("views/navigation"), \TAO::taoDir("views/navigation")), $file); }
/** * @param $name * @return mixed */ public function formObject($name, $check = true) { $path = \TAO::localDir("forms/{$name}.php"); if (is_file($path)) { include_once $path; $class = "\\App\\Form\\{$name}"; return new $class($name); } foreach (\TAO::bundles() as $bundle) { $class = $bundle->hasClass("Form\\{$name}"); if ($class) { $object = new $class($name); $object->bundle = $bundle; return $object; } } if ($check) { print "Unknown form '{$name}'"; die; } }
/** * @param $dir * @return array */ private function fileDirs($dir) { $dirs = array(); $sub = $this->subdir(); if ($this->bundle) { if ($sub) { $dirs[] = $this->bundle->localPath("{$dir}/shop/{$sub}"); } $dirs[] = $this->bundle->localPath("{$dir}/shop"); } if ($sub) { $dirs[] = \TAO::localDir("{$dir}/shop/{$sub}"); } $dirs[] = \TAO::localDir("{$dir}/shop"); $dirs[] = \TAO::taoDir("{$dir}/shop"); return $dirs; }
/** * @param $sub * @return array */ public function dirs($sub) { $dirs = array(); if ($this->dir) { $dirs[] = "{$this->dir}/{$sub}"; } $dirs[] = \TAO::localDir($sub); $dirs[] = \TAO::taoDir($sub); return $dirs; }
/** * @return string */ public function sectionClassName() { $code = $this->getMnemocode(); if (isset(self::$sectionClasses[$code])) { return self::$sectionClasses[$code]; } if (!$this->sectionClassName) { $path = \TAO::localDir("section/{$code}.php"); if (is_file($path)) { include_once $path; $this->sectionClassName = '\\App\\Section\\' . $code; } else { if ($bundle = $this->bundle()) { if ($className = $bundle->getSectionClassName($code)) { $this->sectionClassName = $className; } } } if (!$this->sectionClassName) { $this->sectionClassName = '\\TAO\\Section'; } } return $this->sectionClassName; }