public function create($object_id) { $newComment = Comment::create(['object_id' => $object_id, 'user_id' => Auth::id(), 'comment' => Input::get('comment.comment'), 'parent' => Input::get('comment.parent'), 'depth' => 0]); $comment = Comment::where('comment_id', $newComment->comment_id)->with('user')->first(); Redis::sadd('objects:toReindex', $object_id); return response()->json($comment); }
public function all($limit = 10) { if (!($tagKeys = Redis::keys("tags:{$this->language}:*"))) { $posts = $this->loader->loadList(); foreach ($posts as $item) { $post = $this->loader->load($item['slug'], $item); foreach ($post['tags'] as $tag) { if (Redis::sadd(Key::tags($tag), $item['slug']) && !in_array(Key::tags($tag), $tagKeys)) { $tagKeys[] = Key::tags($tag); } } } } $tags = []; foreach ($tagKeys as $key) { $chunks = explode(':', $key); $key = array_pop($chunks); $tags[$key] = Redis::scard(Key::tags($key)); } arsort($tags); return array_slice($tags, 0, $limit); }
/** * 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"; } }
private static function requestDmaCache($dma_code) { $cache_key = self::getDmaCacheKey($dma_code); $sql = "SELECT a.id, a.dma_code, aj.job_id\n \t\t\t FROM ad_jobs aj, ads a\n \t\t\t WHERE aj.ad_id = a.id\n \t\t\t AND a.is_active = 1\n \t\t\t\tAND dma_code = {$dma_code}"; $ads = DB::select($sql); foreach ($ads as $ad) { $ad_details_cache_key = self::getAdDetailsCacheKey($ad->dma_code, $ad->id, $ad->job_id); Redis::sadd($cache_key, $ad_details_cache_key); } }
public function download($object_id) { $object = Object::find($object_id); // Only increment the downloads table if the same user has not downloaded it in the last hour (just like views) $mostRecentDownload = Download::where('user_id', Auth::id())->where('object_id', $object_id)->first(); if ($mostRecentDownload === null || $mostRecentDownload->created_at->diffInSeconds(Carbon::now()) > 3600) { Download::create(array('user_id' => Auth::id(), 'object_id' => $object_id)); // Reindex object Redis::sadd('objects:toReindex', $object_id); } if ($object->hasFile()) { return response()->json(null, 204); } else { if ($object->type == MissionControlType::Tweet) { $data = $object->tweet_text; } else { if ($object->type == MissionControlType::Comment) { if ($object->subtype == MissionControlSubtype::RedditComment) { $data = $object->reddit_comment_text; } else { if ($object->subtype == MissionControlSubtype::NSFComment) { $data = $object->nsf_comment_text; } } } else { if ($object->type == MissionControlType::Article) { $data = $object->article_text; } else { if ($object->type == MissionControlType::Text) { $data = $object->summary; } } } } return response()->make($data, 200, array('Content-type' => 'text/plain', 'Content-Disposition' => 'attachment;filename="' . str_slug($object->title) . '.txt"')); } }
private function reindex() { Redis::sadd('objects:toReindex', $this->object_id); }
public static function addCompanyToKeywordCache($keyword, $str_id) { $cache_key = self::getKeywordCompaniesCacheKey($keyword); $exists = Redis::exists($cache_key); if (empty($exists)) { self::requestKeywordCompaniesCache($keyword); } else { Redis::sadd($cache_key, $str_id); } }