feeddata.inc.php ➔ mylinks_feednew()   B
last analyzed

Complexity

Conditions 7
Paths 40

Size

Total Lines 41

Duplication

Lines 13
Ratio 31.71 %

Importance

Changes 0
Metric Value
cc 7
nc 40
nop 2
dl 13
loc 41
rs 8.3306
c 0
b 0
f 0
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)) {
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...
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