Completed
Push — master ( 0424ea...923121 )
by Michael
03:57
created

admin/adsligh_rsslib.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 23.

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.

Loading history...
2
/*
3
-------------------------------------------------------------------------
4
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
23
$RSS_Content = array();
24
25
/**
26
 * @param $item
27
 * @param $type
28
 *
29
 * @return array
30
 */
31
function RSS_Tags($item, $type)
32
{
33
    $y     = array();
34
    $tnl   = $item->getElementsByTagName('title');
35
    $tnl   = $tnl->item(0);
36
    $title = $tnl->firstChild->textContent;
37
38
    $tnl  = $item->getElementsByTagName('link');
39
    $tnl  = $tnl->item(0);
40
    $link = $tnl->firstChild->textContent;
41
42
    $tnl  = $item->getElementsByTagName('pubDate');
43
    $tnl  = $tnl->item(0);
44
    $date = $tnl->firstChild->textContent;
45
46
    $tnl         = $item->getElementsByTagName('description');
47
    $tnl         = $tnl->item(0);
48
    $description = $tnl->firstChild->textContent;
49
50
    $y['title']       = $title;
51
    $y['link']        = $link;
52
    $y['date']        = $date;
53
    $y['description'] = $description;
54
    $y['type']        = $type;
55
56
    return $y;
57
}
58
59
/**
60
 * @param $channel
61
 */
62
function RSS_Channel($channel)
63
{
64
    global $RSS_Content;
65
66
    $items = $channel->getElementsByTagName('item');
67
68
    // Processing channel
69
70
    $y = RSS_Tags($channel, 0);        // get description of channel, type 0
71
    array_push($RSS_Content, $y);
72
73
    // Processing articles
74
75
    foreach ($items as $item) {
76
        $y = RSS_Tags($item, 1);    // get description of article, type 1
77
        array_push($RSS_Content, $y);
78
    }
79
}
80
81
/**
82
 * @param $url
83
 */
84
function RSS_Retrieve($url)
85
{
86
    global $RSS_Content;
87
88
    $doc = new DOMDocument();
89
    $doc->load($url);
90
91
    $channels = $doc->getElementsByTagName('channel');
92
93
    $RSS_Content = array();
94
95
    foreach ($channels as $channel) {
96
        RSS_Channel($channel);
97
    }
98
}
99
100
/**
101
 * @param $url
102
 */
103
function RSS_RetrieveLinks($url)
104
{
105
    global $RSS_Content;
106
107
    $doc = new DOMDocument();
108
    $doc->load($url);
109
110
    $channels = $doc->getElementsByTagName('channel');
111
112
    $RSS_Content = array();
113
114
    foreach ($channels as $channel) {
115
        $items = $channel->getElementsByTagName('item');
116
        foreach ($items as $item) {
117
            $y = RSS_Tags($item, 1);    // get description of article, type 1
118
            array_push($RSS_Content, $y);
119
        }
120
    }
121
}
122
123
/**
124
 * @param     $url
125
 * @param int $size
126
 *
127
 * @return string
128
 */
129
function RSS_Links($url, $size = 15)
130
{
131
    global $RSS_Content;
132
133
    $page = '<ul>';
134
135
    RSS_RetrieveLinks($url);
136
    if ($size > 0) {
137
        $recents = array_slice($RSS_Content, 0, $size + 1);
138
    }
139
140
    foreach ($recents as $article) {
141
        $type = $article['type'];
142
        if ($type == 0) {
143
            continue;
144
        }
145
        $title = $article['title'];
146
        $link  = $article['link'];
147
        $page .= "<li><a href=\"$link\">$title</a></li>\n";
148
    }
149
150
    $page .= "</ul>\n";
151
152
    return $page;
153
}
154
155
/**
156
 * @param     $url
157
 * @param int $size
158
 * @param int $site
159
 *
160
 * @return string
161
 */
162
function RSS_Display($url, $size = 15, $site = 0)
163
{
164
    global $RSS_Content;
165
166
    $opened = false;
167
    $page   = '';
168
    $site   = ((int)$site == 0) ? 1 : 0;
169
170
    RSS_Retrieve($url);
171
    if ($size > 0) {
172
        $recents = array_slice($RSS_Content, $site, $size + 1 - $site);
173
    }
174
175
    foreach ($recents as $article) {
176
        $type = $article['type'];
177 View Code Duplication
        if ($type == 0) {
178
            if ($opened == true) {
179
                $page .= '</ul>';
180
                $opened = false;
181
            }
182
            $page .= '<b>';
183
        } else {
184
            if ($opened == false) {
185
                $page .= '<ul>';
186
                $opened = true;
187
            }
188
        }
189
        $title = $article['title'];
190
        $link  = $article['link'];
191
        $page .= "<tr class=\"even\"><td width=\"300\"><img src=\"../assets/images/admin/info_button.png\" border=0 /> <a href=\"$link\">$title</a><br>";
192
193
        $description = $article['description'];
194
        if ($description != false) {
195
            $page .= "$description<br><br></td></tr>";
196
        }
197
        $page .= '';
198
199
        if ($type == 0) {
200
            $page .= '</b>';
201
        }
202
    }
203
204
    if ($opened == true) {
205
        $page .= '</ul>';
206
    }
207
208
    return $page . '';
209
}
210
211
/**
212
 * @param     $url
213
 * @param int $size
214
 * @param int $site
215
 * @param int $withdate
216
 *
217
 * @return string
218
 */
219
function RSS_DisplayForum($url, $size = 15, $site = 0, $withdate = 0)
220
{
221
    global $RSS_Content;
222
223
    $opened = false;
224
    $page   = '';
225
    $site   = ((int)$site == 0) ? 1 : 0;
226
227
    RSS_Retrieve($url);
228
    if ($size > 0) {
229
        $recents = array_slice($RSS_Content, $site, $size + 1 - $site);
230
    }
231
232
    foreach ($recents as $article) {
233
        $type = $article['type'];
234 View Code Duplication
        if ($type == 0) {
235
            if ($opened == true) {
236
                $page .= '</ul>';
237
                $opened = false;
238
            }
239
            $page .= '<b>';
240
        } else {
241
            if ($opened == false) {
242
                $page .= '<ul>';
243
                $opened = true;
244
            }
245
        }
246
247
        $title = $article['title'];
248
        $link  = $article['link'];
249
250
        $page .= "<img src=\"../assets/images/admin/comment.png\" border=0 />&nbsp;&nbsp;&nbsp;<a href=\"$link\">$title</a><br><br>";
251
252
        if ($type == 0) {
253
            $page .= '</b>';
254
        }
255
    }
256
257
    if ($opened == true) {
258
        $page .= '</ul>';
259
    }
260
261
    return $page . '';
262
}
263