OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
content.php
Go to the documentation of this file.
1 <?php
2 
6 class Content extends oxUBase
7 {
12  protected $_sContentId = null;
13 
18  protected $_oContent = null;
19 
24  protected $_sThisTemplate = 'page/info/content.tpl';
25 
30  protected $_sThisPlainTemplate = 'page/info/content_plain.tpl';
31 
36  protected $_oContentCat = null;
37 
42  protected $_aPsAllowedContents = array( "oxagb", "oxrightofwithdrawal", "oximpressum" );
43 
48  protected $_sContentTitle = null;
49 
54  protected $_blBargainAction = true;
55 
60  protected $_sBusinessTemplate = 'rdfa/content/inc/business_entity.tpl';
61 
66  protected $_sDeliveryTemplate = 'rdfa/content/inc/delivery_charge.tpl';
67 
72  protected $_sPaymentTemplate = 'rdfa/content/inc/payment_charge.tpl';
73 
80  protected $_aBusinessEntityExtends = array( "sRDFaLogoUrl",
81  "sRDFaLongitude",
82  "sRDFaLatitude",
83  "sRDFaGLN",
84  "sRDFaNAICS",
85  "sRDFaISIC",
86  "sRDFaDUNS");
87 
93  public function getViewId()
94  {
95  if ( !isset( $this->_sViewId ) ) {
96  $this->_sViewId = parent::getViewId().'|'.oxConfig::getParameter( 'oxcid' );
97  }
98  return $this->_sViewId;
99  }
100 
108  public function render()
109  {
110  parent::render();
111 
112  $oContent = $this->getContent();
113  if ( $oContent && !$this->_canShowContent( $oContent->oxcontents__oxloadid->value ) ) {
114  oxRegistry::getUtils()->redirect( $this->getConfig()->getShopHomeURL() . 'cl=account' );
115  }
116 
117  $sTpl = false;
118  if ( $sTplName = $this->_getTplName() ) {
119  $this->_sThisTemplate = $sTpl = $sTplName;
120  } elseif ( $oContent ) {
121  $sTpl = $oContent->getId();
122  }
123 
124  if ( !$sTpl ) {
125  error_404_handler();
126  }
127 
128  // sometimes you need to display plain templates (e.g. when showing popups)
129  if ( $this->showPlainTemplate() ) {
130  $this->_sThisTemplate = $this->_sThisPlainTemplate;
131  }
132 
133  if ( $oContent ) {
134  $this->getViewConfig()->setViewConfigParam( 'oxloadid', $oContent->getLoadId() );
135  }
136 
137  return $this->_sThisTemplate;
138  }
139 
147  protected function _canShowContent( $sContentIdent )
148  {
149  $blCan = true;
150  if ( $this->isEnabledPrivateSales() &&
151  !$this->getUser() && !in_array( $sContentIdent, $this->_aPsAllowedContents ) ) {
152  $blCan = false;
153  }
154  return $blCan;
155  }
156 
167  protected function _prepareMetaDescription( $sMeta, $iLength = 200, $blDescTag = false )
168  {
169  if ( !$sMeta ) {
170  $sMeta = $this->getContent()->oxcontents__oxtitle->value;
171  }
172  return parent::_prepareMetaDescription( $sMeta, $iLength, $blDescTag );
173  }
174 
184  protected function _prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords = true )
185  {
186  if ( !$sKeywords ) {
187  $sKeywords = $this->getContent()->oxcontents__oxtitle->value;
188  }
189  return parent::_prepareMetaKeyword( $sKeywords, $blRemoveDuplicatedWords );
190  }
191 
197  public function getContentCategory()
198  {
199  if ( $this->_oContentCat === null ) {
200  // setting default status ..
201  $this->_oContentCat = false;
202  if ( ( $oContent = $this->getContent() ) && $oContent->oxcontents__oxtype->value == 2 ) {
203  $this->_oContentCat = $oContent;
204  }
205  }
206  return $this->_oContentCat;
207  }
208 
215  public function showPlainTemplate()
216  {
217  $blPlain = (bool) oxConfig::getParameter( 'plain' );
218  if ( $blPlain === false ) {
219  $oUser = $this->getUser();
220  if ( $this->isEnabledPrivateSales() &&
221  ( !$oUser || ( $oUser && !$oUser->isTermsAccepted() ) ) ) {
222  $blPlain = true;
223  }
224  }
225 
226  return (bool) $blPlain;
227  }
228 
234  protected function _getSeoObjectId()
235  {
236  return oxConfig::getParameter( 'oxcid' );
237  }
238 
245  public function getContentId()
246  {
247  if ( $this->_sContentId === null ) {
248 
249  $sContentId = oxConfig::getParameter( 'oxcid' );
250  $sLoadId = oxConfig::getParameter( 'oxloadid' );
251 
252  $this->_sContentId = false;
253  $oContent = oxNew( 'oxContent' );
254  $blRes = false;
255 
256  if ( $sLoadId ) {
257  $blRes = $oContent->loadByIdent( $sLoadId );
258  } elseif ( $sContentId ) {
259  $blRes = $oContent->load( $sContentId );
260  } else {
261  //get default content (impressum)
262  $blRes = $oContent->loadByIdent( 'oximpressum' );
263  }
264 
265  if ( $blRes && $oContent->oxcontents__oxactive->value ) {
266  $this->_sContentId = $oContent->oxcontents__oxid->value;
267  $this->_oContent = $oContent;
268  }
269  }
270 
271  return $this->_sContentId;
272  }
273 
279  public function getContent()
280  {
281  if ( $this->_oContent === null ) {
282  $this->_oContent = false;
283  if ( $this->getContentId() ) {
284  return $this->_oContent;
285  }
286  }
287  return $this->_oContent;
288  }
289 
298  protected function _getSubject( $iLang )
299  {
300  return $this->getContent();
301  }
302 
308  protected function _getTplName()
309  {
310  // assign template name
311  $sTplName = oxConfig::getParameter( 'tpl');
312 
313  if ( $sTplName ) {
314  // security fix so that you cant access files from outside template dir
315  $sTplName = basename( $sTplName );
316 
317  //checking if it is template name, not content id
318  if ( !getStr()->preg_match("/\.tpl$/", $sTplName) ) {
319  $sTplName = null;
320  } else {
321  $sTplName = 'message/'.$sTplName;
322  }
323  }
324 
325  return $sTplName;
326  }
327 
333  public function getBreadCrumb()
334  {
335  $oContent = $this->getContent();
336 
337  $aPaths = array();
338  $aPath = array();
339 
340  $aPath['title'] = $oContent->oxcontents__oxtitle->value;
341  $aPath['link'] = $this->getLink();
342  $aPaths[] = $aPath;
343 
344  return $aPaths;
345  }
346 
352  public function getTitle()
353  {
354  if ( $this->_sContentTitle === null ) {
355  $oContent = $this->getContent();
356  $this->_sContentTitle = $oContent->oxcontents__oxtitle->value;
357  }
358 
359  return $this->_sContentTitle;
360  }
361 
367  public function showRdfa()
368  {
369  return $this->getConfig()->getConfigParam( 'blRDFaEmbedding' );
370  }
371 
378  public function getContentPageTpl()
379  {
380  $aTemplate = array();
381  $sContentId = $this->getContent()->oxcontents__oxloadid->value;
382  $myConfig = $this->getConfig();
383  if ( $sContentId == $myConfig->getConfigParam( 'sRDFaBusinessEntityLoc' )) {
384  $aTemplate[] = $this->_sBusinessTemplate;
385  }
386  if ( $sContentId == $myConfig->getConfigParam( 'sRDFaDeliveryChargeSpecLoc' )) {
387  $aTemplate[] = $this->_sDeliveryTemplate;
388  }
389  if ( $sContentId == $myConfig->getConfigParam( 'sRDFaPaymentChargeSpecLoc' )) {
390  $aTemplate[] = $this->_sPaymentTemplate;
391  }
392  return $aTemplate;
393  }
394 
400  public function getBusinessEntityExtends()
401  {
402  $myConfig = $this->getConfig();
403  $aExtends = array();
404 
405  foreach ( $this->_aBusinessEntityExtends as $sExtend ) {
406  $aExtends[$sExtend] = $myConfig->getConfigParam($sExtend);
407  }
408 
409  return $aExtends;
410  }
411 
419  public function getNotMappedToRDFaPayments()
420  {
421  $oPayments = oxNew("oxPaymentList");
422  $oPayments->loadNonRDFaPaymentList();
423  return $oPayments;
424  }
425 
434  {
435  $oDelSets = oxNew("oxDeliverySetList");
436  $oDelSets->loadNonRDFaDeliverySetList();
437  return $oDelSets;
438  }
439 
445  public function getDeliveryChargeSpecs()
446  {
447  $aDeliveryChargeSpecs = array();
448  $oDeliveryChargeSpecs = $this->getDeliveryList();
449  foreach ($oDeliveryChargeSpecs as $oDeliveryChargeSpec) {
450  if ($oDeliveryChargeSpec->oxdelivery__oxaddsumtype->value == "abs") {
451  $oDelSets = oxNew("oxdeliverysetlist");
452  $oDelSets->loadRDFaDeliverySetList($oDeliveryChargeSpec->getId());
453  $oDeliveryChargeSpec->deliverysetmethods = $oDelSets;
454  $aDeliveryChargeSpecs[] = $oDeliveryChargeSpec;
455  }
456  }
457  return $aDeliveryChargeSpecs;
458  }
459 
465  public function getDeliveryList()
466  {
467  if ( $this->_oDelList === null ) {
468  $this->_oDelList = oxNew( 'oxDeliveryList' );
469  $this->_oDelList->getList();
470  }
471  return $this->_oDelList;
472  }
473 
479  public function getRdfaVAT()
480  {
481  return $this->getConfig()->getConfigParam( 'iRDFaVAT' );
482  }
483 
489  public function getRdfaPriceValidity()
490  {
491  $iDays = $this->getConfig()->getConfigParam( 'iRDFaPriceValidity' );
492  $iFrom = oxRegistry::get("oxUtilsDate")->getTime();
493  $iThrough = $iFrom + ($iDays * 24 * 60 * 60);
494  $oPriceValidity = array();
495  $oPriceValidity['validfrom'] = date('Y-m-d\TH:i:s', $iFrom)."Z";
496  $oPriceValidity['validthrough'] = date('Y-m-d\TH:i:s', $iThrough)."Z";
497  return $oPriceValidity;
498  }
499 
505  public function getParsedContent()
506  {
508  $oUtilsView = oxRegistry::get("oxUtilsView");
509  return $oUtilsView->parseThroughSmarty( $this->getContent()->oxcontents__oxcontent->value, $this->getContent()->getId(), null, true );
510  }
511 
512 }