oxcontent.php

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         $this->oxcontents__oxcontent->setValue(str_replace( '&amp;', '&', $this->oxcontents__oxcontent->value ), oxField::T_RAW);
00129         // workaround for firefox showing &lang= as &9001;= entity, mantis#0001272
00130         $this->oxcontents__oxcontent->setValue(str_replace( '&lang=', '&amp;lang=', $this->oxcontents__oxcontent->value ), oxField::T_RAW);
00131     }
00132 
00140     public function getBaseSeoLink( $iLang )
00141     {
00142         return oxSeoEncoderContent::getInstance()->getContentUrl( $this, $iLang );
00143     }
00144 
00152     public function getLink( $iLang = null )
00153     {
00154         if ( !oxUtils::getInstance()->seoIsActive() ) {
00155             return $this->getStdLink( $iLang );
00156         }
00157 
00158         if ( $iLang === null ) {
00159             $iLang = $this->getLanguage();
00160         }
00161 
00162         if ( !isset( $this->_aSeoUrls[$iLang] ) ) {
00163             $this->_aSeoUrls[$iLang] = $this->getBaseSeoLink( $iLang );
00164         }
00165 
00166         return $this->_aSeoUrls[$iLang];
00167     }
00168 
00178     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
00179     {
00180         $sUrl = '';
00181         if ( $blFull ) {
00182             //always returns shop url, not admin
00183             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
00184         }
00185 
00186         $sUrl .= "index.php?cl=content";
00187         if ( $blAddId ) {
00188             $sUrl .= "&amp;oxcid=".$this->getId();
00189             // adding parent category if if available
00190             if ( $this->_sParentCatId !== false &&
00191                  $this->oxcontents__oxcatid->value && $this->oxcontents__oxcatid->value != 'oxrootid' ) {
00192 
00193                 if ( $this->_sParentCatId === null ) {
00194                     $this->_sParentCatId = false;
00195                     $oDb = oxDb::getDb();
00196                     $sParentId = $oDb->getOne( "select oxparentid from oxcategories where oxid = ".$oDb->quote( $this->oxcontents__oxcatid->value ) );
00197                     if ( $sParentId && 'oxrootid' != $sParentId ) {
00198                         $this->_sParentCatId = $sParentId;
00199                     }
00200                 }
00201 
00202                 if ( $this->_sParentCatId ) {
00203                     $sUrl .= "&amp;cnid=".$this->_sParentCatId;
00204                 }
00205             }
00206         }
00207 
00208         //always returns shop url, not admin
00209         return $sUrl;
00210     }
00211 
00220     public function getStdLink( $iLang = null, $aParams = array() )
00221     {
00222         if ( $iLang === null ) {
00223             $iLang = $this->getLanguage();
00224         }
00225 
00226         return oxUtilsUrl::getInstance()->processUrl( $this->getBaseStdLink( $iLang ), true, $aParams, $iLang);
00227     }
00228 
00238     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00239     {
00240         if ('oxcontent' === strtolower($sFieldName) || 'oxcontents__oxcontent' === strtolower($sFieldName)) {
00241             $iDataType = oxField::T_RAW;
00242         }
00243 
00244         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00245     }
00246 
00254     public function delete( $sOXID = null)
00255     {
00256         if ( !$sOXID ) {
00257             $sOXID = $this->getId();
00258         }
00259         if (parent::delete($sOXID)) {
00260             oxSeoEncoderContent::getInstance()->onDeleteContent($sOXID);
00261             return true;
00262         }
00263         return false;
00264     }
00265 
00271     public function save()
00272     {
00273         $blSaved = parent::save();
00274         if ( $blSaved && $this->oxcontents__oxloadid->value === 'oxagb' ) {
00275             $sShopId  = $this->getConfig()->getShopId();
00276             $sVersion = $this->oxcontents__oxtermversion->value;
00277 
00278             $oDb = oxDb::getDb();
00279             // dropping expired..
00280             $oDb->execute( "delete from oxacceptedterms where oxshopid='{$sShopId}' and oxtermversion != ".$oDb->quote( $sVersion ) );
00281         }
00282         return $blSaved;
00283     }
00284 
00290     public function getTermsVersion()
00291     {
00292         if ( $this->loadByIdent( 'oxagb' ) ) {
00293             return $this->oxcontents__oxtermversion->value;
00294         }
00295     }
00296 }