public function index()
 {
     $types = Access_token::$types_with_tools;
     $configs = Config::findAll()->all_to_array();
     $available_configs = array();
     foreach ($types as $type) {
         foreach ($configs as $config) {
             $available_config = Available_config::create()->where('type', $type)->where('config_id', $config['id'])->get(1);
             $config['is_enable'] = $available_config->exists() ? true : false;
             $available_configs[$type][$config['id']] = $config;
         }
     }
     $post = $this->input->post();
     if (!empty($post)) {
         $old_available_configs = Available_config::findAll();
         foreach ($old_available_configs as $old_available_config) {
             $old_available_config->delete();
         }
         foreach ($post as $_type => $configs) {
             foreach ($configs as $config_id => $value) {
                 $new_available_config = Available_config::create();
                 $new_available_config->type = $_type;
                 $new_available_config->config_id = $config_id;
                 $new_available_config->save();
             }
         }
         $this->addFlash(lang('social_update_success'), 'success');
         redirect('admin/social_settings');
     }
     $this->template->set('available_configs', $available_configs);
     $this->template->render();
 }
 /**
  * @param string    $type
  * @param array     $exclude
  *
  * @return array
  */
 public static function getByTypeAsArray($type, $exclude = array())
 {
     $available_configs = Available_config::create()->where('type', $type)->get();
     $configs = array();
     foreach ($available_configs as $available_config) {
         $_config = $available_config->config->get()->to_array();
         if (!in_array($_config['key'], $exclude)) {
             $configs[] = $_config;
         }
     }
     return $configs;
 }
 /**
  * Form with mentions keywords list
  */
 public function index()
 {
     $keywords = User_search_keyword::inst()->get_user_keywords($this->c_user->id, $this->profile->id);
     $new_keywords = array();
     $errors = array();
     $saved_ids = array(0);
     // '0' to prevent datamapper error caused by empty array
     $delete = true;
     if ($post = $this->input->post()) {
         unset($post['submit']);
         $grouped = Arr::collect($post);
         foreach ($grouped as $id => $data) {
             if (strpos($id, 'new_') === 0) {
                 $keyword = User_search_keyword::inst()->fill_from_array($data, $this->c_user->id, $this->profile->id);
                 $new_keywords[$id] = $keyword;
             } else {
                 $keyword = User_search_keyword::inst()->fill_from_array($data, $this->c_user->id, $this->profile->id, $id);
                 if ($keyword->id !== $id) {
                     $new_keywords[$id] = $keyword;
                 }
             }
             if ($keyword->save()) {
                 $saved_ids[] = $keyword->id;
             } else {
                 $errors[$id] = $keyword->error->string;
             }
         }
         if (empty($errors)) {
             if ($delete) {
                 User_search_keyword::inst()->set_deleted($this->c_user->id, $this->profile->id, $saved_ids);
             }
             $this->addFlash(lang('keywords_saved_success'), 'success');
             redirect('settings/user_search_keywords');
         } else {
             $this->addFlash(implode('<br>', Arr::map('strip_tags', $errors)));
         }
     }
     CssJs::getInst()->c_js('settings/user_search_keywords', 'index');
     $configs = Available_config::getByKeysAsArray(array('auto_follow_users_by_search', 'max_daily_auto_follow_users_by_search'), $this->c_user, $this->profile->id);
     $outp_keywords = array();
     foreach ($keywords as $keyword) {
         $outp_keywords[$keyword->id] = $keyword;
     }
     $outp_keywords = array_merge($outp_keywords, $new_keywords);
     $this->template->set('keywords', $outp_keywords);
     $this->template->set('errors', $errors);
     $this->template->set('configs', $configs);
     $this->template->render();
 }
 /**
  * @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;
 }
Beispiel #5
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();
 }