123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- defined('GNUSOCIAL') || die();
- class SitemapPlugin extends Plugin
- {
- const PLUGIN_VERSION = '2.0.0';
- const USERS_PER_MAP = 50000;
- const NOTICES_PER_MAP = 50000;
-
- public function onEndRobotsTxt($action)
- {
- $url = common_local_url('sitemapindex');
- print "\nSitemap: $url\n";
- return true;
- }
-
- public function onRouterInitialized(URLMapper $m)
- {
- $m->connect(
- 'sitemapindex.xml',
- ['action' => 'sitemapindex']
- );
- $m->connect(
- 'notice-sitemap-:year-:month-:day-:index.xml',
- ['action' => 'noticesitemap'],
- [
- 'year' => '[0-9]{4}',
- 'month' => '[01][0-9]',
- 'day' => '[0123][0-9]',
- 'index' => '[1-9][0-9]*',
- ]
- );
- $m->connect(
- 'user-sitemap-:year-:month-:day-:index.xml',
- ['action' => 'usersitemap'],
- [
- 'year' => '[0-9]{4}',
- 'month' => '[01][0-9]',
- 'day' => '[0123][0-9]',
- 'index' => '[1-9][0-9]*',
- ]
- );
- $m->connect(
- 'panel/sitemap',
- ['action' => 'sitemapadminpanel']
- );
- return true;
- }
-
- public function onStartShowHeadElements($action)
- {
- $actionName = $action->trimmed('action');
- $singleUser = common_config('singleuser', 'enabled');
-
- if (($singleUser && $actionName == 'showstream') ||
- (!$singleUser && $actionName == 'public')) {
- $keys = array('yahookey' => 'y_key',
- 'bingkey' => 'msvalidate.01');
- foreach ($keys as $config => $metaname) {
- $content = common_config('sitemap', $config);
- if (!empty($content)) {
- $action->element('meta', array('name' => $metaname,
- 'content' => $content));
- }
- }
- }
- return true;
- }
-
- public function onCheckSchema()
- {
- $schema = Schema::get();
- $schema->ensureTable('sitemap_user_count', Sitemap_user_count::schemaDef());
- $schema->ensureTable('sitemap_notice_count', Sitemap_notice_count::schemaDef());
- return true;
- }
- public function onEndAdminPanelNav($menu)
- {
- if (AdminPanelAction::canAdmin('sitemap')) {
-
- $menu_title = _m('Sitemap configuration');
-
- $menu->out->menuItem(
- common_local_url('sitemapadminpanel'),
- _m('MENU', 'Sitemap'),
- $menu_title,
- ($action_name === 'sitemapadminpanel'),
- 'nav_sitemap_admin_panel'
- );
- }
- return true;
- }
-
- public function onPluginVersion(array &$versions): bool
- {
- $url = GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/Sitemap';
- $versions[] = array('name' => 'Sitemap',
- 'version' => self::PLUGIN_VERSION,
- 'author' => 'Evan Prodromou',
- 'homepage' => $url,
- 'rawdescription' =>
-
- _m('This plugin allows creation of sitemaps for Bing and Yahoo!.'));
- return true;
- }
- }
|