Exemplo n.º 1
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.º 2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     DB::table('urls')->delete();
     Url::create(['token' => 'Aa', 'long_url' => 'https://www.google.com/']);
     Url::create(['token' => 'aA', 'long_url' => 'https://github.com/']);
 }
Exemplo n.º 3
0
 public function store()
 {
     if (Request::ajax()) {
         $data = Input::all();
         $id = rand(10000, 99999);
         $shorturl = base_convert($id, 20, 36);
         $data['short_url'] = $shorturl;
         Url::create($data);
         echo json_encode($data);
     }
 }
 /**
  * Create token for a url.
  *
  * @param $longUrl
  * @param null $customToken
  * @return string
  */
 public function make($longUrl, $customToken = null)
 {
     if ($customToken) {
         if ($this->exists('token', $customToken)) {
             throw new DuplicateTokenException();
         }
         $token = $customToken;
     } else {
         $duplicate = $this->exists('url', $longUrl);
         if ($duplicate) {
             return $duplicate['token'];
         }
         $token = $this->token();
     }
     Url::create(['token' => $token, 'url' => $longUrl]);
     return $token;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $hashids = new Hashids('smpx', 6);
     $hashed_url = $hashids->encode(125);
     $url = new Url();
     $url->long_url = $request["long_url"];
     $url->short_url = config('app.url') + '/' + $hashed_url;
     $url->is_active = true;
     $url->clicks = 0;
     $urlInstance = $url->create();
     echo $urlInstance->toJson(), "hoeee";
     return;
 }
Exemplo n.º 6
0
 /**
  * Store a newly created Url in storage.
  * Required: long_url
  * Optional: custom_key, category
  */
 public function create(Request $request)
 {
     //	Get the largest Id of url from db
     $maxId = Url::withTrashed()->max('id');
     //	Validate maxId, and fix it
     if (!isset($maxId)) {
         $maxId = 0;
     }
     //	Validate custom Key (key for short url), and generate new one using MAXID
     if (empty($request["custom_key"])) {
         $hashids = new Hashids('smpx', 6);
         $hashedUrl = $hashids->encode($maxId++);
     } else {
         $hashedUrl = $request["custom_key"];
     }
     //	trim long url (Original Url)
     $longUrl = trim($request["long_url"]);
     //	Validate Long Url and send error if invalid
     if (strlen($longUrl) <= 0) {
         $error = Utility::getError(null, 400, 'Error', 'Invalid Url');
         return response()->json($error, 400);
     }
     //	Check whether Long url contains http protocol or not, If not then append 'http://'
     //	Here not checking for protocols other than http
     if (substr($longUrl, 0, 7) !== "http://" and substr($longUrl, 0, 8) !== "https://") {
         $longUrl = 'http://' . $longUrl;
     }
     //	Validate category
     if (!isset($request["category"]) || $request["category"] == '') {
         $category = 'no_category';
     } else {
         $category = $request["category"];
     }
     //	build array object of Url data to save to DB
     $array = array('long_url' => $longUrl, 'short_url' => config('app.url') . '/' . $hashedUrl, 'is_active' => true, 'clicks' => 0, 'category' => $category);
     try {
         //	save Url data to DB
         $urlInstance = Url::create($array);
     } catch (QueryException $e) {
         // Make logging for QueryException
         $error = Utility::getError(null, 400, 'Error', 'Duplicate Entry of short Url');
         return response()->json($error, 400);
     }
     //	Add attribute 'time' containing humna readable time format
     $urlInstance['time'] = $urlInstance['created_at']->diffForHumans(Carbon::now());
     //	Build response object
     $res = new \stdClass();
     $res->status = 'Success';
     $res->data = $urlInstance;
     $res->message = 'Successfully created';
     //	Send response Object in json string
     return response()->json($res, 200);
 }
Exemplo n.º 7
0
    } while (!empty($url));
    return $name;
}
$app->get('/', function () use($app) {
    return view('index');
});
$app->post('create', function (Request $request) use($app) {
    $requested = $request->input('url');
    if (empty($requested)) {
        return 'Sorry, you can not enter nothing.';
    }
    // Do a quick check.
    if (substr($requested, 0, 4) !== "http") {
        $requested = "http://" . $requested;
    }
    $url = Url::create(['name' => generateName(), 'url' => $requested, 'hits' => 0]);
    return view('created', compact('url'));
});
// URL stats.
$app->get('{name:.*}/s', function ($name) {
    $url = Url::where('name', '=', $name)->first();
    if (empty($url)) {
        return 'Not found: ' . $name;
    }
    return view('stats', compact('url'));
});
// URL deletion.
$app->get('{name:.*}/d', function ($name) {
    $url = Url::where('name', '=', $name)->first();
    if (empty($url)) {
        return 'Not found: ' . $name;
Exemplo n.º 8
0
 /**
  * This functions add the URL to the datase and generates the
  * unique short url
  * 
  * return string $new code
  */
 private function _addUrl()
 {
     // Add both url and short key to the database
     $url = Url::create(array('url' => Request::get('url'), 'code' => md5(Request::get('url'))));
     return $url->id;
 }