Beispiel #1
0
 public function social($social = 'facebook')
 {
     $this->load->helper('clicable_links');
     //$social = ($social === 'twitter') ? $social : 'facebook';
     $has_access = Access_token::inst()->get_by_type($social, $this->c_user->id)->exists();
     $this->template->set('has_access', $has_access);
     if ($has_access) {
         $page = max(1, intval(Arr::get($_GET, 'page', 1)));
         $per_page = 10;
         $keyword = Arr::get($_GET, 'keyword', 0);
         $keyword_query_str = $keyword ? '&keyword=' . $keyword : '';
         $keywords = Mention_keyword::inst()->dropdown($this->c_user->id);
         $use_dates = Arr::get($_GET, 'from') || Arr::get($_GET, 'to');
         $from = date('M j, Y', strtotime(Arr::get($_GET, 'from', 'yesterday')));
         $to = date('M j, Y', strtotime(Arr::get($_GET, 'to', 'today')));
         list($from, $to) = $this->getDatesFromRequest();
         $formatedFrom = $from->format($this->dateFormat);
         $formatedTo = $to->format($this->dateFormat);
         $dates = array('from' => $formatedFrom, 'to' => $formatedTo);
         $dates_query_str = '&from=' . urlencode($formatedFrom) . '&to=' . urlencode($formatedTo);
         $this->template->set('dates', $dates);
         $this->template->set('use_dates', $use_dates);
         $mentions = Mention::inst()->by_social($this->c_user->id, $social);
         if ($keyword) {
             $mentions->where('mention_keyword_id', $keyword);
         }
         $mentions->where('created_at >=', $from->getTimestamp())->where('created_at <=', $to->getTimestamp());
         $mentions->get_paged($page, $per_page);
         $keywords_for_highlight = Mention_keyword::inst()->get_for_highlight($this->c_user->id, intval($keyword));
         JsSettings::instance()->add(array('non_ajax_pagination' => true, 'keywords' => $keywords_for_highlight, 'keyword_query_str' => $keyword_query_str, 'keyword_query_id' => $keyword, 'dates_query_str' => $dates_query_str, 'dates' => $dates));
         CssJs::getInst()->c_js('social/activity', $social)->c_js();
         if ($social === 'facebook') {
             $profile_photo = User_additional::inst()->get_value($this->c_user->id, 'facebook_profile_photo');
             if (is_null($profile_photo)) {
                 try {
                     $this->load->library('Socializer/socializer');
                     $facebook = Socializer::factory('Facebook', $this->c_user->id);
                     $profile_picture = $facebook->get_profile_picture();
                     if (isset($profile_picture['picture']['data']['url'])) {
                         $profile_photo = $profile_picture['picture']['data']['url'];
                     }
                     if ($profile_photo) {
                         User_additional::inst()->set_value($this->c_user->id, 'facebook_profile_photo', $profile_photo);
                     }
                 } catch (Exception $e) {
                     $this->template->set('socializer_error', $e->getMessage());
                 }
             }
             $this->template->set('profile_photo', $profile_photo);
         }
         $this->template->set('keyword', $keyword);
         $this->template->set('keyword_query_str', $keyword_query_str);
         $this->template->set('keywords', $keywords);
         $this->template->set('mentions', $mentions);
     }
     $this->template->set('social', $social);
     $this->template->render();
 }
Beispiel #2
0
 protected function grabberments($mention_keyword_array)
 {
     try {
         $mention_keyword_id = Arr::get($mention_keyword_array, 'id');
         $mention_keyword = new Mention_keyword($mention_keyword_id);
         $error_info = 'mkwid: ' . Arr::get($mention_keyword_array, 'social', 'no soc') . '/' . $mention_keyword_id;
         if (!$mention_keyword->exists()) {
             throw new Exception($error_info . ' doesn\'t exist.');
         }
         if ($mention_keyword->is_deleted) {
             throw new Exception($error_info . ' is set for deletion.');
         }
         if (!$mention_keyword->user_id) {
             throw new Exception($error_info . ' has no user id.');
         }
         $user = new User($mention_keyword->user_id);
         if (!$user->exists()) {
             throw new Exception($error_info . ' has no user');
         }
         $social = Arr::get($mention_keyword_array, 'social');
         if (is_null($social)) {
             throw new Exception($error_info . ' invalid social');
         }
         $user_socials = Access_token::inst()->get_user_socials($mention_keyword->user_id);
         if (!in_array($social, $user_socials)) {
             throw new Exception($error_info . ' invalid social');
         }
         $this->load->library('mentioner');
         $mentioner = Mentioner::factory($user->id);
         $mention_keyword_data = array_merge($mention_keyword_array, array('keyword' => $mention_keyword->keyword, 'exact' => $mention_keyword->exact, 'other_fields' => $mention_keyword->other_fields));
         if ($social === 'facebook') {
             $data = $mentioner->posts($mention_keyword_data, $mention_keyword_array);
         } else {
             if ($social === 'twitter') {
                 $data = $mentioner->tweets($mention_keyword_data, $mention_keyword_array);
             } else {
                 if ($social === 'google') {
                     $data = $mentioner->activities($mention_keyword_data, $mention_keyword_array);
                 } else {
                     if ($social === 'instagram') {
                         $data = $mentioner->tags($mention_keyword_data, $mention_keyword_array);
                     } else {
                         $data = array();
                     }
                 }
             }
         }
         if (!is_array($data)) {
             throw new Exception($error_info . ' no results for mentions, not an array. mkwid: ');
         }
         if ($user->ifUserHasConfigValue('auto_follow_twitter')) {
             $autoFollowTwitter = true;
             $radar = $this->get('core.radar');
             $conditions = Influencers_condition::allToOptionsArray();
         } else {
             $autoFollowTwitter = false;
         }
         foreach ($data as $original_id => $row) {
             $mention = new Mention();
             $mention->where(array('mention_keyword_id' => $mention_keyword->id, 'original_id' => $original_id))->get(1);
             $mention->social = $social;
             $mention->original_id = Arr::get($row, 'original_id');
             $mention->created_at = Arr::get($row, 'created_at');
             $message = Arr::get($row, 'message');
             $trimMessage = strlen($message) > 4000 ? substr($message, 0, 4000) : $message;
             $mention->message = $trimMessage;
             $mention->creator_id = Arr::get($row, 'creator_id');
             $mention->creator_name = Arr::get($row, 'creator_name');
             $mention->creator_image_url = Arr::get($row, 'creator_image_url');
             $mention->other_fields = serialize(Arr::get($row, 'other_fields', array()));
             $mention->source = Arr::get($row, 'source');
             $relations = array('user' => $user, 'mention_keyword' => $mention_keyword);
             $saved = $mention->save($relations);
             if (!$saved) {
                 log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Mention not saved for mkwid: ' . $error_info . ' grabbed: ' . $mention->error->string);
             } else {
                 switch ($social) {
                     case 'twitter':
                         $followers = (int) Arr::path($row, 'other_fields.creator_followers_count');
                         $retweetCount = (int) Arr::path($row, 'other_fields.retweet_count');
                         if ($followers || $retweetCount) {
                             $mentionTwitter = new Mention_twitter();
                             $mentionTwitter->followers_count = $followers;
                             $mentionTwitter->retweet_count = $retweetCount;
                             $mentionTwitter->mention_id = $mention->id;
                             $mentionTwitter->save();
                         }
                         break;
                     case 'facebook':
                         $friendsCount = (int) Arr::path($row, 'other_fields.friends_count');
                         $commentsCount = (int) Arr::path($row, 'other_fields.comments');
                         $likesCount = (int) Arr::path($row, 'other_fields.likes');
                         if ($friendsCount || $commentsCount || $likesCount) {
                             $mentionTwitter = new Mention_facebook();
                             $mentionTwitter->friends_count = $friendsCount;
                             $mentionTwitter->comments_count = $commentsCount;
                             $mentionTwitter->likes_count = $likesCount;
                             $mentionTwitter->mention_id = $mention->id;
                             $mentionTwitter->save();
                         }
                         break;
                     case 'google':
                         $peopleCount = (int) Arr::path($row, 'other_fields.people_count');
                         $commentsCount = (int) Arr::path($row, 'other_fields.comments');
                         $plusonersCount = (int) Arr::path($row, 'other_fields.plusoners');
                         $resharersCount = (int) Arr::path($row, 'other_fields.resharers');
                         if ($peopleCount || $commentsCount || $plusonersCount || $resharersCount) {
                             $mentionTwitter = new Mention_google();
                             $mentionTwitter->people_count = $peopleCount;
                             $mentionTwitter->comments_count = $commentsCount;
                             $mentionTwitter->plusoners_count = $plusonersCount;
                             $mentionTwitter->resharers_count = $resharersCount;
                             $mentionTwitter->mention_id = $mention->id;
                             $mentionTwitter->save();
                         }
                         break;
                 }
             }
         }
         // get socials that were already grabbed
         $grabbed_socials = $mention_keyword->get_grabbed_socials_as_array();
         if (!in_array($social, $grabbed_socials)) {
             $grabbed_socials[] = $social;
             $now = date('U');
             $mention_keyword->grabbed_socials = implode(',', $grabbed_socials);
             $mention_keyword->grabbed_at = $now;
             $saved = $mention_keyword->save();
             if (!$saved) {
                 log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Mention keyword not saved for mkwid: ' . $error_info . ' grabbed: ' . $mention->error->string);
             }
         }
         log_message('TASK_SUCCESS', __FUNCTION__ . ' > ' . 'Mentions for mkwid: ' . $error_info . ' grabbed');
     } catch (Exception $e) {
         log_message('TASK_ERROR', __FUNCTION__ . ' > ' . $e->getMessage());
         return;
         // throw $e;
     }
 }
 protected function transform(stdClass $object)
 {
     return Mention::wrap($object);
 }
 public function remove_unrelated()
 {
     try {
         $limit = 500;
         $mentions = Mention::inst()->where('user_id IS NULL')->or_where('mention_keyword_id IS NULL')->get($limit)->delete_all();
         log_message('TASK_SUCCESS', __FUNCTION__ . ' > ' . 'Unrelated mentions removed');
     } catch (Exception $e) {
         log_message('TASK_ERROR', __FUNCTION__ . ' > ' . $e->getMessage());
         return;
         // throw $e;
     }
 }
 /**
  * Check mentions not related to anything
  * And move them to queue
  * 
  * minutely ?
  */
 public function queue_unrelated_mentions()
 {
     $mentions_count = Mention::inst()->where('user_id IS NULL')->or_where('mention_keyword_id IS NULL')->count();
     if (!$mentions_count) {
         log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'No unrelated mentions');
         return;
     }
     $this->jobQueue->addJob('tasks/mentions_task/remove_unrelated', array(), array('thread' => self::MENTIONS_THREAD));
     log_message('CRON_SUCCESS', __FUNCTION__ . ' > ' . 'Unrelated mentions: ' . $mentions_count);
     return;
 }
Beispiel #6
0
 /**
  * Used to add new comment for instagram media
  *
  * @access public
  * @param null $mediaId
  * @param null $type
  */
 public function instagram_comment($mediaId = null, $type = null)
 {
     if ($this->template->is_ajax()) {
         $post = $this->input->post();
         if (isset($post['message']) && $mediaId != null) {
             try {
                 $this->load->library('Socializer/socializer');
                 $instagram = Socializer::factory('Instagram', $this->c_user->id);
                 $comment = $instagram->postMediaComment($mediaId, $post['message']);
                 if (empty($comment->meta->error_message)) {
                     if ($type == 'crm') {
                         Crm_directory_activity::inst()->update_other_field($mediaId, 'comments', 'inc');
                     } else {
                         Mention::inst()->update_other_field($mediaId, 'comments', 'inc');
                     }
                 } else {
                     throw new Exception($comment->meta->error_message);
                 }
                 $result['success'] = true;
                 $result['html'] = $this->template->block('_comment', 'social/activity/blocks/_one_instagram_comment', array('comment' => $comment, 'socializer' => $instagram, 'radar' => $this->radar));
             } catch (Exception $e) {
                 $result = array();
                 $result['success'] = false;
                 $result['error'] = $e->getMessage();
             }
             echo json_encode($result);
         }
     }
 }