/**
  * Возвращает список скриптов и стилей для использования на сайте.
  *
  * @mcms_message ru.molinos.cms.compressor.enumXXX
  */
 public static function on_compressor_enum(Context $ctx, $mode = 'website')
 {
     $result = array();
     $conf = $ctx->config->get('modules/tinymce');
     $conf['gzip'] = false;
     if (empty($conf['gzip'])) {
         $result[] = array('script', 'lib/modules/tinymce/editor/tiny_mce.js');
     } else {
         $result[] = array('script', 'lib/modules/tinymce/editor/tiny_mce_gzip.js');
     }
     $initializer = empty($conf['initializer']) ? '' : $conf['initializer'] . ', ';
     $initializer .= 'document_base_url: "http://' . MCMS_HOST_NAME . $ctx->folder() . '/", ';
     $initializer .= 'tiny_mce_path: "lib/modules/tinymce/editor"';
     $text = 'tinyMCE_initializer = {' . $initializer . '};';
     os::write($path = os::path($ctx->config->getPath('main/tmpdir'), 'tinymce_initializer.js'), $text);
     $result[] = array('script', os::localpath($path));
     $theme = empty($conf['theme']) ? 'simple' : $conf['theme'];
     if (!empty($conf['gzip'])) {
         if (file_exists($path = os::path('lib', 'modules', 'tinymce', 'editor', 'template_' . $theme . '_gzip.js'))) {
             $result[] = array('script', os::webpath($path));
         }
     }
     if (file_exists($path = os::path('lib', 'modules', 'tinymce', 'editor', 'template_' . $theme . '.js'))) {
         $result[] = array('script', os::webpath($path));
     }
     return $result;
 }
Beispiel #2
0
 /**
  * Запись файла с поддержкой секций.
  */
 public static function write($filename, array $data, $header = null)
 {
     $output = null === $header ? "" : trim($header) . "\n\n";
     // Сначала пишет простые значения
     $output .= self::write_keys($data);
     // Теперь сохраняем секции.
     foreach ($data as $k => $v) {
         if (is_array($v) and !empty($v)) {
             if (!empty($output)) {
                 $output .= "\n";
             }
             $output .= sprintf("[%s]\n", $k);
             $output .= self::write_keys($v, true);
         }
     }
     if (file_exists($filename)) {
         rename($filename, $filename . '~');
     }
     os::write($filename, $output);
 }
Beispiel #3
0
 /**
  * Сохранение сессионных данных.
  *
  * Перед сохранением из БД удаляются ранее существовавшие данные этой сессии.
  * @todo менять sid надо при _каждом_ сохранении, см. Session Fixation
  * Vulnerability.
  *
  * Если сессия не была загружена — возникает RuntimeException().
  *
  * @see http://en.wikipedia.org/wiki/Session_fixation
  *
  * @return Session $this
  */
 public function save($force = false)
 {
     static $sent = false;
     if ($force) {
         $sent = false;
     }
     // При запуске из консоли сессии никуда не сохраняем.
     if (empty($_SERVER['REMOTE_ADDR'])) {
         return;
     }
     if (null === $this->data) {
         throw new RuntimExeption(t('Session is being saved ' . 'without having been loaded.'));
     }
     if ($this->hash() != $this->_hash) {
         if (null === $this->id) {
             $this->id = $this->getsessionId();
         }
         switch ($this->getStorageType()) {
             case 'file':
                 os::mkdir(dirname($path = $this->getStoragePath($this->id)), t('Не удалось создать временный каталог для хранения сессий.'));
                 if (!empty($this->data)) {
                     os::write($path, serialize($this->data));
                 } elseif (file_exists($path)) {
                     unlink($path);
                 }
                 break;
             default:
                 $db = Context::last()->db;
                 $db->exec("DELETE FROM node__session WHERE `sid` = ?", array($this->id));
                 $ckey = 'session:' . $this->id;
                 $cache = cache::getInstance();
                 if (!empty($this->data)) {
                     $db->exec("INSERT INTO node__session (`created`, `sid`, `data`) " . "VALUES (UTC_TIMESTAMP(), ?, ?)", array($this->id, serialize($this->data)));
                     $cache->{$ckey} = serialize($this->data);
                 } else {
                     unset($cache->{$ckey});
                 }
         }
         if (!$sent) {
             $sent = true;
             // $path = '/';
             $time = time() + 60 * 60 * 24 * 30;
             $name = self::cookie;
             if (!headers_sent()) {
                 setcookie($name, empty($this->data) ? null : $this->id, $time);
                 Logger::log("cookie set: {$name}={$this->id}", 'auth');
             }
         }
     }
     return $this;
 }
 /**
  * Возвращает файлы для админки.
  */
 private static function getAdminFiles(Context $ctx, $compressed = true)
 {
     if (!$compressed) {
         list($scripts, $styles) = self::getGlobal($ctx);
         foreach (os::find('lib', 'modules', '*', 'scripts', 'admin', '*.js') as $fileName) {
             $scripts[] = $fileName;
         }
         foreach (os::find('lib', 'modules', '*', 'styles', 'admin', '*.css') as $fileName) {
             $styles[] = $fileName;
         }
     } else {
         $scripts = $styles = array();
         $prefix = $ctx->config->getPath('main/tmpdir') . DIRECTORY_SEPARATOR . 'admin.';
         if (file_exists($js = $prefix . 'js')) {
             $scripts[] = $js;
         }
         if (file_exists($css = $prefix . 'css')) {
             $styles[] = $css;
         }
         if (empty($scripts) or empty($styles)) {
             list($scripts, $styles) = self::getAdminFiles($ctx, false);
             if (empty($scripts)) {
                 touch($js);
             } else {
                 os::write($js, self::join($scripts, ';'));
             }
             $scripts = array($js);
             if (empty($styles)) {
                 touch($css);
             } else {
                 os::write($css, self::join($styles));
             }
             $styles = array($css);
         }
     }
     return array($scripts, $styles);
 }