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 = oxConfig::getInstance()->getConfigParam('sShopURL')."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 
00314     protected function _getCategoryTree( $sTplVarName, $sSelectedCatId, $sEditCatId = '', $blForceNonCache = false, $iTreeShopId = null )
00315     {
00316         // caching category tree, to load it once, not many times
00317         if ( !isset( $this->oCatTree ) || $blForceNonCache ) {
00318             $this->oCatTree = oxNew( 'oxCategoryList' );
00319             $this->oCatTree->setShopID( $iTreeShopId );
00320 
00321             // setting language
00322             $oBase = $this->oCatTree->getBaseObject();
00323             $oBase->setLanguage( $this->_iEditLang );
00324 
00325             $this->oCatTree->loadList();
00326         }
00327 
00328         // copying tree
00329         $oCatTree = $this->oCatTree;
00330         //removing current category
00331         if ( $sEditCatId && isset( $oCatTree[$sEditCatId] ) ) {
00332             unset( $oCatTree[$sEditCatId] );
00333         }
00334 
00335         // add first fake category for not assigned articles
00336         $oRoot = oxNew( 'oxcategory' );
00337         $oRoot->oxcategories__oxtitle = new oxField('--');
00338 
00339         $oCatTree->assign( array_merge( array( '' => $oRoot ), $oCatTree->getArray() ) );
00340 
00341         // mark selected
00342         if ( $sSelectedCatId ) {
00343             // fixed parent category in select list
00344             foreach ($oCatTree as $oCategory) {
00345                 if ($oCategory->getId() == $sSelectedCatId ) {
00346                     $oCategory->selected = 1;
00347                     break;
00348                 }
00349             }
00350         } else {
00351             // no category selected - opening first available
00352             $oCatTree->rewind();
00353             if ( $oCat = $oCatTree->current() ) {
00354                 $oCat->selected = 1;
00355                 $sSelectedCatId = $oCat->getId();
00356             }
00357         }
00358 
00359         // passing to view
00360         $this->_aViewData[$sTplVarName] =  $oCatTree;
00361 
00362         return $sSelectedCatId;
00363     }
00364 
00370     public function changeFolder()
00371     {
00372         $sFolder = oxConfig::getParameter( 'setfolder' );
00373         $sFolderClass = oxConfig::getParameter( 'folderclass' );
00374 
00375         if ( $sFolderClass == 'oxcontent' && $sFolder == 'CMSFOLDER_NONE' ) {
00376             $sFolder = '';
00377         }
00378 
00379         $oObject = oxNew( $sFolderClass );
00380         if ( $oObject->load( $this->getEditObjectId() ) ) {
00381             $oObject->{$oObject->getCoreTableName() . '__oxfolder'} = new oxField($sFolder);
00382             $oObject->save();
00383         }
00384     }
00385 
00393     protected function _setupNavigation( $sNode )
00394     {
00395         // navigation according to class
00396         if ( $sNode ) {
00397 
00398             $myAdminNavig = $this->getNavigation();
00399 
00400             // default tab
00401             $this->_aViewData['default_edit'] = $myAdminNavig->getActiveTab( $sNode, $this->_iDefEdit );
00402 
00403             // buttons
00404             $this->_aViewData['bottom_buttons'] = $myAdminNavig->getBtn( $sNode );
00405         }
00406     }
00407 
00415     protected function _resetCounts( $aIds )
00416     {
00417         $oUtils = oxRegistry::get("oxUtilsCount");
00418         foreach ( $aIds as $sType => $aResetInfo ) {
00419             foreach ( $aResetInfo as $sResetId => $iPos ) {
00420                 switch ( $sType ) {
00421                     case 'vendor':
00422                         $this->resetCounter( "vendorArticle", $sResetId );
00423                         break;
00424                     case 'manufacturer':
00425                         $this->resetCounter( "manufacturerArticle", $sResetId );
00426                         break;
00427                 }
00428             }
00429         }
00430     }
00431 }