BxBaseSocialSharing.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 TridentCore Trident Core
  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. break;
  60. case 'service':
  61. $a = @unserialize($aButton['content']);
  62. if (false === $a || !is_array($a))
  63. break;
  64. $a = $this->_replaceMarkers($a, $aMarkers);
  65. $sButton = BxDolService::call($a['module'], $a['method'], isset($a['params']) ? $a['params'] : array(), isset($a['class']) ? $a['class'] : 'Module');
  66. break;
  67. }
  68. if (!isset($sButton) || preg_match('/{[A-Za-z0-9_]+}/', $sButton)) // if not all markers are replaced skip it
  69. continue;
  70. $aButtons[] = array ('button' => $sButton, 'object' => $aButton['object']);
  71. }
  72. // output
  73. $aTemplateVars = array (
  74. 'bx_repeat:buttons' => $aButtons,
  75. );
  76. return $this->_oTemplate->parseHtmlByName('social_sharing.html', $aTemplateVars);
  77. }
  78. }
  79. /** @} */