| 1 |
<?php |
| 2 |
/** |
| 3 |
* Generates Inline styles |
| 4 |
* |
| 5 |
* Based on Ultimate Widgets Light |
| 6 |
* Author: khothemes, freemius |
| 7 |
* License: GPLv2 or later |
| 8 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html |
| 9 |
*/ |
| 10 |
|
| 11 |
class Flash_Toolkit_Inline_Style { |
| 12 |
private $style; |
| 13 |
private $add_style; |
| 14 |
|
| 15 |
/** |
| 16 |
* Class Constructor |
| 17 |
*/ |
| 18 |
public function __construct( $atts, $add_style ) { |
| 19 |
$this->style = array(); |
| 20 |
$this->add_style = $add_style; |
| 21 |
|
| 22 |
// Loop through widget atts and run class methods |
| 23 |
foreach ( $atts as $key => $value ) { |
| 24 |
if ( ! empty( $value ) ) { |
| 25 |
$method = 'parse_' . $key; |
| 26 |
if ( method_exists( $this, $method ) ) { |
| 27 |
$this->$method( $value ); |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Background |
| 36 |
*/ |
| 37 |
private function parse_background( $value ) { |
| 38 |
$this->style[] = 'background:'.$value.';'; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Background Color |
| 43 |
*/ |
| 44 |
private function parse_background_color( $value ) { |
| 45 |
$value = 'none' == $value ? 'transparent' : $value; |
| 46 |
$this->style[] = 'background-color:'.$value.';'; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Border: Color |
| 51 |
*/ |
| 52 |
private function parse_border_color( $value ) { |
| 53 |
$value = 'none' == $value ? 'transparent' : $value; |
| 54 |
$this->style[] = 'border-color:'.$value.';'; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Color |
| 59 |
*/ |
| 60 |
private function parse_color( $value ) { |
| 61 |
$this->style[] = 'color:'.$value.';'; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Font Size |
| 66 |
*/ |
| 67 |
private function parse_font_size( $value ) { |
| 68 |
$this->style[] = 'font-size:'.$value.'px;'; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Height |
| 73 |
*/ |
| 74 |
private function parse_height( $value ) { |
| 75 |
$this->style[] = 'height:'.$value.'px;'; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Font |
| 80 |
*/ |
| 81 |
private function parse_font_family( $value ) { |
| 82 |
$this->style[] = '\'font-family:'.$value.'\';'; |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Text Align |
| 87 |
*/ |
| 88 |
private function parse_text_align( $value ) { |
| 89 |
if ( 'textcenter' == $value ) { |
| 90 |
$value = 'center'; |
| 91 |
} elseif ( 'textleft' == $value ) { |
| 92 |
$value = 'left'; |
| 93 |
} elseif ( 'textright' == $value ) { |
| 94 |
$value = 'right'; |
| 95 |
} |
| 96 |
$this->style[] = 'text-align:'.$value.';'; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Returns the styles |
| 101 |
*/ |
| 102 |
public function return_style() { |
| 103 |
if ( ! empty( $this->style ) ) { |
| 104 |
$this->style = implode( false, $this->style ); |
| 105 |
if ( $this->add_style ) { |
| 106 |
return ' style='. $this->style .''; |
| 107 |
} else { |
| 108 |
return $this->style; |
| 109 |
} |
| 110 |
} else { |
| 111 |
return null; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
} // End Class |
| 117 |
|
| 118 |
// Helper function runs the Flash_Inline_Style class |
| 119 |
function flash_toolkit_inline_style( $atts = array(), $add_style = true ) { |
| 120 |
if ( ! empty( $atts ) && is_array( $atts ) ) { |
| 121 |
$inline_style = new Flash_Toolkit_Inline_Style( $atts, $add_style ); |
| 122 |
return $inline_style->return_style(); |
| 123 |
} |
| 124 |
} |
| 125 |
|