oxadmindetails.php

Go to the documentation of this file.
00001 <?php
00002 
00006 //require_once "oxajax.php";
00007 
00011 class oxAdminDetails extends oxAdminView
00012 {
00013 
00019     protected $_oEditor = null;
00020 
00026     public function render()
00027     {
00028         $sReturn = parent::render();
00029         $oLang = oxRegistry::getLang();
00030 
00031         // generate help link
00032         $myConfig = $this->getConfig();
00033         $sDir = $myConfig->getConfigParam('sShopDir') . '/documentation/admin';
00034         $iLang = 1;
00035         $sAbbr = $oLang->getLanguageAbbr($oLang->getTplLanguage());
00036         if ($sAbbr == "de") {
00037             $iLang = 0;
00038         }
00039         if (is_dir($sDir)) {
00040             $sDir = $myConfig->getConfigParam('sShopURL') . 'documentation/admin';
00041         } else {
00042 
00043             $oShop = $this->_getEditShop(oxRegistry::getSession()->getVariable('actshop'));
00044             //$sDir = "http://docu.oxid-esales.com/PE/{$oShop->oxshops__oxversion->value}/" .
00045             //$myConfig->getConfigParam( 'iAdminLanguage' ) . '/admin';
00046             $sDir = "http://docu.oxid-esales.com/PE/{$oShop->oxshops__oxversion->value}/" . $iLang . '/admin';
00047         }
00048 
00049         $this->_aViewData['sHelpURL'] = $sDir;
00050 
00051         return $sReturn;
00052     }
00053 
00065     protected function _getTextEditor($iWidth, $iHeight, $oObject, $sField, $sStylesheet = null)
00066     {
00067         if ($this->_oEditor === null) {
00068             $myConfig = $this->getConfig();
00069 
00070             // include the config file and editor class:
00071             $sEditorPath = 'wysiwigpro';
00072             $sEditorFile = getShopBasePath() . "core/" . $sEditorPath . '/wysiwygPro.class.php';
00073 
00074 
00075             // setting loaded state
00076             $this->_oEditor = false;
00077 
00078             if ($sEditorFile && file_exists($sEditorFile)) {
00079                 include_once $sEditorFile;
00080 
00081                 // create a new instance of the wysiwygPro class:
00082                 $this->_oEditor = new wysiwygPro();
00083 
00084                 if (oxRegistry::getConfig()->isSsl() && oxRegistry::getConfig()->getSslShopUrl()) {
00085                     $sEditorUrl = rtrim(oxRegistry::getConfig()->getSslShopUrl(), '/') . "/core/{$sEditorPath}/";
00086                 } else {
00087                     $sEditorUrl = rtrim(oxRegistry::getConfig()->getShopUrl(), '/') . "/core/{$sEditorPath}/";
00088                 }
00089 
00090                 $this->_oEditor->editorURL = $sEditorUrl;
00091                 $this->_oEditor->urlFormat = 'preserve';
00092 
00093                 // document & image directory:
00094                 $sPictureDir = $myConfig->getPictureDir(false) . 'wysiwigpro/';
00095                 $sPictureUrl = $myConfig->getPictureUrl(null, false) . 'wysiwigpro/';
00096                 $this->_oEditor->documentDir = $this->_oEditor->imageDir = $sPictureDir;
00097                 $this->_oEditor->documentURL = $this->_oEditor->imageURL = $sPictureUrl;
00098 
00099                 // enabling upload
00100                 $this->_oEditor->upload = true;
00101 
00102                 // setting empty value
00103                 $this->_oEditor->emptyValue = "<p>&nbsp;</p>";
00104 
00105                 //#M432 enabling deleting files and folders
00106                 $this->_oEditor->deleteFiles = true;
00107                 $this->_oEditor->deleteFolders = true;
00108 
00109                 // allowed image extensions
00110                 $this->_oEditor->allowedImageExtensions = '.jpg, .jpeg, .gif, .png';
00111 
00112                 // allowed document extensions
00113                 $this->_oEditor->allowedDocExtensions = '.html, .htm, .pdf, .doc, .rtf, .txt, .xl, .xls, .ppt, .pps, ' .
00114                                                         '.zip, .tar, .swf, .wmv, .rm, .mov, .jpg, .jpeg, .gif, .png';
00115 
00116                 // set name
00117                 $this->_oEditor->name = $sField;
00118 
00119                 // set language file name
00120                 $oLang = oxRegistry::getLang();
00121                 $this->_oEditor->lang = $oLang->translateString('editor_language', $oLang->getTplLanguage());
00122 
00123                 // set contents
00124                 if ($sEditObjectValue = $this->_getEditValue($oObject, $sField)) {
00125                     $this->_oEditor->value = $sEditObjectValue;
00126                     $this->_oEditor->encoding = $this->getConfig()->isUtf() ? 'UTF-8' : 'ISO-8859-15';
00127                 }
00128 
00129                 // parse for styles and add them
00130                 $this->setAdminMode(false);
00131                 $sCSSPath = $myConfig->getResourcePath("{$sStylesheet}", false);
00132                 $sCSSUrl = $myConfig->getResourceUrl("{$sStylesheet}", false);
00133 
00134                 $aCSSPaths = array();
00135                 $this->setAdminMode(true);
00136 
00137                 if (is_file($sCSSPath)) {
00138 
00139                     $aCSSPaths[] = $sCSSUrl;
00140 
00141                     if (is_readable($sCSSPath)) {
00142                         $aCSS = @file($sCSSPath);
00143                         if (isset($aCSS) && $aCSS) {
00144                             $aClasses = array();
00145                             $oStr = getStr();
00146                             foreach ($aCSS as $key => $sLine) {
00147                                 $sLine = trim($sLine);
00148 
00149                                 if ($sLine[0] == '.' && !$oStr->strstr($sLine, 'default')) {
00150                                     // found one tag
00151                                     $sTag = $oStr->substr($sLine, 1);
00152                                     $iEnd = $oStr->strpos($sTag, ' ');
00153                                     if (!isset($iEnd) || !$iEnd) {
00154                                         $iEnd = $oStr->strpos($sTag, '\n');
00155                                     }
00156 
00157                                     if ($sTag = $oStr->substr($sTag, 0, $iEnd)) {
00158                                         $aClasses["span class='{$sTag}'"] = $sTag;
00159                                     }
00160                                 }
00161                             }
00162                             $this->_oEditor->stylesMenu = $aClasses;
00163                         }
00164                     }
00165                 }
00166 
00167                 foreach ($aCSSPaths as $sCssPath) {
00168                     $this->_oEditor->addStylesheet($sCssPath);
00169                 }
00170 
00171                 //while there is a bug in editor template filter we cannot use this feature
00172                 // loading template filter plugin
00173                 $this->_oEditor->loadPlugin('templateFilter');
00174                 $this->_oEditor->plugins['templateFilter']->protect('[{', '}]');
00175                 if ($myConfig->getConfigParam('bl_perfParseLongDescinSmarty')) {
00176                     $sCurrentHomeDir = '[{$oViewConf->getCurrentHomeDir()}]';
00177                     $this->_oEditor->plugins['templateFilter']->assign($sCurrentHomeDir, $myConfig->getShopURL());
00178                     // note: in "[{ $" the space is needed for this parameter not to override previous call.
00179                     // see assign fnc of templateFilter
00180                     $this->_oEditor->plugins['templateFilter']->assign($sCurrentHomeDir, $myConfig->getSSLShopURL());
00181                 }
00182             }
00183 
00184             return $this->_oEditor;
00185         }
00186     }
00187 
00196     protected function _getEditValue($oObject, $sField)
00197     {
00198         $sEditObjectValue = '';
00199         if ($oObject && $sField && isset($oObject->$sField)) {
00200 
00201             if ($oObject->$sField instanceof oxField) {
00202                 $sEditObjectValue = $oObject->$sField->getRawValue();
00203             } else {
00204                 $sEditObjectValue = $oObject->$sField->value;
00205             }
00206 
00207             $sEditObjectValue = $this->_processEditValue($sEditObjectValue);
00208             $oObject->$sField = new oxField($sEditObjectValue, oxField::T_RAW);
00209         }
00210 
00211         return $sEditObjectValue;
00212     }
00213 
00221     protected function _processEditValue($sValue)
00222     {
00223         // A. replace ONLY if long description is not processed by smarty, or users will not be able to
00224         // store smarty tags ([{$shop->currenthomedir}]/[{$oViewConf->getCurrentHomeDir()}]) in long
00225         // descriptions, which are filled dynamically
00226         if (!$this->getConfig()->getConfigParam('bl_perfParseLongDescinSmarty')) {
00227             $aReplace = array('[{$shop->currenthomedir}]', '[{$oViewConf->getCurrentHomeDir()}]');
00228             $sValue = str_replace($aReplace, $this->getConfig()->getCurrentShopURL(false), $sValue);
00229         }
00230 
00231         return $sValue;
00232     }
00233 
00244     protected function _getPlainEditor($iWidth, $iHeight, $oObject, $sField)
00245     {
00246         $sEditObjectValue = $this->_getEditValue($oObject, $sField);
00247 
00248         if (strpos($iWidth, '%') === false) {
00249             $iWidth .= 'px';
00250         }
00251         if (strpos($iHeight, '%') === false) {
00252             $iHeight .= 'px';
00253         }
00254 
00255         return "<textarea id='editor_{$sField}' style='width:{$iWidth}; height:{$iHeight};'>{$sEditObjectValue}</textarea>";
00256     }
00257 
00269     protected function _generateTextEditor($iWidth, $iHeight, $oObject, $sField, $sStylesheet = null)
00270     {
00271         // setup editor
00272         if ($oEditor = $this->_getTextEditor($iWidth, $iHeight, $oObject, $sField, $sStylesheet)) {
00273             // generate and return editor code
00274             $sEditorHtml = $oEditor->fetch($iWidth, $iHeight);
00275         } else {
00276             $sEditorHtml = $this->_getPlainEditor($iWidth, $iHeight, $oObject, $sField);
00277         }
00278 
00279         return $sEditorHtml;
00280     }
00281 
00285     public function resetNrOfCatArticles()
00286     {
00287         // resetting categories article count cache
00288         $this->resetContentCache();
00289     }
00290 
00294     public function resetNrOfVendorArticles()
00295     {
00296         // resetting vendors cache
00297         $this->resetContentCache();
00298     }
00299 
00303     public function resetNrOfManufacturerArticles()
00304     {
00305         // resetting manufacturers cache
00306         $this->resetContentCache();
00307     }
00308 
00319     protected function _createCategoryTree($sTplVarName, $sEditCatId = '', $blForceNonCache = false, $iTreeShopId = null)
00320     {
00321         // caching category tree, to load it once, not many times
00322         if (!isset($this->oCatTree) || $blForceNonCache) {
00323             $this->oCatTree = oxNew('oxCategoryList');
00324             $this->oCatTree->setShopID($iTreeShopId);
00325 
00326             // setting language
00327             $oBase = $this->oCatTree->getBaseObject();
00328             $oBase->setLanguage($this->_iEditLang);
00329 
00330             $this->oCatTree->loadList();
00331         }
00332 
00333         // copying tree
00334         $oCatTree = $this->oCatTree;
00335         //removing current category
00336         if ($sEditCatId && isset($oCatTree[$sEditCatId])) {
00337             unset($oCatTree[$sEditCatId]);
00338         }
00339 
00340         // add first fake category for not assigned articles
00341         $oRoot = oxNew('oxcategory');
00342         $oRoot->oxcategories__oxtitle = new oxField('--');
00343 
00344         $oCatTree->assign(array_merge(array('' => $oRoot), $oCatTree->getArray()));
00345 
00346         // passing to view
00347         $this->_aViewData[$sTplVarName] = $oCatTree;
00348 
00349         return $oCatTree;
00350     }
00351 
00364     protected function _getCategoryTree($sTplVarName, $sSelectedCatId, $sEditCatId = '', $blForceNonCache = false, $iTreeShopId = null)
00365     {
00366         $oCatTree = $this->_createCategoryTree($sTplVarName, $sEditCatId, $blForceNonCache, $iTreeShopId);
00367 
00368         // mark selected
00369         if ($sSelectedCatId) {
00370             // fixed parent category in select list
00371             foreach ($oCatTree as $oCategory) {
00372                 if ($oCategory->getId() == $sSelectedCatId) {
00373                     $oCategory->selected = 1;
00374                     break;
00375                 }
00376             }
00377         } else {
00378             // no category selected - opening first available
00379             $oCatTree->rewind();
00380             if ($oCat = $oCatTree->current()) {
00381                 $oCat->selected = 1;
00382                 $sSelectedCatId = $oCat->getId();
00383             }
00384         }
00385 
00386         // passing to view
00387         $this->_aViewData[$sTplVarName] = $oCatTree;
00388 
00389         return $sSelectedCatId;
00390     }
00391 
00395     public function changeFolder()
00396     {
00397         $sFolder = oxRegistry::getConfig()->getRequestParameter('setfolder');
00398         $sFolderClass = oxRegistry::getConfig()->getRequestParameter('folderclass');
00399 
00400         if ($sFolderClass == 'oxcontent' && $sFolder == 'CMSFOLDER_NONE') {
00401             $sFolder = '';
00402         }
00403 
00404         $oObject = oxNew($sFolderClass);
00405         if ($oObject->load($this->getEditObjectId())) {
00406             $oObject->{$oObject->getCoreTableName() . '__oxfolder'} = new oxField($sFolder);
00407             $oObject->save();
00408         }
00409     }
00410 
00416     protected function _setupNavigation($sNode)
00417     {
00418         // navigation according to class
00419         if ($sNode) {
00420 
00421             $myAdminNavig = $this->getNavigation();
00422 
00423             // default tab
00424             $this->_aViewData['default_edit'] = $myAdminNavig->getActiveTab($sNode, $this->_iDefEdit);
00425 
00426             // buttons
00427             $this->_aViewData['bottom_buttons'] = $myAdminNavig->getBtn($sNode);
00428         }
00429     }
00430 
00436     protected function _resetCounts($aIds)
00437     {
00438         $oUtils = oxRegistry::get("oxUtilsCount");
00439         foreach ($aIds as $sType => $aResetInfo) {
00440             foreach ($aResetInfo as $sResetId => $iPos) {
00441                 switch ($sType) {
00442                     case 'vendor':
00443                         $this->resetCounter("vendorArticle", $sResetId);
00444                         break;
00445                     case 'manufacturer':
00446                         $this->resetCounter("manufacturerArticle", $sResetId);
00447                         break;
00448                 }
00449             }
00450         }
00451     }
00452 }