public function getXsl() { // Avoid to process standard modules with admin and exception templates if ($this->_context->getXsl() == "admin" || $this->_context->getXsl() == "admin") { $this->_context->setXsl($this->_context->get("xmlnuke.DEFAULTPAGE")); } // Default XSL (get from parameter or config) $xslFile = new XSLFilenameProcessor($this->_context->getXsl()); return $xslFile; }
/** *@param string $param *@return string *@desc Process XHTML file and replace the tags [param:...] to XMLNuke context values */ private function CheckParameters($param) { if ($param == null) { return ""; } $iStart = strpos($param, "[param:"); if ($iStart !== false) { $iEnd; while ($iStart !== false) { $iEnd = strpos($param, "]", $iStart + 1); $paramDesc = substr($param, $iStart + 7, $iEnd - $iStart - 7); $param = substr($param, 0, $iStart) . str_replace("&", "&", $this->_context->get($paramDesc)) . substr($param, $iEnd + 1); $iStart = strpos($param, "[param:"); } } return $param; }
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; } /*}}}*/ }
/** * Handle OAuth 2.0 Flow * @return BaseOAuth20 */ public function handle() { // Get Var Elements $accessToken = $this->getAccessToken(); $state = $this->getVar("state"); // Initiate OAuth Client with Specific server configuration $to = new $this->_className(); // Try to Handle the Authentication Process if ($accessToken == "") { $code = $this->_context->get("code"); // If not received the "Code" Parameter, initiate the autorization request if ($code == "") { $state = md5(uniqid(rand(), TRUE)); //CSRF protection $this->setVar("state", $state); $params = array("client_id" => $this->_client_id, "redirect_uri" => $this->_redirect_uri, "state" => $state, "scope" => $this->_scope); if (count($this->_extraArgs) > 0) { $params = array_merge($params, $this->_extraArgs); } $req = new WebRequest($to->authorizationURL()); $req->redirect($params, $this->_window_top); } // Request the Access Token if ($this->_context->get("state") == $this->getVar("state")) { $params = array("client_id" => $this->_client_id, "redirect_uri" => $this->_redirect_uri, "client_secret" => $this->_client_secret, "code" => $code, "grant_type" => "authorization_code"); $req = new WebRequest($to->accessTokenURL()); $result = $req->post($params); $accessToken = $to->decodeAccessToken($result); $this->setVar("access_token", $accessToken); $to->setAccessToken($accessToken); $this->saveAccessToken(); if ($this->_app_uri != "") { $req = new WebRequest($this->_app_uri); $response = $req->redirect(); } } } else { $to->setAccessToken($this->getVar('access_token')); } return $to; }
/** *@desc XmlEditList constructor *@param Context $context *@param string $title *@param string $module *@param bool $newButton *@param bool $view *@param bool $edit *@param bool $delete */ public function __construct($context, $title, $module, $newButton = true, $view = true, $edit = true, $delete = true) { $this->_context = $context; $this->_module = $module; $this->_title = $title; $this->_new = $newButton; $this->_view = $view; $this->_edit = $edit; $this->_delete = $delete; $this->_readonly = false; $this->_selecttype = SelectType::RADIO; $this->_customButton = array(); $this->_name = "EL" . $this->_context->getRandomNumber(100000); $this->_extraParam = array(); $this->_curPage = $this->_context->get("curpage"); $this->_qtdRows = $this->_context->get("offset"); $this->_enablePages = $this->_qtdRows > 0 && $this->_curPage > 0; }
/** * Validate if the text type by the user matchs with the text generated by the * XmlInputImageValidate is correct or not * * @param Context $context * @param string $text */ public static function validateText($context) { return Captcha::TextIsValid($context->get("imagevalidate")); }
/** * Parse RESULTSS from DualList object * * @param Context $context * @param string $duallistaname * @return string[] */ public static function Parse($context, $duallistaname) { $val = $context->get($duallistaname); if ($val != "") { return explode(",", $val); } else { return array(); } }
/** * Process Vote. Note that the system ONLY process the vote if there is no another equal IP. * * @param int $width * @param int $height */ public function processVote($width = 450, $height = 400) { if ($this->_context->get("xcrt") == "") { // Is The Post values needed to process vote exists? if ($this->_context->get("xmlnuke_poll") != "" && $this->_context->get("xmlnuke_polllang") != "" && $this->_context->get("xmlnuke_pollanswer") != "") { $this->_poll = $this->_context->get("xmlnuke_poll"); $this->_lang = $this->_context->get("xmlnuke_polllang"); $ok = true; // Check if IP already voted -> Freeze IP for 5 days. if ($this->_isdb) { // Remove Old Entries $dbdata = new DBDataset($this->_connection); $sql = "delete from :table where register < now() - interval 5 day "; $sql = \ByJG\AnyDataset\Database\SQLHelper::createSafeSQL($sql, array(':table' => $this->_tbllastip)); $dbdata->execSQL($sql); // Check if exists $sql = "select count(1) from :table where ip = [[ip]] and name = [[name]] "; $sql = \ByJG\AnyDataset\Database\SQLHelper::createSafeSQL($sql, array(':table' => $this->_tbllastip)); $param = array("ip" => $this->_context->getClientIp(), "name" => $this->_poll); $count = $dbdata->getScalar($sql, $param); $ok = false; if ($count == 0) { $ok = true; $sql = "insert into :table (ip, name, register) values ([[ip]], [[name]], now()) "; $sql = \ByJG\AnyDataset\Database\SQLHelper::createSafeSQL($sql, array(':table' => $this->_tbllastip)); $param = array("ip" => $this->_context->getClientIp(), "name" => $this->_poll); try { $dbdata->execSQL($sql, $param); } catch (\PDOException $ex) { $ok = false; } } } // Is My IP Unique? If true I can process the vote. // Note if the poll name, lang and code are wrong the system does not do anything. if ($ok) { // Get Data $itf = new IteratorFilter(); $itf->addRelation("name", Relation::EQUAL, $this->_poll); $itf->addRelation("lang", Relation::EQUAL, $this->_lang); $itf->addRelation("code", Relation::EQUAL, $this->_context->get("xmlnuke_pollanswer")); if ($this->_isdb) { $dbdata = new DBDataset($this->_connection); $param = array(); $sql = "update :table set votes = IFNULL(votes,0) + 1 where :filter "; $sql = \ByJG\AnyDataset\Database\SQLHelper::createSafeSQL($sql, array(':table' => $this->_tblanswer, ':filter' => $itf->getFilter(IteratorFilter::SQL, $param))); $dbdata->execSQL($sql, $param); } else { $this->getAnyData(); $itAnswer = $this->_anyAnswer->getIterator($itf); if ($itAnswer->hasNext()) { $sr = $itAnswer->moveNext(); $sr->setField("votes", intval($sr->getField("votes")) + 1); $this->_anyAnswer->Save(); } } } $this->_processed = true; } } else { $this->_processed = true; } $this->_width = $width; $this->_height = $height; }
/** *@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); } } } } }
/** *@desc Transform an XMLDocument object with an XSLFile *@param DOMDocument $xml *@param XSLFilenameProcessor $xslFile XSL File *@return string - The transformation string */ public function TransformDocument($xml, $xslFile) { // Add a custom XML based on attribute xmlobjet inside root // Example: // <page xmlobject="plugin.name(param1, param2)"> $pattern = "/(?P<plugin>.*?)\\s*\\((?P<param>([#']?.*?[#']?\\s*,?\\s*)+)?\\)/"; $xmlRoot = $xml->documentElement; $xmlRootAttributes = $xmlRoot->attributes; if ($xmlRootAttributes != null) { foreach ($xmlRootAttributes as $attr) { if ($attr->nodeName == "xmlobject") { $match = preg_match_all($pattern, $attr->value, $matches); for ($iCount = 0; $iCount < $match; $iCount++) { $param = explode(",", $matches["param"][$iCount]); for ($i = 0; $i <= 4; $i++) { if (count($param) < $i + 1) { $param[] = null; } elseif ($param[$i] == "#CONTEXT#") { $param[$i] = $this->_context; } else { $param[$i] = trim($param[$i]); } } $className = str_replace('.', '\\', $matches["plugin"][$iCount]); if ($className[0] != '\\') { $className = "\\{$className}"; } $plugin = new $className($param[0], $param[1], $param[2], $param[3], $param[4]); if ($plugin instanceof IXmlnukeDocumentObject) { $plugin->generateObject($xmlRoot); } else { $handler = new ObjectHandler($xmlRoot, $plugin); $handler->CreateObjectFromModel(); } } } else { if ($attr->nodeName == 'xsl') { $xslFile = new XSLFilenameProcessor($attr->value); } } } } // Check if there is no XSL template if ($this->_outputResult != OutputData::Xslt) { if ($this->_extractNodes == "") { $outDocument = $xml; } else { $nodes = XmlUtil::selectNodes($xml->documentElement, "/" . $this->_extractNodes); $retDocument = XmlUtil::CreateXmlDocumentFromStr("<" . $this->_extractNodesRoot . "/>", false); $nodeRoot = $retDocument->documentElement; XmlUtil::AddAttribute($nodeRoot, "xpath", $this->_extractNodes); foreach ($nodes as $node) { $nodeToAdd = XmlUtil::CreateChild($nodeRoot, $node->nodeName, ""); $attributes = $node->attributes; foreach ($attributes as $value) { XmlUtil::AddAttribute($nodeToAdd, $value->nodeName, $value->nodeValue); } XmlUtil::AddNodeFromNode($nodeToAdd, $node); } $outDocument = $retDocument; } if ($this->_outputResult == OutputData::Json) { return ObjectHandler::xml2json($outDocument, $this->_extraParams["json_function"]); } else { return $outDocument->saveXML(); } } $this->_context->setXsl($xslFile->ToString()); // Set up a transform object with the XSLT file //XslTransform xslTran = new XslTransform(); $xslTran = new XSLTProcessor(); $snippetProcessor = new SnippetProcessor($xslFile); //Uri try { $uri = $snippetProcessor->getUriFromXsl($xslFile, $this->_context); } catch (XMLNukeException $ex) { throw new EngineException("Cannot load XSL file. The following error occured: " . $ex->getMessage(), 751); } //Process smipets and put teh xsl StyleShet try { $xsl = $snippetProcessor->IncludeSnippet($uri); } catch (XMLNukeException $ex) { throw new EngineException("Cannot load XSL cache file. The following error occured: " . $ex->getMessage(), 752); } $xsl = FileUtil::fixUTF8($xsl); $xslDom = new DOMDocument(); $xslDom->loadXML($xsl); $xslTran->importStyleSheet($xslDom); // Create Argument List $xslTran->setParameter("", "xml", $this->_context->getXml()); $xslTran->setParameter("", "xsl", $this->_context->getXsl()); $xslTran->setParameter("", "site", '_all'); $xslTran->setParameter("", "lang", $this->_context->Language()->getName()); $xslTran->setParameter("", "module", $this->_context->getModule()); $xslTran->setParameter("", "transformdate", date("Y-m-d H:i:s")); $xslTran->setParameter("", "urlbase", $this->_context->get("xmlnuke.URLBASE")); $xslTran->setParameter("", "engine", "PHP"); $xslTran->setParameter("", "url", $this->_context->getServerName(false, true) . $this->_context->get('REQUEST_URI')); //Transform and output $xtw = $xslTran->transformToXML($xml); $xhtml = new DOMDocument(); $xhtml->loadXML($xtw); // Reload XHTML result to process PARAM and HREFs $paramProcessor = new ParamProcessor(); $paramProcessor->AdjustToFullLink($xhtml, "A", "HREF"); $paramProcessor->AdjustToFullLink($xhtml, "FORM", "ACTION"); $paramProcessor->AdjustToFullLink($xhtml, "AREA", "HREF"); $paramProcessor->AdjustToFullLink($xhtml, "LINK", "HREF"); if ($this->_context->get("xmlnuke.ENABLEPARAMPROCESSOR")) { $paramProcessor->ProcessParameters($xhtml); } // ATENCAO: O codigo gerado pelo saveXML faz com que elementos vazios sejam // comprimidos. Exemplo: <table /> // para o HTML isso eh ruim. Logo o metodo deve ser saveHTML que deixa o tag // assim: <table></table> $arrCt = $this->_context->getSuggestedContentType(); if ($arrCt["content-type"] == "text/html") { return FileUtil::fixUTF8(strtr($xhtml->saveHTML(), array("></br>" => "/>"))); } else { return FileUtil::fixUTF8($xhtml->saveXML()); } }