deepexport.php
4.47 KB
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
<?php
require '../Slim/Slim.php';
require_once dirname(__FILE__) . '/PHPRtfLite-1.3.1/lib/PHPRtfLite.php';
/**
* Class DeepExport
*/
class DeepExport
{
private static $instance = null;
private $app;
public static function getInstance()
{
if(self::$instance == null)
{
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance;
}
private function __construct()
{
\Slim\Slim::registerAutoloader();
$this->app = new \Slim\Slim();
$this->app->post('/export-datalet-as-img', function(){
if(!empty($this->app->request()->params('svg_data'))) {
try {
echo ($this->createImage($this->app->request()->params('svg_data')));
}catch (Exception $e){}
}
});
$this->app->post('/export-datalet-as-rtf', function(){
if(!empty($this->app->request()->params('svg_data'))) {
try {
// register PHPRtfLite class loader
PHPRtfLite::registerAutoloader();
// rtf document
$rtf = new PHPRtfLite();
$sect = $rtf->addSection();
if(!empty($_REQUEST["name"]))
$sect->writeText("Dataset name : " . strip_tags($_REQUEST["name"]), new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center'));
if(!empty($_REQUEST["datalet"]))
$sect->writeText("Datalet name : " . strip_tags($_REQUEST["datalet"]), new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center'));
$sect->addImageFromString($this->createImage($this->app->request()->params('svg_data')), PHPRtfLite_Image::TYPE_PNG);
if(!empty($_REQUEST["description"]))
$sect->writeText("Dataset description : " . strip_tags($_REQUEST["description"]), new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center'));
if(!empty($_REQUEST["created"]))
$sect->writeText("Dataset creation date : " . strip_tags($_REQUEST["created"]), new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center'));
if(!empty($_REQUEST["format"]))
$sect->writeText("Dataset format : " . strip_tags($_REQUEST["format"]), new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center'));
if(!empty($_REQUEST["lastModified"]))
$sect->writeText("Dataset last modified : " . strip_tags($_REQUEST["lastModified"]), new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center'));
if(!empty($_REQUEST["dataset"]))
$sect->writeText("Dataset link : " . strip_tags($_REQUEST["dataset"]), new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center'));
if(!empty($_REQUEST["timestamp"]))
$sect->writeText("Datalet added on : " . strip_tags($_REQUEST["timestamp"]), new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center'));
if(!empty($_REQUEST["user"]))
$sect->writeText("Datalet created by : " . strip_tags($_REQUEST["user"]), new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center'));
if(!empty($_REQUEST["comment"]))
$sect->writeText("Datalet comment : " . strip_tags($_REQUEST["comment"]), new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center'));
// save rtf document
$rtf->sendRtf('datalet.rtf');
}catch (Exception $e){}
}
});
}
private function createImage($svg_data)
{
$svg = $svg_data;
$chart = new Imagick();
$chart->setFormat('SVG');
$chart->readImageBlob($svg);
$chart->setFormat("png24");
$logo = new Imagick();
$logo->readImage("pbrtpa.bmp");
$image = new Imagick();
$image->setFormat("png24");
$image->newImage($chart->getImageWidth() > $logo->getImageHeight() ? $chart->getImageWidth() : $logo->getImageWidth(),
$chart->getImageHeight()+$logo->getImageHeight(),
"white");
$image->compositeImage($chart, Imagick::COMPOSITE_COPY, 0, 0);
$image->compositeImage($logo, Imagick::COMPOSITE_COPY, 20, $chart->getImageHeight());
return $image;
}
public function run(){
//run the Slim app
$this->app->run();
}
}