Go to the documentation of this file.00001 <?php
00002
00008 class oxContent extends oxI18n implements oxIUrl
00009 {
00015 protected $_sCoreTbl = 'oxcontents';
00016
00022 protected $_sClassName = 'oxcontent';
00023
00030 protected $_aSkipSaveFields = array( 'oxtimestamp' );
00031
00037 protected $_aSeoUrls = array();
00038
00044 protected $_sParentCatId = null;
00045
00051 protected $_blExpanded = null;
00052
00058 protected $_blIsSeoObject = true;
00059
00067 public function __get( $sName )
00068 {
00069 switch ( $sName ) {
00070 case 'expanded':
00071 return $this->getExpanded();
00072 break;
00073 }
00074 return parent::__get( $sName );
00075 }
00076
00080 public function __construct()
00081 {
00082 parent::__construct();
00083 $this->init( 'oxcontents' );
00084 }
00085
00091 public function getExpanded()
00092 {
00093 if ( !isset( $this->_blExpanded ) ) {
00094 $this->_blExpanded = ( $this->getId() == oxConfig::getParameter( 'oxcid' ) );
00095 }
00096 return $this->_blExpanded;
00097 }
00098
00106 public function loadByIdent( $sLoadId )
00107 {
00108 $sContentsTable = $this->getViewName();
00109
00110 $sSelect = $this->buildSelectString( array( $sContentsTable.'.oxloadid' => $sLoadId,
00111 $sContentsTable.'.oxactive' => '1',
00112 $sContentsTable.'.oxshopid' => $this->getConfig()->getShopId() ) );
00113
00114 return $this->assignRecord( $sSelect );
00115 }
00116
00124 public function assign( $dbRecord )
00125 {
00126
00127 parent::assign( $dbRecord );
00128
00129 $this->oxcontents__oxcontent->setValue(str_replace( '&lang=', '&lang=', $this->oxcontents__oxcontent->value ), oxField::T_RAW);
00130 }
00131
00139 public function getBaseSeoLink( $iLang )
00140 {
00141 return oxSeoEncoderContent::getInstance()->getContentUrl( $this, $iLang );
00142 }
00143
00151 public function getLink( $iLang = null )
00152 {
00153 if ( !oxUtils::getInstance()->seoIsActive() ) {
00154 return $this->getStdLink( $iLang );
00155 }
00156
00157 if ( $iLang === null ) {
00158 $iLang = $this->getLanguage();
00159 }
00160
00161 if ( !isset( $this->_aSeoUrls[$iLang] ) ) {
00162 $this->_aSeoUrls[$iLang] = $this->getBaseSeoLink( $iLang );
00163 }
00164
00165 return $this->_aSeoUrls[$iLang];
00166 }
00167
00177 public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
00178 {
00179 $sUrl = '';
00180 if ( $blFull ) {
00181
00182 $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
00183 }
00184
00185 $sUrl .= "index.php?cl=content";
00186 if ( $blAddId ) {
00187 $sUrl .= "&oxcid=".$this->getId();
00188
00189 if ( $this->_sParentCatId !== false &&
00190 $this->oxcontents__oxcatid->value && $this->oxcontents__oxcatid->value != 'oxrootid' ) {
00191
00192 if ( $this->_sParentCatId === null ) {
00193 $this->_sParentCatId = false;
00194 $oDb = oxDb::getDb();
00195 $sParentId = $oDb->getOne( "select oxparentid from oxcategories where oxid = ".$oDb->quote( $this->oxcontents__oxcatid->value ) );
00196 if ( $sParentId && 'oxrootid' != $sParentId ) {
00197 $this->_sParentCatId = $sParentId;
00198 }
00199 }
00200
00201 if ( $this->_sParentCatId ) {
00202 $sUrl .= "&cnid=".$this->_sParentCatId;
00203 }
00204 }
00205 }
00206
00207
00208 return $sUrl;
00209 }
00210
00219 public function getStdLink( $iLang = null, $aParams = array() )
00220 {
00221 if ( $iLang === null ) {
00222 $iLang = $this->getLanguage();
00223 }
00224
00225 return oxUtilsUrl::getInstance()->processUrl( $this->getBaseStdLink( $iLang ), true, $aParams, $iLang);
00226 }
00227
00237 protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00238 {
00239 if ('oxcontent' === strtolower($sFieldName) || 'oxcontents__oxcontent' === strtolower($sFieldName)) {
00240 $iDataType = oxField::T_RAW;
00241 }
00242
00243 return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00244 }
00245
00253 public function delete( $sOXID = null)
00254 {
00255 if ( !$sOXID ) {
00256 $sOXID = $this->getId();
00257 }
00258 if (parent::delete($sOXID)) {
00259 oxSeoEncoderContent::getInstance()->onDeleteContent($sOXID);
00260 return true;
00261 }
00262 return false;
00263 }
00264
00270 public function save()
00271 {
00272 $blSaved = parent::save();
00273 if ( $blSaved && $this->oxcontents__oxloadid->value === 'oxagb' ) {
00274 $sShopId = $this->getConfig()->getShopId();
00275 $sVersion = $this->oxcontents__oxtermversion->value;
00276
00277 $oDb = oxDb::getDb();
00278
00279 $oDb->execute( "delete from oxacceptedterms where oxshopid='{$sShopId}' and oxtermversion != ".$oDb->quote( $sVersion ) );
00280 }
00281 return $blSaved;
00282 }
00283
00289 public function getTermsVersion()
00290 {
00291 if ( $this->loadByIdent( 'oxagb' ) ) {
00292 return $this->oxcontents__oxtermversion->value;
00293 }
00294 }
00295 }