public static function wp_title($title, $sep) { /** * check unread count */ if (theme_cache::is_user_logged_in()) { $unread_count = (int) self::get_count(array('type' => 'unread')); } else { $unread_count = 0; } if ($unread_count === 0) { if (!self::is_page()) { return $title; } if (self::get_tabs(get_query_var('tab'))) { $title = self::get_tabs(get_query_var('tab'))['text']; } } else { if (!self::is_page()) { return " ({$unread_count}) " . $title; } if (self::get_tabs(get_query_var('tab'))) { $title = " ({$unread_count}) " . self::get_tabs(get_query_var('tab'))['text']; } } return $title . $sep . theme_cache::get_bloginfo('name'); }
/** * frontend css */ public static function frontend_enqueue_css() { $frontend_css = theme_cache::is_user_logged_in() ? 'frontend-logged' : 'frontend'; $css = ['frontend' => ['deps' => ['awesome'], 'url' => theme_features::get_theme_css($frontend_css)], 'awesome' => ['deps' => [], 'url' => '//cdn.bootcss.com/font-awesome/4.4.0/css/font-awesome.min.css', 'version' => null]]; foreach ($css as $k => $v) { wp_enqueue_style($k, $v['url'], isset($v['deps']) ? $v['deps'] : [], self::get_version($v)); } }
public static function template_redirect() { if (!self::is_page()) { return false; } if (theme_cache::is_user_logged_in()) { $account_navs = apply_filters('account_navs', []); if (!isset($account_navs[get_query_var('tab')])) { wp_redirect(add_query_arg('tab', 'dashboard', self::get_url())); } } else { wp_redirect(theme_custom_sign::get_tabs('login', get_current_url())['url']); die; } }
public static function process() { $output = []; theme_features::check_referer(); theme_features::check_nonce(); $type = isset($_GET['type']) && is_string($_GET['type']) ? $_GET['type'] : null; $post_id = isset($_POST['post-id']) && is_numeric($_POST['post-id']) ? (int) $_POST['post-id'] : null; if (!$post_id) { $output['status'] = 'error'; $output['code'] = 'invaild_post_id'; $output['msg'] = ___('Invaild post id param.'); die(theme_features::json_format($output)); } $post = theme_cache::get_post($post_id); if (!$post || $post->post_type !== 'post') { die(theme_features::json_format(['status' => 'error', 'code' => 'post_not_exist', 'msg' => ___('Post does not exist.')])); } /** * check user logged */ if (!theme_cache::is_user_logged_in()) { $output['status'] = 'error'; $output['code'] = 'need_login'; $output['msg'] = '<a href="' . wp_login_url(theme_cache::get_permalink($post->ID)) . '" title="' . ___('Go to log-in') . '">' . ___('Sorry, please log-in.') . '</a>'; die(theme_features::json_format($output)); } $rater_id = theme_cache::get_current_user_id(); switch ($type) { /** * incr point */ case 'incr': /** * points */ $points = isset($_POST['points']) && is_numeric($_POST['points']) ? (int) $_POST['points'] : null; if (!in_array($points, self::get_point_values())) { $output['status'] = 'error'; $output['code'] = 'invaild_point_value'; $output['msg'] = ___('Invaild point value.'); die(theme_features::json_format($output)); } /** * incr post raters */ $post_raters = self::incr_post_raters($post_id, $rater_id, $points); if ($post_raters !== true) { die(theme_features::json_format($post_raters)); } else { /** * incr post points */ $points_count = self::incr_post_points_count($post_id, $points); if (!$points_count) { $output['status'] = 'error'; $output['code'] = 'error_incr_points_count'; $output['msg'] = ___('Sorry, system can not increase post points count.'); die(theme_features::json_format($output)); } /** * incr rater posts */ $rater_posts = self::incr_rater_posts($post_id, $rater_id, $points); if ($rater_posts !== true) { $output['status'] = 'error'; $output['code'] = 'error_incr_rater_posts'; $output['msg'] = ___('System can not increase rater posts.'); die(theme_features::json_format($output)); } /** * increase post author points */ theme_custom_point::incr_user_points($post->post_author, $points); /** * add point history for rater */ self::add_history_for_rater($post_id, $rater_id, $points); /** * add point history for post author */ self::add_history_for_post_author($post_id, $rater_id, $points); /** * decrease rater points */ theme_custom_point::decr_user_points($rater_id, $points); /** * success */ $output['status'] = 'success'; $output['points'] = (int) self::get_post_points_count($post_id); $output['msg'] = ___('Operation successful, thank you for your participation.'); die(theme_features::json_format($output)); } break; default: $output['status'] = 'error'; $output['code'] = 'invaild_type'; $output['msg'] = ___('Invaild type param.'); die(theme_features::json_format($output)); } die(theme_features::json_format($output)); }
public static function the_homebox(array $args = []) { if (!class_exists('theme_custom_homebox')) { return false; } $opt = array_filter((array) theme_custom_homebox::get_options()); /** * cache */ $device = wp_is_mobile() ? 'mobile' : 'desktop'; $sign_status = theme_cache::is_user_logged_in() ? 'login' : 'logout'; $cache_id = $device . $sign_status; $cache = (array) theme_custom_homebox::get_cache(); if (isset($cache[$cache_id])) { echo $cache[$cache_id]; unset($cache); return; } ob_start(); if (empty($opt)) { ?> <div class="panel"> <div class="content"> <div class="page-tip"><?php echo status_tip('info', ___('Please add some homebox.')); ?> </div> </div> </div> <?php return false; } global $post; static $lazyload_i = 0; foreach ($opt as $k => $v) { /** display type */ $display_type = isset($v['display-type']) ? $v['display-type'] : 'all'; /** for login */ if ($display_type === 'login' && !theme_cache::is_user_logged_in()) { continue; } /** for logout */ if ($display_type === 'logout' && theme_cache::is_user_logged_in()) { continue; } if (!isset($v['title']) || trim($v['title']) === '') { continue; } $title = esc_html($v['title']); $link = isset($v['link']) && !empty($v['link']) ? esc_url($v['link']) : false; ?> <div id="homebox-<?php echo $k; ?> " class="homebox panel mod"> <div class="heading"> <h2 class="title"> <span class="bg"> <?php if ($link) { ?> <a href="<?php echo $link; ?> " title="<?php echo sprintf(___('More about %s'), $title); ?> "> <?php } ?> <?php if (!empty($v['icon'])) { ?> <i class="fa fa-<?php echo $v['icon']; ?> "></i> <?php } ?> <?php echo $title; ?> <?php if ($link) { ?> </a> <?php } ?> </span> </h2> <div class="extra"> <?php if (!empty($v['keywords'])) { ?> <div class="keywords"> <?php if (wp_is_mobile()) { $keyword_i = 0; foreach (theme_custom_homebox::keywords_to_html($v['keywords']) as $kw) { if ($keyword_i == 3) { break; } ?> <a href="<?php echo esc_url($kw['url']); ?> "><?php echo $kw['name']; ?> </a> <?php ++$keyword_i; } } else { foreach (theme_custom_homebox::keywords_to_html($v['keywords']) as $kw) { ?> <a href="<?php echo esc_url($kw['url']); ?> "><?php echo $kw['name']; ?> </a> <?php } } ?> </div> <?php } ?> </div> </div> <div class="row"> <?php $query = new WP_Query(['category__in' => isset($v['cats']) ? $v['cats'] : [], 'posts_per_page' => isset($v['number']) ? (int) $v['number'] : 8, 'ignore_sticky_posts' => false]); if ($query->have_posts()) { $i = 0; foreach ($query->posts as $post) { setup_postdata($post); self::archive_card_sm(['classes' => $i <= 2 ? 'g-tablet-1-3' : 'g-tablet-1-4', 'lazyload' => wp_is_mobile() && $lazyload_i < 1 ? false : true, 'category' => false]); ++$i; } wp_reset_postdata(); } else { echo status_tip('info', ___('No data yet.')); } unset($query); ?> </div> <a href="<?php echo $link; ?> " class="below-more btn btn-block btn-default" target="<?php echo theme_functions::$link_target; ?> "><?php echo sprintf(___('More about %s'), $title); ?> <i class="fa fa-caret-right"></i></a> <?php /** * ad */ if (isset($v['ad']) && !empty($v['ad'])) { ?> <div class="homebox-ad"><?php echo stripslashes($v['ad']); ?> </div> <?php } ?> </div> <?php ++$lazyload_i; } /** end foreach */ $cache[$cache_id] = html_minify(ob_get_contents()); ob_end_clean(); theme_custom_homebox::set_cache($cache); echo $cache[$cache_id]; unset($cache); }
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 frontend_js_config(array $config) { if (theme_cache::is_user_logged_in() || !self::is_page()) { return $config; } $config[__CLASS__] = ['process_url' => theme_features::get_process_url(['action' => __CLASS__])]; return $config; }
public static function theme_comment($comment, $args, $depth) { global $post; $GLOBALS['comment'] = $comment; switch ($comment->comment_type) { default: $classes = ['media']; if (!empty($args['has_children'])) { $classes[] = 'parent'; } if ($comment->comment_approved == '0') { $classes[] = 'moderation'; } /** * post author checker */ if ($comment->user_id == $post->post_author) { $is_post_author = true; $classes[] = 'is-post-author'; } else { $is_post_author = false; } /** * check is my comment */ if ($comment->user_id != 0) { if (theme_cache::get_current_user_id() == $comment->user_id) { $classes[] = 'is-me'; } } /** * author url */ $author_url = get_comment_author_url(); if (!empty($author_url) && stripos($author_url, theme_cache::home_url()) === false) { $author_nofollow = ' rel="external nofollow" '; } else { $author_nofollow = null; } ?> <li <?php comment_class($classes); ?> id="comment-<?php echo $comment->comment_ID; ?> "> <div id="comment-body-<?php echo $comment->comment_ID; ?> " class="comment-body"> <?php if ($comment->comment_parent == 0) { ?> <div class="media-left"> <?php if ($author_url) { ?> <a href="<?php echo esc_url($author_url); ?> " class="avatar-link" target="_blank" <?php echo $author_nofollow; ?> > <?php echo theme_cache::get_avatar($comment, 50); ?> </a> <?php } else { echo theme_cache::get_avatar($comment, 50); } ?> </div><!-- /.media-left --> <?php } ?> <div class="media-body"> <div class="comment-content"> <?php comment_text(); ?> <?php if ($comment->comment_approved == '0') { ?> <div class="comment-awaiting-moderation"><?php echo status_tip('info', ___('Your comment is awaiting moderation.')); ?> </div> <?php } ?> </div> <h4 class="media-heading"> <span class="comment-meta-data author"> <?php if ($comment->comment_parent != 0) { echo theme_cache::get_avatar($comment, 50), ' '; } comment_author_link(); ?> </span> <time class="comment-meta-data time" datetime="<?php echo get_comment_time('c'); ?> "> <a href="<?php echo esc_url(get_comment_link($comment->comment_ID)); ?> "><?php echo friendly_date(get_comment_time('U')); ?> </a> </time> <?php if (!theme_cache::is_user_logged_in()) { /** * if needs register to comment */ if (theme_cache::get_option('comment_registration')) { static $reply_link; if (!$reply_link) { $reply_link = '<a rel="nofollow" class="comment-reply-login quick-login-btn" href="' . wp_login_url(theme_cache::get_permalink($comment->comment_post_ID)) . '">' . ___('Reply') . '</a>'; } } else { $reply_link = get_comment_reply_link(['add_below' => 'comment-body', 'depth' => $depth, 'max_depth' => $args['max_depth']], $comment, $post->ID); } } else { $reply_link = get_comment_reply_link(['add_below' => 'comment-body', 'depth' => $depth, 'max_depth' => $args['max_depth']], $comment, $post->ID); } $reply_link = preg_replace('/(href=)[^\\s]+/', '$1"javascript:;"', $reply_link); if (!empty($reply_link)) { ?> <span class="comment-meta-data comment-reply reply"> <?php echo $reply_link; ?> </span><!-- .reply --> <?php } ?> </h4> </div><!-- /.media-body --> </div><!-- /.comment-body --> <?php } }
/** * menu-header */ if (!wp_is_mobile()) { if (theme_cache::is_user_logged_in()) { theme_cache::wp_nav_menu(['theme_location' => 'menu-header-login', 'container' => 'nav', 'container_class' => 'menu-header', 'menu_class' => 'menu', 'menu_id' => 'menu-header', 'fallback_cb' => 'custom_navwalker::fallback', 'walker' => new custom_navwalker()]); } else { theme_cache::wp_nav_menu(['theme_location' => 'menu-header', 'container' => 'nav', 'container_class' => 'menu-header', 'menu_class' => 'menu', 'menu_id' => 'menu-header', 'fallback_cb' => 'custom_navwalker::fallback', 'walker' => new custom_navwalker()]); } } ?> <div class="tools"> <!-- account btn --> <?php if (theme_cache::is_user_logged_in()) { ?> <?php if (wp_is_mobile()) { ?> <a class="tool tool-avatar" href="javascript:;" data-mobile-target=".header-nav-account-menu" > <img class="avatar" width="32" height="32" src="<?php echo theme_cache::get_avatar_url(theme_cache::get_current_user_id()); ?> " alt="avatar"> </a> <?php } else { ?> <div class="tool tool-me"> <a href="<?php
public static function frontend_js_config() { if (theme_cache::is_user_logged_in() || !theme_cache::is_page(self::$page_slug)) { return false; } ?> seajs.use('<?php echo self::$iden; ?> ',function(m){ m.config.process_url = '<?php echo theme_features::get_process_url(array('action' => theme_quick_sign::$iden)); ?> '; m.config.lang.M00001 = '<?php echo esc_js(___('Loading, please wait...')); ?> '; m.config.lang.E00001 = '<?php echo esc_js(___('Sorry, server is busy now, can not respond your request, please try again later.')); ?> '; m.init(); }); <?php }
public static function filter_dynamic_request_process($output) { /** * signin daily */ if (!theme_cache::is_user_logged_in()) { return $output; } if (self::action_add_history_signin_daily() === true) { $point = (int) theme_options::get_options(__CLASS__)['points']['signin-daily']; $output['signin-daily'] = array('point' => $point, 'msg' => sprintf(___('Sign-in daily points: +%s'), $point)); } else { $output['signin-daily'] = false; } return $output; }