TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Sitemap Module - 1.0.1 (Fri 02 July)
  • 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.

  • Very nice module. Clean code (on the most part), haven't had a go at testing it, but i'm sure you have and it works.

    In 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.
  • Thanks for the kind words.

    Posted By: Olly

    In 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.


    That's something I picked up from my Java friends. If you make a typo and end up with NULL = $varIt will error out vs $var = NULL which is harder to pickup.

    -Mathew
  • 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.

  • Looks good Matt, have you managed to write any tests for it?
    @banks, what's your username in IRC?
  • 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:


    Upgrade to PHP 5.2.0+ or format the time using date('Y-m-d\TH:i:sP', $unix)
  • Ok, I'll try. My PHP version is 5.2.4

    UPD: And what should be in sitemap/classes/controller/sitemap.php?

  • Posted By: Random

    Ok, I'll try. My PHP version is 5.2.4

    UPD: And what should be in sitemap/classes/controller/sitemap.php?



    It should be enabled already unless you disabled it. See here

    http://www.php.net/manual/en/datetime.installation.php

    I'll probably change though. Using "date('Y-m-d\TH:i:sP', $unix)" is faster by some margin (280%).

    There isn't a controller directory so I'm not sure what you mean. Just follow the example at the top of the page.

    In future can report any bugs and suggestions on the github tracker? It's easier for myself to manage.

    Regards,
    -Mathew
  • 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.

    config/sitemap.php

    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"

    classes/controller/sitemap.php : 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.

    • Classes are now properly renamed to fall into Kohana naming style.
    • Ping has been rewritten to use parallel requests.
    • date_format and encode have been moved to the sitemap class and been made static.
    • encode was fixed due to PHP not supporting a newer RFC
    • Created a sitemap interface to make extending the class more consistent.
    • More input validation checks

    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.

  • Thanks its very very nice, but why GPL ? :P

  • Boo GPL ;)

  • Double Boo GPL :(
  • whats wrong with GPL? :)

  • Because its viral license :/

  • Make a new topic about the GPL if you want to discuss it in detail.

  • 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 would say that you should use the Kohana License unless you have any objections to it!
  • I just released a new version. No more GPL and code coverage has been moved up to 74%. Download Kohana-Sitemap 1.0.1

    Version 1.0.1

    Dated: Fri 02 Jul 2010, 9:12 PM

    • Use "news" namespace instead of "n" in the news sitemap.
    • Add tests for the Mobile and Geo Sitemap.
    • Make Kohana_Sitemap_* classes abstract.
    • Changed to the ISC License
  • How can i use it with gz compression?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion