These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | * **************************************************************************** |
||
26 | */ |
||
27 | |||
28 | $currentFile = basename(__FILE__); |
||
29 | include_once __DIR__ . '/header.php'; |
||
30 | |||
31 | $op = XoopsRequest::getString('op', 'welcome'); |
||
32 | |||
33 | switch ($op) { |
||
34 | case 'welcome' : |
||
35 | default : |
||
36 | $xoopsOption['template_main'] = "{$xnewsletter->getModule()->dirname()}_index.tpl"; |
||
37 | include XOOPS_ROOT_PATH . '/header.php'; |
||
38 | |||
39 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
40 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
41 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
42 | |||
43 | // Breadcrumb |
||
44 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
45 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
46 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
47 | |||
48 | $xoopsTpl->assign('welcome_message', $xnewsletter->getConfig('welcome_message')); |
||
49 | $xoopsTpl->assign('xnewsletter_content', _MA_XNEWSLETTER_WELCOME); // this definition is not removed for backward compatibility issues |
||
50 | break; |
||
51 | |||
52 | case 'show_preview' : |
||
53 | case 'show_letter_preview' : |
||
54 | $xoopsOption['template_main'] = "{$xnewsletter->getModule()->dirname()}_letter_preview.tpl"; |
||
55 | include XOOPS_ROOT_PATH . '/header.php'; |
||
56 | |||
57 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
58 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
59 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
60 | |||
61 | // Breadcrumb |
||
62 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
63 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
64 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
65 | |||
66 | $xoopsTpl->assign('welcome_message', $xnewsletter->getConfig('welcome_message')); |
||
67 | |||
68 | // get letter_id |
||
69 | $letter_id = XoopsRequest::getInt('letter_id', 0); |
||
70 | // get letter object |
||
71 | $letterObj = $xnewsletter->getHandler('letter')->get($letter_id); |
||
72 | // subscr data |
||
73 | $xoopsTpl->assign('sex', _AM_XNEWSLETTER_SUBSCR_SEX_PREVIEW); |
||
74 | $xoopsTpl->assign('salutation', _AM_XNEWSLETTER_SUBSCR_SEX_PREVIEW); // new from v1.3 |
||
75 | $xoopsTpl->assign('firstname', _AM_XNEWSLETTER_SUBSCR_FIRSTNAME_PREVIEW); |
||
76 | $xoopsTpl->assign('lastname', _AM_XNEWSLETTER_SUBSCR_LASTNAME_PREVIEW); |
||
77 | $xoopsTpl->assign('subscr_email', _AM_XNEWSLETTER_SUBSCR_EMAIL_PREVIEW); |
||
78 | $xoopsTpl->assign('email', _AM_XNEWSLETTER_SUBSCR_EMAIL_PREVIEW); // new from v1.3 |
||
79 | // letter data |
||
80 | $xoopsTpl->assign('title', $letterObj->getVar('letter_title', 'n')); // new from v1.3 |
||
81 | $xoopsTpl->assign('content', $letterObj->getVar('letter_content', 'n')); |
||
82 | // extra data |
||
83 | $xoopsTpl->assign('date', time()); // new from v1.3 |
||
84 | $xoopsTpl->assign('unsubscribe_url', XOOPS_URL . '/modules/xnewsletter/'); |
||
85 | $xoopsTpl->assign('catsubscr_id', '0'); |
||
86 | |||
87 | $letter_array = $letterObj->toArray(); |
||
88 | |||
89 | preg_match('/db:([0-9]*)/', $letterObj->getVar('letter_template'), $matches); |
||
90 | View Code Duplication | if(isset($matches[1]) && ($templateObj = $xnewsletter->getHandler('template')->get((int)$matches[1]))) { |
|
91 | // get template from database |
||
92 | $htmlBody = $xoopsTpl->fetchFromData($templateObj->getVar('template_content', 'n')); |
||
93 | } else { |
||
94 | // get template from filesystem |
||
95 | $template_path = XOOPS_ROOT_PATH . '/modules/xnewsletter/language/' . $GLOBALS['xoopsConfig']['language'] . '/templates/'; |
||
96 | if (!is_dir($template_path)) $template_path = XOOPS_ROOT_PATH . '/modules/xnewsletter/language/english/templates/'; |
||
97 | $template = $template_path . $letterObj->getVar('letter_template') . '.tpl'; |
||
98 | $htmlBody = $xoopsTpl->fetch($template); |
||
99 | } |
||
100 | $textBody = xnewsletter_html2text($htmlBody); // new from v1.3 |
||
101 | |||
102 | $letter_array['letter_content_templated'] = $htmlBody; |
||
103 | $letter_array['letter_content_templated_html'] = $htmlBody; |
||
104 | $letter_array['letter_content_templated_text'] = $textBody; // new from v1.3 |
||
105 | $letter_array['letter_created_timestamp'] = formatTimestamp($letterObj->getVar('letter_created'), $xnewsletter->getConfig('dateformat')); |
||
106 | $letter_array['letter_submitter_name'] = XoopsUserUtility::getUnameFromId($letterObj->getVar('letter_submitter')); |
||
107 | $xoopsTpl->assign('letter', $letter_array); |
||
108 | break; |
||
109 | |||
110 | case 'list_letter' : |
||
111 | exit('IN_PROGRESS: use op=list_letters instead of op=list_letter'); |
||
112 | break; |
||
113 | case 'list_letters' : |
||
114 | $xoopsOption['template_main'] = "{$xnewsletter->getModule()->dirname()}_index_list_letters.tpl"; |
||
115 | include XOOPS_ROOT_PATH . '/header.php'; |
||
116 | |||
117 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
118 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
119 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
120 | |||
121 | // Breadcrumb |
||
122 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
123 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
124 | $breadcrumb->addLink(_MD_XNEWSLETTER_LIST, ''); |
||
125 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
126 | |||
127 | $xoopsTpl->assign('welcome_message', $xnewsletter->getConfig('welcome_message')); |
||
128 | |||
129 | // get letters array |
||
130 | $criteria = new CriteriaCompo(); |
||
131 | $criteria->setSort('letter_id'); |
||
132 | $criteria->setOrder('DESC'); |
||
133 | $letterObjs = $xnewsletter->getHandler('letter')->getAll($criteria); |
||
134 | |||
135 | if ($xnewsletter->getHandler('letter')->getCount() > 0) { |
||
136 | // get newsletters available for current user |
||
137 | $gperm_handler = xoops_getHandler('groupperm'); |
||
138 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : [0 => XOOPS_GROUP_ANONYMOUS]; |
||
139 | |||
140 | $letters_array = []; |
||
141 | foreach ($letterObjs as $letterObj) { |
||
142 | $letter_array = $letterObj->toArray(); |
||
143 | $letter_array['letter_content'] = $myts->undoHtmlSpecialChars($letterObj->getVar('letter_content')); //needed when using GUI editors (e.g. tinymce) |
||
144 | $letter_array['letter_created_timestamp'] = formatTimestamp($letterObj->getVar('letter_created'), $xnewsletter->getConfig('dateformat')); |
||
145 | $letter_array['letter_submitter_name'] = XoopsUserUtility::getUnameFromId($letterObj->getVar('letter_submitter')); |
||
146 | $catsAvailableCount = 0; |
||
147 | $cats_string = ''; |
||
148 | $cat_ids = explode('|' , $letterObj->getVar('letter_cats')); |
||
149 | View Code Duplication | foreach ($cat_ids as $cat_id) { |
|
0 ignored issues
–
show
|
|||
150 | $catObj = $xnewsletter->getHandler('cat')->get($cat_id); |
||
151 | if ($gperm_handler->checkRight('newsletter_read_cat', $catObj->getVar('cat_id'), $groups, $xnewsletter->getModule()->mid())) { |
||
152 | ++$catsAvailableCount; |
||
153 | unset($letter_array['letter_cats']); |
||
154 | $letter_array['letter_cats'][] = $catObj->toArray(); |
||
155 | } |
||
156 | unset($catObj); |
||
157 | } |
||
158 | if ($catsAvailableCount > 0) { |
||
159 | $letters_array[] = $letter_array; |
||
160 | } |
||
161 | } |
||
162 | if (count($letters_array) == 0) { |
||
163 | redirect_header('index.php', 3, _MA_XNEWSLETTER_LETTER_NONEAVAIL); |
||
164 | } |
||
165 | $xoopsTpl->assign('letters', $letters_array); |
||
166 | } else { |
||
167 | redirect_header('index.php', 3, _MA_XNEWSLETTER_LETTER_NONEAVAIL); |
||
168 | } |
||
169 | break; |
||
170 | } |
||
171 | |||
172 | include __DIR__ . '/footer.php'; |
||
173 |
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.