コード例 #1
0
ファイル: App.php プロジェクト: jeyemwey/shortenr
 /**
  * Create \Link.
  * @see Validates input using the Violin class. https://github.com/alexgarrett/violin
  */
 private function create()
 {
     /** validate URL using Violin */
     $v = new \Violin\Violin();
     $v->validate(["url" => [$_POST["URL"], "required|url"]]);
     if ($v->passes()) {
         $url = $_POST["URL"];
         /** Check if Link is already in DB */
         $Link = Link::where("url", $url)->get();
         if ($Link->count()) {
             /** If so, just apply the old link. */
             $Link = $Link[0];
             $Link = $Link->getAttributes();
             $short = $Link["short"];
             /** Else, create a new Link */
         } else {
             $Link = new Link();
             $Link->url = $url;
             $Link->save();
             $short = $Link->short;
         }
         /** And shit it all out. */
         $this->render("New", ["short" => $this->getShortURL($short)]);
         /** Validation failed. */
     } else {
         $this->render("Home", ["error" => "Better check your URL!"]);
     }
 }
コード例 #2
0
 /**
  * Shorten a new URL
  *
  * @return Response
  */
 public function postShorten()
 {
     // No big url
     if (!\Input::has('bigurl')) {
         return \Response::json(array('error' => array('code' => 'MISSING-PARAMETERS', 'http_code' => '400', 'message' => 'Bad Request')), 400);
     }
     $bigURL = \Input::get('bigurl');
     $user = $this->apiKey->user;
     // No user linked to API key - SHOULD NEVER HAPPEN
     if (!isset($user)) {
         return \Response::json(array('error' => array('code' => 'NOT-AUTH', 'http_code' => '403', 'message' => 'Forbidden: SHOULD NEVER HAPPEN!')), 403);
     }
     // User has gone over quota so cant shorten
     if ($user->quota_max != 0 && $user->quota_used + 1 > $user->quota_max) {
         return \Response::json(array('error' => array('code' => 'QUOTA-USED', 'http_code' => '400', 'message' => 'Bad Request')), 403);
     }
     if (filter_var($bigURL, FILTER_VALIDATE_URL) === false) {
         return \Response::json(array('error' => array('code' => 'URL-INVALID', 'http_code' => '400', 'message' => 'Bad Request')), 400);
     }
     $dbLink = \Link::where('destination', '=', $bigURL)->first();
     if (!isset($dbLink)) {
         $dbLink = new \Link();
         $dbLink->user_id = $user->id;
         $dbLink->code = $dbLink->generateCode();
         $dbLink->destination = $bigURL;
         $dbLink->clicks = "0";
         $dbLink->save();
         $user->quota_used += 1;
         $user->save();
     }
     $linkCode = $dbLink->code;
     $linkURL = \Request::root() . '/' . $linkCode;
     return \Response::json(array('ok' => array('code' => 'LINK-SHORTENED', 'http_code' => '200', 'message' => 'OK', 'data' => array('url' => $linkURL, 'url_code' => $linkCode))), 200);
 }
コード例 #3
0
 public function addNew()
 {
     //verify the user input and create account
     $validator = Validator::make(Input::all(), array('Amount' => 'required|numeric'));
     if ($validator->fails()) {
         return Redirect::route('withdraw-get')->withErrors($validator)->withInput();
     } else {
         $amount = Input::get('Amount');
         $todaysdate = date("Y-m-d");
         $totalvisits = Link::where('username', '=', Auth::user()->username)->where('active', '=', TRUE)->sum('clicks');
         $totalearned = $totalvisits * 0.1;
         $withdrawn = Payment::where('user_id', '=', Auth::user()->id)->sum('amount');
         $balance = $totalearned - $withdrawn;
         if ($amount <= $balance) {
             if ($amount >= 500) {
                 //register the new user
                 $newwithdrawal = Payment::create(array('user_id' => Auth::user()->id, 'amount' => $amount, 'withdrawal_date' => $todaysdate, 'paid' => FALSE));
                 if ($newwithdrawal) {
                     return Redirect::route('withdraw-get')->with('global', 'Success! Your Withdrawal request is being processed.');
                 }
             } else {
                 return Redirect::route('withdraw-get')->with('global', 'Failed!! You are allowed to withdraw a minimum of Ksh 500.')->withInput();
             }
         } else {
             return Redirect::route('withdraw-get')->with('global', 'Failed!! The amount exceeds your balance.')->withInput();
         }
     }
 }
コード例 #4
0
ファイル: LinksController.php プロジェクト: onlystar1991/mtdb
 /**
  * Delete links that have more reports then passed number.
  * 
  * @return Response
  */
 public function deleteAll()
 {
     if (Input::get('number') && Input::get('number') !== 0) {
         $this->model->where('reports', '>=', Input::get('number'))->delete();
         //fire event manually so we can flush the cache on it
         Event::fire('eloquent.deleted: Link', array($this->model));
         return Response::json(trans('stream::main.linkDelSuccess'), 200);
     }
 }
コード例 #5
0
 public function deleteLink()
 {
     $linkId = Input::get('memberID');
     $link_delete = Link::where('id', '=', $linkId)->first();
     $link_delete->active = FALSE;
     $link_delete = $link_delete->save();
     if ($link_delete) {
         return Redirect::route('viewlink-get')->with('global', 'Success! Link information has been deleted successfully.');
     }
 }
コード例 #6
0
 public function getRedirect($username, $id)
 {
     $link = Link::where('id', '=', $id)->first();
     /*Get user ip address*/
     $ip_address = $_SERVER['REMOTE_ADDR'];
     $device = Device::where('ip', '=', $ip_address);
     if (!$device->count()) {
         //record the device
         $user = Device::create(array('ip' => $ip_address));
         $link->clicks = $link->clicks + 1;
         $link_save = $link->save();
     }
     return Redirect::away($link->link_name);
 }
コード例 #7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     try {
         $log = new Process();
         $log->name = "get-shares";
         $log->status = "running";
         $log->save();
         $filterDate = new DateTime('now');
         $filterDate->sub(new DateInterval('P1D'));
         //Load shares
         Link::where('date', '>', $filterDate)->chunk(100, function ($links) {
             foreach ($links as $value) {
                 $shares = $this->getSharesCount($value->final_url);
                 $ref = Stats::where('id_link', $value->id)->orderBy('created_at', 'DESC')->first();
                 if (!$ref) {
                     $ref = new stdClass();
                     $ref->total = 0;
                 }
                 $stat = new Stats();
                 $stat->id_link = $value->id;
                 $stat->facebook = $shares['facebook'] != null ? $shares['facebook'] : $value->facebook;
                 $stat->twitter = $shares['twitter'] != null ? $shares['twitter'] : $value->twitter;
                 $stat->linkedin = $shares['linkedin'] != null ? $shares['linkedin'] : $value->linkedin;
                 $stat->googleplus = $shares['googleplus'] != null ? $shares['googleplus'] : $value->googleplus;
                 $stat->total = $stat->facebook + $stat->twitter + $stat->linkedin + $stat->googleplus;
                 $stat->dif_total = $stat->total - $ref->total;
                 $stat->save();
                 $value->facebook = $stat->facebook;
                 $value->twitter = $stat->twitter;
                 $value->linkedin = $stat->linkedin;
                 $value->googleplus = $stat->googleplus;
                 $value->total = $stat->total;
                 $value->save();
             }
         });
         $log->status = "finished";
         $log->save();
     } catch (Exception $e) {
         $this->info($url);
         $this->info($e->getMessage());
     }
 }
コード例 #8
0
 private function loadRss($rss)
 {
     try {
         $feed = FeedReader::read($rss->url);
         $data = array();
         foreach ($feed->get_items() as $key => $value) {
             //Fallback bad url
             $url = $value->get_id();
             $url = filter_var($url, FILTER_VALIDATE_URL) === FALSE ? $value->get_permalink() : $url;
             $link = Link::where('url', $url)->get()->first();
             if (is_null($link)) {
                 $htmlParts = $this->getFinalURL($url);
                 $final_url = $htmlParts['final_url'];
                 $this->info($final_url);
                 if (strpos($final_url, "/") == 0) {
                     $orig = parse_url($url);
                     $final_url = $orig['scheme'] . '://' . $orig['host'] . $final_url;
                     $this->info($final_url);
                 }
                 //'Y-m-d H:i:s'
                 $date = strtotime($value->get_date());
                 //Fallback bad dates
                 if (strpos($date, '1969') == 0) {
                     $date = new DateTime();
                 } else {
                     $date = date('Y-m-d H:i:s', $date);
                 }
                 $image = $this->getImage($value, $htmlParts['og_image']);
                 $data[] = array('url' => $url, 'final_url' => $final_url, 'title' => html_entity_decode($value->get_title()), 'image' => $image, 'id_rss' => $rss->id, 'id_tag' => $rss->id_tag, 'id_newspaper' => $rss->id_newspaper, 'date' => $date, 'facebook' => 0, 'twitter' => 0, 'linkedin' => 0, 'googleplus' => 0, 'updated_at' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s'));
             } else {
                 $link->touch();
             }
         }
     } catch (Exception $e) {
         $this->info($rss->url);
         $this->info($e->getTraceAsString());
     }
     if (count($data)) {
         Link::insert($data);
     }
 }
コード例 #9
0
 public function show($series, $seasonNum, $episodeNum)
 {
     $title = Title::byId($series);
     foreach ($title->season as $value) {
         if ($value->number == $seasonNum) {
             $season = $value;
         }
     }
     if (isset($season)) {
         foreach ($season->episode as $value) {
             if ($value->episode_number == $episodeNum) {
                 $episode = $value;
             }
         }
     }
     if (!isset($episode)) {
         App::abort(404);
     }
     $links = Link::where('title_id', $title->id)->where('season', $season->number)->where('episode', $episode->episode_number)->get();
     return View::make('Titles.Episodes.Show')->with('title', $title)->with('episode', $episode)->with('season', $season)->with('links', $links);
 }
コード例 #10
0
ファイル: PageController.php プロジェクト: ke6scs/samples
 public function getIndex($slug = '', $link_id = 0)
 {
     $debug = '';
     $bmStart = microtime(true);
     $perpage = intval(AppConfig::get('articles_per_page', 50));
     $branch_prefixes = explode(',', AppConfig::get('branch_prefixes'));
     $virtualPerpage = intval(AppConfig::get('virtual_per_page', 20));
     $page = Page::where('slug', '=', $slug)->cacheTags('pages')->remember(1440)->first();
     //$page = Page::where('slug', '=', Str::slug($slug))->first();
     if (count($page) > 0) {
         if ($filter_return = $this->authFilter($page->level)) {
             return $filter_return;
         }
         if ($page->redirect) {
             if (substr($page->redirect, 0, 1) == '{') {
                 $redir_arr = json_decode($page->redirect, true);
                 foreach ($redir_arr as $rlvl => $rslug) {
                     if (strpos($this->auth_lvl, $rlvl) !== false) {
                         return Redirect::to($rslug);
                     }
                 }
                 if (isset($redir_arr['def'])) {
                     return Redirect::to($redir_arr['def']);
                 }
             } else {
                 return Redirect::to($page->redirect);
             }
         }
         // get parameters from URL
         $page->category = Input::has('category') ? Input::get('category') : ($page->default_category ? $page->default_category : false);
         $page->section = Input::has('section') ? Input::get('section') : false;
         $page->keywordInput = $page->ddkeycol ? Input::get('keyword') : '';
         $page_vars = new stdClass();
         // separate slug into branch and section, if applicable
         $branch = $slug;
         if ($page->link_slug) {
             $branch = $page->link_slug;
         }
         $els = explode('/', $branch);
         if (in_array($els[0], $branch_prefixes) && count($els) > 1) {
             $branch = $els[0];
             if (!$page->section) {
                 $page->section = $els[1];
             }
         }
         $dta = normal::getTypes();
         // get list of categories, if there is a "ddlist"
         $categories = false;
         $normalized = false;
         if ($page->ddlist) {
             $fld = $page->ddlist;
             $catq = Link::where('branch', '=', $branch);
             if ($page->section) {
                 $catq->where('section', '=', $page->section);
             }
             if ($dtp = array_search($fld, $dta)) {
                 $catq->join('data', 'data.rec_id', '=', 'links.id')->where('data.table_name', '=', 'links')->where('data.type', '=', $dtp)->whereNull('data.deleted_at');
                 $fld = 'data_body';
                 $normalized = true;
             }
             $category_model = $catq->groupBy($fld)->whereRaw('trim(`' . $fld . '`) != ""')->cacheTags('links')->remember(1440)->get(array($fld));
             $categories = array('' => 'All');
             foreach ($category_model as $category_item) {
                 $categories[$category_item->{$fld}] = $category_item->{$fld};
             }
         }
         $links = false;
         $columns = false;
         // get list of links, specified by branch, section, category, state, and/or keyword
         if ($page->linkdef || $link_id && $page->detaildef) {
             // get column layout
             $columns = Listcolumns::where('def', '=', $link_id ? $page->detaildef : $page->linkdef)->cacheTags('links')->remember(1440)->orderBy('listorder')->get();
             $perlinkpage = intval(AppConfig::get('links_per_page', 50));
             $query = new Link();
             if ($link_id) {
                 $query = $query->where('id', '=', $link_id);
             } else {
                 if ($page->section) {
                     $query = $query->where('section', '=', $page->section);
                 }
                 if ($page->category) {
                     if ($normalized) {
                         $query = $query->join('data AS d', 'd.rec_id', '=', 'links.id')->where('d.table_name', '=', 'links')->where('d.type', '=', $dtp)->whereNull('d.deleted_at');
                     }
                     $query = $query->where(isset($fld) ? $fld : ($page->section ? 'category' : 'section'), '=', $page->category);
                 }
                 if ($page->state) {
                     $query = $query->where('state', '=', $page->state);
                 }
                 if ($page->keywordInput) {
                     if ($page->keywordInput == "by_date") {
                         $query = $query->join('data AS d', 'd.rec_id', '=', 'links.id')->where('d.table_name', '=', 'links')->where('d.type', '=', 7)->whereNull('d.deleted_at');
                         $month = Input::get('themonth');
                         $year = Input::get('theyear');
                         $pfx = $year . '-' . $month;
                         $start_date = $pfx . '-01';
                         $end_date = $pfx . '-' . cal_days_in_month(CAL_GREGORIAN, $month, $year);
                         $query = $query->whereRaw('d.`data_body`  BETWEEN ? AND ?', array($start_date, $end_date));
                         unset($page->keywordInput);
                         $page_vars->month = $month;
                         $page_vars->year = $year;
                     } else {
                         $query = $query->whereRaw('`' . $page->ddkeycol . '` RLIKE ?', array($page->keywordInput));
                     }
                 }
                 if (!$page->allowBroken) {
                     $query = $query->join('link_check', 'links.id', '=', 'link_check.id');
                     $query = $query->whereBetween('link_check.last_result', array('200', '399'));
                 }
             }
             $order = 'name';
             $orderdir = 'asc';
             if ($page->linkorder) {
                 $ordera = explode(',', $page->linkorder);
                 $order = $ordera[0];
                 if (count($ordera) > 1) {
                     $orderdir = $ordera[1];
                 }
                 if ($dtp = array_search($order, $dta)) {
                     $query = $query->join('data AS d2', 'd2.rec_id', '=', 'links.id')->where('d2.table_name', '=', 'links')->where('d2.type', '=', $dtp)->whereNull('d2.deleted_at');
                     $order = 'd2.data_body';
                 }
             }
             if ($page->where) {
                 $query = $query->whereRaw($page->where);
             }
             if ($page->remove_dupes) {
                 $query = $query->groupBy('name', 'url');
             }
             $links = $query->where('branch', '=', $branch)->select(array('links.*'))->orderBy($order, $orderdir)->cacheTags('links')->remember(1440)->paginate($perlinkpage);
             $ids = array();
             foreach ($links as $link) {
                 $ids[] = $link->id;
             }
             $xda = count($ids) ? Cache::tags('links')->remember('linkData|' . implode('-', $ids), 1440, function () use($ids) {
                 $xdata = Data::where('table_name', '=', 'links')->join('data_types', 'data_types.id', '=', 'data.type')->whereIn('rec_id', $ids)->whereNull('data_types.deleted_at')->cacheTags('data')->remember(10080)->get();
                 $xdda = array();
                 foreach ($xdata as $xrec) {
                     $xdda[$xrec->rec_id][$xrec->label] = $xrec->data_body;
                 }
                 return $xdda;
             }) : array();
             foreach ($links as $lid => $link) {
                 $id = $link->id;
                 if (isset($xda[$id])) {
                     foreach ($xda[$id] as $xid => $xdt) {
                         $links[$lid]->{$xid} = $xdt;
                     }
                 }
             }
         }
         $thumbs = false;
         if ($page->virtual_type) {
             $thumbs = Ad::where('type', '=', $page->virtual_type)->where('category', '=', $page->category)->orderBy('vorder', 'desc')->cacheTags('ads')->remember(1440)->paginate($virtualPerpage);
             foreach ($thumbs as $thumb) {
                 Ads::track($thumb, 3, $page->id);
             }
             // get list of categories
             $category_model = Ad::groupBy('category')->where('type', '=', $page->virtual_type)->cacheTags('ads')->remember(1440)->get(array('category'));
             $categories = array();
             foreach ($category_model as $category_item) {
                 $categories[$category_item->category] = $category_item->category;
             }
             //                $page->dname = 'Category';
         }
         // benchmarking the database access
         $bmEnd = microtime(true);
         $page->elapsed = $bmEnd - $bmStart;
         $page_vars->qstring = '';
         if ($page->pass_query == 'Y') {
             $qry = Input::query();
             $qry['mc_rnm'] = substr(time(), 2);
             if (count($qry)) {
                 $page_vars->qstring = '?' . http_build_query($qry);
             }
         }
         if ($page->randomize) {
             foreach (explode(',', $page->randomize) as $random_tag) {
                 $page_vars->{$random_tag} = mt_rand(10000, 99999);
             }
         }
         foreach (AppConfig::getAll() as $cfi => $cfd) {
             $page_vars->{$cfi} = $cfd;
         }
         $page_vars->nocache = NOCACHE_CODE;
         if (!$page->layout) {
             //                if ($_SERVER['REMOTE_ADDR'] == '108.47.107.194') {
             //                    $page->layout = 'template.layout2';
             //                } else {
             $page->layout = 'template.layout';
             //                }
         }
         // get data on child and parent pages
         $childpages = new Page();
         $P = clone $childpages->getConnection()->getPaginator();
         $P->setPageName('article');
         $childpages->getConnection()->setPaginator($P);
         $childpages = $childpages->join('article_pages', 'pages.id', '=', 'article_pages.page_id');
         $childpages = $childpages->where('article_pages.parent_id', '=', $page->id);
         $childpages = $childpages->whereNull('article_pages.deleted_at');
         $childpages = $childpages->orderBy('pageOrder');
         $childpages = $childpages->cacheTags('pages')->remember(1440);
         $childpages = $childpages->paginate($perpage);
         // pass ALL the data to the view
         return View::make('page.page')->with('dyn_layout', $page->layout)->with('page', $page)->with('childpages', $childpages)->with('categories', $categories)->with('links', $links)->with('link_id', $link_id)->with('thumbs', $thumbs)->with('columns', $columns)->with('top_banner', empty($slug))->with('debug', $debug)->with('parse_body', Display::format($page->body, $page_vars, false, false));
     } else {
         if (substr($slug, -5) == '.html') {
             $new_slug = substr($slug, 0, -5);
             $new_page = Page::where('slug', '=', $new_slug)->cacheTags('pages')->remember(1440)->first();
             if (count($new_page) > 0) {
                 return Redirect::to('/' . $new_slug, 301);
             }
         }
         $missing = new Missing();
         $missing->slug = $slug;
         $missing->referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "[none]";
         $missing->save();
         AppLog::alert('Page Not Found', 404, json_encode(array('slug' => $slug)));
         return Response::view('page.notfound', array('slug' => $slug), 404);
     }
 }
コード例 #11
0
 public function del_link($slug)
 {
     $link = Link::where(['id' => $slug])->firstOrFail();
     $link->delete();
     View::success('彻底删除成功', 'http://' . __HOST__ . '/admin/link/');
     die;
 }
コード例 #12
0
ファイル: HomeController.php プロジェクト: pchaow/pportal
 public function getSiteIndexs($char)
 {
     $check = false;
     $disablechar = [];
     $thaichar = array('ก', 'ข', 'ค', 'ง', 'จ', 'ฉ', 'ช', 'ซ', 'ฌ', 'ญ', 'ฐ', 'ฑ', 'ฒ', 'ณ', 'ด', 'ต', 'ถ', 'ท', 'ธ', 'น', 'บ', 'ป', 'ผ', 'ฝ', 'พ', 'ฟ', 'ภ', 'ม', 'ย', 'ร', 'ล', 'ว', 'ศ', 'ษ', 'ส', 'ห', 'ฬ', 'อ', 'ฮ');
     $thaivowel = array('เ', 'แ', 'ใ', 'ไ', 'โ');
     if (!isset($char)) {
         $char = "ก";
     }
     for ($i = 0; $i < count($thaichar); $i++) {
         if ($char == $thaichar[$i]) {
             $check = true;
         }
     }
     if (!$check) {
         App::abort(404);
     }
     $links = Link::where('name', 'LIKE', $char . '%')->get();
     for ($i = 0; $i < count($thaivowel); $i++) {
         $links = $links->merge(Link::where('name', 'LIKE', $thaivowel[$i] . $char . '%')->get());
     }
     for ($i = 0; $i < count($thaichar); $i++) {
         $checkChar = Link::where('name', 'LIKE', $thaichar[$i] . '%')->get();
         for ($j = 0; $j < count($thaivowel); $j++) {
             $checkChar = $checkChar->merge(Link::where('name', 'LIKE', $thaivowel[$j] . $thaichar[$i] . '%')->get());
         }
         if (count($checkChar) == 0) {
             $disablechar[] = $thaichar[$i];
         }
     }
     $this->breadcrumbs->push('Site Index', URL::to('/site-index'));
     $this->breadcrumbs->generate();
     return View::make('home.site-index')->with('thaiChar', $thaichar)->with('char', $char)->with('links', $links)->with('disablechar', $disablechar);
 }
コード例 #13
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $dbLink = \Link::where('code', '=', $id)->first();
     if (!isset($dbLink)) {
         Response::make("Link not found, please try again!", 404);
     }
     $dbLink->clicks = bcadd($dbLink->clicks, "1");
     $dbLink->save();
     return \Redirect::away($dbLink->destination);
 }
コード例 #14
0
 public function run()
 {        
     $link = Link::where('url', '=', 'Link')->take(1)->get();
     var_dump($link);
     exit();
 }
コード例 #15
0
 /**
  * [artice 文章内容]
  * @return [type] [description]
  */
 public function artice($slug)
 {
     $webSite = Website::find(1)->toArray();
     $arcData = Article::with('belongsToCategory')->find($slug)->toArray();
     //print_r($arcData);
     $hotArcData = Article::with('belongsToCategory')->where(['is_del' => 0])->get()->toArray();
     $linkData = Link::where(['is_look' => 1])->get()->toArray();
     //print_r($linkData);
     $cateData = Category::where(['is_del' => 0])->get()->toArray();
     //print_r($cateData);
     $item = [];
     foreach ($cateData as $k => $v) {
         if (!isset($item[$v['id']])) {
             $item[$v['id']] = $v;
         } else {
             $item[$v['id']] = $v;
         }
     }
     //上一篇
     $pre = Article::get_pre($slug);
     //print_r($pre);
     //下一篇
     $next = Article::get_next($slug);
     //print_r($next);
     //相关文章
     $this->smarty->assign('pre', $pre);
     $this->smarty->assign('next', $next);
     $this->smarty->assign('webSite', $webSite);
     $this->smarty->assign('hotArcData', $hotArcData);
     $this->smarty->assign('cateData', $item);
     $this->smarty->assign('slug', $slug);
     $this->smarty->assign('linkData', $linkData);
     $this->smarty->assign('article', $arcData);
     $this->smarty->display('Index/article.html');
 }