protected static function getSchema($mode) { switch ($mode) { case 'update': return new Schema(array('info' => array('type' => 'InfoControl', 'text' => t('Система полностью обновлена (наличие обновлений проверяется в фоновом режиме, по расписанию).')), 'submit' => array('type' => 'SubmitControl', 'text' => t('Проверить наличие обновлений')))); case 'upgrade': return new Schema(array('modules' => array('type' => 'ModManControl', 'label' => t('Доступные обновления'), 'columns' => array('check', 'name', 'version', 'available'), 'disable_required' => false), 'submit' => array('type' => 'SubmitControl', 'text' => t('Обновить отмеченные')))); default: mcms::debug($mode); } }
public function checkPermission($perm) { $user = Context::last()->user; mcms::debug($this->uid, $this->re); if ($this->cmp($this->uid, $user->id)) { return true; } if ($this->cmp($this->re, $user->id)) { return true; } return false; }
protected function getRequestOptions(Context $ctx, array $params) { $options = parent::getRequestOptions($ctx, $params); if ($params['section'] or $params['document']) { mcms::debug("Виджет {$this->getInstanceName()} не может работать на страницах, параметризуемых кодом раздела или документа."); throw new WidgetHaltedException(); } if (count($ctx->apath) == 1) { $options['user'] = $ctx->apath[0]; } elseif (count($ctx->apath) > 1) { throw new PageNotFoundException(); } else { $options['user'] = null; } $options['limit'] = $this->limit ? $this->limit : 10; $options['page'] = $this->get('page', 1); return $options; }
public function send() { if (headers_sent()) { die(t('<br/>Вывод страницы невозможен: заголовки уже ушли.')); } header('HTTP/1.1 ' . $this->code . ' ' . $this->getResponseTitle()); header('Content-Type: ' . $this->type . '; charset=utf-8'); $this->addHeaders(); $content = $this->getContent(); if (!($length = strlen($content))) { mcms::debug('zero length response'); } if ($this->cache and $this->ckey and $this->ttl) { $store = array('code' => $this->code, 'text' => $this->getResponseTitle(), 'type' => $this->type . '; charset=utf-8', 'length' => $length, 'content' => $content, 'expires' => time() + $this->ttl); $this->cache->{$this->ckey} = $store; } header(sprintf('Content-Length: %u', $length)); die($content); }
protected function getData() { switch ($this->preset) { case 'pages': $data = self::getNodeTree(); if (empty($data)) { $url = 'admin/create/' . $this->type; if ($parent_id = $this->getParentId()) { $url .= '/' . $parent_id; } $url .= '?destination=CURRENT'; $r = new Redirect($url); $r->send(); } return $data; default: mcms::debug($this->ctx->get('preset'), $this->ctx); } }
/** * Вывод содержимого объекта. */ public static function on_get_dump(Context $ctx) { $filter = array('id' => $ctx->get('node')); if (!$ctx->canDebug()) { $filter['deleted'] = 0; } if ($ctx->get('raw')) { $node = Node::load($filter, $ctx->db); $temp = $node->{'never should this field exist'}; mcms::debug($node); } else { $xml = Node::findXML($filter, $ctx->db); if (empty($xml)) { throw new RuntimeException(t('Для этого документа нет XML представления (такого быть не должно), см. <a href="@url">сырой вариант</a>.', array('@url' => '?q=node/' . $filter['id'] . '/dump&raw=1'))); } $res = new Response('<?xml version="1.0"?>' . $xml, 'text/xml'); $res->send(); } throw new ForbiddenException(); }
/** * Заглушка для неверных вызовов. */ private final function __call($method, $args) { mcms::debug('Bad method call', $method); throw new RuntimeException(t('Метод %class::%method() не существует.', array('%class' => get_class($this), '%method' => $method))); }
/** * Возвращает инструкцию для выборки идентификаторов. */ public function getSelect(array $fields = null) { if (!$fields) { $fields = array('`node`.`id`', '`parent_id`', '`name`', '`lang`', '`class`', '`left`', '`right`', '`created`', '`updated`', '`published`', '`uid`', '`deleted`', '`data`'); } $sql = sql::getSelect((array) $fields, $this->tables, $this->conditions); if (!empty($this->order)) { $sql .= ' ORDER BY ' . join(', ', $this->order); } if (null !== $this->limit) { $lim = array(); if (null !== $this->offset) { $lim[] = intval($this->offset); } $lim[] = intval($this->limit); $sql .= ' LIMIT ' . join(', ', $lim); } if ($this->debug) { mcms::debug($sql, $this->params); } return array($sql, $this->params); }
/** * Диспетчер команд. * * Используется для упрощения разделения логики на методы. В соответствии с * запрошенной командой вызывает метод onGetКоманда(). Если метод для * обработки команды отсутствует, возникает PageNotFoundException(). * * @param array $params Команды. Например, при ('one', 'two') будет вызван * метод onGetOneTwo(). * * @param array &$options параметры для обработчика. * * @return mixed результат работы обработчика. */ protected final function dispatch(array $params, array &$options) { $method = 'on'; if (empty($params[0])) { throw new RuntimeException(t('Метод dispatch для виджета %name (%class) вызван без параметра.', array('%name' => $this->name, '%class' => get_class($this)))); } array_unshift($params, 'GET'); foreach ($params as $part) { $method .= ucfirst(strtolower($part)); } if ($method != 'onGet' and method_exists($this, $method)) { return $this->{$method}($options); } mcms::debug("No handler {$method} in class " . get_class($this)); throw new PageNotFoundException(); }
private function parse($url, $options = array()) { $options = array_merge(array('width' => 425, 'height' => 318), $options); $nothing = 'You need Adobe Flash for this.'; $link = array('url' => $url); if (preg_match('%^http://vimeo.com/([0-9]+)%', $url, $m1)) { $link['type'] = 'video/flv'; $link['embed'] = '<object width="' . $options['width'] . '" height="' . $options['height'] . '">' . '<param name="allowfullscreen" value="true" />' . '<param name="allowscriptaccess" value="always" />' . '<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' . $m1[1] . '&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00ADEF&fullscreen=1" />' . '<embed src="http://vimeo.com/moogaloop.swf?clip_id=' . $m1[1] . '&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00ADEF&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="' . $options['width'] . '" height="' . $options['height'] . '">' . '</embed></object>'; $link['host'] = 'Vimeo'; $link['vid'] = $m1[1]; } elseif (preg_match('%^http://video\\.google\\.com/videoplay\\?docid=([0-9\\-]+)%i', $url, $m1)) { $link['type'] = 'video/flv'; $link['embed'] = '<object width="' . $options['width'] . '" height="' . $options['height'] . '"><param name="movie" value="http://video.google.com/googleplayer.swf?docId=' . $m1[1] . '&hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://video.google.com/googleplayer.swf?docId=' . $m1[1] . '&hl=en" type="application/x-shockwave-flash" wmode="transparent" width="' . $options['width'] . '" height="' . $options['height'] . '"></embed></object>'; $link['host'] = 'Google Video'; $link['vid'] = $m1[1]; } elseif (preg_match('%^http://www\\.vesti\\.ru/videos\\?vid=(\\d+)%', $url, $m1)) { $link['type'] = 'video/flv'; $link['host'] = 'vesti.ru'; $link['vid'] = $m1[1]; try { $xml = http::fetch('http://www.vesti.ru/v.xml?adv=1&z=2&vid=' . $link['vid'], http::CONTENT); $s = new SimpleXMLElement($xml); $link['thumbnail'] = (string) $s->picture; } catch (Exception $e) { } $link['embed'] = t('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,29,0" width="408" height="356" id="flvplayer" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="movie" value="http://www.vesti.ru/i/flvplayer.swf?vid=%vid&autostart=false" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="devicefont" value="true" /><param name="bgcolor" value="#000000" /><param name="vid" value="%vid" /><a href="@url"><img src="@thumbnail" alt="preview" /></a></object>', array('%width' => $options['width'], '%height' => $options['height'], '%vid' => $link['vid'], '@thumbnail' => $link['thumbnail'], '@url' => $url)); } elseif (preg_match('%^http://([a-z0-9]+\\.){0,1}youtube\\.com/(?:watch\\?v=|v/)([^&]+)%i', $url, $m1)) { $link['thumbnail'] = 'http://img.youtube.com/vi/' . $m1[2] . '/2.jpg'; $link['type'] = 'video/flv'; $link['host'] = 'YouTube'; $link['vid'] = $m1[2]; $link['embed'] = t("<object width='%width' height='%height'><param name='movie' value='http://www.youtube.com/v/%vid' /><param name='wmode' value='transparent' /><a href='http://www.youtube.com/watch?v=%vid'><img src='@thumbnail' alt='preview' /></a></object>", array('%width' => $options['width'], '%height' => $options['height'], '%vid' => $m1[2], '@thumbnail' => $link['thumbnail'])); } elseif (preg_match('%^http://vids\\.myspace\\.com/index.cfm\\?fuseaction=[^&]+\\&(?:amp;){0,1}videoID=([0-9]+)%i', $url, $m1)) { $link['type'] = 'video/flv'; $link['embed'] = '<embed src="http://lads.myspace.com/videos/vplayer.swf" flashvars="m=' . $m1[1] . '&type=video" type="application/x-shockwave-flash" width="' . $options['width'] . '" height="' . $options['height'] . '"></embed>'; $link['host'] = 'MySpace'; $link['vid'] = $m1[1]; } elseif (preg_match('%^http://vision\\.rambler\\.ru/users/(.+)$%i', $url, $m1)) { $link['type'] = 'video/flv'; $link['embed'] = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' . $options['width'] . '" height="' . $options['height'] . '"><param name="wmode" value="transparent"></param><param name="movie" value="http://vision.rambler.ru/i/e.swf?id=' . $m1[1] . '&logo=1" /><embed src="http://vision.rambler.ru/i/e.swf?id=' . $m1[1] . '&logo=1" width="' . $options['width'] . '" height="' . $options['height'] . '" type="application/x-shockwave-flash" wmode="transparent"/></object>'; $link['host'] = 'Rambler'; $link['vid'] = $m1[1]; } elseif (preg_match('%^http://video\\.mail\\.ru/([a-z]+)/([^/]+)/([0-9]+)/([0-9]+)\\.html*%i', $url, $m1)) { $link['type'] = 'video/flv'; $link['embed'] = '<object width="' . $options['width'] . '" height="' . $options['height'] . '"><param name="flashvars" value="imaginehost=video.mail.ru&perlhost=my.video.mail.ru&alias=' . $m1[1] . '&username='******'&albumid=' . $m1[3] . '&id=' . $m1[4] . '&catalogurl=http://video.mail.ru/catalog/music/" /><param name="movie" value="http://img.mail.ru/r/video/player_full_size.swf?par=http://video.mail.ru/' . $m1[1] . '/' . $m1[2] . '/' . $m1[3] . '/$' . $m1[4] . '$0$248"></param><embed src="http://img.mail.ru/r/video/player_full_size.swf?par=http://video.mail.ru/' . $m1[1] . '/' . $m1[2] . '/' . $m1[3] . '/$' . $m1[4] . '$0$248" type="application/x-shockwave-flash" width="' . $options['width'] . '" height="' . $options['height'] . '" flashvars="imaginehost=video.mail.ru&perlhost=my.video.mail.ru&alias=' . $m1[1] . '&username='******'&albumid=' . $m1[3] . '&id=' . $m1[4] . '&catalogurl=http://video.mail.ru/catalog/music/"></embed></object>'; $link['host'] = 'Mail.Ru'; $link['vid'] = $m1[1] . '/' . $m1[2] . '/' . $m1[3] . '/' . $m1[4]; } elseif (preg_match('%^http://rutube\\.ru/tracks/(\\d+).html\\?v=(.+)$%i', $url, $m1)) { $link['type'] = 'video/flv'; $link['embed'] = '<OBJECT width="' . $options['width'] . '" height="' . $options['height'] . '"><PARAM name="movie" value="http://video.rutube.ru/' . $m1[2] . '" /><PARAM name="wmode" value="transparent" /><EMBED src="http://video.rutube.ru/' . $m1[2] . '" type="application/x-shockwave-flash" wmode="transparent" width="' . $options['width'] . '" height="' . $options['height'] . '" /></OBJECT>'; $link['host'] = 'RuTube'; $link['vid'] = $m[2]; } else { return false; } if (0 === strpos($link['type'], 'video/') and empty($link['thumbnail'])) { mcms::debug($url, $link); $link['thumbnail'] = 'lib/modules/base/video.png'; } return $link; }
private function fromString($source) { // Функция не любит неэкранированные слэши в параметрах, // зато их любят некоторые OpenID провайдеры. $parts = explode('?', $source, 2); if (count($parts) > 1) { $parts[1] = str_replace('/', '%2F', $parts[1]); } $source = join('?', $parts); $url = parse_url($source); if (!is_array($url)) { mcms::debug('Could not parse this URL.', $source); } else { // Парсим дополнительные параметры. if (array_key_exists('query', $url)) { $url['args'] = $this->parse_request_args($url['query']); unset($url['query']); } // Дальше работаем как с массивом. $this->fromArray($url); } }
/** * Вставляет ноду в родительский объект. */ public function format(Node $node, $em) { $ids = array(); foreach ((array) $node->{$this->value} as $v) { if (empty($v)) { } elseif (is_object($v)) { $ids[] = $v->id; } elseif (is_array($v)) { // как так получается?! $ids[] = $v['id']; } else { $ids[] = $v; } } if ('more' == $this->details) { $result = Node::findXML(array('class' => $this->dictionary, 'deleted' => 0, 'id' => $ids)); } else { $params = array($this->dictionary); $data = Context::last()->db->getResults("SELECT `id`, `class`, `published`, `name` FROM {node} WHERE `class` = ? AND `id` " . sql::in($ids, $params), $params); $result = ''; foreach ($data as $row) { $result .= html::em('node', $row); } } if (empty($result)) { mcms::debug($ids, $node); } return html::em($em, $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; }
public function dispatch(Context $ctx) { $cache = cache::getInstance(); $ckey = $this->getCacheKey(); // Если страница есть в кэше — выводим сразу, даже не ищем маршрут. if (empty($_GET['nocache']) and is_array($cached = $cache->{$ckey})) { if (isset($cached['expires']) and time() < $cached['expires']) { Logger::log('hit: ' . MCMS_HOST_NAME . $_SERVER['REQUEST_URI'], 'cache'); header('HTTP/1.1 ' . $cached['code'] . ' ' . $cached['text']); header('Content-Type: ' . $cached['type']); header('Content-Length: ' . $cached['length']); die($cached['content']); } } if (false === ($tmp = $this->find($ctx, $ctx->query()))) { $tmp = $this->find($ctx, 'errors/404'); } if (!empty($tmp[0]['cache'])) { Logger::log('mis: ' . MCMS_HOST_NAME . '/' . $ctx->query(), 'cache'); } elseif (0 !== strpos($ctx->query(), 'api/')) { Logger::log('ign: ' . MCMS_HOST_NAME . '/' . $ctx->query(), 'cache'); } if ($ctx->debug('route')) { mcms::debug($tmp, $this); } if (false === $tmp) { return false; } list($match, $args) = $tmp; if (!empty($match['call'])) { array_unshift($args, $match); array_unshift($args, $ctx->query()); array_unshift($args, $ctx); list($class, $method) = explode('::', $match['call']); if (!class_exists($class) or !method_exists($class, $method)) { throw new RuntimeException(t('Неверный обработчик: <tt>%call()</tt>.', array('%call' => $match['call']))); } $output = call_user_func_array($match['call'], $args); if (empty($output)) { throw new RuntimeException(t('Обработчик этого адреса — %call — ничего не вернул.', array('%call' => $match['call'] . '()'))); } if ($output instanceof Response and !empty($match['cache'])) { $output->setCache($cache, $ckey, $match['cache']); } return $output; } return false; }
private function getDocument(array $options) { if ($options['root'] instanceof Node) { return $options['root']->id ? $options['root'] : null; } elseif (!empty($options['root'])) { return mcms::debug(Node::load(array('id' => $options['root'], '#cache' => false))); } return null; }
public static function make(array $ctl) { $class = $ctl['type']; if (class_exists($class)) { return new $class($ctl); } mcms::debug("Missing control class: {$class}", $ctl); }
public static function on_get_type_fields(Context $ctx, $path, array $pathinfo, $node) { mcms::debug($node); }