From 7611109d78a03912af114b5539394a2331bd70ab Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Fri, 22 Aug 2014 07:55:17 -0300 Subject: [PATCH 1/4] Allow the $arguments for post_content --- providers/wp-post.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/wp-post.php b/providers/wp-post.php index caa31f0..84b483d 100644 --- a/providers/wp-post.php +++ b/providers/wp-post.php @@ -15,9 +15,9 @@ public function post_title( $qty_words = 5 ) { return $title; } - public function post_content( $html = true ) { + public function post_content( $html = true, $args = array() ) { if ( $html === true ){ - $content = implode( "\n", $this->generator->html_elements() ); + $content = implode( "\n", $this->generator->html_elements( $args ) ); } else { $content = implode( "\r\n\r\n", $this->generator->paragraphs( $this->generator->randomDigitNotNull() ) ); } From 2e2e44e04da2d68989b0b60a472616e1832471e0 Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Fri, 22 Aug 2014 10:11:20 -0300 Subject: [PATCH 2/4] Include a Tags Select2 field --- ui/js/fields.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/ui/js/fields.js b/ui/js/fields.js index e9f1865..706744b 100644 --- a/ui/js/fields.js +++ b/ui/js/fields.js @@ -1,5 +1,5 @@ // Simple Select2 Fields -( function( $ ){ +( function( $, _ ){ 'use strict'; $(document).ready(function(){ $( '.field-select2-simple' ).each(function(){ @@ -37,7 +37,24 @@ $select.select2({ width: 200 }); }); }); -}( jQuery ) ); +}( window.jQuery, window._ ) ); + +// Tagged Select2 Fields +( function( $, _ ){ + 'use strict'; + $(document).ready(function(){ + $( '.field-select2-tags' ).each(function(){ + var $select = $(this); + + $select.select2({ + multiple: true, + width: 400, + tags: $select.data('tags'), + tokenSeparators: [','] + }); + }); + }); +}( window.jQuery, window._ ) ); // Date Fields ( function( $ ){ @@ -182,7 +199,45 @@ return; } $field.data( 'post_parent', $field.parents( '.form-table' ).find( '.field-container-post_parent' ).detach() ); - }) + }); + }); +}( window.jQuery, window._ ) ); + +// Check for checkbox dependecies +( function( $, _ ){ + 'use strict'; + $(document).ready(function(){ + var checkDependency = function( event ){ + var $box, $dependecyField; + if ( _.isNumber( event ) ){ + $box = $( this ); + $dependecyField = $( $box.data('fkDepends') ); + } else { + $dependecyField = $( this ); + $box = $dependecyField.data( 'fkDependent' ); + } + + var condition = $box.data('fkCondition'), + $placeholder = $dependecyField.data( 'fkPlaceholder' ); + + if ( ! $placeholder ){ + $placeholder = $( "
" ).attr( 'id', _.uniqueId( 'fk-dependent-placeholder-' ) ); + $dependecyField.data( 'fkPlaceholder', $placeholder ); + } + $dependecyField.data( 'fkDependent', $box ); + + if ( _.isNumber( event ) ){ + $dependecyField.on( 'change', checkDependency ); + } + + if ( $dependecyField.is(':checked') != condition ){ + $box.after( $placeholder ).detach(); + } else if ( $placeholder.is(':visible') ) { + $placeholder.replaceWith( $dependecyField.data( 'fkDependent' ) ); + } + }; + + $( '.fk-field-dependent' ).each( checkDependency ); }); }( window.jQuery, window._ ) ); From 059797491642bdbc934280184f40d4a4673be666 Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Fri, 22 Aug 2014 10:11:55 -0300 Subject: [PATCH 3/4] Improving the providers to allow HTML in a better way --- providers/html.php | 28 +++++++++++++--------------- providers/wp-post.php | 3 ++- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/providers/html.php b/providers/html.php index c70ed85..d85b5ca 100644 --- a/providers/html.php +++ b/providers/html.php @@ -1,24 +1,22 @@ generator = $generator; - self::$sets = (object) self::$sets; - $provider = new Internet( $this->generator ); $this->generator->addProvider( $provider ); } - static private $sets = array( + static public $sets = array( 'self_close' => array( 'img', 'hr', 'submit' ), 'header' => array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6' ), 'list' => array( 'ul', 'ol' ), - 'block' => array( 'div', 'p' ), + 'block' => array( 'div', 'p', 'blockquote' ), 'item' => array( 'li' ), 'inline' => array( 'b', 'big', 'i', 'small', 'tt', @@ -33,7 +31,7 @@ public function html_elements( $args = array() ){ $defaults = array( 'qty' => Base::randomNumber( 5, 25 ), - 'elements' => array_merge( self::$sets->header, self::$sets->list, self::$sets->block ), + 'elements' => array_merge( self::$sets['header'], self::$sets['list'], self::$sets['block'] ), 'attr' => array(), 'exclude' => array( 'div' ), ); @@ -44,10 +42,10 @@ public function html_elements( $args = array() ){ if ( isset( $element ) ){ // Here we check if we need to exclude some elements from the next // This one is to exclude header elements from apearing one after the other, or in the end of the string - if ( in_array( $element, self::$sets->header ) || $args->qty - 1 === $i ){ - $exclude = array_merge( (array) $exclude, self::$sets->header ); - } elseif ( $i > 1 && ( in_array( $els[$i - 1], self::$sets->list ) || in_array( $els[$i - 2], self::$sets->list ) ) ) { - $exclude = array_merge( (array) $exclude, self::$sets->list ); + if ( in_array( $element, self::$sets['header'] ) || $args->qty - 1 === $i ){ + $exclude = array_merge( (array) $exclude, self::$sets['header'] ); + } elseif ( $i > 1 && ( in_array( $els[$i - 1], self::$sets['list'] ) || in_array( $els[$i - 2], self::$sets['list'] ) ) ) { + $exclude = array_merge( (array) $exclude, self::$sets['list'] ); } } $els[] = $element = Base::randomElement( array_diff( $args->elements, $exclude ) ); @@ -107,7 +105,7 @@ public function element( $name = 'div', $attr = array(), $text = null ){ 'attr' => $attr, ); - $element->one_liner = in_array( $element->name, self::$sets->self_close ); + $element->one_liner = in_array( $element->name, self::$sets['self_close'] ); $html = array(); @@ -129,17 +127,17 @@ public function element( $name = 'div', $attr = array(), $text = null ){ if ( ! is_null( $text ) ){ $html[] = $text; - } elseif ( in_array( $element->name, self::$sets->inline ) ){ + } elseif ( in_array( $element->name, self::$sets['inline'] ) ){ $text = Lorem::text( Base::randomNumber( 5, 25 ) ); $html[] = substr( $text, 0, strlen( $text ) - 1 ); - } elseif ( in_array( $element->name, self::$sets->item ) ){ + } elseif ( in_array( $element->name, self::$sets['item'] ) ){ $text = Lorem::text( Base::randomNumber( 10, 60 ) ); $html[] = substr( $text, 0, strlen( $text ) - 1 ); - } elseif ( in_array( $element->name, self::$sets->list ) ){ + } elseif ( in_array( $element->name, self::$sets['list'] ) ){ for ( $i = 0; $i < Base::randomNumber( 1, 15 ); $i++ ) { $html[] = $this->element( 'li' ); } - } elseif ( in_array( $element->name, self::$sets->header ) ){ + } elseif ( in_array( $element->name, self::$sets['header'] ) ){ $text = Lorem::text( Base::randomNumber( 60, 200 ) ); $html[] = substr( $text, 0, strlen( $text ) - 1 ); } else { diff --git a/providers/wp-post.php b/providers/wp-post.php index 84b483d..a3db185 100644 --- a/providers/wp-post.php +++ b/providers/wp-post.php @@ -51,7 +51,8 @@ public function tax_input( $taxonomies = null, $range = array( 1, 6 ) ) { public function post_type( $haystack = array() ){ if ( empty( $haystack ) ){ - $haystack = get_post_types( array(), 'names' ); + // Later on we will remove the Attachment rule + $haystack = array_diff( get_post_types( array( 'public' => true, 'show_ui' => true ), 'names' ), array( 'attachment' ) ); } return $this->generator->randomElement( (array) $haystack ); From 56e4e7e0471f22cd5964676e9f05b744d4642bca Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Fri, 22 Aug 2014 10:12:33 -0300 Subject: [PATCH 4/4] Include an administration to HTML elements --- inc/init/posts.php | 4 ++++ modules/post.php | 2 +- view/posts.php | 28 +++++++++++++++++++++++----- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/inc/init/posts.php b/inc/init/posts.php index 9edceb8..ad04a3a 100644 --- a/inc/init/posts.php +++ b/inc/init/posts.php @@ -26,6 +26,9 @@ function( $view ) { $taxonomies = array_intersect( get_taxonomies( array( 'public' => true ) ), array_map( 'trim', explode( ',', Filter::super( INPUT_POST, 'fakerpress_taxonomies', FILTER_SANITIZE_STRING ) ) ) ); + $post_content_use_html = Filter::super( INPUT_POST, 'fakerpress_post_content_use_html', FILTER_SANITIZE_STRING, 'off' ) === 'on'; + $post_content_html_tags = array_map( 'trim', explode( ',', Filter::super( INPUT_POST, 'fakerpress_post_content_html_tags', FILTER_SANITIZE_STRING ) ) ); + $post_parents = array_map( 'trim', explode( ',', Filter::super( INPUT_POST, 'fakerpress_post_parents', FILTER_SANITIZE_STRING ) ) ); if ( $quantity === 0 ){ @@ -43,6 +46,7 @@ function( $view ) { 'post_status' => array( array( 'publish' ) ), 'post_date' => array( $min_date, $max_date ), 'post_parent' => array( $post_parents ), + 'post_content' => array( $post_content_use_html, array( 'elements' => $post_content_html_tags ) ), 'post_type' => array( 'post' ), 'post_author' => array( $post_author ), 'post_type' => array( $post_types ), diff --git a/modules/post.php b/modules/post.php index 6af0a74..463c055 100644 --- a/modules/post.php +++ b/modules/post.php @@ -6,7 +6,7 @@ class Post extends Base { public $dependencies = array( '\Faker\Provider\Lorem', '\Faker\Provider\DateTime', - '\Faker\Provider\Html', + '\Faker\Provider\HTML', ); public $provider = '\Faker\Provider\WP_Post'; diff --git a/view/posts.php b/view/posts.php index 44baeb0..7524c1e 100644 --- a/view/posts.php +++ b/view/posts.php @@ -20,6 +20,8 @@ ); } +$_elements = array_merge( \Faker\Provider\HTML::$sets['header'], \Faker\Provider\HTML::$sets['list'], \Faker\Provider\HTML::$sets['block'] ); + // Mount the options for taxonomies $taxonomies = get_taxonomies( array( 'public' => true ), 'object' ); @@ -70,7 +72,7 @@ slug . ( isset( Admin::$view->action ) ? '.' . Admin::$view->action : '' ) ); ?> - + - + - + + + + + + + + + - + - +
@@ -97,7 +99,7 @@

@@ -106,7 +108,23 @@

+ +

+
+
+ ' data-tags='' /> +
+

+
@@ -115,7 +133,7 @@

@@ -133,7 +151,7 @@