<?php global $current_user; get_currentuserinfo(); ?> <div class="panel"> <div class="content"> <?php /** * consume points to modify avatar */ $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
public static function get_max_times() { $times = (int) theme_custom_point::get_point_value('bomb-times'); return $times === 0 ? self::get_max_times_default() : $times; }
public static function get_point_values() { static $cache = null; if ($cache !== null) { return $cache; } $values = explode(',', theme_custom_point::get_point_value('post-swap')); if (!is_null_array($values)) { $cache = array_map(function ($v) { $v = trim($v); if (is_numeric($v)) { return $v; } }, $values); } else { $cache = self::get_point_values_default(); } return $cache; }
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 }
<?php global $current_user; get_currentuserinfo(); ?> <div class="panel"> <div class="content"> <?php /** * consume points to modify settings */ $disabled = null; if (class_exists('theme_custom_point')) { $consume_points = abs(theme_custom_point::get_point_value('save-settings')); $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 ($user_points - $consume_points < 0) { $disabled = 'disabled'; echo status_tip('info', sprintf(___('You have %1$s %2$s, You need to collect %3$s %2$s to modify the settings.'), '<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 settings will consume %3$s %2$s.'), '<strong>' . $user_points . '</strong>', theme_custom_point::get_point_name(), '<strong>' . $consume_points . '</strong>')); } ?> </div> <?php
public static function add_noti_views_per_hundred($post_id) { if (!class_exists('theme_notification')) { return; } $post = theme_cache::get_post($post_id); if (!$post) { return false; } $meta = ['type' => self::$type_key, 'timestamp' => self::get_timestamp(), 'post-id' => $post->ID, 'views' => self::get_views($post_id), 'points' => theme_custom_point::get_point_value(self::$type_key)]; theme_notification::add_noti($post->post_author, $meta); }
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)); }