Blame view

export/deepexport.php 4.47 KB
6c90d466   Andrea Petta   leafletjs
1
2
3
  <?php
  
  require '../Slim/Slim.php';
f90e19c3   Andrea Petta   plugin update
4
  require_once dirname(__FILE__) . '/PHPRtfLite-1.3.1/lib/PHPRtfLite.php';
6c90d466   Andrea Petta   leafletjs
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
  
  /**
  * 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 {
f90e19c3   Andrea Petta   plugin update
33
34
35
36
                      echo ($this->createImage($this->app->request()->params('svg_data')));
                  }catch (Exception $e){}
              }
          });
6c90d466   Andrea Petta   leafletjs
37
  
f90e19c3   Andrea Petta   plugin update
38
39
40
41
42
          $this->app->post('/export-datalet-as-rtf', function(){
              if(!empty($this->app->request()->params('svg_data'))) {
                  try {
                      // register PHPRtfLite class loader
                      PHPRtfLite::registerAutoloader();
6c90d466   Andrea Petta   leafletjs
43
  
f90e19c3   Andrea Petta   plugin update
44
45
                      // rtf document
                      $rtf = new PHPRtfLite();
6c90d466   Andrea Petta   leafletjs
46
  
f90e19c3   Andrea Petta   plugin update
47
                      $sect = $rtf->addSection();
b261add7   Andrea Petta   plugin update
48
49
50
51
52
53
54
  
                      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'));
  
f90e19c3   Andrea Petta   plugin update
55
                      $sect->addImageFromString($this->createImage($this->app->request()->params('svg_data')), PHPRtfLite_Image::TYPE_PNG);
b261add7   Andrea Petta   plugin update
56
57
58
  
                      if(!empty($_REQUEST["description"]))
                          $sect->writeText("Dataset description : " . strip_tags($_REQUEST["description"]), new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center'));
e2d8a521   Andrea Petta   plugin update
59
  
b261add7   Andrea Petta   plugin update
60
61
                      if(!empty($_REQUEST["created"]))
                          $sect->writeText("Dataset creation date : " . strip_tags($_REQUEST["created"]), new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center'));
e2d8a521   Andrea Petta   plugin update
62
  
b261add7   Andrea Petta   plugin update
63
64
                      if(!empty($_REQUEST["format"]))
                          $sect->writeText("Dataset format : " . strip_tags($_REQUEST["format"]), new PHPRtfLite_Font(14), new PHPRtfLite_ParFormat('center'));
e2d8a521   Andrea Petta   plugin update
65
  
b261add7   Andrea Petta   plugin update
66
67
68
69
70
                      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'));
e2d8a521   Andrea Petta   plugin update
71
72
73
74
75
76
77
78
79
80
  
                      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'));
  
f90e19c3   Andrea Petta   plugin update
81
82
83
                      // save rtf document
                      
                      $rtf->sendRtf('datalet.rtf');
6c90d466   Andrea Petta   leafletjs
84
85
86
87
                  }catch (Exception $e){}
              }
          });
      }
f90e19c3   Andrea Petta   plugin update
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
  
      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;
      }
  
6c90d466   Andrea Petta   leafletjs
113
114
115
116
117
      public function run(){
          //run the Slim app
          $this->app->run();
      }
  }