Add upstream plugins

Signed-off-by: Adrian Nöthlich <git@promasu.tech>
This commit is contained in:
2019-10-25 22:42:20 +02:00
parent 5d3c2ec184
commit 290736650a
1186 changed files with 302577 additions and 0 deletions

View File

@@ -0,0 +1,268 @@
<?php
/**
* This class handles generations of href for links.
*
* @author Time.ly Network, Inc.
* @instantiator Ai1ec_Factory_Html.create_href_helper_instance
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
class Ai1ec_Html_Element_Href {
/**
* @var array the parameters that are used in the urls
*/
private $used_paramaters = array(
'action',
'page_offset',
'month_offset',
'oneday_offset',
'week_offset',
'time_limit',
'exact_date',
'cat_ids',
'auth_ids',
'post_ids',
'tag_ids',
'instance_ids',
'events_limit',
'request_format',
'no_navigation'
);
/**
* @var boolean
*/
private $is_category;
/**
* @var boolean
*/
private $is_tag;
/**
* @var boolean
*/
private $is_author;
/**
* @var boolean
*/
private $is_custom_filter;
/**
* @var array the arguments to parse
*/
private $args;
/**
* @var int
*/
private $term_id;
/**
* @var string
*/
private $calendar_page;
/**
* @var boolean
*/
private $pretty_permalinks_enabled;
/**
* @var string
*/
private $uri_particle = null;
/**
* @param boolean $pretty_permalinks_enabled
*/
public function set_pretty_permalinks_enabled( $pretty_permalinks_enabled ) {
$this->pretty_permalinks_enabled = $pretty_permalinks_enabled;
if ( $pretty_permalinks_enabled ) {
$this->calendar_page = trim( (string)$this->calendar_page, '/' )
. '/';
}
}
/**
* @param number $term_id
*/
public function set_term_id( $term_id ) {
$this->term_id = $term_id;
}
public function __construct( array $args, $calendar ) {
$this->args = $args;
$this->calendar_page = $calendar;
if ( isset( $args['_extra_used_parameters'] ) ) {
$this->used_paramaters = array_merge(
$this->used_paramaters,
$args['_extra_used_parameters']
);
}
$this->used_paramaters = array_merge(
$this->used_paramaters,
apply_filters(
'ai1ec_view_args_for_view',
array()
)
);
}
/**
* @param boolean $is_category
*/
public function set_is_category( $is_category ) {
$this->is_category = $is_category;
}
/**
* @param boolean $is_tag
*/
public function set_is_tag( $is_tag ) {
$this->is_tag = $is_tag;
}
/**
* @param boolean $is_author
*/
public function set_is_author( $is_author ) {
$this->is_author = $is_author;
}
/**
* Generate the correct href for the view.
* This takes into account special filters for categories and tags
*
* @return string
*/
public function generate_href() {
$href = '';
$to_implode = array();
foreach ( $this->used_paramaters as $key ) {
if ( ! empty( $this->args[$key] ) ) {
$value = $this->args[$key];
if( is_array( $this->args[$key] ) ) {
$value = implode( ',', $this->args[$key] );
}
$to_implode[$key] = $key . Ai1ec_Uri::DIRECTION_SEPARATOR .
$value;
}
}
if (
$this->is_category ||
$this->is_tag ||
$this->is_author ||
$this->is_custom_filter
) {
$to_implode = $this->add_or_remove_category_from_href(
$to_implode
);
}
if ( $this->pretty_permalinks_enabled ) {
$href .= implode( '/', $to_implode );
if ( ! empty( $href ) ) {
$href .= '/';
}
} else {
$href .= $this->get_param_delimiter_char( $this->calendar_page );
$href .= 'ai1ec=' . implode( '|', $to_implode );
}
$full_url = $this->calendar_page . $href;
// persist the `lang` parameter if present
if ( isset( $_REQUEST['lang'] ) ) {
$full_url = esc_url_raw( add_query_arg( 'lang', $_REQUEST['lang'], $full_url ) );
}
return $full_url;
}
/**
* Sets that class is used for custom filter.
*
* @param bool $value Expected true or false.
* @param string $uri_particle URI particle identifier.
*
* @return void Method does not return.
*/
public function set_custom_filter( $value, $uri_particle = null ) {
$this->is_custom_filter = $value;
$this->uri_particle = $uri_particle;
}
/**
* Perform some extra manipulation for filter href. Basically if the current
* category is part of the filter, the href will not contain it (because
* clicking on it will actually mean "remove that one from the filter")
* otherwise it will be preserved.
*
* @param array $to_implode
* @return array
*/
private function add_or_remove_category_from_href( array $to_implode ) {
$array_key = $this->uri_particle;
if ( null === $this->uri_particle ) {
$array_key = $this->_current_array_key();
}
// Let's copy the origina cat_ids or tag_ids so we do not affect it
$copy = array();
if ( isset( $this->args[$array_key] ) ) {
$copy = (array)$this->args[$array_key];
}
$key = array_search( $this->term_id, $copy );
// Let's check if we are already filtering for tags / categorys
if( isset( $to_implode[$array_key] ) ) {
if( $key !== false ) {
unset( $copy[$key] );
} else {
$copy[] = $this->term_id;
}
if( empty( $copy ) ) {
unset( $to_implode[$array_key] );
} else {
$to_implode[$array_key] = $array_key . Ai1ec_Uri::DIRECTION_SEPARATOR .
implode( ',', $copy );
}
} else {
$to_implode[$array_key] = $array_key . Ai1ec_Uri::DIRECTION_SEPARATOR . $this->term_id;
}
return $to_implode;
}
/**
* Match current argument key
*
* @return string Name of current argument key
*/
protected function _current_array_key() {
$map = array(
'category' => 'cat',
'tag' => 'tag',
'author' => 'auth',
);
$use_name = '';
foreach ( $map as $value => $name ) {
if ( $this->{'is_' . $value} ) {
$use_name = $name;
break;
}
}
return $use_name . '_ids';
}
/**
* Returns the delimiter character to use if a new query string parameter is
* going to be appended to the URL.
*
* @param string $url URL to parse
*
* @return string
*/
public static function get_param_delimiter_char( $url ) {
return strpos( $url, '?' ) === false ? '?' : '&';
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* Interface for HTML elements.
*
* In this context element is a complex collection of HTML tags
* rendered to suit specific needs.
*
* @author Time.ly Network, Inc.
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
interface Ai1ec_Html_Element_Interface {
/**
* Set attribute for renderable element.
*
* Attributes are object specific.
*
* @param string $attribute Name of attribute to set.
* @param mixed $value Value to set for attribute.
*
* @return Ai1ec_Html_Element_Interface Instance of self for chaining.
*/
public function set( $attribute, $value );
/**
* Generate HTML snippet for inclusion in page.
*
* @param string $snippet Particle to append to result.
*
* @return string HTML snippet.
*
* @throws Ai1ec_Html_Exception If rendering may not be completed.
*/
public function render( $snippet = '' );
}

View File

@@ -0,0 +1,172 @@
<?php
/**
* Base html element.
*
* @author Time.ly Network, Inc.
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
abstract class Ai1ec_Html_Element extends Ai1ec_Base implements Ai1ec_Renderable {
/**
*
* @var string
*/
protected $id;
/**
*
* @var array
*/
protected $classes = array();
/**
* @var array
*/
protected $attributes = array();
/**
*
* @var Ai1ec_Template_Adapter
*/
protected $template_adapter;
/**
* Adds the passed attribute name & value to the link's attributes.
*
* @param string $name
* @param string|array $value
*/
public function set_attribute( $name, $value ) {
$value = ( array ) $value;
// Let's check if we have a value
if ( isset( $this->attributes[$name] ) ) {
// Let's check if it's an array
$this->attributes[$name] = array_unique(
array_merge( $this->attributes[$name], $value )
);
} else {
$this->attributes[$name] = $value;
}
}
/**
*
* @param string $name
* @return array|NULL
*/
public function get_attribute( $name ) {
if ( isset( $this->attributes[$name] ) ) {
return $this->attributes[$name];
} else {
return null;
}
}
/**
* Adds the given name="value"-formatted attribute expression to the link's
* set of attributes.
*
* @param string $expr Attribute name-value pair in name="value" format
*/
public function set_attribute_expr( $expr ) {
preg_match( '/^([\w\-_]+)=[\'"]([^\'"]*)[\'"]$/', $expr, $matches );
$name = $matches[1];
$value = $matches[2];
$this->set_attribute( $name, $value );
}
public function __construct( Ai1ec_Registry_Object $registry ) {
$this->_registry = $registry;
$this->template_adapter = $registry->get( 'html.helper' );
}
/**
* Magic method that renders the object as html
*
* @return string
*/
public function __toString() {
return $this->render_as_html();
}
/**
*
* @param $id string
*/
public function set_id( $id ) {
$this->id = $id;
}
/**
* Adds an element to the class array
*
* @param string $class
*/
public function add_class( $class ) {
$this->classes[] = $class;
}
/**
* Creates the markup to be used to create classes
*
* @return string
*/
protected function create_class_markup() {
if ( empty( $this->classes ) ) {
return '';
}
$classes = $this->template_adapter->escape_attribute(
implode( ' ', $this->classes )
);
return "class='$classes'";
}
/**
* Creates the markup for an attribute
*
* @param string $attribute_name
* @param string $attribute_value
* @return string
*/
protected function create_attribute_markup(
$attribute_name,
$attribute_value
) {
if (empty( $attribute_value )) {
return '';
}
$attribute_value = $this->template_adapter->escape_attribute( $attribute_value );
return "$attribute_name='$attribute_value'";
}
/**
* Renders the markup for the attributes of the tag
*
* @return string
*/
protected function render_attributes_markup() {
$html = array();
foreach ( $this->attributes as $name => $values ) {
$values = $this->template_adapter->escape_attribute(
implode( ' ', $values )
);
$html[] = "$name='$values'";
}
return implode( ' ', $html );
}
/**
* Return the content as html instead of echoing it.
*
* @return string
*/
public function render_as_html() {
$this->_registry->get( 'compatibility.ob' )->start();
$this->render();
return $this->_registry->get( 'compatibility.ob' )->get_clean();
}
}

View File

@@ -0,0 +1,17 @@
<?php
/**
* Basic interface for the composite.
*
* @author Time.ly Network, Inc.
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
interface Ai1ec_Renderable {
/**
* This is the main function, it just renders the method for the element,
* taking care of childrens ( if any )
*/
public function render();
}

View File

@@ -0,0 +1,132 @@
<?php
/**
* A class that renders bootstrap modals.
*
* @instantiator new
* @author Time.ly Network, Inc.
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
class Ai1ec_Bootstrap_Modal extends Ai1ec_Html_Element {
/**
* @var string
*/
private $delete_button_text;
/**
* @var string
*/
private $keep_button_text;
/**
* @var string
*/
private $body_text;
/**
* @var string
*/
private $header_text;
/**
* @param string $modal_text
*/
public function __construct( Ai1ec_Registry_Object $registry, $modal_text ) {
$this->body_text = $modal_text;
parent::__construct( $registry );
}
/**
* @param string $delete_button_text
*/
public function set_delete_button_text( $delete_button_text ) {
$this->delete_button_text = $delete_button_text;
}
/**
* @param string $keep_button_text
*/
public function set_keep_button_text( $keep_button_text ) {
$this->keep_button_text = $keep_button_text;
}
/**
* @param string $body_text
*/
public function set_body_text( $body_text ) {
$this->body_text = $body_text;
}
/**
* @param string $header_text
*/
public function set_header_text( $header_text ) {
$this->header_text = $header_text;
}
/**
* @return string
*/
private function render_id_if_present() {
return isset( $this->id ) ? "id='{$this->id}'" : '';
}
/**
* @return string
*/
private function render_header_if_present() {
return isset( $this->header_text ) ?
'<h2>' . $this->header_text . '</h2>'
: '';
}
/**
* @return string
*/
private function render_keep_button_if_present() {
return isset( $this->keep_button_text ) ? "<a href='#' class='ai1ec-btn keep ai1ec-btn-primary ai1ec-btn-lg'>{$this->keep_button_text}</a>" : '';
}
/**
* @return string
*/
private function render_remove_button_if_present() {
return isset( $this->delete_button_text ) ? "<a href='#' class='ai1ec-btn remove ai1ec-btn-danger ai1ec-btn-lg'>{$this->delete_button_text}</a>" : '';
}
/**
* @return string
*/
public function render() {
$header = $this->render_header_if_present();
$id = $this->render_id_if_present();
$remove_event_button = $this->render_remove_button_if_present();
$keep_event_button = $this->render_keep_button_if_present();
$body = $this->body_text;
$classes = implode( ' ', $this->classes );
$html = <<<HTML
<div class="ai1ec-modal $classes ai1ec-fade timely" $id>
<div class="ai1ec-modal-dialog">
<div class="ai1ec-modal-content">
<div class="ai1ec-modal-header">
<button type="button" class="ai1ec-close" data-dismiss="ai1ec-modal"
aria-hidden="true">×</button>
$header
</div>
<div class="ai1ec-modal-body">
$body
</div>
<div class="ai1ec-modal-footer">
$remove_event_button
$keep_event_button
</div>
</div>
</div>
</div>
HTML;
echo $html;
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* Missing class setting-renderer description.
*
* @author Time.ly Network Inc.
* @since 2.2
*
* @package AI1EC
* @subpackage AI1EC.
*/
class Ai1ec_Html_Setting_Renderer extends Ai1ec_Base {
/**
* Renders single setting.
*
* @param array $setting Setting structure.
*
* @return string Rendered content.
*
* @throws Ai1ec_Bootstrap_Exception
*/
public function render( array $setting ) {
$renderer_name = $setting['renderer']['class'];
$renderer = null;
try {
$renderer = $this->_registry->get(
'html.element.setting.' . $renderer_name,
$setting
);
} catch ( Ai1ec_Bootstrap_Exception $exception ) {
$renderer = $this->_registry->get(
'html.element.setting.input',
$setting
);
}
return $renderer->render();
}
}

View File

@@ -0,0 +1,101 @@
<?php
/**
* Abstract class to accelerate settings page snippets development.
*
* @author Time.ly Network, Inc.
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
abstract class Ai1ec_Html_Element_Settings extends Ai1ec_Base
implements Ai1ec_Html_Element_Interface {
/**
* @var Ai1ec_Html_Helper Instance of HTML helper.
*/
protected $_html = NULL;
/**
* @var array Map of arbitrary arguments passed to an element.
*/
protected $_args = array();
/**
* Constructor accepts system as injectable and requests HTML helper.
*
* @param Ai1ec_Registry_Object $system Injected system argument.
*
* @return void Constructor does not return.
*/
public function __construct(
Ai1ec_Registry_Object $registry,
array $args
) {
parent::__construct( $registry );
$this->_args = $args;
$this->_html = $registry->get( 'html.helper' );
}
/**
* Set value within current object scope
*
* Value name is formed as {$attribute} with underscore ('_') prefixed.
*
* @param string $attribute Name of attribute to set.
* @param mixed $value Value to set for attribute.
*
* @return Ai1ec_Html_Element_Settings Instance of self.
*/
public function set( $attribute, $value ) {
$this->{'_' . $attribute} = $value;
return $this;
}
/**
* Override to include any initialization logics.
*
* @return void Method output is ignored.
*/
protected function _initialize() {
}
/**
* Generate settings output line.
*
* @param string $output Generated output to finalize.
* @param bool $wrap Whether content should be wrapped with div or not.
*
* @return string Finalized HTML snippet.
*/
public function render( $output = '', $wrap = true, $hidden = false ) {
if ( isset( $this->_args['renderer']['condition'] ) ) {
$condition = $this->_args['renderer']['condition'];
if ( is_bool( $condition ) ) {
$render = $condition;
} else {
$callback = explode( ':', $this->_args['renderer']['condition'] );
try {
$render = $this->_registry->dispatch(
$callback[0],
$callback[1]
);
} catch (Ai1ec_Bootstrap_Exception $exception) {
$render = '';
}
}
if ( ! $render ) {
return '';
}
}
if ( ! $wrap ) {
return $output;
}
if ( $hidden ) {
return '<div class="ai1ec-form-group ai1ec-hidden">' . $output . '</div>';
} else {
return '<div class="ai1ec-form-group">' . $output . '</div>';
}
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* Renderer of settings page html.
*
* @author Time.ly Network, Inc.
* @instantiator new
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
class Ai1ec_Html_Setting_Cache extends Ai1ec_Html_Element_Settings {
/* (non-PHPdoc)
* @see Ai1ec_Html_Element_Settings::render()
*/
public function render( $output = '', $wrap = true, $hidden = false ) {
$args = $this->get_twig_cache_args();
$loader = $this->_registry->get( 'theme.loader' );
$file = $loader->get_file( 'setting/twig_cache.twig', $args, true );
return parent::render( $file->get_content(), $wrap, $hidden );
}
/**
* Returns data for Twig template.
*
* @return array Data for template
*/
public function get_twig_cache_args() {
$args = array(
'cache_available' => (
AI1EC_CACHE_UNAVAILABLE !== $this->_args['value'] &&
! empty( $this->_args['value'] )
),
'id' => $this->_args['id'],
'label' => $this->_args['renderer']['label'],
'text' => array(
'refresh' => Ai1ec_I18n::__( 'Check again' ),
'nocache' => Ai1ec_I18n::__( 'Templates cache is not writable' ),
'okcache' => Ai1ec_I18n::__( 'Templates cache is writable' ),
'rescan' => Ai1ec_I18n::__( 'Checking...' ),
'title' => Ai1ec_I18n::__( 'Performance Report' ),
),
);
return $args;
}
}

View File

@@ -0,0 +1,124 @@
<?php
/**
* Renderer of settings page Calendar page selection snippet.
*
* @author Time.ly Network, Inc.
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
class Ai1ec_Html_Element_Calendar_Page_Selector
extends Ai1ec_Html_Element_Settings {
/**
* @var string HTML id attribute for selector.
*/
const ELEMENT_ID = 'calendar_page_id';
/**
* @var array Map of pages defined in system, use `get_pages()` WP call.
*/
protected $_pages = array();
/**
* Set attributes for element.
*
* Currently recognized attributes:
* - 'pages' - {@see self::$_pages} for details;
* - 'selected' - {@see self::$_selected} for details.
*
* @param string $attribute Name of attribute to set.
* @param mixed $value Value to set for attribute.
*
* @return Ai1ec_Html_Element_Calendar_Page_Selector Instance of self.
*/
public function set( $attribute, $value ) {
// any validation may be provided here
return parent::set( $attribute, $value );
}
/**
* Generate HTML snippet for inclusion in settings page.
*
* @param string $snippet Particle to append to result.
*
* @return string HTML snippet for page selection.
*/
public function render( $snippet = '', $wrap = true, $hidden = false ) {
$output = '<label class="ai1ec-control-label ai1ec-col-sm-5" for="' .
self::ELEMENT_ID . '">' . Ai1ec_I18n::__( 'Calendar page' ) . '</label>'
. '<div class="ai1ec-col-sm-7">' .
$this->_get_pages_selector() . $this->_get_page_view_link() . '</div>';
return parent::render( $output, $wrap, $hidden );
}
/**
* Generate link to open selected page in new window.
*
* @return string HTML snippet.
*/
protected function _get_page_view_link() {
if ( empty( $this->_args['value'] ) ) {
return '';
}
$post = get_post( $this->_args['value'] );
if ( empty( $post->ID ) ) {
return '';
}
$args = array(
'view' => Ai1ec_I18n::__( 'View' ),
'link' => get_permalink( $post->ID ),
'title' => apply_filters(
'the_title',
$post->post_title,
$post->ID
),
);
return $this->_registry->get( 'theme.loader' )
->get_file( 'setting/calendar-page-selector.twig', $args, true )
->get_content();
}
/**
* Generate dropdown selector to choose page.
*
* @return string HTML snippet.
*/
protected function _get_pages_selector() {
$html = '<select id="' . self::ELEMENT_ID .
'" class="ai1ec-form-control" name="' . self::ELEMENT_ID . '">';
$list = $this->_get_pages();
foreach ( $list as $key => $value ) {
$html .= '<option value="' . $this->_html->esc_attr( $key ) . '"';
if ( $this->_args['value'] === $key ) {
$html .= ' selected="selected"';
}
$html .= '>' . $this->_html->esc_html( $value ) . '</option>';
}
$html .= '</select>';
return $html;
}
/**
* Make a map of page IDs and titles for selection snippet.
*
* @return array Map of page keys and titles.
*/
protected function _get_pages() {
$pages = get_pages();
if ( ! is_array( $pages ) ) {
$pages = array();
}
$output = array(
'__auto_page:Calendar' => Ai1ec_I18n::__(
'- Auto-Create New Page -'
),
);
foreach ( $pages as $key => $value ) {
$output[$value->ID] = $value->post_title;
}
return $output;
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* Renderer of settings page checkbox option.
*
* @author Time.ly Network, Inc.
* @instantiator new
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
class Ai1ec_Html_Settings_Checkbox extends Ai1ec_Html_Element_Settings {
/* (non-PHPdoc)
* @see Ai1ec_Html_Element_Settings::render()
*/
public function render( $output = '', $wrap = true, $hidden = false ) {
$attributes = array(
'class' => 'checkbox',
);
if ( true === $this->_args['value'] ) {
$attributes['checked'] = 'checked';
}
$args = $this->_args;
$args['attributes'] = $attributes;
$loader = $this->_registry->get( 'theme.loader' );
$file = $loader->get_file(
'setting/checkbox.twig',
$args,
true
);
return parent::render( $file->get_content(), $wrap, $hidden );
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Renderer of settings page custom option.
*
* @author Time.ly Network, Inc.
* @instantiator new
* @since 2.4
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
class Ai1ec_Html_Setting_Custom extends Ai1ec_Html_Element_Settings {
/* (non-PHPdoc)
* @see Ai1ec_Html_Element_Settings::render()
*/
public function render( $output = '', $wrap = true, $hidden = false ) {
$label = $this->_args['renderer']['label'];
$content = $this->_args['renderer']['content'];
$loader = $this->_registry->get( 'theme.loader' );
$file = $loader->get_file( 'setting/custom.twig', array(
'label' => $label,
'content' => $content
), true );
return parent::render( $file->get_content(), $wrap, $hidden );
}
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* Renderer of settings page Enabled views selection snippet.
*
* @author Time.ly Network, Inc.
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
class Ai1ec_Html_Element_Enabled_Views
extends Ai1ec_Html_Element_Settings {
/* (non-PHPdoc)
* @see Ai1ec_Html_Element_Settings::render()
*/
public function render( $output = '', $wrap = true, $hidden = false ) {
$this->_convert_values();
$args = array(
'views' => $this->_args['value'],
'label' => $this->_args['renderer']['label'],
'text_enabled' => __( 'Enabled', AI1EC_PLUGIN_NAME ),
'text_default' => __( 'Default', AI1EC_PLUGIN_NAME ),
'text_desktop' => __( 'Desktop', AI1EC_PLUGIN_NAME ),
'text_mobile' => __( 'Mobile', AI1EC_PLUGIN_NAME ),
);
$loader = $this->_registry->get( 'theme.loader' );
return $loader->get_file( 'setting/enabled-views.twig', $args, true )
->get_content();
}
/**
* Convert values to bo used in rendering
*/
protected function _convert_values() {
foreach( $this->_args['value'] as &$view ) {
$view['enabled'] = $view['enabled'] ?
'checked="checked"' :
'';
$view['default'] = $view['default'] ?
'checked="checked"' :
'';
// Use mobile settings if available, else fall back to desktop settings.
$view['enabled_mobile'] = isset( $view['enabled_mobile'] ) ?
( $view['enabled_mobile'] ?
'checked="checked"' :
'' ) :
$view['enabled'];
$view['default_mobile'] = isset( $view['default_mobile'] ) ?
( $view['default_mobile'] ?
'checked="checked"' :
'' ) :
$view['default'];
$view['longname'] = translate_nooped_plural(
$view['longname'],
1
);
}
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* Renderer of settings page html.
*
* @author Time.ly Network, Inc.
* @instantiator new
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
class Ai1ec_Html_Setting_Html extends Ai1ec_Html_Element_Settings {
/* (non-PHPdoc)
* @see Ai1ec_Html_Element_Settings::render()
*/
public function render( $output = '', $wrap = true, $hidden = false ) {
$file = $this->_args['id'] . '.twig';
$method = 'get_' . $this->_args['id'] . '_args';
$args = array();
if ( method_exists( $this, $method ) ) {
$args = $this->{$method}();
}
$loader = $this->_registry->get( 'theme.loader' );
$file = $loader->get_file( 'setting/' . $file, $args, true );
return parent::render( $file->get_content(), $wrap, $hidden );
}
/*
* Get embedding arguments
*
* @return array
*/
protected function get_embedding_args() {
return array(
'viewing_events_shortcodes' => apply_filters( 'ai1ec_viewing_events_shortcodes', null ),
'text_embed_shortcode' => __( 'Embed the calendar using a shortcode', AI1EC_PLUGIN_NAME ),
'text_insert_shortcode' => __( 'Insert one of these shortcodes into your page body to embed the calendar into any arbitrary WordPress Page:', AI1EC_PLUGIN_NAME ),
'text_month_view' => __( 'Month view:', AI1EC_PLUGIN_NAME ),
'text_week_view' => __( 'Week view:', AI1EC_PLUGIN_NAME ),
'text_day_view' => __( 'Day view:', AI1EC_PLUGIN_NAME ),
'text_agenda_view' => __( 'Agenda view:', AI1EC_PLUGIN_NAME ),
'text_other_view' => __( 'Some Other view:', AI1EC_PLUGIN_NAME ),
'text_default_view' => __( 'Default view as per settings:', AI1EC_PLUGIN_NAME ),
'text_general_form' => __( 'General form:', AI1EC_PLUGIN_NAME ),
'text_optional' => __( 'Optional.', AI1EC_PLUGIN_NAME ),
'text_filter_label' => __( 'Add options to display a filtered calender. (You can find out category and tag IDs by inspecting the URL of your filtered calendar page.)', AI1EC_PLUGIN_NAME ),
'text_filter_category' => __( 'Filter by event category name/slug:', AI1EC_PLUGIN_NAME ),
'text_filter_category_1' => __( 'Holidays', AI1EC_PLUGIN_NAME ),
'text_filter_category_2' => __( 'Lunar Cycles', AI1EC_PLUGIN_NAME ),
'text_filter_category_3' => __( 'zodiac-date-ranges', AI1EC_PLUGIN_NAME ),
'text_filter_category_comma' => __( 'Filter by event category names/slugs (separate names by comma):', AI1EC_PLUGIN_NAME ),
'text_filter_category_id' => __( 'Filter by event category ID:', AI1EC_PLUGIN_NAME ),
'text_filter_category_id_comma' => __( 'Filter by event category IDs (separate IDs by comma):', AI1EC_PLUGIN_NAME ),
'text_filter_tag' => __( 'Filter by event tag name/slug:', AI1EC_PLUGIN_NAME ),
'text_filter_tag_1' => __( 'tips-and-tricks', AI1EC_PLUGIN_NAME ),
'text_filter_tag_2' => __( 'creative writing', AI1EC_PLUGIN_NAME ),
'text_filter_tag_3' => __( 'performing arts', AI1EC_PLUGIN_NAME ),
'text_filter_tag_comma' => __( 'Filter by event tag names/slugs (separate names by comma):', AI1EC_PLUGIN_NAME ),
'text_filter_tag_id' => __( 'Filter by event tag ID:', AI1EC_PLUGIN_NAME ),
'text_filter_tag_id_comma' => __( 'Filter by event tag IDs (separate IDs by comma):', AI1EC_PLUGIN_NAME ),
'text_filter_post_id' => __( 'Filter by post ID:', AI1EC_PLUGIN_NAME ),
'text_filter_post_id_comma' => __( 'Filter by post IDs (separate IDs by comma):', AI1EC_PLUGIN_NAME ),
'text_events_limit' => __( 'Limit number of events per page:', AI1EC_PLUGIN_NAME ),
'text_warning' => __( 'Warning:', AI1EC_PLUGIN_NAME ),
'text_single_calendar' => __( 'It is currently not supported to embed more than one calendar in the same page. Do not attempt to embed the calendar via shortcode in a page that already displays the calendar.', AI1EC_PLUGIN_NAME ),
);
}
}

View File

@@ -0,0 +1,98 @@
<?php
/**
* Renderer of settings page input option.
*
* @author Time.ly Network, Inc.
* @instantiator new
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
class Ai1ec_Html_Setting_Input extends Ai1ec_Html_Element_Settings {
/* (non-PHPdoc)
* @see Ai1ec_Html_Element_Settings::render()
*/
public function render( $output = '', $wrap = true, $hidden = false ) {
$system = $this->_registry->get( 'date.system' );
$type = $this->_args['renderer']['type'];
$date = $append = false;
$class = '';
$input_type = 'text';
switch ( $type ) {
case 'date':
$date = true;
break;
case 'append':
$append = true;
break;
case 'email':
$input_type = 'email';
break;
case 'url':
$input_type = 'url';
break;
case 'number':
$input_type = 'number';
break;
case 'checkbox':
$input_type = 'checkbox';
break;
}
$input_args = array(
'class' => $class,
);
$settings = $this->_registry->get( 'model.settings' );
if ( true === $date ) {
$input_args += array(
'data-date-weekstart' => $settings->get( 'week_start_day' ),
'data-date-format' => $system->get_date_pattern_by_key(
$settings->get( 'input_date_format' )
),
'size' => 12,
);
}
$args = array(
'id' => $this->_args['id'],
'label' => $this->_args['renderer']['label'],
'input_args' => $input_args,
'input_type' => $input_type,
'value' => $this->_args['value'],
);
if ( isset( $this->_args['renderer']['status'] ) ) {
$args['licence_valid'] =
$settings->get( $this->_args['renderer']['status'] ) === 'valid' ?
true :
false;
}
if ( true === $append ) {
$args['append'] = $this->_args['renderer']['append'];
}
if ( isset( $this->_args['renderer']['help'] ) ) {
$args['help'] = $this->_args['renderer']['help'];
}
if ( isset( $this->_args['renderer']['group-class'] ) ) {
$args['group_class'] = $this->_args['renderer']['group-class'];
}
if ( isset( $this->_args['checked'] ) && true === $this->_args['checked'] )
$args['input_args']['checked'] = $this->_args['checked'];
$loader = $this->_registry->get( 'theme.loader' );
$file = $loader->get_file( 'setting/input.twig', $args, true );
if ( isset( $this->_args['type'] ) && 'hidden' === $this->_args['type'] ) {
$hidden = true;
} else {
$hidden = false;
}
return parent::render( $file->get_content(), $wrap, $hidden );
}
}

View File

@@ -0,0 +1,148 @@
<?php
/**
* Renderer of settings page select option.
*
* @author Time.ly Network, Inc.
* @instantiator new
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
class Ai1ec_Html_Setting_Select extends Ai1ec_Html_Element_Settings {
/* (non-PHPdoc)
* @see Ai1ec_Html_Element_Settings::render()
*/
public function render( $output = '', $wrap = true, $hidden = false ) {
$options = $this->_args['renderer']['options'];
if ( ! is_array( $options ) ) {
$callback = explode( ':', $options );
if ( ! isset( $callback[1] ) ) {
$options = $this->{$options}();
} else {
$value = $this->_args['value'];
if( false === is_array( $this->_args['value'] ) ){
$value = array( $this->_args['value'] );
}
try {
$options = $this->_registry->dispatch(
$callback[0],
$callback[1]
);
} catch (Ai1ec_Bootstrap_Exception $exc) {
return '';
}
}
}
$options = apply_filters( 'ai1ec_settings_select_options' , $options, $this->_args['id'] );
$fieldsets = array();
foreach ( $options as $key => &$option ) {
// if the key is a string, it's an optgroup
if ( is_string( $key ) ) {
foreach ( $option as &$opt ) {
$opt = $this->_set_selected_value( $opt );
}
} else {
$option = $this->_set_selected_value( $option );
if ( isset( $option['settings'] ) ) {
$fieldsets[] = $this->_render_fieldset(
$option['settings'],
$option['value'],
$this->_args['id'],
isset( $option['args']['selected'] )
);
}
}
}
$select_args = array();
$args = array(
'id' => $this->_args['id'],
'label' => $this->_args['renderer']['label'],
'attributes' => $select_args,
'options' => $options,
'fieldsets' => $fieldsets,
);
$loader = $this->_registry->get( 'theme.loader' );
$file = $loader->get_file( 'setting/select.twig', $args, true );
return parent::render( $file->get_content(), $wrap, $hidden );
}
/**
* Toggle `selected` attribute according to current selection.
*
* @param array $option Option being checked.
*
* @return array Optionally modified option entry.
*/
protected function _set_selected_value( array $option ) {
if ( $option['value'] === $this->_args['value'] ) {
$option['args'] = array(
'selected' => 'selected',
);
}
return $option;
}
/**
* Gets the options for the "Starting day of week" select.
*
* @return array
*/
protected function get_weekdays() {
$locale = $this->_registry->get( 'p28n.wpml' );
$options = array();
for ( $day_index = 0; $day_index <= 6; $day_index++ ) {
$option = array(
'text' => $locale->get_weekday( $day_index ),
'value' => $day_index,
);
$options[] = $option;
}
return $options;
}
/**
* Renders fieldset with options for selected item.
*
* @param array $settings Settings structure.
* @param string $parent_id Option value from parent Html select element.
* @param string $select_id Html Select element id.
* @param bool $visible Whether fieldset is visible or not.
*
* @return string Html content.
*
* @throws Ai1ec_Bootstrap_Exception
*/
protected function _render_fieldset(
array $settings,
$parent_id,
$select_id,
$visible = false
) {
$setting_renderer = $this->_registry->get(
'html.element.setting-renderer'
);
$global_settings = $this->_registry->get(
'model.settings'
);
$content = '';
foreach ( $settings as $id => $setting ) {
$setting['id'] = $id;
// fetch value from real setting as this one is some kind of
// mockup.
$setting['value'] = $global_settings->get( $id );
$content .= $setting_renderer->render( $setting );
}
$args = array(
'parent_id' => $parent_id,
'contents' => $content,
'select_id' => $select_id,
'visible' => $visible,
);
$loader = $this->_registry->get( 'theme.loader' );
$file = $loader->get_file( 'setting/select-fieldsets.twig', $args, true );
return parent::render( $file->get_content(), false );
}
}

View File

@@ -0,0 +1,98 @@
<?php
/**
* Renderer of settings page tags and categories option.
*
* @author Time.ly Network, Inc.
* @instantiator new
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
class Ai1ec_Html_Setting_Tags_Categories extends Ai1ec_Html_Element_Settings {
/* (non-PHPdoc)
* @see Ai1ec_Html_Element_Settings::render()
*/
public function render( $output = '', $wrap = true, $hidden = false ) {
$tags = array();
$categories = array();
foreach ( array( 'tags', 'categories' ) as $type ) {
$options = array(
'taxonomy' => 'events_' . $type,
'hierarchical' => true,
);
${$type} = get_categories( $options );
}
if ( empty ( $tags ) && empty ( $categories ) ) {
return '';
}
$args = array(
'label' => $this->_args['renderer']['label'],
'help' => $this->_args['renderer']['help'],
);
$loader = $this->_registry->get( 'theme.loader' );
if ( ! empty ( $tags ) ) {
$args['tags'] = $this->_get_select_for_terms(
'tags',
Ai1ec_I18n::__( 'Tags' ),
$tags
);
}
$categories_html = '';
if ( ! empty ( $categories ) ) {
$args['categories'] = $this->_get_select_for_terms(
'categories',
Ai1ec_I18n::__( 'Categories' ),
$categories
);
}
return $loader->get_file( 'setting/tags-categories.twig', $args, true )
->get_content();
}
/**
* Creates the multiselect for tags and categories
*
* @param string $type
* @param string $label
* @param array $terms
*
* @return string The html for the select
*/
protected function _get_select_for_terms( $type, $label, array $terms ) {
$loader = $this->_registry->get( 'theme.loader' );
$options = array();
foreach ( $terms as $term ) {
$option = array(
'value' => $term->term_id,
'text' => $term->name,
);
if ( isset( $this->_args['value'][$type] ) ) {
if ( in_array( $term->term_id , $this->_args['value'][$type] ) ) {
$option['args'] = array(
'selected' => 'selected',
);
}
}
$options[] = $option;
}
$args = array(
'id' => $this->_args['id'] . '_default_' . $type,
'name' => $this->_args['id'] . '_default_' . $type . '[]',
'label' => $label,
'options' => $options,
'stacked' => true,
'attributes' => array(
'class' => 'ai1ec-form-control',
'multiple' => 'multiple',
// for Widget creator
'data-id' => 'tags' === $type ? 'tag_ids' : 'cat_ids',
),
);
return $loader->get_file( 'setting/select.twig', $args, true )
->get_content();
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* Renderer of settings page textarea option.
*
* @author Time.ly Network, Inc.
* @instantiator new
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
class Ai1ec_Html_Setting_Textarea extends Ai1ec_Html_Element_Settings {
const DEFAULT_ROWS = 6;
/* (non-PHPdoc)
* @see Ai1ec_Html_Element_Settings::render()
*/
public function render( $output = '', $wrap = true, $hidden = false ) {
$type = $this->_args['renderer']['type'];
$date = $append = false;
// Set attributes
$input_args = array();
// Set textarea rows
if ( ! empty( $this->_args['renderer']['rows'] ) ) {
$input_args['rows'] = $this->_args['renderer']['rows'];
}
// Set textarea disabled
if ( ! empty( $this->_args['renderer']['disabled'] ) ) {
$input_args['disabled'] = $this->_args['renderer']['disabled'];
}
// Set textarea readonly
if ( ! empty( $this->_args['renderer']['readonly'] ) ) {
$input_args['readonly'] = $this->_args['renderer']['readonly'];
}
$args = array(
'id' => $this->_args['id'],
'label' => $this->_args['renderer']['label'],
'input_args' => $input_args,
'value' => $this->_args['value'],
);
if ( true === $append ) {
$args['append'] = $this->_args['renderer']['append'];
}
if ( isset( $this->_args['renderer']['help'] ) ) {
$args['help'] = $this->_args['renderer']['help'];
}
$loader = $this->_registry->get( 'theme.loader' );
$file = $loader->get_file( 'setting/textarea.twig', $args, true );
return parent::render( $file->get_content(), $wrap, $hidden );
}
}

View File

@@ -0,0 +1,12 @@
<?php
/**
* Exception which occurs during HTML generation.
*
* @author Time.ly Network, Inc.
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Exception
*/
class Ai1ec_Html_Exception extends Ai1ec_Exception {
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* Wrapper to HTML convenience methods.
*
* @author Time.ly Network, Inc.
* @since 2.0
* @package Ai1EC
* @subpackage Ai1EC.Html
*/
class Ai1ec_Html_Helper {
/**
* Escape HTML for use within any tag.
*
* @param string $input Arbitrary UTF-8 input.
*
* @return string Escaped HTML value.
*/
public function esc_html( $input ) {
return esc_html( $input );
}
/**
* Escape string for use within HTML attribute.
*
* @param string $input Characters to be used as HTML attribute.
*
* @return string Escaped characters sequence.
*/
public function esc_attr( $input ) {
return esc_attr( $input );
}
}