Completed
Pull Request — master (#6)
by Michael
02:57
created

singlelink.php (8 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: singlelink.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
include 'header.php';
28
$myts =& MyTextSanitizer::getInstance();// MyTextSanitizer object
29
30
include_once XOOPS_ROOT_PATH . '/class/tree.php';
31
$mylinksCatHandler =& xoops_getmodulehandler('category', $xoopsModule->getVar('dirname'));
32
$catObjs           = $mylinksCatHandler->getAll();
33
$myCatTree         = new XoopsObjectTree($catObjs, 'cid', 'pid');
34
35
include_once './class/utility.php';
36
37
$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...
38
$cid = mylinksUtility::mylinks_cleanVars($_GET, '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...
39
40
$xoopsOption['template_main'] = 'mylinks_singlelink.html';
41
include XOOPS_ROOT_PATH . '/header.php';
42
43
//wanikoo
44
$xoTheme->addStylesheet('browse.php?' . mylinksGetStylePath('mylinks.css', 'include'));
45
$xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
46
$xoTheme->addScript('browse.php?' . mylinksGetStylePath('mylinks.js', 'include'));
47
//
48
49
$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");
50
list($lid, $cid, $ltitle, $url, $logourl, $status, $time, $hits, $rating, $votes, $comments, $description) = $xoopsDB->fetchRow($result);
51
52
$thisCatObj     = $mylinksCatHandler->get($cid);
53
$homePath       = "<a href='" . XOOPSMYLINKURL . "/index.php'>" . _MD_MYLINKS_MAIN . '</a>&nbsp;:&nbsp;';
54
$niceItemPath   = "<a href='" . XOOPSMYLINKURL . "/viewcat.php?cid={$cid}'>" . $thisCatObj->getVar('title') . '</a>';
55
$itemPath       = $thisCatObj->getVar('title');
56
$nicePathFromId = '';
57
$pathFromId     = '';
58
$myParent = $thisCatObj->getVar('pid');
59
while ( $myParent != 0 ) {
60
    $ancestorObj = $myCatTree->getByKey($myParent);
61
    $nicePathFromId  = "<a href='" . XOOPSMYLINKURL . '/viewcat.php?cid=' . $ancestorObj->getVar('cid') . "'>" . $ancestorObj->getVar('title') . "</a>&nbsp;:&nbsp;{$nicePathFromId}";
62
    $pathFromId  = $ancestorObj->getVar('title') . "/{$pathFromId}";
63
    $myParent = $ancestorObj->getVar('pid');
64
}
65
66
$nicePathFromId = "{$homePath}{$nicePathFromId}{$niceItemPath}";
67
$nicePathFromId = str_replace('&nbsp;:&nbsp;', " <img src='" . mylinksGetIconURL('arrow.gif') . "' style='border-width: 0px;' alt=''> ", $nicePathFromId);
68
$pathFromId     = _MD_MYLINKS_MAIN . "/{$pathFromId}{$itemPath}";
69
$pathFromId     = str_replace('/', " <img src='" . mylinksGetIconURL('arrow.gif') . "' style='border-width: 0px;' alt=''> ", $pathFromId);
70
$xoopsTpl->assign('category_path', $nicePathFromId);
71
72
$xoopsTpl->assign('anontellafriend', $GLOBALS['xoopsModuleConfig']['anontellafriend']);
73
74 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...
75
    $adminlink = "<a href='" . XOOPSMYLINKURL . "/admin/main.php?op=modLink&amp;lid={$lid}'><img src='" . mylinksGetIconURL('edit.png') . "' style='border-width: 0px;' alt='" . _MD_MYLINKS_EDITTHISLINK . "' title='" . _MD_MYLINKS_EDITTHISLINK . "'></a>";
76
} else {
77
    $adminlink = '';
78
}
79
$votestring = (1 == $votes) ? _MD_MYLINKS_ONEVOTE : sprintf(_MD_MYLINKS_NUMVOTES, $votes);
80
$new = newlinkgraphic($time, $status);
81
$pop = popgraphic($hits);
82
83
//$xoopsTpl->assign('link', array('id' => $lid, 'cid' => $cid, 'rating' => number_format($rating, 2), 'title' => $myts->htmlSpecialChars($ltitle).$new.$pop, 'category' => $path, 'logourl' => $myts->htmlSpecialChars($logourl), 'updated' => formatTimestamp($time,"m"), 'description' => $myts->displayTarea($description,0), 'adminlink' => $adminlink, 'hits' => $hits, 'votes' => $votestring, 'comments' => $comments, 'mail_subject' => rawurlencode(sprintf(_MD_MYLINKS_INTRESTLINK,$xoopsConfig['sitename'])), 'mail_body' => rawurlencode(sprintf(_MD_MYLINKS_INTLINKFOUND,$xoopsConfig['sitename']).':  '.XOOPSMYLINKURL.'/singlelink.php?lid='.$lid)));
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
84
//by wanikoo
85
/* setup shot provider information */
86
$shotImgSrc = $shotImgHref = $shotAttribution = '';
87
$useShots = $xoopsModuleConfig['useshots'];
88
if ($useShots) {
89
    $shotWidth = $xoopsModuleConfig['shotwidth'];
90
    $xoopsTpl->assign(array('shotwidth'         => $shotWidth . 'px',
91
                            //                            'tablewidth'        => ($shotWidth + 10) . "px",
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% 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...
92
                            'show_screenshot'   => true,
93
                            'lang_noscreenshot' => _MD_MYLINKS_NOSHOTS)
94
    );
95
96
    $shotProvider = mb_strtolower($xoopsModuleConfig['shotprovider']);
97
    $shotImgHref = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/visit.php?cid={$cid}&amp;lid={$lid}";
98
    $logourl = trim($logourl);
99
    if (!empty($logourl)) {
100
        if (file_exists(XOOPSMYLINKIMGPATH . "/{$mylinks_theme}")) {
101
            $shotImgSrc = XOOPSMYLINKIMGURL . "/{$mylinks_theme}/shots/" . $myts->htmlSpecialChars($logourl);
102
        } else {
103
            $shotImgSrc = XOOPSMYLINKIMGURL . '/shots/' . $myts->htmlSpecialChars($logourl);
104
        }
105
    } elseif (_NONE != $shotProvider) {
106
        if (file_exists(XOOPS_ROOT_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $xoopsModule->getVar('dirname') . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'providers' . DIRECTORY_SEPARATOR . mb_strtolower($shotProvider) . '.php')) {
107
            include_once XOOPS_ROOT_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $xoopsModule->getVar('dirname') . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'providers' . DIRECTORY_SEPARATOR . mb_strtolower($shotProvider) . '.php';
108
            $shotClass = ucfirst($xoopsModule->getVar('dirname')) . ucfirst($shotProvider);
109
            $shotObj = new $shotClass;
110
            $shotObj->setProviderPublicKey($xoopsModuleConfig['shotpubkey']);
111
            $shotObj->setProviderPrivateKey($xoopsModuleConfig['shotprivkey']);
112
            $shotObj->setShotSize(array('width' => $xoopsModuleConfig['shotwidth']));
113
            $shotObj->setSiteUrl($myts->htmlSpecialChars($url));
114
            $shotImgSrc = $shotObj->getProviderUrl();
115
            if ($xoopsModuleConfig['shotattribution']) {
116
                $shotAttribution = $shotObj->getAttribution(true);
117
            } else {
118
                $shotAttribution = '';
119
            }
120
        }
121
    }
122
} else {
123
    $xoopsTpl->assign('show_screenshot', false);
124
}
125
$xoopsTpl->assign('shot_attribution', $shotAttribution);
126
$xoopsTpl->assign('link', array('url'          => $myts->htmlSpecialChars($url),
127
                                'id'           => $lid,
128
                                'cid'          => $cid,
129
                                'rating'       => number_format($rating, 2),
130
                                'ltitle'       => $myts->htmlSpecialChars($myts->stripSlashesGPC($ltitle)),
131
                                'title'        => $myts->htmlSpecialChars($myts->stripSlashesGPC($ltitle)).$new.$pop,
132
                                'category'     => $pathFromId,
133
                                'logourl'      => $myts->htmlSpecialChars(trim($logourl)),
134
                                'updated'      => formatTimestamp($time, 'm'),
135
                                'description'  => $myts->displayTarea($myts->stripSlashesGPC($description), 0),
136
                                'adminlink'    => $adminlink,
137
                                'hits'         => $hits,
138
                                'votes'        => $votestring,
139
                                'comments'     => $comments,
140
                                'mail_subject' => rawurlencode(sprintf(_MD_MYLINKS_INTRESTLINK, $xoopsConfig['sitename'])),
141
                                'mail_body'    => rawurlencode(sprintf(_MD_MYLINKS_INTLINKFOUND, $xoopsConfig['sitename']) . ':  ' . XOOPSMYLINKURL . "/singlelink.php?lid={$lid}"),
142
                                'shot_img_src'  => $shotImgSrc,
143
                                'shot_img_href' => $shotImgHref)
144
);
145
146
$xoopsTpl->assign(array('lang_description'  => _MD_MYLINKS_DESCRIPTIONC,
147
                        'lang_lastupdate'   => _MD_MYLINKS_LASTUPDATEC,
148
                        'lang_hits'         => _MD_MYLINKS_HITSC,
149
                        'lang_rating'       => _MD_MYLINKS_RATINGC,
150
                        'lang_ratethissite' => _MD_MYLINKS_RATETHISSITE,
151
                        'lang_reportbroken' => _MD_MYLINKS_REPORTBROKEN,
152
                        'lang_tellafriend'  => _MD_MYLINKS_TELLAFRIEND,
153
                        'lang_modify'       => _MD_MYLINKS_MODIFY,
154
                        'lang_category'     => _MD_MYLINKS_CATEGORYC,
155
                        'lang_visit'        => _MD_MYLINKS_VISIT,
156
                        'lang_comments'     => _COMMENTS)
157
);
158
//wanikoo
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
159
/*
160
if (file_exists(XOOPS_ROOT_PATH."/include/moremetasearch.php")&&$mylinks_show_externalsearch) {
161
  include_once XOOPS_ROOT_PATH."/include/moremetasearch.php";
162
  $thisltitle = $myts->htmlSpecialChars($ltitle);
163
  $_REQUEST['query']= $thisltitle;
164
  $engineblocktitle = _MD_MYLINKS_EXTERNALSEARCH;
165
  $engineblocktitle .= sprintf(_MD_MYLINKS_EXTERNALSEARCH_KEYWORD, _MD_MYLINKS_TITLE, $thisltitle);
166
  $location_list=moremeta("meta_page","on");
167
  $metaresult = more_meta_page($location_list, $target="_blank", $display = false, $engineblocktitle);
168
  $xoopsTpl->assign('moremetasearch', "<br><br>".$metaresult);
169
} else {
170
  $xoopsTpl->assign('moremetasearch', '');
171
}
172
*/
173
$xoopsTpl->assign('moremetasearch', '');
174
175
//wanikoo theme changer
176
$xoopsTpl->assign('lang_themechanger', _MD_MYLINKS_THEMECHANGER);
177
$mymylinkstheme_options = '';
178
179 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...
180
    $mymylinkstheme_options .= "<option value='{$mymylinkstheme}'";
181
    if ($mymylinkstheme == $GLOBALS['mylinks_theme']) {
182
        $mymylinkstheme_options .= ' selected="selected"';
183
    }
184
    $mymylinkstheme_options .= ">{$mymylinkstheme}</option>";
185
}
186
187
$mylinkstheme_select = "<select name='mylinks_theme_select' onchange='submit();' size='1'>{$mymylinkstheme_options}</select>";
188
189
$xoopsTpl->assign('mylinksthemeoption', $mylinkstheme_select);
190
//wanikoo end
191
192
//wanikoo search
193 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...
194
   include_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/search.php';
195
} else {
196
   include_once XOOPS_ROOT_PATH . '/language/english/search.php';
197
}
198
$xoopsTpl->assign('lang_all', _SR_ALL);
199
$xoopsTpl->assign('lang_any', _SR_ANY);
200
$xoopsTpl->assign('lang_exact', _SR_EXACT);
201
$xoopsTpl->assign('lang_search', _SR_SEARCH);
202
$xoopsTpl->assign('module_id', $xoopsModule->getVar('mid'));
203
//
204
//category head
205
$catarray = array();
206
if ($mylinks_show_letters) {
207
    $catarray['letters'] = ml_wfd_letters();
208
}
209
if ($mylinks_show_toolbar) {
210
    $catarray['toolbar'] = ml_wfd_toolbar();
211
}
212
$xoopsTpl->assign('catarray', $catarray);
213
//pagetitle (module name - singlelink)
214
$xoopsTpl->assign('xoops_pagetitle', $xoopsModule->getVar('name') . ' - ' . $myts->htmlSpecialChars($myts->stripSlashesGPC($ltitle)));
215
//category jump box
216
$catjumpbox = "<form name='catjumpbox' method='get' action='viewcat.php'>\n"
217
              . '  <strong>' . _MD_MYLINKS_CATEGORYC . "</strong>&nbsp;\n"
218
              . '  ' . $myCatTree->makeSelBox('title', 'title', $cid) . "&nbsp;\n"
219
             ."  <input type='submit' value='" . _SUBMIT . "'>\n"
220
             ."</form>\n";
221
$xoopsTpl->assign('mylinksjumpbox', $catjumpbox);
222
223
include XOOPS_ROOT_PATH . '/include/comment_view.php';
224
include_once XOOPSMYLINKPATH . '/footer.php';
225