View unanswered posts | View active topics It is currently Wed Sep 08, 2010 11:34 am



Post new topic Reply to topic  [ 9 posts ] 
 jobs sitemap generator 
Author Message

Joined: Wed Oct 07, 2009 12:58 am
Posts: 6
Post jobs sitemap generator
Hello friends I wrote a code to gerenarte sitemaps, there are 3 files of sitemaps I called sitemap.xml (index sitemap) static.xml and jobs.xml I want share with you.

Code:
<?
$mypath=$_SERVER['DOCUMENT_ROOT'];//.'/generator/'.date('Ymd');
$link=mysql_connect('localhost','user','password') or die(mysql_error());
mysql_set_charset('utf8',$link);
mysql_select_db('DB',$link)or die(mysql_error());

//job titles friendly
function friendlyURL($string){
   //$string = str_replace("ñ","n",$string);
   $string = preg_replace("`\[.*\]`U","",$string);
   $string = preg_replace('`&(amp;)?#?[a-z0-9]+;`i','-',$string);
   
   $string = htmlentities($string, ENT_COMPAT, 'utf-8');
   $string = preg_replace( "`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);`i","\\1", $string );
   $string = preg_replace( array("`[^a-z0-9]`i","`[-]+`") , "-", $string);
   return strtolower(trim($string, '-'));
}
//query to smartjobsboard DB to found the ID and title of jobs
            ini_set('mysql.charset', 'UTF-8');
            $sql="select a1.sid,a2.value from listings a1, listings_properties a2 where a1.sid = a2.object_sid and a2.id = 'title' order by a1.sid desc";

            $filename = $mypath.'/jobs.xml';
            $handle = fopen($filename,"w+");
            

            fwrite($handle,'<?xml version="1.0" encoding="UTF-8"?>'."\n");
            fwrite($handle,'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n");
            $r=mysql_query($sql) or die(mysql_error());
            while($fila=mysql_fetch_assoc($r))
            {
               fwrite($handle,'<url>'."\n");
               $titulo = friendlyURL($fila['value']);
               //echo "id:".$fila['sid']."-".$fila['value']."-".$titulo."<br>";
               fwrite($handle,"\t".'<loc>http://www.trabajoperuano.com/display_job/'.$fila['sid'].'/'.$titulo.'.html</loc>'."\n");
               fwrite($handle,"\t".'<lastmod>'.date('Y-m-d').'</lastmod>'."\n");   
               fwrite($handle,"\t".'<changefreq>daily</changefreq>'."\n");
               fwrite($handle,"\t".' <priority>0.9</priority>'."\n");
               fwrite($handle,'</url>'."\n");
            }
            fwrite($handle,'</urlset>');
            fclose($handle);
         

            //get jobs
            //build sitemap_________________________________________________-
            $filename = $mypath.'/sitemap.xml';
            //if(file_exists($filename)) unlink($filename);

            $handle = fopen($filename,"w+");
            fwrite($handle,'<?xml version="1.0" encoding="UTF-8"?>'."\n");
            fwrite($handle,'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n");
            //insert estaticos.xml
            $filexml = $mypath.'/static.xml';
            //copy($filexml,$_SERVER['DOCUMENT_ROOT'].'/');
            if(file_exists($filexml)){
               fwrite($handle,'<sitemap>'."\n");
               fwrite($handle,"\t".'<loc>http://www.trabajoperuano.com/static.xml</loc>'."\n");
               fwrite($handle,"\t".'<lastmod>'.date('Y-m-d').'</lastmod>'."\n");   
               fwrite($handle,'</sitemap>'."\n");
            }
            $i=1;
            $filexml = $mypath.'/jobs.xml';
            if(file_exists($filexml)){
               fwrite($handle,'<sitemap>'."\n");
               fwrite($handle,"\t".'<loc>http://www.trabajoperuano.com/jobs.xml</loc>'."\n");
               fwrite($handle,"\t".'<lastmod>'.date('Y-m-d').'</lastmod>'."\n");   
               fwrite($handle,'</sitemap>'."\n");
            }
            fwrite($handle,'</sitemapindex>'."\n");   

?>


I hope this be util for you


Wed Oct 07, 2009 1:10 am
Profile

Joined: Wed Oct 07, 2009 12:58 am
Posts: 6
Post Re: jobs sitemap generator
I changed display_job by ver-trabajo, because my site is a spanish site, and I changed some vars tooo you can change display_jobs by display-jobs, but I am not sure google can work easly wiht display_jobs too, or maybe take that like a var and not like 2 words, any way if you want how is now my site you can enter to http://www.trabajoperuano.com

See you


Wed Oct 07, 2009 1:14 am
Profile

Joined: Thu Sep 24, 2009 9:17 am
Posts: 2
Post Re: jobs sitemap generator
Hi,

Very good,

Am i correct that when a new job is added, this will update the xml site map? Does it also submit it?

Where do we put this and as what name


Thanks

Mark


Thu Oct 22, 2009 3:05 am
Profile

Joined: Wed Oct 07, 2009 12:58 am
Posts: 6
Post Re: jobs sitemap generator
I did a script called generator-sitemap.php in the public_html directory, and I run this script every days, but you give me a better idea: to create a script that update automatically the xml when some one post a new job, great...
but I have to resubmit to google my xml manually yet...:( or exists a way to do this automatically?,

Take Care ;)


Sat Oct 31, 2009 5:26 pm
Profile

Joined: Mon Feb 22, 2010 6:59 pm
Posts: 4
Post Re: jobs sitemap generator
how to I make this work? Do you have any additional instructions?


Mon Jul 12, 2010 3:11 pm
Profile

Joined: Thu May 27, 2010 5:43 am
Posts: 61
Post Re: jobs sitemap generator
The XML sitemap will be included in the new software version 3.2 :)
Quote:
mark,
Am i correct that when a new job is added, this will update the xml site map?

As for v3.2 - not exactly when a new job posted -the xml sitemap will be updated automatically according to CRON settings. I.e. if you set CRON to run every hour, then the xml sitemap will be checking for updates every hour.


Tue Jul 13, 2010 2:50 am
Profile WWW

Joined: Wed Aug 04, 2010 7:38 am
Posts: 1
Location: Indonesia
Post Re: jobs sitemap generator
@jorge: Very nice Flash you've got there...
@julia: when will the 3.2 released?

Pauro
New Player


Wed Aug 04, 2010 7:43 am
Profile

Joined: Wed Oct 07, 2009 12:58 am
Posts: 6
Post Re: jobs sitemap generator
@Pauro, thank if you want I can to do a flash map like had http://www.trabajoperuano.com... my email and skype is jmendoza@codeperu.com

Chau..


Fri Aug 13, 2010 10:29 am
Profile

Joined: Thu May 27, 2010 5:43 am
Posts: 61
Post Re: jobs sitemap generator
@Pauro
The version 3.2 will be released in the latter half of September.


Mon Aug 16, 2010 2:02 am
Profile WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
SmartJobBoard forum