content_main.php

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