/** *@param string $singlename *@return string *@desc Constructor */ public function __construct($singlename) { if (strpos($singlename, "..") === false) { $this->_singlename = $singlename; $this->_context = Context::getInstance(); $lang = $this->_context->Language(); if ($lang != null) { $this->_languageid = strtolower($lang->getName()); } else { $this->_languageid = 'en-us'; } $this->_filenameLocation = ForceFilenameLocation::UseWhereExists; } else { throw new InvalidArgumentException("Invalid file name"); } }
/** *@desc XmlFormCollection construction *@param Context $context *@param string $action *@param string $title */ public function __construct($context, $action, $title) { parent::__construct(); $this->_context = $context; $this->_action = $action; $this->_title = $title; $this->_formname = "frm" . $this->_context->getRandomNumber(10000); $this->_jsValidate = true; $this->_decimalSeparator = $this->_context->Language()->getDecimalPoint(); $this->_dateformat = $this->_context->Language()->getDateFormat(); }
/** *@param string $xslPath *@return string *@desc Return the XSL with snippet to/from cache. */ public function IncludeSnippet($xslPath) { $xslName = $this->_file->ToString() . '.' . strtolower($this->_context->Language()->getName()) . '.xsl'; $cacheEngine = $this->_context->getXSLCacheEngine(); $result = $cacheEngine->get($xslName, 7200); // Create a new stream representing the file to be written to, // and write the stream cache the stream // from the external location to the file (only if doesnt exist) if ($result === false) { $content = ""; $content = file_get_contents($xslPath); try { $cacheEngine->lock($xslName); $iStart = strpos($content, "<xmlnuke-"); while ($iStart !== false) { $iEnd = strpos($content, ">", $iStart + 1); $snippetFile = substr($content, $iStart + 9, $iEnd - $iStart - 10); $snippet = new SnippetFilenameProcessor(trim($snippetFile)); if (!FileUtil::Exists($snippet)) { throw new SnippetNotFoundException("Snippet " . $snippet->FullQualifiedNameAndPath() . " not found"); } $sReadSnippet = file_get_contents($snippet->FullQualifiedNameAndPath()); $content = substr($content, 0, $iStart) . self::LF . $sReadSnippet . substr($content, $iEnd + 1); $iStart = strpos($content, "<xmlnuke-"); } $cacheEngine->unlock($xslName); $cacheEngine->set($xslName, $content); return $content; } catch (Exception $ex) { $cacheEngine->unlock($xslName); $cacheEngine->release($xslName); throw $ex; } } else { // Already in Cache return $result; } }
/** * Initialize a poll context * Use the method processData to process data. * * @param Context $context * @param string $urlProcess * @param string $poll * @param string $lang * @return XmlnukePoll */ public function __construct($urlProcess, $poll, $lang = "") { $this->_context = Context::getInstance(); $this->_url = $urlProcess; $this->_poll = $poll; if ($lang != "") { $this->_lang = $lang; } else { $this->_lang = $this->_context->Language()->getName(); } $this->_processed = false; $this->getPollConfig(); $this->_myWords = LanguageFactory::GetLanguageCollection(get_class()); }
/** *@param AnydatasetBaseFilenameProcessor $langFile *@return void *@desc Load Languages */ public function LoadLanguages($langFile) { $all = $langFile->ToString() == "_all"; if (!$all) { $this->LoadLanguages(new AnydatasetLangFilenameProcessor("_all")); } $this->_loadedFromFile = false; $paths = array(); if ($langFile->getFilenameLocation() == ForceFilenameLocation::UseWhereExists || $langFile->getFilenameLocation() == ForceFilenameLocation::SharedPath) { $paths[] = $langFile->SharedPath(); } if ($langFile->getFilenameLocation() == ForceFilenameLocation::UseWhereExists || $langFile->getFilenameLocation() == ForceFilenameLocation::PrivatePath) { $paths = array_merge($paths, $langFile->PrivatePath()); } foreach ($paths as $path) { $filename = $path . $langFile->FullQualifiedName(); $this->_debugInfo .= $langFile->ToString() . " in " . $filename . ' '; if (!FileUtil::Exists($filename)) { $this->_debugInfo .= "[Does not exists]; \n"; continue; } $this->_debugInfo .= "[Exists]; \n"; $curLang = strtolower($this->_context->Language()->getName()); try { $lang = new AnyDataset($filename); } catch (Exception $e) { throw new EngineException('Can\'t load language file "' . $langFile->FullQualifiedName() . '"! ' . $e->getMessage()); } $itf = new IteratorFilter(); $itf->addRelation("LANGUAGE", Relation::EQUAL, $curLang); //AnyIterator $it = $lang->getIterator($itf); if ($it->hasNext()) { //SingleRow $sr = $it->moveNext(); $names = $sr->getFieldNames(); foreach ($names as $name) { $this->addText($curLang, $name, $sr->getField($name)); } $this->_loadedFromFile = true; } } }
/** * @return string */ public function getCacheId() { if ($this->_cacheId == "") { // Starting NAME $id = strtolower(get_class($this)) . $this->_context->getXsl() . "#" . $this->_context->Language()->getName(); // Exclude common and random parameteres from request $exclude = array("phpsessid" => 1, "reset" => 1, "debug" => 1, "nocache" => 1, "x" => 1, "y" => 1, "site" => 1, "xml" => 1, "xsl" => 1, "module" => 1, "__clickevent" => 1, "__postback" => 1) + $_COOKIE; $arrRequest = array_diff_key($_REQUEST, $exclude); // Create array of parameters from request $keys = array(); foreach ($arrRequest as $key => $value) { $key = strtolower($key); $value = is_array($value) ? sha1(serialize($value)) : strtolower($value); if (strpos($key, "imagefield_") === false) { $keys[] = $key . "=" . $value; } } asort($keys); $idParam = implode("/", $keys); $this->_cacheId = $id . ":" . md5($idParam); } return $this->_cacheId; }
/** *@desc Generate $page, processing yours childs. *@param DOMNode $current *@return void */ public function generateObject($current) { $nodeWorking = XmlUtil::CreateChild($current, "editlist", ""); XmlUtil::AddAttribute($nodeWorking, "module", $this->_module); XmlUtil::AddAttribute($nodeWorking, "title", $this->_title); XmlUtil::AddAttribute($nodeWorking, "name", $this->_name); if ($this->_new) { XmlUtil::AddAttribute($nodeWorking, "new", "true"); } if ($this->_edit) { XmlUtil::AddAttribute($nodeWorking, "edit", "true"); } if ($this->_view) { XmlUtil::AddAttribute($nodeWorking, "view", "true"); } if ($this->_delete) { XmlUtil::AddAttribute($nodeWorking, "delete", "true"); } if ($this->_readonly) { XmlUtil::AddAttribute($nodeWorking, "readonly", "true"); } if ($this->_selecttype == SelectType::CHECKBOX) { XmlUtil::AddAttribute($nodeWorking, "selecttype", "check"); } if ($this->_extraParam != null) { foreach ($this->_extraParam as $key => $value) { $param = XmlUtil::CreateChild($nodeWorking, "param", ""); XmlUtil::AddAttribute($param, "name", $key); XmlUtil::AddAttribute($param, "value", $value); } } $processor = new ParamProcessor(); if ($this->_customButton != null) { for ($i = 0, $customButtonsLength = sizeof($this->_customButton); $i < $customButtonsLength; $i++) { // CustomButtons $cb $cb = $this->_customButton[$i]; if ($cb->enabled) { $nodeButton = XmlUtil::CreateChild($nodeWorking, "button"); if ($cb->url != "") { $cb->url = str_replace("&", "&", $processor->GetFullLink($cb->url)); } XmlUtil::AddAttribute($nodeButton, "custom", $i + 1); XmlUtil::AddAttribute($nodeButton, "acao", $cb->action); XmlUtil::AddAttribute($nodeButton, "alt", $cb->alternateText); XmlUtil::AddAttribute($nodeButton, "url", $cb->url); XmlUtil::AddAttribute($nodeButton, "img", $cb->icon); XmlUtil::AddAttribute($nodeButton, "multiple", $cb->multiple); XmlUtil::AddAttribute($nodeButton, "message", $cb->message); } } } $qtd = 0; $qtdPagina = 0; $page = 0; $started = !$this->_enablePages; $first = true; $firstRow = true; $summaryFields = array(); if (!$this->_it instanceof IteratorInterface) { throw new InvalidArgumentException('You have to pass an IteratorInterface object to the XmlEditList'); } // Generate XML With Data while ($this->_it->hasNext()) { //com.xmlnuke.anydataset.SingleRow $registro = $this->_it->moveNext(); // Insert fields if none is passed. if (sizeof($this->_fields) == 0) { foreach ($registro->getFieldNames() as $key => $fieldname) { $fieldtmp = new EditListField(true); $fieldtmp->editlistName = $fieldname; $fieldtmp->fieldData = $fieldname; $fieldtmp->fieldType = EditListFieldType::TEXT; $this->addEditListField($fieldtmp); if (sizeof($this->_fields) == 1) { $this->addEditListField($fieldtmp); } } } // Fill values if ($this->_enablePages) { $page = intval($qtd / $this->_qtdRows) + 1; $started = $page == $this->_curPage; } if ($started) { //\DOMNode $row = XmlUtil::CreateChild($nodeWorking, "row", ""); $currentNode = null; if (is_null($this->_fields)) { throw new InvalidArgumentException("No such EditListField Object", 850); } foreach ($this->_fields as $chave => $field) { if ($field->newColumn || $currentNode == null) { $currentNode = XmlUtil::CreateChild($row, "field", ""); if ($firstRow) { if (!$first) { XmlUtil::AddAttribute($currentNode, "name", $field->editlistName); } else { $first = false; } XmlUtil::AddAttribute($currentNode, "source", $field->fieldData); } } else { XmlUtil::CreateChild($currentNode, "br", ""); } $this->renderColumn($currentNode, $registro, $field); // Check if this fields requires summary if ($field->summary != EditListFieldSummary::NONE) { $summaryFields[$field->fieldData] += $this->_context->Language()->getDoubleVal($registro->getField($field->fieldData)); } } $firstRow = false; $qtdPagina++; } $qtd += 1; } // Generate SUMMARY Information if (sizeof($summaryFields) > 0) { $anydata = new AnyDataset(); $anydata->appendRow(); foreach ($this->_fields as $chave => $field) { switch ($field->summary) { case EditListFieldSummary::SUM: $value = $summaryFields[$field->fieldData]; break; case EditListFieldSummary::AVG: $value = $summaryFields[$field->fieldData] / $qtdPagina; break; case EditListFieldSummary::COUNT: $value = $qtdPagina; break; default: $value = ""; break; } $anydata->addField($field->fieldData, $value); } $ittemp = $anydata->getIterator(); $registro = $ittemp->moveNext(); $row = XmlUtil::CreateChild($nodeWorking, "row", ""); XmlUtil::AddAttribute($row, "total", "true"); foreach ($this->_fields as $chave => $field) { $currentNode = null; if ($field->newColumn || $currentNode == null) { $currentNode = XmlUtil::CreateChild($row, "field", ""); } else { XmlUtil::CreateChild($currentNode, "br", ""); } $this->renderColumn($currentNode, $registro, $field); } } // Create other properties XmlUtil::AddAttribute($nodeWorking, "cols", sizeof($this->_fields)); if ($this->_enablePages) { if ($this->_curPage > 1) { XmlUtil::AddAttribute($nodeWorking, "pageback", strval($this->_curPage - 1)); } if (!$started) { XmlUtil::AddAttribute($nodeWorking, "pagefwd", strval($this->_curPage + 1)); } XmlUtil::AddAttribute($nodeWorking, "curpage", strval($this->_curPage)); XmlUtil::AddAttribute($nodeWorking, "offset", strval($this->_qtdRows)); XmlUtil::AddAttribute($nodeWorking, "pages", strval($page)); } if ($this->_customsubmit != "") { XmlUtil::AddAttribute($nodeWorking, "customsubmit", $this->_customsubmit); } if (!is_null($this->_objXmlHeader)) { $nodeHeader = XmlUtil::CreateChild($nodeWorking, "xmlheader", ""); $this->_objXmlHeader->generateObject($nodeHeader); } return $nodeWorking; }
/** *@desc Constructor *@param Context $context XMLNuke context object *@param array fields Fields will be processed *@param string header Simple $header *@param string module Module will be process this request-> Usually is the same $module instantiate the XmlnukeCrudDB *@param array $buttons Custom $buttons in View/Select mode *@return */ public function __construct($context, $fields, $header, $module, $buttons) { $this->_context = $context; $this->_fields = $fields->getCrudFieldCollection(); $this->_buttons = $buttons; $this->_header = $header; $this->_module = $module; $this->_new = true; $this->_view = true; $this->_delete = true; $this->_edit = true; $this->_currentAction = $this->_context->get("acao"); foreach ($this->_fields as $i => $field) { if ($field->key) { $this->_keyIndex[] = $i; } } $this->_parameter = array(); //$this->_filter = $this->_context->get("filter"); //encoded //$this->_sort = $this->_context->get("sort"); // encoded $this->_valueId = $this->_context->get("valueid"); $this->_curPage = $this->_context->get("curpage"); $this->_qtdRows = $this->_context->get("offset"); $this->_decimalSeparator = $this->_context->Language()->getDecimalPoint(); $this->_dateFormat = $this->_context->Language()->getDateFormat(); $this->_lang = LanguageFactory::GetLanguageCollection(__CLASS__); }
/** *@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()); } }
/** *@param string $strHref *@return string - Return the new string if exists engine:xmlnuke or module:... Otherwise returns the original value *@desc Replace a HREF value with XMLNuke context values. */ public function GetFullLink($strHref) { $arResult = array(); $result = ""; $pattern = "(?:(?P<protocol>module|admin|engine):)?(?P<host>[\\w\\d\\-\\.]*)(?P<port>:\\d*)?(?:\\?(?P<param>(([\\w\\d\\W]*=[\\w\\d\\W]*)(?:&(?:amp;)?)?)*))?"; preg_match_all("/{$pattern}/", $strHref, $arResult); $sep = "?"; switch ($arResult["protocol"][0]) { case "engine": if ($arResult["host"][0] == "xmlnuke") { $result = $this->_context->UrlXmlnukeEngine() . $arResult["port"][0]; } else { $result = "Unknow Engine " . $arResult["host"][0]; } break; case "module": if ($arResult['host'][0] == '__self__') { $result = $this->_context->UrlModule() . $arResult["port"][0] . "?module=" . $this->_context->getModule(); } else { $result = $this->_context->UrlModule() . $arResult["port"][0] . "?module=" . $arResult["host"][0]; } $sep = "&"; break; case "admin": if ($arResult["host"] == "engine") { $result = $this->_context->UrlXmlNukeAdmin() . $arResult["port"][0]; } else { $result = $this->_context->UrlModule() . $arResult["port"][0] . "?module=" . (strpos($arResult["host"][0], ".") === false ? "Xmlnuke.Admin." : "") . $arResult["host"][0]; $sep = "&"; } break; default: return $strHref; } $arParam = array(); $xmlnukeParam = array(); $fullLink = $this->_context->get("xmlnuke.USEFULLPARAMETER") == "true"; if ($fullLink || $this->_context->getXsl() != $this->_context->get("xmlnuke.DEFAULTPAGE")) { $xmlnukeParam["xsl"] = $this->_context->getXsl() == "index" ? $this->_context->get("xmlnuke.DEFAULTPAGE") : $this->_context->getXsl(); } if ($fullLink) { $xmlnukeParam["xml"] = $this->_context->getXml(); } if ($fullLink || array_key_exists("lang", $_REQUEST) && $_REQUEST["lang"] == strtolower($this->_context->Language()->getName())) { $xmlnukeParam["lang"] = strtolower($this->_context->Language()->getName()); } $paramsTmp = explode("&", str_replace("&", "&", $arResult["param"][0])); foreach ($paramsTmp as $value) { $arTmp = explode("=", $value); switch ($arTmp[0]) { case "xml": case "xsl": case "lang": $xmlnukeParam[$arTmp[0]] = $arTmp[1]; break; default: if ($value != "") { $arParam[] = $value; } } } $strParam = implode("&", $arParam); $arParam2 = array(); foreach ($xmlnukeParam as $key => $value) { $arParam2[] = $key . "=" . $value; } $strParam2 = implode("&", $arParam2); $paramsFinal = $strParam2 . (!empty($strParam2) && !empty($strParam) ? "&" : "") . $strParam; return $this->_context->VirtualPathAbsolute($result . ($paramsFinal != "" ? $sep . $paramsFinal : "")); }