From eed7ec8c4a3dfe33111633c6bdf877d35c3a8805 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 14:52:16 -1000 Subject: [PATCH 01/17] Remove reference assignment from `Utilities::get_parent_property()` --- includes/class.utilities.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class.utilities.php b/includes/class.utilities.php index 252bc1d..859c2ce 100644 --- a/includes/class.utilities.php +++ b/includes/class.utilities.php @@ -620,7 +620,7 @@ function get_parent() { * @return mixed Parent property value */ function get_parent_property($prop, $default = '') { - $p =& $this->get_parent(); + $p = $this->get_parent(); return ( !!$p && property_exists($p, $prop) ) ? $p->{$prop} : $default; } From d4892ca1eef77c7d89504b42025b6def96e3d9f9 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 14:56:59 -1000 Subject: [PATCH 02/17] Remove reference assignment from `Utilities::__construct()` --- includes/class.utilities.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class.utilities.php b/includes/class.utilities.php index 859c2ce..9ea64b6 100644 --- a/includes/class.utilities.php +++ b/includes/class.utilities.php @@ -58,9 +58,9 @@ class SLB_Utilities { /* Constructors */ - function __construct(&$obj) { + function __construct($obj) { if ( is_object($obj) ) { - $this->_parent =& $obj; + $this->_parent = $obj; } } From 6aab401278b961e852dc06d04fa9ce96558d03b1 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 15:05:51 -1000 Subject: [PATCH 03/17] Optimize: Reference-based assignments in `Field_Base::get_data()` --- includes/class.field_base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class.field_base.php b/includes/class.field_base.php index 811f83a..6d9d461 100644 --- a/includes/class.field_base.php +++ b/includes/class.field_base.php @@ -535,7 +535,7 @@ function get_data($context = '', $top = true) { //Iterate through objects while ( !empty($obj_path) ) { //Get next object - $obj =& array_shift($obj_path); + $obj = array_shift($obj_path); //Shorten path array_shift($path); //Check for value in object and stop iteration if matching data found From 4f8671a9b6883daefdfe23f9c61f7b7ac8b97111 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 15:17:21 -1000 Subject: [PATCH 04/17] Optimize: Reference-based assignments in `Field_Base::set_parent()` --- includes/class.field_base.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/class.field_base.php b/includes/class.field_base.php index 6d9d461..957a88d 100644 --- a/includes/class.field_base.php +++ b/includes/class.field_base.php @@ -572,7 +572,7 @@ function set_parent($parent = null) { return false; //Parent passed as object reference wrapped in array if ( is_array($parent) && isset($parent[0]) && is_object($parent[0]) ) - $parent =& $parent[0]; + $parent = $parent[0]; //No parent set but parent ID (previously) set in object if ( empty($parent) && is_string($this->parent) ) @@ -585,15 +585,15 @@ function set_parent($parent = null) { /** * @var SLB */ - $b =& $this->get_base(); - if ( $b && isset($b->fields) && $b->fields->has($parent) ) { - $parent =& $b->fields->get($parent); + $b = $this->get_base(); + if ( !!$b && isset($b->fields) && $b->fields->has($parent) ) { + $parent = $b->fields->get($parent); } } //Set parent value on object if ( is_string($parent) || is_object($parent) ) - $this->parent =& $parent; + $this->parent = $parent; } /** From e09b455a01d8bf8b99ae8be2e7cfb6f558c868c7 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 15:23:36 -1000 Subject: [PATCH 05/17] Optimize: Reference-based assignments in `Field_Base::get_parent()` & `Field_Base::get_parent_value()` --- includes/class.field_base.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class.field_base.php b/includes/class.field_base.php index 957a88d..114ed49 100644 --- a/includes/class.field_base.php +++ b/includes/class.field_base.php @@ -234,7 +234,7 @@ function &get_path_value($path = '') { * @return mixed Member value if found (Default: empty string) */ function get_parent_value($member, $name = '', $default = '') { - $parent =& $this->get_parent(); + $parent = $this->get_parent(); return $this->get_object_value($parent, $member, $name, $default, 'parent'); } @@ -598,9 +598,9 @@ function set_parent($parent = null) { /** * Retrieve field type parent - * @return SLB_Field_Type Reference to parent field + * @return SLB_Field_Type Parent field */ - function &get_parent() { + function get_parent() { return $this->parent; } From b3c4bde7f70532138bf289f53fa1ad1cac79d665 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 15:30:37 -1000 Subject: [PATCH 06/17] Optimize: Reference-based assignments in `Field_Collection` * `get_data()` * `add_to_group()` --- includes/class.field_collection.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class.field_collection.php b/includes/class.field_collection.php index 908674b..5de4559 100644 --- a/includes/class.field_collection.php +++ b/includes/class.field_collection.php @@ -308,7 +308,7 @@ function get_data($item = null, $context = '', $top = true) { $this->load_data(); $ret = null; if ( $this->has($item) ) { - $item =& $this->get($item); + $item = $this->get($item); $ret = $item->get_data($context, $top); } else { $ret = parent::get_data($context, $top); @@ -540,7 +540,7 @@ function add_to_group($group, $items, $priority = 10) { //Add Items foreach ( $items as $item ) { //Skip if not in current collection - $itm_ref =& $this->get($item); + $itm_ref = $this->get($item); if ( !$itm_ref ) { continue; } @@ -558,7 +558,7 @@ function add_to_group($group, $items, $priority = 10) { if ( !isset($items[$priority]) ) { $items[$priority] = array(); } - $items[$priority][$itm_id] =& $itm_ref; + $items[$priority][$itm_id] = $itm_ref; } unset($itm_ref); } From 0d73a17f17ac578b2644525745541216d4207082 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 15:44:21 -1000 Subject: [PATCH 07/17] Optimize: Reference-based return value in `Field_Collection::add()` --- includes/class.field_collection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class.field_collection.php b/includes/class.field_collection.php index 5de4559..bffd5d8 100644 --- a/includes/class.field_collection.php +++ b/includes/class.field_collection.php @@ -161,9 +161,9 @@ function set_data($item, $value = '', $save = true, $force_set = false) { * @param string|obj $id Unique name for item or item instance * @param array $properties (optional) Item properties * @param bool $update (optional) Update or overwrite existing item (Default: FALSE) - * @return object Reference to new item + * @return object Newly-added item */ - function &add($id, $properties = array(), $update = false) { + function add($id, $properties = array(), $update = false) { $item; $args = func_get_args(); //Properties From f95fc5126d5d27771f5d8df4b6f8fbb2d830f044 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 15:45:38 -1000 Subject: [PATCH 08/17] Optimize: Reference-based assignment in `Options` * `add()` * `migrate()` * `build_client_output()` --- includes/class.options.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/class.options.php b/includes/class.options.php index 2522df5..c5c3880 100644 --- a/includes/class.options.php +++ b/includes/class.options.php @@ -133,7 +133,7 @@ function migrate($full = false) { $d = null; $this->load_data(); - $items =& $this->get_items(); + $items = $this->get_items(); //Migrate separate options to unified option if ( $full ) { @@ -442,7 +442,7 @@ function get_key() { function &add($id, $properties = array(), $update = false) { //Create item $args = func_get_args(); - $ret =& call_user_func_array(array('parent', 'add'), $args); + $ret = call_user_func_array(array('parent', 'add'), $args); return $ret; } @@ -498,7 +498,7 @@ function build_init() { * @return array Associative array of options */ function build_client_output() { - $items =& $this->get_items(); + $items = $this->get_items(); $out = array(); foreach ( $items as $option ) { if ( !$option->get_in_client() ) From ccfec2d494641e6d0f1b40011617b950d108af13 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 16:08:14 -1000 Subject: [PATCH 09/17] Optimize: Standardize `_options()` implementation * Add: `Base::_set_options()` * Add: `Base::_options()` (placeholder) * Update: Child `_options()` methods call `Base::_set_options()` to initialize options --- controller.php | 2 +- includes/class.base.php | 8 +++++++- includes/class.themes.php | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/controller.php b/controller.php index 1beb10d..f369aff 100644 --- a/controller.php +++ b/controller.php @@ -291,7 +291,7 @@ protected function _options() { ) ); - parent::_options($opts); + parent::_set_options($opts); } /* Methods */ diff --git a/includes/class.base.php b/includes/class.base.php index 236ef8f..c5ac795 100644 --- a/includes/class.base.php +++ b/includes/class.base.php @@ -177,11 +177,17 @@ private function _env() { add_action( ( is_admin() ) ? 'admin_print_footer_scripts' : 'wp_footer', $this->util->m('set_client_context'), $this->util->priority('client_footer_output') ); } + /** + * Initialize options + * To be implemented in child classes + */ + protected function _options() {} + /** * Initialize options * To be called by child class */ - protected function _options($options_config = null) { + protected function _set_options($options_config = null) { $class = $this->util->get_class('Options'); $key = 'options'; if ( $this->shares($key) ) { diff --git a/includes/class.themes.php b/includes/class.themes.php index 6d6442a..7c16060 100644 --- a/includes/class.themes.php +++ b/includes/class.themes.php @@ -47,7 +47,7 @@ protected function _options() { ) ); - parent::_options($opts); + parent::_set_options($opts); } /** From cd20e2fc93eb64537ec18b1d8935a7735a02ad9d Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 16:12:43 -1000 Subject: [PATCH 10/17] Optimize: Standardize `Content_Handlers::get()` to `Base_Collection::get()` --- includes/class.content_handlers.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/class.content_handlers.php b/includes/class.content_handlers.php index 80d72c4..ab0a460 100644 --- a/includes/class.content_handlers.php +++ b/includes/class.content_handlers.php @@ -92,9 +92,10 @@ public function clear() { * Retrieves handlers sorted by priority * @see parent::get() * @uses get_cache() + * @param mixed $args Unused * @return array Handlers */ - public function get() { + public function get($args = null) { $items = $this->get_cache(); if ( empty($items) ) { //Retrieve items From 0ce6037a5364204e510229c71560460039617430 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 16:19:20 -1000 Subject: [PATCH 11/17] Update: `Field_Collection::get_items()` returns reference to items in collection --- includes/class.field_collection.php | 2 +- includes/class.options.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class.field_collection.php b/includes/class.field_collection.php index bffd5d8..93d0d75 100644 --- a/includes/class.field_collection.php +++ b/includes/class.field_collection.php @@ -344,7 +344,7 @@ function add_items($items = array(), $update = false) { * Retrieve reference to items in collection * @return array Collection items (reference) */ - function get_items($group = null, $sort = 'priority') { + function &get_items($group = null, $sort = 'priority') { $gset = $this->group_exists($group); if ( $gset ) { $items = $this->get_group_items($group); diff --git a/includes/class.options.php b/includes/class.options.php index c5c3880..6030386 100644 --- a/includes/class.options.php +++ b/includes/class.options.php @@ -280,7 +280,7 @@ function register_fields($fields) { function set_parents($fields) { if ( !is_admin() ) return false; - $items =& $this->get_items(); + $items = &$this->get_items(); foreach ( array_keys($items) as $opt ) { $items[$opt]->set_parent(); } From 157ba0df6fc249709a292ebfd522475b11104fc8 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 16:20:08 -1000 Subject: [PATCH 12/17] Optimize: Reference-based assignment in `Option::set_parent()` --- includes/class.option.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class.option.php b/includes/class.option.php index 77fab93..1903f93 100644 --- a/includes/class.option.php +++ b/includes/class.option.php @@ -66,7 +66,7 @@ function get_default($context = '') { * Sets parent based on default value */ function set_parent($parent = null) { - $p =& $this->get_parent(); + $p = $this->get_parent(); if ( empty($parent) && empty($p) ) { $parent = 'text'; $d = $this->get_default(); From ff1b3bfcd7270b9b8d34c397701a326558a75f09 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 16:32:07 -1000 Subject: [PATCH 13/17] Optimize: Make sure formatting context is scalar (e.g. a string) before building formatting handler --- includes/class.field_base.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/includes/class.field_base.php b/includes/class.field_base.php index 114ed49..88ac80a 100644 --- a/includes/class.field_base.php +++ b/includes/class.field_base.php @@ -981,11 +981,13 @@ function get_styles() { * @return mixed Formatted value */ function format($value, $context = '') { - $handler = 'format_' . trim(strval($context)); - //Only process if context is valid and has a handler - if ( !empty($context) && method_exists($this, $handler) ) { - //Pass value to handler - $value = $this->{$handler}($value, $context); + if ( is_scalar($context) && !empty($context) ) { + $handler = 'format_' . trim(strval($context)); + //Only process if context is valid and has a handler + if ( !empty($context) && method_exists($this, $handler) ) { + //Pass value to handler + $value = $this->{$handler}($value, $context); + } } //Return formatted value return $value; From 606bbef8518dd8bbda692d25d559596e5988b197 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 17:15:56 -1000 Subject: [PATCH 14/17] Update: WP version requirement (4.2.1) --- readme.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.txt b/readme.txt index 64d2a5a..2bdb00a 100644 --- a/readme.txt +++ b/readme.txt @@ -3,8 +3,8 @@ Contributors: Archetyped Donate link: http://gum.co/slb-donate License: GPLv2 Tags: lightbox, gallery, photography, images, theme, template, style -Requires at least: 3.9 -Tested up to: 3.9 +Requires at least: 4.2.1 +Tested up to: 4.2.1 Stable tag: trunk The highly customizable lightbox for WordPress From d1affc7d71e65d77badd924226d721979386f7b2 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 17:51:10 -1000 Subject: [PATCH 15/17] Optimize: Perform quick content validation before processing further * Add: `is_content_valid()` --- controller.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/controller.php b/controller.php index f369aff..d01a815 100644 --- a/controller.php +++ b/controller.php @@ -387,6 +387,30 @@ function is_enabled() { return !!$ret; } + /** + * Make sure content is valid for processing/activation + * + * @param string $content Content to validate + * @return bool TRUE if content is valid (FALSE otherwise) + */ + protected function is_content_valid($content = '') { + // Invalid hooks + if ( doing_filter('get_the_excerpt') ) + return false; + + // Non-string value + if ( !is_string($content) ) + return false; + + // Empty string + $content = trim($content); + if ( empty($content) ) + return false; + + // Content is valid + return true; + } + /** * Activates galleries extracted from post * @see get_post_galleries() @@ -428,6 +452,9 @@ function activate_galleries($galleries) { * @return string Post content */ public function activate_links($content, $group = null) { + if ( !$this->is_content_valid($content) ) { + return $content; + } // Filter content before processing links $content = $this->util->apply_filters('pre_process_links', $content); @@ -1203,6 +1230,9 @@ function group_get_wrapper() { * @return string Modified post content */ function group_shortcodes($content) { + if ( !$this->is_content_valid($content) ) { + return $content; + } // Setup shortcodes to wrap $shortcodes = $this->util->apply_filters('group_shortcodes', array( 'gallery', 'nggallery' )); // Set custom callback From 2ac99a681d017eb86e609a5be59f4d1c12d7574f Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 18:07:07 -1000 Subject: [PATCH 16/17] Update: readme.txt (2.4.0-rc1) --- readme.txt | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/readme.txt b/readme.txt index 2bdb00a..034bdad 100644 --- a/readme.txt +++ b/readme.txt @@ -57,24 +57,12 @@ Get more information on [Simple Lightbox's official page](http://archetyped.com/ == Changelog == -= 2.4.0 (Beta 3) = -* JS: Optimize: View Controller -* JS: Update: Set default ID for components -* JS: Optimize: Component properties -* JS: Optimize: Remove unused/deprecated Component methods/properties -* JS: Optimize: Component references handling -* JS: Optimize: Component attribute handling -* JS: Optimize: Component DOM handling - -= 2.4.0 (Beta 2) = -* JS: Optimize: Core library -* JS: Optimize: Utilities library -* JS: Optimize: Default template tags (item, ui) -* JS: Optimize: Default content handlers (image) -* JS: Optimize: Default themes (baseline, default) -* JS: Optimize: View controller - -= 2.4.0 (Beta 1) = += 2.4.0 (RC1) = + +* Update: WordPress version compatibility (v4.2.1) +* Optimize: Standardize code +* Optimize: Do not process excerpt content +* Optimize: Client-side libraries (Phase 1) * Add: Set group via `slb_activate()` * Add: Set group via `activate_links()` * Add: `slb_is_enabled` filter From 88f40ab6f4a8635f2c20c363b35261dab3371513 Mon Sep 17 00:00:00 2001 From: Archetyped Date: Mon, 27 Apr 2015 18:09:34 -1000 Subject: [PATCH 17/17] Prep for release (2.4.0-rc1) --- main.php | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.php b/main.php index a74fe4c..aa48db9 100644 --- a/main.php +++ b/main.php @@ -3,7 +3,7 @@ Plugin Name: Simple Lightbox Plugin URI: http://archetyped.com/tools/simple-lightbox/ Description: The highly customizable lightbox for WordPress -Version: dev (BETA) +Version: 2.4.0-rc1 Author: Archetyped Author URI: http://archetyped.com Support URI: https://github.com/archetyped/simple-lightbox/wiki/Feedback-&-Support diff --git a/package.json b/package.json index 176f123..65cd56f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-lightbox", - "version": "0.0.0-dev", + "version": "2.4.0-rc1", "title": "Simple Lightbox", "description": "The highly-customizable lightbox for WordPress", "author": "Sol Marchessault ",