3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * Creates a dynamic sitemap for a StatusNet site
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2010 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
42 * @author Evan Prodromou <evan@status.net>
43 * @copyright 2010 StatusNet, Inc.
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45 * @link http://status.net/
47 class SitemapPlugin extends Plugin
49 const USERS_PER_MAP = 50000;
50 const NOTICES_PER_MAP = 50000;
53 * Add sitemap-related information at the end of robots.txt
55 * @param Action $action Action being run
57 * @return boolean hook value.
59 function onEndRobotsTxt($action)
61 $url = common_local_url('sitemapindex');
63 print "\nSitemap: $url\n";
71 * @param URLMapper $m path-to-action mapper
73 * @return boolean hook value; true means continue processing, false means stop.
75 public function onRouterInitialized(URLMapper $m)
77 $m->connect('sitemapindex.xml',
78 array('action' => 'sitemapindex'));
80 $m->connect('notice-sitemap-:year-:month-:day-:index.xml',
81 array('action' => 'noticesitemap'),
82 array('year' => '[0-9]{4}',
83 'month' => '[01][0-9]',
84 'day' => '[0123][0-9]',
85 'index' => '[1-9][0-9]*'));
87 $m->connect('user-sitemap-:year-:month-:day-:index.xml',
88 array('action' => 'usersitemap'),
89 array('year' => '[0-9]{4}',
90 'month' => '[01][0-9]',
91 'day' => '[0123][0-9]',
92 'index' => '[1-9][0-9]*'));
94 $m->connect('panel/sitemap',
95 array('action' => 'sitemapadminpanel'));
101 * Meta tags for "claiming" a site
103 * We add extra meta tags that search engines like Yahoo!, Google, and Bing
104 * require to let you claim your site.
106 * @param Action $action Action being executed
108 * @return boolean hook value.
110 function onStartShowHeadElements($action)
112 $actionName = $action->trimmed('action');
114 $singleUser = common_config('singleuser', 'enabled');
116 // Different "top" pages if it's single user or not
118 if (($singleUser && $actionName == 'showstream') ||
119 (!$singleUser && $actionName == 'public')) {
121 $keys = array('googlekey' => 'google-site-verification',
122 'yahookey' => 'y_key',
123 'bingkey' => 'msvalidate.01'); // XXX: is this the same for all sites?
125 foreach ($keys as $config => $metaname) {
126 $content = common_config('sitemap', $config);
128 if (!empty($content)) {
129 $action->element('meta', array('name' => $metaname,
130 'content' => $content));
139 * Database schema setup
141 * We cache some data persistently to avoid overlong queries.
143 * @see Sitemap_user_count
144 * @see Sitemap_notice_count
146 * @return boolean hook value; true means continue processing, false means stop.
148 function onCheckSchema()
150 $schema = Schema::get();
152 $schema->ensureTable('sitemap_user_count', Sitemap_user_count::schemaDef());
153 $schema->ensureTable('sitemap_notice_count', Sitemap_notice_count::schemaDef());
157 function onEndAdminPanelNav($menu) {
158 if (AdminPanelAction::canAdmin('sitemap')) {
159 // TRANS: Menu item title/tooltip
160 $menu_title = _m('Sitemap configuration');
161 // TRANS: Menu item for site administration
162 $menu->out->menuItem(common_local_url('sitemapadminpanel'), _m('MENU','Sitemap'),
163 $menu_title, $action_name == 'sitemapadminpanel', 'nav_sitemap_admin_panel');
169 * Provide plugin version information.
171 * This data is used when showing the version page.
173 * @param array &$versions array of version data arrays; see EVENTS.txt
175 * @return boolean hook value
177 function onPluginVersion(array &$versions)
179 $url = 'http://status.net/wiki/Plugin:Sitemap';
181 $versions[] = array('name' => 'Sitemap',
182 'version' => GNUSOCIAL_VERSION,
183 'author' => 'Evan Prodromou',
186 // TRANS: Plugin description.
187 _m('This plugin allows creation of sitemaps for Bing, Yahoo! and Google.'));