1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @param int $limit |
4
|
|
|
* @param int $offset |
5
|
|
|
* @return array |
6
|
|
|
*/ |
7
|
|
|
function mylinks_feednew($limit = 0, $offset = 0) |
8
|
|
|
{ |
9
|
|
|
global $xoopsDB; |
10
|
|
|
|
11
|
|
|
$myts = MyTextSanitizer::getInstance(); |
12
|
|
|
$dirname = basename(dirname(__DIR__)); |
13
|
|
|
$moduleURL = XOOPS_URL . "/modules/{$dirname}"; |
14
|
|
|
|
15
|
|
|
$limit = ((int)$limit > 0) ? (int)$limit : 0; |
16
|
|
|
$offset = ((int)$offset > 0) ? (int)$offset : 0; |
17
|
|
|
|
18
|
|
|
if (isset($_GET['cid'])) { |
19
|
|
|
$categoryid = ((int)$_GET['cid'] && (int)($_GET['cid'] > 0)) ? (int)$_GET['cid'] : 0; |
20
|
|
|
$sql = 'SELECT l.lid, l.title as ltitle, l.date, l.cid, l.submitter, l.hits, t.description, c.title as ctitle FROM ' . $xoopsDB->prefix('mylinks_links') . ' l, ' . $xoopsDB->prefix('mylinks_text') . ' t, ' . $xoopsDB->prefix('mylinks_cat') |
21
|
|
|
. " c WHERE l.cid= {$categoryid} AND t.lid=l.lid AND l.cid=c.cid AND l.status>0 ORDER BY l.date DESC"; |
22
|
|
|
} else { |
23
|
|
|
$sql = 'SELECT l.lid, l.title as ltitle, l.date, l.cid, l.submitter, l.hits, t.description, c.title as ctitle FROM ' . $xoopsDB->prefix('mylinks_links') . ' l, ' . $xoopsDB->prefix('mylinks_text') . ' t, ' . $xoopsDB->prefix('mylinks_cat') |
24
|
|
|
. ' c WHERE t.lid=l.lid AND l.cid=c.cid AND l.status>0 ORDER BY l.date DESC'; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$result = $xoopsDB->query($sql, $limit, $offset); |
28
|
|
|
|
29
|
|
|
$i = 0; |
30
|
|
|
$ret = array(); |
31
|
|
|
|
32
|
|
View Code Duplication |
while ($row = $xoopsDB->fetchArray($result)) { |
|
|
|
|
33
|
|
|
$ret[$i]['link'] = "{$moduleURL}/singlelink.php?lid={$row['lid']}"; |
34
|
|
|
$ret[$i]['cat_link'] = "{$moduleURL}/viewcat.php?cid={$row['cid']}"; |
35
|
|
|
$ret[$i]['title'] = $row['ltitle']; // link title |
36
|
|
|
$ret[$i]['time'] = $row['date']; // date |
37
|
|
|
// $ret[$i]['description'] = $row['description']; |
38
|
|
|
$ret[$i]['id'] = $row['lid']; // atom feed |
39
|
|
|
$ret[$i]['description'] = $myts->displayTarea($row['description'], 0); //no html |
40
|
|
|
$ret[$i]['cat_name'] = $row['ctitle']; // category |
41
|
|
|
$ret[$i]['hits'] = $row['hits']; // counter |
42
|
|
|
// $ret[$i]['uid'] = $row['submitter']; // user name |
43
|
|
|
$i++; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $ret; |
47
|
|
|
} |
48
|
|
|
|
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.