public function action_create()
 {
     $url = Input::Get('url');
     $custom = Input::Get('custom');
     $api = Input::Get('api_key');
     if (empty($api) === true) {
         $api = true;
     }
     if (empty($url) === false) {
         // Check to see if its a valid url
         if (filter_var($url, FILTER_VALIDATE_URL) === false) {
             echo 'You did not enter a valid url in, please try again';
             die;
         }
         // Check black list!
         $blocked = Model_Blacklist::query()->get();
         if (empty($blocked) === false) {
             foreach ($blocked as $block) {
                 // Check aginst the blocked
                 if (preg_match('/' . strtolower($block['blocked']) . '/', strtolower($url))) {
                     echo 'URL Blacklisted';
                     die;
                 }
             }
         }
         // Lets generate them a url
         $safe = \Settings::Get('google_safe_api_key');
         // Is it safe?
         if (empty($safe) === false) {
             $m_url = 'https://sb-ssl.google.com/safebrowsing/api/lookup?client=api&apikey=' . $safe . '&appver=1.0&pver=3.0&url=' . $url;
             $curl_handle = curl_init();
             curl_setopt($curl_handle, CURLOPT_URL, $m_url);
             curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
             curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
             $buffer = curl_exec($curl_handle);
             curl_close($curl_handle);
             if (empty($buffer) === false) {
                 echo 'This website has been blocked because of ' . $buffer;
                 die;
             }
         }
         $length = strlen($url);
         $data['short_url_raw'] = Controller_Url::shortenit($url, $custom, $api);
         $data['url'] = $url;
         $data['short_url'] = $data['short_url_raw']['short_url'];
         echo \Uri::Create($data['short_url']);
         die;
     } else {
         echo 'Error';
         die;
     }
 }
 public function action_create()
 {
     if (\Settings::Get('signup_and_approve') === true) {
         if (!Auth::member(4)) {
             if (Input::is_ajax() === true) {
                 echo $data['error'];
                 die;
             }
             Session::Set('error', 'You are not authroized to use this application, please contact the admin');
             Response::Redirect(Uri::Base());
         }
     }
     if (Input::Method() == 'POST') {
         $url = Input::POST('url');
         $custom = Input::POST('custom-url');
         if (empty($url) === false) {
             // Check to see if its a valid url
             if (filter_var($url, FILTER_VALIDATE_URL) === false) {
                 if (Input::is_ajax() === true) {
                     echo 'This is not a valid URL please edit your URL';
                     die;
                 }
                 Session::Set('error', 'This is not a valid URL please edit your URL');
                 Response::Redirect(Uri::Base());
             }
             // Check black list!
             $blocked = Model_Blacklist::query()->get();
             if (empty($blocked) === false) {
                 foreach ($blocked as $block) {
                     // Check aginst the blocked
                     if (preg_match('/' . strtolower($block->expression) . '/', strtolower($url))) {
                         if (Input::is_ajax() === true) {
                             echo 'URL is blacklisted!';
                             die;
                         }
                         Session::Set('error', 'URL is blacklisted!');
                         Response::Redirect(Uri::Base());
                     }
                 }
             }
             // Lets generate them a url
             $safe = \Settings::Get('google_safe_api_key');
             // Is it safe?
             if (empty($safe) === false) {
                 $m_url = 'https://sb-ssl.google.com/safebrowsing/api/lookup?client=api&apikey=' . $safe . '&appver=1.0&pver=3.0&url=' . $url;
                 $curl_handle = curl_init();
                 curl_setopt($curl_handle, CURLOPT_URL, $m_url);
                 curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
                 curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
                 $buffer = curl_exec($curl_handle);
                 curl_close($curl_handle);
                 if (empty($buffer) === false) {
                     if (Input::is_ajax() === true) {
                         echo 'This website has been blocked because of ' . $buffer;
                         die;
                     }
                     Session::Set('error', 'This website has been blocked because of ' . $buffer);
                     Response::Redirect(Uri::Base());
                 }
             }
             $length = strlen($url);
             $new_url_object = Controller_Url::shortenit($url, $custom);
             $data['short_url'] = $new_url_object->short_url;
             $data['url_object'] = $new_url_object;
             if (Input::is_ajax() === true) {
                 $base_url = Settings::get('different_short_url');
                 if (empty($base_url) === true) {
                     echo Uri::Create($data['short_url']);
                 } else {
                     echo $base_url . '/' . $data['short_url'];
                 }
                 die;
             }
         } else {
             if (Input::is_ajax() === true) {
                 echo 'Error';
                 die;
             }
             Response::Redirect(Uri::Base());
         }
     } else {
         if (Input::is_ajax() === true) {
             echo 'Error';
             die;
         }
         Response::Redirect(Uri::Base());
     }
     $this->template->content = View::Forge('url/created', $data);
 }