Ejemplo n.º 1
0
 public function loadList()
 {
     if (!($posts = Redis::zrevrange(Key::posts($this->language), 0, -1, 'WITHSCORES'))) {
         if (!file_exists(base_path("resources/blog/{$this->language}"))) {
             return null;
         }
         $files = (new Filesystem())->allFiles(base_path("resources/blog/{$this->language}"));
         $files = array_map(function ($file) {
             $filename = explode('__', pathinfo($file, PATHINFO_FILENAME));
             $date = count($filename) ? array_shift($filename) : '';
             $date = \DateTime::createFromFormat('Y-m-d', $date) ?: new \DateTime();
             $slug = array_shift($filename);
             return ['path' => $file->getRealPath(), 'slug' => $slug, 'published' => $date->setTime(9, 0, 0), 'extension' => pathinfo($file, PATHINFO_EXTENSION)];
         }, $files);
         $loaded = [];
         foreach ($files as $file) {
             if ($file['slug'] and $file['extension'] == 'md') {
                 $loaded[$file['slug']] = $file;
                 Redis::zadd(Key::posts($this->language), $file['published']->getTimestamp(), serialize($file));
             }
         }
         return $loaded;
     }
     return static::convert($posts);
 }
Ejemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //Default for number of images in the post
     $num_img = 0;
     $locationID = null;
     $taglist = null;
     if (Auth::user()->uuid) {
         if ($request->data) {
             $json = $request->data;
             $topicUUID = rand(0, 10) . str_random(12) . rand(0, 10);
             $topicSlug = str_slug($json['title'], "-") . '-' . $topicUUID;
             //Reviews
             if ($json['reviews'] != 'false') {
                 $count = 0;
                 foreach ($json['reviews'] as $review) {
                     //there is a bug that says name is empty sometime
                     if (!empty($review['name'])) {
                         $review_data[$count] = array('topic_uuid' => $topicUUID, 'user_uuid' => Auth::user()->uuid, 'criteria' => $review['name'], 'scores' => $review['rating'], 'is_template' => TRUE, 'created_at' => date("Y-m-d H:i:s"));
                         $count++;
                     }
                 }
                 Reviews::insert($review_data);
             }
             //Location
             if (!empty($json['location'])) {
                 $locationID = $json['location']['id'];
                 //Check location exists, if not create
                 $location_exist = DB::table('locations')->where('external_id', $locationID)->count();
                 if ($location_exist == 0) {
                     $location = new Location();
                     $location->source = 'facebook';
                     //hardcode for now
                     $location->external_id = $locationID;
                     $location->name = $json['location']['name'];
                     $location->category = !empty($json['location']['category']) ? $json['location']['category'] : null;
                     $location->street = !empty($json['location']['location']['street']) ? $json['location']['location']['street'] : null;
                     $location->city = !empty($json['location']['location']['city']) ? $json['location']['location']['city'] : null;
                     $location->state = !empty($json['location']['location']['state']) ? $json['location']['location']['state'] : null;
                     $location->country = !empty($json['location']['location']['country']) ? $json['location']['location']['country'] : null;
                     $location->zip = !empty($json['location']['location']['zip']) ? $json['location']['location']['zip'] : null;
                     $location->latitude = $json['location']['location']['latitude'];
                     $location->longitude = $json['location']['location']['longitude'];
                     $location->save();
                 }
                 //GEt the ID
             }
             //Tag list - to store in the topic table
             if (!empty($json['tags'])) {
                 $taglist = implode(",", $json['tags']);
             }
             //Images
             if (!empty($json['images'])) {
                 $count = 0;
                 //Insert images in another table
                 foreach ($json['images'] as $image) {
                     $img_data[$count] = array('topic_uuid' => $topicUUID, 'user_uuid' => Auth::user()->uuid, 'filename' => $image, 'created_at' => date("Y-m-d H:i:s"));
                     $count++;
                 }
                 $num_img = $count;
                 TopicImages::insert($img_data);
             }
             $topic = new Topic();
             $topic->uuid = $topicUUID;
             $topic->type = $json['type'];
             $topic->uid = Auth::user()->uuid;
             $topic->topic = clean($json['title']);
             $topic->body = preg_replace('/(<[^>]+) style=".*?"/i', '$1', clean($json['body']));
             $topic->text = clean($json['text']);
             $topic->category = $json['categories'];
             $topic->slug = $topicSlug;
             $topic->num_img = $num_img;
             $topic->tags = $taglist;
             $topic->location_id = $locationID;
             $topic->save();
             $tag_data = array();
             $count = 0;
             //Tags - to store in tags table
             if (!empty($json['tags'])) {
                 //Insert tags in another table
                 foreach ($json['tags'] as $tag) {
                     Redis::zadd('post:tag' . $tag, $topic->uuid, $topic->uuid);
                     Redis::sadd('post:' . $topic->uuid . ':tags', $tag);
                     //Master link of tags
                     Redis::sadd('post:tags', $tag);
                     $tag_data[$count] = array('topic_uuid' => $topicUUID, 'title' => clean($tag), 'created_at' => date("Y-m-d H:i:s"));
                     $count++;
                 }
                 Tags::insert($tag_data);
             }
             $topicEvents = Topic::find($topic->id);
             event(new \App\Events\TopicPostEvent($topicEvents));
             $data = array("slug" => $topicSlug, "author" => Auth::user()->displayname, "type" => $json['type'], "topic_uuid" => $topicUUID);
             return $data;
         }
     } else {
         return "not login";
     }
 }
Ejemplo n.º 3
0
 private static function requestFeaturedCompaniesCache()
 {
     $companies = self::where(['is_promoted' => 1])->orderBy('name')->get();
     if (!$companies->isEmpty()) {
         $cache_key = self::getFeaturedCompaniesCacheKey();
         $i = 1;
         foreach ($companies as $companyObj) {
             Redis::zadd($cache_key, $i, $companyObj->str_id);
             $i++;
         }
     }
 }
Ejemplo n.º 4
0
 public static function addJobToDmaCache($code, $job_id, $score)
 {
     $cache_key = self::getJobsByDmaCahceKey($code);
     $exists = Redis::exists($cache_key);
     if (empty($exists)) {
         self::requestJobsByDmaCache($code);
     } else {
         Redis::zadd($cache_key, $score, $job_id);
     }
 }
Ejemplo n.º 5
0
 private static function requestDmaListCache($str)
 {
     $cache_key = self::getDmaListCacheKey($str);
     $map = self::where('city_state', 'like', $str . '%')->select('code', 'city_state')->orderBy('city_state', 'asc')->take(20)->get();
     if (!empty($map)) {
         $i = 1;
         foreach ($map as $record) {
             $location_record = ['region' => $record->city_state, 'code' => $record->code];
             Redis::zadd($cache_key, $i, json_encode($location_record));
             $i++;
         }
     } else {
         // set an empty values to reduce db hit
         Redis::zadd($cache_key, $i, json_encode([]));
     }
     Redis::expire($cache_key, 60 * 60 * 24 * 7);
 }
Ejemplo n.º 6
0
 public static function addJobToKeywordCache($keyword, $job_id, $score)
 {
     $cache_key = self::getKeywordJobsCacheKey($keyword);
     $exists = Redis::exists($cache_key);
     if (empty($exists)) {
         self::requestKeywordJobsCache($keyword);
     } else {
         Redis::zadd($cache_key, $score, $job_id);
     }
 }