CodeIgniter Forums

Full Version: Very fast sitemap generator (library and helper)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Patroklo[/eluser]
First of all, if you can't understand something in the text, please tell me and I'll try to make myself clearer. English it's not my language and I usually don't have any chance for practicing it.

Last week I needed a sitemap generator for my personal project website. It's a webcomic hosting made fully in codeigniter that uses a subdomain for each webcomic. This is a very particular neccesity because I must make a different sitemap file for each subdomain and I have a tons of urls that change a lot to add to the sitemap files. In short, there are more than 2,000 different files and more than 150,000 different urls in total.

I tried to use the sitemap generator that it's posted in the codeigniter wiki but I didn't liked very much its performance, so I decided to make my own generator and now its posted in git hub for everyone that could need a faster sitemap generator.

Also, as addition, it also can be used to make normal xml files.

Every comment, criticism or anything you want to say(even only say "hello there!") it's very welcome.

(I also have a point I'd like to check... is there any possibility to upload this code to the codeigniter wiki?)

Thanks!

GIT HUB PROJECT URL: https://github.com/Patroklo/Codeigniter-sitemap-creator

El Forum

[eluser]CI705[/eluser]
it looks great, but are there any instructions for beginners like me, thanks

El Forum

[eluser]Clooner[/eluser]
Looking for a good sitemap generator at the moment! Does it also generate relevant lastmod, changefreq, & priority reports?

El Forum

[eluser]Patroklo[/eluser]
[quote author="CI705" date="1327989960"]it looks great, but are there any instructions for beginners like me, thanks[/quote]

I'll try to make today one more complicated example an a simple tutorial. Thanks!


[quote author="Jeroen Schaftenaar" date="1328066181"]Looking for a good sitemap generator at the moment! Does it also generate relevant lastmod, changefreq, & priority reports? [/quote]

In theory you can use any label you want in the generator, you only have to make it.

El Forum

[eluser]Patroklo[/eluser]
I have just uploaded a new version of the code, it's a little slowlier(like one more second from the 44 initial seconds) but I think it works better and also let's to add data into the sitemap and not only making one from scratch.

I have also posted a new example in wich you can also make a sitemap index and a sitemap that has image urls, a tag that google accepts. The sitemap builder can work with every special tag that google accepts: video, images, code, etc...

Also I have made a little manual in spanish and english just for helpping you working with the library and models. If you have any problem or question, feel free to ask. Thanks!!!

El Forum

[eluser]tdupp[/eluser]
To the creator of this code, I'm in need of a lot of help.

I'm attempting to add this to our website, unfortunately I'm not strong in PHP coding, and I'm getting an error in the controller.

Code:
function index()
{
  echo ('hi');
  $this->load->model('sitemaper_model');
  //$this->sitemaper_model->makeSitemapBlock('imagesList');
  //$this->sitemaper_model->makeSitemapBlock('blogList');
  $test=$this->sitemaper_model->makeSitemapBlock('sitemap_builder');
  echo ($test);
}

in an attempt to debug I've shown my code here, when i go to theurl/sitemap

it echo's the hi, but it does not echo the $test.

I'm trying to determine where the break is occcuring.

El Forum

[eluser]CroNiX[/eluser]
You can't echo a boolean value (TRUE/FALSE), which is what sitemaper_model::makeSitemapBlock() returns.
Try var_dump($test) instead.

El Forum

[eluser]tdupp[/eluser]
[quote author="CroNiX" date="1331594546"]You can't echo a boolean value (TRUE/FALSE), which is what sitemaper_model::makeSitemapBlock() returns.
Try var_dump($test) instead.[/quote]

okay the result was "bool(false)" when going to theurl.com/sitemap

Here is the model

Code:
<?php
class sitemaper_model extends CI_Model {

  private $block;

  function sitemaper_model() {
  
    // Call the Model constructor
    parent::__construct();
   $this->load->helper('sitemap_lists');
$this->load->library('sitemaper_builder');
  }
  
  function makeSitemapBlock($new_block, $datos = NULL)
  {  
    if(class_exists($new_block) and is_subclass_of($new_block, 'urlList'))
  {
     if($datos == NULL)
     {
      $this->block = new $new_block();
   }
  

   $this->sitemaper_builder->builder(array('archive' => $this->block->getFileName(), 'type' => $this->block->getType()));
   $this->generateSitemap();
   return TRUE;
  }
  else
  {
   return FALSE;
  }
  }
  
  function generateSitemap()
  {

    while($this->block->makeQuery())
  {
   $rowsList =& $this->block->getList();

   $this->sitemaper_builder->insertLines($rowsList);
  }
  
  $this->sitemaper_builder->close(true);
  }
  
  
}
?>



Here the skinny: This is what I need to get this code to do for me.

1. generates the XML and prints it to sitemap.php
2. I'm not allowed to save an xml file to the server or ping google - i need to disable these behaviors.
3. The idea is that we will just manually take the xml generated from sitemap.php and upload manually.