Passed
Pull Request — master (#9)
by Michael
03:24
created

Thumbshots::getProviderName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace XoopsModules\Mylinks\Providers;
4
5
/*
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * to use the provider:
14
 * $shot = new MylinksThumbshots();
15
 * $shot->setProviderPrivateKey(my_key);
16
 * $shot->setShotSize(array('width'=>120));
17
 * $shot->setSiteUrl("http://site_to_capture");
18
 * $mylinks_shotprovider = $shot->getProviderUrl();
19
 *
20
 * Then in the template use something like:
21
 *  <img src='<{$mylinks_shotprovider}>' target='_blank' alt='' style='margin: 3px 7px;'>
22
 *  and at the bottom of the page show the attribution
23
 *  echo $shot->getAttribution();
24
 */
25
26
use XoopsModules\Mylinks;
27
28
/**
29
 * MyLinks category.php
30
 *
31
 * Xoops mylinks - a multicategory links module
32
 *
33
 * @copyright ::  {@link http://www.zyspec.com ZySpec Incorporated}
34
 * @license   ::    {@link https://www.gnu.org/licenses/gpl-2.0.html GNU Public License}
35
 * @package   ::    mylinks
36
 * @subpackage:: class
37
 * @since     ::      3.11
38
 * @author    ::     zyspec <[email protected]>
39
 */
40
41
/**
42
 * Class MylinksThumbshots
43
 */
44
class Thumbshots implements Mylinks\ThumbPlugin
45
{
46
    private $image_width   = 0;
47
    private $site_url      = null;
48
    private $key           = null;
49
    private $attribution   = '<a href="http://www.thumbshots.com" target="_blank" title="Thumbnails Screenshots by Thumbshots">Thumbnail Screenshots by Thumbshots</a>';
50
    private $provider_url  = 'http://images.thumbshots.com/image.aspx';
51
    private $provider_name = 'Thumbshots';
52
53
    /**
54
     * MylinksThumbshots constructor.
55
     */
56
    public function __construct()
57
    {
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getProviderUrl()
64
    {
65
        $query_string = [
66
            'cid' => $this->getProviderPublicKey(),
67
            'v'   => 1,
68
            'w'   => $this->image_width,
69
            'url' => $this->site_url,
70
        ];
71
        $query        = http_build_query($query_string);
72
        $query        = empty($query) ? '' : '?' . $query;
73
        $providerUrl  = $this->provider_url . $query;
74
75
        return $providerUrl;
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getProviderName()
82
    {
83
        return $this->provider_name;
84
    }
85
86
    /**
87
     * @param $sz
88
     * @return mixed|void
89
     */
90
    public function setShotSize($sz)
91
    {
92
        if (isset($sz)) {
93
            if (is_array($sz) && array_key_exists('width', $sz)) {
94
                $this->image_width = (int)$sz['width'];
95
            } else {
96
                $this->image_width = (int)$sz;
97
            }
98
        }
99
    }
100
101
    /**
102
     * @return array
103
     */
104
    public function getShotSize()
105
    {
106
        return ['width' => $this->image_width, 'height' => 0];
107
    }
108
109
    /**
110
     * @param $url
111
     * @return mixed|void
112
     */
113
    public function setSiteUrl($url)
114
    {
115
        //@todo: sanitize url;
116
        $this->site_url = formatURL($url);
117
    }
118
119
    /**
120
     * @return string
121
     */
122
    public function getSiteUrl()
123
    {
124
        return urlencode($this->site_url);
125
    }
126
127
    /**
128
     * @param null $attr
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $attr is correct as it would always require null to be passed?
Loading history...
129
     */
130
    public function setAttribution($attr = null)
131
    {
132
        $this->attribution = $attr;
133
    }
134
135
    /**
136
     * @param int $allowhtml
137
     * @return string
138
     */
139
    public function getAttribution($allowhtml = 0)
140
    {
141
        if ($allowhtml) {
142
            return $this->attribution;
143
        }
144
        $myts = \MyTextSanitizer::getInstance();
145
146
        return $myts->htmlSpecialChars($this->attribution);
147
    }
148
149
    /**
150
     * @param $key
151
     * @return mixed|void
152
     */
153
    public function setProviderPublicKey($key)
154
    {
155
        $this->key = $key;
156
    }
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