public function setup() { if ($this->auth_realm == 'admin') { $this->auth_realm = CMS::$admin_realm; } return parent::setup()->native_views(CMS::app_path("components/" . CMS::$current_component_name . "/views")); }
public function route($request) { $uri = trim(strtolower($this->clean_url($request->uri))); if (CMS_FSPages::$with_htm_extension) { $uri = preg_replace('{\\.htm$}', '/', $uri); } $path = ''; if ($uri == '/') { $path = '/'; } elseif ($m = Core_Regexps::match_with_results('{^/(.+)/$}', $uri)) { foreach (explode('/', $m[1]) as $chunk) { if (Core_Regexps::match('{[a-z0-9_-]+}', $chunk)) { $path .= "/{$chunk}"; } } } if ($path != '') { $dirs = array(CMS::$taopath . '/views/pages', CMS::app_path('views/pages')); /** * @event cms.fspages.dirs * @arg $dirs Список каталогов * Событие генерируется механизмом статических страниц (CMS.FSPages) для уточнения списка каталогов, в которых ищутся шаблоны. При необходимости в список можно добавить свой каталог. */ Events::call('cms.fspages.dirs', $dirs); if (count($dirs) > 0) { for ($i = count($dirs) - 1; $i >= 0; $i--) { $dir = $dirs[$i]; $page = false; $page_path = "{$dir}{$path}/index.phtml"; if (IO_FS::exists($page_path)) { $page = $page_path; } else { $page_path = "{$dir}/{$path}.phtml"; if (IO_FS::exists($page_path)) { $page = $page_path; } } if ($page) { return array('controller' => 'CMS.Controller.FSPages', 'action' => 'index', $page); } } } } return false; }
public function page_navigator($view, $pagenum, $numpages, $url) { $app = CMS::app_path('views/helpers'); $lib = CMS::tao_view('helpers'); $templates = array(); if (CMS::admin()) { $templates[] = "{$app}/page-navigator-admin.phtml"; $templates[] = "{$lib}/page-navigator-admin.phtml"; } else { $templates[] = "{$app}/page-navigator-site.phtml"; $templates[] = "{$app}/page-navigator.phtml"; } $templates[] = "{$lib}/page-navigator.phtml"; foreach ($templates as $template) { if (IO_FS::exists($template)) { break; } } self::$pn_url = $url; self::$pn_current = $pagenum; return $view->partial($template, array('tpl' => $url, 'page' => $pagenum, 'numpages' => $numpages)); }
/** * @return CMS_Controller_Index */ public function setup() { return parent::setup()->use_views_from(CMS::app_path('views')); }
protected function lang_messages_for($file, $lang) { $dir = CMS::site_dir(); if (strpos($file, $dir) === 0) { $rfile = substr($file, strlen($dir)); } else { return false; } $files = array(); if (strpos($rfile, 'tao/') === 0) { $rfile = substr($rfile, 4); $this->add_lang_file_if_exists($files, CMS::tao_path("lang/{$rfile}/{$lang}.php")); } $components_dir = $this->components_dir(); if (strpos($file, $components_dir) === 0) { $cfile = substr($file, strlen($components_dir)); if ($m = Core_Regexps::match_with_results('{^/([^/]+)/(.+)$}', $cfile)) { $component = $m[1]; $cfile = $m[2]; $this->add_lang_file_if_exists($files, CMS::component_dir($component, "app/lang/{$lang}.php")); $this->add_lang_file_if_exists($files, CMS::component_dir($component, "lang/{$lang}.php")); $this->add_lang_file_if_exists($files, CMS::component_dir($component, "app/lang/{$cfile}/{$lang}.php")); $this->add_lang_file_if_exists($files, CMS::component_dir($component, "lang/{$cfile}/{$lang}.php")); } } $this->add_lang_file_if_exists($files, CMS::app_path("lang/{$lang}.php")); $this->add_lang_file_if_exists($files, CMS::app_path("lang/{$rfile}/{$lang}.php")); if (count($files) == 0) { return false; } $messages = array(); foreach ($files as $file) { $fm = (include $file); if (is_array($fm)) { $messages = array_merge($messages, $fm); } } if (count($messages) == 0) { return false; } return $messages; }
/** * @return string */ static function embedded_admin_menu($style = '') { $menu = CMS::navigation()->admin(); if (!$menu || $menu->count() == 0) { return ''; } ob_start(); if (IO_FS::exists(CMS::app_path('views/embedded-admin-menu.phtml'))) { include CMS::app_path('views/embedded-admin-menu.phtml'); } else { include CMS::views_path('embedded-admin-menu.phtml'); } $contents = ob_get_contents(); ob_end_clean(); return $contents; }
/** * @param WebKit_Environment $env * @param WebKit_HTTP_Response $response * * @return Iterator */ public function run(WS_Environment $env) { $response = $env->response; $uri = $env->request->urn; /** * @event cms.actions.dispatch * * Вызывается перед началом диспетчеризации запроса. * Здесь можно подменить что-нибудь в запросе, обратившись к WS::env()->request, выполнить какие-либо действия, * а также вернуть объект Net_HTTP_Response - в этом случае диспетчеризация даже не начнется, * а будет использован возвращенный отклик. * * @arg $uri REQUEST_URI */ $rs = Events::call('cms.actions.dispatch', $uri); if (!is_null($rs)) { return $rs; } if ($m = Core_Regexps::match_with_results('{^/cms-actions/(.+)}', $uri)) { $action = preg_replace('{\\?.+$}', '', $m[1]); if ($m = Core_Regexps::match_with_results('{^files/(.+)/(\\d+)/$}', $action)) { $file = CMS::stdfile(trim($m[1])); if (!IO_FS::exists($file)) { return $response->status(Net_HTTP::NOT_FOUND); } return Net_HTTP::Download($file); } if ($m = Core_Regexps::match_with_results('{^subsite/(.+)}', $action)) { $site = $m[1]; CMS_Admin::set_site($site); $path = CMS::$admin; header("location: /{$path}/"); die; } if ($m = Core_Regexps::match_with_results('{^help/([^/]+)/([^/]+)/(.+)/$}', $action)) { $stddir = CMS::$taopath . '/views/help'; $file = "{$stddir}/en/_notfound"; if ($m[1] == '_app') { $dir = trim($m[2]); $f = trim($m[3]); $f = CMS::app_path("help/{$dir}/{$f}"); if (file_exists($f)) { $file = $f; } } else { $lang = trim($m[1]); $component = trim($m[2]); $help = trim($m[3]); $dir = $component == '_std' ? $stddir : CMS::app_path("components/{$component}/help"); $file = "{$dir}/{$lang}/{$help}"; if (!file_exists($file)) { $file = "{$dir}/{$help}"; if (!file_exists($file)) { $file = "{$dir}/ru/{$help}"; if (!file_exists($file)) { $file = "{$stddir}/{$lang}/_notfound"; if (!file_exists($file)) { "{$stddir}/en/_notfound"; } } } } } $content = CMS::parse_wiki(file_get_contents($file)); include "{$stddir}/screen.phtml"; die; } } if (md5($uri) == '5dc55ea23076fc98474b89cfd51ef6f2') { die($uri . ' ok'); } //FIXME: move to status middleware try { $r = $this->application->run($env); if ($r instanceof Net_HTTP_Response && $r->status->code == 404) { return $this->not_found($env->request->urn, $env, $r); } return $r; } catch (WebKit_Controller_NoRouteException $e) { return $this->not_found($e->url, $env, $response); } }