Completed
Push — master ( 7c5656...a50592 )
by Michael
01:55
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: https://xoops.org                         //
25
// Project: Article Project                                                 //
26
// ------------------------------------------------------------------------ //
27
use Xmf\Request;
28
29
ob_start();
30
include __DIR__ . '/header.php';
31
32 View Code Duplication
if (PlanetUtility::planetParseArguments($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...
33
    $args['article'] = @$args_num[0];
34
    $args['type']    = @$args_str[0];
35
}
36
37
/* Specified Article */
38
$article_id = Request::getInt('article', @$args['article'], 'GET'); //(int)(empty($_GET['article']) ? @$args['article'] : $_GET['article']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
39
/* Specified Category */
40
$category_id = Request::getInt('category', @$args['category'], 'GET'); //(int)(empty($_GET['category']) ? @$args['category'] : $_GET['category']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
/* Specified Blog */
42
$blog_id = Request::getInt('blog', @$args['blog'], 'GET'); //(int)(empty($_GET['blog']) ? @$args['blog'] : $_GET['blog']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
43
/* Specified Bookmar(Favorite) UID */
44
$uid = Request::getInt('uid', @$args['uid'], 'GET'); //(int)(empty($_GET['uid']) ? @$args['uid'] : $_GET['uid']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
85% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
46
$type = Request::getString('type', Request::getString('op', @$args['type'], 'POST'), 'GET'); // empty($_GET['type']) ? (empty($_GET['op']) ? @$args['type'] : $_GET['op']) : $_GET['type'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
47
$type = strtoupper($type);
48
49
$valid_format = ['RSS0.91', 'RSS1.0', 'RSS2.0', 'PIE0.1', 'MBOX', 'OPML', 'ATOM', 'ATOM0.3', 'HTML', 'JS'];
50
if ($type === 'RDF') {
51
    $type = 'RSS1.0';
52
}
53
if ($type === 'RSS') {
54
    $type = 'RSS0.91';
55
}
56
if (empty($type) || !in_array($type, $valid_format)) {
57
    PlanetUtility::planetRespondToTrackback(1, planet_constant('MD_INVALID'));
58
    exit();
59
}
60
61
$categoryHandler = xoops_getModuleHandler('category', $GLOBALS['moddirname']);
62
$blogHandler     = xoops_getModuleHandler('blog', $GLOBALS['moddirname']);
63
$articleHandler  = xoops_getModuleHandler('article', $GLOBALS['moddirname']);
64
$bookmarkHandler = xoops_getModuleHandler('bookmark', $GLOBALS['moddirname']);
65
66
if (!empty($article_id)) {
67
    $article_obj = $articleHandler->get($article_id);
68
    if (!$article_obj->getVar('art_id')) {
69
        PlanetUtility::planetRespondToTrackback(1, planet_constant('MD_EXPIRED'));
70
        exit();
71
    }
72
    $source = 'article';
73
} elseif (!empty($blog_id)) {
74
    $blog_obj = $blogHandler->get($blog_id);
75
    if (!$blog_obj->getVar('blog_id')) {
76
        PlanetUtility::planetRespondToTrackback(1, planet_constant('MD_INVALID'));
77
        exit();
78
    }
79
    $source = 'blog';
80
} elseif (!empty($category_id)) {
81
    $source       = 'category';
82
    $category_obj = $categoryHandler->get($category_id);
83
    if (!$category_obj->getVar('cat_id')) {
84
        PlanetUtility::planetRespondToTrackback(1, planet_constant('MD_INVALID'));
85
        exit();
86
    }
87
} elseif (!empty($uid)) {
88
    $source = 'bookmark';
89
} else {
90
    $source = '';
91
}
92
93
$xml_charset = 'UTF-8';
94
require_once XOOPS_ROOT_PATH . '/class/template.php';
95
$tpl = new XoopsTpl();
96
$tpl->xoops_setCaching(2);
97
$tpl->xoops_setCacheTime(3600);
98
$xoopsCachedTemplateId = md5($xoopsModule->getVar('mid') . ',' . $article_id . ',' . $category_id . ',' . $blog_id . ',' . $uid . ',' . $type);
99
if (!$tpl->is_cached('db:system_dummy.tpl', $xoopsCachedTemplateId)) {
100
    $criteria = new CriteriaCompo();
101
    $criteria->setLimit($xoopsModuleConfig['articles_perpage']);
102
    $articles_obj = [];
103
    switch ($source) {
104
        case 'article':
105
            $pagetitle = planet_constant('MD_ARTICLE');
106
            $rssdesc   = planet_constant('MD_XMLDESC_ARTICLE');
107
108
            $articles_obj[$article_id] = $article_obj;
109
110
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.article.php' . URL_DELIMITER . '' . $article_obj->getVar('art_id');
111
            break;
112
113 View Code Duplication
        case 'category':
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...
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 = $articleHandler->getByCategory($criteria);
119
120
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . URL_DELIMITER . 'c' . $category_id;
121
            break;
122
123 View Code Duplication
        case 'blog':
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...
124
            $pagetitle = planet_constant('MD_BLOG');
125
            $rssdesc   = sprintf(planet_constant('MD_XMLDESC_BLOG'), $blog_obj->getVar('blog_title'));
126
127
            $criteria->add(new Criteria('blog_id', $blog_id));
128
            $articles_obj = $articleHandler->getAll($criteria);
129
130
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . URL_DELIMITER . 'b' . $blog_id;
131
            break;
132
133 View Code Duplication
        case 'bookmark':
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...
134
            $author_name = XoopsUser::getUnameFromId($uid);
135
            $pagetitle   = planet_constant('MD_BOOKMARKS');
136
            $rssdesc     = sprintf(planet_constant('MD_XMLDESC_BOOKMARK'), $author_name);
137
138
            $criteria->add(new Criteria('bm.bm_uid', $uid));
139
            $articles_obj = $articleHandler->getByBookmark($criteria);
140
141
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . URL_DELIMITER . 'u' . $uid;
142
143
            break;
144
145
        default:
146
            $pagetitle = planet_constant('MD_INDEX');
147
            $rssdesc   = planet_constant('MD_XMLDESC_INDEX');
148
149
            $articles_obj = $articleHandler->getAll($criteria);
150
151
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php';
152
            break;
153
    }
154
    $items = [];
155
    foreach (array_keys($articles_obj) as $id) {
156
        $content = $articles_obj[$id]->getVar('art_content');
157
        $content .= '<br>' . planet_constant('MD_SOURCE') . ': ' . $articles_obj[$id]->getVar('art_link') . ' ' . $articles_obj[$id]->getVar('art_author');
158
        $items[] = [
159
            'title'                     => $articles_obj[$id]->getVar('art_title'),
160
            'link'                      => XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.article.php' . URL_DELIMITER . '' . $articles_obj[$id]->getVar('art_id'),
161
            'description'               => $content,
162
            'descriptionHtmlSyndicated' => true,
163
            'date'                      => $articles_obj[$id]->getTime('rss'),
164
            'source'                    => XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/',
165
            'author'                    => $articles_obj[$id]->getVar('art_author')
166
        ];
167
    }
168
    unset($articles_obj, $criteria);
169
170
    $xmlHandler = xoops_getModuleHandler('xml', $GLOBALS['moddirname']);
171
    $xml        = $xmlHandler->create($type);
172
    $xml->setVar('encoding', $xml_charset);
173
    $xml->setVar('title', $xoopsConfig['sitename'] . ' :: ' . $pagetitle, 'UTF-8', $xml_charset, true);
174
    $xml->setVar('description', $rssdesc, true);
175
    $xml->setVar('descriptionHtmlSyndicated', true);
176
    $xml->setVar('link', $xml_link);
177
    $xml->setVar('syndicationURL', XOOPS_URL . '/' . xoops_getenv('PHP_SELF'), 'post', true);
178
    $xml->setVar('webmaster', checkEmail($xoopsConfig['adminmail'], true));
179
    $xml->setVar('editor', checkEmail($xoopsConfig['adminmail'], true));
180
    $xml->setVar('category', $xoopsModule->getVar('name'), true);
181
    $xml->setVar('generator', $xoopsModule->getInfo('version'));
182
    $xml->setVar('language', _LANGCODE);
183
184
    $dimention = @getimagesize(XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['moddirname'] . '/' . $xoopsModule->getInfo('image'));
185
    $image     = [
186
        'width'       => $dimention[0],
187
        'height'      => $dimention[1],
188
        'title'       => $xoopsConfig['sitename'] . ' :: ' . $pagetitle,
189
        'url'         => XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/' . $xoopsModule->getInfo('image'),
190
        'link'        => XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/',
191
        'description' => $rssdesc
192
    ];
193
    $xml->setImage($image);
194
195
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
196
    $item = array(
197
        "title" => $datatitle,
198
        "link" => $dataurl,
199
        "description" => $datadesc,
200
        "descriptionHtmlSyndicated" => true,
201
        "date" => $datadate,
202
        "source" => $datasource,
203
        "author" => $dataauthor
204
        );
205
    */
206
    $xml->addItems($items);
207
208
    $dummy_content = $xmlHandler->display($xml, XOOPS_CACHE_PATH . '/' . $GLOBALS['moddirname'] . '.xml.tmp');
209
210
    $tpl->assign_by_ref('dummy_content', $dummy_content);
211
}
212
//$content = ob_get_contents();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
213
ob_end_clean();
214
header('Content-Type:text/xml; charset=' . $xml_charset);
215
$tpl->display('db:system_dummy.tpl', $xoopsCachedTemplateId);
216