OXID eShop CE  4.9.6
 All Classes Files Functions Variables Pages
content_main.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
17  public function render()
18  {
19  $myConfig = $this->getConfig();
20 
22 
23  $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
24 
25  // categorie tree
26  $oCatTree = oxNew("oxCategoryList");
27  $oCatTree->loadList();
28 
29  $oContent = oxNew("oxcontent");
30  if ($soxId != "-1" && isset($soxId)) {
31  // load object
32  $oContent->loadInLang($this->_iEditLang, $soxId);
33 
34  $oOtherLang = $oContent->getAvailableInLangs();
35  if (!isset($oOtherLang[$this->_iEditLang])) {
36  // echo "language entry doesn't exist! using: ".key($oOtherLang);
37  $oContent->loadInLang(key($oOtherLang), $soxId);
38  }
39 
40  // remove already created languages
41  $aLang = array_diff(oxRegistry::getLang()->getLanguageNames(), $oOtherLang);
42  if (count($aLang)) {
43  $this->_aViewData["posslang"] = $aLang;
44  }
45  foreach ($oOtherLang as $id => $language) {
46  $oLang = new stdClass();
47  $oLang->sLangDesc = $language;
48  $oLang->selected = ($id == $this->_iEditLang);
49  $this->_aViewData["otherlang"][$id] = clone $oLang;
50  }
51  // mark selected
52  if ($oContent->oxcontents__oxcatid->value && isset($oCatTree[$oContent->oxcontents__oxcatid->value])) {
53  $oCatTree[$oContent->oxcontents__oxcatid->value]->selected = 1;
54  }
55 
56  } else {
57  // create ident to make life easier
58  $sUId = oxUtilsObject::getInstance()->generateUId();
59  $oContent->oxcontents__oxloadid = new oxField($sUId);
60  }
61 
62  $this->_aViewData["edit"] = $oContent;
63  $this->_aViewData["link"] = "[{ oxgetseourl ident=&quot;" . $oContent->oxcontents__oxloadid->value . "&quot; type=&quot;oxcontent&quot; }]";
64  $this->_aViewData["cattree"] = $oCatTree;
65 
66  // generate editor
67  $sCSS = "content.tpl.css";
68  if ($oContent->oxcontents__oxsnippet->value == '1') {
69  $sCSS = null;
70  }
71 
72  $this->_aViewData["editor"] = $this->_generateTextEditor("100%", 300, $oContent, "oxcontents__oxcontent", $sCSS);
73  $this->_aViewData["afolder"] = $myConfig->getConfigParam('aCMSfolder');
74 
75  return "content_main.tpl";
76  }
77 
83  public function save()
84  {
85  parent::save();
86 
87  $myConfig = $this->getConfig();
88 
89  $soxId = $this->getEditObjectId();
90  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
91 
92  if (isset($aParams['oxcontents__oxloadid'])) {
93  $aParams['oxcontents__oxloadid'] = $this->_prepareIdent($aParams['oxcontents__oxloadid']);
94  }
95 
96  // check if loadid is unique
97  if ($this->_checkIdent($aParams['oxcontents__oxloadid'], $soxId)) {
98  // loadid already used, display error message
99  $this->_aViewData["blLoadError"] = true;
100 
101  $oContent = oxNew("oxcontent");
102  if ($soxId != '-1') {
103  $oContent->load($soxId);
104  }
105  $oContent->assign($aParams);
106  $this->_aViewData["edit"] = $oContent;
107 
108  return;
109  }
110 
111  // checkbox handling
112  if (!isset($aParams['oxcontents__oxactive'])) {
113  $aParams['oxcontents__oxactive'] = 0;
114  }
115 
116  // special treatment
117  if ($aParams['oxcontents__oxtype'] == 0) {
118  $aParams['oxcontents__oxsnippet'] = 1;
119  } else {
120  $aParams['oxcontents__oxsnippet'] = 0;
121  }
122 
123  //Updates object folder parameters
124  if ($aParams['oxcontents__oxfolder'] == 'CMSFOLDER_NONE') {
125  $aParams['oxcontents__oxfolder'] = '';
126  }
127 
128  // shopid
129  $sShopID = oxRegistry::getSession()->getVariable("actshop");
130  $aParams['oxcontents__oxshopid'] = $sShopID;
131  $oContent = oxNew("oxcontent");
132 
133  if ($soxId != "-1") {
134  $oContent->loadInLang($this->_iEditLang, $soxId);
135  } else {
136  $aParams['oxcontents__oxid'] = null;
137  }
138 
139  //$aParams = $oContent->ConvertNameArray2Idx( $aParams);
140 
141  $oContent->setLanguage(0);
142  $oContent->assign($aParams);
143  $oContent->setLanguage($this->_iEditLang);
144  $oContent->save();
145 
146  // set oxid if inserted
147  $this->setEditObjectId($oContent->getId());
148  }
149 
153  public function saveinnlang()
154  {
155  parent::save();
156 
157  $myConfig = $this->getConfig();
158 
159  $soxId = $this->getEditObjectId();
160  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
161 
162  if (isset($aParams['oxcontents__oxloadid'])) {
163  $aParams['oxcontents__oxloadid'] = $this->_prepareIdent($aParams['oxcontents__oxloadid']);
164  }
165 
166  // checkbox handling
167  if (!isset($aParams['oxcontents__oxactive'])) {
168  $aParams['oxcontents__oxactive'] = 0;
169  }
170 
171  // shopid
172  $sShopID = oxRegistry::getSession()->getVariable("actshop");
173  $aParams['oxcontents__oxshopid'] = $sShopID;
174 
175  $oContent = oxNew("oxcontent");
176 
177  if ($soxId != "-1") {
178  $oContent->loadInLang($this->_iEditLang, $soxId);
179  } else {
180  $aParams['oxcontents__oxid'] = null;
181  }
182 
183  $oContent->setLanguage(0);
184  $oContent->assign($aParams);
185 
186  // apply new language
187  $oContent->setLanguage(oxRegistry::getConfig()->getRequestParameter("new_lang"));
188  $oContent->save();
189 
190  // set oxid if inserted
191  $this->setEditObjectId($oContent->getId());
192  }
193 
201  protected function _prepareIdent($sIdent)
202  {
203  if ($sIdent) {
204  return getStr()->preg_replace("/[^a-zA-Z0-9_]*/", "", $sIdent);
205  }
206  }
207 
216  protected function _checkIdent($sIdent, $sOxId)
217  {
218  $blAllow = false;
219  $oDb = oxDb::getDb();
220  // null not allowed
221  if (!strlen($sIdent)) {
222  $blAllow = true;
223  } elseif ($oDb->getOne("select oxid from oxcontents where oxloadid = " . $oDb->quote($sIdent) . " and oxid != " . $oDb->quote($sOxId) . " and oxshopid = '" . $this->getConfig()->getShopId() . "'", false, false)) {
224  $blAllow = true;
225  }
226 
227  return $blAllow;
228  }
229 }