Welcome Guest, Not a member yet? Register   Sign In
User Dedicated RSS
#1

[eluser]Byron10[/eluser]
Greetings to all.

You will probably know I am new to CI from my question.

I have a small network built with CI with a small number of user.

The question:

Is there a way to create a function where each member can disply the postings they add on my site onto other sites like their blogs?

I thought that this could be done either by RSS or perhaps creating a new controller or function under the user controller and then creating the view for it. From their, they can carry that view with an IFrame or any other way.

Any assistance would be greatly appreciated.

Cheers.
#2

[eluser]Byron10[/eluser]
I guess it cannot be done with CI.

Time to consider a different platform perhaps.
#3

[eluser]neomech[/eluser]
I just recently needed to make an RSS feed using codeigniter.

This link here told me everything I needed to know.

http://www.derekallard.com/blog/post/bui...e-igniter/

I'm not sure how much familiarity you need with codeigniter to follow this, but it works well and was pretty straightforward for a middling CI user Wink
#4

[eluser]Byron10[/eluser]
@Neomech..

Thank you kindly. I appreciate you taking the time to help.

I was just about to download another script to run my site with, but I think I'll hold back on that and look at the link you suggested.

I'll post back with the progress.

Thanks again.
#5

[eluser]neomech[/eluser]
I should note that when I copied that code over, I ran into some small problems with the formatting of Dereks' <description> tag in the rss view file. You'll see that it spans several lines, and that it uses a php short tag &lt;?= instead of ?php. It was giving me trouble, so I set it all to one line, used a regular php tag, and actually got rid of the CDATA stuff for good measure (although I added it back later).

Anyway, if you're having trouble, just take a look and make sure that that it's not something weird with the <description> tag if you haven't changed it much.
#6

[eluser]Byron10[/eluser]
Cool, thanks.

The code seems to be easy enough to work with, however, it is not exactly what I needed, but may be with some code re-writing it can be modified to suit what I want to achieve.

The case:

I have a number of users who want to be able to display their latest posts on our site on another website.. ie, take their posts from our site and display them on their own sites, blogs..etc.

The code I was looking at does produce an RSS feed for recent posts for the entire site, not a particular user..so I guess we probably need to do a little tweaking.

Now, going by that code, if I create a controller (feed), but have it like this:

Code:
&lt;?php
class Feed extends Controller
{

    function Feed()
    {
        parent::Controller();
        $this->load->model('user_model', '', TRUE);
        $this->load->helper('xml');
    }
    
    function index()
    {
        $data['encoding'] = 'utf-8';
        $data['feed_name'] = 'DerekAllard.com';
        $data['feed_url'] = 'http://www.derekallard.com';
        $data['page_description'] = 'Code Igniter, PHP, and the World of Web Design';
        $data['page_language'] = 'en-ca';
        $data['creator_email'] = 'Derek Allard is at derek at derekallard dot com';
        $data['posts'] = $this->user_model->getUserRecentPosts();    
        header("Content-Type: application/rss+xml");
        $this->load->view('feed/rss', $data);
    }
}
?&gt;

Next, the code gives a code for the getRecentPosts function inside the posts_model.. May be, what I can do is create a similar function, but inside the user_model: Note that the code orders the db by post_date and desc.. I will need to take out the desc and replace with the 'user' since I will not need the desc as part of the rss because all I want to feed is images (which are the posts themselves):

Code:
function getUserRecentPosts ()
{
        $this->db->orderby('post_date', 'desc');
        $this->db->where('post_visible', 1);
        $this->db->limit(10);
        return $this->db->get('posts');
}

So, how do you think that would go for us?

Thanks.
#7

[eluser]neomech[/eluser]
What you're trying to do sounds pretty straightforward, actually. You just need to capture the user's id when you're calling the feed controller, and plug it into your model when you're getting the feed details.

Certainly CI can do what you want. I modified Derek's code to do something much more complicated, and it didn't take much work.

Just quickly, here's how your Model would look (note the 2nd "where" clause):
Code:
function getUserRecentPosts ($user_id)
{
        $this->db->orderby('post_date', 'desc');
        $this->db->where('post_visible', 1);
        $this->db->where('user_id',$user_id);
        $this->db->limit(10);
        return $this->db->get('posts');
}
And here's the call to that model (note that I'm now passing the user id as a variable):
Code:
$data['posts'] = $this->user_model->getUserRecentPosts($user_id);
And finally, all you'd need to do is make sure you were getting the variable when you declare the index function (not sure my terminology is correct there, but you get the idea):
Code:
function index($user_id=1) //defaults to user with user_id of 1
Now if you want to have someone subscribe to a particular users feed, the link would look like this:
Code:
<a href="/feed/index/35" type="application/rss+xml">Feed for User 35</a>
You can get rid of the "/index/" there using URI Routing (check the CI manual). Or, you can just do what I did and rename the feed function from index to something like "news". Then the url would be "/feed/news/35", which looks better, in my opinion.

Hope that helps!
#8

[eluser]Unknown[/eluser]
I have tested almost all ring tones sites. I found most of them to be bad. I finally found a great site that gives the best ring tones for free.
#9

[eluser]Byron10[/eluser]
Hello again,

I actually dropped this for a couple of days as it was giving me too much pain.. I decided to get back to it and see what I can do.

I found a function in our post_model where I think I can use it to generate an rss feed.. as mentioned above, I want to allow members to generate an rss feed for their posts where they can show their latest posts on other sites.

I would be grateful if someone could help me out with:

1. is this model function good for what we want?
2. help with writing the controller

Thank you so much..

Here's the model:
Code:
function getLatestPostsByUsername($page, $per_page, $username, $my_profile = FALSE)
    {
      $this->db->select('posts.post_id,
                         posts.post_title,
                         posts.post_body,
                         posts.post_date,
                         posts.post_added,
                         posts.post_type,
                         posts.post_image,
                         posts.post_rating,
                         posts.user_id,
                         users.username,
                         posts.post_location')
               ->from('posts, users')
               ->where('posts.user_id = users.id')
               ->where('users.username', $username)
               ->order_by('post_id', 'desc');
              
      if ($my_profile == FALSE)
      {
        $this->db->where('posts.post_is_public', 1);
      }
      
      if ($page >= 0 && $per_page > 0)
      {
        $this->db->limit($per_page, $per_page * $page);
      }
      $post_data_raw = $this->db->get();
      $post_data = $post_data_raw->result_array();
      
      $posts = array(); $i = 0;
      foreach ($post_data as $post)
      {
        $posts[$i] = $post;
        $this->db->select('tags.tag_id, tags.tag_name')
                 ->from('tags, post_to_tag')
                 ->where('tags.tag_id = post_to_tag.tag_id')
                 ->where('post_to_tag.post_id = ' . intval($post['post_id']));
        $tag_data_raw = $this->db->get();
        $tag_data = $tag_data_raw->result_array();
        
        $posts[$i]['tags'] = $tag_data;
        
        /*$this->db->select('brands.brand_id, brands.brand_name')
                 ->from('brands, post_to_brand')
                 ->where('brands.brand_id = post_to_brand.brand_id')
                 ->where('post_to_brand.post_id = ' . intval($post['post_id']));
        $brand_data_raw = $this->db->get();
        $brand_data = $brand_data_raw->result_array();
        
        $posts[$i]['brands'] = $brand_data;*/
        
        $this->db->select('COUNT(favorite_id) as favorite')
                 ->from('favorites')
                 ->where('favorites.post_id = ' . intval($post['post_id']));
        $tag_data_raw = $this->db->get();
        $tag_data = $tag_data_raw->row_array();
        
        $posts[$i]['favorite'] = $tag_data;
        
        $i++;
      }
      
      return $posts;
    }




Theme © iAndrew 2016 - Forum software by © MyBB