| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaCoreBaseRepresentation UNA Core Base Representation Classes
- * @{
- */
- /**
- * @see BxDolSocialSharing
- */
- class BxBaseSocialSharing extends BxDolSocialSharing
- {
- protected $_oTemplate;
- /**
- * Constructor
- */
- protected function __construct($oTemplate)
- {
- parent::__construct();
- $this->_oTemplate = $oTemplate ? $oTemplate : BxDolTemplate::getInstance();
- }
- public function getCode ($sContentId, $sModuleName, $sUrl, $sTitle, $aCustomVars = false)
- {
- // define markers for replacments
- $sLang = BxDolLanguages::getInstance()->getCurrentLanguage();
- $aMarkers = array (
- 'id' => $sContentId,
- 'module' => $sModuleName,
- 'url' => $sUrl,
- 'url_encoded' => rawurlencode($sUrl),
- 'lang' => $sLang,
- 'locale' => $this->_getLocaleFacebook($sLang),
- 'title' => $sTitle,
- 'title_encoded' => rawurlencode($sTitle),
- );
- if (!empty($aCustomVars) && is_array($aCustomVars))
- $aMarkers = array_merge($aMarkers, $aCustomVars);
- // alert
- $sOverrideOutput = null;
- $oAlert = new BxDolAlerts('system', 'social_sharing_display', '', '', array (
- 'buttons' => &$this->_aSocialButtons,
- 'markers' => &$aMarkers,
- 'override_output' => &$sOverrideOutput,
- ));
- $oAlert->alert();
- // return custom code if there is one
- if ($sOverrideOutput)
- return $sOverrideOutput;
- // return empty string of there is no buttons
- if (empty($this->_aSocialButtons))
- return '';
- // prepare buttons
- $aButtons = array();
- foreach ($this->_aSocialButtons as $aButton) {
- switch ($aButton['type']) {
- case 'html':
- $sButton = $this->_replaceMarkers($aButton['content'], $aMarkers);
- $sButton = $this->_oTemplate->parseHtmlByContent($sButton, array());
- break;
- case 'service':
- $a = @unserialize($aButton['content']);
- if (false === $a || !is_array($a))
- break;
- $a = $this->_replaceMarkers($a, $aMarkers);
- $sButton = BxDolService::call($a['module'], $a['method'], isset($a['params']) ? $a['params'] : array(), isset($a['class']) ? $a['class'] : 'Module');
- break;
- }
- if (!isset($sButton) || preg_match('/{[A-Za-z0-9_]+}/', $sButton)) // if not all markers are replaced skip it
- continue;
- $aButtons[] = array ('button' => $sButton, 'object' => $aButton['object']);
- }
- // output
- $aTemplateVars = array (
- 'bx_repeat:buttons' => $aButtons,
- );
- return $this->_oTemplate->parseHtmlByName('social_sharing.html', $aTemplateVars);
- }
- }
- /** @} */
|