1<?php
2/**
3 * Reads the path for a mediafile from the owncloud database identified by the fileID
4 * submitted by &fileid=... . Then redirects to fetch.php
5 *
6 * @license    GPL 3 (http://www.gnu.org/licenses/gpl.html)
7 * @author     Martin Schulte <lebowski[at]corvus[dot]uberspace[dot]de>, 2013
8 */
9
10//error_reporting (E_ALL | E_STRICT);
11//ini_set ('display_errors', 'On');
12
13// Prepare
14if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/../../../../');
15define('DOKU_DISABLE_GZIP_OUTPUT', 1);
16// $INPUT and $conf
17
18require_once(DOKU_INC.'inc/init.php');
19
20$xlink = '';
21
22// Get parameters from url
23$fileID = $INPUT->int('fileid');
24$media = stripctl(getID('media', false));
25
26
27// db access
28$helper = new helper_plugin_owncloud();
29$realmedia = $helper->getFilenameForID($fileID,true);
30
31/*
32echo "<hr>";
33echo '$fileID:'.$fileID."<br>";
34echo '$media:'.$media."<br>";
35echo '$realmedia:'.$realmedia."<br>";
36echo '$queryString:'.$queryString."<br>";
37
38echo "<hr>";
39*/
40
41// rebuild the given url-query
42$queryString = $_SERVER['QUERY_STRING'];
43// if there is an entry in the database for this id, try the given path
44if(!empty($realmedia)) {
45	$queryString = str_replace($media,$realmedia,$queryString);
46}else{
47	$realmedia = $media;
48}
49
50$width  = $INPUT->int('w');
51$height = $INPUT->int('h');
52$token  = $INPUT->str('tok');
53$newtoken = media_get_token($realmedia, $width, $height);
54$queryString = str_replace($token,$newtoken,$queryString);
55
56
57
58
59// follow the rewrite-mode (from function ml(...), see /inc/common.php)
60// Webserver- or dokuwiki-/no rewrite?
61if($conf['userewrite'] == 1) {
62	$script = '_media';
63} else {
64	$script = 'lib/exe/fetch.php';
65}
66// build URL based on rewrite mode
67if($conf['userewrite']) {
68	$xlink .= $script.'/'.$realmedia;
69	if($queryString) $xlink .= '?'.$queryString;
70} else {
71	if($queryString) {
72		$xlink .= $script.'?'.$queryString;
73	} else {
74		$xlink .= $script.'?media='.$realmedia;
75	}
76}
77
78/*
79echo "<hr>";
80echo '$script:'.$script."<br>";
81echo '$xlink:'.$xlink."<br>";
82echo '$queryString:'.$queryString."<br>";
83echo '$realmedia:'.$realmedia."<br>";
84echo "<hr>";
85*/
86session_write_close(); //close session, we want use header()
87
88//redirect to original fetch.php
89header("Location: ".DOKU_URL.$xlink);
90
91
92
93