-
Notifications
You must be signed in to change notification settings - Fork 2
/
pico_share.php
70 lines (63 loc) · 2.18 KB
/
pico_share.php
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
<?php
/**
* Social plugin for Pico CMS
* Adds social media buttons to posts and pages
*
* @author Narcis Radu
* @link http://narcisradu.ro
* @license http://opensource.org/licenses/MIT
*/
class Pico_Share {
public $templates = array(
'twitter' => 'https://twitter.com/intent/tweet?text=__TITLE__&url=__URL__',
'facebook' => 'https://www.facebook.com/sharer/sharer.php?u=__URL__',
'google' => 'https://plus.google.com/share?url=__URL__',
'linkedin' => 'http://www.linkedin.com/shareArticle?mini=true&url=__URL__&title=__TITLE__&summary=__EXCERPT__&source=__URL__'
);
public function __construct() {
$this->config = array(
'services' => array(
'twitter' => true,
'facebook' => true,
'google' => true,
'linkedin' => true
),
'output' => 'list',
'class_prefix' => 'btn-'
);
}
public function config_loaded(&$settings) {
if(isset($settings['social']['services'])) {
$this->config['services'] = $settings['social']['services'];
};
if(isset($settings['social']['output'])) {
$this->config['output'] = $settings['social']['output'];
};
if(isset($settings['social']['class_prefix'])) {
$this->config['class_prefix'] = $settings['social']['class_prefix'];
};
}
public function before_render(&$twig_vars, &$twig, &$template) {
$pageTitle = $twig_vars['current_page']['title'];
$pageURL = $twig_vars['current_page']['url'];
$pageExcerpt = $twig_vars['current_page']['excerpt'];
$activeServices = array();
foreach($this->config['services'] as $key => $value) {
if(is_bool($value) && $value) {
$activeServices[$key] = '<a class="'.$this->config['class_prefix'].$key.'" target="_blank" href="'.
preg_replace(array('/__TITLE__/', '/__URL__/', '/__EXCERPT__/'), array($pageTitle, $pageURL, $pageExcerpt), $this->templates[$key]).
'">'.$key.'</a>';
};
};
switch($this->config['output']) {
case 'link':
$twig_vars['social_share'] = '<div id="share">'.implode('', array_values($activeServices)).'</div>';
break;
default:
//show as list by default
$twig_vars['social_share'] = '<ul id="share"><li>'.implode('</li><li>', array_values($activeServices)).'</li></ul>';
break;
};
}
}
?>