public static function process() { if (!theme_cache::current_user_can('manage_options')) { die(___('You have not permission.')); } theme_options::set_options(self::$iden, $_SERVER['REQUEST_TIME']); header('location: ' . theme_options::get_url() . '&' . self::$iden); die; }
public static function process_backend() { theme_features::check_referer(); theme_features::check_nonce(); if (!theme_cache::current_user_can('manage_options')) { return false; } $type = isset($_GET['type']) && is_string($_GET['type']) ? $_GET['type'] : false; switch ($type) { case 'recalculate': global $post; $query = new WP_Query(['nopaging' => true, 'meta_key' => self::$post_meta_key['count_points']]); if ($query->have_posts()) { foreach ($query->posts as $post) { setup_postdata($post); /** get points from db */ $old_points = get_post_meta($post->ID, self::$post_meta_key['count_points'], true); $new_points = self::get_post_points_count_from_users($post->ID); /** * skip if equal */ if ($old_points == $new_points) { continue; } /** * update new points */ update_post_meta($post->ID, self::$post_meta_key['count_points'], $new_points); } } header('location: ' . theme_options::get_url() . '&' . __CLASS__); die; break; default: die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_type', 'msg' => ___('Sorry, type param is invaild.')])); } }
/** * process */ public static function process() { if (!theme_cache::current_user_can('manage_options')) { return false; } @ini_set('max_input_nesting_level', '10000'); @ini_set('max_execution_time', 0); remove_dir(theme_features::get_stylesheet_directory() . theme_features::$basedir_js_min); theme_features::minify_force(theme_features::get_stylesheet_directory() . theme_features::$basedir_js_src); remove_dir(theme_features::get_stylesheet_directory() . theme_features::$basedir_css_min); theme_features::minify_force(theme_features::get_stylesheet_directory() . theme_features::$basedir_css_src); theme_features::minify_force(theme_features::get_stylesheet_directory() . theme_features::$basedir_addons); theme_file_timestamp::set_timestamp(); wp_redirect(add_query_arg(__CLASS__, 1, theme_options::get_url())); die; }
public static function process() { theme_features::check_referer(); $type = isset($_REQUEST['type']) && is_string($_REQUEST['type']) ? $_REQUEST['type'] : false; $current_user_id = theme_cache::get_current_user_id(); switch ($type) { /** * backend create db table */ case 'create-db': if (!theme_cache::current_user_can('manage_options')) { die(___('Sorry, your permission is not enough to create database table.')); } //die(theme_features::json_format([ // 'status' => 'error', // 'code' => 'invaild_permission', // 'msg' => ___('Sorry, your permission is not enough to create database table.'), //])); if (self::has_table()) { die(___('Sorry, the database table already exists.')); } //die(theme_features::json_format([ // 'status' => 'error', // 'code' => 'exists_table', // 'msg' => ___('Sorry, the database table already exists.'), //])); self::create_db_table(); theme_options::set_options(__CLASS__, ['db-version' => self::$db_version]); header('location: ' . theme_options::get_url() . '&' . __CLASS__); die; //die(theme_features::json_format([ // 'status' => 'success', // 'msg' => ___('Database table has been created.'), //])); /** * get-userdata */ //die(theme_features::json_format([ // 'status' => 'success', // 'msg' => ___('Database table has been created.'), //])); /** * get-userdata */ case 'get-userdata': /** nonce */ theme_features::check_nonce(); /** * uid */ $uid = isset($_REQUEST['uid']) && is_numeric($_REQUEST['uid']) ? $_REQUEST['uid'] : false; /** * get userdata */ $user = self::check_uid($uid); /** add user to lists */ self::add_list($current_user_id, $user->ID); die(theme_features::json_format(['status' => 'success', 'name' => esc_html($user->display_name), 'avatar' => get_avatar_url($user->ID), 'msg' => ___('User data loaded, you can send P.M. now.'), 'url' => theme_cache::get_author_posts_url($user->ID)])); /** * remove user lists */ /** * remove user lists */ case 'remove-dialog': $receiver_uid = isset($_REQUEST['uid']) && is_numeric($_REQUEST['uid']) ? (int) $_REQUEST['uid'] : false; $receiver = self::check_uid($receiver_uid); $status = self::remove_list($current_user_id, $receiver->ID); if ($status) { die(theme_features::json_format(['status' => 'success', 'code' => 'removed'])); } die(theme_features::json_format(['status' => 'error', 'code' => 'remove_fail'])); /** * send */ /** * send */ case 'send': /** nonce */ theme_features::check_nonce(); $receiver_uid = isset($_REQUEST['uid']) && is_numeric($_REQUEST['uid']) ? $_REQUEST['uid'] : false; $receiver = self::check_uid($receiver_uid); /** check content */ $content = isset($_REQUEST['content']) && is_string($_REQUEST['content']) ? trim($_REQUEST['content']) : false; if ($content != '') { $content = fliter_script(strip_tags($content, '<a><b><strong><em><i><del>')); } if (trim($content) == '') { die(theme_features::json_format(['status' => 'error', 'code' => 'empty_content', 'msg' => ___('Sorry, message content is null, please try again.')])); } /** pass */ $pm_id = self::insert_pm(['pm_author' => $current_user_id, 'pm_receiver' => $receiver->ID, 'pm_content' => $content]); if (!$pm_id) { die(theme_features::json_format(['status' => 'error', 'code' => 'can_not_create_pm', 'msg' => ___('Sorry, system can not create the private message, please try again later.')])); } /** get pm */ $pm = self::get_pm($pm_id); /** add list for author */ self::add_list($current_user_id, $pm->pm_receiver); /** add list for receiver */ self::add_list($pm->pm_receiver, $current_user_id); die(theme_features::json_format(['status' => 'success', 'pm' => ['pm_receiver' => self::get_niceid($pm->pm_receiver), 'pm_author' => self::get_niceid($pm->pm_author), 'pm_date' => current_time('Y/m/d H:i:s'), 'pm_content' => $pm->pm_content, 'url' => theme_cache::get_author_posts_url($pm->pm_receiver)], 'msg' => ___('Message sent.')])); /** * latest pm id */ /** * latest pm id */ case 'comet': /** nonce */ theme_features::check_nonce(); $receiver_id = $current_user_id; $client_timestamp = isset($_REQUEST['timestamp']) && is_numeric($_REQUEST['timestamp']) ? $_REQUEST['timestamp'] : false; /** if not client timestamp, return error */ if (!$client_timestamp) { die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_timestamp', 'msg' => ___('Sorry, your session is timeout, please refresh page.')])); } /** set timeout */ set_time_limit(60); /** check new pm for receiver */ for ($i = 0; $i < self::$comet_timeout; ++$i) { /** have new pm */ $timestamp = self::get_timestamp($receiver_id); if ($timestamp <= $client_timestamp) { sleep(1); continue; } /** have new pm, output latest pm */ $latest_pm = self::get_pm(self::get_latest_pm_id($receiver_id)); /** clear unreads for me */ self::clear_unreads($current_user_id); die(theme_features::json_format(['status' => 'success', 'pm' => ['pm_receiver' => self::get_niceid($latest_pm->pm_receiver), 'pm_author' => self::get_niceid($latest_pm->pm_author), 'pm_author_name' => theme_cache::get_the_author_meta('display_name', $latest_pm->pm_author), 'pm_author_avatar' => get_avatar_url($latest_pm->pm_author), 'pm_date' => current_time('Y/m/d H:i:s'), 'pm_content' => $latest_pm->pm_content, 'url' => theme_cache::get_author_posts_url($pm->pm_author)], 'timestamp' => $timestamp])); } /** timeout msg */ die(theme_features::json_format(['status' => 'error', 'code' => 'timeout', 'msg' => ___('Timeout')])); default: die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_type', 'msg' => ___('Sorry, type param is invaild.')])); } }