BxBaseSocialSharing.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 UnaCoreBaseRepresentation UNA Core Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * @see BxDolSocialSharing
  11. */
  12. class BxBaseSocialSharing extends BxDolSocialSharing
  13. {
  14. protected $_oTemplate;
  15. /**
  16. * Constructor
  17. */
  18. protected function __construct($oTemplate)
  19. {
  20. parent::__construct();
  21. $this->_oTemplate = $oTemplate ? $oTemplate : BxDolTemplate::getInstance();
  22. }
  23. public function getCode ($sContentId, $sModuleName, $sUrl, $sTitle, $aCustomVars = false)
  24. {
  25. // define markers for replacments
  26. $sLang = BxDolLanguages::getInstance()->getCurrentLanguage();
  27. $aMarkers = array (
  28. 'id' => $sContentId,
  29. 'module' => $sModuleName,
  30. 'url' => $sUrl,
  31. 'url_encoded' => rawurlencode($sUrl),
  32. 'lang' => $sLang,
  33. 'locale' => $this->_getLocaleFacebook($sLang),
  34. 'title' => $sTitle,
  35. 'title_encoded' => rawurlencode($sTitle),
  36. );
  37. if (!empty($aCustomVars) && is_array($aCustomVars))
  38. $aMarkers = array_merge($aMarkers, $aCustomVars);
  39. // alert
  40. $sOverrideOutput = null;
  41. $oAlert = new BxDolAlerts('system', 'social_sharing_display', '', '', array (
  42. 'buttons' => &$this->_aSocialButtons,
  43. 'markers' => &$aMarkers,
  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->_aSocialButtons))
  52. return '';
  53. // prepare buttons
  54. $aButtons = array();
  55. foreach ($this->_aSocialButtons as $aButton) {
  56. switch ($aButton['type']) {
  57. case 'html':
  58. $sButton = $this->_replaceMarkers($aButton['content'], $aMarkers);
  59. $sButton = $this->_oTemplate->parseHtmlByContent($sButton, array());
  60. break;
  61. case 'service':
  62. $a = @unserialize($aButton['content']);
  63. if (false === $a || !is_array($a))
  64. break;
  65. $a = $this->_replaceMarkers($a, $aMarkers);
  66. $sButton = BxDolService::call($a['module'], $a['method'], isset($a['params']) ? $a['params'] : array(), isset($a['class']) ? $a['class'] : 'Module');
  67. break;
  68. }
  69. if (!isset($sButton) || preg_match('/{[A-Za-z0-9_]+}/', $sButton)) // if not all markers are replaced skip it
  70. continue;
  71. $aButtons[] = array ('button' => $sButton, 'object' => $aButton['object']);
  72. }
  73. // output
  74. $aTemplateVars = array (
  75. 'bx_repeat:buttons' => $aButtons,
  76. );
  77. return $this->_oTemplate->parseHtmlByName('social_sharing.html', $aTemplateVars);
  78. }
  79. }
  80. /** @} */