Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sitemapforum.php
1<?php
8namespace Bitrix\Seo;
9
12
30 extends SitemapEntityTable
31{
32 const ENTITY_TYPE = 'FORUM';
33}
34
36{
37 public static function __callStatic($name, $arguments)
38 {
39 $name = ToUpper($name);
40 switch($name)
41 {
42 case "ADDMESSAGE":
43 if ($arguments[1]["APPROVED"] == "Y")
44 {
45 self::actionUpdate($arguments[2], $arguments[2]);
46 }
47 break;
48 case 'ADDTOPIC':
49 if ($arguments[1]["APPROVED"] == "Y")
50 {
51 self::actionAdd(array(), $arguments[1]);
52 }
53 break;
54 case 'UPDATETOPIC':
55 if ($arguments[1]["APPROVED"] == "N")
56 {
57 self::actionDelete($arguments[1]);
58 }
59 else if (empty($arguments[2]) || $arguments[1]["FORUM_ID"] == $arguments[2]["FORUM_ID"])
60 {
61 self::actionUpdate((empty($arguments[2]) ? $arguments[1] : $arguments[2]), $arguments[1]);
62 }
63 else
64 {
65 self::actionDelete($arguments[2]);
66 self::actionAdd(array(), $arguments[1]);
67 }
68 break;
69 case 'DELETETOPIC':
70 if ($arguments[1]["APPROVED"] == "Y")
71 {
72 self::actionDelete($arguments[1]);
73 }
74 break;
75 }
76 }
77
78 protected static function checkParams($arMessage = array(), &$arTopic, &$arForum)
79 {
80 if (\Bitrix\Main\Loader::includeModule('forum'))
81 {
82 $arTopic = (!empty($arTopic) ? $arTopic : \CForumTopic::GetByID($arMessage["TOPIC_ID"]));
83 if (empty($arTopic))
84 return false;
85 $arSitemaps = SitemapForumTable::getSitemapsByEntityId($arTopic["FORUM_ID"] ?? 0);
86 if (!empty($arSitemaps) && ($arForum = \CForumNew::GetByIDEx($arTopic["FORUM_ID"])) && $arForum)
87 {
88 $arForum["PATH2FORUM_MESSAGE"] = \CForumNew::GetSites($arTopic["FORUM_ID"]);
89 $date = MakeTimeStamp($arTopic['LAST_POST_DATE']);
90 $result = array();
91 foreach($arSitemaps as $arSitemap)
92 {
93 $path = $arForum["PATH2FORUM_MESSAGE"][$arSitemap["SITE_ID"]];
94 if (!empty($path))
95 {
96 $arSitemap["fileName"] = str_replace("#FORUM_ID#", $arForum["ID"], $arSitemap['SITEMAP_FILE_FORUM']);
97 $arSitemap["url"] = \CForumNew::PreparePath2Message(
98 $path,
99 array(
100 "FORUM_ID" => $arForum["ID"],
101 "TOPIC_ID" => $arTopic["ID"],
102 "TITLE_SEO" => $arTopic["TITLE_SEO"],
103 "MESSAGE_ID" => "s",
104 "SOCNET_GROUP_ID" => $arTopic["SOCNET_GROUP_ID"],
105 "OWNER_ID" => $arTopic["OWNER_ID"],
106 "PARAM1" => $arTopic["PARAM1"],
107 "PARAM2" => $arTopic["PARAM2"]
108 )
109 );
110 $arSitemap["date"] = $date;
111 $result[] = $arSitemap;
112 }
113 }
114 return (empty($result) ? false : $result);
115 }
116 }
117 return false;
118 }
119
120 protected static function actionUpdate($arOldTopic, $arTopic, $arForum = array())
121 {
122 if (($arSitemaps = self::checkParams(array(), $arTopic, $arForum)) && $arSitemaps)
123 {
124 $arSitemapsOld = self::checkParams(array(), $arOldTopic, $arForum);
125 foreach($arSitemaps as $key => $arSitemap)
126 {
127 $sitemapFile = new SitemapFile($arSitemap["fileName"], $arSitemap);
128 $sitemapFile->removeEntry($arSitemapsOld[$key]['url']);
129
130 $sitemapFile->appendIblockEntry($arSitemap["url"], $arSitemap['date']);
131
132 $sitemapIndex = new SitemapIndex($arSitemap['SITEMAP_FILE'], $arSitemap);
133 $sitemapIndex->appendIndexEntry($sitemapFile);
134 if($arSitemap['ROBOTS'] == 'Y')
135 {
136 $robotsFile = new RobotsFile($arSitemap['SITE_ID']);
137 $robotsFile->addRule(
138 array(RobotsFile::SITEMAP_RULE, $sitemapIndex->getUrl())
139 );
140 }
141 }
142 }
143 }
144
145 protected static function actionDelete($arTopic, $arForum = array())
146 {
147 if (($arSitemaps = self::checkParams(array(), $arTopic, $arForum)) && $arSitemaps)
148 {
149 foreach($arSitemaps as $arSitemap)
150 {
151 $sitemapFile = new SitemapFile($arSitemap["fileName"], $arSitemap);
152 $sitemapFile->removeEntry($arSitemap['url']);
153 $informRobots = false;
154 if (!$sitemapFile->isNotEmpty())
155 {
156 $rule = array(
157 'url' => \CForumNew::PreparePath2Message(
158 $arForum["PATH2FORUM_MESSAGE"][$arSitemap["SITE_ID"]],
159 array(
160 "FORUM_ID" => $arForum["ID"],
161 "TOPIC_ID" => $arForum["TID"],
162 "TITLE_SEO" => $arForum["TITLE_SEO"],
163 "MESSAGE_ID" => "s",
164 "SOCNET_GROUP_ID" => $arForum["SOCNET_GROUP_ID"],
165 "OWNER_ID" => $arForum["OWNER_ID"],
166 "PARAM1" => $arForum["PARAM1"],
167 "PARAM2" => $arForum["PARAM2"]
168 )
169 ),
170 'date' => MakeTimeStamp($arForum['LAST_POST_DATE'])
171 );
172 $sitemapFile->appendIblockEntry($rule['url'], $rule['date']);
173 $informRobots = true;
174 }
175
176 $sitemapIndex = new SitemapIndex($arSitemap['SITEMAP_FILE'], $arSitemap);
177 $sitemapIndex->appendIndexEntry($sitemapFile);
178 if ($informRobots && $arSitemap['ROBOTS'] == 'Y')
179 {
180 $robotsFile = new RobotsFile($arSitemap['SITE_ID']);
181 $robotsFile->addRule(
182 array(RobotsFile::SITEMAP_RULE, $sitemapIndex->getUrl())
183 );
184 }
185 }
186 }
187 }
188
189 protected static function actionAdd($arMessage, $arTopic, $arForum = array())
190 {
191 if (($arSitemaps = self::checkParams($arMessage, $arTopic, $arForum)) && $arSitemaps)
192 {
193 foreach($arSitemaps as $arSitemap)
194 {
195 $sitemapFile = new SitemapFile($arSitemap["fileName"], $arSitemap);
196 $sitemapFile->appendIblockEntry($arSitemap['url'], $arSitemap['date']);
197
198 $sitemapIndex = new SitemapIndex($arSitemap['SITEMAP_FILE'], $arSitemap);
199 $sitemapIndex->appendIndexEntry($sitemapFile);
200
201 if($arSitemap['ROBOTS'] == 'Y')
202 {
203 $robotsFile = new RobotsFile($arSitemap['SITE_ID']);
204 $robotsFile->addRule(
205 array(RobotsFile::SITEMAP_RULE, $sitemapIndex->getUrl())
206 );
207 }
208 }
209 }
210 }
211}
static getSitemapsByEntityId($entityId)
static actionUpdate($arOldTopic, $arTopic, $arForum=array())
static actionDelete($arTopic, $arForum=array())
static __callStatic($name, $arguments)
static actionAdd($arMessage, $arTopic, $arForum=array())
static checkParams($arMessage=array(), &$arTopic, &$arForum)