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 
00048     protected $_sContentTitle = null;
00049 
00055     public function getViewId()
00056     {
00057         if ( !isset( $this->_sViewId ) ) {
00058             $this->_sViewId = parent::getViewId().'|'.oxConfig::getParameter( 'oxcid' );
00059         }
00060         return $this->_sViewId;
00061     }
00062 
00070     public function render()
00071     {
00072         parent::render();
00073 
00074         $oContent = $this->getContent();
00075         if ( $oContent && !$this->_canShowContent( $oContent->oxcontents__oxloadid->value ) ) {
00076             oxUtils::getInstance()->redirect( $this->getConfig()->getShopHomeURL() . 'cl=account' );
00077         }
00078 
00079         $sTpl = false;
00080         if ( $sTplName = $this->_getTplName() ) {
00081             $this->_sThisTemplate = $sTpl = $sTplName;
00082         } elseif ( $oContent ) {
00083             $sTpl = $oContent->getId();
00084         }
00085 
00086         if ( !$sTpl ) {
00087             error_404_handler();
00088         }
00089 
00090         // sometimes you need to display plain templates (e.g. when showing popups)
00091         if ( $this->showPlainTemplate() ) {
00092             $this->_sThisTemplate = $this->_sThisPlainTemplate;
00093         }
00094 
00095         $this->getViewConfig()->setViewConfigParam( 'tpl', $sTpl );
00096         return $this->_sThisTemplate;
00097     }
00098 
00106     protected function _canShowContent( $sContentIdent )
00107     {
00108         $blCan = true;
00109         if ( $this->isEnabledPrivateSales() &&
00110              !$this->getUser() && !in_array( $sContentIdent, $this->_aPsAllowedContents ) ) {
00111             $blCan = false;
00112         }
00113         return $blCan;
00114     }
00115 
00126     protected function _prepareMetaDescription( $sMeta, $iLength = 200, $blDescTag = false )
00127     {
00128         if ( !$sMeta ) {
00129             $sMeta = $this->getContent()->oxcontents__oxtitle->value;
00130         }
00131         return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00132     }
00133 
00143     protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00144     {
00145         if ( !$sKeywords ) {
00146             $sKeywords = $this->getContent()->oxcontents__oxtitle->value;
00147         }
00148         return parent::_prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords );
00149     }
00150 
00156     public function getContentCategory()
00157     {
00158         if ( $this->_oContentCat === null ) {
00159             // setting default status ..
00160             $this->_oContentCat = false;
00161             if ( ( $oContent = $this->getContent() ) && $oContent->oxcontents__oxtype->value == 2 ) {
00162                 $this->_oContentCat = $oContent;
00163             }
00164         }
00165         return $this->_oContentCat;
00166     }
00167 
00174     public function showPlainTemplate()
00175     {
00176         $blPlain = (bool) oxConfig::getParameter( 'plain' );
00177         if ( $blPlain === false ) {
00178             $oUser = $this->getUser();
00179             if ( $this->isEnabledPrivateSales() &&
00180                  ( !$oUser || ( $oUser && !$oUser->isTermsAccepted() ) ) ) {
00181                 $blPlain = true;
00182             }
00183         }
00184 
00185         return (bool) $blPlain;
00186     }
00187 
00193     protected function _getSeoObjectId()
00194     {
00195         return oxConfig::getParameter( 'oxcid' );
00196     }
00197 
00204     public function getContentId()
00205     {
00206         if ( $this->_sContentId === null ) {
00207             $oConfig    = $this->getConfig();
00208             $sContentId = oxConfig::getParameter( 'oxcid' );
00209 
00210             if ( !$sContentId ) {
00211                 //trying to load content id from tpl variable
00212                 //usage of tpl variable as content id is deprecated
00213                 $sContentId = oxConfig::getParameter( 'tpl' );
00214             }
00215 
00216             if ( !$sContentId ) {
00217                 //get default content id (impressum)
00218                 $sContentId = parent::getContentId();
00219             }
00220 
00221             $this->_sContentId = false;
00222             $oContent = oxNew( 'oxcontent' );
00223             if ( $oContent->load( $sContentId ) && $oContent->oxcontents__oxactive->value ) {
00224                 $this->_sContentId = $sContentId;
00225                 $this->_oContent = $oContent;
00226             }
00227         }
00228         return $this->_sContentId;
00229     }
00230 
00236     public function getContent()
00237     {
00238         if ( $this->_oContent === null ) {
00239             $this->_oContent = false;
00240             if ( $this->getContentId() ) {
00241                 return $this->_oContent;
00242             }
00243         }
00244         return $this->_oContent;
00245     }
00246 
00255     protected function _getSubject( $iLang )
00256     {
00257         return $this->getContent();
00258     }
00259 
00265     protected function _getTplName()
00266     {
00267         // assign template name
00268         $sTplName = oxConfig::getParameter( 'tpl');
00269 
00270         if ( $sTplName ) {
00271             // security fix so that you cant access files from outside template dir
00272             $sTplName = basename( $sTplName );
00273 
00274             //checking if it is template name, not content id
00275             if ( !getStr()->preg_match("/\.tpl$/", $sTplName) ) {
00276                 $sTplName = null;
00277             } else {
00278                 $sTplName = 'message/'.$sTplName;
00279             }
00280         }
00281 
00282         return $sTplName;
00283     }
00284 
00290     public function getBreadCrumb()
00291     {
00292         $oContent = $this->getContent();
00293 
00294         $aPaths = array();
00295         $aPath = array();
00296 
00297         $aPath['title'] = $oContent->oxcontents__oxtitle->value;
00298         $aPath['link']  = $this->getLink();
00299         $aPaths[] = $aPath;
00300 
00301         return $aPaths;
00302     }
00303 
00309     public function getTitle()
00310     {
00311         if ( $this->_sContentTitle === null ) {
00312             $oContent = $this->getContent();
00313             $this->_sContentTitle = $oContent->oxcontents__oxtitle->value;
00314         }
00315 
00316         return $this->_sContentTitle;
00317     }
00318 }