コード例 #1
0
ファイル: 401.php プロジェクト: deraemons/deraemon-cms
 /**
  * Generate a Response for the 401 Exception.
  *
  * Unauthorized / Login Requied
  * The user should be redirect to a login page.
  *
  * @return Response
  */
 public function get_response()
 {
     // Todo:: これはどうつくるの?
     // Get tpl directory
     $home_page = Cms_Helper::settings('home_page');
     $response = Response::factory()->status(401)->headers('Location', URL::site($home_page, 'http'));
     return $response;
 }
コード例 #2
0
ファイル: Imagefly.php プロジェクト: deraemons/deraemon-cms
 /**
  * Action index
  *
  * Example,  imagefly/1/w253-h253-h/test4.jpg
  * 					  imagefly/1/w-h-h/test4.jpg
  *
  * direction, portrait/landscape/square/original
  *
  * @throws HTTP_Exception
  */
 public function action_index()
 {
     // Get param
     try {
         $staff = $this->request->param('stuff');
         $stuffs = explode('/', $staff);
         $num = count($stuffs);
         $paths = array_slice($stuffs, 0, $num - 2);
         list($width_string, $height_string, $direction) = explode('-', $stuffs[$num - 2]);
         list($segment, $ext) = explode('.', $stuffs[$num - 1]);
         $width = substr($width_string, 1) ? substr($width_string, 1) : 0;
         $height = substr($height_string, 1) ? substr($height_string, 1) : 0;
         // Get content type
         switch ($ext) {
             case 'jpg':
                 $content_type = 'image/jpeg';
                 break;
             case 'png':
                 $content_type = 'image/png';
                 break;
             case 'gif':
                 $content_type = 'image/gif';
                 break;
             default:
                 $content_type = NULL;
                 break;
         }
         $first_dir = reset($paths);
         if (!in_array($first_dir, array('item', 'user'))) {
             throw HTTP_Exception::factory(404);
         }
         $image_dir = Cms_Helper::settings('image_dir');
         $dir = $image_dir . '/' . implode('/', $paths);
         $file = $segment;
         if ($direction !== 'o') {
             $file .= '_' . $direction;
         }
         $filename = Kohana::find_file($dir, $file, $ext);
     } catch (ErrorException $e) {
         throw HTTP_Exception::factory(404);
     }
     // Set render
     $rendered = FALSE;
     // If file
     if (is_file($filename)) {
         // Render image
         $this->_render_image($filename, $ext, $width, $height, $content_type);
         $rendered = TRUE;
     }
     // If rendered is false then throw to 404
     if (!$rendered) {
         throw HTTP_Exception::factory(404);
     }
 }
コード例 #3
0
ファイル: Media.php プロジェクト: deraemons/deraemon-cms
 /**
  * Action index
  *
  *
  * @throws HTTP_Exception
  */
 public function action_index()
 {
     try {
         $dir = NULL;
         $path = NULL;
         $file = NULL;
         $ext = NULL;
         $mime = NULL;
         $staff = $this->request->param('stuff');
         $front_tpl_dir = Cms_Helper::settings('front_tpl_dir');
         $full_path = $front_tpl_dir . '/media/' . $staff;
         // full_pathからファイルを探す
         $splited_path = explode('/', $full_path);
         foreach ($splited_path as $key => $value) {
             if ($key == 0) {
                 $dir = $value;
             } elseif ($key == count($splited_path) - 1) {
                 $dotpos = strrpos($value, '.');
                 if ($dotpos) {
                     $file = substr($value, 0, $dotpos);
                     $ext = substr($value, $dotpos + 1);
                 }
             } else {
                 $path .= $value . '/';
             }
         }
         if ($ext) {
             $mime = (object) $this->mime[$ext];
         }
         $filename = Kohana::find_file($dir, $path . $file, $ext);
     } catch (Exception $e) {
         throw HTTP_Exception::factory(404);
     }
     // Set render
     $rendered = FALSE;
     // If file
     if (is_file($filename)) {
         $rendered = TRUE;
         // Calculate ETag from original file padded with the dimension specs
         $etag_sum = md5(base64_encode(file_get_contents($filename)));
         // Render as image and cache for 1 hour
         $this->response->headers('Content-Type', $mime->content_type)->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('Last-Modified', date('r', filemtime($filename)))->headers('ETag', $etag_sum);
         if ($this->request->headers('if-none-match') and (string) $this->request->headers('if-none-match') === $etag_sum) {
             $this->response->status(304)->headers('Content-Length', '0');
         } else {
             $this->response->body(file_get_contents($filename));
         }
     }
     // If rendered is false then throw to 404
     if (!$rendered) {
         throw HTTP_Exception::factory(404);
     }
 }
コード例 #4
0
ファイル: Settings.php プロジェクト: deraemons/deraemon-cms
 /**
  * Action index
  */
 public function action_index()
 {
     // Get settings
     $settings = Tbl::factory('settings')->order_by('id')->read()->as_array('key');
     // If there are post
     if ($this->request->post()) {
         // Set post to settings
         foreach ($this->request->post() as $key => $value) {
             if (isset($settings[$key])) {
                 $settings[$key]->value = $value;
             }
         }
         // Database transaction start
         Database::instance()->begin();
         // Try
         try {
             // Update
             foreach ($this->request->post() as $key => $value) {
                 Tbl::factory('settings')->where('key', '=', $key)->get()->update(array('value' => $value));
             }
             // Database commit
             Database::instance()->commit();
             // Clear post
             $this->request->post(array());
             // Add success notice
             Notice::add(Notice::SUCCESS, Kohana::message('general', 'create_success'));
             // Redirect バックエンドネームが変わってる時があるから
             $backend_name = Cms_Helper::settings('backend_name');
             $this->redirect(URL::site("{$backend_name}/settings", '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', 'create_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('index', $this->settings->back_tpl_dir . '/settings', $this->partials);
     $this->content = Tpl::factory($content_file)->set('settings', $settings);
 }
コード例 #5
0
ファイル: Auth.php プロジェクト: deraemons/deraemon-cms
 /**
  * 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());
 }
コード例 #6
0
ファイル: Route.php プロジェクト: deraemons/deraemon-cms
 /**
  * Route
  *
  * @return Route
  */
 public static function write()
 {
     // Get backend name
     $backend_name = Cms_Helper::settings('backend_name');
     // Backend Auth
     Route::set('backend_auth', $backend_name . '/<action>', array('action' => '(directuser|login|logout)'))->defaults(array('directory' => 'backend', 'controller' => 'auth'));
     // Backend Media
     Route::set('backend_media', $backend_name . '/media(/<stuff>)', array('stuff' => '.*'))->defaults(array('directory' => 'backend', 'controller' => 'media', 'action' => 'index'));
     // Backend items
     Route::set('backend_items', $backend_name . '/items/<division>(/<action>(/<key>))')->filter(function ($route, $params, $request) {
         foreach ($params as &$param) {
             $param = str_replace('-', '_', $param);
         }
         return $params;
     })->defaults(array('directory' => 'backend', 'controller' => 'items', 'action' => 'index'));
     // Backend
     Route::set('backend', $backend_name . '(/<controller>(/<action>(/<key>)))')->filter(function ($route, $params, $request) {
         foreach ($params as &$param) {
             $param = str_replace('-', '_', Text::ucfirst($param));
         }
         return $params;
     })->defaults(array('directory' => 'backend', 'controller' => 'home', 'action' => 'index'));
     // Media
     Route::set('media', 'media(/<stuff>)', array('stuff' => '.*'))->defaults(array('controller' => 'media', 'action' => 'index'));
     // Imagefly
     // imagefly/1/w253-h253-p/test4.jpg
     Route::set('imagefly', 'imagefly(/<stuff>)', array('stuff' => '.*'))->defaults(array('controller' => 'imagefly', 'action' => 'index'));
     // Item
     Route::set('item', '<stuff>', array('stuff' => '.*'))->filter(function ($route, $params, $request) {
         foreach ($params as &$param) {
             $param = str_replace('-', '_', Text::ucfirst($param));
         }
         $stuffs = explode('/', $params['stuff']);
         $end_staff = end($stuffs);
         $segment = substr($end_staff, 0, strlen($end_staff) - (strpos($end_staff, '.') - 1));
         if (!$segment) {
             $segment = Cms_Helper::settings('home_page');
         }
         $params['segment'] = $segment;
         $item = (bool) DB::select('id')->from('items')->where('segment', '=', $segment)->execute()->get('id');
         if (!$item) {
             return FALSE;
         }
         return $params;
     })->defaults(array('controller' => 'item', 'action' => 'index'));
 }
コード例 #7
0
ファイル: 500.php プロジェクト: deraemons/deraemon-cms
 /**
  * Generate a Response for the 500 Exception.
  *
  * Internal
  * The user should be shown a nice 500 page.
  *
  * @return Response
  */
 public function get_response()
 {
     // Lets log the Exception, Just in case it's important!
     Kohana_Exception::log($this);
     if (Kohana::$environment >= Kohana::DEVELOPMENT) {
         // Show the normal Kohana error page.
         return parent::get_response();
     } else {
         // Get tpl directory
         $front_tpl_dir = Cms_Helper::settings('front_tpl_dir');
         // Get file
         $content_file = Tpl::get_file($this->code, $front_tpl_dir . '/error');
         // Set variable and render
         $content = Tpl::factory($content_file)->set('code', $this->getCode())->set('message', $this->getMessage())->set('request_url', URL::site(Request::current()->url(), "http"))->render();
         // Factory response
         $response = Response::factory();
         $response->body($content);
         return $response;
     }
 }
コード例 #8
0
ファイル: Item.php プロジェクト: deraemons/deraemon-cms
 /**
  * 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
ファイル: Functions.php プロジェクト: deraemons/deraemon-cms
 /**
  * Get user
  *
  * $is_blockがTRUEの時はblocl以外を取得
  */
 public static function get_user($user_id, $is_block = FALSE)
 {
     $result = array();
     $user = Tbl::factory('users')->where('id', '=', $user_id)->read(1);
     if ($is_block) {
         if ($user->is_block) {
             return FALSE;
         }
     }
     if ($user) {
         $result = array('id' => $user->id, 'username' => $user->username, 'email' => $user->email, 'avatar' => array(), 'detail' => array());
         if (!is_file('application/' . Cms_Helper::settings('image_dir') . '/user/' . $user->username . '/avatar' . $user->ext)) {
             $result['avatar'] = FALSE;
         } else {
             $result['avatar'] = array('path' => URL::site("imagefly", 'http') . '/user/' . $user->username . '/', 'file' => '/' . 'avatar' . $user->ext);
         }
         $result['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', '=', $user->id)->read()->as_array('segment');
     }
     return $result;
 }
コード例 #10
0
ファイル: Template.php プロジェクト: deraemons/deraemon-cms
 /**
  * Before
  */
 public function before()
 {
     /**
      * before
      */
     parent::before();
     /**
      * Get settings
      */
     // <editor-fold defaultstate="collapsed" desc="Get settings">
     $this->settings = Cms_Helper::settings();
     // </editor-fold>
     /**
      * Set website language
      */
     // <editor-fold defaultstate="collapsed" desc="Set website language">
     I18n::lang('backend' . $this->settings->backend_lang);
     // </editor-fold>
     /**
      * Authenticate and get logged in user:ディレクト、アドミン、エディター以外は入れない、入ったときはlogged in userをセット
      */
     // <editor-fold defaultstate="collapsed" desc="Authenticate and get logged in user">
     if (Auth::instance()->logged_in('direct') or Auth::instance()->logged_in('admin') or Auth::instance()->logged_in('edit')) {
         // もしログインしていてアクションがloginの場合はバックエンドホームに飛ばす
         if ($this->request->action() == 'login') {
             HTTP::redirect(URL::site($this->settings->backend_name, 'http'));
         }
         // Set logged in user
         $this->logged_in_user = Tbl::factory('users')->where('id', '=', Auth::instance()->get_user()->id)->read(1);
         // 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', '=', $this->logged_in_user->id)->where('roles.name', '!=', 'login')->read('name');
         // Set logged in user role name for template
         $this->logged_in_user->{$this->logged_in_user->role} = TRUE;
     } else {
         // If not logged in throw to login
         if (!($this->request->controller() == 'Auth')) {
             $this->redirect(URL::site("{$this->settings->backend_name}/login", 'http'));
         }
     }
     // </editor-fold>
     /**
      * Get item menu:itemのメニューを取得 $menusのitemsに入れる
      */
     // <editor-fold defaultstate="collapsed" desc="Get item menu">
     $divisions = Tbl::factory('divisions')->read()->as_array();
     // itemのチルドレンの配列を作成
     $item_children = array();
     // item search
     // controllerは新しく作ったよ
     $item_children['item_search'] = array('name' => 'item search', 'controller' => 'item_search', 'division' => '', 'actions' => array('index'), 'url' => URL::site("{$this->settings->backend_name}/item_search", 'http'), 'roles' => array('direct', 'admin', 'edit'), 'allow' => FALSE);
     // 作成されたディビジョンの数だけ作成
     foreach ($divisions as $division) {
         $item_children[$division->name] = array('name' => $division->name, 'controller' => 'items', 'division' => $division->segment, 'actions' => array('index', 'edit', 'content', 'images', 'image_delete', 'fields', 'received_comments', 'received_comment_delete', 'delete'), 'url' => URL::site("{$this->settings->backend_name}/items/{$division->segment}", 'http'), 'roles' => array('direct', 'admin', 'edit'), 'allow' => FALSE);
     }
     // </editor-fold>
     /**
      * Build menu:全体のメニューを作成
      *
      * 許可するロールを指定
      * 'roles' => array('direct', 'admin', 'edit')
      */
     // <editor-fold defaultstate="collapsed" desc="Build menu">
     $this->menus = array('dashboard' => array('name' => 'dashboard', 'icon' => 'fa fa-dashboard', 'children' => array('home' => array('name' => 'home', 'controller' => 'home', 'actions' => array('index', 'about', 'syntax'), 'url' => URL::site("{$this->settings->backend_name}/home/index", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin', 'edit')), 'settings' => array('name' => 'settings', 'controller' => 'settings', 'actions' => array('index', 'frontend'), 'url' => URL::site("{$this->settings->backend_name}/settings/index", 'http'), 'allow' => FALSE, 'roles' => array('direct')), 'users' => array('name' => 'users', 'controller' => 'users', 'actions' => array('index', 'edit', 'avatar_delete', 'detail', 'delete'), 'url' => URL::site("{$this->settings->backend_name}/users/index", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')), 'received_emails' => array('name' => 'received emails', 'controller' => 'received_emails', 'actions' => array('index', 'delete'), 'url' => URL::site("{$this->settings->backend_name}/received-emails/index", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')), 'received_comments' => array('name' => 'received comments', 'controller' => 'received_comments', 'actions' => array('index', 'delete'), 'url' => URL::site("{$this->settings->backend_name}/received-comments/index", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')))), 'template' => array('name' => 'template', 'icon' => 'fa fa-file-o', 'children' => array('wrappers' => array('name' => 'wrappers', 'controller' => 'wrappers', 'actions' => array('index', 'edit', 'delete'), 'url' => URL::site("{$this->settings->backend_name}/wrappers/index", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')), 'divisions' => array('name' => 'divisions', 'controller' => 'divisions', 'actions' => array('index', 'edit', 'delete'), 'url' => URL::site("{$this->settings->backend_name}/divisions/index", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')), 'shapes' => array('name' => 'shapes', 'controller' => 'shapes', 'actions' => array('index', 'edit', 'delete'), 'url' => URL::site("{$this->settings->backend_name}/shapes/index", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')), 'parts' => array('name' => 'parts', 'controller' => 'parts', 'actions' => array('index', 'edit', 'delete'), 'url' => URL::site("{$this->settings->backend_name}/parts/index", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')), 'search' => array('name' => 'search', 'controller' => 'search', 'actions' => array('form', 'result', 'delete'), 'url' => URL::site("{$this->settings->backend_name}/search/form", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')), 'emails' => array('name' => 'emails', 'controller' => 'emails', 'actions' => array('setting', 'index', 'edit', 'confirm', 'receive', 'rule', 'rule_delete', 'delete'), 'url' => URL::site("{$this->settings->backend_name}/emails/setting", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')), 'comment' => array('name' => 'comment', 'controller' => 'comment', 'actions' => array('setting', 'form', 'result'), 'url' => URL::site("{$this->settings->backend_name}/comment/setting", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')), 'author' => array('name' => 'author', 'controller' => 'author', 'actions' => array('setting', 'login', 'register', 'activate_mail', 'activate', 'forgot', 'reset_mail', 'reset', 'resign', 'account', 'password', 'detail'), 'url' => URL::site("{$this->settings->backend_name}/author/setting", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')), 'errors' => array('name' => 'errors', 'controller' => 'errors', 'actions' => array('404', '500', 'default'), 'url' => URL::site("{$this->settings->backend_name}/errors/404", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')))), 'attachment' => array('name' => 'attachment', 'icon' => 'fa fa-paperclip', 'children' => array('fields' => array('name' => 'fields', 'controller' => 'fields', 'actions' => array('index', 'edit', 'delete'), 'url' => URL::site("{$this->settings->backend_name}/fields/index", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')), 'categories' => array('name' => 'categories', 'controller' => 'categories', 'actions' => array('index', 'edit', 'delete'), 'url' => URL::site("{$this->settings->backend_name}/categories/index", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')), 'tags' => array('name' => 'tags', 'controller' => 'tags', 'actions' => array('index', 'edit', 'delete'), 'url' => URL::site("{$this->settings->backend_name}/tags/index", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')), 'details' => array('name' => 'details', 'controller' => 'details', 'actions' => array('index', 'edit', 'rule', 'rule_delete', 'delete'), 'url' => URL::site("{$this->settings->backend_name}/details/index", 'http'), 'allow' => FALSE, 'roles' => array('direct', 'admin')))), 'items' => array('name' => 'items', 'icon' => 'fa fa-files-o', 'children' => $item_children));
     // </editor-fold>
     /**
      * Set current to menu:currentをセット、現在のページ(current_child)をセット
      */
     // <editor-fold defaultstate="collapsed" desc="Set current to menu">
     $controller = strtolower($this->request->controller());
     $action = strtolower($this->request->action());
     $division = $this->request->param('division');
     $current_child = NULL;
     // メニューをイテレート
     foreach ($this->menus as $key => &$value) {
         // メニューのチャイルドをイテレート
         foreach ($value['children'] as &$child) {
             // If except an item:もしcontrollerがitemsの時で↓
             if ($child['controller'] !== 'items') {
                 // カレントの場合
                 if ($child['controller'] === $controller) {
                     // parrentにTRUEをセット
                     $value['current'] = TRUE;
                     if (in_array($action, $child['actions'])) {
                         // currentにTRUEをセット
                         $child['current'] = TRUE;
                         // カレントチャイルドにセット
                         $current_child = (object) $child;
                         $current_child->parrent = $key;
                     }
                 }
                 // ロールがある場合
                 if ($this->logged_in_user and in_array($this->logged_in_user->role, $child['roles'])) {
                     $child['allow'] = TRUE;
                 }
             } else {
                 // カレントの場合
                 if ($child['division'] === $division) {
                     // currentにTRUEをセット
                     $value['current'] = TRUE;
                     if (in_array($action, $child['actions'])) {
                         // currentにTRUEをセット
                         $child['current'] = TRUE;
                         // カレントチャイルドにセット
                         $current_child = (object) $child;
                         $current_child->parrent = $key;
                     }
                 }
                 // ロールがある場合
                 if ($this->logged_in_user and in_array($this->logged_in_user->role, $child['roles'])) {
                     $child['allow'] = TRUE;
                 }
             }
         }
     }
     // </editor-fold>
     /**
      * Allow page controll:許可するページのみ入れる、それ以外はのNoticeを出してredirect
      *
      * user_idのfilterはitemsのcontlollerで行う
      */
     // <editor-fold defaultstate="collapsed" desc="Allow page controll">
     if ($this->logged_in_user and $current_child) {
         // ロールに含まれない場合
         if (!in_array($this->logged_in_user->role, $current_child->roles)) {
             // ワーニング
             Notice::add(Notice::WARNING, Kohana::message('general', 'no_authority'));
             // リダイレクト
             $this->redirect(URL::site("{$this->settings->backend_name}", 'http'));
         }
     } elseif ($controller !== 'auth' and $action !== 'login') {
         // ワーニング
         Notice::add(Notice::WARNING, Kohana::message('general', 'no_authority'));
         // リダイレクト
         $this->redirect(URL::site("{$this->settings->backend_name}", 'http'));
     }
     // </editor-fold>
     /**
      * View
      */
     // <editor-fold defaultstate="collapsed" desc="View">
     if ($this->auto_render) {
         // Partial header and footer
         $this->partials['header'] = Tpl::get_file('header', $this->settings->back_tpl_dir);
         $this->partials['footer'] = Tpl::get_file('footer', $this->settings->back_tpl_dir);
         $this->partials['snippets'] = Tpl::get_file('snippets', $this->settings->back_tpl_dir);
     }
     // </editor-fold>
 }
コード例 #11
0
ファイル: Item.php プロジェクト: deraemons/deraemon-cms
 /**
  * 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);
 }