1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* **************************************************************************** |
4
|
|
|
* - A Project by Developers TEAM For Xoops - ( https://xoops.org ) |
5
|
|
|
* **************************************************************************** |
6
|
|
|
* XNEWSLETTER - MODULE FOR XOOPS |
7
|
|
|
* Copyright (c) 2007 - 2012 |
8
|
|
|
* Goffy ( wedega.com ) |
9
|
|
|
* |
10
|
|
|
* You may not change or alter any portion of this comment or credits |
11
|
|
|
* of supporting developers from this source code or any supporting |
12
|
|
|
* source code which is considered copyrighted (c) material of the |
13
|
|
|
* original comment or credit authors. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU General Public License for more details. |
19
|
|
|
* --------------------------------------------------------------------------- |
20
|
|
|
* @copyright Goffy ( wedega.com ) |
21
|
|
|
* @license GPL 2.0 |
22
|
|
|
* @package xnewsletter |
23
|
|
|
* @author Goffy ( [email protected] ) |
24
|
|
|
* |
25
|
|
|
* Version : 1 Mon 2012/11/05 14:31:32 : Exp $ |
26
|
|
|
* **************************************************************************** |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
use XoopsModules\Xnewsletter; |
30
|
|
|
|
31
|
|
|
// defined("XOOPS_ROOT_PATH") || die("XOOPS root path not defined"); |
32
|
|
|
require_once dirname(__DIR__) . '/include/common.php'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param $options |
36
|
|
|
* |
37
|
|
|
* @return array |
38
|
|
|
*/ |
39
|
|
|
function b_xnewsletter_catsubscr($options) |
40
|
|
|
{ |
41
|
|
|
global $xoopsUser; |
42
|
|
|
$helper = Xnewsletter\Helper::getInstance(); |
43
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
|
|
|
44
|
|
|
|
45
|
|
|
$catsubscrArray = []; |
46
|
|
|
$type_block = $options[0]; |
47
|
|
|
$nb_catsubscr = $options[1]; |
48
|
|
|
$length_title = $options[2]; |
49
|
|
|
|
50
|
|
|
array_shift($options); |
51
|
|
|
array_shift($options); |
52
|
|
|
array_shift($options); |
53
|
|
|
|
54
|
|
|
$catsubscrCriteria = new \CriteriaCompo(); |
55
|
|
View Code Duplication |
switch ($type_block) { |
|
|
|
|
56
|
|
|
// For the block: catsubscr recents |
57
|
|
|
case 'recent': |
58
|
|
|
$catsubscrCriteria->setSort('catsubscr_created'); |
59
|
|
|
$catsubscrCriteria->setOrder('DESC'); |
60
|
|
|
break; |
61
|
|
|
// For the block: catsubscr of today |
62
|
|
|
case 'day': |
63
|
|
|
$catsubscrCriteria->add(new \Criteria('catsubscr_created', strtotime(date('Y/m/d')), '>=')); |
64
|
|
|
$catsubscrCriteria->add(new \Criteria('catsubscr_created', strtotime(date('Y/m/d')) + 86400, '<=')); |
65
|
|
|
$catsubscrCriteria->setSort('catsubscr_created'); |
66
|
|
|
$catsubscrCriteria->setOrder('ASC'); |
67
|
|
|
break; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$catsubscrCriteria->setLimit($nb_catsubscr); |
71
|
|
|
$catsubscrObjs = $helper->getHandler('Catsubscr')->getAll($catsubscrCriteria); |
72
|
|
|
foreach ($catsubscrObjs as $catsubscr_id => $catsubscrObj) { |
73
|
|
|
$cat_id = $catsubscrObj->getVar('catsubscr_catid'); |
74
|
|
|
if (in_array($cat_id, $options) || '0' == $options[0]) { |
75
|
|
|
$subscr_id = $catsubscrObj->getVar('catsubscr_subscrid'); |
76
|
|
|
$subscrObj = $helper->getHandler('Subscr')->get($subscr_id); |
77
|
|
|
$email = $subscrObj->getVar('subscr_email'); |
78
|
|
|
if ($length_title > 0 && mb_strlen($email) > $length_title) { |
79
|
|
|
$email = mb_substr($email, 0, $length_title) . '...'; |
80
|
|
|
} |
81
|
|
|
$catsubscrArray[$catsubscr_id]['catsubscr_email'] = $email; |
82
|
|
|
|
83
|
|
|
$catObj = $helper->getHandler('Cat')->get($cat_id); |
84
|
|
|
$cat_name = $catObj->getVar('cat_name'); |
85
|
|
|
if ($length_title > 0 && mb_strlen($cat_name) > $length_title) { |
86
|
|
|
$cat_name = mb_substr($cat_name, 0, $length_title) . '...'; |
87
|
|
|
} |
88
|
|
|
$catsubscrArray[$catsubscr_id]['catsubscr_newsletter'] = $cat_name; |
89
|
|
|
$catsubscrArray[$catsubscr_id]['catsubscr_created'] = formatTimestamp($catsubscrObj->getVar('catsubscr_created'), 'S'); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $catsubscrArray; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param $options |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
function b_xnewsletter_catsubscr_edit($options) |
102
|
|
|
{ |
103
|
|
|
global $xoopsUser; |
104
|
|
|
$helper = Xnewsletter\Helper::getInstance(); |
105
|
|
|
|
106
|
|
|
$form = '' . _MB_XNEWSLETTER_LETTER_DISPLAY . "\n"; |
107
|
|
|
$form .= '<input type="hidden" name="options[0]" value="' . $options[0] . '">'; |
108
|
|
|
$form .= '<input name="options[1]" size="5" maxlength="255" value="' . $options[1] . '" type="text"> <br>'; |
109
|
|
|
$form .= '' . _MB_XNEWSLETTER_LETTER_TITLELENGTH . ' : <input name="options[2]" size="5" maxlength="255" value="' . $options[2] . '" type="text"><br><br>'; |
110
|
|
|
array_shift($options); |
111
|
|
|
array_shift($options); |
112
|
|
|
array_shift($options); |
113
|
|
|
$form .= '' . _MB_XNEWSLETTER_LETTER_CATTODISPLAY . '<br><select name="options[]" multiple="multiple" size="5">'; |
114
|
|
|
$form .= '<option value="0" ' . (!in_array(0, $options, true) ? '' : 'selected="selected"') . '>' . _MB_XNEWSLETTER_CATSUBSCR_ALLCAT . '</option>'; |
115
|
|
|
|
116
|
|
|
$catCriteria = new \CriteriaCompo(); |
117
|
|
|
$catCriteria->setSort('cat_id'); |
118
|
|
|
$catCriteria->setOrder('ASC'); |
119
|
|
|
$catObjs = $helper->getHandler('Cat')->getAll($catCriteria); |
120
|
|
|
foreach ($catObjs as $cat_id => $catObj) { |
121
|
|
|
$form .= '<option value="' . $cat_id . '" ' . (!in_array($cat_id, $options, true) ? '' : 'selected="selected"') . '>' . $catObj->getVar('cat_name') . '</option>'; |
122
|
|
|
} |
123
|
|
|
$form .= '</select>'; |
124
|
|
|
|
125
|
|
|
return $form; |
126
|
|
|
} |
127
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.