Passed
Push — master ( f493ff...9be1c2 )
by Michael
06:39
created

brokenlink.php (2 issues)

Labels
Severity
1
<?php
2
/**
3
 * Module: WF-Links
4
 * Version: v1.0.3
5
 * Release Date: 21 June 2005
6
 * Developer: John N
7
 * Team: WF-Projects
8
 * Licence: GNU
9
 */
10
11
use XoopsModules\Wflinks;
12
13
require_once __DIR__ . '/header.php';
14
15
/** @var Wflinks\Helper $helper */
16
$helper = Wflinks\Helper::getInstance();
17
18
$op      = Wflinks\Utility::cleanRequestVars($_REQUEST, 'op', '');
19
$lid     = Wflinks\Utility::cleanRequestVars($_REQUEST, 'lid', 0);
20
$lid     = (int)$lid;
21
$buttonn = _MD_WFL_SUBMITBROKEN;
22
$buttonn = mb_strtolower($buttonn);
23
24
switch (mb_strtolower($op)) {
25
    case $buttonn:
26
        global $xoopsUser;
27
28
        $sender = (is_object($xoopsUser) && null !== $xoopsUser) ? $xoopsUser->getVar('uid') : 0;
29
        $ip     = getenv('REMOTE_ADDR');
30
        $title  = Wflinks\Utility::cleanRequestVars($_REQUEST, 'title', '');
31
        $title  = $myts->addSlashes($title);
32
        $time   = time();
33
34
        // Check if REG user is trying to report twice.
35
        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('wflinks_broken') . ' WHERE lid=' . $lid);
36
        list($count) = $xoopsDB->fetchRow($result);
37
        if ($count > 0) {
38
            redirect_header('index.php', 2, _MD_WFL_ALREADYREPORTED);
39
        } else {
40
            $reportid = 0;
41
            $sql      = sprintf('INSERT INTO `%s` (reportid, lid, sender, ip, DATE, confirmed, acknowledged, title ) VALUES ( %u, %u, %u, %s, %u, %u, %u, %s)', $xoopsDB->prefix('wflinks_broken'), $reportid, $lid, $sender, $xoopsDB->quoteString($ip), $time, 0, 0, $xoopsDB->quoteString($title));
42
            if (!$result = $xoopsDB->query($sql)) {
43
                $error[] = _MD_WFL_ERROR;
44
            }
45
            $newid = $xoopsDB->getInsertId();
46
47
            // Send notifications
48
            $tags                      = [];
49
            $tags['BROKENREPORTS_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/main.php?op=listBrokenlinks';
50
            $notificationHandler       = xoops_getHandler('notification');
51
            $notificationHandler->triggerEvent('global', 0, 'link_broken', $tags);
0 ignored issues
show
The method triggerEvent() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsNotificationHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
            $notificationHandler->/** @scrutinizer ignore-call */ 
52
                                  triggerEvent('global', 0, 'link_broken', $tags);
Loading history...
52
53
            // Send email to the owner of the linkload stating that it is broken
54
            $sql      = 'SELECT * FROM ' . $xoopsDB->prefix('wflinks_links') . ' WHERE lid=' . $lid . ' AND published > 0 AND published <= ' . time() . ' AND (expired = 0 OR expired > ' . time() . ')';
55
            $link_arr = $xoopsDB->fetchArray($xoopsDB->query($sql));
56
            unset($sql);
57
58
            $memberHandler = xoops_getHandler('member');
59
            $submit_user   = $memberHandler->getUser($link_arr['submitter']);
0 ignored issues
show
The method getUser() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsAvatarHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
            /** @scrutinizer ignore-call */ 
60
            $submit_user   = $memberHandler->getUser($link_arr['submitter']);
Loading history...
60
            if (is_object($submit_user) && !empty($submit_user)) {
61
                $subdate = formatTimestamp($link_arr['date'], $helper->getConfig('dateformat'));
62
                $cid     = $link_arr['cid'];
63
                $title   = htmlspecialchars($link_arr['title']);
64
                $subject = _MD_WFL_BROKENREPORTED;
65
66
                $xoopsMailer = xoops_getMailer();
67
                $xoopsMailer->useMail();
68
                $template_dir = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template';
69
70
                $xoopsMailer->setTemplateDir($template_dir);
71
                $xoopsMailer->setTemplate('linkbroken_notify.tpl');
72
                $xoopsMailer->setToEmails($submit_user->getVar('email'));
73
                $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
74
                $xoopsMailer->setFromName($xoopsConfig['sitename']);
75
                $xoopsMailer->assign('X_UNAME', $submit_user->getVar('uname'));
76
                $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
77
                $xoopsMailer->assign('X_ADMINMAIL', $xoopsConfig['adminmail']);
78
                $xoopsMailer->assign('X_SITEURL', XOOPS_URL . '/');
79
                $xoopsMailer->assign('X_TITLE', $title);
80
                $xoopsMailer->assign('X_SUB_DATE', $subdate);
81
                $xoopsMailer->assign('X_LINKLOAD', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/singlelink.php?cid=' . (int)$cid . '&amp;lid=' . $lid);
82
                $xoopsMailer->setSubject($subject);
83
                $message = $xoopsMailer->send() ? _MD_WFL_BROKENREPORTED : _MD_WFL_ERRORSENDEMAIL;
84
            } else {
85
                $message = _MD_WFL_ERRORSENDEMAIL;
86
            }
87
            redirect_header('index.php', 2, $message);
88
        }
89
        break;
90
    default:
91
92
        $GLOBALS['xoopsOption']['template_main'] = 'wflinks_brokenlink.tpl';
93
        require XOOPS_ROOT_PATH . '/header.php';
94
        xoops_load('XoopsUserUtility');
95
96
        $catarray['imageheader'] = Wflinks\Utility::getImageHeader();
97
        $catarray['letters']     = Wflinks\Utility::getLetters();
98
        $catarray['toolbar']     = Wflinks\Utility::getToolbar();
99
        $xoopsTpl->assign('catarray', $catarray);
100
101
        $sql      = 'SELECT * FROM ' . $xoopsDB->prefix('wflinks_links') . ' WHERE lid=' . $lid;
102
        $link_arr = $xoopsDB->fetchArray($xoopsDB->query($sql));
103
        unset($sql);
104
105
        $sql       = 'SELECT * FROM ' . $xoopsDB->prefix('wflinks_broken') . ' WHERE lid=' . $lid;
106
        $broke_arr = $xoopsDB->fetchArray($xoopsDB->query($sql));
107
108
        if (is_array($broke_arr)) {
109
            $broken['title']        = htmlspecialchars($link_arr['title']);
110
            $broken['id']           = $broke_arr['reportid'];
111
            $broken['reporter']     = \XoopsUserUtility::getUnameFromId($broke_arr['sender']);
112
            $broken['date']         = formatTimestamp($broke_arr['date'], $helper->getConfig('dateformat'));
113
            $broken['acknowledged'] = (1 == $broke_arr['acknowledged']) ? _YES : _NO;
114
            $broken['confirmed']    = (1 == $broke_arr['confirmed']) ? _YES : _NO;
115
            $xoopsTpl->assign('broken', $broken);
116
            $xoopsTpl->assign('brokenreport', true);
117
        } else {
118
            if (!is_array($link_arr) || empty($link_arr)) {
119
                redirect_header('index.php', 0, _MD_WFL_THISFILEDOESNOTEXIST);
120
            }
121
122
            // file info
123
            $link['title']     = htmlspecialchars($link_arr['title']);
124
            $time              = ($link_arr['published'] > 0) ? $link_arr['published'] : $link_arr['updated'];
125
            $link['updated']   = formatTimestamp($time, $helper->getConfig('dateformat'));
126
            $is_updated        = (0 != $link_arr['updated']) ? _MD_WFL_UPDATEDON : _MD_WFL_SUBMITDATE;
127
            $link['publisher'] = \XoopsUserUtility::getUnameFromId($link_arr['submitter']);
128
129
            $xoopsTpl->assign('link_id', $lid);
130
            $xoopsTpl->assign('lang_subdate', $is_updated);
131
            $xoopsTpl->assign('link', $link);
132
        }
133
134
        if (is_object($xoTheme)) {
135
            $xoTheme->addMeta('meta', 'robots', 'noindex,nofollow');
136
        } else {
137
            $xoopsTpl->assign('xoops_meta_robots', 'noindex,nofollow');
138
        }
139
140
        $xoopsTpl->assign('module_dir', $xoopsModule->getVar('dirname'));
141
        require XOOPS_ROOT_PATH . '/footer.php';
142
        break;
143
} // switch
144