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 = 'content.tpl';
00025 
00030     protected $_sThisPlainTemplate = '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 
00067     public function render()
00068     {
00069         parent::render();
00070 
00071         $oContent = $this->getContent();
00072         if ( $oContent && !$this->_canShowContent( $oContent->oxcontents__oxloadid->value ) ) {
00073             oxUtils::getInstance()->redirect( $this->getConfig()->getShopHomeURL() . 'cl=account' );
00074         }
00075 
00076         $sTpl = false;
00077         if ( $sTplName = $this->_getTplName() ) {
00078             $this->_sThisTemplate = $sTpl = $sTplName;
00079         } elseif ( $oContent ) {
00080             $this->_aViewData['oxcid'] = $sTpl = $oContent->getId();
00081             $this->_aViewData['oContent'] = $oContent;
00082         }
00083 
00084         if ( !$sTpl ) {
00085             error_404_handler();
00086         }
00087 
00088         // sometimes you need to display plain templates (e.g. when showing popups)
00089         if ( $this->showPlainTemplate() ) {
00090             $this->_sThisTemplate = $this->_sThisPlainTemplate;
00091         }
00092 
00093         $this->_aViewData['tpl'] = $sTpl;
00094         $this->getViewConfig()->setViewConfigParam( 'tpl', $sTpl );
00095         return $this->_sThisTemplate;
00096     }
00097 
00105     protected function _canShowContent( $sContentIdent )
00106     {
00107         $blCan = true;
00108         if ( $this->isEnabledPrivateSales() &&
00109              !$this->getUser() && !in_array( $sContentIdent, $this->_aPsAllowedContents ) ) {
00110             $blCan = false;
00111         }
00112         return $blCan;
00113     }
00114 
00125     protected function _prepareMetaDescription( $sMeta, $iLength = 200, $blDescTag = false )
00126     {
00127         if ( !$sMeta ) {
00128             $sMeta = $this->getContent()->oxcontents__oxtitle->value;
00129         }
00130         return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00131     }
00132 
00142     protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00143     {
00144         if ( !$sKeywords ) {
00145             $sKeywords = $this->getContent()->oxcontents__oxtitle->value;
00146         }
00147         return parent::_prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords );
00148     }
00149 
00155     public function getContentCategory()
00156     {
00157         if ( $this->_oContentCat === null ) {
00158             // setting default status ..
00159             $this->_oContentCat = false;
00160             if ( ( $oContent = $this->getContent() ) && $oContent->oxcontents__oxtype->value == 2 ) {
00161                 $this->_oContentCat = $oContent;
00162             }
00163         }
00164         return $this->_oContentCat;
00165     }
00166 
00173     public function showPlainTemplate()
00174     {
00175         $blPlain = (bool) oxConfig::getParameter( 'plain' );
00176         if ( $blPlain === false ) {
00177             $oUser = $this->getUser();
00178             if ( $this->isEnabledPrivateSales() &&
00179                  ( !$oUser || ( $oUser && !$oUser->isTermsAccepted() ) ) ) {
00180                 $blPlain = true;
00181             }
00182         }
00183 
00184         return (bool) $blPlain;
00185     }
00186 
00192     protected function _getSeoObjectId()
00193     {
00194         return oxConfig::getParameter( 'oxcid' );
00195     }
00196 
00203     public function getContentId()
00204     {
00205         if ( $this->_sContentId === null ) {
00206             $oConfig    = $this->getConfig();
00207             $sContentId = oxConfig::getParameter( 'oxcid' );
00208 
00209             if ( !$sContentId ) {
00210                 //trying to load content id from tpl variable
00211                 //usage of tpl variable as content id is deprecated
00212                 $sContentId = oxConfig::getParameter( 'tpl' );
00213             }
00214 
00215             if ( !$sContentId ) {
00216                 //get default content id (impressum)
00217                 $sContentId = parent::getContentId();
00218             }
00219 
00220             $this->_sContentId = false;
00221             $oContent = oxNew( 'oxcontent' );
00222             if ( $oContent->load( $sContentId ) && $oContent->oxcontents__oxactive->value ) {
00223                 $this->_sContentId = $sContentId;
00224                 $this->_oContent = $oContent;
00225             }
00226         }
00227         return $this->_sContentId;
00228     }
00229 
00235     public function getContent()
00236     {
00237         if ( $this->_oContent === null ) {
00238             $this->_oContent = false;
00239             if ( $this->getContentId() ) {
00240                 return $this->_oContent;
00241             }
00242         }
00243         return $this->_oContent;
00244     }
00245 
00254     protected function _getSubject( $iLang )
00255     {
00256         return $this->getContent();
00257     }
00258 
00264     protected function _getTplName()
00265     {
00266         // assign template name
00267         $sTplName = oxConfig::getParameter( 'tpl');
00268 
00269         if ( $sTplName ) {
00270             // security fix so that you cant access files from outside template dir
00271             $sTplName = basename( $sTplName );
00272 
00273             //checking if it is template name, not content id
00274             if ( !getStr()->preg_match("/\.tpl$/", $sTplName) ) {
00275                 $sTplName = null;
00276             }
00277         }
00278 
00279         return $sTplName;
00280     }
00281 }