Completed
Push — next ( 5f2bc0...cef70f )
by Thomas
25s queued 12s
created

cachelist   F

Complexity

Total Complexity 88

Size/Duplication

Total Lines 574
Duplicated Lines 4.18 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
dl 24
loc 574
rs 2
c 0
b 0
f 0
wmc 88
lcom 2
cbo 2

43 Methods

Rating   Name   Duplication   Size   Complexity  
A addCachesByIDs() 0 11 3
A __construct() 24 24 2
A exist() 0 4 1
A getId() 0 4 1
A getUUID() 0 4 1
A setNode() 0 4 1
A getNode() 0 4 1
A getUserId() 0 4 1
A isMyList() 0 6 1
A getName() 0 4 1
A getVisibility() 0 4 1
B setNameAndVisibility() 0 28 8
A getDescription() 0 4 1
A getDescriptionForDisplay() 0 4 1
A getDescHtmledit() 0 4 1
A setDescription() 0 6 2
A setPassword() 0 4 1
A getPassword() 0 4 1
A getCachesCount() 0 9 1
A getWatchersCount() 0 9 1
A save() 0 16 4
A getCaches() 0 24 2
A addCacheByWP() 0 9 2
A addCachesByWPs() 0 19 5
A addCacheByID() 0 4 1
A addCache() 0 15 3
A removeCacheById() 0 8 1
A watch() 0 27 4
A isWatchedByMe() 0 12 1
A bookmark() 0 18 6
A unbookmark() 0 11 1
B allowView() 0 23 6
A getMyLists() 0 6 1
A getListsWatchedByMe() 0 10 1
A getBookmarkedLists() 0 10 1
A getPublicListCount() 0 14 3
A getPublicLists() 0 12 3
A getPublicListsOf() 0 6 1
A getListsByCacheId() 0 34 2
A getListById() 0 11 2
A getLists() 0 41 3
A getMyLastAddedToListId() 0 19 2
A watchingCacheByListsCount() 0 15 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like cachelist often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use cachelist, and based on these observations, apply Extract Interface, too.

1
<?php
2
/***************************************************************************
3
 * for license information see LICENSE.md
4
 *
5
 *
6
 *   get/set has to be committed with save
7
 *   add/remove etc. is executed instantly
8
 ***************************************************************************/
9
10
require_once __DIR__ . '/../translate.class.php';
11
12
define('ERROR_BAD_LISTNAME', 1);
13
define('ERROR_DUPLICATE_LISTNAME', 2);
14
15
16
class cachelist
17
{
18
    public $nCachelistId = 0;
19
    public $reCachelist;
20
21 View Code Duplication
    public function __construct($nNewCacheListId = ID_NEW, $nUserId = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
22
    {
23
        $this->reCachelist = new rowEditor('cache_lists');
24
        $this->reCachelist->addPKInt('id', null, false, RE_INSERT_AUTOINCREMENT);
25
        $this->reCachelist->addString('uuid', '', false, RE_INSERT_AUTOUUID);
26
        $this->reCachelist->addInt('node', 0, false);
27
        $this->reCachelist->addInt('user_id', $nUserId, false);
28
        $this->reCachelist->addDate('date_created', time(), true, RE_INSERT_IGNORE);
29
        $this->reCachelist->addDate('last_modified', time(), true, RE_INSERT_IGNORE);
30
        $this->reCachelist->addDate('last_added', null, true);
31
        $this->reCachelist->addString('name', '', false);
32
        $this->reCachelist->addInt('is_public', 0, false);
33
        $this->reCachelist->addString('description', '', false);
34
        $this->reCachelist->addInt('desc_htmledit', 1, false);
35
        $this->reCachelist->addString('password', '', false);
36
37
        $this->nCachelistId = $nNewCacheListId + 0;
38
39
        if ($nNewCacheListId == ID_NEW) {
40
            $this->reCachelist->addNew(null);
41
        } else {
42
            $this->reCachelist->load($this->nCachelistId);
43
        }
44
    }
45
46
    public function exist()
47
    {
48
        return $this->reCachelist->exist();
49
    }
50
51
    public function getId()
52
    {
53
        return $this->nCachelistId;
54
    }
55
56
    public function getUUID()
57
    {
58
        return $this->reCachelist->getValue('uuid');
59
    }
60
61
    public function setNode($value)
62
    {
63
        return $this->reCachelist->setValue('node', $value);
64
    }
65
66
    public function getNode()
67
    {
68
        return $this->reCachelist->getValue('node');
69
    }
70
71
    public function getUserId()
72
    {
73
        return $this->reCachelist->getValue('user_id');
74
    }
75
76
    public function isMyList()
77
    {
78
        global $login;
79
80
        return $this->getUserId() == $login->userid;
81
    }
82
83
    public function getName()
84
    {
85
        return $this->reCachelist->getValue('name');
86
    }
87
88
    // 0 = private, 1 = private & friends (not impl.), 2 = public, 3 = public + listing display
89
    public function getVisibility()
90
    {
91
        return $this->reCachelist->getValue('is_public');
92
    }
93
94
    // !! This method returns an error state instead of a success flag; false means "no error".
95
    public function setNameAndVisibility($name, $visibility)
96
    {
97
        $name = trim($name);
98
        if ($name == '') {
99
            return ERROR_BAD_LISTNAME;
100
        }
101
        if (sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
102
                "SELECT `id`
103
                 FROM `cache_lists`
104
                 WHERE `user_id`='&1' AND `id`<>'&2' AND `name`='&3'",
105
                false,
106
                $this->getUserId(),
107
                $this->getId(),
108
                $name
109
            )) {
110
            // $this->getId() is 0 when creating a new list -> condition has no effect
111
            return ERROR_DUPLICATE_LISTNAME;
112
        } elseif ($visibility >= 2 && strlen($name) < 10) {
113
            return ERROR_BAD_LISTNAME;
114
        }
115
116
        $error = !$this->reCachelist->setValue('name', trim($name));
117
        if ($visibility == 0 || $visibility == 2 || $visibility == 3) {
118
            $error |= !$this->reCachelist->setValue('is_public', $visibility);
119
        }
120
121
        return $error;
122
    }
123
124
    // return description in HTML format
125
    public function getDescription()
126
    {
127
        return $this->reCachelist->getValue('description');
128
    }
129
130
    public function getDescriptionForDisplay()
131
    {
132
        return use_current_protocol_in_html(getDescription());
133
    }
134
135
    public function getDescHtmledit()
136
    {
137
        return $this->reCachelist->getValue('desc_htmledit');
138
    }
139
140
    // set description in HTML format, must be purified!
141
    public function setDescription($desc, $htmledit)
142
    {
143
        $this->reCachelist->setValue('desc_htmledit', $htmledit ? 1 : 0);
144
145
        return $this->reCachelist->setValue('description', $desc);
146
    }
147
148
    public function setPassword($pw): void
149
    {
150
        $this->reCachelist->setValue('password', $pw);
151
    }
152
153
    public function getPassword()
154
    {
155
        return $this->reCachelist->getValue('password');
156
    }
157
158
    public function getCachesCount()
159
    {
160
        return sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
161
            "
162
            SELECT `entries` FROM `stat_cache_lists`
163
            WHERE `stat_cache_lists`.`cache_list_id`='" . sql_escape($this->getId()) . "'",
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
164
            0
165
        );
166
    }
167
168
    public function getWatchersCount()
169
    {
170
        return sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
171
            "
172
            SELECT `watchers` FROM `stat_cache_lists`
173
            WHERE `stat_cache_lists`.`cache_list_id`='" . sql_escape($this->getId()) . "'",
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
174
            0
175
        );
176
    }
177
178
    public function save()
179
    {
180
        if ($this->getVisibility() > 0) {
181
            $this->setPassword('');
182
        }
183
        sql_slave_exclude();
0 ignored issues
show
Deprecated Code introduced by
The function sql_slave_exclude() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
184
        if ($this->reCachelist->save()) {
185
            if ($this->getId() == ID_NEW) {
186
                $this->nCachelistId = $this->reCachelist->getValue('id');
187
            }
188
189
            return true;
190
        }
191
192
        return false;
193
    }
194
195
    // get and set list contents
196
197
    // locked/hidden caches may be added to a list by the owner or an administrator,
198
    // but getCaches() will return visible==0 if the list is queried by someone else.
199
    // The 'visible' flag MUST be evaluated and the cache name must not be shown
200
    // if it is 0. This also ensures that cache names are hidden if a cache is locked/hidden
201
    // after being added to a list.
202
203
    public function getCaches()
204
    {
205
        global $login;
206
        $login->verify();
207
208
        $rs = sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
209
            "
210
            SELECT `cache_list_items`.`cache_id`, `caches`.`wp_oc`, `caches`.`name`,
211
                   `caches`.`type`, `caches`.`status`,
212
                   (`cache_status`.`allow_user_view` OR `caches`.`user_id`='&2' OR '&3') AS `visible`,
213
                   `ca`.`attrib_id` IS NOT NULL AS `oconly`
214
            FROM `cache_list_items`
215
            LEFT JOIN `caches` ON `caches`.`cache_id`=`cache_list_items`.`cache_id`
216
            LEFT JOIN `cache_status` ON `cache_status`.`id`=`caches`.`status`
217
            LEFT JOIN `caches_attributes` `ca` ON `ca`.`cache_id`=`caches`.`cache_id` AND `ca`.`attrib_id`=6
218
            WHERE `cache_list_items`.`cache_list_id` = '&1'
219
            ORDER BY `caches`.`name`",
220
            $this->nCachelistId,
221
            $login->userid,
222
            ($login->admin & ADMIN_USER) ? 1 : 0
223
        );
224
225
        return sql_fetch_assoc_table($rs);
0 ignored issues
show
Deprecated Code introduced by
The function sql_fetch_assoc_table() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
Documentation introduced by
$rs is of type object<mysqli_result>, but the function expects a resource.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
226
    }
227
228
    public function addCacheByWP($wp)
229
    {
230
        $cache = cache::fromWP($wp);
231
        if (!is_object($cache)) {
232
            return false;
233
        }
234
235
        return $this->addCache($cache);
236
    }
237
238
    // returns true if all wayPoints were valid, or an array of invalid wayPoints
239
    public function addCachesByWPs($wps)
240
    {
241
        $wpa = explode(' ', trim($wps));
242
        $non_added_wps = [];
243
        foreach ($wpa as $wp) {
244
            $wp = trim($wp);
245
            if ($wp) {
246
                $result = $this->addCacheByWP($wp);
247
                if ($result !== true) {
248
                    $non_added_wps[] = $wp;
249
                }
250
            }
251
        }
252
        if (count($non_added_wps)) {
253
            return $non_added_wps;
254
        }
255
256
        return true;
257
    }
258
259
    public function addCachesByIDs($cache_ids)
260
    {
261
        $number_wps = 0;
262
        foreach ($cache_ids as $cache_id) {
263
            $result = $this->addCacheByID($cache_id);
264
            if ($result == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
265
                $number_wps++;
266
            }
267
        }
268
        return $number_wps;
269
    }
270
271
    public function addCacheByID($cache_id)
272
    {
273
        return $this->addCache(new cache($cache_id));
274
    }
275
276
    public function addCache($cache)
277
    {
278
        if (!$cache->exist() || !$cache->allowView()) {
279
            return false;
280
        }
281
        sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
282
            "
283
            INSERT IGNORE INTO `cache_list_items` (`cache_list_id`, `cache_id`)
284
            VALUES ('&1', '&2')",
285
            $this->nCachelistId,
286
            $cache->getCacheId()
287
        );
288
289
        return true;
290
    }
291
292
    public function removeCacheById($cache_id): void
293
    {
294
        sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
295
            "DELETE FROM `cache_list_items` WHERE `cache_list_id`='&1' AND `cache_id`='&2'",
296
            $this->nCachelistId,
297
            $cache_id
298
        );
299
    }
300
301
    // watching, bookmarking and access tests
302
    public function watch($watch): void
303
    {
304
        global $login;
305
        $login->verify();
306
307
        if ($login->userid != 0) {
308
            if ($watch) {
309
                if ($this->allowView()) {
310
                    sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
311
                        "
312
                        INSERT IGNORE INTO `cache_list_watches` (`cache_list_id`, `user_id`)
313
                        VALUES ('&1','&2')",
314
                        $this->getId(),
315
                        $login->userid
316
                    );
317
                }
318
            } else {
319
                sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
320
                    "
321
                    DELETE FROM `cache_list_watches`
322
                    WHERE `cache_list_id`='&1' AND `user_id`='&2'",
323
                    $this->getId(),
324
                    $login->userid
325
                );
326
            }
327
        }
328
    }
329
330
    public function isWatchedByMe()
331
    {
332
        global $login;
333
334
        return sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
335
            "SELECT 1 FROM `cache_list_watches`
336
             WHERE `cache_list_id`='&1' AND `user_id`='&2'",
337
            0,
338
            $this->getId(),
339
            $login->userid
340
        ) != 0;
341
    }
342
343
    public function bookmark($pw): void
344
    {
345
        global $login;
346
347
        if ($login->userid != 0 &&
348
            !$this->isMyList() &&
349
            ($this->getVisibility() >= 2 || ($this->getPassword() != '' && $pw == $this->getPassword()))
350
        ) {
351
            sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
352
                "INSERT IGNORE INTO `cache_list_bookmarks` (`cache_list_id`, `user_id`, `password`)
353
                 VALUES('&1','&2','&3')
354
                 ON DUPLICATE KEY UPDATE `password`='&3'",
355
                $this->getId(),
356
                $login->userid,
357
                $pw
358
            );
359
        }
360
    }
361
362
    public function unbookmark(): void
363
    {
364
        global $login;
365
366
        sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
367
            "DELETE FROM `cache_list_bookmarks`
368
             WHERE `cache_list_id`='&1' AND `user_id`='&2'",
369
            $this->getId(),
370
            $login->userid
371
        );
372
    }
373
374
    public function allowView($pw = '')
375
    {
376
        global $login;
377
378
        if (!$this->exist()) {
379
            return false;
380
        }
381
382
        return $this->isMyList() ||
383
        $this->getVisibility() >= 2 ||
384
        ($this->getPassword() != '' && $pw == $this->getPassword()) ||
385
        sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
386
            "
387
                         SELECT COUNT(*)
388
                         FROM `cache_lists` `cl`
389
                         LEFT JOIN `cache_list_bookmarks` `clb` ON `clb`.`cache_list_id`=`cl`.`id`
390
                         WHERE `cl`.`id`='&1' AND `cl`.`password`<>''
391
                           AND `clb`.`user_id`='&2' AND `clb`.`password`=`cl`.`password`",
392
            0,
393
            $this->getId(),
394
            $login->userid
395
        );
396
    }
397
398
    // get list of lists -- public static functions
399
    public static function getMyLists()
400
    {
401
        global $login;
402
403
        return self::getLists("`cache_lists`.`user_id`='" . sql_escape($login->userid) . "'");
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
404
    }
405
406
    public static function getListsWatchedByMe()
407
    {
408
        global $login;
409
410
        return self::getLists(
411
            "`id` IN (SELECT `cache_list_id` FROM `cache_list_watches` WHERE `user_id`='" . sql_escape(
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
412
                $login->userid
413
            ) . "')"
414
        );
415
    }
416
417
    public static function getBookmarkedLists()
418
    {
419
        global $login;
420
421
        return self::getLists(
422
            "`id` IN (SELECT `cache_list_id` FROM `cache_list_bookmarks` WHERE `user_id`='" . sql_escape(
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
423
                $login->userid
424
            ) . "')"
425
        );
426
    }
427
428
    public static function getPublicListCount($namelike = '', $userlike = '')
429
    {
430
        return sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
431
            '
432
            SELECT COUNT(*)
433
            FROM `cache_lists`
434
            LEFT JOIN `stat_cache_lists` ON  `stat_cache_lists`.`cache_list_id`=`cache_lists`.`id`
435
            LEFT JOIN `user` ON `user`.`user_id`=`cache_lists`.`user_id`
436
            WHERE `is_public`>=2 AND `entries`>0'
437
            . ($namelike ? " AND `name` LIKE '%" . sql_escape($namelike) . "%'" : '')
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
438
            . ($userlike ? " AND `username` LIKE '%" . sql_escape($userlike) . "%'" : ''),
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
439
            0
440
        );
441
    }
442
443
    public static function getPublicLists($startat = 0, $maxitems = PHP_INT_MAX, $namelike = '', $userlike = '')
444
    {
445
        return self::getLists(
446
            '`is_public`>=2 AND `entries`>0'
447
            . ($namelike ? " AND `name` LIKE '%" . sql_escape($namelike) . "%'" : '')
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
448
            . ($userlike ? " AND `username` LIKE '%" . sql_escape($userlike) . "%'" : ''),
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
449
            0,
450
            (int) $startat,
451
            (int) $maxitems,
452
            true
453
        );
454
    }
455
456
    public static function getPublicListsOf($userid)
457
    {
458
        return self::getLists(
459
            "`is_public`>=2 AND `entries`>0 AND `cache_lists`.`user_id`='" . sql_escape($userid) . "'"
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
460
        );
461
    }
462
463
    // If $all is false, only own lists and public lists of the cache owner will be returned.
464
    public static function getListsByCacheId($cacheid, $all)
465
    {
466
        global $login;
467
468
        $cache_owner_id = sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
469
            "
470
            SELECT `user_id`
471
            FROM `caches`
472
            WHERE `cache_id`='" . sql_escape($cacheid) . "'",
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
473
            0
474
        );
475
        $my_watches = sql_fetch_column(
0 ignored issues
show
Deprecated Code introduced by
The function sql_fetch_column() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
476
            sql("SELECT `cache_list_id` FROM `cache_list_watches` WHERE `user_id`='&1'", $login->userid)
0 ignored issues
show
Documentation introduced by
sql('SELECT `cache_list_...'&1\'', $login->userid) is of type object<mysqli_result>, but the function expects a resource.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
477
        );
478
479
        return self::getLists(
480
            "
481
            `id` IN
482
                (SELECT `cache_list_id`
483
                 FROM `cache_list_items`
484
                 WHERE `cache_id`='" . sql_escape($cacheid) . "')
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
485
            AND
486
            (
487
                `cache_lists`.`user_id`='" . sql_escape($login->userid) . "' " .
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
488
            ($all ? 'OR `is_public`= 3 ' : '') .
489
            "OR (`is_public`> 0 AND
490
                   `cache_lists`.`id` IN ('" . implode("','", array_map('sql_escape', $my_watches)) . "'))
491
            )",
492
            "`cache_lists`.`user_id`<>'" . sql_escape($cache_owner_id) . "'",
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
493
            0,
494
            20,
495
            true
496
        );
497
    }
498
499
    public static function getListById($listid)
500
    {
501
        $lists = self::getLists("`id`='" . sql_escape($listid) . "'");
0 ignored issues
show
Deprecated Code introduced by
The function sql_escape() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
502
        if (count($lists)) {
503
            $lists[0]['description_for_display'] = use_current_protocol_in_html($lists[0]['description']);
504
505
            return $lists[0];
506
        }
507
508
        return false;
509
    }
510
511
    private static function getLists(
512
        $condition,
513
        $prio = 0,
514
        $startat = 0,
515
        $maxitems = PHP_INT_MAX,
516
        $strip_nagchars = false
517
    ) {
518
        global $login;
519
        $login->verify();
520
521
        $nameField = ($strip_nagchars ? 'STRIP_LEADING_NONALNUM(`cache_lists`.`name`)' : '`cache_lists`.`name`');
522
        $rs = sql(
0 ignored issues
show
Deprecated Code introduced by
The function sql() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
523
            "SELECT `cache_lists`.`id`, `cache_lists`.`user_id`, `user`.`username`,
524
                    $nameField `name`,
525
                    `cache_lists`.`is_public` `visibility`, `cache_lists`.`password`,
526
                    `cache_lists`.`description`, `cache_lists`.`desc_htmledit`,
527
                    `cache_lists`.`user_id`='&1' `own_list`,
528
                    `stat_cache_lists`.`entries`, `stat_cache_lists`.`watchers`,
529
                    `w`.`user_id` IS NOT NULL `watched_by_me`,
530
                    `b`.`user_id` IS NOT NULL `bookmarked`,
531
                    $prio `prio`
532
             FROM `cache_lists`
533
             LEFT JOIN `stat_cache_lists` ON `stat_cache_lists`.`cache_list_id`=`cache_lists`.`id`
534
             LEFT JOIN `user` ON `user`.`user_id`=`cache_lists`.`user_id`
535
             LEFT JOIN `cache_list_watches` `w` ON `w`.`cache_list_id`=`cache_lists`.`id` AND `w`.`user_id`='&1'
536
             LEFT JOIN `cache_list_bookmarks` `b` ON `b`.`cache_list_id`=`cache_lists`.`id` AND `b`.`user_id`='&1'
537
             WHERE $condition
538
             ORDER BY `prio`, $nameField
539
             LIMIT &2,&3",
540
            $login->userid,
541
            (int) $startat,
542
            (int) $maxitems
543
        );
544
545
        $lists = sql_fetch_assoc_table($rs);
0 ignored issues
show
Documentation introduced by
$rs is of type object<mysqli_result>, but the function expects a resource.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Deprecated Code introduced by
The function sql_fetch_assoc_table() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
546
        foreach ($lists as &$list) {
547
            $list['description_for_display'] = use_current_protocol_in_html($list['description']);
548
        }
549
550
        return $lists;
551
    }
552
553
    // other
554
    public static function getMyLastAddedToListId()
555
    {
556
        global $login;
557
        $login->verify();
558
559
        $maxDate = sql_value("SELECT MAX(`last_added`) FROM `cache_lists` WHERE `user_id`='&1'", null, $login->userid);
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
560
        if (!$maxDate) {
561
            return 0;
562
        }
563
564
        return sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
565
            "SELECT `id` FROM `cache_lists`
566
             WHERE `user_id`='&1' AND `last_added`='&2'
567
             LIMIT 1",
568
            0,
569
            $login->userid,
570
            $maxDate
571
        );
572
    }
573
574
    public static function watchingCacheByListsCount($userId, $cacheId)
575
    {
576
        if (!$userId) {
577
            return 0;
578
        }
579
580
        return sql_value(
0 ignored issues
show
Deprecated Code introduced by
The function sql_value() has been deprecated with message: use DBAL Conenction instead. See adminreports.php for an example implementation

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
581
            "SELECT COUNT(*)
582
             FROM `cache_list_watches` `clw`, `cache_list_items` `cli`
583
             WHERE `clw`.`user_id`='&1' AND `cli`.`cache_id`='&2' AND `clw`.`cache_list_id`=`cli`.`cache_list_id`",
584
            0,
585
            $userId,
586
            $cacheId
587
        );
588
    }
589
}
590