Completed
Push — master ( 692213...d4ec0d )
by Goffy
03:18 queued 01:37
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 - ( http://www.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 Wed 2012/11/28 22:18:22 :  Exp $
26
 * ****************************************************************************
27
 */
28
29
$currentFile = basename(__FILE__);
30
include_once __DIR__ . "/header.php";
31
32
include_once XOOPS_ROOT_PATH . "/header.php";
33
34
error_reporting(0);
35
$xoopsLogger->activated = false;
36
37
$GLOBALS['xoopsTpl']->assign('xoops_pagetitle', _AM_XNEWSLETTER_LETTER_ACTION_PREVIEW);
38
39
// get letter_id
40
$letter_id = XoopsRequest::getString('letter_id', 'list');
41
// check letter_id
42
if ($letter_id < 1) {
43
    redirect_header("letter.php", 3, _AM_XNEWSLETTER_ERROR_NO_VALID_ID);
44
}
45
46
$content = '';
47
$letterObj = $xnewsletter->getHandler('letter')->get($letter_id);
48
if ($letterObj && $letterObj->getVar('letter_template') != '') {
49
    $letterTemplate = "{$letterTemplatePath}{$letterObj->getVar('letter_template')}.tpl";
50
    // subscr data
51
    $xoopsTpl->assign('sex', _AM_XNEWSLETTER_SUBSCR_SEX_PREVIEW);
52
    $xoopsTpl->assign('salutation', _AM_XNEWSLETTER_SUBSCR_SEX_PREVIEW); // new from v1.3
53
    $xoopsTpl->assign('firstname', _AM_XNEWSLETTER_SUBSCR_FIRSTNAME_PREVIEW);
54
    $xoopsTpl->assign('lastname', _AM_XNEWSLETTER_SUBSCR_LASTNAME_PREVIEW);
55
    $xoopsTpl->assign('subscr_email', _AM_XNEWSLETTER_SUBSCR_EMAIL_PREVIEW);
56
    $xoopsTpl->assign('email', _AM_XNEWSLETTER_SUBSCR_EMAIL_PREVIEW); // new from v1.3
57
    // letter data
58
    $xoopsTpl->assign('title', $letterObj->getVar('letter_title', 'n')); // new from v1.3
59
    $xoopsTpl->assign('content', $letterObj->getVar('letter_content', 'n'));
60
    // extra
61
    $xoopsTpl->assign('date', time()); // new from v1.3
62
    $xoopsTpl->assign('unsubscribe_url', XOOPS_URL . '/modules/xnewsletter/');
63
    $xoopsTpl->assign('catsubscr_id', '0'); // ???
64
65
    $letter_array = $letterObj->toArray();
66
    $letter_array['letter_content_templated'] = $xoopsTpl->fetch($letterTemplate);
67
    $letter_array['letter_created_timestamp'] = formatTimestamp($letterObj->getVar('letter_created'), $xnewsletter->getConfig('dateformat'));
68
    $letter_array['letter_submitter_name'] = XoopsUserUtility::getUnameFromId($letterObj->getVar('letter_submitter'));
69
    $xoopsTpl->assign('letter', $letter_array);
70
71
// IN PROGRESS
72
// IN PROGRESS
73
// IN PROGRESS
74
75
    $content .= "<h2>{$letterObj->getVar('letter_title')}</h2>";
76
    $content .= "<div style='clear:both;'><div style='padding:10px;border:1px solid black;'>";
77
78
    preg_match('/db:([0-9]*)/', $letterObj->getVar("letter_template"), $matches);
79 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...
80
        // get template from database
81
        $htmlBody = $xoopsTpl->fetchFromData($templateObj->getVar('template_content', "n"));
82
    } else {
83
        // get template from filesystem
84
        $template_path = XOOPS_ROOT_PATH . '/modules/xnewsletter/language/' . $GLOBALS['xoopsConfig']['language'] . '/templates/';
85
        if (!is_dir($template_path)) $template_path = XOOPS_ROOT_PATH . '/modules/xnewsletter/language/english/templates/';
86
        $template = $template_path . $letterObj->getVar("letter_template") . ".tpl";
87
        $htmlBody = $xoopsTpl->fetch($template);
88
    }
89
    $content .= $htmlBody;
90
    $content .=  '</div></div>\n';
91
}
92
93
if ($content == '') {
94
    redirect_header("letter.php", 3, _AM_XNEWSLETTER_SEND_ERROR_NO_LETTERCONTENT);
95
}
96
97
$xoopsTpl->assign('xoopsConfig', $xoopsConfig);
98
$xoopsTpl->assign('xoops_meta_keywords', $xoops_meta_keywords);
99
$xoopsTpl->assign('xoops_meta_description', $xoops_meta_description);
100
101
xnewsletter_printPage($content);
102
103
//******************************************************************
104
//*********************** Printfunktion ****************************
105
//******************************************************************
106
/**
107
 * @param $content
108
 */
109
function xnewsletter_printPage($content) {
110
    global $xoopsConfig, $xoops_meta_keywords, $xoops_meta_description;
111
    $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...
112
113
    echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
114
       . "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"" . _LANGCODE . "\" lang=\"" . _LANGCODE . "\">\n";
115
116
    echo "<head>\n";
117
    echo '<title>' . $xoopsConfig['sitename'] . '</title>\n';
118
    echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\n';
119
    echo '<meta name="AUTHOR" content="' . $xoopsConfig['sitename'] . '" />\n';
120
    echo '<meta name="keywords" content="' . $xoops_meta_keywords . '" />\n';
121
    echo '<meta name="COPYRIGHT" content="Copyright (c) 2012 by ' . $xoopsConfig['sitename'] . '" />\n';
122
    echo '<meta name="DESCRIPTION" content="' . $xoops_meta_description . '" />\n';
123
    echo '<meta name="GENERATOR" content="XOOPS" />\n';
124
    echo '<!-- Sheet Css -->';
125
    echo '<link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="' . XOOPS_URL . '/xoops.css" />\n';
126
    echo '<link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="' . XOOPS_URL . '/themes/default/style.css" />\n';
127
    echo '<link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="' . XOOPS_URL . '/modules/xnewsletter/assets/css/module.css" />\n';
128
129
?>
130
    <script type="text/javascript">
131
    // <![CDATA[
132
    /*------------------------------------------------------------------------------
133
    Function:       footnoteLinks()
134
    Author:         Aaron Gustafson (aaron at easy-designs dot net)
135
    Creation Date:  8 May 2005
136
    Version:        1.3
137
    Homepage:       http://www.easy-designs.net/code/footnoteLinks/
138
    License:        Creative Commons Attribution-ShareAlike 2.0 License
139
                    http://creativecommons.org/licenses/by-sa/2.0/
140
    Note:           This version has reduced functionality as it is a demo of
141
                    the script's development
142
    ------------------------------------------------------------------------------*/
143
    function footnoteLinks(containerID,targetID) {
144
        if (!document.getElementById ||
145
            !document.getElementsByTagName ||
146
            !document.createElement) return false;
147
        if (!document.getElementById(containerID) ||
148
            !document.getElementById(targetID)) return false;
149
          var container = document.getElementById(containerID);
150
          var target    = document.getElementById(targetID);
151
          var h2        = document.createElement('h2');
152
          addClass.apply(h2,['printOnly']);
153
          var h2_txt    = document.createTextNode('<?php echo "_MA_NW_LINKS"; ?>');
154
          h2.appendChild(h2_txt);
155
          var coll = container.getElementsByTagName('*');
156
          var ol   = document.createElement('ol');
157
          addClass.apply(ol,['printOnly']);
158
          var myArr = [];
159
          var thisLink;
160
          var num = 1;
161
          for (var i=0; i<coll.length; i++) {
162
            if ( coll[i].getAttribute('href') ||
163
                coll[i].getAttribute('cite') ) {
164
                thisLink = coll[i].getAttribute('href') ? coll[i].href : coll[i].cite;
165
                var note = document.createElement('sup');
166
                addClass.apply(note,['printOnly']);
167
                var note_txt;
168
                var j = inArray.apply(myArr,[thisLink]);
169
                if (j || j===0) { // if a duplirolee
170
                    // get the corresponding number from
171
                    // the array of used links
172
                    note_txt = document.createTextNode(j+1);
173
                } else {
174
                    // if not a duplirolee
175
                    var li     = document.createElement('li');
176
                    var li_txt = document.createTextNode(thisLink);
177
                    li.appendChild(li_txt);
178
                    ol.appendChild(li);
179
                    myArr.push(thisLink);
180
                    note_txt = document.createTextNode(num);
181
                    num++;
182
                }
183
                note.appendChild(note_txt);
184
                if (coll[i].tagName.toLowerCase() == 'blockquote') {
185
                    var lastChild = lastChildContainingText.apply(coll[i]);
186
                    lastChild.appendChild(note);
187
                } else {
188
                    coll[i].parentNode.insertBefore(note, coll[i].nextSibling);
189
                }
190
            }
191
        }
192
      target.appendChild(h2);
193
      target.appendChild(ol);
194
195
      return true;
196
    }
197
    // ]]>
198
    </script>
199
    <script type="text/javascript">
200
    // <![CDATA[
201
    /*------------------------------------------------------------------------------
202
    Excerpts from the jsUtilities Library
203
    Version:        2.1
204
    Homepage:       http://www.easy-designs.net/code/jsUtilities/
205
    License:        Creative Commons Attribution-ShareAlike 2.0 License
206
                    http://creativecommons.org/licenses/by-sa/2.0/
207
    Note:           If you change or improve on this script, please let us know.
208
    ------------------------------------------------------------------------------*/
209
    if (Array.prototype.push == null) {
210
        Array.prototype.push = function(item) {
211
            this[this.length] = item;
212
213
            return this.length;
214
        };
215
    };
216
    // ---------------------------------------------------------------------
217
    //                  function.apply (if unsupported)
218
    //           Courtesy of Aaron Boodman - http://youngpup.net
219
    // ---------------------------------------------------------------------
220
    if (!Function.prototype.apply) {
221
        Function.prototype.apply = function(oScope, args) {
222
            var sarg = [];
223
            var rtrn, call;
224
            if (!oScope) oScope = window;
225
            if (!args) args = [];
226
            for (var i = 0; i < args.length; i++) {
227
                sarg[i] = "args["+i+"]";
228
            };
229
            call = "oScope.__applyTemp__(" + sarg.join(",") + ");";
230
            oScope.__applyTemp__ = this;
231
            rtrn = eval(call);
232
            oScope.__applyTemp__ = null;
233
234
            return rtrn;
235
        };
236
    };
237
    function inArray(needle) {
238
        for (var i=0; i < this.length; i++) {
239
            if (this[i] === needle) {
240
                return i;
241
            }
242
        }
243
244
    return false;
245
    }
246
    function addClass(theClass) {
247
        if (this.className != '') {
248
            this.className += ' ' + theClass;
249
        } else {
250
            this.className = theClass;
251
        }
252
    }
253
    function lastChildContainingText() {
254
        var testChild = this.lastChild;
255
        var contentCntnr = ['p','li','dd'];
256
        while (testChild.nodeType != 1) {
257
            testChild = testChild.previousSibling;
258
        }
259
        var tag = testChild.tagName.toLowerCase();
260
        var tagInArr = inArray.apply(contentCntnr, [tag]);
261
        if (!tagInArr && tagInArr!==0) {
262
            testChild = lastChildContainingText.apply(testChild);
263
        }
264
265
        return testChild;
266
    }
267
    // ]]>
268
    </script>
269
    <style type="text/css" media="screen">
270
        .printOnly {
271
        display: none;
272
    }
273
    </style>
274
    </head>
275
    <body bgcolor="#ffffff" text="#000000" onload="window.print()">
276
<?php
277
    echo $content;
278
?>
279
    </body>
280
    </html>
281
<?php
282
}
283