/** * getFbChannels. * * @return void */ public function getFbChannels() { @ob_end_clean(); header('Content-type: text/plain'); $this->_loadFbParams(); JLoader::register('FbAppHelper', JPATH_AUTOTWEET_HELPERS . '/channels/fbapp.php'); $status = false; $error_message = 'Unknown'; $icon = null; try { $fbAppHelper = new FbAppHelper($this->_app_id, $this->_secret, $this->_access_token); if ($fbAppHelper->login()) { $channels = $fbAppHelper->getChannels(); $status = true; $error_message = 'Ok'; $icon = F0FModel::getTmpInstance('Channeltypes', 'AutoTweetModel')->getIcon(AutotweetModelChanneltypes::TYPE_FB_CHANNEL); } else { $error_message = 'Facebook Login Failed!'; } } catch (Exception $e) { $error_message = $e->getMessage(); } $message = json_encode(array('status' => $status, 'error_message' => $error_message, 'channels' => $channels, 'icon' => $icon)); echo EJSON_START . $message . EJSON_END; flush(); JFactory::getApplication()->close(); }
/** * fbchannels. * * @param string $selected The key that is selected * @param string $name The name for the field * @param array $attribs Additional HTML attributes for the <select> tag* * @param string $app_id Params * @param string $secret Params * @param string $access_token Params * * @return string HTML */ public static function fbchannels($selected = null, $name = 'xtform[fbchannel_id]', $attribs = array(), $app_id = null, $secret = null, $access_token = null) { $options = array(); $attribs = array(); if ($access_token) { require_once dirname(__FILE__) . '/../helpers/channels/fbapp.php'; try { $fbAppHelper = new FbAppHelper($app_id, $secret, $access_token); if ($fbAppHelper->login()) { $channels = $fbAppHelper->getChannels(); $icon = F0FModel::getTmpInstance('Channeltypes', 'AutoTweetModel')->getIcon(AutotweetModelChanneltypes::TYPE_FB_CHANNEL); foreach ($channels as $channel) { $nm = $channel['name']; if (empty($nm) || $nm == 'null') { $nm = $channel['id']; } $opt = JHTML::_('select.option', $channel['id'], $channel['type'] . ': ' . $nm); if (array_key_exists('access_token', $channel)) { $opt->access_token = array('access_token' => $channel['access_token'], 'social_icon' => $icon, 'social_url' => $channel['url'], 'data_type' => $channel['type']); } $options[] = $opt; } $attribs['id'] = $name; $attribs['list.attr'] = null; $attribs['list.translate'] = false; $attribs['option.key'] = 'value'; $attribs['option.text'] = 'text'; $attribs['list.select'] = $selected; $attribs['option.attr'] = 'access_token'; return EHtmlSelect::genericlist($options, $name, $attribs); } else { $error_message = 'Facebook Login Failed!'; $options[] = JHTML::_('select.option', '', $error_message); } } catch (Exception $e) { $error_message = $e->getMessage(); $options[] = JHTML::_('select.option', '', $error_message); } } else { $options[] = JHTML::_('select.option', null, '-' . JText::_('JSELECT') . '-'); } return EHtmlSelect::customGenericList($options, $name, $attribs, $selected, $name, array('option.attr' => 'access_token')); }