oxcontent.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxContent extends oxI18n implements oxIUrl
00009 {
00015     protected $_sClassName = 'oxcontent';
00016 
00023     protected $_aSkipSaveFields = array( 'oxtimestamp' );
00024 
00030     protected $_aSeoUrls = array();
00031 
00037     protected $_sParentCatId = null;
00038 
00044     protected $_blExpanded = null;
00045 
00051     protected $_blIsSeoObject = true;
00052 
00060     public function __get( $sName )
00061     {
00062         switch ( $sName ) {
00063             case 'expanded':
00064                 return $this->getExpanded();
00065                 break;
00066         }
00067         return parent::__get( $sName );
00068     }
00069 
00073     public function __construct()
00074     {
00075         parent::__construct();
00076         $this->init( 'oxcontents' );
00077     }
00078 
00084     public function getExpanded()
00085     {
00086         if ( !isset( $this->_blExpanded ) ) {
00087             $this->_blExpanded = ( $this->getId() == oxConfig::getParameter( 'oxcid' ) );
00088         }
00089         return $this->_blExpanded;
00090     }
00091 
00099     public function loadByIdent( $sLoadId )
00100     {
00101         $sContentsTable = $this->getViewName();
00102 
00103         $sSelect = $this->buildSelectString( array( $sContentsTable.'.oxloadid' => $sLoadId,
00104                                                     $sContentsTable.'.oxactive' => '1',
00105                                                     $sContentsTable.'.oxshopid' => $this->getConfig()->getShopId() ) );
00106 
00107         return $this->assignRecord( $sSelect );
00108     }
00109 
00117     public function assign( $dbRecord )
00118     {
00119 
00120         parent::assign( $dbRecord );
00121         // workaround for firefox showing &lang= as &9001;= entity, mantis#0001272
00122         $this->oxcontents__oxcontent->setValue(str_replace( '&lang=', '&amp;lang=', $this->oxcontents__oxcontent->value ), oxField::T_RAW);
00123     }
00124 
00132     public function getBaseSeoLink( $iLang )
00133     {
00134         return oxSeoEncoderContent::getInstance()->getContentUrl( $this, $iLang );
00135     }
00136 
00144     public function getLink( $iLang = null )
00145     {
00146         if ( !oxUtils::getInstance()->seoIsActive() ) {
00147             return $this->getStdLink( $iLang );
00148         }
00149 
00150         if ( $iLang === null ) {
00151             $iLang = $this->getLanguage();
00152         }
00153 
00154         if ( !isset( $this->_aSeoUrls[$iLang] ) ) {
00155             $this->_aSeoUrls[$iLang] = $this->getBaseSeoLink( $iLang );
00156         }
00157 
00158         return $this->_aSeoUrls[$iLang];
00159     }
00160 
00170     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
00171     {
00172         $sUrl = '';
00173         if ( $blFull ) {
00174             //always returns shop url, not admin
00175             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
00176         }
00177 
00178         if ( $this->oxcontents__oxloadid->value === 'oxcredits' ) {
00179             $sUrl .= "index.php?cl=credits";
00180         } else {
00181             $sUrl .= "index.php?cl=content";
00182         }
00183 
00184         if ( $blAddId ) {
00185             $sUrl .= "&amp;oxcid=".$this->getId();
00186             // adding parent category if if available
00187             if ( $this->_sParentCatId !== false &&
00188                  $this->oxcontents__oxcatid->value && $this->oxcontents__oxcatid->value != 'oxrootid' ) {
00189 
00190                 if ( $this->_sParentCatId === null ) {
00191                     $this->_sParentCatId = false;
00192                     $oDb = oxDb::getDb();
00193                     $sParentId = $oDb->getOne( "select oxparentid from oxcategories where oxid = ".$oDb->quote( $this->oxcontents__oxcatid->value ) );
00194                     if ( $sParentId && 'oxrootid' != $sParentId ) {
00195                         $this->_sParentCatId = $sParentId;
00196                     }
00197                 }
00198 
00199                 if ( $this->_sParentCatId ) {
00200                     $sUrl .= "&amp;cnid=".$this->_sParentCatId;
00201                 }
00202             }
00203         }
00204 
00205         //always returns shop url, not admin
00206         return $sUrl;
00207     }
00208 
00217     public function getStdLink( $iLang = null, $aParams = array() )
00218     {
00219         if ( $iLang === null ) {
00220             $iLang = $this->getLanguage();
00221         }
00222 
00223         return oxUtilsUrl::getInstance()->processUrl( $this->getBaseStdLink( $iLang ), true, $aParams, $iLang);
00224     }
00225 
00235     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00236     {
00237         if ('oxcontent' === strtolower($sFieldName) || 'oxcontents__oxcontent' === strtolower($sFieldName)) {
00238             $iDataType = oxField::T_RAW;
00239         }
00240 
00241         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00242     }
00243 
00251     public function delete( $sOXID = null)
00252     {
00253         if ( !$sOXID ) {
00254             $sOXID = $this->getId();
00255         }
00256         if (parent::delete($sOXID)) {
00257             oxSeoEncoderContent::getInstance()->onDeleteContent($sOXID);
00258             return true;
00259         }
00260         return false;
00261     }
00262 
00268     public function save()
00269     {
00270         $blSaved = parent::save();
00271         if ( $blSaved && $this->oxcontents__oxloadid->value === 'oxagb' ) {
00272             $sShopId  = $this->getConfig()->getShopId();
00273             $sVersion = $this->oxcontents__oxtermversion->value;
00274 
00275             $oDb = oxDb::getDb();
00276             // dropping expired..
00277             $oDb->execute( "delete from oxacceptedterms where oxshopid='{$sShopId}' and oxtermversion != ".$oDb->quote( $sVersion ) );
00278         }
00279         return $blSaved;
00280     }
00281 
00287     public function getTermsVersion()
00288     {
00289         if ( $this->loadByIdent( 'oxagb' ) ) {
00290             return $this->oxcontents__oxtermversion->value;
00291         }
00292     }
00293 
00301     public function loadCredits( $sCreditsId = "oxcredits" )
00302     {
00303         $sShopId = $this->getShopId();
00304 
00305         // fetching column names
00306         $sColQ = "SHOW COLUMNS FROM oxcontents WHERE field LIKE  'oxcontent%'";
00307 
00308         $aCols = oxDb::getDb()->getAll( $sColQ );
00309 
00310         // building subquery
00311         $sPattern = "IF ( %s != '', %s, %s ) ";
00312         $iCount = count( $aCols ) - 1;
00313 
00314         $sContQ = "SELECT {$sPattern}";
00315         foreach ( $aCols as $iKey => $aCol ) {
00316             $sContQ = sprintf( $sContQ, $aCol[0], $aCol[0], $iCount != $iKey ? $sPattern : "''" );
00317         }
00318         $sContQ .= " FROM oxcontents WHERE oxloadid = '{$sCreditsId}' AND oxshopid = '{$sShopId}'";
00319 
00320         $sTable  = $this->getViewName();
00321         $aParams = array( "{$sTable}.oxloadid" => $sCreditsId,
00322                           "{$sTable}.oxshopid" => $sShopId );
00323         $sQ = $this->buildSelectString( $aParams );
00324         $sQ = str_replace( "{$sTable}.oxcontent", "( $sContQ ) as oxcontent", $sQ );
00325 
00326         return $this->assignRecord( $sQ );
00327     }
00328 }