35db7fbc by Jeff Balicki

commit

1 parent 1469375f
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers;
use App\pdfModel;
use URL;
use Storage;
use Response;
use File;
Use PDF;
use Illuminate\Support\Facades\Input;
use Intervention\Image\Facades\Image;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\Response;
use League\Flysystem\Filesystem;
use App\File;
class FilesController extends Controller
{
/**
* Previews an image if possible.
*
* @param File $file
* @return mixed
* @internal param $id
*/
public function preview(File $file)
{
$path = storage_path('app/') . $file->path . $file->name_thumbnail;
$handler = new \Symfony\Component\HttpFoundation\File\File($path);
$lifetime = 31556926; // One year in seconds
/**
* Prepare some header variables
*/
$file_time = $handler->getMTime(); // Get the last modified time for the file (Unix timestamp)
$header_content_type = $handler->getMimeType();
$header_content_length = $handler->getSize();
$header_etag = md5($file_time . $path);
$header_last_modified = gmdate('r', $file_time);
$header_expires = gmdate('r', $file_time + $lifetime);
$headers = array(
'Content-Disposition' => 'inline; filename="' . $file->name_thumbnail . '"',
'Last-Modified' => $header_last_modified,
'Cache-Control' => 'must-revalidate',
'Expires' => $header_expires,
'Pragma' => 'public',
'Etag' => $header_etag
);
/**
* Is the resource cached?
*/
$h1 = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $header_last_modified;
$h2 = isset($_SERVER['HTTP_IF_NONE_MATCH']) && str_replace('"', '', stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) == $header_etag;
if ($h1 || $h2) {
return Response::make('', 304, $headers); // File (image) is cached by the browser, so we don't have to send it again
}
$headers = array_merge($headers, array(
'Content-Type' => $header_content_type,
'Content-Length' => $header_content_length
));
return Response::make(file_get_contents($path), 200, $headers);
}
}
\ No newline at end of file
......@@ -28,6 +28,7 @@ Route::group(array('prefix' => 'api/v1'), function($json)
Route::resource('api', 'ApiController@getApi');
});
Route::get('files/{file}/preview', ['as' => 'file_preview', 'uses' => 'FilesController@preview']);
//Route::resource('js/interface.js', function () {
// return asset('js/interface.js');
......
<SCRIPT LANGUAGE="JavaScript">
function pickPdfFromList(){
var strVar="";
strVar += "<link rel=\"stylesheet\" href=\"http:\/\/dhbhdrzi4tiry.cloudfront.net\/cdn\/sites\/foundation.min.css\">";
strVar += " <link href=\"http:\/\/cdnjs.cloudflare.com\/ajax\/libs\/foundicons\/3.0.0\/foundation-icons.css\" rel=\"stylesheet\" type=\"text\/css\">";
strVar += " <script src=\"https:\/\/code.jquery.com\/jquery-2.2.3.min.js\" integrity=\"sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=\" crossorigin=\"anonymous\"><\/script>";
var json = [{"idPDF":14,"name":"SISKINDS_test file","folder":"SISKINDS_test","file":"SISKINDS_test_file.pdf","image":"SISKINDS_test_file.jpg","custId":1,"apiCallId":3},{"idPDF":27,"name":"test file","folder":"SISKINDStest-file","file":"pdf-sample.pdf","image":"pdf-sample.jpg","custId":1,"apiCallId":25}];
var i;
var pdflist ="";
for (i = 0; i < json.length; ++i) {
pdflist += "<div class=\"column\">";
pdflist += ' <img class=\"thumbnail\" src="/Applications/MAMP/htdocs/pdfEdit/storage/app/public/'+json[i].folder+'/'+json[i].image+'" height=\"270px\">';
pdflist += " <h5>"+json[i].name+"<\/h5>";
pdflist += "<\/div>";
}
strVar += " <link rel=\"stylesheet\" href=\"http:\/\/dhbhdrzi4tiry.cloudfront.net\/cdn\/sites\/foundation.min.css\">";
strVar += "<div class=\"off-canvas-wrapper\">";
strVar += " <div class=\"off-canvas-wrapper-inner\" data-off-canvas-wrapper>";
strVar += " <div class=\"off-canvas position-left reveal-for-large\" id=\"my-info\" data-off-canvas data-position=\"left\">";
strVar += " <div class=\"row column\">";
strVar += " <br>";
strVar += " <img class=\"thumbnail\" src=\"http:\/\/placehold.it\/550x350\">";
strVar += " <\/div>";
strVar += " <\/div>";
strVar += " <div class=\"off-canvas-content\" data-off-canvas-content>";
strVar += " <div class=\"title-bar hide-for-large\">";
strVar += " <div class=\"title-bar-left\">";
strVar += " <button class=\"menu-icon\" type=\"button\" data-open=\"my-info\"><\/button>";
strVar += " <span class=\"title-bar-title\">Synapsus<\/span>";
strVar += " <\/div>";
strVar += " <\/div>";
strVar += " <div class=\"callout primary\">";
strVar += " <div class=\"row column\">";
strVar += " <h1>Welcome to Synapsus Online PDF Editor<\/h1>";
strVar += " <p class=\"lead\">Lorem ipsum dolor sit amet, consectetur adipiscing elit.<\/p>";
strVar += " <\/div>";
strVar += " <\/div>";
strVar += " <div class=\"row small-up-2 medium-up-3 large-up-4\">";
strVar += pdflist;
strVar += " <\/div>";
strVar += " <hr>";
strVar += "";
strVar += " <\/div>";
strVar += " <\/div>";
strVar += " <\/div>";
strVar += " <\/div>";
strVar += "<\/div>";
strVar += "";
strVar += "<script src=\"http:\/\/dhbhdrzi4tiry.cloudfront.net\/cdn\/sites\/foundation.js\"><\/script>";
strVar += "<script>";
strVar += " $(document).foundation();";
strVar += "<\/script>";
strVar += "";
strVar += "";
}
function changePdfOptions(){
var strVar2="";
strVar2 += "<link rel=\"stylesheet\" href=\"http:\/\/dhbhdrzi4tiry.cloudfront.net\/cdn\/sites\/foundation.min.css\">";
strVar2 += " <link href=\"http:\/\/cdnjs.cloudflare.com\/ajax\/libs\/foundicons\/3.0.0\/foundation-icons.css\" rel=\"stylesheet\" type=\"text\/css\">";
strVar2 += " <script src=\"https:\/\/code.jquery.com\/jquery-2.2.3.min.js\" integrity=\"sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=\" crossorigin=\"anonymous\"><\/script>";
var json = [{"idPDF":14,"name":"test file","folder":"SISKINDS_test","file":"SISKINDS_test_file.pdf","image":"SISKINDS_test_file.jpg","custId":1,"apiCallId":3,"idchangesPDF":18,"PDF_idPDF":14,"change_typePDF_idchange_typePDF":1,"stylesPDF_idstylesPDF":18,"locationUp":"60","locationRight":290,"pages":"1","content":"519.660.2121 siskinds.com\/change","z-index":0,"idstylesPDF":18,"order":"1","label":"Text","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\";}","idchange_typePDF":1,"change_type":"text"},{"idPDF":14,"name":"test file","folder":"SISKINDS_test","file":"SISKINDS_test_file.pdf","image":"SISKINDS_test_file.jpg","custId":1,"apiCallId":3,"idchangesPDF":17,"PDF_idPDF":14,"change_typePDF_idchange_typePDF":2,"stylesPDF_idstylesPDF":17,"locationUp":"400","locationRight":90,"pages":"1","content":"siskins.png","z-index":0,"idstylesPDF":17,"order":"2","label":"Image","style":null,"idchange_typePDF":2,"change_type":"img"}];
var pdflist ="";
pdflist += "<div class=\"column\">";
pdflist += ' <img src=\"/Applications/MAMP/htdocs/pdfEdit/storage/app/public/'+json[0].folder+'/'+json[0].image+'\" width=\"300px\">';
pdflist += "<\/div>";
var pdfChange="<br>";
pdfChange += "<form id=\"changes\" action=\"\"><h4>" + json[0].name+"</h4>";
for (i = 0; i < json.length; ++i) {
if(json[i].change_type == "text"){
pdfChange += " Text: <input id=\"content"+i+"\" type=\"text\" name=\"content"+i+"\" value=\""+json[i].content+"\">";
}if(json[i].change_type == "img"){
pdfChange += " <input type=\"hidden\" id=\"content"+i+"\" name=\"content"+i+"\" value=\""+json[i].content+"\">";
pdfChange += " Image: <input id=\"content"+i+"\" style=\"display: block; box-sizing: border-box; width: 100%; height: 2.4375rem; padding: .5rem; border: 1px solid #cacaca; margin: 0 0 1rem; font-family: inherit; font-size: 1rem; color: #8a8a8a; background-color: #fefefe; box-shadow: inset 0 1px 2px rgba(10,10,10,.1); border-radius: 0; transition: box-shadow .5s,border-color .25s ease-in-out; -webkit-appearance: none; -moz-appearance: none;\" type=\"file\" name=\"content"+i+"\" value=\""+json[i].content+"\">";
}
}
pdfChange += " <input type=\"submit\" value=\"Submit\">";
pdfChange += "<\/form>";
strVar2 += " <link rel=\"stylesheet\" href=\"http:\/\/dhbhdrzi4tiry.cloudfront.net\/cdn\/sites\/foundation.min.css\">";
strVar2 += "<div class=\"off-canvas-wrapper\">";
strVar2 += " <div class=\"off-canvas-wrapper-inner\" data-off-canvas-wrapper>";
strVar2 += " <div class=\"off-canvas position-left reveal-for-large\" id=\"my-info\" data-off-canvas data-position=\"left\">";
strVar2 += " <div class=\"row column\">";
strVar2 += " <br>";
strVar2 += " <img class=\"thumbnail\" src=\"http:\/\/placehold.it\/550x350\">";
strVar2 += " <\/div>";
strVar2 += " <\/div>";
strVar2 += " <div class=\"off-canvas-content\" data-off-canvas-content>";
strVar2 += " <div class=\"title-bar hide-for-large\">";
strVar2 += " <div class=\"title-bar-left\">";
strVar2 += " <button class=\"menu-icon\" type=\"button\" data-open=\"my-info\"><\/button>";
strVar2 += " <span class=\"title-bar-title\">Synapsus<\/span>";
strVar2 += " <\/div>";
strVar2 += " <\/div>";
strVar2 += " <div class=\"callout primary\">";
strVar2 += " <div class=\"row column\">";
strVar2 += " <h1>Welcome to Synapsus Online PDF Editor<\/h1>";
strVar2 += " <p class=\"lead\">Lorem ipsum dolor sit amet, consectetur adipiscing elit.<\/p>";
strVar2 += " <\/div>";
strVar2 += " <\/div>";
strVar2 += " <div class=\"row small-up-2 medium-up-3 large-up-3\">";
strVar2 += pdflist+"<div class=\"column\">"+pdfChange+"<\/div>";
strVar2 += " <\/div>";
strVar2 += " <hr>";
strVar2 += "";
strVar2 += " <\/div>";
strVar2 += " <\/div>";
strVar2 += " <\/div>";
strVar2 += " <\/div>";
strVar2 += "<\/div>";
strVar2 += "";
strVar2 += "<script src=\"http:\/\/dhbhdrzi4tiry.cloudfront.net\/cdn\/sites\/foundation.js\"><\/script>";
strVar2 += "<script>";
strVar2 += " $(document).foundation();";
strVar2 += "<\/script>";
strVar2 += "";
strVar2 += "";
}
function returnOptions(){
var jsonReturn = '{"pdf":[{"name":"'+json[0].name+'", "folder":"'+json[0].name+'", "pdfLocation":""}],"changes":['
for (i = 0; i < json.length; ++i) {
jsonReturn +='{"label":"'+json[i].label+'", "locationUp":"'+json[i].locationUp+'", "locationRight":"'+json[i].locationRight+'", "pages":"'+json[i].pages+'", "content":"'+json[i].content+'", "z-index":null, "idstylesPDF":"'+json[i].idstylesPDF, "order":"'+json[i].order, "style":"'+json[i].style, "idchange_typePDF":"'+json[i].idchange_typePDF+'", "change_type":"'+json[i].change_type+'", "fileLocation":""}';
}
jsonReturn +=' }]}';
}
</script>
\ No newline at end of file
No preview for this file type
No preview for this file type