Template override for "admin" templates

As I had guessed, “Template override” for the “admin” templates is very simple to implement.

In “[B]oxconfig.php[/B]” replace

        // Check for custom template
        $sCustomTheme = $this->getConfigParam( 'sCustomTheme' );
        if( !$blAdmin && $sCustomTheme && $sCustomTheme != $sTheme) {
            $sReturn = $this->getDir($sFile, $sDir, $blAdmin, $iLang, $iShopl, $sCustomTheme, $blAbsolute, $blReturnArray);
        }

with

        // Check for custom template
        //Avenger
        $sCustomTheme='sCustomTheme';
        if ( $blAdmin ) {
            $sCustomTheme .= 'Admin';
        }
        $sCustomTheme = $this->getConfigParam( $sCustomTheme );
        if( $sCustomTheme && $sCustomTheme != $sTheme) {
            $sReturn = $this->getDir($sFile, $sDir, false, $iLang, $iShopl, $sCustomTheme, $blAbsolute, $blReturnArray);
        }
        //Avenger

[B]And add[/B]

$this->sCustomThemeAdmin = 'admin_powertemplate';

to “[B]config.inc.php[/B]”

Unfortunately this has to go into the core routine itself, because “[B]oxconfig.php[/B]” can not be overloaded…

Something to put into “[B]oxconfig.php[/B]” in the next release…

[QUOTE=avenger;27665]As I had guessed, “Template override” for the “admin” templates is very simple to implement.

In “[B]oxconfig.php[/B]” replace

        // Check for custom template
        $sCustomTheme = $this->getConfigParam( 'sCustomTheme' );
        if( !$blAdmin && $sCustomTheme && $sCustomTheme != $sTheme) {
            $sReturn = $this->getDir($sFile, $sDir, $blAdmin, $iLang, $iShopl, $sCustomTheme, $blAbsolute, $blReturnArray);
        }

with

        // Check for custom template
        //Avenger
        $sCustomTheme='sCustomTheme';
        if ( $blAdmin ) {
            $sCustomTheme .= 'Admin';
        }
        $sCustomTheme = $this->getConfigParam( $sCustomTheme );
        if( $sCustomTheme && $sCustomTheme != $sTheme) {
            $sReturn = $this->getDir($sFile, $sDir, false, $iLang, $iShopl, $sCustomTheme, $blAbsolute, $blReturnArray);
        }
        //Avenger

[B]And add[/B]

$this->sCustomThemeAdmin = 'admin_powertemplate';

to “[B]config.inc.php[/B]”

Unfortunately this has to go into the core routine itself, because “[B]oxconfig.php[/B]” can not be overloaded…

Something to put into “[B]oxconfig.php[/B]” in the next release…[/QUOTE]
A small enhancement to the [B]replacement [/B]code, to save some superfluous action…

        // Check for custom template
        //Avenger
        $sCustomTheme='sCustomTheme';
        if ( $blAdmin ) {
            $sCustomTheme .= 'Admin';
        }
        $sCustomTheme = $this->getConfigParam( $sCustomTheme );
        if( $sCustomTheme && $sCustomTheme != $sTheme) {
            $sReturn = $this->getDir($sFile, $sDir, false, $iLang, $iShopl, $sCustomTheme, $blAbsolute, $blReturnArray);
        }
        if ( !$blAdmin ) {
            $blAdmin = strpos($sTheme,'admin')!==false;
        }
        //Avenger

I have reworked the complete “[B]public function getDir[/B]”, which has been not only changed for the [B]admin template override[/B], but also optimized, and restructered to a decent coding…

The original version does a whole lot of totally unecessary directory accesses, because the OXID 4 directory structures were tested only in the 3rd or 4th test, instead of being the 1st test…

Also, some heavily used data values and objects are now held “static”, so that they need to be computed only once, instead of in every call.

    public function getDir($sFile, $sDir, $blAdmin, $iLang = null, $iShop = null, $sTheme = null, $blAbsolute = true )
    {
        //Avenger
        static $sCustomTheme,$sBase,$sAbsBase,$oLang,$sLang,$sEditLang,$iShopId;
                    
        if (is_null($sBase))
        {
          // Check for custom template
          $sCustomTheme='sCustomTheme';
          if ( $blAdmin ) 
          {
            $sCustomTheme .= 'Admin';
          }
          $sCustomTheme = $this->getConfigParam( $sCustomTheme );
          $sAbsBase = $this->getOutDir();
          $oLang = oxLang::getInstance();
          $sLang = $oLang->getLanguageAbbr( $iLang );
          $sEditLang = $oLang->getEditLanguage();
          $iShopId = $this->getShopId();
        }
        $sBase    = $this->getOutDir( $blAbsolute );
        if (is_null($sTheme))
        {
          if ( $blAdmin ) 
          {
            $sTheme = 'admin';
          }
          else
          {
            $sTheme = $this->getConfigParam( 'sTheme' );
          }
        }
        if ( is_null($iLang) ) 
        {
          $iLang = $sEditLang;
        }
        if ( is_null($iShop) ) 
        {
          $iShop = $iShopId;
        }
        //Load from
        $sPath = "$sTheme/$sDir/$sFile";
        $sCacheKey = $sPath . "_$blAbsolute";
        if ( ( $sReturn = oxutils::getInstance()->fromStaticCache( $sCacheKey ) ) !== null ) 
        {
          return $sReturn;
        }
        $sReturn = false;
        if ( $sCustomTheme && $sCustomTheme != $sTheme) {
          $sReturn = $this->getDir($sFile, $sDir, $blAdmin, $iLang, $iShopl, $sCustomTheme, $blAbsolute, $blReturnArray);
        }
        if (!$sReturn) 
        {
          $aPaths=array(
            $sPath,
            "$sTheme/$iShop/$sLang/$sDir/$sFile",
            "$sTheme/$sLang/$sDir/$sFile"
          );
          if (!$blAdmin ) 
          {
            $aPaths=array_merge($aPaths,array(
            "$sTheme/$iShop/$sDir/$sFile",
            "$sLang/$sDir/$sFile",
            "$sDir/$sFile"));
          }
          foreach ($aPaths as $sPath) 
          {
            $sAbsPath=$sAbsBase.$sPath;
            if (is_readable( $sAbsPath ) || is_dir( realpath( $sAbsPath ) ) ) 
            {
              $sReturn = $sBase . $sPath;
              break;
            }
          }
        }
        //Avenger
        // to cache
        oxutils::getInstance()->toStaticCache( $sCacheKey, $sReturn );

        return $sReturn;
    }

In order to use it (with [B]version 4.2.0[/B]!), replace the complete “[B]public function getDir[/B]” in “[B]core/oxconfig.php[/B]” with the above code…

[B]Use at your own risk!!![/B]