-
Notifications
You must be signed in to change notification settings - Fork 3
/
sharingbuttons.php
97 lines (78 loc) · 2.67 KB
/
sharingbuttons.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
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
<?php
/**
* Kirby Sharingbuttons Plugin
*
* @package Kirby CMS
* @author Flo Kosiol <[email protected]>
* @link http://flokosiol.de
* @version 1.2
*/
/**
* Custom page method
*/
page::$methods['sharingbuttons'] = function($page, $config = false) {
// get custom setting from config.php or set defaults
$urlField = c::get('plugin.sharingbuttons.urlField', 'url');
$descriptionField = c::get('plugin.sharingbuttons.descriptionField', 'title');
$size = c::get('plugin.sharingbuttons.size','small');
$style = c::get('plugin.sharingbuttons.style','solid');
$networks = c::get('plugin.sharingbuttons.networks', [
'twitter' => 'Twitter',
'facebook' => 'Facebook',
'google' => 'Google+',
'linkedin' => 'LinkedIn',
'email' => 'E-Mail',
// 'tumblr' => 'Tumblr',
// 'pinterest' => 'Pinterest',
// 'reddit' => 'Reddit',
// 'xing' => 'XING',
// 'whatsapp' => 'WhatsApp',
// 'hackernews' => 'Hacker News',
// 'vk' => 'VK',
// 'telegram' => 'Telegram',
]);
// override with inline settings if set
if (!empty($config['urlField'])) {
$urlField = $config['urlField'];
}
if (!empty($config['descriptionField'])) {
$descriptionField = $config['descriptionField'];
}
if (!empty($config['size']) && in_array($config['size'], ['small', 'medium', 'large'])) {
$size = $config['size'];
}
if (!empty($config['style']) && in_array($config['style'], ['normal', 'solid', 'circle', 'solidcircle'])) {
$style = $config['style'];
}
if (!empty($config['networks']) && is_array($config['networks'])) {
$networks = $config['networks'];
}
// prepare data for templates
$url = (string) (isset($config['url']) ? $config['url'] : call([$page, $urlField]));
$description = (string) (isset($config['description']) ? $config['description'] : call([$page, $descriptionField]));
$data = [
'url' => rawurlencode($url),
'description' => rawurlencode($description),
'size' => $size,
'style' => $style,
];
// build html brick
$content = new Brick('div');
$content->addClass('sharingbuttons');
$buttons = '';
foreach ($networks as $template => $network) {
switch ($data['size']) {
case 'medium':
$data['title'] = $network;
break;
case 'large':
$data['title'] = l::get('plugin.sharingbuttons.' . $template, 'Share on ' . $network);
break;
default:
$data['title'] = '';
break;
}
$buttons .= tpl::load(__DIR__ . DS . 'templates' . DS . $template . '.php', $data);
}
return $content->html($buttons);
};