protected function check($inputs)
 {
     $response = (new Github())->checkSettings($inputs);
     if ($response === true) {
         return true;
     }
     Notifier::error('Your setting aren\'t working, reason: ' . $response, true);
     return false;
 }
 /**
  * Stores the share.
  *
  * @param \Herbert\Framework\Http $http
  *
  * @return \Herbert\Framework\RedirectResponse
  */
 public function store(Http $http)
 {
     $input = ['title' => $http->get('title'), 'slug' => $http->get('slug'), 'url' => $http->get('url')];
     $rules = $this->repository->rules();
     $validator = new Validator($input, $rules);
     $validator->validate($redirect = panel_url('Socializr::shares'));
     if ($this->repository->create($input)) {
         Notifier::success('Your <strong>sharing link</strong> has been created', true);
         return new RedirectResponse(panel_url('Socializr::index'));
     }
 }
 /**
  * Validates the form.
  *
  * @param string $url
  *
  * @return bool
  */
 public function validate($url)
 {
     if ($this->dirty) {
         $this->gatherErrors();
     }
     if ($url === null || ($valid = $this->isValid())) {
         return $valid;
     }
     Notifier::error('There were errors validating your input.', true);
     throw new HttpErrorException(302, redirect_response($url)->with('__validation_errors', $this->errors)->with('__form_data', $this->data));
 }
 public function missing_settings()
 {
     $ns = Helper::get('agreable_namespace');
     $screen = get_current_screen();
     $app_id = get_field("{$ns}_plugin_firebase_api_key", 'options');
     if (empty($app_id)) {
         $options = get_admin_url(null, '/admin.php?page=acf-options#acf-options_group_agreable_venues');
         $missing = empty($app_id) ? "'Firebase API Key'" : '';
         Notifier::error("Your are missing options that will cause Venues to not display correctly ({$missing}). Please visit <a href='{$options}'>Options</a> page and contact the digital operations team if necessary.");
         return;
     }
 }
 /**
  * Updates a share.
  *
  * @param \Herbert\Framework\Http $http
  *
  * @return \Herbert\Framework\RedirectResponse
  */
 public function update(Http $http)
 {
     $share = $this->getShare($http->get('set'));
     $input = ['title' => $http->get('title'), 'slug' => $http->get('slug'), 'url' => $http->get('url')];
     $rules = $this->repository->rules();
     $validator = new Validator($input, $rules);
     $validator->validate($redirect = panel_url('Socializr::shares'));
     if ($this->repository->modify($share->id, $input)) {
         Notifier::success('Your <strong>sharing link</strong> has been updated', true);
         return new RedirectResponse(panel_url('Socializr::index'));
     }
     return redirect_response(panel_url('Socializr::shares', ['action' => 'edit', 'share' => $share->id]));
 }
 /**
  * Stores the set.
  *
  * @param \Herbert\Framework\Http $http
  *
  * @return \Herbert\Framework\RedirectResponse
  */
 public function store(Http $http)
 {
     /*
      * 1. Collect all http data
      * 2. Validate
      * 3. Pass off to Repo
      */
     $input = ['title' => $http->get('title'), 'type' => $http->get('type'), 'slug' => $http->get('slug')];
     if ($http->get('type') === 'SHARE') {
         $input['shares'] = $http->get('shares');
     } else {
         $input['profile'] = $http->get('profile');
     }
     $rules = $this->repository->rules($input['type']);
     $validator = new Validator($input, $rules);
     $validator->validate($redirect = panel_url('Socializr::sets'));
     if ($this->repository->create($input)) {
         Notifier::success('Your Set has been created', true);
         return new RedirectResponse(panel_url('Socializr::index'));
     }
     Notifier::error('Something went wrong there, please try again', true);
     return (new RedirectResponse(panel_url('Socializr::sets')))->with('__form_data', $input);
 }
 /**
  * Notifies the user of mismatched plugins.
  *
  * @return void
  */
 protected function notifyMismatched()
 {
     $matched = array_map(function ($value) {
         return basename($value);
     }, $this->matched);
     $mismatched = array_map(function ($value) {
         return basename($value);
     }, $this->mismatched);
     $message = 'Unfortunately plugin(s) ' . implode(', ', $mismatched) . ' can’t work with the following plugin(s) ' . implode(', ', $matched) . '. Please disable and try updating all of the above plugins before reactivating.';
     Notifier::error($message);
 }
 /**
  * Return the correct callable based on action
  *
  * @param  array   $panel
  * @param  boolean $strict
  * @return void
  */
 protected function handler($panel, $strict = false)
 {
     $callable = $uses = $panel['uses'];
     $method = strtolower($this->http->method());
     $action = strtolower($this->http->get('action', 'uses'));
     $callable = array_get($panel, $method, false) ?: $callable;
     if ($callable === $uses || is_array($callable)) {
         $callable = array_get($panel, $action, false) ?: $callable;
     }
     if ($callable === $uses || is_array($callable)) {
         $callable = array_get($panel, "{$method}.{$action}", false) ?: $callable;
     }
     if (is_array($callable)) {
         $callable = $uses;
     }
     if ($strict && $uses === $callable) {
         return false;
     }
     try {
         $this->call($callable);
     } catch (HttpErrorException $e) {
         if ($e->getStatus() === 301 || $e->getStatus() === 302) {
             $this->call(function () use(&$e) {
                 return $e->getResponse();
             });
         }
         global $wp_query;
         $wp_query->set_404();
         status_header($e->getStatus());
         define('HERBERT_HTTP_ERROR_CODE', $e->getStatus());
         define('HERBERT_HTTP_ERROR_MESSAGE', $e->getMessage());
         Notifier::error('<strong>' . $e->getStatus() . '</strong>: ' . $e->getMessage());
         do_action('admin_notices');
     }
     return true;
 }
 public function add_firebase_token()
 {
     if (session_status() == PHP_SESSION_NONE) {
         session_start();
     }
     // If exists and session is not active.
     if (isset($_SESSION['firebase_token'])) {
         $token_obj = unserialize($_SESSION['firebase_token']);
         $ttl = $token_obj['ttl'];
         if (time() < $ttl) {
             // echo "<script> var firebase_JWT = '{$token_obj['token']}'; </script>";
             $this->renderFirebaseToken($token_obj['token']);
             return;
         }
     }
     if (get_post_type() !== 'poll') {
         return;
     }
     $secret = get_field('agreable_poll_plugin_settings_firebase_secret', 'options');
     $user = get_field('agreable_poll_plugin_settings_senti_user_id', 'options');
     if (empty($secret) || empty($user)) {
         $missing = empty($secret) ? "'Firebase secret'" : '';
         $missing .= empty($secret) === true && empty($user) === true ? ' and ' : '';
         $missing .= empty($user) ? "'Senti User ID'" : '';
         Notifier::warning("Your are missing settings, which will cause Polls to not function correctly ({$missing}). Please contact the development/digital team.");
         return;
     }
     // include_once "FirebaseToken.php";
     $token_generator = new TokenGenerator($secret);
     $token = $token_generator->setData(array("uid" => $user))->create();
     $_SESSION['firebase_token'] = serialize(array('ttl' => time() + 60 * 60 * 24, 'token' => $token));
     $this->renderFirebaseToken($token);
 }
Ejemplo n.º 10
0
 /**
  * Looks through cart items and checks the posts are not trashed or deleted.
  *
  * @return bool|Notifier
  */
 public function checkCartItemValidity()
 {
     $return = true;
     foreach ($this->getCart() as $cart_item_key => $cartitem) {
         $product = $cartitem->get('product');
         if (!$product || !$product->exists() || 'trash' === $product->getStatus()) {
             $this->setQuantity($cart_item_key, 0);
             $return = Notifier::notify('An item which is no longer available was removed from your cart.');
         }
     }
     return $return;
 }
 /**
  * Handles the save of metabox values.
  *
  * @param $postID
  *
  * @return mixed
  */
 public function save($postID)
 {
     $validator = new Validator();
     $github = new Github();
     $http = herbert('http');
     if (!$validator->validateSave($this->nonce, $this->name, $postID)) {
         return $postID;
     }
     $file = trim($http->get('gitcontent_file'));
     if (strlen($file) == 0) {
         Notifier::success('Git Content: Disabled', true);
         update_post_meta($postID, $this->metaKey, '');
         return;
     }
     $inputs = get_option((new AdminController())->optionName);
     $response = $github->checkFile($inputs, $file);
     $markdownFile = Helper::storagePath($postID);
     if ($response === false) {
         Notifier::error('Git Content: Something went wrong, check the name of your file.', true);
         return;
     }
     if ($github->downloadFile($inputs, $response, $markdownFile) === false) {
         Notifier::error('Git Content: Something went wrong, couldn\'t download file', true);
         return;
     }
     /**
      * Should really be using wp_insert_post_data filter
      * but it fires to early, requires double update.
      * Will update later. See app/filters.php
      **/
     remove_action('save_post', [$this, 'save']);
     wp_update_post(['ID' => $postID, 'post_content' => (new ParsedownExtra())->text(file_get_contents($markdownFile))], false);
     add_action('save_post', [$this, 'save']);
     /**
      * End
      **/
     Notifier::success('Git Content: Success using ' . $file, true);
     update_post_meta($postID, $this->metaKey, $file);
 }