Passed
Push — master ( 17bb73...af3dbd )
by Richard
06:15 queued 11s
created

printCheckForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 25
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * XOOPS misc utilities
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license         GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14
 * @package         core
15
 * @since           2.0.0
16
 */
17
18
use Xmf\Request;
19
20
include __DIR__ . '/mainfile.php';
21
22
xoops_loadLanguage('misc');
23
xoops_loadLanguage('user');
24
25
$action = Request::getCmd('action', '');
26
$type = Request::getCmd('type', '');
27
28
if ($action !== 'showpopups') {
29
    header("HTTP/1.0 404 Not Found");
30
    exit();
31
}
32
    xoops_header(false);
33
    // show javascript close button?
34
    $closebutton = 1;
35
    switch ($type) {
36
        case 'smilies':
37
            $target = Request::getString('target', '');
38
            if ($target !== '' && preg_match('/^[0-9a-z_]*$/i', $target)) {
39
                $variables = array();
40
$javaScript = <<<EOSMJS
41
<script type="text/javascript">
42
function doSmilie(addSmilie) {
43
    var textareaDom = window.opener.xoopsGetElementById("{$target}");
44
    xoopsInsertText(textareaDom, addSmilie);
45
    textareaDom.focus();
46
}
47
</script>
48
EOSMJS;
49
                $variables['headContents'] = $javaScript;
50
                $variables['closeHead'] = true;
51
                $variables['lang_smiles'] = _MSC_SMILIES;
52
                $variables['lang_code'] = _MSC_CODE;
53
                $variables['lang_emotion'] = _MSC_EMOTION;
54
                $variables['lang_image'] = _IMAGE;
55
                $variables['lang_clicksmile'] = _MSC_CLICKASMILIE;
56
                $variables['lang_close'] = _CLOSE;
57
                $variables['upload_url'] = XOOPS_UPLOAD_URL .'/';
58
                $myts = MyTextSanitizer::getInstance();
59
                if ($smiles = $myts->getSmileys()) {
60
                    $variables['smilies'] = $smiles;
61
                } else {
62
                    $variables['smilies'] = array();
63
                    trigger_error('Could not retrieve smilies from the database.', E_USER_NOTICE);
64
                }
65
                xoops_misc_popup_body('db:system_misc_smilies.tpl', $variables);
66
            }
67
            break;
68
        case 'avatars':
69
            /* @var  XoopsAvatarHandler $avatarHandler */
70
            $avatarHandler = xoops_getHandler('avatar');
71
            $avatarsList = $avatarHandler->getList('S');
72
73
            $upload_url = XOOPS_UPLOAD_URL . '/';
74
            $javaScript = <<<EOAVJS
75
<script language='javascript'>
76
    function myimage_onclick(counter) {
77
        window.opener.xoopsGetElementById("user_avatar").options[counter].selected = true;
78
        showAvatar();
79
        window.opener.xoopsGetElementById("user_avatar").focus();
80
        window.close();
81
    }
82
    function showAvatar() {
83
        window.opener.xoopsGetElementById("avatar").src="{$upload_url}" + window.opener.xoopsGetElementById("user_avatar").options[window.opener.xoopsGetElementById("user_avatar").selectedIndex].value;
84
    }
85
</script>
86
EOAVJS;
87
            $variables['headContents'] = $javaScript;
88
            $variables['closeHead'] = true;
89
            $variables['lang_avavatars'] = _MSC_AVAVATARS;
90
            $variables['lang_select'] = _SELECT;
91
            $variables['lang_close'] = _CLOSE;
92
            $variables['avatars'] = $avatarsList;
93
            $variables['upload_url'] = $upload_url;
94
            xoops_misc_popup_body('db:system_misc_avatars.tpl', $variables);
95
            break;
96
        case 'friend':
97
            include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
98
99
            $variables['headContents'] = '';
100
            $variables['closeHead'] = true;
101
            $variables['lang_recommend'] = _MSC_RECOMMENDSITE;
102
            $variables['lang_yourname'] = _MSC_YOURNAMEC;
103
            $variables['lang_youremail'] = _MSC_YOUREMAILC;
104
            $variables['lang_friendname'] = _MSC_FRIENDNAMEC;
105
            $variables['lang_friendemail'] = _MSC_FRIENDEMAILC;
106
            $variables['lang_send'] = _SEND;
107
            $variables['lang_close'] = _CLOSE;
108
109
            $error = false;
110
            $errorMessage = '';
111
112
            $method = Request::getMethod();
113
            if ('POST' === $method) {
114
                $yname = Request::getString('yname', '', 'POST');
115
                $ymail = Request::getString('ymail', '', 'POST');
116
                $fname = Request::getString('fname', '', 'POST');
117
                $fmail = Request::getString('fmail', '', 'POST');
118
119
                if (!$GLOBALS['xoopsSecurity']->check()) {
120
                    $error = true;
121
                    $temp = $GLOBALS['xoopsSecurity']->getErrors();
122
                    $errorMessage = (is_array($temp)) ? implode('<br>', $temp) : $temp;
123
                }
124
                if (!$error && false === filter_var($ymail, FILTER_VALIDATE_EMAIL)) {
125
                    $error = true;
126
                    $errorMessage = _MSC_INVALIDEMAIL1;
127
                }
128
                if (!$error && false === filter_var($fmail, FILTER_VALIDATE_EMAIL)) {
129
                    $error = true;
130
                    $errorMessage = _MSC_INVALIDEMAIL1;
131
                }
132
                if (!$error && '' === $yname) {
133
                    $error = true;
134
                    $errorMessage = _MSC_ENTERYNAME;
135
                }
136
                if (!$error && '' === $fname) {
137
                    $error = true;
138
                    $errorMessage = _MSC_ENTERFNAME;
139
                }
140
                if ($error) {
141
                    $variables['errorMessage'] = $errorMessage;
142
                }
143
            }
144
            if ('POST' === $method && false === $error) {
145
                // send it
146
                $xoopsMailer = xoops_getMailer();
147
                $xoopsMailer->setTemplate('tellfriend.tpl');
148
                $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
149
                $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
150
                $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
151
                $xoopsMailer->assign('YOUR_NAME', $yname);
152
                $xoopsMailer->assign('FRIEND_NAME', $fname);
153
                $xoopsMailer->setToEmails($fmail);
154
                $xoopsMailer->setFromEmail($ymail);
155
                $xoopsMailer->setFromName($yname);
156
                $xoopsMailer->setSubject(sprintf(_MSC_INTSITE, $xoopsConfig['sitename']));
157
158
                if (!$xoopsMailer->send()) {
159
                    $error = true;
160
                    $errorMessage = $xoopsMailer->getErrors();
161
                    $variables['errorMessage'] = $errorMessage;
162
                } else {
163
                    $variables['successMessage'] = _MSC_REFERENCESENT;
164
                }
165
            } else {
166
                // build form
167
                $ynameDefault = '';
168
                $ymailDefault = '';
169
                if (is_object($xoopsUser)) {
170
                    $ynameDefault = $xoopsUser->getVar('uname', 'e');
171
                    $ymailDefault = $xoopsUser->getVar('email', 'e');
172
                }
173
                $yname = Request::getString('yname', $ynameDefault);
174
                $ymail = Request::getString('ymail', $ymailDefault);
175
                $fname = Request::getString('fname', '');
176
                $fmail = Request::getString('fmail', '');
177
            }
178
            $form = new XoopsThemeForm(_MSC_RECOMMENDSITE, 'recommendus', XOOPS_URL . '/misc.php', 'post', true);
179
            $ynameElelment = new XoopsFormText(_MSC_YOURNAMEC, 'yname', 32, 64, $yname);
180
            $form->addElement($ynameElelment, true);
181
            $ymailElelment = new XoopsFormText(_MSC_YOUREMAILC, 'ymail', 48, 96, $ymail);
182
            $form->addElement($ymailElelment, true);
183
            if ('' !== $ymail && false === filter_var($ymail, FILTER_VALIDATE_EMAIL)) {
184
                $ynameElelment->setDescription(_MSC_INVALIDEMAIL1);
185
            }
186
            $fnameElement = new XoopsFormText(_MSC_FRIENDNAMEC, 'fname', 32, 64, $fname);
187
            $form->addElement($fnameElement, true);
188
            $fmailElelment = new XoopsFormText(_MSC_FRIENDEMAILC, 'fmail', 48, 96, $fmail);
189
            if ('' !== $fmail && false === filter_var($fmail, FILTER_VALIDATE_EMAIL)) {
190
                $fmailElelment->setDescription(_MSC_INVALIDEMAIL1);
191
            }
192
            $form->addElement($fmailElelment, true);
193
            $form->addElement(new XoopsFormHidden('action', $action));
194
            $form->addElement(new XoopsFormHidden('type', $type));
195
            $form->addElement(new XoopsFormButton('', 'submit', _SEND, 'submit'));
196
197
            xoops_misc_popup_body('db:system_misc_friend.tpl', $variables, true, true, $form);
198
            break;
199
        case 'online':
200
            include_once $GLOBALS['xoops']->path('class/pagenav.php');
201
202
            $isadmin = false;
203
            $timezone = $xoopsConfig['default_TZ'];
204
            if (is_object($xoopsUser)) {
205
                $isadmin = $xoopsUser->isAdmin();
206
                $timezone = $xoopsUser->timezone();
207
            }
208
209
            $variables['headContents'] = '';
210
            $variables['closeHead'] = true;
211
            $variables['isadmin'] = $isadmin;
212
            $variables['lang_whoisonline'] = _WHOSONLINE;
213
            $variables['lang_close'] = _CLOSE;
214
            $variables['lang_avatar'] = _US_AVATAR;
215
            $variables['anonymous'] = $xoopsConfig['anonymous'];
216
            $variables['upload_url'] = XOOPS_UPLOAD_URL .'/';
217
218
            $start = Request::getInt('start', 0);
219
            $limit = 20; // how many to make available per page
220
221
            /* @var XoopsModuleHandler $module_handler */
222
            $module_handler = xoops_getHandler('module');
223
            $modules = $module_handler->getObjects(new Criteria('isactive', 1), true);
224
225
            /* @var XoopsOnlineHandler $onlineHandler */
226
            $onlineHandler = xoops_getHandler('online');
227
            $onlineTotal = $onlineHandler->getCount();
228
            $criteria = new CriteriaCompo();
229
            $criteria->setStart($start);
230
            $criteria->setLimit($limit);
231
            $onlines = $onlineHandler->getAll($criteria);
232
233
            $onlineUserInfo = array();
234
            foreach ($onlines as $online) {
235
                $info = array();
236
                if (0 == $online['online_uid']) {
237
                    $info['uid'] = $online['online_uid'];
238
                    $info['uname'] = $xoopsConfig['anonymous'];;
239
                    $info['name'] = '';
240
                    $info['xoopsuser'] = false;
241
                    $info['avatar'] = 'avatars/blank.gif';
242
                } else {
243
                    /** @var XoopsUser $onlineUser */
244
                    $onlineUser = new XoopsUser($online['online_uid']);
245
                    $info['xoopsuser'] = $onlineUser;
246
                    $info['uid'] = $online['online_uid'];
247
                    $info['uname'] = $online['online_uname'];
248
                    $info['name'] = $onlineUser->name();
249
                    $info['avatar'] = $onlineUser->user_avatar();
250
                }
251
                $info['updated'] = formatTimestamp($online['online_updated'], 'm', $timezone);
252
                $info['ip'] = $online['online_ip'];
253
                $info['mid'] = $online['online_module'];
254
                if (0 === $online['online_module'] || !isset($modules[$online['online_module']])) {
255
                    $info['module_name'] = '';
256
                    $info['dirname'] = '';
257
                } else {
258
                    /** @var \XoopsModule $mod */
259
                    $mod = $modules[$online['online_module']];
260
                    $info['module_name'] = $mod->name();
261
                    $info['dirname'] = $mod->dirname();
262
                }
263
                $onlineUserInfo[] = $info;
264
            }
265
            $variables['onlineUserInfo'] = $onlineUserInfo;
266
267
            $nav = new XoopsPageNav($onlineTotal, $limit, $start, 'start', 'action=showpopups&amp;type=online');
268
            $variables['pageNav'] = $nav->renderNav();
269
270
            xoops_misc_popup_body('db:system_misc_online.tpl', $variables, true, true);
271
            break;
272
        case 'ssllogin':
273
            if ($xoopsConfig['use_ssl'] && isset($_POST[$xoopsConfig['sslpost_name']]) && is_object($xoopsUser)) {
274
                include_once $GLOBALS['xoops']->path('language/' . $xoopsConfig['language'] . '/user.php');
275
                echo sprintf(_US_LOGGINGU, $xoopsUser->getVar('uname'));
276
                echo '<div style="text-align:center;"><input class="formButton" value="' . _CLOSE . '" type="button" onclick="window.opener.location.reload();window.close();" /></div>';
277
                $closebutton = false;
278
            }
279
            break;
280
        default:
281
            break;
282
    }
283
    $closebutton=false;
284
    if ($closebutton) {
0 ignored issues
show
introduced by
The condition $closebutton is always false.
Loading history...
285
        echo '<div style="text-align:center;"><input class="formButton" value="' . _CLOSE . '" type="button" onclick="window.close();" /></div>';
286
    }
287
    xoops_footer();
288
289
/**
290
 * xoops_misc_popup_body()
291
 *
292
 * @param string         $template  smarty template to user
293
 * @param array          $variables array of variables to assign for template
294
 * @param bool           $closehead if true, close the head element and open the body
295
 * @param XoopsForm|null $xoopsForm optioal form
296
 * @return void  echos rendered template
297
 */
298
function xoops_misc_popup_body($template, $variables, $closehead = true, $closebutton = true, $xoopsForm = null)
299
{
300
    global $xoopsConfig;
301
302
    $themeSet = $xoopsConfig['theme_set'];
303
    $themePath = XOOPS_THEME_PATH . '/' . $themeSet . '/';
304
    $themeUrl = XOOPS_THEME_URL . '/' . $themeSet . '/';
305
    include_once XOOPS_ROOT_PATH . '/class/template.php';
306
    $headTpl = new \XoopsTpl();
307
    //$GLOBALS['xoopsHeadTpl'] = $headTpl;  // expose template for use by caller
308
    $headTpl->assign(array(
309
        'closeHead'      => (bool) $closehead,
310
        'closeButton'    => (bool) $closebutton,
311
        'themeUrl'       => $themeUrl,
312
        'themePath'      => $themePath,
313
        'xoops_langcode' => _LANGCODE,
314
        'xoops_charset'  => _CHARSET,
315
        'xoops_sitename' => $xoopsConfig['sitename'],
316
        'xoops_url'      => XOOPS_URL,
317
    ));
318
319
    $headTpl->assign($variables);
320
    if ($xoopsForm instanceof XoopsForm) {
321
        $xoopsForm->assign($headTpl);
322
    }
323
324
    $output = $headTpl->fetch($template);
325
    echo $output;
326
}
327