/** * Default dispatcher * * @param string $action * @param string $subaction */ public function index($type = NULL) { $q = $this->input->get('q'); page_header($q ? t('Search results for «%s»', $q) : t('Search')); $tpl = new Template('Search/templates/form'); $tpl->action = l('/search/') . $type; $q && ($tpl->value = $q); $tpl->show('info'); new Menu_Tabs(array('name' => 'search', 'elements' => array('posts' => array('label' => t('Посты'), 'link' => l('/search' . ($q ? '?q=' . $q : '')), 'active' => check_route('search$')), 'blogs' => array('label' => t('Блоги'), 'link' => l('/search/blogs' . ($q ? '?q=' . $q : '')), 'active' => check_route('search/blogs')), 'users' => array('label' => t('Пользователи'), 'link' => l('/search/users' . ($q ? '?q=' . $q : '')), 'active' => check_route('search/users')), 'comments' => array('label' => t('Комментарии'), 'link' => l('/search/comments' . ($q ? '?q=' . $q : '')), 'active' => check_route('search/comments'))))); if (!$q) { return event('empty'); } switch ($type) { case 'blogs': new Blog_List(array('name' => 'search.blogs', 'like' => array(array('name', $q, 'both'), array('login', $q, 'both'), array('body', $q, 'both')))); break; case 'users': new User_List(array('name' => 'search.users', 'where' => array('login !=' => ''), 'like' => array(array('name', $q, 'both'), array('login', $q, 'both')))); break; case 'comments': new Comments_List(array('name' => 'search.comments', 'where' => array('published' => 1), 'like' => array(array('body', $q, 'both')), 'per_page' => config('User.comments.per_page', 10), 'flat' => TRUE)); break; default: new Post_List(array('name' => 'search.posts', 'where' => array('published' => 1), 'like' => array(array('name', $q, 'both'), array('body', $q, 'both')))); } }
/** * Default dispatcher * * @param string $action * @param string $subaction */ public function index($action = '') { template('Install/templates/header')->show('info'); new Menu_Tabs(array('name' => 'install', 'render' => 'content', 'elements' => array(array('label' => t('1. Начало'), 'link' => '', 'active' => check_route('install$')), array('label' => t('2. Проверка'), 'link' => '', 'active' => check_route('check$')), array('label' => t('3. Настройки'), 'link' => '', 'active' => check_route('site$')), array('label' => t('4. Завершение'), 'link' => '', 'active' => check_route('finish$'))))); switch ($action) { case 'check': $tpl = new Template('Install/templates/check'); $tpl->show(); break; case 'site': append('content', '<p class="alert alert-info">' . t('Определите базовые настройки сайта.') . '</p>'); $form = new Form('Install/forms/site'); if ($result = $form->result()) { $site = new Config(SITE . DS . 'site' . EXT); $config = new Config(SITE . DS . 'config' . EXT); $config->site->name = $result->sitename; $site->key or $site->key = md5(md5(time()) + time() + $site->site->name); $result->port or $result->port = 3306; $site->database = array('driver' => config('database.driver'), 'host' => $result->host, 'base' => $result->base, 'user' => $result->user, 'pass' => $result->pass, 'port' => $result->port, 'prefix' => $result->prefix); $db = Db::factory('temp', $site->database); if (!$db->connect()) { if ($result->create_db && $db->connect(FALSE)) { $db->query("CREATE DATABASE `{$site->database->base}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;\n CREATE USER '{$site->database->user}'@'{$site->database->host}' IDENTIFIED BY '{$site->database->pass}';\n GRANT ALL ON `{$site->database->base}`.* TO '{$site->database->user}'@'localhost';\n FLUSH PRIVILEGES;"); } $db->connect(); } if ($db->is_connected) { $site->store(TRUE); $config->store(TRUE); if ($db->import($this->dir . DS . 'cogear.sql', $site->database->prefix)) { redirect(l('/install/finish')); } } else { error(t("Не удалось установить подключение к базе данных."), '', 'content'); } } else { $form->save->label = t('Попробуйте снова'); } $form->show(); break; case 'finish': $tpl = new Template('Install/templates/finish'); $tpl->show(); break; case 'done': // $site = new Config(SITE . DS . 'site' . EXT); // $site->store(TRUE); flash_success(t('Ваш сайт успешно настроен! <p> Данные для входа – логин <b>admin</b> и пароль <b>password</b>.'), '', 'info'); $this->disable(); redirect(); break; default: case 'welcome': $tpl = new Template('Install/templates/welcome'); $tpl->show(); } }
/** * Add Control Panel to user panel */ public function hookMenu($name, $menu) { switch ($name) { case 'admin': $menu->add(array('label' => icon('home'), 'link' => l('/admin'), 'active' => check_route('admin$') or check_route('^admin/dashboard'), 'order' => 0, 'elements' => array(array('link' => l('/admin'), 'label' => icon('home') . ' ' . t('Главная')), array('link' => l('/admin/clear/session'), 'label' => icon('remove') . ' ' . t('Сбросить сессию'), 'order' => '0.1'), array('link' => l('/admin/clear/cache'), 'label' => icon('trash') . ' ' . t('Сбросить кеш'), 'access' => access('Admin'), 'order' => '0.2')))); $counter = config('admin.update.counter', 0); $menu->add(array('label' => icon('refresh') . ' ' . t('Обновления') . ($counter ? badge($counter) : ''), 'title' => t('Обновления'), 'link' => l('/admin/update'), 'order' => 1001)); $menu->add(array('link' => l('/admin/site'), 'label' => icon('inbox') . ' ' . t('Сайт'), 'order' => 1000)); break; } }
/** * Show login page menu */ public function showMenu() { new Menu_Auto(array('name' => 'user.login', 'template' => 'Bootstrap/templates/tabs', 'elements' => array('login' => array('label' => icon('lock') . ' ' . t('Войти'), 'link' => l('/login')), 'lostpassword' => array('label' => icon('wrench') . ' ' . t('Забыли пароль?'), 'link' => l('/lostpassword'), 'access' => check_route('lostpassword')), 'register' => array('label' => icon('ok') . ' ' . t('Регистрация'), 'link' => l('/register'), 'access' => config('user.register.active', FALSE))), 'render' => 'info')); }
/** * Управление элементами отдельного меню * * @param mixed $id */ public function items_action($menu_id, $id = NULL) { $this->theme->hookAdminMenu(); $this->hookAdminMenu(); if ($menu = menu($menu_id)) { append('content', '<div class="page-header"><h2>' . $menu->name . '</h2></div>'); } else { return event('empty'); } $pills = new Menu_Pills(array('name' => 'admin.menu.items', 'render' => FALSE, 'elements' => array(array('label' => icon('list') . ' ' . t('Список пунктов'), 'link' => l('/admin/theme/menu/' . $menu_id . '/items')), array('label' => icon('plus') . ' ' . t('Добавить'), 'link' => l('/admin/theme/menu/' . $menu_id . '/item/add'), 'class' => 'fl_r'), array('label' => icon('pencil') . ' ' . t('Редактировать'), 'link' => l('/admin/theme/menu/' . $menu_id . '/item/' . $this->router->getSegments(5)), 'access' => check_route('admin/theme/menu/\\d+/item/\\d+'), 'class' => 'fl_r')))); append('content', $pills->render()); if (NULL === $id) { $handler = new Menu_Db_Item(); $handler->menu_id = $menu->id; if ($items = $handler->findAll()) { $tree = new Db_Tree_DDList(array('items' => $items, 'saveUri' => l('/admin/theme/menu/ajax/saveItemsTree/'))); } else { return event('empty'); } } else { $form = new Form('Menu/forms/item'); $item = new Menu_Db_Item(); if ($id != 'add' && is_numeric($id)) { $item->id = $id; if ($item->find()) { $form->object($item); } else { return event('empty'); } } else { $form->remove('delete'); $item->menu_id = $menu_id; } $form->pid->setValues($item->getSelectValues('label')); if ($result = $form->result()) { if ($result->delete && $item->delete()) { flash_success(t('Элемент меню <b>«%s»</b> был удалён!', $item->label), '', 'growl'); redirect(l('admin/theme/menu/' . $menu_id . '/items')); } $item->object()->extend($result); if ($id !== 'add') { $item->branching(); } if ($item->save()) { flash_success($id == 'add' ? t('Элемент меню <b>«%s»</b> успешно создан!', $item->label) : t('Элемент меню <b>«%s»</b> успешно отредактирован!', $item->label), '', 'growl'); redirect(l('admin/theme/menu/' . $menu_id . '/items')); } } $form->show(); } }
/** * Вывод админ меню */ public function hookAdminMenu() { new Menu_Tabs(array('name' => 'code.admin', 'elements' => array(array('label' => icon('list') . ' ' . t('Список'), 'link' => l('/admin/code')), array('label' => icon('plus') . ' ' . t('Добавить'), 'link' => l('/admin/code/snippet'), 'class' => 'fl_r'), array('label' => icon('pencil') . ' ' . t('Редактировать'), 'link' => l('/admin/code/snippet/' . $this->router->getSegments(3)), 'access' => check_route('admin/code/snippet/\\d+'), 'class' => 'fl_r')))); }
/** * Управление виджетами * * @param mixed $action */ public function widgets_action($action = 'list', $subaction = NULL) { $this->hookAdminMenu(); new Menu_Tabs(array('name' => 'admin.theme.widgets', 'elements' => array(array('label' => icon('list') . ' ' . t('Список'), 'link' => l('/admin/theme/widgets')), array('label' => icon('plus') . ' ' . t('Добавить'), 'link' => l('/admin/theme/widgets/add') . e('uri', $this->input->get('uri')), 'class' => 'fl_r'), array('label' => icon('pencil') . ' ' . t('Редактировать'), 'link' => l('/admin/theme/widgets/' . $this->router->getSegments(3)), 'access' => check_route('widgets/(\\d+)'), 'active' => check_route('widgets/(\\d+)$'), 'class' => 'fl_r'), array('label' => icon('wrench') . ' ' . t('Настройки'), 'link' => l('/admin/theme/widgets/' . $this->router->getSegments(3) . '/options'), 'access' => check_route('widgets/(\\d+)'), 'active' => check_route('widgets/(\\d+)/options'), 'class' => 'fl_r')))); if ($action == 'ajax' && ($widgets = $this->input->post('widgets'))) { $ajax = new Ajax(); $position = 0; foreach ($widgets as $config) { if ($widget = widget($config['id'])) { $widget->region = $config['region']; $widget->position = ++$position; $widget->save(); } } $this->cache->remove('widgets'); $ajax->success = TRUE; $ajax->json(); } else { if ($action == 'list') { jqueryui(); template('Theme/templates/widgets/search')->show(); $widget = widget(); $widget->order('position'); $widgets = $widget->findAll(); // Фильтруем, если задан параметр if ($uri = $this->input->get('uri')) { $remove_ids = array(); foreach ($widgets as $key => $widget) { if (!check_route($widget->route, $uri)) { $remove_ids[] = $key; } } foreach ($remove_ids as $id) { $widgets->offsetUnset($id); } } template('Theme/templates/widgets/list', array('regions' => $this->regions, 'widgets' => $widgets))->show(); } else { $form = new Form('Theme/forms/widget'); $form->callback->setValues($this->getWidgets()); $form->region->setValues(array_combine($this->regions, $this->regions)); if (is_numeric($action) && ($widget = widget($action))) { if ($subaction === 'options') { template('Theme/templates/widgets/options.header', array('widget' => $widget))->show(); $class = $widget->callback; $current_widget = new $class($widget->object()->options); $current_widget->object($widget); if ($current_widget->settings()) { $this->cache->remove('widgets'); flash_success(t('Настройки виджета <b>%s</b> сохранены!', $widget->name), '', 'growl'); redirect(l(TRUE)); } return; } $form->object($widget); $form->callback->options->disabled = TRUE; } elseif ($action == 'add') { if ($uri = $this->input->get('uri')) { $form->route->setValue($uri); } if ($region = $this->input->get('region')) { $form->region->setValue($region); } $form->remove('delete'); $widget = widget(); } else { return event('empty'); } if ($result = $form->result()) { $this->cache->remove('widgets'); if ($result->delete && $widget->delete()) { flash_success(t('Виджет «<b>%s</b>»успешно удалён!', $widget->name), '', 'growl'); redirect(l('/admin/theme/widgets')); } if ($action == 'add') { $result->position = 1 + widget()->where('region', $result->region)->countAll(); } $widget->object()->extend($result); if ($widget->save()) { if ($action == 'add') { flash_success(t('Виджет «<b>%s</b>» успешно добавлен!', $widget->name), '', 'growl'); redirect(l('/admin/theme/widgets/' . $widget->id . '/options')); } else { flash_success(t('Виджет «<b>%s</b>» успешно отредактирован!', $widget->name)); redirect(l(TRUE)); } } } $form->show(); } } }
/** * Создаёт меню панели управления страницами * * На всякий случай метод сделан в виде хука */ public function hookPagesAdminMenu() { new Menu_Tabs(array('name' => 'pages.admin', 'render' => 'info', 'elements' => array(array('label' => icon('list') . ' ' . t('Список'), 'link' => l('/admin/pages'), 'active' => check_route('admin/pages', Router::ENDS)), array('label' => icon('asterisk') . ' ' . t('Настройки'), 'link' => l('/admin/pages/settings'), 'active' => check_route('admin/pages/settings')), array('label' => icon('pencil') . ' ' . t('Создать'), 'link' => l('/admin/pages/create'), 'access' => check_route('admin/pages(/create)?'), 'class' => 'fl_r'), array('label' => icon('pencil') . ' ' . t('Редактирование'), 'link' => l('/admin/pages/' . $this->router->getSegments(3)), 'active' => check_route('admin/pages/(\\d+)'), 'access' => check_route('admin/pages/(\\d+)'), 'class' => 'fl_r')))); }