Пример #1
0
 /**
  * getLiOAuth2Companies
  *
  * @return	void
  */
 public function getLiOAuth2Companies()
 {
     @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');
     $channel = F0FTable::getAnInstance('Channel', 'AutoTweetTable');
     $result = $channel->load($channel_id);
     $channel->xtform = EForm::paramsToRegistry($channel);
     $status = false;
     $error_message = 'Unknown';
     $icon = null;
     try {
         $lioauth2ChannelHelper = new LiOAuth2CompanyChannelHelper($channel);
         $channels = $lioauth2ChannelHelper->getMyCompanies();
         $icon = F0FModel::getTmpInstance('Channeltypes', 'AutoTweetModel')->getIcon(AutotweetModelChanneltypes::TYPE_LINK_CHANNEL);
         $status = true;
         $error_message = 'Ok';
     } catch (Exception $e) {
         $error_message = $e->getMessage();
     }
     if (count($channels) == 2 && $channels[0] == false) {
         $message = json_encode(array('status' => false, 'error_message' => $channels[1]));
     } else {
         $message = json_encode(array('status' => $status, 'error_message' => $error_message, 'channels' => $channels, 'icon' => $icon));
     }
     echo EJSON_START . $message . EJSON_END;
     flush();
     JFactory::getApplication()->close();
 }
Пример #2
0
 /**
  * lioauth2companies.
  *
  * @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  $channel_id  Params
  *
  * @return  string  HTML
  */
 public static function lioauth2companies($selected = null, $name = 'xtform[company_id]', $attribs = array(), $channel_id = null)
 {
     $options = array();
     $attribs = array();
     if (!empty($channel_id)) {
         try {
             $channel = F0FTable::getAnInstance('Channel', 'AutoTweetTable');
             $result = $channel->load($channel_id);
             if (!$result) {
                 throw new Exception('LinkedIn OAuth2 Channel failed to load!');
             }
             $lioauth2ChannelHelper = new LiOAuth2CompanyChannelHelper($channel);
             $channels = $lioauth2ChannelHelper->getMyCompanies();
             if (count($channels) > 0 && $channels[0]) {
                 $icon = F0FModel::getTmpInstance('Channeltypes', 'AutoTweetModel')->getIcon(AutotweetModelChanneltypes::TYPE_LINK_CHANNEL);
                 foreach ($channels as $channel) {
                     $nm = $channel->name;
                     if (empty($nm) || $nm == 'null') {
                         $nm = $channel->id;
                     }
                     $attr = 'social_url="' . $channel->url . '" social_icon="' . $icon . '"';
                     $attrs = array('attr' => $attr, 'option.attr' => 'social_url', 'option.key' => 'value', 'option.text' => 'text', 'disable' => false);
                     $opt = JHTML::_('select.option', $channel->id, $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'));
 }