private static function isLocked(Context $ctx, $enable_admin = true)
 {
     $conf = $ctx->config->get('modules/maintenance');
     if (!empty($conf['state']) and 'closed' === $conf['state']) {
         if (!$enable_admin) {
             return true;
         }
         if (!$ctx->canDebug()) {
             $query = $ctx->query();
             if ('admin' != $query and 0 !== strpos($query, 'admin/')) {
                 return true;
             }
         }
     }
     return false;
 }
 /**
  * Вывод содержимого объекта.
  */
 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();
 }
Example #3
0
 public static function checkperm(Context $ctx, array $pathinfo)
 {
     if (!empty($pathinfo['anonymous'])) {
         return;
     }
     if (!$ctx->user->id) {
         throw new UnauthorizedException();
     }
     if ($gid = $ctx->config->get('modules/admin/requiregroup')) {
         if (!$ctx->user->hasGroups(array($gid))) {
             throw new ForbiddenException();
         }
     }
     if (!empty($pathinfo['perms'])) {
         if ('debug' == $pathinfo['perms']) {
             $result = $ctx->canDebug();
         } else {
             list($mode, $type) = explode(',', $pathinfo['perms']);
             $result = $ctx->user->hasAccess($mode, $type);
         }
         if (!$result) {
             throw new ForbiddenException();
         }
     }
 }
Example #4
0
 /**
  * Шаблонизация виджета.
  *
  * @return string результат работы шаблона или NULL.
  */
 public final function render(Context $ctx, array $params)
 {
     try {
         $this->ctx = $ctx;
         $time = microtime(true);
         if (!is_array($options = $this->getRequestOptions($this->ctx, $params))) {
             return "<!-- widget {$this->name} halted. -->";
         }
         if (array_key_exists('#cache', $options) and empty($options['#cache'])) {
             $ckey = null;
         } elseif ($ctx->get('nocache') and $ctx->canDebug()) {
             $ckey = null;
         } else {
             $ckey = 'widget:' . $this->name . ':' . md5(serialize($options));
         }
         if (null !== $ckey and is_array($cached = cache::get($ckey))) {
             return $cached['content'];
         }
         try {
             $data = $this->onGet($options);
             if (null === $data) {
                 $result = "<!-- widget {$this->name} had nothing to say. -->";
             } elseif (!is_string($data)) {
                 throw new RuntimeException(t('Виджет %name (%class) вернул мусор вместо XML.', array('%name' => $this->name, '%class' => get_class($this))));
             } else {
                 // TODO: добавить заголовок виджета
                 $result = html::em('widget', array('name' => $this->name, 'class' => get_class($this), 'title' => $this->title, 'time' => microtime(true) - $time), $data);
             }
         } catch (WidgetHaltedException $e) {
             $result = '<!-- ' . $e->getMessage() . ' -->';
         }
         if (null !== $ckey) {
             cache::set($ckey, array('content' => $result));
         }
     } catch (WidgetHaltedException $e) {
         return false;
     }
     return $result;
 }
Example #5
0
 private function checkPerm(Context $ctx, array $item)
 {
     if (!array_key_exists('perms', $item)) {
         return true;
     }
     if (!array_key_exists($item['perms'], self::$permcache)) {
         if ('debug' == $item['perms']) {
             $result = $ctx->canDebug();
         } else {
             list($mode, $type) = explode(',', $item['perms']);
             $result = $ctx->user->hasAccess($mode, $type);
         }
         self::$permcache[$item['perms']] = $result;
     }
     return self::$permcache[$item['perms']];
 }