public function postAdd()
 {
     $validator = Validator::make(Input::all(), Safewebsite::$rules);
     if ($validator->passes()) {
         $array = explode("\n", Input::get('url'));
         foreach ($array as $value) {
             $value = str_replace(array("\r", "\n"), "", $value);
             // in case scheme relative URI is passed, e.g., //www.google.com/
             $value = trim($value, '/');
             // If scheme not included, prepend it
             if (!preg_match('#^http(s)?://#', $value)) {
                 $value = 'http://' . $value;
             }
             $urlParts = parse_url($value);
             // remove www
             $domain = preg_replace('/^www\\./', '', $urlParts['host']);
             if (Safewebsite::where('url', '=', $domain)->count() == 0 && Blacklist::where('value', '=', $domain)->count() == 0) {
                 $Safewebsite = new Safewebsite();
                 $Safewebsite->url = str_replace(array("\r", "\n"), "", $domain);
                 $Safewebsite->save();
             }
         }
         return Redirect::action('SafewebsiteController@getIndex')->with('message', 'Website added!');
     }
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
 }
Exemplo n.º 2
0
 public function postAdd()
 {
     $validator = Validator::make(Input::all(), Blacklist::$rules);
     if ($validator->passes()) {
         if (Blacklist::where('value', '=', Input::get('value'))->count() == 0) {
             $Blacklist = new Blacklist();
             $Blacklist->value = str_replace(array("\r", "\n"), "", Input::get('value'));
             $Blacklist->save();
         }
         return Redirect::action('BlacklistController@getIndex')->with('message', 'Website added!');
     }
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
 }