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

Nemui::setProviderPublicKey()   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 1
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 MylinksNemui
43
 */
44
class Nemui implements Mylinks\ThumbPlugin
45
{
46
    private   $image_width   = 0;
47
    private   $image_height  = 0;
48
    protected $image_ratio   = 1.33;  // (4:3)
49
    private   $site_url      = null;
50
    private   $key           = null;
51
    private   $attribution   = '<a href="http://mozshot.nemui.org" target="_blank" title="Thumbnails Screenshots by Nemui.org">Thumbnail Screenshots by Nemui.org</a>';
52
    private   $provider_url  = 'http://mozshot.nemui.org';
53
    private   $provider_name = 'Nemui';
54
55
    /**
56
     * MylinksNemui constructor.
57
     */
58
    public function __construct()
59
    {
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getProviderUrl()
66
    {
67
        $sz          = $this->getShotSize();
68
        $image_size  = $sz['width'] . 'x' . $sz['height'];
69
        $providerUrl = $this->provider_url . "/shot/{$image_size}?" . $this->site_url;
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 (is_array($sz)) {
89
            if (array_key_exists('width', $sz)) {
90
                $this->image_width = (int)$sz['width'];
91
                if (array_key_exists('height', $sz)) {
92
                    $this->image_height = (int)$sz['height'];
93
                } else {
94
                    $this->image_height = (int)($this->image_width / $this->image_ratio);
95
                }
96
            } else {
97
                $this->image_width  = (int)$sz;
98
                $this->image_height = (int)($sz / $this->image_ratio);
99
            }
100
        } else {
101
            $this->image_width  = (int)$sz;
102
            $this->image_height = (int)($sz / $this->image_ratio);
103
        }
104
    }
105
106
    /**
107
     * @return array
108
     */
109
    public function getShotSize()
110
    {
111
        return ['width' => $this->image_width, 'height' => $this->image_height];
112
    }
113
114
    /**
115
     * @param $url
116
     * @return mixed|void
117
     */
118
    public function setSiteUrl($url)
119
    {
120
        //@todo: sanitize url;
121
        $this->site_url = formatURL($url);
122
    }
123
124
    /**
125
     * @return string
126
     */
127
    public function getSiteUrl()
128
    {
129
        return urlencode($this->site_url);
130
    }
131
132
    /**
133
     * @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...
134
     */
135
    public function setAttribution($attr = null)
136
    {
137
        $this->attribution = $attr;
138
    }
139
140
    /**
141
     * @param int $allowhtml
142
     * @return string
143
     */
144
    public function getAttribution($allowhtml = 0)
145
    {
146
        if ($allowhtml) {
147
            return $this->attribution;
148
        }
149
        $myts = \MyTextSanitizer::getInstance();
150
151
        return $myts->htmlSpecialChars($this->attribution);
152
    }
153
154
    /**
155
     * @param $key
156
     * @return mixed|void
157
     */
158
    public function setProviderPublicKey($key)
159
    {
160
        $this->key = $key;
161
    }
162
163
    public function getProviderPublicKey()
164
    {
165
        return $this->key;
166
    }
167
168
    /**
169
     * @param $key
170
     * @return bool
171
     */
172
    public function setProviderPrivateKey($key)
173
    {
174
        return false;
175
    }
176
177
    /**
178
     * @return bool
179
     */
180
    public function getProviderPrivateKey()
181
    {
182
        return false;
183
    }
184
}
185