Ejemplo n.º 1
0
 public static function feed($mode, $user_fp, $input, $blacklist = false)
 {
     switch ($mode) {
         case 'top':
             $posts = DB::table('posts')->join('users', 'posts.user_fp', '=', 'users.user_fp')->select('posts.*', 'users.public_hash', 'users.nickname')->where('posts.parent_id', '=', 0)->where('posts.rating', '>', 1)->where('posts.timestamp', '>', Carbon\Carbon::now()->subMonth())->orderBy('posts.rating', 'desc');
             break;
         case 'new':
             $posts = DB::table('posts')->join('users', 'posts.user_fp', '=', 'users.user_fp')->select('posts.*', 'users.public_hash', 'users.nickname')->where('posts.parent_id', '=', 0)->orderBy('posts.created_at', 'desc');
             break;
         case 'discuss':
             $posts = DB::table('posts')->join('users', 'posts.user_fp', '=', 'users.user_fp')->select('posts.*', 'users.public_hash', 'users.nickname')->where('posts.parent_id', '=', 0)->where('posts.replies', '>', 4)->orderBy('posts.updated_at', 'desc');
             break;
         default:
             $posts = DB::table('posts')->join('users', 'posts.user_fp', '=', 'users.user_fp')->select('posts.*', 'users.public_hash', 'users.nickname')->orderBy('posts.created_at', 'desc');
             break;
     }
     if (isset($input['timestamp'])) {
         $date = Carbon\Carbon::createFromTimeStamp($input['timestamp']);
         $posts = $posts->where('posts.created_at', '>', $date->toDateTimeString());
     }
     if (isset($input['chans'])) {
         $chans = explode(',', $input['chans']);
         $posts = $posts->whereIn('posts.chan', $chans);
     }
     if (isset($input['count'])) {
         $count = $input['count'];
     } else {
         $count = 20;
     }
     if ($blacklist) {
         $posts->whereNotIn("posts.user_fp", $blacklist);
     }
     return $posts->limit($count)->get();
 }
Ejemplo n.º 2
0
function recent_posts($limit = 3)
{
    return Cache::remember('reddit-posts', 30, function () use($limit) {
        $user_agent = 'User-Agent: php:ffxivcrafting:v0.0.1 (by /u/tickthokk)';
        $request = new Jyggen\Curl\Request('http://api.reddit.com/user/tickthokk/submitted.json');
        $request->setOption(CURLOPT_HTTPHEADER, [$user_agent]);
        $request->execute();
        if (!$request->isSuccessful()) {
            return [];
        }
        $response = json_decode($request->getResponse()->getContent());
        $posts = [];
        foreach ($response->data->children as $child) {
            if ($child->data->subreddit == 'ffxivcrafting') {
                $posts[] = ['title' => $child->data->title, 'url' => 'http://reddit.com' . $child->data->permalink, 'created' => Carbon\Carbon::createFromTimeStamp($child->data->created)->format('M d, Y')];
            }
            if (count($posts) == $limit) {
                break;
            }
        }
        return $posts;
    });
}
Ejemplo n.º 3
0
 public function scopeValid()
 {
     return !Carbon\Carbon::createFromTimeStamp(strtotime($this->expires_on))->isPast();
 }
Ejemplo n.º 4
0
/**
 * Convert unix timestamp to readable format
 *
 * @return string
 */
function ago($timestamp)
{
    return Carbon\Carbon::createFromTimeStamp($timestamp)->diffForHumans();
}
function time_ago($before)
{
    $time = Carbon\Carbon::createFromTimeStamp(strtotime($before))->diffForHumans();
    // $time = Carbon::createFromTimeStamp(strtotime($before))->diffForHumans();
    return $time;
}
Ejemplo n.º 6
0
<?php

/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(LaravelAcademy\User::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'remember_token' => str_random(10)];
});
$factory->define(LaravelAcademy\Teacher::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'email' => $faker->email, 'funfact' => $faker->paragraph, 'age' => $faker->numberBetween(20, 67)];
});
$factory->define(LaravelAcademy\Lesson::class, function (Faker\Generator $faker) {
    $start = Carbon\Carbon::createFromTimeStamp($faker->dateTimeBetween('-1 month', '+1 month')->getTimestamp());
    return ['title' => $faker->sentence, 'description' => $faker->paragraph, 'start' => $start->toDateTimeString(), 'end' => $start->addHours($faker->numberBetween(1, 2))->toDateTimeString()];
});