1
|
|
|
<?php |
|
|
|
|
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 ) |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
$mydirname = basename( dirname( dirname( __FILE__ ) ) ); |
23
|
|
|
global $xoopsUser; |
|
|
|
|
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) { |
|
|
|
|
33
|
|
|
return false; |
34
|
|
|
} else { |
35
|
|
|
redirect_header( 'index.php', 3, _NOPERM ); |
36
|
|
|
exit(); |
|
|
|
|
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; |
|
|
|
|
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 . " "; |
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] . "' /> " . _MB_WFL_FILES . ""; |
108
|
|
|
$form .= " <br />" . _MB_WFL_CHARS . " <input type='text' name='options[]' value='" . $options[2] . "' /> " . _MB_WFL_LENGTH . ""; |
109
|
|
|
$form .= " <br />" . _MB_WFL_DATEFORMAT . " <input type='text' name='options[]' value='" . $options[3] . "' /> " . _MB_WFL_DATEFORMATMANUAL; |
110
|
|
|
|
111
|
|
|
return $form; |
112
|
|
|
} |
113
|
|
|
|
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.