]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Sitemap/SitemapPlugin.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / Sitemap / SitemapPlugin.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * Creates a dynamic sitemap for a StatusNet site
7  *
8  * PHP version 5
9  *
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.
14  *
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.
19  *
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/>.
22  *
23  * @category  Sample
24  * @package   StatusNet
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/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Sitemap plugin
39  *
40  * @category  Sample
41  * @package   StatusNet
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/
46  */
47 class SitemapPlugin extends Plugin
48 {
49     const USERS_PER_MAP   = 50000;
50     const NOTICES_PER_MAP = 50000;
51
52     /**
53      * Add sitemap-related information at the end of robots.txt
54      *
55      * @param Action $action Action being run
56      *
57      * @return boolean hook value.
58      */
59     function onEndRobotsTxt($action)
60     {
61         $url = common_local_url('sitemapindex');
62
63         print "\nSitemap: $url\n";
64
65         return true;
66     }
67
68     /**
69      * Map URLs to actions
70      *
71      * @param URLMapper $m path-to-action mapper
72      *
73      * @return boolean hook value; true means continue processing, false means stop.
74      */
75     public function onRouterInitialized(URLMapper $m)
76     {
77         $m->connect('sitemapindex.xml',
78                     array('action' => 'sitemapindex'));
79
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]*'));
86
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]*'));
93
94         $m->connect('panel/sitemap',
95                     array('action' => 'sitemapadminpanel'));
96
97         return true;
98     }
99
100     /**
101      * Meta tags for "claiming" a site
102      *
103      * We add extra meta tags that search engines like Yahoo!, Google, and Bing
104      * require to let you claim your site.
105      *
106      * @param Action $action Action being executed
107      *
108      * @return boolean hook value.
109      */
110     function onStartShowHeadElements($action)
111     {
112         $actionName = $action->trimmed('action');
113
114         $singleUser = common_config('singleuser', 'enabled');
115
116         // Different "top" pages if it's single user or not
117
118         if (($singleUser && $actionName == 'showstream') ||
119             (!$singleUser && $actionName == 'public')) {
120
121             $keys = array('googlekey' => 'google-site-verification',
122                           'yahookey' => 'y_key',
123                           'bingkey' => 'msvalidate.01'); // XXX: is this the same for all sites?
124
125             foreach ($keys as $config => $metaname) {
126                 $content = common_config('sitemap', $config);
127
128                 if (!empty($content)) {
129                     $action->element('meta', array('name' => $metaname,
130                                                    'content' => $content));
131                 }
132             }
133         }
134
135         return true;
136     }
137
138     /**
139      * Database schema setup
140      *
141      * We cache some data persistently to avoid overlong queries.
142      *
143      * @see Sitemap_user_count
144      * @see Sitemap_notice_count
145      *
146      * @return boolean hook value; true means continue processing, false means stop.
147      */
148     function onCheckSchema()
149     {
150         $schema = Schema::get();
151
152         $schema->ensureTable('sitemap_user_count', Sitemap_user_count::schemaDef());
153         $schema->ensureTable('sitemap_notice_count', Sitemap_notice_count::schemaDef());
154         return true;
155     }
156
157     function onEndAdminPanelNav(Menu $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');
164         }
165         return true;
166     }
167
168     /**
169      * Provide plugin version information.
170      *
171      * This data is used when showing the version page.
172      *
173      * @param array &$versions array of version data arrays; see EVENTS.txt
174      *
175      * @return boolean hook value
176      */
177     function onPluginVersion(array &$versions)
178     {
179         $url = 'http://status.net/wiki/Plugin:Sitemap';
180
181         $versions[] = array('name' => 'Sitemap',
182             'version' => GNUSOCIAL_VERSION,
183             'author' => 'Evan Prodromou',
184             'homepage' => $url,
185             'rawdescription' =>
186             // TRANS: Plugin description.
187             _m('This plugin allows creation of sitemaps for Bing, Yahoo! and Google.'));
188
189         return true;
190     }
191 }