OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
oxadmindetails.php
Go to the documentation of this file.
1 <?php
2 
6 //require_once "oxajax.php";
7 
12 {
18  protected $_oEditor = null;
19 
25  public function render()
26  {
27  $sReturn = parent::render();
28  $oLang = oxRegistry::getLang();
29 
30  // generate help link
31  $myConfig = $this->getConfig();
32  $sDir = $myConfig->getConfigParam( 'sShopDir' ) . '/documentation/admin';
33  $iLang = 1;
34  $sAbbr = $oLang->getLanguageAbbr($oLang->getTplLanguage());
35  if ( $sAbbr == "de" ) {
36  $iLang = 0;
37  }
38  if ( is_dir( $sDir ) ) {
39  $sDir = $myConfig->getConfigParam( 'sShopURL' ) . 'documentation/admin';
40  } else {
41 
42  $oShop = $this->_getEditShop( oxSession::getVar( 'actshop' ) );
43  //$sDir = "http://docu.oxid-esales.com/PE/{$oShop->oxshops__oxversion->value}/" . $myConfig->getConfigParam( 'iAdminLanguage' ) . '/admin';
44  $sDir = "http://docu.oxid-esales.com/PE/{$oShop->oxshops__oxversion->value}/" . $iLang . '/admin';
45  }
46 
47  $this->_aViewData['sHelpURL'] = $sDir;
48 
49  return $sReturn;
50  }
51 
63  protected function _getTextEditor( $iWidth, $iHeight, $oObject, $sField, $sStylesheet = null )
64  {
65  if ( $this->_oEditor === null ) {
66  $myConfig = $this->getConfig();
67 
68  // include the config file and editor class:
69  $sEditorPath = 'wysiwigpro';
70  $sEditorFile = getShopBasePath()."core/".$sEditorPath . '/wysiwygPro.class.php';
71 
72 
73  // setting loaded state
74  $this->_oEditor = false;
75 
76  if ( $sEditorFile && file_exists( $sEditorFile ) ) {
77  include_once $sEditorFile;
78 
79  // create a new instance of the wysiwygPro class:
80  $this->_oEditor = new wysiwygPro();
81 
82  if (oxRegistry::getConfig()->isSsl() && oxRegistry::getConfig()->getSslShopUrl()) {
83  $sEditorUrl = rtrim(oxRegistry::getConfig()->getSslShopUrl(), '/') . "/core/{$sEditorPath}/";
84  } else {
85  $sEditorUrl = rtrim(oxRegistry::getConfig()->getShopUrl(), '/') . "/core/{$sEditorPath}/";
86  }
87 
88  $this->_oEditor->editorURL = $sEditorUrl;
89  $this->_oEditor->urlFormat = 'preserve';
90 
91  // document & image directory:
92  $this->_oEditor->documentDir = $this->_oEditor->imageDir = $myConfig->getPictureDir( false ).'wysiwigpro/';
93  $this->_oEditor->documentURL = $this->_oEditor->imageURL = $myConfig->getPictureUrl( null, false ).'wysiwigpro/';
94 
95  // enabling upload
96  $this->_oEditor->upload = true;
97 
98  // setting empty value
99  $this->_oEditor->emptyValue = "<p>&nbsp;</p>";
100 
101  //#M432 enabling deleting files and folders
102  $this->_oEditor->deleteFiles = true;
103  $this->_oEditor->deleteFolders = true;
104 
105  // allowed image extensions
106  $this->_oEditor->allowedImageExtensions = '.jpg, .jpeg, .gif, .png';
107 
108  // allowed document extensions
109  $this->_oEditor->allowedDocExtensions = '.html, .htm, .pdf, .doc, .rtf, .txt, .xl, .xls, .ppt, .pps, .zip, .tar, .swf, .wmv, .rm, .mov, .jpg, .jpeg, .gif, .png';
110 
111  // set name
112  $this->_oEditor->name = $sField;
113 
114  // set language file name
115  $oLang = oxRegistry::getLang();
116  $this->_oEditor->lang = $oLang->translateString( 'editor_language', $oLang->getTplLanguage() );
117 
118  // set contents
119  if ( $sEditObjectValue = $this->_getEditValue( $oObject, $sField ) ) {
120  $this->_oEditor->value = $sEditObjectValue;
121  $this->_oEditor->encoding = $this->getConfig()->isUtf() ? 'UTF-8': 'ISO-8859-15';
122  }
123 
124  // parse for styles and add them
125  $this->setAdminMode( false );
126  $sCSSPath = $myConfig->getResourcePath("{$sStylesheet}", false );
127  $sCSSUrl = $myConfig->getResourceUrl("{$sStylesheet}", false );
128 
129  $aCSSPaths = array();
130  $this->setAdminMode( true );
131 
132  if (is_file($sCSSPath)) {
133 
134  $aCSSPaths[] = $sCSSUrl;
135 
136  if (is_readable($sCSSPath)) {
137  $aCSS = @file( $sCSSPath);
138  if ( isset( $aCSS) && $aCSS) {
139  $aClasses = array();
140  $oStr = getStr();
141  foreach ( $aCSS as $key => $sLine ) {
142  $sLine = trim($sLine);
143 
144  if ( $sLine[0] == '.' && !$oStr->strstr( $sLine, 'default' ) ) {
145  // found one tag
146  $sTag = $oStr->substr( $sLine, 1);
147  $iEnd = $oStr->strpos( $sTag, ' ' );
148  if ( !isset( $iEnd ) || !$iEnd ) {
149  $iEnd = $oStr->strpos( $sTag, '\n' );
150  }
151 
152  if ( $sTag = $oStr->substr( $sTag, 0, $iEnd ) ) {
153  $aClasses["span class='{$sTag}'"] = $sTag;
154  }
155  }
156  }
157  $this->_oEditor->stylesMenu = $aClasses;
158  }
159  }
160  }
161 
162  foreach ( $aCSSPaths as $sCssPath ) {
163  $this->_oEditor->addStylesheet( $sCssPath );
164  }
165 
166  //while there is a bug in editor template filter we cannot use this feature
167  // loading template filter plugin
168  $this->_oEditor->loadPlugin( 'templateFilter' );
169  $this->_oEditor->plugins['templateFilter']->protect( '[{', '}]' );
170  if ( $myConfig->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
171  $this->_oEditor->plugins['templateFilter']->assign( '[{$oViewConf->getCurrentHomeDir()}]', $myConfig->getShopURL() );
172  // note: in "[{ $" the space is needed for this parameter not to override previous call. see assign fnc of templateFilter
173  $this->_oEditor->plugins['templateFilter']->assign( '[{ $oViewConf->getCurrentHomeDir()}]', $myConfig->getSSLShopURL() );
174  }
175  }
176 
177  return $this->_oEditor;
178  }
179  }
180 
189  protected function _getEditValue( $oObject, $sField )
190  {
191  $sEditObjectValue = '';
192  if ( $oObject && $sField && isset( $oObject->$sField ) ) {
193 
194  if ( $oObject->$sField instanceof oxField ) {
195  $sEditObjectValue = $oObject->$sField->getRawValue();
196  } else {
197  $sEditObjectValue = $oObject->$sField->value;
198  }
199 
200  $sEditObjectValue = $this->_processEditValue( $sEditObjectValue );
201  $oObject->$sField = new oxField( $sEditObjectValue, oxField::T_RAW );
202  }
203 
204  return $sEditObjectValue;
205  }
206 
214  protected function _processEditValue( $sValue )
215  {
216  // A. replace ONLY if long description is not processed by smarty, or users will not be able to
217  // store smarty tags ([{$shop->currenthomedir}]/[{$oViewConf->getCurrentHomeDir()}]) in long
218  // descriptions, which are filled dynamically
219  if ( !$this->getConfig()->getConfigParam( 'bl_perfParseLongDescinSmarty' ) ) {
220  $aReplace = array( '[{$shop->currenthomedir}]', '[{$oViewConf->getCurrentHomeDir()}]' );
221  $sValue = str_replace( $aReplace, $this->getConfig()->getCurrentShopURL(false), $sValue );
222  }
223  return $sValue;
224  }
225 
236  protected function _getPlainEditor( $iWidth, $iHeight, $oObject, $sField )
237  {
238  $sEditObjectValue = $this->_getEditValue( $oObject, $sField );
239 
240  if ( strpos( $iWidth, '%' ) === false ) {
241  $iWidth .= 'px';
242  }
243  if ( strpos( $iHeight, '%' ) === false ) {
244  $iHeight .= 'px';
245  }
246  return "<textarea id='editor_{$sField}' style='width:{$iWidth}; height:{$iHeight};'>{$sEditObjectValue}</textarea>";
247  }
248 
260  protected function _generateTextEditor( $iWidth, $iHeight, $oObject, $sField, $sStylesheet = null )
261  {
262  // setup editor
263  if ( $oEditor = $this->_getTextEditor( $iWidth, $iHeight, $oObject, $sField, $sStylesheet ) ) {
264  // generate and return editor code
265  $sEditorHtml = $oEditor->fetch( $iWidth, $iHeight );
266  } else {
267  $sEditorHtml = $this->_getPlainEditor( $iWidth, $iHeight, $oObject, $sField );
268  }
269 
270  return $sEditorHtml;
271  }
272 
278  public function resetNrOfCatArticles()
279  {
280  // resetting categories article count cache
281  $this->resetContentCache();
282  }
283 
289  public function resetNrOfVendorArticles()
290  {
291  // resetting vendors cache
292  $this->resetContentCache();
293  }
294 
301  {
302  // resetting manufacturers cache
303  $this->resetContentCache();
304  }
305 
316  protected function _createCategoryTree( $sTplVarName, $sEditCatId = '', $blForceNonCache = false, $iTreeShopId = null )
317  {
318  // caching category tree, to load it once, not many times
319  if ( !isset( $this->oCatTree ) || $blForceNonCache ) {
320  $this->oCatTree = oxNew( 'oxCategoryList' );
321  $this->oCatTree->setShopID( $iTreeShopId );
322 
323  // setting language
324  $oBase = $this->oCatTree->getBaseObject();
325  $oBase->setLanguage( $this->_iEditLang );
326 
327  $this->oCatTree->loadList();
328  }
329 
330  // copying tree
331  $oCatTree = $this->oCatTree;
332  //removing current category
333  if ( $sEditCatId && isset( $oCatTree[$sEditCatId] ) ) {
334  unset( $oCatTree[$sEditCatId] );
335  }
336 
337  // add first fake category for not assigned articles
338  $oRoot = oxNew( 'oxcategory' );
339  $oRoot->oxcategories__oxtitle = new oxField('--');
340 
341  $oCatTree->assign( array_merge( array( '' => $oRoot ), $oCatTree->getArray() ) );
342 
343  // passing to view
344  $this->_aViewData[$sTplVarName] = $oCatTree;
345 
346  return $oCatTree;
347  }
348 
361  protected function _getCategoryTree( $sTplVarName, $sSelectedCatId, $sEditCatId = '', $blForceNonCache = false, $iTreeShopId = null )
362  {
363  $oCatTree = $this->_createCategoryTree($sTplVarName, $sEditCatId, $blForceNonCache, $iTreeShopId);
364 
365  // mark selected
366  if ( $sSelectedCatId ) {
367  // fixed parent category in select list
368  foreach ($oCatTree as $oCategory) {
369  if ($oCategory->getId() == $sSelectedCatId ) {
370  $oCategory->selected = 1;
371  break;
372  }
373  }
374  } else {
375  // no category selected - opening first available
376  $oCatTree->rewind();
377  if ( $oCat = $oCatTree->current() ) {
378  $oCat->selected = 1;
379  $sSelectedCatId = $oCat->getId();
380  }
381  }
382 
383  // passing to view
384  $this->_aViewData[$sTplVarName] = $oCatTree;
385 
386  return $sSelectedCatId;
387  }
388 
394  public function changeFolder()
395  {
396  $sFolder = oxConfig::getParameter( 'setfolder' );
397  $sFolderClass = oxConfig::getParameter( 'folderclass' );
398 
399  if ( $sFolderClass == 'oxcontent' && $sFolder == 'CMSFOLDER_NONE' ) {
400  $sFolder = '';
401  }
402 
403  $oObject = oxNew( $sFolderClass );
404  if ( $oObject->load( $this->getEditObjectId() ) ) {
405  $oObject->{$oObject->getCoreTableName() . '__oxfolder'} = new oxField($sFolder);
406  $oObject->save();
407  }
408  }
409 
417  protected function _setupNavigation( $sNode )
418  {
419  // navigation according to class
420  if ( $sNode ) {
421 
422  $myAdminNavig = $this->getNavigation();
423 
424  // default tab
425  $this->_aViewData['default_edit'] = $myAdminNavig->getActiveTab( $sNode, $this->_iDefEdit );
426 
427  // buttons
428  $this->_aViewData['bottom_buttons'] = $myAdminNavig->getBtn( $sNode );
429  }
430  }
431 
439  protected function _resetCounts( $aIds )
440  {
441  $oUtils = oxRegistry::get("oxUtilsCount");
442  foreach ( $aIds as $sType => $aResetInfo ) {
443  foreach ( $aResetInfo as $sResetId => $iPos ) {
444  switch ( $sType ) {
445  case 'vendor':
446  $this->resetCounter( "vendorArticle", $sResetId );
447  break;
448  case 'manufacturer':
449  $this->resetCounter( "manufacturerArticle", $sResetId );
450  break;
451  }
452  }
453  }
454  }
455 }