/**
  * Вывод поисковой формы.
  */
 public static function on_get_search_form(Context $ctx)
 {
     $output = '';
     $url = new url($ctx->get('destination', $ctx->get('from')));
     if (null === $url->arg('preset')) {
         $types = Node::find(array('class' => 'type', 'published' => 1, 'deleted' => 0, 'name' => $ctx->user->getAccess(ACL::READ)), $ctx->db);
         $list = array();
         foreach ($types as $type) {
             if (!$type->isdictionary) {
                 $list[$type->name] = $type->title;
             }
         }
         asort($list);
         if ('file' == ($type = $ctx->get('type')) and array_key_exists($type, $list)) {
             $list = array($type => $type);
         }
         $tmp = '';
         foreach ($list as $k => $v) {
             $tmp .= html::em('type', array('name' => $k, 'title' => $v));
         }
         $output .= html::em('types', $tmp);
     }
     $tmp = '';
     foreach (Node::getSortedList('user', 'fullname', 'id') as $k => $v) {
         $tmp .= html::em('user', array('id' => $k, 'name' => $v));
     }
     $output .= html::em('users', $tmp);
     if (null === $url->arg('preset')) {
         $tmp = '';
         foreach (Node::getSortedList('tag', 'id', 'name') as $k => $v) {
             $tmp .= html::em('section', array('id' => $k, 'name' => $v));
         }
         $output .= html::em('sections', $tmp);
     }
     return html::em('content', array('name' => 'search', 'query' => self::get_clean_query($url->arg('search')), 'from' => urlencode($ctx->get('from'))), $output);
 }
Example #2
0
 private function getAction()
 {
     $action = isset($this->action) ? $this->action : MCMS_REQUEST_URI;
     if ($this->edit) {
         $url = new url($action);
         if (null !== ($next = $url->arg('destination'))) {
             $next = new url($next);
             $next->setarg('pending', null);
             $next->setarg('created', null);
             $destination = $next->string();
             $next->setarg('mode', 'edit');
             $next->setarg('type', null);
             $next->setarg('id', '%ID');
             $next->setarg('destination', $destination);
             $url->setarg('destination', $next->string());
             $action = $url->string();
         }
     }
     return $action;
 }
 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 #4
0
 /**
  * Перенаправление в контексте CMS.
  *
  * Позволяет перенаправлять используя относительные урлы (относительно папки,
  * в которой установлена CMS).
  *
  * @param mixed $url текст ссылки, массив или объект url.
  * @return void
  */
 public function redirect($url, $status = 301, Node $node = null)
 {
     $url1 = new url($url);
     if (empty($_GET['__cleanurls'])) {
         if (isset($url1->path)) {
             $url1->setarg('q', $url1->path);
             $url1->path = null;
         }
     } elseif (!isset($url1->path)) {
         $url1->path = $url1->arg('q');
         $url1->setarg('q', null);
     }
     $next = $url1->getAbsolute($this);
     if (null !== $node and $node->id) {
         if (!$node->published) {
             $mode = 'pending';
         } elseif ($node->isNew()) {
             $mode = 'created';
         } else {
             $mode = 'updated';
         }
         $url = new url($next);
         $url->setarg('pending', null);
         $url->setarg('created', null);
         $url->setarg('updated', null);
         if ('%ID' == $url->arg('id')) {
             $url->setarg('id', $node->id);
         } else {
             $url->setarg($mode, $node->id);
             $url->setarg('type', $node->class);
         }
         $next = $url->string();
     }
     $r = new Redirect($next, $status);
     $r->send();
 }