1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace XoopsModules\Adslight; |
6
|
|
|
|
7
|
|
|
/* |
8
|
|
|
* You may not change or alter any portion of this comment or credits |
9
|
|
|
* of supporting developers from this source code or any supporting source code |
10
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
19
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
20
|
|
|
* @author XOOPS Development Team |
21
|
|
|
* @author Pascal Le Boustouller: original author ([email protected]) |
22
|
|
|
* @author Luc Bizet (www.frxoops.org) |
23
|
|
|
* @author jlm69 (www.jlmzone.com) |
24
|
|
|
* @author mamba (www.xoops.org) |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Protection against inclusion outside the site |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Includes of form objects and uploader |
33
|
|
|
*/ |
34
|
|
|
require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
35
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
36
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
37
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* light_pictures class. |
41
|
|
|
* $this class is responsible for providing data access mechanisms to the data source |
42
|
|
|
* of XOOPS user class objects. |
43
|
|
|
*/ |
44
|
|
|
class Pictures extends \XoopsObject |
45
|
|
|
{ |
46
|
|
|
/** |
47
|
|
|
* @var \XoopsMySQLDatabase |
48
|
|
|
*/ |
49
|
|
|
public $db; |
50
|
|
|
public $helper; |
51
|
|
|
// constructor |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param null $id |
|
|
|
|
55
|
|
|
* @param array|null $lid |
56
|
|
|
*/ |
57
|
|
|
public function __construct( |
58
|
|
|
$id = null, |
|
|
|
|
59
|
|
|
$lid = null |
60
|
|
|
) { |
61
|
|
|
$this->helper = Helper::getInstance(); |
62
|
|
|
$this->db = \XoopsDatabaseFactory::getDatabaseConnection(); |
63
|
|
|
$this->initVar('cod_img', \XOBJ_DTYPE_INT, null, false, 10); |
64
|
|
|
$this->initVar('title', \XOBJ_DTYPE_TXTBOX, null, false); |
65
|
|
|
$this->initVar('date_created', \XOBJ_DTYPE_INT, 0, false); |
66
|
|
|
$this->initVar('date_updated', \XOBJ_DTYPE_INT, 0, false); |
67
|
|
|
$this->initVar('lid', \XOBJ_DTYPE_INT, null, false, 10); |
68
|
|
|
$this->initVar('uid_owner', \XOBJ_DTYPE_TXTBOX, null, false); |
69
|
|
|
$this->initVar('url', \XOBJ_DTYPE_TXTBOX, null, false); |
70
|
|
|
if (!empty($lid)) { |
71
|
|
|
if (\is_array($lid)) { |
|
|
|
|
72
|
|
|
$this->assignVars($lid); |
73
|
|
|
} else { |
74
|
|
|
$this->load((int)$lid); |
75
|
|
|
} |
76
|
|
|
} else { |
77
|
|
|
$this->setNew(); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param $id |
83
|
|
|
*/ |
84
|
|
|
public function load($id): void |
85
|
|
|
{ |
86
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('adslight_pictures') . ' WHERE cod_img=' . $id . ' '; |
87
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
|
|
|
|
88
|
|
|
$this->assignVars($myrow); |
|
|
|
|
89
|
|
|
if (!$myrow) { |
90
|
|
|
$this->setNew(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param array $criteria |
96
|
|
|
* @param bool $asobject |
97
|
|
|
* @param string $sort |
98
|
|
|
* @param string $cat_order |
99
|
|
|
* @param int $limit |
100
|
|
|
* @param int $start |
101
|
|
|
* @internal param string $order |
102
|
|
|
* @deprecated this should be handled through {@see PicturesHandler} |
103
|
|
|
*/ |
104
|
|
|
public function getAllPictures( |
105
|
|
|
$criteria = [], |
106
|
|
|
$asobject = false, |
107
|
|
|
$sort = 'cod_img', |
108
|
|
|
$cat_order = 'ASC', |
109
|
|
|
$limit = 0, |
110
|
|
|
$start = 0 |
111
|
|
|
): array { |
112
|
|
|
/** @var \XoopsMySQLDatabase $xoopsDB */ |
113
|
|
|
$xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
114
|
|
|
$ret = []; |
115
|
|
|
$where_query = ''; |
116
|
|
|
if (\is_array($criteria) && \count($criteria) > 0) { |
117
|
|
|
$where_query = ' WHERE'; |
118
|
|
|
foreach ($criteria as $c) { |
119
|
|
|
$where_query .= " {$c} AND"; |
120
|
|
|
} |
121
|
|
|
$where_query = \mb_substr($where_query, 0, -4); |
122
|
|
|
} elseif (!\is_array($criteria) && $criteria) { |
123
|
|
|
$where_query = " WHERE {$criteria}"; |
124
|
|
|
} |
125
|
|
|
if ($asobject) { |
126
|
|
|
$sql = 'SELECT * FROM ' . $xoopsDB->prefix('adslight_pictures') . "${where_query} ORDER BY ${sort} ${cat_order}"; |
127
|
|
|
$result = $xoopsDB->query($sql, $limit, $start); |
128
|
|
|
while (false !== ($myrow = $xoopsDB->fetchArray($result))) { |
|
|
|
|
129
|
|
|
$ret[] = new self($myrow); |
130
|
|
|
} |
131
|
|
|
} else { |
132
|
|
|
$sql = 'SELECT cod_img FROM ' . $xoopsDB->prefix('adslight_pictures') . "${where_query} ORDER BY ${sort} ${cat_order}"; |
133
|
|
|
$result = $xoopsDB->query($sql, $limit, $start); |
134
|
|
|
while (false !== ($myrow = $xoopsDB->fetchArray($result))) { |
135
|
|
|
$ret[] = $myrow['cog_img']; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
return $ret; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Get form |
144
|
|
|
* |
145
|
|
|
* @param null |
146
|
|
|
* @return Form\PicturesForm |
147
|
|
|
*/ |
148
|
|
|
public function getForm(): Form\PicturesForm |
149
|
|
|
{ |
150
|
|
|
$form = new Form\PicturesForm($this); |
151
|
|
|
return $form; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
// ------------------------------------------------------------------------- |
156
|
|
|
// ------------------light_pictures user handler class ------------------- |
157
|
|
|
// ------------------------------------------------------------------------- |
158
|
|
|
|