예제 #1
0
 /**
  * Actuion direct user
  *
  * http://.../.../[backend_name]/directuser?direct_key=[database direct_key]
  * g1072551 -> 876d93b12883451950f7577762279768fd8a38b6e197137cd43666298f3be4f5
  */
 public function action_directuser()
 {
     // if logged in
     if ($this->logged_in_user) {
         throw HTTP_Exception::factory(404);
     }
     // Get direct key from query string
     $direct_key = Cms_Helper::settings('direct_key');
     // If key doesn't passed
     if ($this->request->query('direct_key') != $direct_key) {
         throw HTTP_Exception::factory(404);
     }
     if ($this->request->post()) {
         $data = array('username' => $this->request->post('username'), 'email' => $this->request->post('email'), 'password' => $this->request->post('password'), 'is_block' => 0);
         // Transaction start
         Database::instance()->begin();
         // Try
         try {
             $direct = Tbl::factory('users')->create($data);
             $direct->add_roles('login')->add_roles('direct');
             // Make user dir
             Cms_Helper::make_dir($direct->username, $this->settings->image_dir . '/user');
             // Transaction commit
             Database::instance()->commit();
             // Add success notice
             Notice::add(Notice::SUCCESS, Kohana::message('auth', 'directuser_success'));
             // Redirect
             $this->redirect(URL::site($this->settings->backend_name, 'http'));
         } catch (HTTP_Exception_302 $e) {
             $this->redirect($e->location());
         } catch (Validation_Exception $e) {
             // Transaction rollback
             Database::instance()->rollback();
             // Add validation notice
             Notice::add(Notice::VALIDATION, Kohana::message('auth', 'directuser_failed'), NULL, $e->errors('validation'));
         } catch (Exception $e) {
             // Transaction rollback
             Database::instance()->rollback();
             // Add error notice
             Notice::add(Notice::ERROR, $e->getMessage());
         }
     }
     /**
      * View
      */
     // Get content
     $content_file = Tpl::get_file('directuser', $this->settings->back_tpl_dir . '/auth');
     $this->content = Tpl::factory($content_file)->set('post', $this->request->post());
 }
예제 #2
0
 /**
  * Action setting
  */
 public function action_setting()
 {
     $settings = new stdClass();
     $settings->send_comment_is_on = $this->settings->send_comment_is_on;
     $settings->send_comment_is_user_only = $this->settings->send_comment_is_user_only;
     $settings->send_comment_is_on_default = $this->settings->send_comment_is_on_default;
     $settings->send_comment_is_accept_default = $this->settings->send_comment_is_accept_default;
     $settings->send_comment_allowable_tags = $this->settings->send_comment_allowable_tags;
     // If there are post
     if ($this->request->post()) {
         // Set post to email
         $settings->send_comment_is_on = Arr::get($this->request->post(), 'send_comment_is_on', 0);
         $settings->send_comment_is_user_only = Arr::get($this->request->post(), 'send_comment_is_user_only', 0);
         $settings->send_comment_is_on_default = Arr::get($this->request->post(), 'send_comment_is_on_default', 0);
         $settings->send_comment_is_accept_default = Arr::get($this->request->post(), 'send_comment_is_accept_default', 0);
         $settings->send_comment_allowable_tags = Arr::get($this->request->post(), 'send_comment_allowable_tags');
         // Database transaction start
         Database::instance()->begin();
         // Try
         try {
             foreach ($settings as $key => $value) {
                 Tbl::factory('settings')->where('key', '=', $key)->get()->update(array('value' => $value));
             }
             // Database commit
             Database::instance()->commit();
             // Add success notice
             Notice::add(Notice::SUCCESS, Kohana::message('general', 'update_success'));
         } catch (HTTP_Exception_302 $e) {
             $this->redirect($e->location());
         } catch (Validation_Exception $e) {
             // Database rollback
             Database::instance()->rollback();
             // Add validation notice
             Notice::add(Notice::VALIDATION, Kohana::message('general', 'update_failed'), NULL, $e->errors('validation'));
         } catch (Exception $e) {
             // Database rollback
             Database::instance()->rollback();
             // Add error notice
             Notice::add(Notice::ERROR, $e->getMessage());
         }
     }
     /**
      * View
      */
     $content_file = Tpl::get_file('setting', $this->settings->back_tpl_dir . '/comment', $this->partials);
     $this->content = Tpl::factory($content_file)->set('settings', $settings);
 }
예제 #3
0
 /**
  * get settings
  *
  * @param string $key setting key
  * @uses Tbl module
  * @return string Value
  */
 public static function settings($key = NULL)
 {
     $settings = (object) Tbl::factory('settings')->read()->as_array('key', 'value');
     return $key ? $settings->{$key} : $settings;
 }
예제 #4
0
 /**
  * Action delete
  */
 public function action_delete()
 {
     // Auto render off
     $this->auto_render = FALSE;
     // Get id from param, if there is nothing then throw to 404
     $id = $this->request->param('key');
     if (!$id) {
         throw HTTP_Exception::factory(404);
     }
     // Get tag, if there is nothing then throw to 404
     $tag = Tbl::factory('tags')->get($id);
     if (!$tag) {
         throw HTTP_Exception::factory(404);
     }
     // Database transaction start
     Database::instance()->begin();
     // Try
     try {
         /**
          * Delete
          */
         // Get items_tags ids has this tag id このfieldのidを持つitems_tagsを取得
         $items_tags_ids = Tbl::factory('items_tags')->where('tag_id', '=', $tag->id)->read()->as_array(NULL, 'id');
         // Delete items_tags
         foreach ($items_tags_ids as $items_tags_id) {
             Tbl::factory('items_tags')->where('id', '=', $items_tags_id)->get()->delete();
         }
         // Delete
         $tag->delete();
         // Database commit
         Database::instance()->commit();
         // Add success notice
         Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success'));
         $this->redirect(URL::site("{$this->settings->backend_name}/tags/index", 'http'));
     } catch (HTTP_Exception_302 $e) {
         $this->redirect($e->location());
     } catch (Validation_Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add validation notice
         Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation'));
     } catch (Warning_Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add
         Notice::add(Notice::WARNING, $e->getMessage());
     } catch (Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add error notice
         Notice::add(Notice::ERROR);
     }
     // Redirect to wrapper edit
     $this->redirect(URL::site("{$this->settings->backend_name}/tags/index", 'http'));
 }
예제 #5
0
 /**
  * Action delete
  */
 public function action_delete()
 {
     // Auto render off
     $this->auto_render = FALSE;
     // Get id from param, if there is nothing then throw to 404
     $id = $this->request->param('key');
     if (!$id) {
         throw HTTP_Exception::factory(404);
     }
     // Get tag, if there is nothing then throw to 404
     $user = Tbl::factory('users')->get($id);
     if (!$user) {
         throw HTTP_Exception::factory(404);
     }
     /**
      * Delete
      */
     // Database transaction start
     Database::instance()->begin();
     // Try
     try {
         // Delete roles_users
         $roles_users_ids = Tbl::factory('roles_users')->where('user_id', '=', $user->id)->read()->as_array(NULL, 'id');
         if ($roles_users_ids) {
             foreach ($roles_users_ids as $roles_users_id) {
                 Tbl::factory('roles_users')->get($roles_users_id)->delete();
             }
         }
         // Delate users_details
         $users_details_ids = Tbl::factory('users_details')->where('user_id', '=', $user->id)->read()->as_array(NULL, 'id');
         if ($users_details_ids) {
             foreach ($users_details_ids as $users_details_id) {
                 Tbl::factory('users_details')->get($users_details_id)->delete();
             }
         }
         // Delete
         $user->delete();
         // Delete image user dir
         Cms_Helper::delete_dir($user->username, $this->settings->image_dir . '/user', TRUE);
         // Database commit
         Database::instance()->commit();
         // Add success notice
         Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success'));
     } catch (HTTP_Exception_302 $e) {
         $this->redirect($e->location());
     } catch (Validation_Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add validation notice
         Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation'));
     } catch (Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add error notice
         Notice::add(Notice::ERROR, $e->getMessage());
     }
     // Redirect to wrapper edit
     $this->redirect(URL::site("{$this->settings->backend_name}/users", 'http'));
 }
예제 #6
0
 /**
  * After
  */
 public function after()
 {
     // Auto render
     if ($this->auto_render) {
         /**
          * build snippets -> snippetsようにつくるようにつくる!
          */
         // <editor-fold defaultstate="collapsed" desc="build snippets">
         // Get site details
         $sites = array();
         $site_details = Tbl::factory('settings')->where('key', '=', 'site_details')->read('value');
         $site_detail_strings = explode("\n", $site_details);
         if ($site_detail_strings) {
             foreach ($site_detail_strings as $site_detail_string) {
                 $array = explode(':', $site_detail_string);
                 $sites[trim($array[0])] = array('key' => trim($array[0]), 'value' => trim($array[1]));
             }
         }
         // Get items for snippets item. 下の$this->snippetsのitemに入れるように取得する
         $snippet_item = NULL;
         if ($this->request->param('key')) {
             $snippet_item_segment = Tbl::factory('items')->where('id', '=', $this->request->param('key'))->read('segment');
             if ($snippet_item_segment) {
                 $snippet_item = Cms_Functions::get_item($snippet_item_segment, TRUE, TRUE, TRUE);
             }
         }
         // Get parts for snippets part. 下の$this->snippetsのpartsに入れるように取得する
         $snippet_parts = Cms_Helper::get_dirfiles('part', $this->settings->front_tpl_dir);
         foreach ($snippet_parts as $snippet_part) {
             $snippet_part->content = Tpl::get_file($snippet_part->segment, $this->settings->front_tpl_dir . '/part');
         }
         // Set snippets
         $this->snippets = array('host' => URL::base(true), 'media_dir' => URL::site('media', 'http') . '/', 'images_dir' => URL::site('media/images_dir', 'http') . '/', 'css_dir' => URL::site('media/css_dir', 'http') . '/', 'js_dir' => URL::site('media/js_dir', 'http') . '/', 'icon_dir' => URL::site('media/icon_dir', 'http') . '/', 'lang' => $this->settings->lang, 'logged_in_user' => array('id' => isset($this->logged_in_user->id) ? $this->logged_in_user->id : NULL, 'email' => isset($this->logged_in_user->email) ? $this->logged_in_user->email : NULL, 'username' => isset($this->logged_in_user->username) ? $this->logged_in_user->username : NULL, 'logins' => isset($this->logged_in_user->logins) ? $this->logged_in_user->logins : NULL, 'details' => isset($this->logged_in_user->details) ? $this->logged_in_user->details : NULL), 'sites' => $sites, 'timestamp' => time(), 'return' => 'PHP_EOL', 'item' => isset($snippet_item) ? (object) $snippet_item : NULL, 'parts' => isset($snippet_parts) ? (object) $snippet_parts : NULL);
         // </editor-fold>
         /**
          * View
          */
         // <editor-fold defaultstate="collapsed" desc="View">
         // Set global value -> Set to contentといっしょ
         Tpl::set_global(array('host' => URL::base(true), 'site_title' => $this->settings->site_title, 'site_email_address' => $this->settings->site_email_address, 'backend_host' => URL::base(true) . $this->settings->backend_name . '/', 'logged_in_user' => $this->logged_in_user, 'logout_url' => URL::site("{$this->settings->backend_name}/logout", 'http'), 'time' => time()));
         // Set to content
         $this->content->set('menus', $this->menus)->set('notice', Notice::render())->set('local_menus', $this->local_menus)->set('frontend_link', $this->frontend_link)->set('snippets', $this->snippets);
         // Get tamplate file
         $template = Tpl::get_file('template', $this->settings->back_tpl_dir);
         $backend_ucfirst = str_replace('_', ' ', Text::ucfirst($this->settings->backend_name, '_'));
         // Factory and set
         $this->template = Tpl::factory($template)->set('title', $backend_ucfirst)->set('keywords', $backend_ucfirst)->set('description', $backend_ucfirst)->set('content', $this->content->render());
         // Render body
         $this->response->body($this->template->render());
         // </editor-fold>
     }
     /**
      * after
      */
     parent::after();
 }
예제 #7
0
 /**
  * Action delete
  */
 public function action_delete()
 {
     // Auto render off
     $this->auto_render = FALSE;
     // Get id from param, if there is nothing then throw to 404
     $id = $this->request->param('key');
     if (!$id) {
         throw HTTP_Exception::factory(404);
     }
     // Get division, if there is nothing then throw to 404
     $division = Tbl::factory('divisions')->get($id);
     if (!$division) {
         throw HTTP_Exception::factory(404);
     }
     // Database transaction start
     Database::instance()->begin();
     // Try
     try {
         /**
          * Check other tables
          */
         // used by items
         $used_items = (bool) Tbl::factory('items')->where('division_id', '=', $division->id)->read()->count();
         // used by categories
         $used_categories = (bool) Tbl::factory('categories')->where('division_id', '=', $division->id)->read()->count();
         // used by fields
         $used_fields = (bool) Tbl::factory('fields')->where('division_id', '=', $division->id)->read()->count();
         // Build tables array
         $tables = array();
         if ($used_items) {
             $tables[] = 'items';
         }
         if ($used_categories) {
             $tables[] = 'categories';
         }
         if ($used_fields) {
             $tables[] = 'fields';
         }
         // If this division is used when throw to warning
         if ($used_items or $used_categories or $used_fields) {
             throw new Warning_Exception(Kohana::message('general', 'division_is_used'), array(':tables' => implode(', ', $tables)));
         }
         /**
          * Delete
          */
         // Delete file まずファイルを消す!
         $file_delete_success = Cms_Helper::delete_file($division->segment, $this->settings->front_tpl_dir . '/division');
         if ($file_delete_success) {
             Cms_Helper::delete_dir($division->segment, $this->settings->item_dir);
             Cms_Helper::delete_dir($division->segment, $this->settings->image_dir . '/item');
         }
         // Delete
         $division->delete();
         // Database commit
         Database::instance()->commit();
         // Add success notice
         Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success'));
         $this->redirect(URL::site("{$this->settings->backend_name}/divisions/index", 'http'));
     } catch (HTTP_Exception_302 $e) {
         $this->redirect($e->location());
     } catch (Validation_Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add validation notice
         Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation'));
     } catch (Warning_Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add
         Notice::add(Notice::WARNING, $e->getMessage());
     } catch (Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add error notice
         Notice::add(Notice::ERROR, $e->getMessage());
     }
     // Redirect to wrapper edit
     $this->redirect(URL::site("{$this->settings->backend_name}/divisions/edit/{$division->id}", 'http'));
 }
예제 #8
0
 /**
  * Action index
  */
 public function action_index()
 {
     //		//---------------------------------------------------------------//
     //		if (Kohana::$profiling === TRUE)
     //		{
     //			// Start a new benchmark
     //			$benchmark = Profiler::start('check', __FUNCTION__);
     //		}
     //		//Do some stuff--------------------------------------------------//
     //		try
     //		{
     //
     //		}
     //		catch (Exception $e)
     //		{
     //			echo Debug::vars($e);
     //		}
     //
     //
     //		//Do some stuff--------------------------------------------------//
     //		if (isset($benchmark))
     //		{
     //			// Stop the benchmark
     //			Profiler::stop($benchmark);
     //		}
     //		echo View::factory('profiler/stats');
     //		//---------------------------------------------------------------//
     /**
      * Get settings
      */
     // <editor-fold defaultstate="collapsed" desc="Get settings">
     $settings = Cms_Helper::settings();
     // </editor-fold>
     /**
      * Lang
      */
     // <editor-fold defaultstate="collapsed" desc="Lang">
     I18n::lang($settings->lang);
     // </editor-fold>
     /**
      * Get item:セグメントからURLを取得 間はなんでもOK でもセグメントはユニーク
      */
     // <editor-fold defaultstate="collapsed" desc="Get segment and item">
     // Get item
     $item = Cms_Functions::get_item($this->request->param('segment'), TRUE, TRUE, FALSE);
     // Check issued
     if (Date::formatted_time($item->issued, 'U') > time()) {
         $item = FALSE;
     }
     // itemがないとき(false)は404へ飛ばす
     if (!$item) {
         throw HTTP_Exception::factory(404);
     }
     // </editor-fold>
     /**
      * If login
      */
     // <editor-fold defaultstate="collapsed" desc="If login">
     // If switch and post ログイン機能ONのときポストがあったら
     if ($settings->author_login_is_on and $this->request->post('login')) {
         $this->login_result = Cms_Item::login($this->request->post());
     }
     // </editor-fold>
     /**
      * login check:ログインのチェック
      */
     // <editor-fold defaultstate="collapsed" desc="login check">
     // ログインのチェック
     if (Auth::instance()->logged_in()) {
         // Get user from auth
         $get_user = Auth::instance()->get_user();
         // Build logged_in_user
         $this->logged_in_user = (object) array('id' => $get_user->id, 'email' => $get_user->email, 'username' => $get_user->username, 'logins' => $get_user->logins, 'last_login' => $get_user->last_login, 'ext' => $get_user->ext, 'avatar' => FALSE, 'detail' => FALSE, 'role' => FALSE);
         // Set logged in user avatar
         if (is_file('application/' . Cms_Helper::settings('image_dir') . '/user/' . $get_user->username . '/avatar' . $get_user->ext)) {
             $this->logged_in_user->avatar = (object) array('path' => URL::site("imagefly", 'http') . '/user/' . $get_user->username . '/', 'file' => '/' . 'avatar' . $get_user->ext);
         }
         // Set logged in user detail
         $this->logged_in_user->detail = Tbl::factory('users_details')->join('details')->on('users_details.detail_id', '=', 'details.id')->select('users_details.*')->select('details.name')->select('details.segment')->where('users_details.user_id', '=', $get_user->id)->read()->as_array('segment');
         // Set logged in user role
         $this->logged_in_user->role = Tbl::factory('roles_users')->select('roles.*')->join('roles')->on('roles_users.role_id', '=', 'roles.id')->where('roles_users.user_id', '=', $get_user->id)->where('roles.name', '!=', 'login')->read('name');
     }
     // </editor-fold>
     /**
      * Set global value
      */
     // <editor-fold defaultstate="collapsed" desc="Set global value">
     // Get site details
     $site = array();
     $site_detail_string = explode("\n", $settings->site_details);
     if ($site_detail_string) {
         foreach ($site_detail_string as $value) {
             $array = explode(':', $value);
             $site[trim($array[0])] = trim($array[1]);
         }
     }
     // Build logged_in_user
     if ($this->logged_in_user) {
         $logged_in_user = clone $this->logged_in_user;
         unset($logged_in_user->password, $logged_in_user->reset_key);
     } else {
         $logged_in_user = $this->logged_in_user;
     }
     Tpl::set_global(array('host' => URL::base(true), 'media_dir' => URL::site('media', 'http') . '/', 'images_dir' => URL::site('media/images', 'http') . '/', 'imagefly' => URL::site('imagefly/item', 'http') . '/', 'css_dir' => URL::site('media/css', 'http') . '/', 'js_dir' => URL::site('media/js', 'http') . '/', 'icon_dir' => URL::site('media/icon', 'http') . '/', 'lang' => $settings->lang, 'logged_in_user' => $logged_in_user, 'time' => time(), 'return' => PHP_EOL, 'site_title' => $settings->site_title, 'site_email_address' => $settings->site_email_address, 'site' => $site));
     // </editor-fold>
     /**
      * If logout
      */
     // <editor-fold defaultstate="collapsed" desc="If logout">
     // If query ここはログイン機能OFFでもログアウト
     if ($this->request->query('logout')) {
         Cms_Item::logout();
         $this->redirect();
     }
     // </editor-fold>
     /**
      * If post register
      */
     // <editor-fold defaultstate="collapsed" desc="register">
     // If switch and post レジスター機能ONのときポストがあったら
     if ($settings->author_register_is_on and $this->request->post('register')) {
         Cms_Item::register($this->request->post());
     }
     // </editor-fold>
     /**
      * If get activate
      */
     // <editor-fold defaultstate="collapsed" desc="activate">
     // If switch and post レジスター機能ONでアクティベートONのときポストがあったら
     if ($settings->author_register_is_on and $settings->author_register_activate_is_on and $this->request->query('activate_key')) {
         Cms_Item::activate($this->request->query());
     }
     // </editor-fold>
     /**
      * If post forgot
      */
     // <editor-fold defaultstate="collapsed" desc="forgot">
     // If switch and post フォーガット機能ONのときポストがあったら
     if ($settings->author_password_forgot_is_on and $this->request->post('forgot')) {
         Cms_Item::forgot($this->request->post());
     }
     // </editor-fold>
     /**
      * If post reset
      */
     // <editor-fold defaultstate="collapsed" desc="reset">
     if ($settings->author_password_forgot_is_on and ($this->request->post('reset') or $this->request->query('reset_key'))) {
         Cms_Item::reset($this->request->post(), $this->request->query());
     }
     // </editor-fold>
     /**
      * If post resign
      */
     // <editor-fold defaultstate="collapsed" desc="resign">
     // If switch and post レジスター機能ONでアクティベートONのときポストがあったら
     if ($settings->author_register_is_on and $settings->author_register_activate_is_on and $this->request->post('resign')) {
         Cms_Item::resign($this->request->post());
     }
     // </editor-fold>
     /**
      * If post account
      */
     // <editor-fold defaultstate="collapsed" desc="account">
     if ($settings->author_account_is_on and $this->request->post('account') and $this->logged_in_user) {
         Cms_Item::account($this->request->post());
     }
     // </editor-fold>
     /**
      * If post password
      */
     // <editor-fold defaultstate="collapsed" desc="password">
     if ($settings->author_password_is_on and $this->request->post('password') and $this->logged_in_user) {
         Cms_Item::password($this->request->post());
     }
     // </editor-fold>
     /**
      * If post detail
      */
     // <editor-fold defaultstate="collapsed" desc="detail">
     if ($settings->author_detail_is_on and $this->request->post('detail') and $this->logged_in_user) {
         Cms_Item::detail($this->request->post());
     }
     // </editor-fold>
     /**
      * If post send email
      */
     // <editor-fold defaultstate="collapsed" desc="If post send email">
     // If switch and post
     if ($settings->send_email_is_on and $this->request->post('send_email')) {
         Cms_Item::send_email($this->request->post());
     }
     // </editor-fold>
     /**
      * If post send comment
      */
     // <editor-fold defaultstate="collapsed" desc="If post send comment">
     // settingsのsend_comment_is_onと、itemのsend_comment_is_onが両方オンでポストsend_commentがあるとき
     $this->send_comment_result = new stdClass();
     if ($this->request->post('send_comment')) {
         if ($settings->send_comment_is_on and $item->send_comment_is_on) {
             // send comment is user only
             // ユーザーだけ送信できる場合
             if ($settings->send_comment_is_user_only) {
                 if ($this->logged_in_user) {
                     $this->send_comment_result = Cms_Item::send_comment($item->id, $this->request->post());
                 } else {
                     $this->send_comment_result->information = TRUE;
                     $this->send_comment_result->errors[] = array('field' => 'Only a user can comment. Please register as a user.');
                 }
             } else {
                 $this->send_comment_result = Cms_Item::send_comment($item->id, $this->request->post());
             }
         } else {
             $this->send_comment_result->information = TRUE;
             $this->send_comment_result->errors[] = array('field' => 'The comment is not set up.');
         }
     }
     // </editor-fold>
     /**
      * If get search
      */
     // <editor-fold defaultstate="collapsed" desc="If get search">
     if ($this->request->query('search')) {
         Cms_Item::search($this->request->query());
     }
     // </editor-fold>
     /**
      * Set ticket
      *
      * postにワンタイムチケットを使うときは{{&ticket}}をフォームの中に入れる
      */
     // <editor-fold defaultstate="collapsed" desc="Set ticket">
     $ticket = Text::random('alnum', 8);
     Session::instance()->set('ticket', $ticket);
     Tpl::set_global(array('ticket' => '<input type="hidden" name="ticket" value="' . $ticket . '" />'));
     // </editor-fold>
     /**
      * First view render
      */
     // <editor-fold defaultstate="collapsed" desc="First view render">
     $first_html = Cms_Item::build_html($item);
     $first_view = Tpl::factory($first_html, array('item' => $item))->set('login_result', Session::instance()->get('login_result'))->set('logout_result', Session::instance()->get('logout_result'))->set('register_result', Session::instance()->get('register_result'))->set('activate_result', Session::instance()->get('activate_result'))->set('forgot_result', Session::instance()->get('forgot_result'))->set('reset_result', Session::instance()->get('reset_result'))->set('resign_result', Session::instance()->get('resign_result'))->set('detail_result', Session::instance()->get('detail_result'))->set('account_result', Session::instance()->get('account_result'))->set('password_result', Session::instance()->get('password_result'))->set('send_email_result', Session::instance()->get('send_email_result'))->set('send_comment_result', Session::instance()->get('send_comment_result'))->set('search_result', Session::instance()->get('search_result'));
     // </editor-fold>
     /**
      * Second view render
      */
     // <editor-fold defaultstate="collapsed" desc="Second view render">
     $second_html = $first_view->render();
     $second_view = Tpl::factory($second_html, array('item' => $item));
     $html = $second_view->render();
     // delete result session 2階読み込むからget_onecじゃなくてここで消す。
     Session::instance()->delete('login_result');
     Session::instance()->delete('logout_result');
     Session::instance()->delete('register_result');
     Session::instance()->delete('activate_result');
     Session::instance()->delete('forgot_result');
     Session::instance()->delete('reset_result');
     Session::instance()->delete('resign_result');
     Session::instance()->delete('account_result');
     Session::instance()->delete('password_result');
     Session::instance()->delete('detail_result');
     Session::instance()->delete('send_email_result');
     Session::instance()->delete('send_comment_result');
     Session::instance()->delete('search_result');
     // </editor-fold>
     /**
      * Response
      */
     // <editor-fold defaultstate="collapsed" desc="Response">
     $this->response->headers('Content-Type', $item->wrapper->content_type);
     //Todo::1 ブラウザーキャッシュOK でもlogoutのときクリアできない!
     //// Browser cache
     //$this->response
     //	->headers('Cache-Control', 'max-age='.Date::HOUR.', public, must-revalidate')
     //	->headers('Expires', gmdate('D, d M Y H:i:s', time() + Date::HOUR).' GMT')
     //	->headers('ETag', $html);
     //// Tell browser to check the cache
     //$this->check_cache(sha1($html));
     //for jakartaekidan
     if ($item->wrapper->content_type == 'application/octet-stream') {
         $html = mb_convert_encoding($html, "SJIS", "UTF-8");
     }
     //for jakartaekidan
     $this->response->body($html);
     // </editor-fold>
 }
예제 #9
0
Kohana::init(array('base_url' => '/', 'caching' => TRUE, 'profile' => FALSE, 'index_file' => FALSE));
/**
 * Attach the file write to logging. Multiple writers are supported.
 */
Kohana::$log->attach(new Log_File(APPPATH . 'logs'));
/**
 * Attach a file reader to config. Multiple readers are supported.
 */
Kohana::$config->attach(new Config_File());
/**
 * Enable modules. Modules are referenced by a relative or absolute path.
 */
Kohana::modules(array('auth' => MODPATH . 'auth', 'cache' => MODPATH . 'cache', 'codebench' => MODPATH . 'codebench', 'database' => MODPATH . 'database', 'image' => MODPATH . 'image', 'minion' => MODPATH . 'minion', 'unittest' => MODPATH . 'unittest', 'userguide' => MODPATH . 'userguide', 'cms' => MODPATH . 'cms', 'tbl' => MODPATH . 'tbl', 'tpl' => MODPATH . 'tpl', 'pgn' => MODPATH . 'pgn', 'notice' => MODPATH . 'notice', 'email' => MODPATH . 'email', 'mysqli' => MODPATH . 'mysqli'));
/**
 * Get settings
 */
// Kohx
$settings = (object) Tbl::factory('settings')->read()->as_array('key', 'value');
// Set timezoon
date_default_timezone_set($settings->timezoon);
Cookie::$salt = $settings->cooki_salt;
Cookie::$expiration = Cms_Helper::sec($settings->cooki_expiration);
Session::$default = 'database';
/**
 * Set the routes. Each route must have a minimum of a name, a URI and a set of
 * defaults for the URI.
 */
// Kohx
Cms_Route::write();
// Default
Route::set('default', '(<controller>(/<action>(/<id>)))')->defaults(array('controller' => 'home', 'action' => 'index'));
예제 #10
0
 /**
  * Action delete
  */
 public function action_delete()
 {
     // Auto render off
     $this->auto_render = FALSE;
     // Get id from param, if there is nothing then throw to 404
     $id = $this->request->param('key');
     if (!$id) {
         throw HTTP_Exception::factory(404);
     }
     // Get wrapper, if there is nothing then throw to 404
     $wrapper = Tbl::factory('wrappers')->get($id);
     if (!$wrapper) {
         throw HTTP_Exception::factory(404);
     }
     // Database transaction start
     Database::instance()->begin();
     // Try
     try {
         /**
          * Check other tables
          */
         // used by divisions
         $used_divisions = (bool) Tbl::factory('divisions')->where('wrapper_id', '=', $wrapper->id)->read()->count();
         // If this warpper is used by division
         if ($used_divisions) {
             throw new Warning_Exception(Kohana::message('general', 'wrapper_is_used'));
         }
         /**
          * Delete
          */
         // Delete file
         $file = "wrapper/{$wrapper->segment}";
         Cms_Helper::delete_file($file, $this->settings->front_tpl_dir);
         // Delete
         $wrapper->delete();
         // Database commit
         Database::instance()->commit();
         // Add success notice
         Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success'));
         // Redirect to wrapper index
         $this->redirect(URL::site("{$this->settings->backend_name}/wrappers/index", 'http'));
     } catch (HTTP_Exception_302 $e) {
         $this->redirect($e->location());
     } catch (Validation_Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add validation notice
         Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation'));
     } catch (Warning_Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add
         Notice::add(Notice::WARNING, $e->getMessage());
     } catch (Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add error notice
         Notice::add(Notice::ERROR);
     }
     // Redirect to wrapper edit
     $this->redirect(URL::site("{$this->settings->backend_name}/wrappers/edit/{$wrapper->id}", 'http'));
 }
예제 #11
0
 /**
  * Get Comments
  *
  * @param array $params
  * 	array(
  * 		'item_segment' => 'item_segment',
  * 		'order_column' => 'order_column',
  * 		'order_direction' => 'order_direction',
  * 		'offset' => '2',
  * 		'limit' => '5',
  * 	);
  */
 public static function get_comments(array $params)
 {
     /**
      * Build results
      */
     $return = new stdClass();
     $return->total = NULL;
     $return->comments = NULL;
     // Get param
     $item_segment = Arr::get($params, 'item_segment');
     $order_column = Arr::get($params, 'order_column');
     $order_direction = Arr::get($params, 'order_direction');
     $offset = Arr::get($params, 'offset');
     $limit = Arr::get($params, 'limit');
     // parent_segmentからparent_idを取得
     $item_id = Tbl::factory('items')->where('segment', '=', $item_segment)->read('id');
     $sql = Tbl::factory('received_comments')->where('item_id', '=', $item_id)->where('is_accept', '=', 1);
     // if there is order_column
     if ($order_column) {
         $sql->order_by($order_column, $order_direction);
     }
     // if there is offset
     if ($offset) {
         $sql->offset($offset);
     }
     // if there is limit
     if ($limit) {
         $sql->limit($limit);
     }
     // Items sqlを実行
     $return->comments = $sql->read()->as_array();
     // count
     $return->total = count($return->comments);
     return $return;
 }
예제 #12
0
 /**
  * Attempt to log in a user by using an Database object and plain-text password.
  *
  * @param   string   $username  Username to log in
  * @param   string   $password  Password to check against
  * @param   boolean  $remember  Enable autologin
  * @return  boolean
  */
 public function login($username, $password, $remember = FALSE)
 {
     if (empty($password)) {
         return FALSE;
     }
     // Todo:: kohx::1
     // もしブロックが1ならreturn FALSE
     $block_check = Tbl::factory('users')->where('username', '=', $username)->read('is_block');
     if ($block_check) {
         return FALSE;
     }
     return $this->_login($username, $password, $remember);
 }
예제 #13
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
$settings = (object) Tbl::factory('settings')->or_where('key', '=', 'auth_hash_method')->or_where('key', '=', 'auth_hash_key')->or_where('key', '=', 'auth_lifetime')->or_where('key', '=', 'auth_session_key')->read()->as_array('key', 'value');
return array('driver' => 'Database', 'hash_method' => $settings->auth_hash_method, 'hash_key' => $settings->auth_hash_key, 'lifetime' => Cms_Helper::sec($settings->auth_lifetime), 'session_type' => Session::$default, 'session_key' => $settings->auth_session_key);
예제 #14
0
 /**
  * Action rule_delete
  */
 public function action_rule_delete()
 {
     // Auto render off
     $this->auto_render = FALSE;
     // Get id from param, if there is nothing then throw to 404
     $id = $this->request->param('key');
     if (!$id) {
         throw HTTP_Exception::factory(404);
     }
     // Get detail, if there is nothing then throw to 404
     $detail_rule = Tbl::factory('detail_rules')->get($id);
     if (!$detail_rule) {
         throw HTTP_Exception::factory(404);
     }
     // Database transaction start
     Database::instance()->begin();
     // Try
     try {
         // Delete detail
         $detail_rule->delete();
         // Database commit
         Database::instance()->commit();
         // Add success notice
         Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success'));
     } catch (HTTP_Exception_302 $e) {
         $this->redirect($e->location());
     } catch (Validation_Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add validation notice
         Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation'));
     } catch (Warning_Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add
         Notice::add(Notice::WARNING, $e->getMessage());
     } catch (Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add error notice
         Notice::add(Notice::ERROR);
     }
     // Redirect to wrapper edit
     $this->redirect(URL::site("{$this->settings->backend_name}/details/rule/{$detail_rule->detail_id}", 'http'));
 }
예제 #15
0
 /**
  * Action detail
  */
 public function action_detail()
 {
     // Get content from file and direct set to detail
     $detail = new stdClass();
     $detail->content = Tpl::get_file('detail', $this->settings->front_tpl_dir . '/author');
     // If there are post
     if ($this->request->post()) {
         // Set post to author
         $detail->content = $this->request->post('content');
         // Database transaction start
         Database::instance()->begin();
         // Try
         try {
             // Update file
             Cms_Helper::set_file('detail', $this->settings->front_tpl_dir . '/author', $this->request->post('content'));
             // Database commit
             Database::instance()->commit();
             // Add success notice
             Notice::add(Notice::SUCCESS, Kohana::message('general', 'update_success'));
         } catch (HTTP_Exception_302 $e) {
             $this->redirect($e->location());
         } catch (Validation_Exception $e) {
             // Database rollback
             Database::instance()->rollback();
             // Add validation notice
             Notice::add(Notice::VALIDATION, Kohana::message('general', 'update_failed'), NULL, $e->errors('validation'));
         } catch (Exception $e) {
             // Database rollback
             Database::instance()->rollback();
             // Add error notice
             Notice::add(Notice::ERROR, $e->getMessage());
         }
     }
     // usable details
     $usable_details = Tbl::factory('details')->read()->as_array('segment');
     /**
      * View
      */
     $content_file = Tpl::get_file('detail', $this->settings->back_tpl_dir . '/author', $this->partials);
     $this->content = Tpl::factory($content_file)->set('usable_details', $usable_details)->set('detail', $detail);
 }
예제 #16
0
 /**
  * Action received comment delete
  */
 public function action_received_comment_delete()
 {
     // Auto render off
     $this->auto_render = FALSE;
     // Get ids, if When it is smaller than 2 then throw to 404
     $ids = explode('_', $this->request->param('key'));
     if (!(count($ids) == 2)) {
         throw HTTP_Exception::factory(404);
     }
     // idsをitem_idとreceived_comment_idに分ける
     list($item_id, $received_comment_id) = $ids;
     // Get received_comment, if there is nothing then throw to 404
     $received_comment = Tbl::factory('received_comments')->get($received_comment_id);
     if (!$received_comment) {
         throw HTTP_Exception::factory(404);
     }
     // Get item, if there is nothing then throw to 404
     $this->item = Tbl::factory('items')->get($item_id);
     if (!$this->item) {
         throw HTTP_Exception::factory(404);
     }
     // Get division
     $division = Tbl::factory('divisions')->where('id', '=', $this->item->division_id)->read(1);
     // Database transaction start
     Database::instance()->begin();
     // Try
     try {
         // Delete
         $received_comment->delete();
         // Database commit
         Database::instance()->commit();
         // Add success notice
         Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success'));
         // redirect
         $this->redirect(URL::site("{$this->settings->backend_name}/items/{$division->segment}/received_comments/{$this->item->id}", 'http'));
     } catch (HTTP_Exception_302 $e) {
         $this->redirect($e->location());
     } catch (Validation_Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add validation notice
         Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation'));
     } catch (Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add error notice
         Notice::add(Notice::ERROR);
     }
     // Redirect to received_comments edit
     $this->redirect(URL::site("{$this->settings->backend_name}/items/{$division->segment}/received_comments/{$this->item->id}", 'http') . URL::query());
 }
예제 #17
0
<?php

defined('SYSPATH') or die('No direct script access.');
$session_name = Tbl::factory('settings')->where('key', '=', 'session_name')->read('value');
return array('database' => array('name' => $session_name, 'group' => 'default', 'table' => 'sessions', 'gc' => 500, 'columns' => array('session_id' => 'session_id', 'last_active' => 'last_active', 'contents' => 'contents')));
예제 #18
0
 /**
  * Action delete
  */
 public function action_delete()
 {
     // Auto render off
     $this->auto_render = FALSE;
     // Get id from param, if there is nothing then throw to 404
     $segment = $this->request->param('key');
     if (!$segment) {
         throw HTTP_Exception::factory(404);
     }
     // Make shape and get content from file and direct set to shape
     $shape = new stdClass();
     $shape->segment = $segment;
     $shape->content = Tpl::get_file($segment, $this->settings->front_tpl_dir . '/shape');
     // If there is nothing then throw to 404
     if ($shape->content === FALSE) {
         throw HTTP_Exception::factory(404);
     }
     // Try
     try {
         /**
          * Check other tables
          */
         // used by items
         $used_items = (bool) Tbl::factory('items')->where('shape_segment', '=', $shape->segment)->read()->count();
         // If this shape is used throw to warning
         if ($used_items) {
             throw new Warning_Exception(Kohana::message('general', 'shape_is_used'));
         }
         /**
          * Delete
          */
         // Delete file
         Cms_Helper::delete_file($shape->segment, "{$this->settings->front_tpl_dir}/shape");
         // Add success notice
         Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success'));
         $this->redirect(URL::site("{$this->settings->backend_name}/shapes/index", 'http'));
     } catch (HTTP_Exception_302 $e) {
         $this->redirect($e->location());
     } catch (Validation_Exception $e) {
         // Add validation notice
         Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation'));
     } catch (Warning_Exception $e) {
         // Add
         Notice::add(Notice::WARNING, $e->getMessage());
     } catch (Exception $e) {
         // Add error notice
         Notice::add(Notice::ERROR, $e->getMessage() . ' : ' . $e->getFile() . ' : ' . $e->getLine());
     }
     // Redirect to wrapper edit
     $this->redirect(URL::site("{$this->settings->backend_name}/shapes/edit/{$shape->segment}", 'http'));
 }
예제 #19
0
<?php

$settings = (object) Tbl::factory('settings')->or_where('key', '=', 'encrypt_key')->or_where('key', '=', 'encrypt_cipher')->or_where('key', '=', 'encrypt_mode')->read()->as_array('key', 'value');
return array('default' => array('key' => $settings->encrypt_key, 'cipher' => $settings->encrypt_cipher, 'mode' => $settings->encrypt_mode));
예제 #20
0
 /**
  * Action index
  */
 public function action_index()
 {
     /*
      * Get order
      */
     $string = Arr::get($this->request->query(), 'string', '');
     $and_or = Arr::get($this->request->query(), 'and_or', 'and');
     $divisions = Arr::get($this->request->query(), 'divisions', array());
     $categories = Arr::get($this->request->query(), 'categories', array());
     $tags = Arr::get($this->request->query(), 'tags', array());
     $order_column = Arr::get($this->request->query(), 'order_column', 'id');
     $order_direction = Arr::get($this->request->query(), 'order_direction', 'ASC');
     $get = array('string' => $string, 'and_or' => $and_or, 'divisions' => $divisions, 'categories' => $categories, 'tags' => $tags, 'order_column' => $order_column, 'order_direction' => $order_direction);
     /*
      * Get lists
      */
     $division_list = Tbl::factory('divisions')->read()->as_array();
     $category_list = Tbl::factory('categories')->read()->as_array();
     $tag_list = Tbl::factory('tags')->read()->as_array();
     /*
      * Build columns
      */
     // <editor-fold defaultstate="collapsed" desc="Build columns">
     $columns = array('id' => array('name' => 'id', 'order_column' => 'id', 'order_direction' => 'ASC'), 'title' => array('name' => 'title', 'order_column' => 'title', 'order_direction' => 'ASC'), 'segment' => array('name' => 'segment', 'order_column' => 'segment', 'order_direction' => 'ASC'), 'division' => array('name' => 'division', 'order_column' => 'division_name', 'order_direction' => 'ASC'), 'username' => array('name' => 'username', 'order_column' => 'username', 'order_direction' => 'ASC'), 'issued' => array('name' => 'issued', 'order_column' => 'issued', 'order_direction' => 'ASC'), 'created' => array('name' => 'created', 'order_column' => 'created', 'order_direction' => 'ASC'), 'order' => array('name' => 'order', 'order_column' => 'order', 'order_direction' => 'ASC'), 'activate' => array('name' => 'activate', 'order_column' => 'is_active', 'order_direction' => 'ASC'));
     foreach ($columns as &$column) {
         if (isset($column['order_column'])) {
             if ($column['order_column'] == $order_column) {
                 $column['current'] = TRUE;
                 if ($order_direction == 'ASC') {
                     $column['order_direction'] = 'DESC';
                     $column['current_asc'] = TRUE;
                 } else {
                     $column['order_direction'] = 'ASC';
                     $column['current_desc'] = TRUE;
                 }
             }
             $column['url'] = URL::base(TRUE) . Request::current()->uri() . URL::query(array('order_column' => $column['order_column'], 'order_direction' => $column['order_direction']), TRUE);
         }
     }
     // </editor-fold>
     /*
      * Search items
      */
     // <editor-fold defaultstate="collapsed" desc="Get items">
     $sql = DB::select('items.id', 'items.segment')->from('items')->select('items.*')->select('users.username')->select(array('divisions.segment', 'division_segment'))->select(array('divisions.name', 'division_name'))->join('users', 'LEFT')->on('items.user_id', '=', 'users.id')->join('divisions')->on('items.division_id', '=', 'divisions.id')->join('items_categories', 'LEFT')->on('items.id', '=', 'items_categories.item_id')->join('categories', 'LEFT')->on('items_categories.category_id', '=', 'categories.id')->join('items_tags', 'LEFT')->on('items.id', '=', 'items_tags.item_id')->join('tags', 'LEFT')->on('items_tags.tag_id', '=', 'tags.id');
     // authority is edit
     if ($this->logged_in_user->role == 'edit') {
         $sql->where('users.id', '=', $this->logged_in_user->id);
     }
     // Divisionsがある場合
     if ($divisions) {
         $sql->where_open();
         foreach ($divisions as $division) {
             $sql->or_where('divisions.segment', '=', $division);
         }
         $sql->where_close();
     }
     // Categoriesがある場合
     if ($categories) {
         $sql->where_open();
         foreach ($categories as $category) {
             $sql->or_where('categories.segment', '=', $category);
         }
         $sql->where_close();
     }
     // Tagsがある場合
     if ($tags) {
         $sql->where_open();
         foreach ($tags as $tag) {
             $sql->or_where('tags.segment', '=', $tag);
         }
         $sql->where_close();
     }
     // string タブスペースなんかを半角に置き換えてexplodeで分ける
     if ($string) {
         $strings = array_filter(explode(' ', preg_replace(array('/\\s+/', '/,/', '/、/'), array(' ', ' ', ' '), mb_convert_kana($string, "s"))));
         // AND検索のとき
         if ($and_or == 'and') {
             $sql->where_open();
             foreach ($strings as $string) {
                 $sql->and_where(DB::expr("concat(ifnull(items.segment, ''), ' ', ifnull(items.title, ''), ' ', ifnull(items.catch, ''), ' ', ifnull(items.keywords, ''), ' ', ifnull(items.description, ''), ' ', ifnull(items.summary, ''))"), 'like', "%{$string}%");
             }
             $sql->where_close();
         } else {
             $sql->where_open();
             foreach ($strings as $string) {
                 $sql->or_where(DB::expr("concat(items.segment, ' ', items.title, ' ', items.catch, ' ', items.keywords, ' ', items.description, ' ', items.summary)"), 'like', "%{$string}%");
             }
             $sql->where_close();
         }
     }
     $all_items = $sql->group_by('items.id')->order_by($order_column, $order_direction)->as_object()->execute()->as_array('segment');
     // Pagenate
     $pagenate = Pgn::factory(array('total_items' => count($all_items), 'items_per_page' => $this->settings->pagenate_items_per_page_for_items, 'follow' => $this->settings->pagenate_items_follow_for_items));
     // Paginated items
     $items = array_slice($all_items, $pagenate->offset, $pagenate->items_per_page);
     foreach ($items as $item) {
         // Get division
         $division = Tbl::factory('divisions')->where('id', '=', $item->division_id)->read(1);
         // Get main image
         $item->main_image = Tbl::factory('images')->where('id', '=', $item->image_id)->read(1);
         if ($item->main_image) {
             $item->main_image->path = URL::site("imagefly", 'http') . '/item/' . $division->segment . '/' . $item->segment . '/';
             $item->main_image->file = '/' . $item->main_image->segment . $item->main_image->ext;
         }
         // Get categories
         $item->categories = Tbl::factory('categories')->select('categories.*')->join('items_categories')->on('categories.id', '=', 'items_categories.category_id')->where('items_categories.item_id', '=', $item->id)->read()->as_array();
         // Get received comments
         $item->received_commnets_count = count(Tbl::factory('received_comments')->where('item_id', '=', $item->id)->read()->as_array(NULL, 'id'));
         // Set to item
         $item->issued = $item->issued ? Date::formatted_time($item->issued, 'Y-n-j h:i') : $item->issued;
         $item->created = $item->created ? Date::formatted_time($item->created, 'Y-n-j h:i') : $item->created;
         $item->summary = $item->summary;
         $item->edit_url = URL::site("{$this->settings->backend_name}/items/{$item->division_segment}/edit/{$item->id}", 'http');
     }
     // </editor-fold>
     /**
      * View
      */
     // <editor-fold defaultstate="collapsed" desc="View">
     $this->partials['pagenate'] = Tpl::get_file('pagenate', $this->settings->back_tpl_dir);
     $content_file = Tpl::get_file('index', $this->settings->back_tpl_dir . '/item_search', $this->partials);
     $this->content = Tpl::factory($content_file)->set('columns', $columns)->set('division_list', $division_list)->set('category_list', $category_list)->set('tag_list', $tag_list)->set('items', $items)->set('pagenate', $pagenate)->set('get', $get);
     // </editor-fold>
 }
예제 #21
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
$settings = (object) Tbl::factory('settings')->or_where('key', '=', 'temp_dir')->or_where('key', '=', 'temp_pre')->or_where('key', '=', 'tpl_func')->read()->as_array('key', 'value');
return array('temp_dir' => $settings->temp_dir, 'temp_pre' => $settings->temp_pre, 'tpl_func' => $settings->tpl_func);
예제 #22
0
 /**
  * Action delete
  */
 public function action_delete()
 {
     // Auto render off
     $this->auto_render = FALSE;
     // Get id from param, if there is nothing then throw to 404
     $id = $this->request->param('key');
     if (!$id) {
         throw HTTP_Exception::factory(404);
     }
     // Get email, if there is nothing then throw to 404
     $email = Tbl::factory('emails')->get($id);
     if (!$email) {
         throw HTTP_Exception::factory(404);
     }
     // Database transaction start
     Database::instance()->begin();
     // Try
     try {
         /**
          * Delete
          */
         // used by email
         $used_rule_ids = Tbl::factory('email_rules')->where('email_id', '=', $email->id)->read()->as_array(NULL, 'id');
         if ($used_rule_ids) {
             foreach ($used_rule_ids as $used_rule_id) {
                 Tbl::factory('email_rules')->get($used_rule_id)->delete();
             }
         }
         // Delete file
         Cms_Helper::delete_file($email->segment, "{$this->settings->front_tpl_dir}/email");
         Cms_Helper::delete_file($email->segment, "{$this->settings->front_tpl_dir}/email/confirm");
         Cms_Helper::delete_file($email->segment, "{$this->settings->front_tpl_dir}/email/receive");
         // Delete
         $email->delete();
         // Database commit
         Database::instance()->commit();
         // Add success notice
         Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success'));
         $this->redirect(URL::site("{$this->settings->backend_name}/emails/index", 'http'));
     } catch (HTTP_Exception_302 $e) {
         $this->redirect($e->location());
     } catch (Validation_Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add validation notice
         Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation'));
     } catch (Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add error notice
         Notice::add(Notice::ERROR);
     }
     // Redirect to wrapper edit
     $this->redirect(URL::site("{$this->settings->backend_name}/emails/edit/{$email->id}", 'http'));
 }
예제 #23
0
 /**
  * Add roles
  *
  * @param   string role names
  * @return  this
  */
 public function add_roles($role_names)
 {
     // If not loaded
     if (!$this->_loaded) {
         throw new Kohana_Exception('this is not loaded.');
     }
     if ($role_names) {
         // Get role id
         $role_id = Tbl::factory('roles')->where('name', '=', $role_names)->read('id');
         // Build sql
         Tbl::factory('roles_users')->create(array('user_id' => $this->id, 'role_id' => $role_id));
         // Reload
         $this->get($this->id);
     }
     return $this;
 }
예제 #24
0
 /**
  * Frontend
  */
 public function action_frontend()
 {
     $settings = array('frontend_theme' => basename($this->settings->front_tpl_dir), 'lang' => $this->settings->lang, 'home_page' => $this->settings->home_page, 'site_details' => $this->settings->site_details);
     // If there are post
     if ($this->request->post()) {
         // Set post to email
         $settings['frontend_theme'] = Arr::get($this->request->post(), 'frontend_theme');
         $settings['lang'] = Arr::get($this->request->post(), 'lang');
         $settings['home_page'] = Arr::get($this->request->post(), 'home_page');
         $settings['site_details'] = Arr::get($this->request->post(), 'site_details');
         // Database transaction start
         Database::instance()->begin();
         // Try
         try {
             $validation = Validation::factory($settings)->rule('frontend_theme', 'not_empty')->rule('frontend_theme', 'alpha_numeric')->rule('lang', 'not_empty')->rule('home_page', 'not_empty')->label('front_theme', 'Front theme')->label('lang', 'Lang')->label('home_page', 'Home page');
             // Check validation
             if (!$validation->check()) {
                 throw new Validation_Exception($validation);
             }
             // Build frontend data
             $frontend_data = array('front_tpl_dir' => 'contents/frontend/' . Arr::get($settings, 'frontend_theme'), 'lang' => Arr::get($settings, 'lang'), 'home_page' => Arr::get($settings, 'home_page'), 'site_details' => Arr::get($settings, 'site_details'));
             foreach ($frontend_data as $key => $value) {
                 Tbl::factory('settings')->where('key', '=', $key)->get()->update(array('value' => $value));
             }
             // Database commit
             Database::instance()->commit();
             // Add success notice
             Notice::add(Notice::SUCCESS, Kohana::message('general', 'update_success'));
         } catch (HTTP_Exception_302 $e) {
             $this->redirect($e->location());
         } catch (Validation_Exception $e) {
             // Database rollback
             Database::instance()->rollback();
             // Add validation notice
             Notice::add(Notice::VALIDATION, Kohana::message('general', 'update_failed'), NULL, $e->errors('validation'));
         } catch (Exception $e) {
             // Database rollback
             Database::instance()->rollback();
             // Add error notice
             Notice::add(Notice::ERROR, $e->getMessage());
         }
     }
     /**
      * View
      */
     // Get content file
     $content_file = Tpl::get_file('frontend', $this->settings->back_tpl_dir . '/settings', $this->partials);
     $this->content = Tpl::factory($content_file)->set('settings', $settings);
 }
예제 #25
0
 /**
  * Action delete
  */
 public function action_delete()
 {
     // Auto render off
     $this->auto_render = FALSE;
     // Get id from param, if there is nothing then throw to 404
     $id = $this->request->param('key');
     if (!$id) {
         throw HTTP_Exception::factory(404);
     }
     // Get comment, if there is nothing then throw to 404
     $received_email = Tbl::factory('received_emails')->get($id);
     if (!$received_email) {
         throw HTTP_Exception::factory(404);
     }
     // Database transaction start
     Database::instance()->begin();
     // Try
     try {
         /**
          * Delete
          */
         $received_email->delete();
         // Database commit
         Database::instance()->commit();
         // Add success notice
         Notice::add(Notice::SUCCESS, Kohana::message('general', 'delete_success'));
         $this->redirect(URL::site("{$this->settings->backend_name}/received_emails/index", 'http'));
     } catch (HTTP_Exception_302 $e) {
         $this->redirect($e->location());
     } catch (Validation_Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add validation notice
         Notice::add(Notice::VALIDATION, Kohana::message('general', 'delete_failed'), NULL, $e->errors('validation'));
     } catch (Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Add error notice
         Notice::add(Notice::ERROR);
     }
     // Redirect to received_emails index
     $this->redirect(URL::site("{$this->settings->backend_name}/received_emails/index", 'http'));
 }
예제 #26
0
 /**
  * Send comment
  *
  * @return object
  * 					post
  * 					success
  * 					failed
  * 					errors
  */
 public static function send_comment($item_id, $post)
 {
     /*
      * Check onetime ticket
      */
     // <editor-fold defaultstate="collapsed" desc="Check onetime ticket">
     $session_ticket = Session::instance()->get_once('ticket');
     $post_ticket = Arr::get($post, 'ticket');
     if (!$session_ticket or !$post_ticket or $session_ticket !== $post_ticket) {
         HTTP::redirect(Request::current()->referrer());
     }
     // </editor-fold>
     //
     //Get settings
     $settings = Cms_Helper::settings();
     $logged_in_user = Tbl::factory('users')->where('id', '=', Auth::instance()->get_user()->id)->read(1);
     // post filter
     $post = self::post_filter($post, $settings->send_comment_allowable_tags);
     // Build result
     $result = new stdClass();
     $result->post = $post;
     $result->success = FALSE;
     $result->invalid = FALSE;
     $result->exception = FALSE;
     $result->errors = array();
     // Database transaction start
     Database::instance()->begin();
     // Try
     try {
         // Create
         Tbl::factory('received_comments')->create(array('item_id' => $item_id, 'user_id' => isset($logged_in_user->id) ? $logged_in_user->id : NULL, 'replay_id' => Arr::get($post, 'replay_id'), 'display_name' => Arr::get($post, 'display_name'), 'subject' => Arr::get($post, 'subject'), 'content' => Arr::get($post, 'content'), 'created' => Date::formatted_time(), 'is_accept' => $settings->send_comment_is_accept_default));
         // Database commit
         Database::instance()->commit();
         /**
          * Set result
          */
         $result->post = array();
         $result->success = TRUE;
     } catch (Validation_Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Result
         $result->invalid = TRUE;
         // Separate errors field and message
         $errors = $e->errors('validation');
         foreach ($errors as $key => $value) {
             $result->errors[] = array('field' => $key, 'message' => $value);
         }
     } catch (Exception $e) {
         // Database rollback
         Database::instance()->rollback();
         // Result
         $result->exception = TRUE;
         // errors
         $result->errors[] = array('field' => 'system error');
     }
     Session::instance()->set('send_comment_result', $result);
 }