Exemple #1
0
 public static function boot()
 {
     parent::boot();
     static::created(function ($topic) {
         SiteStatus::newTopic();
     });
 }
Exemple #2
0
 /**
  * Collection site status
  *
  * @param  [string] $action
  * @return void
  */
 public static function collect($subject)
 {
     $today = Carbon::now()->toDateString();
     if (!($todayStatus = SiteStatus::where('day', $today)->first())) {
         $todayStatus = new SiteStatus();
         $todayStatus->day = $today;
     }
     switch ($subject) {
         case 'new_user':
             $todayStatus->register_count += 1;
             break;
         case 'new_topic':
             $todayStatus->topic_count += 1;
             break;
         case 'new_reply':
             $todayStatus->reply_count += 1;
             break;
         case 'new_image':
             $todayStatus->image_count += 1;
             break;
     }
     $todayStatus->save();
 }
Exemple #3
0
 public function uploadImage()
 {
     if ($file = Input::file('file')) {
         $allowed_extensions = ["png", "jpg", "gif"];
         if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
             return ['error' => 'You may only upload png, jpg or gif.'];
         }
         $fileName = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension() ?: 'png';
         $folderName = 'uploads/images/' . date("Ym", time()) . '/' . date("d", time()) . '/' . Auth::user()->id;
         $destinationPath = public_path() . '/' . $folderName;
         $safeName = str_random(10) . '.' . $extension;
         $file->move($destinationPath, $safeName);
         // If is not gif file, we will try to reduse the file size
         if ($file->getClientOriginalExtension() != 'gif') {
             // open an image file
             $img = Image::make($destinationPath . '/' . $safeName);
             // prevent possible upsizing
             $img->resize(1440, null, function ($constraint) {
                 $constraint->aspectRatio();
                 $constraint->upsize();
             });
             // finally we save the image as a new file
             $img->save();
         }
         $data['filename'] = getUserStaticDomain() . $folderName . '/' . $safeName;
         SiteStatus::newImage();
     } else {
         $data['error'] = 'Error while uploading file';
     }
     return $data;
 }