Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as PHP by Ivan ( 15 years ago )
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);


/**
 * PHP Readability
 *
 * @author mingcheng<i.feelinglucky#gmail.com>
 * @date   2011-02-17
 * @link   http://www.gracecode.com/
 */

require 'config.inc.php';
require 'common.inc.php';
require 'lib/Readability.inc.php';

$request_url = getRequestParam("url",  "");
$output_type = strtolower(getRequestParam("type", "html"));
$content = "<html><title>Blanc Content</title>Blanc Content<html>";

if (!preg_match('/^http:///i', $request_url) ||
    !filter_var($request_url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)) {
    include 'template/index.html';
    exit;
}

$request_url_hash = md5($request_url);
$request_url_cache_file = sprintf(DIR_CACHE."/%s.url", $request_url_hash);

if (file_exists($request_url_cache_file) && 
        (time() - filemtime($request_url_cache_file) < CACHE_TIME)) {

    $source = file_get_contents&#40;$request_url_cache_file&#41;;
} else {

    $handle = curl_init();
    curl_setopt_array($handle, array(
     CURLOPT_USERAGENT => USER_AGENT,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HEADER  => false,
        CURLOPT_HTTPGET => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_URL => $request_url
    ));

    $source = curl_exec&#40;$handle&#41;;
    curl_close($handle);

    // Write request data into cache file.
    file_put_contents($request_url_cache_file, $source);
}

//if (!$charset = mb_detect_encoding($source)) {
//}
preg_match("/charset=([w|-]+);?/", $source, $match);
$charset = isset($match[1]) ? $match[1] : 'utf-8';

$Readability = new Readability($source, $charset);
$Data = $Readability->getContent();

switch($output_type) {
    case 'json':
        header("Content-type: text/json;charset=utf-8");
        $Data['url'] = $request_url;
        echo json_encode($Data);
        break;

    case 'pdf':
        include("mpdf/mpdf.php");

        $mpdf = new mPDF('utf-8', 'A4', '8', '', 10, 10, 7, 7, 10, 10); //задаем формат, отступы и.т.д.
        //$mpdf->StartProgressBarOutput(2);
        $mpdf->charset_in = $charset; //не забываем про русский
        $mpdf->SetAutoFont();
        //$stylesheet = file_get_contents&#40;'style.css'&#41;; //подключаем css
        $mpdf->setBasePath($request_url);
        $mpdf->showImageErrors = true;
        //$mpdf->WriteHTML($stylesheet, 1);
        $mpdf->SetDisplayMode('fullpage');
        //$mpdf->list_indent_first_level = 0; 
        //$mpdf->WriteHTML($html, 2); //формируем pdf
        $mpdf->WriteHTML($content);
        $mpdf->Output('mpdf.pdf', 'I');
    break;

    case 'html': default:
        header("Content-type: text/html;charset=utf-8");

        $title   = $Data['title'];
        $content = $Data['content'];
        include 'template/reader.html';
    break;
}

?>

 

Revise this Paste

Parent: 34734
Children: 34737
Your Name: Code Language: