public function createHandle()
 {
     $pr = DirectoryHelpers::getPagerank(e(Input::get('url')));
     $valid_domain = function ($domain_name) {
         return preg_match("/^([a-z\\d](-*[a-z\\d])*)(\\.([a-z\\d](-*[a-z\\d])*))*\$/i", $domain_name) && preg_match("/^.{1,253}\$/", $domain_name) && preg_match("/^[^\\.]{1,63}(\\.[^\\.]{1,63})*\$/", $domain_name);
         //length of each label
     };
     $format_url = rtrim(str_replace(['http://', 'https://'], '', e(Input::get('url'))), '/');
     if (!$valid_domain($format_url)) {
         Session::put('category_id', e(Input::get('category_id')));
         return Redirect::back()->with('url_error', trans('directory.invalid_url'))->withInput();
     }
     $url_details = parse_url(e(Input::get('url')));
     $final_url = isset($url_details['scheme']) ? $url_details['scheme'] . '://' . $format_url : 'http://' . $format_url;
     Input::merge(array('url' => $final_url));
     $nice_input_names = ['category_id' => trans('directory.select_category'), 'name' => trans('directory.name'), 'url' => trans('directory.url'), 'format_url' => trans('directory.url'), 'description' => trans('directory.description'), 'keywords' => trans('directory.keywords')];
     $rules = ['category_id' => 'not_in:"0"', 'name' => 'required|between:6,260', 'url' => 'required|url|between:6,100|unique:domains', 'description' => 'required|between:200,1000', 'keywords' => 'between:5,255'];
     if (!Auth::check()) {
         $nice_input_names['g-recaptcha-response'] = 'captcha';
         $rules['g-recaptcha-response'] = 'required|recaptcha';
     }
     $coma_replace = function ($string) {
         return str_replace(',', ', ', $string);
     };
     if (strlen(str_replace(' ', '', e(Input::get('description')))) < 200 && Auth::user()->type != User::ADMIN_USER) {
         $attempt = new Attempt();
         $attempt->user_id = Auth::check() ? Auth::user()->id : null;
         $attempt->category_id = (int) e(Input::get('category_id'));
         $attempt->url = 'http://' . $format_url;
         $attempt->name = e(Input::get('name'));
         $attempt->description = $coma_replace(DirectoryHelpers::correctText(e(Input::get('description')), '.'));
         $attempt->keywords = $coma_replace(e(Input::get('keywords')));
         $attempt->save();
         return Redirect::back()->with('error', 'Descrierea este prea scurt&#259;')->withInput();
     }
     $validator = Validator::make(array_map('trim', Input::all()), $rules, [], $nice_input_names);
     if ($validator->fails()) {
         Session::put('category_id', e(Input::get('category_id')));
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $status = Acl::isSuperAdmin() ? 1 : 0;
     $domain = new Domain();
     $domain->category_id = (int) e(Input::get('category_id'));
     $domain->status = $status;
     $domain->name = $coma_replace(e(Input::get('name')));
     $domain->url = 'http://' . $format_url;
     $domain->page_rank = $pr;
     $domain->description = $coma_replace(DirectoryHelpers::correctText(e(Input::get('description')), '.'));
     $domain->keywords = $coma_replace(e(Input::get('keywords')));
     try {
         $domain->thumb = DirectoryHelpers::generateThumb($domain->url);
     } catch (Exception $ex) {
         Log::error($ex->getMessage());
     }
     if ($domain->save()) {
         Acl::addAdmin($domain);
         return Redirect::route('domain.create')->with('success', trans('directory.domain_added'));
     }
     return Redirect::back()->with('error', trans('directory.domain_add_error'));
 }