function index() { $current_user = Users_Model::get_current_user(); $posts = Users_Model::get_facebook_posts(); $post_chart = array('Posts'); $post_count = 0; $likes = Users_Model::get_facebook_likes(); $likes_chart = array('Likes'); $likes_count = 0; $date_start = $date_first = strtotime('-7 DAYS'); $date_end = time(); if ($this->is_ajax() && isset($_POST['startDate']) && isset($_POST['endDate'])) { $date_start = $_POST['startDate']; $date_end = $_POST['endDate']; } while ($date_start <= $date_end) { $index = date('d.m', $date_start); $post_chart[$index] = 0; $likes_chart[$index] = 0; // Posts if (!empty($posts)) { foreach ($posts['data'] as $post) { if (date('Y-m-d', strtotime($post->created_time)) == date('Y-m-d', $date_start)) { $post_chart[$index]++; $post_count++; } } } // Likes if (!empty($likes->data)) { foreach ($likes->data as $like) { if (date('Y-m-d', strtotime($like->created_time)) == date('Y-m-d', $date_start)) { $likes_chart[$index]++; $likes_count++; } } } $date_start = strtotime('+1 day', $date_start); } $categories = array_slice(array_keys($post_chart), 1); $post_chart = array_values($post_chart); $likes_chart = array_values($likes_chart); if ($this->is_ajax() && isset($_POST['startDate']) && isset($_POST['endDate'])) { echo json_encode(array('status' => true, 'html' => $this->load->view('facebook/_facebook_chart', array('chart_categories' => $categories, 'post_count' => $post_count, 'post_chart' => $post_chart, 'likes_count' => $likes_count, 'likes_chart' => $likes_chart, 'startDate' => date('d/m/y', $date_first), 'endDate' => date('d/m/y', $date_end)), TRUE), 'chart_categories' => $categories, 'post_chart' => $post_chart, 'likes_chart' => $likes_chart)); exit; } else { $this->layout('admin', 'facebook/facebook', array('current_user' => $current_user, 'post_count' => $post_count, 'post_chart' => $post_chart, 'likes_count' => $likes_count, 'likes_chart' => $likes_chart, 'chart_categories' => $categories, 'startDate' => date('d/m/y', $date_first), 'endDate' => date('d/m/y', $date_end))); } }
public function twitter() { $current_user = Users_Model::get_current_user(); $twitter_meta = $current_user->get_usermeta('twitter_meta'); $favorites = $current_user->get_twitter_favorites(); $tweets = $current_user->get_all_tweets(); $favorites_chart = array('Favorites'); $retweets_chart = array('Retweets'); $favorites_count = 0; $retweets_count = 0; $date_start = $date_first = strtotime('-7 DAYS'); $date_end = time(); if ($this->is_ajax() && isset($_POST['startDate']) && isset($_POST['endDate'])) { $date_start = $_POST['startDate']; $date_end = $_POST['endDate']; } while ($date_start <= $date_end) { $index = date('d.m', $date_start); $favorites_chart[$index] = 0; $retweets_chart[$index] = 0; // Favorites foreach ($favorites as $favorite) { if (date('Y-m-d', strtotime($favorite->created_at)) == date('Y-m-d', $date_start)) { $favorites_chart[$index]++; $favorites_count++; } } // Retweets foreach ($tweets as $tweet) { if (date('Y-m-d', strtotime($tweet->created_at)) == date('Y-m-d', $date_start)) { $retweets_chart[$index] += $tweet->retweet_count; $retweets_count += $tweet->retweet_count; } } $date_start = strtotime('+1 day', $date_start); } $categories = array_slice(array_keys($favorites_chart), 1); $favorites_chart = array_values($favorites_chart); $retweets_chart = array_values($retweets_chart); if ($this->is_ajax() && isset($_POST['startDate']) && isset($_POST['endDate'])) { echo json_encode(array('status' => true, 'html' => $this->load->view('dashboard/social/_twitter_chart', array('favorites_chart' => $favorites_chart, 'chart_categories' => $categories, 'startDate' => date('Y/d/m', $date_first), 'endDate' => date('Y/d/m', $date_end), 'favorites_count' => $favorites_count, 'retweets_count' => $retweets_count), TRUE), 'favorites_chart' => $favorites_chart, 'retweets_chart' => $retweets_chart, 'chart_categories' => $categories)); exit; } else { $this->view_admin(array('view' => 'social/twitter', 'current_user' => $current_user, 'twitter_meta' => $twitter_meta, 'favorites_chart' => $favorites_chart, 'retweets_chart' => $retweets_chart, 'chart_categories' => $categories, 'startDate' => date('Y/d/m', $date_first), 'endDate' => date('Y/d/m', $date_end), 'favorites_count' => $favorites_count, 'retweets_count' => $retweets_count)); } }
public function edit_tweet() { if ($this->is_ajax() && isset($_POST['id'])) { $current_user = Users_Model::get_current_user(); $tweet = Tweets_Model::first(array('id' => $_POST['id'])); if ($tweet && $tweet->user_id == $current_user->user_id) { echo json_encode(array('status' => true, 'tweet' => $tweet->attributes())); } else { echo json_encode(array('status' => false)); } } exit; }