|
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
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
/** |
|
12
|
|
|
* Xoopstube class |
|
13
|
|
|
* |
|
14
|
|
|
* @copyright The XUUPS Project http://sourceforge.net/projects/xuups/ |
|
15
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
|
16
|
|
|
* @package Xoopstube |
|
17
|
|
|
* @subpackage Utils |
|
18
|
|
|
* @since 1.0 |
|
19
|
|
|
* @author trabis <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
// defined('XOOPS_ROOT_PATH') || die('XOOPS Root Path not defined'); |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class XoopstubeXoopstube |
|
25
|
|
|
*/ |
|
26
|
|
|
class XoopstubeXoopstube |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
var $dirname; |
|
|
|
|
|
|
29
|
|
|
var $module; |
|
|
|
|
|
|
30
|
|
|
var $handler; |
|
|
|
|
|
|
31
|
|
|
var $config; |
|
|
|
|
|
|
32
|
|
|
var $debug; |
|
|
|
|
|
|
33
|
|
|
var $debugArray = array(); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param $debug |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function __construct($debug) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->debug = $debug; |
|
41
|
|
|
$this->dirname = basename(dirname(__DIR__)); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param bool $debug |
|
46
|
|
|
* |
|
47
|
|
|
* @return XoopstubeXoopstube |
|
48
|
|
|
*/ |
|
49
|
|
|
static function &getInstance($debug = false) |
|
50
|
|
|
{ |
|
51
|
|
|
static $instance = false; |
|
52
|
|
|
if (!$instance) { |
|
53
|
|
|
$instance = new self($debug); |
|
54
|
|
|
} |
|
55
|
|
|
//error_log("istance: [" . print_r($istance,true) . "]"); |
|
|
|
|
|
|
56
|
|
|
//phpinfo(); |
|
57
|
|
|
//debug_print_backtrace (); |
|
58
|
|
|
return $instance; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
function &getModule() |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
if ($this->module == null) { |
|
64
|
|
|
$this->initModule(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return $this->module; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param null $name |
|
72
|
|
|
* |
|
73
|
|
|
* @return null |
|
74
|
|
|
*/ |
|
75
|
|
|
function getConfig($name = null) |
|
|
|
|
|
|
76
|
|
|
{ |
|
77
|
|
|
if ($this->config == null) { |
|
78
|
|
|
$this->initConfig(); |
|
79
|
|
|
} |
|
80
|
|
|
if (!$name) { |
|
81
|
|
|
$this->addLog("Getting all config"); |
|
82
|
|
|
|
|
83
|
|
|
return $this->config; |
|
84
|
|
|
} |
|
85
|
|
|
if (!isset($this->config[$name])) { |
|
86
|
|
|
$this->addLog("ERROR :: CONFIG '{$name}' does not exist"); |
|
87
|
|
|
|
|
88
|
|
|
return null; |
|
89
|
|
|
} |
|
90
|
|
|
$this->addLog("Getting config '{$name}' : " . print_r($this->config[$name], true)); |
|
91
|
|
|
|
|
92
|
|
|
return $this->config[$name]; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @param null $name |
|
97
|
|
|
* @param null $value |
|
98
|
|
|
* |
|
99
|
|
|
* @return mixed |
|
100
|
|
|
*/ |
|
101
|
|
|
function setConfig($name = null, $value = null) |
|
|
|
|
|
|
102
|
|
|
{ |
|
103
|
|
|
if ($this->config == null) { |
|
104
|
|
|
$this->initConfig(); |
|
105
|
|
|
} |
|
106
|
|
|
$this->config[$name] = $value; |
|
107
|
|
|
$this->addLog("Setting config '{$name}' : " . $this->config[$name]); |
|
108
|
|
|
|
|
109
|
|
|
return $this->config[$name]; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param $name |
|
114
|
|
|
* |
|
115
|
|
|
* @return mixed |
|
116
|
|
|
*/ |
|
117
|
|
|
function &getHandler($name) |
|
118
|
|
|
{ |
|
119
|
|
|
if (!isset($this->handler[$name . '_handler'])) { |
|
120
|
|
|
$this->initHandler($name); |
|
121
|
|
|
} |
|
122
|
|
|
$this->addLog("Getting handler '{$name}'"); |
|
123
|
|
|
|
|
124
|
|
|
return $this->handler[$name . '_handler']; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
function initModule() |
|
|
|
|
|
|
128
|
|
|
{ |
|
129
|
|
|
global $xoopsModule; |
|
|
|
|
|
|
130
|
|
|
if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $this->dirname) { |
|
131
|
|
|
$this->module = $xoopsModule; |
|
132
|
|
|
} else { |
|
133
|
|
|
$hModule = xoops_gethandler('module'); |
|
134
|
|
|
$this->module = $hModule->getByDirname($this->dirname); |
|
135
|
|
|
} |
|
136
|
|
|
$this->addLog('INIT MODULE'); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
function initConfig() |
|
|
|
|
|
|
140
|
|
|
{ |
|
141
|
|
|
$this->addLog('INIT CONFIG'); |
|
142
|
|
|
$hModConfig = xoops_gethandler('config'); |
|
143
|
|
|
$this->config = $hModConfig->getConfigsByCat(0, $this->getModule()->getVar('mid')); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @param $name |
|
148
|
|
|
*/ |
|
149
|
|
|
function initHandler($name) |
|
|
|
|
|
|
150
|
|
|
{ |
|
151
|
|
|
$this->addLog('INIT ' . $name . ' HANDLER'); |
|
152
|
|
|
$this->handler[$name . '_handler'] = xoops_getModuleHandler($name, $this->dirname); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @param $log |
|
157
|
|
|
*/ |
|
158
|
|
|
function addLog($log) |
|
|
|
|
|
|
159
|
|
|
{ |
|
160
|
|
|
if ($this->debug) { |
|
161
|
|
|
if (is_object($GLOBALS['xoopsLogger'])) { |
|
162
|
|
|
$GLOBALS['xoopsLogger']->addExtra($this->module->name(), $log); |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Class WfdownloadsDownloadHandler |
|
170
|
|
|
*/ |
|
171
|
|
|
class XoopstubeXoopstubeHandler extends XoopsPersistableObjectHandler |
|
|
|
|
|
|
172
|
|
|
{ |
|
173
|
|
|
/** |
|
174
|
|
|
* @var WfdownloadsWfdownloads |
|
175
|
|
|
* @access public |
|
176
|
|
|
*/ |
|
177
|
|
|
public $xoopstube = null; |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @param null|object $db |
|
181
|
|
|
*/ |
|
182
|
|
|
public function __construct(&$db) |
|
183
|
|
|
{ |
|
184
|
|
|
parent::__construct($db, 'xoopstube_videos', 'XoopstubeXoopstube', 'lid', 'title'); |
|
185
|
|
|
$this->xoopstube = XoopstubeXoopstube::getInstance(); |
|
|
|
|
|
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Get criteria for active videos |
|
190
|
|
|
* |
|
191
|
|
|
* @return CriteriaElement |
|
|
|
|
|
|
192
|
|
|
*/ |
|
193
|
|
|
public function getActiveCriteria() |
|
194
|
|
|
{ |
|
195
|
|
|
global $xoopsUser; |
|
|
|
|
|
|
196
|
|
|
$gperm_handler = xoops_gethandler('groupperm'); |
|
197
|
|
|
|
|
198
|
|
|
$criteria = new CriteriaCompo(new Criteria('offline', false)); |
|
199
|
|
|
$criteria->add(new Criteria('published', 0, '>')); |
|
200
|
|
|
$criteria->add(new Criteria('published', time(), '<=')); |
|
201
|
|
|
$expiredCriteria = new CriteriaCompo(new Criteria('expired', 0)); |
|
202
|
|
|
$expiredCriteria->add(new Criteria('expired', time(), '>='), 'OR'); |
|
203
|
|
|
$criteria->add($expiredCriteria); |
|
204
|
|
|
// add criteria for categories that the user has permissions for |
|
205
|
|
|
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : array(0 => XOOPS_GROUP_ANONYMOUS); |
|
206
|
|
|
$allowedDownCategoriesIds = $gperm_handler->getItemIds('XTubeCatPerm', $groups, $this->xoopstube->getModule()->mid()); |
|
207
|
|
|
$criteria->add(new Criteria('cid', '(' . implode(',', $allowedDownCategoriesIds) . ')', 'IN')); |
|
208
|
|
|
|
|
209
|
|
|
return $criteria; |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.