Completed
Push — master ( 96da4e...7c5656 )
by Michael
04:52
created

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
2
//
3
// ------------------------------------------------------------------------ //
4
// This program is free software; you can redistribute it and/or modify     //
5
// it under the terms of the GNU General Public License as published by     //
6
// the Free Software Foundation; either version 2 of the License, or        //
7
// (at your option) any later version.                                      //
8
//                                                                          //
9
// You may not change or alter any portion of this comment or credits       //
10
// of supporting developers from this source code or any supporting         //
11
// source code which is considered copyrighted (c) material of the          //
12
// original comment or credit authors.                                      //
13
//                                                                          //
14
// This program is distributed in the hope that it will be useful,          //
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of           //
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
17
// GNU General Public License for more details.                             //
18
//                                                                          //
19
// You should have received a copy of the GNU General Public License        //
20
// along with this program; if not, write to the Free Software              //
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
22
// ------------------------------------------------------------------------ //
23
// Author: phppp (D.J., [email protected])                                  //
24
// URL: http://xoops.org                         //
25
// Project: Article Project                                                 //
26
// ------------------------------------------------------------------------ //
27
ob_start();
28
include __DIR__ . '/header.php';
29
30 View Code Duplication
if (planet_parse_args($args_num, $args, $args_str)) {
0 ignored issues
show
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...
31
    $args['article'] = @$args_num[0];
32
    $args['type']    = @$args_str[0];
33
}
34
35
/* Specified Article */
36
$article_id = (int)(empty($_GET['article']) ? @$args['article'] : $_GET['article']);
37
/* Specified Category */
38
$category_id = (int)(empty($_GET['category']) ? @$args['category'] : $_GET['category']);
39
/* Specified Blog */
40
$blog_id = (int)(empty($_GET['blog']) ? @$args['blog'] : $_GET['blog']);
41
/* Specified Bookmar(Favorite) UID */
42
$uid = (int)(empty($_GET['uid']) ? @$args['uid'] : $_GET['uid']);
43
44
$type = empty($_GET['type']) ? (empty($_GET['op']) ? @$args['type'] : $_GET['op']) : $_GET['type'];
45
$type = strtoupper($type);
46
47
$valid_format = array('RSS0.91', 'RSS1.0', 'RSS2.0', 'PIE0.1', 'MBOX', 'OPML', 'ATOM', 'ATOM0.3', 'HTML', 'JS');
48
if ($type === 'RDF') {
49
    $type = 'RSS1.0';
50
}
51
if ($type === 'RSS') {
52
    $type = 'RSS0.91';
53
}
54
if (empty($type) || !in_array($type, $valid_format)) {
55
    planet_trackback_response(1, planet_constant('MD_INVALID'));
56
    exit();
57
}
58
59
$category_handler = xoops_getModuleHandler('category', $GLOBALS['moddirname']);
60
$blog_handler     = xoops_getModuleHandler('blog', $GLOBALS['moddirname']);
61
$article_handler  = xoops_getModuleHandler('article', $GLOBALS['moddirname']);
62
$bookmark_handler = xoops_getModuleHandler('bookmark', $GLOBALS['moddirname']);
63
64
if (!empty($article_id)) {
65
    $article_obj =& $article_handler->get($article_id);
66
    if (!$article_obj->getVar('art_id')) {
67
        planet_trackback_response(1, planet_constant('MD_EXPIRED'));
68
        exit();
69
    }
70
    $source = 'article';
71
} elseif (!empty($blog_id)) {
72
    $blog_obj =& $blog_handler->get($blog_id);
73
    if (!$blog_obj->getVar('blog_id')) {
74
        planet_trackback_response(1, planet_constant('MD_INVALID'));
75
        exit();
76
    }
77
    $source = 'blog';
78
} elseif (!empty($category_id)) {
79
    $source       = 'category';
80
    $category_obj =& $category_handler->get($category_id);
81
    if (!$category_obj->getVar('cat_id')) {
82
        planet_trackback_response(1, planet_constant('MD_INVALID'));
83
        exit();
84
    }
85
} elseif (!empty($uid)) {
86
    $source = 'bookmark';
87
} else {
88
    $source = '';
89
}
90
91
$xml_charset = 'UTF-8';
92
include_once XOOPS_ROOT_PATH . '/class/template.php';
93
$tpl = new XoopsTpl();
94
$tpl->xoops_setCaching(2);
95
$tpl->xoops_setCacheTime(3600);
96
$xoopsCachedTemplateId = md5($xoopsModule->getVar('mid') . ',' . $article_id . ',' . $category_id . ',' . $blog_id . ','
97
                             . $uid . ',' . $type);
98
if (!$tpl->is_cached('db:system_dummy.tpl', $xoopsCachedTemplateId)) {
99
    $criteria = new CriteriaCompo();
100
    $criteria->setLimit($xoopsModuleConfig['articles_perpage']);
101
    $articles_obj = array();
102
    switch ($source) {
103
        case 'article':
104
            $pagetitle = planet_constant('MD_ARTICLE');
105
            $rssdesc   = planet_constant('MD_XMLDESC_ARTICLE');
106
107
            $articles_obj[$article_id] =& $article_obj;
108
109
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.article.php' . URL_DELIMITER . ''
110
                        . $article_obj->getVar('art_id');
111
            break;
112
113 View Code Duplication
        case 'category':
114
            $pagetitle = planet_constant('MD_CATEGORY');
115
            $rssdesc   = sprintf(planet_constant('MD_XMLDESC_CATEGORY'), $category_obj->getVar('cat_title'));
116
117
            $criteria->add(new Criteria('bc.cat_id', $category_id));
118
            $articles_obj =& $article_handler->getByCategory($criteria);
119
120
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . URL_DELIMITER . 'c'
121
                        . $category_id;
122
            break;
123
124 View Code Duplication
        case 'blog':
125
            $pagetitle = planet_constant('MD_BLOG');
126
            $rssdesc   = sprintf(planet_constant('MD_XMLDESC_BLOG'), $blog_obj->getVar('blog_title'));
127
128
            $criteria->add(new Criteria('blog_id', $blog_id));
129
            $articles_obj =& $article_handler->getAll($criteria);
130
131
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . URL_DELIMITER . 'b'
132
                        . $blog_id;
133
            break;
134
135 View Code Duplication
        case 'bookmark':
136
            $author_name = XoopsUser::getUnameFromId($uid);
137
            $pagetitle   = planet_constant('MD_BOOKMARKS');
138
            $rssdesc     = sprintf(planet_constant('MD_XMLDESC_BOOKMARK'), $author_name);
139
140
            $criteria->add(new Criteria('bm.bm_uid', $uid));
141
            $articles_obj =& $article_handler->getByBookmark($criteria);
142
143
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . URL_DELIMITER . 'u' . $uid;
144
145
            break;
146
147
        default:
148
            $pagetitle = planet_constant('MD_INDEX');
149
            $rssdesc   = planet_constant('MD_XMLDESC_INDEX');
150
151
            $articles_obj =& $article_handler->getAll($criteria);
152
153
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php';
154
            break;
155
    }
156
    $items = array();
157
    foreach (array_keys($articles_obj) as $id) {
158
        $content = $articles_obj[$id]->getVar('art_content');
159
        $content .= '<br>' . planet_constant('MD_SOURCE') . ': ' . $articles_obj[$id]->getVar('art_link') . ' '
160
                    . $articles_obj[$id]->getVar('art_author');
161
        $items[] = array(
162
            'title'                     => $articles_obj[$id]->getVar('art_title'),
163
            'link'                      => XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.article.php'
164
                                           . URL_DELIMITER . '' . $articles_obj[$id]->getVar('art_id'),
165
            'description'               => $content,
166
            'descriptionHtmlSyndicated' => true,
167
            'date'                      => $articles_obj[$id]->getTime('rss'),
168
            'source'                    => XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/',
169
            'author'                    => $articles_obj[$id]->getVar('art_author')
170
        );
171
    }
172
    unset($articles_obj, $criteria);
173
174
    $xml_handler = xoops_getModuleHandler('xml', $GLOBALS['moddirname']);
175
    $xml         = $xml_handler->create($type);
176
    $xml->setVar('encoding', $xml_charset);
177
    $xml->setVar('title', $xoopsConfig['sitename'] . ' :: ' . $pagetitle, 'UTF-8', $xml_charset, true);
178
    $xml->setVar('description', $rssdesc, true);
179
    $xml->setVar('descriptionHtmlSyndicated', true);
180
    $xml->setVar('link', $xml_link);
181
    $xml->setVar('syndicationURL', XOOPS_URL . '/' . xoops_getenv('PHP_SELF'));
182
    $xml->setVar('webmaster', checkEmail($xoopsConfig['adminmail'], true));
183
    $xml->setVar('editor', checkEmail($xoopsConfig['adminmail'], true));
184
    $xml->setVar('category', $xoopsModule->getVar('name'), true);
185
    $xml->setVar('generator', $xoopsModule->getInfo('version'));
186
    $xml->setVar('language', _LANGCODE);
187
188
    $dimention = @getimagesize(XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['moddirname'] . '/'
189
                               . $xoopsModule->getInfo('image'));
190
    $image     = array(
191
        'width'       => $dimention[0],
192
        'height'      => $dimention[1],
193
        'title'       => $xoopsConfig['sitename'] . ' :: ' . $pagetitle,
194
        'url'         => XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/' . $xoopsModule->getInfo('image'),
195
        'link'        => XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/',
196
        'description' => $rssdesc
197
    );
198
    $xml->setImage($image);
199
200
    /*
201
    $item = array(
202
        "title" => $datatitle,
203
        "link" => $dataurl,
204
        "description" => $datadesc,
205
        "descriptionHtmlSyndicated" => true,
206
        "date" => $datadate,
207
        "source" => $datasource,
208
        "author" => $dataauthor
209
        );
210
    */
211
    $xml->addItems($items);
212
213
    $dummy_content = $xml_handler->display($xml, XOOPS_CACHE_PATH . '/' . $GLOBALS['moddirname'] . '.xml.tmp');
214
215
    $tpl->assign_by_ref('dummy_content', $dummy_content);
216
}
217
//$content = ob_get_contents();
218
ob_end_clean();
219
header('Content-Type:text/xml; charset=' . $xml_charset);
220
$tpl->display('db:system_dummy.tpl', $xoopsCachedTemplateId);
221