diff options
author | nicosomb <nicolas@loeuillet.org> | 2013-04-12 13:13:21 +0200 |
---|---|---|
committer | nicosomb <nicolas@loeuillet.org> | 2013-04-12 13:13:21 +0200 |
commit | c8bbe19b3fd2ba268c98561690de37fe599ff055 (patch) | |
tree | cb6d9c7c6c1bc973f3569b85a6694cb4d5059d10 /inc/functions.php | |
parent | 67e7910439d364f1f7a4dac1d233a7c1055fb933 (diff) | |
download | wallabag-c8bbe19b3fd2ba268c98561690de37fe599ff055.tar.gz wallabag-c8bbe19b3fd2ba268c98561690de37fe599ff055.tar.zst wallabag-c8bbe19b3fd2ba268c98561690de37fe599ff055.zip |
possibilité de mettre en fav ou en archive un article depuis la page article
Diffstat (limited to 'inc/functions.php')
-rwxr-xr-x | inc/functions.php | 101 |
1 files changed, 31 insertions, 70 deletions
diff --git a/inc/functions.php b/inc/functions.php index 6fa5a17a..37a56038 100755 --- a/inc/functions.php +++ b/inc/functions.php | |||
@@ -1,32 +1,46 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | function url() { | 3 | /** |
4 | $protocol = "http"; | 4 | * Permet de générer l'URL de poche pour le bookmarklet |
5 | if(isset($_SERVER['HTTPS'])) | 5 | */ |
6 | if($_SERVER['HTTPS'] != "off") | 6 | function url() |
7 | $protocol = "https"; | 7 | { |
8 | $protocol = "http"; | ||
9 | if(isset($_SERVER['HTTPS'])) { | ||
10 | if($_SERVER['HTTPS'] != "off") { | ||
11 | $protocol = "https"; | ||
12 | } | ||
13 | } | ||
8 | 14 | ||
9 | return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | 15 | return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
10 | } | 16 | } |
11 | 17 | ||
12 | function generate_page($url,$title,$content) { | 18 | /** |
13 | raintpl::$tpl_dir = './tpl/'; // template directory | 19 | * Génération de la page "vue d'un article" |
14 | raintpl::$cache_dir = "./cache/"; // cache directory | 20 | */ |
15 | raintpl::$base_url = url(); // base URL of blog | 21 | function generate_page($entry) |
22 | { | ||
23 | raintpl::$tpl_dir = './tpl/'; | ||
24 | raintpl::$cache_dir = "./cache/"; | ||
25 | raintpl::$base_url = url(); | ||
16 | raintpl::configure( 'path_replace', false ); | 26 | raintpl::configure( 'path_replace', false ); |
17 | raintpl::configure('debug', false); | 27 | raintpl::configure('debug', false); |
18 | 28 | ||
19 | $tpl = new raintpl(); //include Rain TPL | 29 | $tpl = new raintpl(); |
20 | 30 | ||
21 | $tpl->assign( "url", $url); | 31 | $tpl->assign("id", $entry['id']); |
22 | $tpl->assign( "title", $title); | 32 | $tpl->assign("url", $entry['url']); |
23 | $tpl->assign( "content", $content); | 33 | $tpl->assign("title", $entry['title']); |
34 | $tpl->assign("content", $entry['content']); | ||
35 | $tpl->assign("is_fav", $entry['is_fav']); | ||
36 | $tpl->assign("is_read", $entry['is_read']); | ||
24 | 37 | ||
25 | $tpl->draw( "index"); // draw the template | 38 | $tpl->draw( "index"); |
26 | } | 39 | } |
27 | 40 | ||
28 | // function define to retrieve url content | 41 | // function define to retrieve url content |
29 | function get_external_file($url, $timeout) { | 42 | function get_external_file($url, $timeout) |
43 | { | ||
30 | // spoofing FireFox 18.0 | 44 | // spoofing FireFox 18.0 |
31 | $useragent="Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0"; | 45 | $useragent="Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0"; |
32 | 46 | ||
@@ -95,57 +109,4 @@ function get_external_file($url, $timeout) { | |||
95 | else { | 109 | else { |
96 | return FALSE; | 110 | return FALSE; |
97 | } | 111 | } |
98 | } | 112 | } \ No newline at end of file |
99 | |||
100 | function rel2abs($rel, $base) | ||
101 | { | ||
102 | /* return if already absolute URL */ | ||
103 | if (parse_url($rel, PHP_URL_SCHEME) != '') return $rel; | ||
104 | |||
105 | /* queries and anchors */ | ||
106 | if ($rel[0]=='#' || $rel[0]=='?') return $base.$rel; | ||
107 | |||
108 | /* parse base URL and convert to local variables: | ||
109 | $scheme, $host, $path */ | ||
110 | extract(parse_url($base)); | ||
111 | |||
112 | /* remove non-directory element from path */ | ||
113 | $path = preg_replace('#/[^/]*$#', '', $path); | ||
114 | |||
115 | /* destroy path if relative url points to root */ | ||
116 | if ($rel[0] == '/') $path = ''; | ||
117 | |||
118 | /* dirty absolute URL */ | ||
119 | $abs = "$host$path/$rel"; | ||
120 | |||
121 | /* replace '//' or '/./' or '/foo/../' with '/' */ | ||
122 | $re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#'); | ||
123 | for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {} | ||
124 | |||
125 | /* absolute URL is ready! */ | ||
126 | return $scheme.'://'.$abs; | ||
127 | } | ||
128 | |||
129 | // $str=preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\s|\+)[^"]*"))#','$1="http://wintermute.com.au/$2$3',$str); | ||
130 | |||
131 | function absolutes_links($data, $base) { | ||
132 | // cherche les balises 'a' qui contiennent un href | ||
133 | $matches = array(); | ||
134 | preg_match_all('#(href|src)="([^:"]*)("|(?:(?:%20|\s|\+)[^"]*"))#Si', $data, $matches, PREG_SET_ORDER); | ||
135 | |||
136 | // ne conserve que les liens ne commençant pas par un protocole « protocole:// » ni par une ancre « # » | ||
137 | foreach($matches as $i => $link) { | ||
138 | $link[1] = trim($link[1]); | ||
139 | |||
140 | if (!preg_match('#^(([a-z]+://)|(\#))#', $link[1]) ) { | ||
141 | |||
142 | $absolutePath=rel2abs($link[2],$base); | ||
143 | |||
144 | $data = str_replace($matches[$i][2], $absolutePath, $data); | ||
145 | } | ||
146 | |||
147 | } | ||
148 | return $data; | ||
149 | } | ||
150 | |||
151 | ?> \ No newline at end of file | ||