/** * Collect info from socials * (get twitter followers / facebook likes count) * * @access public * @param $post */ public function check_for_sending($post) { try { $date_now = new DateTime('UTC'); $now = $date_now->getTimestamp(); $post['schedule_date'] = (int) $post['schedule_date']; $social_post = Social_post::inst((int) $post['id']); log_message('TASK_DEBUG', __FUNCTION__ . ' > ' . 'ID - ' . $post['id'] . '; sch_date - ' . $post['schedule_date'] . '; now - ' . $now); if ($post['schedule_date'] <= $now) { $this->load->library('Socializer/Socializer'); $attachment = $social_post->media; if (!is_array($post['post_to_socials'])) { $post['post_to_socials'] = unserialize($post['post_to_socials']); } if (!is_array($post['post_to_groups'])) { $post['post_to_groups'] = unserialize($post['post_to_groups']); } if ($attachment->id) { $post['image_name'] = basename($attachment->path); if ($attachment->type == 'video') { Social_post::inst()->_send_video_to_socials($post, $post['user_id']); } else { Social_post::inst()->_send_to_social($post, $post['user_id']); } } else { Social_post::inst()->_send_to_social($post, $post['user_id']); } $social_post->delete(); log_message('TASK_SUCCESS', __FUNCTION__ . ' > ' . 'ID - ' . $post['id']); } } catch (Exception $e) { log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'ID - ' . $post['id'] . "\n" . $e->getMessage()); } }
public function minutely_posts() { $posts = Social_post::inst()->where('posting_type', 'schedule')->get(); foreach ($posts as $_post) { $post = $_post->to_array(); $now = strtotime('now'); $social_post = Social_post::inst((int) $post['id']); if ($post['schedule_date'] > $now - 60 && $post['schedule_date'] < $now + 60) { $post['post_to_social'] = array(); if ($post['posted_to_twitter']) { array_push($post['post_to_social'], 'twitter'); } if ($post['posted_to_facebook']) { array_push($post['post_to_social'], 'facebook'); } $this->load->library('Socializer/Socializer'); $attachment = $social_post->media; if ($attachment->id) { $post['image_name'] = basename($attachment->path); if ($attachment->type == 'video') { Social_post::inst()->_send_video_to_socials($post, $post['user_id']); } else { Social_post::inst()->_send_to_social($post, $post['user_id']); } } else { Social_post::inst()->_send_to_social($post, $post['user_id']); } $social_post->delete(); } } }
/** * @access public * @return void */ public function run() { try { log_message('CRON_START', __FUNCTION__ . ' > Start post cron'); $date = new DateTime('UTC'); $start_of_day = new DateTime('00:00:00 UTC'); $end_of_day = new DateTime('23:59:59 UTC'); /** @var Cron_day $day */ $day = Cron_day::inst()->where('day', $date->format('l'))->get(); $cron_posts = $day->social_post_cron->get(); /** @var Social_post_cron $cron_post */ foreach ($cron_posts as $cron_post) { $times = $cron_post->getTimeInUtc(); $social_posts = $cron_post->social_post->where(array('schedule_date >=' => $start_of_day->getTimestamp(), 'schedule_date <=' => $end_of_day->getTimestamp()))->get(); if (count($times) && count($times) != $social_posts->count()) { $timezone = new DateTimeZone($cron_post->timezone); $date->setTimezone($timezone); foreach ($times as $time) { $_date = new DateTime($time); $_date->setTimezone($timezone); if (!$date->diff($_date)->invert) { $social_post = new Social_post(); $social_post->schedule_date = $_date->getTimestamp(); $social_post->user_id = $cron_post->user_id; $social_post->description = $cron_post->description; $social_post->post_cron_id = $cron_post->id; $social_post->post_to_groups = serialize([$cron_post->profile_id]); $social_post->post_to_socials = $cron_post->post_to_socials; $social_post->posting_type = 'schedule'; $social_post->timezone = $cron_post->timezone; $social_post->url = $cron_post->url; $social_post->profile_id = $cron_post->profile_id; $social_post->category_id = 0; $social_post->save($cron_post->media->get(1), 'media'); log_message('CRON_START', __FUNCTION__ . ' > Schedule post was added. ' . 'Socials: ' . implode(', ', $cron_post->post_to_socials) . '; ' . 'User id: ' . $cron_post->user_id . '; ' . 'Date: ' . $_date->format('Y-m-d H:i') . '; '); } } } } } catch (Exception $e) { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . $e->getMessage()); } }
public function index() { if ($this->c_user->isTrialPlanEnds()) { $this->addFlash(lang('subscription_ends_error', [site_url('subscript/plans')]), 'error'); } // UNCOMMENT TO USE // get average google rank for all keywords for chart in range $keyword_rank = Keyword::average_for_range($this->c_user->id, '-30 days', 'today'); // average result for all the range $keywords_trending = Keyword::average_for_range($this->c_user->id, '-30 days', 'today', FALSE); // average for each day in range // analytics data $google_access_token = Access_token::getByTypeAndUserId('googlea', $this->c_user->id); list($ga_visits_chart, $ga_visits_count) = $google_access_token->google_analytics_dashboard_visits(); $review = new Review(); $last_reviews_count = $review->last_period_count($this->c_user->id, $this->profile->id); $review->clear(); $social_values = Social_value::inst(); $social_values->set_values($this->c_user->id, $this->profile->id, array('from' => date('Y-m-d', strtotime('-30 days')), 'to' => date('Y-m-d', time()))); $all_socials_data = $social_values->get_data(); $monthly_trending = array('reviews' => $review->last_month_trending($this->c_user->id, $this->profile->id), 'traffic' => $ga_visits_chart, 'keywords' => $keywords_trending, 'twitter_followers' => $all_socials_data['twitter'], 'facebook_likes' => $all_socials_data['facebook']); $keywordsForHighlight = Mention_keyword::inst()->get_for_highlight($this->c_user->id, 0); CssJs::getInst()->add_js('www.google.com/jsapi', 'external', 'footer'); CssJs::getInst()->add_js(array('libs/lodash.compat.js', 'libs/highcharts/highcharts.js'))->c_js(); $opportunities = $this->getOpportunities(); if (!empty($opportunities['web_radar'])) { CssJs::getInst()->add_js('controller/webradar/index.js'); } JsSettings::instance()->add(array('monthly_trending' => $monthly_trending, 'dashboard' => true, 'keywords' => $keywordsForHighlight, 'opportunities' => $opportunities)); $summary = array('reviews' => (int) $last_reviews_count, 'fb_likes' => (int) $all_socials_data['likes_count'], 'twiter_followers' => (int) $all_socials_data['followers_count'], 'web_traffic' => (int) $ga_visits_count, 'google_rank' => (int) round($keyword_rank, 3)); $this->isSupportScheduledPosts = $this->getAAC()->isGrantedPlan('scheduled_posts'); $this->load->helper('my_url_helper'); $this->template->set('isSupportScheduledPosts', $this->isSupportScheduledPosts); $this->template->set('socials', Social_post::getActiveSocials($this->profile->id)); $this->is_user_set_timezone = User_timezone::is_user_set_timezone($this->c_user->id); JsSettings::instance()->add(array('twitterLimits' => array('maxLength' => 140, 'midLength' => 117, 'lowLength' => 94), 'twitterLimitsText' => lang('twitter_error'), 'linkedinLimits' => array('maxLength' => 400), 'linkedinLimitsText' => lang('linkedin_error'))); CssJs::getInst()->add_css(array('custom/pick-a-color-1.css')); CssJs::getInst()->add_js(array('libs/jq.file-uploader/jquery.iframe-transport.js', 'libs/jq.file-uploader/jquery.fileupload.js', 'libs/fabric/fabric.min.js', 'libs/fabric/StackBlur.js', 'libs/color/tinycolor-0.9.15.min.js', 'libs/color/pick-a-color-1.2.3.min.js')); CssJs::getInst()->c_js('social/create', 'post_update'); CssJs::getInst()->c_js('social/create', 'post_cron'); CssJs::getInst()->c_js('social/create', 'post_attachment'); CssJs::getInst()->c_js('social/create', 'social_limiter'); CssJs::getInst()->c_js('social/create', 'schedule_block'); CssJs::getInst()->c_js('social/create', 'bulk_upload'); $this->template->set('is_user_set_timezone', User_timezone::is_user_set_timezone($this->c_user->id)); $user_posts = Social_post::inst()->get_user_scheduled_posts($this->c_user->id, $this->profile->id, 1, 3, 'all'); $this->template->set('posts', $user_posts); $this->load->helper('Image_designer_helper'); $this->template->set('imageDesignerImages', Image_designer::getImages()); $this->template->set('summary', $summary); $this->template->set('opportunities', $opportunities); $this->template->set('need_welcome_notification', User_notification::needShowNotification($this->c_user->id, User_notification::WELCOME)); $this->template->render(); }
/** * Daily social statistic collect * Add new access token to Queue * * @access public * @return void */ public function run() { $posts = Social_post::inst()->where('posting_type', 'schedule')->get(); log_message('TASK_DEBUG', __FUNCTION__ . ' > ' . 'scheduled posts count - ' . $posts->result_count()); $acc = $this->getAAC(); /** @var Social_post $_post */ foreach ($posts as $_post) { $user = new User($_post->user_id); if (!$user->exists()) { continue; } $acc->setUser($user); if (!$acc->isGrantedPlan('scheduled_posts')) { continue; } $args = $_post->to_array(); $this->jobQueue->addJob('tasks/scheduled_posts_task/check_for_sending', $args, array('thread' => self::SCHEDULED_THREAD)); } }
public function delete($post_id) { if (Social_post::inst()->delete_scheduled((int) $post_id, $this->c_user->id)) { $this->addFlash(lang('delete_scheduled_success'), 'success'); } else { $this->addFlash(lang('delete_scheduled_error')); } redirect('social/scheduled'); }
public function delete($user_id = NULL) { $user = $this->prepare_user($user_id); if ($this->ion_auth->is_admin($user_id)) { $url = 'manage_admins'; } elseif ($this->ion_auth->is_manager($user_id)) { $url = 'manage_accounts'; } else { $url = 'admin_users'; } if ($this->ion_auth->is_collaborator($user_id)) { $this->c_user->delete($user); } $user_deleted = $this->ion_auth->delete_user($user->id); if (!$user_deleted) { $this->addFlash(lang('delete_error', [$this->ion_auth->errors()])); redirect('admin/admin_users'); } $sender = $this->get('core.mail.sender'); $sender->sendUserDeleteMail(array('user' => $user)); $access_token = new Access_token(); $access_token->where('user_id', $user->id)->get()->delete_all(); $directory_user = new Directory_User(); $directory_user->where('user_id', $user->id)->get()->delete_all(); $facebook_fanpage = new Facebook_Fanpage(); $facebook_fanpage->where('user_id', $user->id)->get()->delete_all(); $keyword = new Keyword(); $keyword->where('user_id', $user->id)->get(); foreach ($keyword as $k) { $keyword_rank = new Keyword_rank(); $keyword_rank->where('keyword_id', $k->id)->get()->delete_all(); } $keyword->delete_all(); $media = new Media(); $media->where('user_id', $user->id)->get()->delete_all(); $post = new Post(); $post->where('user_id', $user->id)->get(); foreach ($post as $p) { $post_social = new Post_social(); $post_social->where('post_id', $p->id)->get()->delete_all(); } $post->delete_all(); $review = new Review(); $review->where('user_id', $user->id)->get()->delete_all(); $reviews_notification = new Reviews_notification(); $reviews_notification->where('user_id', $user->id)->get()->delete_all(); $rss_feeds_users = new Rss_feeds_users(); $rss_feeds_users->where('user_id', $user->id)->get()->delete_all(); $social_post = new Social_post(); $social_post->where('user_id', $user->id)->get()->delete_all(); $social_value = new Social_value(); $social_value->where('user_id', $user->id)->get()->delete_all(); $user_additional = new User_additional(); $user_additional->where('user_id', $user->id)->get()->delete_all(); $user_feed = new User_feed(); $user_feed->where('user_id', $user->id)->get()->delete_all(); $user_timezone = new User_timezone(); $user_timezone->where('user_id', $user->id)->get()->delete_all(); $this->addFlash(lang('delete_success'), 'success'); redirect('admin/' . $url); }
public function add_cron_post($post) { if ($this->template->is_ajax()) { $post['post_to_groups'] = array($this->profile->id); $post['timezone'] = User_timezone::get_user_timezone($this->c_user->id); $post['user_id'] = $this->c_user->id; $errors = Social_post::validate_post($post); if (empty($errors)) { $errors = Social_post_cron::validate_cron($post); if (empty($errors)) { Social_post_cron::add_new_post($post, $this->c_user->id, $this->profile->id); $result['success'] = true; $result['message'] = lang('post_was_successfully_added'); } else { $result['success'] = false; $result['errors'] = $errors; } } else { $result['success'] = false; $result['errors'] = $errors; } echo json_encode($result); } exit; }
public static function post_video($feeds, $user_id, $profile_id) { if ($feeds['posting_type'] != 'schedule') { if (isset($feeds['post_id'])) { $post = Social_post::inst((int) $feeds['post_id']); $post->delete(); } self::_send_video_to_socials($feeds, $user_id); } else { $post = isset($feeds['post_id']) ? new self((int) $feeds['post_id']) : new self(); $post->from_array($feeds, array('description', 'posting_type')); $post->post_to_groups = serialize($feeds['post_to_groups']); $post->post_to_socials = serialize($feeds['post_to_socials']); $post->user_id = $user_id; $post->profile_id = $profile_id; $post->title = 'from ' . clear_domain(site_url()); $post->category_id = isset($feeds['category_id']) ? (int) $feeds['category_id'] : 0; $post->schedule_date = self::_get_schedule_date($feeds); $post->timezone = $feeds['timezone']; self::_save_attachment($post, $feeds, $user_id); $post->save(); } }
/** * @access public * * @param $args * * @throws Exception */ public function send($args) { $this->load->library('Simplepie'); $this->load->library('Socializer/socializer'); $now = new DateTime('UTC'); $now_timestamp = $now->getTimestamp(); $now->modify('-10 minutes'); $cache_location = APPPATH . 'cache/rss'; if (!file_exists($cache_location) && !is_writable($cache_location)) { $old = umask(0); mkdir($cache_location, 0777); umask($old); } $post_date = new \DateTime('UTC'); // $post_date->modify('30 minutes'); foreach ($args as $token) { try { log_message('TASK_DEBUG', __FUNCTION__ . ' > ' . 'Rss send' . $this->createAddidationalData($token)); $user = new User($token['user_id']); $rss_feeds = Rss_feed::inst()->user_custom_feeds($token['user_id'], $token['profile_id']); foreach ($rss_feeds as $rss) { if (!$rss->last_check) { $last_check = $now->getTimestamp(); } else { $last_check = $rss->last_check; } $this->simplepie->set_feed_url($rss->link); $this->simplepie->set_cache_location($cache_location); $this->simplepie->init(); $this->simplepie->handle_content_type(); $rss_feed = $this->simplepie->get_items(0, self::RSS_LIMIT); foreach ($rss_feed as $rss_post) { $title = $rss_post->get_title(); $link = $rss_post->get_link(); $date = new DateTime($rss_post->get_date()); if ($date->getTimestamp() >= $last_check) { $social_post = new Social_post(); $social_post->schedule_date = $post_date->getTimestamp(); $social_post->user_id = $token['user_id']; $social_post->description = $title; $social_post->post_to_groups = serialize([$token['profile_id']]); $social_post->post_to_socials = serialize([$token['type']]); $social_post->posting_type = 'schedule'; $social_post->timezone = $user->timezone; $social_post->url = $link; $social_post->profile_id = $token['profile_id']; $social_post->category_id = 0; $social_post->save(); log_message('TASK_SUCCESS', __FUNCTION__ . ' > ' . 'RSS: Will posted in ' . $post_date->format('d/m/Y h:i:s') . ' to ' . ucfirst($token['type']) . '.' . $this->createAddidationalData($token)); $post_date->modify('1 minutes'); } else { break; } } } } catch (Exception $e) { log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'RSS: ' . $this->createAddidationalData($token) . "\n" . $e->getMessage()); } } foreach ($args as $token) { $rss_feeds = Rss_feed::inst()->user_custom_feeds($token['user_id'], $token['profile_id']); foreach ($rss_feeds as $rss) { $rss->last_check = $now_timestamp; $rss->save(); } } }
public function delete($user_id = NULL) { $user = $this->prepare_user($user_id); $ia = $this->ion_auth; if ($ia->is_collaborator($user_id) && $this->c_user->isManager($user_id)) { $this->c_user->delete(new User($user_id)); $user_deleted = $this->ion_auth->delete_user($user->id); if (!$user_deleted) { $this->addFlash(lang('delete_error', [$this->ion_auth->errors()])); redirect('settings/collaboration'); } $sender = $this->get('core.mail.sender'); $sender->sendUserDeleteMail(array('user' => $user)); $media = new Media(); $media->where('user_id', $user->id)->get()->delete_all(); $post = new Post(); $post->where('user_id', $user->id)->get(); foreach ($post as $p) { $post_social = new Post_social(); $post_social->where('post_id', $p->id)->get()->delete_all(); } $post->delete_all(); $social_post = new Social_post(); $social_post->where('user_id', $user->id)->get()->delete_all(); $this->addFlash(lang('delete_success'), 'success'); } else { $this->addFlash(lang('permission_error')); } redirect('settings/collaboration'); }