1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* You may not change or alter any portion of this comment or credits |
4
|
|
|
* of supporting developers from this source code or any supporting source code |
5
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
* This program is distributed in the hope that it will be useful, |
7
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
8
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
9
|
|
|
* |
10
|
|
|
* to use the provider: |
11
|
|
|
* $shot = new MylinksThumbshots(); |
12
|
|
|
* $shot->setProviderPrivateKey(my_key); |
13
|
|
|
* $shot->setShotSize(array('width'=>120)); |
14
|
|
|
* $shot->setSiteUrl("http://site_to_capture"); |
15
|
|
|
* $mylinks_shotprovider = $shot->getProviderUrl(); |
16
|
|
|
* |
17
|
|
|
* Then in the template use something like: |
18
|
|
|
* <img src='<{$mylinks_shotprovider}>' target='_blank' alt='' style='margin: 3px 7px;'> |
19
|
|
|
* and at the bottom of the page show the attribution |
20
|
|
|
* echo $shot->getAttribution(); |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* MyLinks category.php |
25
|
|
|
* |
26
|
|
|
* Xoops mylinks - a multicategory links module |
27
|
|
|
* |
28
|
|
|
* @copyright :: {@link http://xoops.org/ XOOPS Project} |
29
|
|
|
* @copyright :: {@link http://www.zyspec.com ZySpec Incorporated} |
30
|
|
|
* @license :: {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License} |
31
|
|
|
* @package :: mylinks |
32
|
|
|
* @subpackage:: class |
33
|
|
|
* @author :: zyspec <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/mylinks/class/thumbplugin.interface.php'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Class MylinksShrinktheweb |
39
|
|
|
*/ |
40
|
|
View Code Duplication |
class MylinksShrinktheweb implements MylinksThumbPlugin |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
private $image_width = 0; |
43
|
|
|
private $site_url = null; |
44
|
|
|
private $key = null; |
45
|
|
|
private $attribution = "<a href=\"http://www.shrinktheweb.com\" target=\"_blank\" title=\"Thumbnail Screenshots by ShrinkTheWeb\">Thumbnail Screenshots by ShrinkTheWeb</a>"; |
46
|
|
|
private $provider_url = 'http://images.shrinktheweb.com/xino.php'; |
47
|
|
|
private $provider_name = 'ShrinkTheWeb'; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* MylinksShrinktheweb constructor. |
51
|
|
|
*/ |
52
|
|
|
public function __construct() |
53
|
|
|
{ |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
public function getProviderUrl() |
60
|
|
|
{ |
61
|
|
|
$query_string = array( |
62
|
|
|
'stwembed' => 1, |
63
|
|
|
'stwaccesskeyid' => $this->getProviderPrivateKey(), |
64
|
|
|
'stwxmax' => $this->image_width, |
65
|
|
|
'stwurl' => $this->site_url |
66
|
|
|
); |
67
|
|
|
$query = http_build_query($query_string); |
68
|
|
|
$query = empty($query) ? '' : '?' . $query; |
69
|
|
|
$providerUrl = $this->provider_url . $query; |
70
|
|
|
|
71
|
|
|
return $providerUrl; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function getProviderName() |
78
|
|
|
{ |
79
|
|
|
return $this->provider_name; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param $sz |
84
|
|
|
* @return mixed|void |
85
|
|
|
*/ |
86
|
|
|
public function setShotSize($sz) |
87
|
|
|
{ |
88
|
|
|
if (isset($sz)) { |
89
|
|
|
if (is_array($sz) && array_key_exists('width', $sz)) { |
90
|
|
|
$this->image_width = (int)$sz['width']; |
91
|
|
|
} else { |
92
|
|
|
$this->image_width = (int)$sz; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return array |
99
|
|
|
*/ |
100
|
|
|
public function getShotSize() |
101
|
|
|
{ |
102
|
|
|
return array('width' => $this->image_width, 'height' => 0); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param $url |
107
|
|
|
* @return mixed|void |
108
|
|
|
*/ |
109
|
|
|
public function setSiteUrl($url) |
110
|
|
|
{ |
111
|
|
|
//@todo: sanitize url; |
112
|
|
|
$this->site_url = formatURL($url); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public function getSiteUrl() |
119
|
|
|
{ |
120
|
|
|
return urlencode($this->site_url); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param null $attr |
125
|
|
|
*/ |
126
|
|
|
public function setAttribution($attr = null) |
127
|
|
|
{ |
128
|
|
|
$this->attribution = $attr; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param int $allowhtml |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
public function getAttribution($allowhtml = 0) |
136
|
|
|
{ |
137
|
|
|
if ($allowhtml) { |
138
|
|
|
return $this->attribution; |
139
|
|
|
} else { |
140
|
|
|
$myts = MyTextSanitizer::getInstance(); |
141
|
|
|
|
142
|
|
|
return $myts->htmlSpecialChars($this->attribution); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param $key |
148
|
|
|
* @return mixed|void |
149
|
|
|
*/ |
150
|
|
|
public function setProviderPublicKey($key) |
151
|
|
|
{ |
152
|
|
|
$this->key = $key; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @return null |
157
|
|
|
*/ |
158
|
|
|
public function getProviderPublicKey() |
159
|
|
|
{ |
160
|
|
|
return $this->key; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param $key |
165
|
|
|
* @return bool |
166
|
|
|
*/ |
167
|
|
|
public function setProviderPrivateKey($key) |
168
|
|
|
{ |
169
|
|
|
return false; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return bool |
174
|
|
|
*/ |
175
|
|
|
public function getProviderPrivateKey() |
176
|
|
|
{ |
177
|
|
|
return false; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.