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(); }
public function rels() { $mention = Mention::inst()->get(); foreach ($mention as $key => $value) { var_dump($value->user->id); } }
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; }
/** * 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); } } }