/** * Поиск (обработка). */ 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()); }
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 pager($total, $current, $limit, $paramname = 'page', $default = 1) { $result = array(); $list = ''; if (empty($limit)) { return null; } $result['documents'] = $total; $result['pages'] = $pages = ceil($total / $limit); $result['perpage'] = intval($limit); $result['current'] = $current; if ('last' == $current) { $result['current'] = $current = $pages; } if ('last' == $default) { $default = $pages; } if ($pages > 0) { // Немного валидации. if ($current > $pages or $current <= 0) { throw new UserErrorException("Страница не найдена", 404, "Страница не найдена", "Вы обратились к странице {$current} списка, содержащего {$pages} страниц. Это недопустимо."); } // С какой страницы начинаем список? $beg = max(1, $current - 5); // На какой заканчиваем? $end = min($pages, $current + 5); // Расщеплённый текущий урл. $url = new url(); $plinks = array(); for ($i = $beg; $i <= $end; $i++) { $url->setarg($paramname, $i == $default ? '' : $i); $plinks[$i] = $i == $current ? '' : $url->string(); $list .= html::em('page', array('number' => $i, 'link' => $plinks[$i])); } if (!empty($plinks[$current - 1])) { $result['prev'] = $plinks[$current - 1]; } if (!empty($plinks[$current + 1])) { $result['next'] = $plinks[$current + 1]; } } return html::em('pager', $result, $list); }
/** * Подставляет в адрес редиректа информацию о модифицированном объекте. */ public static function fixredir($path, Node $node, $updated = false) { if ($updated) { $mode = 'updated'; } elseif ($node->published) { $mode = 'created'; } else { $mode = 'pending'; } $url = new url($path); $url->setarg('created', null); $url->setarg('updated', null); $url->setarg('pending', null); if ('%ID' == $url->arg('id')) { $url->setarg('id', $node->id); } else { $url->setarg($mode, $node->id); $url->setarg('type', $node->class); } return $url->string(); }
/** * Возвращает форму для создания документа. */ public static function on_get_create_form(Context $ctx) { if (!($type = $ctx->get('type'))) { throw new BadRequestException(t('Не указан тип документа (GET-параметр type).')); } $node = Node::create(array('class' => $type, 'parent_id' => $ctx->get('parent')))->knock(ACL::CREATE); $form = $node->formGet(); // destination берётся из $_SERVER, и при работе через XML API содержит не то, // что может быть нужно, поэтому корректируем руками. $action = new url($form->action); $action->setarg('destination', $ctx->get('destination')); $form->action = $action->string(); $form->addClass('create'); $form->addClass('create-' . $type); return new Response($form->getXML(Control::data()), 'text/xml'); }
private static function getToolBar() { $xslmode = empty($_GET['xslt']) ? '' : $_GET['xslt']; $toolbar = html::em('a', array('class' => 'editprofile', 'href' => '?q=admin&cgroup=access&mode=edit&id=' . Context::last()->user->id . '&destination=CURRENT', 'title' => t('Редактирование профиля')), Context::last()->user->getName()); $toolbar .= html::em('a', array('class' => 'home', 'href' => '?q=admin', 'title' => t('Вернуться к началу'))); $toolbar .= html::em('a', array('class' => 'reload', 'href' => '?q=admin.rpc&action=reload&destination=CURRENT', 'title' => t('Перезагрузка'))); $toolbar .= html::em('a', array('class' => 'exit', 'href' => '?q=auth.rpc&action=logout&from=' . urlencode(MCMS_REQUEST_URI))); if ($xslmode != 'none') { $url = new url(); $url->setarg('xslt', 'none'); $toolbar .= html::em('a', array('class' => 'xml', 'href' => MCMS_REQUEST_URI . '&xslt=none'), 'XML'); } if ($xslmode != 'client') { $url = new url(); $url->setarg('xslt', 'client'); $toolbar .= html::em('a', array('class' => 'xml', 'href' => MCMS_REQUEST_URI . '&xslt=client'), 'Client'); } if ($xslmode != '') { $url = new url(); $url->setarg('xslt', null); $toolbar .= html::em('a', array('class' => 'xml', 'href' => $url->string()), 'Server'); } return html::em('content', array('name' => 'toolbar'), $toolbar); }
private function getPlayer($_url, array $options = array()) { foreach ($options as $k => $v) { if (null === $v) { unset($options[$k]); } } $options = array_merge(array('width' => 400, 'height' => 300), $options); $ctx = Context::last(); $base = $ctx->url()->getBase($ctx); $_file = $base . $_url; $url = new url(array('path' => $base . 'lib/modules/files/player.swf')); $url->setarg('file', os::webpath($_file)); $url->setarg('width', $options['width']); $url->setarg('height', $options['height']); $params = html::em('param', array('name' => 'movie', 'value' => $url->string())); $params .= html::em('param', array('name' => 'wmode', 'value' => 'transparent')); $obj = array('type' => 'application/x-shockwave-flash', 'data' => $url->string(), 'width' => $options['width'], 'height' => $options['height']); return html::em('object', $obj, $params); }
private function getYearList(array $options, array $query) { $result = array(); $url = new url(array()); $taglist = $this->getTagList($query); $sql = "SELECT YEAR(`created`) AS `year`, COUNT(*) AS `count` " . "FROM `node` WHERE `id` IN " . "(SELECT `nid` FROM `node__rel` WHERE `tid` IN ({$taglist})) " . "AND `published` = 1 " . "AND `created` IS NOT NULL " . "AND `deleted` = 0 " . $this->getQueryFilter($query); $sql .= "GROUP BY `year` ORDER BY `year`"; if ($this->reverse_years) { $sql .= ' DESC'; } // FIXME: publishing foreach ($this->ctx->db->getResultsKV("year", "count", $sql) as $k => $v) { if (!empty($k)) { $url->setarg($this->host . '.year', $k); $url->setarg($this->host . '.page', null); $result[$k] = $url->string(); } } return $result; }
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()); }
/** * Перенаправление в контексте 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(); }