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