|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Rssfit\Plugins; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* You may not change or alter any portion of this comment or credits |
|
7
|
|
|
* of supporting developers from this source code or any supporting source code |
|
8
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
17
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
18
|
|
|
* @package RSSFit - Extendable XML news feed generator |
|
19
|
|
|
* @author NS Tai (aka tuff) <http://www.brandycoke.com> |
|
20
|
|
|
* @author XOOPS Development Team |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
/* |
|
24
|
|
|
* This file is a dummy for making a RSSFit plug-in, follow the following steps |
|
25
|
|
|
* if you really want to do so. |
|
26
|
|
|
* Step 0: Stop here if you are not sure what you are doing, it's no fun at all |
|
27
|
|
|
* Step 1: Clone this file and rename as something like rssfit.[mod_dir].php |
|
28
|
|
|
* Step 2: Replace the text "RssfitSample" with "Rssfit[mod_dir]" at line 59 and |
|
29
|
|
|
* line 65, i.e. "RssfitNews" for the module "News" |
|
30
|
|
|
* Step 3: Modify the word in line 60 from 'sample' to [mod_dir] |
|
31
|
|
|
* Step 4: Modify the function "grabEntries" to satisfy your needs |
|
32
|
|
|
* Step 5: Move your new plug-in file to the RSSFit plugins folder, |
|
33
|
|
|
* i.e. your-xoops-root/modules/rssfit/plugins |
|
34
|
|
|
* Step 6: Install your plug-in by pointing your browser to |
|
35
|
|
|
* your-xoops-url/modules/rssfit/admin/?do=plugins |
|
36
|
|
|
* Step 7: Finally, tell us about yourself and this file by modifying the |
|
37
|
|
|
* "About this RSSFit plug-in" section which is located... somewhere. |
|
38
|
|
|
* |
|
39
|
|
|
* [mod_dir]: Name of the driectory of your module, i.e. 'news' |
|
40
|
|
|
* |
|
41
|
|
|
* About this RSSFit plug-in |
|
42
|
|
|
* Author: John Doe <http://www.your.site> |
|
43
|
|
|
* Requirements (or Tested with): |
|
44
|
|
|
* Module: Blah <http://www.where.to.find.it> |
|
45
|
|
|
* Version: 1.0 |
|
46
|
|
|
* RSSFit verision: 1.2 / 1.5 |
|
47
|
|
|
* XOOPS version: 2.0.13.2 / 2.2.3 |
|
48
|
|
|
*/ |
|
49
|
|
|
|
|
50
|
|
|
if (!\defined('RSSFIT_ROOT_PATH')) { |
|
51
|
|
|
exit(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Class Sample |
|
56
|
|
|
* @package XoopsModules\Rssfit\Plugins |
|
57
|
|
|
*/ |
|
58
|
|
|
class Wgdiaries |
|
59
|
|
|
{ |
|
60
|
|
|
public $dirname = 'wgdiaries'; |
|
61
|
|
|
public $modname; |
|
62
|
|
|
public $grab; |
|
63
|
|
|
public $module; // optional, see line 71 |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return false|string |
|
67
|
|
|
*/ |
|
68
|
|
|
public function loadModule() |
|
69
|
|
|
{ |
|
70
|
|
|
$mod = $GLOBALS['module_handler']->getByDirname($this->dirname); |
|
71
|
|
|
if (!$mod || !$mod->getVar('isactive')) { |
|
72
|
|
|
return false; |
|
73
|
|
|
} |
|
74
|
|
|
$this->modname = $mod->getVar('name'); |
|
75
|
|
|
$this->module = $mod; // optional, remove this line if there is nothing |
|
76
|
|
|
// to do with module info when grabbing entries |
|
77
|
|
|
return $mod; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @param \XoopsObject $obj |
|
82
|
|
|
* @return bool|array |
|
83
|
|
|
*/ |
|
84
|
|
|
public function grabEntries(&$obj) |
|
|
|
|
|
|
85
|
|
|
{ |
|
86
|
|
|
global $xoopsDB; |
|
87
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
|
|
|
|
|
88
|
|
|
$ret = false; |
|
89
|
|
|
$i = 0; |
|
90
|
|
|
// The following example code grabs the latest entries from the module |
|
91
|
|
|
$sql = 'SELECT i.item_id, i.item_datecreated, i.item_name, i.item_remarks, c.cat_name '; |
|
92
|
|
|
$sql .= 'FROM ' . $xoopsDB->prefix('wgdiaries_items') . ' i INNER JOIN ' . $xoopsDB->prefix('wgdiaries_categories') . ' c ON i.item_catid = c.cat_id '; |
|
93
|
|
|
$sql .= 'ORDER BY i.item_datecreated DESC, i.item_id DESC'; |
|
94
|
|
|
|
|
95
|
|
|
$result = $xoopsDB->query($sql, $this->grab, 0); |
|
96
|
|
|
if ($result instanceof \mysqli_result) { |
|
97
|
|
|
$ret = []; |
|
98
|
|
|
while (false !== ($row = $xoopsDB->fetchArray($result))) { |
|
99
|
|
|
$link = XOOPS_URL . '/modules/' . $this->dirname . '/items.php?op=show&item_id=' . $row['item_id']; |
|
100
|
|
|
/* |
|
101
|
|
|
* Required elements of an RSS item |
|
102
|
|
|
*/ |
|
103
|
|
|
// 1. Title of an item |
|
104
|
|
|
$ret[$i]['title'] = $row['item_name']; |
|
105
|
|
|
// 2. URL of an item |
|
106
|
|
|
$ret[$i]['link'] = $link; |
|
107
|
|
|
// 3. Item modification date, must be in Unix time format |
|
108
|
|
|
$ret[$i]['timestamp'] = $row['item_datecreated']; |
|
109
|
|
|
// 4. The item synopsis, or description, whatever |
|
110
|
|
|
$ret[$i]['description'] = $row['item_remarks']; |
|
111
|
|
|
/* |
|
112
|
|
|
* Optional elements of an RSS item |
|
113
|
|
|
*/ |
|
114
|
|
|
// 5. The item synopsis, or description, whatever |
|
115
|
|
|
$ret[$i]['guid'] = $link; |
|
116
|
|
|
// 6. A string + domain that identifies a categorization taxonomy |
|
117
|
|
|
$ret[$i]['category'] = $this->modname; |
|
118
|
|
|
$ret[$i]['domain'] = XOOPS_URL . '/modules/' . $this->dirname . '/'; |
|
119
|
|
|
// 7. extra tags examples |
|
120
|
|
|
$ret[$i]['extras'] = []; |
|
121
|
|
|
// 7a. without attribute |
|
122
|
|
|
$ret[$i]['extras']['state'] = ['content' => $row['cat_name']]; |
|
123
|
|
|
// 7b. with attributes |
|
124
|
|
|
//$ret[$i]['extras']['enclosure']['attributes'] = ['url' => 'url-to-any-file', 'length' => 1024000, 'type' => 'audio/mpeg']; |
|
125
|
|
|
$i++; |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
return $ret; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.