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 init()
00044 {
00045 parent::init();
00046 }
00047
00053 public function getViewId()
00054 {
00055 if ( !isset( $this->_sViewId ) ) {
00056 $this->_sViewId = parent::getViewId().'|'.oxConfig::getParameter( 'oxcid' );
00057 }
00058 return $this->_sViewId;
00059 }
00060
00071 public function render()
00072 {
00073 parent::render();
00074
00075 if ( $sTplName = $this->_getTplName() ) {
00076 $this->_sThisTemplate = $sTpl = $sTplName;
00077 } else {
00078 $this->_aViewData['oxcid'] = $sTpl = $this->getContentId();
00079 $this->_aViewData['oContent'] = $this->getContent();
00080 }
00081
00082
00083 if ( $this->showPlainTemplate() ) {
00084 $this->_sThisTemplate = $this->_sThisPlainTemplate;
00085 }
00086
00087 $this->_aViewData['tpl'] = $sTpl;
00088 $this->getViewConfig()->setViewConfigParam( 'tpl', $sTpl );
00089 return $this->_sThisTemplate;
00090 }
00091
00102 protected function _prepareMetaDescription( $sMeta, $iLength = 200, $blDescTag = false )
00103 {
00104 if ( !$sMeta ) {
00105 $sMeta = $this->getContent()->oxcontents__oxtitle->value;
00106 }
00107 return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
00108 }
00109
00119 protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
00120 {
00121 if ( !$sKeywords ) {
00122 $sKeywords = $this->getContent()->oxcontents__oxtitle->value;
00123 }
00124 return parent::_prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords );
00125 }
00126
00132 public function getContentCategory()
00133 {
00134 if ( $this->_oContentCat === null ) {
00135
00136 $this->_oContentCat = false;
00137 if ( ( $oContent = $this->getContent() ) && $oContent->oxcontents__oxtype->value == 2 ) {
00138 $this->_oContentCat = $oContent;
00139 }
00140 }
00141 return $this->_oContentCat;
00142 }
00143
00149 public function showPlainTemplate()
00150 {
00151 return (bool) oxConfig::getParameter( 'plain' );
00152 }
00153
00159 protected function _getSeoObjectId()
00160 {
00161 return oxConfig::getParameter( 'oxcid' );
00162 }
00163
00170 public function getContentId()
00171 {
00172 if ( $this->_sContentId === null ) {
00173 $sContentId = oxConfig::getParameter( 'oxcid' );
00174
00175 if ( !$sContentId ) {
00176
00177
00178 $sContentId = oxConfig::getParameter( 'tpl' );
00179 }
00180
00181 if ( !$sContentId ) {
00182
00183 $sContentId = parent::getContentId();
00184 }
00185
00186 $this->_sContentId = false;
00187 $oContent = oxNew( 'oxcontent' );
00188 if ( $oContent->load( $sContentId ) && $oContent->oxcontents__oxactive->value ) {
00189 $this->_sContentId = $sContentId;
00190 $this->_oContent = $oContent;
00191 }
00192 }
00193 return $this->_sContentId;
00194 }
00195
00201 public function getContent()
00202 {
00203 if ( $this->_oContent === null ) {
00204 $this->_oContent = false;
00205 if ( $this->getContentId() ) {
00206 return $this->_oContent;
00207 }
00208 }
00209 return $this->_oContent;
00210 }
00211
00220 protected function _getSubject( $iLang )
00221 {
00222 return $this->getContent();
00223 }
00224
00230 protected function _getTplName()
00231 {
00232
00233 $sTplName = oxConfig::getParameter( 'tpl');
00234
00235 if ( $sTplName ) {
00236
00237 $sTplName = basename( $sTplName );
00238
00239
00240 if ( !preg_match("/\.tpl$/", $sTplName) ) {
00241 $sTplName = null;
00242 }
00243 }
00244
00245 return $sTplName;
00246 }
00247 }