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                 // set language file name
00083                 $sEditorUrl = oxConfig::getInstance()->getConfigParam('sShopURL')."core/{$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 = "<p>&nbsp;</p>";
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 = oxRegistry::getLang();
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                 $sCSSPath = $myConfig->getResourcePath("{$sStylesheet}", false );
00126                 $sCSSUrl  = $myConfig->getResourceUrl("{$sStylesheet}", false );
00127 
00128                 $aCSSPaths = array();
00129                 $this->setAdminMode( true );
00130 
00131                 if (is_file($sCSSPath)) {
00132 
00133                     $aCSSPaths[] = $sCSSUrl;
00134 
00135                     if (is_readable($sCSSPath)) {
00136                         $aCSS = @file( $sCSSPath);
00137                         if ( isset( $aCSS) && $aCSS) {
00138                             $aClasses = array();
00139                             $oStr = getStr();
00140                             foreach ( $aCSS as $key => $sLine ) {
00141                                 $sLine = trim($sLine);
00142 
00143                                 if ( $sLine[0] == '.' && !$oStr->strstr( $sLine, 'default' ) ) {
00144                                     // found one tag
00145                                     $sTag = $oStr->substr( $sLine, 1);
00146                                     $iEnd = $oStr->strpos( $sTag, ' ' );
00147                                     if ( !isset( $iEnd ) || !$iEnd ) {
00148                                         $iEnd = $oStr->strpos( $sTag, '\n' );
00149                                     }
00150 
00151                                     if ( $sTag = $oStr->substr( $sTag, 0, $iEnd ) ) {
00152                                         $aClasses["span class='{$sTag}'"] = $sTag;
00153                                     }
00154                                 }
00155                             }
00156                             $this->_oEditor->stylesMenu = $aClasses;
00157                         }
00158                     }
00159                 }
00160 
00161                 foreach ( $aCSSPaths as $sCssPath ) {
00162                     $this->_oEditor->addStylesheet( $sCssPath );
00163                 }
00164 
00165                 //while there is a bug in editor template filter we cannot use this feature
00166                 // loading template filter plugin
00167                 $this->_oEditor->loadPlugin( 'templateFilter' );
00168                 $this->_oEditor->plugins['templateFilter']->protect( '[{', '}]' );
00169                 if ( $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
00170                     $this->_oEditor->plugins['templateFilter']->assign( '[{$oViewConf->getCurrentHomeDir()}]', $myConfig->getShopURL() );
00171                     // note: in "[{ $" the space is needed for this parameter not to override previous call. see assign fnc of templateFilter
00172                     $this->_oEditor->plugins['templateFilter']->assign( '[{ $oViewConf->getCurrentHomeDir()}]', $myConfig->getSSLShopURL() );
00173                 }
00174             }
00175 
00176             return $this->_oEditor;
00177         }
00178     }
00179 
00188     protected function _getEditValue( $oObject, $sField )
00189     {
00190         $sEditObjectValue = '';
00191         if ( $oObject && $sField && isset( $oObject->$sField ) ) {
00192 
00193             if ( $oObject->$sField instanceof oxField ) {
00194                 $sEditObjectValue = $oObject->$sField->getRawValue();
00195             } else {
00196                 $sEditObjectValue = $oObject->$sField->value;
00197             }
00198 
00199             $sEditObjectValue = $this->_processEditValue( $sEditObjectValue );
00200             $oObject->$sField = new oxField( $sEditObjectValue, oxField::T_RAW );
00201         }
00202 
00203         return $sEditObjectValue;
00204     }
00205 
00213     protected function _processEditValue( $sValue )
00214     {
00215         // A. replace ONLY if long description is not processed by smarty, or users will not be able to
00216         // store smarty tags ([{$shop->currenthomedir}]/[{$oViewConf->getCurrentHomeDir()}]) in long
00217         // descriptions, which are filled dynamically
00218         if ( !$this->getConfig()->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
00219             $aReplace = array( '[{$shop->currenthomedir}]', '[{$oViewConf->getCurrentHomeDir()}]' );
00220             $sValue = str_replace( $aReplace, $this->getConfig()->getCurrentShopURL(false), $sValue );
00221         }
00222         return $sValue;
00223     }
00224 
00235     protected function _getPlainEditor( $iWidth, $iHeight, $oObject, $sField )
00236     {
00237         $sEditObjectValue = $this->_getEditValue( $oObject, $sField );
00238 
00239         if ( strpos( $iWidth, '%' ) === false ) {
00240             $iWidth .= 'px';
00241         }
00242         if ( strpos( $iHeight, '%' ) === false ) {
00243             $iHeight .= 'px';
00244         }
00245         return "<textarea id='editor_{$sField}' style='width:{$iWidth}; height:{$iHeight};'>{$sEditObjectValue}</textarea>";
00246     }
00247 
00259     protected function _generateTextEditor( $iWidth, $iHeight, $oObject, $sField, $sStylesheet = null )
00260     {
00261         // setup editor
00262         if ( $oEditor = $this->_getTextEditor( $iWidth, $iHeight, $oObject, $sField, $sStylesheet ) ) {
00263             // generate and return editor code
00264             $sEditorHtml = $oEditor->fetch( $iWidth, $iHeight );
00265         } else {
00266             $sEditorHtml = $this->_getPlainEditor( $iWidth, $iHeight, $oObject, $sField );
00267         }
00268 
00269         return $sEditorHtml;
00270     }
00271 
00277     public function resetNrOfCatArticles()
00278     {
00279         // resetting categories article count cache
00280         $this->resetContentCache();
00281     }
00282 
00288     public function resetNrOfVendorArticles()
00289     {
00290         // resetting vendors cache
00291         $this->resetContentCache();
00292     }
00293 
00299     public function resetNrOfManufacturerArticles()
00300     {
00301         // resetting manufacturers cache
00302         $this->resetContentCache();
00303     }
00304 
00315     protected function _createCategoryTree( $sTplVarName, $sEditCatId = '', $blForceNonCache = false, $iTreeShopId = null )
00316     {
00317         // caching category tree, to load it once, not many times
00318         if ( !isset( $this->oCatTree ) || $blForceNonCache ) {
00319             $this->oCatTree = oxNew( 'oxCategoryList' );
00320             $this->oCatTree->setShopID( $iTreeShopId );
00321 
00322             // setting language
00323             $oBase = $this->oCatTree->getBaseObject();
00324             $oBase->setLanguage( $this->_iEditLang );
00325 
00326             $this->oCatTree->loadList();
00327         }
00328 
00329         // copying tree
00330         $oCatTree = $this->oCatTree;
00331         //removing current category
00332         if ( $sEditCatId && isset( $oCatTree[$sEditCatId] ) ) {
00333             unset( $oCatTree[$sEditCatId] );
00334         }
00335 
00336         // add first fake category for not assigned articles
00337         $oRoot = oxNew( 'oxcategory' );
00338         $oRoot->oxcategories__oxtitle = new oxField('--');
00339 
00340         $oCatTree->assign( array_merge( array( '' => $oRoot ), $oCatTree->getArray() ) );
00341 
00342         // passing to view
00343         $this->_aViewData[$sTplVarName] = $oCatTree;
00344 
00345         return $oCatTree;
00346     }
00347 
00360     protected function _getCategoryTree( $sTplVarName, $sSelectedCatId, $sEditCatId = '', $blForceNonCache = false, $iTreeShopId = null )
00361     {
00362         $oCatTree = $this->_createCategoryTree($sTplVarName, $sEditCatId, $blForceNonCache, $iTreeShopId);
00363 
00364         // mark selected
00365         if ( $sSelectedCatId ) {
00366             // fixed parent category in select list
00367             foreach ($oCatTree as $oCategory) {
00368                 if ($oCategory->getId() == $sSelectedCatId ) {
00369                     $oCategory->selected = 1;
00370                     break;
00371                 }
00372             }
00373         } else {
00374             // no category selected - opening first available
00375             $oCatTree->rewind();
00376             if ( $oCat = $oCatTree->current() ) {
00377                 $oCat->selected = 1;
00378                 $sSelectedCatId = $oCat->getId();
00379             }
00380         }
00381 
00382         // passing to view
00383         $this->_aViewData[$sTplVarName] =  $oCatTree;
00384 
00385         return $sSelectedCatId;
00386     }
00387 
00393     public function changeFolder()
00394     {
00395         $sFolder = oxConfig::getParameter( 'setfolder' );
00396         $sFolderClass = oxConfig::getParameter( 'folderclass' );
00397 
00398         if ( $sFolderClass == 'oxcontent' && $sFolder == 'CMSFOLDER_NONE' ) {
00399             $sFolder = '';
00400         }
00401 
00402         $oObject = oxNew( $sFolderClass );
00403         if ( $oObject->load( $this->getEditObjectId() ) ) {
00404             $oObject->{$oObject->getCoreTableName() . '__oxfolder'} = new oxField($sFolder);
00405             $oObject->save();
00406         }
00407     }
00408 
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 
00438     protected function _resetCounts( $aIds )
00439     {
00440         $oUtils = oxRegistry::get("oxUtilsCount");
00441         foreach ( $aIds as $sType => $aResetInfo ) {
00442             foreach ( $aResetInfo as $sResetId => $iPos ) {
00443                 switch ( $sType ) {
00444                     case 'vendor':
00445                         $this->resetCounter( "vendorArticle", $sResetId );
00446                         break;
00447                     case 'manufacturer':
00448                         $this->resetCounter( "manufacturerArticle", $sResetId );
00449                         break;
00450                 }
00451             }
00452         }
00453     }
00454 }