Completed
Push — master ( c39b68...a1acf8 )
by Michael
03:03
created

functions.php ➔ TDMDownloads_Thumbnail()   C

Complexity

Conditions 8
Paths 12

Size

Total Lines 33
Code Lines 23

Duplication

Lines 13
Ratio 39.39 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
cc 8
eloc 23
c 4
b 0
f 1
nc 12
nop 2
dl 13
loc 33
rs 5.3846
1
<?php
2
/**
3
 * TDMDownload
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright   Gregory Mage (Aka Mage)
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Gregory Mage (Aka Mage)
15
 */
16
17
//**********************************************************************************************************************
18
// ModuleName_checkModuleAdmin
19
//**********************************************************************************************************************
20
// return true if moduladmin framworks exists.
21
//**********************************************************************************************************************
22
function TDMDownloads_checkModuleAdmin()
0 ignored issues
show
Coding Style introduced by
TDMDownloads_checkModuleAdmin uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
23
{
24
    if ( file_exists($GLOBALS['xoops']->path('/Frameworks/moduleclasses/moduleadmin/moduleadmin.php'))) {
25
        include_once $GLOBALS['xoops']->path('/Frameworks/moduleclasses/moduleadmin/moduleadmin.php');
26
27
        return true;
28
    } else {
29
        echo xoops_error("Error: You don't use the Frameworks \"admin module\". Please install this Frameworks");
30
31
        return false;
32
    }
33
}
34
35
function TDMDownloads_MygetItemIds($permtype,$dirname)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
36
{
37
    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...
38
    static $permissions = array();
39
    if (is_array($permissions) && array_key_exists($permtype, $permissions)) {
40
        return $permissions[$permtype];
41
    }
42
       $module_handler =& xoops_gethandler('module');
43
       $tdmModule =& $module_handler->getByDirname($dirname);
44
       $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
45
       $gperm_handler =& xoops_gethandler('groupperm');
46
       $categories = $gperm_handler->getItemIds($permtype, $groups, $tdmModule->getVar('mid'));
47
48
    return $categories;
49
}
50
51
/**
52
* retourne le nombre de t�l�chargements dans le cat�gories enfants d'une cat�gorie
53
**/
54
55
function TDMDownloads_NumbersOfEntries($mytree, $categories, $entries,$cid)
56
{
57
    $count = 0;
58
    $child_arr = array();
0 ignored issues
show
Unused Code introduced by
$child_arr 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...
59
    if (in_array($cid, $categories)) {
60
        $child = $mytree->getAllChild($cid);
61
        foreach (array_keys($entries) as $i) {
62
            if ($entries[$i]->getVar('cid') == $cid) {
63
                $count++;
64
            }
65
            foreach (array_keys($child) as $j) {
66
                if ($entries[$i]->getVar('cid') == $j) {
67
                    $count++;
68
                }
69
            }
70
        }
71
    }
72
73
    return $count;
74
}
75
76
/**
77
* retourne une image "nouveau" ou "mise � jour"
78
**/
79
80
function TDMDownloads_Thumbnail($time, $status)
0 ignored issues
show
Coding Style introduced by
TDMDownloads_Thumbnail uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
81
{
82
    global $xoopsModuleConfig;
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...
83
    $count = 7;
84
    $new = '';
85
    $startdate = (time()-(86400 * $count));
86
    if ($xoopsModuleConfig['showupdated'] == 1) {
87
        if ($startdate < $time) {
88
            $language = $GLOBALS['xoopsConfig']['language'];
89
            if ( !is_dir( XOOPS_ROOT_PATH . "/modules/TDMDownloads/language/" . $language . "/" ) ) {
90
                $language = 'english';
91
            }
92
            $img_path = XOOPS_ROOT_PATH . "/modules/TDMDownloads/language/" . $language . "/";
93
            $img_url = XOOPS_URL . "/modules/TDMDownloads/language/" . $language . "/";
94
            if ($status==1) {
95 View Code Duplication
                if ( is_readable( $img_path . 'new.png') ) {
0 ignored issues
show
Duplication introduced by
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...
96
                    $new = '&nbsp;<img src="' . $img_url . 'new.png" alt="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '" title="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '"/>';
97
                } else {
98
                    $new = '&nbsp;<img src="' . XOOPS_URL . '/modules/TDMDownloads/language/english/new.png" alt="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '" title="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '"/>';
99
                }
100 View Code Duplication
            } elseif ($status==2) {
0 ignored issues
show
Duplication introduced by
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...
101
                if ( is_readable( $img_path . 'updated.png') ) {
102
                    $new = '&nbsp;<img src="' . $img_url . 'updated.png" alt="' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . '" title="' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . '"/>';
103
                } else {
104
                    $new = '&nbsp;<img src="' . XOOPS_URL . '/modules/TDMDownloads/language/english/updated.png" alt="' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . '" title="' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . '"/>';
105
                }
106
107
            }
108
        }
109
    }
110
111
    return $new;
112
}
113
114
/**
115
* retourne une image "populaire"
116
**/
117
118
function TDMDownloads_Popular($hits)
0 ignored issues
show
Coding Style introduced by
TDMDownloads_Popular uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
119
{
120
    global $xoopsModuleConfig;
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...
121
    $pop = '';
122
    if ($hits >= $xoopsModuleConfig['popular']) {
123
        $language = $GLOBALS['xoopsConfig']['language'];
124
        if ( !is_dir( XOOPS_ROOT_PATH . "/modules/TDMDownloads/language/" . $language . "/" ) ) {
125
            $language = 'english';
126
        }
127
        $img_path = XOOPS_ROOT_PATH . "/modules/TDMDownloads/language/" . $language . "/";
128
        $img_url = XOOPS_URL . "/modules/TDMDownloads/language/" . $language . "/";
129 View Code Duplication
        if ( is_readable( $img_path . 'popular.png') ) {
0 ignored issues
show
Duplication introduced by
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...
130
            $pop = '&nbsp;<img src="' . $img_url . 'popular.png" alt="' . _MD_TDMDOWNLOADS_INDEX_POPULAR . '" title="' . _MD_TDMDOWNLOADS_INDEX_POPULAR . '"/>';
131
        } else {
132
            $pop = '&nbsp;<img src ="' . XOOPS_URL . '/modules/TDMDownloads/language/english/popular.png" alt="' . _MD_TDMDOWNLOADS_INDEX_POPULAR . '" title="' . _MD_TDMDOWNLOADS_INDEX_POPULAR . '"/>';
133
        }
134
    }
135
136
    return $pop;
137
}
138
139
function trans_size($size)
140
{
141
    if ($size>0) {
142
        $mb = 1024*1024;
143
        if ($size > $mb) {
144
            $mysize = sprintf ("%01.2f",$size/$mb) . " MB";
145
        } elseif ($size >= 1024) {
146
            $mysize = sprintf ("%01.2f",$size/1024) . " KB";
147
        } else {
148
            $mysize = sprintf(_AM_TDMDOWNLOADS_NUMBYTES,$size);
149
        }
150
151
        return $mysize;
152
    } else {
153
        return '';
154
    }
155
}
156
157
function TDMDownloads_CleanVars( &$global, $key, $default = '', $type = 'int' )
158
{
159
    switch ($type) {
160
        case 'string':
161
            $ret = ( isset( $global[$key] ) ) ? filter_var( $global[$key], FILTER_SANITIZE_MAGIC_QUOTES ) : $default;
162
            break;
163
        case 'int': default:
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

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

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

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

Loading history...
164
            $ret = ( isset( $global[$key] ) ) ? filter_var( $global[$key], FILTER_SANITIZE_NUMBER_INT ) : $default;
165
            break;
166
    }
167
    if ($ret === false) {
168
        return $default;
169
    }
170
171
    return $ret;
172
}
173
174
function TDMDownloads_PathTree($mytree, $key, $category_array, $title, $prefix = '' )
175
{
176
    $category_parent = $mytree->getAllParent($key);
177
    $category_parent = array_reverse($category_parent);
178
    $Path = '';
179
    foreach (array_keys($category_parent) as $j) {
180
        $Path .= $category_parent[$j]->getVar($title) . $prefix;
181
    }
182 View Code Duplication
    if (array_key_exists($key, $category_array)) {
0 ignored issues
show
Duplication introduced by
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...
183
        $first_category = $category_array[$key]->getVar($title);
184
    } else {
185
        $first_category = '';
186
    }
187
    $Path .= $first_category;
188
189
    return $Path;
190
}
191
192
function TDMDownloads_PathTreeUrl($mytree, $key, $category_array, $title, $prefix = '', $link = false, $order = 'ASC', $lasturl = false)
193
{
194
    global $xoopsModule;
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...
195
    $category_parent = $mytree->getAllParent($key);
196
    if ($order == 'ASC') {
197
        $category_parent = array_reverse($category_parent);
198
        if ($link == true) {
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...
199
            $Path = '<a href="index.php">' . $xoopsModule->name() . '</a>' . $prefix;
200
        } else {
201
            $Path = $xoopsModule->name() . $prefix;
202
        }
203
    } else {
204 View Code Duplication
        if (array_key_exists($key, $category_array)) {
0 ignored issues
show
Duplication introduced by
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...
205
            $first_category = $category_array[$key]->getVar($title);
206
        } else {
207
            $first_category = '';
208
        }
209
        $Path = $first_category . $prefix;
210
    }
211
    foreach (array_keys($category_parent) as $j) {
212
        if ($link == true) {
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...
213
            $Path .= '<a href="viewcat.php?cid=' . $category_parent[$j]->getVar('cat_cid') . '">' . $category_parent[$j]->getVar($title) . '</a>' . $prefix;
214
        } else {
215
            $Path .= $category_parent[$j]->getVar($title) . $prefix;
216
        }
217
    }
218
    if ($order == 'ASC') {
219
        if (array_key_exists($key, $category_array)) {
220
            if ($lasturl == true) {
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...
221
                $first_category = '<a href="viewcat.php?cid=' . $category_array[$key]->getVar('cat_cid') . '">' . $category_array[$key]->getVar($title) . '</a>';
222
            } else {
223
                $first_category = $category_array[$key]->getVar($title);
224
            }
225
        } else {
226
            $first_category = '';
227
        }
228
        $Path .= $first_category;
229
    } else {
230
        if ($link == true) {
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...
231
            $Path .= '<a href="index.php">' . $xoopsModule->name() . '</a>';
232
        } else {
233
            $Path .= $xoopsModule->name();
234
        }
235
    }
236
237
    return $Path;
238
}
239