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 );
64 $oXPath =
new DomXPath( $oDom );
67 $oNodeList = $oXPath->query(
"//SUBMENU[@cl]" );
68 foreach ( $oNodeList as $oNode ) {
70 $sCl = $oNode->getAttribute(
'cl' );
71 $sCl = $sCl?
"cl=$sCl":
'';
74 $sParam = $oNode->getAttribute(
'clparam' );
75 $sParam = $sParam?
"&$sParam":
'';
78 $oNode->setAttribute(
'link',
"{$sURL}{$sCl}{$sParam}" );
93 $oDomFile =
new DomDocument();
94 $oDomFile->preserveWhiteSpace =
false;
95 if ( !@$oDomFile->load( $sMenuFile ) ) {
97 } elseif ( is_readable( $sMenuFile ) && ( $sXml = @file_get_contents( $sMenuFile ) ) ) {
100 if (
getStr()->preg_match(
"/encoding\=(.*)\?>/", $sXml, $aMatches ) !== 0 ) {
101 if ( isset( $aMatches[1] ) ) {
102 $sCurrEncoding = trim( $aMatches[1],
"\"" );
103 if ( !in_array( strtolower( $sCurrEncoding ), $this->_aSupportedExpathXmlEncodings ) ) {
104 $sXml = str_replace( $aMatches[1],
"\"UTF-8\"", $sXml );
105 $sXml = iconv( $sCurrEncoding,
"UTF-8", $sXml );
111 if ( @$oDomFile->loadXml( $sXml ) ) {
117 $this->
_merge( $oDomFile, $oDom );
133 $sURL =
'index.php?';
135 $oXPath =
new DomXPath( $oDom );
136 $oNodeList = $oXPath->query(
"//OXMENU[@type='dyn']/MAINMENU/SUBMENU" );
138 foreach ( $oNodeList as $oNode ) {
141 $sCl = $oNode->getAttribute(
'cl' );
142 $sCl =
"cl=dynscreen&menu=$sCl";
145 $sParam = $oNode->getAttribute(
'clparam' );
146 $sParam = $sParam?
"&$sParam":
'';
149 if ( !$oNode->getAttribute(
'list' ) ) {
150 $oNode->setAttribute(
'list',
'dynscreen_list' );
151 $oNode->setAttribute(
'listparam',
'menu='.$oNode->getAttribute(
'cl' ) );
155 $oNode->setAttribute(
'link',
"{$sURL}{$sCl}{$sParam}" );
158 $oNode->parentNode->setAttribute(
'id',
'dyn_menu' );
163 $sFile = $oNode->getAttribute(
'cl' );
167 if ( $myUtilsFile->checkFile(
"{$this->_sDynIncludeUrl}pages/{$sFile}_about.php" ) ) {
168 $oTabElem =
new DOMElement(
'TAB' );
169 $oNode->appendChild( $oTabElem );
170 $oTabElem->setAttribute(
'external',
'true' );
171 $oTabElem->setAttribute(
'location',
"{$this->_sDynIncludeUrl}pages/{$sFile}_about.php" );
172 $oTabElem->setAttribute(
'id',
'dyn_about' );
176 if ( $myUtilsFile->checkFile(
"{$this->_sDynIncludeUrl}pages/{$sFile}_technics.php" ) ) {
177 $oTabElem =
new DOMElement(
'TAB' );
178 $oNode->appendChild( $oTabElem );
179 $oTabElem->setAttribute(
'external',
'true' );
180 $oTabElem->setAttribute(
'location',
"{$this->_sDynIncludeUrl}pages/{$sFile}_technics.php" );
181 $oTabElem->setAttribute(
'id',
'dyn_interface' );
185 if ( file_exists(
$myConfig->getConfigParam(
'sShopDir' ).
"/application/controllers/admin/{$sFile}.php" ) ) {
186 $oTabElem =
new DOMElement(
'TAB' );
187 $oNode->appendChild( $oTabElem );
188 $oTabElem->setAttribute(
'id',
'dyn_interface' );
189 $oTabElem->setAttribute(
'cl', $sFile );
204 $oXPath =
new DomXPath( $oDom );
206 foreach (array(
'url',
'link') as $sAttrType) {
207 foreach ( $oXPath->query(
"//OXMENU//*[@$sAttrType]" ) as $oNode ) {
208 $sLocalUrl = $oNode->getAttribute( $sAttrType );
209 if (strpos($sLocalUrl,
'index.php?') === 0) {
210 $sLocalUrl = $oStr->preg_replace(
'#^index.php\?#', $sURL, $sLocalUrl);
211 $oNode->setAttribute( $sAttrType, $sLocalUrl );
226 $oXPath =
new DomXPath( $oDom );
227 $oNodeList = $oXPath->query(
'//*[@rights or @norights]' );
229 foreach ( $oNodeList as $oNode ) {
231 if ( ( $sReq = $oNode->getAttribute(
'rights' ) ) ) {
232 $aPerm = explode(
',', $sReq );
233 foreach ( $aPerm as $sPerm ) {
234 if ( $sPerm && !$this->
_hasRights( $sPerm ) ) {
235 $oNode->parentNode->removeChild( $oNode );
239 } elseif ( ( $sNoReq = $oNode->getAttribute(
'norights' ) ) ) {
240 $aPerm = explode(
',', $sNoReq );
241 foreach ( $aPerm as $sPerm ) {
242 if ( $sPerm && $this->
_hasRights( $sPerm ) ) {
243 $oNode->parentNode->removeChild( $oNode );
259 $oXPath =
new DomXPath( $oDom );
260 $oNodeList = $oXPath->query(
"//*[@nogroup or @group]" );
262 foreach ( $oNodeList as $oNode ) {
264 if ( ( $sReq = $oNode->getAttribute(
'group') ) ) {
265 $aPerm = explode(
',', $sReq );
266 foreach ( $aPerm as $sPerm ) {
267 if ( $sPerm && !$this->
_hasGroup( $sPerm ) ) {
268 $oNode->parentNode->removeChild($oNode);
272 } elseif ( ( $sNoReq = $oNode->getAttribute(
'nogroup') ) ) {
273 $aPerm = explode(
',', $sNoReq );
274 foreach ( $aPerm as $sPerm ) {
275 if ( $sPerm && $this->
_hasGroup( $sPerm ) ) {
276 $oNode->parentNode->removeChild($oNode);
297 $oXPath =
new DomXPath( $oDom );
298 $oNodeList = $oXPath->query(
"//*[@disableForDemoShop]" );
299 foreach ( $oNodeList as $oNode ) {
300 if ( $oNode->getAttribute(
'disableForDemoShop') ) {
301 $oNode->parentNode->removeChild($oNode);
316 foreach ( $oDomElemFrom->attributes as $oAttr ) {
317 $oDomElemTo->setAttribute( $oAttr->nodeName, $oAttr->nodeValue );
332 protected function _mergeNodes( $oDomElemTo, $oDomElemFrom, $oXPathTo, $oDomDocTo, $sQueryStart )
334 foreach ( $oDomElemFrom->childNodes as $oFromNode ) {
335 if ( $oFromNode->nodeType === XML_ELEMENT_NODE ) {
337 $sFromAttrName = $oFromNode->getAttribute(
'id' );
338 $sFromNodeName = $oFromNode->tagName;
341 $sQuery =
"{$sQueryStart}/{$sFromNodeName}[@id='{$sFromAttrName}']";
342 $oCurNode = $oXPathTo->query( $sQuery );
345 if ( $oCurNode->length == 0 ) {
346 $oDomElemTo->appendChild( $oDomDocTo->importNode( $oFromNode,
true ) );
349 $oCurNode = $oCurNode->item( 0 );
354 if ( $oFromNode->childNodes->length ) {
355 $this->
_mergeNodes( $oCurNode, $oFromNode, $oXPathTo, $oDomDocTo, $sQuery );
370 protected function _merge( $oDomNew, $oDom )
372 $oXPath =
new DOMXPath( $oDom );
373 $this->
_mergeNodes( $oDom->documentElement, $oDomNew->documentElement, $oXPath, $oDom,
'/OX' );
385 public function getTabs( $sId, $iAct, $blSetActive =
true )
387 $oXPath =
new DOMXPath( $this->
getDomXml() );
389 $oNodeList = $oXPath->query(
"//SUBMENU[@cl='$sId']/TAB | //SUBMENU[@list='$sId']/TAB | //SUBMENU/../TAB[@cl='$sId']" );
391 $iAct = ( $iAct > $oNodeList->length )?( $oNodeList->length - 1 ):$iAct;
393 if ( $blSetActive ) {
394 foreach ( $oNodeList as $iPos => $oNode ) {
395 if ( $iPos == $iAct ) {
397 $oNode->setAttribute(
'active', 1 );
416 $oNodeList = $this->
getTabs( $sId, $iAct,
false );
417 $iAct = ( $iAct > $oNodeList->length )?( $oNodeList->length - 1 ):$iAct;
418 if ( $oNodeList->length && ( $oNode = $oNodeList->item( $iAct ) ) ) {
419 $sTab = $oNode->getAttribute(
'cl' );
435 $oXPath =
new DOMXPath($this->
getDomXml());
436 $oNodeList = $oXPath->query(
"//TAB[@cl='$sClass']/../BTN");
437 if ($oNodeList->length) {
438 $oButtons =
new stdClass();
439 foreach ($oNodeList as $oNode) {
440 $sBtnID = $oNode->getAttribute(
'id');
441 $oButtons->$sBtnID = 1;
457 $sFullAdminDir = getShopBasePath() .
'application/views/admin';
458 $sMenuFile =
"/menu.xml";
460 $sTmpDir =
$myConfig->getConfigParam(
'sCompileDir' );
462 $sLocalDynPath =
"{$sTmpDir}{$sDynLang}_dynscreen.xml";
466 if ( file_exists( $sFullAdminDir.$sMenuFile ) ) {
467 $aFilesToLoad[] = $sFullAdminDir.$sMenuFile;
471 if ( file_exists(
"$sFullAdminDir/user.xml" ) ) {
472 $aFilesToLoad[] =
"$sFullAdminDir/user.xml";
476 $sPath = getShopBasePath();
477 $oModulelist =
oxNew(
'oxmodulelist');
478 $aActiveModuleInfo = $oModulelist->getActiveModuleInfo();
479 if (is_array($aActiveModuleInfo)) {
480 foreach ( $aActiveModuleInfo as $sModulePath ) {
481 $sFullPath = $sPath.
"modules/" . $sModulePath;
483 if ( is_dir( $sFullPath ) ) {
485 $sMenuFile = $sFullPath .
"/menu.xml";
486 if ( file_exists( $sMenuFile ) && is_readable( $sMenuFile ) ) {
487 $aFilesToLoad[] = $sMenuFile;
493 $blLoadDynContents =
$myConfig->getConfigParam(
'blLoadDynContents' );
494 $sShopCountry =
$myConfig->getConfigParam(
'sShopCountry' );
499 if ( $blLoadDynContents ) {
500 if ( $sShopCountry ) {
501 $sRemoteDynUrl = $this->
_getDynMenuUrl( $sDynLang, $blLoadDynContents );
507 if ( ( !isset( $blLoadRemote ) || $blLoadRemote ) && ( $sDynPath = $myOxUtlis->getRemoteCachePath( $sRemoteDynUrl, $sLocalDynPath ) ) ) {
515 if ( $sShopCountry ) {
522 $aFilesToLoad[] = $sDynPath;
524 return $aFilesToLoad;
537 if ( file_exists( $sDynFilePath ) ) {
539 if ( ( $rHandle = @fopen($sDynFilePath,
'r' ) ) ) {
540 $sLine = stream_get_line( $rHandle, 100,
"?>");
544 if ( $sLine && stripos( $sLine,
'<?xml' ) !==
false ) {
545 $sDynFile = $sDynFilePath;
551 @unlink( $sDynFilePath );
571 return $sCacheContents;
581 if ( $this->_oInitialDom === null ) {
590 $sShopId = $this->
getConfig()->getActiveShop()->getShopId();
591 $sCacheName =
'menu_' . $sDynLang . $sShopId .
'_xml';
592 $sCacheFile = $myOxUtlis->getCacheFilePath( $sCacheName );
593 $sCacheContents = $myOxUtlis->fromFileCache( $sCacheName );
594 if ( $sCacheContents && file_exists( $sCacheFile ) && ( $iCacheModTime = filemtime( $sCacheFile ) ) ) {
595 foreach ( $aFilesToLoad as $sDynPath ) {
596 if ( $iCacheModTime < filemtime( $sDynPath ) ) {
604 $this->_oInitialDom =
new DOMDocument();
607 $this->_oInitialDom->appendChild(
new DOMElement(
'OX' ) );
609 foreach ( $aFilesToLoad as $sDynPath ) {
620 $myOxUtlis->toFileCache( $sCacheName, $this->_oInitialDom->saveXML() );
624 $this->_oInitialDom->preserveWhiteSpace =
false;
625 $this->_oInitialDom->loadXML( $sCacheContents );
642 if ( $this->_oDom === null ) {
671 $oXPath =
new DOMXPath( $this->
getDomXml() );
672 $oNodeList = $oXPath->query(
"//SUBMENU[@cl='".implode(
"' or @cl='", $aNodes).
"']" );
674 return ( $oNodeList->length ) ? $oNodeList : null;
686 $oXPath =
new DOMXPath( $this->
getDomXml() );
687 $oNodeList = $oXPath->query(
"//*[@cl='{$sNodeId}' or @list='{$sNodeId}']" );
689 if ( $oNodeList->length ) {
690 foreach ( $oNodeList as $oNode ) {
692 $oNode->setAttribute(
'active', 1 );
693 $oNode->parentNode->setAttribute(
'active', 1 );
709 $oXPath =
new DOMXPath( $this->
getDomXml() );
710 $oNodeList = $oXPath->query(
"//SUBMENU[@cl='{$sId}']" );
711 if ( $oNodeList->length && ( $oNode = $oNodeList->item( 0 ) ) ) {
712 $sCl = $oNode->getAttribute(
'list');
713 $sCl = $sCl?
"cl=$sCl":
'';
715 $sParams = $oNode->getAttribute(
'listparam');
716 $sParams = $sParams?
"&$sParams":
'';
718 $sUrl =
"{$sCl}{$sParams}";
734 $oXPath =
new DOMXPath( $this->
getDomXml() );
735 $oNodeList = $oXPath->query(
"//SUBMENU[@cl='{$sId}']/TAB" );
737 $iActTab = ( $iActTab > $oNodeList->length )?( $oNodeList->length - 1 ) : $iActTab;
738 if ( $oNodeList->length && ( $oActTab = $oNodeList->item( $iActTab ) ) ) {
740 if ( $oActTab->getAttribute(
'external' ) ) {
741 $sUrl = $oActTab->getAttribute(
'location' );
743 $sCl = $oActTab->getAttribute(
'cl' );
744 $sCl = $sCl?
"cl={$sCl}":
'';
746 $sParams = $oActTab->getAttribute(
'clparam' );
747 $sParams = $sParams?
"&{$sParams}":
'';
749 $sUrl =
"{$sCl}{$sParams}";
764 if ( ( $sAdminSslUrl =
$myConfig->getConfigParam(
'sAdminSSLURL' ) ) ) {
765 $sURL = trim( $sAdminSslUrl,
'/' );
767 $sURL = trim(
$myConfig->getConfigParam(
'sShopURL' ),
'/' ).
'/admin';
769 return oxRegistry::get(
"oxUtilsUrl")->processUrl(
"{$sURL}/index.php",
false);
781 return $this->
getUser()->oxuser__oxrights->value == $sRights;
793 return $this->
getUser()->inGroup( $sGroupId );
808 $oNodeList = $oXPath->query(
"//*[@cl='{$sClassName}' or @list='{$sClassName}']" );
809 if ( $oNodeList->length && ( $oFirstItem = $oNodeList->item( 0 ) ) ) {
810 $sClassId = $oFirstItem->getAttribute(
'id' );
827 if ( !$blLoadDynContents ) {
829 $sFullAdminDir = getShopBasePath() .
'application/views/admin';
830 $sUrl = $sFullAdminDir .
"/dynscreen_local.xml";
832 $oAdminView =
oxNew(
'oxadminview' );
833 $this->_sDynIncludeUrl = $oAdminView->getServiceUrl( $iLang );
834 $sUrl .= $this->_sDynIncludeUrl .
"menue/dynscreen.xml";
850 $iDynLang =
$myConfig->getConfigParam(
'iDynInterfaceLanguage' );
851 $iDynLang = isset( $iDynLang )?$iDynLang:( $oLang->getTplLanguage() );