public static function rpc_post_install(Context $ctx)
 {
     $data = $ctx->post;
     if (empty($data['dbtype'])) {
         throw new RuntimeException(t('Вы не выбрали тип БД.'));
     }
     $config = $ctx->config;
     // Выносим секцию main в самое начало.
     $config['main'] = array();
     if ($config->isok()) {
         throw new ForbiddenException(t('Инсталляция невозможна: конфигурационный файл уже есть.'));
     }
     $dsn = self::getDSN($data['dbtype'], $data['db'][$data['dbtype']]);
     if (!empty($data['db']['prefix'])) {
         $dsn['prefix'] = $data['db']['prefix'];
     }
     $config->set('modules/db', $dsn);
     foreach (array('modules/mail/server', 'modules/mail/from', 'main/debug/errors') as $key) {
         if (!empty($data[$key])) {
             $config->set($key, $data[$key]);
         }
     }
     $config->set('modules/files/storage', 'files');
     $config->set('modules/files/ftp', 'ftp');
     $config->set('main/tmpdir', 'tmp');
     $config->set('main/debug/allow', array('127.0.0.1', $_SERVER['REMOTE_ADDR']));
     // Создаём маршрут для главной страницы.
     $config['routes']['localhost/'] = array('title' => 'Molinos CMS', 'theme' => 'example', 'call' => 'BaseRoute::serve');
     // Проверим соединение с БД.
     $pdo = Database::connect($config->get('modules/db'));
     // Подключились, можно сохранять конфиг.
     $config->save();
     $ctx->redirect('admin/system/reload?destination=admin/system/settings');
 }
Example #2
0
 public static function rpc_get(Context $ctx)
 {
     $host = null;
     if ($tmp = $ctx->get('host')) {
         $host = $tmp;
     } elseif ($tmp = $ctx->get('url')) {
         $url = new url($tmp);
         $host = $url->host;
     }
     if (null === $host) {
         throw new InvalidArgumentException(t('Имя сервера нужно указать в параметре host или url.'));
     }
     $next = 'http://www.google.com/s2/favicons?domain=' . urlencode($host);
     $ctx->redirect($next);
 }
Example #3
0
 /**
  * Клонирование объекта.
  * @route GET//api/node/clone.rpc
  */
 public static function on_clone(Context $ctx)
 {
     $node = Node::load($ctx->get('id'))->knock(ACL::CREATE);
     $ctx->db->beginTransaction();
     $node->published = false;
     $node->deleted = false;
     $node->created = null;
     $node->parent_id = $ctx->get('parent');
     // Копируем связи с другими объектами.
     $node->onSave("REPLACE INTO `node__rel` (`tid`, `nid`, `key`) " . "SELECT %ID%, `nid`, `key` FROM `node__rel` WHERE `tid` = ?", array($node->id));
     $node->onSave("REPLACE INTO `node__rel` (`tid`, `nid`, `key`) " . "SELECT `tid`, %ID%, `key` FROM `node__rel` WHERE `nid` = ?", array($node->id));
     $ctx->registry->broadcast('ru.molinos.cms.node.clone', array($node));
     $node->id = null;
     $node->save();
     $node->updateXML();
     $ctx->db->commit();
     $ctx->redirect("admin/node/{$node->id}?destination=" . urlencode($ctx->get('destination')));
 }
 /**
  * Поиск (обработка).
  */
 public static function on_post_search_form(Context $ctx)
 {
     $list = 'admin/content/list';
     $term = $ctx->post('search_term');
     if (null !== ($tmp = $ctx->post('search_class'))) {
         $list = Node::create($tmp)->getListURL();
     }
     $url = new url($ctx->get('from', $list));
     if (null !== ($tmp = $ctx->post('search_uid'))) {
         $url->setarg('author', $tmp);
     }
     if (null !== ($tmp = $ctx->post('search_tag'))) {
         $term .= ' tags:' . $tmp;
     }
     $url->setarg('search', trim($term));
     $url->setarg('page', null);
     $ctx->redirect($url->string());
 }
Example #5
0
 /**
  * Main module function, executed right after module loading by Orion.
  * Handles route parsing and function callbacks.
  */
 public function load()
 {
     if ($this->route == null) {
         if (!\Orion::config()->defined('ROUTING_AUTO') || \Orion::config()->get('ROUTING_AUTO') == false) {
             throw new Exception('No route object found in controller and automatic routing is disabled.', E_USER_ERROR, get_class($this));
         }
         $this->route = new Route();
         $function = $this->route->decodeAuto();
     } else {
         $function = $this->route->decode();
     }
     if (Tools::startWith($function->getName(), '__')) {
         throw new Exception('Trying to access a resticted function, you are not allowed to use methods starting with "__".', E_USER_ERROR, get_class($this));
     }
     if (Tools::startWith($function->getName(), self::FUNCTION_PREFIX)) {
         throw new Exception('Function name in rule must be declared without function prefix ' . self::FUNCTION_PREFIX . '.', E_USER_ERROR, get_class($this));
     }
     if (!is_callable(array($this, self::FUNCTION_PREFIX . $function->getName()))) {
         Context::redirect(404);
     }
     Tools::callClassMethod($this, self::FUNCTION_PREFIX . $function->getName(), $function->getArgs());
 }
 public static function on_post_sendto(Context $ctx)
 {
     if ($pick = $ctx->post('selected')) {
         if (false === strpos($ctx->post('sendto'), '.')) {
             list($nid, $fieldName) = array($ctx->post('sendto'), null);
         } else {
             list($nid, $fieldName) = explode('.', $ctx->post('sendto'));
         }
         $params = array($fieldName);
         $sql = "REPLACE INTO `node__rel` (`tid`, `nid`, `key`) SELECT %ID%, `id`, ? FROM `node` WHERE `deleted` = 0 AND `id` " . sql::in($pick, $params);
         $ctx->db->beginTransaction();
         $node = Node::load($nid)->knock(ACL::UPDATE);
         if (isset($node->{$fieldName})) {
             unset($node->{$fieldName});
         }
         $node->onSave("DELETE FROM `node__rel` WHERE `tid` = %ID% AND `key` = ?", array($fieldName))->onSave($sql, $params)->save();
         $ctx->db->commit();
         // destiantion сейчас указывает на список, а нам надо
         // вернуться на уровень выше.
         $url = new url($ctx->get('destination'));
         if ($next = $url->arg('destination')) {
             $ctx->redirect($next);
         }
     }
     return $ctx->getRedirect();
 }
Example #7
0
 /**
  * Редактирование поля (форма).
  */
 public static function on_get_edit_field_form(Context $ctx, $path, array $pathinfo, $nid, $fieldName)
 {
     $node = Node::load($nid);
     if (!array_key_exists($fieldName, $schema = $node->getFormFields())) {
         throw new PageNotFoundException();
     }
     if ($url = $schema[$fieldName]->getFieldEditURL($node)) {
         $ctx->redirect($url);
     }
     $form = $node->formGet($fieldName);
     $form->addClass('tabbed');
     $page = new AdminPage(html::em('content', array('name' => 'edit'), $form->getXML($node)));
     return $page->getResponse($ctx);
 }
 /**
  * Обработка нескольких файлов.
  */
 private static function add_files(Context $ctx, array $files)
 {
     $bad = 0;
     $good = array();
     $ctx->db->beginTransaction();
     foreach ($files as $file) {
         try {
             $good[] = Node::create('file', $ctx->db)->import($file)->save()->id;
         } catch (Exception $e) {
             $bad = 1;
         }
     }
     if (count($good)) {
         $ctx->db->commit();
     }
     $next = 'admin/files/edit' . '?destination=' . urlencode($ctx->get('destination')) . '&files=' . implode('+', $good);
     if ($bad) {
         $next .= '&bad=' . $bad;
     }
     $next .= '&sendto=' . $ctx->get('sendto');
     $ctx->redirect($next);
 }
Example #9
0
 /**
  * Inits Orion's URI context.
  * Basically retreiving and parsing : base directory, requested URI, module URI, URI parameters, and mode.
  * 
  * Throw an Exception if no compatible URI is found.
  */
 public static function init($path)
 {
     try {
         self::$URI = $_SERVER['REQUEST_URI'];
         if (\Orion::config()->defined('BASE_DIR')) {
             self::$BASE_DIR = \Orion::config()->get('BASE_DIR');
         } else {
             self::$BASE_DIR = '';
         }
         if (\Orion::config()->defined('MODULE_SEPARATOR')) {
             self::$MODULE_SEP = \Orion::config()->get('MODULE_SEPARATOR');
         } else {
             self::$MODULE_SEP = '/';
         }
         self::$PATH = $path;
         $uri = self::getRelativeURI();
         $modelist = \Orion::config()->get('MODE_LIST');
         if ($uri == '') {
             $mode = \Orion::config()->get('DEFAULT_MODE');
             if (!array_key_exists($mode, $modelist)) {
                 throw new Exception("Default mode isn't registered in MODE_LIST", E_USER_ERROR, get_class());
             }
             \Orion::setMode($mode);
             self::$MODULE_EXT = $modelist[$mode];
             self::$MODULE_NAME = \Orion::config()->get('DEFAULT_MODULE');
             self::$MODULE_URI = '';
         } else {
             foreach ($modelist as $mode => $ext) {
                 $matches = array();
                 // Module-only URI type (ex: module.html)
                 if (preg_match('#^(\\w+)' . Tools::escapeRegex($ext) . '$#', $uri, $matches)) {
                     \Orion::setMode($mode);
                     self::$MODULE_EXT = $ext;
                     self::$MODULE_NAME = $matches[1];
                     self::$MODULE_URI = null;
                     break;
                 } elseif (preg_match('#^(\\w+)' . self::$MODULE_SEP . '(.*)' . Tools::escapeRegex($ext) . '$#', $uri, $matches)) {
                     \Orion::setMode($mode);
                     self::$MODULE_EXT = $ext;
                     self::$MODULE_NAME = $matches[1];
                     self::$MODULE_URI = $matches[2];
                     break;
                 }
             }
         }
         // No compatible URI found, redirecting.
         if (self::$MODULE_NAME == null) {
             Context::redirect(404);
         }
     } catch (Exception $e) {
         throw $e;
     }
 }