public function handle() { $this->getAccessToken(); $state = $this->getVar('oauth_state'); /* If oauth_token is missing get it */ if ($this->_context->get('oauth_token') != "" && $state === 'start') { /*{{{*/ $this->setVar('oauth_state', 'returned'); $state = 'returned'; } /*}}}*/ $class = new ReflectionClass($this->_className); switch ($state) { /*{{{*/ default: /* Create CredentialsOAuth object with app key/secret */ $to = $class->newInstance($this->_consumer_key, $this->_consumer_secret); /* Request tokens from OAuth Server */ $tok = $to->getRequestToken(); /* Save tokens for later */ $this->setVar('oauth_request_token', $token = $tok['oauth_token']); $this->setVar('oauth_request_token_secret', $tok['oauth_token_secret']); $this->setVar('oauth_state', "start"); /* Build the authorization URL */ $request_link = $to->getAuthorizeURL($token); $this->_context->redirectUrl($request_link); break; case 'returned': /* If the access tokens are already set skip to the API call */ if ($this->getVar('oauth_access_token') === "" && $this->getVar('oauth_access_token_secret') === "") { /* Create CredentialOAuth object with app key/secret and token key/secret from default phase */ $to = $class->newInstance($this->_consumer_key, $this->_consumer_secret, $this->getVar('oauth_request_token'), $this->getVar('oauth_request_token_secret')); /* Request access tokens from OAuth Server */ $tok = $to->getAccessToken(); /* Save the access tokens. Normally these would be saved in a database for future use. */ $this->setVar('oauth_access_token', $tok['oauth_token']); $this->setVar('oauth_access_token_secret', $tok['oauth_token_secret']); $this->saveAccessToken(); } /* Create CredentialsOAuth with app key/secret and user access key/secret */ $to = $class->newInstance($this->_consumer_key, $this->_consumer_secret, $this->getVar('oauth_access_token'), $this->getVar('oauth_access_token_secret')); return $to; break; } /*}}}*/ }
/** *@desc Contains specific instructions to generate all XML informations-> This method is processed only one time-> Usually is the last method processed-> *@param DOMNode $current \DOMNode where the XML will be created-> *@return void */ public function generateObject($current) { // Improve Security $wrongway = !$this->_edit && ($this->_currentAction == self::ACTION_EDIT || $this->_currentAction == self::ACTION_EDIT_CONFIRM); $wrongway = $wrongway || !$this->_new && ($this->_currentAction == self::ACTION_NEW || $this->_currentAction == self::ACTION_NEW_CONFIRM); $wrongway = $wrongway || !$this->_delete && ($this->_currentAction == self::ACTION_DELETE || $this->_currentAction == self::ACTION_DELETE_CONFIRM); if ($wrongway) { $message = $this->_lang->Value("MSG_DONT_HAVEGRANT"); $p = new XmlParagraphCollection(); $p->addXmlnukeObject(new XmlnukeText($message, true, true, false)); $p->generateObject($current); return; } // Checkings! if ($this->_context->get(self::PARAM_CANCEL) != "") { $this->listAllRecords()->generateObject($current); } else { if (strpos($this->_currentAction, "_confirm") !== false) { try { $validateResult = $this->updateRecord(); } catch (Exception $ex) { $nvc = array($ex->getMessage()); //XmlParagraphCollection $p $p = new XmlParagraphCollection(); $p->addXmlnukeObject(new XmlEasyList(EasyListType::UNORDEREDLIST, "Error", $this->_lang->Value("ERR_FOUND"), $nvc, "")); //XmlAnchorCollection $a $a = new XmlAnchorCollection("javascript:history.go(-1)", ""); $a->addXmlnukeObject(new XmlnukeText($this->_lang->Value("TXT_GOBACK"))); $p->addXmlnukeObject($a); $validateResult = $p; } if (is_null($validateResult)) { $this->_context->redirectUrl($this->redirProcessPage(false)); } else { $validateResult->generateObject($current); if ($this->_currentAction != XmlnukeCrudBase::ACTION_NEW_CONFIRM) { $this->showCurrentRecord()->generateObject($current); } } } else { if ($this->_currentAction == self::ACTION_MSG) { $this->showResultMessage()->generateObject($current); $this->listAllRecords()->generateObject($current); } else { if ($this->_currentAction == self::ACTION_NEW || $this->_currentAction == self::ACTION_VIEW || $this->_currentAction == self::ACTION_EDIT || $this->_currentAction == self::ACTION_DELETE) { $this->showCurrentRecord()->generateObject($current); } else { $this->listAllRecords()->generateObject($current); } } } } }