-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsharebuttons.php
More file actions
97 lines (80 loc) · 2.78 KB
/
Copy pathsharebuttons.php
File metadata and controls
97 lines (80 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
defined('_JEXEC') or die;
class Sharetools
{
protected $id = 0;
protected $catid = 0;
protected $link = '';
protected $option;
protected $root;
protected $slug;
protected $view;
function __construct(int $id = 0, int $catid = 0, string $option = '', string $view = '', string $slug = '', array $params = [])
{
if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['PORT'] == 443)
{
$scheme = 'https://';
}
else
{
$scheme = 'http://';
}
$this->id = $id;
$this->catid = $catid;
$this->option = $option;
$this->params = (array) $params;
$this->root = $scheme . $_SERVER['HTTP_HOST'];
$this->slug = $slug;
$this->view = $view;
}
/**
* Set the fully qualified link if we already have one built
* @param link string
*/
function setLinkText($link = '')
{
if(!empty($link))
{
$this->link = trim($link);
}
}
/**
* Build the URL to use for the share buttons
* @return uri string
*/
protected function buildUri()
{
$qstring = array();
$uri_query = '';
$qstring['option'] = $this->option;
$qstring['view'] = $this->view;
$qstring['id'] = $this->slug;
$uri_query = http_build_query($qstring);
$uri = JRoute::_($this->root . '/index.php?' . $uri_query);
return $uri;
}
/**
* Outputs social media buttons
* @return buttons string
*/
function shareButtons()
{
$this->uri = !empty($this->link) ? $this->root . $this->link : $this->buildUri();
// Facebook
// $fb = '<div class="fb-like st-button" data-href="'.$this->uri.'" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div>';
$fb = '<div class="fb-share-button st-button" data-href="'.$this->uri.'" data-layout="button_count" data-action="like"></div>';
// Twitter
$tw = '<div class="st-button"><a href="https://twitter.com/share" class="twitter-share-button" data-url="'.$this->uri.'" data-text="Check out this site!"></a></div>';
// Email
$email = '<div class="st-button"><a class="mail" href="mailto:?subject=Check+out+this+link&body='.$this->uri.'" target="_blank" rel="noopener noreferrer">';
$email .= '<span class="fa fa-envelope"></span> Email a Friend</a></div>';
// LinkedIn
$ln = '<div class="st-button"><script type="IN/Share" data-counter="right" data-url="'.$this->uri.'"></script></div>';
// Pinterest
$pt = '<div class="st-button"><a data-pin-do="buttonBookmark" data-pin-url="'.$this->uri.'" data-pin-count="beside" ';
$pt .= (isset($this->params['image']) && !empty($this->params['image'])) ? ' data-pin-media="'.$this->params['image'].'"' : '';
$pt .= 'data-pin-color="white" href="https://www.pinterest.com/pin/create/button/"></a></div>';
$buttons = '<div class="sharetools">' . $fb . $tw . $pt . $ln . $email . '</div>';
return $buttons;
}
}