|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/* |
|
3
|
|
|
* **************************************************************************** |
|
4
|
|
|
* Module generated by TDMCreate from TDM "http://www.tdmxoops.net" |
|
5
|
|
|
* **************************************************************************** |
|
6
|
|
|
* xsitemap - MODULE FOR XOOPS CMS |
|
7
|
|
|
* Copyright (c) Urbanspaceman (http://www.takeaweb.it) |
|
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 source code |
|
11
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
15
|
|
|
* **************************************************************************** |
|
16
|
|
|
*/ |
|
17
|
|
|
/** |
|
18
|
|
|
* Module: xsitemap |
|
19
|
|
|
* |
|
20
|
|
|
* @package module\xsitemap\includes |
|
21
|
|
|
* @author XOOPS Module Development Team |
|
22
|
|
|
* @author http://www.takeaweb.it Urbanspaceman |
|
23
|
|
|
* @copyright http://www.takeaweb.it Urbanspaceman |
|
24
|
|
|
* @copyright http://xoops.org 2001-2017 XOOPS Project |
|
25
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
|
26
|
|
|
* @link http://xoops.org XOOPS |
|
27
|
|
|
* @since 1.00 |
|
28
|
|
|
*/ |
|
29
|
|
|
|
|
30
|
|
|
defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
|
31
|
|
|
|
|
32
|
|
|
xoops_loadLanguage('admin', 'xsitemap'); |
|
33
|
|
|
if (!class_exists('XsitemapDummyObject')) { |
|
34
|
|
|
xoops_load('dummy', 'xsitemap'); |
|
35
|
|
|
} |
|
36
|
|
|
/** |
|
37
|
|
|
* |
|
38
|
|
|
* Show Site map |
|
39
|
|
|
* |
|
40
|
|
|
* @return array |
|
41
|
|
|
*/ |
|
42
|
|
|
function xsitemap_generate_sitemap() |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
$block = array(); |
|
45
|
|
|
$moduleDirName = $moduleDirName = basename(dirname(__DIR__)); |
|
46
|
|
|
/** @internal can't use Helper since function called during install |
|
47
|
|
|
$xsitemapHelper = \Xmf\Module\Helper::getHelper($moduleDirName); |
|
48
|
|
|
$pluginHandler = $xsitemapHelper->getHandler('plugin', $moduleDirName); |
|
49
|
|
|
*/ |
|
50
|
|
|
xoops_load('plugin', $moduleDirName); |
|
51
|
|
|
|
|
52
|
|
|
// Get list of modules admin wants to hide from xsitemap |
|
53
|
|
|
$invisibleDirnames = empty($GLOBALS['xoopsModuleConfig']['invisible_dirnames']) ? array('xsitemap') : explode(',', $GLOBALS['xoopsModuleConfig']['invisible_dirnames'] . ',xsitemap'); |
|
54
|
|
|
$invisibleDirnames = array_map('trim', $invisibleDirnames); |
|
55
|
|
|
$invisibleDirnames = array_map('mb_strtolower', $invisibleDirnames); |
|
56
|
|
|
|
|
57
|
|
|
// Get the mid for any of these modules if they're active and hasmain (visible frontside) |
|
58
|
|
|
$moduleHandler = xoops_gethandler('module'); |
|
59
|
|
|
$invisibleMidArray = array(); |
|
60
|
|
|
foreach ($invisibleDirnames as $hiddenDir) { |
|
61
|
|
|
$criteria = new CriteriaCompo(new Criteria('hasmain', 1)); |
|
62
|
|
|
$criteria->add(new Criteria('isactive', 1)); |
|
63
|
|
|
$criteria->add(new Criteria('name', $hiddenDir)); |
|
64
|
|
|
$modObj = $moduleHandler->getByDirname($hiddenDir); |
|
65
|
|
|
if (false !== $modObj && $modObj instanceof XoopsModule) { |
|
|
|
|
|
|
66
|
|
|
$invisibleMidArray[] = $modObj->mid(); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
// Where user has permissions |
|
71
|
|
|
$modulepermHandler = xoops_gethandler('groupperm'); |
|
72
|
|
|
$groups = ($GLOBALS['xoopsUser'] instanceof XoopsUser) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
|
|
|
|
|
73
|
|
|
$readAllowed = $modulepermHandler->getItemIds('module_read', $groups); |
|
74
|
|
|
$filteredMids = array_diff($readAllowed, $invisibleMidArray); |
|
75
|
|
|
$pluginHandler = xoops_getModuleHandler('plugin', $moduleDirName); |
|
76
|
|
|
$criteria = new CriteriaCompo(new Criteria('hasmain', 1)); |
|
77
|
|
|
$criteria->add(new Criteria('isactive', 1)); |
|
78
|
|
|
if (count($filteredMids) > 0) { |
|
79
|
|
|
$criteria->add(new Criteria('mid', '(' . implode(',', $filteredMids) . ')', 'IN')); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$modules = $moduleHandler->getObjects($criteria, true); |
|
83
|
|
|
|
|
84
|
|
|
$criteria = new CriteriaCompo(); |
|
85
|
|
|
$criteria->setSort('plugin_id'); |
|
86
|
|
|
$criteria->order = 'ASC'; |
|
87
|
|
|
$pluginObjArray = $pluginHandler->getAll($criteria); |
|
88
|
|
|
|
|
89
|
|
|
foreach ($modules as $mid => $modObj) { |
|
90
|
|
|
$sublinks = $modObj->subLink(); |
|
91
|
|
|
$modDirName = $modObj->getVar('dirname', 'n'); |
|
92
|
|
|
$block['modules'][$mid] = array('id' => $mid, |
|
93
|
|
|
'name' => $modObj->getVar('name'), |
|
94
|
|
|
'directory' => $modDirName, |
|
95
|
|
|
'sublinks' => array() // init the sublinks array |
|
96
|
|
|
); |
|
97
|
|
|
// Now 'patch' the sublink to include module path |
|
98
|
|
|
if (count($sublinks) > 0) { |
|
99
|
|
|
foreach ($sublinks as $sublink) { |
|
100
|
|
|
$block['modules'][$mid]['sublinks'][] = array('name' => $sublink['name'], |
|
101
|
|
|
'url' => $GLOBALS['xoops']->url("www/modules/{$modDirName}/{$sublink['url']}")); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
foreach ($pluginObjArray as $pObj) { |
|
106
|
|
|
if ((0 == $pObj->getVar('topic_pid')) && in_array($pObj->getVar('plugin_mod_table'), (array) $modObj->getInfo('tables'))) { |
|
107
|
|
|
$objVars = $pObj->getValues(); |
|
108
|
|
|
if (1 == $objVars['plugin_online']) { |
|
109
|
|
|
$tmpMap = xsitemap_get_map($objVars['plugin_mod_table'], $objVars['plugin_cat_id'], $objVars['plugin_cat_pid'], $objVars['plugin_cat_name'], $objVars['plugin_call'], $objVars['plugin_weight']); |
|
110
|
|
|
$block['modules'][$mid]['parent'] = isset($tmpMap['parent']) ? $tmpMap['parent'] : null; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return $block; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Get the Sitemap |
|
121
|
|
|
* |
|
122
|
|
|
* @return array sitemap links |
|
123
|
|
|
*/ |
|
124
|
|
|
function xsitemap_get_map($table, $id_name, $pid_name, $title_name, $url, $order = '') |
|
|
|
|
|
|
125
|
|
|
{ |
|
126
|
|
|
$xDB = XoopsDatabaseFactory::getDatabaseConnection(); |
|
127
|
|
|
$myts = MyTextSanitizer::getInstance(); |
|
128
|
|
|
|
|
129
|
|
|
$sql = "SELECT `{$id_name}`, `{$pid_name}`, `{$title_name}` FROM " . $xDB->prefix . "_{$table}" ; |
|
130
|
|
|
$result = $xDB->query($sql); |
|
131
|
|
|
$objsArray = array(); |
|
132
|
|
|
|
|
133
|
|
|
while ($row = $xDB->fetchArray($result)) { |
|
134
|
|
|
$objsArray[] = new XsitemapDummyObject($row, $id_name, $pid_name, $title_name); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
//$sql = "SELECT `{$id_name}`, `{$title_name}` FROM " . $xDB->prefix . "_{$table} WHERE `{$pid_name}`= 0"; |
|
|
|
|
|
|
138
|
|
|
// v1.54 added in the event categories are flat (don't support hierarchy) |
|
139
|
|
|
$sql = "SELECT `{$id_name}`, `{$title_name}` FROM " . $xDB->prefix . "_{$table}"; |
|
140
|
|
|
if ($pid_name !== $id_name) { |
|
141
|
|
|
$sql .= " WHERE `{$pid_name}`= 0"; |
|
142
|
|
|
} |
|
143
|
|
|
if ('' != $order) { |
|
144
|
|
|
$sql .= " ORDER BY `{$order}`" ; |
|
145
|
|
|
} |
|
146
|
|
|
$result = $xDB->query($sql); |
|
147
|
|
|
|
|
148
|
|
|
$i = 0; |
|
149
|
|
|
$xsitemap = array(); |
|
150
|
|
|
while (list($catid, $name) = $xDB->fetchRow($result)) { |
|
151
|
|
|
$xsitemap['parent'][$i] = array('id' => $catid, |
|
152
|
|
|
'title' => $myts->htmlSpecialChars($name), |
|
153
|
|
|
'url' => $url.$catid |
|
154
|
|
|
); |
|
155
|
|
|
|
|
156
|
|
|
if ($GLOBALS['xoopsModuleConfig']['show_subcategories'] && ($pid_name !== $id_name)) { |
|
157
|
|
|
$j = 0; |
|
158
|
|
|
$mytree = new XoopsObjectTree($objsArray, $id_name, $pid_name); |
|
159
|
|
|
$child_array = $mytree->getAllChild($catid); |
|
160
|
|
|
foreach ($child_array as $child) { |
|
161
|
|
|
$xsitemap['parent'][$i]['child'][$j] = array('id' => $child->getVar($id_name), |
|
162
|
|
|
'title' => $child->getVar($title_name), |
|
163
|
|
|
'url' => $url.$child->getVar($id_name) |
|
164
|
|
|
); |
|
165
|
|
|
++$j; |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
++$i; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
return $xsitemap; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Save the XML Sitemap |
|
176
|
|
|
* |
|
177
|
|
|
* @return mixed int number of bytes saved | false on failure |
|
178
|
|
|
*/ |
|
179
|
|
|
function xsitemap_save(array $xsitemap_show) |
|
|
|
|
|
|
180
|
|
|
{ |
|
181
|
|
|
$xml = new DOMDocument("1.0", "UTF-8"); |
|
182
|
|
|
$xml->preserveWhiteSpace = false; |
|
183
|
|
|
$xml->formatOutput = true; |
|
184
|
|
|
$xml_set = $xml->createElement('urlset'); |
|
185
|
|
|
$xml_set->setAttribute('xmlns', "http://www.sitemaps.org/schemas/sitemap/0.9"); |
|
186
|
|
|
|
|
187
|
|
|
if (!empty($xsitemap_show)) { |
|
188
|
|
|
foreach ($xsitemap_show['modules'] as $mod) { |
|
189
|
|
|
if ($mod["directory"]) { |
|
190
|
|
|
$xml_url = $xml->createElement("url"); |
|
191
|
|
|
$xml_url->appendChild($xml->createComment(htmlentities(ucwords($mod['name'])))); |
|
192
|
|
|
// $xml_url->appendChild($xml->createTextNode("<!-- ". htmlentities(ucwords($mod['name'])) . " -->")); |
|
|
|
|
|
|
193
|
|
|
$loc = $xml->createElement('loc', htmlentities($GLOBALS['xoops']->url("www/modules/{$mod['directory']}/index.php"))); |
|
194
|
|
|
$xml_url->appendChild($loc); |
|
195
|
|
|
} |
|
196
|
|
|
if (isset($mod['parent']) ? $mod['parent'] : null) { |
|
197
|
|
View Code Duplication |
foreach ($mod["parent"] as $parent) { |
|
|
|
|
|
|
198
|
|
|
$xml_parent = $xml->createElement("url"); |
|
199
|
|
|
$loc = $xml->createElement('loc', htmlentities($GLOBALS['xoops']->url("www/modules/{$mod['directory']}/{$parent['url']}"))); |
|
200
|
|
|
$xml_parent->appendChild($loc); |
|
201
|
|
|
$xml_url->appendChild($xml_parent); |
|
|
|
|
|
|
202
|
|
|
} |
|
203
|
|
|
$z = 0; |
|
204
|
|
|
//if ($mod["parent"][$z]["child"]) { |
|
|
|
|
|
|
205
|
|
|
if (isset($mod["parent"][$z]["child"]) ? $mod["parent"][$z]["child"] : null) { |
|
206
|
|
View Code Duplication |
foreach ($mod["parent"][$z]["child"] as $child) { |
|
|
|
|
|
|
207
|
|
|
$xml_child = $xml->createElement("url"); |
|
208
|
|
|
$loc = $xml->createElement('loc', htmlentities($GLOBALS['xoops']->url("www/modules/{$mod['directory']}/{$child['url']}"))); |
|
209
|
|
|
$xml_child->appendChild($loc); |
|
210
|
|
|
$xml_url->appendChild($xml_child); |
|
211
|
|
|
} |
|
212
|
|
|
++$z; |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
$xml_set->appendChild($xml_url); |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
$xml->appendChild($xml_set); |
|
219
|
|
|
return $xml->save($GLOBALS['xoops']->path("www/xsitemap.xml")); |
|
220
|
|
|
} |
|
221
|
|
|
|
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.