Example #1
0
 public function show($groupName)
 {
     $group = Group::name($groupName)->with('creator')->firstOrFail();
     $group->checkAccess();
     $stats = ['contents' => intval(Content::where('group_id', $group->getKey())->count()), 'comments' => intval(Content::where('group_id', $group->getKey())->sum('comments')), 'entries' => intval(Entry::where('group_id', $group->getKey())->count()), 'banned' => intval(GroupBan::where('group_id', $group->getKey())->count()), 'subscribers' => $group->subscribers, 'moderators' => intval(GroupModerator::where('group_id', $group->getKey())->count())];
     return array_merge($group->toArray(), ['stats' => $stats]);
 }
Example #2
0
 public function delete()
 {
     foreach ($this->replies as $reply) {
         $reply->delete();
     }
     Content::where('id', $this->content_id)->decrement('comments_count');
     return parent::delete();
 }
Example #3
0
 public function getURLTitle()
 {
     $url = Input::get('url');
     try {
         $client = new Client($url);
         $response = $client->get()->send();
     } catch (Exception $e) {
         return Response::json(['status' => 'error']);
     }
     // Only HTML content-type is supported
     $contentType = $response->getHeader('Content-Type');
     if (strpos($contentType, 'text/html') === false) {
         return Response::json(['status' => 'error']);
     }
     $html = $response->getBody();
     // Fix for HTML5
     $html = preg_replace('/<meta charset="(.+)">/', '<meta http-equiv="Content-Type" content="text/html; charset=$1">', $html);
     $contentType = $response->getHeader('Content-Type');
     // Small hack to use encoding used on the given page
     $encodingHint = '';
     if (preg_match('/charset=(.*)/', $contentType, $results)) {
         $encodingHint = '<meta http-equiv="Content-Type" content="text/html; charset=' . $results[1] . '">';
     }
     $doc = new \DOMDocument('1.0', 'UTF-8');
     @$doc->loadHTML($encodingHint . $html);
     $xpath = new \DOMXPath($doc);
     $title = '';
     $description = '';
     // Try to get OpenGraph data first
     try {
         $title = $xpath->query('/html/head/meta[@property="og:title"]')->item(0)->attributes->getNamedItem('content')->nodeValue;
     } catch (Exception $e) {
     }
     try {
         $description = $xpath->query('/html/head/meta[@property="og:description"]')->item(0)->attributes->getNamedItem('content')->nodeValue;
     } catch (Exception $e) {
     }
     // Use title and meta data if OpenGraph data wasn't found
     try {
         if (empty($title)) {
             $title = $xpath->query('/html/head/title')->item(0)->nodeValue;
         }
     } catch (Exception $e) {
     }
     try {
         if (empty($description)) {
             $description = $xpath->query('/html/head/meta[@name="description"]')->item(0)->attributes->getNamedItem('content')->nodeValue;
         }
     } catch (Exception $e) {
     }
     $title = Str::limit($title, 128);
     $description = Str::limit($description, 255);
     // Find duplicates
     $duplicates = Content::where('url', $url)->where('group_id', Input::get('group'))->get(['title', 'group_id'])->toArray();
     return Response::json(['status' => 'ok', 'title' => $title, 'description' => $description, 'duplicates' => $duplicates]);
 }
Example #4
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $dayBefore = Carbon::now()->subDay();
     $content = Content::where('created_at', '>', $dayBefore)->orderBy('uv', 'desc')->firstOrFail();
     $params = ['access_token' => config('social.facebook.page_token'), 'name' => $content->title, 'link' => route('content_comments', $content->getKey()), 'description' => $content->description];
     if ($content->thumbnail) {
         $params['picture'] = $content->getThumbnailPath(500, 250);
     }
     Guzzle::post('https://graph.facebook.com/strimoid/feed', ['body' => $params]);
 }
Example #5
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $dayBefore = Carbon::now()->subDay();
     $content = Content::where('created_at', '>', $dayBefore)->orderBy('uv', 'desc')->firstOrFail();
     $client = new Client(['base_url' => 'https://api.twitter.com/1.1/', 'defaults' => ['auth' => 'oauth']]);
     $oauth = new Oauth1(['consumer_key' => config('social.twitter.consumer_key'), 'consumer_secret' => config('social.twitter.consumer_secret'), 'token' => config('social.twitter.token'), 'token_secret' => config('social.twitter.token_secret')]);
     $client->getEmitter()->attach($oauth);
     $params = ['status' => Str::limit($content->title, 100) . ' https://strm.pl/c/' . $content->hashId()];
     $client->post('statuses/update.json', ['body' => $params]);
 }
Example #6
0
 public function getURLTitle()
 {
     $url = request('url');
     $data = OEmbed::getData($url);
     $title = data_get($data, 'meta.title', '');
     $title = str_limit($title, 128);
     $description = data_get($data, 'meta.description', '');
     $description = str_limit($description, 255);
     // Find duplicates
     $duplicates = Content::where('url', $url)->get(['title', 'group_id'])->toArray();
     return ['status' => 'ok', 'title' => $title, 'description' => $description, 'duplicates' => $duplicates];
 }
Example #7
0
 public function search()
 {
     if (Input::has('q')) {
         $keywords = preg_replace('/((\\w+):(\\w+\\pL.))+\\s?/i', '', Input::get('q'));
         switch (Input::get('t')) {
             case 'e':
                 $builder = Entry::where('text', 'like', '%' . $keywords . '%');
                 break;
             case 'g':
                 $builder = Group::where('name', 'like', '%' . $keywords . '%')->orWhere('urlname', 'like', '%' . $keywords . '%');
                 break;
             case 'c':
             default:
                 $builder = Content::where(function ($query) use($keywords) {
                     $query->where('title', 'like', '%' . $keywords . '%')->orWhere('description', 'like', '%' . $keywords . '%');
                 });
                 break;
         }
         $this->builder = $builder;
         $this->setupFilters(Input::get('q'));
         $results = $this->builder->paginate(25);
     }
     return view('search.main', compact('results'));
 }
Example #8
0
 public function delete()
 {
     Content::where('id', $this->content_id)->decrement('related_count');
     return parent::delete();
 }