Version 1 has been tagged and released.
Grab it here: http://github.com/ThePixelDeveloper/kohana-sitemap/tree/1.0
Documentation exists for the basic examples and contains unit tests for up to 60% code coverage. The 1.0.1 release will focus on 100% code coverage and finishing the documentation. Enjoy.
I would also appreciate any code review as this is the first time I've released an OO module for Kohana.
Kind Regards, -Mathew Davies.
Posted By: OllyIn places you have statements along the lines of if (NULL === $var). Normally these would go the other way round for readabilities sake. Also a few touchups on the method comments, otherwise a great module. Well done.
NULL = $varIt will error out vs $var = NULL which is harder to pickup.When I tried to use basic sample, I got error: ErrorException [ Strict ]: is_a(): Deprecated. Please use the instanceof operator
MODPATH/sitemap\classes\sitemap\url.php [ 76 ]
71 *
72 * @param <type> $driver
73 */
74 public function __construct( $driver = NULL)
75 {
76 if ( is_a($driver, 'Sitemap_Data') AND NULL !== $driver )
77 {
78 $this->_driver = $driver;
79 }
80 }
81
That's something I picked up from my Java friends. If you make a typo and end up with NULL = $var It will error out
For me, code readability beats minor debugging benefit. We are all different though I don't mean to start a big argument!
Thanks Random, pushed an update out to fix that. :-)
http://github.com/ThePixelDeveloper/Sitemap/commit/0d7aafd02462f9bf49c3a4af480510df5ed4c515
banks, I'll argue about it in the IRC or a whisper.
Sorry, I have no account on Github, an cann't add commits. I found another undefined method DateTime::setTimestamp() in data.php:
MODPATH/sitemap\classes\sitemap\data.php [ 65 ]
60 protected function date_format($unix)
61 {
62 $date = new DateTime;
63
64 // For unixtime stamps.
65 $date->setTimestamp($unix);
66
67 // Format to W3C standards
68 return $date->format(DATE_W3C);
69 }
70 }
Posted By: RandomI found another undefined method DateTime::setTimestamp() in data.php:
Ok, I'll try. My PHP version is 5.2.4
UPD: And what should be in sitemap/classes/controller/sitemap.php?
Posted By: RandomOk, I'll try. My PHP version is 5.2.4
UPD: And what should be in sitemap/classes/controller/sitemap.php?
Mathew, thanks for your answer. Ok, I'll register and write reports on Github.
In example at the top of the page you show how to add a page to sitemap. My question was about how to get sitemap. If I call URL mysite/sitemap.xml or mysite/sitemap.xml.gz, I get error message: ReflectionException [ -1 ]: Class controller_sitemap does not exist. In module's init.php both route rules calls sitemap contoller:
->defaults(array(
'controller' => 'sitemap',
'action' => 'index'
));
I shouldn't of committed those sitemap routes as the 2nd one is specific to my needs but here's a full example of what you need to do.
Route::set('sitemap', 'sitemap.xml(<gzip>)', array('gzip' => '\\\\.gz'))
->defaults(array(
'controller' => 'sitemap',
'action' => 'index'
));
For example, http://website.com/sitemap.xml will call the "sitemap" controller and "action_index"
public function action_index()
{
// Set response headers
$this->request->headers['Content-Type'] = 'text/xml';
// Sitemap class
$sitemap = new Sitemap;
// Find all rows
$coasters = ORM::factory('user')->find_all();
// Add the URLs
foreach($coasters as $row)
{
$url = new Sitemap_Url();
// Core attributes
$url->set_loc($row->url);
$url->set_last_mod($row->last_login);
$url->set_priority(0.5);
$url->set_change_frequency('weekly');
$sitemap->add($url);
}
$this->request->response = $sitemap;
}
When "sitemap.xml.gz" is specified the sitemap class will know it needs to return a gzipped file and will do so automatically.
Hope that helps
Mathew, sorry for my more one question. I'm not a guru in PHP and Kohana and need some illustrations about your module. Should I save an url info in database or in file each time, when I add it to sitemap in my application?
I think it will be very useful, if your module automatically save all data in a file (may be as cache), and return it on demand.
I've been away from this project a bit and made some progress on it.
I'm also in progress writing tests for it. Currently up to 60% coverage and should be nearing 100% soon enough. Documentation is also coming, but it should be easy enough to use.
All changes can be found in the develop branch of kohana-sitemap. Version 1 coming soon.
Note: If you plan to run the tests, you'll need pecl_http. Funny story, PHP provides you with gzencode, but not gzdecode. We have to wait for PHP 6 before we're allowed to decode gzip encoded data. Insane!
Version 1 has been tagged and released.
Grab it here: http://github.com/ThePixelDeveloper/kohana-sitemap/tree/1.0
Documentation exists for the basic examples and contains unit tests for up to 60% code coverage. The 1.0.1 release will focus on 100% code coverage and finishing the documentation. Enjoy.
You're not required to release your changes if you use this module on your website. This is a hole in the GPL.
Using != Distributing
I might change the license at a later date, but for now you can sleep easy.
I just released a new version. No more GPL and code coverage has been moved up to 74%. Download Kohana-Sitemap 1.0.1
How can i use it with gz compression?
It looks like you're new here. If you want to get involved, click one of these buttons!