EllisLab text mark
Advanced Search
     
ATOM Feed “Generator”
Posted: 28 April 2009 03:13 PM
Avatar
Joined: 2002-11-11
180 posts

So, i wrote this right after waking up. It still “looks” okay to me, I think.

Is there a more elegant way of going about this? It feels messy.

<?php

class Atom {

        
var $CI;

        function 
Atom()
        
{
                $this
->CI =& get_instance();
        
}

        
function generate($feed_type 'full')
        
{
                $xml 
'<?xml version="1.0" encoding="utf-8"?>'."\n";
                
$xml .= '<feed xmlns="http://www.w3.org/2005/Atom">'."\n";
                
$xml .= '   <title>IgnitedJobs '.ucfirst($feed_type)."</title>\n";
                
$xml .= '   <link href="http://ignitedjobs.com/atom/" rel="self" />'."\n";
                
$xml .= '   <link href="http://example.org/" />'."\n";
                
$xml .= '   <updated>'.date('Y-m-d').'T'.date('H:i:s').'Z</updated>'."\n";
                
$xml .= "   <author>\n";
                
$xml .= '      <name>Ignited Jobs '.ucfirst($job_type)." Feed!\n";
                
$xml .= "      <email>feeds@ignitedjobs.com</email>\n";
                
$xml .= "   </author>\n";

                
$this->CI->db->limit(50);
                
$this->CI->db->orderby('job_id''DESC');

                switch(
$feed_type)
                
{
                        
case 'full':
                                
$data $this->CI->db->get('jobs');
                        break;
                        case 
'real':
                                
$this->CI->db->where('job_type''real');
                        break;
                        case 
'contract':
                                
$this->CI->db->where('job_type''contract');
                        break;
                        case 
'shorty':
                                
$this->CI->db->where('job_type''shorty');
                        break;
                
}

                $data 
$this->CI->db->get('jobs');

                foreach(
$data as $entry)
                
{
                        $xml 
.= "   <entry>\n";
                        
$xml .= "      <title>{$entry->job_title}</title>\n";
                        
$xml .= '      <link href=\"http://ignitedjobs.com/view/{$entry->job_id}/" />'."\n";
                        
$xml .= "      <id>tag:ignitedjobs.com,view:job-{$entry->job_id}</id>\n";
                        
$xml .= "      <updated>".date('Y-m-d'$entry->job_date_created).'T'.date('H:i:s'$entry->job_date_created)."Z</updated>\n";
                        
$xml .= "      <summary>{$entry->job_city}, {$entry->job_state} - {$entry->job_title} - {$entry->job_type}</summary>\n";
                        
$xml .= "   </entry>\n";
                
}
                
return $xml;
        
}

 Signature 

Blog:
GeekLAN
Projects:
Ignited Jobs - LAMP Tips

 
Posted: 28 April 2009 05:41 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2006-07-27
2617 posts

Just have an atom.php view.

 Signature 

Check out the Template Library
Oh yeah, I tweet, too (regarding CodeIgniter on occassion).