/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->info('Started...');
     Subscription::chunk(200, function ($subscriptions) {
         $accepted = 0;
         $declined = 0;
         $client = new Paylane\PayLaneRestClient('adubiel', 'dru9pra2');
         foreach ($subscriptions as $subscription) {
             $expiration = Carbon::createFromTimeStamp(strtotime($subscription->expires_at));
             if ($expiration->isToday() || $expiration->isPast()) {
                 $sale = $subscription->payment()->orderBy('id', 'desc')->where('is_success', '=', 1)->orWhere('is_success', '=', 2)->first();
                 if ($sale->is_success == 2) {
                     $resale_params = array('id_authorization' => $sale->sale_id, 'amount' => 149.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info');
                     $status = $client->resaleByAuthorization($resale_params);
                 } else {
                     if ($sale->is_success == 1) {
                         $params = array('id_sale' => $sale->sale_id, 'amount' => 149.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info');
                         $status = $client->resaleBySale($params);
                     }
                 }
                 if ($client->isSuccess()) {
                     $accepted++;
                     $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'sale_id' => $status['id_sale']));
                     $subscription->expires_at = Carbon::now()->addDays(30);
                     $subscription->is_active = 1;
                     $subscription->save();
                     $user = User::find($subscription->user_id);
                     $user->level = 2;
                     $user->save();
                     $configs = BoardConfig::where('user_id', '=', $subscription->user_id)->get();
                     if ($configs->count() > 0) {
                         foreach ($configs as $config) {
                             $config->is_active = 1;
                             $config->save();
                         }
                     }
                     EmailNotification::where('subscription_id', '=', $subscription->id)->delete();
                     $faktura = $subscription->company_id == 0 ? false : true;
                     Event::fire('invoice.email', array($subscription->user_id, $subscription->id, $payment->id, $faktura));
                 } else {
                     $declined++;
                     $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'is_success' => 0, 'sale_id' => $status['error']['error_number']));
                     Event::fire('deactivate.subscription', array($subscription->id, $payment->created_at));
                 }
             }
         }
         $this->info('Accepted:' . $accepted);
         $this->info('Declined:' . $declined);
     });
     $this->info('Done');
 }
Beispiel #2
0
             $status = $client->resaleByAuthorization($resale_params);
         } else {
             if ($sale->is_success == 1) {
                 $params = array('id_sale' => $sale->sale_id, 'amount' => 149.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info');
                 $status = $client->resaleBySale($params);
             }
         }
         if ($client->isSuccess()) {
             $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'sale_id' => $status['id_sale']));
             $subscription->expires_at = Carbon::now()->addDays(30);
             $subscription->is_active = 1;
             $subscription->save();
             $user = User::find($subscription->user_id);
             $user->level = 2;
             $user->save();
             $configs = BoardConfig::where('user_id', '=', $subscription->user_id)->get();
             if ($configs->count() > 0) {
                 foreach ($configs as $config) {
                     $config->is_active = 1;
                     $config->save();
                 }
             }
             EmailNotification::where('subscription_id', '=', $subscription->id)->delete();
             $faktura = $subscription->company_id == 0 ? false : true;
             Event::fire('invoice.email', array($subscription->user_id, $subscription->id, $payment->id, $faktura));
         } else {
             $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'is_success' => 0));
             Event::fire('deactivate.subscription', array($subscription->id, $payment->created_at));
         }
     }
 }
 /**
 def sslify_instagram_cdn_url(url):
     """Intercept IG CDN urls and serve using a SSL-friendly CDN instead"""
     replace_prefixes = (
         ('^http://images.ak.instagram.com(.*)$', '//distillery.s3.amazonaws.com%s'),
         ('^http://distilleryimage([0-9]*).ak.instagram.com(.*)$', '//distilleryimage%s.s3.amazonaws.com%s'),
         ('^http://origincache-([a-z]*).fbcdn.net(.*)$', '//origincache-%s.fbcdn.net%s'),
         ('^http://distilleryimage([0-9]*).s3.amazonaws.com(.*)$', '//distilleryimage%s.s3.amazonaws.com%s'),
         ('^http://scontent-([a-z]).cdninstagram.com(.*)$', '//scontent-%s.cdninstagram.com%s'),
         ('^http://photos-[a-z].ak.instagram.com/hphotos-ak-[0-9a-z]{3,4}/(.*)$', '//origincache-frc.fbcdn.net/%s'),
     )
     for prefix, replacement in replace_prefixes:
         results = re.findall(prefix, url)
         if not results:
             continue
         return replacement % results[0]
     return url
 */
 public function postsToHtml($posts, $boardId = NULL, $featured = NULL)
 {
     $html = '';
     $base = URL::to('/');
     if (isset($boardId)) {
         $config = BoardConfig::where('board_id', '=', $boardId)->first();
         if (Auth::check()) {
             $user = Auth::user();
             if ($user->id == $config->user_id) {
                 $owned = true;
             }
         }
         if ($config->filter != '') {
             $filter = explode(',', $config->filter);
         }
         if ($config->banned_users != '') {
             $users = explode(',', $config->banned_users);
         }
         $featuredPosts = FeaturedPost::where('board_id', '=', $config->board_id);
         if ($featured == true && $featuredPosts->count() > 0) {
             $hasFeatured = true;
             foreach ($featuredPosts->get() as $post) {
                 $html .= $post['html'];
             }
         }
     }
     shuffle($posts);
     foreach ($posts as $post) {
         if (strlen($post['username']) > 0) {
             if (isset($filter) && $filter != '' && !empty($post['caption'])) {
                 if ($this->filterWords($post['caption'], $filter)) {
                     continue;
                 }
             }
             if (isset($users) && $users != '') {
                 if (in_array($post['username'], $users)) {
                     continue;
                 }
             }
             if (isset($featured) && $featuredPosts->count() > 0) {
                 if ($this->checkIfFeatured($featuredPosts, $post['post_id'])) {
                     continue;
                 }
             }
             $html .= '<div data-post-id="' . $post['post_id'] . '" class="post post-' . $post['vendor'] . ' post-type-' . $post['post_type'] . '">';
             $html .= '<div class="filter filter-' . $post['vendor'] . ' pull-right"><i class="fa fa-' . $post['vendor'] . '"></i></div>';
             $html .= '<div class="user-info pull-left">';
             if ($post['vendor'] == 'instagram') {
                 $profilePic = $this->sslInstagramProfilePic($post['user_img_url']);
                 $html .= '<img src="' . $profilePic . '" alt="" />';
             } else {
                 $html .= '<img src="' . str_replace('http://', '//', $post['user_img_url']) . '" alt="" />';
             }
             if ($post['vendor'] == 'twitter') {
                 $html .= '<a href="http://www.twitter.com/' . $post['username'] . '" target="_blank" rel="nofollow">' . $post['username'] . '</a>';
                 $post['date_created'] = Carbon::createFromFormat('m-d-y H:i:s', $post['date_created'])->toIso8601String();
             } else {
                 if ($post['vendor'] == 'instagram') {
                     $html .= '<a href="http://www.instagram.com/' . $post['username'] . '" target="_blank" rel="nofollow">' . $post['username'] . '</a>';
                     $post['date_created'] = Carbon::createFromFormat('m-d-y H:i:s', $post['date_created'])->toIso8601String();
                 } else {
                     if ($post['vendor'] == 'google-plus') {
                         $html .= '<a href="https://plus.google.com/' . $post['user_id'] . '" target="_blank" rel="nofollow">' . $post['username'] . '</a>';
                         $post['date_created'] = Carbon::parse($post['date_created'])->toIso8601String();
                     } else {
                         if ($post['vendor'] == 'facebook') {
                             $html .= '<a href="http://facebook.com/profile.php?id=' . $post['user_id'] . '" target="_blank" rel="nofollow">' . $post['username'] . '</a>';
                             $post['date_created'] = Carbon::parse($post['date_created'])->toIso8601String();
                         } else {
                             if ($post['vendor'] == 'vine') {
                                 $html .= '<a href="https://vine.co/u/' . $post['user_id'] . '" target="_blank" rel="nofollow">' . $post['username'] . '</a>';
                                 $post['date_created'] = Carbon::createFromFormat('Y-m-d H:i:s', $post['date_created'])->toIso8601String();
                             }
                         }
                     }
                 }
             }
             $html .= '<p><abbr class="timeago" title="' . $post['date_created'] . '">' . $post['date_created'] . '</abbr></p>';
             $html .= '</div><div class="clearfix"></div>';
             if ($post['post_type'] == 'image') {
                 $post['img_url'] = str_replace('http://', '//', $post['img_url']);
                 if ($post['vendor'] == 'instagram') {
                     $html .= '<a href="' . $post['img_url'] . '" class="image-link">';
                     $html .= '<div class="post-img">';
                     $html .= '<img src="' . $post['img_url'] . '" alt="" />';
                     $html .= '</div>';
                     $html .= '</a>';
                 } else {
                     if ($post['vendor'] == 'twitter') {
                         $html .= '<a href="' . $post['img_url'] . '" class="image-link">';
                         $html .= '<div class="post-img">';
                         $html .= '<img src="' . $post['img_url'] . '" alt="" />';
                         $html .= '</div>';
                         $html .= '</a>';
                     } else {
                         $html .= '<a href="' . $post['img_url'] . '" class="image-link">';
                         $html .= '<div class="post-img">';
                         $html .= '<img src="' . $post['img_url'] . '" alt="" />';
                         $html .= '</div>';
                         $html .= '</a>';
                     }
                 }
             } else {
                 if ($post['post_type'] == 'video') {
                     $post['embed'] = str_replace('http://', '//', $post['embed']);
                     $post['img_url'] = str_replace('http://', '//', $post['img_url']);
                     if ($post['vendor'] == 'facebook') {
                         $html .= '<a href="' . $post['embed'] . '" target="_blank" class="video-link" rel="nofollow">';
                         $html .= '<div class="post-img">';
                         $html .= '<i class="fa fa-play"></i>';
                         $html .= '<img src="' . $post['img_url'] . '" alt="" />';
                         $html .= '</div>';
                         $html .= '</a>';
                     } else {
                         if ($post['vendor'] == 'instagram') {
                             $html .= '<a href="' . $post['img_url'] . '" target="_blank" data-video="' . $post['embed'] . '" class="video-link-popup" rel="nofollow">';
                             $html .= '<div class="post-img">';
                             $html .= '<i class="fa fa-play"></i>';
                             $html .= '<img src="' . $post['img_url'] . '" alt="" />';
                             $html .= '</div>';
                             $html .= '</a>';
                         } else {
                             if ($post['vendor'] == 'google-plus') {
                                 $html .= '<a href="' . $post['embed'] . '" target="_blank" class="video-link" rel="nofollow">';
                                 $html .= '<div class="post-img">';
                                 $html .= '<i class="fa fa-play"></i>';
                                 $html .= '<img src="' . $post['img_url'] . '" alt="" />';
                                 $html .= '</div>';
                                 $html .= '</a>';
                             } else {
                                 if ($post['vendor'] == 'vine') {
                                     $html .= '<a href="' . $post['img_url'] . '" target="_blank" data-video="' . $post['embed'] . '" class="video-link-popup" rel="nofollow">';
                                     $html .= '<div class="post-img">';
                                     $html .= '<i class="fa fa-play"></i>';
                                     $html .= '<img src="' . $post['img_url'] . '" alt="" />';
                                     $html .= '</div>';
                                     $html .= '</a>';
                                 } else {
                                     $html .= '<div class="post-img">';
                                     $html .= '<img src="' . $post['img_url'] . '" alt="" />';
                                     $html .= '</div>';
                                 }
                             }
                         }
                     }
                 }
             }
             if (!empty($post['caption'])) {
                 $caption = preg_replace('/(http|https|ftp|ftps)\\:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(\\/\\S*)?/', '', $post['caption']);
                 $caption = $this->removeEmoji($caption);
                 $html .= '<div class="post-description">';
                 $html .= '<p>' . preg_replace('/#([^\\s#]+)/', ' <a class="hashtag" href="' . $base . '/$1/szukaj">#$1</a>', $caption) . '</p>';
                 $html .= '</div>';
             }
             if (isset($owned) && $owned == true) {
                 $html .= '<div class="featured-post"><a data-post-id="' . $post['post_id'] . '" href="#" class="js-make-featured"><i class="fa fa-star"></i></a></div>';
             }
             $html .= '</div>';
         }
     }
     return $html;
 }
 public function showAddBoard()
 {
     if (Auth::check()) {
         $user = Auth::user();
         $boardCount = BoardConfig::where('user_id', '=', $user->id)->count();
         //dd($boardCount);
         if ($user->level == 1) {
             if ($boardCount < 1) {
                 $data['user'] = $user;
                 $data['title'] = $this->layout->title = 'Dodaj tablicę';
                 $this->layout->content = View::make('user.board-new', $data);
             } else {
                 return Redirect::to('/konto/tablice')->with('alert', array('type' => 'error', 'content' => 'Limit przekroczony! Zostań Pro i dodaj więcej tablic!'));
             }
         } else {
             if ($user->level == 2) {
                 if ($boardCount < 5) {
                     $data['user'] = $user;
                     $data['title'] = $this->layout->title = 'Dodaj tablicę';
                     $this->layout->content = View::make('user.board-new', $data);
                 } else {
                     return Redirect::to('/konto/tablice')->with('alert', array('type' => 'error', 'content' => 'Nie możesz dodać więcej tablic!'));
                 }
             }
         }
     }
 }