';var_dump($a);echo '';if ($stop){exit();}} function BodyClasses($add=''){$regex='#(msie)[/ ]([0-9])+|(firefox)/([0-9])+|(chrome)/([0-9])+|(opera)/([0-9]+)|(safari)/([0-9]+)|(android)|(iphone)|(ipad)|(blackberry)|(Windows Phone)|(symbian)|(mobile)|(bada])#i';@preg_match($regex,$_SERVER['HTTP_USER_AGENT'],$resultat);return ' class="'.$add.' '.@preg_replace('#([a-zA-Z ]+)[ /]([0-9]+)#','$1 $1$2',$resultat[0]).' '.basename($_SERVER['PHP_SELF'],'.php').'" ';} function title2filename($chaine){$a=array(' ',':','|','#','/','\\','$','*','?','&','<','>');return substr(stripAccents(str_replace($a,'_',$chaine)),0,30);} function stripAccents($string){ $a=explode(' ','à á â ã ä ç è é ê ë ì í î ï ñ ò ó ô õ ö ù ú û ü ý ÿ À Á Â Ã Ä Ç È É Ê Ë Ì Í Î Ï Ñ Ò Ó Ô Õ Ö Ù Ú Û Ü Ý');$b=explode(' ','a a a a a c e e e e i i i i n o o o o o u u u u y y A A A A A C E E E E I I I I N O O O O O U U U U Y');return str_replace($a,$b,$string);} function returncurrenturl(){$domaine=dirname($_SERVER['SERVER_PROTOCOL']) . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ;$domaine=explode('?',$domaine);return $domaine[0];} function store($file,$datas){file_put_contents($file,serialize($datas));} function unstore($file){ return unserialize(file_get_contents($file));} function search($public='public',$tag=false){ global $GLOBAL; //$GLOBAL['tag_array']; if (!$tag){return scandir($GLOBAL[$public.'_data_folder'] );} else{ foreach ($GLOBAL['tag_array'][$public] as $key=>$val){ if (stripos($val,$tag)!==false){$result[]=$key;} } if (!empty($result)){return $result;}else{return array();} } } function array2feed($array=null){ // more infos on this function at https://github.com/broncowdd/feed2array if (!$array){return false;} if (empty($array['infos']['type'])){$array['infos']['type']='rss';}else{$array['infos']['type']=strtolower($array['infos']['type']);} if (empty($array['infos']['description'])){$array['infos']['description']='';} $r="\n";$t="\t"; $tpl=array('rss'=>array(),'atom'=>array()); $tpl['rss']['header']=''.$r.''.$r.$t.''.$r; $tpl['atom']['header']=''.$r; $tpl['rss']['footer']=$t.''.$r; $tpl['atom']['footer']=''.$r; $tpl['rss']['content-type']='Content-Type: application/rss+xml'; $tpl['atom']['content-type']='Content-Type: application/atom+xml;charset=utf-8'; header($tpl[$array['infos']['type']]['content-type']); $feed=$tpl[$array['infos']['type']]['header']; //create the feed's info content foreach($array['infos'] as $key=>$value){ if ($array['infos']['type']=='atom'){ // ATOM if ($key=='link'){$feed.=$t.$t.''.$r;} elseif ($key=='author'){$feed.=$t.$t.''.$value.''.$r;} elseif ($key=='licence'){$feed.=$t.$t.'<'.$key.' href="'.$value.'" rel="license"/>'.$r;} // in atom feed, licence is the link to the licence type elseif ($key!='version'&&$key!='type'){$feed.=$t.$t.'<'.$key.'>'.$value.''.$r;} }else{ // RSS if ($key!='version'&&$key!='type'){$feed.=$t.$t.'<'.$key.'>'.$value.''.$r;} } } //then the items content foreach ($array['items'] as $item){ if ($array['infos']['type']=='atom'){ $feed.=$t.$t.$t.''.$r;}else{$feed.=$t.$t.$t.''.$r;} foreach($item as $key=>$value){ if ($array['infos']['type']=='atom'){ // ATOM if ($key=='link'){$feed.=$t.$t.$t.$t.''.$r;} elseif ($key=='content'){$feed.=$t.$t.$t.$t.''.htmlspecialchars($value).''.$r;} else{$feed.=$t.$t.$t.$t.'<'.$key.'>'.$value.''.$r;} }else{ // RSS if ($key=='date'||$key=='pubDate'||$key=='title'||$key=='link'){$feed.=$t.$t.$t.$t.'<'.$key.'>'.htmlspecialchars($value).''.$r;} elseif($key=='guid'){ $feed.=$t.$t.$t.$t.''.$value.''.$r;} else{$feed.=$t.$t.$t.$t.'<'.$key.'>'.$r;} } } if ($array['infos']['type']=='atom'){ $feed.=$t.$t.$t.''.$r;}else{$feed.=$t.$t.$t.''.$r;} } $feed.=$tpl[$array['infos']['type']]['footer']; return $feed; } function tagcloud(){ global $GLOBAL; $array=array(); if (!$GLOBAL['public']){ foreach ($GLOBAL['tag_array']['private'] as $key=>$tag){ $tags=explode(' ',$tag); foreach ($tags as $t){ if (!isset($array[$t]['nb'])){$array[$t]['nb']=1;}else{$array[$t]['nb']++;} if (!isset($array[$t]['status'])){$array[$t]['status']='private';} } } } foreach ($GLOBAL['tag_array']['public'] as $key=>$tag){ $tags=explode(' ',$tag); foreach ($tags as $t){ if (!isset($array[$t]['nb'])){$array[$t]['nb']=1;}else{$array[$t]['nb']++;} if (!isset($array[$t]['status'])){$array[$t]['status']='public';} } } foreach ($array as $tag=>$val){ echo ''.$tag.' '.$val['nb'].''; } } function tag2links($tagstring){ global $GLOBAL; $array=explode(' ',$tagstring);$links=''; foreach ($array as $tag){ $links.=''.$tag.''; } return $links; } if(isset($_GET['publicget'])||isset($_GET['privateget'])){$bodyclass.=' iframe';} $bodyclass=bodyclasses($bodyclass);$target=''; /* (webpage retriever by Timo Van Neerden; http://lehollandaisvolant.net/contact December 2012) * last updated : December, 10th, 2012 * * This piece of software is under the WTF Public Licence. * Everyone is permitted to copy and distribute verbatim or modified * copies of this program, under the following terms of the WFTPL : * * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE * TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION * * 0. You just DO WHAT THE FUCK YOU WANT TO. * */ /* all the enhancements (logo, css, session lock, bookmarklet, tags, rss feed, api) are from Bronco (www.warriordudimanche.net) * and are based on the same licence ;) * thanks a lot to Timo for his great job on this app ;) */ // PHP 5.1.2 minimum required error_reporting(-1); date_default_timezone_set('UTC'); // CONFIGURABLE OPTIONS // change those directories'names for more security $GLOBAL['data_folder'] = 'mypersonaldata'; $GLOBAL['private_data_folder'] = $GLOBAL['data_folder'].'/private'; $GLOBAL['public_data_folder'] = $GLOBAL['data_folder'].'/public'; $GLOBAL['default_data_folder'] = $GLOBAL['public_data_folder'];//change to private_data_folder to make private the default status $GLOBAL['version']='2.0'; $GLOBAL['rss_title']='Respawn: le flux de la webliothèque'; $GLOBAL['rss_description']='Le respawn de warriordudimanche.net'; $GLOBAL['respawn_url']=returncurrenturl(); $GLOBAL['message'] = 'Votre webliothèque perso'; $GLOBAL['public_title'] = 'Voici la webliothèque publique de Bronco'; $bookmarklet='Bookmarklet'; $column_width='width:47%'; if ($GLOBAL['public']){$bookmarklet='';$column_width='width:97%';} if (!creer_dossier($GLOBAL['data_folder'], TRUE)) { die('Cant create '.$GLOBAL['data_folder'].' folder.'); } if (!creer_dossier($GLOBAL['data_folder'].'/zipversions', TRUE)) { die('Cant create '.$GLOBAL['data_folder'].'/zipversions'.' folder.'); } if (!creer_dossier($GLOBAL['private_data_folder'], TRUE)) { die('Cant create '.$GLOBAL['private_data_folder'].' folder.'); } if (!creer_dossier($GLOBAL['public_data_folder'], TRUE)) { die('Cant create '.$GLOBAL['public_data_folder'].' folder.'); } if (is_file($GLOBAL['data_folder'].'/tags.txt')){$GLOBAL['tag_array']=unstore($GLOBAL['data_folder'].'/tags.txt');}else{$GLOBAL['tag_array']=array('public'=>array(),'private'=>array());store($GLOBAL['data_folder'].'/tags.txt',$GLOBAL['tag_array']);} if (!isset($GLOBAL['tag_array']['public'])){$GLOBAL['tag_array']['public']=array();}; if (!isset($GLOBAL['tag_array']['private'])){$GLOBAL['tag_array']['private']=array();}; // // BEGIN SCRIPT // #TODO /* - remplacer les liens relatifs par les liens absolus (ne chercher que les liens relatifs, uri) - gestion des pages DL (classement ?) - gestion de la taille max des fichiers à télélcharger */ // init // url not yet retrieved $GLOBAL['done']['d'] = FALSE; if (!$GLOBAL['public']){ // private // Get URL to save. if (!empty($_GET['q'])) { $url = htmlspecialchars($_GET['q']); if (strpos($url, '://') === false) { $url = 'http://'.$url; } $GLOBAL['url'] = $url; $url_p = url_parts(); // retrieve the file main HTML file $GLOBAL['main_page_data'] = get_external_file($GLOBAL['url'], 6); if ($GLOBAL['main_page_data'] === FALSE) { die('error retrieving external main page'); } else { // crée le nouveau dossier basé sur le TS. $new_folder = date('Y-m-d-H-i-s'); if (!creer_dossier($GLOBAL['default_data_folder'].'/'.$new_folder) === TRUE ) { die('error creating data folder'); } else { $GLOBAL['target_folder'] = $GLOBAL['default_data_folder'].'/'.$new_folder; } /*GESTION DU PDF ICI*/ if (strtolower(substr($_GET['q'],-4))=='.pdf'){ $title=basename($_GET['q']); file_put_contents($GLOBAL['target_folder'].'/'.$title,$GLOBAL['main_page_data']); file_put_contents($GLOBAL['target_folder'].'/index.php',''); }else{ $liste_css = array(); // parse le fichier principal à la recherche de données à télécharger $files = list_retrievable_data($GLOBAL['url'], $GLOBAL['main_page_data']); // les récupère et les enregistre. //echo '
';print_r($files);die();
				foreach ($files as $i => $file) {
					if ($data = get_external_file($file['url_fichier'], 3) and ($data !== FALSE) ) {
						// CSS files need to be parsed aswell
						if ($file['type'] == 'css') {
							$liste_css[] = $file;
						}
						else {
							file_put_contents($GLOBAL['target_folder'].'/'.$file['nom_destination'], $data);
						}
					}
				}
				// remplace juste les liens  relatifs vers des liens absolus
				absolutes_links($GLOBAL['main_page_data']);

				// enregistre le fichier HTML principal
				file_put_contents($GLOBAL['target_folder'].'/'.'index.html', $GLOBAL['main_page_data']);

				// récupère le titre de la page
				// cherche le charset spécifié dans le code HTML.
				// récupère la balise méta tout entière, dans $meta
				preg_match('##Usi', $GLOBAL['main_page_data'], $meta);

				// si la balise a été trouvée, on tente d’isoler l’encodage.
				if (!empty($meta[0])) {
					// récupère juste l’encodage utilisé, dans $enc
					preg_match('#charset="?(.*)"#si', $meta[0], $enc);
					// regarde si le charset a été trouvé, sinon le fixe à UTF-8
					$html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8';
				} else { $html_charset = 'utf-8'; }
				// récupère le titre, dans le tableau $titles, rempli par preg_match()
				preg_match('#(.*)#Usi', $GLOBAL['main_page_data'], $titles);
				if (!empty($titles[1])) {
					$html_title = trim($titles[1]);
					// ré-encode le titre en UTF-8 en fonction de son encodage.
					$title = ($html_charset == 'iso-8859-1') ? utf8_encode($html_title) : $html_title;
				// si pas de titre : on utilise l’URL.
				} else {
					$title = $url;
				}


				// récupère, parse, modifie & enregistre les fichier CSS (et les fichiés liés)
				$n = 0;
				$count = count($liste_css);
				while ( $n < $count and $n <300) { // no more than 300 ext files.
					$i = $n;
					$file = $liste_css[$i];
					if ($data = get_external_file($file['url_fichier'], 3) and ($data !== FALSE) ) {
						if (preg_match('#(css|php|txt|html|xml|js)#', $file['url_fichier']) ) {
							$matches_url = array();
							preg_match_all('#url\s{0,}\(("|\')?([^\'")]{1,})(\'|")?\)#i', $data, $matches_url, PREG_SET_ORDER);
							$matches_url2 = array();
							preg_match_all("#@import\s*(?:\"([^\">]*)\"?|'([^'>]*)'?)([^;]*)(;|$)#i", $data, $matches_url2, PREG_SET_ORDER);


							$matches_url = array_merge($matches_url2, $matches_url);
					

							// pour chaque URL/URI
							foreach ($matches_url as $j => $valuej) {

								if (preg_match('#^data:#', $matches_url[$j][2])) break; // if BASE64 data, dont download.

								// get the filenam (basename)
								$nom_fichier = (preg_match('#^(ht|f)tps?://#', $matches_url[$j][2])) ? pathinfo(parse_url($matches_url[$j][2], PHP_URL_PATH), PATHINFO_BASENAME) : pathinfo($matches_url[$j][2], PATHINFO_BASENAME);

								// get the URL. For URIs, uses the GLOBALS[url] tu make the URL
								// the files in CSS are relative to the CSS !
								if (preg_match('#^https?://#', $matches_url[$j][2])) {
									$url_fichier = $matches_url[$j][2];
								}
								// abs url w/o protocole
								elseif (preg_match('#^//#', $matches_url[$j][2])) {
									$url_fichier = $url_p['s'].':'.$matches_url[$j][2];
								}
								// rel url
								elseif (preg_match('#^/#', $matches_url[$j][2])) {
									$url_fichier = $url_p['s'].'://'.$url_p['h'].$matches_url[$j][2];
								}

								else {
									$endstr = ($w = strpos($file['url_fichier'], '?')) ? $w : strlen($file['url_fichier']);
									$url_fichier = substr(substr($file['url_fichier'], 0, $endstr), 0, -strlen($file['nom_fich_origine'])).$matches_url[$j][2];
								}
								// new rand name, for local storage.
								$nouveau_nom = rand_new_name($nom_fichier);
								//echo '
'.$nouveau_nom."\n";
								$add = TRUE;

								// avoids downloading the same file twice. (yes, we re-use the same $retrievable ($files), why not ?)
								foreach ($files as $key => $item) {
									if ($item['url_fichier'] == $url_fichier) {
										$nouveau_nom = $item['nom_destination'];
										$add = FALSE;
										break;
									}
								}

								// if we do download, add it to the array.
								if ($add === TRUE) {
									$files_n = array(
										'url_origine' => $matches_url[$j][2],
										'url_fichier' => $url_fichier,
										'nom_fich_origine' => $nom_fichier,
										'nom_destination' => $nouveau_nom
										);
									$files[] = $files_n;
									$liste_css[] = $files_n;
								}

								// replace url in CSS $data
								$data = str_replace($matches_url[$j][2], $nouveau_nom, $data);
								// echo $nouveau_nom."
\n"; if (!preg_match('#(css|php|txt|html)#', $file['url_fichier']) ) { if (FALSE !== ($f = get_external_file($url_fichier, 3)) ) { file_put_contents($GLOBAL['target_folder'].'/'.$nouveau_nom, $f); } } } } // don't forget to save data file_put_contents($GLOBAL['target_folder'].'/'.$file['nom_destination'], $data); } $n++; $count = count($liste_css); } } // enregistre un fichier d’informations concernant la page (date, url, titre) $info = ''; $info .= 'URL="'.$GLOBAL['url'].'"'."\n"; $info .= 'TITLE="'.$title.'"'."\n"; $info .= 'DATE="'.time().'"'."\n"; file_put_contents($GLOBAL['target_folder'].'/'.'index.ini', $info); /*$GLOBAL['done']['d'] = 'ajout'; $GLOBAL['done']['lien'] = $GLOBAL['target_folder'].'/'; */ } }//die; // in case of delete an entry if (isset($_GET['suppr']) and $torem = $_GET['suppr'] and $torem != '') { $torem = htmlspecialchars($_GET['suppr']); if (is_dir($_GET['suppr'])){ $sousliste = scandir($_GET['suppr']); // listage des dossiers de data. $nb_sousfichier = count($sousliste); for ($j = 0 ; $j < $nb_sousfichier ; $j++) { if (!($sousliste[$j] == '..' or $sousliste[$j] == '.')) { unlink($_GET['suppr'].'/'.$sousliste[$j]); } } // then the folder itself. if (TRUE === rmdir($_GET['suppr'])) { $GLOBAL['done']['d'] = 'remove'; } } header("location: index.php"); } // to private if (isset($_GET['toprivate']) and $torem = $_GET['toprivate'] and $torem != '') { $torem = htmlspecialchars($_GET['toprivate']); if (is_dir($GLOBAL['public_data_folder'].'/'.$_GET['toprivate'])){ rename ($GLOBAL['public_data_folder'].'/'.$_GET['toprivate'],$GLOBAL['private_data_folder'].'/'.$_GET['toprivate']); header("location: index.php"); } } // to public if (isset($_GET['topublic']) and $torem = $_GET['topublic'] and $torem != '') { $torem = htmlspecialchars($_GET['topublic']); if (is_dir($GLOBAL['private_data_folder'].'/'.$_GET['topublic'])){ rename ($GLOBAL['private_data_folder'].'/'.$_GET['topublic'],$GLOBAL['public_data_folder'].'/'.$_GET['topublic']); header("location: index.php"); } } // disconnect if (isset($_GET['discotime'])){log_user('disco','');} if (isset($_GET['privateget'])&&is_dir($GLOBAL['private_data_folder'].'/'.$_GET['privateget'])){$target=$GLOBAL['private_data_folder'].'/'.$_GET['privateget'];} if (isset($_GET['zipprivate'])) { $ini_file = $GLOBAL['private_data_folder'].'/'.$_GET['zipprivate'].'/index.ini'; if(is_file($ini_file)){$info=parse_ini_file($ini_file);}else{$info['TITLE']='';} $origin_folder_path=$GLOBAL['private_data_folder'].'/'.$_GET['zipprivate']; $zip_foldername=title2filename($info['TITLE']).'-'.$_GET['zipprivate']; $zip_filename=$zip_foldername.'.zip'; $zip_completepath=$GLOBAL['data_folder'].'/zipversions/'.$zip_filename; if (is_file($zip_completepath)){header("location: $zip_completepath");exit();}// il existe déjà, on envoie if (is_dir($origin_folder_path)){// sinon on crée le zip si le dossier existe include 'zip.php'; rename ($origin_folder_path,$zip_foldername); // on le déplace pour éviter de voir la structure de dossiers apparaître dans le zip zip($zip_filename,$zip_foldername,$GLOBAL['data_folder'].'/zipversions/'); rename ($zip_foldername,$origin_folder_path); // on le remet à sa place header('location: '.$GLOBAL['data_folder'].'/zipversions/'.$zip_filename); } } if (isset($_GET['rename'])&&isset($_GET['to'])&&isset($_GET['file'])) { if (is_file($_GET['file'].'/index.ini')){ $ini=parse_ini_file($_GET['file'].'/index.ini'); $old=strip_tags(urldecode($_GET['rename'])); $new=strip_tags(urldecode($_GET['to'])); $newini='URL="'.$ini['URL'].'"'."\n".'TITLE="'.$new.'"'."\n".'DATE="'.$ini['DATE'].'"'; //$ini=str_replace('TITLE="'.$old.'"','TITLE="'.$new.'"',$ini);aff($ini); file_put_contents($_GET['file'].'/index.ini',$newini); } } if (isset($_GET['settag'])&&isset($_GET['file'])) { if (is_file($GLOBAL['data_folder'].'/tags.txt')){$GLOBAL['tag_array']=unstore($GLOBAL['data_folder'].'/tags.txt');}else{$GLOBAL['tag_array']=array();} if (isset($_GET['ispublic'])){$type='public';}else{$type='private';} $GLOBAL['tag_array'][$type][$_GET['file']]=strip_tags($_GET['settag']); store($GLOBAL['data_folder'].'/tags.txt',$GLOBAL['tag_array']); } }else{ // public get //download public zip version if (isset($_GET['zippublic'])) { $ini_file = $GLOBAL['public_data_folder'].'/'.$_GET['zippublic'].'/index.ini'; if(is_file($ini_file)){$info=parse_ini_file($ini_file);}else{$info['TITLE']='';} $origin_folder_path=$GLOBAL['public_data_folder'].'/'.$_GET['zippublic']; $zip_foldername=title2filename($info['TITLE']).'-'.$_GET['zippublic']; $zip_filename=$zip_foldername.'.zip'; $zip_completepath=$GLOBAL['data_folder'].'/zipversions/'.$zip_filename; if (is_file($zip_completepath)){header("location: $zip_completepath");exit();}// il existe déjà, on envoie if (is_dir($origin_folder_path)){// sinon on crée le zip si le dossier existe include 'zip.php'; rename ($origin_folder_path,$zip_foldername); // on le déplace pour éviter de voir la structure de dossiers apparaître dans le zip zip($zip_filename,$zip_foldername,$GLOBAL['data_folder'].'/zipversions/'); rename ($zip_foldername,$origin_folder_path); // on le remet à sa place header('location: '.$GLOBAL['data_folder'].'/zipversions/'.$zip_filename); } } if (isset($_GET['publicget'])&&is_dir($GLOBAL['public_data_folder'].'/'.$_GET['publicget'])){$target=$GLOBAL['public_data_folder'].'/'.$_GET['publicget'];} if (isset($_GET['rss'])){ $items=array_reverse(search('public',$search_tags)); $feed=array( 'infos'=>array( 'type'=>'rss', 'description'=>$GLOBAL['rss_description'], 'title'=>$GLOBAL['rss_title'], 'link'=>$GLOBAL['respawn_url'], ) ); foreach ($items as $key=>$item){ if ($item!='index.html'){ if (is_dir($GLOBAL['public_data_folder'].'/'.$item)){ if (is_file($GLOBAL['public_data_folder'].'/'.$item.'/index.ini')){ $infos=parse_ini_file($GLOBAL['public_data_folder'].'/'.$item.'/index.ini'); date_default_timezone_set('Europe/Paris'); $infos['DATE']= date("r", $infos['DATE']); if ($infos['TITLE']==''){$infos['TITLE']='Version Respawn de '.$infos['URL'];} $feed['items'][$key]=array( 'description'=>'Version Respawn de '.$infos['URL'], 'title'=>$infos['TITLE'], 'link'=>$GLOBAL['respawn_url'].'?publicget='.$item, 'guid'=>$infos['URL'], 'pubDate'=>$infos['DATE'], ); } } } } exit(array2feed($feed)); } if (isset($_GET['api'])){ $content=array(); $items=search('public',$search_tags); foreach ($items as $key=>$item){ if ($item!='index.html'){ if (is_dir($GLOBAL['public_data_folder'].'/'.$item)){ if (is_file($GLOBAL['public_data_folder'].'/'.$item.'/index.ini')){ $infos=parse_ini_file($GLOBAL['public_data_folder'].'/'.$item.'/index.ini'); date_default_timezone_set('Europe/Paris'); $infos['DATE']= date('d/m/Y', $infos['DATE']); if ($infos['TITLE']==''){$infos['TITLE']='Respawn de '.$infos['URL'];} $content[$key]=array( 'description'=>'Version Respawn de '.$infos['URL'], 'title'=>$infos['TITLE'], 'respawn_link'=>$GLOBAL['respawn_url'].'?publicget='.$item, 'original_link'=>$infos['URL'], 'date'=>$infos['DATE'], 'tags'=>$GLOBAL['tag_array']['public'][$item], ); } } } } exit(serialize($content)); } } function url_parts() { global $GLOBAL; $url_p['s'] = parse_url($GLOBAL['url'], PHP_URL_SCHEME); $url_p['s'] = (is_null($url_p['s'])) ? '' : $url_p['s']; $url_p['h'] = parse_url($GLOBAL['url'], PHP_URL_HOST); $url_p['h'] = (is_null($url_p['h'])) ? '' : $url_p['h']; $url_p['p'] = parse_url($GLOBAL['url'], PHP_URL_PORT); $url_p['p'] = (is_null($url_p['p'])) ? '' : ':'.$url_p['p']; $url_p['pat'] = parse_url($GLOBAL['url'], PHP_URL_PATH); $url_p['pat'] = (is_null($url_p['pat'])) ? '' : $url_p['pat']; $url_p['file'] = pathinfo($url_p['pat'], PATHINFO_BASENAME); return $url_p; } // // Gets external file by URL. // Make a stream context (better). // function get_external_file($url, $timeout) { $context = stream_context_create(array('http'=>array('timeout' => $timeout))); // Timeout : time until we stop waiting for the response. $data = @file_get_contents($url, false, $context, -1, 4000000); // We download at most 4 Mb from source. if (isset($data) and isset($http_response_header) and isset($http_response_header[0]) and (strpos($http_response_header[0], '200 OK') !== FALSE) ) { return $data; } else { return FALSE; } } // // CREATE FOLDER // function creer_dossier($dossier, $indexfile = FALSE) { if ( !is_dir($dossier) ) { if (mkdir($dossier, 0777, TRUE) === TRUE) { chmod($dossier, 0777); if ($indexfile == TRUE) touch($dossier.'/index.html'); // make a index.html file : avoid the possibility of listing folder's content return TRUE; } else { return FALSE; } } return TRUE; // if folder already exists } // // PARSE TAGS AND LISTE DOWNLOADABLE CONTENT IN ARRAY // Also modify html source code to replace absolutes URLs with local URIs. // function list_retrievable_data($url, &$data) { $url_p = url_parts(); $retrievable = array(); // cherche les balises 'link' qui contiennent un rel="(icon|favicon|stylesheet)" et un href="" // (on ne cherche pas uniquement le "href" sinon on se retrouve avec les flux RSS aussi) $matches = array(); preg_match_all('#<\s*link[^>]+rel=["\'][^"\']*(icon|favicon|stylesheet)[^"\']*["\'][^>]*>#Si', $data, $matches, PREG_SET_ORDER); // dans les link avec une icone, stylesheet, etc récupère l’url. foreach($matches as $i => $key) { $type = (strpos($key[1], 'stylesheet') !== FALSE) ? 'css' : 'other'; if ( (preg_match_all('#(href|src)=["\']([^"\']*)["\']#i', $matches[$i][0], $matches_attr, PREG_SET_ORDER) === 1) ) { $retrievable = add_table_and_replace($data, $retrievable, $matches[$i][0], $matches_attr[0][2], $url_p, $type); } } // recherche les images, scripts, audio & videos HTML5. // dans les balises, récupère l’url/uri contenue dans les src="". // le fichier sera téléchargé. // Le nom du fichier sera modifié pour être unique, et sera aussi modifié dans le code source. $matches = array(); preg_match_all('#<\s*(source|audio|img|script|video)[^>]+src="([^"]*)"[^>]*>#Si', $data, $matches, PREG_SET_ORDER); foreach($matches as $i => $key) { if (preg_match('#^data:#', $matches[$i][2])) break; $retrievable = add_table_and_replace($data, $retrievable, $matches[$i][0], $matches[$i][2], $url_p, 'other'); } // Dans les balises