BxBaseSocialSharing.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolSocialSharing');
  10. /**
  11. * @see BxDolSocialSharing
  12. */
  13. class BxBaseSocialSharing extends BxDolSocialSharing
  14. {
  15. protected $_oTemplate;
  16. /**
  17. * Constructor
  18. */
  19. protected function __construct($oTemplate)
  20. {
  21. parent::__construct();
  22. $this->_oTemplate = $oTemplate ? $oTemplate : BxDolTemplate::getInstance();
  23. }
  24. public function getCode ($sContentId, $sModuleName, $sUrl, $sTitle, $aCustomVars = false)
  25. {
  26. // define markers for replacments
  27. bx_import('BxDolLanguages');
  28. $sLang = BxDolLanguages::getInstance()->getCurrentLanguage();
  29. $aMarkers = array (
  30. 'id' => $sContentId,
  31. 'module' => $sModuleName,
  32. 'url' => $sUrl,
  33. 'url_encoded' => rawurlencode($sUrl),
  34. 'lang' => $sLang,
  35. 'locale' => $this->_getLocaleFacebook($sLang),
  36. 'title' => $sTitle,
  37. 'title_encoded' => rawurlencode($sTitle),
  38. );
  39. if (!empty($aCustomVars) && is_array($aCustomVars))
  40. $aMarkers = array_merge($aMarkers, $aCustomVars);
  41. // alert
  42. $sOverrideOutput = null;
  43. bx_import('BxDolAlerts');
  44. $oAlert = new BxDolAlerts('system', 'social_sharing_display', '', '', array (
  45. 'buttons' => &$this->_aSocialButtons,
  46. 'markers' => &$aMarkers,
  47. 'override_output' => &$sOverrideOutput,
  48. ));
  49. $oAlert->alert();
  50. // return custom code if there is one
  51. if ($sOverrideOutput)
  52. return $sOverrideOutput;
  53. // return empty string of there is no buttons
  54. if (empty($this->_aSocialButtons))
  55. return '';
  56. // prepare buttons
  57. $aButtons = array();
  58. foreach ($this->_aSocialButtons as $aButton) {
  59. switch ($aButton['type']) {
  60. case 'html':
  61. $sButton = $this->_replaceMarkers($aButton['content'], $aMarkers);
  62. break;
  63. case 'service':
  64. $a = @unserialize($aButton['content']);
  65. if (false === $a || !is_array($a))
  66. break;
  67. $a = $this->_replaceMarkers($a, $aMarkers);
  68. $sButton = BxDolService::call($a['module'], $a['method'], isset($a['params']) ? $a['params'] : array(), isset($a['class']) ? $a['class'] : 'Module');
  69. break;
  70. }
  71. if (!isset($sButton) || preg_match('/{[A-Za-z0-9_]+}/', $sButton)) // if not all markers are replaced skip it
  72. continue;
  73. $aButtons[] = array ('button' => $sButton, 'object' => $aButton['object']);
  74. }
  75. // output
  76. $aTemplateVars = array (
  77. 'bx_repeat:buttons' => $aButtons,
  78. );
  79. return $this->_oTemplate->parseHtmlByName('social_sharing.html', $aTemplateVars);
  80. }
  81. }
  82. /** @} */