|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/* |
|
3
|
|
|
------------------------------------------------------------------------- |
|
4
|
|
|
ADSLIGHT 2 : Module for Xoops |
|
5
|
|
|
|
|
6
|
|
|
Redesigned and ameliorate By Luc Bizet user at www.frxoops.org |
|
7
|
|
|
Started with the Classifieds module and made MANY changes |
|
8
|
|
|
Website : http://www.luc-bizet.fr |
|
9
|
|
|
Contact : [email protected] |
|
10
|
|
|
------------------------------------------------------------------------- |
|
11
|
|
|
Original credits below Version History |
|
12
|
|
|
########################################################################## |
|
13
|
|
|
# Classified Module for Xoops # |
|
14
|
|
|
# By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com # |
|
15
|
|
|
# Started with the MyAds module and made MANY changes # |
|
16
|
|
|
########################################################################## |
|
17
|
|
|
Original Author: Pascal Le Boustouller |
|
18
|
|
|
Author Website : [email protected] |
|
19
|
|
|
Licence Type : GPL |
|
20
|
|
|
------------------------------------------------------------------------- |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
use Xmf\Request; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Protection against inclusion outside the site |
|
27
|
|
|
*/ |
|
28
|
|
|
// defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Includes of form objects and uploader |
|
32
|
|
|
*/ |
|
33
|
|
|
require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
|
|
|
|
|
|
34
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
|
35
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
36
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
|
37
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/adslight/class/Utility.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
|
|
|
public $db; |
|
47
|
|
|
// constructor |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param null $id |
|
|
|
|
|
|
51
|
|
|
* @param null|array $lid |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct($id = null, $lid = null) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->db = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
|
|
|
|
|
56
|
|
|
$this->initVar('cod_img', XOBJ_DTYPE_INT, null, false, 10); |
|
|
|
|
|
|
57
|
|
|
$this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false); |
|
|
|
|
|
|
58
|
|
|
$this->initVar('date_added', XOBJ_DTYPE_TXTBOX, null, false); |
|
59
|
|
|
$this->initVar('date_modified', XOBJ_DTYPE_TXTBOX, null, false); |
|
60
|
|
|
$this->initVar('lid', XOBJ_DTYPE_INT, null, false, 10); |
|
61
|
|
|
$this->initVar('uid_owner', XOBJ_DTYPE_TXTBOX, null, false); |
|
62
|
|
|
$this->initVar('url', XOBJ_DTYPE_TXTBOX, null, false); |
|
63
|
|
|
if (!empty($lid)) { |
|
64
|
|
|
if (is_array($lid)) { |
|
|
|
|
|
|
65
|
|
|
$this->assignVars($lid); |
|
66
|
|
|
} else { |
|
67
|
|
|
$this->load((int)$lid); |
|
68
|
|
|
} |
|
69
|
|
|
} else { |
|
70
|
|
|
$this->setNew(); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param $id |
|
76
|
|
|
*/ |
|
77
|
|
|
public function load($id) |
|
78
|
|
|
{ |
|
79
|
|
|
global $moduleDirName; |
|
80
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('adslight_pictures') . ' WHERE cod_img=' . $id . ''; |
|
81
|
|
|
$myrow = $this->db->fetchArray($this->db->query($sql)); |
|
82
|
|
|
$this->assignVars($myrow); |
|
83
|
|
|
if (!$myrow) { |
|
84
|
|
|
$this->setNew(); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param array $criteria |
|
90
|
|
|
* @param bool $asobject |
|
91
|
|
|
* @param string $sort |
|
92
|
|
|
* @param string $cat_order |
|
93
|
|
|
* @param int $limit |
|
94
|
|
|
* @param int $start |
|
95
|
|
|
* @return array |
|
96
|
|
|
* @internal param string $order |
|
97
|
|
|
* @deprecated this should be handled through {@see PicturesHandler} |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getAllPictures($criteria = [], $asobject = false, $sort = 'cod_img', $cat_order = 'ASC', $limit = 0, $start = 0) |
|
100
|
|
|
{ |
|
101
|
|
|
global $moduleDirName; |
|
102
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
103
|
|
|
$ret = []; |
|
104
|
|
|
$where_query = ''; |
|
105
|
|
|
if (is_array($criteria) && count($criteria) > 0) { |
|
106
|
|
|
$where_query = ' WHERE'; |
|
107
|
|
|
foreach ($criteria as $c) { |
|
108
|
|
|
$where_query .= " {$c} AND"; |
|
109
|
|
|
} |
|
110
|
|
|
$where_query = substr($where_query, 0, -4); |
|
111
|
|
|
} elseif (!is_array($criteria) && $criteria) { |
|
112
|
|
|
$where_query = " WHERE {$criteria}"; |
|
113
|
|
|
} |
|
114
|
|
|
if (!$asobject) { |
|
115
|
|
|
$sql = 'SELECT cod_img FROM ' . $db->prefix('adslight_pictures') . "$where_query ORDER BY $sort $cat_order"; |
|
116
|
|
|
$result = $db->query($sql, $limit, $start); |
|
117
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
|
118
|
|
|
$ret[] = $myrow['cog_img']; |
|
119
|
|
|
} |
|
120
|
|
|
} else { |
|
121
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('adslight_pictures') . "$where_query ORDER BY $sort $cat_order"; |
|
122
|
|
|
$result = $db->query($sql, $limit, $start); |
|
123
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
|
124
|
|
|
$ret[] = new Pictures($myrow); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return $ret; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
// ------------------------------------------------------------------------- |
|
133
|
|
|
// ------------------light_pictures user handler class ------------------- |
|
134
|
|
|
// ------------------------------------------------------------------------- |
|
135
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.