Cheetah
ChBaseSocialSharing.php
Go to the documentation of this file.
1 <?php
2 
8 ch_import('ChWsbSocialSharing');
9 
14 {
18  protected function __construct()
19  {
20  parent::__construct();
21  }
22 
23  public function getCode ($sUrl, $sTitle, $aCustomVars = false)
24  {
25  $this->_addOpenGraphInfo($sTitle, isset($aCustomVars['img_url']) ? $aCustomVars['img_url'] : '');
26 
27  $aLang = ch_lang_info();
28 
29  // define markers for replacments
30  $aMarkers = array (
31  'url' => $sUrl,
32  'url_encoded' => rawurlencode($sUrl),
33  'lang' => $GLOBALS['sCurrentLanguage'],
34  'locale' => $this->_getLocaleFacebook($aLang['LanguageCountry']),
35  'twit' => _t('_sys_social_sharing_twit'),
36  'title' => $sTitle,
37  'title_encoded' => rawurlencode($sTitle),
38  );
39 
40  if (!empty($aCustomVars) && is_array($aCustomVars))
41  $aMarkers = array_merge($aMarkers, $aCustomVars);
42 
43  // alert
44  $sOverrideOutput = null;
45  ch_import('ChWsbAlerts');
46  $oAlert = new ChWsbAlerts('system', 'social_sharing_display', '', '', array (
47  'buttons' => &$this->_aSocialButtons,
48  'markers' => &$aMarkers,
49  'override_output' => &$sOverrideOutput,
50  ));
51  $oAlert->alert();
52 
53  // return custom code if there is one
54  if ($sOverrideOutput)
55  return $sOverrideOutput;
56 
57  // return empty string of there is no buttons
58  if (empty($this->_aSocialButtons))
59  return '';
60 
61  // prepare buttons
62  $aButtons = array();
63  foreach ($this->_aSocialButtons as $aButton) {
64  $sButton = $this->_replaceMarkers($aButton['content'], $aMarkers);
65  if (preg_match('/{[A-Za-z0-9_]+}/', $sButton)) // if not all markers are replaced skip it
66  continue;
67  $aButtons[] = array ('button' => $sButton);
68  }
69 
70  // output
71  $aTemplateVars = array (
72  'ch_repeat:buttons' => $aButtons,
73  );
74  return $GLOBALS['oSysTemplate']->parseHtmlByName('social_sharing.html', $aTemplateVars);
75  }
76 
77  protected function _addOpenGraphInfo($sTitle, $sImageUrl = '')
78  {
79  $GLOBALS['oSysTemplate']->setOpenGraphInfo(array('title' => $sTitle));
80  if ($sImageUrl)
81  $GLOBALS['oSysTemplate']->setOpenGraphInfo(array('image' => $sImageUrl));
82  }
83 }
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$oAlert
$oAlert
Definition: embed.php:15
ChWsbSocialSharing
Definition: ChWsbSocialSharing.php:33
$sUrl
$sUrl
Definition: cart.php:15
php
ch_lang_info
ch_lang_info()
Definition: languages.inc.php:562
ChWsbAlerts
Definition: ChWsbAlerts.php:39
ChBaseSocialSharing
Definition: ChBaseSocialSharing.php:14
ChWsbSocialSharing\_getLocaleFacebook
_getLocaleFacebook($sLocale)
Definition: ChWsbSocialSharing.php:88
$sTitle
$sTitle
Definition: actions.inc.php:13
ChBaseSocialSharing\getCode
getCode($sUrl, $sTitle, $aCustomVars=false)
Definition: ChBaseSocialSharing.php:23
ChWsbSocialSharing\_replaceMarkers
_replaceMarkers($s, $a)
Definition: ChWsbSocialSharing.php:72
ChBaseSocialSharing\_addOpenGraphInfo
_addOpenGraphInfo($sTitle, $sImageUrl='')
Definition: ChBaseSocialSharing.php:77
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
ChBaseSocialSharing\__construct
__construct()
Definition: ChBaseSocialSharing.php:18
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10