content.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class Content extends oxUBase
00007 {
00012     protected $_sContentId = null;
00013 
00018     protected $_oContent = null;
00019 
00024     protected $_sThisTemplate = 'page/info/content.tpl';
00025 
00030     protected $_sThisPlainTemplate = 'page/info/content_plain.tpl';
00031 
00036      protected $_oContentCat = null;
00037 
00042      protected $_aPsAllowedContents = array( "oxagb", "oxrightofwithdrawal", "oximpressum" );
00043 
00049     public function getViewId()
00050     {
00051         if ( !isset( $this->_sViewId ) ) {
00052             $this->_sViewId = parent::getViewId().'|'.oxConfig::getParameter( 'oxcid' );
00053         }
00054         return $this->_sViewId;
00055     }
00056 
00064     public function render()
00065     {
00066         parent::render();
00067 
00068         $oContent = $this->getContent();
00069         if ( $oContent && !$this->_canShowContent( $oContent->oxcontents__oxloadid->value ) ) {
00070             oxUtils::getInstance()->redirect( $this->getConfig()->getShopHomeURL() . 'cl=account' );
00071         }
00072 
00073         $sTpl = false;
00074         if ( $sTplName = $this->_getTplName() ) {
00075             $this->_sThisTemplate = $sTpl = $sTplName;
00076         } elseif ( $oContent ) {
00077             $sTpl = $oContent->getId();
00078         }
00079 
00080         if ( !$sTpl ) {
00081             error_404_handler();
00082         }
00083 
00084         // sometimes you need to display plain templates (e.g. when showing popups)
00085         if ( $this->showPlainTemplate() ) {
00086             $this->_sThisTemplate = $this->_sThisPlainTemplate;
00087         }
00088 
00089         $this->getViewConfig()->setViewConfigParam( 'tpl', $sTpl );
00090         return $this->_sThisTemplate;
00091     }
00092 
00100     protected function _canShowContent( $sContentIdent )
00101     {
00102         $blCan = true;
00103         if ( $this->isEnabledPrivateSales() &&
00104              !$this->getUser() && !in_array( $sContentIdent, $this->_aPsAllowedContents ) ) {
00105             $blCan = false;
00106         }
00107         return $blCan;
00108     }
00109 
00120     protected function _prepareMetaDescription( $sMeta, $iLength = 200, $blDescTag = false )
00121     {
00122         if ( !$sMeta ) {
00123             $sMeta = $this->getContent()->oxcontents__oxtitle->value;
00124         }
00125         return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00126     }
00127 
00137     protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00138     {
00139         if ( !$sKeywords ) {
00140             $sKeywords = $this->getContent()->oxcontents__oxtitle->value;
00141         }
00142         return parent::_prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords );
00143     }
00144 
00150     public function getContentCategory()
00151     {
00152         if ( $this->_oContentCat === null ) {
00153             // setting default status ..
00154             $this->_oContentCat = false;
00155             if ( ( $oContent = $this->getContent() ) && $oContent->oxcontents__oxtype->value == 2 ) {
00156                 $this->_oContentCat = $oContent;
00157             }
00158         }
00159         return $this->_oContentCat;
00160     }
00161 
00168     public function showPlainTemplate()
00169     {
00170         $blPlain = (bool) oxConfig::getParameter( 'plain' );
00171         if ( $blPlain === false ) {
00172             $oUser = $this->getUser();
00173             if ( $this->isEnabledPrivateSales() &&
00174                  ( !$oUser || ( $oUser && !$oUser->isTermsAccepted() ) ) ) {
00175                 $blPlain = true;
00176             }
00177         }
00178 
00179         return (bool) $blPlain;
00180     }
00181 
00187     protected function _getSeoObjectId()
00188     {
00189         return oxConfig::getParameter( 'oxcid' );
00190     }
00191 
00198     public function getContentId()
00199     {
00200         if ( $this->_sContentId === null ) {
00201             $oConfig    = $this->getConfig();
00202             $sContentId = oxConfig::getParameter( 'oxcid' );
00203 
00204             if ( !$sContentId ) {
00205                 //trying to load content id from tpl variable
00206                 //usage of tpl variable as content id is deprecated
00207                 $sContentId = oxConfig::getParameter( 'tpl' );
00208             }
00209 
00210             if ( !$sContentId ) {
00211                 //get default content id (impressum)
00212                 $sContentId = parent::getContentId();
00213             }
00214 
00215             $this->_sContentId = false;
00216             $oContent = oxNew( 'oxcontent' );
00217             if ( $oContent->load( $sContentId ) && $oContent->oxcontents__oxactive->value ) {
00218                 $this->_sContentId = $sContentId;
00219                 $this->_oContent = $oContent;
00220             }
00221         }
00222         return $this->_sContentId;
00223     }
00224 
00230     public function getContent()
00231     {
00232         if ( $this->_oContent === null ) {
00233             $this->_oContent = false;
00234             if ( $this->getContentId() ) {
00235                 return $this->_oContent;
00236             }
00237         }
00238         return $this->_oContent;
00239     }
00240 
00249     protected function _getSubject( $iLang )
00250     {
00251         return $this->getContent();
00252     }
00253 
00259     protected function _getTplName()
00260     {
00261         // assign template name
00262         $sTplName = oxConfig::getParameter( 'tpl');
00263 
00264         if ( $sTplName ) {
00265             // security fix so that you cant access files from outside template dir
00266             $sTplName = basename( $sTplName );
00267 
00268             //checking if it is template name, not content id
00269             if ( !getStr()->preg_match("/\.tpl$/", $sTplName) ) {
00270                 $sTplName = null;
00271             } else {
00272                 $sTplName = 'message/'.$sTplName;
00273             }
00274         }
00275 
00276         return $sTplName;
00277     }
00278 
00284     public function getBreadCrumb()
00285     {
00286         $oContent = $this->getContent();
00287 
00288         $aPaths = array();
00289         $aPath = array();
00290 
00291         $aPath['title'] = $oContent->oxcontents__oxtitle->value;
00292         $aPath['link']  = $this->getLink();
00293         $aPaths[] = $aPath;
00294 
00295         return $aPaths;
00296     }
00297 }