Completed
Push — master ( bbda49...c5c3b2 )
by Michael
02:49
created

wflinks_top.php ➔ b_wflinks_top_show()   C

Complexity

Conditions 8
Paths 11

Size

Total Lines 40
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 30
nc 11
nop 1
dl 0
loc 40
rs 5.3846
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 20 and the first side effect is on line 12.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * $Id: wflinks_top.php v 1.00 21 June 2005 John N Exp $
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
defined('XOOPS_ROOT_PATH') || die('XOOPS root path not defined');
13
14
// checkBlockgroups()
15
//
16
// @param integer $cid
17
// @param string $permType
18
// @param boolean $redirect
19
// @return
20 View Code Duplication
function checkBlockgroups( $cid = 0, $permType = 'WFLinkCatPerm', $redirect = false )
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
21
{
22
    $mydirname = basename( dirname(  dirname( __FILE__ ) ) );
23
    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...
24
25
    $groups = is_object( $xoopsUser ) ? $xoopsUser -> getGroups() : XOOPS_GROUP_ANONYMOUS;
26
    $gperm_handler = &xoops_gethandler( 'groupperm' );
27
28
    $module_handler = &xoops_gethandler( 'module' );
29
    $module = &$module_handler -> getByDirname( $mydirname );
30
31
    if ( !$gperm_handler -> checkRight( $permType, $cid, $groups, $module -> getVar( 'mid' ) ) ) {
32
        if ($redirect == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
33
            return false;
34
        } else {
35
            redirect_header( 'index.php', 3, _NOPERM );
36
            exit();
0 ignored issues
show
Coding Style Compatibility introduced by
The function checkBlockgroups() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
37
        }
38
    }
39
    unset( $module );
40
41
    return true;
42
}
43
44
// Function: b_mylinks_top_show
45
// Input   : $options[0] = date for the most recent links
46
// 		           hits for the most popular links
47
//           $options[1] = How many links are displayes
48
//           $options[2] = Length of title
49
//           $options[3] = Date format
50
//           $block['content'] = The optional above content
51
// Output  : Returns the most recent or most popular links
52
function b_wflinks_top_show( $options )
53
{
54
    $mydirname = basename( dirname(  dirname( __FILE__ ) ) );
55
    global $xoopsDB;
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...
56
57
    $block = array();
58
    $time = time();
59
    $modhandler = &xoops_gethandler( 'module' );
60
    $wflModule = &$modhandler -> getByDirname( $mydirname );
61
    $config_handler = &xoops_gethandler( 'config' );
62
    $wflModuleConfig = &$config_handler -> getConfigsByCat( 0, $wflModule -> getVar( 'mid' ) );
63
    $wfmyts = &MyTextSanitizer :: getInstance();
64
65
    $result = $xoopsDB -> query( "SELECT lid, cid, title, published, hits FROM " . $xoopsDB -> prefix( 'wflinks_links' ) . " WHERE published > 0 AND published <= " . $time . " AND (expired = 0 OR expired > " . $time . ") AND offline = 0 ORDER BY " . $options[0] . " DESC", $options[1], 0 );
66
    while ( $myrow = $xoopsDB -> fetchArray( $result ) ) {
67
        if ( false == checkBlockgroups( $myrow['cid'] ) || $myrow['cid'] == 0 ) {
68
            continue;
69
        }
70
        $linkload = array();
71
        $title = $wfmyts -> htmlSpecialChars( $wfmyts -> stripSlashesGPC( $myrow["title"] ) );
72
        if (!XOOPS_USE_MULTIBYTES) {
73
            if ( strlen( $myrow['title'] ) >= $options[2] ) {
74
                $title = substr( $myrow['title'], 0, ( $options[2] -1 ) ) . "...";
75
            }
76
        }
77
        $linkload['id'] = intval( $myrow['lid'] );
78
        $linkload['cid'] = intval( $myrow['cid'] );
79
        $linkload['title'] = $title;
80
        if ($options[0] == "published") {
81
            $linkload['date'] = formatTimestamp( $myrow['published'], $options[3] );
82
        } elseif ($options[0] == "hits") {
83
            $linkload['hits'] = $myrow['hits'];
84
        }
85
        $linkload['dirname'] = $wflModule -> getVar( 'dirname' );
86
        $block['links'][] = $linkload;
87
    }
88
    unset( $_block_check_array );
89
90
    return $block;
91
}
92
93
// b_wflinks_top_edit()
94
//
95
// @param $options
96
// @return
97
function b_wflinks_top_edit( $options )
98
{
99
    $form = "" . _MB_WFL_DISP . "&nbsp;";
100
    $form .= "<input type='hidden' name='options[]' value='";
101
    if ($options[0] == "published") {
102
        $form .= "published'";
103
    } else {
104
        $form .= "hits'";
105
    }
106
    $form .= " />";
107
    $form .= "<input type='text' name='options[]' value='" . $options[1] . "' />&nbsp;" . _MB_WFL_FILES . "";
108
    $form .= "&nbsp;<br />" . _MB_WFL_CHARS . "&nbsp;<input type='text' name='options[]' value='" . $options[2] . "' />&nbsp;" . _MB_WFL_LENGTH . "";
109
    $form .= "&nbsp;<br />" . _MB_WFL_DATEFORMAT . "&nbsp;<input type='text' name='options[]' value='" . $options[3] . "' />&nbsp;" . _MB_WFL_DATEFORMATMANUAL;
110
111
    return $form;
112
}
113