예제 #1
0
 /**
  * @param integer $group_id
  * @param array   $exclude types
  * @param bool    $has_twitter_marketing_tools
  *
  * @return array
  */
 public static function getGroupTokensArray($group_id, $exclude = array(), $has_twitter_marketing_tools = false)
 {
     $tokens = array();
     foreach (self::$types as $type) {
         if (in_array($type, $exclude)) {
             continue;
         }
         $has_configs = count(Available_config::getByTypeAsArray($type)) || $type == 'facebook' ? true : false;
         if ($has_configs && $type == 'twitter') {
             $has_configs = $has_twitter_marketing_tools;
         }
         $tokens_array = Social_group::getAccountByTypeAsArray($group_id, $type);
         foreach ($tokens_array as &$token) {
             $token['has_configs'] = $has_configs;
         }
         if (!empty($tokens_array)) {
             $tokens[$type] = $tokens_array;
         } else {
             $tokens[$type] = array();
         }
     }
     return $tokens;
 }
예제 #2
0
 /**
  * @param $id
  * @throws Exception
  */
 public function edit_account($id)
 {
     $token = Access_token::inst($id);
     if ($token->user_id != $this->c_user->id) {
         $this->addFlash(lang('account_owner_error'), 'error');
         redirect('settings/socialmedia');
     }
     if (!$this->profile->has_account($id)) {
         redirect('settings/socialmedia');
     }
     $available_configs = Available_config::getByTypeAsArray($token->type, []);
     if ($this->input->post()) {
         $errors = array();
         $configs = $this->input->post('config');
         foreach ($available_configs as $available_config) {
             $config_key = $available_config['key'];
             $value = isset($configs[$config_key]) ? $configs[$config_key] : '';
             $userConfig = $this->c_user->setConfig($config_key, $value == 'on' ? true : $value, $token->id);
             if (!$userConfig) {
                 $error_message = preg_replace('|<p>|', '', $userConfig->error->string);
                 $error_message = preg_replace('|</p>|', '<br>', $error_message);
                 $errors[] = $error_message;
             }
         }
         if ($token->type == 'facebook') {
             try {
                 if ($this->input->post('page_group') == '0') {
                     throw new Exception(lang('fanpage_error'));
                 }
                 $this->load->library('Socializer/socializer');
                 /* @var Socializer_Facebook $facebook */
                 $facebook = Socializer::factory('Facebook', $this->c_user->id, $token->to_array());
                 $userdata = $facebook->get_profile();
                 Facebook_Fanpage::inst()->save_selected_page($this->c_user->id, $this->input->post('page_group'), $userdata['id'], $token->id);
             } catch (Exception $e) {
                 $errors[] = $e->getMessage();
             }
         }
         if (empty($errors)) {
             $this->addFlash(lang('config_save_success'), 'success');
             redirect('settings/socialmedia');
         } else {
             $this->addFlash(implode('', $errors), 'error');
         }
     }
     if ($token->type == 'facebook') {
         try {
             $this->load->library('Socializer/socializer');
             /* @var Socializer_Facebook $facebook */
             $facebook = Socializer::factory('Facebook', $this->c_user->id, $token->to_array());
             $user_facebook_pages = $facebook->get_user_pages();
             $pages = $user_facebook_pages;
             $selected_fanpage = Facebook_Fanpage::inst()->get_selected_page($this->c_user->id, $token->id);
             $selected_fanpage_id = $selected_fanpage->fanpage_id;
             $this->template->set('pages', $pages);
             $this->template->set('selected_fanpage_id', $selected_fanpage_id);
         } catch (Exception $e) {
             if ($e->getCode() !== Socializer::FBERRCODE) {
                 $this->addFlash($e->getMessage());
             }
         }
     }
     $not_display_configs = ['welcome_message_text', 'days_before_unfollow', 'auto_favourite_min_favourites_count', 'auto_favourite_max_favourites_count', 'auto_favourite_min_retweets_count', 'auto_favourite_max_retweets_count', 'auto_retweet_min_favourites_count', 'auto_retweet_max_favourites_count', 'auto_retweet_min_retweets_count', 'auto_retweet_max_retweets_count', 'max_daily_auto_follow_users_by_search', 'age_of_account', 'number_of_tweets'];
     $not_display_configs_values = [];
     foreach ($available_configs as &$available_config) {
         if (in_array($available_config['key'], $not_display_configs)) {
             $not_display_configs_values[$available_config['key']] = ['value' => $this->c_user->ifUserHasConfigValue($available_config['key'], $id), 'type' => Config::getConfigType($available_config['key'])];
         }
         $available_config['value'] = $this->c_user->ifUserHasConfigValue($available_config['key'], $id);
         $available_config['type'] = Config::getConfigType($available_config['key']);
     }
     $this->template->set('available_configs', $available_configs);
     $this->template->set('not_display_configs', $not_display_configs);
     $this->template->set('not_display_configs_values', $not_display_configs_values);
     CssJs::getInst()->add_js(array('masonry-docs.min.js', 'masonry.pkgd.min.js'));
     $this->template->set('token', $token);
     $this->template->render();
 }