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');
 }
 public static function rpc_post_subscribe(Context $ctx)
 {
     $data = $ctx->post;
     if (empty($data['sections'])) {
         throw new InvalidArgumentException("Не выбраны разделы для подписки.");
     }
     if (false === strpos($data['email'], '@')) {
         throw new InvalidArgumentException(t('Введённый email не похож на email.'));
     }
     // В массиве могут быть и другие данные, поэтому мы
     // выбираем только то, что нам нужно завернуть.
     $bulk = array('email' => $data['email'], 'sections' => $data['sections']);
     $link = new url(array('args' => array('q' => 'subscription.rpc', 'action' => 'confirm', 'code' => base64_encode(serialize($bulk)))));
     $sections = Node::findXML(array('class' => 'tag', 'deleted' => 0, 'published' => 1, 'id' => $data['sections'], '#sort' => 'name'), $ctx->db, 'section');
     if (empty($sections)) {
         throw new InvalidArgumentException("Выбраны несуществующие разделы для подписки.");
     }
     $xml = html::em('message', array('mode' => 'confirm', 'host' => MCMS_HOST_NAME, 'email' => $data['email'], 'base' => $ctx->url()->getBase($ctx), 'confirmLink' => $link->string()), html::em('sections', $sections));
     $xsl = $ctx->config->get('modules/subscription/stylesheet', os::path('lib', 'modules', 'subscription', 'message.xsl'));
     if (false === ($body = xslt::transform($xml, $xsl, null))) {
         throw new RuntimeException(t('Возникла ошибка при форматировании почтового сообщения.'));
     }
     $subject = t('Подписка на новости сайта %host', array('%host' => MCMS_HOST_NAME));
     // mcms::debug($data['email'], $subject, $body);
     BebopMimeMail::send(null, $data['email'], $subject, $body);
 }
 /**
  * @mcms_message ru.molinos.cms.cron
  */
 public static function taskRun(Context $ctx)
 {
     $types = $ctx->config->get('modules/subscription/types', array());
     $xsl = $ctx->config->get('modules/subscription/stylesheet', os::path('lib', 'modules', 'subscription', 'message.xsl'));
     $sub = $ctx->config->get('modules/subscription/subject', 'Новости сайта %host');
     if (empty($types)) {
         return;
     }
     $ctx->db->beginTransaction();
     $users = Node::find(array('class' => 'subscription', 'deleted' => 0, 'published' => 1, '#sort' => 'name'), $ctx->db);
     // Обрабатываем активных пользователей.
     foreach ($users as $user) {
         $olast = $last = intval($user->last);
         if ($sections = (array) $user->tags) {
             list($sql, $params) = Query::build(array('class' => $types, 'tags' => $sections, 'published' => 1, 'deleted' => 0, 'id' => array('>' . ($olast + 1))))->getSelect(array('id', 'xml'));
             $nodes = $ctx->db->getResultsKV('id', 'xml', $sql, $params);
             // Отправляем документы.
             foreach ($nodes as $nid => $node) {
                 $xml = html::em('message', array('mode' => 'regular', 'unsubscribe' => 'subscription.rpc?action=remove&name=' . urlencode($user->name) . '&id=' . $user->id, 'base' => $ctx->url()->getBase($ctx), 'host' => MCMS_HOST_NAME), $node);
                 $body = xslt::transform($xml, $xsl, null);
                 $subject = t($sub, array('%host' => $ctx->url()->host()));
                 BebopMimeMail::send(null, $user->name, $subject, $body);
                 $last = max($last, $nid);
             }
             // Запоминаем последнее отправленное сообщение.
             $user->last = $last;
             $user->save();
         }
     }
     $ctx->db->commit();
 }
 /**
  * Вывод формы авторизации.
  * @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 rpc_get_default(Context $ctx)
 {
     if ($ctx->config->isOk()) {
         $ctx->redirect('admin');
     }
     $xml = self::listDriversXML();
     $xsl = os::path('lib', 'modules', 'install', 'template.xsl');
     return xslt::transform(html::em('installer', array('base' => $ctx->url()->getBase($ctx), 'dirname' => $ctx->config->getDirName()), $xml), $xsl);
 }
Exemple #6
0
 public static function transform($xml, $xsltName, $mimeType = 'text/html', $status = 200)
 {
     if (null !== self::$lock) {
         Logger::backtrace('XSLT recursion: ' . $xsltName . ' while in ' . self::$lock);
         throw new RuntimeException(t('Рекурсия в XSLT недопустима.'));
     }
     $mode = empty($_GET['xslt']) ? 'server' : $_GET['xslt'];
     $xml = self::fixEntities($xml);
     if ('none' == $mode or empty($xsltName)) {
         return new Response('<?xml version="1.0"?>' . $xml, 'text/xml', $status);
     }
     if (!file_exists($xsltName)) {
         throw new RuntimeException(t('Шаблон %name не найден.', array('%name' => $xsltName)));
     }
     if ('client' == $mode) {
         $xml = str_replace('?>', '?><?xml-stylesheet type="text/xsl" href="' . $xsltName . '"?>', $xml);
         return new Response($xml, 'text/xml');
     }
     $nocache = !empty($_GET['nocache']);
     $cache = cache::getInstance();
     $ckey = 'xml:xsl:' . md5($xml) . ',' . filemtime($xsltName);
     if (false === ($output = $cache->{$ckey}) or $nocache) {
         set_error_handler(array(__CLASS__, 'eh'));
         $doc = new DOMDocument();
         $doc->loadXML($xml);
         if (class_exists('xsltCache') and !$nocache) {
             $proc = new xsltCache();
             $proc->importStyleSheet($xsltName);
         } else {
             $xsl = new DOMDocument();
             @$xsl->load($xsltName);
             $proc = new XSLTProcessor();
             $proc->importStyleSheet($xsl);
         }
         self::$lock = $xsltName;
         if ($output = str_replace(' xmlns=""', '', $proc->transformToXML($doc))) {
             $cache->{$ckey} = $output;
         }
         self::$lock = null;
         restore_error_handler();
     }
     if (empty($output)) {
         throw new RuntimeException(t('Шаблон %xslt ничего не вернул.', array('%xslt' => $xsltName)));
     }
     if (null === $mimeType) {
         return trim(str_replace('<?xml version="1.0"?>', '', $output));
     }
     return new Response($output, $mimeType, $status);
 }
Exemple #7
0
 protected function sendEmail($to, $mode)
 {
     if (empty($to)) {
         Logger::log($mode . ' not sent: email not found', 'cart');
         return;
     }
     if (!($xslt = Context::last()->config->get("modules/cart/{$mode}_templates"))) {
         Logger::log($mode . ' not sent: XSLT file not set', 'cart');
         return;
     }
     if ($html = xslt::process($this->getXML(), $xslt)) {
         $subject = t('Заказ на %host', array('%host' => MCMS_HOST_NAME));
         BebopMimeMail::send(null, $to, $subject, $html);
     }
 }
 /**
  * Вывод административной страницы. Вызывает обработчик, указанный в next,
  * предварительно проверив права пользователя.
  */
 public static function serve(Context $ctx, $path, array $pathinfo)
 {
     if (class_exists('APIStream')) {
         APIStream::init($ctx);
     }
     try {
         self::checkperm($ctx, $pathinfo);
         if (!$ctx->user->id and empty($pathinfo['anonymous'])) {
             throw new UnauthorizedException();
         }
         if (empty($pathinfo['next'])) {
             if (!empty($pathinfo['xsl'])) {
                 $pathinfo['next'] = 'AdminPage::xsltonly';
             } else {
                 throw new RuntimeException(t('Не указан обработчик для страницы %path (параметр <tt>next</tt>).', array('%path' => $path)));
             }
         }
         if (!is_callable($pathinfo['next'])) {
             throw new RuntimeException(t('Неверный обработчик для страницы %path (<tt>%next()</tt>).', array('%path' => $path, '%next' => $pathinfo['next'])));
         }
         $args = func_get_args();
         $output = call_user_func_array($pathinfo['next'], $args);
         if (!$output instanceof Response) {
             $xsl = empty($pathinfo['xsl']) ? null : implode(DIRECTORY_SEPARATOR, explode('/', $pathinfo['xsl']));
             $tmp = new AdminPage($output, $xsl);
             $output = $tmp->getResponse($ctx);
         }
         return $output;
     } catch (NotConnectedException $e) {
         Logger::trace($e);
         if (is_dir(os::path('lib', 'modules', 'install'))) {
             $ctx->redirect('install?destination=' . urlencode(MCMS_REQUEST_URI));
         } else {
             throw new RuntimeException('Система не проинсталлирована и модуля install нет.');
         }
     } catch (Exception $e) {
         Logger::trace($e);
         $data = array('status' => 500, 'error' => get_class($e), 'message' => $e->getMessage(), 'version' => MCMS_VERSION, 'release' => MCMS_RELEASE, 'base' => $ctx->url()->getBase($ctx), 'prefix' => MCMS_SITE_FOLDER . '/themes', 'back' => urlencode(MCMS_REQUEST_URI), 'next' => urlencode($ctx->get('destination')), 'clean' => !empty($_GET['__cleanurls']));
         if ($e instanceof UserErrorException) {
             $data['status'] = $e->getCode();
         }
         $xsl = os::path('lib', 'modules', 'admin', 'template.xsl');
         xslt::transform(html::em('page', $data), $xsl)->send();
     }
 }
 /**
  * Восстановление пароля.
  * 
  * @param Context $ctx 
  * @param array $params 
  * @return void
  * @mcms_message ru.molinos.cms.auth.process.basicpw
  */
 public static function on_register(Context $ctx, array $params)
 {
     if (false === strpos($params['email'], '@')) {
         throw new BadRequestException(t('Неверно введён почтовый адрес.'));
     }
     $node = Node::load(array('class' => 'user', 'name' => $params['email']));
     if ($node->deleted) {
         throw new ForbiddenException(t('Этот пользователь был удалён.'));
     } elseif (!$node->published) {
         throw new ForbiddenException(t('Этот пользователь заблокирован.'));
     }
     $salt = md5($_SERVER['REMOTE_ADDR'] . microtime(true) . $node->name . rand());
     $node->otp = $salt;
     $ctx->db->beginTransaction();
     $node->save();
     $ctx->db->commit();
     $xml = html::em('request', array('email' => $node->name, 'host' => MCMS_HOST_NAME, 'base' => $ctx->url()->getBase($ctx), 'link' => 'authbasic/restore.rpc?email=' . urlencode($node->name) . '&otp=' . urlencode($salt)));
     $xsl = $ctx->config->get('modules/authbasic/restoretpl', os::path('lib', 'modules', 'authbasic', 'restore.xsl'));
     $html = xslt::transform($xml, $xsl, null);
     BebopMimeMail::send(null, $node->name, t('Восстановление пароля'), $html);
 }
 private static function render(Context $ctx, array $data, $content = null)
 {
     $data['base'] = $ctx->url()->getBase($ctx);
     $data['prefix'] = 'lib/modules/admin';
     $data['urlEncoded'] = urlencode(MCMS_REQUEST_URI);
     $data['back'] = urlencode($ctx->get('destination', MCMS_REQUEST_URI));
     $data['url'] = $ctx->url()->string();
     $data['cgroup'] = $ctx->get('cgroup');
     $data['folder'] = $ctx->folder();
     $data['picker'] = $ctx->get('picker');
     if (empty($data['status'])) {
         $data['status'] = 200;
     }
     if (isset($ctx->theme)) {
         $theme = $ctx->theme;
     } else {
         $theme = os::path('lib', 'modules', 'admin', 'template.xsl');
     }
     if (file_exists($tmp = str_replace('.xsl', '.css', $theme))) {
         $ctx->addExtra('style', $tmp);
     }
     if (file_exists($tmp = str_replace('.xsl', '.js', $theme))) {
         $ctx->addExtra('script', $tmp);
     }
     if ('' !== ($tmp = $ctx->getExtrasXML())) {
         $content .= $tmp;
     }
     $xml = '<?xml version="1.0" encoding="utf-8"?>';
     $xml .= html::em('page', $data, $content);
     $output = xslt::transform($xml, $theme);
     return $output;
 }
Exemple #11
0
function wwwvar($name)
{
    return xslt::top()->variable($name);
}