Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
body {
font-family: Arial;
font-size: 14px;
background-color: #fff;
}
p {
margin: 0px;
}
p + p {
margin-top: 5px;
}

View File

@@ -0,0 +1,146 @@
(function($){
if ( !$.factory ) $.factory = {}
if ( $.factory.widget ) return;
/**
* OnePress Widget Factory.
*/
$.factory.widget = function (pluginName, pluginObject) {
var factory = {
createWidget: function (element, options) {
var widget = $.extend(true, {}, pluginObject);
widget.element = $(element);
widget.options = $.extend(true, widget.options, options);
if (widget._init) widget._init();
if (widget._create) widget._create();
$.data(element, 'plugin_' + pluginName, widget);
},
callMethod: function (widget, methodName) {
widget[methodName] && widget[methodName]();
}
};
$.fn[pluginName] = function () {
var args = arguments;
var argsCount = arguments.length;
this.each(function () {
var widget = $.data(this, 'plugin_' + pluginName);
// a widget is not created yet
if (!widget && argsCount <= 1) {
factory.createWidget(this, argsCount ? args[0] : false);
// a widget is created, the public method with no args is being called
} else if (argsCount == 1) {
factory.callMethod(widget, args[0]);
}
});
};
};
/**
* Radio #1
*/
$.fn.onpRadioCircles = function( options ) {
if ( !options ) options = {};
options.theme = 'circles';
$(this).onpRadio(options);
};
$.fn.onpRadioSquares = function( options ) {
if ( !options ) options = {};
options.theme = 'squares';
$(this).onpRadio(options);
};
$.factory.widget('onpRadio', {
options: {
theme: 'squares',
selected: null
},
_create: function() {
var self = this;
this._createMarkup();
this.radio.find('.onp-radio-option').click(function(){
if ( $(this).is(".disabled") ) return;
var selected = self.radio.find('.onp-radio-option.selected');
if ( selected.data('value') == $(this).data('value')) return;
selected.removeClass('selected');
$(this).addClass("selected");
var value = $(this).data('value');
self.element.val(value);
self.element.trigger( "change", $(this).data('value') );
});
},
_createMarkup: function() {
var wrap = $("<ul class='onp-radio-wrap'></ul>").addClass('onp-radio-' + this.options.theme);
this.element.find("option").each(function(){
var $this = $(this);
var value = $this.attr('value');
var text = $this.html();
var icon = $this.data('icon');
var disabled = $this.attr('disabled');
var option = $("<li class='onp-radio-option' data-value='" + value + "'></li>");
var innerOptionWrap = $("<span class='onp-radio-option-inner-wrap'></span>").appendTo(option);
option.addClass('onp-radio-option-' + value);
if ( icon ) innerOptionWrap.append("<i class='" + icon + "'></i>");
if ( disabled ) option.addClass('disabled');
wrap.append(option);
});
this.options.selected = this.options.selected || this.element.find("option:selected").attr('value');
wrap.find('.onp-radio-option-' + this.options.selected).addClass("selected");
this.element.hide();
this.element.after(wrap);
this.radio = wrap;
}
});
var factoryForms = {
collapsedGroups: function( $target ) {
if ( !$target ) $target = $("body");
$target.find(".fy-collapsed-show").click(function(){
$( $(this).attr('href') ).fadeIn();
$(this).hide();
return false;
});
$target.find(".fy-collapsed-hide").click(function(){
var content = $( $(this).attr('href') );
content.fadeOut(300, function(){
content.prev().show();
});
return false;
});
}
}
$(function(){
$(".onp-radio-circles.auto").onpRadioCircles();
$(".onp-radio-squares.auto").onpRadioSquares();
factoryForms.collapsedGroups();
});
})(jQuery)

View File

@@ -0,0 +1,247 @@
<?php
/**
* Factory Forms
*
* Factory Forms is a Factory module that provides a declarative
* way to build forms without any extra html or css markup.
*
* Factory is an internal professional framework developed by OnePress Ltd
* for own needs. Please don't use it to create your own independent plugins.
* In future the one will be documentated and released for public.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
// the module provides function for the admin area only
if ( !is_admin() ) return;
// checks if the module is already loaded in order to
// prevent loading the same version of the module twice.
if (defined('FACTORY_FORMS_328_LOADED')) return;
define('FACTORY_FORMS_328_LOADED', true);
// absolute path and URL to the files and resources of the module.
define('FACTORY_FORMS_328_DIR', dirname(__FILE__));
define('FACTORY_FORMS_328_URL', plugins_url(null, __FILE__ ));
#comp merge
require(FACTORY_FORMS_328_DIR . '/includes/providers/value-provider.interface.php');
require(FACTORY_FORMS_328_DIR . '/includes/providers/meta-value-provider.class.php');
require(FACTORY_FORMS_328_DIR . '/includes/providers/options-value-provider.class.php');
require(FACTORY_FORMS_328_DIR. '/includes/form.class.php');
require(FACTORY_FORMS_328_DIR. '/helpers.php');
#endcomp
/**
* We add this code into the hook because all these controls quite heavy. So in order to get better perfomance,
* we load the form controls only on pages where the forms are created.
*
* @see the 'factory_forms_328_register_controls' hook
*
* @since 3.0.7
*/
if (!function_exists('factory_forms_328_register_default_controls')) {
function factory_forms_328_register_default_controls( $plugin ) {
if ( $plugin && !isset( $plugin->forms) ) {
throw new Exception("The module Factory Forms is not loaded for the plugin '{$plugin->pluginName}'.");
}
require_once(FACTORY_FORMS_328_DIR. '/includes/html-builder.class.php');
require_once(FACTORY_FORMS_328_DIR. '/includes/form-element.class.php');
require_once(FACTORY_FORMS_328_DIR. '/includes/control.class.php');
require_once(FACTORY_FORMS_328_DIR. '/includes/complex-control.class.php');
require_once(FACTORY_FORMS_328_DIR. '/includes/holder.class.php');
require_once(FACTORY_FORMS_328_DIR. '/includes/control-holder.class.php');
require_once(FACTORY_FORMS_328_DIR. '/includes/custom-element.class.php');
require_once(FACTORY_FORMS_328_DIR. '/includes/form-layout.class.php');
// registration of controls
$plugin->forms->registerControls(array(
array(
'type' => 'checkbox',
'class' => 'FactoryForms328_CheckboxControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/checkbox.php'
),
array(
'type' => 'list',
'class' => 'FactoryForms328_ListControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/list.php'
),
array(
'type' => 'dropdown',
'class' => 'FactoryForms328_DropdownControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/dropdown.php'
),
array(
'type' => 'hidden',
'class' => 'FactoryForms328_HiddenControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/hidden.php'
),
array(
'type' => 'hidden',
'class' => 'FactoryForms328_HiddenControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/hidden.php'
),
array(
'type' => 'radio',
'class' => 'FactoryForms328_RadioControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/radio.php'
),
array(
'type' => 'textarea',
'class' => 'FactoryForms328_TextareaControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/textarea.php'
),
array(
'type' => 'textbox',
'class' => 'FactoryForms328_TextboxControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/textbox.php'
),
array(
'type' => 'url',
'class' => 'FactoryForms328_UrlControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/url.php'
),
array(
'type' => 'wp-editor',
'class' => 'FactoryForms328_WpEditorControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/wp-editor.php'
),
array(
'type' => 'color',
'class' => 'FactoryForms328_ColorControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/color.php'
),
array(
'type' => 'color-and-opacity',
'class' => 'FactoryForms328_ColorAndOpacityControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/color-and-opacity.php'
),
array(
'type' => 'gradient',
'class' => 'FactoryForms328_GradientControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/gradient.php'
),
array(
'type' => 'font',
'class' => 'FactoryForms328_FontControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/font.php'
),
array(
'type' => 'google-font',
'class' => 'FactoryForms328_GoogleFontControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/google-font.php'
),
array(
'type' => 'pattern',
'class' => 'FactoryForms328_PatternControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/pattern.php'
),
array(
'type' => 'integer',
'class' => 'FactoryForms328_IntegerControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/integer.php'
),
array(
'type' => 'control-group',
'class' => 'FactoryForms328_ControlGroupHolder',
'include' => FACTORY_FORMS_328_DIR. '/controls/holders/control-group.php'
),
array(
'type' => 'paddings-editor',
'class' => 'FactoryForms328_PaddingsEditorControl',
'include' => FACTORY_FORMS_328_DIR. '/controls/paddings-editor.php'
),
));
// registration of control holders
$plugin->forms->registerHolders(array(
array(
'type' => 'tab',
'class' => 'FactoryForms328_TabHolder',
'include' => FACTORY_FORMS_328_DIR. '/controls/holders/tab.php'
),
array(
'type' => 'tab-item',
'class' => 'FactoryForms328_TabItemHolder',
'include' => FACTORY_FORMS_328_DIR. '/controls/holders/tab-item.php'
),
array(
'type' => 'accordion',
'class' => 'FactoryForms328_AccordionHolder',
'include' => FACTORY_FORMS_328_DIR. '/controls/holders/accordion.php'
),
array(
'type' => 'accordion-item',
'class' => 'FactoryForms328_AccordionItemHolder',
'include' => FACTORY_FORMS_328_DIR. '/controls/holders/accordion-item.php'
),
array(
'type' => 'control-group',
'class' => 'FactoryForms328_ControlGroupHolder',
'include' => FACTORY_FORMS_328_DIR. '/controls/holders/control-group.php'
),
array(
'type' => 'control-group-item',
'class' => 'FactoryForms328_ControlGroupItem',
'include' => FACTORY_FORMS_328_DIR. '/controls/holders/control-group-item.php'
),
array(
'type' => 'form-group',
'class' => 'FactoryForms328_FormGroupHolder',
'include' => FACTORY_FORMS_328_DIR. '/controls/holders/form-group.php'
),
array(
'type' => 'more-link',
'class' => 'FactoryForms328_MoreLinkHolder',
'include' => FACTORY_FORMS_328_DIR. '/controls/holders/more-link.php'
),
array(
'type' => 'div',
'class' => 'FactoryForms328_DivHolder',
'include' => FACTORY_FORMS_328_DIR. '/controls/holders/div.php'
),
array(
'type' => 'columns',
'class' => 'FactoryForms328_ColumnsHolder',
'include' => FACTORY_FORMS_328_DIR. '/controls/holders/columns.php'
)
));
// registration custom form elements
$plugin->forms->registerCustomElements(array(
array(
'type' => 'html',
'class' => 'FactoryForms328_Html',
'include' => FACTORY_FORMS_328_DIR. '/controls/customs/html.php',
),
array(
'type' => 'separator',
'class' => 'FactoryForms328_Separator',
'include' => FACTORY_FORMS_328_DIR. '/controls/customs/separator.php',
),
));
// registration of form layouts
$plugin->forms->registerFormLayout( array(
'name' => 'bootstrap-2',
'class' => 'FactoryForms328_Bootstrap2FormLayout',
'include' => FACTORY_FORMS_328_DIR. '/layouts/bootstrap-2/bootstrap-2.php'
));
$plugin->forms->registerFormLayout( array(
'name' => 'bootstrap-3',
'class' => 'FactoryForms328_Bootstrap3FormLayout',
'include' => FACTORY_FORMS_328_DIR. '/layouts/bootstrap-3/bootstrap-3.php'
));
}
add_action('factory_forms_328_register_controls', 'factory_forms_328_register_default_controls');
}

View File

@@ -0,0 +1,106 @@
<?php
/**
* Checkbox Control
*
* Main options:
* name => a name of the control
* value => a value to show in the control
* default => a default value of the control if the "value" option is not specified
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
class FactoryForms328_CheckboxControl extends FactoryForms328_Control
{
public $type = 'checkbox';
public function getSubmitValue( $name, $subName ) {
$nameOnForm = $this->getNameOnForm( $name );
return isset($_POST[$nameOnForm]) && $_POST[$nameOnForm] != 0 ? 1 : 0;
}
/**
* Shows the html markup of the control.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
if ( 'buttons' == $this->getOption('way') ) {
$this->buttonsHtml();
} else {
$this->defaultHtml();
}
}
/**
* Shows the Buttons Checkbox.
*
* @since 1.0.0
* @return void
*/
protected function buttonsHtml() {
$value = $this->getValue();
$nameOnForm = $this->getNameOnForm();
$this->addCssClass('factory-buttons-way');
$this->addCssClass('btn-group');
if ( $this->getOption('tumbler', false ) ) {
$this->addCssClass('factory-tumbler');
}
$tumblerFunction = $this->getOption('tumblerFunction', false );
if ( $tumblerFunction ) $this->addHtmlData('tumbler-function', $tumblerFunction );
if ( $this->getOption('tumblerHint', false ) ) {
$this->addCssClass('factory-has-tumbler-hint');
$delay = $this->getOption('tumblerDelay', 3000);
$this->addHtmlData('tumbler-delay', $delay);
}
?>
<div <?php $this->attrs() ?>>
<button type="button" class="btn btn-default btn-small btn-sm factory-on <?php if ( $value ) { echo 'active'; } ?>"><?php _e('On', 'factory_forms_328') ?></button>
<button type="button" class="btn btn-default btn-small btn-sm factory-off <?php if ( !$value ) { echo 'active'; } ?>" data-value="0"><?php _e('Off', 'factory_forms_328') ?></button>
<input type="checkbox" style="display: none" id="<?php echo $nameOnForm ?>" class="factory-result" name="<?php echo $nameOnForm ?>" value="1" <?php if ( $value ) { echo 'checked="checked"'; } ?>" />
</div>
<?php if ( $this->getOption('tumblerHint', false )) { ?>
<div class="factory-checkbox-tumbler-hint factory-tumbler-hint" style="display: none;">
<div class="factory-tumbler-content">
<?php echo $this->getOption('tumblerHint') ?>
</div>
</div>
<?php } ?>
<?php
}
/**
* Shows the standart checkbox.
*
* @since 1.0.0
* @return void
*/
protected function defaultHtml() {
$value = $this->getValue();
$nameOnForm = $this->getNameOnForm();
$this->addHtmlAttr('type', 'checkbox');
$this->addHtmlAttr('id', $nameOnForm);
$this->addHtmlAttr('name', $nameOnForm);
$this->addHtmlAttr('value', $value);
if ( $value ) $this->addHtmlAttr('checked', 'checked');
$this->addCssClass('factory-default-way');
?>
<input <?php $this->attrs() ?>/>
<?php
}
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* Color and Opacity
*
* Main options:
* name => a name of the control
* value => a value to show in the control
* default => a default value of the control if the "value" option is not specified
*
* @author Alex Kovalev <alex.kovalevv@gmail.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package core
* @since 1.0.0
*/
class FactoryForms328_ColorAndOpacityControl extends FactoryForms328_ComplexControl
{
public $type = 'color-and-opacity';
public function __construct( $options, $form, $provider = null ) {
parent::__construct( $options, $form, $provider );
if ( !isset( $options['color']) ) $options['color'] = array();
$options['color'] = array_merge($options['color'], array(
'name' => $this->options['name'] . '__color',
'default' => isset( $this->options['default'] ) ? $this->options['default']['color'] : '#1e8cbe',
'pickerTarget' => '.factory-control-' . $this->options['name'] . ' .factory-picker-target'
));
if ( !isset( $options['opacity']) ) $options['opacity'] = array();
$options['opacity'] = array_merge($options['opacity'], array(
'name' => $this->options['name'] . '__opacity',
'default' => isset( $this->options['default'] ) ? $this->options['default']['opacity'] : 100,
'units' => '%',
'range' => array(0, 100),
'way' => 'slider'
));
$this->color = new FactoryForms328_ColorControl( $options['color'], $form, $provider );
$this->opacity = new FactoryForms328_IntegerControl( $options['opacity'], $form, $provider );
$this->innerControls = array( $this->color, $this->opacity );
}
/**
* Shows the html markup of the control.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
?>
<div <?php $this->attrs() ?>>
<div class="factory-control-row">
<div class="factory-color-wrap">
<?php $this->color->html() ?>
</div>
<div class="factory-opacity-wrap">
<?php $this->opacity->html() ?>
</div>
</div>
<div class="factory-picker-target"></div>
</div>
<?php
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* Color
*
* Main options:
* name => a name of the control
* value => a value to show in the control
* default => a default value of the control if the "value" option is not specified
*
* @author Alex Kovalev <alex.kovalevv@gmail.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package core
* @since 1.0.0
*/
class FactoryForms328_ColorControl extends FactoryForms328_Control
{
public $type = 'color';
/**
* Shows the html markup of the control.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
$name = $this->getNameOnForm();
$value = $this->getValue();
if ( !$value ) $value = '#1e8cbe';
// the "pickerTarget" options allows to select element where the palette will be shown
$pickerTarget = $this->getOption('pickerTarget');
if ( !empty( $pickerTarget ) ) $this->addHtmlData('picker-target', $pickerTarget);
?>
<div <?php $this->attrs() ?>>
<div class="factory-background" <?php echo (!empty($value) ? 'style="background:'.$value.';"' : '' ); ?>></div>
<div class="factory-pattern"></div>
<input type="text" id="<?php echo $name; ?>" name="<?php echo $name; ?>" class="factory-input-text factory-color-hex" value="<?php echo $value; ?>">
</div>
<?php
}
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* Html Markup
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
class FactoryForms328_Html extends FactoryForms328_CustomElement
{
public $type = 'html';
/**
* Shows the html markup of the element.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
$html = $this->getOption('html', '');
// if the data options is a valid callback for an object method
if (
( is_array($html) &&
count($html) == 2 &&
gettype($html[0]) == 'object' ) || function_exists( $html ) ) {
call_user_func($html);
return;
}
// if the data options is an array of values
echo $html;
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Html Markup
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
class FactoryForms328_Separator extends FactoryForms328_CustomElement
{
public $type = 'separator';
/**
* Shows the html markup of the element.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
?>
<div <?php $this->attrs()?>></div>
<?php
}
}

View File

@@ -0,0 +1,305 @@
<?php
/**
* Dropdown List Control
*
* Main options:
* name => a name of the control
* value => a value to show in the control
* default => a default value of the control if the "value" option is not specified
* items => a callback to return items or an array of items to select
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
class FactoryForms328_DropdownControl extends FactoryForms328_Control
{
public $type = 'dropdown';
/**
* Returns a set of available items for the list.
*
* @since 1.0.0
* @return mixed[]
*/
private function getItems() {
$data = $this->getOption('data', array());
// if the data options is a valid callback for an object method
if (
is_array($data) &&
count($data) == 2 &&
gettype($data[0]) == 'object' ) {
return call_user_func($data);
// if the data options is a valid callback for a function
} elseif ( gettype($data) == 'string' ) {
return $data();
}
// if the data options is an array of values
return $data;
}
/**
* Returns true, if the data should be loaded via ajax.
*
* @since 1.0.0
* @return bool
*/
protected function isAjax() {
$data = $this->getOption('data', array());
return is_array($data) && isset($data['ajax']);
}
/**
* Shows the html markup of the control.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
$way = $this->getOption('way', 'default');
$this->addHtmlData('way', $way);
if ( $this->isAjax() ) {
$data = $this->getOption('data', array());
$ajaxId = 'factory-dropdown-' . rand(1000000, 9999999);
$value = $this->getValue();
if ( empty( $value ) || ( is_array( $value) && empty( $value[0] ) ) ) $value = null;
?>
<div class="factory-ajax-loader <?php echo $ajaxId . '-loader'; ?>"></div>
<script>
window['<?php echo $ajaxId ?>'] = {
'loader': '.<?php echo $ajaxId . '-loader' ?>',
'url': '<?php echo $data['url'] ?>',
'data': <?php echo json_encode( $data['data'] ) ?>,
'selected': '<?php echo $value ?>',
'emptyList': '<?php echo $this->getOption('empty', __('The list is empty.', 'factory_forms_328') ) ?>'
};
</script>
<?php
$this->addHtmlData('ajax', true);
$this->addHtmlData('ajax-data-id', $ajaxId);
$this->addCssClass('factory-hidden');
}
if ( 'buttons' == $way ) {
$this->buttonsHtml();
} elseif ( 'ddslick' == $way ) {
$this->ddslickHtml();
} else {
$this->defaultHtml();
}
}
/**
* Shows the Buttons Dropdown.
*
* @since 1.0.0
* @return void
*/
protected function buttonsHtml() {
$items = $this->getItems();
$value = $this->getValue();
$nameOnForm = $this->getNameOnForm();
$this->addCssClass('factory-buttons-way');
?>
<div <?php $this->attrs() ?>>
<div class="btn-group factory-buttons-group">
<?php foreach($items as $item) { ?>
<button type="button" class="btn btn-default btn-small factory-<?php echo $item[0] ?> <?php if ( $value == $item[0] ) { echo 'active'; } ?>" data-value="<?php echo $item[0] ?>"><?php echo $item[1] ?></button>
<?php } ?>
<input type="hidden" id="<?php echo $nameOnForm ?>" class="factory-result" name="<?php echo $nameOnForm ?>" value="<?php echo $value ?>" />
</div>
<div class="factory-hints">
<?php foreach($items as $item) { ?>
<?php if ( isset( $item[2] )) { ?>
<div class="factory-hint factory-hint-<?php echo $item[0] ?>" <?php if ( $value !== $item[0] ) { echo 'style="display: none;"'; } ?>><?php echo $item[2] ?></div>
<?php } ?>
<?php } ?>
</div>
</div>
<?php
}
/**
* Shows the ddSlick dropbox.
*
* @since 3.2.8
* @return void
*/
protected function ddslickHtml() {
$items = $this->getItems();
$value = $this->getValue();
$nameOnForm = $this->getNameOnForm();
$this->addCssClass('factory-ddslick-way');
$this->addHtmlData('name', $nameOnForm);
$this->addHtmlData('width', $this->getOption('width', 300));
$this->addHtmlData('align', $this->getOption('imagePosition', 'right'));
?>
<div <?php $this->attrs() ?>>
<script>
//Dropdown plugin data
var factory_<?php echo $nameOnForm ?>_data = [
<?php foreach ( $items as $item ) { ?>
{
text: "<?php echo $item['title'] ?>",
value: "<?php echo $item['value'] ?>",
selected: <?php if ( $value == $item['value'] ) { echo 'true'; } else { echo 'false'; } ?>,
description: "<?php echo ( isset( $item['hint'] ) ? $item['hint'] : '' ); ?>",
imageSrc: "<?php echo ( isset( $item['image'] ) ? $item['image'] : '' ); ?>",
imageHoverSrc: "<?php echo ( isset( $item['hover'] ) ? $item['hover'] : '' ); ?>"
},
<?php } ?>
];
</script>
<div class="factory-ddslick"></div>
<input type="hidden" class="factory-result" id="<?php echo $nameOnForm ?>" name="<?php echo $nameOnForm ?>" value="<?php echo $value ?>" />
</div>
<?php
}
/**
* Shows the standart dropdown.
*
* @since 1.3.1
* @return void
*/
protected function defaultHtml() {
$items = $this->getItems();
$value = $this->getValue();
$nameOnForm = $this->getNameOnForm();
$this->addHtmlAttr('id', $nameOnForm);
$this->addHtmlAttr('name', $nameOnForm);
$this->addCssClass('form-control');
$hasGroups = $this->getOption('hasGroups', true);
$hasHints = $this->getOption('hasHints', false);
foreach($items as $item) {
if ( !isset( $item['hint'] ) ) continue;
if ( empty( $item['hint'] ) ) continue;
$hasHints = true;
break;
}
$isEmpty = $this->isAjax() || empty( $items );
$emptyList = $this->getOption('empty', __('- empty -', 'factory_forms_328') );
?>
<select <?php $this->attrs() ?>>
<?php if ( $isEmpty ) { ?>
<option value='' class="factory-empty-option" >
<?php echo $emptyList ?>
</option>
<?php } else { ?>
<?php $this->printItems( $items, $value ) ?>
<?php } ?>
</select>
<?php if ( $hasHints ) { ?>
<div class="factory-hints">
<?php foreach($items as $item) {
$hint = isset( $item[2] ) ? $item[2] : null;
$hint = isset( $item['hint'] ) ? $item['hint'] : null;
$value = isset( $item[0] ) ? $item[0] : null;
$value = isset( $item['value'] ) ? $item['value'] : null;
if ( !empty( $hint ) ) { ?>
<div style="display: none;" class="factory-hint factory-hint-<?php echo $value ?>" <?php if ( $value !== $value ) { echo 'style="display: none;"'; } ?>><?php echo $hint ?></div>
<?php }
} ?>
</div>
<?php } ?>
<?php
}
protected function printItems( $items, $selected = null ) {
foreach( $items as $item ) {
$subitems = array();
$data = null;
// this item is an associative array
if ( isset( $item['type'] ) || isset( $item['value'] ) ) {
$type = isset( $item['type'] ) ? $item['type'] : 'option';
if ( 'group' === $type ) $subitems = isset( $item['items'] ) ? $item['items'] :array();
$value = isset( $item['value'] ) ? $item['value'] : '';
$title = isset( $item['title'] ) ? $item['title'] : __( '- empty -', 'factory_forms_328' );
$data = isset( $item['data'] ) ? $item['data'] : null;
} else {
$type = ( count($item) == 3 && $item[0] === 'group' ) ? 'group' : 'option';
if ( 'group' === $type ) $subitems = $item[2];
$title = $item[1];
$value = $item[0];
}
if ( 'group' === $type ) {
?>
<optgroup label="<?php echo $item[1] ?>" >
<?php $this->printItems( $subitems, $selected ); ?>
</optgroup>
<?php
} else {
$attr = ( $selected == $value ) ? 'selected="selected"' : '';
$strData = '';
if ( !empty( $data ) ) {
foreach( $data as $key => $values ) {
$strData = $strData . ' data-' . $key . '="' . ( is_array( $values ) ? implode(',', $values ) : $values ) . '"';
}
}
?>
<option value='<?php echo $value ?>' <?php echo $attr ?> <?php echo $strData ?>>
<?php echo $title ?>
</option>
<?php
}
}
}
}

View File

@@ -0,0 +1,169 @@
<?php
/**
* Dropdown List Control
*
* Main options:
* name => a name of the control
* value => a value to show in the control
* default => a default value of the control if the "value" option is not specified
* items => a callback to return items or an array of items to select
*
* @author Alex Kovalev <alex@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package core
* @since 1.0.0
*/
class FactoryForms328_FontControl extends FactoryForms328_ComplexControl
{
public $type = 'font';
public function __construct($options, $form, $provider = null) {
parent::__construct($options, $form, $provider);
$optionFontSize = array(
'name' => $this->options['name'] . '__size',
'units' => $this->options['units'],
'default' => isset( $this->options['default'] ) ? $this->options['default']['size'] : null
);
$optionFontFamily = array(
'name' => $this->options['name'] . '__family',
'data' => $this->getFonts(),
'default' => isset( $this->options['default'] ) ? $this->options['default']['family'] : null
);
$optionFontColor = array(
'name' => $this->options['name'] . '__color',
'default' => isset( $this->options['default'] ) ? $this->options['default']['color'] : null,
'pickerTarget' => '.factory-control-' . $this->options['name'] . ' .factory-picker-target'
);
$this->size = new FactoryForms328_IntegerControl( $optionFontSize, $form, $provider );
$this->family = new FactoryForms328_DropdownControl( $optionFontFamily, $form, $provider );
$this->color = new FactoryForms328_ColorControl( $optionFontColor, $form, $provider );
$this->innerControls = array( $this->family, $this->size, $this->color );
}
public function getFonts() {
$fonts = $this->getDefaultFonts();
$fonts = apply_filters('factory_forms_328_fonts', $fonts);
$fonts = apply_filters('factory_forms_328_fonts-' . $this->options['name'], $fonts);
return $fonts;
}
public function getDefaultFonts() {
$fonts = array(
array( 'inherit', __( '(use default website font)', 'factory_forms_328' ) ),
array( 'group', __('Sans Serif:', 'factory_forms_328'), array(
array( 'Arial, "Helvetica Neue", Helvetica, sans-serif', 'Arial' ),
array( '"Arial Black", "Arial Bold", Gadget, sans-serif', 'Arial Black' ),
array( '"Arial Narrow", Arial, sans-serif', 'Arial Narrow' ),
array( '"Arial Rounded MT Bold", "Helvetica Rounded", Arial, sans-serif', 'Arial Rounded MT Bold' ),
array( '"Avant Garde", Avantgarde, "Century Gothic", CenturyGothic, "AppleGothic", sans-serif', 'Avant Garde' ),
array( 'Calibri, Candara, Segoe, "Segoe UI", Optima, Arial, sans-serif', 'Calibri' ),
array( 'Candara, Calibri, Segoe, "Segoe UI", Optima, Arial, sans-serif', 'Candara' ),
array( '"Century Gothic", CenturyGothic, AppleGothic, sans-serif', 'Century Gothic' ),
array( '"Franklin Gothic Medium", "Franklin Gothic", "ITC Franklin Gothic", Arial, sans-serif', 'Franklin Gothic Medium' ),
array( 'Futura, "Trebuchet MS", Arial, sans-serif', 'Futura' ),
array( 'Geneva, Tahoma, Verdana, sans-serif', 'Geneva' ),
array( '"Gill Sans", "Gill Sans MT", Calibri, sans-serif', 'Gill Sans' ),
array( '"Helvetica Neue", Helvetica, Arial, sans-serif', 'Helvetica' ),
array( 'Impact, Haettenschweiler, "Franklin Gothic Bold", Charcoal, "Helvetica Inserat", "Bitstream Vera Sans Bold", "Arial Black", sans serif', 'Impact' ),
array( '"Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Geneva, Verdana, sans-serif', 'Lucida Grande' ),
array( 'Optima, Segoe, "Segoe UI", Candara, Calibri, Arial, sans-serif', 'Optima' ),
array( '"Segoe UI", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serif', 'Segoe UI' ),
array( 'Tahoma, Verdana, Segoe, sans-serif', 'Tahoma' ),
array( '"Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Tahoma, sans-serif', 'Trebuchet MS' ),
array( 'Verdana, Geneva, sans-serif', 'Verdana' ),
)),
array( 'group', __('Serif:', 'factory_forms_328'), array(
array( 'Baskerville, "Baskerville Old Face", "Hoefler Text", Garamond, "Times New Roman", serif', 'Baskerville' ),
array( '"Big Caslon", "Book Antiqua", "Palatino Linotype", Georgia, serif', 'Big Caslon' ),
array( '"Bodoni MT", Didot, "Didot LT STD", "Hoefler Text", Garamond, "Times New Roman", serif', 'Bodoni MT' ),
array( '"Book Antiqua", Palatino, "Palatino Linotype", "Palatino LT STD", Georgia, serif', 'Book Antiqua' ),
array( '"Calisto MT", "Bookman Old Style", Bookman, "Goudy Old Style", Garamond, "Hoefler Text", "Bitstream Charter", Georgia, serif', 'Calisto MT' ),
array( 'Cambria, Georgia, serif', 'Cambria' ),
array( 'Didot, "Didot LT STD", "Hoefler Text", Garamond, "Times New Roman", serif', 'Didot' ),
array( 'Garamond, Baskerville, "Baskerville Old Face", "Hoefler Text", "Times New Roman", serif', 'Garamond' ),
array( 'Georgia, Times, "Times New Roman", serif', 'Georgia' ),
array( '"Goudy Old Style", Garamond, "Big Caslon", "Times New Roman", serif', 'Goudy Old Style' ),
array( '"Hoefler Text", "Baskerville old face", Garamond, "Times New Roman", serif', 'Hoefler Text' ),
array( '"Lucida Bright", Georgia, serif', 'Lucida Bright' ),
array( 'Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif', 'Palatino' ),
array( 'Perpetua, Baskerville, "Big Caslon", "Palatino Linotype", Palatino, "URW Palladio L", "Nimbus Roman No9 L", serif', 'Perpetua' ),
array( 'Rockwell, "Courier Bold", Courier, Georgia, Times, "Times New Roman", serif', 'Rockwell' ),
array( '"Rockwell Extra Bold", "Rockwell Bold", monospace', 'Rockwell Extra Bold' ),
array( 'TimesNewRoman, "Times New Roman", Times, Baskerville, Georgia, serif', 'Times New Roman' )
)),
array( 'group', __('Monospaced:', 'factory_forms_328'), array(
array( '"Andale Mono", AndaleMono, monospace', 'Andale Mono' ),
array( 'Consolas, monaco, monospace', 'Consolas' ),
array( '"Courier New", Courier, "Lucida Sans Typewriter", "Lucida Typewriter", monospace', 'Courier New' ),
array( '"Lucida Console", "Lucida Sans Typewriter", Monaco, "Bitstream Vera Sans Mono", monospace', 'Lucida Console' ),
array( '"Lucida Sans Typewriter", "Lucida Console", Monaco, "Bitstream Vera Sans Mono", monospace', 'Lucida Sans Typewriter' ),
array( 'Monaco, Consolas, "Lucida Console", monospace', 'Monaco' )
))
);
return $fonts;
}
/**
* Removes \" in the font family value.
*
* @since 3.1.0
* @return mixed[]
*/
public function getValuesToSave() {
$values = parent::getValuesToSave();
$familyKey = $this->options['name'] . '__family';
$values[$familyKey] = stripcslashes( $values[$familyKey] );
return $values;
}
public function beforeControlsHtml() {}
public function afterControlsHtml() {}
/**
* Shows the html markup of the control.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
?>
<div <?php $this->attrs() ?>>
<div class="factory-control-row">
<?php $this->beforeControlsHtml() ?>
<div class="factory-family-wrap">
<?php $this->family->html() ?>
</div>
<div class="factory-size-wrap">
<?php $this->size->html() ?>
</div>
<div class="factory-color-wrap">
<?php $this->color->html() ?>
</div>
<?php $this->afterControlsHtml() ?>
</div>
<div class="factory-picker-target"></div>
</div>
<?php
}
}

View File

@@ -0,0 +1,123 @@
<?php
/**
* Dropdown List Control
*
* Main options:
* name => a name of the control
* value => a value to show in the control
* default => a default value of the control if the "value" option is not specified
* items => a callback to return items or an array of items to select
*
* @author Alex Kovalev <alex@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package core
* @since 1.0.0
*/
class FactoryForms328_GoogleFontControl extends FactoryForms328_FontControl
{
public $type = 'google-font';
const APIKEY = 'AIzaSyBlib1mA-QePPSrNkBYwcyTVw3IKZBDHOE';
public function __construct($options, $form, $provider = null) {
parent::__construct($options, $form, $provider);
$this->addCssClass('factory-font');
$optionGoogleFontData = array(
'name' => $this->options['name'] . '__google_font_data',
'cssClass' => 'factory-google-font-data'
);
$this->googleFontData = new FactoryForms328_HiddenControl( $optionGoogleFontData, $form, $provider );
$this->innerControls[] = $this->googleFontData;
}
public function getDefaultFonts() {
$googleFonts = $this->getGoogleFonts();
$fonts = array(
array( 'inherit', __( '(use default website font)', 'factory_forms_328' ) )
);
$fontsCommon = array( 'group', __('Standard:', 'factory_forms_328'), array(
array( 'Arial, "Helvetica Neue", Helvetica, sans-serif', 'Arial' ),
array( '"Helvetica Neue", Helvetica, Arial, sans-serif', 'Helvetica' ),
array( 'Tahoma, Verdana, Segoe, sans-serif', 'Tahoma' ),
array( 'Verdana, Geneva, sans-serif', 'Verdana' ),
));
$fontsGoogleFonts = array( 'group', __('Google Fonts:', 'factory_forms_328'), array() );
foreach( $googleFonts->items as $item ) {
$altFont = $item->category;
if ( in_array( $altFont, array( 'handwriting', 'display' ) ) ) $altFont = 'serif';
$listItem = array(
'title' => $item->family,
'value' => $item->family . ', ' . $item->category,
'hint' => '<em>Google Font</em>',
'data' => array(
'google-font' => true,
'family' => $item->family,
'variants' => $item->variants,
'subsets' => $item->subsets
)
);
$fontsGoogleFonts[2][] = $listItem;
}
$fonts[] = $fontsCommon;
$fonts[] = $fontsGoogleFonts;
set_transient('factory_google_fonts', $fonts, 60 * 60 * 6);
return $fonts;
}
protected function getGoogleFonts() {
$body = get_transient('factory_google_fonts_raw');
if ( !empty( $body ) ) return $body;
$response = wp_remote_get( sprintf( 'https://www.googleapis.com/webfonts/v1/webfonts?key=%s', self::APIKEY ) );
$this->error = false;
$this->defailedError = false;
if ( is_wp_error( $response ) ) {
$this->error = __('Unable to retrieve the list of Google Fonts.', 'factory_forms_328');
$this->defailedError = $response->get_error_message();
return $body;
}
if ( !isset( $response['body'] ) ) {
$this->error = __('Invalide response from the Google Fonts API.', 'factory_forms_328');
$this->defailedError = $response['body'];
return $body;
}
$body = json_decode( $response['body']);
if ( empty( $body->items ) ) {
$this->error = __('Unexpected error. The list of Google Fonts are empty.', 'factory_forms_328');
return $body;
}
set_transient('factory_google_fonts_raw', $body, 60 * 60 * 6);
return $body;
}
public function afterControlsHtml() {
?>
<?php $this->googleFontData->html() ?>
<?php
}
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* Gradient picker Control
*
* Main options:
* name => a name of the control
* title => Заголовок
* colors => массив цветов для градиента
* Пример: array("#000 0% 0.5", "#e70303 100% 1")
* filldirection => Направление градиента(top, left)
* Пример: 90deg
* value => a value to show in the control
* default => a default value of the control if the "value" option is not specified
*
* @author Alex Kovalev <alex.kovalevv@gmail.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package core
* @since 1.0.0
*/
class FactoryForms328_GradientControl extends FactoryForms328_Control
{
public $type = 'gradient';
/**
* Shows the html markup of the control.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
$name = $this->getNameOnForm();
$value = $this->getValue();
if ( !empty( $value )) {
$values = json_decode( stripcslashes( $value ) );
$points = '';
foreach( $values->color_points as $splitVlaues ) {
$points .= $splitVlaues .',';
}
$points = rtrim($points, ',');
$this->addHtmlData('points', $points );
$this->addHtmlData('directions', $values->filldirection );
} else {
$this->addHtmlData('directions', 'top' );
}
?>
<script>
if ( !window.factory ) window.factory = {};
if ( !window.factory.res ) window.factory.res = {};
factory.res.resVertical = '<?php _e( 'vertical', 'factory_forms_328' ) ?>';
factory.res.resHorizontal = '<?php _e( 'horizontal', 'factory_forms_328' ) ?>';
</script>
<div <?php $this->attrs() ?>>
<div class="factory-gradient-picker">
<ul class="gradientPicker-pallets">
<li class="factory-preset-gradient factory-primary-gradient" data-primary="#1bbc9d" data-secondary="#16a086"></li>
<li class="factory-preset-gradient factory-primary-gradient" data-primary="#2fcc71" data-secondary="#27ae61"></li>
<li class="factory-preset-gradient factory-primary-gradient" data-primary="#3598dc" data-secondary="#2a80b9"></li>
<li class="factory-preset-gradient factory-primary-gradient" data-primary="#9c59b8" data-secondary="#8f44ad"></li>
<li class="factory-preset-gradient factory-primary-gradient" data-primary="#34495e" data-secondary="#2d3e50"></li>
<li class="factory-preset-gradient factory-primary-gradient" data-primary="#f1c40f" data-secondary="#f49c14"></li>
<li class="factory-preset-gradient factory-primary-gradient" data-primary="#e84c3d" data-secondary="#c1392b"></li>
<li class="factory-preset-gradient factory-primary-gradient" data-primary="#ecf0f1" data-secondary="#bec3c7"></li>
</ul>
<canvas class='gradientPicker-preview'></canvas>
<div class='factory-points'></div>
<div class='factory-color-picker-container'>
<div class="factory-slider-container">
<div class="factory-slider">
<input type="text" class="factory-input-text factory-color-hex" />
<div class="factory-bar"></div>
<div class="factory-visible-value">100%</div>
</div>
</div>
<div class="factory-color-picker"></div>
</div>
</div>
<input type="hidden" id="<?php echo $name; ?>" class="factory-result" name="<?php echo $name; ?>" value="<?php echo $this->getValue(); ?>">
</div>
<?php
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* Hidden Input Control
*
* Main options:
* name => a name of the control
* value => a value to show in the control
* default => a default value of the control if the "value" option is not specified
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
class FactoryForms328_HiddenControl extends FactoryForms328_Control
{
public $type = 'hidden';
/**
* Shows the html markup of the control.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
$value = htmlspecialchars ( $this->getValue() );
$nameOnForm = $this->getNameOnForm();
$this->addHtmlAttr('id', $nameOnForm);
$this->addHtmlAttr('name', $nameOnForm);
$this->addHtmlAttr('value', $value);
$this->addHtmlAttr('type', 'hidden');
?>
<input <?php $this->attrs() ?>/>
<?php
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* The file contains the class of Tab Control Holder.
*
* @author Alex Kovalev <alex@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package core
* @since 1.0.0
*/
/**
* Tab Control Holder
*
* @since 1.0.0
*/
class FactoryForms328_AccordionItemHolder extends FactoryForms328_Holder {
/**
* A holder type.
*
* @since 1.0.0
* @var string
*/
public $type = 'accordion-item';
/**
* Here we should render a beginning html of the tab.
*
* @since 1.0.0
* @return void
*/
public function beforeRendering() {
?>
<h3><?php echo $this->options['title']; ?></h3>
<div class="factory-accordion-item">
<div class="inner-factory-accordion-item">
<?php
}
/**
* Here we should render an end html of the tab.
*
* @since 1.0.0
* @return void
*/
public function afterRendering() {
?>
</div>
</div>
<?php
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* The file contains the class of Tab Control Holder.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package core
* @since 1.0.0
*/
/**
* Tab Control Holder
*
* @since 1.0.0
*/
class FactoryForms328_AccordionHolder extends FactoryForms328_Holder {
/**
* A holder type.
*
* @since 1.0.0
* @var string
*/
public $type = 'accordion';
/**
* Here we should render a beginning html of the tab.
*
* @since 1.0.0
* @return void
*/
public function beforeRendering() {
?>
<div <?php $this->attrs() ?>>
<?php
}
/**
* Here we should render an end html of the tab.
*
* @since 1.0.0
* @return void
*/
public function afterRendering() {
?>
</div>
<?php
}
}

View File

@@ -0,0 +1,85 @@
<?php
/**
* The file contains the class of Columns Holder.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2014, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* Columns Holder
*
* @since 1.0.0
*/
class FactoryForms328_ColumnsHolder extends FactoryForms328_Holder {
/**
* A holder type.
*
* @since 1.0.0
* @var string
*/
public $type = 'columns';
public function __construct($options, $form) {
$columnsItems = array();
$items = isset( $options['items'] ) ? $options['items'] : array();
// calculates the number of columns
$this->columnsCount = 0;
foreach( $options['items'] as $item ) {
$i = ( !isset( $item['column'] ) ? 1 : intval( $item['column'] ) ) - 1;
$columnsItems[$i][] = $item;
if ( $i > $this->columnsCount ) $this->columnsCount = $i + 1;
}
// calculates the number of rows
$this->rowsCount = 0;
foreach($columnsItems as $items) {
$count = count( $items );
if ( $count > $this->rowsCount ) $this->rowsCount = $count;
}
// creates elements
parent::__construct($options, $form);
// groups the created by columns
$elementIndex = 0;
$this->columns = array();
foreach($columnsItems as $columnIndex => $columnItems) {
$count = count ( $columnItems );
for ( $k = 0; $k < $count; $k++ ) {
$this->columns[$columnIndex][] = $this->elements[$elementIndex];
$elementIndex++;
}
}
}
public function render() {
$this->beforeRendering();
for( $n = 0; $n < $this->rowsCount; $n++ ) {
$this->form->layout->startRow( $n, $this->rowsCount );
for( $i = 0; $i < $this->columnsCount; $i++ ) {
$control = $this->columns[$i][$n];
$this->form->layout->startColumn( $control, $i, $this->columnsCount );
$this->columns[$i][$n]->render();
$this->form->layout->endColumn( $control, $i, $this->columnsCount );
}
$this->form->layout->endRow( $n, $this->rowsCount );
}
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* The file contains the class of Tab Control Holder.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* Tab Control Holder
*
* @since 1.0.0
*/
class FactoryForms328_ControlGroupItem extends FactoryForms328_Holder {
/**
* A holder type.
*
* @since 1.0.0
* @var string
*/
public $type = 'control-group-item';
/**
* Here we should render a beginning html of the tab.
*
* @since 1.0.0
* @return void
*/
public function beforeRendering() {
$this->addCssClass('control-group-item' );
$this->addCssClass('factory-control-group-item-' . $this->options['name'] );
if ( $this->parent->getValue() == $this->options['name'] ) {
$this->addCssClass('current');
foreach( $this->elements as $val ) {
$val->setOption('isActive', 1);
}
} else {
foreach( $this->elements as $val ) {
$val->setOption('isActive', 0);
}
}
?>
<div <?php $this->attrs() ?>>
<?php
}
/**
* Here we should render an end html of the tab.
*
* @since 1.0.0
* @return void
*/
public function afterRendering() {
?>
</div>
<?php
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* The file contains the class of Tab Control Holder.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* Tab Control Holder
*
* @since 1.0.0
*/
class FactoryForms328_ControlGroupHolder extends FactoryForms328_ControlHolder {
/**
* A holder type.
*
* @since 1.0.0
* @var string
*/
public $type = 'control-group';
/**
* Here we should render a beginning html of the tab.
*
* @since 1.0.0
* @return void
*/
public function beforeRendering() {
$name = $this->getNameOnForm();
$value = $this->getValue();
$title = $this->getOption('title', null);
?>
<div <?php $this->attrs() ?>>
<input type="hidden" name="<?php echo $name ?>" id="<?php echo $name ?>" class="factory-ui-control-group" value="<?php echo $value ?>" />
<?php if ( $title ) {?>
<strong class="factory-header"><?php echo $title; ?></strong>
<?php } ?>
<ul class="factory-control-group-nav">
<?php
foreach( $this->elements as $element ):
if ( $element->options['type'] !== 'control-group-item' ) continue;
$builder = new FactoryForms328_HtmlAttributeBuilder();
$builder->addCssClass('factory-control-group-nav-label');
$builder->addCssClass('factory-control-group-nav-label-'. $element->getOption('name') );
$builder->addHtmlData('control-id', 'factory-control-group-item-' . $element->getOption('name') );
$builder->addHtmlData('control-name', $element->getOption('name') );
if ( $value == $element->getOption('name') ) $builder->addCssClass('current');
?>
<li <?php $builder->printAttrs(); ?>><?php $element->title(); ?></li>
<?php endforeach; ?>
</ul>
<div class="factory-control-group-body">
<?php
}
/**
* Here we should render an end html of the tab.
*
* @since 1.0.0
* @return void
*/
public function afterRendering() {
?>
</div>
</div>
<?php
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* The file contains the class of Div Control Holder.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* Div Control Holder
*
* @since 1.0.0
*/
class FactoryForms328_DivHolder extends FactoryForms328_Holder {
/**
* A holder type.
*
* @since 1.0.0
* @var string
*/
public $type = 'div';
/**
* Here we should render a beginning html of the tab.
*
* @since 1.0.0
* @return void
*/
public function beforeRendering() {
if ( isset( $this->options['class'] )) $this->addCssClass ( $this->options['class'] );
if ( isset( $this->options['id'] )) $this->addHtmlAttr ( 'id', $this->options['id'] );
?>
<div <?php $this->attrs() ?>>
<?php
}
/**
* Here we should render an end html of the tab.
*
* @since 1.0.0
* @return void
*/
public function afterRendering() {
?>
</div>
<?php
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* The file contains the class of Group Holder.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* Group Holder
*
* @since 1.0.0
*/
class FactoryForms328_FormGroupHolder extends FactoryForms328_Holder {
/**
* A holder type.
*
* @since 1.0.0
* @var string
*/
public $type = 'form-group';
/**
* Here we should render a beginning html of the tab.
*
* @since 1.0.0
* @return void
*/
public function beforeRendering() {
$this->addCssClass('factory-form-group-'. $this->getName() );
$this->addHtmlAttr('id', 'factory-form-group-' . $this->getName() );
?>
<fieldset <?php $this->attrs()?>>
<?php if ( $this->hasTitle() ) { ?>
<legend class='factory-legend'>
<p class='factory-title'><?php $this->title() ?></p>
<?php if ( $this->hasHint() ) { ?>
<p class='factory-hint'><?php echo $this->hint() ?></p>
<?php } ?>
</legend>
<?php } ?>
<?php
}
/**
* Here we should render an end html of the tab.
*
* @since 1.0.0
* @return void
*/
public function afterRendering() {
?>
</fieldset>
<?php
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* The file contains the class of More Link Holder.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* Collapsed Group Holder
*
* @since 1.0.0
*/
class FactoryForms328_MoreLinkHolder extends FactoryForms328_Holder {
/**
* A holder type.
*
* @since 1.0.0
* @var string
*/
public $type = 'more-link';
/**
* Here we should render a beginning html of the tab.
*
* @since 1.0.0
* @return void
*/
public function beforeRendering() {
$count = isset( $this->options['count'] ) ? $this->options['count'] : 0;
$id = 'factory-more-link-' . $this->getName();
?>
<div <?php $this->attrs() ?>>
<div class="form-group">
<div class="control-label col-sm-2"></div>
<div class="control-group col-sm-10">
<a href="#<?php echo $id ?>" class="factory-more-link-show"><?php $this->title() ?> (<?php echo $count ?>)</a>
</div>
</div>
<div class='factory-more-link-content' id="<?php echo $id ?>" style="display: none;">
<a href="#<?php echo $id ?>" class='factory-more-link-hide'><?php _e('hide extra options', 'factory'); ?></a>
<?php
}
/**
* Here we should render an end html of the tab.
*
* @since 1.0.0
* @return void
*/
public function afterRendering() {
?>
</div></div>
<?php
}
}

View File

@@ -0,0 +1,57 @@
<?php
/**
* The file contains the class of Tab Item Control Holder.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* Tab Item Control Holder
*
* @since 1.0.0
*/
class FactoryForms328_TabItemHolder extends FactoryForms328_Holder {
/**
* A holder type.
*
* @since 1.0.0
* @var string
*/
public $type = 'tab-item';
/**
* Here we should render a beginning html of the tab.
*
* @since 1.0.0
* @return void
*/
public function beforeRendering() {
$this->addCssClass('tab-'. $this->getName() );
$this->addHtmlAttr('id', $this->getName() );
$this->addCssClass('tab-pane');
if ( isset( $this->options['isFirst'] ) && $this->options['isFirst'] ) $this->addCssClass('active');
?>
<div <?php $this->attrs()?>>
<?php
}
/**
* Here we should render an end html of the tab.
*
* @since 1.0.0
* @return void
*/
public function afterRendering() {
?>
</div>
<?php
}
}

View File

@@ -0,0 +1,112 @@
<?php
/**
* The file contains the class of Tab Control Holder.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* Tab Control Holder
*
* @since 1.0.0
*/
class FactoryForms328_TabHolder extends FactoryForms328_Holder {
/**
* A holder type.
*
* @since 1.0.0
* @var string
*/
public $type = 'tab';
/**
* An align of a tab (horizontal or vertical).
*
* @since 1.0.0
* @var string
*/
public $align = 'horizontal';
/**
* Creates a new instance of control holder.
*
* @since 1.0.0
* @param mixed[] $options A holder options.
* @param FactoryForms328_Form $form A parent form.
*/
public function __construct($options, $form) {
parent::__construct($options, $form);
$this->align = isset( $options['align'] ) ? $options['align'] : 'horizontal';
}
/**
* Here we should render a beginning html of the tab.
*
* @since 1.0.0
* @return void
*/
public function beforeRendering() {
$isFirstTab = true;
$tabClass = $this->getOption('class');
if(!empty($tabClass))
$this->addCssClass($tabClass);
$this->addCssClass('factory-align-' . $this->align);
?>
<div <?php $this->attrs() ?>>
<div class="factory-headers">
<ul class="nav nav-tabs">
<?php foreach( $this->elements as $element ) {
if ( $element->options['type'] !== 'tab-item' ) continue;
$hasIcon = isset( $element->options['icon'] );
if ( $hasIcon ) $tabIcon = $element->options['icon'];
$builder = new FactoryForms328_HtmlAttributeBuilder();
$builder->addCssClass('factory-tab-item-header');
$builder->addCssClass('factory-tab-item-header-'. $element->getName() );
if ( $hasIcon ) $builder->addCssClass('factory-tab-item-header-with-icon');
if ( $isFirstTab ) $builder->addCssClass('active');
$builder->addHtmlData('tab-id', $element->getName() );
$isFirstTab = false;
if ($hasIcon) { ?>
<style>
.factory-form-tab-item-header-<?php $element->name() ?> a {
background-image: url("<?php echo $tabIcon ?>");
}
</style>
<?php } ?>
<li <?php $builder->printAttrs() ?>>
<a href="#<?php $element->name() ?>" data-toggle="tab">
<?php $element->title() ?>
</a>
</li>
<?php } ?>
</ul>
</div>
<div class='tab-content factory-bodies'>
<?php
}
/**
* Here we should render an end html of the tab.
*
* @since 1.0.0
* @return void
*/
public function afterRendering() {
?>
</div>
</div>
<?php
}
}

View File

@@ -0,0 +1,136 @@
<?php
/**
* Integer Control
* Main options:
* name => a name of the control
* way => Тип значения 'slider' - слайдер, 'checkbox-slider' - чекбокс активирует слайдер, по умолчанию input
* checkbox => Указывается если, 'way' имеет значение 'checkbox-slider'
* Пример:
* array(
* 'on' => __('Show shadow', 'bizpanda'),
* 'off' => __('Hide shadow', 'bizpanda'),
* )
* title => Заголовок контрола
* slider-title => Заголовок слайдера( Только если 'way' имеет значение 'checkbox-slider' )
* range => Диапазон значений, указывается если 'way' имеет значение 'slider' или 'checkbox-slider'
* Пример: array(0,100)
* units => Единицы измерения(px,pt,em,%)
* isActive => Включение, отключение поля
* value => a value to show in the control
* default => a default value of the control if the "value" option is not specified
*
* @author Alex Kovalev <alex.kovalevv@gmail.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
class FactoryForms328_IntegerControl extends FactoryForms328_Control
{
public $type = 'integer';
/**
* Converting string to integer.
*
* @since 1.0.0
* @return integer
*/
public function html() {
$name = $this->getNameOnForm();
$value = $this->getValue();
$isActive = $this->getOption( 'isActive', 1 );
$unit = $this->getOption('units');
$way = $this->getOption('way');
if ( empty( $way ) ) $way = 'text';
$hasSlider = false;
if ( in_array( $way, array( 'slider', 'checkbox-slider' ) ) ) {
$range = $this->getOption('range', array(0, 99));
$slider_title = $this->getOption('slider-title');
$checkbox = $this->getOption('checkbox');
$step = $this->getOption('step', 1);
$hasSlider = true;
}
$this->addCssClass('factory-way-' . $way);
if ( $hasSlider ) $this->addCssClass('factory-has-slider');
?>
<div <?php $this->attrs() ?>>
<?php if ( $hasSlider ) { ?>
<?php if( 'checkbox-slider' == $way ) { ?>
<div>
<label for="<?php echo $name; ?>_checker"><?php echo $isActive ? $checkbox['off'] : $checkbox['on']; ?></label><br>
<input type="checkbox" id="<?php echo $name; ?>_checker" class="factory-checkbox" name="<?php echo $name; ?>_checker" <?php echo $isActive ? 'checked' : '' ?>></p>
</div>
<?php } ?>
<div
data-units="<?php echo $unit ?>"
data-range-start="<?php echo $range[0] ?>"
data-range-end="<?php echo $range[1] ?>"
data-step="<?php echo $step ?>"
<?php echo !$isActive ? ' style="display:none;"' : '' ?>
class="factory-slider-container factory-slider-container-<?php echo $name; ?>">
<?php if( !empty($slider_title) ): ?>
<label class="factory-title">
<?php echo $this->getOption('slider-title'); ?>
</label>
<?php endif; ?>
<div class="factory-slider">
<div class="factory-bar"></div>
<span class="factory-visible-value">
<?php echo $value ?><?php echo $unit ?>
</span>
</div>
<input type="hidden" name="<?php echo $name; ?>" class="factory-result" value="<?php echo $value; ?>" />
</div>
<?php } else { ?>
<input type="text" id="<?php echo $name; ?>" name="<?php echo $name; ?>" value="<?php echo $value; ?>" class="factory-input-text" />
<span class="factory-units"><?php echo $unit ?></span>
<?php } ?>
</div><!-- .factory-integer -->
<?php
}
/**
* Форматирует значение без единиц измерения
* @param string $values
* @param string $unit
* @return string
*/
public function valueFormatWithoutUnit($values, $unit) {
if(!is_numeric($values))
return str_replace($unit, '', $values);
else
return $values;
}
/**
* Форматирует значение c единицами измерения
* @param string $values
* @param string $unit
* @return string
*/
public function valueFormatWithUnit($values, $unit) {
if(is_numeric($values))
return $values.$unit;
else
return $values;
}
}

View File

@@ -0,0 +1,211 @@
<?php
/**
* Multiselect List Control
*
* Main options:
* name => a name of the control
* value => a value to show in the control
* default => a default value of the control if the "value" option is not specified
* items => a callback to return items or an array of items to select
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
class FactoryForms328_ListControl extends FactoryForms328_Control
{
public $type = 'list';
/**
* Returns a set of available items for the list.
*
* @since 1.0.0
* @return mixed[]
*/
private function getItems() {
$data = $this->getOption('data', array());
// if the data options is a valid callback for an object method
if (
is_array($data) &&
count($data) == 2 &&
gettype($data[0]) == 'object' ) {
return call_user_func($data);
// if the data options is a valid callback for a function
} elseif ( gettype($data) == 'string' ) {
return $data();
}
// if the data options is an array of values
return $data;
}
/**
* Returns true, if the data should be loaded via ajax.
*
* @since 1.0.0
* @return bool
*/
protected function isAjax() {
$data = $this->getOption('data', array());
return is_array($data) && isset($data['ajax']);
}
/**
* Shows the html markup of the control.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
$way = $this->getOption('way', 'default');
$this->addHtmlData('way', $way);
if ( $this->isAjax() ) {
$data = $this->getOption('data', array());
$ajaxId = 'factory-list-' . rand(1000000, 9999999);
$value = $this->getValue( null, true );
if ( empty( $value ) || empty( $value[0] )) $value = array();
?>
<div class="factory-ajax-loader <?php echo $ajaxId . '-loader'; ?>"></div>
<script>
window['<?php echo $ajaxId ?>'] = {
'loader': '.<?php echo $ajaxId . '-loader' ?>',
'url': '<?php echo $data['url'] ?>',
'data': <?php echo json_encode( $data['data'] ) ?>,
'selected': <?php echo json_encode( $value ) ?>,
'emptyList': '<?php echo $this->getOption('empty', __('The list is empty.', 'factory_forms_328') ) ?>'
};
</script>
<?php
$this->addHtmlData('ajax', true);
$this->addHtmlData('ajax-data-id', $ajaxId);
$this->addCssClass('factory-hidden');
}
if ( 'checklist' == $way ) {
$this->checklistHtml();
} else {
$this->defaultHtml();
}
}
/**
* Shows the Buttons Dropdown.
*
* @since 1.0.0
* @return void
*/
protected function checklistHtml() {
$items = $this->getItems();
$value = explode( ',', $this->getValue() );
if ( empty( $value ) || empty( $value[0] )) $value = array();
$nameOnForm = $this->getNameOnForm();
$this->addCssClass('factory-checklist-way');
$this->addHtmlData('name', $nameOnForm);
$errorsCallback = $this->getOption('errors');
$errors = !empty( $errorsCallback ) ? call_user_func( $errorsCallback ) : array();
$isEmpty = $this->isAjax() || empty( $items );
$emptyList = $this->getOption('empty', __('The list is empty.', 'factory_forms_328') );
if ( $isEmpty ) {
$this->addCssClass('factory-empty');
}
?>
<ul <?php $this->attrs() ?>>
<?php if ( $isEmpty ) { ?>
<li><?php echo $emptyList ?></li>
<?php } else { ?>
<?php foreach($items as $item) { ?>
<li>
<label for="factory-checklist-<?php echo $nameOnForm ?>-<?php echo $item[0] ?>" class="<?php if ( !empty( $errors[$item[0] ] ) ) { echo 'factory-has-error'; } ?>">
<?php if ( !empty( $errors[$item[0] ] ) ) { ?>
<span class="factory-error">
<i class="fa fa-exclamation-triangle"></i>
<div class='factory-error-text'><?php echo $errors[$item[0]] ?></div>
</span>
<?php } else { ?>
<span>
<input
type="checkbox"
name="<?php echo $nameOnForm ?>[]"
value="<?php echo $item[0] ?>"
id="factory-checklist-<?php echo $nameOnForm ?>-<?php echo $item[0] ?>"
<?php if ( in_array( $item[0], $value) ) { echo 'checked="checked"'; } ?> />
</span>
<?php } ?>
<span><?php echo $item[1] ?></span>
</label>
</li>
<?php } ?>
<?php } ?>
</ul>
<?php
}
/**
* Shows the standart dropdown.
*
* @since 1.3.1
* @return void
*/
protected function defaultHtml() {
$items = $this->getItems();
$value = $this->getValue();
$nameOnForm = $this->getNameOnForm();
$this->addHtmlAttr('id', $nameOnForm);
$this->addHtmlAttr('name', $nameOnForm);
$this->addCssClass('form-control');
?>
<select multiple="multiple" <?php $this->attrs() ?>/>
<?php foreach($items as $item) {
if ( count($item) == 3 ) {
?>
<optgroup label="<?php echo $item[1] ?>" >
<?php foreach($item[2] as $subitem) { ?>
<?php $selected = ( $subitem[0] == $value ) ? 'selected="selected"' : ''; ?>
<option value='<?php echo $subitem[0] ?>' <?php echo $selected ?>>
<?php echo $subitem[1] ?>
</option>
<?php } ?>
</optgroup>
<?php
} else {
$selected = ( $item[0] == $value ) ? 'selected="selected"' : '';
?>
<option value='<?php echo $item[0] ?>' <?php echo $selected ?>>
<?php echo $item[1] ?>
</option>
<?php } ?>
<?php } ?>
</select>
<?php
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* Paddings Control
*/
class FactoryForms328_PaddingsEditorControl extends FactoryForms328_Control
{
public $type = 'paddings-editor';
/**
* Converting string to integer.
*
* @since 1.0.0
* @return integer
*/
public function html() {
$name = $this->getNameOnForm();
$rawValue = $this->getValue();
$units = $this->getOption('units');
$valuesWithUnits = explode(' ', $rawValue);
$values = array();
foreach($valuesWithUnits as $valueWithUnit) {
$values[] = intval($valueWithUnit);
}
$unit = $this->getOption('units', 'px');
$range = $this->getOption('range', array(0, 99));
$step = $this->getOption('step', 1);
?>
<div <?php $this->attrs() ?>
data-units="<?php echo $unit ?>"
data-range-start="<?php echo $range[0] ?>"
data-range-end="<?php echo $range[1] ?>"
data-step="<?php echo $step ?>">
<div class="factory-rectangle">
<div class="factory-side factory-side-top" data-value="<?php echo $values[0] ?>"><span class="factory-visible-value"><?php echo $values[0] ?><?php echo $units ?></span></div>
<div class="factory-side factory-side-bottom" data-value="<?php echo $values[1] ?>"><span class="factory-visible-value"><?php echo $values[1] ?><?php echo $units ?></span></div>
<div class="factory-side factory-side-left" data-value="<?php echo $values[2] ?>"><span class="factory-visible-value"><?php echo $values[2] ?><?php echo $units ?></span></div>
<div class="factory-side factory-side-right" data-value="<?php echo $values[3] ?>"><span class="factory-visible-value"><?php echo $values[3] ?><?php echo $units ?></span></div>
<div class="factory-side factory-side-center" data-value="<?php echo $values[0] ?>"></div>
</div>
<div class="factory-slider-container">
<label class="factory-title">
<?php _e('Select a side and move the slider to set up:','factory_forms_328') ?>
</label>
<div class="factory-slider">
<div class="factory-bar"></div>
</div>
</div>
<input type="hidden" class="factory-result" name="<?php echo $name ?>" value="<?php echo $rawValue ?>" />
</div>
<?php
}
}

View File

@@ -0,0 +1,147 @@
<?php
/**
* Pattern Control
*
* @author Alex Kovalev <alex@byonepress.com>
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013-2014, OnePress Ltd
*
* @package factory-forms
* @since 3.1.0
*/
class FactoryForms328_PatternControl extends FactoryForms328_Control
{
public $type = 'pattern';
public function getName() {
return array (
$this->getOption('name') . '__url',
$this->getOption('name') . '__color'
);
}
public function __construct( $options, $form, $provider = null ) {
parent::__construct( $options, $form, $provider );
if ( !isset( $options['color']) ) $options['color'] = array();
$options['color'] = array_merge($options['color'], array(
'name' => $this->options['name'] . '_color_picker',
'default' => isset( $this->options['default'] ) ? $this->options['default']['color'] : null,
'pickerTarget' => '.factory-control-' . $this->options['name'] . ' .factory-picker-target'
));
if ( !$options['color']['default'] ) $options['color']['default'] = '#1e8cbe';
$name = $this->getOption('name');
// filters to get available patterns for the given background contols
$this->patterns = apply_filters('factory_forms_328_patterns', array());
$this->patterns = apply_filters('factory_forms_328_patterns-' . $name, $this->patterns);
$this->customPatterns = $this->getOption('patterns', array());
$this->color = new FactoryForms328_ColorControl( $options['color'], $form, $provider );
}
/**
* Shows the html markup of the control.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
$name = $this->getNameOnForm();
$values = $this->getValue();
// if a pattern is not set by defaut, sets the first available pattern
if ( empty( $values['url'] ) && !empty( $this->patterns ) ) {
foreach( $this->patterns as $groupKey => $groupValue ) {
if ( !empty( $this->patterns[$groupKey]['patterns'] ) ) {
$values['url'] = $this->patterns[$groupKey]['patterns'][0]['pattern'];
break;
}
}
}
if ( !empty( $values['color'] )) {
$this->color->setOption( 'value', $values['color'] );
}
$hasColor = !empty( $values['color'] );
if ( $hasColor ) $this->addCssClass('factory-color-panel-active');
?>
<div <?php $this->attrs() ?>>
<div class="factory-pattern-controls">
<div class="factory-preview-wrap">
<div <?php echo (!empty( $values['url'] )) ? 'style="background:url('.$values['url'].') repeat; border:0; font-size:0;"' : ''; ?> class="factory-preview <?php echo $name; ?>"><span></span></div>
</div>
<a href="#" class="button button-default factory-button factory-change-color-btn <?php if ( $hasColor ) { echo 'button-active'; }?>" title="<?php _e('Change color', 'factory_forms_328') ?>">
<i class="fa fa-flask"></i>
<span><?php _e( 're-color', 'factory_forms_328') ?></span>
</a>
<input type="hidden" id="<?php echo $name[0]; ?>" name="<?php echo $name[0]; ?>" value="<?php echo $values['url']; ?>" class="factory-pattern-result">
<input type="hidden" id="<?php echo $name[1]; ?>" name="<?php echo $name[1]; ?>" value="<?php echo $values['color']; ?>" class="factory-color-result">
</div>
<div class="factory-color-panel">
<div class="factory-color-wrap">
<span class="factory-color-label"><?php _e('Select color:', 'factory_forms_328') ?></span>
<?php $this->color->html() ?>
<div class="factory-hint"><i><?php _e('Changing the color may takes a minute or more. Please be patient.', 'factory_forms_328') ?></i></div>
</div>
<div class="factory-picker-target"></div>
</div>
<div class="factory-patterns-panel">
<div class="factory-patterns-group factory-patterns-group-custom">
<?php $this->printPatterns( $this->customPatterns, 4, '<div class="factory-patterns-item factory-upload-btn factory-no-preview"><span class="fa fa-upload"></span></div>' ) ?>
</div>
<?php foreach( $this->patterns as $key => $group ): ?>
<?php if( !empty( $group['patterns'] ) ): ?>
<div class="factory-patterns-group factory-patterns-group-<?php echo $key ?>">
<div class="factory-patterns-group-title"><?php echo $group['title'] ?></div>
<?php $this->printPatterns( $group['patterns'], 4 ) ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<div class="clearfix"></div>
</div>
<?php
}
private function printPatterns( $patterns, $perRow, $firstItem = null ) {
$counter = 0;
$printFirstItem = $firstItem;
?>
<div class="factory-patterns-row">
<?php
if ( $printFirstItem ) {
echo $printFirstItem;
$printFirstItem = null;
$counter++;
}
foreach( $patterns as $pattern ) {
$counter++;
?>
<div class="factory-patterns-item" data-pattern="<?php echo $pattern['pattern']; ?>">
<div class="factory-pattern-holder" style="background:url(<?php echo $pattern['preview']; ?>) repeat;"></div>
</div>
<?php
if ( $counter == 4 ) {
$counter = 0;
?>
</div><div class="factory-patterns-row">
<?php
}
}
?>
</div>
<?php
}
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* Radio Control
*
* Main options:
* name => a name of the control
* value => a value to show in the control
* default => a default value of the control if the "value" option is not specified
* items => a callback to return items or an array of items to select
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
class FactoryForms328_RadioControl extends FactoryForms328_Control
{
public $type = 'radio';
/**
* Returns a set of available items for the radio.
*
* @since 1.0.0
* @return mixed[]
*/
private function getItems() {
$data = $this->getOption('data', array());
// if the data options is a valid callback for an object method
if (
is_array($data) &&
count($data) == 2 &&
gettype($data[0]) == 'object' ) {
return call_user_func($data);
// if the data options is a valid callback for a function
} elseif ( gettype($data) == 'string' ) {
return $data();
}
// if the data options is an array of values
return $data;
}
/**
* Preparing html attributes before rendering html of the control.
*
* @since 1.0.0
* @return void
*/
protected function beforeHtml() {
$nameOnForm = $this->getNameOnForm();
$this->addHtmlAttr('name', $nameOnForm);
}
/**
* Shows the html markup of the control.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
$items = $this->getItems();
$value = $this->getValue();
?>
<?php foreach($items as $item) {
$checked = ( $item[0] == $value ) ? 'checked="checked"' : '';
?>
<span class="factory-form-radio-item">
<label class="factory-from-radio-label"><?php echo $item[1] ?></lable>
<input type="radio" <?php $this->attrs() ?> value="<?php echo $item[0] ?>" <?php echo $checked ?>/>
</span>
<?php }
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Textarea Control
*
* Main options:
* name => a name of the control
* value => a value to show in the control
* default => a default value of the control if the "value" option is not specified
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
class FactoryForms328_TextareaControl extends FactoryForms328_Control
{
public $type = 'textarea';
/**
* Preparing html attributes before rendering html of the control.
*
* @since 1.0.0
* @return void
*/
protected function beforeHtml() {
$nameOnForm = $this->getNameOnForm();
$this->addCssClass('form-control');
$this->addHtmlAttr('name', $nameOnForm);
$this->addHtmlAttr('id', $nameOnForm);
}
/**
* Shows the html markup of the control.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
$value = htmlspecialchars ( $this->getValue() );
?>
<textarea <?php $this->attrs(); ?> /><?php echo $value ?></textarea>
<?php
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* Textbox Control
*
* Main options:
* name => a name of the control
* value => a value to show in the control
* default => a default value of the control if the "value" option is not specified
* maxLength => set the max length of text in the input control
* placeholder => a placeholder text for the control when the control value is empty
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
class FactoryForms328_TextboxControl extends FactoryForms328_Control
{
public $type = 'textbox';
/**
* Preparing html attributes before rendering html of the control.
*
* @since 1.0.0
* @return void
*/
protected function beforeHtml() {
$value = htmlspecialchars ( $this->getValue() );
$nameOnForm = $this->getNameOnForm();
if ( $this->getOption('maxLength', false) ) {
$this->addHtmlAttr('maxlength', intval( $this->getOption('maxLength') ));
}
if ( $this->getOption('placeholder', false) ) {
$this->addHtmlAttr('placeholder', $this->getOption('placeholder') );
}
$this->addCssClass('form-control');
$this->addHtmlAttr('type', 'text');
$this->addHtmlAttr('id', $nameOnForm);
$this->addHtmlAttr('name', $nameOnForm);
$this->addHtmlAttr('value', $value);
}
/**
* Shows the html markup of the control.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
$units = $this->getOption('units', false );
?>
<?php if ( $units ) { ?><div class="input-group"><?php } ?>
<input <?php $this->attrs() ?>/>
<?php if ( $units ) { ?>
<span class="input-group-addon"><?php echo $units ?></span>
<?php }?>
<?php if ( $units ) { ?></div><?php } ?>
<?php
}
public function getSubmitValue( $name, $subName ) {
$nameOnForm = $this->getNameOnForm( $name );
return isset( $_POST[$nameOnForm] ) ? trim( $_POST[$nameOnForm] ) : '';
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* Url Control
*
* Main options:
* @see FactoryForms328_TextboxControl
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
class FactoryForms328_UrlControl extends FactoryForms328_TextboxControl
{
public $type = 'url';
/**
* Adding 'http://' to the url if it was missed.
*
* @since 1.0.0
* @return string
*/
public function getSubmitValue( $name, $subName ) {
$value = parent::getSubmitValue( $name, $subName );
if ( !empty( $value ) && substr($value, 0, 4) != 'http' ) $value = 'http://' . $value;
return $value;
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* WP Editor Control
*
* Main options:
* name => a name of the control
* value => a value to show in the control
* default => a default value of the control if the "value" option is not specified
* tinymce => an array of options for tinymce
* @link http://codex.wordpress.org/Function_Reference/wp_editor
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
class FactoryForms328_WpEditorControl extends FactoryForms328_Control
{
public $type = 'wp-editor';
/**
* Preparing html attributes and options for tinymce.
*
* @since 1.0.0
* @return void
*/
protected function beforeHtml() {
if ( empty( $this->options['tinymce'] ) ) $this->options['tinymce'] = array();
if ( !isset( $this->options['tinymce']['content_css'] ) )
$this->options['tinymce']['content_css'] = FACTORY_FORMS_328_URL . '/assets/css/editor.css';
}
/**
* Shows the html markup of the control.
*
* @since 1.0.0
* @return void
*/
public function html( ) {
$nameOnForm = $this->getNameOnForm();
$value = $this->getValue();
?>
<div class='factory-form-wp-editor'>
<?php wp_editor( $value, $nameOnForm, array(
'textarea_name' => $nameOnForm,
'wpautop' => false,
'teeny' => true,
'tinymce' => $this->getOption('tinymce', array())
)); ?>
</div>
<?php
}
}

View File

@@ -0,0 +1,101 @@
<?php
/**
* Html Helper is to render form elements independently.
*
* Factory Forms is a Factory module that provides a declarative
* way to build forms without any extra html or css markup.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* A class that provides a set of methods to render form elements independently.
*
* @since 1.0.0
*/
class FactoryForms328_FormHelpers {
/**
* Renders a form element.
*
* @since 1.0.0
* @param type $type A type of a form element.
* @param type $options Element options.
* @return void
*/
public static function render( $type, $options = array() ) {
$options['type'] = $type;
if ( FactoryForms328_Form::isControl($type) ) {
self::renderControl($type, $options);
} elseif ( FactoryForms328_Form::isControlHolder($type) ) {
self::renderHolder($type, $options);
} else {
print_r($options);
die('The control type was not found: ' . $type );
}
}
/**
* Renders a given control.
*
* @since 1.0.0
* @param type $type A control type.
* @param type $options Control options.
* @return void
*/
public static function renderControl($type, $options) {
FactoryForms328_Form::connectAssetsForItem( $options );
$data = self::$_registeredControls[$type];
require_once ($data['include']);
$object = new $data['class']( $options );
$object->html();
}
/**
* Renders a given control holder.
*
* @since 1.0.0
* @param type $type A holder type.
* @param type $options Holder options.
* @return void
*/
public static function renderHolder($type, $options) {
FactoryForms328_Form::connectAssetsForItem( $options );
$data = self::$_registeredHolders[$type];
require_once ($data['include']);
$object = new $data['class']( $options );
$object->html();
}
/**
* A helper method to extract control options (items) by a given name.
*
* @since 3.0.5
* @param string $controlName a control name to search
* @param mixed $options a set of contol options
* @return null|string
*/
public static function extractControlOptions( $controlName, $options = array() ) {
foreach($options as $itemOptions) {
if ( isset( $itemOptions['name'] ) && $itemOptions['name'] == $controlName ) {
return $itemOptions;
}
if ( isset( $itemOptions['items'] ) && is_array( $itemOptions['items'] ) ) {
$result = self::extractControlOptions( $controlName, $itemOptions['items'] );
if ( $result ) return $result;
}
}
return null;
}
}

View File

@@ -0,0 +1,117 @@
<?php
/**
* The file contains the base class for all complex controls.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2014, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* The base class for all controls.
*
* @since 1.0.0
*/
abstract class FactoryForms328_ComplexControl extends FactoryForms328_Control {
/**
* Is this element a complex control?
*
* @since 1.0.0
* @var bool
*/
public $isComplexControl = true;
/**
* Contains a set of internal controls.
*
* @since 1.0.0
* @var FactoryForms328_Control[]
*/
public $innerControls = array();
/**
* Sets a provider for the control.
*
* @since 1.0.0
* @param IFactoryForms328_ValueProvider $provider
* @return void
*/
public function setProvider( $provider ) {
$this->provider = $provider;
foreach( $this->innerControls as $control ) {
$control->setProvider( $provider );
}
}
/**
* Returns a control name used to save data with a provider.
*
* The method can return if the control have several elements.
*
* @since 1.0.0
* @return string[]|string|null A control name.
*/
public function getName()
{
$names = array();
foreach( $this->innerControls as $control ) {
$innerNames = $control->getName();
if ( is_array($innerNames) ) $names = array_merge($names, $innerNames );
else $names[] = $innerNames;
}
return $names;
}
/**
* Returns an array of value to save received after submission of a form.
*
* @see getSubmitValue
*
* The array has the following format:
* array(
* 'control-name1' => 'value1',
* 'control-name2__sub-name1' => 'value2'
* 'control-name2__sub-name2' => 'value3'
* )
*
* @since 3.1.0
* @return mixed[]
*/
public function getValuesToSave() {
$values = array();
foreach( $this->innerControls as $control ) {
$innerValues = $control->getValuesToSave();
if ( is_array($innerValues) ) $values = array_merge( $values, $innerValues );
else $values[] = $innerValues;
}
return $values;
}
/**
* Returns an initial value of control that is used to render the control first time.
*
* @since 1.0.0
* @return mixed;
*/
public function getValue( $index = null, $multiple = false ) {
$values = array();
foreach( $this->innerControls as $control ) {
$innerValues = array_merge($values, $control->getValue() );
if ( is_array($innerValues) ) $values = array_merge($values, $innerValues );
else $values[] = $innerValues;
}
if ( $index !== null ) { return $values[$index]; }
else { return $values; }
}
}

View File

@@ -0,0 +1,152 @@
<?php
/**
* The file contains the base class for all control holder
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* The base class for control holders.
*
* @since 1.0.0
*/
abstract class FactoryForms328_ControlHolder extends FactoryForms328_Control {
/**
* Holder Elements.
*
* @since 1.0.0
* @var FactoryForms328_FormElement[]
*/
protected $elements = array();
/**
* Is this element a control holder?
*
* @since 1.0.0
* @var bool
*/
public $isHolder = true;
/**
* Creates a new instance of control holder.
*
* @since 1.0.0
* @param mixed[] $options A holder options.
* @param FactoryForms328_Form $form A parent form.
*/
public function __construct($options, $form) {
parent::__construct($options, $form);
$this->elements = $form->createElements( $options['items'] );
foreach( $this->elements as $val ) {
$val->parent = $this;
}
}
/**
* Returns holder elements.
*
* @since 1.0.0
* @return FactoryForms328_FormElement[].
*/
public function getElements() {
return $this->elements;
}
/**
* Renders the form or a given control holder.
*
* @since 1.0.0
* @param $holder A control holder to render.
* @return void
*/
function render() {
$this->beforeRendering();
$isFirstItem = true;
foreach( $this->elements as $element ) {
$element->setOption('isFirst', $isFirstItem);
if ( $isFirstItem ) $isFirstItem = false;
do_action('factory_form_before_element_' . $element->getName() );
// if a current item is a control holder
if ( $element->isHolder ) {
$this->form->layout->beforeHolder( $element );
$element->render();
$this->form->layout->afterHolder( $element );
// if a current item is an input control
} elseif ( $element->isControl ) {
$this->form->layout->beforeControl( $element );
$element->render();
$this->form->layout->afterControl( $element );
// if a current item is a custom form element
} elseif ( $element->isCustom ) {
$element->render();
// otherwise, show the error
} else {
print_r($element);
echo( '[ERROR] Invalid item.' );
}
do_action('factory_form_after_element_' . $element->getName() );
}
$this->afterRendering();
}
/**
* Rendering a beginning of a holder.
*
* @since 1.0.0
* @return void
*/
public function beforeRendering(){}
/**
* Rendering an end of a holder.
*
* @since 1.0.0
* @return void
*/
public function afterRendering(){}
/**
* Rendering some html before an inner holder.
*
* @since 1.0.0
* @return void
*/
public function beforeInnerHolder(){}
/**
* Rendering some html after an inner holder.
*
* @since 1.0.0
* @return void
*/
public function afterInnerHolder(){}
public function beforeInnerElement(){}
/**
* Rendering some html after an inner element.
*
* @since 1.0.0
* @return void
*/
public function afterInnerElement(){}
}

View File

@@ -0,0 +1,321 @@
<?php
/**
* The file contains the base class for all controls.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* The base class for all controls.
*
* @since 1.0.0
*/
abstract class FactoryForms328_Control extends FactoryForms328_FormElement {
/**
* Is this element a control?
*
* @since 1.0.0
* @var bool
*/
public $isControl = true;
/**
* Is this element a complex control?
*
* @since 1.0.0
* @var bool
*/
public $isComplexControl = false;
/**
* A provider that is used to get values.
*
* @since 1.0.0
* @var IFactoryValueProvider
*/
protected $provider = null;
/**
* Create a new instance of the control.
*
* @since 1.0.0
* @return void
*/
public function __construct( $options, $form, $provider = null ) {
parent::__construct( $options, $form );
$this->provider = $provider;
}
/**
* Sets a provider for the control.
*
* @since 1.0.0
* @param IFactoryForms328_ValueProvider $provider
* @return void
*/
public function setProvider( $provider ) {
$this->provider = $provider;
}
/**
* Returns a control name used to save data with a provider.
*
* The method can return if the control have several elements.
*
* @since 1.0.0
* @return string[]|string|null A control name.
*/
public function getName()
{
return isset( $this->options['name'] ) ? $this->options['name'] : null;
}
/**
* Prints a control name used to save data with a provider.
*
* @since 1.0.0
* @return void
*/
protected function printName() {
$name = $this->getName();
if ( is_array( $name ) ) echo $name[0];
else echo $name;
}
/**
* Returns a control scope.
*
* @since 1.0.0
* @return string|null A control scope.
*/
public function getScope()
{
return isset( $this->options['scope'] ) ? $this->options['scope'] : null;
}
/**
* Prints a control scope.
*
* @since 1.0.0
* @return void
*/
protected function printScope() {
echo $this->getScope();
}
/**
* Returns a name of control on a form (scope + _ + name)
*
* @since 1.0.0
* @return string|null A control name on a form.
*/
public function getNameOnForm( $name = null )
{
$scope = $this->getScope();
$name = !$name ? $this->getName() : $name;
if ( is_array( $name ) ) {
$names = array();
foreach( $name as $item ) {
$names[] = empty($scope) ? $item : $scope . '_' . $item;
}
return $names;
}
if ( empty($scope) ) return $name;
if ( empty($name) ) return null;
return $scope . '_' . $name;
}
/**
* Prints a control name on a form.
*
* @since 1.0.0
* @return void
*/
public function printNameOnForm() {
$name = $this->getNameOnForm();
if ( is_array( $name ) ) echo $name[0];
else echo $name;
}
/**
* Returns a submit value of the control by a given name.
*
* @since 1.0.0
* @return mixed
*/
public function getSubmitValue( $name, $subName ) {
$nameOnForm = $this->getNameOnForm( $name );
$value = isset( $_POST[$nameOnForm] ) ? $_POST[$nameOnForm] : null;
if ( is_array( $value ) ) $value = implode (',', $value);
return $value;
}
/**
* Returns an array of value to save received after submission of a form.
*
* @see getSubmitValue
*
* The array has the following format:
* array(
* 'control-name1' => 'value1',
* 'control-name2__sub-name1' => 'value2'
* 'control-name2__sub-name2' => 'value3'
* )
*
* @since 3.1.0
* @return mixed[]
*/
public function getValuesToSave() {
$name = $this->getName();
if ( is_array( $name ) ) {
$i = 0;
foreach($name as $singleName) {
$subName = $this->getSubName( $singleName );
if ( !$subName ) { $subName = $i; $i++; }
$values[$singleName] = $this->getSubmitValue( $singleName, $subName );
}
return $values;
}
$values[$name] = $this->getSubmitValue( $name, null );
return $values;
}
/**
* Returns an initial value of control that is used to render the control first time.
*
* @since 1.0.0
* @return mixed;
*/
public function getValue( $index = null, $multiple = false ) {
if ( isset( $this->options['value'] ) ) {
if ( is_array( $this->options['value'] ) ) {
if ( $index !== null ) return $this->options['value'][$index];
else return $this->options['value'];
} else {
return $this->options['value'];
}
}
$default = null;
if ( isset( $this->options['default'] ) ) {
if ( is_array( $this->options['default'] ) ) {
if ( $index !== null ) $default = $this->options['default'][$index];
else $default = $this->options['default'];
} else {
$default = $this->options['default'];
}
}
if ( $this->provider ) {
$name = $this->getName();
if ( is_array( $name )) {
$values = array();
$i = 0;
foreach($name as $singleName) {
$subName = $this->getSubName( $singleName );
if ( !$subName ) { $subName = $i; $i++; }
$values[$subName] = $this->provider->getValue( $singleName, isset( $default[$subName] ) ? $default[$subName] : null );
}
if ( $index !== null ) return $values[$index];
return $values;
} else {
return $this->provider->getValue( $this->getName(), $default, $multiple );
}
}
return $default;
}
/**
* Shows the control.
*
* @since 1.0.0
* @return void
*/
public function render() {
$this->addCssClass('factory-from-control-' . $this->type);
$isActive = $this->provider->getValue( $this->getOption('name') . '_is_active', $this->getOption('isActive', 1) );
// if the control is off, then ignore it
$off = $this->getOption('off', false);
if ( $off ) return;
?>
<input type="hidden" class="factory-control-is-active" name="<?php echo $this->getOption('name') ?>_is_active" value="<?php echo $isActive ?>" />
<?php
$this->beforeHtml();
$this->html();
$this->afterHtml();
}
/**
* A virtual method that is executed before rendering html markup of the control.
*
* @since 1.0.0
* @return void
*/
protected function beforeHtml(){}
/**
* A virtual method that is executed after rendering html markup of the control.
*
* @since 1.0.0
* @return void
*/
protected function afterHtml(){}
/**
* Renders the html markup for the control.
*
* @since 1.0.0
* @return void
*/
public function html(){}
/**
* Returns a layout option.
*
* @since 1.0.0
* @param type $optionName A layout option to return.
* @param type $default A default value to return if the option doesn't exist.
* @return mixed
*/
public function getLayoutOption( $optionName, $default ) {
if ( !isset( $this->options['layout'] ) ) return $default;
if ( !isset( $this->options['layout'][$optionName] ) ) return $default;
return $this->options['layout'][$optionName];
}
/**
* Splits the control name by '__' and return the right part.
*
* For example, if the $controlName is 'control__color', then returns 'color'.
* Throws an error if the control name cannot be splitted.
*
* @since 3.1.0
* @param string $controlName
* @return string
*/
protected function getSubName( $controlName ) {
$parts = explode('__', $controlName, 2 );
if ( !isset( $parts[1] )) return null;
return $parts[1];
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* The file contains the base class for all custom elements.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* The base class for all controls.
*
* @since 1.0.0
*/
abstract class FactoryForms328_CustomElement extends FactoryForms328_FormElement {
/**
* Is this element a custom form element?
*
* @since 1.0.0
* @var bool
*/
public $isCustom = true;
public function render() {
// if the control is off, then ignore it
$off = $this->getOption('off', false);
if ( $off ) return;
$this->html();
}
}

View File

@@ -0,0 +1,366 @@
<?php
/**
* The file contains the base class for all form element (controls, holders).
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* The base class for all form element (controls, holders).
*
* Provides several methods to build html markup of an element.
*
* @since 1.0.0
*/
abstract class FactoryForms328_FormElement {
/**
* A type of an elemnt.
*
* @since 1.0.0
* @var boolean
*/
protected $type = null;
/**
* An html attribute builder.
*
* @since 1.0.0
* @var FactoryForms328_HtmlAttributeBuilder
*/
private $htmlBuilder;
/**
* Element options.
*
* @since 1.0.0
* @var array
*/
public $options = array();
/**
* A parent form.
*
* @since 1.0.0
* @var FactoryForms328_Form
*/
protected $form;
/**
* A form layout.
*
* @since 1.0.0
* @var FactoryForms328_FormLayout
*/
protected $layout;
/**
* Is this element a control?
*
* @since 1.0.0
* @var bool
*/
public $isControl = false;
/**
* Is this element a control holder?
*
* @since 1.0.0
* @var bool
*/
public $isHolder = false;
/**
* Is this element a custom form element?
*
* @since 1.0.0
* @var bool
*/
public $isCustom = false;
/**
* Creates a new instance of a form element.
*
* @since 1.0.0
* @param mixed[] $options A holder options.
* @param FactoryForms328_Form $form A parent form.
*/
public function __construct( $options, $form ) {
$this->options = $options;
$this->form = $form;
$this->layout = $form->layout;
$this->htmlBuilder = new FactoryForms328_HtmlAttributeBuilder();
if ( isset( $this->options['cssClass']) ) {
$this->htmlBuilder->addCssClass( $this->options['cssClass'] );
}
if ( isset( $this->options['htmlData'] ) ) {
foreach($this->options['htmlData'] as $dataKey => $dataValue) {
$this->htmlBuilder->addHtmlData($dataKey, $dataValue);
}
}
if ( isset( $this->options['htmlAttrs'] ) ) {
foreach($this->options['htmlAttrs'] as $attrKey => $attrValue) {
$this->htmlBuilder->addHtmlAttr($attrKey, $attrValue);
}
}
$this->addCssClass('factory-' . $this->type);
}
/**
* Sets options for the control.
*
* @since 1.0.0
* @param mixed[] $options
* @return void
*/
public function setOptions( $options ) {
$this->options = $options;
}
/**
* Gets options of the control.
*
* @since 1.0.0
* @return mixed[] $options
*/
public function getOptions() {
return $this->options;
}
/**
* Sets a new value for a given option.
*
* @since 1.0.0
* @param type $name An option name to set.
* @param type $value A value to set.
* @return void
*/
public function setOption( $name, $value ) {
$this->options[$name] = $value;
}
/**
* Gets an option value or default.
*
* @since 1.0.0
* @param mixed $name An option name to get.
* @param mixed $default A default value/
* @return mixed
*/
public function getOption( $name, $default = null ) {
return isset( $this->options[$name] ) ? $this->options[$name] : $default;
}
/**
* Prints an option value or default.
*
* @since 1.0.0
* @param mixed $name An option name to get.
* @param mixed $default A default value/
* @return void
*/
public function option( $name, $default = null ) {
$value = $this->getOption($name, $default);
echo $value;
}
/**
* Adds a new CSS class for the element.
*
* @since 1.0.0
* @return void
*/
public function addCssClass( $class ) {
$this->htmlBuilder->addCssClass( $class );
}
/**
* Prints CSS classes of the element.
*
* @since 1.0.0
* @return void
*/
protected function cssClass() {
$this->htmlBuilder->printCssClass();
}
/**
* Adds a new html attribute.
*
* @since 1.0.0
* @param type $attrName
* @param type $attrValue
* @return void
*/
protected function addHtmlData( $dataKey, $dataValue ) {
return $this->htmlBuilder->addHtmlData( $dataKey, $dataValue );
}
/**
* Adds a new html attribute.
*
* @since 1.0.0
* @param type $attrName
* @param type $attrValue
* @return void
*/
protected function addHtmlAttr( $attrName, $attrValue ) {
return $this->htmlBuilder->addHtmlAttr( $attrName, $attrValue );
}
/**
* Prints all html attributes, including css classes and data.
*
* @since 1.0.0
* @return void
*/
protected function attrs() {
return $this->htmlBuilder->printAttrs();
}
/**
* Returns an element title.
*
* @since 1.0.0
* @return string
*/
public function getTitle() {
if ( isset( $this->options['title'] ) ) return $this->options['title'];
return false;
}
/**
* Returns true if an element has title.
*
* @since 1.0.0
* @return bool
*/
public function hasTitle() {
$title = $this->getTitle();
return !empty( $title );
}
/**
* Prints an element title.
*
* @since 1.0.0
* @return void
*/
public function title() {
echo $this->getTitle();
}
/**
* Returns an element hint.
*
* @since 1.0.0
* @return string
*/
public function getHint() {
if ( isset( $this->options['hint'] ) ) return $this->options['hint'];
return false;
}
/**
* Returns true if an element has hint.
*
* @since 1.0.0
* @return bool
*/
public function hasHint() {
$hint = $this->getHint() ;
return !empty( $hint );
}
/**
* Prints an element hint.
*
* @since 1.0.0
* @return void
*/
public function hint() {
echo $this->getHint();
}
/**
* Returns an element name.
*
* @since 1.0.0
* @return string
*/
public function getName() {
if ( empty( $this->options['name'] ) && !empty( $this->options['title'] ) ) {
$this->options['name'] = str_replace(' ', '-', $this->options['title'] );
$this->options['name'] = strtolower( $this->options['name'] );
}
if ( !isset( $this->options['name'] ) ) {
$this->options['name'] = $this->type . '-' . rand();
}
return $this->options['name'];
}
/**
* Prints an element name.
*
* @since 1.0.0
* @return void
*/
public function name() {
echo $this->getName();
}
/**
* Returns an element type.
*
* @since 1.0.0
* @return string
*/
public function getType() {
return $this->type;
}
/**
* Returns an element icon.
*
* @since 1.0.0
* @return string
*/
public function getIcon() {
if ( isset( $this->options['icon'] ) ) return $this->options['icon'];
return false;
}
/**
* Returns true if an element has a icon.
*
* @since 1.0.0
* @return bool
*/
public function hasIcon() {
$icon = $this->getIcon() ;
return !empty( $icon );
}
/**
* Prints an element icon.
*
* @since 1.0.0
* @return void
*/
public function icon() {
echo $this->getIcon();
}
}

View File

@@ -0,0 +1,102 @@
<?php
/**
* The file contains the base class for all form layouts.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* The base class for all form layouts.
*/
abstract class FactoryForms328_FormLayout extends FactoryForms328_Holder {
/**
* A form layout name.
*
* @since 1.0.0
* @var string
*/
protected $name = 'default';
/**
* A holder type.
*
* @since 1.0.0
* @var string
*/
protected $type = 'form-layout';
/**
* Creates a new instance of a form layout.
*
* @since 1.0.0
* @param mixed[] $options A holder options.
* @param FactoryForms328_Form $form A parent form.
*/
public function __construct($options, $form) {
$options['name'] = $this->name;
$options['items'] = $form->getItems();
parent::__construct($options, $form);
$this->addCssClass('factory-forms-328-' . $this->type);
$this->addCssClass('factory-forms-328-' . $this->name);
}
/**
* Renders a beginning of a form.
*
* @since 1.0.0
* @return void
*/
public function beforeRendering() {
echo '<div '; $this->attrs(); echo '>';
}
/**
* Renders the end of a form.
*
* @since 1.0.0
* @return void
*/
public function afterRendering() {
echo '</div>';
}
/**
* Rendering some html before a holder.
*
* @since 1.0.0
* @return void
*/
public function beforeHolder( $element ) {}
/**
* Rendering some html after a holder.
*
* @since 1.0.0
* @return void
*/
public function afterHolder( $element ) {}
/**
* Rendering some html before a contol.
*
* @since 1.0.0
* @return void
*/
public function beforeControl( $element ) {}
/**
* Rendering some html after a contol.
*
* @since 1.0.0
* @return void
*/
public function afterControl( $element ) {}
}

View File

@@ -0,0 +1,631 @@
<?php
/**
* The file contains a class that represnets an abstraction for forms.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
// creating a license manager for each plugin created via the factory
add_action('factory_forms_328_plugin_created', 'factory_forms_328_plugin_created');
function factory_forms_328_plugin_created( $plugin ) {
$plugin->forms = new FactoryForms328_Manager( $plugin );
}
class FactoryForms328_Manager {
// ----------------------------------------------------
// Static fields and methods
// ----------------------------------------------------
/**
* This array contains data to use a respective control.
*
* @since 1.0.0
* @var array
*/
public static $registeredControls = array();
/**
* Registers a new control.
*
* @since 1.0.0
* @param mixed[] $item Control data having the following format:
* type => a control type
* class => a control php class
* include => a path to include control code
* @return void
*/
public function registerControl( $item ) {
self::$registeredControls[$item['type']] = $item;
require_once $item['include'];
}
/**
* Registers a set of new controls.
*
* @see FactoryForms328_Form::registerControl()
*
* @since 1.0.0
* @return void
*/
public function registerControls( $data ) {
foreach($data as $item) $this->registerControl($item);
}
/**
* This array contains holder data to use a respective control holder.
*
* @since 1.0.0
* @var array
*/
public static $registeredHolders = array();
/**
* Registers a new holder.
*
* @since 1.0.0
* @param mixed[] $item Holder data having the follwoin format:
* type => a control holder type
* class => a control holder php class
* include => a path to include control holder code
* @return void
*/
public function registerHolder( $item ) {
self::$registeredHolders[$item['type']] = $item;
require_once $item['include'];
}
/**
* Registers a set of new holder controls.
*
* @see FactoryForms328_Form::registerHolder()
*
* @since 1.0.0
* @return void
*/
public function registerHolders( $data ) {
foreach($data as $item) $this->registerHolder( $item );
}
/**
* This array contains custom form element data to use a respective elements.
*
* @since 1.0.0
* @var array
*/
public static $registeredCustomElements = array();
/**
* Registers a new custom form element.
*
* @since 1.0.0
* @return void
*/
public function registerCustomElement( $item ) {
self::$registeredCustomElements[$item['type']] = $item;
require_once $item['include'];
}
/**
* Registers a set of new custom form elements.
*
* @see FactoryForms328_Form::registerCustomElement()
*
* @since 1.0.0
* @return void
*/
public function registerCustomElements( $data ) {
foreach($data as $item) $this->registerCustomElement( $item );
}
/**
* Contains a set of layouts registered for forms.
*
* @since 1.0.0
* @var mixed[]
*/
public static $formLayouts = array();
/**
* Registers a new layout for forms.
*
* @since 1.0.0
* @param type $data A layout data. Has the following format:
* name => a name of the layout
* class => a layout php class
* include => a path to include layout code
* @return void
*/
public function registerFormLayout( $data ) {
self::$formLayouts[$data['name']] = $data;
}
/**
* Extra propery that determines which UI is used in the admin panel.
*
* @since 1.0.0
* @var string
*/
public static $temper;
/**
* A flat to register control only once.
*
* @since 3.0.7
* @var bool
*/
public static $controlsRegistered = false;
}
/**
* An abstraction for forms.
*/
class FactoryForms328_Form {
// ----------------------------------------------------
// Object fields and methods
// ----------------------------------------------------
/**
* A value provider of the form that is used to save and load values.
*
* @since 1.0.0
* @var IFactoryValueProvider
*/
private $provider;
/**
* A prefix that will be used for names of input fields in the form.
*
* @since 1.0.0
* @var string
*/
public $scope;
/**
* A form name that is used to call hooks and filter data.
*
* @since 1.0.0
* @var string
*/
public $name = 'default';
/**
* It's not yet input controls. The array contains names of input controls and their
* options that are used to render and process input controls.
*
* @since 1.0.0
* @var mixed[]
*/
protected $items = array();
/**
* Full set of input controls available after building the form.
*
* The array contains objects.
*
* @since 1.0.0
* @var mixed[]
*/
private $controls = array();
/**
* A layout for the form.
*
* @since 1.0.0
* @var string
*/
public $formLayout;
/**
* A current form layout used to render a form.
*
* @since 1.0.0
* @var FactoryForms328_FormLayout
*/
public $layout;
/**
* Creates a new instance of a form.
*
* @since 1.0.0
* @param string $options Contains form options to setup.
*/
public function __construct( $options = array(), $plugin = null ) {
global $wp_version;
// register controls once, when the first form is created
if ( !FactoryForms328_Manager::$controlsRegistered ) {
do_action('factory_forms_328_register_controls', $plugin);
do_action('factory_forms_register_controls', $plugin);
if ( !empty( $plugin ) ) do_action('factory_forms_register_controls_' . $plugin->pluginName, $plugin);
FactoryForms328_Manager::$controlsRegistered = true;
}
//$isFlat = version_compare( $wp_version, '3.8', '>=' );
$isFlat = true;
$this->scope = isset( $options['scope'] ) ? $options['scope'] : null;
$this->name = isset( $options['name'] ) ? $options['name'] : $this->name;
if ( isset( $options['formLayout'] ) ) {
$this->formLayout = $options['formLayout'];
} else {
$this->formLayout = 'bootstrap-3';
}
if ( !FactoryForms328_Manager::$temper ) FactoryForms328_Manager::$temper = $isFlat ? 'flat' : 'volumetric';
}
/**
* Sets a provider for the control.
*
* @since 1.0.0
* @param IFactoryForms328_ValueProvider $provider
* @return void
*/
public function setProvider( $provider ) {
$this->provider = $provider;
}
/**
* Adds items into the form.
*
* It's base method to use during configuration form.
*
* @since 1.0.0
* @param array $array An array of items.
*/
public function add( $array ) {
if ( (bool)count(array_filter(array_keys($array), 'is_string')) ) {
$this->items[] = $array;
} else {
$this->items = array_merge($this->items, $array);
}
}
/**
* Returns items to render.
*
* Has the follwoing hooks:
* 'factory_form_items' ( $formName, $items ) to filter form controls before building.
*
* @since 1.0.0
* @return mixed[] Items to render.
*/
public function getItems() {
return apply_filters('factory_form_items', $this->items, $this->name );
}
/**
* Returns form controls (control objects).
*
* @since 1.0.0
* @return mixed[]
*/
public function getControls() {
if ( !empty($this->controls) ) return $this->controls;
$this->createControls();
return $this->controls;
}
/**
* Builds a form items to the control objects ready to use.
*
* @since 1.0.0
* @return void
*/
public function createControls( $holder = null ) {
$items = ( $holder == null ) ? $this->getItems() : $holder['items'];
foreach($items as $item ) {
if ( $this->isControlHolder( $item ) && $this->isControl( $item ) ) {
$this->controls[] = $this->createControl( $item );
$this->createControls( $item );
// if a current item is a control holder
} elseif ( $this->isControlHolder( $item ) ) {
$this->createControls( $item );
// if a current item is an input control
} elseif ( $this->isControl( $item ) ) {
$this->controls[] = $this->createControl( $item );
// if a current item is an input control
} elseif ( $this->isCustomElement( $item ) ) {
// nothing
// otherwise, show the error
} else {
print_r($item);
die( '[ERROR] Invalid item.' );
}
}
return $this->controls;
}
/**
* Create an element.
*
* @since 1.0.0
* @param type $item Item data.
* @return FactoryFrom_FormElement|null A form element.
*/
public function createElement( $item ) {
if ( $this->isControl( $item )) {
return $this->createControl( $item );
} elseif ( $this->isControlHolder( $item ) ) {
return $this->createHolder( $item );
} elseif ( $this->isCustomElement( $item ) ) {
return $this->createCustomElement( $item );
} else {
printf( '[ERROR] The element with the type <strong>%s</strong> was not found.', $item['type'] );
exit;
}
}
/**
* Creates a set of elements.
*
* @since 1.0.0
* @param mixed[] $item Data of items.
* @return FactoryFrom_FormElement[] Created elements.
*/
public function createElements( $items = array() ) {
$objects = array();
foreach( $items as $item ) $objects[] = $this->createElement($item);
return $objects;
}
/**
* Create a control.
*
* @since 1.0.0
* @param type $item Item data.
* @return FactoryFrom_Control A control object.
*/
public function createControl( $item ) {
$object = null;
if ( is_array( $item ) ) {
$controlData = FactoryForms328_Manager::$registeredControls[$item['type']];
require_once ($controlData['include']);
$options = $item;
$options['scope'] = $this->scope;
$object = new $controlData['class']( $options, $this );
} elseif ( gettype( $item ) == 'object' ) {
$object = $item;
} else {
print_r($item);
die( '[ERROR] Invalid input control.' );
}
$object->setProvider( $this->provider );
return $object;
}
/**
* Create a control holder.
*
* @since 1.0.0
* @param type $item Item data.
* @return FactoryForms328_Holder A control holder object.
*/
public function createHolder( $item ) {
$object = null;
if ( is_array( $item ) ) {
$holderData = FactoryForms328_Manager::$registeredHolders[$item['type']];
require_once ($holderData['include']);
$object = new $holderData['class']( $item, $this );
} elseif ( gettype( $item ) == 'object' ) {
$object = $item;
} else {
print_r($item);
die( '[ERROR] Invalid control holder.' );
}
return $object;
}
/**
* Create a custom form element.
*
* @since 1.0.0
* @param type $item Item data.
* @return FactoryForms328_FormElement A custom form element object.
*/
public function createCustomElement( $item ) {
$object = null;
if ( is_array( $item ) ) {
$data = FactoryForms328_Manager::$registeredCustomElements[$item['type']];
require_once ($data['include']);
$options = $item;
$object = new $data['class']( $options, $this );
} elseif ( gettype( $item ) == 'object' ) {
$object = $item;
} else {
print_r($item);
die( '[ERROR] Invalid custom form element.' );
}
return $object;
}
/**
* Renders a form.
*
* @since 1.0.0
* @param mixed[] $options Options for a form layout.
* @return void
*/
public function html( $options = array() ) {
if ( !isset( FactoryForms328_Manager::$formLayouts[$this->formLayout] ) )
die( sprintf( '[ERROR] The form layout %s was not found.', $this->formLayout ) );
// include a render code
$layoutData = FactoryForms328_Manager::$formLayouts[$this->formLayout];
require_once ($layoutData['include']);
$this->connectAssets();
if ( $this->provider ) $this->provider->init();
$layout = new $layoutData['class']( $options, $this );
$this->layout = $layout;
$this->layout->render();
}
/**
* Connects assets (css and js).
*
* @since 1.0.0
* @param mixed[] $options Options for a form layout.
* @return void
*/
private function connectAssets() {
$this->connectAssetsForItems();
$layoutData = FactoryForms328_Manager::$formLayouts[$this->formLayout];
if ( $layoutData['name'] == 'default') {
if ( isset( $layoutData['style'] ) )
wp_enqueue_style('factory-form-000-default-layout', $layoutData['style']);
if ( isset( $layoutData['script'] ) )
wp_enqueue_script('factory-form-000-default-layout-', $layoutData['script']);
} else {
if ( isset( $layoutData['style'] ) )
wp_enqueue_style('factory-form-layout-' . $layoutData['name'], $layoutData['style']);
if ( isset( $layoutData['script'] ) )
wp_enqueue_script('factory-form-layout-' . $layoutData['name'], $layoutData['script']);
}
}
/**
* Connects scripts and styles of form items.
*
* @since 1.0.0
* @param mixed[] $items Items for which it's nessesary to connect scripts and styles.
* @return void
*/
public static function connectAssetsForItems( $items = array() ) {
foreach($items as $item) self::connectAssetsForItem( $item );
}
/**
* Connects scripts and styles of form item.
*
* @since 1.0.0
* @param mixed[] $item Item for which it's nessesary to connect scripts and styles.
* @return void
*/
public static function connectAssetsForItem( $item ) {
if ( !is_array( $item ) ) return;
$type = $item['type'];
$haystack = array();
if ( self::isControl($type) ) $haystack = FactoryForms328_Manager::$registerControls;
elseif ( self::isControlHolder($type) ) $haystack = FactoryForms328_Manager::$registeredHolders;
if ( isset( $haystack[$type] ) ) {
if ( isset( $haystack[$type]['style'] ) ) {
$style = $haystack[$type]['style'];
if ( !wp_style_is( $style ) )
wp_enqueue_style('factory-form-control-' . $type, $style);
}
if ( isset( $haystack[$type]['script'] ) ) {
$script = $haystack[$type]['script'];
if ( !wp_script_is( $script ) )
wp_enqueue_script('factory-form-control-' . $type, $script, array('jquery'));
}
}
if ( isset($item['items'] ))
self::connectAssetsForItem( $item['items'] );
}
/**
* Saves form data by using a specified value provider.
*
* @since 1.0.0
* @return void
*/
public function save() {
if ( !$this->provider ) return;
$controls = $this->getControls();
foreach($controls as $control) {
$values = $control->getValuesToSave();
foreach( $values as $keyToSave => $valueToSave ) {
$this->provider->setValue($keyToSave, $valueToSave);
}
$nameOption = $control->getOption('name') . '_is_active';
$isActive = ( isset( $_POST[$nameOption] ) && intval( $_POST[$nameOption] ) == 0 ) ? 0 : 1;
$this->provider->setValue($nameOption, $isActive );
}
return $this->provider->saveChanges();
}
/**
* Returns true if a given item is an input control item.
*
* @since 1.0.0
* @param mixed[] $item
* @return bool
*/
public static function isControl( $item ) {
return isset( FactoryForms328_Manager::$registeredControls[ $item['type'] ] );
}
/**
* Returns true if a given item is an control holder item.
*
* @since 1.0.0
* @param mixed[] $item
* @return bool
*/
public static function isControlHolder( $item ) {
return isset( FactoryForms328_Manager::$registeredHolders[ $item['type'] ] );
}
/**
* Returns true if a given item is html markup.
*
* @since 1.0.0
* @param mixed[] $item
* @return bool
*/
public static function isCustomElement( $item ) {
return isset( FactoryForms328_Manager::$registeredCustomElements[ $item['type'] ] );
}
}

View File

@@ -0,0 +1,149 @@
<?php
/**
* The file contains the base class for all control holder
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* The base class for control holders.
*
* @since 1.0.0
*/
abstract class FactoryForms328_Holder extends FactoryForms328_FormElement {
/**
* Holder Elements.
*
* @since 1.0.0
* @var FactoryForms328_FormElement[]
*/
protected $elements = array();
/**
* Is this element a control holder?
*
* @since 1.0.0
* @var bool
*/
public $isHolder = true;
/**
* Creates a new instance of control holder.
*
* @since 1.0.0
* @param mixed[] $options A holder options.
* @param FactoryForms328_Form $form A parent form.
*/
public function __construct($options, $form) {
parent::__construct($options, $form);
$this->elements = $form->createElements( $options['items'] );
}
/**
* Returns holder elements.
*
* @since 1.0.0
* @return FactoryForms328_FormElement[].
*/
public function getElements() {
return $this->elements;
}
/**
* Renders the form or a given control holder.
*
* @since 1.0.0
* @param $holder A control holder to render.
* @return void
*/
function render() {
$this->beforeRendering();
$isFirstItem = true;
foreach( $this->elements as $element ) {
$element->setOption('isFirst', $isFirstItem);
if ( $isFirstItem ) $isFirstItem = false;
do_action('factory_form_before_element_' . $element->getOption('name') );
// if a current item is a control holder
if ( $element->isHolder ) {
$this->form->layout->beforeHolder( $element );
$element->render();
$this->form->layout->afterHolder( $element );
// if a current item is an input control
} elseif ( $element->isControl ) {
$this->form->layout->beforeControl( $element );
$element->render();
$this->form->layout->afterControl( $element );
// if a current item is a custom form element
} elseif ( $element->isCustom ) {
$element->render();
// otherwise, show the error
} else {
print_r($element);
echo( '[ERROR] Invalid item.' );
}
do_action('factory_form_after_element_' . $element->getOption('name') );
}
$this->afterRendering();
}
/**
* Rendering a beginning of a holder.
*
* @since 1.0.0
* @return void
*/
protected function beforeRendering(){}
/**
* Rendering an end of a holder.
*
* @since 1.0.0
* @return void
*/
protected function afterRendering(){}
/**
* Rendering some html before an inner holder.
*
* @since 1.0.0
* @return void
*/
protected function beforeInnerHolder(){}
/**
* Rendering some html after an inner holder.
*
* @since 1.0.0
* @return void
*/
protected function afterInnerHolder(){}
protected function beforeInnerElement(){}
/**
* Rendering some html after an inner element.
*
* @since 1.0.0
* @return void
*/
protected function afterInnerElement(){}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* The file contains Html Attribute Builder.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* Html Attribute Builder
*
* @since 1.0.0
*/
class FactoryForms328_HtmlAttributeBuilder {
/**
* An array to store css classes.
*
* @since 1.0.0
* @var string[]
*/
protected $cssClasses = array();
/**
* An array to store html attributes.
*
* @since 1.0.0
* @var string[]
*/
protected $htmlAttrs = array();
/**
* An array to store html data.
*
* @since 1.0.0
* @var string[]
*/
protected $htmlData = array();
/**
* Adds a new CSS class.
*
* @since 1.0.0
* @return void
*/
public function addCssClass( $class ) {
if (!is_array($class)) {
$this->cssClasses[] = $class;
} else {
$this->cssClasses = array_merge( $this->cssClasses, $class );
}
}
/**
* Prints CSS classes.
*
* @since 1.0.0
* @return void
*/
public function printCssClass() {
echo implode(' ', $this->cssClasses);
}
/**
* Adds a new html data item.
*
* @since 1.0.0
* @param string $dataKey
* @param string $dataValue
* @return void
*/
public function addHtmlData( $dataKey, $dataValue ) {
$this->htmlData[$dataKey] = $dataValue;
}
/**
* Prints html data items.
*
* @since 1.0.0
* @return void
*/
public function printHtmlData() {
foreach($this->htmlData as $key => $value) {
echo 'data-' . $key . '="' . $value . '" ';
}
}
/**
* Adds a new html attribute.
*
* @since 1.0.0
* @param type $attrName
* @param type $attrValue
* @return void
*/
public function addHtmlAttr( $attrName, $attrValue ) {
$this->htmlAttrs[$attrName] = $attrValue;
}
/**
* Prints all html attributes, including css classes and data.
*
* @since 1.0.0
* @return void
*/
public function printAttrs() {
$attrs = $this->htmlAttrs;
if ( !empty($this->cssClasses) ) $attrs['class'] = implode(' ', $this->cssClasses);
foreach( $this->htmlData as $dataKey => $dataValue) {
$attrs['data-'.$dataKey] = $dataValue;
}
foreach($attrs as $key => $value) {
echo $key . '="' . $value . '" ';
}
}
}

View File

@@ -0,0 +1,223 @@
<?php
/**
* The file contains the class of Factory Meta Value Provider.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* Factory Meta Value Provider
*
* This provide works with meta values like a lazy key-value storage and
* provides methods to commit changes on demand. It increases perfomance on form saving.
*
* @since 1.0.0
*/
class FactoryForms328_MetaValueProvider implements IFactoryForms328_ValueProvider
{
/**
* Values to save $metaName => $metaValue
* @var array
*/
private $values = array();
/**
* Chanched meta keys (indexed array)
* @var array
*/
private $keys = array();
private $meta = array();
public $scope;
/**
* Creates a new instance of a meta value provider.
*
* @global type $post
* @param type $options
*/
public function __construct( $options = array() ) {
global $post;
$this->scope = ( isset( $options['scope'] ) ) ? $options['scope'] : null;
$this->scope = preg_replace('/\_meta\_box$/', '', $this->formatCamelCase( $this->scope ) );
$this->postId = ( isset( $options['postId'] ) ) ? $options['postId'] : $post->ID;
// the second parameter for compatibility with wordpress 3.0
$temp = get_post_meta( $this->postId, '' );
foreach($temp as $key => &$content) {
if ( strpos( $key, $this->scope ) === 0 ) {
$this->meta[$key] = $content;
}
}
}
/**
* Initizalize an instance of the provider.
* This method should be invoked before the provider usage.
*
* @param type $scope Scope is prefix that is added to all meta keys.
* @param type $postId Post id we will use meta data or empty for current post.
*/
public function init( $postId = false ) {
global $post;
$this->postId = $postId ? $postId : $post->ID;
// the second parameter for compatibility with wordpress 3.0
$temp = get_post_meta( $this->postId, '' );
foreach($temp as $key => &$content) {
if ( strpos( $key, $this->scope ) === 0 ) {
$this->meta[$key] = $content;
}
}
}
/**
* Saves changes into a database.
* The method is optimized for bulk updates.
*/
public function saveChanges() {
$this->deleteValues();
$this->insertValues();
/**
foreach ($this->values as $key => $value) {
update_post_meta($this->postId, $key, $value);
}
*/
}
/**
* Removes all actual values from a database.
*/
private function deleteValues() {
if ( count( $this->keys ) == 0 ) return;
global $wpdb;
$keys = array();
for($i = 0; $i < count($this->keys); $i++) {
$keys[] = '\'' . $this->keys[$i] . '\'';
}
$clause = implode( ',', $keys );
$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id={$this->postId} AND meta_key IN ($clause)");
}
/**
* Inserts new values by using bulk insert directly into a database.
*/
private function insertValues() {
global $wpdb;
$sql = "INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value) VALUES ";
$rows = array();
foreach($this->values as $metaKey=>$metaValue) {
if ( is_array( $metaValue ) ) {
foreach( $metaValue as $value ) {
$rows[] = $wpdb->prepare( '(%d,%s,%s)' , $this->postId, $metaKey, $value );
}
} else {
$rows[] = $wpdb->prepare( '(%d,%s,%s)' , $this->postId, $metaKey, $metaValue );
}
}
$sql = $sql . implode( ',', $rows );
$wpdb->query($sql);
}
public function getValue($name, $default = null, $multiple = false ) {
if ( is_array( $name ) ) {
$values = array();
$index = 0;
foreach($name as $item) {
$itemDefault = ( $default && is_array($default) && isset($default[$index]) )
? $default[$index] : null;
$values[] = $this->getValueBySingleName($item, $itemDefault, $multiple);
$index++;
}
return $values;
}
$value = $this->getValueBySingleName($name, $default, $multiple);
return $value;
}
protected function getValueBySingleName( $singleName, $default = null, $multiple = false ) {
$value = isset( $this->meta[$this->scope . '_' . $singleName] )
? ( $multiple ) ? $this->meta[$this->scope . '_' . $singleName] : $this->meta[$this->scope . '_' . $singleName][0]
: $default;
if ($value === 'true') $value = 1;
if ($value === 'false') $value = 0;
return $value;
}
public function setValue($name, $value) {
if ( is_array( $name ) ) {
$index = 0;
foreach($name as $item) {
$itemValue = ( $value && is_array($value) && isset($value[$index]) )
? $value[$index] : null;
$this->setValueBySingleName($item, $itemValue);
$index++;
}
return;
}
$this->setValueBySingleName($name, $value);
return;
}
protected function setValueBySingleName( $singleName, $singeValue ) {
$name = $this->scope . '_' . $singleName;
if ( is_array( $singeValue ) ) {
foreach ($singeValue as $index => $value) {
$singeValue[$index] = empty( $singeValue[$index] )
? $singeValue[$index]
: stripslashes ( $singeValue[$index] );
}
$value = $singeValue;
} else {
$value = empty( $singeValue ) ? $singeValue : stripslashes ( $singeValue );
}
$this->values[$name] = $value;
$this->keys[] = $name;
}
private function formatCamelCase( $string ) {
$output = "";
foreach( str_split( $string ) as $char ) {
if ( strtoupper( $char ) == $char && !in_array($char, array('_', '-'))) {
$output .= "_";
}
$output .= $char;
}
$output = strtolower($output);
return $output;
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* The file contains the class of Factory Option Value Provider.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* Factory Options Value Provider
*
* This provide stores form values in the wordpress options.
*
* @since 1.0.0
*/
class FactoryForms328_OptionsValueProvider implements IFactoryForms328_ValueProvider
{
/**
* Values to save $optionName => $optionValue
*
* @since 1.0.0
* @var mixed[]
*/
private $values = array();
/**
* A prefix that will be added to all option names.
*
* @since 1.0.0
* @var string
*/
public $scope;
/**
* Creates a new instance of an options value provider.
*/
public function __construct( $options = array() ) {
$this->scope = ( isset( $options['scope'] ) ) ? $options['scope'] : null;
}
/**
* @since 1.0.0
*/
public function init() {
// nothing to do
}
/**
* @since 1.0.0
*/
public function saveChanges() {
// nothing to do
}
public function getValue($name, $default = null, $multiple = false ) {
$name = ( !empty( $this->scope ) ) ? $this->scope . '_' . $name : $name;
$value = get_option($name, $default);
if ($value === 'true') $value = 1;
if ($value === 'false') $value = 0;
return $value;
}
public function setValue($name, $value) {
$name = ( !empty( $this->scope ) ) ? $this->scope . '_' . $name : $name;
$value = empty( $value ) ? $value : stripslashes ( $value );
update_option($name, $value);
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* The file contains an interface for all value provides.
*
* A value provider is a provide to get and save values to some stores (database, metadata and so on).
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* The interface for all value provides.
*
* @since 1.0.0
*/
interface IFactoryForms328_ValueProvider {
/**
* Inits a form a provider to get data from a storage.
*
* @since 1.0.0
* @return void
*/
public function init();
/**
* Commits all changes.
*
* @since 1.0.0
* @return void
*/
public function saveChanges();
/**
* Gets a value by its name.
*
* @since 1.0.0
* @param string $name A value name to get.
* @param mixed $default A default to return if a given name doesn't exist.
* @return mixed
*/
public function getValue( $name, $default = null, $multiple = false );
/**
* Sets a value by its name.
*
* @since 1.0.0
* @param seting $name A value name to set.
* @param mixed $value A value to set.
* @return void
*/
public function setValue( $name, $value );
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* The file contains a form layout based on Twitter Bootstrap 2
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* A form layout based on Twitter Bootstrap 2
*/
class FactoryForms328_Bootstrap2FormLayout extends FactoryForms328_FormLayout {
public $name = 'default';
/**
* Creates a new instance of a bootstrap3 form layout.
*
* @since 1.0.0
* @param mixed[] $options A holder options.
* @param FactoryForms328_Form $form A parent form.
*/
public function __construct($options, $form) {
parent::__construct($options, $form);
$this->addCssClass('factory-bootstrap-331');
}
/**
* Renders a beginning of a form.
*
* @since 1.0.0
* @return void
*/
public function beforeRendering() {
?>
<div <?php $this->attrs() ?>>
<div class="form-horizontal">
<?php
}
/**
* Renders the end of a form.
*
* @since 1.0.0
* @return void
*/
public function afterRendering() {
?>
</div>
</div>
<?php
}
public function beforeControl( $control ) {
if ( $control->getType() == 'hidden' ) return;
$themeClass = '';
if ( isset($control->options['theme']) ) $themeClass = $control->options['theme'];
$controlName = $control->getName();
$controlNameClass = $controlName ? 'factory-control-' . $controlName : '';
?>
<div class="control-group <?php echo $themeClass ?> <?php echo $controlNameClass ?>">
<label for="<?php $control->printNameOnForm() ?>" class="control-label">
<?php if ( $control->hasIcon() ) { ?>
<img class="control-icon" src="<?php $control->icon() ?>" />
<?php } ?>
<?php $control->title() ?>
<?php if ( $control->hasHint() && $control->getLayoutOption('hint-position', 'bottom') == 'left' ) { ?>
<div class="help-block"><?php $control->hint() ?></div>
<?php } ?>
</label>
<div class="controls">
<?php
}
public function afterControl( $control ) {
if ( $control->getType() == 'hidden' ) return;
?>
<?php if ( $control->hasHint() && $control->getLayoutOption('hint-position', 'bottom') == 'bottom' ) { ?>
<div class="help-block">
<?php $control->hint() ?>
</div>
<?php } ?>
</div>
</div>
<?php
}
}

View File

@@ -0,0 +1,145 @@
<?php
/**
* The file contains a form layout based on Twitter Bootstrap 3
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package factory-forms
* @since 1.0.0
*/
/**
* A form layout based on Twitter Bootstrap 3
*/
class FactoryForms328_Bootstrap3FormLayout extends FactoryForms328_FormLayout {
public $name = 'default';
/**
* Creates a new instance of a bootstrap3 form layout.
*
* @since 1.0.0
* @param mixed[] $options A holder options.
* @param FactoryForms328_Form $form A parent form.
*/
public function __construct($options, $form) {
parent::__construct($options, $form);
$this->addCssClass('factory-bootstrap');
if ( isset( $options['cssClass'] ) ) $this->addCssClass( $options['cssClass'] );
}
/**
* Renders a beginning of a form.
*
* @since 1.0.0
* @return void
*/
public function beforeRendering() {
?>
<div <?php $this->attrs() ?>>
<div class="form-horizontal">
<?php
}
/**
* Renders the end of a form.
*
* @since 1.0.0
* @return void
*/
public function afterRendering() {
?>
</div>
</div>
<?php
}
public function beforeControl( $control ) {
if ( $control->getType() == 'hidden' ) return;
$themeClass = '';
if ( isset($control->options['theme']) ) $themeClass = $control->options['theme'];
$controlName = $control->getOption('name');
$controlNameClass = $controlName ? 'factory-control-' . $controlName : '';
?>
<div class="form-group form-group-<?php echo $control->type ?> <?php echo $themeClass ?> <?php echo $controlNameClass ?>">
<label for="<?php $control->printNameOnForm() ?>" class="col-sm-2 control-label">
<?php if ( $control->hasIcon() ) { ?>
<img class="control-icon" src="<?php $control->icon() ?>" />
<?php } ?>
<?php $control->title() ?>
<?php if ( $control->hasHint() && $control->getLayoutOption('hint-position', 'bottom') == 'left' ) { ?>
<div class="help-block"><?php $control->hint() ?></div>
<?php } ?>
</label>
<div class="control-group col-sm-10">
<?php
}
public function afterControl( $control ) {
if ( $control->getType() == 'hidden' ) return;
?>
<?php if ( $control->getOption('after', false) ) { ?>
<span class="factory-after">
<?php $control->option('after') ?>
</span>
<?php } ?>
<?php if ( $control->hasHint() && $control->getLayoutOption('hint-position', 'bottom') == 'bottom' ) { ?>
<div class="help-block">
<?php $control->hint() ?>
</div>
<?php } ?>
</div>
</div>
<?php
}
public function startRow( $index, $total ) {
?>
<div class='factory-row factory-row-<?php echo $index ?> factory-row-<?php echo $index ?>-of-<?php echo $total ?>'>
<div class="form-group form-group">
<?php
}
public function endRow( $index, $total ) {
?>
</div>
</div>
<?php
}
public function startColumn( $control, $index, $total ) {
$index = $total == 2 ? 4 : 3;
$name = $control->getNameOnForm();
?>
<label for="<?php echo $name ?>" class="col-sm-2 control-label control-label-<?php echo $name ?>">
<?php if ( $control->hasIcon() ) { ?>
<img class="control-icon" src="<?php $control->icon() ?>" />
<?php } ?>
<?php $control->title() ?>
<?php if ( $control->hasHint() && $control->getLayoutOption('hint-position', 'bottom') == 'left' ) { ?>
<div class="help-block"><?php $control->hint() ?></div>
<?php } ?>
</label>
<div class="control-group control-group-<?php echo $name ?> col-sm-<?php echo $index ?>">
<?php
}
public function endColumn( $control, $index, $total ) {
?>
<?php if ( $control->getOption('after', false) ) { ?>
<span class="factory-after">
<?php $control->option('after') ?>
</span>
<?php } ?>
<?php if ( $control->hasHint() && $control->getLayoutOption('hint-position', 'bottom') == 'bottom' ) { ?>
<div class="help-block">
<?php $control->hint() ?>
</div>
<?php } ?>
</div>
<?php
}
}