Ejemplo n.º 1
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));
 }
Ejemplo n.º 2
0
 public function preview($data)
 {
     if ($url = $data->{$this->value}) {
         $a = html::em('a', array('href' => $url), html::plain($url));
         return html::em('value', array('html' => true), html::cdata($a));
     }
 }
Ejemplo n.º 3
0
 public function getXML($data)
 {
     if (null === ($value = $data->{$this->value})) {
         $value = $this->default;
     }
     return parent::wrapXML(array('type' => 'hidden'), html::cdata($value));
 }
Ejemplo n.º 4
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));
 }
Ejemplo n.º 5
0
 public function onGet(array $options)
 {
     $sections = array_intersect_key(Node::getSortedList('tag'), array_flip(Node::create('subscription')->getEnabledSections()));
     $output = html::simpleOptions($sections, 'section', 'sections');
     if ($this->description) {
         $output .= html::em('description', html::cdata($this->description));
     }
     return $output;
 }
 /**
  * Возвращает код для включения в страницу.
  * @mcms_message ru.molinos.cms.page.head
  */
 public static function on_get_content(Context $ctx)
 {
     $conf = $ctx->config->get('modules/googleanalytics');
     if (!empty($conf['account'])) {
         $proto = empty($_SERVER['HTTPS']) ? 'http' : 'https';
         $output = html::em('script', array('src' => $proto . '://www.google-analytics.com/ga.js', 'type' => 'text/javascript'));
         $output .= '<script type="text/javascript">try{var pageTracker = _gat._getTracker("' . $conf['account'] . '");pageTracker._trackPageview();}catch(err){}</script>';
         return html::em('head', array('module' => 'googleanalytics'), html::cdata($output));
     }
 }
Ejemplo n.º 7
0
 /**
  * Добавляет в предварительный просмотр количество отмеченных документов.
  */
 public function getPreviewXML(Context $ctx)
 {
     $result = parent::getPreviewXML($ctx);
     $count = $ctx->db->fetch("SELECT COUNT(*) FROM node WHERE deleted = 0 AND id IN " . "(SELECT nid FROM node__rel WHERE tid = ?) AND class IN " . "(SELECT name FROM node WHERE class = 'type' AND deleted = 0 AND published = 1)", array($this->id));
     if ($count) {
         $message = t('%count (<a href="@url">список</a>)', array('%count' => $count, '@url' => 'admin/content/list?search=tags%3A' . $this->id));
         $result .= html::em('field', array('title' => t('Отмечено документов')), html::em('value', html::cdata($message)));
     }
     return $result;
 }
Ejemplo n.º 8
0
 public function getXML($data)
 {
     $lines = array();
     foreach ((array) $data->{$this->value} as $line) {
         $lines[] = count($line) > 1 ? $line['href'] . ' ' . $line['name'] : $line['href'];
     }
     $this->addClass('form-text');
     $this->addClass('resizable');
     $this->addClass('nowrap');
     return parent::wrapXML(array('rows' => $this->rows, 'cols' => $this->cols), html::cdata(join("\n", $lines)));
 }
Ejemplo n.º 9
0
 /**
  * Возвращает результаты по опросу.
  */
 public static function on_get_results(Context $ctx)
 {
     $output = '';
     $id = $ctx->get('id');
     $data = $ctx->db->getResultsKV("option", "count", "SELECT `option`, COUNT(*) AS `count` FROM `node__poll` WHERE `nid` = ? GROUP BY `option`", array($ctx->get('id')));
     foreach ($data as $k => $v) {
         $output .= html::em('option', array('count' => $v), html::cdata($k));
     }
     $voted = $ctx->user->id ? $ctx->db->fetch("SELECT COUNT(*) FROM `node__poll` WHERE `nid` = ? AND `uid` = ?", array($id, $ctx->user->id)) : $ctx->db->fetch("SELECT COUNT(*) FROM `node__poll` WHERE `nid` = ? AND `ip` = ?", array($id, $_SERVER['REMOTE_ADDR']));
     return new Response(html::em('results', array('voted' => (bool) $voted), $output), 'text/xml');
 }
Ejemplo n.º 10
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));
     }
 }
Ejemplo n.º 11
0
 /**
  * Добавляет информацию о разделах в предварительный просмотр.
  * @mcms_message ru.molinos.cms.hook.preview.xml
  */
 public static function on_preview_tags(Node $node)
 {
     if (!$node->checkPermission(ACL::UPDATE)) {
         return;
     }
     if ($data = $node->getDB()->getResultsKV("id", "name", "SELECT `id`, `name` FROM `node` WHERE `deleted` = 0 AND `class` = 'tag' AND `id` IN (SELECT `tid` FROM `node__rel` WHERE `nid` = ?)", array($node->id))) {
         $result = array();
         foreach ($data as $k => $v) {
             $result[] = html::em('a', array('href' => "admin/node/{$k}?destination=CURRENT"), html::plain($v));
         }
         $result = html::em('value', html::cdata(implode(', ', $result)));
         return html::em('field', array('html' => true, 'title' => t('Находится в разделах'), 'editurl' => "admin/structure/taxonomy/setup?node={$node->id}&destination=" . urlencode(MCMS_REQUEST_URI)), $result);
     }
 }
Ejemplo n.º 12
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);
 }
Ejemplo n.º 13
0
 /**
  * Выводит <link>
  * @mcms_message ru.molinos.cms.page.head
  */
 public static function on_get_head(Context $ctx, array $pathinfo, $param)
 {
     $attrs = array('rel' => 'alternate', 'type' => 'application/x-wiki');
     if ($param) {
         $attrs['title'] = t('Редактировать');
         $attrs['href'] = 'admin/node/' . $param;
     } else {
         $attrs['title'] = t('Создать документ');
         $attrs['href'] = 'admin/create';
     }
     $attrs['href'] = $ctx->url()->getBase($ctx) . $attrs['href'] . '?destination=' . urlencode($_SERVER['REQUEST_URI']);
     $output = html::em('link', $attrs);
     return html::em('head', array('module' => 'ueb'), html::cdata($output));
 }
Ejemplo n.º 14
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']));
     }
 }
Ejemplo n.º 15
0
 public static function on_find_xml(Context $ctx)
 {
     if (null === ($search = $ctx->get('search'))) {
         throw new BadRequestException(t('Не указана подстрока для поиска (GET-параметр search).'));
     }
     if (!($limit = intval($ctx->get('limit', 5)))) {
         throw new BadRequestException(t('Не указано количество возовращаемых меток (GET-параметр limit).'));
     }
     list($sql, $params) = Query::build(array('class' => 'label', 'deleted' => 0, 'published' => 1, 'name?|' => '%' . $search . '%', '#sort' => 'name'))->getSelect(null, null, 'name');
     $result = '';
     foreach ((array) $ctx->db->getResultsV("name", $sql, $params) as $name) {
         $result .= html::em('label', html::cdata($name));
     }
     return new Response(html::em('labels', array('search' => $search, 'limit' => $limit), $result), 'text/xml');
 }
Ejemplo n.º 16
0
 public function getPreviewXML(Context $ctx)
 {
     $xml = parent::getPreviewXML($ctx);
     $data = $ctx->db->getResultsKV("option", "count", "SELECT `option`, COUNT(*) AS `count` FROM `node__poll` WHERE `nid` = ? GROUP BY `option`", array($this->id));
     $result = '';
     foreach (self::split($this->answers) as $k => $v) {
         $count = isset($data[$k]) ? $data[$k] : 0;
         $result .= html::em('li', $v . ': ' . $count);
     }
     if (!empty($result)) {
         $value = html::em('value', html::cdata(html::em('ul', $result)));
         $xml .= html::em('field', array('title' => t('Результаты'), 'editurl' => "admin/edit/{$this->id}/answers?destination=" . urlencode(MCMS_REQUEST_URI)), $value);
     }
     return $xml;
 }
Ejemplo n.º 17
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'));
             }
         }
     }
 }
Ejemplo n.º 18
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');
 }
Ejemplo n.º 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'));
     }
 }
Ejemplo n.º 20
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;
 }
Ejemplo n.º 21
0
 public function getXML($data)
 {
     $selected = $data->{$this->value};
     if (null === $selected) {
         if (null !== $this->default and array_key_exists($this->default, $this->options)) {
             $selected = $this->default;
         } elseif ($this->required) {
             $tmp = array_keys($this->options);
             $selected = $tmp[0];
         }
     }
     if (count($options = $this->getData())) {
         $output = '';
         foreach ($options as $k => $v) {
             $output .= html::em('option', array('selected' => $selected == $k, 'value' => $k), html::cdata($v));
         }
     }
     if (!empty($output)) {
         return parent::wrapXML(array('type' => 'select', 'mode' => 'radio'), $output);
     }
 }
Ejemplo n.º 22
0
 public function getPreviewXML(Context $ctx)
 {
     $result = parent::getPreviewXML($ctx);
     if (!$this->published) {
         $message = t('Документы этого (скрытого) типа не отображаются в обычном <a href="@url1">списке документов</a>, их не предлагают в стандартной <a href="@url2">форме создания документа</a>.', array('@url1' => 'admin/content/list', '@url2' => 'admin/create'));
         $result .= html::em('field', array('title' => t('Комментарий')), html::em('value', html::cdata($message)));
     }
     $count = Node::count(array('class' => $this->name, 'deleted' => 0), $ctx->db);
     if ($count) {
         $message = t('%count документов (<a href="@url">список</a>)', array('%count' => $count, '@url' => Node::create($this->name)->getListURL()));
         $result .= html::em('field', array('title' => t('Статистика')), html::em('value', html::cdata($message)));
     }
     return $result;
 }
Ejemplo n.º 23
0
 public function testCdata()
 {
     $this->assertEquals(null, html::cdata(null));
     $this->assertEquals(null, html::cdata(0));
     $this->assertEquals(null, html::cdata(''));
     $this->assertEquals(null, html::cdata(array(123)));
     $this->assertEquals(null, html::cdata(new stdClass()));
     $this->assertEquals('test', html::cdata('test'));
     $this->assertEquals('<![CDATA[&nbsp;]]>', html::cdata('&nbsp;'));
 }
Ejemplo n.º 24
0
 public function format(Node $node, $em)
 {
     return html::em($em, array('value' => $node->{$this->value}), html::cdata($node->{$this->value} ? 'да' : 'нет'));
 }
Ejemplo n.º 25
0
 /**
  * Возвращает доступные режимы загрузки файлов.
  */
 private static function get_modes(Context $ctx, $mode)
 {
     $result = '';
     $next = array();
     if ($tmp = $ctx->get('sendto')) {
         $next[] = 'sendto=' . urlencode($tmp);
     }
     if ($tmp = $ctx->get('destination')) {
         $next[] = 'destination=' . urlencode($tmp);
     }
     $next = empty($next) ? '' : '?' . implode('&', $next);
     if ($mode != 'normal') {
         $result .= html::em('mode', array('name' => 'normal', 'href' => 'admin/create/file' . $next), html::cdata(t('со своего компьютера')));
     }
     if ($mode != 'remote') {
         $result .= html::em('mode', array('name' => 'remote', 'href' => 'admin/create/file/remote' . $next), html::cdata(t('с другого веб-сайта')));
     }
     if ($mode != 'ftp' and self::getFtpFiles($ctx)) {
         $result .= html::em('mode', array('name' => 'ftp', 'href' => 'admin/create/file/ftp' . $next), html::cdata(t('по FTP')));
     }
     $result .= html::em('mode', array('name' => 'archive', 'href' => 'admin/content/files' . $next), html::cdata(t('найти нужные файлы в архиве')));
     return $result;
 }
Ejemplo n.º 26
0
 private static function getDesktopNotes(Context $ctx)
 {
     $icons = array();
     $ctx->registry->broadcast('ru.molinos.cms.admin.status.enum', array($ctx, &$icons));
     foreach ($icons as $k => $v) {
         if (empty($v['message'])) {
             unset($icons[$k]);
         }
     }
     $output = '';
     foreach ($icons as $icon) {
         $output .= html::em('message', array('link' => str_replace('destination=CURRENT', 'destination=' . urlencode(MCMS_REQUEST_URI), $icon['link'])), html::cdata($icon['message']));
     }
     if (!empty($output)) {
         return html::em('content', array('name' => 'status', 'title' => t('Системные сообщения')), $output);
     }
 }
Ejemplo n.º 27
0
 /**
  * Форматирование значения.
  */
 public function format(Node $node, $em)
 {
     return html::wrap($em, html::cdata($node->{$this->value}));
 }
Ejemplo n.º 28
0
 public function preview($value)
 {
     $file = $value->{$this->value};
     if (!$file instanceof FileNode) {
         return;
     }
     if (0 === strpos($file->filetype, 'image/')) {
         $path = Context::last()->config->getPath('modules/files/storage');
         if (isset($file->versions['thumbnail'])) {
             $attrs = array('width' => $file->versions['thumbnail']['width'], 'height' => $file->versions['thumbnail']['height'], 'src' => os::webpath($path, $file->versions['thumbnail']['filename']));
         } else {
             $attrs = array('width' => $file->width, 'height' => $file->height, 'src' => os::webpath($path, $file->filepath));
         }
         $attrs['alt'] = $file->filename;
         $img = html::em('img', $attrs);
         $html = html::em('a', array('href' => 'admin/node/' . $file->id . '?destination=' . urlencode(MCMS_REQUEST_URI)), $img);
     } else {
         $html = html::em('a', array('href' => "admin/node/{$file->id}?destination=CURRENT"), html::plain($file->filename));
         // $html = $this->getEmbedCode($file);
     }
     if ($value->checkPermission(ACL::UPDATE)) {
         $html .= t('<p><a href="@url">Открепить файл</a></p>', array('@url' => "files/unlink.rpc?node={$value->id}&file={$file->id}&field={$this->value}&destination=" . urlencode(MCMS_REQUEST_URI)));
     }
     return html::em('value', array('html' => true), html::cdata($html));
 }
Ejemplo n.º 29
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));
         }
     }
 }
Ejemplo n.º 30
0
 public function preview($data)
 {
     $nodes = Node::find($filter = array('class' => $this->dictionary, 'deleted' => 0, $this->parents ? 'tagged' : 'tags' => $data->id));
     $items = array();
     foreach ($nodes as $node) {
         $items[$node->id] = $node->getName();
     }
     asort($items);
     $result = array();
     foreach ($items as $k => $v) {
         $result[] = html::em('a', array('href' => 'admin/node/' . $k), html::plain($v));
     }
     $result = empty($result) ? null : implode(', ', $result) . '.';
     if (empty($result)) {
         $result = t('нет');
     }
     return html::em('value', array('html' => true), html::cdata($result));
 }