-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpecialPdfTemplateEditor.php
131 lines (88 loc) · 3.14 KB
/
SpecialPdfTemplateEditor.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
require_once("classes/pdf.class.php");
require_once("classes/template.class.php");
class SpecialPdfTemplateEditor extends SpecialPage {
function __construct() {
parent::__construct( 'PdfTemplateEditor' );
chdir('extensions/wiki2pdf/');
}
function execute( $par ) {
//Manual: https://www.mediawiki.org/wiki/Manual:Special_pages
global $wgRequest, $wgOut, $wgResourceModules;
$this->setHeaders();
# Get request data from, e.g.
$param = $wgRequest->getText('param');
# Do stuff
# ...
//$output = '[http://smw.xan8.de/extensions/wiki2pdf/upload.php Editor öffnen]';
//$wgOut->addWikiText( $output );
//$output = $this->getOutput();
//$output->addHTML('<canvas></canvas>');
$action = ($this->getRequest()->getVal('action') !== null) ? ($this->getRequest()->getVal('action')) : ('upload');
switch ($action) {
case 'upload':
$this->uploadPrompt();
break;
case 'editor':
$this->editorPrompt();
break;
default:
# code...
break;
}
}
function uploadPrompt(){
global $wgResourceModules;
$output = $this->getOutput();
$this->getOutput()->addModules( 'ext.wiki2pdf' );
$template = new Template("templates/upload.tpl");
$template->assignVariable("FORMURL", $this->buildQueryString(array('action' => 'editor')));
$output -> setPageTitle("Wiki2PDF Editor - Upload your file");
$output->addHTML($template->compile());
}
private function buildQueryString($add){
$str = "?";
$data = array_merge($_GET, $add);
$keys = array_keys($data);
$last_key = end($keys);
foreach ($data as $key => $value) {
if ($key == $last_key) {
// last element
$str .= $key . "=" . $value;
} else {
// not last element
$str .= $key . "=" . $value . "&";
}
}
return $str;
}
function editorPrompt(){
$pdf = new Pdf($_POST['url']);
$pdf->createImagesFromPdf();
//$pdf->printDebug();
$output = $this->getOutput();
$this->getOutput()->addModules( 'ext.wiki2pdf.editor' );
$template = new Template("templates/editor.tpl");
$pages = "[";
foreach ($pdf->getImagedata() as $key => $value) {
$pages .= '"' . $value . '"';
if($key < count($pdf->getImagedata())-1){
$pages .= ",";
}
$pages .= "\n";
}
$pages .= "]";
$template->assignVariable("pages", $pages);
$template->assignVariable("pagecount", $pdf->getPages());
$template->assignVariable("width", $pdf->getWidth());
$template->assignVariable("height", $pdf->getHeight());
$imagedata = $pdf->getImagedata();
//@TODO: Make Link dynamic
$template->assignVariable("startpic", "/britsch/extensions/wiki2pdf/tmp/" . $pdf->getHash() . "/" . $imagedata[0]);
$template->assignVariable("image_basepath", "/britsch/extensions/wiki2pdf/tmp/" . $pdf->getHash() . "/" );
$template->assignVariable("images", $pdf->getImagedata());
$template->assignVariable("url", $pdf->getUrl());
$output -> setPageTitle("MagicPDF Editor - Upload your file");
$output->addHTML($template->compile());
}
}