lundi 7 novembre 2011

Restore Google Reader Sharing list with PHP

As Google removed the capability to share news through RSS and allow only G+ method, this is l4kul1n method to recover an RSS flux as previously:
  1. Open a blog using or wordpress
  2. In Parameters configures a secret email for mail2web service
  3. On your own server download
  4. Create a file called read.php containing:

function get_html_content($url, $referer='')

    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_TIMEOUT, 20);
    curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20071127 Firefox/');  
    curl_setopt ($ch, CURLOPT_REFERER, $referer);
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);

    $content = "";
    $content = curl_exec ($ch);
    curl_close ($ch);

    $content = preg_replace("/\n/", " ", $content);
    $content = preg_replace("/\s+/", " ", $content);

    return $content;
require_once 'Readability.php';

header('Content-Type: text/html; charset=utf-8');

$url = $_GET["url"];
$html = get_html_content($url);

if (function_exists('tidy_parse_string')) {
    $tidy = tidy_parse_string($html, array(), 'UTF8');
    $html = $tidy->value;

$readability = new Readability($html, $url);

$readability->debug = false;

$readability->convertLinksToFootnotes = true;

// process it
$result = $readability->init();

if ($result) {
    echo "

    echo $readability->getTitle()->textContent, "\n\n";

    echo "

    $content = $readability->getContent()->innerHTML;

    // if we've got Tidy, let's clean it up for output
    if (function_exists('tidy_parse_string')) {
        $tidy = tidy_parse_string($content,
            array('indent'=>true, 'show-body-only'=>true),
        $content = $tidy->value;
    $content .= "
    echo $content;
} else {
    echo 'Looks like we couldn\'t find the content.';


" />

Now create another file called email.php:

function sendHTMLemail($HTML,$from,$to,$subject)
$headers ='From: "nom"<'.$from.'>'."\n";
     $headers .='Reply-To: '.$from."\n";
     $headers .='Content-Type: text/html; charset="utf-8"'."\n";
     $headers .='Content-Transfer-Encoding: 8bit';

     $message =$HTML;

     if(mail($to, $subject, $message, $headers))
          echo 'Le message a été envoyé';
          echo 'Le message n\'a pu être envoyé';

//change this to secret blogger email2web  email.
    $to = "";
    $from = "";
    $subject = utf8_decode(stripslashes($_POST["titre"]));

    //begin of HTML message
    $message = "".stripslashes($_POST["article"])."";
   //end of message


Now in Google Reader Parameters, in SendTo parameter, add a customized one with:${url}&titre=${title}

when you'll send to this new service, then submit a clen version of article you selected will be put on the blog and its RSS flux will be updated. Use this RSS  instead on the google reader Shared RSS