MylinksNemui::getShotSize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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 MylinksNemui
39
 */
40
class MylinksNemui implements MylinksThumbPlugin
41
{
42
    private   $image_width   = 0;
43
    private   $image_height  = 0;
44
    protected $image_ratio   = 1.33;  // (4:3)
45
    private   $site_url      = null;
46
    private   $key           = null;
47
    private   $attribution   = "<a href=\"http://mozshot.nemui.org\" target=\"_blank\" title=\"Thumbnails Screenshots by Nemui.org\">Thumbnail Screenshots by Nemui.org</a>";
48
    private   $provider_url  = 'http://mozshot.nemui.org';
49
    private   $provider_name = 'Nemui';
50
51
    /**
52
     * MylinksNemui constructor.
53
     */
54
    public function __construct()
55
    {
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getProviderUrl()
62
    {
63
        $sz          = $this->getShotSize();
64
        $image_size  = $sz['width'] . 'x' . $sz['height'];
65
        $providerUrl = $this->provider_url . "/shot/{$image_size}?" . $this->site_url;
66
67
        return $providerUrl;
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getProviderName()
74
    {
75
        return $this->provider_name;
76
    }
77
78
    /**
79
     * @param $sz
80
     * @return mixed|void
81
     */
82
    public function setShotSize($sz)
83
    {
84
        if (is_array($sz)) {
85 View Code Duplication
            if (array_key_exists('width', $sz)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
86
                $this->image_width = (int)$sz['width'];
87
                if (array_key_exists('height', $sz)) {
88
                    $this->image_height = (int)$sz['height'];
89
                } else {
90
                    $this->image_height = (int)($this->image_width / $this->image_ratio);
91
                }
92
            } else {
93
                $this->image_width  = (int)$sz;
94
                $this->image_height = (int)($sz / $this->image_ratio);
95
            }
96
        } else {
97
            $this->image_width  = (int)$sz;
98
            $this->image_height = (int)($sz / $this->image_ratio);
99
        }
100
    }
101
102
    /**
103
     * @return array
104
     */
105
    public function getShotSize()
106
    {
107
        return array('width' => $this->image_width, 'height' => $this->image_height);
108
    }
109
110
    /**
111
     * @param $url
112
     * @return mixed|void
113
     */
114
    public function setSiteUrl($url)
115
    {
116
        //@todo: sanitize url;
117
        $this->site_url = formatURL($url);
118
    }
119
120
    /**
121
     * @return string
122
     */
123
    public function getSiteUrl()
124
    {
125
        return urlencode($this->site_url);
126
    }
127
128
    /**
129
     * @param null $attr
130
     */
131
    public function setAttribution($attr = null)
132
    {
133
        $this->attribution = $attr;
134
    }
135
136
    /**
137
     * @param int $allowhtml
138
     * @return string
139
     */
140
    public function getAttribution($allowhtml = 0)
141
    {
142
        if ($allowhtml) {
143
            return $this->attribution;
144
        } else {
145
            $myts = MyTextSanitizer::getInstance();
146
147
            return $myts->htmlSpecialChars($this->attribution);
148
        }
149
    }
150
151
    /**
152
     * @param $key
153
     * @return mixed|void
154
     */
155
    public function setProviderPublicKey($key)
156
    {
157
        $this->key = $key;
158
    }
159
160
    /**
161
     * @return null
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