/** * Deletes a specific post based on ID. * * @param $id * @param Http $http * * @return \Herbert\Framework\Response * * @throws HttpErrorException */ public function deletePost($id, Http $http) { $this->allowed($http->ip()); $deleted = ApiPost::query()->where('ID', $id)->delete(); if ($deleted) { return json_response(['Success']); } return response('Nothing deleted', 404); }
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')); }
/** * 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')); }
/** * 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}"); }
/** * Register the service provider. * * @return void */ public function register() { $this->registerEloquent(); $this->app->instance('env', defined('HERBERT_ENV') ? HERBERT_ENV : (defined('WP_DEBUG') ? 'local' : 'production')); $this->app->instance('http', \Herbert\Framework\Http::capture()); $this->app->alias('http', 'Herbert\\Framework\\Http'); $this->app->instance('router', $this->app->make('Herbert\\Framework\\Router', ['app' => $this->app])); $this->app->bind('route', 'Herbert\\Framework\\Route'); $this->app->instance('enqueue', $this->app->make('Herbert\\Framework\\Enqueue', ['app' => $this->app])); $this->app->alias('enqueue', 'Herbert\\Framework\\Enqueue'); $this->app->instance('panel', $this->app->make('Herbert\\Framework\\Panel', ['app' => $this->app])); $this->app->alias('panel', 'Herbert\\Framework\\Panel'); $this->app->instance('shortcode', $this->app->make('Herbert\\Framework\\Shortcode', ['app' => $this->app])); $this->app->alias('shortcode', 'Herbert\\Framework\\Shortcode'); $this->app->instance('widget', $this->app->make('Herbert\\Framework\\Widget', ['app' => $this->app])); $this->app->alias('widget', 'Herbert\\Framework\\Widget'); $this->app->instance('session', $this->app->make('Herbert\\Framework\\Session', ['app' => $this->app])); $this->app->alias('session', 'Herbert\\Framework\\Session'); $this->app->instance('notifier', $this->app->make('Herbert\\Framework\\Notifier', ['app' => $this->app])); $this->app->alias('notifier', 'Herbert\\Framework\\Notifier'); $this->app->singleton('errors', function () { return session_flashed('__validation_errors', []); }); $_GLOBALS['errors'] = $this->app['errors']; }
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]); }
/** * Parses a WordPress request. * * @param $wp * @return void */ public function parseRequest($wp) { if (!array_key_exists('herbert_route', $wp->query_vars)) { return; } $data = @json_decode($wp->query_vars['herbert_route'], true); $route = null; if (isset($data['id']) && isset($this->routes[$this->http->method()][$data['id']])) { $route = $this->routes[$this->http->method()][$data['id']]; } elseif (isset($data['name']) && isset($this->routes['named'][$data['name']])) { $route = $this->routes['named'][$data['name']]; } if (!isset($route)) { return; } if (!isset($data['parameters'])) { $data['parameters'] = []; } foreach ($data['parameters'] as $key => $val) { if (!isset($wp->query_vars['herbert_param_' . $key])) { return; } $data['parameters'][$key] = $wp->query_vars['herbert_param_' . $key]; } try { $this->processRequest($this->buildRoute($route, $data['parameters'])); } catch (HttpErrorException $e) { if ($e->getStatus() === 301 || $e->getStatus() === 302) { $this->processResponse($e->getResponse()); die; } if ($e->getStatus() === 404) { 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()); if ($e->getStatus() === 404) { @(include get_404_template()); } else { echo $e->getMessage(); } } die; }
/** * Register the service provider. * * @return void */ public function register() { $this->registerEloquent(); $this->app->instance('env', defined('HERBERT_ENV') ? HERBERT_ENV : (defined('WP_DEBUG') ? 'local' : 'production')); $this->app->instance('http', \Herbert\Framework\Http::capture()); $this->app->alias('http', 'Herbert\\Framework\\Http'); $this->app->instance('router', $this->app->make('Herbert\\Framework\\Router', ['app' => $this->app])); $this->app->bind('route', 'Herbert\\Framework\\Route'); $this->app->instance('enqueue', $this->app->make('Herbert\\Framework\\Enqueue', ['app' => $this->app])); $this->app->alias('enqueue', 'Herbert\\Framework\\Enqueue'); $this->app->instance('panel', $this->app->make('Herbert\\Framework\\Panel', ['app' => $this->app])); $this->app->alias('panel', 'Herbert\\Framework\\Panel'); $this->app->instance('shortcode', $this->app->make('Herbert\\Framework\\Shortcode', ['app' => $this->app])); $this->app->alias('shortcode', 'Herbert\\Framework\\Shortcode'); $this->app->instance('widget', $this->app->make('Herbert\\Framework\\Widget', ['app' => $this->app])); $this->app->alias('widget', 'Herbert\\Framework\\Widget'); $this->app->instance('session', $this->app->make('Herbert\\Framework\\Session', ['app' => $this->app])); $this->app->alias('session', 'Herbert\\Framework\\Session'); $this->app->instance('notifier', $this->app->make('Herbert\\Framework\\Notifier', ['app' => $this->app])); $this->app->alias('notifier', 'Herbert\\Framework\\Notifier'); }
/** * 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')); }