Completed
Push — master ( 76b4a1...141e43 )
by Michael
06:17 queued 02:44
created

blocks/xfguestbook_new.php (1 issue)

Severity

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: block/xfguestbook_new.php,v 1.11 2004/12/02 C. Félix AKA the Cat
3
//  ------------------------------------------------------------------------ //
4
//             XF Guestbook                                                  //
5
// ------------------------------------------------------------------------- //
6
//  This program is free software; you can redistribute it and/or modify     //
7
//  it under the terms of the GNU General Public License as published by     //
8
//  the Free Software Foundation; either version 2 of the License, or        //
9
//  (at your option) any later version.                                      //
10
//                                                                           //
11
//  You may not change or alter any portion of this comment or credits       //
12
//  of supporting developers from this source code or any supporting         //
13
//  source code which is considered copyrighted (c) material of the          //
14
//  original comment or credit authors.                                      //
15
//                                                                           //
16
//  This program is distributed in the hope that it will be useful,          //
17
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
18
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
19
//  GNU General Public License for more details.                             //
20
//                                                                           //
21
//  You should have received a copy of the GNU General Public License        //
22
//  along with this program; if not, write to the Free Software              //
23
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
24
//  ------------------------------------------------------------------------ //
25
26
/**
27
 * @param $options
28
 * @return array
29
 */
30
function b_xfguestbook_show($options)
31
{
32
    global $xoopsModule, $xoopsModuleConfig, $xoopsDB;
33
    if (empty($xoopsModule) || 'xfguestbook' !== $xoopsModule->getVar('dirname')) {
34
        $module_handler = xoops_getHandler('module');
35
        $module = $module_handler->getByDirname('xfguestbook');
36
        $config_handler = xoops_getHandler('config');
37
        $config =& $config_handler->getConfigsByCat(0, $module->getVar('mid'));
38
    } else {
39
        $module =& $xoopsModule;
40
        $config =& $xoopsModuleConfig;
41
    }
42
    
43
    $block = array();
44
    if (0 != $options[1]) {
45
        $block['full_view'] = true;
46
    } else {
47
        $block['full_view'] = false;
48
    }
49
    
50
    $msg_hnd = xoops_getModuleHandler('msg', 'xfguestbook');
51
    $criteria = new Criteria('moderate', '0', '=');
52
    $criteria->setSort('post_time');
53
    $criteria->setOrder('DESC');
54
    $criteria->setLimit($options[0]);
55
    $nbmsg = $msg_hnd->countMsg($criteria);
56
    
57
    $a_item = array();
58
    
59
    if ($nbmsg > 0) {
60
        $msg = $msg_hnd->getObjects($criteria);
61
        $ts = MyTextSanitizer::getInstance();
0 ignored issues
show
$ts is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
62
        foreach ($msg as $onemsg) {
63
            $msg_id = $onemsg->getVar('msg_id');
64
            $a_item['id'] = $msg_id;
65
            $a_item['title'] = $onemsg->getVar('title');
66
            if (!XOOPS_USE_MULTIBYTES) {
67
                $length = strlen($onemsg->getVar('title'));
68
                if ($length >= $options[1]) {
69
                    $a_item['title'] = substr($a_item['title'], 0, $options[1] - $length) . '...';
70
                }
71
            }
72
            $a_item['name'] = $onemsg->getVar('uname');
73
            $a_item['date'] = formatTimestamp($onemsg->getVar('post_time'), 's') ;
74
            $block['items'][] = $a_item;
75
            unset($a_item);
76
        }
77
    } else {
78
        $block['nbmsg'] = 0;
79
    }
80
81
    return $block;
82
}
83
84
/**
85
 * @param $options
86
 * @return string
87
 */
88
function b_xfguestbook_edit($options)
89
{
90
    $form = '' . _MB_XFGB_DISP . '&nbsp;';
91
    $form .= "<input type=\"text\" name=\"options[]\" value=\"".$options[0]."\" />&nbsp;"._MB_XFGB_NBMSG . '';
92
    $form .= '&nbsp;<br>' . _MB_XFGB_CHARS . "&nbsp;<input type='text' name='options[]' value='" . $options[1] . "' />&nbsp;" . _MB_XFGB_LENGTH . '';
93
94
    return $form;
95
}
96