Beispiel #1
0
 /**
  *@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("&", "&amp;", $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;
 }
Beispiel #2
0
 /**
  *@param Context $context
  *@return string
  *@desc Build full URL.
  */
 public function getUrlFull()
 {
     $url = $this->_target;
     $separator = "?";
     foreach ($this->_parameters as $param => $value) {
         if ($separator == "?") {
             if (strpos($url, "?") !== false) {
                 $separator = '&';
             }
         }
         $url .= $separator . $param . "=" . urlencode($value);
     }
     $processor = new ParamProcessor();
     return $processor->GetFullLink($url);
     //return htmlentities($processor->GetFullLink($url));
 }
Beispiel #3
0
 /**
  *@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());
     }
 }
Beispiel #4
0
 public function addRedirectButton($text, $url)
 {
     $param = new ParamProcessor();
     $urlXml = $param->GetFullLink($url);
     $this->_buttons[$text] = "window.location='{$urlXml}';";
 }
Beispiel #5
0
 /**
  * Redirect to Url.
  * @access public
  * @param string $url
  * @return void
  */
 public function redirectUrl($url)
 {
     $processor = new ParamProcessor();
     $url = $processor->GetFullLink($url);
     $url = str_replace("&amp;", "&", $url);
     // IIS running CGI mode has a bug related to POST and header(LOCATION) to the SAME script.
     // In this environment the behavior expected causes a loop to the same page
     // To reproduce this behavior comment the this and try use any processpage state class
     $isBugVersion = stristr(PHP_OS, "win") && stristr($this->get("GATEWAY_INTERFACE"), "cgi") && stristr($this->get("SERVER_SOFTWARE"), "iis");
     ob_clean();
     if (!$isBugVersion) {
         header("Location: " . $url);
     }
     echo "<html>";
     echo "<head>";
     echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1;URL={$url}\">";
     echo "<style type='text/css'> ";
     echo "\t#logo{";
     echo "\t\twidth:32px;";
     echo "\t\theight:32px;";
     echo "\t\ttop: 50%;";
     echo "\t\tleft: 50%;";
     echo "\t\tmargin-top: -16px;";
     echo "\t\tmargin-left: -16px;";
     echo "\t\tposition:absolute;";
     echo "} </style>";
     echo "</head>";
     echo "<h1></h1>";
     echo "<div id='logo'><a href='{$url}'><img src='common/imgs/ajax-loader.gif' border='0' title='If this page does not refresh, Click here' alt='If this page does not refresh, Click here' /></a></div>";
     echo "</html>";
     exit;
 }