1<?php
2/**
3 * Media Link handler
4 *
5 * Copy the file into the archive directory, downloads it
6 * if it is external.
7 *
8 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 * @author     Yann Hamon <yann@mandragor.org>
10 * @return     A link to the file, relative to the page asked.
11 */
12
13function dokukiwix_ml($id='',$more='',$direct=true,$sep='&'){
14  global $_POST;
15  global $offlineVersionPath;
16
17  // We build a link relative to the current page
18  $xlink = './';
19  $page_depth = substr_count($_POST['page'], ":");
20  for($i=0;$i<=$page_depth;$i++)
21    $xlink .= "../";
22
23  // External pictures: dowload in /images/_extern
24  if(preg_match('#^(https?|ftp)://#i',$id)){
25    io_download($id, $offlineVersionPath.'images/_extern/'.$_POST['page'].'-'.basename($id));
26    $xlink .= 'images/_extern/'.$_POST['page'].'-'.basename($id);
27  }
28  else
29  // Files starting with tag_ are only tags
30  if(!preg_match('#\/?tag_#i',$id)) {
31    $id = str_replace(":", "/", $id);
32    io_mkdir_p(dirname($offlineVersionPath.'images/'.$id));
33    copy(DOKU_INC.'data/media/'.$id,$offlineVersionPath.'images/'.$id);
34    $xlink .= 'images/'.$id;
35  }
36
37  return $xlink;
38}
39
40/**
41 * Wiki Link handler
42 *
43 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
44 * @author     Yann Hamon <yann@mandragor.org>
45 * @return     A link to the page linked, relative to the page asked.
46 */
47function dokukiwix_wl($id='',$more='',$abs=false,$sep='&amp;'){
48  global $_POST;
49
50  $xlink = './';
51
52  // If $id does not contain any :, the link is relative; in all other case, it is absolute.
53  if(!(preg_match('#^\.#i',$id) || (!preg_match('#^\.#i',$id) && !preg_match('#:#i',$id))) ){ // Link is absolute
54    $page_depth = substr_count($_POST['page'], ":");
55    for($i=0;$i<$page_depth;$i++)
56      $xlink .= "../";
57  }
58
59  $id = str_replace(":", "/", $id);
60  $id = preg_replace("#^\.(.*)#i", "\\1", $id);
61  $xlink .= $id.'.html';
62
63  return $xlink;
64}
65
66
67