Created
May 7, 2013 17:09
-
-
Save jimthedev/5534306 to your computer and use it in GitHub Desktop.
Command line wrapper for emogrifier written in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* DETECT CLI MODE */ | |
if ( isset($_SERVER['argc']) && $_SERVER['argc']>=1 ) { | |
/* CHECK FOR EMOGRIFIER.PHP */ | |
if(!file_exists(dirname(__FILE__).'/emogrifier.php')) { | |
quit(1,"emogrifier.php is missing."); | |
} | |
require_once(dirname(__FILE__).'/emogrifier.php'); | |
/* Make sure we have the right number of arguments */ | |
if(is_array($argv) && count($argv)>=3 && count($argv)<5) { | |
/* Check if the files exist */ | |
if(!file_exists($argv[1]) || !file_exists($argv[2])) { | |
quit(1,"Either the HTML or CSS file doesn't exist!"); | |
} | |
$html = file_get_contents('./'.$argv[1]); | |
$css = preg_replace("/\s+/", " ", file_get_contents('./'.$argv[2])); | |
$emo = new emogrifier($html,$css); | |
if(count($argv)>3 && $argv[3] !=='') { | |
file_put_contents($argv[3], $emo->emogrify()); | |
exit(0); | |
} else { | |
echo("" . $emo->emogrify()); | |
exit(0); | |
} | |
} else { | |
quit(1,"Error: Wrong number of arguments!"); | |
} | |
} else { | |
quit(1,"This script is meant to run in command line mode."); | |
} | |
/* Helper function used to quit gracefully */ | |
function quit($code,$msg) { | |
printf("\n".$msg . "\n\n"); | |
exit($code); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment