Example #1
0
 private static function goNext(Context $ctx)
 {
     if ($ctx->method('post')) {
         foreach ($ctx->post('next', array()) as $k => $v) {
             if (!empty($v) and null !== $ctx->post($k)) {
                 return new Redirect($v);
             }
         }
     }
     return $ctx->getRedirect();
 }
 /**
  * Поиск (обработка).
  */
 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 #3
0
 /**
  * Открепление файлов от ноды.
  */
 public static function on_post_detach(Context $ctx)
 {
     if (is_array($ids = $ctx->post('remove'))) {
         $ctx->db->beginTransaction();
         $params = array();
         Node::load($ctx->get('id'), $ctx->db)->touch(ACL::UPDATE)->onSave('DELETE FROM `node__rel` WHERE `tid` = %ID% AND `key` IS NULL AND `nid` ' . sql::in($ids, $params), $params)->save();
         $ctx->db->commit();
     }
     return $ctx->getRedirect();
 }
Example #4
0
 public static function rpc_post_add(Context $ctx)
 {
     $ctx->user->checkAccess(ACL::CREATE, 'comment');
     $node = Node::create('comment', array('published' => $ctx->user->hasAccess(ACL::PUBLISH, 'comment')));
     $node->formProcess($ctx->post);
     if ($ctx->post('anonymous')) {
         $node->name = t('Комментарий анонимный');
         $node->uid = null;
     }
     $node->save();
 }
Example #5
0
 public static function on_post_manage(Context $ctx)
 {
     if (!($nid = $ctx->get('id'))) {
         throw new BadRequestException(t('Не указан идентификатор метки (GET-параметр id).'));
     }
     $params = array($nid);
     $sql = "DELETE FROM `node__rel` WHERE `tid` = ? AND `nid` " . sql::notin($ctx->post('apply'), $params);
     $ctx->db->beginTransaction();
     $ctx->db->exec($sql, $params);
     $ctx->db->commit();
     return $ctx->getRedirect();
 }
 /**
  * Изменяет список разделов, разрешённых для ноды.
  */
 public static function on_post_setup(Context $ctx)
 {
     if (!($node = $ctx->get('node'))) {
         throw new BadRequestException();
     }
     $ctx->db->beginTransaction();
     $ctx->db->exec("DELETE FROM `node__rel` WHERE `nid` = ? AND `tid` IN (SELECT `id` FROM `node` WHERE `class` = 'tag')", array($node));
     $params = array($node);
     $sql = "INSERT INTO `node__rel` (`tid`, `nid`) SELECT `id`, ? FROM `node` WHERE `id` " . sql::in($ctx->post('selected'), $params);
     $ctx->db->exec($sql, $params);
     $ctx->db->commit();
     return $ctx->getRedirect();
 }
Example #7
0
 public static function hookRemoteCall(Context $ctx)
 {
     switch ($ctx->get('action')) {
         case 'add':
             $ctx->user->checkAccess(ACL::CREATE, 'todo');
             $node = Node::create('todo', array('name' => $ctx->post('name'), 'uid' => $ctx->user->id, 'to' => $ctx->post('user', $ctx->user->id), 'published' => 1, 'rel' => $ctx->post('rel')));
             if (empty($node->name)) {
                 $msg = t('не указан текст задачи.');
                 bebop_on_json(array('status' => 'error', 'message' => $msg));
                 throw new InvalidArgumentException($msg);
             }
             $node->save();
             bebop_on_json(array('status' => 'created', 'id' => $node->id, 'html' => $node->render()));
             break;
         case 'toggle':
             try {
                 $node = Node::load(array('class' => 'todo', 'id' => $ctx->get('id')));
             } catch (ObjectNotFoundException $e) {
                 bebop_on_json(array('status' => 'error', 'message' => 'todo ' . $ctx->get('id') . ' not found'));
                 throw new PageNotFoundException();
             }
             if (empty($node->closed)) {
                 $node->closed = date('Y-m-d H:i:s', time() - date('Z', time()));
             } else {
                 $node->closed = null;
             }
             $node->save();
             if ($ctx->method('POST') and null !== ($comment = $ctx->post('comment'))) {
                 $tmp = Node::create('comment', array('uid' => $ctx->user->id, 'author' => $ctx->user->name, 'name' => t('Комментарий к напоминанию'), 'text' => $comment));
                 $tmp->save();
                 $tmp->linkAddParent($node->id);
             }
             $state = $node->closed ? 'closed' : 'open';
             bebop_on_json(array('status' => 'ok', 'state' => $state));
             break;
     }
 }
Example #8
0
 public static function on_vote(Context $ctx)
 {
     if (!$ctx->get('id')) {
         throw new InvalidArgumentException(t('Не указан номер опроса (GET-параметр nid).'));
     }
     $votes = $ctx->post('vote');
     $ctx->db->beginTransaction();
     if (is_array($votes)) {
         foreach ($votes as $i => $vote) {
             $ctx->db->exec("INSERT INTO `node__poll` (`nid`, `uid`, `ip`, `option`) VALUES (:nid, :uid, :ip, :option)", array(':nid' => $ctx->get('id'), ':uid' => $ctx->user->id, ':ip' => $_SERVER['REMOTE_ADDR'], ':option' => $vote));
         }
     } else {
         $ctx->db->exec("INSERT INTO `node__poll` (`nid`, `uid`, `ip`, `option`) VALUES (:nid, :uid, :ip, :option)", array(':nid' => $ctx->get('id'), ':uid' => $ctx->user->id, ':ip' => $_SERVER['REMOTE_ADDR'], ':option' => $votes));
     }
     $ctx->db->commit();
     return $ctx->getRedirect();
 }
Example #9
0
 /**
  * Обработка запросов на авторизацию. Переправляет в нужный модуль.
  * 
  * @param Context $ctx 
  * @return Redirect
  */
 public static function rpc_post_login(Context $ctx)
 {
     if (!($mode = $ctx->post('auth_type'))) {
         throw new BadRequestException(t('Не указан тип авторизации.'));
     }
     $params = array();
     foreach ($ctx->post as $k => $v) {
         if (0 === strpos($k, $mode . '_')) {
             $params[substr($k, strlen($mode) + 1)] = $v;
         }
     }
     $result = $ctx->registry->unicast($message = 'ru.molinos.cms.auth.process.' . $mode, array($ctx, $params));
     if (false === $result) {
         Logger::log($message . ' not handled.', 'auth');
     }
     if (!$result instanceof Response) {
         $result = $ctx->getRedirect();
     }
     return $result;
 }
Example #10
0
 public static function hookRemoteCall(Context $ctx, $className)
 {
     $default = 'default';
     if ($ctx->method('post')) {
         $default = $ctx->post('action', $default);
     }
     $action = $ctx->get('action', $default);
     $call = array(array($className, 'rpc_' . strtolower($ctx->method()) . '_' . $action), array($className, 'rpc_' . $action));
     foreach ($call as $args) {
         if (method_exists($args[0], $args[1])) {
             if (null === ($result = call_user_func(array($args[0], $args[1]), $ctx))) {
                 $result = $ctx->getRedirect();
             }
             return $result;
         }
     }
     if (null !== ($next = $ctx->getRedirect())) {
         return $next;
     }
     return false;
 }
Example #11
0
 /**
  * Обрабатывает форму редактирования поля.
  */
 public static function on_post_edit_field(Context $ctx)
 {
     $type = Node::load(array('class' => 'type', 'name' => $ctx->get('type'), 'deleted' => 0), $ctx->db);
     $type->backportLinkedFields();
     if (!array_key_exists($fieldName = $ctx->get('field'), $type->fields)) {
         throw new PageNotFoundException();
     }
     $field = $type->fields[$fieldName];
     // Удаление.
     if ($ctx->post('delete')) {
         $fields = $type->fields;
         unset($fields[$fieldName]);
         $type->fields = $fields;
     } else {
         $schema = self::getFieldSchema($field['type']);
         $data = $schema->getFormData($ctx);
         $data->type = $field['type'];
         $data = $data->dump();
         foreach ($data as $k => $v) {
             if (empty($v)) {
                 unset($data[$k]);
             }
         }
         $fields = $type->fields;
         $fields[$data['name']] = $data;
         unset($fields[$data['name']]['name']);
         // Переименовали поле, удаляем старое.
         if ($data['name'] != $fieldName) {
             unset($fields[$fieldName]);
         }
         $type->fields = $fields;
     }
     $ctx->db->beginTransaction();
     $type->save();
     $ctx->db->commit();
     return $ctx->getRedirect();
 }
Example #12
0
 public static function on_post_delete(Context $ctx)
 {
     if ($ctx->post('confirm')) {
         $delete = (array) $ctx->post('delete');
         $widgets = Widget::loadWidgets($ctx);
         foreach ((array) $ctx->post('delete') as $k) {
             if (array_key_exists($k, $widgets)) {
                 unset($widgets[$k]);
             } else {
                 throw new PageNotFoundException();
             }
         }
         Widget::save($widgets);
         BaseRoute::save(self::remove_dead_widgets(BaseRoute::load($ctx), array_keys($widgets)));
     }
     return $ctx->getRedirect(self::listurl);
 }
 /**
  * Возвращает обрабатываемые ноды.
  * Для запросов методом POST использует массив selected[],
  * для запросов методом GET — параметр node.
  */
 private static function getNodes(Context $ctx)
 {
     if ($ctx->method('post')) {
         $ids = $ctx->post('selected', array());
     } else {
         $ids = explode(' ', $ctx->get('node'));
     }
     if (empty($ids)) {
         throw new BadRequestException(t('Не указаны идентификаторы документов (POST-массив selected[] или GET-параметр node)'));
     }
     return Node::find(array('id' => $ids), $ctx->db);
 }
Example #14
0
 public static function rpc_post_remove(Context $ctx)
 {
     $status = array();
     $remove = (array) $ctx->post('modules');
     // Удаляем отключенные модули.
     foreach (modman::getLocalModules() as $name => $info) {
         if ('required' != @$info['priority'] and in_array($name, $remove)) {
             // Отказываемся удалять локальные модули, которые нельзя вернуть.
             if (!empty($info['url'])) {
                 if (modman::uninstall($name)) {
                     $status[$name] = 'removed';
                 }
             }
         }
     }
     /*
     $ctx->config->modules = $enabled;
     $ctx->config->write();
     */
     $next = new url($ctx->get('destination', 'admin'));
     $next->setarg('status', $status);
     self::rpc_rebuild($ctx);
     // Обновляем базу модулей, чтобы выбросить удалённые локальные.
     modman::updateDB();
     return new Redirect($next->string());
 }
Example #15
0
 /**
  * Валидирует форму, возвращает данные.
  */
 public function getFormData(Context $ctx, &$data = null)
 {
     if (null === $data) {
         $data = Control::data(array());
     }
     foreach ($this as $name => $field) {
         $value = $ctx->post($name);
         $field->set($value, $data, $ctx->post);
     }
     return $data;
 }
Example #16
0
 /**
  * Изменение прав на разделы.
  * @route POST//api/taxonomy/access.rpc
  */
 public static function on_post_access(Context $ctx)
 {
     $ctx->user->checkAccess(ACL::UPDATE, 'tag');
     if ($sections = (array) $ctx->post('sections')) {
         $publishers = $ctx->post('publishers');
         $owners = $ctx->post('owners');
         $ctx->db->beginTransaction();
         ACL::resetNode($sections);
         foreach ($sections as $nid) {
             if ($publishers == $owners) {
                 ACL::set($nid, $owners, ACL::CREATE | ACL::READ | ACL::UPDATE | ACL::DELETE | ACL::PUBLISH);
             } else {
                 ACL::set($nid, $publishers, ACL::PUBLISH);
                 ACL::set($nid, $owners, ACL::CREATE | ACL::READ | ACL::UPDATE | ACL::DELETE);
             }
         }
         $ctx->db->commit();
     }
     return $ctx->getRedirect('admin/access/taxonomy');
 }
 /**
  * Редактирование нескольких файлов (обработка).
  */
 public static function on_post_edit_form(Context $ctx)
 {
     if ($ctx->get('redir')) {
         $next = 'admin/files/edit?files=' . implode('+', $ctx->post('selected')) . '&destination=' . urlencode($ctx->get('destination'));
         $ctx->redirect($next);
     }
     $labels = preg_split('/,\\s+/', $ctx->post('labels'), -1, PREG_SPLIT_NO_EMPTY);
     $ctx->db->beginTransaction();
     foreach ($ctx->post('files', array()) as $nid => $info) {
         $node = Node::load($nid, $ctx->db);
         $node->name = $info['name'];
         $node->labels = array_merge($labels, preg_split('/,\\s+/', $info['labels'], -1, PREG_SPLIT_NO_EMPTY));
         $node->save();
     }
     if ($to = $ctx->get('sendto')) {
         $node = Node::load($to)->link(array_keys($ctx->post('files')), false)->save();
     }
     $ctx->db->commit();
     return $ctx->getRedirect('admin/content/files');
 }