/**
  * @test
  */
 public function creates_token_for_url()
 {
     $token = $this->shortener->make('https://phpunit.de/manual/4.8/en/appendixes.assertions.html');
     $this->assertRegExp('/^[a-z0-9]{5}$/i', $token);
     $result = Url::where('token', $token)->first();
     $this->assertNotNull($result);
 }
 public function see_if_count_was_incremented()
 {
     $this->shortener->make('https://phpunit.de/manual/4.8/en/appendixes.assertions.html', 'phpunit');
     $this->resolver('phpunit');
     $result = Url::where('token', 'phpunit')->first();
     $this->assertEquals('1', $result['visits']);
 }
Exemplo n.º 3
0
 /**
  * @return insert data to url table
  */
 public function postUrl(Request $request)
 {
     $this->validate($request, ['name' => 'required|unique:urls|max:255']);
     $url = Url::create($request->all());
     $requesturl = $request->input('name');
     $scrapedurl = Url::where('name', $requesturl)->firstOrFail();
     $this->urlId = $scrapedurl->id;
     $crawler = $this->helper_crawler($scrapedurl->name);
     $isBlock = $crawler->filter('p')->text();
     //dd($crawler->html());
     if (strpos($isBlock, 'blocked') != false) {
         echo "Your ip is blocked. Please try again later";
         die;
     } else {
         $data = $crawler->filterXpath("//div[@class='rows']");
         $data->filter('p > a')->each(function ($node) {
             $scrapedurl = $node->attr('href');
             if (!preg_match("/\\/\\/.+/", $scrapedurl)) {
                 $this->getInfo($scrapedurl);
             }
         });
     }
     $leads = Lead::all();
     Session::flash('leads', $leads);
     return redirect()->back()->with('message', "Link was scraped please view link");
 }
Exemplo n.º 4
0
 public function redirect($short)
 {
     $redirect = App\Url::where('short', $short)->first();
     if ($redirect) {
         return redirect($redirect->url);
     } else {
         return view('404');
     }
 }
 public function short_url($short_url)
 {
     $res = Url::where('short_url', $short_url)->first();
     //dd($res->url);
     if (is_null($res)) {
         return redirect('url');
     }
     return redirect($res->url);
 }
Exemplo n.º 6
0
 public static function get_short_url()
 {
     $short_url = base_convert(rand(1000, 99999), 10, 36);
     $res = Url::where('short_url', $short_url)->first();
     if (!empty($res)) {
         static::get_short_url();
     } else {
         return $short_url;
     }
 }
Exemplo n.º 7
0
 public function handleShortcode($shortCode)
 {
     $url = Url::where('short_url', $shortCode)->get();
     if (count($url) > 0) {
         return Redirect::to($url[0]['original']['long_url'], 302);
     } else {
         Session::flash('message', 'This Short Url Is Not Valid!');
         Session::flash('alert-class', 'alert-danger');
         return Redirect::to('urls');
     }
 }
Exemplo n.º 8
0
 public function shortenlink(Request $request)
 {
     $input = Request::get('link');
     $count = Url::where('long_url', $input)->count();
     if ($count) {
         $url = Url::where('long_url', $input)->get();
         return 'long~' . $url;
     } else {
         $url = Url::where('short_url', $input)->get();
         return 'short~' . $url;
     }
 }
Exemplo n.º 9
0
function generateName()
{
    $chars = str_split('abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . '0123456789');
    // Find a filename.
    do {
        $name = '';
        foreach (array_rand($chars, 4) as $k) {
            $name .= $chars[$k];
        }
        $url = Url::where('name', '=', $name)->first();
    } while (!empty($url));
    return $name;
}
Exemplo n.º 10
0
 /**
  * Add url to database.
  *
  * @return Url
  */
 public function addurl(Request $request)
 {
     $url = $request->input('long_url');
     $hash_url = hash('adler32', $url);
     $results = Url::where('hash', '=', $hash_url)->get();
     if (empty($results[0])) {
         $iurl = new Url();
         $iurl->hash = $hash_url;
         $iurl->long_url = base64_encode($url);
         $iurl->ip = $request->ip();
         $iurl->save();
         return sprintf('%s/%s', url('/'), $hash_url);
     } else {
         return sprintf('%s/%s', url('/'), $results[0]->hash);
     }
 }
 /**
  * Redirect to long url
  * @return rediect to long url 
  */
 public function redirect(Request $request, $shortUrl)
 {
     $agent = new Agent();
     $agent->setUserAgent($request->headers);
     $urls = Url::where('short_url', '=', $shortUrl)->get();
     if (!$urls->first()) {
         echo "Not Found";
         return;
     }
     $url = $urls[0];
     $longUrl = $url['long_url'];
     $url->clicks = $url['clicks'] + 1;
     $url->save();
     $url->hits()->create(['client_ip' => $_SERVER['REMOTE_ADDR'], 'language' => $agent->languages()[0], 'device' => $agent->device(), 'platform' => $agent->platform(), 'browser' => $agent->browser()]);
     //$agent->languages()[0],$agent->device(), $agent->platform(),$agent->browser(),$agent->robot();;;;
     return redirect($url['long_url']);
 }
Exemplo n.º 12
0
 public function shorten(Request $request)
 {
     $longUrl = parse_url($request->url, PHP_URL_SCHEME) ? $request->url : 'http://' . $request->url;
     if (filter_var($longUrl, FILTER_VALIDATE_URL) === false) {
         return view('pages.url.index', ['error' => 'Unable to shorten that link. It is not a valid url.']);
     }
     $url = Url::where('long_url', '=', $longUrl)->first();
     if ($url == null) {
         $ln = 2;
         $generatedToken = null;
         while ($generatedToken == null && $ln < 10) {
             $tempToken = $this->generateToken($ln);
             $url = Url::where('token', '=', $tempToken)->first();
             if ($url == null) {
                 $generatedToken = $tempToken;
             } else {
                 $ln++;
             }
         }
         if ($generatedToken != null) {
             $url = new Url();
             $url->token = $generatedToken;
             $url->long_url = $longUrl;
             $url->save();
             $success['token'] = $url->token;
             $success['long_url'] = $url->long_url;
             $success['short_url'] = preg_replace('#(http|https|ftp)://(www\\.?)?#i', '', $request->root()) . '/' . $url->token;
             $success['filtered_url'] = preg_replace('#(http|https|ftp)://(www\\.?)?#i', '', $url->long_url);
         } else {
             $error = 'Something went wrong and it\'s my fault. Please try again.';
             return view('pages.url.index', ['error' => $error]);
         }
     } else {
         $success['token'] = $url->token;
         $success['long_url'] = $url->long_url;
         $success['short_url'] = preg_replace('#(http|https|ftp)://(www\\.?)?#i', '', $request->root()) . '/' . $url->token;
         $success['filtered_url'] = preg_replace('#(http|https|ftp)://(www\\.?)?#i', '', $url->long_url);
     }
     //return redirect()->route('pages.url.index');
     return view('pages.url.index', ['success' => $success]);
 }
Exemplo n.º 13
0
 /**
  * Fetches the url by it's token.
  * @param $token
  * @return mixed
  */
 public function make($token)
 {
     $result = Url::where('token', $token)->firstOrFail();
     $result->incrementVisits();
     return $result['url'];
 }
Exemplo n.º 14
0
 /**
  * Check whether a value exists in a column.
  * @param $url
  *
  * @return null|Model
  */
 protected function exists($column, $value)
 {
     return Url::where($column, $value)->first();
 }
Exemplo n.º 15
0
 public function redirect($url)
 {
     $find = Url::where(['short_url' => $url])->first();
     return redirect()->to("http://" . $find);
     // return redirectTo($find);
 }
Exemplo n.º 16
0
 public function getCotegoryUrlsCount($name)
 {
     $urls = Url::where('category', $name)->count();
     echo $urls;
 }
Exemplo n.º 17
0
 /**
  * Get all the user urls.
  *
  * @param int $userId
  * @return \Illuminate\Http\JsonResponse
  */
 public function showUserUrls($userId)
 {
     $urls = Url::where(['user_id' => $userId])->paginate(20);
     return $this->respondWithCollection($urls, new UrlTransformer(), 'urls');
 }
Exemplo n.º 18
0
 /**
  * Redirect the shor url the the long/original url
  * redirect the long url to the view 
  * 
  */
 public function redirect($code)
 {
     $id = $this->_getIndex($code);
     $row = Url::where('id', '=', $id)->first();
     if ($row) {
         return Redirect::to($row->url);
     } else {
         return Redirect::to('/invalid')->with('url', 'Invalid');
     }
 }