public static function hookRemoteCall(Context $ctx) { if ($ctx->get('action') and ($result = parent::hookRemoteCall($ctx, __CLASS__)) instanceof Response) { return $result; } $menu = new AdminMenu(); $menu->poll($ctx); if (false === ($result = $menu->dispatch($ctx))) { throw new PageNotFoundException(); } $xmlmenu = $menu->getPath($ctx->query()) . $menu->getXML(); $page = array('status' => 200, 'base' => $ctx->url()->getBase($ctx), 'host' => MCMS_HOST_NAME, 'folder' => $ctx->folder(), 'sitefolder' => os::webpath(MCMS_SITE_FOLDER), 'query' => $ctx->query(), 'version' => defined('MCMS_VERSION') ? MCMS_VERSION : 'unknown', 'cache' => cache::getInstance()->getName(), 'memory' => ini_get('memory_limit'), 'time' => microtime(true) - MCMS_START_TIME, 'back' => urlencode(MCMS_REQUEST_URI)); $page['debug'] = $ctx->canDebug(); if (is_string($result)) { $xslt = isset($ctx->theme) ? $ctx->theme : os::path('lib', 'modules', 'admin', 'template.xsl'); if (file_exists($fname = substr($xslt, 0, -3) . 'css')) { $ctx->addExtra('style', $fname); } if (file_exists($fname = substr($xslt, 0, -3) . 'js')) { $ctx->addExtra('script', $fname); } $result = html::em('request', array('remoteIP' => $_SERVER['REMOTE_ADDR'], 'uri' => urlencode(MCMS_REQUEST_URI)), $ctx->user->getNode()->getXML('user') . $ctx->url()->getArgsXML()) . $xmlmenu . $result . $ctx->getExtrasXML(); $output = html::em('page', $page, $result); $result = xslt::transform($output, $xslt); } return $result; }
/** * Возвращает список скриптов и стилей для использования на сайте. * * @mcms_message ru.molinos.cms.compressor.enumXXX */ public static function on_compressor_enum(Context $ctx, $mode = 'website') { $result = array(); $conf = $ctx->config->get('modules/tinymce'); $conf['gzip'] = false; if (empty($conf['gzip'])) { $result[] = array('script', 'lib/modules/tinymce/editor/tiny_mce.js'); } else { $result[] = array('script', 'lib/modules/tinymce/editor/tiny_mce_gzip.js'); } $initializer = empty($conf['initializer']) ? '' : $conf['initializer'] . ', '; $initializer .= 'document_base_url: "http://' . MCMS_HOST_NAME . $ctx->folder() . '/", '; $initializer .= 'tiny_mce_path: "lib/modules/tinymce/editor"'; $text = 'tinyMCE_initializer = {' . $initializer . '};'; os::write($path = os::path($ctx->config->getPath('main/tmpdir'), 'tinymce_initializer.js'), $text); $result[] = array('script', os::localpath($path)); $theme = empty($conf['theme']) ? 'simple' : $conf['theme']; if (!empty($conf['gzip'])) { if (file_exists($path = os::path('lib', 'modules', 'tinymce', 'editor', 'template_' . $theme . '_gzip.js'))) { $result[] = array('script', os::webpath($path)); } } if (file_exists($path = os::path('lib', 'modules', 'tinymce', 'editor', 'template_' . $theme . '.js'))) { $result[] = array('script', os::webpath($path)); } return $result; }
/** * Вывод формы авторизации. * @route GET//login */ public static function on_get_login_form(Context $ctx) { if ($ctx->user->id and !$ctx->get('stay')) { return $ctx->getRedirect(); } if (class_exists('APIStream')) { APIStream::init($ctx); } $handler = array('theme' => $ctx->config->get('modules/auth/login_theme')); $content = ''; foreach ((array) $ctx->registry->poll('ru.molinos.cms.page.head', array($ctx, $handler, null), true) as $block) { if (!empty($block['result'])) { $content .= $block['result']; } } $content .= self::getXML($ctx); $xml = html::em('page', array('status' => 401, 'base' => $ctx->url()->getBase($ctx), 'host' => MCMS_HOST_NAME, 'prefix' => os::webpath(MCMS_SITE_FOLDER, 'themes'), 'back' => urlencode(MCMS_REQUEST_URI), 'next' => $ctx->get('destination'), 'api' => APIStream::getPrefix(), 'query' => $ctx->query()), $content); if (file_exists($xsl = os::path(MCMS_SITE_FOLDER, 'themes', $handler['theme'], 'templates', 'login.xsl'))) { try { return xslt::transform($xml, $xsl); } catch (Exception $e) { } } return xslt::transform($xml, 'lib/modules/auth/xsl/login.xsl'); }
/** * Вывод списка файлов. */ public static function on_get_list(Context $ctx) { try { $options = array('#raw' => true, 'name' => 'list', 'title' => t('Файловый архив'), 'path' => os::webpath(MCMS_SITE_FOLDER, $ctx->config->get('modules/files/storage')), 'advsearch' => true, 'canedit' => true, 'mode' => $ctx->get('mode', 'table'), 'scope' => $ctx->get('scope'), 'type' => 'file'); $tmp = new FileList($ctx, $options['scope']); return $tmp->getHTML('files', $options); } catch (TableNotFoundException $e) { if ($e->getTableName() != 'node__idx_filetype') { throw $e; } throw new Exception(t('Отсутствует индекс по полю filetype, <a href="@url">исправьте это</a> и возвращайтесь.', array('@url' => 'admin/structure/fields/edit?type=file&field=filetype&destination=' . urlencode(MCMS_REQUEST_URI)))); } }
private static function checkDbAccess(Context $ctx) { if (null !== ($file = $ctx->db->getDbFile())) { if (0 === strpos(realpath($file), MCMS_ROOT . DIRECTORY_SEPARATOR)) { $url = $ctx->url()->getBase($ctx) . os::webpath($file); if (false !== ($headers = (array) @get_headers($url, 1))) { if (3 == count($parts = explode(' ', $headers[0]))) { if (200 == $parts[1]) { return t('Файл базы данных доступен веб серверу, любой желающий может <a href=\'@url\'>скачать его</a>. Пожалуйста, вынесите его в папку, недоступную веб серверу, и измените путь в конфигурационном файле (%config).', array('@url' => $url, '%config' => mcms::config('fullpath'))); } } } } } }
public function getResponse(Context $ctx) { if (class_exists('APIStream')) { APIStream::init($ctx); } $page = array('status' => 200, 'base' => $ctx->url()->getBase($ctx), 'host' => MCMS_HOST_NAME, 'folder' => $ctx->folder(), 'sitefolder' => os::webpath(MCMS_SITE_FOLDER), 'prefix' => os::webpath(MCMS_SITE_FOLDER, 'themes'), 'query' => $ctx->query(), 'version' => defined('MCMS_VERSION') ? MCMS_VERSION : 'unknown', 'cache' => cache::getInstance()->getName(), 'memory' => ini_get('memory_limit'), 'time' => microtime(true) - MCMS_START_TIME, 'back' => urlencode(MCMS_REQUEST_URI), 'back_raw' => MCMS_REQUEST_URI, 'next' => $ctx->get('destination'), 'api' => 'cms://localhost/api/', 'rss' => class_exists('RSSRouter')); $request = ''; if ($userid = $ctx->user->id) { $request .= html::wrap('user', Node::findXML(array('id' => $userid), $ctx->db)); } $request .= $ctx->url()->getArgsXML(); $this->content .= html::wrap('request', $request); foreach ((array) $ctx->registry->poll('ru.molinos.cms.page.head', array($ctx, array(), null)) as $block) { if (!empty($block['result'])) { $this->content .= $block['result']; } } return xslt::transform(html::em('page', $page, $this->content), $this->xsl); }
/** * Редактирование нескольких файлов (форма). */ public static function on_get_edit_form(Context $ctx) { $nodes = Node::findXML(array('class' => 'file', 'id' => explode(' ', $ctx->get('files')), 'deleted' => 0)); return html::em('content', array('name' => 'editfiles', 'title' => t('Редактирование файлов'), 'action' => 'admin/files/edit?destination=' . urlencode($ctx->get('destination')) . '&sendto=' . urlencode($ctx->get('sendto')), 'path' => os::webpath(MCMS_SITE_FOLDER, $ctx->config->get('modules/files/storage')), 'ids' => $ctx->get('files')), $nodes); }
private function getPlayer($_url, array $options = array()) { foreach ($options as $k => $v) { if (null === $v) { unset($options[$k]); } } $options = array_merge(array('width' => 400, 'height' => 300), $options); $ctx = Context::last(); $base = $ctx->url()->getBase($ctx); $_file = $base . $_url; $url = new url(array('path' => $base . 'lib/modules/files/player.swf')); $url->setarg('file', os::webpath($_file)); $url->setarg('width', $options['width']); $url->setarg('height', $options['height']); $params = html::em('param', array('name' => 'movie', 'value' => $url->string())); $params .= html::em('param', array('name' => 'wmode', 'value' => 'transparent')); $obj = array('type' => 'application/x-shockwave-flash', 'data' => $url->string(), 'width' => $options['width'], 'height' => $options['height']); return html::em('object', $obj, $params); }
/** * Возвращает описание версий в XML. */ public function getVersionsXML() { $result = ''; $storage = Context::last()->config->getPath('modules/files/storage', 'files'); foreach ((array) $this->versions as $name => $info) { $info['name'] = $name; $info['url'] = os::webpath($storage, $info['filename']); $info['filename'] = basename($info['filename']); $result .= html::em('version', $info); } return $result; }
public static function formatExtras(array $extras) { $output = ''; foreach ($extras as $item) { switch ($item[0]) { case 'style': $output .= html::em('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => os::webpath($item[1]))); break; case 'script': $output .= html::em('script', array('type' => 'text/javascript', 'src' => os::webpath($item[1]))); break; } } mcms::debug($output); return $output; }
/** * Вывод инфорамации о подключаемых скриптах и стилях. * @mcms_message ru.molinos.cms.page.head */ public static function on_get_head(Context $ctx, array $pathinfo = null) { $output = ''; if (self::isAdminPage($query = $ctx->query())) { list($scripts, $styles) = self::getAdminFiles($ctx, !$ctx->get('nocompress')); } elseif (null !== $pathinfo and !empty($pathinfo['theme'])) { list($scripts, $styles) = self::getThemeFiles($ctx, $pathinfo['theme'], !$ctx->get('nocompress')); } else { $scripts = $styles = array(); } foreach ($styles as $fileName) { if (file_exists($fileName) and filesize($fileName)) { $output .= html::em('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => os::webpath($fileName))); } } foreach ($scripts as $fileName) { if (file_exists($fileName) and filesize($fileName)) { $output .= html::em('script', array('src' => os::webpath($fileName), 'type' => 'text/javascript')); } } return html::wrap('head', html::cdata($output), array('module' => 'compressor', 'weight' => 100)); }
public function getExtrasXML() { $output = ''; foreach ($this->getExtras() as $e) { $output .= html::em('item', array('type' => $e[0], 'value' => os::webpath($e[1]))); } return empty($output) ? '' : html::em('extras', $output); }