CodeIgniter Forums
ATOM Feed "Generator" - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: ATOM Feed "Generator" (/showthread.php?tid=18194)



ATOM Feed "Generator" - El Forum - 04-28-2009

[eluser]awpti[/eluser]
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.

Code:
<?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>[email protected]</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 .= "      &lt;title&gt;{$entry->job_title}&lt;/title&gt;\n";
                        $xml .= '      &lt;link href=\"http://ignitedjobs.com/view/{$entry-&gt;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;
        }

}



ATOM Feed "Generator" - El Forum - 04-28-2009

[eluser]Colin Williams[/eluser]
Just have an atom.php view.