@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Abstract class for less variables.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.0
|
||||
*
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Less.Variable
|
||||
*/
|
||||
abstract class Ai1ec_Less_Variable extends Ai1ec_Html_Element {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $value;
|
||||
|
||||
/**
|
||||
* it takes an array of parameters and a renderable.
|
||||
*
|
||||
* @param Ai1ec_Registry_Object $registry
|
||||
* @param array $params
|
||||
* @internal param \Ai1ec_Renderable $renderable
|
||||
*/
|
||||
public function __construct( Ai1ec_Registry_Object $registry, array $params ) {
|
||||
parent::__construct( $registry );
|
||||
$this->id = $params['id'];
|
||||
$this->description = $params['description'];
|
||||
$this->value = $params['value'];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This class represents a LESS variable of type color. It supports hex, rgb
|
||||
* and rgba formats.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.0
|
||||
* @instantiator new
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Less.Variable
|
||||
*/
|
||||
class Ai1ec_Less_Variable_Color extends Ai1ec_Less_Variable {
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $readonly = false;
|
||||
|
||||
public function render() {
|
||||
$readonly = $this->readonly === true ? 'readonly' : '';
|
||||
|
||||
$args = array(
|
||||
'label' => $this->description,
|
||||
'readonly' => $readonly,
|
||||
'id' => $this->id,
|
||||
'value' => $this->value,
|
||||
'format' => $this->_get_format(),
|
||||
);
|
||||
$loader = $this->_registry->get( 'theme.loader' );
|
||||
$file = $loader->get_file( 'theme-options/color-picker.twig', $args, true );
|
||||
return $file->get_content();
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* Set up the color picker
|
||||
* @see Ai1ec_Less_Variable::set_up_renderable()
|
||||
*/
|
||||
protected function _get_format() {
|
||||
$format = 'hex';
|
||||
if( substr( $this->value, 0, 3 ) === 'rgb' ) {
|
||||
if( substr( $this->value, 0, 4 ) === 'rgba' ) {
|
||||
$format = 'rgba';
|
||||
} else {
|
||||
$format = 'rgb';
|
||||
}
|
||||
}
|
||||
return $format;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This class represent a LESS variable of type font.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.0
|
||||
* @instantiator new
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Less.Variable
|
||||
*/
|
||||
class Ai1ec_Less_Variable_Font extends Ai1ec_Less_Variable {
|
||||
|
||||
/**
|
||||
* @var string Value saved when a custom font is used
|
||||
*/
|
||||
const CUSTOM_FONT = 'custom';
|
||||
|
||||
/**
|
||||
* @var string suffix added to custom font fields
|
||||
*/
|
||||
const CUSTOM_FONT_ID_SUFFIX = '_custom';
|
||||
|
||||
|
||||
/**
|
||||
* @var string True if using a custom value
|
||||
*/
|
||||
private $use_custom_value = false;
|
||||
|
||||
/**
|
||||
* @var string The custom value.
|
||||
*/
|
||||
private $custom_value;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $fonts = array(
|
||||
'Arial' => 'Arial, Helvetica, sans-serif',
|
||||
'Arial Black' => '"Arial Black", Gadget, sans-serif',
|
||||
'Comic Sans MS' => '"Comic Sans MS", cursive',
|
||||
'Courier New' => '"Courier New", monospace',
|
||||
'Georgia' => 'Georgia, Georgia, serif',
|
||||
'Helvetica Neue' => '"Helvetica Neue", Helvetica, Arial, sans-serif',
|
||||
'League Gothic' => '"League Gothic", Impact, "Arial Black", Arial, sans-serif',
|
||||
'Impact' => 'Impact, Charcoal, sans-serif',
|
||||
'Lucida Console' => '"Lucida Console", Monaco, monospace',
|
||||
'Lucida Sans Unicode' => '"Lucida Sans Unicode", Lucida Grande, sans-serif',
|
||||
'MS Sans Serif' => '"MS Sans Serif", Geneva, sans-serif',
|
||||
'MS Serif' => '"MS Serif", "New York", serif',
|
||||
'Palatino' => '"Palatino Linotype", "Book Antiqua", Palatino, serif',
|
||||
'Tahoma' => 'Tahoma, Geneva, sans-serif',
|
||||
'Times New Roman' => '"Times New Roman", Times, serif',
|
||||
'Trebuchet Ms' => '"Trebuchet MS", "Lucida Grande", sans-serif',
|
||||
'Verdana' => 'Verdana, Geneva, sans-serif',
|
||||
);
|
||||
|
||||
/**
|
||||
* @param Ai1ec_Registry_Object $registry
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct( Ai1ec_Registry_Object $registry, array $params ) {
|
||||
$this->fonts[__( "Custom...", AI1EC_PLUGIN_NAME )] = self::CUSTOM_FONT;
|
||||
|
||||
// Allow extensions to add options to the font list.
|
||||
$this->fonts = apply_filters( 'ai1ec_font_options', $this->fonts );
|
||||
if ( ! in_array( $params['value'], $this->fonts ) ) {
|
||||
$this->use_custom_value = true;
|
||||
$this->custom_value = $params['value'];
|
||||
$this->value = self::CUSTOM_FONT;
|
||||
}
|
||||
parent::__construct( $registry, $params );
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* add the fonts
|
||||
* @see Ai1ec_Less_Variable::set_up_renderable()
|
||||
*/
|
||||
public function _get_options() {
|
||||
$options = array();
|
||||
foreach ( $this->fonts as $text => $key ) {
|
||||
$option = array(
|
||||
'text' => $text,
|
||||
'value' => $key,
|
||||
);
|
||||
if ( $key === $this->value
|
||||
|| ( self::CUSTOM_FONT === $key && $this->use_custom_value )
|
||||
) {
|
||||
$option['args'] = array(
|
||||
'selected' => 'selected',
|
||||
);
|
||||
}
|
||||
$options[] = $option;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see Ai1ec_Less_Variable::render()
|
||||
*/
|
||||
public function render() {
|
||||
$args = array(
|
||||
'label' => $this->description,
|
||||
'id' => $this->id,
|
||||
'input' => array(
|
||||
'id' => $this->id . self::CUSTOM_FONT_ID_SUFFIX,
|
||||
'value' => '',
|
||||
'args' => array(
|
||||
'placeholder' => __( "Enter custom font(s)", AI1EC_PLUGIN_NAME ),
|
||||
'class' => 'ai1ec-custom-font',
|
||||
),
|
||||
),
|
||||
'select' => array(
|
||||
'id' => $this->id,
|
||||
'args' => array(
|
||||
'class' => 'ai1ec_font'
|
||||
),
|
||||
'options' => $this->_get_options(),
|
||||
)
|
||||
|
||||
);
|
||||
|
||||
if ( ! $this->use_custom_value ) {
|
||||
$args['input']['args']['class'] = 'ai1ec-custom-font ai1ec-hide';
|
||||
} else {
|
||||
$args['input']['value'] = $this->custom_value;
|
||||
}
|
||||
$loader = $this->_registry->get( 'theme.loader' );
|
||||
$file = $loader->get_file( 'theme-options/font.twig', $args, true );
|
||||
return $file->get_content();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This class represent a LESS variable of type size.
|
||||
*
|
||||
* @author Time.ly Network Inc.
|
||||
* @since 2.0
|
||||
* @instantiator new
|
||||
* @package AI1EC
|
||||
* @subpackage AI1EC.Less.Variable
|
||||
*/
|
||||
class Ai1ec_Less_Variable_Size extends Ai1ec_Less_Variable {
|
||||
|
||||
/**
|
||||
*
|
||||
* @see Ai1ec_Renderable::render()
|
||||
*
|
||||
*/
|
||||
public function render() {
|
||||
$args = array(
|
||||
'label' => $this->description,
|
||||
'id' => $this->id,
|
||||
'value' => $this->value,
|
||||
'args' => array(
|
||||
'class' => 'input-mini ai1ec-less-variable-size',
|
||||
'placeholder' => __( 'Length', AI1EC_PLUGIN_NAME ),
|
||||
)
|
||||
);
|
||||
$loader = $this->_registry->get( 'theme.loader' );
|
||||
$file = $loader->get_file( 'theme-options/size.twig', $args, true );
|
||||
return $file->get_content();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user