Exemplo n.º 1
2
 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))));
     }
 }
Exemplo n.º 2
1
 public function _action_setup_admin_page()
 {
     // Prevent any modules with page to be added to menu
     if (!$this->page) {
         return;
     }
     Admin::add_menu($this->page->view, $this->page->title, $this->page->menu, 'manage_options', 10);
 }
Exemplo n.º 3
1
 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)));
     }
 }
Exemplo n.º 4
0
 public function _action_setup_admin_page()
 {
     if (!$this->page) {
         return;
     }
     \FakerPress\Admin::add_menu($this->page->view, $this->page->title, $this->page->menu, 'manage_options', 10);
 }
Exemplo n.º 5
0
 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));
     $taxonomies = array_intersect(get_taxonomies(array('public' => true)), array_map('trim', explode(',', Filter::super(INPUT_POST, array('fakerpress', 'taxonomies'), FILTER_SANITIZE_STRING))));
     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('taxonomy', $taxonomies);
         $this->generate();
         $results->all[] = $this->save();
     }
     $results->success = array_filter($results->all, 'absint');
     if (!empty($results->success)) {
         return Admin::add_message(sprintf(__('Faked %d new %s: [ %s ]', 'fakerpress'), count($results->all), _n('term', 'terms', count($results->all), 'fakerpress'), implode(', ', $results->all)));
     }
 }
Exemplo n.º 6
0
 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
     $results = $this->parse_request(null, Variable::super(INPUT_POST, array(Plugin::$slug), FILTER_UNSAFE_RAW));
     if (!empty($results)) {
         return Admin::add_message(sprintf(__('Faked %d new %s: [ %s ]', 'fakerpress'), count($results), _n('comment', 'comments', count($results), 'fakerpress'), implode(', ', array_map(array($this, 'format_link'), $results))));
     }
 }