Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate https://github.com/christiaan/InlineStyle #7

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mosaico-php-backend.iml
autoload.php
vendor
composer.phar
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@ This is a PHP backend for Mosaico

Mosaico can be found at https://github.com/voidlabs/mosaico

First, install and set up Mosaico. Then install these files on top of the Mosaico installation.
## Getting started

1. install and set up Mosaico
2. copy `mosaico/dist` to your webserver, e.g. to `myserver/mosaico/dist`
3. copy `mosaico/templates` to youer webserver, e.g. to `myserver/mosaico/templates`
4. copy `index.html`, `editor.html`, `dl`, `img`, `upload` from this project on top of the Mosaico installation e.g. `myserver/mosaico/*`
5. run `php composer.phar install` if you want to use InlineStyle on your server. (See https://getcomposer.org/doc/00-intro.md how to get and use composer.)
You can do this offline and copy `vendor`to e.g. `myserver/mosaico`; The results of this installation are not checked in to this project.
6. adapt `config.php` according to your needs and copy it to e.g. `myserver/mosaico`
7. goto `{url of your server}/mosaico`


## Dependencies

You do need to have Imagemagick support enabled in your PHP configuration.

This project also requires Premailer (http://premailer.dialect.ca/). Premailer is used to inline the CSS styles. If that service is ever taken down, we will have to find an alternate solution. Or, if you have an alternate solution that does not require dependencies on a web service, feel free to contribute!

Alternatively you can use InlineStyle (https://github.com/christiaan/InlineStyle) which runs ony your own server. You need to install it via composer. This is experimental, we will have to investigate if it works well with mosaico.

## New folders and files
```
config.php
Expand Down Expand Up @@ -45,3 +57,5 @@ This example file has been slightly modified.
1) The leading slashes in the three paths to the back end (/dl, /img, and /upload) has been removed so that Mosaico can be used in subfolders and not have to be at the root.

2) Trailing slashes have been added to /dl and /upload to avoid 301 redirects which Mosaico does not handle well. The /img backend path here does not need a trailing slash added because the Mosaico code already adds one when this is used.

# Getting started
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": {
"inlinestyle/inlinestyle": "^1.2"
}
}
119 changes: 119 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
$thumbnails_dir = "uploads/thumbnails/";
$thumbnail_width = 90;
$thumbnail_height = 90;
$style_inliner = 'inlinestyle'; // 'premailer' | 'inlinestyle'

60 changes: 40 additions & 20 deletions dl/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,36 @@

chdir( ".." );

require( "config.php" );
require( "dl/premailer.php" );

/* run this puppy through premailer */

require( "config.php" );

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

$premailer = Premailer::html( $_POST[ "html" ], true, "hpricot", $base_url );
use \InlineStyle\InlineStyle;

switch($style_inliner){
/* run this puppy through premailer */

case 'premailer':
require( "dl/premailer.php" );
$premailer = Premailer::html( $_POST[ "html" ], false, "hpricot", $base_url );
$html = $premailer[ "html" ];
break;

case 'inlinestyler':
require 'vendor/autoload.php';
$htmldoc = new InlineStyle($_POST["html"]);
$htmldoc->applyStylesheet($htmldoc->extractStylesheets());
$html = $htmldoc->getHTML();
break;

default:
$html = $_POST["html"];
}



$html = $premailer[ "html" ];

/* create static versions of resized images */

Expand All @@ -25,20 +45,20 @@
{
$file_name = urldecode( $src_matches[ 1 ] );
$file_name = substr( $file_name, strlen( $uploads_dir ) );

$method = urldecode( $src_matches[ 2 ] );

$params = urldecode( $src_matches[ 3 ] );
$params = explode( ",", $params );
$width = (int) $params[ 0 ];
$height = (int) $params[ 1 ];
$static_file_name = $static_dir . $method . "_" . $width . "x" . $height . "_" . $file_name;
$html = str_ireplace( $matches[ 1 ][ $i ], $base_url . urlencode( $static_file_name ), $html );

$static_file_name = $static_dir . $method . "_" . $width . "x" . $height . "_" . urlencode( $file_name );

$html = str_ireplace( $matches[ 1 ][ $i ], $base_url . $static_file_name, $html );

require( "img/resize.php" );

$image->writeImage( $static_file_name );
}
}
Expand All @@ -53,30 +73,30 @@
header( "Content-Type: application/force-download" );
header( "Content-Disposition: attachment; filename=\"" . $_POST[ "filename" ] . "\"" );
header( "Content-Length: " . strlen( $html ) );

echo $html;

break;
}

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

$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, $html, $headers ) === FALSE )
{
header( $_SERVER[ "SERVER_PROTOCOL" ] . " 500 Internal Server Error" );

echo "ERR";
}
else
Expand Down
1 change: 1 addition & 0 deletions editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<title>HTML Email Editor</title>
<meta name="viewport" content="width=1024, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<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" />
Expand Down