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] Clean up the indentation levels. #22

Merged
merged 1 commit into from
Jan 23, 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
57 changes: 28 additions & 29 deletions emogrifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,36 +375,35 @@ private function translateCSStoXpath($css_selector) {
if (!isset($this->caches[CACHE_XPATH][$xpathkey])) {
// returns an Xpath selector
$search = array(
// Matches any element that is a child of parent.
'/\\s+>\\s+/',
// Matches any element that is an adjacent sibling.
'/\\s+\\+\\s+/',
// Matches any element that is a descendant of an parent element element.
'/\\s+/',
// first-child pseudo-selector
'/([^\\/]+):first-child/i',
// last-child pseudo-selector
'/([^\\/]+):last-child/i',
// Matches element with attribute
'/(\\w)\\[(\\w+)\\]/',
// Matches element with EXACT attribute
'/(\\w)\\[(\\w+)\\=[\'"]?(\\w+)[\'"]?\\]/',
// Matches id attributes
'/(\\w+)?\\#([\\w\\-]+)/e',
// Matches class attributes
'/(\\w+|[\\*\\]])?((\\.[\\w\\-]+)+)/e',

// Matches any element that is a child of parent.
'/\\s+>\\s+/',
// Matches any element that is an adjacent sibling.
'/\\s+\\+\\s+/',
// Matches any element that is a descendant of an parent element element.
'/\\s+/',
// first-child pseudo-selector
'/([^\\/]+):first-child/i',
// last-child pseudo-selector
'/([^\\/]+):last-child/i',
// Matches element with attribute
'/(\\w)\\[(\\w+)\\]/',
// Matches element with EXACT attribute
'/(\\w)\\[(\\w+)\\=[\'"]?(\\w+)[\'"]?\\]/',
// Matches id attributes
'/(\\w+)?\\#([\\w\\-]+)/e',
// Matches class attributes
'/(\\w+|[\\*\\]])?((\\.[\\w\\-]+)+)/e',
);
$replace = array(
'/',
'/following-sibling::*[1]/self::',
'//',
'*[1]/self::\\1',
'*[last()]/self::\\1',
'\\1[@\\2]',
'\\1[@\\2="\\3"]',
"(strlen('\\1') ? '\\1' : '*').'[@id=\"\\2\"]'",
"(strlen('\\1') ? '\\1' : '*').'[contains(concat(\" \",@class,\" \"),concat(\" \",\"'.implode('\",\" \"))][contains(concat(\" \",@class,\" \"),concat(\" \",\"',explode('.',substr('\\2',1))).'\",\" \"))]'",
'/',
'/following-sibling::*[1]/self::',
'//',
'*[1]/self::\\1',
'*[last()]/self::\\1',
'\\1[@\\2]',
'\\1[@\\2="\\3"]',
"(strlen('\\1') ? '\\1' : '*').'[@id=\"\\2\"]'",
"(strlen('\\1') ? '\\1' : '*').'[contains(concat(\" \",@class,\" \"),concat(\" \",\"'.implode('\",\" \"))][contains(concat(\" \",@class,\" \"),concat(\" \",\"',explode('.',substr('\\2',1))).'\",\" \"))]'",
);

$css_selector = '//'.preg_replace($search, $replace, $css_selector);
Expand Down Expand Up @@ -468,8 +467,8 @@ private function parseNth(array $match) {
if (in_array(strtolower($match[2]), array('even','odd'))) {
$index = strtolower($match[2]) == 'even' ? 0 : 1;
return array(self::MULTIPLIER => 2, self::INDEX => $index);
// if there is a multiplier
} elseif (stripos($match[2], 'n') === FALSE) {
// if there is a multiplier
$index = intval(str_replace(' ', '', $match[2]));
return array(self::INDEX => $index);
} else {
Expand Down