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])); }
/** * Post form * * @return * @version 1.0.0 */ function post_form($post_id = null) { $edit = false; $post_title = null; $post_content = null; $post_excerpt = null; /** * edit */ if (is_numeric($post_id)) { /** * check post exists */ global $post; $post = theme_cache::get_post($post_id); if (!$post || !theme_custom_contribution::in_edit_post_status($post->post_status) || $post->post_type !== 'post') { ?> <div class="page-tip"><?php echo status_tip('error', ___('Sorry, the post does not exist.')); ?> </div> <?php wp_reset_postdata(); return false; } /** * check post category in collection category */ if (class_exists('theme_custom_collection') && !empty(theme_custom_collection::get_cat_ids())) { foreach (get_the_category($post_id) as $v) { if (in_array($v->term_id, theme_custom_collection::get_cat_ids())) { ?> <div class="page-tip"><?php echo status_tip('error', ___('Sorry, collection edits feature is not supported currently.')); ?> </div> <?php wp_reset_postdata(); return false; } break; } } /** * check author */ if ($post->post_author != theme_cache::get_current_user_id()) { ?> <div class="page-tip"><?php echo status_tip('error', ___('Sorry, you are not the post author, can not edit it.')); ?> </div> <?php return false; wp_reset_postdata(); } setup_postdata($post); /** * check edit lock status */ $lock_user_id = theme_custom_contribution::wp_check_post_lock($post_id); if ($lock_user_id) { ?> <div class="page-tip"><?php echo status_tip('error', ___('Sorry, you can not edit this post now, because editor is editing. Please wait a minute...')); ?> </div> <?php return false; } $edit = true; $post_title = $post->post_title; $post_content = $post->post_content; $post_excerpt = stripslashes($post->post_excerpt); } ?> <?php echo theme_custom_contribution::get_des(); ?> <div id="fm-ctb-loading" class="page-tip"><?php echo status_tip('loading', ___('Loading, please wait...')); ?> </div> <form action="javascript:;" id="fm-ctb" class="form-horizontal" hidden> <div class="form-group"> <label for="ctb-title" class="g-tablet-1-6 control-label"> <?php echo ___('Post title'); ?> </label> <div class="g-tablet-5-6"> <input type="text" name="ctb[post-title]" class="form-control" id="ctb-title" placeholder="<?php echo ___('Post title (require)'); ?> " title="<?php echo ___('Post title must to write'); ?> " value="<?php echo esc_attr($post_title); ?> " required autofocus > </div> </div> <!-- post excerpt --> <div class="form-group"> <label for="ctb-excerpt" class="g-tablet-1-6 control-label"> <?php echo ___('Post excerpt'); ?> </label> <div class="g-tablet-5-6"> <textarea name="ctb[post-excerpt]" id="ctb-excerpt" rows="3" class="form-control" placeholder="<?php echo ___('Your can write excerpt for describe the post, it will show every page nagination header.'); ?> "><?php echo $post_excerpt; ?> </textarea> </div> </div> <!-- post content --> <div class="form-group"> <div class="g-tablet-1-1"> <label for="ctb-content" > <?php echo ___('Post content'); ?> </label> <?php wp_editor($post_content, 'ctb-content', ['textarea_name' => 'ctb[post-content]', 'drag_drop_upload' => false, 'teeny' => false, 'media_buttons' => false, 'editor_class' => 'form-control']); ?> </div> </div> <!-- upload image --> <div class="form-group"> <div class="g-tablet-1-6 control-label"> <i class="fa fa-image"></i> <?php echo ___('Upload preview image'); ?> </div> <div class="g-tablet-5-6"> <div id="ctb-file-area"> <div class="" id="ctb-file-btn"> <i class="fa fa-upload"></i> <?php echo ___('Select or Drag images'); ?> <input type="file" id="ctb-file" multiple > </div> </div> <!-- upload progress --> <div id="ctb-file-progress-container" class="progress"> <div id="ctb-file-progress" class="progress-bar progress-bar-success progress-bar-striped active"></div> </div> <!-- file tool --> <div id="ctb-file-tool" class="row"> <div class="g-tablet-1-2"> <!-- batch insert --> <a href="javascript:;" id="ctb-batch-insert-btn" class="btn btn-primary btn-block"> <i class="fa fa-plug"></i> <?php echo ___('Batch insert images to content'); ?> </a> </div> <div class="g-tablet-1-2"> <select id="ctb-split-number" class="form-control" title="<?php echo ___('How many images to split with next-page tag?'); ?> "> <option value="0"><?php echo ___('Do not use next-page tag'); ?> </option> <?php for ($i = 1; $i <= 10; ++$i) { ?> <option value="<?php echo $i; ?> "><?php echo sprintf(___('%d image(s) / page'), $i); ?> </option> <?php } ?> </select> </div> </div> <!-- file completion --> <div id="ctb-file-completion"></div> <!-- files --> <div id="ctb-files" class="row"></div> </div> </div> <!-- storage --> <?php if (class_exists('theme_custom_storage') && theme_custom_storage::is_enabled()) { ?> <div class="form-group theme_custom_storage-group"> <div class="g-tablet-1-6 control-label"> <i class="fa fa-cloud-download"></i> <?php echo ___('Storage link'); ?> </div> <div class="g-tablet-5-6"> <?php echo theme_custom_storage::display_frontend_contribution($post_id); ?> </div> </div> <?php /** * end theme_custom_storage */ } ?> <!-- cats --> <div class="form-group"> <div class="g-tablet-1-6 control-label"> <i class="fa fa-folder-open"></i> <?php echo ___('Category'); ?> </div> <div class="g-tablet-5-6" id="ctb-cat-container"> <?php if ($edit) { $selected_cat_id = 0; $cats = get_the_category($post->ID); if (isset($cats[0]->term_id)) { $selected_cat_id = $cats[0]->term_id; } foreach ($cats as $cat) { if ($cat->parent != 0) { $selected_cat_id = $cat->term_id; } } wp_dropdown_categories(['id' => 'ctb-cat', 'name' => 'ctb[cat]', 'class' => 'form-control', 'selected' => $selected_cat_id, 'show_option_none' => ___('Select category'), 'hierarchical' => true, 'hide_empty' => false, 'include' => (array) theme_custom_contribution::get_cat_ids()]); } ?> </div> </div> <!-- tags --> <div class="form-group"> <div class="g-tablet-1-6 control-label"> <i class="fa fa-tags"></i> <?php echo ___('Pop. tags'); ?> </div> <div class="g-tablet-5-6"> <div class="checkbox-select"> <?php $tags_args = ['orderby' => 'count', 'order' => 'desc', 'hide_empty' => 0, 'number' => theme_custom_contribution::get_options('tags-number') ? theme_custom_contribution::get_options('tags-number') : 16]; $tags_ids = theme_custom_contribution::get_options('tags'); if (empty($tag_ids)) { $tags = get_tags($tags_args); } else { $tags = get_tags(['include' => implode($tags_ids), 'orderby' => 'count', 'order' => 'desc', 'hide_empty' => 0]); } /** * edit */ if ($edit) { $exist_tags = []; $post_tags = get_the_tags($post->ID); if ($post_tags) { foreach ($post_tags as $v) { $v->selected = true; array_unshift($tags, $v); } } } foreach ($tags as $tag) { if ($edit) { if (isset($exist_tags[$tag->term_id])) { continue; } else { $exist_tags[$tag->term_id] = 1; } } $tag_name = esc_html($tag->name); ?> <label class="ctb-tag" for="ctb-tags-<?php echo $tag->term_id; ?> "> <input class="ctb-preset-tag" type="checkbox" id="ctb-tags-<?php echo $tag->term_id; ?> " name="ctb[tags][]" value="<?php echo $tag_name; ?> " hidden <?php echo isset($tag->selected) ? 'checked' : null; ?> > <span class="label label-default"> <?php echo $tag_name; ?> </span> </label> <?php } ?> </div> </div> </div> <!-- custom tags --> <div class="form-group"> <div class="g-tablet-1-6 control-label"> <i class="fa fa-tag"></i> <?php echo ___('Custom tags'); ?> </div> <div class="g-tablet-5-6"> <div class="row"> <?php for ($i = 0; $i <= 3; ++$i) { ?> <div class="g-phone-1-2 g-tablet-1-4"> <input id="ctb-custom-tag-<?php echo $i; ?> " class="ctb-custom-tag form-control" type="text" name="ctb[tags][]" placeholder="<?php echo sprintf(___('Custom tag %d'), $i + 1); ?> " > </div> <?php } ?> </div> </div> </div> <!-- source --> <?php if (class_exists('theme_custom_post_source') && theme_custom_post_source::is_enabled()) { if ($edit) { $post_source_meta = theme_custom_post_source::get_post_meta($post->ID); } else { $post_source_meta = null; } ?> <div class="form-group"> <div class="g-tablet-1-6 control-label"> <i class="fa fa-truck"></i> <?php echo ___('Source'); ?> </div> <div class="g-tablet-5-6"> <label class="radio-inline" for="theme_custom_post_source-source-original"> <input type="radio" name="theme_custom_post_source[source]" id="theme_custom_post_source-source-original" value="original" class="theme_custom_post_source-source-radio" <?php echo !isset($post_source_meta['source']) || $post_source_meta['source'] === 'original' ? 'checked' : null; ?> target="theme_custom_post_source-input-original" > <?php echo ___('Original'); ?> </label> <label class="radio-inline" for="theme_custom_post_source-source-reprint"> <input type="radio" name="theme_custom_post_source[source]" id="theme_custom_post_source-source-reprint" value="reprint" class="theme_custom_post_source-source-radio" <?php echo isset($post_source_meta['source']) && $post_source_meta['source'] === 'reprint' ? 'checked' : null; ?> target="theme_custom_post_source-input-reprint" > <?php echo ___('Reprint'); ?> </label> <div class="row theme_custom_post_source-inputs" id="theme_custom_post_source-input-reprint" > <div class="g-tablet-1-2"> <div class="input-group"> <label class="addon" for="theme_custom_post_source-reprint-url"> <i class="fa fa-link"></i> </label> <input type="url" class="form-control" name="theme_custom_post_source[reprint][url]" id="theme_custom_post_source-reprint-url" placeholder="<?php echo ___('The source of work URL, includes http://'); ?> " title="<?php echo ___('The source of work URL, includes http://'); ?> " value="<?php echo isset($post_source_meta['reprint']['url']) ? $post_source_meta['reprint']['url'] : null; ?> " > </div> </div> <div class="g-tablet-1-2"> <div class="input-group"> <label class="addon" for="theme_custom_post_source-reprint-author"> <i class="fa fa-user"></i> </label> <input type="text" class="form-control" name="theme_custom_post_source[reprint][author]" id="theme_custom_post_source-reprint-author" placeholder="<?php echo ___('Author'); ?> " title="<?php echo ___('Author'); ?> " value="<?php echo isset($post_source_meta['reprint']['author']) ? esc_attr($post_source_meta['reprint']['author']) : null; ?> " > </div> </div> </div> </div> </div> <?php } /** end theme_custom_post_source */ ?> <!-- submit --> <div class="form-group"> <div class="g-tablet-1-6"> <a href="javascript:;" id="ctb-quick-save" class="btn btn-block btn-default btn-lg" title="<?php echo ___('The post data will be saved automatically per minute in your current borwser, you can also save it now manually.'); ?> "> <i class="fa fa-save"></i> <?php echo ___('Quick save'); ?> </a> </div> <div class="g-tablet-5-6"> <button type="submit" class="btn btn-lg btn-success btn-block submit" data-loading-text="<?php echo ___('Sending, please wait...'); ?> "> <i class="fa fa-check"></i> <?php echo $edit ? ___('Update') : ___('Submit'); ?> </button> <input type="hidden" id="ctb-post-id" name="post-id" value="<?php echo $edit ? $post->ID : 0; ?> "> <input type="hidden" name="type" value="post"> </div> </div> </form> <?php wp_reset_postdata(); }
/** * get_thumbnail_src * * @return * @version 1.1.0 */ public static function get_thumbnail_src($post_id, $size = 'thumbnail', $placeholder = null) { if (!$placeholder) { $placeholder = self::$thumbnail_placeholder; } if (!$size) { $size = self::$thumbnail_size[0]; } $src = null; if (has_post_thumbnail($post_id)) { $src = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $size)[0]; } /** get img src from post content */ if (!$src) { $post = theme_cache::get_post($post_id); $src = $post ? get_img_source($post->post_content) : false; unset($post); } if (!$src) { $src = $placeholder; } return esc_url($src); }
/** * Get post thumbnail src, if the post have not thumbnail, then get the first image from post content. * * @version 1.1.0 * @param int $post_id The post ID, default is global $post->ID * @param string $size Thumbnail size * @return string Placeholder img url */ public static function get_thumbnail_src($post_id = null, $size = 'thumbnail', $replace_img = null) { static $caches = []; if (!$post_id) { global $post; $post_id = $post->ID; } $cache_id = $post_id . $size . $replace_img; if (isset($caches[$cache_id])) { return $caches[$cache_id]; } $src = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $size); if (!empty($src)) { $caches[$cache_id] = $src[0]; return $caches[$cache_id]; } /** * have not thumbnail, get first img from post content */ $post = theme_cache::get_post($post_id); $caches[$cache_id] = get_img_source($post->post_content); if ($caches[$cache_id]) { return $caches[$cache_id]; } if ($replace_img) { return $replace_img; } return null; }
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)); } }
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; }
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(); }
/** * action_add_history_core_post_reply * * @param int $comment_id Comment ID * @version 1.0.0 */ public static function action_add_history_core_post_reply($comment_id) { $comment = get_comment($comment_id); /** * return if visitor comment */ if ($comment->user_id == 0) { return false; } $post = theme_cache::get_post($comment->comment_post_ID); /** post author id */ $post_author_id = $post->post_author; /** do not add history for myself post */ if ($post->post_author == $comment->user_id) { return false; } $meta = array('type' => 'post-reply', 'comment-id' => $comment_id, 'timestamp' => current_time('timestamp')); /** * add to history */ self::add_history($post->post_author, $meta); /** * update point */ /** * if not post type, return false */ if ($post->post_type !== 'post') { return false; } $old_point = self::get_point($post->post_author); update_user_meta($post->post_author, self::$user_meta_key['point'], $old_point + (int) self::get_point_value('post-reply')); }
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 get_post_attachs($post_id) { $post = theme_cache::get_post($post_id); if (!$post) { return false; } return get_children(['post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'posts_per_page' => -1, 'orderby' => 'ID', 'order' => 'ASC']); }
/** * Start the element output. * * @see Walker_Nav_Menu::start_el() * @since 3.0.0 * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args Not used. * @param int $id Not used. */ public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) { global $_wp_nav_menu_max_depth; $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth; ob_start(); $item_id = esc_attr($item->ID); $removed_args = array('action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce'); $original_title = ''; if ('taxonomy' == $item->type) { $original_title = get_term_field('name', $item->object_id, $item->object, 'raw'); if (is_wp_error($original_title)) { $original_title = false; } } elseif ('post_type' == $item->type) { $original_object = theme_cache::get_post($item->object_id); $original_title = theme_cache::get_the_title($original_object->ID); } $classes = array('menu-item menu-item-depth-' . $depth, 'menu-item-' . esc_attr($item->object), 'menu-item-edit-' . (isset($_GET['edit-menu-item']) && $item_id == $_GET['edit-menu-item'] ? 'active' : 'inactive')); $title = $item->title; if (!empty($item->_invalid)) { $classes[] = 'menu-item-invalid'; /* translators: %s: title of menu item which is invalid */ $title = sprintf(__('%s (Invalid)'), $item->title); } elseif (isset($item->post_status) && 'draft' == $item->post_status) { $classes[] = 'pending'; /* translators: %s: title of menu item in draft status */ $title = sprintf(__('%s (Pending)'), $item->title); } $title = !isset($item->label) || '' == $item->label ? $title : $item->label; $submenu_text = ''; if (0 == $depth) { $submenu_text = 'style="display: none;"'; } ?> <li id="menu-item-<?php echo $item_id; ?> " class="<?php echo implode(' ', $classes); ?> "> <dl class="menu-item-bar"> <dt class="menu-item-handle"> <span class="item-title"><span class="menu-item-title"><?php echo esc_html($title); ?> </span> <span class="is-submenu" <?php echo $submenu_text; ?> ><?php _e('sub item'); ?> </span></span> <span class="item-controls"> <span class="item-type"><?php echo esc_html($item->type_label); ?> </span> <span class="item-order hide-if-js"> <a href="<?php echo wp_nonce_url(add_query_arg(array('action' => 'move-up-menu-item', 'menu-item' => $item_id), remove_query_arg($removed_args, admin_url('nav-menus.php'))), 'move-menu_item'); ?> " class="item-move-up"><abbr title="<?php esc_attr_e('Move up'); ?> ">↑</abbr></a> | <a href="<?php echo wp_nonce_url(add_query_arg(array('action' => 'move-down-menu-item', 'menu-item' => $item_id), remove_query_arg($removed_args, admin_url('nav-menus.php'))), 'move-menu_item'); ?> " class="item-move-down"><abbr title="<?php esc_attr_e('Move down'); ?> ">↓</abbr></a> </span> <a class="item-edit" id="edit-<?php echo $item_id; ?> " title="<?php esc_attr_e('Edit Menu Item'); ?> " href="<?php echo isset($_GET['edit-menu-item']) && $item_id == $_GET['edit-menu-item'] ? admin_url('nav-menus.php') : add_query_arg('edit-menu-item', $item_id, remove_query_arg($removed_args, admin_url('nav-menus.php#menu-item-settings-' . $item_id))); ?> "><?php _e('Edit Menu Item'); ?> </a> </span> </dt> </dl> <div class="menu-item-settings" id="menu-item-settings-<?php echo $item_id; ?> "> <?php if ('custom' == $item->type) { ?> <p class="field-url description description-wide"> <label for="edit-menu-item-url-<?php echo $item_id; ?> "> <?php _e('URL'); ?> <br /> <input type="text" id="edit-menu-item-url-<?php echo $item_id; ?> " class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?> ]" value="<?php echo esc_attr($item->url); ?> " /> </label> </p> <?php } ?> <p class="description description-thin"> <label for="edit-menu-item-title-<?php echo $item_id; ?> "> <?php _e('Navigation Label'); ?> <br /> <input type="text" id="edit-menu-item-title-<?php echo $item_id; ?> " class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?> ]" value="<?php echo esc_attr($item->title); ?> " /> </label> </p> <p class="description description-thin"> <label for="edit-menu-item-attr-title-<?php echo $item_id; ?> "> <?php _e('Title Attribute'); ?> <br /> <input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?> " class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?> ]" value="<?php echo esc_attr($item->post_excerpt); ?> " /> </label> </p> <p class="field-link-target description"> <label for="edit-menu-item-target-<?php echo $item_id; ?> "> <input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?> " value="_blank" name="menu-item-target[<?php echo $item_id; ?> ]"<?php checked($item->target, '_blank'); ?> /> <?php _e('Open link in a new window/tab'); ?> </label> </p> <!-- awesome icon --> <p class="description description-thin"> <label for="edit-menu-item-awesome-<?php echo $item_id; ?> "> <?php __e('Awesome icon'); ?> <a href="//fortawesome.github.io/Font-Awesome/icons" target="_blank" title="<?php echo ___('Views all icons'); ?> ">#<?php echo ___('ALL'); ?> </a> <br /> <input type="text" id="edit-menu-item-awesome-<?php echo $item_id; ?> " class="widefat edit-menu-item-awesome" name="menu-item-awesome[<?php echo $item_id; ?> ]" value="<?php echo $item->awesome; ?> " list="edit-menu-item-awesome-<?php echo $item_id; ?> -datalist"> <?php echo icon_option_list('edit-menu-item-awesome-' . $item_id . '-datalist'); ?> </label> </p><!-- /awesome icon --> <p class="field-css-classes description description-thin"> <label for="edit-menu-item-classes-<?php echo $item_id; ?> "> <?php _e('CSS Classes (optional)'); ?> <br /> <input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?> " class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?> ]" value="<?php echo esc_attr(implode(' ', $item->classes)); ?> " /> </label> </p> <!-- only show icon --> <p class="description description-thin field-hide-title"> <label for="edit-menu-item-hide-title-<?php echo $item_id; ?> "> <?php echo ___('Toggle navigation label'); ?> <br> <select id="edit-menu-item-hide-title-<?php echo $item_id; ?> " class="widefat edit-menu-item-hide-title" name="menu-item-hide-title[<?php echo $item_id; ?> ]" > <option value="-1"><?php echo ___('Show navigation label'); ?> </option> <option value="1" <?php echo isset($item->hide_title) && $item->hide_title == 1 ? 'select' : null; ?> ><?php echo ___('Hide navigation label'); ?> </option> </select> </label> </p><!-- /only show icon --> <p class="field-xfn description description-thin"> <label for="edit-menu-item-xfn-<?php echo $item_id; ?> "> <?php _e('Link Relationship (XFN)'); ?> <br /> <input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?> " class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?> ]" value="<?php echo esc_attr($item->xfn); ?> " /> </label> </p> <p class="field-description description description-wide"> <label for="edit-menu-item-description-<?php echo $item_id; ?> "> <?php _e('Description'); ?> <br /> <textarea id="edit-menu-item-description-<?php echo $item_id; ?> " class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?> ]"><?php echo esc_html($item->description); // textarea_escaped ?> </textarea> <span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?> </span> </label> </p> <p class="field-move hide-if-no-js description description-wide"> <label> <span><?php _e('Move'); ?> </span> <a href="#" class="menus-move menus-move-up" data-dir="up"><?php _e('Up one'); ?> </a> <a href="#" class="menus-move menus-move-down" data-dir="down"><?php _e('Down one'); ?> </a> <a href="#" class="menus-move menus-move-left" data-dir="left"></a> <a href="#" class="menus-move menus-move-right" data-dir="right"></a> <a href="#" class="menus-move menus-move-top" data-dir="top"><?php _e('To the top'); ?> </a> </label> </p> <div class="menu-item-actions description-wide submitbox"> <?php if ('custom' != $item->type && $original_title !== false) { ?> <p class="link-to-original"> <?php printf(__('Original: %s'), '<a href="' . esc_attr($item->url) . '">' . esc_html($original_title) . '</a>'); ?> </p> <?php } ?> <a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?> " href="<?php echo wp_nonce_url(add_query_arg(array('action' => 'delete-menu-item', 'menu-item' => $item_id), admin_url('nav-menus.php')), 'delete-menu_item_' . $item_id); ?> "><?php _e('Remove'); ?> </a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?> " href="<?php echo esc_url(add_query_arg(array('edit-menu-item' => $item_id, 'cancel' => time()), admin_url('nav-menus.php'))); ?> #menu-item-settings-<?php echo $item_id; ?> "><?php _e('Cancel'); ?> </a> </div> <input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?> ]" value="<?php echo $item_id; ?> " /> <input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?> ]" value="<?php echo esc_attr($item->object_id); ?> " /> <input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?> ]" value="<?php echo esc_attr($item->object); ?> " /> <input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?> ]" value="<?php echo esc_attr($item->menu_item_parent); ?> " /> <input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?> ]" value="<?php echo esc_attr($item->menu_order); ?> " /> <input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?> ]" value="<?php echo esc_attr($item->type); ?> " /> </div><!-- .menu-item-settings--> <ul class="menu-item-transport"></ul> <?php $output .= ob_get_clean(); }
if (empty($comments)) { ?> <div class="content"> <div class="page-tip"><?php echo status_tip('info', ___('No comment yet.')); ?> </div> </div> <?php } else { global $comment, $post; ?> <ul class="list-group"> <?php foreach ($comments as $comment) { $post = theme_cache::get_post($comment->comment_post_ID); $thumbnail_real_src = theme_functions::get_thumbnail_src($post->ID); ?> <li class="list-group-item"> <div class="media"> <div class="media-left"> <a href="<?php echo theme_cache::get_permalink($post->ID); ?> "> <img class="post-list-img" src="<?php echo theme_functions::$thumbnail_placeholder; ?> " data-src="<?php echo esc_url($thumbnail_real_src); ?>
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)); }
function ajax_process_image() { @error_reporting(0); // Don't break the JSON result header('Content-type: application/json'); $id = (int) $_REQUEST['id']; $image = theme_cache::get_post($id); if (!$image || 'attachment' != $image->post_type || 'image/' != substr($image->post_mime_type, 0, 6)) { die(json_encode(array('error' => sprintf(___('Failed resize: %s is an invalid image ID.'), esc_html($_REQUEST['id']))))); } if (!theme_cache::current_user_can($this->capability)) { $this->die_json_error_msg($image->ID, ___("Your user account doesn't have permission to resize images")); } $fullsizepath = get_attached_file($image->ID); if (false === $fullsizepath || !file_exists($fullsizepath)) { $this->die_json_error_msg($image->ID, sprintf(___('The originally uploaded image file cannot be found at %s'), '<code>' . esc_html($fullsizepath) . '</code>')); } @set_time_limit(900); // 5 minutes per image should be PLENTY $metadata = wp_generate_attachment_metadata($image->ID, $fullsizepath); if (is_wp_error($metadata)) { $this->die_json_error_msg($image->ID, $metadata->get_error_message()); } if (empty($metadata)) { $this->die_json_error_msg($image->ID, ___('Unknown failure reason.')); } // If this fails, then it just means that nothing was changed (old value == new value) wp_update_attachment_metadata($image->ID, $metadata); die(json_encode(array('success' => sprintf(___('"%1$s" (ID %2$s) was successfully resized in %3$s seconds.'), theme_cache::get_the_title($image->ID), $image->ID, timer_stop())))); }
public static function get_decode_post() { static $cache = null; if ($cache !== null) { return $cache; } $code = isset($_GET['code']) && is_string($_GET['code']) ? base64_decode($_GET['code']) : null; if (!$code) { $cache = false; return $cache; } $decode = authcode($code, 'decode'); if (!$decode) { $cache = false; return $cache; } $decode = json_decode($decode, true); if (!isset($decode['post-id'])) { $cache = false; return $cache; } $cache = theme_cache::get_post($decode['post-id']); return $cache; }
/** * 递增投币用户的文章 * * @param int $post_id Post id * @param int $user_id rater id * @param int $points $points * @return * @version 1.0.0 */ public static function incr_rater_posts($post_id, $rater_id, $points) { if (!is_numeric($post_id) || (int) $post_id === 0) { return ['status' => 'error', 'code' => 'invaild_post_id', 'msg' => ___('Invaild post id.')]; } if (!is_numeric($rater_id) || (int) $rater_id === 0) { return ['status' => 'error', 'code' => 'invaild_rater_id', 'msg' => ___('Invaild rater id.')]; } if (!is_numeric($points) || (int) $points === 0) { return ['status' => 'error', 'code' => 'invaild_point_value', 'msg' => ___('Invaild points value.')]; } $post = theme_cache::get_post($post_id); if (!$post) { return ['status' => 'error', 'code' => 'post_not_exist', 'msg' => ___('Post is not exist.')]; } $rater = get_user_by('id', $rater_id); if (!$rater) { return ['status' => 'error', 'code' => 'rater_not_exist', 'msg' => ___('Rater is not exist.')]; } $posts = (array) get_user_meta($rater_id, self::$user_meta_key['posts'], true); if (isset($posts[$post_id])) { return ['status' => 'error', 'code' => 'rated', 'msg' => ___('You had rated this post.')]; } $posts[$post_id] = $points; update_user_meta($rater_id, self::$user_meta_key['posts'], $posts); return true; }
/** * comment reply noti */ public static function action_add_noti_core_comment_reply($comment_id) { $comment = self::get_comment($comment_id); if ($comment->comment_parent == 0) { return false; } /** get post author */ $post_author_id = theme_cache::get_post($comment->comment_post_ID)->post_author; /** * if post author is current comment author, return */ //if($post_author_id == $comment->user_id) // return false; /** * get parent comment author */ $parent_comment_author_id = self::get_comment($comment->comment_parent)->user_id; /** * if parent comment author is visitor, return */ if ($parent_comment_author_id == 0) { return false; } /** * if parent comment author is current comment author, return */ if ($parent_comment_author_id == $comment->user_id) { return false; } /** * add noti for parent comment author */ $meta = array('id' => self::get_timestamp(true), 'type' => 'comment-reply', 'comment-id' => $comment->comment_ID, 'timestamp' => self::get_timestamp()); self::add_noti($parent_comment_author_id, $meta); }