/** * 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')); } }
public function saveConfig(Http $http) { $do_next_fields = false; if (get_option('instant_articles_app_id')) { $do_next_fields = true; } foreach ($this->fields as $field) { update_option($field['name'], $http->get($field['name'])); } if ($do_next_fields) { $this->decode_facebook_page_data($http->get('instant_articles_page')); } $redirect = $_SERVER['HTTP_REFERER']; header("location: {$redirect}"); }
/** * Returns a list of posts. * * @param Http $http * * @return \Herbert\Framework\Response * * @throws HttpErrorException */ public function posts(Http $http) { $this->allowed($http->ip()); $page = $http->get('page', 1); $posts = ApiPost::query()->forPage($page, self::$perPage)->get(); return json_response($posts); }
/** * Delete an IP address. * * @param Http $http * * @return \Herbert\Framework\Response * * @throws HttpErrorException */ public function delete(Http $http) { try { $address = Access::findOrFail($http->get('id')); } catch (ModelNotFoundException $e) { throw new HttpErrorException(404, "It looks like that address doesn't exist."); } $address->delete(); return redirect_response(panel_url('ApiPosts::mainPanel')); }
public function editAuthor(Http $http) { $author = new Author(); $id = $http->get('formEditAuthors')['id']; $author = $this->entityManager->getRepository('HerbertExtraDemo\\Models\\Entity\\Author')->find($id); $form = $this->formFactory->create(new AuthorForm(), $author); $form->handleRequest(); if ($form->isValid()) { $em = $this->entityManager; $em->persist($author); $em->flush(); $msg = "Mise à jour effectuées"; } else { $msg = "Formulaire invalide ! "; } return view('@HerbertExtraDemo/authors/form.twig', ['author' => $author, 'form' => $form->createView(), 'msg' => $msg]); }
/** * 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; }
/** * 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); }
/** * Destroys a share. * * @param \Herbert\Framework\Http $http * * @return \Herbert\Framework\RedirectResponse */ public function postDestroy(Http $http) { $share = $this->getShare($http->get('set')); $share->delete(); return redirect_response(panel_url('Socializr::index')); }