XF 1.2 Can I include image urls for attachments in our rss feeds?


New member
We're setting up a news node on our forum for our team to post to, and for users to discuss.

The forums are only one part of our site though, and we're integrating the rss feed from our news node into the home page of our website.

The rss feed only seems to offer an attachment link for the threads. Is there a way to include an actual img tag for image attachments (I understand that this would make it hard to track hits to our hosted images)?

I see that when I include an image via url, it inserts an img tag, with the src url that I entered. Is there a way to set up image attachments to do this too?

Otherwise, to get the image to display on our homepage where we're displaying the rss feed, I'll have to write a script to process the rss feed to pull the url from the first attachment link to drop that into the src of an img tag. This seems really unnecessary though, and I'm hoping that there is a built in way to do this.

Thanks for any help, or suggestions.


New member
Since no one got back to me, I skipped the rss feed, and went straight into the database.

It's a bit hacky, because the first thing in the news post needs to be an image attachment with a space after the bbcode, but it gave me way more control over showing a feed from the forum elsewhere on my site, and allowed me to get the image attachments and to show them to users who aren't logged in. Plus I set it up to get the image thumbnail rather than pulling in the full sized image (I set my thumbnail size to 370 x 370 max to fit my needs).

Here's the code in case anyone wants to do something similar.

function get_forum_news(){
        $news_node_id = 3;
        $post_limit = 20;
        $query = "SELECT xf_thread.thread_id, xf_thread.post_date, xf_thread.title,
                        xf_post.message,  xf_post.username
                        FROM xf_thread, xf_post
                        WHERE xf_thread.node_id = $news_node_id AND (xf_thread.post_date = xf_post.post_date) AND (xf_post.message_state = 'visible')
                        LIMIT $post_limit";
        $result = mysql_query($query);
        //build array of objects or return false
        if(mysql_num_rows($result) <= 0)
            //echo mysql_errno() . ": " . mysql_error(). "\n";
            //echo $query;
            return false;
            $return_array = array();
            $key = 0;
            while($data = mysql_fetch_array($result)){
                $data['message'] = trim(stripBBCode($data['message']).'<br><br>');
                $attachment_id = strstr($data['message'], ' ', true);// attachment id should be the first thing in the post
                // attachment id should be a number
                    // can we get the attachment from the db?
                    $attachment_src = get_forum_attachement_thumb($attachment_id);
                        $return_array[$key]['image_src'] = $attachment_src;
                        // remove attachment id from message
                        $pos = strpos($data['message'], $attachment_id);
                        if ($pos !== false) {
                            $data['message'] = substr_replace($data['message'], '', $pos, strlen($attachment_id));
                        $return_array[$key]['title'] = $data['title'];
                        $return_array[$key]['message'] = $data['message'];
                        $return_array[$key]['username'] = $data['username'];
                        $return_array[$key]['link'] = '/community/threads/'.$data['thread_id'].'/';
                        $return_array[$key]['post_date'] = $data['post_date'];
                    }// if attachment src                 
                }// if is numeric
            }//while data
            return $return_array;
        }// else num rows
    }// function get_featured_content()
    function stripBBCode($text_to_search) {
        $pattern = '|[[\/\!]*?[^\[\]]*?]|si';
        $replace = '';
        return preg_replace($pattern, $replace, $text_to_search);
    }// function stripBBCode($text_to_search)
    function get_forum_attachement_thumb($attachment_id){
        $attachment_id = mysql_real_escape_string($attachment_id);
        $query = "SELECT xf_attachment_data.data_id, xf_attachment_data.file_hash
                        FROM xf_attachment, xf_attachment_data
                        WHERE (xf_attachment.attachment_id = $attachment_id) AND (xf_attachment.data_id = xf_attachment_data.data_id)
                        LIMIT 1";
        $result = mysql_query($query);
        if(mysql_num_rows($result) <= 0)
            //echo mysql_errno() . ": " . mysql_error(). "\n";
            //echo $query;
            return false;
            $data = mysql_fetch_array($result);
            //get folder number (new folder every 1000 images)
            $folder = floor($data['data_id'] / 1000);
            $return_src = 'http://dev.altgg.dev/community/data/attachments/'.$folder.'/'.$data['data_id'].'-'.$data['file_hash'].'.jpg';
            return $return_src;
        }// else num rows
    }// get_forum_attachement_thumb($attachment_id)