forked from lebowski42/dokuwiki-owncloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
work.php
74 lines (62 loc) · 2.19 KB
/
work.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Reads the path for a mediafile from the owncloud database identified by the fileID
* submitted by &fileid=... . Then redirects to fetch.php
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Martin Schulte <lebowski[at]corvus[dot]uberspace[dot]de>
*/
//error_reporting (E_ALL | E_STRICT);
//ini_set ('display_errors', 'On');
// Prepare
if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/../../../');
define('DOKU_DISABLE_GZIP_OUTPUT', 1);
// $INPUT and $conf
require_once(DOKU_INC.'inc/init.php');
$text = "sdfsdf{{wiki:dokuwiki-128.png|beschreibung|6}}sdfsd{{wiki:dokuwiki-128.png|beschreibung|5}}f";
//$inhalt = preg_replace('#\[url=(.*)\](.*)\[/url\]#Uis', '<a href="\1">\2</a>', $text);
$inhalt = preg_replace('#\{\{(.+)\}\}#Uise', "'{{'.buildLink('\\1').'}}'", $text);
echo $inhalt;
//echo "<h1>".buildLink("wiki:dokuwiki-128.png?200&direcrt&nocache|Beschreibung|6")."</h1>";
function buildLiwnk($rawdata){
$parts = explode("|",$rawdata);
$link = array_shift($parts);
//split into src and parameters (using the very last questionmark) from /inc/parser/handler.php
$pos = strrpos($link,'?');
if($pos != false){
$src = substr($link,0,$pos);
$param = substr($link,$pos+1);
}else{
$src = $link;
$param = '';
}
// get fileID
if(count($parts) > 1 ){ // We've a fileid
$last = array_pop($parts);
$fileid = intval($last); // Last element maybe fileid
$desc = implode("|",$parts); // The rest is the description, can contain |
if($fileid == 0 ) $desc .= "|".$last; // no fileid, is part of description
}else{
$fileid = 0;
$desc = array_shift($parts);
}
// db access
$helper = new helper_plugin_cloud();
if($fileid > 0){ // Then find source from id
$path = $helper->getFilenameForID($fileid);
if($path != ""){
$src = str_replace('/',':',$path);
$notfound = false;
}else{
$notfound = true;
}
}else{
$notfound = true;
}
// We have no file from id, look for id using source
if($notfound){ // Try to find ID from source
$path = str_replace(':','/',$src);
$fileid = $helper->getIDForFilename($path);
}
return $src.(($param != "") ? "?$param":"")."|".$desc."|".$fileid;
}