/**
  * Creates a new paste item
  *
  * @return \Illuminate\Support\Facades\Redirect
  */
 public function postCreate()
 {
     // Get the site configuration
     $site = Site::config('general');
     // Define validation rules
     $validator = Validator::make(Input::all(), array('title' => 'max:30', 'data' => 'required|auth|mbmax:' . $site->maxPasteSize, 'language' => 'required|in:' . Highlighter::make()->languages(TRUE), 'expire' => 'in:' . Paste::getExpiration('create', TRUE)));
     // Generate anti-spam modules
     $antispam = Antispam::make('paste', 'data');
     // Run validations
     $resultValidation = $validator->passes();
     // Execute antispam services
     $resultAntispam = $antispam->passes();
     // Get the paste language. We use it to store a language history
     $language = Input::get('language');
     $historyLangs = Cookie::get('languages');
     // History languages must always be an array
     $historyLangs = is_array($historyLangs) ? $historyLangs : array();
     // No dulicates allowed in the history
     if (in_array($language, $historyLangs)) {
         $key = array_search($language, $historyLangs);
         unset($historyLangs[$key]);
     } else {
         if (count($historyLangs) >= 10) {
             $historyLangs = array_slice($historyLangs, 1, count($historyLangs));
         }
     }
     // Add current language to the history
     array_push($historyLangs, $language);
     $cookie = Cookie::forever('languages', $historyLangs);
     // Evaluate validation results
     if ($resultValidation and $resultAntispam) {
         // We inject the project into the input so that
         // it is also inserted into the DB accordingly
         Input::merge(array('project' => $this->project));
         // All OK! Create the paste already!!
         $paste = Paste::createNew('web', Input::all());
         // Now, save the attachment, if any (and if enabled)
         if ($site->allowAttachment and Input::hasFile('attachment')) {
             $file = Input::file('attachment');
             if ($file->isValid()) {
                 $file->move(storage_path() . '/uploads', $paste->urlkey);
             }
         }
         // Redirect to paste if there's no password
         // Otherwise, just show a link
         if ($paste->password) {
             $url = link_to("{$paste->urlkey}/{$paste->hash}");
             $message = sprintf(Lang::get('create.click_for_paste'), $url);
             Session::flash('messages.success', $message);
         } else {
             return Redirect::to(Paste::getUrl($paste))->withCookie($cookie);
         }
     } else {
         // Set the error message as flashdata
         if (!$resultValidation) {
             Session::flash('messages.error', $validator->messages()->all('<p>:message</p>'));
         } else {
             if (!$resultAntispam) {
                 Session::flash('messages.error', $antispam->message());
             }
         }
     }
     return Redirect::to(URL::previous())->withInput()->withCookie($cookie);
 }