예제 #1
0
 /**
  * getTumblrValidation.
  *
  * @return	void
  */
 public function getTumblrValidation()
 {
     @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';
     $user = null;
     $url = null;
     $icon = null;
     try {
         $tumblrChannelHelper = new TumblrChannelHelper($channel);
         $isAuth = $tumblrChannelHelper->isAuth();
         if ($isAuth) {
             $status = true;
             $error_message = $isAuth->meta->msg;
             $user = $isAuth->response->user;
             $url = $tumblrChannelHelper->getSocialUrl($user);
             $icon = F0FModel::getTmpInstance('Channeltypes', 'AutoTweetModel')->getIcon(AutoTweetModelChanneltypes::TYPE_TUMBLR_CHANNEL);
             $user->blogs = SelectControlHelper::tumblrOptions($user->blogs);
         } else {
             $error_message = 'Tumblr Login Failed!';
         }
     } catch (Exception $e) {
         $error_message = $e->getMessage();
     }
     $message = json_encode(array('status' => $status, 'error_message' => $error_message, 'user' => $user, 'icon' => $icon, 'url' => $url));
     echo EJSON_START . $message . EJSON_END;
     flush();
     JFactory::getApplication()->close();
 }