oxadmindetails.php

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