OXID eShop CE  4.9.6
 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 {
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 
65  protected function _getTextEditor($iWidth, $iHeight, $oObject, $sField, $sStylesheet = null)
66  {
67  if ($this->_oEditor === null) {
68  $myConfig = $this->getConfig();
69 
70  // include the config file and editor class:
71  $sEditorPath = 'wysiwigpro';
72  $sEditorFile = getShopBasePath() . "core/" . $sEditorPath . '/wysiwygPro.class.php';
73 
74 
75  // setting loaded state
76  $this->_oEditor = false;
77 
78  if ($sEditorFile && file_exists($sEditorFile)) {
79  include_once $sEditorFile;
80 
81  // create a new instance of the wysiwygPro class:
82  $this->_oEditor = new wysiwygPro();
83 
84  if (oxRegistry::getConfig()->isSsl() && oxRegistry::getConfig()->getSslShopUrl()) {
85  $sEditorUrl = rtrim(oxRegistry::getConfig()->getSslShopUrl(), '/') . "/core/{$sEditorPath}/";
86  } else {
87  $sEditorUrl = rtrim(oxRegistry::getConfig()->getShopUrl(), '/') . "/core/{$sEditorPath}/";
88  }
89 
90  $this->_oEditor->editorURL = $sEditorUrl;
91  $this->_oEditor->urlFormat = 'preserve';
92 
93  // document & image directory:
94  $sPictureDir = $myConfig->getPictureDir(false) . 'wysiwigpro/';
95  $sPictureUrl = $myConfig->getPictureUrl(null, false) . 'wysiwigpro/';
96  $this->_oEditor->documentDir = $this->_oEditor->imageDir = $sPictureDir;
97  $this->_oEditor->documentURL = $this->_oEditor->imageURL = $sPictureUrl;
98 
99  // enabling upload
100  $this->_oEditor->upload = true;
101 
102  // setting empty value
103  $this->_oEditor->emptyValue = "<p>&nbsp;</p>";
104 
105  //#M432 enabling deleting files and folders
106  $this->_oEditor->deleteFiles = true;
107  $this->_oEditor->deleteFolders = true;
108 
109  // allowed image extensions
110  $this->_oEditor->allowedImageExtensions = '.jpg, .jpeg, .gif, .png';
111 
112  // allowed document extensions
113  $this->_oEditor->allowedDocExtensions = '.html, .htm, .pdf, .doc, .rtf, .txt, .xl, .xls, .ppt, .pps, ' .
114  '.zip, .tar, .swf, .wmv, .rm, .mov, .jpg, .jpeg, .gif, .png';
115 
116  // set name
117  $this->_oEditor->name = $sField;
118 
119  // set language file name
120  $oLang = oxRegistry::getLang();
121  $this->_oEditor->lang = $oLang->translateString('editor_language', $oLang->getTplLanguage());
122 
123  // set contents
124  if ($sEditObjectValue = $this->_getEditValue($oObject, $sField)) {
125  $this->_oEditor->value = $sEditObjectValue;
126  $this->_oEditor->encoding = $this->getConfig()->isUtf() ? 'UTF-8' : 'ISO-8859-15';
127  }
128 
129  // parse for styles and add them
130  $this->setAdminMode(false);
131  $sCSSPath = $myConfig->getResourcePath("{$sStylesheet}", false);
132  $sCSSUrl = $myConfig->getResourceUrl("{$sStylesheet}", false);
133 
134  $aCSSPaths = array();
135  $this->setAdminMode(true);
136 
137  if (is_file($sCSSPath)) {
138 
139  $aCSSPaths[] = $sCSSUrl;
140 
141  if (is_readable($sCSSPath)) {
142  $aCSS = @file($sCSSPath);
143  if (isset($aCSS) && $aCSS) {
144  $aClasses = array();
145  $oStr = getStr();
146  foreach ($aCSS as $key => $sLine) {
147  $sLine = trim($sLine);
148 
149  if ($sLine[0] == '.' && !$oStr->strstr($sLine, 'default')) {
150  // found one tag
151  $sTag = $oStr->substr($sLine, 1);
152  $iEnd = $oStr->strpos($sTag, ' ');
153  if (!isset($iEnd) || !$iEnd) {
154  $iEnd = $oStr->strpos($sTag, '\n');
155  }
156 
157  if ($sTag = $oStr->substr($sTag, 0, $iEnd)) {
158  $aClasses["span class='{$sTag}'"] = $sTag;
159  }
160  }
161  }
162  $this->_oEditor->stylesMenu = $aClasses;
163  }
164  }
165  }
166 
167  foreach ($aCSSPaths as $sCssPath) {
168  $this->_oEditor->addStylesheet($sCssPath);
169  }
170 
171  //while there is a bug in editor template filter we cannot use this feature
172  // loading template filter plugin
173  $this->_oEditor->loadPlugin('templateFilter');
174  $this->_oEditor->plugins['templateFilter']->protect('[{', '}]');
175  if ($myConfig->getConfigParam('bl_perfParseLongDescinSmarty')) {
176  $sCurrentHomeDir = '[{$oViewConf->getCurrentHomeDir()}]';
177  $this->_oEditor->plugins['templateFilter']->assign($sCurrentHomeDir, $myConfig->getShopURL());
178  // note: in "[{ $" the space is needed for this parameter not to override previous call.
179  // see assign fnc of templateFilter
180  $this->_oEditor->plugins['templateFilter']->assign($sCurrentHomeDir, $myConfig->getSSLShopURL());
181  }
182  }
183 
184  return $this->_oEditor;
185  }
186  }
187 
196  protected function _getEditValue($oObject, $sField)
197  {
198  $sEditObjectValue = '';
199  if ($oObject && $sField && isset($oObject->$sField)) {
200 
201  if ($oObject->$sField instanceof oxField) {
202  $sEditObjectValue = $oObject->$sField->getRawValue();
203  } else {
204  $sEditObjectValue = $oObject->$sField->value;
205  }
206 
207  $sEditObjectValue = $this->_processEditValue($sEditObjectValue);
208  $oObject->$sField = new oxField($sEditObjectValue, oxField::T_RAW);
209  }
210 
211  return $sEditObjectValue;
212  }
213 
221  protected function _processEditValue($sValue)
222  {
223  // A. replace ONLY if long description is not processed by smarty, or users will not be able to
224  // store smarty tags ([{$shop->currenthomedir}]/[{$oViewConf->getCurrentHomeDir()}]) in long
225  // descriptions, which are filled dynamically
226  if (!$this->getConfig()->getConfigParam('bl_perfParseLongDescinSmarty')) {
227  $aReplace = array('[{$shop->currenthomedir}]', '[{$oViewConf->getCurrentHomeDir()}]');
228  $sValue = str_replace($aReplace, $this->getConfig()->getCurrentShopURL(false), $sValue);
229  }
230 
231  return $sValue;
232  }
233 
244  protected function _getPlainEditor($iWidth, $iHeight, $oObject, $sField)
245  {
246  $sEditObjectValue = $this->_getEditValue($oObject, $sField);
247 
248  if (strpos($iWidth, '%') === false) {
249  $iWidth .= 'px';
250  }
251  if (strpos($iHeight, '%') === false) {
252  $iHeight .= 'px';
253  }
254 
255  return "<textarea id='editor_{$sField}' style='width:{$iWidth}; height:{$iHeight};'>{$sEditObjectValue}</textarea>";
256  }
257 
269  protected function _generateTextEditor($iWidth, $iHeight, $oObject, $sField, $sStylesheet = null)
270  {
271  // setup editor
272  if ($oEditor = $this->_getTextEditor($iWidth, $iHeight, $oObject, $sField, $sStylesheet)) {
273  // generate and return editor code
274  $sEditorHtml = $oEditor->fetch($iWidth, $iHeight);
275  } else {
276  $sEditorHtml = $this->_getPlainEditor($iWidth, $iHeight, $oObject, $sField);
277  }
278 
279  return $sEditorHtml;
280  }
281 
285  public function resetNrOfCatArticles()
286  {
287  // resetting categories article count cache
288  $this->resetContentCache();
289  }
290 
294  public function resetNrOfVendorArticles()
295  {
296  // resetting vendors cache
297  $this->resetContentCache();
298  }
299 
304  {
305  // resetting manufacturers cache
306  $this->resetContentCache();
307  }
308 
319  protected function _createCategoryTree($sTplVarName, $sEditCatId = '', $blForceNonCache = false, $iTreeShopId = null)
320  {
321  // caching category tree, to load it once, not many times
322  if (!isset($this->oCatTree) || $blForceNonCache) {
323  $this->oCatTree = oxNew('oxCategoryList');
324  $this->oCatTree->setShopID($iTreeShopId);
325 
326  // setting language
327  $oBase = $this->oCatTree->getBaseObject();
328  $oBase->setLanguage($this->_iEditLang);
329 
330  $this->oCatTree->loadList();
331  }
332 
333  // copying tree
334  $oCatTree = $this->oCatTree;
335  //removing current category
336  if ($sEditCatId && isset($oCatTree[$sEditCatId])) {
337  unset($oCatTree[$sEditCatId]);
338  }
339 
340  // add first fake category for not assigned articles
341  $oRoot = oxNew('oxcategory');
342  $oRoot->oxcategories__oxtitle = new oxField('--');
343 
344  $oCatTree->assign(array_merge(array('' => $oRoot), $oCatTree->getArray()));
345 
346  // passing to view
347  $this->_aViewData[$sTplVarName] = $oCatTree;
348 
349  return $oCatTree;
350  }
351 
364  protected function _getCategoryTree($sTplVarName, $sSelectedCatId, $sEditCatId = '', $blForceNonCache = false, $iTreeShopId = null)
365  {
366  $oCatTree = $this->_createCategoryTree($sTplVarName, $sEditCatId, $blForceNonCache, $iTreeShopId);
367 
368  // mark selected
369  if ($sSelectedCatId) {
370  // fixed parent category in select list
371  foreach ($oCatTree as $oCategory) {
372  if ($oCategory->getId() == $sSelectedCatId) {
373  $oCategory->selected = 1;
374  break;
375  }
376  }
377  } else {
378  // no category selected - opening first available
379  $oCatTree->rewind();
380  if ($oCat = $oCatTree->current()) {
381  $oCat->selected = 1;
382  $sSelectedCatId = $oCat->getId();
383  }
384  }
385 
386  // passing to view
387  $this->_aViewData[$sTplVarName] = $oCatTree;
388 
389  return $sSelectedCatId;
390  }
391 
395  public function changeFolder()
396  {
397  $sFolder = oxRegistry::getConfig()->getRequestParameter('setfolder');
398  $sFolderClass = oxRegistry::getConfig()->getRequestParameter('folderclass');
399 
400  if ($sFolderClass == 'oxcontent' && $sFolder == 'CMSFOLDER_NONE') {
401  $sFolder = '';
402  }
403 
404  $oObject = oxNew($sFolderClass);
405  if ($oObject->load($this->getEditObjectId())) {
406  $oObject->{$oObject->getCoreTableName() . '__oxfolder'} = new oxField($sFolder);
407  $oObject->save();
408  }
409  }
410 
416  protected function _setupNavigation($sNode)
417  {
418  // navigation according to class
419  if ($sNode) {
420 
421  $myAdminNavig = $this->getNavigation();
422 
423  // default tab
424  $this->_aViewData['default_edit'] = $myAdminNavig->getActiveTab($sNode, $this->_iDefEdit);
425 
426  // buttons
427  $this->_aViewData['bottom_buttons'] = $myAdminNavig->getBtn($sNode);
428  }
429  }
430 
436  protected function _resetCounts($aIds)
437  {
438  $oUtils = oxRegistry::get("oxUtilsCount");
439  foreach ($aIds as $sType => $aResetInfo) {
440  foreach ($aResetInfo as $sResetId => $iPos) {
441  switch ($sType) {
442  case 'vendor':
443  $this->resetCounter("vendorArticle", $sResetId);
444  break;
445  case 'manufacturer':
446  $this->resetCounter("manufacturerArticle", $sResetId);
447  break;
448  }
449  }
450  }
451  }
452 }