Completed
Pull Request — master (#8)
by Michael
02:48
created

class/providers/thumbalizr.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 MylinksThumbalizr
39
 */
40
class MylinksThumbalizr implements MylinksThumbPlugin
41
{
42
    private $image_width   = 0;
43
    private $site_url      = null;
44
    private $key           = null;
45
    private $attribution   = "<a href=\"http://www.thumbalizr.com\" target=\"_blank\" title=\"Thumbnail Screenshots by Thumbalizr\">Thumbnail Screenshots by Thumbalizr</a>";
46
    private $provider_url  = 'http://api.thumbalizr.com';
47
    private $provider_name = 'Thumbalizr';
48
49
    /**
50
     * MylinksThumbalizr constructor.
51
     */
52
    public function __construct()
53
    {
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getProviderUrl()
60
    {
61
        $query_string = array(
62
            'url'      => $this->site_url,
63
            'width'    => $this->image_width,
64
            'encoding' => 'jpg',
65
            'mode'     => 'screen'
66
        );
67
        $api_key      = $this->getProviderPublicKey();
0 ignored issues
show
Are you sure the assignment to $api_key is correct as $this->getProviderPublicKey() (which targets MylinksThumbalizr::getProviderPublicKey()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
68
        if (!empty($api_key)) {
69
            $query_string['api_key'] = $api_key;
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 array('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
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
        } else {
144
            $myts = MyTextSanitizer::getInstance();
145
146
            return $myts->htmlSpecialChars($this->attribution);
147
        }
148
    }
149
150
    /**
151
     * @param $key
152
     * @return mixed|void
153
     */
154
    public function setProviderPublicKey($key)
155
    {
156
        $this->key = $key;
157
    }
158
159
    /**
160
     * @return null
161
     */
162
    public function getProviderPublicKey()
163
    {
164
        return $this->key;
165
    }
166
167
    /**
168
     * @param $key
169
     * @return bool
170
     */
171
    public function setProviderPrivateKey($key)
172
    {
173
        return false;
174
    }
175
176
    /**
177
     * @return bool
178
     */
179
    public function getProviderPrivateKey()
180
    {
181
        return false;
182
    }
183
}
184