WordPress.org

Forums

Twitter Feed not working (1 post)

  1. zockey
    Member
    Posted 1 year ago #

    I have problem with Twitter Feed because it's not working. There is a code which shows Twitter Feeds:

    function grey_twitter_timeline( $id=NULL, $nr=5 ) {
        $feed = "http://twitter.com/statuses/public_timeline.rss";
        if($id) $feed = str_replace( "public_timeline", "user_timeline/".$id, $feed );
    
        $ch = curl_init($feed);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch,CURLOPT_HEADER, 0);
        curl_setopt($ch,CURLOPT_USERAGENT,"GREY");
        curl_setopt($ch,CURLOPT_TIMEOUT,10);
        $data = curl_exec($ch);
        if (curl_errno($ch) !== 0 || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {
            $data === false;
        }
        curl_close($ch);
    
        $xml = new SimpleXmlElement($data, LIBXML_NOCDATA);
        if(!$xml->error) {
            $i = 0;
            $return = "<ul class='twitter_list'>";
            foreach( $xml->channel->item as $row ) {
                if( $i<$nr ) {
                    (isset($id)) ? $title = preg_replace( "/^$id: /",'', $row->title) : $title = $row->title;
    
                    $title = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $title);
                    $title = preg_replace("/@(\w+)/", '<a href="http://twitter.com/$1">@$1</a>', $title);
                    $title = preg_replace("/#(\w+)/", '<a href="http://twitter.com/#search?q=$1">#$1</a>', $title);
    
                    $return .= "
    <li>". $title ."</li>
    ";
                }
    
                $i++;
            }
    
            update_option('grey_twitter_timeline', $return);
            return $return . "";
        } else {
            return get_option('grey_twitter_timeline');
        }
    }
    
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic