data.inc.php ➔ mylinks_data()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 8
nop 2
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
1
<?php
2
// $Id: data.inc.php 8112 2011-11-06 13:41:14Z beckmi $
3
4
// 2005-10-01 K.OHWADA
5
// category, counter
6
7
// 2005-03-28 K.OHWADA
8
// bug fix: forget to declare $myts
9
10
// 2004/08/20 K.OHWADA
11
// atom feed
12
13
//================================================================
14
// What's New Module
15
// get links from module
16
// for mylinks 1.10 <http://www.xoops.org/>
17
// 2003.12.20 K.OHWADA
18
//================================================================
19
20
/**
21
 * @param int $limit
22
 * @param int $offset
23
 * @return array
24
 */
25
function mylinks_new($limit = 0, $offset = 0)
26
{
27
    global $xoopsDB;
28
29
    $myts      = MyTextSanitizer::getInstance();
30
    $dirname   = basename(dirname(__DIR__));
31
    $moduleURL = XOOPS_URL . "/modules/{$dirname}";
32
33
    $limit  = ((int)$limit > 0) ? (int)$limit : 0;
34
    $offset = ((int)$offset > 0) ? (int)$offset : 0;
35
36
    $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')
37
              . ' c WHERE t.lid=l.lid AND l.cid=c.cid AND l.status>0 ORDER BY l.date DESC';
38
    $result = $xoopsDB->query($sql, $limit, $offset);
39
40
    $i   = 0;
41
    $ret = array();
42
43 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...
44
        $ret[$i]['link']     = "{$moduleURL}/singlelink.php?lid={$row['lid']}";
45
        $ret[$i]['cat_link'] = "{$moduleURL}/viewcat.php?cid={$row['cid']}";
46
        $ret[$i]['title']    = $row['ltitle'];
47
        $ret[$i]['time']     = $row['date'];
48
        //        $ret[$i]['description'] = $row['description'];
49
50
        // atom feed
51
        $ret[$i]['id']          = $row['lid'];
52
        $ret[$i]['description'] = $myts->displayTarea($row['description'], 0);    //no html
53
        $ret[$i]['cat_name']    = $row['ctitle'];   // category
54
        $ret[$i]['hits']        = $row['hits'];         // counter
55
        //        $ret[$i]['uid'] = $row['submitter'];   // show user name
56
        $i++;
57
    }
58
59
    return $ret;
60
}
61
62
/**
63
 * @return int
64
 */
65
function mylinks_num()
66
{
67
    global $xoopsDB;
68
69
    $sql   = 'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mylinks_links') . ' WHERE status>0 ORDER BY lid';
70
    $array = $xoopsDB->fetchRow($xoopsDB->query($sql));
71
    $num   = $array[0];
72
    if (empty($num)) {
73
        $num = 0;
74
    }
75
76
    return $num;
77
}
78
79
/**
80
 * @param int $limit
81
 * @param int $offset
82
 * @return array
83
 */
84
function mylinks_data($limit = 0, $offset = 0)
85
{
86
    global $xoopsDB;
87
    $dirname = basename(dirname(__DIR__));
88
89
    $limit  = ((int)$limit > 0) ? (int)$limit : 0;
90
    $offset = ((int)$offset > 0) ? (int)$offset : 0;
91
92
    $sql    = 'SELECT lid, title, date FROM ' . $xoopsDB->prefix('mylinks_links') . ' WHERE status>0 ORDER BY lid';
93
    $result = $xoopsDB->query($sql, $limit, $offset);
94
95
    $i   = 0;
96
    $ret = array();
97
98
    while ($row = $xoopsDB->fetchArray($result)) {
99
        $id               = $row['lid'];
100
        $ret[$i]['id']    = $id;
101
        $ret[$i]['link']  = XOOPS_URL . "/modules/{$dirname}/singlelink.php?lid={$id}";
102
        $ret[$i]['title'] = $row['title'];
103
        $ret[$i]['time']  = $row['date'];
104
        $i++;
105
    }
106
107
    return $ret;
108
}
109