Example #1
0
 /**
  * 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();
     }
 }
Example #2
0
 /**
  * Настройки
  */
 public function admin_action()
 {
     $form = new Form(array('#name' => 'admin.parser', 'title' => array('label' => t('Настройки')), 'nl2br' => array('type' => 'checkbox', 'label' => t('Автоматическая обработка строк'), 'value' => config('Parser.nl2br')), 'save' => array()));
     if ($result = $form->result()) {
         $this->set('Parser.nl2br', $result->nl2br);
         flash_success(t('Настройки сохранены!'));
         reload();
     }
     $form->show();
 }
Example #3
0
 /**
  * Панель управления
  */
 public function admin_action()
 {
     $this->theme->hookAdminMenu();
     $form = new Form(array('#name' => 'admin.bootstrap', 'title' => array('label' => icon('wrench') . ' ' . t('Настройки')), 'theme' => array('type' => 'select', 'label' => t('Выберите тему'), 'values' => array('default' => t('Стандартная'), 'amelia' => 'Amelia', 'cerulean' => 'Cerulean', 'cosmo' => 'Cosmo', 'cyborg' => 'Cyborg', 'journal' => 'Journal', 'readable' => 'Readable', 'simplex' => 'Simplex', 'slate' => 'Slate', 'spacelab' => 'Spacelab', 'spruce' => 'Spruce', 'superhero' => 'Superhero', 'united' => 'United'), 'value' => config('bootstrap.theme', 'default')), 'save' => array()));
     if ($result = $form->result()) {
         $this->set('bootstrap.theme', $result->theme);
         flash_success(t('Настройки сохранены успешно!'));
         reload();
     }
     $form->show();
 }
Example #4
0
 /**
  * Настройки
  */
 public function settings()
 {
     $form = new Form(array('#name' => 'widget.html', 'content' => array('type' => 'editor', 'validate' => array('Required'), 'value' => $this->options->content), 'actions' => array('#class' => 'form-actions', 'save' => array())));
     if ($result = $form->result()) {
         $this->options->title = $result->title;
         $this->options->content = $result->content;
         if ($this->save()) {
             return TRUE;
         }
     }
     $form->show();
 }
Example #5
0
 /**
  * Панель управления
  */
 public function admin_action()
 {
     $form = new Form("Wysiwyg/forms/config");
     $options = new Core_ArrayObject();
     $options->type = config('wysiwyg.editor');
     $form->type->setValues(self::$editors);
     $form->object($options);
     if ($result = $form->result()) {
         if (isset(self::$editors[$result['type']])) {
             cogear()->set('wysiwyg.editor', $result['type']);
             success(t('Конфигурация успешно сохранена.'));
         }
     }
     append('content', $form->render());
 }
Example #6
0
 /**
  * Control Panel
  */
 public function admin()
 {
     $form = new Form("Wysiwyg.config");
     $options = new Core_ArrayObject();
     $options->editor = config('wysiwyg.editor');
     $form->init();
     $form->elements->type->setValues(self::$editors);
     $form->object($options);
     if ($result = $form->result()) {
         if (isset(self::$editors[$result['type']])) {
             cogear()->set('wysiwyg.editor', $result['type']);
             success('Configuration saved successfully.');
         }
     }
     append('content', $form->render());
 }
Example #7
0
 /**
  * Настройки
  */
 public function settings()
 {
     $handler = menu();
     $menus = array();
     if ($result = $handler->findAll()) {
         foreach ($result as $menu) {
             $menus[$menu->id] = $menu->name;
         }
     }
     $form = new Form(array('#name' => 'widget.menu', 'id' => array('type' => 'select', 'validate' => array('Required'), 'label' => t('Выберите меню'), 'value' => $this->options->id, 'values' => $menus), 'actions' => array('#class' => 'form-actions', 'save' => array())));
     if ($result = $form->result()) {
         $this->options->id = $result->id;
         if ($this->save()) {
             return TRUE;
         }
     }
     $form->show();
 }
Example #8
0
 /**
  * Theme admin page
  * 
  * @param type $action
  * @param type $subaction 
  */
 public function admin($action = NULL, $subaction = NULL)
 {
     $form = new Form('Admin.theme');
     if ($form->is_ajaxed) {
         if ($form->elements->logo->is_ajaxed) {
             $cogear->set('theme.logo', '');
         }
         if ($form->elements->favicon->is_ajaxed) {
             $cogear->set('theme.favicon', '');
         }
     } else {
         $form->setValues(array('logo' => config('theme.logo'), 'favicon' => config('theme.favicon')));
     }
     if ($result = $form->result()) {
         $result->logo && $cogear->set('theme.logo', $result->logo);
         $result->favicon && $cogear->set('theme.favicon', $result->favicon);
     }
     append('content', $form->render());
 }
Example #9
0
 /**
  * Show comment post form
  * 
  * @param object $Page 
  */
 public function showForm($Page)
 {
     if (access('comments post')) {
         $form = new Form('Comments.add');
         if ($result = $form->result()) {
             $comment = new Comments_Object();
             $comment->pid = $Page->id;
             $comment->aid = $this->user->id;
             $comment->created_date = time();
             $comment->body = $result->body;
             $comment->ip = $this->session->ip;
             if ($comment->save()) {
                 $Page->comments = $this->db->where('pid', $Page->id)->count('comments');
                 $Page->save();
                 flash_success(t('Your comment has been successfully posted!'));
                 redirect($Page->getUrl());
             }
         }
         $form->show();
     }
 }
Example #10
0
    /**
     * Настройки
     */
    public function settings()
    {
        $form = new Form(array('#name' => 'widget.pages.list', 'root' => array('type' => 'select', 'validate' => array('Required'), 'value' => $this->options->root, 'values' => page()->getSelectValues(), 'label' => t('Выберите корневую страницу')), 'current' => array('type' => 'checkbox', 'label' => t('Использовать текущую страницу как корневую'), 'value' => $this->options->current), 'template' => array('type' => 'text', 'value' => $this->options->template, 'label' => t('Шаблон для вывода'), 'description' => t('Будьте внимательны! Указывайте только существующий шаблон во избежание ошибок.')), 'actions' => array('#class' => 'form-actions', 'save' => array())));
        inline_js('$(document).ready(function(){
            $("input[type=checkbox]").on("change",function(){
                if($(this).attr("checked")){
                    $("#form-widget-pages-list-root").slideUp("fast");
                }
                else {
                    $("#form-widget-pages-list-root").slideDown("fast");
                }
            }).trigger("change");

        })');
        if ($result = $form->result()) {
            $this->options->root = $result->root;
            $this->options->template = $result->template;
            $this->options->current = (bool) $result->current;
            if ($this->save()) {
                return TRUE;
            }
        }
        $form->show();
    }
Example #11
0
 /**
  * Add action
  */
 public function create_action()
 {
     $post = new Post();
     //        if ($pid = $this->session->get('draft')) {
     //            $post->id = $pid;
     //            $post->find();
     //        } else {
     //            $post->aid = $this->user->id;
     //            $post->created_date = time();
     //            $post->insert();
     //            $this->session->set('draft', $post->id);
     //        }
     $form = new Form('Post/forms/post');
     if ($result = $form->result()) {
         $post->object()->extend($result);
         if ($result->preview) {
             $post->preview = TRUE;
             $post->aid = user()->id;
             $post->created_date = time();
             $post->show();
         } else {
             //                if (Ajax::is() && $this->input->get('autosave')) {
             //                    $post->update();
             //                    $ajax = new Ajax();
             //                    $ajax->message(t('Post saved!', 'Post'));
             //                    $ajax->send();
             //                }
             $post->last_update = time();
             if ($result->draft) {
                 $post->published = 0;
             } elseif ($result->publish) {
                 $post->published = 1;
             }
             if ($post->save()) {
                 $this->session->remove('draft');
                 flash_success($post->published ? t('Пост опубликован!') : t('Сохранено в черновиках!'), NULL, 'growl');
                 redirect($post->getLink());
             }
         }
     } else {
         $form->object($post);
     }
     // Remove 'delete' button from create post form
     $form->elements->offsetUnset('delete');
     $form->show();
     //        js($this->folder . '/js/inline/autosave.js','footer');
 }
Example #12
0
 public function upload_action($type)
 {
     $ajax = new Ajax();
     $ajax->success = FALSE;
     switch ($type) {
         case 'editor/image':
             $form = new Form(array('#name' => 'file.upload.editor.image', 'file' => array('type' => 'image', 'allowed_types' => array('jpg', 'png', 'gif'), 'maxsize' => '300Kb', 'path' => Image::uploadPath(), 'validate' => array('Required'), 'rewrite' => TRUE, 'preset' => 'image.large')));
             if ($result = $form->result()) {
                 if ($result->file) {
                     $ajax->code = Image::getThumbCode($result->file, 'image.medium');
                     $ajax->success = TRUE;
                 }
             }
             break;
     }
     $ajax->json();
 }
Example #13
0
 /**
  * Default dispatcher
  * 
  * @param string $action 
  */
 public function index_action($action = '', $subaction = NULL)
 {
     if (!empty($_POST['token'])) {
         // Get the profile of authorized user
         $UserProfile = $this->api->getAuthInfo($_POST['token']);
         // Check for errors
         if (!empty($UserProfile->error_type)) {
             // Debug info for developer
             error(t($UserProfile->error_type . ": " . $UserProfile->error_message));
         } elseif (empty($UserProfile)) {
             error(t('Temporary error with Loginza authentification.'));
         } else {
             $this->session->loginza = $UserProfile;
         }
     }
     if ($loginza = $this->session->loginza) {
         /**
          * There we have 3 ways of workflow
          * 
          * 1. User is logged in. Add new identity to database if it's not exist.
          * 2. User is registred. Authorize.
          * 3. User is not registred. Show register form connected and fullfilled with Loginza data (login, e-mail and so on).
          */
         $user = new Db_ORM('users_loginza');
         $user->identity = $loginza->identity;
         // If user is logged in
         if ($this->user->id) {
             // If integration is found
             if ($user->find()) {
                 // If integration belongs to the current user
                 if ($user->uid == $this->user->id) {
                     $user->loginza->data = json_encode($loginza);
                     $user->update();
                     flash_info(t('Your integration with profile <b>%s</b> was updated successfully.', 'Loginza', $loginza->identity), t('Updated succeed.'));
                 } else {
                     flash_error(t('Profile <b>%s</b> is integrated with sombody else account. You cannot use it before someone would left it out.', 'Loginza', $loginza->identity), t('Update failure.'));
                 }
             } else {
                 // Create new database record
                 $user->uid = $this->user->id;
                 $user->provider = $loginza->provider;
                 $UserProfile = new Loginza_UserProfile($loginza);
                 isset($loginza->photo) && ($user->photo = $loginza->photo);
                 $user->full_name = $UserProfile->genFullName();
                 $user->data = json_encode($loginza);
                 $user->save();
             }
             $this->session->loginza = NULL;
             // Redirect to user profile
             redirect(Url::gear('user') . 'edit/#tab-social');
         } else {
             // Record found → try to log in
             if ($user->find()) {
                 $search = new User_Object();
                 $search->id = $user->uid;
                 if ($search->find()) {
                     $this->user->forceLogin($user->uid, 'id');
                 } else {
                     flash_error(t('Cannot find user with id <b>%s</b>.', 'Loginza', $user->uid));
                 }
                 $this->session->loginza = NULL;
                 // This tiny little redirect caused error by Loginza "Invalid / empty session data! Retry auth.:
                 // Left it where it is for memories.
                 // Important! Do not uncomment!
                 //back();
             } else {
                 if (!access('user register')) {
                     return info('You don\'t have an access to registration');
                 }
                 success('First step of registration is done. Please, fill some fields to complete your registration.');
                 $form = new Form('User.register');
                 $UserProfile = new Loginza_UserProfile($loginza);
                 $tpl = new Template('Loginza.register');
                 $tpl->loginza = $loginza;
                 $tpl->profile = $UserProfile;
                 append('content', $tpl->render());
                 $data['login'] = $UserProfile->genFullName();
                 isset($loginza->email) && ($data['email'] = $loginza->email);
                 $form->setValues($data);
                 if ($data = $form->result()) {
                     $this->user->object($data);
                     $this->user->hashPassword();
                     if ($uid = $this->user->save()) {
                         // Create new database record
                         $user->uid = $uid;
                         $user->provider = $loginza->provider;
                         $UserProfile = new Loginza_UserProfile($loginza);
                         isset($loginza->photo) && ($user->photo = $loginza->photo);
                         $user->full_name = $UserProfile->genFullName();
                         $user->data = json_encode($loginza);
                         $user->save();
                     }
                     $this->session->loginza = NULL;
                     flash_success('User was successfully registered! Please, check your email for further instructions.', 'Registration succeed.');
                     redirect();
                 }
                 append('content', $form->render());
             }
         }
     }
 }
Example #14
0
 /**
  * Загрузка тем
  */
 public function upload_action()
 {
     $this->hookAdminMenu();
     $this->hookAdminMenu(2);
     $form = new Form('Gears/forms/add');
     if ($result = $form->result()) {
         if ($file = $result->file ? $result->file : $result->url) {
             $zip = new Zip(array('file' => UPLOADS . $file, 'check' => array('type' => 'gears')));
             if ($zip->extract(GEARS)) {
                 $info = $zip->info();
                 success(t('<b>Архив успешно распакован!</b> <p>Он содержал в себе следующие шестерёнки: <ul><li>%s</li></ul>', implode('</li><li>', $info['gears'])), '', 'content');
             }
             $zip->close();
             unlink(UPLOADS . $file);
         }
     }
     $form->show();
 }
Example #15
0
 /**
  * Управление виджетами
  *
  * @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();
         }
     }
 }
Example #16
0
 /**
  * Show pages
  * 
  * @param string $type 
  */
 public function index($action = '', $subaction = NULL)
 {
     new Menu_Tabs('pages', Url::gear('pages'));
     switch ($action) {
         case 'create':
             if (!page_access('pages create')) {
                 return;
             }
             $form = new Form('Pages.createdit');
             if ($result = $form->result()) {
                 $page = new Pages_Object();
                 $page->object($result);
                 $page->aid = cogear()->user->id;
                 $page->created_date = time();
                 $page->last_update = time();
                 $page->save();
                 flash_success(t('New page has been successfully added!', 'Pages'));
                 redirect($page->getUrl());
             }
             append('content', $form->render());
             break;
         case 'show':
             $this->showPage($subaction);
             break;
         case 'edit':
             $page = new Pages_Object();
             $page->where('id', intval($subaction));
             if ($page->find()) {
                 if (access('pages edit_all') or $cogear->user->id == $page->aid) {
                     $form = new Form('Pages.createdit');
                     $form->init();
                     if (access('pages delete')) {
                         $form->addElement('delete', array('label' => t('Delete'), 'type' => 'submit'));
                     }
                     $form->setValues($page->object());
                     if ($result = $form->result()) {
                         if ($result->delete) {
                             $page->delete();
                             redirect(Url::gear('pages'));
                         }
                         $page->object()->mix($result);
                         $page->last_update = time();
                         $page->update();
                         $link = $page->getUrl();
                         success(t('Page has been update. You can visit it by link <a href="%s">%s</a>', 'Pages', $link, $link));
                         //redirect($page->getUrl());
                     }
                     $form->elements->submit->setValue(t('Update'));
                     append('content', $form->render());
                 } else {
                     return _403();
                 }
             } else {
                 return _404();
             }
             break;
         default:
             $this->showPages($action);
     }
 }
Example #17
0
 /**
  * Импорт и экспорт
  */
 public function tools_action()
 {
     $this->hookSiteSettingsMenu();
     template('Admin/templates/tools')->show();
     $form = new Form('Admin/forms/import');
     if ($result = $form->result()) {
         if ($file = $result->file) {
             $zip = new Zip(array('file' => $file->path, 'check' => array('type' => 'config')));
             if ($zip->extract(ROOT)) {
                 success(t('<b>Архив успешно распакован!</b> Новый файл конфигурации установлен.'));
             }
             $zip->close();
             unlink($file->path);
         }
     }
     $form->show();
 }
Example #18
0
 /**
  *
  */
 public function index_action($action = 'import')
 {
     $this->hookAdminMenu(1);
     $this->hookAdminMenu(3);
     switch ($action) {
         case 'import':
             $form = new Form('Lang/forms/import');
             if ($result = $form->result()) {
                 if ($file = $result->file) {
                     $zip = new Zip(array('file' => $file->path, 'check' => array('type' => 'lang')));
                     if ($zip->extract(LANG)) {
                         $info = $zip->info();
                         $langs = $this->getLangs(array($info['lang']));
                         success(t('<b>Архив успешно распакован!</b> Индекс для языка <b>«%s»</b> установлен.', implode($langs)), '', 'content');
                     }
                     $zip->close();
                     unlink($file->path);
                 }
             }
             $form->show();
             break;
         case 'export':
             template('Lang/templates/download')->show();
             break;
         case 'download':
             $file = ROOT . $this->prepareFilePath();
             $archive = TEMP . DS . pathinfo($file, PATHINFO_FILENAME) . '.zip';
             $zip = new Zip(array('file' => $archive, 'create' => TRUE));
             $zip->add($file);
             $zip->info(array('type' => 'lang', 'lang' => config('lang.lang')));
             $zip->close();
             File::download($archive, basename($archive), TRUE);
             break;
     }
 }
Example #19
0
    /**
     * Dispatch request
     */
    public function index($action = '', $subaction = 'index') {
        $cogear = getInstance();
        $args = $cogear->router->getArgs();
        $rev_args = array_reverse($args);
        $class = array();
        $stop = FALSE;
        while ($piece = array_pop($rev_args)) {
            $class[] = ucfirst($piece);
            $gear = implode('_', $class);
            if ($cogear->gears->$gear) {
                $callback = array($cogear->gears->$gear, 'admin');
                if (is_callable($callback)) {
                    $cogear->router->exec($callback, $rev_args);
                    $stop = TRUE;
                    break;
                }
            }
        }
        if ($stop)
            return;
        switch ($action) {
            case 'clear':

                break;
            case 'gears':
                $this->gears($subaction);
                break;
            case 'theme':
                $form = new Form('Admin.theme');

                if ($form->is_ajaxed) {
                    if($form->elements->logo->is_ajaxed){
                        $cogear->set('theme.logo', '');
                    }
                    if($form->elements->favicon->is_ajaxed){
                        $cogear->set('theme.favicon', '');
                    }
                } else {
                    $form->setValues(array(
                        'logo' => config('theme.logo'),
                        'favicon' => config('theme.favicon'),
                    ));
                }
                if ($result = $form->result()) {
                    $result->logo && $cogear->set('theme.logo', $result->logo);
                    $result->favicon && $cogear->set('theme.favicon', $result->favicon);
                }
                append('content', $form->render());
                break;
        }
    }
Example #20
0
 /**
  * Add a new user
  */
 public function admin_add()
 {
     $form = new Form('User.register');
     if ($data = $form->result()) {
         $user = new User_Object(FALSE);
         $user->object($data);
         $user->hashPassword();
         $user->save();
         info('User was successfully registered!', 'Registration succeed.');
     } else {
         append('content', $form->render());
     }
 }
Example #21
0
 /**
  * Управление элементами отдельного меню
  *
  * @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();
     }
 }
Example #22
0
    /**
     * Добавление или редактирование сниппета
     *
     * @param int $id
     */
    public function snippet_action($id = NULL)
    {
        $this->hookAdminMenu();
        $form = new Form('Code/forms/snippet');
        $tpl = new Template('Code/templates/form');
        $snippet = new Code_Snippet();
        if ($id) {
            $snippet->id = $id;
            if ($snippet->find()) {
                $tpl->code = $snippet->code;
                $form->object($snippet);
            }
        } else {
            $tpl->code = htmlspecialchars('<?php

');
        }
        $snippet->name or $form->remove('delete');
        $form->code_editor->options->label = $tpl->render();
        if ($result = $form->result()) {
            $snippet->name = $result->name;
            $snippet->code = $result->code;
            $snippet->aid or $snippet->aid = user()->id;
            $snippet->type = $result->type;
            $snippet->created_date or $snippet->created_date = time();
            if ($snippet->save()) {
                flash_success(t('Сниппет кода успешно сохранён!'));
                redirect(l('/admin/code/snippet/' . $snippet->id));
            }
        }
        $form->show();
    }
Example #23
0
 /**
  * User Регистрация
  */
 public function register_action($code = NULL)
 {
     $this->theme->template('User/templates/login');
     if (!config('user.register.active', FALSE)) {
         return error(t('Регистрация отключена администрацией сайта.'));
     }
     if ($this->isLogged()) {
         return error('Вы уже авторизированы!');
     }
     $this->showMenu();
     if ($code) {
         $user = new User();
         $user->hash = $code;
         if ($user->find()) {
             $form = new Form('User/forms/verify');
             $form->email->setValue($user->email);
             if ($result = $form->result()) {
                 $user->object()->extend($result);
                 $result->realname && ($user->name = $result->realname);
                 $user->hashPassword();
                 $user->hash = $this->secure->genHash($user->password);
                 $user->reg_date = time();
                 $user->last_visit = time();
                 if ($user->save()) {
                     event('user.register', $user);
                     if ($user->login()) {
                         flash_success(t('Регистрация завершена!'));
                         redirect($user->getLink());
                     }
                 }
             }
             $form->show();
         } else {
             error(t('Регистрационный код не найден.'));
         }
     } else {
         $form = new Form('User/forms/register');
         if ($result = $form->result()) {
             $user = new User();
             $user->email = $result->email;
             $user->find();
             $user->hash = $this->secure->genHash(date('H d.m.Y') . $this->session->get('ip') . $result->email);
             if (config('user.register.verification', TRUE)) {
                 $verify_link = l('/user/register/' . $user->hash, TRUE);
                 $mail = new Mail(array('name' => 'register.verify', 'subject' => t('Регистрация на сайте %s', SITE_URL), 'body' => t('Вы успешно зарегистрировались на сайте http://%s. <br/>
                         Пожалуйста, перейдите по ссылке ниже, для того чтобы подтвердить данный почтовый ящик:<p>
                         <a href="%s">%s</a>', SITE_URL, $verify_link, $verify_link)));
                 $mail->to($user->email);
                 if ($mail->send()) {
                     $user->save();
                     event('user.confirmation', $user);
                     success(t('Письмо с подтвержденим регистрации было отправлено на почтовый адрес <b>%s</b>. Следуйте инструкциям.', $user->email));
                 }
             } else {
                 $user->save();
                 redirect(l('/user/register/' . $user->hash));
             }
         } else {
             $form->show();
         }
     }
 }
Example #24
0
 /**
  * Редактирование настроек
  */
 public function admin_settings_action()
 {
     $this->hookPagesAdminMenu();
     $form = new Form(array('name' => 'admin.pages.settings', 'elements' => array('main_page' => array('label' => t('Главная страница'), 'type' => 'select', 'values' => page()->getSelectValues(), 'value' => config('Pages.main_id', 1)), 'actions' => array('elements' => array('save' => array())))));
     if ($result = $form->result()) {
         if ($result->main_page) {
             $this->set('Pages.main_id', $result->main_page);
         }
     }
     $form->show();
 }