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 init() { if (!theme_cache::current_user_can('manage_options')) { return; } self::$checker_url = ___('http://update.inn-studio.com') . '/?action=get_update&slug=' . theme_functions::$iden; add_filter('site_transient_update_themes', __CLASS__ . '::check_for_update'); add_filter('upgrader_source_selection', __CLASS__ . '::filter_upgrader_source_selection', 10, 3); add_filter('upgrader_pre_install', __CLASS__ . '::filter_upgrader_pre_install', 10, 2); }
public static function page_create() { if (!theme_cache::current_user_can('manage_options')) { return false; } $page_slugs = array(self::$page_slug => array('post_content' => '[no-content]', 'post_name' => 'account', 'post_title' => ___('Account'), 'page_template' => 'page-' . self::$page_slug . '.php')); $defaults = array('post_content' => '[post_content]', 'post_name' => null, 'post_title' => null, 'post_status' => 'publish', 'post_type' => 'page', 'comment_status' => 'closed'); foreach ($page_slugs as $k => $v) { theme_cache::get_page_by_path($k) || wp_insert_post(array_merge($defaults, $v)); } }
public static function init() { add_filter('wp_handle_upload_prefilter', __CLASS__ . '::compress_jpeg_quality', 1, 99); add_filter('theme_options_save', __CLASS__ . '::options_save'); add_filter('theme_options_default', __CLASS__ . '::options_default'); add_action('base_settings', __CLASS__ . '::display_backend'); if (theme_cache::current_user_can('manage_options')) { return; } add_filter('wp_handle_upload_prefilter', __CLASS__ . '::filter_wp_handle_upload_prefilter'); }
public static function delete_post($post_id) { if (!theme_cache::current_user_can('delete_posts')) { return; } $opt = self::get_options(); $recomm_posts = isset($opt['ids']) ? (array) $opt['ids'] : []; $k = array_search($post_id, $recomm_posts); if ($k !== false) { unset($opt['ids'][$k]); arsort($opt['ids']); $opt['ids'] = array_slice($opt['ids'], 0, 50); theme_options::set_options(__CLASS__, $opt); self::clear_cache(); } }
/** * 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_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.')])); } }
function ajax_process_image() { @error_reporting(0); // Don't break the JSON result header('Content-type: application/json'); $id = (int) $_REQUEST['id']; $image = theme_cache::get_post($id); if (!$image || 'attachment' != $image->post_type || 'image/' != substr($image->post_mime_type, 0, 6)) { die(json_encode(array('error' => sprintf(___('Failed resize: %s is an invalid image ID.'), esc_html($_REQUEST['id']))))); } if (!theme_cache::current_user_can($this->capability)) { $this->die_json_error_msg($image->ID, ___("Your user account doesn't have permission to resize images")); } $fullsizepath = get_attached_file($image->ID); if (false === $fullsizepath || !file_exists($fullsizepath)) { $this->die_json_error_msg($image->ID, sprintf(___('The originally uploaded image file cannot be found at %s'), '<code>' . esc_html($fullsizepath) . '</code>')); } @set_time_limit(900); // 5 minutes per image should be PLENTY $metadata = wp_generate_attachment_metadata($image->ID, $fullsizepath); if (is_wp_error($metadata)) { $this->die_json_error_msg($image->ID, $metadata->get_error_message()); } if (empty($metadata)) { $this->die_json_error_msg($image->ID, ___('Unknown failure reason.')); } // If this fails, then it just means that nothing was changed (old value == new value) wp_update_attachment_metadata($image->ID, $metadata); die(json_encode(array('success' => sprintf(___('"%1$s" (ID %2$s) was successfully resized in %3$s seconds.'), theme_cache::get_the_title($image->ID), $image->ID, timer_stop())))); }
/** * Menu Fallback * ============= * If this function is assigned to the wp_nav_menu's fallback_cb variable * and a manu has not been assigned to the theme location in the WordPress * menu manager the function with display nothing to a non-logged in user, * and will add a link to the WordPress menu manager if logged in as an admin. * * @param array $args passed from the wp_nav_menu function. */ public static function fallback($args) { if (!theme_cache::current_user_can('manage_options')) { return ''; } extract($args); $fb_output = null; if ($container) { $fb_output = '<' . $container; if ($container_id) { $fb_output .= ' id="' . $container_id . '"'; } if ($container_class) { $fb_output .= ' class="' . $container_class . '"'; } $fb_output .= '>'; } $fb_output .= '<ul'; if ($menu_id) { $fb_output .= ' id="' . $menu_id . '"'; } if ($menu_class) { $fb_output .= ' class="' . $menu_class . '"'; } $fb_output .= '>'; $fb_output .= '<li><a href="' . admin_url('nav-menus.php') . '">Add a menu</a></li>'; $fb_output .= '</ul>'; if ($container) { $fb_output .= '</' . $container . '>'; } echo $fb_output; }
/** * Redirect */ public static function redirect() { $url = self::has_url(); if (!theme_cache::current_user_can('manage_options') && $url) { header("Location: {$url}"); die; } }
public static function process() { //theme_features::check_nonce(); theme_features::check_referer(); $output = []; $type = isset($_REQUEST['type']) && is_string($_REQUEST['type']) ? $_REQUEST['type'] : null; switch ($type) { /** * test */ case 'test': if (!theme_cache::current_user_can('manage_options')) { die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_permission', 'msg' => ___('Sorry, your permission is invaild.')])); } $test = isset($_POST['test']) && filter_var($_POST['test'], FILTER_VALIDATE_EMAIL) ? $_POST['test'] : false; if (!$test) { die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_test_mail', 'msg' => ___('Sorry, test mail is invaild.')])); } self::$debug = true; ob_start(); ?> <pre><?php echo wp_mail($test, ___('This is a test email.'), ___('This is a test email generated by your blog.')); ?> </pre> <?php $mail = ob_get_contents(); ob_end_clean(); die(theme_features::json_format(['status' => 'info', 'code' => 'unknow', 'msg' => $mail])); default: die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_param', 'msg' => ___('Sorry, param is invaild.')])); } }
/** * check_timestamp * * @version 1.0.1 */ public static function check_timestamp() { if (theme_cache::current_user_can('manage_options') && theme_file_timestamp::get_timestamp() < self::get_theme_mtime()) { /** clear opcache */ if (function_exists('opcache_reset')) { opcache_reset(); } /** update timestamp */ theme_file_timestamp::set_timestamp(); } }
public static function process() { theme_features::check_referer(); $output = []; $type = isset($_GET['type']) ? $_GET['type'] : null; if (!theme_cache::current_user_can('manage_options')) { die; } timer_start(); global $wpdb; switch ($type) { /** * revision */ case 'redundant-posts': $sql = $wpdb->prepare("\n\t\t\t\t\tDELETE posts,term,postmeta \n\t\t\t\t\tFROM `{$wpdb->posts}`posts \n\t\t\t\t\tLEFT JOIN `{$wpdb->term_relationships}` term\n\t\t\t\t\tON (posts.ID = term.object_id)\n\t\t\t\t\tLEFT JOIN `{$wpdb->postmeta}` postmeta \n\t\t\t\t\tON (posts.ID = postmeta.post_id)\n\t\t\t\t\tWHERE posts.post_type = '%s'\n\t\t\t\t\tOR posts.post_status = '%s'\n\t\t\t\t\tOR posts.post_status = '%s'\n\t\t\t\t\tOR posts.post_status = '%s'\n\t\t\t\t\t", 'revision', 'draft', 'auto-draft', 'trash'); break; /** * edit_lock */ /** * edit_lock */ case 'orphan-postmeta': $sql = $wpdb->prepare("\n\t\t\t\t\tDELETE FROM `{$wpdb->postmeta}`\n\t\t\t\t\tWHERE `meta_key` = '%s'\n\t\t\t\t\tOR `post_id`\n\t\t\t\t\tNOT IN (SELECT `ID` FROM `{$wpdb->posts}`)\n\t\t\t\t\t", '_edit_lock'); break; /** * moderated */ /** * moderated */ case 'redundant-comments': $sql = $wpdb->prepare("\n\t\t\t\t\tDELETE FROM `{$wpdb->comments}`\n\t\t\t\t\tWHERE `comment_approved` = '%s'\n\t\t\t\t\tOR `comment_approved` = '%s'\n\t\t\t\t\tOR `comment_approved` = '%s'\n\t\t\t\t\t", '0', 'spam', 'trash'); break; /** * commentmeta */ /** * commentmeta */ case 'orphan-commentmeta': $sql = "\n\t\t\t\tDELETE FROM `{$wpdb->commentmeta}`\n\t\t\t\tWHERE `comment_ID` \n\t\t\t\tNOT IN (SELECT `comment_ID` FROM `{$wpdb->comments}`)\n\t\t\t\t"; break; /** * relationships */ /** * relationships */ case 'orphan-relationships': $sql = $wpdb->prepare("\n\t\t\t\t\tDELETE FROM `{$wpdb->term_relationships}`\n\t\t\t\t\tWHERE `term_taxonomy_id` = %d \n\t\t\t\t\tAND `object_id` \n\t\t\t\t\tNOT IN (SELECT `id` FROM `{$wpdb->posts}`)\n\t\t\t\t\t", 1); break; /** * optimizate */ /** * optimizate */ case 'optimizate': $sql = 'SHOW TABLE STATUS FROM `' . DB_NAME . '`'; $results = $wpdb->get_results($sql); foreach ($results as $v) { $sql = 'OPTIMIZE TABLE ' . $v->Name; $wpdb->get_results($sql); } break; default: $output['status'] = 'error'; $output['msg'] = ___('No param'); die(theme_features::json_format($output)); } if ($type !== 'optimizate') { $wpdb->query($sql); } /** flush cache */ wp_cache_flush(); $output['status'] = 'success'; $output['msg'] = sprintf(___('Database updated in %s s.'), timer_stop()); die(theme_features::json_format($output)); }
/** * Process * * * @return * @version 1.0.0 * */ public static function process() { theme_features::check_referer(); if (!theme_cache::current_user_can('manage_options')) { die; } $output = []; $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; switch ($type) { case 'import': $file = isset($_FILES['file']) ? $_FILES['file'] : false; if (!$file || $file['error'] != 0) { die(theme_features::json_format(['status' => 'error', 'msg' => ___('Invalid file.')])); } $contents = json_decode(base64_decode(file_get_contents($file['tmp_name'])), true); if (is_array($contents) && !empty($contents)) { set_theme_mod('theme_options', $contents); die(theme_features::json_format(['status' => 'success', 'msg' => ___('Settings has been restored, refreshing page, please wait...')])); /** * invalid contents */ } else { die(theme_features::json_format(['status' => 'error', 'msg' => ___('Invalid file content.')])); } break; /** * export */ /** * export */ case 'export': $contents = base64_encode(json_encode(theme_options::get_options())); /** * write content to a tmp file */ $tmp = tmpfile(); $filepath = stream_get_meta_data($tmp)['uri']; file_put_contents($filepath, $contents); /** * output file download */ header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($filepath)); $download_fn = ___('Backup'); $download_fn .= '-' . theme_cache::get_bloginfo('name'); $download_fn .= '-' . theme_functions::$iden; $download_fn .= '-' . date('Ymd-His') . '.bk'; header('Content-Disposition: attachment; filename=" ' . $download_fn . '"'); readfile($filepath); die; } die(theme_features::json_format($output)); }
/** * auto_minify * * @return * @version 2.0.0 */ public static function auto_minify() { /** * js and css files version */ if (theme_cache::current_user_can('manage_options') && theme_file_timestamp::get_timestamp() < self::get_theme_mtime()) { ini_set('max_input_nesting_level', 10000); ini_set('max_execution_time', 0); self::minify_force(self::get_stylesheet_directory() . self::$basedir_js_src); self::minify_force(self::get_stylesheet_directory() . self::$basedir_css_src); self::minify_force(self::get_stylesheet_directory() . self::$basedir_addons); theme_file_timestamp::set_timestamp(); } }
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.')])); } }
public static function process() { $output = []; theme_features::check_referer(); theme_features::check_nonce(); $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; switch ($type) { /** * case upload */ case 'add-cover': /** * if not image */ $filename = isset($_FILES['img']['name']) ? $_FILES['img']['name'] : null; $file_ext = $filename ? array_slice(explode('.', $filename), -1, 1)[0] : null; $file_ext = strtolower($file_ext); if (!in_array($file_ext, self::$file_exts)) { $output['status'] = 'error'; $output['code'] = 'invaild_file_type'; $output['msg'] = ___('Invaild file type.'); die(theme_features::json_format($output)); } /** rename file name */ $_FILES['img']['name'] = theme_cache::get_current_user_id() . '-' . current_time('YmdHis') . '-' . rand(100, 999) . '.' . $file_ext; /** * pass */ require_once ABSPATH . 'wp-admin/includes/image.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; $attach_id = media_handle_upload('img', 0); if (is_wp_error($attach_id)) { $output['status'] = 'error'; $output['code'] = $attach_id->get_error_code(); $output['msg'] = $attach_id->get_error_message(); die(theme_features::json_format($output)); } else { $output['status'] = 'success'; $output['thumbnail'] = ['url' => esc_url(self::wp_get_attachment_image_src($attach_id, 'thumbnail')[0])]; $output['attach-id'] = $attach_id; $output['msg'] = ___('Upload success.'); die(theme_features::json_format($output)); } break; /** * post */ /** * post */ case 'post': $clt = isset($_POST['clt']) && is_array($_POST['clt']) ? $_POST['clt'] : null; if (is_null_array($clt)) { $output['status'] = 'error'; $output['code'] = 'invaild_ctb_param'; $output['msg'] = ___('Invaild collection param.'); die(theme_features::json_format($output)); } /** * get posts */ $posts = isset($clt['posts']) && is_array($clt['posts']) ? $clt['posts'] : null; if (empty($posts)) { $output['status'] = 'error'; $output['code'] = 'invaild_posts'; $output['msg'] = ___('Sorry, posts can not be empty.'); die(theme_features::json_format($output)); } /** * post title */ $post_title = isset($clt['post-title']) && is_string($clt['post-title']) ? esc_html(trim($clt['post-title'])) : null; if (empty($post_title)) { $output['status'] = 'error'; $output['code'] = 'invaild_post_title'; $output['msg'] = ___('Please write the post title.'); die(theme_features::json_format($output)); } /** * check thumbnail cover */ $thumbnail_id = isset($clt['thumbnail-id']) && is_numeric($clt['thumbnail-id']) ? (int) $clt['thumbnail-id'] : null; if (empty($thumbnail_id)) { $output['status'] = 'error'; $output['code'] = 'invaild_thumbnail_id'; $output['msg'] = ___('Please set an image as post thumbnail'); die(theme_features::json_format($output)); } /** * post content */ $post_content = isset($clt['post-content']) && is_string($clt['post-content']) ? strip_tags(trim($clt['post-content']), '<del><a><b><strong><em><i>') : null; if (empty($post_content)) { $output['status'] = 'error'; $output['code'] = 'invaild_post_content'; $output['msg'] = ___('Please explain why you recommend this collection.'); die(theme_features::json_format($output)); } /** * get posts template */ $post_content = '<p>' . $post_content . '</p>' . self::get_preview($posts); /** * tags */ $tags = isset($clt['tags']) && is_array($clt['tags']) ? $clt['tags'] : []; if (!empty($tags)) { $tags = array_map(function ($tag) { if (!is_string($tag)) { return null; } return $tag; }, $tags); } /** * post status */ if (theme_cache::current_user_can('moderate_comments')) { $post_status = 'publish'; } else { $post_status = 'pending'; } /** * insert */ $post_id = wp_insert_post(array('post_title' => $post_title, 'post_content' => fliter_script($post_content), 'post_status' => $post_status, 'post_author' => theme_cache::get_current_user_id(), 'post_category' => (array) self::get_options('cats'), 'tags_input' => $tags), true); if (is_wp_error($post_id)) { $output['status'] = 'error'; $output['code'] = $post_id->get_error_code(); $output['msg'] = $post_id->get_error_message(); } else { /** set post thumbnail */ set_post_thumbnail($post_id, $thumbnail_id); /** * pending status */ if ($post_status === 'pending') { $output['status'] = 'success'; $output['msg'] = sprintf(___('Your collection submitted successful, it will be published after approve in a while. Thank you very much! How about %s again?'), '<a href="' . self::get_tabs('collection')['url'] . '">' . ___('write a new collection') . '</a>'); die(theme_features::json_format($output)); } else { $output['status'] = 'success'; $output['msg'] = sprintf(___('Congratulation! Your post has been published. You can %s or %s.'), '<a href="' . theme_cache::get_permalink($post_id) . '" title="' . theme_cache::get_the_title($post_id) . '">' . ___('View it now') . '</a>', '<a href="' . self::get_tabs('collection')['url'] . '">' . ___('countinue to write a new collection') . '</a>'); /** * add point */ if (class_exists('theme_custom_point')) { $post_publish_point = theme_custom_point::get_point_value('post-publish'); $output['point'] = array('value' => $post_publish_point, 'detail' => ___('Post published')); } die(theme_features::json_format($output)); } } break; /** * get post */ /** * get post */ case 'get-post': $post_id = isset($_REQUEST['post-id']) && is_numeric($_REQUEST['post-id']) ? $_REQUEST['post-id'] : null; if (!$post_id) { $output['status'] = 'error'; $output['code'] = 'invaild_post_id'; $output['msg'] = ___('Sorry, the post id is invaild.'); die(theme_features::json_format($output)); } global $post; $post = theme_cache::get_post($post_id); if (!$post || $post->post_type !== 'post') { $output['status'] = 'error'; $output['code'] = 'post_not_exist'; $output['msg'] = ___('Sorry, the post do not exist, please type another post ID.'); //echo(json_encode($output)); die(theme_features::json_format($output)); } setup_postdata($post); $output = ['status' => 'success', 'msg' => ___('Finished get the post data.'), 'thumbnail' => ['url' => theme_functions::get_thumbnail_src($post_id), 'size' => [theme_functions::$thumbnail_size[1], theme_functions::$thumbnail_size[2]]], 'title' => theme_cache::get_the_title($post_id), 'excerpt' => html_minify(str_sub(strip_tags(trim($post->post_content)), 120, '...'))]; wp_reset_postdata(); die(theme_features::json_format($output)); } die(theme_features::json_format($output)); }
private static function get_update_post_status($old_status) { if ($old_status === 'pending') { return 'pending'; } /** if is editor, return publish status */ if (theme_cache::current_user_can('edit_pages')) { return 'publish'; } /** if is author, check the pending after edit status */ if (theme_cache::current_user_can('publish_posts')) { return self::is_pending_after_edited() ? 'pending' : 'publish'; } /** if is lower than author, return pending */ return 'pending'; }
public static function process() { $output = []; /** * if not image */ $filename = isset($_FILES['img']['name']) ? $_FILES['img']['name'] : null; $file_ext = $filename ? strtolower(array_slice(explode('.', $filename), -1, 1)[0]) : null; if (!in_array($file_ext, self::$file_exts)) { $output['status'] = 'error'; $output['code'] = 'invaild_file_type'; $output['msg'] = ___('Invaild file type.'); die(theme_features::json_format($output)); } /** * check permission */ if (!theme_cache::current_user_can('manage_options')) { $output['status'] = 'error'; $output['code'] = 'invaild_permission'; $output['msg'] = ___('You have not permission to upload.'); die(theme_features::json_format($output)); } /** * pass */ require_once ABSPATH . 'wp-admin/includes/image.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; add_image_size(__CLASS__, self::$image_size[0], self::$image_size[1], self::$image_size[2]); $attach_id = media_handle_upload('img', 0); if (is_wp_error($attach_id)) { $output['status'] = 'error'; $output['code'] = $attach_id->get_error_code(); $output['msg'] = $attach_id->get_error_message(); die(theme_features::json_format($output)); } else { $output['status'] = 'success'; $output['url'] = wp_get_attachment_image_src($attach_id, __CLASS__)[0]; $output['msg'] = ___('Upload success.'); die(theme_features::json_format($output)); } die(theme_features::json_format($output)); }
/** * Add admin bar * * * @return * @version 1.0.1 * */ public static function add_bar() { if (!theme_cache::current_user_can('manage_options')) { return false; } global $wp_admin_bar; $wp_admin_bar->add_menu(array('parent' => 'appearance', 'id' => 'theme_settings', 'title' => ___('Theme settings'), 'href' => self::get_url())); }
public static function process() { $output = []; $type = isset($_GET['type']) ? $_GET['type'] : null; switch ($type) { case 'get-points': if (!isset($_GET['user-id']) || !is_numeric($_GET['user-id'])) { $output['status'] = 'error'; $output['code'] = 'invaild_user_id'; $output['msg'] = ___('Invaild user id.'); die(theme_features::json_format($output)); } $user = get_user_by('id', $_GET['user-id']); if (!$user) { $output['status'] = 'error'; $output['code'] = 'user_not_exist'; $output['msg'] = ___('User does not exist.'); die(theme_features::json_format($output)); } $output['status'] = 'success'; $output['points'] = self::get_point($user->ID); $output['msg'] = sprintf(___('The user %1$s has %2$d points now.'), esc_html($user->display_name), self::get_point($user->ID)); break; /** * special */ /** * special */ case 'special': if (!theme_cache::current_user_can('create_users')) { $output['status'] = 'error'; $output['code'] = 'invaild_permission'; $output['msg'] = ___('Your are not enough permission to modify user.'); die(theme_features::json_format($output)); } $special = isset($_GET['special']) && is_array($_GET['special']) ? $_GET['special'] : null; if (empty($special)) { $output['status'] = 'error'; $output['code'] = 'invaild_param'; $output['msg'] = ___('Invaild param.'); die(theme_features::json_format($output)); } $invalidations = array('user-id' => array('msg' => ___('Invaild user ID.'), 'code' => 'invaild_user_id'), 'point' => array('msg' => ___('Invaild point.'), 'code' => 'invaild_point'), 'event' => array('msg' => ___('Invaild event.'), 'code' => 'invaild_event')); foreach ($invalidations as $k => $v) { if (!isset($special[$k]) || empty($special[$k])) { $output['status'] = 'error'; $output['code'] = $v['code']; $output['msg'] = $v['msg']; die(theme_features::json_format($output)); } } /** * check user exist */ $user = get_user_by('id', $special['user-id']); if (!$user) { $output['status'] = 'error'; $output['code'] = 'user_not_exist'; $output['msg'] = ___('The user is not exist'); die(theme_features::json_format($output)); } /** * pass, set the new point for user */ self::action_add_history_special_event($special['user-id'], $special['point'], $special['event']); $output['status'] = 'success'; $sign = $special['point'] > 0 ? '+' : null; $output['msg'] = sprintf(___('The user %1$s(%2$d) point has set to %3$d.'), esc_html($user->display_name), $user->ID, self::get_point($user->ID) . $sign . $special['point'] . '=' . self::get_point($user->ID, true)); die(theme_features::json_format($output)); break; } die(theme_features::json_format($output)); }