コード例 #1
0
ファイル: term.php プロジェクト: luancuba/fakerpress
 public function parse_request($qty, $request = array())
 {
     if (is_null($qty)) {
         $qty = Utils::instance()->get_qty_from_range(Variable::super(INPUT_POST, array(Plugin::$slug, 'qty'), FILTER_UNSAFE_RAW));
     }
     if (0 === $qty) {
         return esc_attr__('Zero is not a good number of terms to fake...', 'fakerpress');
     }
     $name_size = Variable::super(INPUT_POST, array(Plugin::$slug, 'size'), FILTER_UNSAFE_RAW);
     // Fetch taxomies
     $taxonomies = Variable::super($request, array('taxonomies'), FILTER_SANITIZE_STRING);
     $taxonomies = array_map('trim', explode(',', $taxonomies));
     $taxonomies = array_intersect(get_taxonomies(array('public' => true)), $taxonomies);
     // Only has meta after 4.4-beta
     $has_metas = version_compare($GLOBALS['wp_version'], '4.4-beta', '>=');
     if ($has_metas) {
         $metas = Variable::super($request, array('meta'), FILTER_UNSAFE_RAW);
     }
     for ($i = 0; $i < $qty; $i++) {
         $this->set('taxonomy', $taxonomies);
         $this->set('name', $name_size);
         $this->set('description');
         $this->set('parent_term');
         $term_id = $this->generate()->save();
         if ($has_metas && $term_id && is_numeric($term_id)) {
             foreach ($metas as $meta_index => $meta) {
                 Meta::instance()->object($term_id, 'term')->generate($meta['type'], $meta['name'], $meta)->save();
             }
         }
         $results[] = $term_id;
     }
     $results = array_filter((array) $results, 'absint');
     return $results;
 }
コード例 #2
0
ファイル: comment.php プロジェクト: juanfra/fakerpress
 public function parse_request($qty, $request = array())
 {
     if (is_null($qty)) {
         $qty = Variable::super(INPUT_POST, array(Plugin::$slug, 'qty'), FILTER_UNSAFE_RAW);
         $min = absint($qty['min']);
         $max = max(absint(isset($qty['max']) ? $qty['max'] : 0), $min);
         $qty = $this->faker->numberBetween($min, $max);
     }
     if (0 === $qty) {
         return esc_attr__('Zero is not a good number of comments to fake...', 'fakerpress');
     }
     $meta_module = Meta::instance();
     $comment_content_use_html = Variable::super($request, array('use_html'), FILTER_SANITIZE_STRING, 'off') === 'on';
     $comment_content_html_tags = array_map('trim', explode(',', Variable::super($request, array('html_tags'), FILTER_SANITIZE_STRING)));
     $min_date = Variable::super($request, array('interval_date', 'min'));
     $max_date = Variable::super($request, array('interval_date', 'max'));
     $metas = Variable::super($request, array('meta'), FILTER_UNSAFE_RAW);
     $results = array();
     for ($i = 0; $i < $quantity; $i++) {
         $this->param('comment_date', $min_date, $max_date);
         $this->param('comment_content', $comment_content_use_html, array('elements' => $comment_content_html_tags));
         $this->param('user_id', 0);
         $this->generate();
         $comment_id = $this->save();
         if ($comment_id && is_numeric($comment_id)) {
             foreach ($metas as $meta_index => $meta) {
                 $meta_module->object($comment_id, 'comment')->build($meta['type'], $meta['name'], $meta)->save();
             }
         }
         $results[] = $comment_id;
     }
     $results = array_filter($results, 'absint');
     return $results;
 }
コード例 #3
0
ファイル: post.php プロジェクト: juanfra/fakerpress
 public function parse_request($qty, $request = array())
 {
     if (is_null($qty)) {
         $qty = Variable::super(INPUT_POST, array(Plugin::$slug, 'qty'), FILTER_UNSAFE_RAW);
         $min = absint($qty['min']);
         $max = max(absint(isset($qty['max']) ? $qty['max'] : 0), $min);
         $qty = $this->faker->numberBetween($min, $max);
     }
     if (0 === $qty) {
         return esc_attr__('Zero is not a good number of posts to fake...', 'fakerpress');
     }
     $comment_status = array_map('trim', explode(',', Variable::super($request, array('comment_status'), FILTER_SANITIZE_STRING)));
     $post_author = array_intersect(get_users(array('fields' => 'ID')), array_map('trim', explode(',', Variable::super($request, array('author')))));
     $min_date = Variable::super($request, array('interval_date', 'min'));
     $max_date = Variable::super($request, array('interval_date', 'max'));
     $post_types = array_intersect(get_post_types(array('public' => true)), array_map('trim', explode(',', Variable::super($request, array('post_types'), FILTER_SANITIZE_STRING))));
     $taxonomies = array_intersect(get_taxonomies(array('public' => true)), array_map('trim', explode(',', Variable::super($request, array('taxonomies'), FILTER_SANITIZE_STRING))));
     $post_content_use_html = Variable::super($request, array('use_html'), FILTER_SANITIZE_NUMBER_INT, 0) === 1;
     $post_content_html_tags = array_map('trim', explode(',', Variable::super($request, array('html_tags'), FILTER_SANITIZE_STRING)));
     $post_parents = array_map('trim', explode(',', Variable::super($request, array('post_parent'), FILTER_SANITIZE_STRING)));
     $featured_image_rate = absint(Variable::super($request, array('featured_image_rate'), FILTER_SANITIZE_NUMBER_INT));
     $images_origin = array_map('trim', explode(',', Variable::super($request, array('images_origin'), FILTER_SANITIZE_STRING)));
     $metas = Variable::super($request, array('meta'), FILTER_UNSAFE_RAW);
     $attach_module = Attachment::instance();
     $meta_module = Meta::instance();
     $results = array();
     for ($i = 0; $i < $qty; $i++) {
         $this->param('tax_input', $taxonomies);
         $this->param('post_status', 'publish');
         $this->param('post_date', array($min_date, $max_date));
         $this->param('post_parent', $post_parents);
         $this->param('post_content', $post_content_use_html, array('elements' => $post_content_html_tags));
         $this->param('post_author', $post_author);
         $this->param('post_type', $post_types);
         $this->param('comment_status', $comment_status);
         $post_id = $this->generate()->save();
         if ($post_id && is_numeric($post_id)) {
             foreach ($metas as $meta_index => $meta) {
                 $meta_module->object($post_id)->build($meta['type'], $meta['name'], $meta)->save();
             }
             if ($this->faker->numberBetween(0, 100) <= $featured_image_rate) {
                 $attach_module->param('attachment_url', $this->faker->randomElement($images_origin));
                 $attach_module->param('post_parent', $post_id, 1);
                 $attach_module->generate();
                 $attachment_id = $attach_module->save();
                 $meta_module->object($post_id)->build('raw', '_thumbnail_id', array(100, $attachment_id, 0))->save();
             }
         }
         $results[] = $post_id;
     }
     $results = array_filter((array) $results, 'absint');
     return $results;
 }
コード例 #4
0
ファイル: comment.php プロジェクト: samuelleal/jardimdigital
 public function _action_parse_request($view)
 {
     if ('post' !== Admin::$request_method || empty($_POST)) {
         return false;
     }
     $nonce_slug = Plugin::$slug . '.request.' . Admin::$view->slug . (isset(Admin::$view->action) ? '.' . Admin::$view->action : '');
     if (!check_admin_referer($nonce_slug)) {
         return false;
     }
     // After this point we are safe to say that we have a good POST request
     $meta_module = Meta::instance();
     $qty_min = absint(Filter::super(INPUT_POST, array('fakerpress', 'qty', 'min'), FILTER_SANITIZE_NUMBER_INT));
     $qty_max = absint(Filter::super(INPUT_POST, array('fakerpress', 'qty', 'max'), FILTER_SANITIZE_NUMBER_INT));
     $comment_content_use_html = Filter::super(INPUT_POST, array('fakerpress', 'use_html'), FILTER_SANITIZE_STRING, 'off') === 'on';
     $comment_content_html_tags = array_map('trim', explode(',', Filter::super(INPUT_POST, array('fakerpress', 'html_tags'), FILTER_SANITIZE_STRING)));
     $min_date = Filter::super(INPUT_POST, array('fakerpress', 'interval_date', 'min'));
     $max_date = Filter::super(INPUT_POST, array('fakerpress', 'interval_date', 'max'));
     $metas = Filter::super(INPUT_POST, array('fakerpress', 'meta'), FILTER_UNSAFE_RAW);
     if (0 === $qty_min) {
         return Admin::add_message(sprintf(__('Zero is not a good number of %s to fake...', 'fakerpress'), 'posts'), 'error');
     }
     if (!empty($qty_min) && !empty($qty_max)) {
         $quantity = $this->faker->numberBetween($qty_min, $qty_max);
     }
     if (!empty($qty_min) && empty($qty_max)) {
         $quantity = $qty_min;
     }
     $results = (object) array();
     for ($i = 0; $i < $quantity; $i++) {
         $this->param('comment_date', $min_date, $max_date);
         $this->param('comment_content', $comment_content_use_html, array('elements' => $comment_content_html_tags));
         $this->param('user_id', 0);
         $this->generate();
         $comment_id = $this->save();
         if ($comment_id && is_numeric($comment_id)) {
             foreach ($metas as $meta_index => $meta) {
                 $meta_module->object($comment_id, 'comment')->build($meta['type'], $meta['name'], $meta)->save();
             }
         }
         $results->all[] = $comment_id;
     }
     $results->success = array_filter($results->all, 'absint');
     if (!empty($results->success)) {
         return Admin::add_message(sprintf(__('Faked %d new %s: [ %s ]', 'fakerpress'), count($results->success), _n('comment', 'comments', count($results->success), 'fakerpress'), implode(', ', $results->success)));
     }
 }
コード例 #5
0
ファイル: user.php プロジェクト: andrewevans/lana
 public function parse_request($qty, $request = array())
 {
     if (is_null($qty)) {
         $qty = Variable::super(INPUT_POST, array(Plugin::$slug, 'qty'), FILTER_UNSAFE_RAW);
         $min = absint($qty['min']);
         $max = max(absint(isset($qty['max']) ? $qty['max'] : 0), $min);
         $qty = $this->faker->numberBetween($min, $max);
     }
     if (0 === $qty) {
         return esc_attr__('Zero is not a good number of users to fake...', 'fakerpress');
     }
     $description_use_html = Variable::super($request, array('use_html'), FILTER_SANITIZE_STRING, 'off') === 'on';
     $description_html_tags = array_map('trim', explode(',', Variable::super($request, array('html_tags'), FILTER_SANITIZE_STRING)));
     $roles = array_intersect(array_keys(get_editable_roles()), array_map('trim', explode(',', Variable::super($request, array('roles'), FILTER_SANITIZE_STRING))));
     $metas = Variable::super($request, array('meta'), FILTER_UNSAFE_RAW);
     $results = array();
     for ($i = 0; $i < $qty; $i++) {
         $this->set('role', $roles);
         $this->set('description', $description_use_html, array('elements' => $description_html_tags));
         $this->set('user_login');
         $this->set('user_pass');
         $this->set('user_nicename');
         $this->set('user_url');
         $this->set('user_email');
         $this->set('display_name');
         $this->set('nickname');
         $this->set('first_name');
         $this->set('last_name');
         $this->set('user_registered', 'yesterday', 'now');
         $user_id = $this->generate()->save();
         if ($user_id && is_numeric($user_id)) {
             foreach ($metas as $meta_index => $meta) {
                 Meta::instance()->object($user_id, 'user')->generate($meta['type'], $meta['name'], $meta)->save();
             }
         }
         $results[] = $user_id;
     }
     $results = array_filter($results, 'absint');
     return $results;
 }
コード例 #6
0
ファイル: comment.php プロジェクト: luancuba/fakerpress
 public function parse_request($qty, $request = array())
 {
     if (is_null($qty)) {
         $qty = Utils::instance()->get_qty_from_range(Variable::super(INPUT_POST, array(Plugin::$slug, 'qty'), FILTER_UNSAFE_RAW));
     }
     if (0 === $qty) {
         return esc_attr__('Zero is not a good number of comments to fake...', 'fakerpress');
     }
     $comment_content_use_html = Variable::super($request, array('use_html'), FILTER_SANITIZE_STRING, 'off') === 'on';
     $comment_content_html_tags = array_map('trim', explode(',', Variable::super($request, array('html_tags'), FILTER_SANITIZE_STRING)));
     $min_date = Variable::super($request, array('interval_date', 'min'));
     $max_date = Variable::super($request, array('interval_date', 'max'));
     $metas = Variable::super($request, array('meta'), FILTER_UNSAFE_RAW);
     $results = array();
     for ($i = 0; $i < $qty; $i++) {
         $this->set('comment_date', $min_date, $max_date);
         $this->set('comment_content', $comment_content_use_html, array('elements' => $comment_content_html_tags));
         $this->set('user_id', 0);
         $this->set('comment_author');
         $this->set('comment_parent');
         $this->set('comment_author_IP');
         $this->set('comment_agent');
         $this->set('comment_approved');
         $this->set('comment_post_ID');
         $this->set('comment_author_email');
         $this->set('comment_author_url');
         $comment_id = $this->generate()->save();
         if ($comment_id && is_numeric($comment_id)) {
             foreach ($metas as $meta_index => $meta) {
                 Meta::instance()->object($comment_id, 'comment')->generate($meta['type'], $meta['name'], $meta)->save();
             }
         }
         $results[] = $comment_id;
     }
     $results = array_filter($results, 'absint');
     return $results;
 }
コード例 #7
0
ファイル: post.php プロジェクト: samuelleal/jardimdigital
 public function _action_parse_request($view)
 {
     if ('post' !== Admin::$request_method || empty($_POST)) {
         return false;
     }
     $nonce_slug = Plugin::$slug . '.request.' . Admin::$view->slug . (isset(Admin::$view->action) ? '.' . Admin::$view->action : '');
     if (!check_admin_referer($nonce_slug)) {
         return false;
     }
     // After this point we are safe to say that we have a good POST request
     $qty_min = absint(Filter::super(INPUT_POST, array('fakerpress', 'qty', 'min'), FILTER_SANITIZE_NUMBER_INT));
     $qty_max = absint(Filter::super(INPUT_POST, array('fakerpress', 'qty', 'max'), FILTER_SANITIZE_NUMBER_INT));
     $comment_status = array_map('trim', explode(',', Filter::super(INPUT_POST, array('fakerpress', 'comment_status'), FILTER_SANITIZE_STRING)));
     $post_author = array_intersect(get_users(array('fields' => 'ID')), array_map('trim', explode(',', Filter::super(INPUT_POST, array('fakerpress', 'author')))));
     $min_date = Filter::super(INPUT_POST, array('fakerpress', 'interval_date', 'min'));
     $max_date = Filter::super(INPUT_POST, array('fakerpress', 'interval_date', 'max'));
     $post_types = array_intersect(get_post_types(array('public' => true)), array_map('trim', explode(',', Filter::super(INPUT_POST, array('fakerpress', 'post_types'), FILTER_SANITIZE_STRING))));
     $taxonomies = array_intersect(get_taxonomies(array('public' => true)), array_map('trim', explode(',', Filter::super(INPUT_POST, array('fakerpress', 'taxonomies'), FILTER_SANITIZE_STRING))));
     $post_content_use_html = Filter::super(INPUT_POST, array('fakerpress', 'use_html'), FILTER_SANITIZE_NUMBER_INT, 0) === 1;
     $post_content_html_tags = array_map('trim', explode(',', Filter::super(INPUT_POST, array('fakerpress', 'html_tags'), FILTER_SANITIZE_STRING)));
     $post_parents = array_map('trim', explode(',', Filter::super(INPUT_POST, array('fakerpress', 'post_parent'), FILTER_SANITIZE_STRING)));
     $featured_image_rate = absint(Filter::super(INPUT_POST, array('fakerpress', 'featured_image_rate'), FILTER_SANITIZE_NUMBER_INT));
     $images_origin = array_map('trim', explode(',', Filter::super(INPUT_POST, array('fakerpress', 'images_origin'), FILTER_SANITIZE_STRING)));
     $metas = Filter::super(INPUT_POST, array('fakerpress', 'meta'), FILTER_UNSAFE_RAW);
     $attach_module = Attachment::instance();
     $meta_module = Meta::instance();
     if (0 === $qty_min) {
         return Admin::add_message(sprintf(__('Zero is not a good number of %s to fake...', 'fakerpress'), 'posts'), 'error');
     }
     if (!empty($qty_min) && !empty($qty_max)) {
         $quantity = $this->faker->numberBetween($qty_min, $qty_max);
     }
     if (!empty($qty_min) && empty($qty_max)) {
         $quantity = $qty_min;
     }
     $results = (object) array();
     for ($i = 0; $i < $quantity; $i++) {
         $this->param('tax_input', $taxonomies);
         $this->param('post_status', 'publish');
         $this->param('post_date', array($min_date, $max_date));
         $this->param('post_parent', $post_parents);
         $this->param('post_content', $post_content_use_html, array('elements' => $post_content_html_tags));
         $this->param('post_author', $post_author);
         $this->param('post_type', $post_types);
         $this->param('comment_status', $comment_status);
         $this->generate();
         $post_id = $this->save();
         if ($post_id && is_numeric($post_id)) {
             foreach ($metas as $meta_index => $meta) {
                 $meta_module->object($post_id)->build($meta['type'], $meta['name'], $meta)->save();
             }
             if ($this->faker->numberBetween(0, 100) <= $featured_image_rate) {
                 $attach_module->param('attachment_url', $this->faker->randomElement($images_origin));
                 $attach_module->param('post_parent', $post_id, 1);
                 $attach_module->generate();
                 $attachment_id = $attach_module->save();
                 $meta_module->object($post_id)->build('raw', '_thumbnail_id', array(100, $attachment_id, 0))->save();
             }
         }
         $results->all[] = $post_id;
     }
     $results->success = array_filter($results->all, 'absint');
     if (!empty($results->success)) {
         return Admin::add_message(sprintf(__('Faked %d new %s: [ %s ]', 'fakerpress'), count($results->success), _n('post', 'posts', count($results->success), 'fakerpress'), implode(', ', array_map(function ($id) {
             return '<a href="' . esc_url(get_edit_post_link($id)) . '">' . absint($id) . '</a>';
         }, $results->success))));
     }
 }
コード例 #8
0
ファイル: post.php プロジェクト: arobbins/sblog
 public function parse_request($qty, $request = array())
 {
     if (is_null($qty)) {
         $qty = Variable::super(INPUT_POST, array(Plugin::$slug, 'qty'), FILTER_UNSAFE_RAW);
         $min = absint($qty['min']);
         $max = max(absint(isset($qty['max']) ? $qty['max'] : 0), $min);
         $qty = $this->faker->numberBetween($min, $max);
     }
     if (0 === $qty) {
         return esc_attr__('Zero is not a good number of posts to fake...', 'fakerpress');
     }
     // Fetch Comment Status
     $comment_status = Variable::super($request, array('comment_status'), FILTER_SANITIZE_STRING);
     $comment_status = array_map('trim', explode(',', $comment_status));
     // Fetch Post Author
     $post_author = Variable::super($request, array('author'), FILTER_SANITIZE_STRING);
     $post_author = array_map('trim', explode(',', $post_author));
     $post_author = array_intersect(get_users(array('fields' => 'ID')), $post_author);
     // Fetch the dates
     $date = array(Variable::super($request, array('interval_date', 'min'), FILTER_SANITIZE_STRING), Variable::super($request, array('interval_date', 'max'), FILTER_SANITIZE_STRING));
     // Fetch Post Types
     $post_types = Variable::super($request, array('post_types'), FILTER_SANITIZE_STRING);
     $post_types = array_map('trim', explode(',', $post_types));
     $post_types = array_intersect(get_post_types(array('public' => true)), $post_types);
     // Fetch Post Content
     $post_content_use_html = Variable::super($request, array('use_html'), FILTER_SANITIZE_NUMBER_INT, 0) === 1;
     $post_content_html_tags = array_map('trim', explode(',', Variable::super($request, array('html_tags'), FILTER_SANITIZE_STRING)));
     // Fetch and clean Post Parents
     $post_parents = Variable::super($request, array('post_parent'), FILTER_SANITIZE_STRING);
     $post_parents = array_map('trim', explode(',', $post_parents));
     $images_origin = array_map('trim', explode(',', Variable::super($request, array('images_origin'), FILTER_SANITIZE_STRING)));
     // Fetch Taxonomies
     $taxonomies_configuration = Variable::super($request, array('taxonomy'), FILTER_UNSAFE_RAW);
     // Fetch Metas It will be parsed later!
     $metas = Variable::super($request, array('meta'), FILTER_UNSAFE_RAW);
     $results = array();
     for ($i = 0; $i < $qty; $i++) {
         $this->set('post_title');
         $this->set('post_status', 'publish');
         $this->set('post_date', $date);
         $this->set('post_parent', $post_parents);
         $this->set('post_content', $post_content_use_html, array('elements' => $post_content_html_tags, 'sources' => $images_origin));
         $this->set('post_author', $post_author);
         $this->set('post_type', $post_types);
         $this->set('comment_status', $comment_status);
         $this->set('ping_status');
         $this->set('tax_input', $taxonomies_configuration);
         $generated = $this->generate();
         $post_id = $generated->save();
         if ($post_id && is_numeric($post_id)) {
             foreach ($metas as $meta_index => $meta) {
                 Meta::instance()->object($post_id)->generate($meta['type'], $meta['name'], $meta)->save();
             }
         }
         $results[] = $post_id;
     }
     $results = array_filter((array) $results, 'absint');
     return $results;
 }