These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | /** |
||
13 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
14 | * @license {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
||
15 | * @package |
||
16 | * @since |
||
17 | * @author XOOPS Development Team |
||
18 | */ |
||
19 | |||
20 | /** |
||
21 | * Print an article |
||
22 | * |
||
23 | * This page is used to print an article. The advantage of this script is that you |
||
24 | * only see the article and nothing else. |
||
25 | * |
||
26 | * @package News |
||
27 | * @author Xoops Modules Dev Team |
||
28 | * @copyright (c) XOOPS Project (https://xoops.org) |
||
29 | * |
||
30 | * Parameters received by this page : |
||
31 | * @page_param int storyid Id of news to print |
||
32 | * |
||
33 | * @page_title Story's title - Printer Friendly Page - Topic's title - Site's name |
||
34 | * |
||
35 | * @template_name This page does not use any template |
||
36 | * |
||
37 | */ |
||
38 | include __DIR__ . '/../../mainfile.php'; |
||
39 | require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; |
||
40 | require_once XOOPS_ROOT_PATH . '/modules/news/class/utility.php'; |
||
41 | $storyid = isset($_GET['storyid']) ? (int)$_GET['storyid'] : 0; |
||
42 | if (empty($storyid)) { |
||
43 | redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY); |
||
44 | } |
||
45 | |||
46 | // Verify that the article is published |
||
47 | $story = new NewsStory($storyid); |
||
48 | // Not yet published |
||
49 | View Code Duplication | if (0 == $story->published() || $story->published() > time()) { |
|
0 ignored issues
–
show
|
|||
50 | redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY); |
||
51 | } |
||
52 | |||
53 | // Expired |
||
54 | View Code Duplication | if (0 != $story->expired() && $story->expired() < time()) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
55 | redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY); |
||
56 | } |
||
57 | |||
58 | // Verify permissions |
||
59 | $gpermHandler = xoops_getHandler('groupperm'); |
||
60 | if (is_object($xoopsUser)) { |
||
61 | $groups = $xoopsUser->getGroups(); |
||
62 | } else { |
||
63 | $groups = XOOPS_GROUP_ANONYMOUS; |
||
64 | } |
||
65 | if (!$gpermHandler->checkRight('news_view', $story->topicid(), $groups, $xoopsModule->getVar('mid'))) { |
||
66 | redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM); |
||
67 | } |
||
68 | |||
69 | $xoops_meta_keywords = ''; |
||
70 | $xoops_meta_description = ''; |
||
71 | |||
72 | if ('' !== trim($story->keywords())) { |
||
73 | $xoops_meta_keywords = $story->keywords(); |
||
74 | } else { |
||
75 | $xoops_meta_keywords = NewsUtility::createMetaKeywords($story->hometext() . ' ' . $story->bodytext()); |
||
76 | } |
||
77 | |||
78 | if ('' !== trim($story->description())) { |
||
79 | $xoops_meta_description = $story->description(); |
||
80 | } else { |
||
81 | $xoops_meta_description = strip_tags($story->title()); |
||
82 | } |
||
83 | |||
84 | function PrintPage() |
||
85 | { |
||
86 | global $xoopsConfig, $xoopsModule, $story, $xoops_meta_keywords, $xoops_meta_description; |
||
87 | $myts = MyTextSanitizer::getInstance(); |
||
88 | $datetime = formatTimestamp($story->published(), NewsUtility::getModuleOption('dateformat')); ?> |
||
89 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
||
90 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
||
91 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo _LANGCODE; ?>" lang="<?php echo _LANGCODE; ?>"> |
||
92 | <?php |
||
93 | echo "<head>\n"; |
||
94 | echo '<title>' . $myts->htmlSpecialChars($story->title()) . ' - ' . _NW_PRINTER . ' - ' . $myts->htmlSpecialChars($story->topic_title()) . ' - ' . $xoopsConfig['sitename'] . '</title>'; |
||
95 | echo '<meta http-equiv="Content-Type" content="text/html; charset=' . _CHARSET . '">'; |
||
96 | echo '<meta name="author" content="XOOPS">'; |
||
97 | echo '<meta name="keywords" content="' . $xoops_meta_keywords . '">'; |
||
98 | echo '<meta name="COPYRIGHT" content="Copyright (c) 2014 by ' . $xoopsConfig['sitename'] . '">'; |
||
99 | echo '<meta name="DESCRIPTION" content="' . $xoops_meta_description . '">'; |
||
100 | echo '<meta name="generator" content="XOOPS">'; |
||
101 | echo '<meta name="robots" content="noindex,nofollow">'; |
||
102 | if (file_exists(XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/style.css')) { |
||
103 | echo '<link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="' . XOOPS_URL . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/style.css">'; |
||
104 | } else { |
||
105 | echo '<link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="' . XOOPS_URL . '/language/english/style.css">'; |
||
106 | } |
||
107 | echo '<link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="' . XOOPS_URL . '/modules/news/assets/css/print.css">'; |
||
108 | $supplemental = ''; |
||
109 | if (NewsUtility::getModuleOption('footNoteLinks')) { |
||
110 | $supplemental = "footnoteLinks('content','content'); "; ?> |
||
111 | <script type="text/javascript"> |
||
112 | // <![CDATA[ |
||
113 | /*------------------------------------------------------------------------------ |
||
114 | Function: footnoteLinks() |
||
115 | Author: Aaron Gustafson (aaron at easy-designs dot net) |
||
116 | Creation Date: 8 May 2005 |
||
117 | Version: 1.3 |
||
118 | Homepage: http://www.easy-designs.net/code/footnoteLinks/ |
||
119 | License: Creative Commons Attribution-ShareAlike 2.0 License |
||
120 | http://creativecommons.org/licenses/by-sa/2.0/ |
||
121 | Note: This version has reduced functionality as it is a demo of |
||
122 | the script's development |
||
123 | ------------------------------------------------------------------------------*/ |
||
124 | function footnoteLinks(containerID, targetID) { |
||
125 | if (!document.getElementById || !document.getElementsByTagName || !document.createElement) return false; |
||
126 | if (!document.getElementById(containerID) || !document.getElementById(targetID)) return false; |
||
127 | var container = document.getElementById(containerID); |
||
128 | var target = document.getElementById(targetID); |
||
129 | var h2 = document.createElement('h2'); |
||
130 | addClass.apply(h2, ['printOnly']); |
||
131 | var h2_txt = document.createTextNode('<?php echo _NW_LINKS; ?>'); |
||
132 | h2.appendChild(h2_txt); |
||
133 | var coll = container.getElementsByTagName('*'); |
||
134 | var ol = document.createElement('ol'); |
||
135 | addClass.apply(ol, ['printOnly']); |
||
136 | var myArr = []; |
||
137 | var thisLink; |
||
138 | var num = 1; |
||
139 | for (var i = 0; i < coll.length; i++) { |
||
140 | if (coll[i].getAttribute('href') || |
||
141 | coll[i].getAttribute('cite')) { |
||
142 | thisLink = coll[i].getAttribute('href') ? coll[i].href : coll[i].cite; |
||
143 | var note = document.createElement('sup'); |
||
144 | addClass.apply(note, ['printOnly']); |
||
145 | var note_txt; |
||
146 | var j = inArray.apply(myArr, [thisLink]); |
||
147 | if (j || j === 0) { // if a duplicate |
||
148 | // get the corresponding number from |
||
149 | // the array of used links |
||
150 | note_txt = document.createTextNode(j + 1); |
||
151 | } else { // if not a duplicate |
||
152 | var li = document.createElement('li'); |
||
153 | var li_txt = document.createTextNode(thisLink); |
||
154 | li.appendChild(li_txt); |
||
155 | ol.appendChild(li); |
||
156 | myArr.push(thisLink); |
||
157 | note_txt = document.createTextNode(num); |
||
158 | num++; |
||
159 | } |
||
160 | note.appendChild(note_txt); |
||
161 | if (coll[i].tagName.toLowerCase() === 'blockquote') { |
||
162 | var lastChild = lastChildContainingText.apply(coll[i]); |
||
163 | lastChild.appendChild(note); |
||
164 | } else { |
||
165 | coll[i].parentNode.insertBefore(note, coll[i].nextSibling); |
||
166 | } |
||
167 | } |
||
168 | } |
||
169 | target.appendChild(h2); |
||
170 | target.appendChild(ol); |
||
171 | |||
172 | return true; |
||
173 | } |
||
174 | |||
175 | // ]]> |
||
176 | </script> |
||
177 | <script type="text/javascript"> |
||
178 | // <![CDATA[ |
||
179 | /*------------------------------------------------------------------------------ |
||
180 | Excerpts from the jsUtilities Library |
||
181 | Version: 2.1 |
||
182 | Homepage: http://www.easy-designs.net/code/jsUtilities/ |
||
183 | License: Creative Commons Attribution-ShareAlike 2.0 License |
||
184 | http://creativecommons.org/licenses/by-sa/2.0/ |
||
185 | Note: If you change or improve on this script, please let us know. |
||
186 | ------------------------------------------------------------------------------*/ |
||
187 | if (Array.prototype.push === null) { |
||
188 | Array.prototype.push = function (item) { |
||
189 | this[this.length] = item; |
||
190 | |||
191 | return this.length; |
||
192 | }; |
||
193 | } |
||
194 | // --------------------------------------------------------------------- |
||
195 | // function.apply (if unsupported) |
||
196 | // Courtesy of Aaron Boodman - http://youngpup.net |
||
197 | // --------------------------------------------------------------------- |
||
198 | if (!Function.prototype.apply) { |
||
199 | Function.prototype.apply = function (oScope, args) { |
||
200 | var sarg = []; |
||
201 | var rtrn, call; |
||
202 | if (!oScope) oScope = window; |
||
203 | if (!args) args = []; |
||
204 | for (var i = 0; i < args.length; i++) { |
||
205 | sarg[i] = "args[" + i + "]"; |
||
206 | } |
||
207 | call = "oScope.__applyTemp__(" + sarg.join(",") + ");"; |
||
208 | oScope.__applyTemp__ = this; |
||
209 | rtrn = eval(call); |
||
210 | oScope.__applyTemp__ = null; |
||
211 | |||
212 | return rtrn; |
||
213 | }; |
||
214 | } |
||
215 | |||
216 | function inArray(needle) { |
||
217 | for (var i = 0; i < this.length; i++) { |
||
218 | if (this[i] === needle) { |
||
219 | return i; |
||
220 | } |
||
221 | } |
||
222 | |||
223 | return false; |
||
224 | } |
||
225 | |||
226 | function addClass(theClass) { |
||
227 | if (this.className !== '') { |
||
228 | this.className += ' ' + theClass; |
||
229 | } else { |
||
230 | this.className = theClass; |
||
231 | } |
||
232 | } |
||
233 | |||
234 | function lastChildContainingText() { |
||
235 | var testChild = this.lastChild; |
||
236 | var contentCntnr = ['p', 'li', 'dd']; |
||
237 | while (testChild.nodeType != 1) { |
||
238 | testChild = testChild.previousSibling; |
||
239 | } |
||
240 | var tag = testChild.tagName.toLowerCase(); |
||
241 | var tagInArr = inArray.apply(contentCntnr, [tag]); |
||
242 | if (!tagInArr && tagInArr !== 0) { |
||
243 | testChild = lastChildContainingText.apply(testChild); |
||
244 | } |
||
245 | |||
246 | return testChild; |
||
247 | } |
||
248 | |||
249 | // ]]> |
||
250 | </script> |
||
251 | <style type="text/css" media="screen"> |
||
252 | .printOnly { |
||
253 | display: none; |
||
254 | } |
||
255 | </style> |
||
256 | <?php |
||
257 | } |
||
258 | echo '</head>'; |
||
259 | echo '<body bgcolor="#ffffff" text="#000000" onload="' . $supplemental . ' window.print()"> |
||
260 | <div id="content"> |
||
261 | <table border="0"><tr><td align="center"> |
||
262 | <table border="0" width="100%" cellpadding="0" cellspacing="1" bgcolor="#000000"><tr><td> |
||
263 | <table border="0" width="100%" cellpadding="20" cellspacing="1" bgcolor="#ffffff"><tr><td align="center"> |
||
264 | <img src="' . XOOPS_URL . '/images/logo.png" border="0" alt=""><br><br> |
||
265 | <h3>' . $story->title() . '</h3> |
||
266 | <small><b>' . _NW_DATE . '</b> ' . $datetime . ' | <b>' . _NW_TOPICC . '</b> ' . $myts->htmlSpecialChars($story->topic_title()) . '</small><br><br></td></tr>'; |
||
267 | echo '<tr valign="top" style="font:12px;"><td>' . $story->hometext() . '<br>'; |
||
268 | $bodytext = $story->bodytext(); |
||
269 | $bodytext = str_replace('[pagebreak]', '<br style="page-break-after:always;">', $bodytext); |
||
270 | if ('' !== $bodytext) { |
||
271 | echo $bodytext . '<br><br>'; |
||
272 | } |
||
273 | echo '</td></tr></table></td></tr></table> |
||
274 | <br><br>'; |
||
275 | printf(_NW_THISCOMESFROM, htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES)); |
||
276 | echo '<br><a href="' . XOOPS_URL . '/">' . XOOPS_URL . '</a><br><br> |
||
277 | ' . _NW_URLFORSTORY . ' <!-- Tag below can be used to display Permalink image --><!--img src="' . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/assets/images/x.gif" /--><br> |
||
278 | <a class="ignore" href="' . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/article.php?storyid=' . $story->storyid() . '">' . XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid() . '</a> |
||
279 | </td></tr></table></div> |
||
280 | </body> |
||
281 | </html> |
||
282 | '; |
||
283 | } |
||
284 | |||
285 | PrintPage(); |
||
286 |
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.