![]() |
|
prestaSitemapPlugin - 1.0.4Generate XML sitemaps |
|
![]() |
22
users
Sign-in
to change your status |
The prestaSitemapPlugin provides an easy way to generate a sitemap.xml. Features:
|
Plugin that allow to easily generate XML sitemap.
Orginally developed by Prestaconcept for it's projects.
Warning: The svn repository has changed. It is now hosted on http://svn.prestaconcept.net/symfony/prestaSitemapPlugin/.
| Name | Status | |
|---|---|---|
|
|
lead | ten.tpecnocatserp <<ta>> tevilodc |
|
|
lead | ten.tpecnocatserp <<ta>> ydnarm |
Copyright (c) 2009 PrestaConcept
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
| Version | License | API | Released |
|---|---|---|---|
| 1.0.4stable | MIT license | 1.0.4stable | 10/08/2011 |
| 1.0.3stable | MIT license | 1.0.3stable | 07/10/2010 |
| 1.0.2stable | MIT license | 1.0.1stable | 29/01/2010 |
| 1.0.1stable | MIT license | 1.0.1stable | 30/11/2009 |
| 1.0.0stable | MIT license | 1.0.0stable | 21/08/2009 |
| 0.0.4beta | MIT license | 0.0.1beta | 07/08/2009 |
| 0.0.3beta | MIT license | 0.0.1beta | 06/08/2009 |
| 0.0.2beta | MIT license | 0.0.1beta | 04/08/2009 |
| Version | License | API | Released |
|---|---|---|---|
| 1.0.4stable | MIT license | 1.0.4stable | 10/08/2011 |
| 1.0.3stable | MIT license | 1.0.3stable | 07/10/2010 |
| 1.0.2stable | MIT license | 1.0.1stable | 29/01/2010 |
| 1.0.1stable | MIT license | 1.0.1stable | 30/11/2009 |
| 1.0.0stable | MIT license | 1.0.0stable | 21/08/2009 |
| 0.0.4beta | MIT license | 0.0.1beta | 07/08/2009 |
| 0.0.3beta | MIT license | 0.0.1beta | 06/08/2009 |
| 0.0.2beta | MIT license | 0.0.1beta | 04/08/2009 |
| Version | License | API | Released |
|---|---|---|---|
| 1.0.4stable | MIT license | 1.0.4stable | 10/08/2011 |
| 1.0.3stable | MIT license | 1.0.3stable | 07/10/2010 |
| 1.0.2stable | MIT license | 1.0.1stable | 29/01/2010 |
| 1.0.1stable | MIT license | 1.0.1stable | 30/11/2009 |
| 1.0.0stable | MIT license | 1.0.0stable | 21/08/2009 |
| 0.0.4beta | MIT license | 0.0.1beta | 07/08/2009 |
| 0.0.3beta | MIT license | 0.0.1beta | 06/08/2009 |
| 0.0.2beta | MIT license | 0.0.1beta | 04/08/2009 |
Add support for google's mobile extension for sitemaps
Add support for google's mobile extension for sitemaps
Remove code used for compatibility with sf1.1 (sfLoader) that is not used (as this plugin doesn't officially support symfony 1.1) that were producing notices with project:validate
The prestaSitemapPlugin provides an easy way to generate a sitemap.xml.
The prestaSitemapPlugin is licensed under the MIT License.
Install the plugin:
$ symfony plugin:install prestaSitemapPlugin $ symfony cc
Be sure that the plugin is activated in config/ProjectConfiguration.class.php
In order to register methods and or functions that should add URLs to the sitemap, we should add listeners for the event 'presta_sitemap.generate_urls'.
In apps/%appName%/config/%appName%Configuration.class.php, we declare one or more listeners in configure() method:
// 'sitemapUtils' and 'generateSitemapEntries' are just exemple of a valid callback. You can name them as you want. $this->dispatcher->connect( 'presta_sitemap.generate_urls', array( 'sitemapUtils', 'generateSitemapEntries' ) );
We add the listener method in a new class (eg: apps/%appName%/lib/sitemapUtils.class.php ):
class sitemapUtils { /** * Listens to the presta_sitemap.generate_urls event. * * @param sfEvent $event An sfEvent instance */ public static function generateSitemapEntries( sfEvent $event ) { // create a new prestaSitemapSection object $o_sitemapSection = new prestaSitemapSection( 'miscSectionName' ); // check is it is up-to-date if( !$o_sitemapSection->isUpToDate() ) { // add prestaSitemapUrl to the prestaSitemapSection $o_sitemapSection->addUrl( new prestaSitemapUrl( '@homepage', new DateTime(), prestaSitemapUrl::CHANGE_FREQUENCY_HOURLY, 0.9 ) ); // add other urls $o_sitemapSection->addUrl( new prestaSitemapUrl( /* Put your own stuff here */ ) ); } } }
Enabled prestaSitemap module in your settings.yml:
all:
.settings:
enabled_modules: [default, prestaSitemap]
You can now see your sitemap index file in http://www.mydomain.com/sitemap.xml. That's all, you now have a sitemap.
prestaSitemapPlugin use mbstring php's extension because it should produce UTF-8 xml files no matter the input encoding. This extension is not required but highly recommanded.
If "mbstring" extension is not installed, you are responsible to give UTF-8 encoded absolute urls to prestaSitemapUrl objects.
// Both lines are valid if "mbstring" extension is installed, but invalid if "mb_string" is not installed new prestaSitemapUrl( '@homepage?slug=non-UTF8-characters' ); new prestaSitemapUrl( 'http://www.foo.bar/non-UTF8-characters' ); // Valid even if "mbstring" extension is not installed $baseUrl = 'http://www.foo.bar/non-UTF8-characters'; $utf8Url = aFunctionThatConvertToUTF8( $baseUrl ); new prestaSitemapUrl( $utf8Url );
If you try to access to non-existing section's sitemap content (eg: http://www.mydomain.com/sitemap.nonExistingSection.xml), it will return a 404 page.
A prestaSitemapUrl object expect 4 parameters that can be passed to the constructor or defined using setters methods:
The url. This is the only parameter that should be defined in order to see it appears in the sitemap.xml
Constructor's 1st parameter or defined by ->setLocation().
This can be a route or an absolute url. It will use url_for().
If you specificly need to use url_for1() or url_for2() methods you can use setLocation1() (for url_for1()) or setLocation2() (for url_for2())
A last modification date. You should give a DateTime object.
Constructor's 2nd parameter or defined by ->setLastModificationDate().
A change frequency.
Constructor's 3rd parameter or defined by ->setChangeFrequency().
Valid values are 'always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly' and 'never'.
It is recommended that you use prestaSitemapUrl::CHANGE_FREQUENCY_* constants.
Invalid values will be ignored.
A priority.
Constructor's 4th parameter or defined by ->setPriority().
This must be a number between 0 and 1.
Invalid values will be ignored.
So the 2 examples below will produce the same results
$o_prestaSitemapUrl1 = new prestaSitemapUrl( $miscUrl, $o_date, $changeFrequency, $priority ); $o_prestaSitemapUrl2 = new prestaSitemapUrl(); $o_prestaSitemapUrl2-> setLocation( $miscUrl )-> setLastModificationDate( $o_date )-> setChangeFrequency( $changeFrequency )-> setPriority( $priority );
It is possible to add extra datas to prestaSitemapUrl in order to provid more informaiton about one url in the generated sitemap.
You can use an option to generate a sitemap for mobile website. When the prestaSitemapUrl class is instanciated you can call the setMobile method with a boolean param. If you pass true, the plugin will generate a sitemap for a mobile website, with a specific tag : '
$o_prestaSitemapUrl1 = new prestaSitemapUrl( $miscUrl, $o_date, $changeFrequency, $priority ); o_prestaSitemapUrl1->setMobile( true );
Setting this parameter to true is mandatory if you want google to know that this is a mobile URL.
prestaSitemapUrlImage object allow to implement Google's image extensions for Sitemaps. This allow to list the images currently present in you web page and to describe metadata about them.
Use the presteSitemapUrl method addImage() to add one prestaSitemapUrlImage. Currently only 1000 images can be added to one single url tag (can be reconfigured in yml).
Exemple:
$o_prestaSitemapUrl1 = new prestaSitemapUrl( $miscUrl, $o_date, $changeFrequency, $priority ); $o_prestaSitemapUrlImage1 = new prestaSitemapUrlImage( $miscUrl, $caption, $geo_location, $title, $license); $o_prestaSitemapUrl1->addImage( $o_prestaSitemapUrlImage1 );
A prestaSitemapUrlImage object expect 5 parameters that can be passed to the constructor or defined using setters methods:
The image path. This is the only parameter that should be defined in order to see it appears in the sitemap.xml
Constructor's 1st parameter or defined by ->setLocation().
This can be a name or an absolute path. It will use image_path().
If you specificly need to use url_for() for a dynamic image methods you can use setLocationUrlFor()
A caption [optionnal]. Corresponding to the alt attribute.
Constructor's 2nd parameter or defined by ->setCaption().
A geolocation [optionnal].
Constructor's 3rd parameter or defined by ->setGeoLocation().
A title [optionnal]. Corresponding to the title attribute.
Constructor's 4th parameter or defined by ->setTitle().
A license [optionnal]. An URL to the license of the image.
Constructor's 5th parameter or defined by ->setLicense().
So the 2 examples below will produce the same results
$o_prestaSitemapUrlImage1 = new prestaSitemapUrlImage( $miscUrl, $caption, $geo_location, $title, $license); $o_prestaSitemapUrlImage2 = new prestaSitemapUrlImage(); $o_prestaSitemapUrlImage2-> setLocation( $miscUrl )-> setCaption( $caption )-> setGeoLocation( $geo_location )-> setTitle( $title )-> setLicense( $license );
There si 2 cache levels: a generated xml file cache and a prestaSitemapSection cache
First the xml files are cached (for 1 hour by default).
When they expires, the 'presta_sitemap.generate_urls' event is triggered and prestaSitemapSection object are instanciated.
If they're up-to-date there is no need to do action for retrieving all possible urls and instanciting prestaSitemapUrl object for each.
By default generated xml files are cached for 3600 seconds. Here is the associated config used internally and that can be redefined in project's config.yml
all:
prestaSitemapPlugin:
mainCache: # determine usage of generated xml files
enabled: true # cache enable
lifetime: 3600 # valid for 1 hour
sectionCache: # determine usage of internal cached datas at prestaSitemapSection level
enabled: true # enabled or disable internal cache usage for all prestaSitemapSection objects
lifetime: 86400 # default lifetime used for section when cache secitonCache is enabled (can be respecified for each sitemapSection)
Notice that in all cases (no matter the cache configuration) no datas will be generated when accessing to a section's sitemap (eg: sitemap.main.xml). Datas generation will only be triggered when calling sitemap.xml, this will ensure datas consistency and improved performances.
So if you want to see modifications in sitemap.main.xml don't forget to call sitemap.xml before.
Notice that if you want to see your latest modifications in url generation you can do manually a "symfony cache:clear" or add the follwing code to your app.yml in order to always see updated datas in your dev environement.
dev:
prestaSitemapPlugin:
mainCache:
enabled: false # disable main cache
sectionCache:
enabled: false # disable section cache
A prestaSitemapSection is a group of url that will be valid for a given lifetime and will be displayed in the sitemap 'sitemap.sectionName.xml'
Here is a little example about prestaSitemapSection
$o_sitemapSection = new prestaSitemapSection( 'sectionName', array( 'lifetime' => 172800 ) ); if( !$o_sitemapSection->isUpToDate() ) { // the code here will be executed each 48 hours, and the url will be outputed in 'sitemap.sectionName.xml' } $o_sitemapSection = new prestaSitemapSection( 'sectionName', array( 'lifetime' => 86400 ) ); if( !$o_sitemapSection->isUpToDate() ) { // the code here will be executed each 24 hours, and the url will be outputed in 'sitemap.sectionName.xml' // Notice that 2 sections have the same name but different lifetime. This will correrctly work. } $o_sitemapSection = new prestaSitemapSection( 'anotherSectionName', array( 'lifetime' => 86400 ) ); if( !$o_sitemapSection->isUpToDate() ) { // the code here will be executed each 24 hours, and the url will be outputed in 'sitemap.anotherSectionName.xml' } $o_sitemapSection = new prestaSitemapSection(); if( !$o_sitemapSection->isUpToDate() ) { // the code here will have a lifetime as defined by 'app_prestaSitemapPlugin_sectionCache[enabled]', and the url will be outputed in 'sitemap.main.xml' }
Add support for google's mobile extension for sitemaps
