Installing cURL in rss.php page ...or where do I install it?

Discussion in 'PHP' started by wfalexander, Aug 14, 2008.

  1. #1
    Hello.
    Does anyone know where to install Godaddys cURL code in the rss.php file to allow my website to receive the rss feeds?
    I am hosting with Godaddy (yuk i know). Their tech support told me I need cURL installed to connect to their proxy (Godaddy uses proxys on shared servers) and he sent me this code:



    <?

    $URL="https://www.paypal.com";
    if (isset($_GET["site"])) { $URL = $_GET["site"]; }
    $ch = curl_init();
    echo "URL = $URL <br>n";
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
    curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
    curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt ($ch, CURLOPT_URL, $URL);
    curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
    $result = curl_exec ($ch);
    echo "<hr><br>n";
    echo 'Errors: ' . curl_errno($ch) . ' ' . curl_error($ch) . '<br><br>';
    echo "<hr><br>n";
    curl_close ($ch);
    print "result - $result";
    echo "<hr><br>n";

    ?>

    Here is a copy of my rss.php page:

    <?php

    if(!class_exists('rss_parser')) {

    class rss_parser {
    var $update_interval = 1440;
    /* How often to fetch the rss file (minutes).
    A cached version will be used between updates */

    var $data_directory = "includes/rss-cache";
    /* Where to store the rss data from the feeds
    Note: an absolute path is better than a relative path here
    unless you plan on keeping the script to display the feeds
    in the same folder as this file and the feeds. */



    /* NO NEED TO EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING */


    var $rss_url;
    var $num_to_show;
    var $offset; //added in version 0.4.3
    var $do_update;
    var $tags = array();
    var $content;
    var $rss = array();
    var $isempty = false;

    var $feed_title;
    var $feed_link;
    var $feed_description;

    var $my_html;

    function rss_parser($url, $numtoshow = 10, $html = "", $update = FALSE, $offset = 1)
    {
    $this->rss_url = $url;
    $this->num_to_show = $numtoshow;
    $this->do_update = $update;
    $this->my_html = preg_replace("/(#{.*?):(.*?})/", "\\1__\\2", $html); //xx:xx tag workaround
    $this->offset = --$offset;

    $this->content = $this->fetch_feed();
    $this->parse_feed();
    $this->show();
    }


    /* string */
    function fetch_feed()
    {
    $create = 0;
    $update = 0;
    $rss_data = "";
    $url_parts = parse_url($this->rss_url);

    $filename = $url_parts['host'] . str_replace("/", ",", $url_parts['path']) . "_" . @$url_parts['query'];
    if(file_exists($this->data_directory . "/$filename")) {
    $last = filemtime($this->data_directory . "/$filename");
    if(time() - $last > $this->update_interval * 60 || $this->update_interval == 0) {
    $update = 1;
    }
    } else {
    $create = 1;
    }

    if($create == 1 || ($this->do_update == TRUE && $update == 1)) {
    $fp = @fsockopen($url_parts['host'], 80, $errno, $errstr, 5);
    if (!$fp) {
    echo "Couldn't open rss feed {$this->feed_url} in {$_SERVER['PHP_SELF']}<br>\n";
    return;
    }

    fputs($fp, "GET " . $url_parts['path'] . "?" . @$url_parts['query'] . " HTTP/1.0\r\n"
    ."Host: " . $url_parts['host'] . "\r\n"
    ."User-Agent: Drew's RSS Reader 0.1\r\n"
    ."Connection: Close\r\n\r\n");

    while(!feof($fp)) {
    $rss_data .= @fgets($fp, 1024);
    }

    list(, $rss_data) = explode("\r\n\r\n", $rss_data, 2);

    $output = @fopen($this->data_directory . "/$filename", "w+");
    if(!$output) {
    return $rss_data;
    } else {
    flock($output, LOCK_EX);
    fputs($output, $rss_data);
    flock($output, LOCK_UN);
    fclose($output);
    }
    } //update

    return file_get_contents($this->data_directory . "/$filename");
    }

    /* void */
    function parse_feed()
    {
    preg_match("/<title>(.*?)<\/title>/", $this->content, $title);
    $this->feed_title = @$title[1];

    preg_match("/<link>(.*?)<\/link>/", $this->content, $link);
    $this->feed_link = @$link[1];

    preg_match("/<description>(.*?)<\/description>/", $this->content, $description);
    $this->feed_description = @$description[1];

    preg_match_all("/<item[^>]*>(.*?)<\/item>/s", $this->content, $items);
    if (sizeof($items[0]) == 0) {
    // echo "No item elements found in rss feed. $keyword_feed<br>\n";
    $this->isempty = true;
    }

    for($i = 0; $i < sizeof($items[0]); ++$i) {
    preg_match_all("/(?:<([\w:]*)[^>]*>\s*(?:<!\[CDATA\[)?(.*?)(?:]]>)?\s*<\/\\1>)+?/si", preg_replace("/<item[^>]*>/", "", $items[0][$i]), $elements);
    for($j = 0; $j < sizeof($elements[0]); ++$j) {
    $elements[1][$j] = str_replace(":", "__", $elements[1][$j]); //regex fix for items with : like dc:date
    $this->rss[$i][$elements[1][$j]] = trim(html_entity_decode($elements[2][$j]));
    }
    }
    }


    /* void */
    function show()
    {
    if($this->my_html == "") {
    $this->show_html();
    } else {
    $this->show_user_html();
    }
    }

    function show_html()
    {
    $show = (sizeof($this->rss) > $this->num_to_show ? $this->num_to_show : sizeof($this->rss));
    for($i = $this->offset; $i < $this->offset + $show; ++$i) {
    echo "- <a href=\"{$this->rss[$i]['link']}\" target=\"_new\">{$this->rss[$i]['title']}</a><br>\n";
    }
    }

    function show_user_html()
    {
    $show = (sizeof($this->rss) > $this->num_to_show + $this->offset ? $this->num_to_show : sizeof($this->rss));
    $show = ($this->offset + $this->num_to_show > sizeof($this->rss) ? sizeof($this->rss) - $this->offset : $this->num_to_show);
    for($i = $this->offset; $i < $this->offset + $show; ++$i) {
    extract($this->rss[$i]);
    $item = preg_replace("/#\{([^}]+)}/e", "$\\1", $this->my_html);
    echo $item;
    }
    }

    } // end class

    }

    global $keyword_feed;



    //set our feeds
    // Replace '+' with spaces for urlencode to replace
    $keyword_feed = str_replace ('+', ' ', $keyword_feed);
    $feeds = array(
    "http://news.google.com/news?q=".urlencode($keyword_feed)."&output=rss",
    "http://news.search.yahoo.com/news/rss?p=".urlencode($keyword_feed),
    "http://news.google.com/news?q=".urlencode($keyword_feed)."&output=rss",
    "http://news.search.yahoo.com/news/rss?p=".urlencode($keyword_feed),
    "http://www.newsvine.com/_feeds/rss2/tag?id=".urlencode($keyword_feed),
    "http://news.google.com/news?q=".urlencode($keyword_feed)."&output=rss",
    "http://news.search.yahoo.com/news/rss?p=".urlencode($keyword_feed)
    );

    //pick a random feed to display
    $randomurl = mt_rand(0, count($feeds)-1);

    $url = $feeds[$randomurl];

    //define layout for rss item display
    $html = " <h3>#{title}</h3>\n";
    $html .= " <p>#{description}</p>\n";
    $html .= " <a href='#{link}' target='_new' rel='nofollow'>Read more...</a><br><br>\n";
    $html .= " <hr size=1>\n";

    //check url of feed we're trying to display
    //echo "News provided by: ".$url."<br><br>";

    $rss = new rss_parser($url, $_numResults, $html, 1); //Parse and Display
    if ($rss->isempty == true) {
    $randomurl = mt_rand(0, count($feeds)-1);
    $url = $feeds[$randomurl];
    $rss = new rss_parser($url, $_numResults, $html, 1);
    }
    if ($rss->isempty == true) {
    $randomurl = mt_rand(0, count($feeds)-1);
    $url = $feeds[$randomurl];
    $rss = new rss_parser($url, $_numResults, $html, 1);
    }
    if ($rss->isempty == true) {
    $randomurl = mt_rand(0, count($feeds)-1);
    $url = $feeds[$randomurl];
    $rss = new rss_parser($url, $_numResults, $html, 1);
    }

    ?>



    I'm not sure if the code would go into this page ( i assume it does because the links to the feeds are here).
    Thank you for any help you can offer. I am so frustrated with the "tech" people at Godaddy it seems they don't know how to implement the code or where.....

    Thanks again,
    William

    P.S. I will pay for help P.M if interested.
     
    wfalexander, Aug 14, 2008 IP
  2. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    cURL needs to be compiled into php. the code he gave you just uses curl.
     
    matthewrobertbell, Aug 15, 2008 IP