0596f80b by Jeff Balicki

working demo

1 parent 3d6cfd71
...@@ -97,12 +97,41 @@ class ApiController extends Controller ...@@ -97,12 +97,41 @@ class ApiController extends Controller
97 97
98 public function update() 98 public function update()
99 { 99 {
100
101
100 $json = Input::all(); 102 $json = Input::all();
101 $apiCallId = new pdfModel(); 103
102 $apiCallId = $apiCallId->addApiCall('1',$json); 104 $json = json_encode($json);
103 //$apiCallId = "3"; 105 $json = json_decode($json);
106
107
108 $storagePath = Storage::disk('public')->getDriver()->getAdapter()->getPathPrefix();
109
110
111 foreach ($json->changes as $change) {
112 if ($change->change_type == 'img') {
113
114 $folder = str_replace(' ', '-', $json->pdf[0]->folder); // Replaces all spaces with hyphens.
115 $folder = preg_replace('/[^A-Za-z0-9\-]/', '', $folder);
116 $fileLocation = $change->fileLocation;
117 $file = explode('\\', $change->content);
118
119 $curl = new Curl();
120 $curl->download($fileLocation.'/'.end($file), $storagePath . $folder . '/' . end($file));
121 $curl->close();
122
123 }
124 }
125
126 $json = json_encode($json);
127 // $json = '{"pdf":[{"name":"Sample PDF Document","folder":"Sample","pdfLocation":"http://hotelpodlipou.sk/uploads/files/sample.pdf"}],"changes":[{"label":"none","locationUp":"400","locationRight":90,"pages":"1","content":"logo-sample-text_355-558.jpg","z-index":null,"idstylesPDF":1,"order":"2","style":null,"idchange_typePDF":2,"change_type":"2","fileLocation":"https://image.freepik.com/free-vector/logo-sample-text_355-558.jpg"},{"label":"text style","locationUp":"60","locationRight":290,"pages":"1","content":"519.642.4404 London","z-index":null,"idstylesPDF":2,"order":"1","style":"a:3:{s:11:\"font-family\";s:11:\"TradeGothic\";s:9:\"font-size\";s:2:\"14\";s:10:\"font-color\";s:16:\"cmyk 0 0.6 0.5 0\";}","idchange_typePDF":1,"change_type":"1"}]}';
128
129 //$apiCallId = new pdfModel();
130 // $apiCallId = $apiCallId->addApiCall('1',$json);
131 $apiCallId = "3";
104 $pdfId = new pdfModel(); 132 $pdfId = new pdfModel();
105 $pdfId = $pdfId->addPdf($apiCallId, $json); 133 $pdfId = $pdfId->changePdf($apiCallId, $json);
134
106 $pdf = new PdfController(); 135 $pdf = new PdfController();
107 $pdf = $pdf->pdf($pdfId); 136 $pdf = $pdf->pdf($pdfId);
108 $response = $pdf; 137 $response = $pdf;
...@@ -139,6 +168,8 @@ class ApiController extends Controller ...@@ -139,6 +168,8 @@ class ApiController extends Controller
139 168
140 public function getPdf($json) 169 public function getPdf($json)
141 { 170 {
171
172
142 $rows = new pdfModel(); 173 $rows = new pdfModel();
143 $rows = $rows->getpdf($json)->get(); 174 $rows = $rows->getpdf($json)->get();
144 $response = $rows; 175 $response = $rows;
......
...@@ -37,7 +37,9 @@ class FileEntryController extends Controller { ...@@ -37,7 +37,9 @@ class FileEntryController extends Controller {
37 return redirect('fileentry'); 37 return redirect('fileentry');
38 38
39 } 39 }
40 public function getone($folder, $filename){ 40
41
42 public function getImage($folder, $filename){
41 43
42 //$entry = Fileentry::where('filename', '=', $filename)->firstOrFail(); 44 //$entry = Fileentry::where('filename', '=', $filename)->firstOrFail();
43 $file = Storage::disk('public')->get($folder.'/'.$filename); 45 $file = Storage::disk('public')->get($folder.'/'.$filename);
...@@ -46,6 +48,17 @@ class FileEntryController extends Controller { ...@@ -46,6 +48,17 @@ class FileEntryController extends Controller {
46 ->header('Content-Type', 'image/jpeg'); 48 ->header('Content-Type', 'image/jpeg');
47 } 49 }
48 50
51
52 public function getPDF($folder, $filename){
53
54 //$entry = Fileentry::where('filename', '=', $filename)->firstOrFail();
55 $file = Storage::disk('public')->get($folder.'/'.$filename);
56 return (new Response($file, 200))
57 ->header('Content-Type','application/pdf');
58
59 }
60
61
49 public function get($filename){ 62 public function get($filename){
50 63
51 $entry = Fileentry::where('filename', '=', $filename)->firstOrFail(); 64 $entry = Fileentry::where('filename', '=', $filename)->firstOrFail();
...@@ -55,6 +68,46 @@ class FileEntryController extends Controller { ...@@ -55,6 +68,46 @@ class FileEntryController extends Controller {
55 ->header('Content-Type', $entry->mime); 68 ->header('Content-Type', $entry->mime);
56 } 69 }
57 70
71
72 public function postUpload(){
73
74 $files = Input::file('files');
75
76 $json = array(
77 'files' => array()
78 );
79
80 foreach( $files as $file ):
81
82 $filename = $file->getClientOriginalName().".".$file->getClientOriginalExtension();
83
84 $json['files'][] = array(
85 'name' => $filename,
86 'size' => $file->getSize(),
87 'type' => $file->getMimeType(),
88 'url' => '/uploads/files/'.$filename,
89 'deleteType' => 'DELETE',
90 'deleteUrl' => self::$route.'/deleteFile/'.$filename,
91 );
92
93 $upload = $file->move( public_path().'/files', $filename );
94
95
96 endforeach;
97
98
99
100
101
102 return Response::json($json);
103
104 }
105
106
107
108
109
110
58 public function getApi($json) 111 public function getApi($json)
59 { 112 {
60 $file = Storage::disk('public')->get('js/interface.js'); 113 $file = Storage::disk('public')->get('js/interface.js');
......
...@@ -23,18 +23,20 @@ use PDFlib; ...@@ -23,18 +23,20 @@ use PDFlib;
23 class PdfController extends Controller 23 class PdfController extends Controller
24 { 24 {
25 25
26 public function pdf($id) 26 public function pdf($pdfId)
27 { 27 {
28 28
29 $rows = new pdfModel(); 29 $rows = new pdfModel();
30 $rows = $rows->getpdf($id)->get(); 30 $rows = $rows->getpdf($pdfId)->get();
31
31 $folder = $rows[0]->folder; 32 $folder = $rows[0]->folder;
32 $searchpath = "$folder"; 33 $searchpath = "$folder";
33 $pdffile = $searchpath.'/'.$rows[0]->file; 34 $pdffile = $searchpath.'/'.$rows[0]->file;
34 $outfile=""; 35 //$outfile="";
35 $title = "Test Pages"; 36 $title = "Test Pages";
36 $storagePath = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix(); 37 $storagePath = Storage::disk('public')->getDriver()->getAdapter()->getPathPrefix();
37 $outfile = $storagePath.$searchpath."/new_".$rows[0]->file; 38 $outfile = $storagePath.$searchpath."/new_".$rows[0]->file;
39 $download = 'http://localhost:8888/pdf-customizer/public/fileentry/getPDF/'.$searchpath."/new_".$rows[0]->file;
38 40
39 try { 41 try {
40 42
...@@ -152,12 +154,12 @@ try { ...@@ -152,12 +154,12 @@ try {
152 $p->end_document(""); 154 $p->end_document("");
153 155
154 156
155 return $outfile; 157 return $download;
156 158
157 /// To turn on pdf screen out put uncomment below lines and remove the text in $output="" Var 159 /// To turn on pdf screen out put uncomment below lines and remove the text in $output="" Var
158 160
159 //$buf = $p->get_buffer(); 161 // $buf = $p->get_buffer();
160 //$len = strlen($buf); 162 // $len = strlen($buf);
161 163
162 //header("Content-type: application/pdf"); 164 //header("Content-type: application/pdf");
163 //header("Content-Length: $len"); 165 //header("Content-Length: $len");
......
...@@ -11,7 +11,7 @@ class VerifyCsrfToken extends BaseVerifier ...@@ -11,7 +11,7 @@ class VerifyCsrfToken extends BaseVerifier
11 * 11 *
12 * @var array 12 * @var array
13 */ 13 */
14 protected $except = [ 14 protected $except = [ 'api/update', 'fileentry/postUpload'
15 // 15 //
16 ]; 16 ];
17 } 17 }
......
...@@ -30,14 +30,16 @@ Route::group(array('prefix' => 'api/v1'), function($json) ...@@ -30,14 +30,16 @@ Route::group(array('prefix' => 'api/v1'), function($json)
30 30
31 }); 31 });
32 32
33 Route::get('api/update/1', 'ApiController@update'); 33 Route::any('api/update', 'ApiController@update');
34 Route::any('fileentry/postUpload', 'FileEntryController@postUpload');
34 35
35 Route::get('fileentry/get/{filename}', [ 36 Route::get('fileentry/get/{filename}', [
36 'as' => 'getentry', 'uses' => 'FileEntryController@get']); 37 'as' => 'getentry', 'uses' => 'FileEntryController@get']);
37 38
38 39
39 Route::get('fileentry', 'FileEntryController@index'); 40 Route::get('fileentry', 'FileEntryController@index');
40 Route::get('fileentry/getone/{folder}/{filename}', 'FileEntryController@getone'); 41 Route::get('fileentry/getImage/{folder}/{filename}', 'FileEntryController@getImage');
42 Route::get('fileentry/getPDF/{folder}/{filename}', 'FileEntryController@getPDF');
41 43
42 Route::post('fileentry/add',[ 44 Route::post('fileentry/add',[
43 'as' => 'addentry', 'uses' => 'FileEntryController@add']); 45 'as' => 'addentry', 'uses' => 'FileEntryController@add']);
......
...@@ -18,6 +18,7 @@ class pdfModel extends Model ...@@ -18,6 +18,7 @@ class pdfModel extends Model
18 public function getPdf($id){ 18 public function getPdf($id){
19 19
20 20
21
21 $rows = DB::table('PDF') 22 $rows = DB::table('PDF')
22 ->join('changesPDF', 'PDF_idPDF', '=', 'idPDF') 23 ->join('changesPDF', 'PDF_idPDF', '=', 'idPDF')
23 ->join('stylesPDF', 'stylesPDF_idstylesPDF', '=', 'idstylesPDF') 24 ->join('stylesPDF', 'stylesPDF_idstylesPDF', '=', 'idstylesPDF')
...@@ -66,6 +67,7 @@ class pdfModel extends Model ...@@ -66,6 +67,7 @@ class pdfModel extends Model
66 $fileName = end($file); 67 $fileName = end($file);
67 $fileName = explode('.', $fileName); 68 $fileName = explode('.', $fileName);
68 69
70
69 $pdfId = DB::table('PDF')->insertGetId( 71 $pdfId = DB::table('PDF')->insertGetId(
70 array('name' => $json->pdf[0]->name, 'folder' => $folder, 'file' => end($file), 'apiCallId' => $apiCallId, 'image'=> $fileName[0].'.jpg') 72 array('name' => $json->pdf[0]->name, 'folder' => $folder, 'file' => end($file), 'apiCallId' => $apiCallId, 'image'=> $fileName[0].'.jpg')
71 ); 73 );
...@@ -87,5 +89,49 @@ class pdfModel extends Model ...@@ -87,5 +89,49 @@ class pdfModel extends Model
87 89
88 90
89 } 91 }
92 public function changePdf($apiCallId, $json){
93
94
95
96
97
98
99
100 $json = json_decode($json);
101
102 $folder = str_replace(' ', '-', $json->pdf[0]->name); // Replaces all spaces with hyphens.
103 $folder = preg_replace('/[^A-Za-z0-9\-]/', '', $folder);
104 $pdfLocation = $json->pdf[0]->pdfLocation;
105 $file = explode('/', $pdfLocation);
106 $fileName = end($file);
107 $fileName = explode('.', $fileName);
108
109 $pdfId = DB::table('PDF')->insertGetId(
110 array('name' => $json->pdf[0]->name, 'folder' => $folder, 'file' => end($file), 'apiCallId' => $apiCallId, 'image'=> $fileName[0].'.jpg')
111 );
112
113 foreach($json->changes as $change) {
114 if ($change->change_type == 'img') {
115 $content = explode('\\', $change->content);
116 $content = end($content);
117 }else{
118 $content = $change->content;
119
120 }
121
122 $idstylesPDF = DB::table('stylesPDF')->insertGetId(
123 array('label' => $change->label, 'style' => 'a:3:{s:11:"font-family";s:11:"TradeGothic";s:9:"font-size";s:2:"14";s:10:"font-color";s:14:"cmyk 0 0 0.5 0";}')
124 );
125
126 $idchangesPDF = DB::table('changesPDF')->insertGetId(
127 array('PDF_idPDF' => $pdfId, 'change_typePDF_idchange_typePDF' => $change->idchange_typePDF, 'stylesPDF_idstylesPDF' => $idstylesPDF, 'locationUp' => $change->locationUp, 'locationRight' => $change->locationRight, 'pages' => $change->pages, 'content' => $content, 'z-index' => '')
128 );
129
130 }
131
132 return $pdfId;
133
134
135 }
90 136
91 } 137 }
......
This diff could not be displayed because it is too large.
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type