BxBaseMenuSocialSharing.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Menu for content social sharing
  11. */
  12. class BxBaseMenuSocialSharing extends BxTemplMenu
  13. {
  14. protected $_aNeedEncode = array(
  15. 'url' => 'url_encoded',
  16. 'title' => 'title_encoded',
  17. 'img_url' => 'img_url_encoded'
  18. );
  19. public function __construct ($aObject, $oTemplate)
  20. {
  21. parent::__construct ($aObject, $oTemplate);
  22. $sLang = BxDolLanguages::getInstance()->getCurrentLanguage();
  23. $this->addMarkers(array (
  24. 'lang' => $sLang,
  25. ));
  26. }
  27. public function addMarkers($a)
  28. {
  29. if(!empty($this->_aNeedEncode) && is_array($this->_aNeedEncode))
  30. foreach($this->_aNeedEncode as $sKey1 => $sKey2)
  31. if(array_key_exists($sKey1, $a))
  32. $a[$sKey2] = rawurlencode($a[$sKey1]);
  33. return parent::addMarkers($a);
  34. }
  35. public function getCode()
  36. {
  37. if (!isset($this->_aObject['menu_items']))
  38. $this->_aObject['menu_items'] = $this->getMenuItemsRaw();
  39. // alert
  40. $sOverrideOutput = null;
  41. $oAlert = new BxDolAlerts('system', 'social_sharing_display', '', '', array (
  42. 'markers' => &$this->_aMarkers,
  43. 'buttons' => &$this->_aObject['menu_items'],
  44. 'override_output' => &$sOverrideOutput,
  45. ));
  46. $oAlert->alert();
  47. // return custom code if there is one
  48. if ($sOverrideOutput)
  49. return $sOverrideOutput;
  50. //return empty string of there is no buttons
  51. if (empty($this->_aObject['menu_items']))
  52. return '';
  53. return parent::getCode();
  54. }
  55. }
  56. /** @} */