Example #1
0
 public function store()
 {
     $validator = Validator::make(Input::all(), ['paste' => 'required']);
     if ($validator->fails()) {
         return Redirect::route('create')->withErrors($validator);
     }
     try {
         $paste = Paste::create(['paste' => Input::get('paste'), 'fork_of' => Input::get('fork', null)]);
     } catch (Exception $e) {
         return Redirect::route('create')->withErrors($e->getMessage());
     }
     return Redirect::route('show', Math::to_base($paste->id));
 }
Example #2
0
 function generateBase62IDs()
 {
     $this->load->library('Math');
     $url_to_shorten = get_magic_quotes_gpc() ? stripslashes(trim($_REQUEST['longurl'])) : trim($_REQUEST['longurl']);
     if (!empty($url_to_shorten) && preg_match('|^https?://|', $url_to_shorten)) {
         $this->db->select("id");
         $this->db->from("shortenedurls");
         $this->db->where('long_url', $url_to_shorten);
         $query = $this->db->get();
         $already_shortened = $query->result();
         if (!empty($already_shortened)) {
             $already_shortened = array_shift($already_shortened);
             $shortened_url = Math::to_base($already_shortened->id, 62);
         } else {
             $data = array('long_url' => $url_to_shorten, 'created' => time(), 'creator' => $_SERVER['REMOTE_ADDR']);
             $url_id = $this->ShortenedUrl->add($data);
             $shortened_url = Math::to_base($url_id, 62);
             $data = array('shortened_url' => 'http://ins.in/l/' . $shortened_url, 'unique_code' => $shortened_url);
             $this->db->where('id', $url_id);
             $this->db->update('shortenedurls', $data);
         }
     } else {
     }
 }