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

[CLEANUP] Use spaces instead of tabs for indentation. #9

Merged
merged 1 commit into from
Jan 21, 2014
Merged
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
290 changes: 145 additions & 145 deletions emogrifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,88 +41,88 @@
define('CACHE_XPATH', 2);

class Emogrifier {
/**
* for calculating nth-of-type and nth-child selectors
*
* @var integer
*/
const INDEX = 0;

/**
* for calculating nth-of-type and nth-child selectors
*
* @var integer
*/
/**
* for calculating nth-of-type and nth-child selectors
*
* @var integer
*/
const INDEX = 0;

/**
* for calculating nth-of-type and nth-child selectors
*
* @var integer
*/
const MULTIPLIER = 1;

/**
* @var string
*/
private $html = '';
/**
* @var string
*/
private $html = '';

/**
* @var string
*/
/**
* @var string
*/
private $css = '';

/**
* @var array<string>
*/
/**
* @var array<string>
*/
private $unprocessableHTMLTags = array('wbr');

/**
* @var array<array>
*/
/**
* @var array<array>
*/
private $caches = array();

/**
* This attribute applies to the case where you want to preserve your original text encoding.
*
* By default, emogrifier translates your text into HTML entities for two reasons:
*
* 1. Because of client incompatibilities, it is better practice to send out HTML entities rather than unicode over email.
*
* 2. It translates any illegal XML characters that DOMDocument cannot work with.
*
* If you would like to preserve your original encoding, set this attribute to true.
*
* @var boolean
*/
public $preserveEncoding = false;

/**
* @param string $html
* @param string $css
*/
public function __construct($html = '', $css = '') {
/**
* This attribute applies to the case where you want to preserve your original text encoding.
*
* By default, emogrifier translates your text into HTML entities for two reasons:
*
* 1. Because of client incompatibilities, it is better practice to send out HTML entities rather than unicode over email.
*
* 2. It translates any illegal XML characters that DOMDocument cannot work with.
*
* If you would like to preserve your original encoding, set this attribute to true.
*
* @var boolean
*/
public $preserveEncoding = false;

/**
* @param string $html
* @param string $css
*/
public function __construct($html = '', $css = '') {
$this->html = $html;
$this->css = $css;
$this->clearCache();
}

/**
* @param string $html
*
* @return void
*/
public function setHTML($html = '') { $this->html = $html; }

/**
* @param string $css
*
* @return void
*/
public function setCSS($css = '') {
/**
* @param string $html
*
* @return void
*/
public function setHTML($html = '') { $this->html = $html; }

/**
* @param string $css
*
* @return void
*/
public function setCSS($css = '') {
$this->css = $css;
$this->clearCache(CACHE_CSS);
}

/**
* @param integer|null $key
*
* @return void
*/
public function clearCache($key = null) {
/**
* @param integer|null $key
*
* @return void
*/
public function clearCache($key = null) {
if (!is_null($key)) {
if (isset($this->caches[$key])) $this->caches[$key] = array();
} else {
Expand All @@ -134,45 +134,45 @@ public function clearCache($key = null) {
}
}

/**
* There are some HTML tags that DOMDocument cannot process, and it will throw an error if it encounters them.
* In particular, DOMDocument will complain if you try to use HTML5 tags in an XHTML document.
*
* This method allows you to add them if necessary.
*
* It only strips them from the code (i.e., it does not actually remove any nodes).
*
* @param string $tag
*
* @return void
*/
public function addUnprocessableHTMLTag($tag) { $this->unprocessableHTMLTags[] = $tag; }

/**
* There are some HTML tags that DOMDocument cannot process, and it will throw an error if it encounters them.
* In particular, DOMDocument will complain if you try to use HTML5 tags in an XHTML document.
*
* This method allows you to remove them if necessary.
*
* It only strips them from the code (i.e., it does not actually remove any nodes).
*
* @param string $tag
*
* @return void
*/
/**
* There are some HTML tags that DOMDocument cannot process, and it will throw an error if it encounters them.
* In particular, DOMDocument will complain if you try to use HTML5 tags in an XHTML document.
*
* This method allows you to add them if necessary.
*
* It only strips them from the code (i.e., it does not actually remove any nodes).
*
* @param string $tag
*
* @return void
*/
public function addUnprocessableHTMLTag($tag) { $this->unprocessableHTMLTags[] = $tag; }

/**
* There are some HTML tags that DOMDocument cannot process, and it will throw an error if it encounters them.
* In particular, DOMDocument will complain if you try to use HTML5 tags in an XHTML document.
*
* This method allows you to remove them if necessary.
*
* It only strips them from the code (i.e., it does not actually remove any nodes).
*
* @param string $tag
*
* @return void
*/
public function removeUnprocessableHTMLTag($tag) {
if (($key = array_search($tag,$this->unprocessableHtmlTags)) !== false)
unset($this->unprocessableHtmlTags[$key]);
}

/**
* Applies the CSS you submit to the HTML you submit.
*
* This method places the CSS inline.
*
* @return string
*/
public function emogrify() {
/**
* Applies the CSS you submit to the HTML you submit.
*
* This method places the CSS inline.
*
* @return string
*/
public function emogrify() {
$body = $this->html;

// remove any unprocessable HTML tags (tags that DOMDocument cannot parse; this includes wbr and many new HTML5 tags)
Expand Down Expand Up @@ -327,13 +327,13 @@ public function emogrify() {
}
}

/**
* @param array $a
* @param array $b
*
* @return integer
*/
private function sortBySelectorPrecedence(array $a, array $b) {
/**
* @param array $a
* @param array $b
*
* @return integer
*/
private function sortBySelectorPrecedence(array $a, array $b) {
$precedenceA = $this->getCSSSelectorPrecedence($a['selector']);
$precedenceB = $this->getCSSSelectorPrecedence($b['selector']);

Expand All @@ -342,12 +342,12 @@ private function sortBySelectorPrecedence(array $a, array $b) {
return ($precedenceA == $precedenceB) ? ($a['line'] < $b['line'] ? -1 : 1) : ($precedenceA < $precedenceB ? -1 : 1);
}

/**
* @param string $selector
*
* @return integer
*/
private function getCSSSelectorPrecedence($selector) {
/**
* @param string $selector
*
* @return integer
*/
private function getCSSSelectorPrecedence($selector) {
$selectorkey = md5($selector);
if (!isset($this->caches[CACHE_SELECTOR][$selectorkey])) {
$precedence = 0;
Expand All @@ -367,16 +367,16 @@ private function getCSSSelectorPrecedence($selector) {
return $this->caches[CACHE_SELECTOR][$selectorkey];
}

/**
* Right now, we support all CSS 1 selectors and most CSS2/3 selectors.
*
* @see http://plasmasturm.org/log/444/
*
* @param string $css_selector
*
* @return string
*/
private function translateCSStoXpath($css_selector) {
/**
* Right now, we support all CSS 1 selectors and most CSS2/3 selectors.
*
* @see http://plasmasturm.org/log/444/
*
* @param string $css_selector
*
* @return string
*/
private function translateCSStoXpath($css_selector) {

$css_selector = trim($css_selector);
$xpathkey = md5($css_selector);
Expand Down Expand Up @@ -418,12 +418,12 @@ private function translateCSStoXpath($css_selector) {
return $this->caches[CACHE_SELECTOR][$xpathkey];
}

/**
* @param array $match
*
* @return string
*/
private function translateNthChild(array $match) {
/**
* @param array $match
*
* @return string
*/
private function translateNthChild(array $match) {

$result = $this->parseNth($match);

Expand All @@ -439,12 +439,12 @@ private function translateNthChild(array $match) {
}
}

/**
* @param array $match
*
* @return string
*/
private function translateNthOfType(array $match) {
/**
* @param array $match
*
* @return string
*/
private function translateNthOfType(array $match) {

$result = $this->parseNth($match);

Expand All @@ -460,12 +460,12 @@ private function translateNthOfType(array $match) {
}
}

/**
* @param array $match
*
* @return array
*/
private function parseNth(array $match) {
/**
* @param array $match
*
* @return array
*/
private function parseNth(array $match) {

if (in_array(strtolower($match[2]), array('even','odd'))) {
$index = strtolower($match[2]) == 'even' ? 0 : 1;
Expand Down Expand Up @@ -496,12 +496,12 @@ private function parseNth(array $match) {
}
}

/**
* @param string $style
*
* @return array
*/
private function cssStyleDefinitionToArray($style) {
/**
* @param string $style
*
* @return array
*/
private function cssStyleDefinitionToArray($style) {
$definitions = explode(';',$style);
$retArr = array();
foreach ($definitions as $def) {
Expand Down