content_main.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Content_Main extends oxAdminDetails
00009 {
00016     public function render()
00017     {
00018         $myConfig = $this->getConfig();
00019 
00020         parent::render();
00021 
00022         $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
00023 
00024         // categorie tree
00025         $oCatTree = oxNew( "oxCategoryList" );
00026         $oCatTree->buildList($myConfig->getConfigParam( 'bl_perfLoadCatTree' ));
00027 
00028         $oContent = oxNew( "oxcontent" );
00029         if ( $soxId != "-1" && isset( $soxId)) {
00030             // load object
00031             $oContent->loadInLang( $this->_iEditLang, $soxId );
00032 
00033             $oOtherLang = $oContent->getAvailableInLangs();
00034             if (!isset($oOtherLang[$this->_iEditLang])) {
00035                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00036                 $oContent->loadInLang( key($oOtherLang), $soxId );
00037             }
00038 
00039             // remove already created languages
00040             $aLang = array_diff ( oxLang::getInstance()->getLanguageNames(), $oOtherLang );
00041             if ( count( $aLang))
00042                 $this->_aViewData["posslang"] = $aLang;
00043             foreach ( $oOtherLang as $id => $language) {
00044                 $oLang= new oxStdClass();
00045                 $oLang->sLangDesc = $language;
00046                 $oLang->selected = ($id == $this->_iEditLang);
00047                 $this->_aViewData["otherlang"][$id] =  clone $oLang;
00048             }
00049             // mark selected
00050             if (  $oContent->oxcontents__oxcatid->value && isset( $oCatTree[$oContent->oxcontents__oxcatid->value] ) ) {
00051                 $oCatTree[$oContent->oxcontents__oxcatid->value]->selected = 1;
00052             }
00053 
00054         } else {
00055                 // create ident to make life easier
00056                 $sUId = oxUtilsObject::getInstance()->generateUId();
00057                 $oContent->oxcontents__oxloadid = new oxField( $sUId );
00058         }
00059 
00060         $this->_aViewData["edit"] = $oContent;
00061         $this->_aViewData["link"] = "[{ oxgetseourl ident=&quot;".$oContent->oxcontents__oxloadid->value."&quot; type=&quot;oxcontent&quot; }]";
00062         $this->_aViewData["cattree"] = $oCatTree;
00063 
00064         // generate editor
00065         $sCSS = "content.tpl.css";
00066         if ( $oContent->oxcontents__oxsnippet->value == '1') {
00067             $sCSS = null;
00068         }
00069 
00070         $this->_aViewData["editor"]  = $this->_generateTextEditor( "100%", 300, $oContent, "oxcontents__oxcontent", $sCSS);
00071         $this->_aViewData["afolder"] = $myConfig->getConfigParam( 'aCMSfolder' );
00072 
00073         return "content_main.tpl";
00074     }
00075 
00081     public function save()
00082     {
00083         $myConfig = $this->getConfig();
00084 
00085 
00086         $soxId = $this->getEditObjectId();
00087         $aParams = oxConfig::getParameter( "editval");
00088 
00089         if ( isset( $aParams['oxcontents__oxloadid'] ) ) {
00090             $aParams['oxcontents__oxloadid'] = $this->_prepareIdent( $aParams['oxcontents__oxloadid'] );
00091         }
00092 
00093         // check if loadid is unique
00094         if ( $this->_checkIdent( $aParams['oxcontents__oxloadid'], $soxId ) ) {
00095             // loadid already used, display error message
00096             $this->_aViewData["blLoadError"] = true;
00097 
00098             $oContent = oxNew( "oxcontent" );
00099             if ( $soxId != '-1') {
00100                 $oContent->load( $soxId );
00101             }
00102             $oContent->assign( $aParams );
00103             $this->_aViewData["edit"] = $oContent;
00104             return;
00105         }
00106 
00107         // checkbox handling
00108         if ( !isset( $aParams['oxcontents__oxactive']))
00109             $aParams['oxcontents__oxactive'] = 0;
00110 
00111         // special treatment
00112         if ( $aParams['oxcontents__oxtype'] == 0)
00113             $aParams['oxcontents__oxsnippet'] = 1;
00114         else
00115             $aParams['oxcontents__oxsnippet'] = 0;
00116 
00117         //Updates object folder parameters
00118         if ( $aParams['oxcontents__oxfolder'] == 'CMSFOLDER_NONE' ) {
00119             $aParams['oxcontents__oxfolder'] = '';
00120         }
00121 
00122             // shopid
00123             $sShopID = oxSession::getVar( "actshop");
00124             $aParams['oxcontents__oxshopid'] = $sShopID;
00125         $oContent = oxNew( "oxcontent" );
00126 
00127         if ( $soxId != "-1")
00128             $oContent->loadInLang( $this->_iEditLang, $soxId );
00129         else
00130             $aParams['oxcontents__oxid'] = null;
00131 
00132         //$aParams = $oContent->ConvertNameArray2Idx( $aParams);
00133 
00134         $oContent->setLanguage(0);
00135         $oContent->assign( $aParams);
00136         $oContent->setLanguage($this->_iEditLang);
00137         $oContent->save();
00138 
00139         // set oxid if inserted
00140         $this->setEditObjectId( $oContent->getId() );
00141     }
00142 
00148     public function saveinnlang()
00149     {
00150         $myConfig  = $this->getConfig();
00151 
00152 
00153         $soxId = $this->getEditObjectId();
00154         $aParams = oxConfig::getParameter( "editval");
00155 
00156         if ( isset( $aParams['oxcontents__oxloadid'] ) ) {
00157             $aParams['oxcontents__oxloadid'] = $this->_prepareIdent( $aParams['oxcontents__oxloadid'] );
00158         }
00159 
00160         // checkbox handling
00161         if ( !isset( $aParams['oxcontents__oxactive']))
00162             $aParams['oxcontents__oxactive'] = 0;
00163 
00164             // shopid
00165             $sShopID = oxSession::getVar( "actshop");
00166             $aParams['oxcontents__oxshopid'] = $sShopID;
00167 
00168         $oContent = oxNew( "oxcontent" );
00169 
00170         if ( $soxId != "-1")
00171             $oContent->loadInLang( $this->_iEditLang, $soxId );
00172         else
00173             $aParams['oxcontents__oxid'] = null;
00174 
00175         $oContent->setLanguage(0);
00176         $oContent->assign( $aParams);
00177 
00178         // apply new language
00179         $oContent->setLanguage( oxConfig::getParameter( "new_lang" ) );
00180         $oContent->save();
00181 
00182         // set oxid if inserted
00183         $this->setEditObjectId( $oContent->getId() );
00184     }
00185 
00193     protected function _prepareIdent( $sIdent )
00194     {
00195         if ( $sIdent ) {
00196             return getStr()->preg_replace( "/[^a-zA-Z0-9_]*/", "", $sIdent );
00197         }
00198     }
00199 
00208     protected function _checkIdent( $sIdent, $sOxId )
00209     {
00210         $blAllow = false;
00211         $oDb = oxDb::getDb();
00212         // null not allowed
00213         if ( !strlen( $sIdent ) ) {
00214             $blAllow = true;
00215         } elseif ( $oDb->getOne( "select oxid from oxcontents where oxloadid = ".$oDb->quote( $sIdent ) ." and oxid != ".$oDb->quote( $sOxId ) ." and oxshopid = '".$this->getConfig()->getShopId()."'" ) ) {
00216             $blAllow = true;
00217         }
00218         return $blAllow;
00219     }
00220 }