fetching rss feed, mktime problem (wordpress plugin)

Posted by krike on Stack Overflow See other posts from Stack Overflow or by krike
Published on 2010-03-28T07:34:11Z Indexed on 2010/03/28 7:43 UTC
Read the original article Hit count: 258

Filed under:
|
|

sorry for the weird question but actually I'm not sure how to ask this.

the code works fine but the problem is the following. I fetch items from feeds and compare them to a specific date which is stored into the database as an option. I see if the fetched item is more recent or not and if it is I create a new pending post.

however there is one item that just keeps being added because there is something wrong with the date and I don't understand what is wrong because all other items (before and after) are blocked once they are being added as post (so when they are not recent anymore compared with the date I store as an option)

I then echo'ed that line and this is the result:

yes it exist! 27-03-2010-04-03
Free Exclusive Vector Icon Pack: Web User Interface 29-01-2010-03-01 if(1330732800 < 1335830400) 01 05 2012

the first line is to see if the option still exist and what data was stored in it the second is the actual items that's causing all the problem, it's initial date is less recent then the date but still passes as more recent....

this is the code I use, any help would be great:

if(!get_option('feed_last_date')):
            echo "nope doesn't exist, but were creating one";
            $time = time()-60*60*24*30*3;
            add_option("feed_last_date", date('d-m-Y-h-m', $time));
        else:
            echo "yes it exist! ".get_option('feed_last_date');
        endif;

        //Create new instance of simple pie and pass in feed link
        $feed = new SimplePie($feeds);

        //Call function handle_content_type()
        $feed->handle_content_type();


        $last_date = explode("-", get_option('feed_last_date'));
        $day = $last_date[0];
        $month = $last_date[1];
        $year = $last_date[2];
        $hour = $last_date[3];
        $minute = $last_date[4];
        $last_date = mktime(0,0,0, $day, $month, $year);

        //4 - Loop through received items
        foreach($feed->get_items(0, 500) as $item) :
            $feed_date = explode("-", $item->get_date('d-m-Y-h-m'));

            $day = $feed_date[0];
            $month = $feed_date[1];
            $year = $feed_date[2];
            $hour = $feed_date[3];
            $minute = $feed_date[4];
            $feed_date = mktime(0,0,0,$day, $month, $year);

            if($last_date < $feed_date):
                echo $item->get_title()." ". $item->get_date('d-m-Y-h-m') ." if(".$last_date." < ".$feed_date.") <b>".date("d m Y", $feed_date)."</b><br />";
                //if datum is newer then stored in database, then create new post
                $description = "<h3>download the resource</h3><p><a href='".$item->get_permalink()."' target='_blank'>".$item->get_permalink()."</a></p><h3>Resource description</h3><p>".$item->get_description()."</p>";

                $new_post = array(
                    'post_title' => $item->get_title(),
                    'post_content' => $description,
                    'post_status' => 'pending',
                    'post_date' => date('Y-m-d H:i:s'),
                    'post_author' => $user_ID,
                    'post_type' => 'post',
                    'post_category' => array(0)
                );
                $post_id = wp_insert_post($new_post);

            endif;
        endforeach;
        update_option("feed_last_date", date('d-m-Y-h-m', time()));

© Stack Overflow or respective owner

Related posts about Wordpress

Related posts about feed