Go to the documentation of this file.00001 <?php
00002
00008 class oxContent extends oxI18n implements oxIUrl
00009 {
00015 protected $_sClassName = 'oxcontent';
00016
00022 protected $_aSeoUrls = array();
00023
00029 protected $_sParentCatId = null;
00030
00036 protected $_blExpanded = null;
00037
00043 protected $_blIsSeoObject = true;
00044
00052 public function __get( $sName )
00053 {
00054 switch ( $sName ) {
00055 case 'expanded':
00056 return $this->getExpanded();
00057 break;
00058 }
00059 return parent::__get( $sName );
00060 }
00061
00065 public function __construct()
00066 {
00067 parent::__construct();
00068 $this->init( 'oxcontents' );
00069 }
00070
00076 public function getExpanded()
00077 {
00078 if ( !isset( $this->_blExpanded ) ) {
00079 $this->_blExpanded = ( $this->getId() == oxConfig::getParameter( 'oxcid' ) );
00080 }
00081 return $this->_blExpanded;
00082 }
00083
00084
00092 protected function _loadFromDb( $sLoadId )
00093 {
00094 $sTable = $this->getViewName();
00095 $sShopId = $this->getShopId();
00096 $aParams = array(
00097 $sTable.'.oxloadid' => $sLoadId,
00098 $sTable.'.oxshopid' => $sShopId );
00099
00100 $sSelect = $this->buildSelectString( $aParams );
00101
00102
00103 if ( $sLoadId == 'oxcredits' ) {
00104
00105
00106 $sColQ = "SHOW COLUMNS FROM oxcontents WHERE field LIKE 'oxcontent%'";
00107 $aCols = oxDb::getDb()->getAll( $sColQ );
00108
00109
00110 $sPattern = "IF ( %s != '', %s, %s ) ";
00111 $iCount = count( $aCols ) - 1;
00112
00113 $sContQ = "SELECT {$sPattern}";
00114 foreach ( $aCols as $iKey => $aCol ) {
00115 $sContQ = sprintf( $sContQ, $aCol[0], $aCol[0], $iCount != $iKey ? $sPattern : "''" );
00116 }
00117 $sContQ .= " FROM oxcontents WHERE oxloadid = '{$sLoadId}' AND oxshopid = '{$sShopId}'";
00118
00119 $sSelect = $this->buildSelectString( $aParams );
00120 $sSelect = str_replace( "`{$sTable}`.`oxcontent`", "( $sContQ ) as oxcontent", $sSelect );
00121 }
00122
00123 $aData = oxDb::getDb( oxDb::FETCH_MODE_ASSOC )->getRow( $sSelect );
00124
00125 return $aData;
00126 }
00127
00135 public function loadByIdent( $sLoadId )
00136 {
00137
00138 $aData = $this->_loadFromDb( $sLoadId );
00139
00140 if ( $aData ) {
00141 $this->assign( $aData );
00142 return true;
00143 }
00144
00145 return false;
00146 }
00147
00148
00154 public function getLoadId()
00155 {
00156 return $this->oxcontents__oxloadid->value;
00157 }
00158
00164 public function isActive()
00165 {
00166 return $this->oxcontents__oxactive->value;
00167 }
00168
00176 public function assign( $dbRecord )
00177 {
00178
00179 parent::assign( $dbRecord );
00180
00181
00182 if ( $this->oxcontents__oxcontent ) {
00183 $this->oxcontents__oxcontent->setValue(str_replace( '&lang=', '&lang=', $this->oxcontents__oxcontent->value ), oxField::T_RAW);
00184 }
00185 }
00186
00194 public function getBaseSeoLink( $iLang )
00195 {
00196 return oxRegistry::get("oxSeoEncoderContent")->getContentUrl( $this, $iLang );
00197 }
00198
00206 public function getLink( $iLang = null )
00207 {
00208 if ( !oxRegistry::getUtils()->seoIsActive() ) {
00209 return $this->getStdLink( $iLang );
00210 }
00211
00212 if ( $iLang === null ) {
00213 $iLang = $this->getLanguage();
00214 }
00215
00216 if ( !isset( $this->_aSeoUrls[$iLang] ) ) {
00217 $this->_aSeoUrls[$iLang] = $this->getBaseSeoLink( $iLang );
00218 }
00219
00220 return $this->_aSeoUrls[$iLang];
00221 }
00222
00232 public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
00233 {
00234 $sUrl = '';
00235 if ( $blFull ) {
00236
00237 $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
00238 }
00239
00240 if ( $this->oxcontents__oxloadid->value === 'oxcredits' ) {
00241 $sUrl .= "index.php?cl=credits";
00242 } else {
00243 $sUrl .= "index.php?cl=content";
00244 }
00245 $sUrl .= '&oxloadid='.$this->getLoadId();
00246
00247 if ( $blAddId ) {
00248 $sUrl .= "&oxcid=".$this->getId();
00249
00250 if ( $this->_sParentCatId !== false &&
00251 $this->oxcontents__oxcatid->value && $this->oxcontents__oxcatid->value != 'oxrootid' ) {
00252
00253 if ( $this->_sParentCatId === null ) {
00254 $this->_sParentCatId = false;
00255 $oDb = oxDb::getDb();
00256 $sParentId = $oDb->getOne( "select oxparentid from oxcategories where oxid = ".$oDb->quote( $this->oxcontents__oxcatid->value ) );
00257 if ( $sParentId && 'oxrootid' != $sParentId ) {
00258 $this->_sParentCatId = $sParentId;
00259 }
00260 }
00261
00262 if ( $this->_sParentCatId ) {
00263 $sUrl .= "&cnid=".$this->_sParentCatId;
00264 }
00265 }
00266 }
00267
00268
00269 return $sUrl;
00270 }
00271
00280 public function getStdLink( $iLang = null, $aParams = array() )
00281 {
00282 if ( $iLang === null ) {
00283 $iLang = $this->getLanguage();
00284 }
00285
00286 return oxRegistry::get("oxUtilsUrl")->processUrl( $this->getBaseStdLink( $iLang ), true, $aParams, $iLang);
00287 }
00288
00298 protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00299 {
00300 if ('oxcontent' === strtolower($sFieldName) || 'oxcontents__oxcontent' === strtolower($sFieldName)) {
00301 $iDataType = oxField::T_RAW;
00302 }
00303
00304 return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00305 }
00306
00314 public function delete( $sOXID = null)
00315 {
00316 if ( !$sOXID ) {
00317 $sOXID = $this->getId();
00318 }
00319
00320 if (parent::delete($sOXID)) {
00321 oxRegistry::get("oxSeoEncoderContent")->onDeleteContent($sOXID);
00322 return true;
00323 }
00324 return false;
00325 }
00326
00332 public function save()
00333 {
00334 $blSaved = parent::save();
00335 if ( $blSaved && $this->oxcontents__oxloadid->value === 'oxagb' ) {
00336 $sShopId = $this->getConfig()->getShopId();
00337 $sVersion = $this->oxcontents__oxtermversion->value;
00338
00339 $oDb = oxDb::getDb();
00340
00341 $oDb->execute( "delete from oxacceptedterms where oxshopid='{$sShopId}' and oxtermversion != ".$oDb->quote( $sVersion ) );
00342 }
00343 return $blSaved;
00344 }
00345
00351 public function getTermsVersion()
00352 {
00353 if ( $this->loadByIdent( 'oxagb' ) ) {
00354 return $this->oxcontents__oxtermversion->value;
00355 }
00356 }
00357
00363 public function getType()
00364 {
00365 return $this->oxcontents__oxtype->value;
00366 }
00367
00368 }