42 $oXPath =
new DomXPath($oDom);
43 $oNodeList = $oXPath->query($sParentXPath);
45 foreach ($oNodeList as $oNode) {
46 $sId = $oNode->getAttribute(
'id');
47 $oChildList = $oXPath->query(
"{$sParentXPath}[@id='$sId']/$sChildXPath");
48 if (!$oChildList->length) {
49 $oNode->parentNode->removeChild($oNode);
62 $oXPath =
new DomXPath($oDom);
65 $oNodeList = $oXPath->query(
"//SUBMENU[@cl]");
66 foreach ($oNodeList as $oNode) {
68 $sCl = $oNode->getAttribute(
'cl');
69 $sCl = $sCl ?
"cl=$sCl" :
'';
72 $sParam = $oNode->getAttribute(
'clparam');
73 $sParam = $sParam ?
"&$sParam" :
'';
76 $oNode->setAttribute(
'link',
"{$sURL}{$sCl}{$sParam}");
89 $oDomFile =
new DomDocument();
90 $oDomFile->preserveWhiteSpace =
false;
91 if (!@$oDomFile->load($sMenuFile)) {
93 } elseif (is_readable($sMenuFile) && ($sXml = @file_get_contents($sMenuFile))) {
96 if (
getStr()->preg_match(
"/encoding\=(.*)\?>/", $sXml, $aMatches) !== 0) {
97 if (isset($aMatches[1])) {
98 $sCurrEncoding = trim($aMatches[1],
"\"");
99 if (!in_array(strtolower($sCurrEncoding), $this->_aSupportedExpathXmlEncodings)) {
100 $sXml = str_replace($aMatches[1],
"\"UTF-8\"", $sXml);
101 $sXml = iconv($sCurrEncoding,
"UTF-8", $sXml);
107 if (@$oDomFile->loadXml($sXml)) {
113 $this->
_merge($oDomFile, $oDom);
127 $sURL =
'index.php?';
129 $oXPath =
new DomXPath($oDom);
130 $oNodeList = $oXPath->query(
"//OXMENU[@type='dyn']/MAINMENU/SUBMENU");
132 foreach ($oNodeList as $oNode) {
135 $sCl = $oNode->getAttribute(
'cl');
136 $sCl =
"cl=dynscreen&menu=$sCl";
139 $sParam = $oNode->getAttribute(
'clparam');
140 $sParam = $sParam ?
"&$sParam" :
'';
143 if (!$oNode->getAttribute(
'list')) {
144 $oNode->setAttribute(
'list',
'dynscreen_list');
145 $oNode->setAttribute(
'listparam',
'menu=' . $oNode->getAttribute(
'cl'));
149 $oNode->setAttribute(
'link',
"{$sURL}{$sCl}{$sParam}");
152 $oNode->parentNode->setAttribute(
'id',
'dyn_menu');
157 $sFile = $oNode->getAttribute(
'cl');
161 if ($myUtilsFile->checkFile(
"{$this->_sDynIncludeUrl}pages/{$sFile}_about.php")) {
162 $oTabElem =
new DOMElement(
'TAB');
163 $oNode->appendChild($oTabElem);
164 $oTabElem->setAttribute(
'external',
'true');
165 $oTabElem->setAttribute(
'location',
"{$this->_sDynIncludeUrl}pages/{$sFile}_about.php");
166 $oTabElem->setAttribute(
'id',
'dyn_about');
170 if ($myUtilsFile->checkFile(
"{$this->_sDynIncludeUrl}pages/{$sFile}_technics.php")) {
171 $oTabElem =
new DOMElement(
'TAB');
172 $oNode->appendChild($oTabElem);
173 $oTabElem->setAttribute(
'external',
'true');
174 $oTabElem->setAttribute(
'location',
"{$this->_sDynIncludeUrl}pages/{$sFile}_technics.php");
175 $oTabElem->setAttribute(
'id',
'dyn_interface');
179 if (file_exists(
$myConfig->getConfigParam(
'sShopDir') .
"/application/controllers/admin/{$sFile}.php")) {
180 $oTabElem =
new DOMElement(
'TAB');
181 $oNode->appendChild($oTabElem);
182 $oTabElem->setAttribute(
'id',
'dyn_interface');
183 $oTabElem->setAttribute(
'cl', $sFile);
196 $oXPath =
new DomXPath($oDom);
198 foreach (array(
'url',
'link') as $sAttrType) {
199 foreach ($oXPath->query(
"//OXMENU//*[@$sAttrType]") as $oNode) {
200 $sLocalUrl = $oNode->getAttribute($sAttrType);
201 if (strpos($sLocalUrl,
'index.php?') === 0) {
202 $sLocalUrl = $oStr->preg_replace(
'#^index.php\?#', $sURL, $sLocalUrl);
203 $oNode->setAttribute($sAttrType, $sLocalUrl);
216 $oXPath =
new DomXPath($oDom);
217 $oNodeList = $oXPath->query(
'//*[@rights or @norights]');
219 foreach ($oNodeList as $oNode) {
221 if (($sReq = $oNode->getAttribute(
'rights'))) {
222 $aPerm = explode(
',', $sReq);
223 foreach ($aPerm as $sPerm) {
225 $oNode->parentNode->removeChild($oNode);
229 } elseif (($sNoReq = $oNode->getAttribute(
'norights'))) {
230 $aPerm = explode(
',', $sNoReq);
231 foreach ($aPerm as $sPerm) {
233 $oNode->parentNode->removeChild($oNode);
247 $oXPath =
new DomXPath($oDom);
248 $oNodeList = $oXPath->query(
"//*[@nogroup or @group]");
250 foreach ($oNodeList as $oNode) {
252 if (($sReq = $oNode->getAttribute(
'group'))) {
253 $aPerm = explode(
',', $sReq);
254 foreach ($aPerm as $sPerm) {
255 if ($sPerm && !$this->
_hasGroup($sPerm)) {
256 $oNode->parentNode->removeChild($oNode);
260 } elseif (($sNoReq = $oNode->getAttribute(
'nogroup'))) {
261 $aPerm = explode(
',', $sNoReq);
262 foreach ($aPerm as $sPerm) {
263 if ($sPerm && $this->
_hasGroup($sPerm)) {
264 $oNode->parentNode->removeChild($oNode);
285 $oXPath =
new DomXPath($oDom);
286 $oNodeList = $oXPath->query(
"//*[@disableForDemoShop]");
287 foreach ($oNodeList as $oNode) {
288 if ($oNode->getAttribute(
'disableForDemoShop')) {
289 $oNode->parentNode->removeChild($oNode);
302 foreach ($oDomElemFrom->attributes as $oAttr) {
303 $oDomElemTo->setAttribute($oAttr->nodeName, $oAttr->nodeValue);
316 protected function _mergeNodes($oDomElemTo, $oDomElemFrom, $oXPathTo, $oDomDocTo, $sQueryStart)
318 foreach ($oDomElemFrom->childNodes as $oFromNode) {
319 if ($oFromNode->nodeType === XML_ELEMENT_NODE) {
321 $sFromAttrName = $oFromNode->getAttribute(
'id');
322 $sFromNodeName = $oFromNode->tagName;
325 $sQuery =
"{$sQueryStart}/{$sFromNodeName}[@id='{$sFromAttrName}']";
326 $oCurNode = $oXPathTo->query($sQuery);
329 if ($oCurNode->length == 0) {
330 $oDomElemTo->appendChild($oDomDocTo->importNode($oFromNode,
true));
333 $oCurNode = $oCurNode->item(0);
338 if ($oFromNode->childNodes->length) {
339 $this->
_mergeNodes($oCurNode, $oFromNode, $oXPathTo, $oDomDocTo, $sQuery);
352 protected function _merge($oDomNew, $oDom)
354 $oXPath =
new DOMXPath($oDom);
355 $this->
_mergeNodes($oDom->documentElement, $oDomNew->documentElement, $oXPath, $oDom,
'/OX');
367 public function getTabs($sId, $iAct, $blSetActive =
true)
369 $oXPath =
new DOMXPath($this->
getDomXml());
371 $oNodeList = $oXPath->query(
"//SUBMENU[@cl='$sId']/TAB | //SUBMENU[@list='$sId']/TAB | //SUBMENU/../TAB[@cl='$sId']");
373 $iAct = ($iAct > $oNodeList->length) ? ($oNodeList->length - 1) : $iAct;
376 foreach ($oNodeList as $iPos => $oNode) {
377 if ($iPos == $iAct) {
379 $oNode->setAttribute(
'active', 1);
398 $oNodeList = $this->
getTabs($sId, $iAct,
false);
399 $iAct = ($iAct > $oNodeList->length) ? ($oNodeList->length - 1) : $iAct;
400 if ($oNodeList->length && ($oNode = $oNodeList->item($iAct))) {
401 $sTab = $oNode->getAttribute(
'cl');
417 $oXPath =
new DOMXPath($this->
getDomXml());
418 $oNodeList = $oXPath->query(
"//TAB[@cl='$sClass']/../BTN");
419 if ($oNodeList->length) {
420 $oButtons =
new stdClass();
421 foreach ($oNodeList as $oNode) {
422 $sBtnID = $oNode->getAttribute(
'id');
423 $oButtons->$sBtnID = 1;
440 $sFullAdminDir = getShopBasePath() .
'application/views/admin';
441 $sMenuFile =
"/menu.xml";
443 $sTmpDir =
$myConfig->getConfigParam(
'sCompileDir');
445 $sLocalDynPath =
"{$sTmpDir}{$sDynLang}_dynscreen.xml";
449 if (file_exists($sFullAdminDir . $sMenuFile)) {
450 $aFilesToLoad[] = $sFullAdminDir . $sMenuFile;
454 if (file_exists(
"$sFullAdminDir/user.xml")) {
455 $aFilesToLoad[] =
"$sFullAdminDir/user.xml";
459 $sPath = getShopBasePath();
460 $oModulelist =
oxNew(
'oxmodulelist');
461 $aActiveModuleInfo = $oModulelist->getActiveModuleInfo();
462 if (is_array($aActiveModuleInfo)) {
463 foreach ($aActiveModuleInfo as $sModulePath) {
464 $sFullPath = $sPath .
"modules/" . $sModulePath;
466 if (is_dir($sFullPath)) {
468 $sMenuFile = $sFullPath .
"/menu.xml";
469 if (file_exists($sMenuFile) && is_readable($sMenuFile)) {
470 $aFilesToLoad[] = $sMenuFile;
476 $blLoadDynContents =
$myConfig->getConfigParam(
'blLoadDynContents');
477 $sShopCountry =
$myConfig->getConfigParam(
'sShopCountry');
482 if ($blLoadDynContents) {
484 $sRemoteDynUrl = $this->
_getDynMenuUrl($sDynLang, $blLoadDynContents);
490 if ((!isset($blLoadRemote) || $blLoadRemote) && ($sDynPath = $myOxUtlis->getRemoteCachePath($sRemoteDynUrl, $sLocalDynPath))) {
505 $aFilesToLoad[] = $sDynPath;
508 return $aFilesToLoad;
521 if (file_exists($sDynFilePath)) {
523 if (($rHandle = @fopen($sDynFilePath,
'r'))) {
524 $sLine = stream_get_line($rHandle, 100,
"?>");
528 if ($sLine && stripos($sLine,
'<?xml') !==
false) {
529 $sDynFile = $sDynFilePath;
535 @unlink($sDynFilePath);
556 return $sCacheContents;
566 if ($this->_oInitialDom === null) {
575 $sShopId = $this->
getConfig()->getActiveShop()->getShopId();
576 $sCacheName =
'menu_' . $sDynLang . $sShopId .
'_xml';
577 $sCacheFile = $myOxUtlis->getCacheFilePath($sCacheName);
578 $sCacheContents = $myOxUtlis->fromFileCache($sCacheName);
579 if ($sCacheContents && file_exists($sCacheFile) && ($iCacheModTime = filemtime($sCacheFile))) {
580 foreach ($aFilesToLoad as $sDynPath) {
581 if ($iCacheModTime < filemtime($sDynPath)) {
589 $this->_oInitialDom =
new DOMDocument();
592 $this->_oInitialDom->appendChild(
new DOMElement(
'OX'));
594 foreach ($aFilesToLoad as $sDynPath) {
605 $myOxUtlis->toFileCache($sCacheName, $this->_oInitialDom->saveXML());
609 $this->_oInitialDom->preserveWhiteSpace =
false;
610 $this->_oInitialDom->loadXML($sCacheContents);
628 if ($this->_oDom === null) {
657 $oXPath =
new DOMXPath($this->
getDomXml());
658 $oNodeList = $oXPath->query(
"//SUBMENU[@cl='" . implode(
"' or @cl='", $aNodes) .
"']");
660 return ($oNodeList->length) ? $oNodeList : null;
670 $oXPath =
new DOMXPath($this->
getDomXml());
671 $oNodeList = $oXPath->query(
"//*[@cl='{$sNodeId}' or @list='{$sNodeId}']");
673 if ($oNodeList->length) {
674 foreach ($oNodeList as $oNode) {
676 $oNode->setAttribute(
'active', 1);
677 $oNode->parentNode->setAttribute(
'active', 1);
693 $oXPath =
new DOMXPath($this->
getDomXml());
694 $oNodeList = $oXPath->query(
"//SUBMENU[@cl='{$sId}']");
695 if ($oNodeList->length && ($oNode = $oNodeList->item(0))) {
696 $sCl = $oNode->getAttribute(
'list');
697 $sCl = $sCl ?
"cl=$sCl" :
'';
699 $sParams = $oNode->getAttribute(
'listparam');
700 $sParams = $sParams ?
"&$sParams" :
'';
702 $sUrl =
"{$sCl}{$sParams}";
719 $oXPath =
new DOMXPath($this->
getDomXml());
720 $oNodeList = $oXPath->query(
"//SUBMENU[@cl='{$sId}']/TAB");
722 $iActTab = ($iActTab > $oNodeList->length) ? ($oNodeList->length - 1) : $iActTab;
723 if ($oNodeList->length && ($oActTab = $oNodeList->item($iActTab))) {
725 if ($oActTab->getAttribute(
'external')) {
726 $sUrl = $oActTab->getAttribute(
'location');
728 $sCl = $oActTab->getAttribute(
'cl');
729 $sCl = $sCl ?
"cl={$sCl}" :
'';
731 $sParams = $oActTab->getAttribute(
'clparam');
732 $sParams = $sParams ?
"&{$sParams}" :
'';
734 $sUrl =
"{$sCl}{$sParams}";
750 if (($sAdminSslUrl =
$myConfig->getConfigParam(
'sAdminSSLURL'))) {
751 $sURL = trim($sAdminSslUrl,
'/');
753 $sURL = trim(
$myConfig->getConfigParam(
'sShopURL'),
'/') .
'/admin';
756 return oxRegistry::get(
"oxUtilsUrl")->processUrl(
"{$sURL}/index.php",
false);
768 return $this->
getUser()->oxuser__oxrights->value == $sRights;
780 return $this->
getUser()->inGroup($sGroupId);
795 $oNodeList = $oXPath->query(
"//*[@cl='{$sClassName}' or @list='{$sClassName}']");
796 if ($oNodeList->length && ($oFirstItem = $oNodeList->item(0))) {
797 $sClassId = $oFirstItem->getAttribute(
'id');
814 if (!$blLoadDynContents) {
816 $sFullAdminDir = getShopBasePath() .
'application/views/admin';
817 $sUrl = $sFullAdminDir .
"/dynscreen_local.xml";
819 $oAdminView =
oxNew(
'oxadminview');
820 $this->_sDynIncludeUrl = $oAdminView->getServiceUrl($iLang);
821 $sUrl .= $this->_sDynIncludeUrl .
"menue/dynscreen.xml";
837 $iDynLang =
$myConfig->getConfigParam(
'iDynInterfaceLanguage');
838 $iDynLang = isset($iDynLang) ? $iDynLang : ($oLang->getTplLanguage());