Current Version of Codefight CMS Available for Download:

            « Version 1.1.4 »

            NOTE: The code available is same as the code used for this site at the time of release.

            Codefight CMS is based on Codeigniter PHP Framework which is very easy to learn.

            It would be nice to hear back some feedback. Also you can contribute with code and helping translating language files in your language.

            You can use this CMS in anyway you want. You can modify as you like and use commercially for free.

 

Select Language.[TESTING For Next Release.]

English | नेपाली | French | German | Korean

Login | Select Language | Thu, 11 Mar 10 17:44:39 -0700

Feed and sitemap generation Part II

2009-03-13 19:34:41Damodar Bashyal

 

This is part II of: Feed and sitemap generation Part I

I hope you were success in creating feed url and were very excited as i was.

I am working on this from long time as a part time after work and on weekends. I hope one day it will be in a condition when i'll be proud to release and be very excited for the contribution to the community. But for now i am thinking to pause uploading new files to google code but write few posts on new updates. This will help anyone to install new feature and understand what's going on.

Ok, thats too much talking, now Time for Sitemap generation. This is another community contribution on codeigniter that i used to create my sitemap. As it is not final but for now i tested this contribution like below. Rather than menu links, and other links, i'll be using last 50 post on my sitemap.

Contribution link on codeignitor: http://codeigniter.com/wiki/Google_Sitemaps/

STEP 1:

Download google_sitemap_pi.php and upload it to plugins directory.

STEP2: [frontend/controllers/sitemap.php]
CODE:

1-
2-<?php
3-class Sitemap extends Controller
4-{
5-function Sitemap()
6-{
7-parent::Controller();
8-$this->load->helper(array('text'));
9-$this->load->plugin('google_sitemap'); //Load Plugin
10-$this->load->model('page_model');
11-}
12-
13-function index()
14-{
15-$sitemap = new google_sitemap; //Create a new Sitemap Object
16-$posts = $this->page_model->getRecentPosts('50');
17-$item = new google_sitemap_item(site_url(), date(“Y-m-d“,time()), 'daily', '0.8' ); //Create a new Item
18-$sitemap->add_item($item);
19-foreach($posts->result() as $entry) {
20-$link = preg_replace('|[^a-z0-9]+|i','-',strtolower($entry->pages_title));
21-//remove last dashes if any
22-while(substr($link, -1) == '-') {
23-$link = substr($link, 0, -1);
24-}
25-$link = “page/{$entry->menu_id}/{$entry->pages_id}/$link“;// . $this->config->item('url_suffix')base_url().
26-$item = new google_sitemap_item(site_url($link), date(“Y-m-d“,strtotime($entry->pages_date)), 'weekly', '0.8' ); //Create a new Item
27-$sitemap->add_item($item); //Append the item to the sitemap object
28-}
29-$sitemap->build(“sitemap.xml“); //Build it...
30-//Let's compress it to gz31-$data = implode(““, file(“sitemap.xml“));32-$gzdata = gzencode($data, 9);33-$fp = fopen(“sitemap.xml.gz“, “w“);34-fwrite($fp, $gzdata);35-fclose($fp);36-//Let's Ping google
37-$this->_pingGoogleSitemaps(base_url().“/sitemap.xml.gz“);
38-}
39-
40-function _pingGoogleSitemaps( $url_xml )
41-{
42-$status = 0;
43-$google = 'www.google.com';
44-if( $fp=@fsockopen($google, 80) )
45-{
46-$req = 'GET /webmasters/sitemaps/ping?sitemap=' .
47-urlencode( $url_xml ) . “ HTTP/1.1\r\n“ .
48-“Host: $google\r\n“ .
49-“User-Agent: Mozilla/5.0 (compatible; “ .
50-PHP_OS . “) PHP/“ . PHP_VERSION . “\r\n“ .
51-“Connection: Close\r\n\r\n“;
52-fwrite( $fp, $req );
53-while( !feof($fp) )
54-{
55-if( @preg_match('~^HTTP/\d\.\d (\d+)~i', fgets($fp, 128), $m) )
56-{
57-$status = intval( $m[1] );
58-break;
59-}
60-}
61-fclose( $fp );
62-}
63-return( $status );
64-}
65-
66-}
67-?>
68-
STEP 3:

Create two files sitemap.xml.gz and sitemap.xml and give write permissions to both.

STEP 4:

Now time to generate sitemap and notify google about new sitemap. To do this just call this file as yoursite/sitemap.html. It will create sitemap for you and notify google about the new sitemap just created for it come and get it :)

All Done!!!

Good Luck.


Bookmark and Share

Good tutorial! Thank you! ;)

18/03/09 03:52:13|kiddo

is your script only for a blog.........

08/08/09 05:31:42|Manset Soft Technology

You need to download CMS and view listed files to better understand the sitemap generation. You need to check page_model.php as well. This was created for codefight cms, so you may need to change code according to your requirement. sitemap for this site is generated using this code. So its fully tested and working. You can check sitemap link at the bottom of the page. Thanks for visiting.

02/11/09 04:40:18|Damu

You can modify and use for blog, cms or whatever you like according to your need.

03/09/09 10:28:35|Damu

 

 





Javascript must be enabled to post comments!