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 detail.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// Prepare
10if(!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__).'/../../../../');
11define('DOKU_DISABLE_GZIP_OUTPUT', 1);
12// $INPUT and $conf
13require_once(DOKU_INC.'inc/init.php');
14
15
16
17// Get parameters from url
18$fileID = $INPUT->int('fileid');
19$media = stripctl(getID('media', false));
20
21
22// db access
23$helper = new helper_plugin_owncloud();
24$realmedia = $helper->getFilenameForID($fileID,true);
25
26/*
27echo "<hr>";
28echo '$fileID:'.$fileID."<br>";
29echo '$media:'.$media."<br>";
30echo '$realmedia:'.$realmedia."<br>";
31echo '$queryString:'.$queryString."<br>";
32
33echo "<hr>";
34*/
35
36// rebuild the given url-query
37$queryString = $_SERVER['QUERY_STRING'];
38// if there is an entry in the database for this id, try the given path
39if(!empty($realmedia)) {
40	$queryString = str_replace($media,$realmedia,$queryString);
41}else{
42	$realmedia = $media;
43}
44
45
46// follow the rewrite-mode (from function ml(...), see /inc/common.php)
47// Webserver- or dokuwiki-/no rewrite?
48if($conf['userewrite'] == 1) {
49	$script = '_detail';
50} else {
51	$script = 'lib/exe/detail.php';
52}
53// build URL based on rewrite mode
54if($conf['userewrite']) {
55	$xlink .= $script.'/'.$realmedia;
56	if($queryString) $xlink .= '?'.$queryString;
57} else {
58	if($queryString) {
59		$xlink .= $script.'?'.$queryString;
60	} else {
61		$xlink .= $script.'?media='.$realmedia;
62	}
63}
64
65
66/*
67echo "<hr>";
68echo '$script:'.$script."<br>";
69echo '$xlink:'.$xlink."<br>";
70echo '$queryString:'.$queryString."<br>";
71echo '$realmedia:'.$realmedia."<br>";
72echo "<hr>";
73*/
74session_write_close(); //close session, we want use header()
75
76//redirect to original detail.php
77header("Location: ".DOKU_URL.$xlink);
78
79
80
81