public function save(Http $http)
 {
     $inputs = $http->only($this->options);
     if (!$this->validate($inputs) || !$this->check($inputs)) {
         return redirect_response(panel_url('GitContent::settings'))->with('__form_data', $inputs);
     }
     update_option($this->optionName, $inputs);
     Notifier::success('Settings have been saved', true);
     return redirect_response(panel_url('GitContent::settings'));
 }
 /**
  * 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'));
     }
 }
 /**
  * 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);
 }
 /**
  * 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);
 }