forked from poesis/xe-sitemaplite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sitemaplite.model.php
64 lines (59 loc) · 1.74 KB
/
sitemaplite.model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* @file sitemaplite.model.php
* @author Kijin Sung <[email protected]>
* @license GPLv2 or Later <https://www.gnu.org/licenses/gpl-2.0.html>
* @brief Sitemap Lite Model
*/
class SitemapLiteModel extends SitemapLite
{
/**
* Update sitemap.xml after editing menu
*/
public function triggerUpdateSitemapXML($trigger_obj)
{
$menu_target_actions = array(
'procMenuAdminInsert' => true,
'procMenuAdminUpdate' => true,
'procMenuAdminDelete' => true,
'procMenuAdminInsertItem' => true,
'procMenuAdminUpdateItem' => true,
'procMenuAdminDeleteItem' => true,
);
$document_target_actions = array(
'/^proc\w+(?:Insert|Update|Delete|Vote)Document$/' => true,
);
// Update sitemap.xml if the menu has changed
if (isset($menu_target_actions[$trigger_obj->act]))
{
getAdminController('sitemaplite')->writeSitemapXml();
return;
}
// Update sitemap.xml if documents have changed and the interval has passed
foreach ($document_target_actions as $regexp => $true)
{
if (preg_match($regexp, $trigger_obj->act))
{
$config = $this->getConfig();
if ($config->document_count && $config->document_source_modules)
{
switch ($config->document_interval)
{
case 'always': $timediff = 0; break;
case 'hourly': $timediff = 3600; break;
case 'daily': $timediff = 86400; break;
case 'weekly': $timediff = 86400 * 7; break;
case 'monthly': $timediff = 86400 * 30; break;
default: $timediff = 86400; break;
}
$xml_path = $this->getSitemapXmlPath($config->sitemap_file_path);
if (filemtime($xml_path) < time() - $timediff)
{
@touch($xml_path);
getAdminController('sitemaplite')->writeSitemapXml($config);
}
}
}
}
}
}