@ -1,7 +1,10 @@
|
||||
<?php namespace MailPoet\Newsletter\Renderer;
|
||||
<?php
|
||||
namespace MailPoet\Newsletter\Renderer;
|
||||
|
||||
use MailPoet\Newsletter\Renderer\Columns\ColumnsHelper;
|
||||
|
||||
class StylesHelper {
|
||||
public $cssAtributesTable = array(
|
||||
static $cssAttributesTable = array(
|
||||
'backgroundColor' => 'background-color',
|
||||
'fontColor' => 'color',
|
||||
'fontFamily' => 'font-family',
|
||||
@ -14,26 +17,234 @@ class StylesHelper {
|
||||
'borderRadius' => 'border-radius',
|
||||
'lineHeight' => 'line-height'
|
||||
);
|
||||
|
||||
function getBlockStyles($element, $ignoreSpecificStyles = false) {
|
||||
if(!isset($element['styles']['block'])) {
|
||||
static $font = array(
|
||||
'Arial' => "Arial, 'Helvetica Neue', Helvetica, sans-serif",
|
||||
'Comic Sans MS' => "'Comic Sans MS', 'Marker Felt-Thin', Arial, sans-serif",
|
||||
'Courier New' => "'Courier New', Courier, 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace",
|
||||
'Georgia' => "Georgia, Times, 'Times New Roman', serif",
|
||||
'Lucida' => "'Lucida Sans Unicode', 'Lucida Grande', sans-serif",
|
||||
'Tahoma' => "Tahoma, Verdana, Segoe, sans-serif",
|
||||
'Times New Roman' => "'Times New Roman', Times, Baskerville, Georgia, serif",
|
||||
'Trebuchet MS' => "'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Tahoma, sans-serif",
|
||||
'Verdana' => "Verdana, Geneva, sans-serif"
|
||||
);
|
||||
static $fontSize = array(
|
||||
// fontSize => array(columnCount => lineHeight);
|
||||
8 => array(
|
||||
1 => "20",
|
||||
2 => "15",
|
||||
3 => "13"
|
||||
),
|
||||
9 => array(
|
||||
1 => "20",
|
||||
2 => "16",
|
||||
3 => "14"
|
||||
),
|
||||
10 => array(
|
||||
1 => "20",
|
||||
2 => "17",
|
||||
3 => "15"
|
||||
),
|
||||
11 => array(
|
||||
1 => "21",
|
||||
2 => "18",
|
||||
3 => "16"
|
||||
),
|
||||
12 => array(
|
||||
1 => "22",
|
||||
2 => "19",
|
||||
3 => "17"
|
||||
),
|
||||
13 => array(
|
||||
1 => "23",
|
||||
2 => "20",
|
||||
3 => "19"
|
||||
),
|
||||
14 => array(
|
||||
1 => "24",
|
||||
2 => "21",
|
||||
3 => "20"
|
||||
),
|
||||
15 => array(
|
||||
1 => "25",
|
||||
2 => "22",
|
||||
3 => "21"
|
||||
),
|
||||
16 => array(
|
||||
1 => "26",
|
||||
2 => "23",
|
||||
3 => "22"
|
||||
),
|
||||
17 => array(
|
||||
1 => "27",
|
||||
2 => "24",
|
||||
3 => "24"
|
||||
),
|
||||
18 => array(
|
||||
1 => "28",
|
||||
2 => "25",
|
||||
3 => "25"
|
||||
),
|
||||
19 => array(
|
||||
1 => "29",
|
||||
2 => "27",
|
||||
3 => "26"
|
||||
),
|
||||
20 => array(
|
||||
1 => "30",
|
||||
2 => "28",
|
||||
3 => "27"
|
||||
),
|
||||
21 => array(
|
||||
1 => "31",
|
||||
2 => "29",
|
||||
3 => "29"
|
||||
),
|
||||
22 => array(
|
||||
1 => "32",
|
||||
2 => "30",
|
||||
3 => "30"
|
||||
),
|
||||
23 => array(
|
||||
1 => "33",
|
||||
2 => "32",
|
||||
3 => "31"
|
||||
),
|
||||
24 => array(
|
||||
1 => "34",
|
||||
2 => "33",
|
||||
3 => "32"
|
||||
),
|
||||
25 => array(
|
||||
1 => "36",
|
||||
2 => "34",
|
||||
3 => "34"
|
||||
),
|
||||
26 => array(
|
||||
1 => "37",
|
||||
2 => "35",
|
||||
3 => "35"
|
||||
),
|
||||
27 => array(
|
||||
1 => "38",
|
||||
2 => "37",
|
||||
3 => "36"
|
||||
),
|
||||
28 => array(
|
||||
1 => "39",
|
||||
2 => "38",
|
||||
3 => "37"
|
||||
),
|
||||
29 => array(
|
||||
1 => "40",
|
||||
2 => "39",
|
||||
3 => "39"
|
||||
),
|
||||
30 => array(
|
||||
1 => "42",
|
||||
2 => "40",
|
||||
3 => "40"
|
||||
),
|
||||
31 => array(
|
||||
1 => "43",
|
||||
2 => "42",
|
||||
3 => "41"
|
||||
),
|
||||
32 => array(
|
||||
1 => "44",
|
||||
2 => "43",
|
||||
3 => "43"
|
||||
),
|
||||
33 => array(
|
||||
1 => "45",
|
||||
2 => "44",
|
||||
3 => "44"
|
||||
),
|
||||
34 => array(
|
||||
1 => "47",
|
||||
2 => "46",
|
||||
3 => "45"
|
||||
),
|
||||
35 => array(
|
||||
1 => "48",
|
||||
2 => "47",
|
||||
3 => "46"
|
||||
),
|
||||
36 => array(
|
||||
1 => "49",
|
||||
2 => "48",
|
||||
3 => "48"
|
||||
),
|
||||
37 => array(
|
||||
1 => "50",
|
||||
2 => "49",
|
||||
3 => "49"
|
||||
),
|
||||
38 => array(
|
||||
1 => "52",
|
||||
2 => "51",
|
||||
3 => "50"
|
||||
),
|
||||
39 => array(
|
||||
1 => "53",
|
||||
2 => "52",
|
||||
3 => "52"
|
||||
),
|
||||
40 => array(
|
||||
1 => "54",
|
||||
2 => "53",
|
||||
3 => "53"
|
||||
)
|
||||
);
|
||||
static $paddingWidth = 20;
|
||||
|
||||
static function getBlockStyles($element, $ignoreSpecificStyles = false) {
|
||||
if (!isset($element['styles']['block'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $this->getStyles($element['styles'], 'block', $ignoreSpecificStyles);
|
||||
return self::getStyles($element['styles'], 'block', $ignoreSpecificStyles);
|
||||
}
|
||||
|
||||
function getStyles($data, $type, $ignoreSpecificStyles = false) {
|
||||
$styles = array_map(function ($attribute, $style) use($ignoreSpecificStyles) {
|
||||
if(!$ignoreSpecificStyles || !in_array($attribute, $ignoreSpecificStyles)) {
|
||||
return $this->translateCSSAttribute($attribute) . ': ' . $style . ' !important;';
|
||||
|
||||
static function getStyles($data, $type, $ignoreSpecificStyles = false) {
|
||||
$styles = array_map(function ($attribute, $style) use ($ignoreSpecificStyles) {
|
||||
if (!$ignoreSpecificStyles || !in_array($attribute, $ignoreSpecificStyles)) {
|
||||
return self::translateCSSAttribute($attribute) . ': ' . $style . ' !important;';
|
||||
}
|
||||
}, array_keys($data[$type]), $data[$type]);
|
||||
|
||||
return implode('', $styles);
|
||||
}
|
||||
|
||||
function translateCSSAttribute($attribute) {
|
||||
return (array_key_exists($attribute, $this->cssAtributesTable)) ? $this->cssAtributesTable[$attribute] : $attribute;
|
||||
|
||||
static function translateCSSAttribute($attribute) {
|
||||
return (array_key_exists($attribute, self::$cssAttributesTable)) ? self::$cssAttributesTable[$attribute] : $attribute;
|
||||
}
|
||||
}
|
||||
|
||||
static function setFontFamily($fontFamily, $selector) {
|
||||
$fontFamily = (isset(self::$font[$fontFamily])) ?
|
||||
self::$font[$fontFamily] :
|
||||
$fontFamily;
|
||||
$css = $selector . '{' . PHP_EOL;
|
||||
$css .= 'font-family:' . $fontFamily . ';' . PHP_EOL;
|
||||
$css .= '}' . PHP_EOL;
|
||||
return $css;
|
||||
}
|
||||
|
||||
static function setFontAndLineHeight($fontSize, $selector) {
|
||||
$css = '';
|
||||
foreach (ColumnsHelper::$columnsClass as $columnCount => $columnClass) {
|
||||
$css .= '.mailpoet_content-' . $columnClass . ' ' . $selector . '{' . PHP_EOL;
|
||||
$css .= 'font-size:' . $fontSize . 'px;' . PHP_EOL;
|
||||
$css .= 'line-height:' . StylesHelper::$fontSize[$fontSize][$columnCount] . 'px;' . PHP_EOL;
|
||||
$css .= '}' . PHP_EOL;
|
||||
}
|
||||
return $css;
|
||||
}
|
||||
|
||||
static function setStyle($style, $selector) {
|
||||
$css = $selector . '{' . PHP_EOL;
|
||||
foreach ($style as $attribute => $individualStyle) {
|
||||
$css .= self::translateCSSAttribute($attribute) . ':' . $individualStyle . ';' . PHP_EOL;
|
||||
}
|
||||
$css .= '}' . PHP_EOL;
|
||||
return $css;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user