From 246195341cd40fd46b8cfe023b9874f94d6630ce Mon Sep 17 00:00:00 2001 From: nicosomb Date: Thu, 4 Apr 2013 21:09:34 +0200 Subject: =?UTF-8?q?r=C3=A9cup=C3=A9ration=20du=20titre=20de=20la=20page=20?= =?UTF-8?q?poch=C3=A9e=20et=20rangement=20de=20fonctions=20dans=20un=20nou?= =?UTF-8?q?veau=20fichier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'index.php') diff --git a/index.php b/index.php index a27f1993..4fdc5736 100755 --- a/index.php +++ b/index.php @@ -22,6 +22,9 @@ * afficher liens mis en favoris et archivés * tri des liens */ +require_once dirname(__FILE__).'/inc/Readability.php'; +require_once dirname(__FILE__).'/inc/Encoding.php'; +include dirname(__FILE__).'/inc/functions.php'; try { @@ -39,8 +42,21 @@ $id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : ''; switch ($action) { case 'add': - $url = (isset ($_GET['url'])) ? htmlspecialchars($_GET['url']) : ''; + $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; + $url = html_entity_decode(trim($url)); $title = $url; + // if url use https protocol change it to http + if (!preg_match('!^https?://!i', $url)) $url = 'http://'.$url; + // convert page to utf-8 + $html = Encoding::toUTF8(get_external_file($url,15)); + if(isset($html) and strlen($html) > 0) { + // send result to readability library + $r = new Readability($html, $url); + if($r->init()) { + $title = $r->articleTitle->innerHTML; + } + } + $query = $db_handle->prepare('INSERT INTO entries ( url, title ) VALUES (?, ?)'); $query->execute(array($url, $title)); break; @@ -53,6 +69,8 @@ switch ($action) { $params_action = array($id); break; case 'delete': + $sql_action = "DELETE FROM entries WHERE id=?"; + $params_action = array($id); break; default: break; @@ -98,16 +116,6 @@ catch (Exception $e) die('query error : '.$e->getMessage()); } -function url() { - $protocol = "http"; - if(isset($_SERVER['HTTPS'])) { - if($_SERVER['HTTPS'] != "off") { - $protocol = "https"; - } - } - - return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; -} ?> @@ -137,13 +145,13 @@ function url() { \ No newline at end of file -- cgit v1.2.3