public function action_create() { \View::set_global('title', 'Add New Group'); if (\Input::post()) { $val = $this->validate('create'); if ($val->run()) { try { $group_id = \Sentry::group()->create(array('name' => \Input::post('title'), 'level' => 80)); \Messages::success('Group successfully created.'); \Response::redirect(\Input::post('update', false) ? \Uri::create('admin/user/group/update/' . $item->id) : \Uri::admin('current')); } catch (\Sentry\SentryGroupException $e) { // show validation errors \Messages::error('<strong>There was an error while trying to create group</strong>'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); } } else { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>There was an error while trying to create group</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } } // Keep existing messages \Messages::instance()->shutdown(); \Response::redirect('admin/user/group/list'); }
/** * Singeltone Get Instance * * @return Messages */ public static function getInstance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
public static function get_instance() { if (!isset(self::$instance)) { self::$instance = new Messages(); } return self::$instance; }
/** * Register JSON config file. * * @param $config * @param $repos * @param $type * * @return bool */ public function register($config, $repos, $type) { if (empty($config)) { return false; } if (null === ($config = json_decode($config, true))) { $error = new \WP_Error('json_invalid', 'JSON ' . json_last_error_msg()); Messages::instance()->create_error_message($error); return false; } $this->add_headers($config, $repos, $type); }
public function render($types = array('error', 'warning', 'success', 'info')) { $res = ''; if (\Messages::any()) { $res .= '<br/>'; } foreach ($types as $type) { foreach (\Messages::instance()->get($type) as $message) { $res .= '<div class="alert alert-' . $message['type'] . '">' . $message['body'] . '</div>' . "\n"; } } \Messages::reset(); return $res; }
/** * Constructor. * * @param object $type */ public function __construct($type) { parent::$hours = 12; $this->type = $type; $this->response = $this->get_transient(); if (!isset(self::$options['gitlab_access_token'])) { self::$options['gitlab_access_token'] = null; } if (!isset(self::$options['gitlab_enterprise_token'])) { self::$options['gitlab_enterprise_token'] = null; } if (empty(self::$options['gitlab_access_token']) || empty(self::$options['gitlab_enterprise_token']) && !empty($type->enterprise)) { Messages::instance()->create_error_message('gitlab'); } add_site_option('github_updater', self::$options); }
public function action_create() { \View::set_global('title', 'Add Discount Codes'); if (\Input::post()) { $val = Model_Discountcode::validate('create'); if (\Input::post('type') != 'free shipping') { $val->add('type_value', 'Amount')->add_rule('required')->add_rule('numeric')->add_rule('numeric_min', 1); } if ($val->run()) { // Get POST values $insert = \Input::post(); if (isset($insert['active_from']) && $insert['active_from']) { $insert['active_from'] = date('Y-m-d', strtotime(str_replace('/', '-', $insert['active_from']))); } if (isset($insert['active_to']) && $insert['active_to']) { $insert['active_to'] = date('Y-m-d', strtotime(str_replace('/', '-', $insert['active_to']))); } $item = Model_Discountcode::forge($insert); try { $item->save(); \Messages::success('Discount code successfully created.'); \Response::redirect(\Uri::create('admin/discountcode/update/' . $item->id)); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to create discount</strong>'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); } } else { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>There was an error while trying to create discount code</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } } // Keep existing messages \Messages::instance()->shutdown(); \Theme::instance()->set_partial('content', $this->view_dir . 'create'); }
public function action_create() { \View::set_global('title', 'Add New Attribute Option'); if (\Input::post()) { $val = Model_Attribute_Option::validate('create'); if ($val->run()) { // Get POST values $insert = \Input::post(); $insert['title'] = $insert['option_title']; $item = Model_Attribute_Option::forge($insert); try { $item->save(); \Messages::success('Attribute option successfully created.'); if (!\Request::is_hmvc()) { \Response::redirect(\Input::referrer(\Uri::create('admin/attribute/list'))); } } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to create attribute option</strong>'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); } } else { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>There was an error while trying to create attribute option</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } } // Keep existing messages \Messages::instance()->shutdown(); if (!\Request::is_hmvc()) { \Response::redirect(\Input::referrer(\Uri::create('admin/attribute/list'))); } }
/** * The basic welcome message * * @access public * @return Response */ public function action_index() { // Keep existing messages \Messages::instance()->shutdown(); \Response::redirect('admin/application/list'); }
public function action_create($group_type = false) { \View::set_global('title', 'Add New Group'); if (\Input::post()) { $val = Model_Group::validate('create'); if ($val->run()) { // Get POST values $insert = \Input::post(); $item = Model_Group::forge($insert); try { $item->save(); \Messages::success('Group successfully created.'); \Response::redirect(\Input::post('update', false) ? \Uri::create('admin/product/group/update/' . $item->id) : \Input::referrer(\Uri::admin('current'))); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to create group</strong>'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); } } else { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>There was an error while trying to create group</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } } // Keep existing messages \Messages::instance()->shutdown(); \Response::redirect('admin/product/group/list' . ($group_type ? '/' . $group_type : '')); }
/** * Call the API and return a json decoded body. * Create error messages. * * @see http://developer.github.com/v3/ * * @param string $url * * @return boolean|object */ protected function api($url) { add_filter('http_request_args', array(&$this, 'http_request_args'), 10, 2); $type = $this->return_repo_type(); $response = wp_remote_get($this->get_api_url($url)); $code = (int) wp_remote_retrieve_response_code($response); $allowed_codes = array(200, 404); if (is_wp_error($response)) { Messages::instance()->create_error_message($response); return false; } if (!in_array($code, $allowed_codes, false)) { self::$error_code = array_merge(self::$error_code, array($this->type->repo => array('repo' => $this->type->repo, 'code' => $code, 'name' => $this->type->name, 'git' => $this->type->type))); if ('github' === $type['repo']) { GitHub_API::ratelimit_reset($response, $this->type->repo); } Messages::instance()->create_error_message($type['repo']); return false; } return json_decode(wp_remote_retrieve_body($response)); }
public function action_login() { if (!(\Sentry::check() && !\Sentry::user()->is_admin())) { \View::set_global('title', 'Login'); if (\Input::post('login')) { $val = \User\Controller_Validate::forge('login'); if ($val->run()) { try { if (\Sentry::user_exists(\Input::param('identity')) && !\Sentry::user(\Input::param('identity'))->is_admin()) { // check the credentials. $valid_login = \Sentry::login(\Input::param('identity'), \Input::param('password'), true); if ($valid_login) { \Messages::success('You have logged in successfully'); // \Response::redirect(\Input::referrer(\Uri::front_create('user/account/dashboard'))); \Response::redirect(\Uri::front_create('order/checkout/cost')); } else { \Messages::error('Email and/or password is incorrect'); } } else { \Messages::error('Email and/or password is incorrect'); } } catch (\Sentry\SentryAuthException $e) { // show validation errors //\Messages::error('<h4>There was an error while trying to login</h4>'); $errors = $e->getMessage(); \Messages::error($errors); } catch (\Sentry\SentryException $e) { // show validation errors //\Messages::error('<h4>There was an error while trying to login</h4>'); $errors = $e->getMessage(); \Messages::error($errors); } } else { if ($val->error() != array()) { // show validation errors foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } } } //Keep existing messages \Messages::instance()->shutdown(); \Response::redirect(\Uri::front_create('order/checkout/address')); }
/** * The index action * * @access public * @return void */ public function action_index() { //Keep existing messages \Messages::instance()->shutdown(); \Response::redirect(\Uri::front_create('user/account/dashboard')); }
/** * Displays ALL success or failure messages */ public function showMessages() { $messages = Messages::instance(); $messages->showMessages($this); }
/** * Get all messages in HTML form * Reset messages after that * * @return array */ public static function display_front($align = 'left') { $output = ''; foreach (array('error', 'warning', 'success', 'info') as $type) { $messages = \Messages::instance()->get($type); if (!empty($messages)) { // Open message container before first message $output === '' and $output = '<div class="message_container" style="display: none;">' . "\n"; $output .= '<div class="popup" id="signUp">' . "\n"; $output .= '<div class="legend">' . "\n"; if ($type == 'error') { $type = 'Oops!'; } if ($type == 'success') { $welcome_message = 'Thanks for registering with Evan Evans. We have sent an email to your nominated address with a link to activate your account. Sometimes inboxes can be a little overprotective so you may need to check your junk or spam folders.'; $activate_message = 'You have been sent an email to activate you new password.'; $newsletter_message = 'Thanks for signing up for our newsletter!'; foreach ($messages as $message) { if ($message['body'] === $welcome_message) { $type = 'Welcome!'; } else { if ($message['body'] === $activate_message) { $type = 'Just one more step'; } else { if ($message['body'] === $newsletter_message) { $type = 'We`ll be in touch'; } } } } } $output .= '<h2>' . ucfirst($type) . '</h2>' . "\n"; $output .= '</div>' . "\n"; $output .= '<div class="container_12">' . "\n"; $output .= '<div class="grid_12">' . "\n"; foreach ($messages as $message) { $output .= "\t\t" . '' . $message['body'] . '<br />' . "\n"; } $output .= '</div>' . "\n"; $output .= '</div>' . "\n"; $output .= '<div class="clear"></div>' . "\n"; $output .= '</div>' . "\n"; } } \Messages::reset(); // Close message container after last message $output !== '' and $output .= '</div>' . "\n"; return $output; }
<?php if (\Messages::any()) { ?> <br/> <?php foreach (array('success', 'info', 'warning', 'error') as $type) { ?> <?php $class = $type == 'error' ? 'danger' : $type; ?> <?php foreach (\Messages::instance()->get($type) as $message) { ?> <div class="alert alert-<?php echo $class; ?> "><?php echo $message['body']; ?> </div> <?php } ?> <?php } ?> <?php \Messages::reset(); }
/** * Change user password * * @param unknown_type $email * @param unknown_type $hash */ public function action_reset_password($email = false, $hash = false) { if ($email && $hash) { //Keep existing messages \Messages::instance()->shutdown(); try { if (\Sentry::reset_password_confirm($email, $hash)) { if (\Input::post('new_password') && \Input::post('confirm_new_password')) { if (\Sentry::reset_password_save($email, \Input::post('new_password'))) { \Messages::success('Password successfully changed. Please login and start using your account.'); \Response::redirect(\Uri::front_create('user/login')); } else { \Messages::error('Password was not save.'); \Theme::instance()->set_partial('content', $this->view_dir . 'reset_password'); } } else { \Theme::instance()->set_partial('content', $this->view_dir . 'reset_password'); } } else { \Messages::error('Wrong reset code. Please check your email and try again.'); \Response::redirect(\Uri::front_create('user/login')); } } catch (\Sentry\SentryException $e) { // show validation errors //\Messages::error('<h4>There was an error while trying activate user</h4>'); $errors = $e->getMessage(); \Messages::error($errors); } } }
/** * Return the AWS download link for a GitHub release asset. * * @since 6.1.0 * @uses Requests, requires WP 4.6 * * @return array|bool|object|\stdClass */ private function get_github_release_asset_url() { $response = isset($this->response['release_asset_url']) ? $this->response['release_asset_url'] : false; if ($this->exit_no_update($response)) { return false; } if (!$response) { $response = $this->api('/repos/:owner/:repo/releases/latest'); if (!$response) { $response = new \stdClass(); $response->message = 'No release asset found'; } if ($response) { add_filter('http_request_args', array(&$this, 'set_github_release_asset_header')); $url = $this->add_access_token_endpoint($this, $response->assets[0]->url); $response_new = wp_remote_get($url); remove_filter('http_request_args', array(&$this, 'set_github_release_asset_header')); if (is_wp_error($response_new)) { Messages::instance()->create_error_message($response_new); return false; } if ($response_new['http_response'] instanceof \WP_HTTP_Requests_Response) { $response_object = $response_new['http_response']->get_response_object(); $response_headers = $response_object->history[0]->headers; $download_link = $response_headers->getValues('location'); } else { return false; } $response = array(); $response = $download_link[0]; $this->set_transient('release_asset_url', $response); } } if ($this->validate_response($response)) { return false; } return $response; }