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 
00043     public function getViewId()
00044     {
00045         if ( !isset( $this->_sViewId ) ) {
00046             $this->_sViewId = parent::getViewId().'|'.oxConfig::getParameter( 'oxcid' );
00047         }
00048         return $this->_sViewId;
00049     }
00050 
00061     public function render()
00062     {
00063         parent::render();
00064 
00065         if ( $sTplName = $this->_getTplName() ) {
00066             $this->_sThisTemplate = $sTpl = $sTplName;
00067         } else {
00068             $this->_aViewData['oxcid'] = $sTpl = $this->getContentId();
00069             if ( !$sTpl ) {
00070                 error_404_handler( );
00071             }
00072             $this->_aViewData['oContent'] = $this->getContent();
00073         }
00074 
00075         // sometimes you need to display plain templates (e.g. when showing popups)
00076         if ( $this->showPlainTemplate() ) {
00077             $this->_sThisTemplate = $this->_sThisPlainTemplate;
00078         }
00079 
00080         $this->_aViewData['tpl'] = $sTpl;
00081         $this->getViewConfig()->setViewConfigParam( 'tpl', $sTpl );
00082         return $this->_sThisTemplate;
00083     }
00084 
00095     protected function _prepareMetaDescription( $sMeta, $iLength = 200, $blDescTag = false )
00096     {
00097         if ( !$sMeta ) {
00098             $sMeta = $this->getContent()->oxcontents__oxtitle->value;
00099         }
00100         return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00101     }
00102 
00112     protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00113     {
00114         if ( !$sKeywords ) {
00115             $sKeywords = $this->getContent()->oxcontents__oxtitle->value;
00116         }
00117         return parent::_prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords );
00118     }
00119 
00125     public function getContentCategory()
00126     {
00127         if ( $this->_oContentCat === null ) {
00128             // setting default status ..
00129             $this->_oContentCat = false;
00130             if ( ( $oContent = $this->getContent() ) && $oContent->oxcontents__oxtype->value == 2 ) {
00131                 $this->_oContentCat = $oContent;
00132             }
00133         }
00134         return $this->_oContentCat;
00135     }
00136 
00142     public function showPlainTemplate()
00143     {
00144         return (bool) oxConfig::getParameter( 'plain' );
00145     }
00146 
00152     protected function _getSeoObjectId()
00153     {
00154         return oxConfig::getParameter( 'oxcid' );
00155     }
00156 
00163     public function getContentId()
00164     {
00165         if ( $this->_sContentId === null ) {
00166             $oConfig    = $this->getConfig();
00167             $sContentId = oxConfig::getParameter( 'oxcid' );
00168 
00169             if ( !$sContentId ) {
00170                 //trying to load content id from tpl variable
00171                 //usage of tpl variable as content id is deprecated
00172                 $sContentId = oxConfig::getParameter( 'tpl' );
00173             }
00174 
00175             if ( !$sContentId ) {
00176                 //get default content id (impressum)
00177                 $sContentId = parent::getContentId();
00178             }
00179 
00180             $this->_sContentId = false;
00181             $oContent = oxNew( 'oxcontent' );
00182             if ( $oContent->load( $sContentId ) && $oContent->oxcontents__oxactive->value ) {
00183                 if ( $oConfig->getConfigParam( 'blPsLoginEnabled' ) && !$this->getUser() &&
00184                      $oContent->oxcontents__oxloadid->value != "oxagb" &&
00185                      $oContent->oxcontents__oxloadid->value != "oxrightofwithdrawal" ) {
00186                     oxUtils::getInstance()->redirect( $oConfig->getShopHomeURL() . 'cl=account' );
00187                 }
00188                 $this->_sContentId = $sContentId;
00189                 $this->_oContent = $oContent;
00190             }
00191         }
00192         return $this->_sContentId;
00193     }
00194 
00200     public function getContent()
00201     {
00202         if ( $this->_oContent === null ) {
00203             $this->_oContent = false;
00204             if ( $this->getContentId() ) {
00205                 return $this->_oContent;
00206             }
00207         }
00208         return $this->_oContent;
00209     }
00210 
00219     protected function _getSubject( $iLang )
00220     {
00221         return $this->getContent();
00222     }
00223 
00229     protected function _getTplName()
00230     {
00231         // assign template name
00232         $sTplName = oxConfig::getParameter( 'tpl');
00233 
00234         if ( $sTplName ) {
00235             // security fix so that you cant access files from outside template dir
00236             $sTplName = basename( $sTplName );
00237 
00238             //checking if it is template name, not content id
00239             if ( !getStr()->preg_match("/\.tpl$/", $sTplName) ) {
00240                 $sTplName = null;
00241             }
00242         }
00243 
00244         return $sTplName;
00245     }
00246 }