/** * Flash the old input to the session and return the Redirect instance. * * Once the input has been flashed, it can be retrieved via the Input::old method. * * <code> * // Redirect and flash all of the input data to the session * return Redirect::to('login')->with_input(); * * // Redirect and flash only a few of the input items * return Redirect::to('login')->with_input('only', array('email', 'username')); * * // Redirect and flash all but a few of the input items * return Redirect::to('login')->with_input('except', array('password', 'ssn')); * </code> * * @param string $filter * @param array $items * @return Redirect */ public function with_input($filter = null, $items = array()) { Input::flash($filter, $items); return $this; }
public function post_edit($user_id) { $avatar = ''; if (\Laravel\Input::has_file('avatar')) { $img = \Laravel\Input::file('avatar'); if ($img['size'] > 100000) { return Redirect::to('administration/users/edit/' . $user_id)->with_input()->with('notice-error', __('tinyissue.file_sizes_errors')); } $arr_size = getimagesize($img['tmp_name']); if ($arr_size[0] > 200 && $arr_size[1] > 200) { return Redirect::to('administration/users/edit/' . $user_id)->with_input()->with('notice-error', __('tinyissue.file_size_errors')); } $destination = "../uploads/avatar/"; $extensions = array('image/png', 'image/jpg', 'image/jpeg'); if (in_array($img['type'], $extensions)) { $name = md5($img['name'] . rand(11111, 99999)) . "." . $this->extensions($img['type']); \Laravel\Input::upload('avatar', $destination, $name); $avatar = 'uploads/avatar/' . $name; } else { return Redirect::to('administration/users/edit/' . $user_id)->with_input()->with('notice-error', __('tinyissue.file_type_errors')); } } $update = User::update_user(Input::all(), $user_id, $avatar); if (!$update['success']) { return Redirect::to('administration/users/edit/' . $user_id)->with_input()->with_errors($update['errors'])->with('notice-error', __('tinyissue.we_have_some_errors')); } return Redirect::to('administration/users')->with('notice', __('tinyissue.user_updated')); }
public static function sessioninit() { // See if we have passed in a access_token and an account id. if (Input::get('access_token') && Input::get('account_id')) { $access_token = Input::get('access_token'); $account_id = Input::get('account_id'); } else { // See if we have a session. If Not do something about it. if (!Session::get('AccountId') || !Session::get('AccessToken')) { die(header('location: ' . Config::get('site.login_url'))); } $access_token = Session::get('AccessToken'); $account_id = Session::get('AccountId'); } // Is this a multi tenant setup? If so set the account. if (Config::get('cloudmanic.account')) { if (!(self::$account = \Accounts::get_by_id($account_id))) { $data = array('status' => 0, 'errors' => array()); $data['errors'][] = 'Account not found.'; return \Laravel\Response::json($data); } } // Validate the access_token if (!($user = Users::get_by_access_token($access_token))) { $data = array('status' => 0, 'errors' => array()); $data['errors'][] = 'Access token not valid.'; return \Laravel\Response::json($data); } else { self::_do_user($user); } }
public function post_new() { $image = 'uploads/project/projectDefault.png'; if (\Laravel\Input::has_file('image')) { $img = \Laravel\Input::file('image'); if ($img['size'] > 100000) { return Redirect::to('projects/new')->with_input()->with('notice-error', __('tinyissue.file_sizes_errors')); } $arr_size = getimagesize($img['tmp_name']); if ($arr_size[0] > 200 && $arr_size[1] > 200) { return Redirect::to('projects/new')->with_input()->with('notice-error', __('tinyissue.file_size_errors')); } $destination = "../uploads/project/"; $extensions = array('image/png', 'image/jpg', 'image/jpeg'); if (in_array($img['type'], $extensions)) { $name = md5($img['name'] . rand(11111, 99999)) . "." . $this->extensions($img['type']); \Laravel\Input::upload('image', $destination, $name); $image = 'uploads/project/' . $name; } else { return Redirect::to('projects/new')->with_input()->with('notice-error', __('tinyissue.file_type_errors')); } } $create = Project::create_project(Input::all(), $image); if ($create['success']) { return Redirect::to($create['project']->to()); } return Redirect::to('projects/new')->with_errors($create['errors'])->with('notice-error', __('tinyissue.we_have_some_errors')); }
/** * Generate an html link with a query string * * @param array $file * @return string */ public static function link($file = array()) { if (!is_array($file['location'])) { $querystring = array('location' => $file['location'], 'name' => $file['name'], 'translate' => \Laravel\Input::get('translate')); $text = $file['name']; } else { $querystring = array('location' => $file['location']['location'], 'name' => $file['name'], 'translate' => \Laravel\Input::get('translate')); $text = $file['location']['location'] . '/' . $file['name']; } $querystring = http_build_query($querystring); return \Laravel\HTML::link('language-builder/edit?' . $querystring, $text); }
public static function parameters_check($rules = null) { $request = \Laravel\Input::all(); if (is_array($rules)) { $validation = Validator::make($request, $rules); if ($validation->fails()) { $error = $validation->errors->first(); return $error; } else { return $request; } } else { return $request; } }
/** * "Forward" the request * * This driver is great for a single server install, * and when debugging your application. * * @param string $method GET, POST, PUT, DELETE, etc. * @param array $segments for example array('account', 'all') * @param array $data the post / put data */ public static function request($method, $segments, $data = array()) { $method = strtoupper($method); if (in_array($method, array('GET', 'POST', 'PUT', 'DELETE'))) { Input::replace($data); } $config = static::config(); $_SERVER['PHP_AUTH_USER'] = $config['username']; $_SERVER['PHP_AUTH_PW'] = $config['password']; list($url, $uri, $query_string) = static::url($segments, $data); $prefix = Config::get('layla.domain.url_prefix'); if (!is_null($prefix)) { $prefix .= '/'; } $response = Route::forward($method, $prefix . $uri); $code = $response->foundation->getStatusCode(); $body = $response->content; return new Response($code, json_decode($body)); }
/** * Get the proper error message for an attribute and size rule. * * @param string $bundle * @param string $attribute * @param string $rule * @return string */ protected function size_message($bundle, $attribute, $rule) { // There are three different types of size validations. The attribute // may be either a number, file, or a string. If the attribute has a // numeric rule attached to it, we can assume it is a number. If the // attribute is in the file array, it is a file, otherwise we can // assume the attribute is simply a string. if ($this->has_rule($attribute, $this->numeric_rules)) { $line = 'numeric'; } elseif (array_key_exists($attribute, Input::file())) { $line = 'file'; } else { $line = 'string'; } return Lang::line("{$bundle}validation.{$rule}.{$line}")->get($this->language); }
/** * Get the proper error message for an attribute and size rule. * * @param string $bundle * @param string $attribute * @param string $rule * @return string */ protected function size_message($bundle, $attribute, $rule) { // There are three different types of size validations. The attribute // may be either a number, file, or a string, so we'll check a few // things to figure out which one it is. if ($this->has_rule($attribute, $this->numeric_rules)) { $line = 'numeric'; } elseif (array_key_exists($attribute, Input::file())) { $line = 'file'; } else { $line = 'string'; } return Lang::line("{$bundle}validation.{$rule}.{$line}")->get($this->language); }
public static function sort_link($url, $sort_by, $name) { return HTML::link($url . '?' . http_build_query(array_merge(Input::all(), array('sort_by' => $sort_by, 'order' => Input::get('sort_by') == $sort_by ? Input::get('order') == 'ASC' ? 'DESC' : 'ASC' : 'ASC'))), $name); }
protected function size_message($bundle, $attribute, $rule) { if ($this->has_rule($attribute, $this->numeric_rules)) { $line = 'numeric'; } elseif (array_key_exists($attribute, Input::file())) { $line = 'file'; } else { $line = 'string'; } return Lang::line("{$bundle}validation.{$rule}.{$line}")->get($this->language); }
public function post_deletestep() { $input = Input::get(); Log::write('User', 'Delete Step ID ' . Step::find($input['id'])->step . ' by ' . Auth::user()->username); Step::find($input['id'])->delete(); Step::where('parentid', '=', $input['id'])->delete(); return Menu::flowtree($input['flowid']); }
/** * Use to populate a form field. Loads the field's value from * flashed input data, if that's not present it loads the value * * <code> * // Get the "email" item from the form's field data array * $email = ExampleForm::get( 'email' ); * * // Return a default value if the specified item doesn't exist * $email = ExampleForm::get( 'email', 'not listed' ); * </code> * * @param string $key * @param mixed $default * @return mixed */ public static function populate($field_name, $default = null) { // prevent need to manually load input when populating forms if (empty(static::$field_data)) { static::unserialize_from_session(); } // return input flash data, fallback on persistent for data, fallback on default return Input::old($field_name, static::get($field_name, $default)); }
private function _validate_request($type) { // A hook before we go any further. if (method_exists($this, '_before_validation')) { $this->_before_validation(); } // Set rules. if ($type == 'create') { $rules = $this->rules_create; } else { $rules = $this->rules_update; } // If we have rules we validate. if (is_array($rules) && count($rules > 0)) { // Time to validate. $validation = Validator::make(Input::get(), $rules, $this->rules_message); if ($validation->fails()) { if (Input::get('redirect_fail')) { return Redirect::to(Input::get('redirect_fail'))->with_errors($validation)->with('data', Input::get()); } else { return $this->api_response(null, 0, $validation->errors->messages); } } } return false; }
/** * Determine if the request has been forged. * * The session CSRF token will be compared to the CSRF token in the request input. * * @return bool */ public static function forged() { return Input::get(Session::csrf_token) !== Session::token(); }
public function validate_test_db_connection() { $this->adm_lang = Session::get('adm_lang'); $this->messages['test_db_connection'] = __('install::lang.Unable to connect to database')->get($this->adm_lang); return Installer::test_db_connection(Input::all()); }
/** * Return the request CSRF token * * It can come from the request input or the HTTP_X_CSRF_TOKEN header * * @return string */ public static function csrf_token() { return isset($_SERVER['HTTP_X_CSRF_TOKEN']) ? $_SERVER['HTTP_X_CSRF_TOKEN'] : Input::get(Session::csrf_token); }
/** * Get the proper error message for an attribute and rule. * * @param string $attribute * @param string $rule * @return string */ protected function message($attribute, $rule) { // First we'll check for developer specified, attribute specific messages. // These messages take first priority. They allow the fine-grained tuning // of error messages for each rule. if (array_key_exists($attribute . '_' . $rule, $this->messages)) { return $this->messages[$attribute . '_' . $rule]; } elseif (array_key_exists($rule, $this->messages)) { return $this->messages[$rule]; } elseif (in_array($rule, $this->size_rules)) { if ($this->has_rule($attribute, $this->numeric_rules)) { $line = 'numeric'; } else { $line = array_key_exists($attribute, Input::file()) ? 'file' : 'string'; } return Lang::line("validation.{$rule}.{$line}")->get($this->language); } else { return Lang::line("validation.{$rule}")->get($this->language); } }
/** * Determine if the request has been forged. * * The session CSRF token will be compared to the CSRF token in the request input. * * @return bool */ public static function forged() { return Input::get(Session::csrf_token) !== IoC::core('session')->token(); }
}); Route::get('case-studies/categories/(:any)', function ($category) { $category = Category::where('slug', '=', $category)->first(); $organisation = Organisation::find(1); $latest_posts = $organisation->posts()->order_by('created_at', 'desc')->where('visibility', '=', '1')->take(5)->get(); $categories = $organisation->categories()->where('visibility', '=', '1')->order_by('title')->get(); $posts = $category->posts()->where('visibility', '=', '1')->order_by('created_at', 'desc')->paginate(20); $galleries = $organisation->galleries()->order_by('sort_order', 'asc')->get(); return View::make('pages.blog.blog')->with('posts', $posts)->with('categories', $categories)->with('category', $category)->with('latest_posts', $latest_posts)->with('galleries', $galleries); }); Route::get('/faqs', function () { $organisation = Organisation::find(1); // Get all FAQ data $faqs = $organisation->faqs()->order_by('sort_order', 'asc')->get(); // Get search term data $search = \Laravel\Input::get('search', ''); // Load FAQ data if (!empty($search)) { $search_faqs = $organisation->faqs()->where(function ($query) use($search) { $query->where('answer', 'LIKE', '%' . $search . '%')->or_where('question', 'LIKE', '%' . $search . '%'); })->order_by('sort_order', 'asc')->get(); } return View::make('pages.faqs')->with('faqs', $faqs)->with('search', $search)->with('search_faqs', $search_faqs); }); Route::get('/galleries/(:any)', function ($gallery) { $gallery = Gallery::where('slug', '=', $gallery)->first(); $organisation = Organisation::find(1); $images = $gallery->images; $galleries = $organisation->galleries()->order_by('sort_order', 'asc')->get(); return View::make('pages.gallery')->with('images', $images)->with('gallery', $gallery)->with('galleries', $galleries); });
public static function input($name) { $tags = explode(',', Input::get($name)); $tags = array_map('trim', $tags); return Tag::prep($tags); }
public function get_my_quotes_load($quote_id) { // If the user clicks the link in the email then this code is used to bypass the login process $code = \Laravel\Input::get('c', null); // Does quote exist $quote = $quote = Quotation::find($quote_id); if (is_null($quote)) { return Redirect::to_action('quotations/sign_in')->with('success', 'Quote could not be found!'); } // Check if quote belongs to the logged in user // If code is present skip login user checks and authenticate with code if (is_null($code)) { $customer_id = \Laravel\Session::get('quote_account_id'); $customer = Customer::find($customer_id); if (is_null($customer) && $customer->id != $quote->id) { return Redirect::to_action('quotations/sign_in')->with('success', 'Quote could not be found!'); } } else { if ($quote->quick_access_code != $code) { return Redirect::to_action('quotations/sign_in')->with('success', 'Quote could not be found!'); } } // Load quote into session data self::loadQuote($quote); return Redirect::to_action('quotations/view', array('id' => $quote->quotation_layouts_id))->with('success', 'Successfully loaded quotation #' . $quote->id . ', please progress to view or edit your quotation.'); }
public function post_edit() { /* Delete the project */ if (Input::get('delete')) { Project::delete_project(Project::current()); return Redirect::to('projects')->with('notice', __('tinyissue.project_has_been_deleted')); } $image = ''; if (\Laravel\Input::has_file('image')) { $img = \Laravel\Input::file('image'); if ($img['size'] > 100000) { return Redirect::to(Project::current()->to('edit'))->with_input()->with('notice-error', __('tinyissue.file_sizes_errors')); } $arr_size = getimagesize($img['tmp_name']); if ($arr_size[0] > 200 && $arr_size[1] > 200) { return Redirect::to(Project::current()->to('edit'))->with_input()->with('notice-error', __('tinyissue.file_size_errors')); } $destination = "../uploads/project/"; $extensions = array('image/png', 'image/jpg', 'image/jpeg'); if (in_array($img['type'], $extensions)) { $name = md5($img['name'] . rand(11111, 99999)) . "." . $this->extensions($img['type']); \Laravel\Input::upload('image', $destination, $name); $image = 'uploads/project/' . $name; } else { return Redirect::to(Project::current()->to('edit'))->with_input()->with('notice-error', __('tinyissue.file_type_errors')); } } /* Update the project */ $update = Project::update_project(Input::all(), Project::current(), $image); if ($update['success']) { return Redirect::to(Project::current()->to('edit'))->with('notice', __('tinyissue.project_has_been_updated')); } return Redirect::to(Project::current()->to('edit'))->with_errors($update['errors'])->with('notice-error', __('tinyissue.we_have_some_errors')); }