/** * Theme respond */ public static function theme_respond() { global $post; ?> <div id="respond" class="panel"> <a href="javascript:;" id="cancel-comment-reply-link" class="none" title="<?php echo ___('Cancel reply'); ?> ">×</a> <div class="content"> <div class="page-tip" id="respond-loading-ready"> <?php echo status_tip('loading', ___('Loading, please wait...')); ?> </div> <p id="respond-must-login" class="well hide-on-logged none"> <?php echo sprintf(___('You must be %s to post a comment.'), '<a href="' . esc_url(wp_login_url(theme_cache::get_permalink($post->ID))) . '#respond' . '"><strong>' . ___('log-in') . '</strong></a>'); ?> </p> <form id="commentform" action="javascript:;" method="post" class="comment-form media none" > <div class="media"> <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="<?php echo $post->ID; ?> "> <input type="hidden" name="comment_parent" id="comment_parent" value="0"> <div class="media-left hidden-phone"> <img id="respond-avatar" src="<?php echo theme_functions::$avatar_placeholder; ?> " alt="avatar" class="media-object avatar" width="100" height="100"> </div> <div class="media-body"> <?php /** * for visitor */ $req = theme_cache::get_option('require_name_email'); ?> <!-- author name --> <div id="area-respond-visitor" class="row"> <div class="g-tablet-1-2"> <div class="form-group"> <input type="text" class="form-control" name="author" id="comment-form-author" placeholder="<?php echo ___('Nickname'); echo $req ? ' * ' : null; ?> " <?php echo $req ? ' required ' : null; ?> title="<?php echo ___('Whats your nickname?'); ?> " > </div><!-- /.form-group --> </div><!-- /.g-tablet-1-2 --> <!-- author email --> <div class="g-tablet-1-2"> <div class="form-group"> <input type="email" class="form-control" name="email" id="comment-form-email" placeholder="<?php echo ___('Email'); echo $req ? ' * ' : null; ?> " <?php echo $req ? ' required ' : null; ?> title="<?php echo ___('Whats your Email?'); ?> " > </div><!-- /.form-group --> </div><!-- /.g-tablet-1-2 --> </div><!-- /.row --> <div class="form-group form-group-textarea"> <textarea name="comment" id="comment-form-comment" class="form-control" rows="3" placeholder="<?php echo ___('Hi, have something to say?'); ?> " title="<?php echo ___('Nothing to say?'); ?> " required ></textarea> </div> <div class="form-group btn-group-submit"> <?php /** * theme comment emotion pop btn */ if (class_exists('theme_comment_emotion') && (theme_comment_emotion::is_enabled('kaomoji') || theme_comment_emotion::is_enabled('img'))) { theme_comment_emotion::display_frontend('pop'); } ?> <?php /** * theme comment emotion */ if (class_exists('theme_comment_emotion') && (theme_comment_emotion::is_enabled('kaomoji') || theme_comment_emotion::is_enabled('img'))) { theme_comment_emotion::display_frontend('pop-btn'); } ?> <button type="submit" class="submit btn btn-success" title="<?php echo ___('Post comment'); ?> "> <i class="fa fa-check"></i> <?php echo ___('Post comment'); ?> </button> </div><!-- .form-group --> </div><!-- /.media-body --> </div><!-- /.media --> </form> </div> </div> <?php }
/** * Get comment pages count * * @param array $comments * @return int Max comment pages number * @version 1.0.1 */ public static function get_comment_pages_count($comments) { static $count = null; if ($count === null) { $count = get_comment_pages_count($comments, theme_cache::get_option('comments_per_page'), theme_cache::get_option('thread_comments')); } return $count; }
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)); }
public static function cache_request(array $output = []) { if (isset($_GET[self::$iden]) && is_array($_GET[self::$iden])) { $get = $_GET[self::$iden]; $post_id = isset($get['post-id']) && is_string($get['post-id']) ? (int) $get['post-id'] : null; $type = isset($get['type']) && is_string($get['type']) ? $get['type'] : null; switch ($type) { case 'get-comments': if (!$post_id) { return $output; } $post = theme_cache::get_post($post_id); $pages = theme_features::get_comment_pages_count(self::get_comments(['post_id' => $post->ID])); /** * cpage */ if (isset($get['capge']) && is_numeric($get['capge'])) { $cpage = (int) $get['capge']; } else { $cpage = theme_cache::get_option('default_comments_page') == 'newest' ? $pages : 1; } if (!theme_cache::is_user_logged_in()) { $commenter = wp_get_current_commenter(); $user_name = $commenter['comment_author']; $user_url = $commenter['comment_author_url']; $avatar_url = theme_cache::get_avatar_url($commenter['comment_author_email']); $user_email = $commenter['comment_author_email']; } else { global $current_user; get_currentuserinfo(); $user_name = $current_user->display_name; $user_url = theme_cache::get_author_posts_url($current_user->ID); $avatar_url = theme_cache::get_avatar_url($current_user->ID); } $output[self::$iden] = ['comments' => self::get_comments_list($post_id, $cpage), 'count' => $post ? $post->comment_count : 0, 'pages' => $pages, 'cpage' => $cpage, 'logged' => theme_cache::is_user_logged_in(), 'registration' => theme_cache::get_option('comment_registration'), 'user-name' => esc_html($user_name), 'user-url' => esc_url($user_url), 'avatar-url' => $avatar_url]; if (isset($user_email)) { $output[self::$iden]['user-email'] = $user_email; } break; } } return $output; }
<img class="avatar" src="<?php echo esc_url($avatar); ?> " alt="avatar"> <?php } ?> <h3><?php echo ___('Account register'); ?> </h3> </div> <div class="content"> <?php if (theme_cache::get_option('users_can_register')) { ?> <form action="javascript:;" id="fm-sign-register" > <div class="form-group"> <div class="input-group"> <label for="sign-nickname" class="addon"><i class="fa fa-user fa-fw"></i></label> <input name="user[nickname]" type="text" class="form-control" id="sign-nickname" placeholder="<?php echo sprintf(___('Your nickname, at least %d length'), theme_custom_sign::$min_display_name_length); ?> " title="<?php echo sprintf(___('Please type nickname, at least %d length'), theme_custom_sign::$min_display_name_length); ?> " required minlength="<?php echo theme_custom_sign::$min_display_name_length; ?> " tabindex="1" autofocus >