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