Completed
Push — master ( a0a78b...8db6f6 )
by Michael
19s
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
use XoopsModules\Planet;
29
/** @var Planet\Helper $helper */
30
$helper = Planet\Helper::getInstance();
31
32
ob_start();
33
include __DIR__ . '/header.php';
34
35 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...
36
    $args['article'] = @$args_num[0];
37
    $args['type']    = @$args_str[0];
38
}
39
40
/* Specified Article */
41
$article_id = Request::getInt('article', @$args['article'], 'GET'); //(int)(empty($_GET['article']) ? @$args['article'] : $_GET['article']);
42
/* Specified Category */
43
$category_id = Request::getInt('category', @$args['category'], 'GET'); //(int)(empty($_GET['category']) ? @$args['category'] : $_GET['category']);
44
/* Specified Blog */
45
$blog_id = Request::getInt('blog', @$args['blog'], 'GET'); //(int)(empty($_GET['blog']) ? @$args['blog'] : $_GET['blog']);
46
/* Specified Bookmar(Favorite) UID */
47
$uid = Request::getInt('uid', @$args['uid'], 'GET'); //(int)(empty($_GET['uid']) ? @$args['uid'] : $_GET['uid']);
48
49
$type = Request::getString('type', Request::getString('op', @$args['type'], 'POST'), 'GET'); // empty($_GET['type']) ? (empty($_GET['op']) ? @$args['type'] : $_GET['op']) : $_GET['type'];
50
$type = strtoupper($type);
51
52
$valid_format = ['RSS0.91', 'RSS1.0', 'RSS2.0', 'PIE0.1', 'MBOX', 'OPML', 'ATOM', 'ATOM0.3', 'HTML', 'JS'];
53
if ('RDF' === $type) {
54
    $type = 'RSS1.0';
55
}
56
if ('RSS' === $type) {
57
    $type = 'RSS0.91';
58
}
59
if (empty($type) || !in_array($type, $valid_format)) {
60
    PlanetUtility::planetRespondToTrackback(1, planet_constant('MD_INVALID'));
61
    exit();
62
}
63
64
$categoryHandler = xoops_getModuleHandler('category', $GLOBALS['moddirname']);
65
$blogHandler     = xoops_getModuleHandler('blog', $GLOBALS['moddirname']);
66
$articleHandler  = xoops_getModuleHandler('article', $GLOBALS['moddirname']);
67
$bookmarkHandler = xoops_getModuleHandler('bookmark', $GLOBALS['moddirname']);
68
69
if (!empty($article_id)) {
70
    $article_obj = $articleHandler->get($article_id);
71
    if (!$article_obj->getVar('art_id')) {
72
        PlanetUtility::planetRespondToTrackback(1, planet_constant('MD_EXPIRED'));
73
        exit();
74
    }
75
    $source = 'article';
76
} elseif (!empty($blog_id)) {
77
    $blog_obj = $blogHandler->get($blog_id);
78
    if (!$blog_obj->getVar('blog_id')) {
79
        PlanetUtility::planetRespondToTrackback(1, planet_constant('MD_INVALID'));
80
        exit();
81
    }
82
    $source = 'blog';
83
} elseif (!empty($category_id)) {
84
    $source       = 'category';
85
    $category_obj = $categoryHandler->get($category_id);
86
    if (!$category_obj->getVar('cat_id')) {
87
        PlanetUtility::planetRespondToTrackback(1, planet_constant('MD_INVALID'));
88
        exit();
89
    }
90
} elseif (!empty($uid)) {
91
    $source = 'bookmark';
92
} else {
93
    $source = '';
94
}
95
96
$xml_charset = 'UTF-8';
97
require_once XOOPS_ROOT_PATH . '/class/template.php';
98
$tpl = new \XoopsTpl();
99
$tpl->caching=(2);
100
$tpl->xoops_setCacheTime(3600);
101
$xoopsCachedTemplateId = md5($xoopsModule->getVar('mid') . ',' . $article_id . ',' . $category_id . ',' . $blog_id . ',' . $uid . ',' . $type);
102
if (!$tpl->is_cached('db:system_dummy.tpl', $xoopsCachedTemplateId)) {
103
    $criteria = new \CriteriaCompo();
104
    $criteria->setLimit($helper->getConfig('articles_perpage'));
105
    $articles_obj = [];
106
    switch ($source) {
107
        case 'article':
108
            $pagetitle = planet_constant('MD_ARTICLE');
109
            $rssdesc   = planet_constant('MD_XMLDESC_ARTICLE');
110
111
            $articles_obj[$article_id] = $article_obj;
112
113
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.article.php' . URL_DELIMITER . '' . $article_obj->getVar('art_id');
114
            break;
115
116 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...
117
            $pagetitle = planet_constant('MD_CATEGORY');
118
            $rssdesc   = sprintf(planet_constant('MD_XMLDESC_CATEGORY'), $category_obj->getVar('cat_title'));
119
120
            $criteria->add(new \Criteria('bc.cat_id', $category_id));
121
            $articles_obj = $articleHandler->getByCategory($criteria);
122
123
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . URL_DELIMITER . 'c' . $category_id;
124
            break;
125
126 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...
127
            $pagetitle = planet_constant('MD_BLOG');
128
            $rssdesc   = sprintf(planet_constant('MD_XMLDESC_BLOG'), $blog_obj->getVar('blog_title'));
129
130
            $criteria->add(new \Criteria('blog_id', $blog_id));
131
            $articles_obj = $articleHandler->getAll($criteria);
132
133
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . URL_DELIMITER . 'b' . $blog_id;
134
            break;
135
136 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...
137
            $author_name = XoopsUser::getUnameFromId($uid);
138
            $pagetitle   = planet_constant('MD_BOOKMARKS');
139
            $rssdesc     = sprintf(planet_constant('MD_XMLDESC_BOOKMARK'), $author_name);
140
141
            $criteria->add(new \Criteria('bm.bm_uid', $uid));
142
            $articles_obj = $articleHandler->getByBookmark($criteria);
143
144
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . URL_DELIMITER . 'u' . $uid;
145
146
            break;
147
148
        default:
149
            $pagetitle = planet_constant('MD_INDEX');
150
            $rssdesc   = planet_constant('MD_XMLDESC_INDEX');
151
152
            $articles_obj = $articleHandler->getAll($criteria);
153
154
            $xml_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php';
155
            break;
156
    }
157
    $items = [];
158
    foreach (array_keys($articles_obj) as $id) {
159
        $content = $articles_obj[$id]->getVar('art_content');
160
        $content .= '<br>' . planet_constant('MD_SOURCE') . ': ' . $articles_obj[$id]->getVar('art_link') . ' ' . $articles_obj[$id]->getVar('art_author');
161
        $items[] = [
162
            'title'                     => $articles_obj[$id]->getVar('art_title'),
163
            'link'                      => XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.article.php' . URL_DELIMITER . '' . $articles_obj[$id]->getVar('art_id'),
164
            'description'               => $content,
165
            'descriptionHtmlSyndicated' => true,
166
            'date'                      => $articles_obj[$id]->getTime('rss'),
167
            'source'                    => XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/',
168
            'author'                    => $articles_obj[$id]->getVar('art_author')
169
        ];
170
    }
171
    unset($articles_obj, $criteria);
172
173
    $xmlHandler = xoops_getModuleHandler('xml', $GLOBALS['moddirname']);
174
    $xml        = $xmlHandler->create($type);
175
    $xml->setVar('encoding', $xml_charset);
176
    $xml->setVar('title', $xoopsConfig['sitename'] . ' :: ' . $pagetitle, 'UTF-8', $xml_charset, true);
177
    $xml->setVar('description', $rssdesc, true);
178
    $xml->setVar('descriptionHtmlSyndicated', true);
179
    $xml->setVar('link', $xml_link);
180
    $xml->setVar('syndicationURL', XOOPS_URL . '/' . xoops_getenv('PHP_SELF'), 'post', true);
181
    $xml->setVar('webmaster', checkEmail($xoopsConfig['adminmail'], true));
182
    $xml->setVar('editor', checkEmail($xoopsConfig['adminmail'], true));
183
    $xml->setVar('category', $xoopsModule->getVar('name'), true);
184
    $xml->setVar('generator', $xoopsModule->getInfo('version'));
185
    $xml->setVar('language', _LANGCODE);
186
187
    $dimention = @getimagesize(XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['moddirname'] . '/' . $xoopsModule->getInfo('image'));
188
    $image     = [
189
        'width'       => $dimention[0],
190
        'height'      => $dimention[1],
191
        'title'       => $xoopsConfig['sitename'] . ' :: ' . $pagetitle,
192
        'url'         => XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/' . $xoopsModule->getInfo('image'),
193
        'link'        => XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/',
194
        'description' => $rssdesc
195
    ];
196
    $xml->setImage($image);
197
198
    /*
199
    $item = array(
200
        "title" => $datatitle,
201
        "link" => $dataurl,
202
        "description" => $datadesc,
203
        "descriptionHtmlSyndicated" => true,
204
        "date" => $datadate,
205
        "source" => $datasource,
206
        "author" => $dataauthor
207
        );
208
    */
209
    $xml->addItems($items);
210
211
    $dummy_content = $xmlHandler->display($xml, XOOPS_CACHE_PATH . '/' . $GLOBALS['moddirname'] . '.xml.tmp');
212
213
    $tpl->assign_by_ref('dummy_content', $dummy_content);
214
}
215
//$content = ob_get_contents();
216
ob_end_clean();
217
header('Content-Type:text/xml; charset=' . $xml_charset);
218
$tpl->display('db:system_dummy.tpl', $xoopsCachedTemplateId);
219