Exemplo n.º 1
0
 protected function _channel_influencer()
 {
     try {
         $id = $this->input->post('id');
         $campaign = new Campaign($id);
         $cinfo = $campaign->get();
         if (!$cinfo) {
             throw new \Exception('Invalid campaign');
         }
         if (!($influencer = $this->input->post('influencer'))) {
             throw new \Exception('Invalid influencer');
         }
         $comment = $this->input->post('comment');
         if (empty($comment)) {
             throw new \Exception('Comment must not be empty');
         }
         $comments = MongoDoc::get($cinfo, 'comments.brand_influencer', array());
         if (!isset($comments[$influencer])) {
             $comments[$influencer] = array();
         }
         $comments[$influencer][] = array('from' => UserSession::get('user._id'), 'from_username' => UserSession::get('user.username'), 'user' => 'brand', 'created_at' => time(), 'text' => $comment);
         $comments[$influencer] = array_slice($comments[$influencer], -20);
         $campaign->update(array('comments.brand_influencer' => $comments));
         Alert::once('success', 'Comment added', Url::referrer());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::referrer());
     }
 }
Exemplo n.º 2
0
 public function limit_remaining($key)
 {
     if ($a = $this->get()) {
         return max(0, MongoDoc::get($a, 'package.limits.' . $key, 0) - MongoDoc::get($a, 'limits.' . $key, 0));
     }
     return 0;
 }
Exemplo n.º 3
0
 protected function _add()
 {
     if (!($id = $this->input->post('id'))) {
         Json::error('Invalid influencer id');
     }
     $id = new \MongoId($id);
     $brand = new Brand(UserSession::get('user._id'));
     $binfo = $brand->get();
     $lists = MongoDoc::get($binfo, 'lists', array());
     $list_idx = $this->input->post('list');
     $new_list = $this->input->post('new_list');
     if ($list_idx !== null && isset($lists[$list_idx])) {
         if (in_array($id, $lists[$list_idx]['influencers'])) {
             Json::success('Influencer is already preset in the list');
         }
         $lists[$list_idx]['influencers'][] = $id;
     } else {
         if (!empty($new_list)) {
             foreach ($lists as $l) {
                 if ($l['name'] === $new_list) {
                     Json::error(sprintf('List with name "%s" already exists', $new_list));
                 }
             }
             $lists[] = array('name' => $new_list, 'influencers' => array($id));
         } else {
             Json::error('Invalid list');
         }
     }
     $brand->update(array('lists' => $lists));
     Json::success('Success');
 }
Exemplo n.º 4
0
 public function get($id)
 {
     $favorite = false;
     if (UserSession::get('user.type') === 'influencer') {
         $iinfo = (new Influencer(UserSession::get('user._id')))->get();
         $favorite = in_array(new \MongoId($id), MongoDoc::get($iinfo, 'favorites', array()));
     }
     $this->_display->view(array('main/app/brand/view.php'), array('user' => (new Brand($id))->get(), 'favorite' => $favorite));
 }
Exemplo n.º 5
0
 protected function _get_data($binfo)
 {
     $data = array('brand' => $binfo['_id'], 'points' => 0, 'state' => 'pending');
     if (!in_array($data['type'] = $this->input->post('type'), array('digital-pr', 'ad-serving', 'custom'))) {
         throw new \Exception('Invalid type: ' . $data['type']);
     }
     if ($data['type'] == 'digital-pr') {
         if (!in_array($data['subtype'] = $this->input->post('subtype'), array('create', 'amplify'))) {
             throw new \Exception('Invalid subtype: ' . $data['type']);
         }
         $data['social'] = array();
         $key = 'social_' . $data['subtype'];
         foreach (array('facebook', 'twitter', 'instagram', 'google-analytics', 'google-youtube', 'google-plus', 'vine') as $k) {
             $data['social'][$k] = $this->input->post($key, str_replace('-', '_', $k));
             if ($data['subtype'] == 'create') {
                 $data['social'][$k] = $data['social'][$k] ? true : false;
             }
         }
     }
     $df = $this->input->post('date', 'from');
     $dt = $this->input->post('date', 'to');
     if (!($df && $dt)) {
         throw new \Exception('Dates must be specified');
     }
     $df_ts = (new \DateTime($df, new \DateTimeZone(UserSession::get('user.timezone') ?: TIMEZONE)))->setTimezone(new \DateTimeZone(TIMEZONE))->getTimestamp();
     $dt_ts = (new \DateTime($dt, new \DateTimeZone(UserSession::get('user.timezone') ?: TIMEZONE)))->setTimezone(new \DateTimeZone(TIMEZONE))->getTimestamp();
     $now = strtotime(date('Y-m-d'));
     if ($df_ts - $now < 0) {
         throw new \Exception('Start date must not be in past');
     }
     if ($df_ts > $dt_ts) {
         throw new \Exception('End date must be greater than start date');
     }
     $data['date'] = array('start' => array('date' => $df, 'timestamp' => $df_ts), 'end' => array('date' => $dt, 'timestamp' => $dt_ts));
     if (!($data['title'] = $this->input->post('title'))) {
         throw new \Exception('Title must be specified');
     }
     $data['title'] = trim($data['title']);
     if (strlen($data['title']) < 10) {
         throw new \Exception('Title must be atleast 10 characters long');
     }
     if (!($data['brief'] = $this->input->post('brief'))) {
         throw new \Exception('Brief must be specified');
     }
     $data['brief'] = trim($data['brief']);
     if (strlen($data['brief']) < 50) {
         throw new \Exception('Brief must be atleast 50 characters long');
     }
     $data['influencers_select'] = array();
     if (($idx = $this->input->post('influencer_list')) !== null) {
         $data['influencers_select'] = MongoDoc::get($binfo, 'lists.' . $idx . '.influencers', array());
     }
     return $data;
 }
Exemplo n.º 6
0
 protected function _set_picture(&$u)
 {
     // Set profile image
     $image = null;
     foreach (array('picture', 'social.facebook.details.picture.url', 'social.twitter.details.profile_image_url_https') as $t) {
         if ($a = MongoDoc::get($u, $t)) {
             $image = $a;
         }
     }
     $u['picture'] = $image;
 }
Exemplo n.º 7
0
 protected function _remove()
 {
     try {
         $influencer = new Influencer(UserSession::get('user._id'));
         $iinfo = $influencer->get();
         if ($social = MongoDoc::get($iinfo, 'social')) {
             unset($social['instagram']);
             $influencer->update(array('social' => $social));
         }
     } catch (\Exception $e) {
         Alert::once('error', 'Failed to remove account: ' . $e->getMessage(), Url::base('influencer/social'));
     }
     Alert::once('success', 'Account remove successfully', Url::base('influencer/social'));
 }
Exemplo n.º 8
0
 protected function _remove()
 {
     try {
         $brand = new Brand(UserSession::get('user._id'));
         $iinfo = $brand->get();
         if ($social = MongoDoc::get($iinfo, 'social')) {
             unset($social['twitter']);
             $brand->update(array('social' => $social));
         }
     } catch (\Exception $e) {
         Alert::once('error', 'Failed to remove account: ' . $e->getMessage(), Url::base('brand/social'));
     }
     Alert::once('success', 'Account remove successfully', Url::base('brand/social'));
 }
Exemplo n.º 9
0
 protected function _get_social_differential($info, $days = 5)
 {
     $stats = new Statistics();
     $stat = $stats->get($info['_id'], date('Y-m-d', strtotime('-' . $days . ' days')));
     $items = array('facebook' => array('details.likes', 'insights.engaged_users'), 'twitter' => array('details.statuses_count', 'details.followers_count'), 'instagram' => array('counts.followed_by'), 'google-youtube' => array('statistics.subscriberCount', 'statistics.videoCount'), 'google-analytics' => array('ga_data.ga:sessions'), 'vine' => array('followerCount'), 'klout' => array('score.score'));
     $result = array();
     foreach ($items as $k => $fields) {
         if (!($a = MongoDoc::get($info, 'social.' . $k))) {
             continue;
         }
         $c = array();
         if ($stat) {
             foreach ($fields as $f) {
                 //echo 'VAL', PHP_EOL;
                 //var_dump($f, 'social.'.$k.'.'.$f, MongoDoc::get($stat, 'social.'.$k.'.'.$f, null));
                 //var_dump($f, MongoDoc::get($a, $f, null));
                 $p = 1.0;
                 if ($stat && ($v_old = MongoDoc::get($stat, 'social.' . $k . '.' . $f, null)) !== null && ($v_new = MongoDoc::get($a, $f, null)) !== null) {
                     /*
                     switch ($k.'.'.$f)
                     {
                     	case 'twitter.details.statuses_count':
                     		$x = strtotime(MongoDoc::get($a, 'details.created_at'));
                     		$d = floor((time() - $x)/(3600*24));
                     		$v_new1 = $d? ($v_new / $d) : 0;
                     		$d -= $days;
                     		$v_old1 = $d? ($v_new / $d) : 0;
                     		$c['details.statuses_per_day'] = round(($v_new1 - $v_old1)*100/$v_new1, 4);
                     		break;
                     }
                     */
                     //echo 'Found value: ', $v_new, ' - ' , $v_old, PHP_EOL;
                     if ($v_new + $v_old == 0) {
                         $p = 0;
                     } else {
                         if ($v_new) {
                             $p = round(($v_new - $v_old) * 100 / $v_new, 4);
                         }
                     }
                 }
                 $c[$f] = $p;
             }
         }
         if ($c) {
             $result[$k] = $c;
         }
     }
     return MongoDoc::explode($result);
 }
Exemplo n.º 10
0
 public function get($brand_id = null)
 {
     $user = new Influencer(UserSession::get('user._id'));
     $uinfo = $user->get();
     $brands = array();
     $bmodel = new Brand(null);
     foreach (MongoDoc::get($uinfo, 'favorites', array()) as $b) {
         $brands[] = $bmodel->filter_one(array('_id' => $b), array('_id' => true, 'name' => true, 'username' => true));
     }
     $river = array();
     if ($brands && !$brand_id) {
         $brand_id = $brands[0]['_id'];
     }
     if ($brand_id) {
         $river = MongoDoc::get((new Brand($brand_id))->get(), 'social_river', array());
     }
     $this->_display->view(array('main/app/influencer/river.php'), array('brands' => $brands, 'brand_id' => $brand_id, 'river' => $river));
 }
Exemplo n.º 11
0
 public function post()
 {
     if (UserSession::get('user.type') !== 'brand') {
         $this->_403();
     }
     if (!($id = $this->input->post('id'))) {
         Json::error('Invalid influencer id');
     }
     $id = new \MongoId($id);
     $brand = new Brand(UserSession::get('user._id'));
     $binfo = $brand->get();
     $favorites = MongoDoc::get($binfo, 'favorites', array());
     if ($reset = in_array($id, $favorites)) {
         $favorites = array_values(array_diff($favorites, array($id)));
     } else {
         $favorites[] = $id;
     }
     $brand->update(array('favorites' => $favorites));
     Json::success('Success', null, array('set' => !$reset));
 }
Exemplo n.º 12
0
 protected function _save_river($key)
 {
     try {
         $user = new Brand(UserSession::get('user._id'));
         $uinfo = $user->get();
         $auto = !!$this->input->post('auto');
         if ($auto) {
             if (($r = MongoDoc::get($uinfo, 'social_river.data_custom')) && isset($r[$key])) {
                 unset($r[$key]);
                 $user->update(array('social_river.data_custom' => (object) $r));
             }
         } else {
             if (($u = $this->input->post('url')) && !empty($u)) {
                 $user->update(array('social_river.data_custom.' . $key => trim($u)));
             }
         }
         Alert::once('success', 'URL updated successfully', Url::current());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::current());
     }
 }
Exemplo n.º 13
0
 protected function _render_approval()
 {
     $id = $this->input->post('id');
     try {
         $campaign = new Campaign(null);
         $cinfo = $campaign->filter_one(array('_id' => new \MongoId($id), 'state' => array('$in' => array('pending', 'rejected'))));
         if (!$cinfo) {
             Alert::once('error', 'Invalid campaign', Url::referrer());
         }
         $i_sel = array();
         $influencer = new Influencer(null);
         $sel = array();
         foreach (MongoDoc::get($cinfo, 'influencers_select', array()) as $i) {
             $i_sel[] = $influencer->filter_one(array('_id' => $i), array('_id' => true, 'username' => true));
             $sel[] = (string) $i;
         }
         $cinfo['influencers_select'] = $i_sel;
         $this->_display->view(array('main/app/admin/campaign/approve.php'), array('campaign' => $cinfo, 'influencers_select_string' => implode(',', $sel), 'influencers' => (new Influencer(null))->filter(array('active' => true))));
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::base('admin/campaign/view/' . $id));
     }
 }
Exemplo n.º 14
0
 protected function _compute_status_latest($u, &$update)
 {
     $river = array();
     if (MongoDoc::get($u, 'social_river.enabled', false)) {
         foreach (array('facebook', 'twitter', 'instagram', 'google-youtube', 'google-plus') as $item) {
             if ($info = MongoDoc::get($update, 'social\\.' . $item)) {
                 $s = null;
                 switch ($item) {
                     case 'facebook':
                         $this->_fetch_status_facebook($u, $s, $info, $item);
                         break;
                     case 'twitter':
                         $this->_fetch_status_twitter($u, $s, $info, $item);
                         break;
                     case 'instagram':
                         $this->_fetch_status_instagram($u, $s, $info, $item);
                         break;
                     case 'google-youtube':
                         $this->_fetch_status_google_youtube($u, $s, $info, $item);
                         break;
                     case 'google-plus':
                         $this->_fetch_status_google_plus($u, $s, $info, $item);
                         break;
                 }
                 if ($s) {
                     printf("%-15s %-30s\n", 'STATUS-SET', $item);
                     $river[$item] = $s;
                 }
             }
         }
         $update['social_river.data'] = array_replace_recursive(MongoDoc::get($u, 'social_river.data', array()), $river);
     }
 }
Exemplo n.º 15
0
 protected function _compute_fluenz_score($u, &$update)
 {
     // Calculate Fluenz score
     $s = MongoDoc::get($update, 'social\\.google-analytics.ga_data.ga:sessions', 0);
     $p = 100;
     $map = array(1000 => 50, 5000 => 60, 10000 => 70, 50000 => 75, 100000 => 80, 500000 => 85, 2000000 => 90, 5000000 => 95);
     foreach ($map as $k => $v) {
         if ($s < $k) {
             $p = $v;
             break;
         }
     }
     $update['score'] = round(($p + MongoDoc::get($update, 'social\\.klout.score.score', 0)) / 2);
 }
Exemplo n.º 16
0
 public function create($data)
 {
     return parent::create(array('name' => $data['name'], 'email' => $data['email'], 'username' => $data['username'], 'password' => $data['password'], 'phone' => $data['phone'], 'city' => $data['city'], 'genre' => $data['genre'], 'type' => $this->_type, 'active' => MongoDoc::get($data, 'active', true), 'last_login' => null));
 }
Exemplo n.º 17
0
 protected function _insert_statistics($u)
 {
     $stats = new Statistics();
     $items = array('facebook' => array('details.likes', 'insights.engaged_users'), 'twitter' => array('details.statuses_count', 'details.followers_count'), 'instagram' => array('counts.followed_by'), 'google-youtube' => array('statistics.subscriberCount', 'statistics.videoCount'), 'google-analytics' => array('ga_data.ga:sessions'), 'vine' => array('followerCount'), 'klout' => array('score.score'));
     $data = array();
     foreach ($items as $k => $fields) {
         if (!($a = MongoDoc::get($u, 'social.' . $k))) {
             continue;
         }
         $c = array();
         foreach ($fields as $f) {
             $c[$f] = MongoDoc::get($a, $f, 0);
         }
         if ($c) {
             $data[$k] = $c;
         }
     }
     if ($data) {
         try {
             $stats->save($u['_id'], date('Y-m-d'), array('social' => MongoDoc::explode($data)));
         } catch (\Exception $e) {
             echo 'Error updating document: ', $e->getMessage(), PHP_EOL;
         }
     }
 }