|
| 1 | +<?php |
| 2 | +/** Zend_Controller_Action */ |
| 3 | +require_once 'Zend/Controller/Action.php'; |
| 4 | +//ini_set("memory_limit", "1024M"); |
| 5 | + |
| 6 | +ini_set('memory_limit', '512M'); |
| 7 | +ini_set("max_execution_time", "0"); |
| 8 | +ini_set('default_socket_timeout', 240); |
| 9 | + |
| 10 | + |
| 11 | +//session_start(); |
| 12 | +class tabllesController extends Zend_Controller_Action { |
| 13 | + |
| 14 | + |
| 15 | + public function viewAction(){ |
| 16 | + |
| 17 | + $tableID = $_GET["tableID"]; |
| 18 | + if(isset($_GET["partID"])){ |
| 19 | + $partID = $_GET["tableID"]; |
| 20 | + } |
| 21 | + |
| 22 | + $partID = $_GET["tableID"]; |
| 23 | + |
| 24 | + $exTableObj = new ExportTable; |
| 25 | + $found = $exTableObj->getByID($tableID); |
| 26 | + if($found){ |
| 27 | + if(isset($_GET["page"])){ |
| 28 | + $exTableObj->recPage = $_GET["page"]; |
| 29 | + } |
| 30 | + $this->view->exTableObj = $exTableObj; |
| 31 | + //return $this->render('tview'); |
| 32 | + } |
| 33 | + else{ |
| 34 | + $this->view->requestURI = $this->_request->getRequestUri(); |
| 35 | + return $this->render('404error'); |
| 36 | + } |
| 37 | + |
| 38 | + $this->_helper->viewRenderer->setNoRender(); |
| 39 | + $outJSON = Zend_Json::encode($exTableObj); |
| 40 | + header('Content-Type: application/json; charset=utf8'); |
| 41 | + echo $outJSON; |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + public function jsonLdAction(){ |
| 46 | + |
| 47 | + $tableID = $_GET["tableID"]; |
| 48 | + if(isset($_GET["partID"])){ |
| 49 | + $partID = $_GET["tableID"]; |
| 50 | + } |
| 51 | + |
| 52 | + $partID = $_GET["tableID"]; |
| 53 | + |
| 54 | + $exTableObj = new ExportTable; |
| 55 | + $found = $exTableObj->getByID($tableID); |
| 56 | + if($found){ |
| 57 | + if(isset($_GET["page"])){ |
| 58 | + $exTableObj->recPage = $_GET["page"]; |
| 59 | + } |
| 60 | + $this->view->exTableObj = $exTableObj; |
| 61 | + //return $this->render('tview'); |
| 62 | + } |
| 63 | + else{ |
| 64 | + $this->view->requestURI = $this->_request->getRequestUri(); |
| 65 | + return $this->render('404error'); |
| 66 | + } |
| 67 | + |
| 68 | + $this->_helper->viewRenderer->setNoRender(); |
| 69 | + $outJSON = Zend_Json::encode($exTableObj->metadata); |
| 70 | + header('Content-Type: application/json; charset=utf8'); |
| 71 | + echo $outJSON; |
| 72 | + } |
| 73 | + |
| 74 | + //returns a csv file |
| 75 | + public function csvAction(){ |
| 76 | + |
| 77 | + $tableID = $_GET["tableID"]; |
| 78 | + if(isset($_GET["partID"])){ |
| 79 | + $partID = $_GET["partID"]; |
| 80 | + } |
| 81 | + |
| 82 | + $file = false; |
| 83 | + $exTableObj = new ExportTable; |
| 84 | + $found = $exTableObj->getByID($tableID); |
| 85 | + if($found){ |
| 86 | + $file = $exTableObj->retrieveFile("csv"); |
| 87 | + } |
| 88 | + else{ |
| 89 | + $this->view->requestURI = $this->_request->getRequestUri(); |
| 90 | + return $this->render('404error'); |
| 91 | + } |
| 92 | + |
| 93 | + if(!$file){ |
| 94 | + $this->view->requestURI = $this->_request->getRequestUri(); |
| 95 | + return $this->render('500error'); |
| 96 | + } |
| 97 | + else{ |
| 98 | + $this->_helper->viewRenderer->setNoRender(); |
| 99 | + header('Content-type: text/csv'); |
| 100 | + header('Content-disposition: attachment; filename=OpenContext.csv'); |
| 101 | + ob_clean(); |
| 102 | + flush(); |
| 103 | + readfile($file); |
| 104 | + exit; |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + //returns a zip file |
| 109 | + public function zipAction(){ |
| 110 | + |
| 111 | + $tableID = $_GET["tableID"]; |
| 112 | + if(isset($_GET["partID"])){ |
| 113 | + $partID = $_GET["partID"]; |
| 114 | + } |
| 115 | + |
| 116 | + $file = false; |
| 117 | + $exTableObj = new ExportTable; |
| 118 | + $found = $exTableObj->getByID($tableID); |
| 119 | + if($found){ |
| 120 | + $file = $exTableObj->retrieveFile("zip"); |
| 121 | + } |
| 122 | + else{ |
| 123 | + $this->view->requestURI = $this->_request->getRequestUri(); |
| 124 | + return $this->render('404error'); |
| 125 | + } |
| 126 | + |
| 127 | + if(!$file){ |
| 128 | + $this->view->requestURI = $this->_request->getRequestUri(); |
| 129 | + return $this->render('500error'); |
| 130 | + } |
| 131 | + else{ |
| 132 | + $this->_helper->viewRenderer->setNoRender(); |
| 133 | + header('Content-type: application/zip'); |
| 134 | + header('Content-disposition: attachment; filename=OpenContext.zip'); |
| 135 | + ob_clean(); |
| 136 | + flush(); |
| 137 | + readfile($file); |
| 138 | + exit; |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + //returns a gzip file |
| 143 | + public function gzipAction(){ |
| 144 | + |
| 145 | + $tableID = $_GET["tableID"]; |
| 146 | + if(isset($_GET["partID"])){ |
| 147 | + $partID = $_GET["partID"]; |
| 148 | + } |
| 149 | + |
| 150 | + $file = false; |
| 151 | + $exTableObj = new ExportTable; |
| 152 | + $found = $exTableObj->getByID($tableID); |
| 153 | + if($found){ |
| 154 | + $file = $exTableObj->retrieveFile("gzip"); |
| 155 | + } |
| 156 | + else{ |
| 157 | + $this->view->requestURI = $this->_request->getRequestUri(); |
| 158 | + return $this->render('404error'); |
| 159 | + } |
| 160 | + |
| 161 | + if(!$file){ |
| 162 | + $this->view->requestURI = $this->_request->getRequestUri(); |
| 163 | + return $this->render('500error'); |
| 164 | + } |
| 165 | + else{ |
| 166 | + $this->_helper->viewRenderer->setNoRender(); |
| 167 | + header('Content-type: application/x-gzip'); |
| 168 | + header('Content-disposition: attachment; filename=OpenContext.gz'); |
| 169 | + ob_clean(); |
| 170 | + flush(); |
| 171 | + readfile($file); |
| 172 | + exit; |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | + //returns a json file of the whole dataset |
| 179 | + public function jsonAction(){ |
| 180 | + |
| 181 | + $tableID = $_GET["tableID"]; |
| 182 | + if(isset($_GET["partID"])){ |
| 183 | + $partID = $_GET["partID"]; |
| 184 | + } |
| 185 | + |
| 186 | + $file = false; |
| 187 | + $exTableObj = new ExportTable; |
| 188 | + $found = $exTableObj->getByID($tableID); |
| 189 | + if($found){ |
| 190 | + $file = $exTableObj->retrieveFile("json"); |
| 191 | + } |
| 192 | + else{ |
| 193 | + $this->view->requestURI = $this->_request->getRequestUri(); |
| 194 | + return $this->render('404error'); |
| 195 | + } |
| 196 | + |
| 197 | + if(!$file){ |
| 198 | + $this->view->requestURI = $this->_request->getRequestUri(); |
| 199 | + return $this->render('500error'); |
| 200 | + } |
| 201 | + else{ |
| 202 | + if(isset($_SERVER['HTTP_ACCEPT_ENCODING'])){ |
| 203 | + $encoding = $this->check_compress_ok($_SERVER['HTTP_ACCEPT_ENCODING']); |
| 204 | + $compressOK = true; |
| 205 | + } |
| 206 | + else{ |
| 207 | + $encoding = 'gzip'; |
| 208 | + $compressOK = false; |
| 209 | + } |
| 210 | + |
| 211 | + $this->_helper->viewRenderer->setNoRender(); |
| 212 | + header('Content-Type: application/json; charset=utf8'); |
| 213 | + header ("Cache-Control:max-age=290304000, public"); |
| 214 | + if($compressOK ){ |
| 215 | + header('Content-Encoding: '.$encoding); |
| 216 | + print("\x1f\x8b\x08\x00\x00\x00\x00\x00"); |
| 217 | + //$filestring = readfile($file); |
| 218 | + $filestring = 1; |
| 219 | + print gzcompress($filestring, 9); |
| 220 | + unset($filestring); |
| 221 | + } |
| 222 | + else{ |
| 223 | + readfile($file); |
| 224 | + } |
| 225 | + } |
| 226 | + } |
| 227 | + |
| 228 | + |
| 229 | + private function check_compress_ok($HTTP_ACCEPT_ENCODING){ |
| 230 | + if( headers_sent() ){ |
| 231 | + $encoding = false; |
| 232 | + }elseif( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false ){ |
| 233 | + $encoding = 'x-gzip'; |
| 234 | + }elseif( strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false ){ |
| 235 | + $encoding = 'gzip'; |
| 236 | + }else{ |
| 237 | + $encoding = false; |
| 238 | + } |
| 239 | + return $encoding; |
| 240 | + } |
| 241 | + |
| 242 | + |
| 243 | +}//end class |
0 commit comments