aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/functions.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/functions.php')
-rwxr-xr-xinc/functions.php101
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
3function 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") 6function 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
12function 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 21function 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
29function get_external_file($url, $timeout) { 42function 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
100function 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
131function 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