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