BxBaseSocialSharing.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. parent::__construct();
  21. $this->_oTemplate = $oTemplate ? $oTemplate : BxDolTemplate::getInstance();
  22. }
  23. public function getCode ($sContentId, $sModuleName, $sUrl, $sTitle, $aCustomVars = false) {
  24. // define markers for replacments
  25. bx_import('BxDolLanguages');
  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. bx_import('BxDolAlerts');
  42. $oAlert = new BxDolAlerts('system', 'social_sharing_display', '', '', array (
  43. 'buttons' => &$this->_aSocialButtons,
  44. 'markers' => &$aMarkers,
  45. 'override_output' => &$sOverrideOutput,
  46. ));
  47. $oAlert->alert();
  48. // return custom code if there is one
  49. if ($sOverrideOutput)
  50. return $sOverrideOutput;
  51. // return empty string of there is no buttons
  52. if (empty($this->_aSocialButtons))
  53. return '';
  54. // prepare buttons
  55. $aButtons = array();
  56. foreach ($this->_aSocialButtons as $aButton) {
  57. switch ($aButton['type']) {
  58. case 'html':
  59. $sButton = $this->_replaceMarkers($aButton['content'], $aMarkers);
  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);
  72. }
  73. // output
  74. $aTemplateVars = array (
  75. 'bx_repeat:buttons' => $aButtons,
  76. );
  77. return $this->_oTemplate->parseHtmlByName('social_sharing.html', $aTemplateVars);
  78. }
  79. }
  80. /** @} */