public function action_login() { $this->view->username = ''; $this->view->return_to = Arr::get($_REQUEST, 'return_to', ''); if ($this->request->post('login') !== NULL) { Auth::instance()->logout(); // Just in case we're logged in. $this->view->username = trim($this->request->post('username')); $password = trim($this->request->post('password')); Auth::instance()->login($this->view->username, $password); if (Auth::instance()->logged_in()) { try { $dbms = new WebDB_DBMS(); $dbms->refresh_cache(); $this->add_flash_message('You are now logged in.', 'info'); Kohana::$log->add(Kohana_Log::INFO, $this->view->username . ' logged in.'); } catch (Exception $e) { $msg = 'Unable to log in as :username.'; throw HTTP_Exception::factory(500, $msg, array(':username' => $this->view->username), $e); } $this->redirect($this->view->return_to); } else { Kohana::$log->add(Kohana_Log::INFO, 'Failed log in: ' . $this->view->username); $this->add_template_message('Login failed. Please try again.'); } } // if ($this->request->post('login') !== NULL) }
public function action_index() { try { if ($token = $this->grantAccessToken()) { // @see http://tools.ietf.org/html/rfc6749#section-5.1 // server MUST disable caching in headers when tokens are involved $this->response->status(200); $this->response->headers(array('Cache-Control' => 'no-store', 'Pragma' => 'no-cache')); $this->response->headers('content-type', 'application/json; charset=' . Kohana::$charset); $this->response->body(JSON::encode($token)); return; } } catch (Oauth2_Exception $e) { // Throw an exception because there was a problem with the client's request $response = array('error' => $e->getError(), 'error_description' => $e->getMessage()); $this->response->status($e->getCode()); $this->response->headers(array('Cache-Control' => 'no-store', 'Pragma' => 'no-cache')); $this->response->headers('content-type', 'application/json; charset=' . Kohana::$charset); $this->response->body(json_encode($response)); return; } catch (Exception $e) { /** * Something went wrong! * * Throw an error when a non-library specific exception has been thrown * * You should probably show a nice error page :) * * Do NOT redirect the user back to the client. */ throw HTTP_Exception::factory(500, $e->getMessage()); } }
/** * REST endpoint for sharing droplets via email */ public function action_share() { $this->template = ''; $this->auto_render = FALSE; if ($this->request->method() != "POST") { throw HTTP_Exception::factory(405)->allowed('POST'); } // Extract the input data to be used for sending the email $post = Arr::extract($_POST, array('recipient', 'drop_title', 'drop_url', 'security_code')); $csrf_token = $this->request->headers('x-csrf-token'); // Setup validation $validation = Validation::factory($post)->rule('recipient', 'not_empty')->rule('recipient', 'email')->rule('security_code', 'Captcha::valid')->rule('drop_title', 'not_empty')->rule('drop_url', 'url'); // Validate if (!CSRF::valid($csrf_token) or !$validation->check()) { Kohana::$log->add(Log::DEBUG, "CSRF token or form validation failure"); throw HTTP_Exception::factory(400); } else { list($recipient, $subject) = array($post['recipient'], $post['drop_title']); // Modify the mail body to include the email address of the // use sharing content $mail_body = __(":user has shared a drop with you via SwiftRiver\n\n:url", array(':user' => $this->user['owner']['username'], ':url' => $post['drop_url'])); // Send the email Swiftriver_Mail::send($recipient, $subject, $mail_body); } }
/** * View users profile */ public function action_index() { $id = $this->request->param('id'); $user = ORM::factory('User', $id); if (!$user->loaded()) { throw HTTP_Exception::Factory('404', 'No such user'); } $container = new Tabs(); $about = new Tab('About me'); $about->add_content(new Tab_Text($user->get_property('about'))); $about->add_content(new Tab_Text($user->get_property('signature'))); $container->add_tab($about); Event::fire('user.profile_tabs', array($user, $container)); $this->view = new View_User_Profile(); $this->view->user = $user; $this->view->tabs = $container->render(); /* // @TODO, This belongs to the pet module, better to use events? $pets = ORM::factory('User_Pet') ->where('user_id', '=', $user->id) ->order_by('active', 'desc'); $paginate = Paginate::factory($pets) ->execute(); $this->view = new View_User_Profile; $this->view->pagination = $paginate->render(); $this->view->profile_user = $user; // $this->view->pets = ORM::factory('User_Pet')->where('user_id', '=', $user->id)->order_by('active', 'desc')->find_all()->as_array(); $this->view->pets = $paginate->result(); */ }
/** * Handle incoming SMS from Twilio */ public function action_reply() { //Check if data provider is available $providers_available = Kohana::$config->load('features.data-providers'); if (!$providers_available['twilio']) { throw HTTP_Exception::factory(403, 'The Twilio data source is not currently available. It can be accessed by upgrading to a higher Ushahidi tier.'); } if ($this->request->method() != 'POST') { // Only POST is allowed throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => Http_Request::POST))->allowed(Http_Request::POST); } $provider = DataProvider::factory('twilio'); // Authenticate the request $options = $provider->options(); if ($this->request->post('AccountSid') !== $options['account_sid']) { throw HTTP_Exception::factory(403, 'Incorrect or missing AccountSid'); } // Remove Non-Numeric characters because that's what the DB has $to = preg_replace("/[^0-9,.]/", "", $this->request->post('To')); $from = preg_replace("/[^0-9,.]/", "", $this->request->post('From')); $message_text = $this->request->post('Body'); $message_sid = $this->request->post('MessageSid'); // @todo use other info from twillio, ie: location, media $provider->receive(Message_Type::SMS, $from, $message_text, $to, NULL, $message_sid); // If we have an auto response configured, return the response messages if (!empty($options['sms_auto_response'])) { $body = View::factory('twillio/sms_response')->set('response', $options['sms_auto_response'])->render(); // Set the correct content-type header $this->response->headers('Content-Type', 'text/xml'); $this->response->body($body); } }
public function action_index() { try { // Validating $this->validateRevokeRequest(); if ($this->token_info['access_token'] == $this->token && !empty($this->token_info['refresh_token'])) { $result = Model::factory('oauth')->revoke_access_refresh($this->token); } elseif ($this->token_info['access_token'] == $this->token && empty($this->token_info['refresh_token'])) { $result = Model::factory('oauth')->revoke_access($this->token); } elseif ($this->token_info['refresh_token'] == $this->token) { $result = Model::factory('oauth')->revoke_refresh($this->token); } $this->response->body(json_encode(array('Response' => "Status Code: 200"))); return; } catch (Oauth2_Exception $e) { // Throw an exception because there was a problem with the client's request $response = array('error' => $e->getError(), 'error_description' => $e->getMessage()); $this->response->status($e->getCode()); $this->response->headers(array('Cache-Control' => 'no-store', 'Pragma' => 'no-cache')); $this->response->body(json_encode($response)); } catch (Exception $e) { /** * Something went wrong! * * Throw an error when a non-library specific exception has been thrown * * You should probably show a nice error page :) * * Do NOT redirect the user back to the client. */ throw HTTP_Exception::factory(500, $e->getMessage()); } }
/** * creates a user from email if exists doesn't... * @param string $email * @param string $name * @param string $password * @return Model_User */ public static function create_email($email, $name = NULL, $password = NULL) { $user = new self(); $user->where('email', '=', $email)->limit(1)->find(); if (!$user->loaded()) { if ($password === NULL) { $password = Text::random('alnum', 8); } $user->email = $email; $user->name = ($name === NULL or !isset($name)) ? substr($email, 0, strpos($email, '@')) : $name; $user->status = self::STATUS_ACTIVE; $user->id_role = Model_Role::ROLE_USER; $user->seoname = $user->gen_seo_title($user->name); $user->password = $password; $user->subscriber = 1; $user->last_ip = ip2long(Request::$client_ip); $user->country = euvat::country_code(); //geo info EU try { $user->save(); //send welcome email $url = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'edit'), TRUE); $user->email('auth-register', array('[USER.PWD]' => $password, '[URL.QL]' => $url)); } catch (ORM_Validation_Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } return $user; }
public function action_complete() { // Get the transaction details. $fetch = $this->_gateway->fetchTransaction($this->_payment_vars())->send(); $data = $fetch->getData(); // Add the buyer email to parameters. $parameters = $this->_payment_vars() + array('email' => $data['EMAIL']); /** @var Payment_PayPal_CreateRecurringPaymentsRequest $request */ $request = $this->_gateway->createRecurringPaymentsProfile($parameters); // Overwrite Item Category. $data = $request->getData(); $data['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = $this->_config['itemCategory']; /** @var Omnipay\PayPal\Message\ExpressAuthorizeResponse $response */ $response = $request->sendData($data); if ($response->isSuccessful()) { $response_data = $response->getData(); // Get the transaction details. // $fetch = $this->_gateway->fetchTransaction($this->_payment_vars())->send(); // $data = $fetch->getData(); ORM::factory('Payment_Subscription')->values(array('user_id' => $this->user->id, 'package_id' => $this->_package->id, 'status' => Model_Payment_Subscription::PENDING, 'recurring_payment_id' => $response_data['PROFILEID']))->create(); Hint::success(Kohana::message('payment', 'payment.success')); $this->redirect(Route::get('payment')->uri()); } else { // Log the error. Kohana::$log->add(Log::ERROR, IPN::array_to_string($response->getData())); throw HTTP_Exception::factory('403', 'Something went wrong, no cash should have been drawn, if the error proceeds contact support!'); } }
public function action_index() { // Log the output Kohana::$log->add(Log::DEBUG, IPN::array_to_string($this->request->post())); $this->_IPN = new IPN(); $this->_IPN->process($this->request->post()); // If the request did not come from PayPal show a 404 page. if (!$this->_IPN->is_verified()) { throw HTTP_Exception::factory('404', 'File not found!'); } // TODO: We want to log all IPN actions and ensure we do not process the same action TWICE! // Find the correct subscription. $this->_subscription = ORM::factory('Payment_Subscription')->where('recurring_payment_id', '=', $this->_IPN->get_data('recurring_payment_id'))->find(); Kohana::$log->add(Log::DEBUG, $this->_IPN->get_transaction_type()); switch ($this->_IPN->get_transaction_type()) { case IPN::RECURRING_PAYMENT_PROFILE_CREATED: Kohana::$log->add(Log::DEBUG, 'PROFILE CREATED'); $this->_profile_created(); break; case IPN::RECURRING_PAYMENT: Kohana::$log->add(Log::DEBUG, 'PAYMENT RECEIVED'); $this->_payment(); break; case IPN::RECURRING_PAYMENT_PROFILE_CANCEL: Kohana::$log->add(Log::DEBUG, 'PROFILE CANCEL'); $this->_profile_cancel(); break; } $this->response->status(200); $this->response->body('OK'); }
/** * Serve the file to the browser AND cache it for direct access if in STAGING OR PRODUCTION. */ public function action_index() { $file = $this->request->param('file'); $ext = pathinfo($file, PATHINFO_EXTENSION); $path = Kohana::find_file('assets', $file, FALSE); if ($path === FALSE) { throw HTTP_Exception::factory('404', 'File not found!'); } $dir = DOCROOT . 'assets' . DIRECTORY_SEPARATOR; // Set the proper headers for browser caching $this->response->headers('content-type', File::mime_by_ext($ext)); $this->response->headers('last-modified', date('r', filemtime($path))); $content = file_get_contents($path); $this->response->body($content); // Don't cache the assets unless we are in STAGING OR PRODUCTION. if (Kohana::$environment >= Kohana::STAGING) { return; } // Only cache for specific extensions. if (!in_array($ext, $this->_cache_extensions)) { return; } // Check if assets sub dir exist. $parts = explode('/', $file); $file = array_pop($parts); foreach ($parts as $part) { $dir .= $part . DIRECTORY_SEPARATOR; if (!is_dir($dir)) { mkdir($dir); } } file_put_contents($dir . $file, $content); }
/** * List of pages (blogs/posts/etc.) with a specific tag * * @throws HTTP_Exception_404 * * @uses Log::add * @uses Text::ucfirst * @uses ACL::check * @uses Meta::links * @uses URL::canonical * @uses Route::url */ public function action_view() { $id = (int) $this->request->param('id', 0); $tag = ORM::factory('tag', $id); if (!$tag->loaded()) { throw HTTP_Exception::factory(404, 'Tag :tag not found!', array(':tag' => $id)); } $this->title = __(':title', array(':title' => Text::ucfirst($tag->name))); $view = View::factory('tag/view')->set('teaser', TRUE)->bind('pagination', $pagination)->bind('posts', $posts); $posts = $tag->posts; if (!ACL::check('administer tags') and !ACL::check('administer content')) { $posts->where('status', '=', 'publish'); } $total = $posts->reset(FALSE)->count_all(); if ($total == 0) { Log::info('No posts found.'); $this->response->body(View::factory('page/none')); return; } $pagination = Pagination::factory(array('current_page' => array('source' => 'cms', 'key' => 'page'), 'total_items' => $total, 'items_per_page' => 15, 'uri' => $tag->url)); $posts = $posts->order_by('created', 'DESC')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all(); $this->response->body($view); // Set the canonical and shortlink for search engines if ($this->auto_render === TRUE) { Meta::links(URL::canonical($tag->url, $pagination), array('rel' => 'canonical')); Meta::links(Route::url('tag', array('action' => 'view', 'id' => $tag->id)), array('rel' => 'shortlink')); } }
public function action_index() { // Set up custom error view Kohana_Exception::$error_view = 'error/data-provider'; if ($this->request->method() != 'GET') { // Only GET is allowed as FrontlineSms does only GET request throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => Http_Request::GET))->allowed(Http_Request::GET); } $provider = DataProvider::factory('frontlinesms'); // Authenticate the request $options = $provider->options(); if (!isset($options['key']) or empty($options['key'])) { throw HTTP_Exception::factory(403, 'Key value has not been configured'); } if (!$this->request->query('key') or $this->request->query('key') != $options['key']) { throw HTTP_Exception::factory(403, 'Incorrect or missing key'); } if (!$this->request->query('m')) { throw HTTP_Exception::factory(403, 'Missing message'); } // Remove Non-Numeric characters because that's what the DB has $from = preg_replace('/\\D+/', "", $this->request->post('from')); $message_text = $this->request->query('m'); // If receiving an SMS Message if ($from and $message_text) { $provider->receive(Message_Type::SMS, $from, $message_text, $to); } $json = array('payload' => array('success' => TRUE, 'error' => NULL)); // Set the correct content-type header $this->response->headers('Content-Type', 'application/json'); $this->response->body(json_encode($json)); }
/** * Callback for 'gather' response on call to Twilio */ public function action_gather() { if ($this->request->method() != 'POST') { // Only POST is allowed throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => Http_Request::POST))->allowed(Http_Request::POST); } $provider = DataProvider::factory('twilio'); // Authenticate the request $options = $provider->options(); if ($this->request->post('AccountSid') !== $options['account_sid']) { // Could not authenticate the request? throw HTTP_Exception::factory(403, 'Incorrect or missing AccountSid'); } // Remove Non-Numeric characters because that's what the DB has $to = preg_replace("/[^0-9,.]/", "", $this->request->post('To')); $from = preg_replace("/[^0-9,.]/", "", $this->request->post('From')); $message_sid = $this->request->post('CallSid'); $digits = $this->request->post('Digits'); if ($digits == 1) { $message_text = 'IVR: Okay'; } else { if ($digits == 2) { $message_text = 'IVR: Not Okay'; } else { // HALT Kohana::$log->add(Log::ERROR, __("':digits' is not a valid IVR response", array(":digits" => $digits))); return; } } $provider->receive(Message_Type::IVR, $from, $message_text, $to, NULL, $message_sid); }
public function action_index() { // Set up custom error view Kohana_Exception::$error_view = 'error/data-provider'; //Check if data provider is available $providers_available = Kohana::$config->load('features.data-providers'); if (!$providers_available['smssync']) { throw HTTP_Exception::factory(403, 'The SMS Sync data source is not currently available. It can be accessed by upgrading to a higher Ushahidi tier.'); } $methods_with_http_request = [Http_Request::POST, Http_Request::GET]; if (!in_array($this->request->method(), $methods_with_http_request)) { // Only POST or GET is allowed throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => implode(',', $methods_with_http_request)))->allowed($methods_with_http_request); } $this->_provider = DataProvider::factory('smssync'); $this->options = $this->_provider->options(); // Ensure we're always returning a payload.. // This will be overwritten later if incoming or task methods are run $this->_json['payload'] = ['success' => TRUE, 'error' => NULL]; // Process incoming messages from SMSSync only if the request is POST if ($this->request->method() == 'POST') { $this->_incoming(); } // Attempt Task if request is GET and task type is 'send' if ($this->request->method() == 'GET' and $this->request->query('task') == 'send') { $this->_task(); } // Set the response $this->_set_response(); }
/** * Ensure we are calling this controller from the install.php by checking the MG_INSTALL constant. * And throw a HTTP 404 exception if that is not the case. * * @throws HTTP_Exception */ public function before() { // Ensure we are in the install.php file. if (!defined('MG_INSTALL') or MG_INSTALL !== TRUE) { throw HTTP_Exception::factory(404, 'File not found!'); } }
/** * upload files */ protected function create($model, $form) { // check rights if (!Acl::instance()->allowed($this->_controller, 'create')) { throw HTTP_Exception::factory(403, 'Create not allowed on :controller', array(':controller' => $this->_controller)); } $hash = FALSE; Event::raise($this, Event::BEFORE_CREATE_FORM_PARSE, array('model' => NULL, 'form' => $form)); if ($form->valid()) { $hash = Upload::process('file', $this->_settings->get('path_temp'), $this->_settings->get('extensions'), $this->_settings->get('unzip')); } if ($hash !== FALSE) { return $hash; } else { if ($form->submitted()) { // set error in form $form->element('file', 0)->error('not_empty'); } // create viewer $viewer = Viewer::factory('Form', $form)->text(Text::instance()); // render form $view = View::factory($this->_settings->get('view.create'), array('viewer' => $viewer)); // event Event::raise($this, Event::BEFORE_CREATE_RENDER, array('model' => NULL, 'form' => $form, 'viewer' => $viewer, 'view' => $view)); // render $this->response->body($view->render()); return FALSE; } }
public function action_index() { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default'))); Breadcrumbs::add(Breadcrumb::factory()->set_title(__('User Profile'))); $seoname = $this->request->param('seoname', NULL); if ($seoname !== NULL) { $user = new Model_User(); $user->where('seoname', '=', $seoname)->limit(1)->cached()->find(); if ($user->loaded()) { $this->template->title = __('User Profile') . ' - ' . $user->name; //$this->template->meta_description = $user->name;//@todo phpseo $this->template->bind('content', $content); $ads = new Model_Ad(); $ads = $ads->where('id_user', '=', $user->id_user)->where('status', '=', Model_Ad::STATUS_PUBLISHED)->order_by('created', 'desc')->cached()->find_all(); // case when user dont have any ads if ($ads->count() == 0) { $profile_ads = NULL; } $this->template->content = View::factory('pages/userprofile', array('user' => $user, 'profile_ads' => $ads)); } else { //throw 404 throw HTTP_Exception::factory(404, __('Page not found')); } } else { //throw 404 throw HTTP_Exception::factory(404, __('Page not found')); } }
/** * expired featured ads * @return void */ public static function renew() { if (Core::config('general.subscriptions') == TRUE) { //get expired subscription that are active $subscriptions = new Model_Subscription(); $subscriptions = $subscriptions->where('status', '=', 1)->where('expire_date', '<=', Date::unix2mysql())->order_by('created', 'desc')->find_all(); foreach ($subscriptions as $s) { //disable the plan $s->status = 0; try { $s->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } $plan = $s->plan; if ($plan->loaded() and $plan->status == 1) { //generate a new order $order = Model_Order::new_order(NULL, $s->user, $plan->id_plan, $plan->price, core::config('payment.paypal_currency'), __('Subscription to ') . $plan->name); //free plan no checkout if ($plan->price == 0) { $order->confirm_payment('cash'); } else { $checkout_url = $s->user->ql('default', array('controller' => 'plan', 'action' => 'checkout', 'id' => $order->id_order)); $s->user->email('plan-expired', array('[PLAN.NAME]' => $plan->name, '[URL.CHECKOUT]' => $checkout_url)); } } //if plan loaded } //end foreach } //if subscription active }
/** * Shows list of permissions per role * * @throws HTTP_Exception_404 */ public function action_role() { $id = $this->request->param('id', 1); $role = ORM::factory('role', $id); if (!$role->loaded()) { throw HTTP_Exception::factory(404, 'Attempt to access non-existent role.'); } if (isset($_POST['permissions']) and $this->valid_post('role')) { $per_insert = DB::insert('permissions', array('rid', 'permission', 'module')); foreach ($_POST['role'] as $key => $val) { if (isset($val['name'])) { $per_insert->values(array($role->id, $val['name'], $val['module'])); } } try { DB::delete('permissions')->where('rid', '=', $role->id)->execute(); $per_insert->execute(); Message::success(__('Permissions saved successfully!')); // Redirect to listing $this->request->redirect(Route::get('admin/permission')->uri(array('action' => 'role', 'id' => $role->id))); } catch (ORM_Validation_Exception $e) { Message::error(__('Permissions save failed!')); $this->_errors = array('models', TRUE); } } $role_perms = DB::select()->from('permissions')->as_object()->execute(); $this->title = __(':role Permissions', array(':role' => $role->name)); $view = View::factory('admin/permission/role')->set('permissions', ACL::all())->bind('errors', $this->_errors)->bind('perms', $role_perms)->bind('role', $role)->bind('id', $id); $this->response->body($view); }
/** * The before() method is called before controller action * * @uses Request::is_ajax * @uses Request::uri * @throws HTTP_Exception_404 */ public function before() { // Ajax request only! if (!$this->request->is_ajax()) { throw HTTP_Exception::factory(404, 'Accessing an ajax request :type externally', array(':type' => '<small>' . $this->request->uri() . '</small>')); } parent::before(); }
/** * Model_Default_User::match_password() * check if given password matches encrypted password * * @param String $password * @return Boolean */ public function verify($string) { if ($this->loaded() == FALSE) { throw HTTP_Exception::factory(500, 'Trying to verify password of unloaded user'); } $password = Password::factory($string); return $password->match($this->password); }
/** * Check to ensure POST requests contains CSRF. * @throws HTTP_Exception */ private function _validate_csrf() { if ($this->request->method() == HTTP_Request::POST) { $validation = Validation::factory($this->request->post())->rule('csrf', 'not_empty')->rule('csrf', 'Security::check'); if (!$validation->check()) { throw HTTP_Exception::Factory(403, 'CSRF check failed!'); } } }
public final function __toString() { try { return (string) $this->render(); } catch (Exception $e) { // Display the exception message HTTP_Exception::factory($e->getCode(), $e->getMessage()); } }
public function action_index() { if (!$this->user->can('Admin_Dashboard_Index')) { throw HTTP_Exception::factory('403', 'Permission denied to access admin dashboard index '); } $feed = $this->_get_news_feed(); $this->view = new View_Admin_Dashboard_Index(); $this->view->feed = $feed; }
public function action_index() { $pet = ORM::factory('User_Pet')->where('name', '=', $this->request->param('name'))->find(); if (!$pet->loaded()) { throw HTTP_Exception::factory('404', 'Pet not found'); } $this->view = new View_Pet_Profile(); $this->view->pet = $pet; $this->view->href = array('create' => Route::url('pet.create')); }
/** * Creates a new translated exception. * * throw new Kohana_Exception('Something went terrible wrong, :user', * array(':user' => $user)); * * @param string $message status message, custom content to display with error * @param array $variables translation variables * @return void */ public function __construct($message = NULL, array $variables = NULL, Exception $previous = NULL, array $errors = NULL) { if ($errors) { $this->setErrors($errors); } if (method_exists($previous, 'getErrors')) { $this->setErrors($previous->getErrors()); } parent::__construct($message, $variables, $previous); }
/** * Package details. * * @throws HTTP_Exception */ public function action_package() { $id = $this->request->param('id'); $package = ORM::factory('Payment_Package', $id); if (!$package->loaded()) { throw HTTP_Exception::factory('404', 'file not found'); } $this->view = new View_Payment_Package(); $this->view->package = $package; }
public function action_index() { // validation active Breadcrumbs::add(Breadcrumb::factory()->set_title(__('List'))); $this->template->title = __('Translations'); //scan project files and generate .po $parse = $this->request->query('parse'); if ($parse) { //scan script require_once Kohana::find_file('vendor', 'POTCreator/POTCreator', 'php'); $obj = new POTCreator(); $obj->set_root(DOCROOT); $obj->set_exts('php'); $obj->set_regular('/_[_|e]\\([\\"|\']([^\\"|\']+)[\\"|\']\\)/i'); $obj->set_base_path('..'); $obj->set_read_subdir(true); $obj->write_pot(i18n::get_language_path()); Alert::set(Alert::SUCCESS, 'File regenerated'); } //change default site language if ($this->request->param('id')) { //save language $locale = new Model_Config(); $locale->where('group_name', '=', 'i18n')->where('config_key', '=', 'locale')->limit(1)->find(); if (!$locale->loaded()) { $locale->group_name = 'i18n'; $locale->config_key = 'locale'; } $locale->config_value = $this->request->param('id'); try { $locale->save(); Alert::set(Alert::SUCCESS, __('Translations regenarated')); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } HTTP::redirect(Route::url('oc-panel', array('controller' => 'translations'))); } //create language if (Core::post('locale')) { $language = $this->request->post('locale'); $folder = DOCROOT . 'languages/' . $language . '/LC_MESSAGES/'; // if folder does not exist, try to make it if (!file_exists($folder) and !@mkdir($folder, 0775, true)) { // mkdir not successful ? Alert::set(Alert::ERROR, __('Language folder cannot be created with mkdir. Please correct to be able to create new translation.')); HTTP::redirect(Route::url('oc-panel', array('controller' => 'translations'))); } // write an empty .po file for $language $out = 'msgid ""' . PHP_EOL; $out .= 'msgstr ""' . PHP_EOL; File::write($folder . 'messages.po', $out); Alert::set(Alert::SUCCESS, $this->request->param('id') . ' ' . __('Language saved')); } $this->template->content = View::factory('oc-panel/pages/translations/index', array('languages' => i18n::get_languages(), 'current_language' => core::config('i18n.locale'))); }
public function execute() { $this->before(); $action = "action_" . $this->request->action(); if (!method_exists($this, $action)) { throw HTTP_Exception::factory(404, "The requested URL :uri was not found on this server.", array(":uri" => $this->request->uri()))->request($this->request); } $this->{$action}(); $this->after(); return $this->response; }
/** * Send response with error code. * * @param string $message * @throws HTTP_Exception */ protected function _deny_access($message = null) { if (Auth::is_logged_in() || $this->request->is_ajax()) { if ($message === null) { $message = 'No tienes permisos para acceder a esta página'; } throw HTTP_Exception::factory(403, $message); } else { throw HTTP_Exception::factory(401); } }