Completed
Pull Request — master (#4)
by Michael
03:05
created

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 94 and the first side effect is on line 45.

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.

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