Esempio n. 1
0
 public static function process()
 {
     $output = [];
     theme_features::check_referer();
     theme_features::check_nonce();
     $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
     $user_id = isset($_REQUEST['user-id']) ? (int) $_REQUEST['user-id'] : null;
     switch ($type) {
         case 'follow':
             $output['count'] = self::set_follow($user_id);
             $output['code'] = 'followed';
             $output['msg'] = ___('Follow success.');
             $output['status'] = 'success';
             break;
         case 'unfollow':
             $output['count'] = self::set_follow($user_id);
             $output['code'] = 'followed';
             $output['msg'] = ___('Unfollow success.');
             $output['status'] = 'success';
             break;
         default:
             $output['status'] = 'error';
             $output['code'] = 'unkown_param';
             $output['msg'] = ___('Unkown param.');
     }
     die(theme_features::json_format($output));
 }
Esempio n. 2
0
 public static function process()
 {
     theme_features::check_referer();
     $post_id = isset($_GET['post-id']) && is_numeric($_GET['post-id']) ? (int) $_GET['post-id'] : false;
     if (!$post_id) {
         die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_post_id', 'msg' => ___('Sorry, post id is invaild.')]));
     }
     global $post, $page;
     /**
      * post
      */
     $post = theme_cache::get_post($post_id);
     if (!$post) {
         die(theme_features::json_format(['status' => 'error', 'code' => 'post_not_exist', 'msg' => ___('Sorry, the post does not exist.')]));
     }
     /**
      * page
      */
     $page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int) $_GET['page'] : false;
     if (!$page) {
         die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_page_number', 'msg' => ___('Sorry, page number is invaild.')]));
     }
     set_query_var('page', $page);
     setup_postdata($post);
     ob_start();
     if (class_exists('theme_img_lazyload')) {
         remove_filter('the_content', 'theme_img_lazyload::the_content');
     }
     the_content();
     $content = html_minify(ob_get_contents());
     ob_end_clean();
     die(theme_features::json_format(['status' => 'success', 'content' => $content]));
 }
 /** 
  * pre_comment_on_post
  */
 public static function pre_comment_on_post($comment_post_ID)
 {
     $comment_post_ID = isset($_POST['comment_post_ID']) ? (int) $_POST['comment_post_ID'] : 0;
     $post = theme_cache::get_post($comment_post_ID);
     /**
      * check comment_status
      */
     if (empty($post->comment_status)) {
         do_action('comment_id_not_found', $comment_post_ID);
         $output['status'] = 'error';
         $output['code'] = 'post_not_exists';
         $output['msg'] = ___('Sorry, the post does not exist.');
         die(theme_features::json_format($output));
     }
     /** 
      * check 
      */
     $status = get_post_status($post);
     $status_obj = get_post_status_object($status);
     /** 
      * check comment is closed
      */
     if (!comments_open($comment_post_ID)) {
         do_action('comment_closed', $comment_post_ID);
         $output['status'] = 'error';
         $output['code'] = 'comment_closed';
         $output['msg'] = ___('Sorry, comments are closed for this item.');
         die(theme_features::json_format($output));
         /**
          * If the post is trash
          */
     } else {
         if ('trash' == $status) {
             do_action('comment_on_trash', $comment_post_ID);
             $output['status'] = 'error';
             $output['code'] = 'trash_post';
             $output['msg'] = ___('Sorry, can not comment on trash post.');
             die(theme_features::json_format($output));
             /**
              * If the post is draft
              */
         } else {
             if (!$status_obj->public && !$status_obj->private) {
                 do_action('comment_on_draft', $comment_post_ID);
                 $output['status'] = 'error';
                 $output['code'] = 'draft_post';
                 $output['msg'] = ___('Sorry, can not comment draft post.');
                 die(theme_features::json_format($output));
                 /**
                  * If the post needs password
                  */
             } else {
                 if (post_password_required($comment_post_ID)) {
                     do_action('comment_on_password_protected', $comment_post_ID);
                     $output['status'] = 'error';
                     $output['code'] = 'need_pwd';
                     $output['msg'] = ___('Sorry, the post needs password to comment.');
                     die(theme_features::json_format($output));
                 }
             }
         }
     }
 }
Esempio n. 4
0
    public static function process()
    {
        theme_features::check_nonce();
        theme_features::check_referer();
        $output = [];
        $type = isset($_REQUEST['type']) && is_string($_REQUEST['type']) ? $_REQUEST['type'] : null;
        $user = isset($_POST['user']) && is_array($_POST['user']) ? $_POST['user'] : false;
        $email = isset($user['email']) && is_email($user['email']) ? $user['email'] : null;
        $pwd = isset($user['pwd']) && is_string($user['pwd']) ? $user['pwd'] : null;
        switch ($type) {
            /** 
             * login
             */
            case 'login':
                $output = self::user_login(array('email' => $email, 'pwd' => $pwd, 'remember' => isset($user['remember']) ? true : false));
                if ($output['status'] === 'success') {
                    $output['msg'] = self::get_options('lang-login-success');
                } else {
                    die(theme_features::json_format($output));
                }
                break;
                /** 
                 * register
                 */
            /** 
             * register
             */
            case 'register':
                /**
                 * check can register
                 */
                if (!theme_cache::get_option('users_can_register')) {
                    die(theme_features::json_format(['status' => 'error', 'code' => 'users_can_not_register', 'msg' => ___('Sorry, it is not the time, the site is temporarily closed registration.')]));
                }
                /**
                 * nickname
                 */
                $user['nickname'] = isset($user['nickname']) && is_string($user['nickname']) ? filter_blank($user['nickname']) : false;
                if (mb_strlen($user['nickname']) < self::$min_display_name_length) {
                    $output['status'] = 'error';
                    $output['code'] = 'invalid_nickname';
                    $output['msg'] = sprintf(___('Sorry, you nick name is invalid, at least %d characters in length, please try again.'), self::$min_display_name_length);
                    die(theme_features::json_format($output));
                }
                /**
                 * pwd
                 */
                if (mb_strlen($pwd) < self::$min_pwd_length) {
                    $output['status'] = 'error';
                    $output['code'] = 'invalid_pwd';
                    $output['msg'] = sprintf(___('Sorry, you password is invalid, at least %d characters in length, please try again.'), self::$min_pwd_length);
                    die(theme_features::json_format($output));
                }
                /**
                 * email 
                 */
                if (!$email) {
                    $output['status'] = 'error';
                    $output['code'] = 'invalid_email';
                    $output['msg'] = ___('Sorry, your email address is invalid, please check it and try again.');
                    die(theme_features::json_format($output));
                }
                /**
                 * check display_name repeat
                 */
                $exists_users = array_filter(get_users(['meta_key' => 'display_name', 'meta_value' => $user['nickname']]));
                if (count($exists_users) >= 1) {
                    $output['status'] = 'error';
                    $output['code'] = 'duplicate_display_name';
                    $output['msg'] = ___('Sorry, the nickname has been used, please change another one.');
                    die(theme_features::json_format($output));
                }
                /******************
                 * PASS
                 *****************/
                $output = self::user_register(array('email' => $email, 'pwd' => $pwd, 'nickname' => $user['nickname'], 'remember' => true));
                if ($output['status'] === 'success') {
                    // $output['redirect'] =
                    $output['msg'] = ___('Register successfully, page is refreshing, please wait...');
                }
                break;
                /** 
                 * lost-password
                 */
            /** 
             * lost-password
             */
            case 'recover':
                if (!$email) {
                    $output['status'] = 'error';
                    $output['code'] = 'invalid_email';
                    $output['msg'] = ___('Sorry, your email address is invalid, please check it and try again.');
                    die(theme_features::json_format($output));
                }
                /** 
                 * check the email is exist
                 */
                $user_id = email_exists($email);
                if (!$user_id) {
                    $output['status'] = 'error';
                    $output['code'] = 'email_not_exist';
                    $output['msg'] = ___('Sorry, the email does not exist.');
                    die(theme_features::json_format($output));
                }
                /** 
                 * create and encode code
                 */
                $user = get_userdata($user_id);
                $encode_arr = array('user_id' => $user_id, 'user_email' => $user->user_email);
                $encode_str = json_encode($encode_arr);
                $encode = base64_encode(authcode($encode_str, 'encode', AUTH_KEY, 7200));
                $callback_url = esc_url(add_query_arg(['token' => $encode], self::get_tabs('reset')['url']));
                $content = '
					<h3>' . sprintf(___('Dear %s!'), esc_html($user->display_name)) . '</h3>
					<p>
						' . sprintf(___('You are receiving this email because you forgot your password. We already made an address for your account, you can access this address ( %s ) to log-in and change your password in 3 hours.'), '<a href="' . $callback_url . '" target="_blank">' . $callback_url . '</a>') . '
					</p>
					<p>' . sprintf(___('-- From %s'), '<a href="' . theme_cache::home_url() . '" target="_blank">' . theme_cache::get_bloginfo('name') . '</a>') . '</p>
				';
                $title = ___('You are applying to reset your password.');
                $headers = ['Content-Type: text/html; charset=UTF-8'];
                $wp_mail = wp_mail($user->user_email, $title, $content, $headers);
                /** 
                 * check wp_mail is success or not
                 */
                if ($wp_mail === true) {
                    update_user_meta($user_id, '_tmp_lost_pwd', 1);
                    $output['status'] = 'success';
                    $output['msg'] = ___('Success, we sent an email that includes how to retrieve your password, please check it out in 3 hours.');
                } else {
                    $output['status'] = 'error';
                    $output['code'] = 'server_error';
                    $output['detial'] = $wp_mail['msg'];
                    $output['msg'] = ___('Error, server can not send email, please contact the administrator.');
                }
                break;
                /** 
                 * reset
                 */
            /** 
             * reset
             */
            case 'reset':
                if (!$user) {
                    $output['status'] = 'error';
                    $output['code'] = 'invalid_param';
                    $output['msg'] = ___('Sorry, the param is invalid.');
                    die(theme_features::json_format($output));
                }
                $token = isset($user['token']) && is_string($user['token']) ? $user['token'] : false;
                if (!$token) {
                    $output['status'] = 'error';
                    $output['code'] = 'invaild_token';
                    $output['msg'] = ___('Sorry, the token is invaild.');
                    die(theme_features::json_format($output));
                }
                /** pwd again */
                $pwd_again = isset($user['pwd-again']) && is_string($user['pwd-again']) ? $user['pwd-again'] : null;
                if (empty($pwd) || $pwd !== $pwd_again) {
                    $output['status'] = 'error';
                    $output['code'] = 'invalid_twice_pwd';
                    $output['msg'] = ___('Sorry, twice password is invaild, please try again.');
                    die(theme_features::json_format($output));
                }
                /** decode token */
                $token_decode = self::get_decode_token($token);
                if (!$token_decode) {
                    $output['status'] = 'error';
                    $output['code'] = 'expired_token';
                    $output['msg'] = ___('Sorry, the token is expired.');
                    die(theme_features::json_format($output));
                }
                $token_user_id = isset($token_decode['user_id']) && is_numeric($token_decode['user_id']) ? $token_decode['user_id'] : null;
                $token_user_email = isset($token_decode['user_email']) && is_email($token_decode['user_email']) ? $token_decode['user_email'] : null;
                /** check token email is match post email */
                if (!$token_user_email) {
                    $output['status'] = 'error';
                    $output['code'] = 'token_email_not_match';
                    $output['msg'] = ___('Sorry, the token email and you account email do not match.');
                    die(theme_features::json_format($output));
                }
                /** check post email exists */
                $user_id = (int) email_exists($token_user_email);
                if ($user_id != $token_decode['user_id']) {
                    $output['status'] = 'error';
                    $output['code'] = 'email_not_exist';
                    $output['msg'] = ___('Sorry, your account email is not exist.');
                    die(theme_features::json_format($output));
                }
                /** check user already apply to recover password */
                if (!get_user_meta($user_id, '_tmp_recover_pwd', true)) {
                    $output['status'] = 'error';
                    $output['code'] = 'not_apply_recover';
                    $output['msg'] = ___('Sorry, the user do not apply recover yet.');
                }
                /** all ok, just set new password */
                delete_user_meta($user_id, '_tmp_recover_pwd');
                wp_set_password($pwd, $user_id);
                wp_set_current_user($user_id);
                wp_set_auth_cookie($user_id, true);
                $output['status'] = 'success';
                $output['redirect'] = theme_cache::home_url();
                $output['msg'] = ___('Congratulation, your account has been recovered! Password has been updated. Redirecting home page, please wait...');
                break;
            default:
                $output['status'] = 'error';
                $output['code'] = 'invalid_type';
                $output['msg'] = ___('Invalid type.');
        }
        die(theme_features::json_format($output));
    }
Esempio n. 5
0
 public static function process()
 {
     $output = [];
     $type = isset($_REQUEST['type']) && is_string($_REQUEST['type']) ? $_REQUEST['type'] : null;
     /** hook theme_api */
     do_action(__CLASS__, $type);
     switch ($type) {
         /**
          * get categories
          */
         case 'get_categories':
             $output['status'] = 'success';
             $output['categories'] = self::get_cats();
             /**
              * get cache
              */
             $cache = wp_cache_get($type, __CLASS__);
             if ($cache) {
                 die(theme_features::json_format($cache));
             }
             /**
              * set cache
              */
             wp_cache_set($type, $output, __CLASS__, 3600 * 24);
             die(theme_features::json_format($output));
             /**
              * get posts
              */
         /**
          * get posts
          */
         case 'get_posts':
             $query_args = [];
             /**
              * $posts_per_page, max 50 count, default: 20
              */
             $posts_per_page = isset($_GET['posts_per_page']) && is_numeric($_GET['posts_per_page']) ? $_GET['posts_per_page'] : 20;
             if ($posts_per_page > 50) {
                 $posts_per_page = 50;
             }
             if ($posts_per_page <= 0) {
                 $posts_per_page = 1;
             }
             $query_args['posts_per_page'] = $posts_per_page;
             /**
              * $paged, default: 1
              */
             $paged = isset($_GET['paged']) && is_numeric($_GET['paged']) ? $_GET['paged'] : 1;
             $query_args['paged'] = $paged;
             /**
              * ignore_sticky, default: false
              */
             $ignore_sticky_posts = isset($_GET['ignore_sticky_posts']) ? (bool) $_GET['ignore_sticky_posts'] : false;
             $query_args['ignore_sticky_posts'] = $ignore_sticky_posts;
             /**
              * cat,e.g. 1
              */
             if (isset($_GET['cat']) && is_numeric($_GET['cat'])) {
                 $query_args['cat'] = (int) $_GET['cat'];
             }
             /**
              * category_name, e.g. cat_slug
              */
             if (isset($_GET['category_name']) && is_string($_GET['category_name'])) {
                 $query_args['category_name'] = $_GET['category_name'];
             }
             /**
              * category__and, e.g. [1,2,3]
              */
             if (isset($_GET['category__and']) && is_array($_GET['category__and'])) {
                 $query_args['category__and'] = $_GET['category__and'];
             }
             /**
              * category__in, e.g. [1,2,3]
              */
             if (isset($_GET['category__in']) && is_array($_GET['category__in'])) {
                 $query_args['category__in'] = $_GET['category__in'];
             }
             /**
              * category__not_in, e.g. [1,2,3]
              */
             if (isset($_GET['category__not_in']) && is_array($_GET['category__not_in'])) {
                 $query_args['category__not_in'] = $_GET['category__not_in'];
             }
             /**
              * get cache
              */
             $cache_id = md5(json_encode($query_args));
             $cache = wp_cache_get($cache_id, __CLASS__);
             if ($cache) {
                 die(theme_features::json_format($cache));
             }
             /**
              * create query
              */
             global $post;
             $query = new WP_Query($query_args);
             if ($query->have_posts()) {
                 foreach ($query->posts as $post) {
                     $output['posts'][] = self::get_postdata();
                 }
                 wp_reset_postdata();
             } else {
                 $output['status'] = 'error';
                 $output['code'] = 'no_content';
                 $output['msg'] = ___('Sorry, no content found.');
             }
             $output['status'] = 'success';
             /**
              * set cache
              */
             wp_cache_set($cache_id, $output, __CLASS__, 3600);
             die(theme_features::json_format($output));
             /**
              * get post
              */
         /**
          * get post
          */
         case 'get_post':
             $post_id = isset($_GET['post_id']) && is_numeric($_GET['post_id']) ? $_GET['post_id'] : null;
             /**
              * check post id
              */
             if (!$post_id) {
                 $output['status'] = 'error';
                 $output['code'] = 'invaild_post_id';
                 $output['msg'] = ___('Sorry, post ID is invaild.');
                 die(theme_features::json_format($output));
             }
             /**
              * get cache
              */
             $cache = wp_cache_get($post_id, __CLASS__);
             if ($cache) {
                 die(theme_features::json_format($cache));
             }
             global $post;
             $post = theme_cache::get_post($post_id);
             /**
              * check post exists
              */
             if (!$post || $post->post_type !== 'post') {
                 $output['status'] = 'error';
                 $output['code'] = 'post_not_exist';
                 $output['msg'] = ___('Sorry, the post do not exist.');
                 die(theme_features::json_format($output));
             }
             $output['status'] = 'success';
             $output['post'] = self::get_postdata($post);
             /**
              * set cache
              */
             wp_cache_set($post_id, $output, __CLASS__, 3600);
             die(theme_features::json_format($output));
         default:
             $output['status'] = 'error';
             $output['code'] = 'invaild_type_param';
             $output['msg'] = ___('Sorry, the type param is invaild.');
             die(theme_features::json_format($output));
     }
 }
Esempio n. 6
0
 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.')]));
     }
 }
Esempio n. 7
0
 public static function process()
 {
     theme_features::check_referer();
     $output = [];
     $type = isset($_GET['type']) && is_string($_GET['type']) ? $_GET['type'] : null;
     switch ($type) {
         case 'clean-cache':
             wp_cache_delete('display-frontend', __CLASS__);
             $output['status'] = 'success';
             $output['msg'] = ___('Cache has been cleaned.');
             break;
     }
     die(theme_features::json_format($output));
 }
Esempio n. 8
0
    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.')]));
        }
    }
 public static function process()
 {
     theme_features::check_referer();
     $output = [];
     $type = isset($_REQUEST['type']) && is_string($_REQUEST['type']) ? $_REQUEST['type'] : false;
     $post_id = isset($_REQUEST['post-id']) && is_numeric($_REQUEST['post-id']) ? (int) $_REQUEST['post-id'] : false;
     if ($type === 'up' || $type === 'down') {
         /**
          * check post id
          */
         if (!$post_id) {
             die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_post_id', 'msg' => ___('Sorry, the post ID is invaild.')]));
         }
         /**
          * check post exists
          */
         $post = theme_cache::get_post($post_id);
         if (!$post || $post->post_type !== 'post' && $post->post_type !== 'page') {
             die(theme_features::json_format(['status' => 'error', 'code' => 'post_not_exist', 'post-type' => $post->post_type, 'msg' => ___('Sorry, the post does not exists.')]));
         }
         /**
          * check voted
          */
         if (self::is_voted($post_id)) {
             die(theme_features::json_format(['status' => 'success', 'code' => 'voted', 'msg' => ___('You voted the post, thank you.')]));
         }
         /**
          * set cookie
          */
         self::set_voted($post_id);
         /**
          * update vote
          */
         die(theme_features::json_format(['status' => 'success', 'votes' => self::update_thumb($type, $post_id), 'msg' => self::get_rand_thumb_tx($type)]));
     } else {
         if ($type === 'convert') {
             if (!current_user_can('manage_options')) {
                 die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_permission', 'msg' => ___('Sorry, your permission is invaild.')]));
             }
             self::convert_new_version();
             die(theme_features::json_format(['status' => 'success', 'msg' => ___('Data has been converted.')]));
         }
     }
     die(theme_features::json_format($output));
 }
Esempio n. 10
0
 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));
 }
Esempio n. 11
0
 public static function process()
 {
     theme_features::check_referer();
     if (!theme_cache::current_user_can('manage_options')) {
         die;
     }
     $output = [];
     wp_cache_delete(__CLASS__);
     $output['status'] = 'success';
     $output['msg'] = ___('Cache has been cleaned.');
     die(theme_features::json_format($output));
 }
Esempio n. 12
0
 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));
 }
Esempio n. 13
0
 public static function process()
 {
     $output = [];
     theme_features::check_referer();
     theme_features::check_nonce();
     $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
     die(theme_features::json_format($output));
 }
Esempio n. 14
0
 /**
  * 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));
 }
Esempio n. 15
0
 private static function get_preview(array $posts = [])
 {
     /**
      * check posts count number
      */
     $count = count($posts);
     if ($count < self::get_posts_number('min')) {
         $output['status'] = 'error';
         $output['code'] = 'not_enough_posts';
         $output['msg'] = ___('Sorry, your posts are not enough, please add more posts.');
         die(theme_features::json_format($output));
     }
     if ($count > self::get_posts_number('max')) {
         $output['status'] = 'error';
         $output['code'] = 'too_many_posts';
         $output['msg'] = ___('Sorry, your post are too many, please reduce some posts and try again.');
         die(theme_features::json_format($output));
     }
     /**
      * template
      */
     $tpl = '';
     /**
      * check each posts value
      */
     foreach ($posts as $k => $v) {
         /** post id */
         $post_id = isset($v['post-id']) && is_string($v['post-id']) ? trim($v['post-id']) : null;
         if (empty($post_id)) {
             $output['status'] = 'error';
             $output['code'] = 'invaild_post_content';
             $output['list-id'] = $k;
             $output['msg'] = ___('Sorry, the post id is invaild, please try again.');
             die(theme_features::json_format($output));
         }
         /** title */
         $title = isset($v['post-title']) && is_string($v['post-title']) ? strip_tags(trim($v['post-title'])) : null;
         if (empty($title)) {
             $output['status'] = 'error';
             $output['code'] = 'invaild_post_title';
             $output['list-id'] = $k;
             $output['msg'] = ___('Sorry, the post title is invaild, please try again.');
             die(theme_features::json_format($output));
         }
         /** content */
         $content = isset($v['post-content']) && is_string($v['post-content']) ? trim($v['post-content']) : null;
         if (empty($content)) {
             $output['status'] = 'error';
             $output['code'] = 'invaild_post_content';
             $output['list-id'] = $k;
             $output['msg'] = ___('Sorry, the post content is invaild, please try again.');
             die(theme_features::json_format($output));
         }
         /** thumbmail */
         $thumbnail = isset($v['thumbnail-url']) && is_string($v['thumbnail-url']) ? esc_url(trim($v['thumbnail-url'])) : null;
         if (empty($thumbnail)) {
             $output['status'] = 'error';
             $output['code'] = 'invaild_post_thumbnail';
             $output['list-id'] = $k;
             $output['msg'] = ___('Sorry, the post thumbnail is invaild, please try again.');
             die(theme_features::json_format($output));
         }
         /** check post exists */
         $url = esc_url(theme_cache::get_permalink($v['post-id']));
         if (empty($url)) {
             $output['status'] = 'error';
             $output['code'] = 'post_not_exist';
             $output['list-id'] = $k;
             $output['msg'] = ___('Sorry, the post do not exist, please try again.');
             die(theme_features::json_format($output));
         }
         /**
          * create template
          */
         $tpl .= self::get_list_tpl(['post_id' => $post_id, 'preview' => false, 'hash' => $k, 'url' => $url, 'thumbnail' => $thumbnail, 'title' => $title, 'content' => $content]);
     }
     return '<div class="collection-list list-group">' . html_minify($tpl) . '</div>';
 }
Esempio n. 16
0
 public static function process()
 {
     $output = [];
     theme_features::check_referer();
     theme_features::check_nonce();
     $type = isset($_REQUEST['type']) && is_string($_REQUEST['type']) ? $_REQUEST['type'] : null;
     $user = isset($_POST['user']) && is_array($_POST['user']) ? $_POST['user'] : null;
     /**
      * get current
      */
     global $current_user;
     get_currentuserinfo();
     switch ($type) {
         /**
          * settings
          */
         case 'settings':
             /**
              * check point is enough
              */
             if (class_exists('theme_custom_point')) {
                 /** get current user points */
                 $user_points = theme_custom_point::get_point($current_user->ID);
                 if ($user_points - abs(theme_custom_point::get_point_value('save-' . $type)) < 0) {
                     die(theme_features::json_format(['status' => 'error', 'code' => 'not_enough_point', 'msg' => ___('Sorry, your points are not enough to modify settings.')]));
                 }
             }
             if (empty($_POST['user']) || !is_array($_POST['user'])) {
                 $output['status'] = 'error';
                 $output['code'] = 'invaild_param';
                 $output['msg'] = ___('Invaild param.');
                 die(theme_features::json_format($output));
             }
             $nickname = isset($user['nickname']) && is_string($user['nickname']) ? trim($user['nickname']) : null;
             if (empty($nickname)) {
                 $output['status'] = 'error';
                 $output['code'] = 'invaild_nickname';
                 $output['msg'] = ___('Invaild nickname.');
                 die(theme_features::json_format($output));
             }
             $url = isset($user['url']) && is_string($user['url']) ? esc_url($user['url']) : null;
             $des = isset($user['description']) && is_string($user['description']) ? $user['description'] : null;
             $user_id = wp_update_user(array('ID' => $current_user->ID, 'user_url' => $url, 'nickname' => $nickname, 'description' => $des, 'display_name' => $nickname));
             if (is_wp_error($user_id)) {
                 $output['status'] = 'error';
                 $output['code'] = $user_id->get_error_code();
                 $output['msg'] = $user_id->get_error_message();
                 die(theme_features::json_format($output));
             } else {
                 /**
                  * add point history
                  */
                 if (class_exists('theme_custom_point')) {
                     $meta = ['type' => 'save-' . $type, 'points' => 0 - abs(theme_custom_point::get_point_value('save-' . $type)), 'timestamp' => current_time('timestamp')];
                     add_user_meta($current_user->ID, theme_custom_point::$user_meta_key['history'], $meta);
                     /**
                      * update points
                      */
                     update_user_meta($current_user->ID, theme_custom_point::$user_meta_key['point'], $user_points - abs(theme_custom_point::get_point_value('save-' . $type)));
                     /**
                      * feelback
                      */
                     $output['points'] = 0 - abs(theme_custom_point::get_point_value('save-' . $type));
                 }
                 $output['status'] = 'success';
                 $output['msg'] = ___('Your settings have been saved.');
                 die(theme_features::json_format($output));
             }
             break;
             /**
              * pwd
              */
         /**
          * pwd
          */
         case 'pwd':
             /**
              * twice pwd
              */
             $new_pwd_1 = isset($user['new-pwd-1']) && is_string($user['new-pwd-1']) ? trim($user['new-pwd-1']) : null;
             $new_pwd_2 = isset($user['new-pwd-2']) && is_string($user['new-pwd-2']) ? trim($user['new-pwd-2']) : null;
             if (empty($new_pwd_1) || $new_pwd_1 !== $new_pwd_2) {
                 $output['status'] = 'error';
                 $output['code'] = 'invaild_pwd_twice';
                 $output['msg'] = ___('Password invaild twice.');
                 die(theme_features::json_format($output));
             }
             /**
              * old pwd
              */
             $old_pwd = isset($user['old-pwd']) && is_string($user['old-pwd']) ? trim($user['old-pwd']) : null;
             if (empty($old_pwd) || !wp_check_password($old_pwd, $current_user->user_pass, $current_user->ID)) {
                 $output['status'] = 'error';
                 $output['code'] = 'invaild_old_pwd';
                 $output['msg'] = ___('Invaild current password.');
                 die(theme_features::json_format($output));
             }
             /**
              * change password
              */
             wp_update_user(array('ID' => $current_user->ID, 'user_pass' => $new_pwd_1));
             /**
              * set current, relogin
              */
             wp_set_current_user($current_user->ID);
             wp_set_auth_cookie($current_user->ID);
             $output['status'] = 'success';
             $output['msg'] = ___('Your new password has been saved.');
             $output['redirect'] = theme_cache::home_url();
             die(theme_features::json_format($output));
             break;
             /**
              * avatar
              */
         /**
          * avatar
          */
         case 'avatar':
             /**
              * check point is enough
              */
             if (class_exists('theme_custom_point')) {
                 /** get current user points */
                 $user_points = theme_custom_point::get_point($current_user->ID);
                 if ($user_points - abs(theme_custom_point::get_point_value('save-' . $type)) < 0) {
                     die(theme_features::json_format(['status' => 'error', 'code' => 'not_enough_point', 'msg' => ___('Sorry, your points are not enough to modify avatar.')]));
                 }
             }
             $base64 = isset($_POST['b4']) && is_string($_POST['b4']) ? explode(',', $_POST['b4']) : null;
             if (!isset($base64[0]) && strpos($base64[0], 'jpeg') === false) {
                 $output['status'] = 'error';
                 $output['code'] = 'invaild_format';
                 $output['msg'] = ___('Sorry, your file is invaild format, please check it again.');
                 die(theme_features::json_format($output));
             }
             $wp_uplaod_dir = wp_upload_dir();
             $filename = $current_user->ID . '.jpg';
             $filesub_url = '/avatar/' . $filename;
             $timestamp = '?v=' . $_SERVER['REQUEST_TIME'];
             if (!is_dir($wp_uplaod_dir['basedir'] . '/avatar')) {
                 mkdir($wp_uplaod_dir['basedir'] . '/avatar', 0755, true);
             }
             $filepath = $wp_uplaod_dir['basedir'] . $filesub_url;
             $fileurl = $wp_uplaod_dir['baseurl'] . $filesub_url . $timestamp;
             $file_contents = file_put_contents($filepath, base64_decode($base64[1]));
             if ($file_contents === false) {
                 $output['status'] = 'error';
                 $output['code'] = 'can_not_write_file';
                 $output['msg'] = ___('Sorry, system can not write file, please try again later or contact the administrator.');
                 die(theme_features::json_format($output));
             } else {
                 /**
                  * add point history
                  */
                 if (class_exists('theme_custom_point')) {
                     $meta = ['type' => 'save-' . $type, 'points' => 0 - abs(theme_custom_point::get_point_value('save-' . $type)), 'timestamp' => current_time('timestamp')];
                     add_user_meta($current_user->ID, theme_custom_point::$user_meta_key['history'], $meta);
                     /**
                      * update points
                      */
                     update_user_meta($current_user->ID, theme_custom_point::$user_meta_key['point'], $user_points - abs(theme_custom_point::get_point_value('save-' . $type)));
                     /**
                      * feelback
                      */
                     $output['points'] = 0 - abs(theme_custom_point::get_point_value('save-' . $type));
                 }
                 /**
                  * update user meta for avatar
                  */
                 $avatar_meta_key = class_exists('theme_custom_avatar') ? theme_custom_avatar::$user_meta_key['avatar'] : 'avatar';
                 update_user_meta($current_user->ID, $avatar_meta_key, $filesub_url . $timestamp);
                 $output['status'] = 'success';
                 $output['avatar-url'] = $fileurl;
                 $output['msg'] = ___('Congratulation! Your avatar has been updated. Page is redirecting, please wait...');
                 die(theme_features::json_format($output));
             }
             break;
         default:
             $output['status'] = 'error';
             $output['code'] = 'invaild_type_param';
             $output['msg'] = ___('Sorry, the type param is invaild.');
             die(theme_features::json_format($output));
     }
 }
Esempio n. 17
0
 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));
 }
Esempio n. 18
0
 public static function process()
 {
     theme_features::check_referer();
     theme_features::check_nonce();
     $output = [];
     $type = isset($_REQUEST['type']) && is_string($_REQUEST['type']) ? $_REQUEST['type'] : null;
     $target_id = isset($_REQUEST['target']) && is_numeric($_REQUEST['target']) ? $_REQUEST['target'] : null;
     switch ($type) {
         case 'get-target':
             /**
              * check login
              */
             $current_user_id = self::check_login();
             /**
              * check times
              */
             self::check_max_times();
             /**
              * get target
              */
             $target = self::check_target($target_id);
             $output = ['status' => 'success', 'points' => theme_custom_point::get_point($target_id), 'avatar' => theme_cache::get_avatar_url($target_id), 'name' => esc_html($target->display_name), 'msg' => ___('Target locked, bomb is ready.')];
             die(theme_features::json_format($output));
             /**
              * bomb
              */
         /**
          * bomb
          */
         case 'bomb':
             /**
              * check login
              */
             $current_user_id = self::check_login();
             /**
              * check times
              */
             self::check_max_times();
             /**
              * get target
              */
             $target = self::check_target($target_id);
             /**
              * check points
              */
             $points = isset($_REQUEST['points']) && is_numeric($_REQUEST['points']) ? $_REQUEST['points'] : null;
             if (!$points || !in_array($points, self::get_point_values())) {
                 die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_point_value', 'msg' => ___('Sorry, the point value is invaild.'), 'points' => self::get_point_values()]));
             }
             /**
              * check target points
              */
             $target_points = theme_custom_point::get_point($target_id);
             if ($points > $target_points) {
                 die(theme_features::json_format(['status' => 'error', 'code' => 'target_points_not_enough', 'msg' => sprintf(___('Sorry, the target %s is not enough to bear your bomb.'), theme_custom_point::get_point_name())]));
             }
             /**
              * check attacker points
              */
             $attacker_id = theme_cache::get_current_user_id();
             $attacker_points = theme_custom_point::get_point($attacker_id);
             if ($points > $attacker_points) {
                 die(theme_features::json_format(['status' => 'error', 'code' => 'attacker_points_not_enough', 'msg' => sprintf(___('Sorry, your %s is not enough to bomb target.'), theme_custom_point::get_point_name())]));
             }
             /**
              * pass 
              */
             $says = isset($_REQUEST['says']) && is_string($_REQUEST['says']) ? mb_substr($_REQUEST['says'], 0, 30) : false;
             /**
              * define $hit
              */
             $hit = false;
             if (mt_rand(0, 100) <= self::get_victory_percent()) {
                 $hit = true;
             }
             /**
              * define data
              */
             $data = ['attacker-id' => $current_user_id, 'target-id' => $target_id, 'says' => $says, 'points' => $points, 'hit' => $hit];
             /** add history for target */
             self::add_history_for_target($data);
             /** add history for attacker */
             self::add_history_for_attacker($data);
             //self::add_noti_for_target($current_user_id,$target_id,$points,$hit);
             /**
              * new target points
              */
             $target_extra_points = self::get_extra_points_for_target($hit, $points);
             $new_target_points = $target_points + $target_extra_points;
             /**
              * new attacker points
              */
             $attacker_extra_points = self::get_extra_points_for_attacker($hit, $points);
             $new_attacker_points = $attacker_points + $attacker_extra_points;
             /** update attacker points */
             theme_custom_point::update_user_points($attacker_id, $new_attacker_points);
             /** update target points */
             theme_custom_point::update_user_points($target_id, $new_target_points);
             $target_name = '<a href="' . theme_cache::get_author_posts_url($target_id) . '" target="_blank" class="author">' . esc_html($target->display_name) . '</a>';
             /**
              * hit target
              */
             if ($hit) {
                 $output['msg'] = sprintf(___('Bombing successfully! Your bomb hit %1$s, you got %2$s %3$s. Target remaining %4$s %3$s.'), $target_name, '<strong class="plus">+' . $attacker_extra_points . '</strong>', theme_custom_point::get_point_name(), $new_target_points);
                 /**
                  * miss target
                  */
             } else {
                 $output['msg'] = sprintf(___('Unlucky! %1$s miss your attack, you lost %2$s %3$s and remaining %4$s %3$s.'), $target_name, '<strong class="mins">' . $attacker_extra_points . '</strong>', theme_custom_point::get_point_name(), $new_attacker_points);
             }
             $output['hit'] = $hit;
             $output['status'] = 'success';
             /**
              * set times
              */
             self::set_times(self::get_times() + 1);
             die(theme_features::json_format($output));
         default:
             die(theme_features::json_format(['status' => 'error', 'code' => 'invaild_type_param', 'msg' => ___('Sorry, type param is invaild.')]));
     }
 }
Esempio n. 19
0
 private static function process_post()
 {
     $output = [];
     $ctb = isset($_POST['ctb']) && is_array($_POST['ctb']) ? array_filter($_POST['ctb']) : null;
     /** check ctb object */
     if (empty($ctb)) {
         $output['status'] = 'error';
         $output['code'] = 'invaild_ctb_param';
         $output['msg'] = ___('Invaild contribution param.');
         die(theme_features::json_format($output));
     }
     $edit_post_id = isset($_POST['post-id']) && is_numeric($_POST['post-id']) ? (int) $_POST['post-id'] : 0;
     $edit_again = false;
     /**
      * check edit
      */
     if ($edit_post_id != 0) {
         /** set edit again */
         $edit_again = true;
         //self::set_once_published($edit_post_id);
         /**
          * check post exists
          */
         $old_post = theme_cache::get_post($edit_post_id);
         if (!$old_post || $old_post->post_type !== 'post' || !self::in_edit_post_status($old_post->post_status)) {
             die(theme_features::json_format(['status' => 'error', 'code' => 'post_not_exist', 'msg' => ___('Sorry, the post does not exist.')]));
         }
         /**
          * check post author is myself
          */
         if ($old_post->post_author != theme_cache::get_current_user_id()) {
             die(theme_features::json_format(['status' => 'error', 'code' => 'post_not_exist', 'msg' => ___('Sorry, you are not the post author, can not edit it.')]));
         }
         /**
          * check post edit lock status
          */
         $lock_user_id = self::wp_check_post_lock($edit_post_id);
         if ($lock_user_id) {
             die(theme_features::json_format(['status' => 'error', 'code' => 'post_not_exist', 'msg' => ___('Sorry, the post does not exist.')]));
         }
     }
     /**
      * post title
      */
     $post_title = isset($ctb['post-title']) && is_string($ctb['post-title']) ? trim($ctb['post-title']) : null;
     if (!$post_title) {
         $output['status'] = 'error';
         $output['code'] = 'invaild_post_title';
         $output['msg'] = ___('Please write the post title.');
         die(theme_features::json_format($output));
     }
     /**
      * post excerpt
      */
     $post_excerpt = isset($ctb['post-excerpt']) && is_string($ctb['post-excerpt']) ? trim($ctb['post-excerpt']) : null;
     /**
      * post content
      */
     $post_content = isset($ctb['post-content']) && is_string($ctb['post-content']) ? trim($ctb['post-content']) : null;
     if (!$post_content) {
         $output['status'] = 'error';
         $output['code'] = 'invaild_post_content';
         $output['msg'] = ___('Please write the post content.');
         die(theme_features::json_format($output));
     }
     /**
      * check thumbnail cover
      */
     $thumbnail_id = isset($ctb['thumbnail-id']) && is_numeric($ctb['thumbnail-id']) ? (int) $ctb['thumbnail-id'] : null;
     if (!$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));
     }
     /**
      * cats
      */
     if ($edit_post_id == 0) {
         /** new post */
         $cat_ids = isset($ctb['cats']) && is_array($ctb['cats']) ? $ctb['cats'] : null;
         if (is_null_array($cat_ids)) {
             $output['status'] = 'error';
             $output['code'] = 'invaild_cat_id';
             $output['msg'] = ___('Please select a category.');
             die(theme_features::json_format($output));
         }
         /** edit post */
     } else {
         /**
          * get all cats
          */
         $cat_id = isset($ctb['cat']) && is_numeric($ctb['cat']) ? (int) $ctb['cat'] : null;
         if (empty($cat_id)) {
             $output['status'] = 'error';
             $output['code'] = 'invaild_cat_id';
             $output['msg'] = ___('Please select a category.');
             die(theme_features::json_format($output));
         }
         $cat_ids = [];
         theme_features::get_all_cats_by_child($cat_id, $cat_ids);
     }
     /**
      * tags
      */
     $tags = isset($ctb['tags']) && is_array($ctb['tags']) ? array_filter($ctb['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('publish_posts')) {
         $post_status = 'publish';
     } else {
         $post_status = 'pending';
     }
     /*****************************
      * PASS ALL, WRITE TO DB
      *****************************/
     /** edit post */
     if ($edit_post_id != 0) {
         $post_status = self::get_update_post_status($old_post->post_status);
         $post_id = wp_update_post(['ID' => $edit_post_id, 'post_title' => $post_title, 'post_status' => $post_status, 'post_type' => $old_post->post_type, 'post_excerpt' => fliter_script($post_excerpt), 'post_content' => fliter_script($post_content), 'post_category' => $cat_ids, 'tags_input' => $tags], true);
         /**
          * insert post
          */
     } else {
         $post_id = wp_insert_post(['post_title' => $post_title, 'post_excerpt' => fliter_script($post_excerpt), 'post_content' => fliter_script($post_content), 'post_status' => $post_status, 'post_author' => theme_cache::get_current_user_id(), 'post_category' => $cat_ids, 'tags_input' => $tags], true);
     }
     /**
      * check error
      */
     if (is_wp_error($post_id)) {
         $output['status'] = 'error';
         $output['code'] = $post_id->get_error_code();
         $output['msg'] = $post_id->get_error_message();
         die(theme_features::json_format($output));
     }
     /** end post error */
     /** set post thumbnail */
     set_post_thumbnail($post_id, $thumbnail_id);
     /**
      * set attachment parent
      */
     $attach_ids = isset($ctb['attach-ids']) && is_array($ctb['attach-ids']) ? array_map('intval', array_filter($ctb['attach-ids'])) : null;
     if ($attach_ids) {
         /** set attachment post parent */
         foreach ($attach_ids as $attach_id) {
             $post = theme_cache::get_post($attach_id);
             if (!$post || $post->post_type !== 'attachment') {
                 continue;
             }
             wp_update_post(['ID' => $attach_id, 'post_parent' => $post_id]);
         }
     }
     /** end set post thumbnail */
     /**
      * if new post
      */
     if ($edit_post_id == 0) {
         /**
          * pending status
          */
         if ($post_status === 'pending') {
             $output['status'] = 'success';
             $output['msg'] = ___('Your post submitted successful, it will be published after approve in a while.');
             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="javascript:location.href=location.href;">' . ___('countinue to write a new post') . '</a>');
             /**
              * add point
              */
             if ($edit_again && 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'));
             }
             /** end point */
         }
         /** end post status */
     } else {
         $output['status'] = 'success';
         if ($old_post->post_status == 'publish') {
             $output['msg'] = ___('Your post has updated successful.') . ' <a href="' . theme_cache::get_permalink($post_id) . '" target="_blank">' . ___('Views it now') . '</a>';
         } else {
             $output['msg'] = ___('Your post has updated successful.');
         }
         die(theme_features::json_format($output));
     }
     /** end post edit */
     die(theme_features::json_format($output));
 }
Esempio n. 20
0
 public static function process()
 {
     $output = [];
     theme_features::check_referer();
     theme_features::check_nonce();
     $type = isset($_GET['type']) && is_string($_GET['type']) ? $_GET['type'] : null;
     $post_id = isset($_POST['post-id']) && is_numeric($_POST['post-id']) ? (int) $_POST['post-id'] : null;
     if (!$post_id) {
         $output['status'] = 'error';
         $output['code'] = 'invaild_post_id';
         $output['msg'] = ___('Invaild post id param.');
         die(theme_features::json_format($output));
     }
     $post = theme_cache::get_post($post_id);
     if (!$post || $post->post_type !== 'post') {
         die(theme_features::json_format(['status' => 'error', 'code' => 'post_not_exist', 'msg' => ___('Post does not exist.')]));
     }
     /**
      * check user logged
      */
     if (!theme_cache::is_user_logged_in()) {
         $output['status'] = 'error';
         $output['code'] = 'need_login';
         $output['msg'] = '<a href="' . wp_login_url(theme_cache::get_permalink($post->ID)) . '" title="' . ___('Go to log-in') . '">' . ___('Sorry, please log-in.') . '</a>';
         die(theme_features::json_format($output));
     }
     $rater_id = theme_cache::get_current_user_id();
     switch ($type) {
         /**
          * incr point
          */
         case 'incr':
             /**
              * points
              */
             $points = isset($_POST['points']) && is_numeric($_POST['points']) ? (int) $_POST['points'] : null;
             if (!in_array($points, self::get_point_values())) {
                 $output['status'] = 'error';
                 $output['code'] = 'invaild_point_value';
                 $output['msg'] = ___('Invaild point value.');
                 die(theme_features::json_format($output));
             }
             /**
              * incr post raters
              */
             $post_raters = self::incr_post_raters($post_id, $rater_id, $points);
             if ($post_raters !== true) {
                 die(theme_features::json_format($post_raters));
             } else {
                 /**
                  * incr post points
                  */
                 $points_count = self::incr_post_points_count($post_id, $points);
                 if (!$points_count) {
                     $output['status'] = 'error';
                     $output['code'] = 'error_incr_points_count';
                     $output['msg'] = ___('Sorry, system can not increase post points count.');
                     die(theme_features::json_format($output));
                 }
                 /**
                  * incr rater posts
                  */
                 $rater_posts = self::incr_rater_posts($post_id, $rater_id, $points);
                 if ($rater_posts !== true) {
                     $output['status'] = 'error';
                     $output['code'] = 'error_incr_rater_posts';
                     $output['msg'] = ___('System can not increase rater posts.');
                     die(theme_features::json_format($output));
                 }
                 /**
                  * increase post author points
                  */
                 theme_custom_point::incr_user_points($post->post_author, $points);
                 /**
                  * add point history for rater
                  */
                 self::add_history_for_rater($post_id, $rater_id, $points);
                 /**
                  * add point history for post author
                  */
                 self::add_history_for_post_author($post_id, $rater_id, $points);
                 /**
                  * decrease rater points
                  */
                 theme_custom_point::decr_user_points($rater_id, $points);
                 /**
                  * success
                  */
                 $output['status'] = 'success';
                 $output['points'] = (int) self::get_post_points_count($post_id);
                 $output['msg'] = ___('Operation successful, thank you for your participation.');
                 die(theme_features::json_format($output));
             }
             break;
         default:
             $output['status'] = 'error';
             $output['code'] = 'invaild_type';
             $output['msg'] = ___('Invaild type param.');
             die(theme_features::json_format($output));
     }
     die(theme_features::json_format($output));
 }
Esempio n. 21
0
 public static function process()
 {
     $output = [];
     /**
      * nonce
      */
     $nonce = theme_features::create_nonce();
     /**
      * sign-type
      */
     $sign_type = isset($_REQUEST['sign-type']) ? $_REQUEST['sign-type'] : null;
     $opt = self::get_options();
     switch ($sign_type) {
         /**
          * sina
          */
         case 'weibo':
         case 'sina':
             $url = urlencode(theme_features::get_process_url(array('action' => 'isos_cb', 'sina' => 'set-auth', 'uri' => isset($_SERVER["HTTP_REFERER"]) && strpos($_SERVER['HTTP_REFERER'], theme_cache::home_url()) === 0 ? $_SERVER["HTTP_REFERER"] : home_url(), 'nonce' => $nonce)));
             $url = add_query_arg(array('sina' => 'get-auth', 'akey' => base64_encode(authcode(self::get_sina_config('akey'), 'encode')), 'skey' => base64_encode(authcode(self::get_sina_config('skey'), 'encode')), 'uri' => $url, 'state' => $nonce), self::$open_url);
             header('Location: ' . $url);
             die(___('Redirecting, please wait...'));
             /**
              * qq
              */
         /**
          * qq
          */
         case 'qq':
             include __DIR__ . '/inc/qq/qqConnectAPI.php';
             $qc = new theme_open_sign\inc\qq\QC(self::get_qc_config());
             //var_dump($qc);exit;
             /** go to login page */
             $qc->qq_login();
             die(___('Redirecting, please wait...'));
         default:
     }
     die(theme_features::json_format($output));
 }