示例#1
0
 public function topSideBar()
 {
     $users = User::limit(12)->get();
     $tmp = [];
     foreach ($users as $user) {
         $tmp[] = ['id' => $user->id, 'name' => $user->name, 'avatar' => \Timthumb::link($user->avatar, 35, 35, 1), 'point' => 100, 'link' => ''];
     }
     $response = ['status' => '1', 'msg' => 'success', 'data' => $tmp];
     return $this->json($response);
 }
示例#2
0
 /**
  * Show the homepage
  * @return \View
  */
 public function getIndex()
 {
     if (Request::isMethod('post')) {
         $addition = [];
         if (\Auth::check()) {
             $addition = ['check_liked' => ['user_id' => \Auth::user()->id]];
         }
         $posts = $this->post->index(10, null, null, null, 'created_at', 'desc', $addition);
         $tmp = [];
         foreach ($posts as $post) {
             $tmp[] = ['id' => $post->id, 'title' => $post->title, 'slug' => $post->slug, 'code' => $post->code, 'url' => $post->getLink(), 'thumbnail' => \Timthumb::link($post->getThumbnail(), 500), 'username' => $post->username, 'user_id' => $post->user_id, 'type' => $post->type, 'name' => $post->name, 'views' => $post->views, 'likes' => $post->likes, 'score' => $post->score, 'comments' => 0, 'created_at_string' => Date::parse($post->created_at)->diffForHumans()];
         }
         $response = ['status' => '1', 'msg' => 'success', 'data' => $tmp];
         return $this->json($response);
     } else {
         return $this->view('gag.frontend.homes.index');
     }
 }
示例#3
0
<?php

Route::group(array('prefix' => Config::get('timthumb::prefix')), function () {
    Route::get('{w}/{h}/{zc}/{src}', function ($w, $h, $zc, $src) {
        return Timthumb::get($src, $w, $h, $zc);
    })->where('w', '[0-9]+')->where('h', '[0-9]+')->where('zc', '[0-9]')->where('src', '.*');
});
示例#4
0
 /**
  * @param $url
  * @param $tempfile
  *
  * @return bool
  */
 protected function getURL($url, $tempfile)
 {
     $this->lastURLError = false;
     $url = preg_replace('/ /', '%20', $url);
     if (function_exists('curl_init')) {
         $this->debug(3, 'Curl is installed so using it to fetch URL.');
         self::$curlFH = fopen($tempfile, 'w');
         if (!self::$curlFH) {
             $this->error("Could not open {$tempfile} for writing.");
             return false;
         }
         self::$curlDataWritten = 0;
         $this->debug(3, "Fetching url with curl: {$url}");
         $curl = curl_init($url);
         curl_setopt($curl, CURLOPT_TIMEOUT, CURL_TIMEOUT);
         curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30');
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($curl, CURLOPT_HEADER, 0);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($curl, CURLOPT_WRITEFUNCTION, 'timthumb::curlWrite');
         @curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
         @curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
         $curlResult = curl_exec($curl);
         fclose(self::$curlFH);
         $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
         if ($httpStatus == 404) {
             $this->set404();
         }
         if ($httpStatus == 302) {
             $this->error('External Image is Redirecting. Try alternate image url');
             return false;
         }
         if ($curlResult) {
             curl_close($curl);
             return true;
         } else {
             $this->lastURLError = curl_error($curl);
             curl_close($curl);
             return false;
         }
     } else {
         $img = @file_get_contents($url);
         if ($img === false) {
             $err = error_get_last();
             if (is_array($err) && $err['message']) {
                 $this->lastURLError = $err['message'];
             } else {
                 $this->lastURLError = $err;
             }
             if (false !== strpos($this->lastURLError, '404')) {
                 $this->set404();
             }
             return false;
         }
         if (!file_put_contents($tempfile, $img)) {
             $this->error("Could not write to {$tempfile}.");
             return false;
         }
         return true;
     }
 }
示例#5
0
 public static function start()
 {
     $tim = new Timthumb();
     $tim->handleErrors();
     $tim->securityChecks();
     if ($tim->tryBrowserCache()) {
         exit(0);
     }
     $tim->handleErrors();
     if (FILE_CACHE_ENABLED && $tim->tryServerCache()) {
         exit(0);
     }
     $tim->handleErrors();
     $tim->run();
     $tim->handleErrors();
     exit(0);
 }