function widget($args = [], $instance = []) { $instance = array_merge(['title' => ___('User point rank'), 'total_number' => 100, 'rand_number' => 12], $instance); if ((int) $instance['total_number'] === 0 || (int) $instance['rand_number'] === 0) { return false; } echo $args['before_widget']; echo $args['before_title']; ?> <i class="fa fa-bar-chart"></i> <?php echo $instance['title']; ?> <?php echo $args['after_title']; $query = new WP_User_Query(['meta_key' => theme_custom_point::$user_meta_key['point'], 'orderby' => 'meta_value_num', 'order' => 'desc', 'number' => (int) $instance['total_number'], 'fields' => 'ID']); $users = $query->get_results(); $count = count($users); if ($count < 2) { ?> <div class="content"> <div class="page-tip"><?php echo status_tip('info', ___('No matched user yet.')); ?> </div> </div> <?php } else { /** * rand */ if ($instance['rand_number'] > $count) { $instance['rand_number'] = $count; } $rand_users = (array) array_rand($users, $instance['rand_number']); ?> <div class="content"> <div class="user-lists row"> <?php $user = null; foreach ($rand_users as $k) { theme_functions::the_user_list(['user_id' => $users[$k], 'extra' => 'point', 'extra_title' => sprintf(__x('%s %s', 'eg. 20 points'), '%', theme_custom_point::get_point_name())]); } ?> </div> </div> <?php } unset($query, $users, $rand_users); echo $args['after_widget']; }
/** * My statistics */ public static function my_statistics() { $current_user_id = theme_cache::get_current_user_id(); ?> <div class="panel"> <div class="heading"> <i class="fa fa-pie-chart"></i> <?php echo ___('My statistics'); ?> </div> <div class="content"> <a class="media" href="<?php echo theme_custom_user_settings::get_tabs('history')['url']; ?> " title="<?php echo ___('Views my histories'); ?> "> <div class="media-left"> <img class="media-object" src="<?php echo theme_custom_point::get_point_img_url(); ?> " alt=""> </div> <div class="media-body"> <h4 class="media-heading"><strong class="total-point"><?php echo number_format(theme_custom_point::get_point($current_user_id)); ?> </strong></h4> </div> </a> <div class="row"> <!-- posts count --> <div class="g-phone-1-2"> <?php echo sprintf(___('My posts: %s'), '<a href="' . theme_cache::get_author_posts_url($current_user_id) . '">' . theme_custom_author_profile::get_count('works', $current_user_id) . '</a>'); ?> </div> <!-- comments count --> <div class="g-phone-1-2"> <?php echo sprintf(___('My comments: %s'), '<a href="' . theme_custom_author_profile::get_tabs('comments', $current_user_id)['url'] . '">' . theme_custom_author_profile::get_count('comments', $current_user_id) . '</a>'); ?> </div> <!-- followers count --> <div class="g-phone-1-2"> <?php echo sprintf(___('My followers: %s'), '<a href="' . theme_custom_author_profile::get_tabs('followers_count', $current_user_id)['url'] . '">' . theme_custom_author_profile::get_count('followers_count', $current_user_id) . '</a>'); ?> </div> <!-- following count --> <div class="g-tablet-1-2 g-desktop-1-3"> <?php echo sprintf(___('My following: %s'), '<a href="' . theme_custom_author_profile::get_tabs('following_count', $current_user_id)['url'] . '">' . theme_custom_author_profile::get_count('following_count', $current_user_id) . '</a>'); ?> </div> </div> </div> </div> <?php }
echo theme_custom_point::get_point_img_url(); ?> " alt=""> </div> <div class="media-body"> <h4 class="media-heading"> <strong class="total-point"><?php echo number_format(theme_custom_point::get_point(theme_cache::get_current_user_id())); ?> </strong> </h4> </div> </div> </div><!-- /.content --> <?php $history_list = theme_custom_point::get_history_list(array('posts_per_page' => 20)); if (empty($history_list)) { ?> <div class="content"> <div class="page-tip"><?php echo status_tip('info', ___('Your have not any history yet.')); ?> </div> </div><!-- /.content --> <?php } else { echo $history_list; } ?> </div> </div>
<p> <img id="bomb-attacker-avatar" src="<?php echo theme_cache::get_avatar_url($current_user->ID); ?> " alt="<?php echo ___('Avatar'); ?> " class="avatar" width="100" height="100" > </p> <p class="bomb-area-meta"> <?php echo $point_icon; ?> <strong id="bomb-attacker-points"> <?php echo theme_custom_point::get_point($current_user->ID); ?> </strong> </p> <p class="bomb-area-meta"> <?php echo esc_html($current_user->display_name); ?> </p> </div> </div><!-- .g-tablet-2-5 --> <div class="g-tablet-1-5 bomb-area-points"> <h4><?php echo ___('Bomb number'); ?>
" alt="point-icon" width="16" height="16"> <span id="point-count"><?php echo theme_custom_point::get_point(theme_cache::get_current_user_id()); ?> </span><span id="modify-count"></span> </span> </div> <div class="form-group"> <?php $boxes = theme_point_lottery::get_box(); if (empty($boxes)) { echo status_tip('info', ___('No any lottery yet.')); } else { foreach ($boxes as $k => $box) { if ($box['type'] === 'point') { $icon = '<img src="' . theme_custom_point::get_point_img_url() . '" alt="icon" width="16" height="16">'; } else { $icon = '<i class="fa fa-yelp fa-fw"></i>'; } ?> <input type="radio" class="lottery-item" name="id" id="lottery-item-<?php echo $k; ?> " data-target="lottery-box-<?php echo $k; ?> " value="<?php echo $k; ?> " required > <label id="lottery-box-<?php
/** * list noti be-bomb */ public static function list_noti_be_bomb($noti) { if ($noti['type'] !== 'be-bomb') { return false; } if ($noti['hit']) { $points = '<strong class="label label-success">' . $noti['points'] . '</strong>'; } else { $points = '<strong class="label label-danger">+' . $noti['points'] . '</strong>'; } if (class_exists('number_user_nicename')) { $fight_back_url = self::get_tabs('bomb', $noti['attacker-id'] + number_user_nicename::$prefix_number)['url']; } else { $fight_back_url = self::get_tabs('bomb', $noti['attacker-id'])['url']; } ?> <div class="media"> <div class="media-left"> <a href="<?php theme_cache::get_author_posts_url($noti['attacker-id']); ?> "> <img src="<?php echo theme_cache::get_avatar_url($noti['attacker-id']); ?> " class="avatar media-object" alt="avatar" width="60" height="60"> </a> </div> <div class="media-body"> <h4 class="media-heading"> <a class="label label-default" href="<?php echo self::get_tabs('bomb')['url']; ?> "><i class="fa fa-<?php echo self::get_tabs('bomb')['icon']; ?> "></i> <?php echo ___('Bomb world'); ?> </a> <?php echo $points; ?> <?php theme_custom_point::the_time($noti); ?> <?php if ($noti['hit']) { ?> <a class="fight-back btn btn-danger btn-xs" href="<?php echo $fight_back_url; ?> " target="_blank"><strong><?php echo ___('It is time to fight back'); ?> <i class="fa fa-external-link"></i></strong></a> <?php } ?> </h4> <div class="excerpt"> <p> <?php $attacker_name = theme_cache::get_the_author_meta('display_name', $noti['attacker-id']); $attacker_name = '<a href="' . theme_cache::get_author_posts_url($noti['attacker-id']) . '" target="_blank">' . $attacker_name . '</a>'; if ($noti['hit']) { echo sprintf(___('%1$s bombed you and hit. You lost %2$s %3$s.'), $attacker_name, '<strong>' . (0 - abs($noti['points'])) . '</strong>', theme_custom_point::get_point_name()); } else { echo sprintf(___('%1$s bombed you but miss! You got %2$s %3$s.'), $attacker_name, '<strong>+' . abs($noti['points']) . '</strong>', theme_custom_point::get_point_name()); } ?> </p> </div> </div><!-- /.media-body --> </div><!-- /.media --> <?php }
/** * Echo the user list within loop * * @param array $args * @return * @version 1.0.2 */ public static function the_user_list(array $args) { $args = array_merge(['classes' => 'g-phone-1-3', 'user_id' => null, 'extra_title' => '', 'extra' => 'point', 'target' => theme_functions::$link_target], $args); /** * extra point value */ switch ($args['extra']) { /** * user point */ case 'point': if (class_exists('theme_custom_point')) { $point_value = theme_custom_point::get_point($args['user_id']); } break; /** * user fav be_count */ /** * user fav be_count */ case 'fav': if (class_exists('custom_post_fav')) { $point_value = custom_post_fav::get_user_be_fav_count($args['user_id']); } break; /** * user posts count */ /** * user posts count */ case 'posts': if (class_exists('theme_custom_author_profile')) { $point_value = theme_custom_author_profile::get_count('works', $args['user_id']); } else { $point_value = count_user_posts($args['user_id']); } break; default: $point_value = null; } if (!empty($args['extra_title']) && $point_value) { $args['extra_title'] = str_replace('%', $point_value, $args['extra_title']); } $display_name = theme_cache::get_the_author_meta('display_name', $args['user_id']); $avatar_url = theme_cache::get_avatar_url($args['user_id']); ?> <div class="user-list <?php echo $args['classes']; ?> "> <a href="<?php echo theme_cache::get_author_posts_url($args['user_id']); ?> " title="<?php echo $display_name; ?> " target="<?php echo $args['target']; ?> " > <div class="avatar-container"> <img src="<?php echo theme_functions::$avatar_placeholder; ?> " data-src="<?php echo $avatar_url; ?> " alt="<?php echo $display_name; ?> " class="avatar"> </div> <h3 class="author"><?php echo $display_name; ?> </h3> <?php if ($args['extra']) { ?> <div class="extra"> <span class="<?php echo $args['extra']; ?> " title="<?php echo $args['extra_title']; ?> "> <?php echo number_format($point_value); ?> </span> </div> <?php } /** end args extra */ ?> </a> </div> <?php }
public static function list_history_signin_daily($history) { if ($history['type'] !== 'signin-daily') { return false; } ?> <li class="list-group-item"> <?php theme_custom_point::the_list_icon('user'); ?> <?php self::the_point_sign(self::get_point_value('signin-daily')); ?> <span class="history-text"> <?php echo ___('Log-in daily reward.'); ?> </span> <?php self::the_time($history); ?> </li> <?php }
<?php if (theme_custom_point::get_point($author) > 0) { if (class_exists('theme_custom_point_bomb')) { ?> <a href="<?php echo theme_custom_point_bomb::get_tabs('bomb', get_the_author_meta('nicename', $author))['url']; ?> "> <i class="fa fa-bomb"></i> <?php echo theme_custom_point::get_point($author); ?> </a> <?php } else { echo theme_custom_point::get_point($author); } } else { ?> 0 <?php } ?> </td> </tr> <?php } ?> <!-- pm --> <?php if (class_exists('theme_custom_pm')) {
function widget($args, $instance) { global $post; $author_id = $post->post_author; echo $args['before_widget']; /** * author profile page url */ if (class_exists('theme_custom_author_profile')) { $author_url = theme_custom_author_profile::get_tabs('profile', $author_id)['url']; } else { $author_url = theme_cache::get_author_posts_url($author_id); } $description = theme_cache::get_the_author_meta('description', $author_id); ?> <div id="widget-author-card" class="widget-container content"> <a href="<?php echo $author_url; ?> " class="author-link" title="<?php echo ___('Views the author information detail'); ?> "> <?php echo theme_cache::get_avatar($author_id, 100); ?> <h3 class="author-card-name"> <?php echo theme_cache::get_the_author_meta('display_name', $author_id); ?> </h3> <?php if (class_exists('theme_custom_author_profile')) { ?> <small class="label label-<?php echo theme_custom_author_profile::get_roles($author_id)['label']; ?> "><?php echo theme_custom_author_profile::get_roles($author_id)['name']; ?> </small> <?php } ?> </a><!-- ./author-link --> <p class="author-card-description" title="<?php echo $description; ?> " > <?php if (empty($description)) { echo ___('The author is lazy, nothing writes here.'); } else { echo $description; } ?> </p> <?php if (class_exists('theme_custom_author_profile')) { ?> <div class="author-card-meta-links"> <!-- works count --> <a class="tooltip" href="<?php echo theme_custom_author_profile::get_tabs('works', $author_id)['url']; ?> " title="<?php echo ___('Views author posts'); ?> " target="_blank"> <span class="tx"><i class="fa fa-fw fa-<?php echo theme_custom_author_profile::get_tabs('works', $author_id)['icon']; ?> "></i></span> <span class="count"><?php echo (int) theme_custom_author_profile::get_tabs('works', $author_id)['count']; ?> </span> </a> <!-- comments count --> <a class="tooltip" href="<?php echo theme_custom_author_profile::get_tabs('comments', $author_id)['url']; ?> " title="<?php echo ___('Views author comments'); ?> " target="_blank"> <span class="tx"><i class="fa fa-fw fa-<?php echo theme_custom_author_profile::get_tabs('comments', $author_id)['icon']; ?> "></i></span> <span class="count"><?php echo (int) theme_custom_author_profile::get_tabs('comments', $author_id)['count']; ?> </span> </a> <!-- point --> <?php if (class_exists('theme_custom_point_bomb')) { if (class_exists('number_user_nicename')) { $target_id = number_user_nicename::$prefix_number + $author_id; } else { $target_id = $author_id; } ?> <!-- followers count --> <a class="tooltip" href="<?php echo theme_custom_point_bomb::get_tabs('bomb', $target_id)['url']; ?> " rel="nofollow" title="<?php echo ___('Bomb!'); ?> " target="_blank"> <span class="tx"><i class="fa fa-fw fa-bomb"></i></span> <span class="count"><?php echo theme_custom_point::get_point($author_id); ?> </span> </a> <?php } ?> <!-- pm --> <?php if (class_exists('theme_custom_pm')) { ?> <a target="_blank" class="tooltip" href="<?php echo theme_custom_pm::get_user_pm_url($author_id); ?> " title="<?php echo ___('Send a private message.'); ?> "> <span class="tx"><i class="fa fa-<?php echo theme_custom_pm::get_tabs('pm')['icon']; ?> "></i></span><span class="count"><?php echo __x('P.M.', 'Widget author card PM.'); ?> </span> </a> <?php } ?> </div> <?php } ?> </div> <?php echo $args['after_widget']; }
public static function list_noti($meta) { if ($meta['type'] !== self::$type_key) { return; } global $post; $post = theme_cache::get_post($meta['post-id']); setup_postdata($post); ?> <div class="media"> <div class="media-left"> <img src="<?php echo theme_functions::$thumbnail_placeholder; ?> " alt="<?php echo ___('Preview image'); ?> " data-src="<?php echo theme_functions::get_thumbnail_src($post->ID); ?> " width="60" height="60" class="post-thumbnail media-object avatar"> </div> <div class="media-body"> <h4 class="media-heading"> <span class="label label-default"> <i class="fa fa-eye"></i> <?php echo ___('Per hundred views'); ?> </span> <strong class="label label-danger">+<?php echo $meta['points']; ?> </strong> <?php theme_notification::the_time($meta); ?> </h4> <div class="excerpt"> <p> <?php echo sprintf(___('Your post %1$s reached per hundred views, %2$s %3$s. Views are %4$s.'), '<a href="' . theme_cache::get_permalink($post->ID) . '" target="_blank">' . theme_cache::get_the_title($post->ID) . ' <i class="fa fa-external-link"></i></a>', '<strong>+' . $meta['points'] . '</strong>', theme_custom_point::get_point_name(), '<strong>' . $meta['views'] . '</strong>'); ?> </p> </div> </div><!-- /.media-body --> </div><!-- /.media --> <?php wp_reset_postdata(); }
echo theme_custom_point::get_point_img_url(); ?> " alt="" width="16" height="16"> <?php } else { ?> <i class="fa fa-diamond fa-fw"></i> <?php } ?> <?php echo number_format(theme_custom_point::get_point(theme_cache::get_current_user_id())); ?> <?php echo theme_custom_point::get_point_name(); ?> </a> <?php } ?> </div> <ul> <?php $account_navs = apply_filters('account_navs', []); if (!empty($account_navs)) { $active_tab = get_query_var('tab'); foreach ($account_navs as $k => $v) { $active_class = $k === $active_tab ? ' active ' : null; ?> <li class="<?php
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)); }
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)); }
public static function post_btn($post_id) { $point_img = theme_custom_point::get_point_img_url(); $point_values = array_filter((array) self::get_point_values()); $count_point_values = count($point_values); $default_point_value = $point_values[0]; if ($count_point_values > 1) { sort($point_values); } ?> <div class="meta meta-post-point"> <a href="javascript:;" class="post-point-btn" title="<?php echo sprintf(__x('Rate %d %s.', 'E.g. Rate 3 points'), $default_point_value, theme_custom_point::get_point_name()); ?> " data-post-id="<?php echo $post_id; ?> " data-points="<?php echo $default_point_value; ?> " > <div id="post-point-number-<?php echo $post_id; ?> " class="number"><?php echo number_format((int) self::get_post_points_count($post_id)); ?> </div> <div class="tx"><?php echo ___('Rate it'); ?> </div> </a> <?php if (!wp_is_mobile() && $count_point_values > 1) { ?> <div class="box"> <?php foreach ($point_values as $v) { $class = $v == $default_point_value ? 'active' : null; ?> <a href="javascript:;" class="post-point-btn <?php echo $class; ?> " title="<?php echo sprintf(__x('Rate %d %s.', 'E.g. Rate 3 points'), $v, theme_custom_point::get_point_name()); ?> " data-post-id="<?php echo $post_id; ?> " data-points="<?php echo $v; ?> " ><?php echo $v; ?> </a><?php } ?> </div> <?php } ?> </div> <?php }
public static function list_history_save_avatar($history) { if ($history['type'] !== 'save-avatar') { return false; } ?> <li class="list-group-item"> <?php theme_custom_point::the_list_icon('github-alt'); ?> <?php theme_custom_point::the_point_sign(0 - abs(theme_custom_point::get_point_value('save-avatar'))); ?> <span class="history-text"> <?php echo ___('You modified your avatar.'); ?> </span> <?php theme_custom_point::the_time($history); ?> </li> <?php }
$disabled = null; if (class_exists('theme_custom_point')) { $consume_points = abs(theme_custom_point::get_point_value('save-avatar')); $user_points = theme_custom_point::get_point($current_user->ID); if ($consume_points != 0) { ?> <div class="page-tip"> <?php /** * not enough points, can not modify */ if ($consume_points > $user_points) { $disabled = 'disabled'; echo status_tip('info', sprintf(___('You have %1$s %2$s, You need to collect %3$s %2$s to modify the avatar.'), '<strong>' . $user_points . '</strong>', theme_custom_point::get_point_name(), '<strong>' . ($consume_points - $user_points) . '</strong>')); } else { echo status_tip('info', sprintf(___('You have %1$s %2$s, modify avatar will consume %3$s %2$s.'), '<strong>' . $user_points . '</strong>', theme_custom_point::get_point_name(), '<strong>' . $consume_points . '</strong>')); } ?> </div> <?php } } ?> <form id="fm-change-avatar" class="user-form form-horizontal" method="post" action="javascript:;"> <fieldset <?php echo $disabled; ?> > <legend class="label label-<?php echo $disabled ? 'default' : 'success'; ?>
/** * list special-event */ public static function list_noti_special_event($noti) { if ($noti['type'] !== 'special-event') { return false; } ?> <div class="media"> <div class="media-left"> <i class="fa fa-bullhorn"></i> </div> <div class="media-body"> <h4 class="media-heading"> <span class="label label-default"><i class="fa fa-info-circle"></i> <?php echo ___('Special event'); ?> </span> <?php echo ___('Special event'); ?> <?php if ($noti['point'] > 0) { $tip_type = 'success'; $sign = '+'; } else { $tip_type = 'danger'; $sign = ''; } ?> <span class="label label-<?php echo $tip_type; ?> "> <?php echo theme_custom_point::get_point_name(); ?> <?php echo $sign, $noti['point']; ?> </label> </h4> <div class="excerpt"><p><?php echo $noti['event']; ?> </p></div> </div> </div> <?php }