/** * getVkGroups. * * @return void */ public function getVkGroups() { @ob_end_clean(); header('Content-type: text/plain'); // No JInputJSON in J2.5 $raw = file_get_contents('php://input'); $data = json_decode($raw, true); $safeHtmlFilter = JFilterInput::getInstance(); $token = $data['token']; $token = $safeHtmlFilter->clean($token, 'ALNUM'); $this->input->set($token, 1); // CSRF prevention if ($this->csrfProtection) { $this->_csrfProtection(); } $channel_id = $data['channel_id']; $channel_id = $safeHtmlFilter->clean($channel_id, 'ALNUM'); $access_token = $data['access_token']; $access_token = $safeHtmlFilter->clean($access_token, 'STRING'); $status = false; $error_message = 'Unknown'; $items = null; $icon = null; $channel = F0FTable::getAnInstance('Channel', 'AutoTweetTable'); $result = $channel->load($channel_id); if (!$result) { $error_message = 'Channel failed to load!'; } else { try { $params = $channel->params; $registry = new JRegistry(); $registry->loadString($params); $registry->set('access_token', $access_token); $channel->bind(array('params' => (string) $registry)); $vkChannelHelper = new VkChannelHelper($channel); $result = $vkChannelHelper->getGroups(); $jselect = array('gid' => 0, 'name' => '-' . JText::_('JSELECT') . '-', 'screen_name' => '', 'is_closed' => 0, 'type' => 'page', 'photo' => '', 'photo_medium' => '', 'photo_big' => '', 'url' => ''); array_unshift($result['items'], $jselect); $status = $result['status']; $message = $result['error_message']; $items = $result['items']; $icon = F0FModel::getTmpInstance('Channeltypes', 'AutoTweetModel')->getIcon(AutotweetModelChanneltypes::TYPE_VK_CHANNEL); } catch (Exception $e) { $error_message = $e->getMessage(); } } $message = json_encode(array('status' => $status, 'error_message' => $error_message, 'groups' => $items, 'social_icon' => $icon)); echo EJSON_START . $message . EJSON_END; flush(); JFactory::getApplication()->close(); }
/** * vkgroups * * @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 $access_token Params * @param int $channel_id Params * * @return string HTML */ public static function vkgroups($selected = null, $name = 'xtform[vkgroup_id]', $attribs = array(), $access_token = null, $channel_id = null) { $options = array(); $attribs = array(); if (!empty($access_token) && !empty($channel_id)) { $options[] = JHTML::_('select.option', null, '-' . JText::_('JSELECT') . '-'); try { $ch = F0FTable::getAnInstance('Channel', 'AutoTweetTable'); $result = $ch->load($channel_id); if (!$result) { break; } $params = $ch->params; $registry = new JRegistry(); $registry->loadString($params); $registry->set('access_token', $access_token); $ch->bind(array('params' => (string) $registry)); $vkChannelHelper = new VkChannelHelper($ch); $result = $vkChannelHelper->getGroups(); if ($result['status']) { $groups = $result['items']; $icon = F0FModel::getTmpInstance('Channeltypes', 'AutoTweetModel')->getIcon(AutotweetModelChanneltypes::TYPE_VK_CHANNEL); foreach ($groups as $group) { $nm = $group['name']; if (empty($nm) || $nm == 'null') { $nm = $group['gid']; } $attr = 'social_url="' . $group['url'] . '" social_icon="' . $icon . '"'; $attrs = array('attr' => $attr, 'option.attr' => 'social_url', 'option.key' => 'value', 'option.text' => 'text', 'disable' => false); $opt = JHTML::_('select.option', $group['gid'], $nm, $attrs); $options[] = $opt; } } $attribs['id'] = $name; $attribs['list.attr'] = null; $attribs['list.translate'] = false; $attribs['option.key'] = 'value'; $attribs['option.text'] = 'text'; $attribs['option.attr'] = 'social_url'; $attribs['list.select'] = $selected; return EHtmlSelect::genericlist($options, $name, $attribs); } 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')); }