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,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;
}
}