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                 }
00118 
00119                 // parse for styles and add them
00120                 $this->setAdminMode( false );
00121                 $sCSSPath = $myConfig->getResourcePath("{$sStylesheet}", false );
00122                 $sCSSUrl  = $myConfig->getResourceUrl("{$sStylesheet}", false );
00123 
00124                 $aCSSPaths = array();
00125                 $this->setAdminMode( true );
00126 
00127                 if (is_file($sCSSPath)) {
00128 
00129                     $aCSSPaths[] = $sCSSUrl;
00130 
00131                     if (is_readable($sCSSPath)) {
00132                         $aCSS = @file( $sCSSPath);
00133                         if ( isset( $aCSS) && $aCSS) {
00134                             $aClasses = array();
00135                             $oStr = getStr();
00136                             foreach ( $aCSS as $key => $sLine ) {
00137                                 $sLine = trim($sLine);
00138 
00139                                 if ( $sLine[0] == '.' && !$oStr->strstr( $sLine, 'default' ) ) {
00140                                     // found one tag
00141                                     $sTag = $oStr->substr( $sLine, 1);
00142                                     $iEnd = $oStr->strpos( $sTag, ' ' );
00143                                     if ( !isset( $iEnd ) || !$iEnd ) {
00144                                         $iEnd = $oStr->strpos( $sTag, '\n' );
00145                                     }
00146 
00147                                     if ( $sTag = $oStr->substr( $sTag, 0, $iEnd ) ) {
00148                                         $aClasses["span class='{$sTag}'"] = $sTag;
00149                                     }
00150                                 }
00151                             }
00152                             $this->_oEditor->stylesMenu = $aClasses;
00153                         }
00154                     }
00155                 }
00156 
00157                 foreach ( $aCSSPaths as $sCssPath ) {
00158                     $this->_oEditor->addStylesheet( $sCssPath );
00159                 }
00160 
00161                 //while there is a bug in editor template filter we cannot use this feature
00162                 // loading template filter plugin
00163                 $this->_oEditor->loadPlugin( 'templateFilter' );
00164                 $this->_oEditor->plugins['templateFilter']->protect( '[{', '}]' );
00165                 if ( $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
00166                     $this->_oEditor->plugins['templateFilter']->assign( '[{$oViewConf->getCurrentHomeDir()}]', $myConfig->getShopURL() );
00167                     // note: in "[{ $" the space is needed for this parameter not to override previous call. see assign fnc of templateFilter
00168                     $this->_oEditor->plugins['templateFilter']->assign( '[{ $oViewConf->getCurrentHomeDir()}]', $myConfig->getSSLShopURL() );
00169                 }
00170             }
00171 
00172             return $this->_oEditor;
00173         }
00174     }
00175 
00184     protected function _getEditValue( $oObject, $sField )
00185     {
00186         $sEditObjectValue = '';
00187         if ( $oObject && $sField && isset( $oObject->$sField ) ) {
00188 
00189             if ( $oObject->$sField instanceof oxField ) {
00190                 $sEditObjectValue = $oObject->$sField->getRawValue();
00191             } else {
00192                 $sEditObjectValue = $oObject->$sField->value;
00193             }
00194 
00195             $sEditObjectValue = $this->_processEditValue( $sEditObjectValue );
00196             $oObject->$sField = new oxField( $sEditObjectValue, oxField::T_RAW );
00197         }
00198 
00199         return $sEditObjectValue;
00200     }
00201 
00209     protected function _processEditValue( $sValue )
00210     {
00211         // A. replace ONLY if long description is not processed by smarty, or users will not be able to
00212         // store smarty tags ([{$shop->currenthomedir}]/[{$oViewConf->getCurrentHomeDir()}]) in long
00213         // descriptions, which are filled dynamically
00214         if ( !$this->getConfig()->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
00215             $aReplace = array( '[{$shop->currenthomedir}]', '[{$oViewConf->getCurrentHomeDir()}]' );
00216             $sValue = str_replace( $aReplace, $this->getConfig()->getCurrentShopURL(false), $sValue );
00217         }
00218         return $sValue;
00219     }
00220 
00231     protected function _getPlainEditor( $iWidth, $iHeight, $oObject, $sField )
00232     {
00233         $sEditObjectValue = $this->_getEditValue( $oObject, $sField );
00234 
00235         if ( strpos( $iWidth, '%' ) === false ) {
00236             $iWidth .= 'px';
00237         }
00238         if ( strpos( $iHeight, '%' ) === false ) {
00239             $iHeight .= 'px';
00240         }
00241         return "<textarea id='editor_{$sField}' style='width:{$iWidth}; height:{$iHeight};'>{$sEditObjectValue}</textarea>";
00242     }
00243 
00255     protected function _generateTextEditor( $iWidth, $iHeight, $oObject, $sField, $sStylesheet = null )
00256     {
00257         // setup editor
00258         if ( $oEditor = $this->_getTextEditor( $iWidth, $iHeight, $oObject, $sField, $sStylesheet ) ) {
00259             // generate and return editor code
00260             $sEditorHtml = $oEditor->fetch( $iWidth, $iHeight );
00261         } else {
00262             $sEditorHtml = $this->_getPlainEditor( $iWidth, $iHeight, $oObject, $sField );
00263         }
00264 
00265         return $sEditorHtml;
00266     }
00267 
00273     public function resetNrOfCatArticles()
00274     {
00275         // resetting categories article count cache
00276         $this->resetContentCache();
00277     }
00278 
00284     public function resetNrOfVendorArticles()
00285     {
00286         // resetting vendors cache
00287         $this->resetContentCache();
00288     }
00289 
00295     public function resetNrOfManufacturerArticles()
00296     {
00297         // resetting manufacturers cache
00298         $this->resetContentCache();
00299     }
00300 
00313     protected function _getCategoryTree( $sTplVarName, $sSelectedCatId, $sEditCatId = '', $blForceNonCache = false, $iTreeShopId = null )
00314     {
00315         // caching category tree, to load it once, not many times
00316         if ( !isset( $this->oCatTree ) || $blForceNonCache ) {
00317             $this->oCatTree = oxNew( 'oxCategoryList' );
00318             $this->oCatTree->setShopID( $iTreeShopId );
00319 
00320             // setting language
00321             $oBase = $this->oCatTree->getBaseObject();
00322             $oBase->setLanguage( $this->_iEditLang );
00323 
00324             $this->oCatTree->loadList();
00325         }
00326 
00327         // copying tree
00328         $oCatTree = $this->oCatTree;
00329         //removing current category
00330         if ( $sEditCatId && isset( $oCatTree[$sEditCatId] ) ) {
00331             unset( $oCatTree[$sEditCatId] );
00332         }
00333 
00334         // add first fake category for not assigned articles
00335         $oRoot = oxNew( 'oxcategory' );
00336         $oRoot->oxcategories__oxtitle = new oxField('--');
00337 
00338         $oCatTree->assign( array_merge( array( '' => $oRoot ), $oCatTree->getArray() ) );
00339 
00340         // mark selected
00341         if ( $sSelectedCatId ) {
00342             // fixed parent category in select list
00343             foreach ($oCatTree as $oCategory) {
00344                 if ($oCategory->getId() == $sSelectedCatId ) {
00345                     $oCategory->selected = 1;
00346                     break;
00347                 }
00348             }
00349         } else {
00350             // no category selected - opening first available
00351             $oCatTree->rewind();
00352             if ( $oCat = $oCatTree->current() ) {
00353                 $oCat->selected = 1;
00354                 $sSelectedCatId = $oCat->getId();
00355             }
00356         }
00357 
00358         // passing to view
00359         $this->_aViewData[$sTplVarName] =  $oCatTree;
00360 
00361         return $sSelectedCatId;
00362     }
00363 
00369     public function changeFolder()
00370     {
00371         $sFolder = oxConfig::getParameter( 'setfolder' );
00372         $sFolderClass = oxConfig::getParameter( 'folderclass' );
00373 
00374         if ( $sFolderClass == 'oxcontent' && $sFolder == 'CMSFOLDER_NONE' ) {
00375             $sFolder = '';
00376         }
00377 
00378         $oObject = oxNew( $sFolderClass );
00379         if ( $oObject->load( $this->getEditObjectId() ) ) {
00380             $oObject->{$oObject->getCoreTableName() . '__oxfolder'} = new oxField($sFolder);
00381             $oObject->save();
00382         }
00383     }
00384 
00392     protected function _setupNavigation( $sNode )
00393     {
00394         // navigation according to class
00395         if ( $sNode ) {
00396 
00397             $myAdminNavig = $this->getNavigation();
00398 
00399             // default tab
00400             $this->_aViewData['default_edit'] = $myAdminNavig->getActiveTab( $sNode, $this->_iDefEdit );
00401 
00402             // buttons
00403             $this->_aViewData['bottom_buttons'] = $myAdminNavig->getBtn( $sNode );
00404         }
00405     }
00406 
00414     protected function _resetCounts( $aIds )
00415     {
00416         $oUtils = oxRegistry::get("oxUtilsCount");
00417         foreach ( $aIds as $sType => $aResetInfo ) {
00418             foreach ( $aResetInfo as $sResetId => $iPos ) {
00419                 switch ( $sType ) {
00420                     case 'vendor':
00421                         $this->resetCounter( "vendorArticle", $sResetId );
00422                         break;
00423                     case 'manufacturer':
00424                         $this->resetCounter( "manufacturerArticle", $sResetId );
00425                         break;
00426                 }
00427             }
00428         }
00429     }
00430 }