Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
mherbold committed Nov 6, 2015
1 parent e355df4 commit d1349d9
Show file tree
Hide file tree
Showing 5 changed files with 321 additions and 0 deletions.
13 changes: 13 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$uploads_dir = "uploads/";
$thumbnails_dir = "uploads/thumbnails/";
$thumbnail_width = 90;
$thumbnail_height = 90;

/* modify only lines above this point to configure the php back end for your server */

$hostname = ( isset( $_SERVER[ "HTTPS" ] ) ? "https" : "http" ) . "://" . $_SERVER[ "SERVER_NAME" ];

$uploads_url = $hostname . dirname( dirname( $_SERVER[ "PHP_SELF" ] ) ) . "/" . $uploads_dir;
$thumbnails_url = $hostname . dirname( dirname( $_SERVER[ "PHP_SELF" ] ) ) . "/" . $thumbnails_dir;
48 changes: 48 additions & 0 deletions dl/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

chdir( ".." );

require( "config.php" );

switch ( $_POST[ "action" ] )
{
case "download":
{
header( "Content-Type: application/force-download" );
header( "Content-Disposition: attachment; filename=\"" . $_POST[ "filename" ] . "\"" );
header( "Content-Length: " . strlen( $_POST[ "html" ] ) );

echo $_POST[ "html" ];

break;
}

case "email":
{
$to = $_POST[ "rcpt" ];
$subject = $_POST[ "subject" ];
$message = $_POST[ "html" ];

$headers = array();

$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=iso-8859-1";
$headers[] = "To: $to";
$headers[] = "Subject: $subject";

$headers = implode( "\r\n", $headers );

if ( mail( $to, $subject, $message, $headers ) === FALSE )
{
header( $_SERVER[ "SERVER_PROTOCOL" ] . " 500 Internal Server Error" );

echo "ERR";
}
else
{
echo "OK: Mail sent.";
}

break;
}
}
56 changes: 56 additions & 0 deletions editor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=1024, initial-scale=1">
<link rel="canonical" href="http://mosaico.io" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="icon" href="/favicon.ico" type="image/x-icon" />

<script src="dist/vendor/knockout.js"></script>
<script src="dist/vendor/jquery.min.js"></script>
<script src="dist/vendor/jquery-ui.min.js"></script>
<script src="dist/vendor/jquery.ui.touch-punch.min.js"></script>
<script src="dist/vendor/load-image.all.min.js"></script>
<script src="dist/vendor/canvas-to-blob.min.js"></script>
<script src="dist/vendor/jquery.iframe-transport.js"></script>
<script src="dist/vendor/jquery.fileupload.js"></script>
<script src="dist/vendor/jquery.fileupload-process.js"></script>
<script src="dist/vendor/jquery.fileupload-image.js"></script>
<script src="dist/vendor/jquery.fileupload-validate.js"></script>
<script src="dist/vendor/knockout-jqueryui.min.js"></script>
<script src="dist/vendor/evol.colorpicker.min.js"></script>
<script src="dist/vendor/tinymce.min.js"></script>

<script src="dist/mosaico.min.js?v=0.11"></script>
<script>
$(function() {
if (!Mosaico.isCompatible()) {
alert('Update your browser!');
return;
}
var webpath = window.location.href.substr(0, window.location.href.lastIndexOf('/'));
var ok = Mosaico.init({
imgProcessorBackend: webpath + '/img',
emailProcessorBackend: webpath + '/dl/',
titleToken: "MOSAICO Responsive Email Designer",
fileuploadConfig: {
url: webpath + '/upload/',
// messages??
}
});
if (!ok) {
console.log("Missing initialization hash, redirecting to main entrypoint");
document.location = ".";
}
});
</script>

<link rel="stylesheet" href="dist/mosaico-material.min.css?v=0.10" />
<link rel="stylesheet" href="dist/vendor/notoregular/stylesheet.css" />
<link rel="stylesheet" href="dist/vendor/evol.colorpicker.min.css" /> <!-- 2k -->
</head>
<body class="mo-standalone">


</body>
</html>
131 changes: 131 additions & 0 deletions img/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

chdir( ".." );

require( "config.php" );

if ( $_SERVER[ "REQUEST_METHOD" ] == "GET" )
{
$params = explode( ",", $_GET[ "params" ] );

$width = (int) $params[ 0 ];
$height = (int) $params[ 1 ];

if ( $_GET[ "method" ] == "placeholder" )
{
$image = new Imagick();

$image->newImage( $width, $height, "#707070" );

$image->setImageFormat( "png" );

$x = 0;
$y = 0;
$size = 40;

$draw = new ImagickDraw();

while ( $y < $height )
{
$draw->setFillColor( "#808080" );

$points = [
[ "x" => $x, "y" => $y ],
[ "x" => $x + $size, "y" => $y ],
[ "x" => $x + $size * 2, "y" => $y + $size ],
[ "x" => $x + $size * 2, "y" => $y + $size * 2 ]
];

$draw->polygon( $points );

$points = [
[ "x" => $x, "y" => $y + $size ],
[ "x" => $x + $size, "y" => $y + $size * 2 ],
[ "x" => $x, "y" => $y + $size * 2 ]
];

$draw->polygon( $points );

$x += $size * 2;

if ( $x > $width )
{
$x = 0;
$y += $size * 2;
}
}

$draw->setFillColor( "#B0B0B0" );
$draw->setFontSize( 20 );
$draw->setGravity( Imagick::GRAVITY_CENTER );
$draw->annotation( 0, 0, $width . " x " . $height );

$image->drawImage( $draw );

header( "Content-type: image/png" );

echo $image;
}
else
{
$file_name = $_GET[ "src" ];

$path_parts = pathinfo( $file_name );

switch ( $path_parts[ "extension" ] )
{
case "png":
$mime_type = "image/png";
break;

case "gif":
$mime_type = "image/gif";
break;

default:
$mime_type = "image/jpeg";
break;
}

$file_name = $path_parts[ "basename" ];

$image = new Imagick( realpath( $uploads_dir . $file_name ) );

if ( $_GET[ "method" ] == "resize" )
{
$image->resizeImage( $width, $height, Imagick::FILTER_LANCZOS, 0 );
}
else // $_GET[ "method" ] == "cover"
{
$image_geometry = $image->getImageGeometry();

$width_ratio = $image_geometry[ "width" ] / $width;
$height_ratio = $image_geometry[ "height" ] / $height;

$resize_width = $width;
$resize_height = $height;

if ( $width_ratio > $height_ratio )
{
$resize_width = 0;
}
else
{
$resize_height = 0;
}

$image->resizeImage( $resize_width, $resize_height, Imagick::FILTER_LANCZOS, 0 );

$image_geometry = $image->getImageGeometry();

$x = ( $image_geometry[ "width" ] - $width ) / 2;
$y = ( $image_geometry[ "height" ] - $height ) / 2;

$image->cropImage( $width, $height, $x, $y );
}

header( "Content-type: " . $mime_type );

echo $image;
}
}
73 changes: 73 additions & 0 deletions upload/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

chdir( ".." );

require( "config.php" );

if ( $_SERVER[ "REQUEST_METHOD" ] == "GET" )
{
$files = array();

$dir = scandir( $uploads_dir );

foreach ( $dir as $file_name )
{
if ( is_file( $uploads_dir . $file_name ) )
{
$file = array(
"name" => $file_name,
"url" => $uploads_url . $file_name,
"size" => filesize( $uploads_dir . $file_name )
);

if ( file_exists( realpath( $thumbnails_dir . $file_name ) ) )
{
$file[ "thumbnailUrl" ] = $thumbnails_url . $file_name;
}

$files[] = $file;
}
}

header( "Content-Type: application/json; charset=utf-8" );
header( "Connection: close" );

echo json_encode( array( "files" => $files ) );
}
else if ( !empty( $_FILES ) )
{
$files = array();

foreach ( $_FILES[ "files" ][ "error" ] as $key => $error )
{
if ( $error == UPLOAD_ERR_OK )
{
$tmp_name = $_FILES[ "files" ][ "tmp_name" ][ $key ];

$file_name = $_FILES[ "files" ][ "name" ][ $key ];

if ( move_uploaded_file( $tmp_name, $uploads_dir . $file_name ) === TRUE )
{
$image = new Imagick( realpath( $uploads_dir . $file_name ) );

$image->resizeImage( $thumbnail_width, $thumbnail_height, Imagick::FILTER_LANCZOS, 0, TRUE );
$image->writeImage( realpath( $thumbnails_dir ) . "/". $file_name );
$image->destroy();

$file = array(
"name" => $file_name,
"url" => $uploads_url . $file_name,
"size" => filesize( $uploads_dir . $file_name ),
"thumbnailUrl" => $thumbnails_url . $file_name
);

$files[] = $file;
}
}
}

header( "Content-Type: application/json; charset=utf-8" );
header( "Connection: close" );

echo json_encode( array( "files" => $files ) );
}

0 comments on commit d1349d9

Please sign in to comment.