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 = oxLang::getInstance();
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()."admin/".$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                 // set language file name
00083                 $sEditorUrl = $myConfig->getConfigParam( 'sShopURL' ).$myConfig->getConfigParam( 'sAdminDir' )."/{$sEditorPath}/";
00084                 if ( $sAdminSSLURL = $myConfig->getConfigParam( 'sAdminSSLURL' ) ) {
00085                     $sEditorUrl = "{$sAdminSSLURL}/{$sEditorPath}/";
00086                 }
00087 
00088                 $this->_oEditor->editorURL = $sEditorUrl;
00089                 $this->_oEditor->urlFormat = 'preserve';
00090 
00091                 // document & image directory:
00092                 $this->_oEditor->documentDir = $this->_oEditor->imageDir = $myConfig->getPictureDir( false ).'wysiwigpro/';
00093                 $this->_oEditor->documentURL = $this->_oEditor->imageURL = $myConfig->getPictureUrl( null, false ).'wysiwigpro/';
00094 
00095                 // enabling upload
00096                 $this->_oEditor->upload = true;
00097 
00098                 // setting empty value
00099                 $this->_oEditor->emptyValue = "";
00100 
00101                 //#M432 enabling deleting files and folders
00102                 $this->_oEditor->deleteFiles = true;
00103                 $this->_oEditor->deleteFolders = true;
00104 
00105                 // allowed image extensions
00106                 $this->_oEditor->allowedImageExtensions = '.jpg, .jpeg, .gif, .png';
00107 
00108                 // allowed document extensions
00109                 $this->_oEditor->allowedDocExtensions   = '.html, .htm, .pdf, .doc, .rtf, .txt, .xl, .xls, .ppt, .pps, .zip, .tar, .swf, .wmv, .rm, .mov, .jpg, .jpeg, .gif, .png';
00110 
00111                 // set name
00112                 $this->_oEditor->name = $sField;
00113 
00114                 // set language file name
00115                 $oLang = oxLang::getInstance();
00116                 $this->_oEditor->lang = $oLang->translateString( 'editor_language', $oLang->getTplLanguage() );
00117 
00118                 // set contents
00119                 if ( $sEditObjectValue = $this->_getEditValue( $oObject, $sField ) ) {
00120                     $this->_oEditor->value = $sEditObjectValue;
00121                 }
00122 
00123                 // parse for styles and add them
00124                 $this->setAdminMode( false );
00125                 if ( $myConfig->getConfigParam( "blFormerTplSupport" ) ) {
00126                     $sCSSPath = $myConfig->getResourcePath("styles/{$sStylesheet}", false );
00127                     $sCSSUrl  = $myConfig->getResourceUrl("styles/{$sStylesheet}", false );
00128                 } else {
00129                     $sCSSPath = $myConfig->getResourcePath("{$sStylesheet}", false );
00130                     $sCSSUrl  = $myConfig->getResourceUrl("{$sStylesheet}", false );
00131                 }
00132 
00133                 $aCSSPaths = array();
00134                 $this->setAdminMode( true );
00135 
00136                 if (is_file($sCSSPath)) {
00137 
00138                     $aCSSPaths[] = $sCSSUrl;
00139 
00140                     if (is_readable($sCSSPath)) {
00141                         $aCSS = @file( $sCSSPath);
00142                         if ( isset( $aCSS) && $aCSS) {
00143                             $aClasses = array();
00144                             $oStr = getStr();
00145                             foreach ( $aCSS as $key => $sLine ) {
00146                                 $sLine = trim($sLine);
00147 
00148                                 if ( $sLine[0] == '.' && !$oStr->strstr( $sLine, 'default' ) ) {
00149                                     // found one tag
00150                                     $sTag = $oStr->substr( $sLine, 1);
00151                                     $iEnd = $oStr->strpos( $sTag, ' ' );
00152                                     if ( !isset( $iEnd ) || !$iEnd ) {
00153                                         $iEnd = $oStr->strpos( $sTag, '\n' );
00154                                     }
00155 
00156                                     if ( $sTag = $oStr->substr( $sTag, 0, $iEnd ) ) {
00157                                         $aClasses["span class='{$sTag}'"] = $sTag;
00158                                     }
00159                                 }
00160                             }
00161                             $this->_oEditor->stylesMenu = $aClasses;
00162                         }
00163                     }
00164                 }
00165 
00166                 foreach ( $aCSSPaths as $sCssPath ) {
00167                     $this->_oEditor->addStylesheet( $sCssPath );
00168                 }
00169 
00170                 //while there is a bug in editor template filter we cannot use this feature
00171                 // loading template filter plugin
00172                 $this->_oEditor->loadPlugin( 'templateFilter' );
00173                 $this->_oEditor->plugins['templateFilter']->protect( '[{', '}]' );
00174                 if ( $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
00175                     $this->_oEditor->plugins['templateFilter']->assign( '[{$oViewConf->getCurrentHomeDir()}]', $myConfig->getShopURL() );
00176                     // note: in "[{ $" the space is needed for this parameter not to override previous call. see assign fnc of templateFilter
00177                     $this->_oEditor->plugins['templateFilter']->assign( '[{ $oViewConf->getCurrentHomeDir()}]', $myConfig->getSSLShopURL() );
00178                 }
00179             }
00180 
00181             return $this->_oEditor;
00182         }
00183     }
00184 
00193     protected function _getEditValue( $oObject, $sField )
00194     {
00195         $sEditObjectValue = '';
00196         if ( $oObject && $sField && isset( $oObject->$sField ) ) {
00197 
00198             if ( $oObject->$sField instanceof oxField ) {
00199                 $sEditObjectValue = $oObject->$sField->getRawValue();
00200             } else {
00201                 $sEditObjectValue = $oObject->$sField->value;
00202             }
00203 
00204             // A. replace ONLY if long description is not processed by smarty, or users will not be able to
00205             // store smarty tags ([{$shop->currenthomedir}]/[{$oViewConf->getCurrentHomeDir()}]) in long
00206             // descriptions, which are filled dynamically
00207             if ( !$this->getConfig()->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
00208                 $aReplace = array( '[{$shop->currenthomedir}]', '[{$oViewConf->getCurrentHomeDir()}]' );
00209                 $oObject->$sField = new oxField( str_replace( $aReplace, $this->getConfig()->getCurrentShopURL(), $sEditObjectValue ), oxField::T_RAW );
00210                 $sEditObjectValue = $oObject->$sField->value;
00211             }
00212         }
00213 
00214         return $sEditObjectValue;
00215     }
00216 
00227     protected function _getPlainEditor( $iWidth, $iHeight, $oObject, $sField )
00228     {
00229         $sEditObjectValue = $this->_getEditValue( $oObject, $sField );
00230 
00231         if ( strpos( $iWidth, '%' ) === false ) {
00232             $iWidth .= 'px';
00233         }
00234         if ( strpos( $iHeight, '%' ) === false ) {
00235             $iHeight .= 'px';
00236         }
00237         return "<textarea id='editor_{$sField}' style='width:{$iWidth}; height:{$iHeight};'>{$sEditObjectValue}</textarea>";
00238     }
00239 
00251     protected function _generateTextEditor( $iWidth, $iHeight, $oObject, $sField, $sStylesheet = null )
00252     {
00253         // setup editor
00254         if ( $oEditor = $this->_getTextEditor( $iWidth, $iHeight, $oObject, $sField, $sStylesheet ) ) {
00255             // generate and return editor code
00256             $sEditorHtml = $oEditor->fetch( $iWidth, $iHeight );
00257         } else {
00258             $sEditorHtml = $this->_getPlainEditor( $iWidth, $iHeight, $oObject, $sField );
00259         }
00260 
00261         return $sEditorHtml;
00262     }
00263 
00269     public function resetNrOfCatArticles()
00270     {
00271         // resetting categories article count cache
00272         $this->resetContentCache();
00273     }
00274 
00280     public function resetNrOfVendorArticles()
00281     {
00282         // resetting vendors cache
00283         $this->resetContentCache();
00284     }
00285 
00291     public function resetNrOfManufacturerArticles()
00292     {
00293         // resetting manufacturers cache
00294         $this->resetContentCache();
00295     }
00296 
00309     protected function _getCategoryTree( $sTplVarName, $sSelectedCatId, $sEditCatId = '', $blForceNonCache = false, $iTreeShopId = null )
00310     {
00311         // caching category tree, to load it once, not many times
00312         if ( !isset( $this->oCatTree ) || $blForceNonCache ) {
00313             $this->oCatTree = oxNew( 'oxCategoryList' );
00314             $this->oCatTree->setShopID( $iTreeShopId );
00315             $this->oCatTree->buildList( $this->getConfig()->getConfigParam( 'bl_perfLoadCatTree' ) );
00316         }
00317 
00318         // copying tree
00319         $oCatTree = $this->oCatTree;
00320         //removing current category
00321         if ( $sEditCatId && isset( $oCatTree[$sEditCatId] ) ) {
00322             unset( $oCatTree[$sEditCatId] );
00323         }
00324 
00325         // add first fake category for not assigned articles
00326         $oRoot = oxNew( 'oxcategory' );
00327         $oRoot->oxcategories__oxtitle = new oxField('--');
00328 
00329         $oCatTree->assign( array_merge( array( '' => $oRoot ), $oCatTree->getArray() ) );
00330 
00331         // mark selected
00332         if ( $sSelectedCatId ) {
00333             // fixed parent category in select list
00334             foreach ($oCatTree as $oCategory) {
00335                 if ($oCategory->getId() == $sSelectedCatId ) {
00336                     $oCategory->selected = 1;
00337                     break;
00338                 }
00339             }
00340         } else {
00341             // no category selected - opening first available
00342             $oCatTree->rewind();
00343             if ( $oCat = $oCatTree->current() ) {
00344                 $oCat->selected = 1;
00345                 $sSelectedCatId = $oCat->getId();
00346             }
00347         }
00348 
00349         // passing to view
00350         $this->_aViewData[$sTplVarName] =  $oCatTree;
00351 
00352         return $sSelectedCatId;
00353     }
00354 
00360     public function changeFolder()
00361     {
00362         $sFolder = oxConfig::getParameter( 'setfolder' );
00363         $sFolderClass = oxConfig::getParameter( 'folderclass' );
00364 
00365         if ( $sFolderClass == 'oxcontent' && $sFolder == 'CMSFOLDER_NONE' ) {
00366             $sFolder = '';
00367         }
00368 
00369         $oObject = oxNew( $sFolderClass );
00370         if ( $oObject->load( oxConfig::getParameter( 'oxid' ) ) ) {
00371             $oObject->{$oObject->getCoreTableName() . '__oxfolder'} = new oxField($sFolder);
00372             $oObject->save();
00373         }
00374     }
00375 
00383     protected function _setupNavigation( $sNode )
00384     {
00385         // navigation according to class
00386         if ( $sNode ) {
00387 
00388             $myAdminNavig = $this->getNavigation();
00389 
00390             // default tab
00391             $this->_aViewData['default_edit'] = $myAdminNavig->getActiveTab( $sNode, $this->_iDefEdit );
00392 
00393             // buttons
00394             $this->_aViewData['bottom_buttons'] = $myAdminNavig->getBtn( $sNode );
00395         }
00396     }
00397 
00405     protected function _resetCounts( $aIds )
00406     {
00407         $oUtils = oxUtilsCount::getInstance();
00408         foreach ( $aIds as $sType => $aResetInfo ) {
00409             foreach ( $aResetInfo as $sResetId => $iPos ) {
00410                 switch ( $sType ) {
00411                     case 'vendor':
00412                         $this->resetCounter( "vendorArticle", $sResetId );
00413                         break;
00414                     case 'manufacturer':
00415                         $this->resetCounter( "manufacturerArticle", $sResetId );
00416                         break;
00417                 }
00418             }
00419         }
00420     }
00421 }