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