예제 #1
0
 public static function module_generate($request = null)
 {
     $response = (object) array('status' => false, 'message' => __('Your request has failed', 'fakerpress'));
     if (!Admin::$is_ajax && is_null($request) || !is_user_logged_in()) {
         return Admin::$is_ajax ? exit(json_encode($response)) : $response;
     }
     $view = Variable::super(INPUT_POST, array(Plugin::$slug, 'view'), FILTER_SANITIZE_STRING);
     $nonce_slug = Plugin::$slug . '.request.' . $view;
     if (!check_admin_referer($nonce_slug)) {
         $response->message = __('Security fail, refresh the page and try again!', 'fakerpress');
         return Admin::$is_ajax ? exit(json_encode($response)) : $response;
     }
     // Here we have a Secure Call
     $module_class_name = '\\FakerPress\\Module\\' . rtrim(ucfirst($view), 's');
     $module = call_user_func_array(array($module_class_name, 'instance'), array());
     $response->allowed = $module->get_amount_allowed();
     $response->offset = absint(Variable::super(INPUT_POST, array('offset'), FILTER_UNSAFE_RAW));
     $qty = $response->total = absint(Variable::super(INPUT_POST, array('total'), FILTER_UNSAFE_RAW));
     if (!$response->total) {
         $qty = Variable::super(INPUT_POST, array(Plugin::$slug, 'qty'), FILTER_UNSAFE_RAW);
         if (is_array($qty)) {
             $min = absint($qty['min']);
             $max = max(absint(isset($qty['max']) ? $qty['max'] : 0), $min);
             $qty = $module->faker->numberBetween($min, $max);
         }
         $response->total = $qty;
     }
     if ($qty > $response->allowed) {
         $response->is_capped = true;
         $qty = $response->allowed;
         if ($response->total < $response->offset + $response->allowed) {
             $qty += $response->total - ($response->offset + $response->allowed);
             $response->is_capped = false;
         }
     } else {
         $response->is_capped = false;
     }
     $results = $module->parse_request($qty, Variable::super(INPUT_POST, array(Plugin::$slug), FILTER_UNSAFE_RAW));
     $response->offset += $qty;
     if (is_string($results)) {
         $response->message = $results;
     } else {
         $response->status = true;
         $response->message = implode(', ', array_map(array($module, 'format_link'), $results));
         $response->results = $results;
     }
     return Admin::$is_ajax ? exit(json_encode($response)) : $response;
 }
예제 #2
0
파일: base.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);
     }
     $taxonomies = array_intersect(get_taxonomies(array('public' => true)), array_map('trim', explode(',', Variable::super($request, array('taxonomies'), FILTER_SANITIZE_STRING))));
     if (0 === $qty) {
         return sprintf(__('Zero is not a good number of %s to fake...', 'fakerpress'), 'posts');
     }
     for ($i = 0; $i < $qty; $i++) {
         $this->param('taxonomy', $taxonomies);
         $this->generate();
         $results[] = $this->save();
     }
     $results = array_filter((array) $results, 'absint');
     return $results;
 }
예제 #3
0
 public function _action_setup_settings_page($view)
 {
     if ('post' !== self::$request_method || empty($_POST)) {
         return false;
     }
     $nonce_slug = Plugin::$slug . '.request.' . self::$view->slug . (isset(self::$view->action) ? '.' . self::$view->action : '');
     if (!check_admin_referer($nonce_slug)) {
         return false;
     }
     $save_500px = is_string(Variable::super(INPUT_POST, array('fakerpress', 'actions', 'save_500px'), FILTER_UNSAFE_RAW));
     if ($save_500px) {
         $opts = array('key' => Variable::super(INPUT_POST, array('fakerpress', '500px-key'), FILTER_SANITIZE_STRING));
         Plugin::update(array('500px'), $opts);
         return self::add_message(__('Updated 500px Customer Application settings', 'fakerpress'), 'success');
     }
     // After this point we are safe to say that we have a good POST request
     $erase_intention = is_string(Variable::super(INPUT_POST, array('fakerpress', 'actions', 'delete'), FILTER_UNSAFE_RAW));
     $erase_check = in_array(strtolower(Variable::super(INPUT_POST, array('fakerpress', 'erase_phrase'), FILTER_SANITIZE_STRING)), array('let it go', 'let it go!'));
     if (!$erase_intention) {
         return false;
     }
     if (!$erase_check) {
         return self::add_message(__('The verification to erase the data has failed, you have to let it go...', 'fakerpress'), 'error');
     }
     $refs = (object) array('post' => array(), 'term' => get_option('fakerpress.module_flag.term', array()), 'comment' => array(), 'user' => array());
     $query_posts = new \WP_Query(array('post_type' => 'any', 'post_status' => 'any', 'nopaging' => true, 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => array(array('key' => apply_filters('fakerpress.modules_flag', 'fakerpress_flag'), 'value' => true, 'type' => 'BINARY'))));
     $refs->post = array_map('absint', $query_posts->posts);
     $query_comments = new \WP_Comment_Query();
     $query_comments = $query_comments->query(array('meta_query' => array(array('key' => apply_filters('fakerpress.modules_flag', 'fakerpress_flag'), 'value' => true, 'type' => 'BINARY'))));
     foreach ($query_comments as $comment) {
         $refs->comment[] = absint($comment->comment_ID);
     }
     $query_users = new \WP_User_Query(array('fields' => 'ID', 'meta_query' => array(array('key' => apply_filters('fakerpress.modules_flag', 'fakerpress_flag'), 'value' => true, 'type' => 'BINARY'))));
     $refs->user = array_map('absint', $query_users->results);
     foreach ($refs as $module => $ref) {
         switch ($module) {
             case 'post':
                 foreach ($ref as $post_id) {
                     wp_delete_post($post_id, true);
                 }
                 break;
             case 'comment':
                 foreach ($ref as $comment_id) {
                     wp_delete_comment($comment_id, true);
                 }
                 break;
             case 'term':
                 foreach ($ref as $taxonomy => $terms) {
                     foreach ($terms as $term) {
                         wp_delete_term($term, $taxonomy);
                     }
                 }
                 delete_option('fakerpress.module_flag.term');
                 break;
             case 'user':
                 foreach ($ref as $user_id) {
                     wp_delete_user($user_id);
                 }
                 break;
         }
     }
     return self::add_message(__('All data is gone for good.', 'fakerpress'), 'success');
 }
예제 #4
0
 public function _action_setup_settings_page($view)
 {
     if ('post' !== self::$request_method || empty($_POST)) {
         return false;
     }
     $nonce_slug = Plugin::$slug . '.request.' . self::$view->slug . (isset(self::$view->action) ? '.' . self::$view->action : '');
     if (!check_admin_referer($nonce_slug)) {
         return false;
     }
     $save_500px = is_string(Variable::super(INPUT_POST, array('fakerpress', 'actions', 'save_500px'), FILTER_UNSAFE_RAW));
     if ($save_500px) {
         $opts = array('key' => Variable::super(INPUT_POST, array('fakerpress', '500px-key'), FILTER_SANITIZE_STRING));
         Plugin::update(array('500px'), $opts);
         return self::add_message(__('Updated 500px Customer Application settings', 'fakerpress'), 'success');
     }
     // After this point we are safe to say that we have a good POST request
     $erase_intention = is_string(Variable::super(INPUT_POST, array('fakerpress', 'actions', 'delete'), FILTER_UNSAFE_RAW));
     $erase_check = in_array(strtolower(Variable::super(INPUT_POST, array('fakerpress', 'erase_phrase'), FILTER_SANITIZE_STRING)), array('let it go', 'let it go!'));
     if (!$erase_intention) {
         return false;
     }
     if (!$erase_check) {
         return self::add_message(__('The verification to erase the data has failed, you have to let it go...', 'fakerpress'), 'error');
     }
     $modules = array('post', 'term', 'comment', 'user');
     foreach ($modules as $module) {
         $class_name = '\\FakerPress\\Module\\' . ucfirst($module);
         if (!class_exists($class_name)) {
             continue;
         }
         $items = call_user_func_array($class_name . '::fetch', array());
         $deleted = call_user_func_array($class_name . '::delete', array($items));
     }
     return self::add_message(__('All data is gone for good.', 'fakerpress'), 'success');
 }