Completed
Push — master ( 234b0e...1578b3 )
by Michael
14s
created

modlink.php (12 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
// $Id: modlink.php 11819 2013-07-09 18:21:40Z zyspec $
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                    Copyright (c) 2000 XOOPS.org                           //
6
//                       <http://www.xoops.org/>                             //
7
//  ------------------------------------------------------------------------ //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
28
include 'header.php';
29
$myts =& MyTextSanitizer::getInstance(); // MyTextSanitizer object
30
31
include_once './class/utility.php';
32
//xoops_load('utility', $xoopsModule->getVar('dirname'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33
34
if (!empty($_POST['submit'])) {
35
    if (empty($xoopsUser)) {
36
        redirect_header(XOOPS_URL . '/user.php', 2, _MD_MYLINKS_MUSTREGFIRST);
37
        exit();
38
    }
39
    $user = $xoopsUser->getVar('uid');
40
    $lid = mylinksUtility::mylinks_cleanVars($_POST, 'lid', 0, 'int', array('min'=>0));
0 ignored issues
show
'lid' is of type string, but the function expects a object<unknown_type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
42
//    include_once XOOPS_ROOT_PATH . '/class/module.errorhandler.php';
43
//    $eh = new ErrorHandler; //ErrorHandler object
44
45
    $msg = '';
46
    switch (true) {
47
        case ( '' == $_POST['title'] ):
0 ignored issues
show
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
48
            $msg .= _MD_MYLINKS_ERRORTITLE;
49
        case ( '' == $_POST['url'] ):
0 ignored issues
show
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
50
            $msg .= _MD_MYLINKS_ERRORURL;
51
        case ( '' == $_POST['description'] ):
52
            $msg .= _MD_MYLINKS_ERRORDESC;
53
    }
54
    if ('' !== $msg) {
55
        mylinksUtility::show_message($msg);
0 ignored issues
show
Deprecated Code introduced by
The method mylinksUtility::show_message() has been deprecated.

This method has been deprecated.

Loading history...
56
        exit();
57
    }
58
59
    $url         = $myts->addSlashes($_POST['url']);
60
    $logourl     = $myts->addSlashes($_POST['logourl']);
61
    $cid         = mylinksUtility::mylinks_cleanVars($_POST, 'cid', 0, 'int', array('min'=>0));
0 ignored issues
show
'cid' is of type string, but the function expects a object<unknown_type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
62
    $title       = $myts->addSlashes($_POST['title']);
63
    $description = $myts->addSlashes($_POST['description']);
64
    $newid       = $xoopsDB->genId($xoopsDB->prefix('mylinks_mod') . '_requestid_seq');
65
    $sql         = sprintf("INSERT INTO %s (requestid, lid, cid, title, url, logourl, description, modifysubmitter) VALUES (%u, %u, %u, '%s', '%s', '%s', '%s', %u)", $xoopsDB->prefix('mylinks_mod'), $newid, $lid, $cid, $title, $url, $logourl, $description, $user);
66
    $result = $xoopsDB->query($sql);
67
    if (!result) {
68
        mylinksUtility::show_message(_MD_MYLINKS_DBNOTUPDATED);
0 ignored issues
show
Deprecated Code introduced by
The method mylinksUtility::show_message() has been deprecated.

This method has been deprecated.

Loading history...
69
        exit();
70
    }
71
    $tags = array();
72
    $tags['MODIFYREPORTS_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/index.php?op=listModReq';
73
    $notification_handler =& xoops_getHandler('notification');
74
    $notification_handler->triggerEvent('global', 0, 'link_modify', $tags);
75
    redirect_header('index.php', 2, _MD_MYLINKS_THANKSFORINFO);
76
    exit();
77
} else {
78
    if (empty($xoopsUser)) {
79
        redirect_header(XOOPS_URL . '/user.php', 2, _MD_MYLINKS_MUSTREGFIRST);
80
        exit();
81
    }
82
    $lid = mylinksUtility::mylinks_cleanVars($_GET, 'lid', 0, 'int', array('min'=>0));
0 ignored issues
show
'lid' is of type string, but the function expects a object<unknown_type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
83
84
    include_once XOOPS_ROOT_PATH . '/class/tree.php';
85
    $mylinksCatHandler =& xoops_getmodulehandler('category', $xoopsModule->getVar('dirname'));
86
    $catObjs           = $mylinksCatHandler->getAll();
87
    $myCatTree         = new XoopsObjectTree($catObjs, 'cid', 'pid');
88
89
    $xoopsOption['template_main'] = 'mylinks_modlink.html';
90
    include XOOPS_ROOT_PATH . '/header.php';
91
92
    //wanikoo
93
    $xoTheme->addStylesheet('browse.php?' . mylinksGetStylePath('mylinks.css', 'include'));
94
    $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
95
    $xoTheme->addScript('browse.php?' . mylinksGetStylePath('mylinks.js', 'include'));
96
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
97
    $mylinks_module_header = ""
98
                          ."<link rel='stylesheet' type='text/css' href='" . mylinksGetStyleURL('mylinks.css') . "'>"
99
                          ."<script src='" . mylinksGetStyleURL('mylinks.js') . "' type='text/javascript'></script>";
100
    $xoopsTpl->assign('xoops_module_header', $mylinks_module_header);
101
*/
102
    //
103
104
    $result = $xoopsDB->query('SELECT l.lid, l.cid, l.title, l.url, l.logourl, l.status, l.date, l.hits, l.rating, l.votes, l.comments, t.description FROM ' . $xoopsDB->prefix('mylinks_links') . ' l, ' . $xoopsDB->prefix('mylinks_text') . " t WHERE l.lid={$lid} AND l.lid=t.lid AND status>0");
105
    list($lid, $cid, $title, $url, $logourl, $status, $time, $hits, $rating, $votes, $comments, $description) = $xoopsDB->fetchRow($result);
106 View Code Duplication
    if ($xoopsUser && $xoopsUser->isAdmin($xoopsModule->mid())) {
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...
107
        $adminlink = "<a href='" . XOOPSMYLINKURL . "/admin/index.php?op=modLink&amp;lid={$lid}'><img src='" . mylinksGetIconURL('edit.png') . "' style='border-width: 0px;' alt='" . _MD_MYLINKS_EDITTHISLINK . "'></a>";
108
    } else {
109
        $adminlink = '';
110
    }
111
    $votestring = (1 == $votes) ? _MD_MYLINKS_ONEVOTE : sprintf(_MD_MYLINKS_NUMVOTES, $votes);
112
113
    $xoopsTpl->assign('link', array('id'          => $lid,
114
                                    'rating'      => number_format($rating, 2),
115
                                    'title'       => $myts->htmlSpecialChars($myts->stripSlashesGPC($title)),
116
                                    'url'         => $myts->htmlSpecialChars($url),
117
                                    'logourl'     => $myts->htmlSpecialChars($logourl),
118
                                    'updated'     => formatTimestamp($time, 'm'),
119
                                    'description' => $myts->htmlSpecialChars($myts->stripSlashesGPC($description)),
120
                                    'adminlink'   => $adminlink,
121
                                    'hits'        => $hits,
122
                                    'votes'       => $votestring));
123
    $xoopsTpl->assign('lang_requestmod', _MD_MYLINKS_REQUESTMOD);
124
    $xoopsTpl->assign('lang_linkid', _MD_MYLINKS_LINKID);
125
    $xoopsTpl->assign('lang_sitetitle', _MD_MYLINKS_SITETITLE);
126
    $xoopsTpl->assign('lang_siteurl', _MD_MYLINKS_SITEURL);
127
    $xoopsTpl->assign('lang_category', _MD_MYLINKS_CATEGORYC);
128
    $xoopsTpl->assign('category_selbox', $myCatTree->makeSelBox('cid', 'title', '-', $cid));
129
    $xoopsTpl->assign('lang_description', _MD_MYLINKS_DESCRIPTIONC);
130
    $xoopsTpl->assign('lang_sendrequest', _MD_MYLINKS_SENDREQUEST);
131
    $xoopsTpl->assign('lang_cancel', _CANCEL);
132
    //wanikoo theme changer
133
    $xoopsTpl->assign('lang_themechanger', _MD_MYLINKS_THEMECHANGER);
134
    $mymylinkstheme_options = '';
135
136 View Code Duplication
    foreach ($GLOBALS['mylinks_allowed_theme'] as $mymylinkstheme) {
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...
137
        $mymylinkstheme_options .= "<option value='{$mymylinkstheme}'";
138
        if ($mymylinkstheme == $GLOBALS['mylinks_theme']) {
139
            $mymylinkstheme_options .= " selected='selected'";
140
        }
141
        $mymylinkstheme_options .= ">{$mymylinkstheme}</option>";
142
    }
143
144
    $mylinkstheme_select = "<select name='mylinks_theme_select' onchange='submit();' size='1'>{$mymylinkstheme_options}</select>";
145
146
    $xoopsTpl->assign('mylinksthemeoption', $mylinkstheme_select);
147
148
    //wanikoo search
149 View Code Duplication
    if (file_exists(XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/search.php')) {
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...
150
       include_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/search.php';
151
    } else {
152
       include_once XOOPS_ROOT_PATH . '/language/english/search.php';
153
    }
154
    $xoopsTpl->assign('lang_all', _SR_ALL);
155
    $xoopsTpl->assign('lang_any', _SR_ANY);
156
    $xoopsTpl->assign('lang_exact', _SR_EXACT);
157
    $xoopsTpl->assign('lang_search', _SR_SEARCH);
158
    $xoopsTpl->assign('module_id', $xoopsModule->getVar('mid'));
159
    //category head
160
    $catarray = array();
161
    if ($mylinks_show_letters) {
162
        $catarray['letters'] = ml_wfd_letters();
163
    }
164
    if ($mylinks_show_toolbar) {
165
        $catarray['toolbar'] = ml_wfd_toolbar();
166
    }
167
    $xoopsTpl->assign('catarray', $catarray);
168
169
    include_once XOOPSMYLINKPATH . '/footer.php';
170
}
171