예제 #1
0
 public function render(Context $ctx, array $options = array())
 {
     $options = array_merge(array('name' => 'custom', 'title' => MCMS_HOST_NAME, 'xsl' => os::path('lib', 'modules', 'rss', 'default.xsl'), 'base' => $ctx->url()->getBase($ctx), 'description' => 'News from ' . MCMS_HOST_NAME, 'language' => 'ru', 'url' => 'http://' . MCMS_HOST_NAME . $ctx->url()->string()), $options);
     $content = html::wrap('nodes', Node::findXML($this->filter, $ctx->db));
     $content = html::em('rss', $options, $content);
     return xslt::transform($content, $options['xsl'], 'text/xml');
 }
예제 #2
0
 /**
  * Добавление произвольных файлов в XML ноды.
  * @mcms_message ru.molinos.cms.node.xml
  */
 public static function on_get_node_xml(Node $node)
 {
     if ($node instanceof FileNode) {
         return;
     }
     return html::wrap('files', Node::findXML(array('class' => 'file', 'deleted' => 0, 'id' => $node->getDB()->getResultsV("nid", "SELECT `nid` FROM `node__rel` WHERE `tid` = ? AND `key` IS NULL", array($node->id))), $node->getDB()));
 }
예제 #3
0
 protected function onGetSimple(array $options)
 {
     $cart = new Cart($this->ctx);
     $result = $cart->getXML();
     $result .= $cart->getConfigXML();
     return html::wrap('cart', $result, array('mode' => 'simple'));
 }
예제 #4
0
 /**
  * Форматирование значения. Вызывает обработчики вроде типографа.
  */
 public function format(Node $node, $em)
 {
     $value = $node->{$this->value};
     $ctx = Context::last();
     $ctx->registry->broadcast('ru.molinos.cms.format.text', array($ctx, $this->value, &$value));
     return html::wrap($em, html::cdata($value));
 }
예제 #5
0
 public function getExtraXMLContent()
 {
     $result = '';
     foreach (self::split($this->answers) as $k => $v) {
         $result .= html::em('answer', array('value' => $k), html::cdata($v));
     }
     return parent::getExtraXMLContent() . html::wrap('answers', $result);
 }
예제 #6
0
 /**
  * Добавляет главный RSS во все страницы.
  * @mcms_message ru.molinos.cms.page.head
  */
 public static function on_get_head(Context $ctx)
 {
     $result = '';
     if ($rss = $ctx->config->get('modules/rss/feedurl')) {
         $result .= html::em('link', array('rel' => 'alternate', 'type' => 'application/rss+xml', 'href' => $rss, 'title' => $ctx->config->get('modules/rss/feedname')));
     }
     return html::wrap('head', html::cdata($result), array('module' => 'rss', 'weight' => 50));
 }
예제 #7
0
 public function format(Node $node, $em)
 {
     if (is_array($value = $node->{$this->value})) {
         $data = $value;
         $embed = $data['embed'];
         unset($data['embed']);
         return html::wrap($em, html::cdata($embed), $data);
     }
 }
예제 #8
0
 public function format(Node $node, $em)
 {
     $value = $node->{$this->value};
     $tmp = '';
     foreach ((array) $value as $line) {
         $tmp .= html::em('link', $line);
     }
     return html::wrap($em, $tmp);
 }
예제 #9
0
 public static function on_get_delete(Context $ctx)
 {
     $list = '';
     foreach ((array) $ctx->get('delete') as $name) {
         $list .= html::em('widget', array('name' => $name));
     }
     if (empty($list)) {
         throw new PageNotFoundException();
     }
     return html::wrap('content', $list, array('name' => 'delete-widgets', 'title' => t('Виджеты'), 'base' => self::listurl));
 }
예제 #10
0
 public static function on_get_delete(Context $ctx)
 {
     $pages = '';
     foreach ((array) $ctx->get('check') as $id) {
         $pages .= html::em('page', urldecode($id));
     }
     if (empty($pages)) {
         throw new ForbiddenException(t('Не выбраны пути для удаления.'));
     }
     return html::wrap('content', $pages, array('name' => 'route-delete'));
 }
예제 #11
0
 public static function on_get_groups(Context $ctx)
 {
     $nodes = Node::find(array('class' => 'group', 'deleted' => 0), $ctx->db);
     $counts = $ctx->db->getResultsKV('id', 'count', "SELECT tid AS id, COUNT(*) AS count FROM node__rel r INNER JOIN node g ON g.id = r.tid INNER JOIN node u ON u.id = r.nid WHERE g.deleted = 0 AND u.deleted = 0 AND g.class = 'group' AND u.class = 'user' GROUP BY tid");
     $html = '';
     foreach ($nodes as $node) {
         $count = isset($counts[$node->id]) ? $counts[$node->id] : 0;
         $html .= html::em('node', array('id' => $node->id, 'name' => $node->getName(), 'created' => $node->created, 'users' => $count, 'editable' => $node->checkPermission(ACL::UPDATE), 'published' => true));
     }
     $html = html::wrap('data', $html);
     return html::em('content', array('name' => 'list', 'preset' => 'groups', 'title' => t('Группы пользователей'), 'nosearch' => true, 'create' => 'admin/create/group'), $html);
 }
예제 #12
0
 /**
  * Формирование предварительного просмотра.
  *
  * Загружает данные прямо из БД, чтобы видеть метки, которые не дошли
  * до XML представления.  Такие метки выделяются курсивом.
  */
 public function preview($value)
 {
     if ($labels = $value->{$this->value}) {
         $result = array();
         foreach ($this->getLabelsFor($value) as $id => $name) {
             if (!array_key_exists($id, $labels)) {
                 $name = html::em('em', $name);
             }
             $result[] = html::em('a', array('href' => 'admin/node/' . $id), $name);
         }
         return html::wrap('value', html::cdata(implode(', ', $result)), array('html' => true));
     }
 }
예제 #13
0
 public function format(Node $node, $em)
 {
     $value = $node->{$this->value};
     include_once os::path(dirname(__FILE__), 'markdown.php');
     $output = Markdown($value);
     $ctx = Context::last();
     $ctx->registry->broadcast('ru.molinos.cms.format.text', array($ctx, $this->value, &$output));
     $attrs = array();
     if (!($sniplen = $this->sniplen)) {
         $sniplen = 50;
     }
     $attrs['snippet'] = mb_strimwidth(strip_tags($output), 0, $sniplen, '…');
     return html::wrap($em, html::cdata(trim($output)), $attrs);
 }
예제 #14
0
 protected function getData()
 {
     $data = Node::find(array('class' => 'type', 'deleted' => 0, '#sort' => '-published name'), $this->ctx->db);
     $counts = $this->ctx->db->getResultsKV("name", "count", "SELECT `class` AS `name`, COUNT(*) AS `count` FROM `node` WHERE `deleted` = 0 GROUP BY `class`");
     $nodes = '';
     foreach ($data as $node) {
         if ($node->isdictionary) {
             $attrs = array('id' => $node->id, 'name' => $node->name, 'title' => $node->title, 'list' => Node::create($node->name)->getListURL(), 'published' => (bool) $node->published);
             $attrs['count'] = array_key_exists($node->name, $counts) ? $counts[$node->name] : 0;
             $nodes .= html::em('node', $attrs);
         }
     }
     return html::wrap('data', $nodes);
 }
예제 #15
0
 public function format(Node $noed, $em)
 {
     $value = $node->{$this->value};
     if (is_array($value) and !empty($value['lat']) and !empty($value['lon'])) {
         $ll = $value['lat'] . ',' . $value['lon'];
         $key = Context::last()->config->get('modules/googlemaps/key');
         $img = html::em('img', array('src' => sprintf('http://maps.google.com/staticmap?center=%s&zoom=%u&size=%ux%u&hl=ru&key=%s', $ll, $this->zoom_embed, $this->width, $this->height, $key), 'width' => $this->width, 'height' => $this->height, 'alt' => $value));
         if (!($zoom_link = $this->zoom_link)) {
             $zoom_link = $this->zoom_embed + 2;
         }
         $result = html::em('a', array('href' => sprintf('http://maps.google.com/maps?ll=%s&z=%u', $ll, $zoom_link), 'title' => $value), $img);
         return html::wrap($em, html::cdata($result), array('address' => $value['query']));
     }
 }
예제 #16
0
 /**
  * Добавление скриптов к странице.
  * @mcms_message ru.molinos.cms.page.head
  */
 public static function on_get_head(Context $ctx, array $pathinfo)
 {
     if ($query = $ctx->get('query') and $key = $ctx->config->get('modules/search/gas_key')) {
         $query = str_replace('"', "'", $query);
         $paths = array(os::path(MCMS_SITE_FOLDER, 'gas.js'), os::path('lib', 'modules', 'search', 'gas.js'));
         $output = '';
         foreach ($paths as $path) {
             if (file_exists($path)) {
                 $js = str_replace('QUERY', $query, file_get_contents($path));
                 $js = str_replace('HOSTNAME', url::host($_SERVER['HTTP_HOST']), $js);
                 $output = '<script type="text/javascript" src="http://www.google.com/jsapi?key=' . $key . '"></script>' . '<script type="text/javascript">' . $js . '</script>';
                 return html::wrap('head', html::cdata($output), array('module' => 'search'));
             }
         }
     }
 }
예제 #17
0
 /**
  * Возвращает информацию о правах на разделы.
  * @route GET//api/taxonomy/access.xml
  */
 public static function on_get_access(Context $ctx)
 {
     if (!$ctx->user->hasAccess(ACL::UPDATE, 'tag')) {
         throw new ForbiddenException();
     }
     $data = $ctx->db->getResults("SELECT n.id, n.parent_id, n.name, (SELECT MIN(uid) FROM {node__access} WHERE nid = n.id AND p = 1) AS `publishers`, (SELECT MIN(uid) FROM {node__access} WHERE nid = n.id AND u = 1) AS `owners` FROM {node} n WHERE n.class = 'tag' AND n.deleted = 0 ORDER BY n.left");
     $result = self::recurse($data, null);
     return new Response(html::em('sections', $result), 'text/xml');
     $perms = $ctx->db->getResultsKV("nid", "gid", "SELECT a.nid AS nid, MIN(a.uid) AS gid FROM node__access a INNER JOIN node n ON n.id = a.nid INNER JOIN node g ON g.id = a.uid WHERE n.class = 'tag' AND g.class = 'group' AND a.p = 1 GROUP BY a.nid");
     $data = Node::getSortedList('tag');
     $tmp = '';
     foreach ($data as $k => $v) {
         $gid = array_key_exists($k, $perms) ? $perms[$k] : null;
         $tmp .= html::em('section', array('id' => $k, 'group' => $gid, 'level' => 1 + (strlen($v) - strlen(ltrim($v))) / 2), html::cdata(trim($v)));
     }
     $result .= html::wrap('sections', $tmp);
     return new Response($result, 'text/xml');
 }
예제 #18
0
 /**
  * Список полей для конкретного типа.
  */
 public static function on_list_fields(Context $ctx)
 {
     $type = $ctx->get('type');
     $node = Node::load(array('class' => 'type', 'name' => $type, 'deleted' => 0), $ctx->db);
     if (empty($node->fields)) {
         if ($node->backportLinkedFields()) {
             $ctx->db->beginTransaction();
             $node->save();
             $ctx->db->commit();
         }
     }
     $types = '';
     foreach (Control::getKnownTypes() as $k => $v) {
         if (!empty($v)) {
             $types .= html::em('type', array('name' => $k, 'title' => $v));
         }
     }
     return html::em('content', array('name' => 'typefields', 'title' => t('%type: поля', array('%type' => $node->title)), 'base' => 'admin/structure/fields'), $node->getXML() . html::wrap('types', $types));
 }
예제 #19
0
 /**
  * @mcms_message ru.molinos.cms.page.head
  */
 public static function on_get_head(Context $ctx)
 {
     if (self::isPageEnabled($ctx)) {
         $result = '';
         $base = $ctx->url()->getBase($ctx);
         $result .= html::em('script', array('type' => 'text/javascript'), "var mcms_url = '{$base}';");
         if ($picker = $ctx->get('tinymcepicker')) {
             $result .= html::em('script', "var tinyMcePicker = '{$picker}';");
             $result .= html::em('script', array('src' => $base . 'lib/modules/tinymce/editor/tiny_mce_popup.js', 'type' => 'text/javascript'));
         } elseif (preg_match('%^(admin/edit/|admin/create/)%', $ctx->query())) {
             foreach (self::on_compressor_admin($ctx) as $script) {
                 if (file_exists($script[1])) {
                     $result .= html::em('script', array('src' => $base . $script[1], 'type' => 'text/javascript'));
                 }
             }
         }
         return html::wrap('head', html::cdata($result), array('module' => 'tinymce'));
     }
 }
예제 #20
0
 /**
  * Добавление нескольких файлов (форма).
  */
 public static function on_get_form(Context $ctx, $path, array $pathinfo)
 {
     $content = $help = '';
     $next = '?destination=' . urlencode($ctx->get('destination'));
     $next .= '&sendto=' . urlencode($ctx->get('sendto'));
     $options = array('name' => 'addfile', 'title' => t('Добавление файлов в архив'), 'mode' => $pathinfo['mode'], 'target' => $path . $next, 'back' => $ctx->get('destination'), '#text' => '');
     $options['#text'] .= self::get_modes($ctx, $pathinfo['mode']);
     switch ($mode = $pathinfo['mode']) {
         case 'remote':
             $options['title'] = t('Добавление файлов с другого сайта', array('@url' => 'admin/content/files'));
             $help = t('<p>Введите ссылки на файлы, включая префикс «http://».  Файлы могут быть любого размера.</p>');
             break;
         case 'normal':
             $help = t('<p>Размер одного загружаемого файла не должен превышать %limit1, а суммарный размер всех загружаемых файлов не должен превышать %limit2.</p>', array('%limit1' => ini_get('upload_max_filesize'), '%limit2' => ini_get('post_max_size')));
             break;
     }
     $options['#text'] .= html::wrap('help', html::cdata($help));
     return html::em('content', $options, $content);
 }
예제 #21
0
 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);
 }
예제 #22
0
 /**
  * Формирует таблицу для предварительного просмотра.
  */
 public function getPreviewXML(Context $ctx)
 {
     $xml = parent::getPreviewXML($ctx);
     if (is_array($this->orderdetails)) {
         $params = array();
         $names = $this->getDB()->getResultsKV("id", "name", "SELECT `id`, `name` FROM `node` WHERE `id` " . sql::in(array_keys($this->orderdetails), $params), $params);
         $table = '';
         foreach ($this->orderdetails as $k => $v) {
             $name = isset($names[$k]) ? $names[$k] : '???';
             $row = html::em('td', html::em('a', array('href' => "admin/node/{$k}?destination=CURRENT"), html::plain($name)));
             $row .= html::em('td', html::cdata('× ' . $v));
             $table .= html::em('tr', $row);
         }
         if ($value = html::wrap('table', $table, array('class' => 'classic'))) {
             $xml .= html::em('field', array('title' => t('Содержимое заказа')), html::em('value', array('html' => true), html::cdata($value)));
         }
     }
     return $xml;
 }
예제 #23
0
 private static function getDashboardXML(Database $db, array $query, array $options)
 {
     return html::wrap('content', Node::findXML($query, $db), $options);
 }
예제 #24
0
 /**
  * Возвращает информацию для предварительного просмотра.
  */
 public function preview($node)
 {
     if ($user = $node->{$this->value}) {
         if (!is_object($user)) {
             $user = Node::load($user);
         }
         $html = html::em('a', array('href' => 'admin/node/' . $user->id), html::cdata($user->getName()));
     } elseif ($name = $node->{$this->value . ':name'}) {
         $html = html::plain($name);
     } else {
         $html = t('Авторство не установлено.');
     }
     return html::wrap('value', html::cdata($html));
 }
예제 #25
0
 /**
  * Диспетчер запросов.
  *
  * В зависимости от GET-параметра mode вызывает один из методов: onGetList()
  * или больше никакой.  Гасит ошибки NoIndexException, возвращая вместо них
  * массив с ключём "error", значение которого содержит описание ошибки.
  *
  * @param array $options то, что насобирал getRequestOptions().
  *
  * @return mixed то, что вернул конкретный метод-обработчик.
  */
 public function onGet(array $options)
 {
     $count = null;
     $result = html::wrap('nodes', Node::findXML($query = $this->getQuery($options), $this->ctx->db));
     // Пусто: откатываемся на другой раздел, но только если в текущем разделе
     // вообще ничего нет, на несуществующей странице выводим пустой список.
     if (empty($result)) {
         $count = $query->getCount($this->ctx->db);
         if (!$count and 'empty' == $this->fallbackmode and $this->fixed) {
             $options['section']['id'] = $this->fixed;
             $result = html::wrap('nodes', Node::findXML($query = $this->getQuery($options), $this->ctx->db));
             $count = null;
         }
     }
     if (!empty($result)) {
         // Добавляем информацию о разделе.
         if ($this->showpath and !empty($options['section'])) {
             $tmp = '';
             $section = Node::load($options['section'], $this->ctx->db);
             foreach ($section->getParents() as $node) {
                 $tmp .= $node->push('section');
             }
             if (!empty($tmp)) {
                 $result .= html::em('path', $tmp);
             }
         }
         if ($this->pager and !empty($options['limit'])) {
             if (null === $count) {
                 $count = $query->getCount($this->ctx->db);
             }
             $result .= $this->getPager($count, $options['page'], $options['limit']);
         }
     }
     return $result;
 }
예제 #26
0
 public function getExtraXMLContent()
 {
     if (!Node::create($this->name)->canEditFields()) {
         return html::em('fields', array('static' => true));
     }
     $this->backportLinkedFields();
     $fields = '';
     foreach ((array) $this->fields as $k => $v) {
         if (class_exists($v['type'])) {
             $info = call_user_func(array($v['type'], 'getInfo'));
             if (isset($info['name'])) {
                 $v['typeName'] = $info['name'];
             }
         }
         if (empty($v['weight'])) {
             $v['weight'] = 50;
         }
         if (Node::isBasicField($k)) {
             $v['indexed'] = true;
         }
         $fields .= html::em('field', array('name' => $k) + $v);
     }
     return html::wrap('fields', $fields);
 }
예제 #27
0
 /**
  * Форматирование значения.
  */
 public function format(Node $node, $em)
 {
     return html::wrap($em, html::cdata($node->{$this->value}));
 }
예제 #28
0
 /**
  * Возвращает возможные действия для объекта.
  */
 public static function get_actions_xml(Context $ctx)
 {
     $result = '';
     $from = $ctx->get('from', MCMS_REQUEST_URI);
     foreach (Node::load($ctx->get('id'))->getActionLinks() as $k => $v) {
         if ($from) {
             $v['href'] = str_replace('destination=CURRENT', 'destination=' . urlencode($from), $v['href']);
         }
         $result .= html::em('action', array('name' => $k) + $v);
     }
     return self::xml(html::wrap('actions', $result));
 }
예제 #29
0
 public function format(Node $node, $em)
 {
     $value = $node->{$this->value};
     if (is_object($value) and 'file' == $value->class) {
         if (!($inside = $value->getVersionsXML())) {
             $inside = html::cdata($this->getEmbedCode($value));
         }
         if ($value->description) {
             $inside .= html::em('description', html::cdata($value->description));
         }
         $ctx = Context::last();
         $url = 0 === strpos($value->filetype, 'image/') ? os::webpath($ctx->config->getPath('modules/files/storage', 'files'), $value->filepath) : "download/{$value->id}/{$value->filename}";
         $options = array_merge(array('id' => $value->id, 'name' => $value->name, 'filename' => $value->name, 'filesize' => $value->filesize, 'filetype' => $value->filetype, 'width' => $value->width, 'height' => $value->height, 'url' => $url), (array) $value->metadata);
         return html::em($em, $options, $inside);
     }
     return html::wrap($em, html::cdata($value));
 }
예제 #30
0
 public function preview($value)
 {
     if ($value = $value->{$this->value}) {
         if (is_object($value)) {
             $link = html::em('a', array('href' => 'admin/node/' . $value->id), html::plain($value->name));
             return html::wrap('value', html::cdata($link), array('html' => true));
         }
     }
 }