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