Passed
Push — master ( 08b589...961b46 )
by Michael
08:46
created

brokenlink.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
 * Module: WF-Links
5
 * Version: v1.0.3
6
 * Release Date: 21 June 2005
7
 * Developer: John N
8
 * Team: WF-Projects
9
 * Licence: GNU
10
 */
11
12
require_once __DIR__ . '/header.php';
13
14
$op      = WflinksUtility::cleanRequestVars($_REQUEST, 'op', '');
15
$lid     = WflinksUtility::cleanRequestVars($_REQUEST, 'lid', 0);
16
$lid     = (int)$lid;
17
$buttonn = _MD_WFL_SUBMITBROKEN;
18
$buttonn = strtolower($buttonn);
19
20
switch (strtolower($op)) {
21
    case $buttonn:
22
        global $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
23
24
        $sender = (is_object($xoopsUser) && !empty($xoopsUser)) ? $xoopsUser->getVar('uid') : 0;
25
        $ip     = getenv('REMOTE_ADDR');
26
        $title  = WflinksUtility::cleanRequestVars($_REQUEST, 'title', '');
27
        $title  = $wfmyts->addSlashes($title);
28
        $time   = time();
29
30
        // Check if REG user is trying to report twice.
31
        $result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('wflinks_broken') . ' WHERE lid=' . $lid);
32
        list($count) = $xoopsDB->fetchRow($result);
33
        if ($count > 0) {
34
            redirect_header('index.php', 2, _MD_WFL_ALREADYREPORTED);
35
        } else {
36
            $reportid = 0;
37
            $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));
38
            if (!$result = $xoopsDB->query($sql)) {
39
                $error[] = _MD_WFL_ERROR;
40
            }
41
            $newid = $xoopsDB->getInsertId();
42
43
            // Send notifications
44
            $tags                      = [];
45
            $tags['BROKENREPORTS_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/main.php?op=listBrokenlinks';
46
            $notificationHandler       = xoops_getHandler('notification');
47
            $notificationHandler->triggerEvent('global', 0, 'link_broken', $tags);
48
49
            // Send email to the owner of the linkload stating that it is broken
50
            $sql      = 'SELECT * FROM ' . $xoopsDB->prefix('wflinks_links') . ' WHERE lid=' . $lid . ' AND published > 0 AND published <= ' . time() . ' AND (expired = 0 OR expired > ' . time() . ')';
51
            $link_arr = $xoopsDB->fetchArray($xoopsDB->query($sql));
52
            unset($sql);
53
54
            $memberHandler = xoops_getHandler('member');
55
            $submit_user   = $memberHandler->getUser($link_arr['submitter']);
56
            if (is_object($submit_user) && !empty($submit_user)) {
57
                $subdate = formatTimestamp($link_arr['date'], $xoopsModuleConfig['dateformat']);
58
                $cid     = $link_arr['cid'];
59
                $title   = $wfmyts->htmlSpecialCharsStrip($link_arr['title']);
60
                $subject = _MD_WFL_BROKENREPORTED;
61
62
                $xoopsMailer = xoops_getMailer();
63
                $xoopsMailer->useMail();
64
                $template_dir = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template';
65
66
                $xoopsMailer->setTemplateDir($template_dir);
67
                $xoopsMailer->setTemplate('linkbroken_notify.tpl');
68
                $xoopsMailer->setToEmails($submit_user->getVar('email'));
69
                $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
70
                $xoopsMailer->setFromName($xoopsConfig['sitename']);
71
                $xoopsMailer->assign('X_UNAME', $submit_user->getVar('uname'));
72
                $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
73
                $xoopsMailer->assign('X_ADMINMAIL', $xoopsConfig['adminmail']);
74
                $xoopsMailer->assign('X_SITEURL', XOOPS_URL . '/');
75
                $xoopsMailer->assign('X_TITLE', $title);
76
                $xoopsMailer->assign('X_SUB_DATE', $subdate);
77
                $xoopsMailer->assign('X_LINKLOAD', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/singlelink.php?cid=' . (int)$cid . '&amp;lid=' . $lid);
78
                $xoopsMailer->setSubject($subject);
79
                $message = $xoopsMailer->send() ? _MD_WFL_BROKENREPORTED : _MD_WFL_ERRORSENDEMAIL;
80
            } else {
81
                $message = _MD_WFL_ERRORSENDEMAIL;
82
            }
83
            redirect_header('index.php', 2, $message);
84
        }
85
        break;
86
87
    default:
0 ignored issues
show
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
88
89
        $GLOBALS['xoopsOption']['template_main'] = 'wflinks_brokenlink.tpl';
90
        include XOOPS_ROOT_PATH . '/header.php';
91
        xoops_load('XoopsUserUtility');
92
93
        $catarray['imageheader'] = WflinksUtility::getImageHeader();
94
        $catarray['letters']     = WflinksUtility::getLetters();
95
        $catarray['toolbar']     = WflinksUtility::getToolbar();
96
        $xoopsTpl->assign('catarray', $catarray);
97
98
        $sql      = 'SELECT * FROM ' . $xoopsDB->prefix('wflinks_links') . ' WHERE lid=' . $lid;
99
        $link_arr = $xoopsDB->fetchArray($xoopsDB->query($sql));
100
        unset($sql);
101
102
        $sql       = 'SELECT * FROM ' . $xoopsDB->prefix('wflinks_broken') . ' WHERE lid=' . $lid;
103
        $broke_arr = $xoopsDB->fetchArray($xoopsDB->query($sql));
104
105
        if (is_array($broke_arr)) {
106
            $broken['title']        = $wfmyts->htmlSpecialCharsStrip($link_arr['title']);
107
            $broken['id']           = $broke_arr['reportid'];
108
            $broken['reporter']     = XoopsUserUtility::getUnameFromId($broke_arr['sender']);
109
            $broken['date']         = formatTimestamp($broke_arr['date'], $xoopsModuleConfig['dateformat']);
110
            $broken['acknowledged'] = (1 == $broke_arr['acknowledged']) ? _YES : _NO;
111
            $broken['confirmed']    = (1 == $broke_arr['confirmed']) ? _YES : _NO;
112
            $xoopsTpl->assign('broken', $broken);
113
            $xoopsTpl->assign('brokenreport', true);
114
        } else {
115
            if (!is_array($link_arr) || empty($link_arr)) {
116
                redirect_header('index.php', 0, _MD_WFL_THISFILEDOESNOTEXIST);
117
            }
118
119
            // file info
120
            $link['title']     = $wfmyts->htmlSpecialCharsStrip($link_arr['title']);
121
            $time              = ($link_arr['published'] > 0) ? $link_arr['published'] : $link_arr['updated'];
122
            $link['updated']   = formatTimestamp($time, $xoopsModuleConfig['dateformat']);
123
            $is_updated        = (0 != $link_arr['updated']) ? _MD_WFL_UPDATEDON : _MD_WFL_SUBMITDATE;
124
            $link['publisher'] = XoopsUserUtility::getUnameFromId($link_arr['submitter']);
125
126
            $xoopsTpl->assign('link_id', $lid);
127
            $xoopsTpl->assign('lang_subdate', $is_updated);
128
            $xoopsTpl->assign('link', $link);
129
        }
130
131
        if (is_object($xoTheme)) {
132
            $xoTheme->addMeta('meta', 'robots', 'noindex,nofollow');
133
        } else {
134
            $xoopsTpl->assign('xoops_meta_robots', 'noindex,nofollow');
135
        }
136
137
        $xoopsTpl->assign('module_dir', $xoopsModule->getVar('dirname'));
138
        include XOOPS_ROOT_PATH . '/footer.php';
139
        break;
140
} // switch
141