Completed
Pull Request — master (#26)
by Goffy
01:45
created

print.php (2 issues)

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
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
include_once XOOPS_ROOT_PATH . '/header.php';
32
33
error_reporting(0);
34
$xoopsLogger->activated = false;
35
36
$GLOBALS['xoopsTpl']->assign('xoops_pagetitle', _AM_XNEWSLETTER_LETTER_ACTION_PREVIEW);
37
38
// get letter_id
39
$letter_id = XoopsRequest::getString('letter_id', 'list');
40
// check letter_id
41
if ($letter_id < 1) {
42
    redirect_header('letter.php', 3, _AM_XNEWSLETTER_ERROR_NO_VALID_ID);
43
}
44
45
$content = '';
46
$letterObj = $xnewsletter->getHandler('letter')->get($letter_id);
47
if ($letterObj && $letterObj->getVar('letter_template') != '') {
48
    $letterTemplate = "{$letterTemplatePath}{$letterObj->getVar('letter_template')}.tpl";
49
    // subscr data
50
    $xoopsTpl->assign('sex', _AM_XNEWSLETTER_SUBSCR_SEX_PREVIEW);
51
    $xoopsTpl->assign('salutation', _AM_XNEWSLETTER_SUBSCR_SEX_PREVIEW); // new from v1.3
52
    $xoopsTpl->assign('firstname', _AM_XNEWSLETTER_SUBSCR_FIRSTNAME_PREVIEW);
53
    $xoopsTpl->assign('lastname', _AM_XNEWSLETTER_SUBSCR_LASTNAME_PREVIEW);
54
    $xoopsTpl->assign('subscr_email', _AM_XNEWSLETTER_SUBSCR_EMAIL_PREVIEW);
55
    $xoopsTpl->assign('email', _AM_XNEWSLETTER_SUBSCR_EMAIL_PREVIEW); // new from v1.3
56
    // letter data
57
    $xoopsTpl->assign('title', $letterObj->getVar('letter_title', 'n')); // new from v1.3
58
    $xoopsTpl->assign('content', $letterObj->getVar('letter_content', 'n'));
59
    // extra
60
    $xoopsTpl->assign('date', time()); // new from v1.3
61
    $xoopsTpl->assign('unsubscribe_url', XOOPS_URL . '/modules/xnewsletter/');
62
    $xoopsTpl->assign('catsubscr_id', '0'); // ???
63
64
    $letter_array = $letterObj->toArray();
65
    $letter_array['letter_content_templated'] = $xoopsTpl->fetch($letterTemplate);
66
    $letter_array['letter_created_timestamp'] = formatTimestamp($letterObj->getVar('letter_created'), $xnewsletter->getConfig('dateformat'));
67
    $letter_array['letter_submitter_name'] = XoopsUserUtility::getUnameFromId($letterObj->getVar('letter_submitter'));
68
    $xoopsTpl->assign('letter', $letter_array);
69
70
// IN PROGRESS
71
// IN PROGRESS
72
// IN PROGRESS
73
74
    $content .= "<h2>{$letterObj->getVar('letter_title')}</h2>";
75
    $content .= "<div style='clear:both;'><div style='padding:10px;border:1px solid black;'>";
76
77
    preg_match('/db:([0-9]*)/', $letterObj->getVar('letter_template'), $matches);
78 View Code Duplication
    if(isset($matches[1]) && ($templateObj = $xnewsletter->getHandler('template')->get((int)$matches[1]))) {
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.

Loading history...
79
        // get template from database
80
        $htmlBody = $xoopsTpl->fetchFromData($templateObj->getVar('template_content', 'n'));
81
    } else {
82
        // get template from filesystem
83
        $template_path = XOOPS_ROOT_PATH . '/modules/xnewsletter/language/' . $GLOBALS['xoopsConfig']['language'] . '/templates/';
84
        if (!is_dir($template_path)) $template_path = XOOPS_ROOT_PATH . '/modules/xnewsletter/language/english/templates/';
85
        $template = $template_path . $letterObj->getVar('letter_template') . '.tpl';
86
        $htmlBody = $xoopsTpl->fetch($template);
87
    }
88
    $content .= $htmlBody;
89
    $content .=  '</div></div>\n';
90
}
91
92
if ($content == '') {
93
    redirect_header('letter.php', 3, _AM_XNEWSLETTER_SEND_ERROR_NO_LETTERCONTENT);
94
}
95
96
$xoopsTpl->assign('xoopsConfig', $xoopsConfig);
97
$xoopsTpl->assign('xoops_meta_keywords', $xoops_meta_keywords);
98
$xoopsTpl->assign('xoops_meta_description', $xoops_meta_description);
99
100
xnewsletter_printPage($content);
101
102
//******************************************************************
103
//*********************** Printfunktion ****************************
104
//******************************************************************
105
/**
106
 * @param $content
107
 */
108
function xnewsletter_printPage($content) {
109
    global $xoopsConfig, $xoops_meta_keywords, $xoops_meta_description;
110
    $myts = MyTextSanitizer::getInstance();
0 ignored issues
show
$myts is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
111
112
    echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
113
         . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . _LANGCODE . '" lang="' . _LANGCODE . "\">\n";
114
115
    echo "<head>\n";
116
    echo '<title>' . $xoopsConfig['sitename'] . '</title>\n';
117
    echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\n';
118
    echo '<meta name="AUTHOR" content="' . $xoopsConfig['sitename'] . '" />\n';
119
    echo '<meta name="keywords" content="' . $xoops_meta_keywords . '" />\n';
120
    echo '<meta name="COPYRIGHT" content="Copyright (c) 2012 by ' . $xoopsConfig['sitename'] . '" />\n';
121
    echo '<meta name="DESCRIPTION" content="' . $xoops_meta_description . '" />\n';
122
    echo '<meta name="GENERATOR" content="XOOPS" />\n';
123
    echo '<!-- Sheet Css -->';
124
    echo '<link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="' . XOOPS_URL . '/xoops.css" />\n';
125
    echo '<link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="' . XOOPS_URL . '/themes/default/style.css" />\n';
126
    echo '<link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="' . XOOPS_URL . '/modules/xnewsletter/assets/css/module.css" />\n';
127
128
?>
129
    <script type="text/javascript">
130
    // <![CDATA[
131
    /*------------------------------------------------------------------------------
132
    Function:       footnoteLinks()
133
    Author:         Aaron Gustafson (aaron at easy-designs dot net)
134
    Creation Date:  8 May 2005
135
    Version:        1.3
136
    Homepage:       http://www.easy-designs.net/code/footnoteLinks/
137
    License:        Creative Commons Attribution-ShareAlike 2.0 License
138
                    http://creativecommons.org/licenses/by-sa/2.0/
139
    Note:           This version has reduced functionality as it is a demo of
140
                    the script's development
141
    ------------------------------------------------------------------------------*/
142
    function footnoteLinks(containerID,targetID) {
143
        if (!document.getElementById ||
144
            !document.getElementsByTagName ||
145
            !document.createElement) return false;
146
        if (!document.getElementById(containerID) ||
147
            !document.getElementById(targetID)) return false;
148
          var container = document.getElementById(containerID);
149
          var target    = document.getElementById(targetID);
150
          var h2        = document.createElement('h2');
151
          addClass.apply(h2,['printOnly']);
152
          var h2_txt    = document.createTextNode('<?php echo '_MA_NW_LINKS'; ?>');
153
          h2.appendChild(h2_txt);
154
          var coll = container.getElementsByTagName('*');
155
          var ol   = document.createElement('ol');
156
          addClass.apply(ol,['printOnly']);
157
          var myArr = [];
158
          var thisLink;
159
          var num = 1;
160
          for (var i=0; i<coll.length; i++) {
161
            if ( coll[i].getAttribute('href') ||
162
                coll[i].getAttribute('cite') ) {
163
                thisLink = coll[i].getAttribute('href') ? coll[i].href : coll[i].cite;
164
                var note = document.createElement('sup');
165
                addClass.apply(note,['printOnly']);
166
                var note_txt;
167
                var j = inArray.apply(myArr,[thisLink]);
168
                if (j || j===0) { // if a duplirolee
169
                    // get the corresponding number from
170
                    // the array of used links
171
                    note_txt = document.createTextNode(j+1);
172
                } else {
173
                    // if not a duplirolee
174
                    var li     = document.createElement('li');
175
                    var li_txt = document.createTextNode(thisLink);
176
                    li.appendChild(li_txt);
177
                    ol.appendChild(li);
178
                    myArr.push(thisLink);
179
                    note_txt = document.createTextNode(num);
180
                    num++;
181
                }
182
                note.appendChild(note_txt);
183
                if (coll[i].tagName.toLowerCase() == 'blockquote') {
184
                    var lastChild = lastChildContainingText.apply(coll[i]);
185
                    lastChild.appendChild(note);
186
                } else {
187
                    coll[i].parentNode.insertBefore(note, coll[i].nextSibling);
188
                }
189
            }
190
        }
191
      target.appendChild(h2);
192
      target.appendChild(ol);
193
194
      return true;
195
    }
196
    // ]]>
197
    </script>
198
    <script type="text/javascript">
199
    // <![CDATA[
200
    /*------------------------------------------------------------------------------
201
    Excerpts from the jsUtilities Library
202
    Version:        2.1
203
    Homepage:       http://www.easy-designs.net/code/jsUtilities/
204
    License:        Creative Commons Attribution-ShareAlike 2.0 License
205
                    http://creativecommons.org/licenses/by-sa/2.0/
206
    Note:           If you change or improve on this script, please let us know.
207
    ------------------------------------------------------------------------------*/
208
    if (Array.prototype.push == null) {
209
        Array.prototype.push = function(item) {
210
            this[this.length] = item;
211
212
            return this.length;
213
        };
214
    };
215
    // ---------------------------------------------------------------------
216
    //                  function.apply (if unsupported)
217
    //           Courtesy of Aaron Boodman - http://youngpup.net
218
    // ---------------------------------------------------------------------
219
    if (!Function.prototype.apply) {
220
        Function.prototype.apply = function(oScope, args) {
221
            var sarg = [];
222
            var rtrn, call;
223
            if (!oScope) oScope = window;
224
            if (!args) args = [];
225
            for (var i = 0; i < args.length; i++) {
226
                sarg[i] = "args["+i+"]";
227
            };
228
            call = "oScope.__applyTemp__(" + sarg.join(",") + ");";
229
            oScope.__applyTemp__ = this;
230
            rtrn = eval(call);
231
            oScope.__applyTemp__ = null;
232
233
            return rtrn;
234
        };
235
    };
236
    function inArray(needle) {
237
        for (var i=0; i < this.length; i++) {
238
            if (this[i] === needle) {
239
                return i;
240
            }
241
        }
242
243
    return false;
244
    }
245
    function addClass(theClass) {
246
        if (this.className != '') {
247
            this.className += ' ' + theClass;
248
        } else {
249
            this.className = theClass;
250
        }
251
    }
252
    function lastChildContainingText() {
253
        var testChild = this.lastChild;
254
        var contentCntnr = ['p','li','dd'];
255
        while (testChild.nodeType != 1) {
256
            testChild = testChild.previousSibling;
257
        }
258
        var tag = testChild.tagName.toLowerCase();
259
        var tagInArr = inArray.apply(contentCntnr, [tag]);
260
        if (!tagInArr && tagInArr!==0) {
261
            testChild = lastChildContainingText.apply(testChild);
262
        }
263
264
        return testChild;
265
    }
266
    // ]]>
267
    </script>
268
    <style type="text/css" media="screen">
269
        .printOnly {
270
        display: none;
271
    }
272
    </style>
273
    </head>
274
    <body bgcolor="#ffffff" text="#000000" onload="window.print()">
275
<?php
276
    echo $content;
277
?>
278
    </body>
279
    </html>
280
<?php
281
}
282