aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xinc/functions.php31
-rwxr-xr-xindex.php27
2 files changed, 35 insertions, 23 deletions
diff --git a/inc/functions.php b/inc/functions.php
index 37a56038..0b9eb936 100755
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -109,4 +109,35 @@ function get_external_file($url, $timeout)
109 else { 109 else {
110 return FALSE; 110 return FALSE;
111 } 111 }
112}
113
114function prepare_url($url)
115{
116 $parametres = array();
117 $url = html_entity_decode(trim($url));
118
119 // We remove the annoying parameters added by FeedBurner and GoogleFeedProxy (?utm_source=...)
120 // from shaarli, by sebsauvage
121 $i=strpos($url,'&utm_source='); if ($i!==false) $url=substr($url,0,$i);
122 $i=strpos($url,'?utm_source='); if ($i!==false) $url=substr($url,0,$i);
123 $i=strpos($url,'#xtor=RSS-'); if ($i!==false) $url=substr($url,0,$i);
124
125 $title = $url;
126 if (!preg_match('!^https?://!i', $url))
127 $url = 'http://' . $url;
128
129 $html = Encoding::toUTF8(get_external_file($url,15));
130 if (isset($html) and strlen($html) > 0)
131 {
132 $r = new Readability($html, $url);
133 if($r->init())
134 {
135 $title = $r->articleTitle->innerHTML;
136 }
137 }
138
139 $parametres['title'] = $title;
140 $parametres['content'] = $r->articleContent->innerHTML;
141
142 return $parametres;
112} \ No newline at end of file 143} \ No newline at end of file
diff --git a/index.php b/index.php
index d40a6c95..d56c1941 100755
--- a/index.php
+++ b/index.php
@@ -14,41 +14,22 @@ $db = new db(DB_PATH);
14$action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : ''; 14$action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : '';
15$view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : ''; 15$view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : '';
16$id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : ''; 16$id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : '';
17$url = (isset ($_GET['url'])) ? $_GET['url'] : '';
17 18
18switch ($action) 19switch ($action)
19{ 20{
20 case 'add': 21 case 'add':
21 $url = (isset ($_GET['url'])) ? $_GET['url'] : ''; 22
22 if ($url == '') 23 if ($url == '')
23 continue; 24 continue;
24 25
25 $url = html_entity_decode(trim($url)); 26 $parametres_url = prepare_url($url);
26
27 // We remove the annoying parameters added by FeedBurner and GoogleFeedProxy (?utm_source=...)
28 // from shaarli, by sebsauvage
29 $i=strpos($url,'&utm_source='); if ($i!==false) $url=substr($url,0,$i);
30 $i=strpos($url,'?utm_source='); if ($i!==false) $url=substr($url,0,$i);
31 $i=strpos($url,'#xtor=RSS-'); if ($i!==false) $url=substr($url,0,$i);
32
33 $title = $url;
34 if (!preg_match('!^https?://!i', $url))
35 $url = 'http://' . $url;
36
37 $html = Encoding::toUTF8(get_external_file($url,15));
38 if (isset($html) and strlen($html) > 0)
39 {
40 $r = new Readability($html, $url);
41 if($r->init())
42 {
43 $title = $r->articleTitle->innerHTML;
44 }
45 }
46 27
47 try 28 try
48 { 29 {
49 # insert query 30 # insert query
50 $query = $db->getHandle()->prepare('INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)'); 31 $query = $db->getHandle()->prepare('INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)');
51 $query->execute(array($url, $title, $r->articleContent->innerHTML)); 32 $query->execute(array($url, $parametres_url['title'], $parametres_url['content']));
52 } 33 }
53 catch (Exception $e) 34 catch (Exception $e)
54 { 35 {