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();
     }
 }
 public function postIndex()
 {
     $validator = Validator::make(Input::all(), Javascript::$rules);
     if ($validator->passes()) {
         $blackwords_array = array();
         foreach (Blackword::all() as $black) {
             $blackwords_array[] = $black->value;
         }
         $blackwords = implode(",", $blackwords_array);
         $blackwords = '"' . $blackwords . '"';
         $porn_websites = json_encode(Blacklist::select('value')->get());
         $safewebsites = json_encode(Safewebsite::select('url', 'topcode', 'leftcode', 'sidecode')->get());
         $safe_accounts = Adsense::where('active', '=', true)->where('safe', '=', true)->get()->toJson();
         $usafe_accounts = Adsense::where('active', '=', true)->where('safe', '=', false)->get()->toJson();
         $jquery = file_get_contents('files/jquery.js', 'r');
         $content = Input::get('javascript');
         $content = str_replace("!porn_websites", $porn_websites, $content);
         $content = str_replace("!blackwords", $blackwords, $content);
         $content = str_replace("!safewebsites", $safewebsites, $content);
         $content = str_replace("!safe_accounts", $safe_accounts, $content);
         $content = str_replace("!unsafe_accounts", $usafe_accounts, $content);
         $minifiedCode = \JShrink\Minifier::minify($content);
         $result = $jquery . $minifiedCode;
         file_put_contents("files/app.js", $result);
         $Javascript = Javascript::find(1);
         $Javascript->code_version = date("Y-m-d H:i:s");
         $Javascript->save();
         return Redirect::action('JavascriptController@getIndex')->with('message', 'Javascript file updated!');
     }
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
 }
 public function getDelete($id)
 {
     $Blacklist = Blacklist::find($id);
     $Blacklist->delete();
     return Redirect::action('BlacklistController@getIndex')->with('message', 'Deleted!');
 }