예제 #1
0
    function widget($args, $instance)
    {
        $instance = array_merge(self::get_default_options(), $instance);
        echo $args['before_widget'];
        $comments = get_comments(array('status' => 'approve', 'number' => isset($instance['number']) ? (int) $instance['number'] : 6, 'type' => 'comment'));
        if (!empty($instance['title'])) {
            echo $args['before_title'];
            ?>
			<i class="fa fa-comments-o"></i> 
			<?php 
            echo $instance['title'];
            echo $args['after_title'];
        }
        if (!empty($comments)) {
            global $comment;
            $comment_bak = $comment;
            ?>
			<ul class="list-group">
				<?php 
            foreach ($comments as $comment) {
                /**
                 * cache
                 */
                static $caches = [];
                /** author_name */
                if (!isset($caches['author_name'][$comment->comment_author])) {
                    $caches['author_name'][$comment->comment_author] = esc_html(get_comment_author());
                }
                /** avatar placeholder */
                if (!isset($caches['avatar_placeholder'])) {
                    $caches['avatar_placeholder'] = theme_functions::$avatar_placeholder;
                }
                /** comment text */
                $comment_text = str_sub(strip_tags(preg_replace('/<img[^>]+>/i', '[' . ___('Image') . ']', get_comment_text($comment->comment_ID))), 35);
                ?>
<li class="list-group-item">
	<a class="media tooltip top" href="<?php 
                echo theme_cache::get_permalink($comment->comment_post_ID);
                ?>
#comment-<?php 
                echo $comment->comment_ID;
                ?>
" title="<?php 
                echo theme_cache::get_the_title($comment->comment_post_ID);
                ?>
">
		<div class="media-left">
			<img class="avatar media-object" data-src="<?php 
                echo esc_url(theme_cache::get_avatar_url($comment));
                ?>
" src="<?php 
                echo $caches['avatar_placeholder'];
                ?>
" alt="<?php 
                echo $caches['author_name'][$comment->comment_author];
                ?>
" width="<?php 
                echo self::$avatar_size;
                ?>
" height="<?php 
                echo self::$avatar_size;
                ?>
"/>
		</div>
		<div class="media-body">
			<h4 class="media-heading">
				<span class="author"><?php 
                echo $caches['author_name'][$comment->comment_author];
                ?>
</span>
				<time datetime="<?php 
                echo get_comment_time('c');
                ?>
">
					<small><?php 
                echo friendly_date(get_comment_time('U'));
                ?>
</small>
				</time>
			</h4>
			<div class="text"><?php 
                echo $comment_text;
                ?>
</div>
		</div>
	</a>
</li>
				<?php 
            }
            ?>
			</ul>
			<?php 
            $comment = $comment_bak;
        } else {
            ?>
			<div class="content">
				<div class="page-tip"><?php 
            echo status_tip('info', ___('No any comment yet.'));
            ?>
</div>
			</div>
		<?php 
        }
        echo $args['after_widget'];
    }
예제 #2
0
 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));
 }
예제 #3
0
 /**
  * Get post excerpt and limit string lenght
  *
  * @param int $len Limit string
  * @param string $extra The more string
  * @return string
  * @version 1.0.0
  */
 public static function get_post_excerpt($len = 120, $extra = '...')
 {
     static $caches = [];
     global $post;
     if (isset($caches[$post->ID])) {
         return $caches[$post->ID];
     }
     $excerpt = get_the_excerpt();
     if ($excerpt) {
         $caches[$post->ID] = str_sub($excerpt, $len, $extra);
     } else {
         $caches[$post->ID] = str_sub(get_the_content(), $len, $extra);
     }
     unset($excerpt);
     return $caches[$post->ID];
 }
예제 #4
0
    public static function rank_img_content($args = [])
    {
        global $post;
        $args = array_merge(['classes' => '', 'lazyload' => true, 'excerpt' => true, 'index' => false, 'target' => theme_functions::$link_target], $args);
        $post_title = theme_cache::get_the_title($post->ID);
        $excerpt = get_the_excerpt();
        if (!empty($excerpt)) {
            $excerpt = esc_html($excerpt);
        }
        $thumbnail_real_src = theme_functions::get_thumbnail_src($post->ID);
        ?>
		<div class="list-group-item <?php 
        echo $args['classes'];
        ?>
">
			<div class="row">
				<div class="g-tablet-1-6">
					<a href="<?php 
        echo theme_cache::get_permalink($post->ID);
        ?>
" title="<?php 
        echo $post_title;
        ?>
" target="<?php 
        echo $args['target'];
        ?>
" class="thumbnail-container">
						<?php 
        if ($args['lazyload'] === true) {
            ?>
							<img class="thumbnail" src="<?php 
            echo theme_functions::$thumbnail_placeholder;
            ?>
" data-src="<?php 
            echo $thumbnail_real_src;
            ?>
" alt="<?php 
            echo $post_title;
            ?>
" width="<?php 
            echo theme_functions::$thumbnail_size[1];
            ?>
" height="<?php 
            echo theme_functions::$thumbnail_size[2];
            ?>
">
						<?php 
        } else {
            ?>
							<img class="thumbnail" src="<?php 
            echo $thumbnail_real_src;
            ?>
" alt="<?php 
            echo $post_title;
            ?>
" width="<?php 
            echo theme_functions::$thumbnail_size[1];
            ?>
" height="<?php 
            echo theme_functions::$thumbnail_size[2];
            ?>
">
						<?php 
        }
        ?>
					</a>
				</div>
				<div class="g-tablet-5-6">
					<h3 class="media-heading">
						<a href="<?php 
        echo theme_cache::get_permalink($post->ID);
        ?>
" title="<?php 
        echo $post_title;
        ?>
" target="<?php 
        echo $args['target'];
        ?>
" ><?php 
        echo $post_title;
        ?>
</a>
					</h3>
					<?php 
        /**
         * output excerpt
         */
        if ($args['excerpt'] === true) {
            ?>
						<div class="excerpt"><?php 
            echo str_sub(strip_tags($excerpt), 200);
            ?>
</div>
					<?php 
        }
        ?>
					<div class="extra">
						<div class="metas row">
							<!-- author -->
							<a class="author meta g-phone-1-2 g-tablet-1-4 g-desktop-1-5" href="<?php 
        echo theme_cache::get_author_posts_url($post->post_author);
        ?>
" target="<?php 
        echo $args['target'];
        ?>
" >
								<img src="<?php 
        echo theme_functions::$avatar_placeholder;
        ?>
" data-src="<?php 
        echo theme_cache::get_avatar_url($post->post_author);
        ?>
" alt="avatar" width="16" height="16" class="avatar"> 
								<?php 
        echo theme_cache::get_the_author_meta('display_name', $post->post_author);
        ?>
							</a>
							
							<!-- category -->
							<div class="category meta g-phone-1-2 g-tablet-1-4 g-desktop-1-5">
								<?php 
        $cats = get_the_category_list('<i class="split"> / </i> ');
        if (!empty($cats)) {
            ?>
									<i class="fa fa-folder-open"></i> 
									<?php 
            echo $cats;
            ?>
								<?php 
        }
        ?>
							</div>

							<!-- views -->
							<?php 
        if (class_exists('theme_post_views') && theme_post_views::is_enabled()) {
            ?>
								<div class="view meta g-phone-1-2 g-tablet-1-4 g-desktop-1-5">
									<i class="fa fa-play-circle"></i> 
									<?php 
            echo theme_post_views::get_views();
            ?>
								</div>
							<?php 
        }
        ?>

							<?php 
        if (!wp_is_mobile()) {
            ?>
								<div class="comments meta g-phone-1-2 g-tablet-1-4 g-desktop-1-5">
									<i class="fa fa-comment"></i> 
									<?php 
            echo (int) $post->comment_count;
            ?>
								</div>
							<?php 
        }
        ?>
							
							<?php 
        /**
         * point
         */
        if (class_exists('custom_post_point')) {
            ?>
								<div class="point meta g-phone-1-2 g-tablet-1-4 g-desktop-1-5">
									<i class="fa fa-paw"></i>
									<?php 
            echo (int) custom_post_point::get_post_points_count($post->ID);
            ?>
								</div>
								<?php 
        }
        ?>


						</div><!-- /.metas -->
					</div>
					<?php 
        if ($args['index']) {
            ?>
						<i class="index"><?php 
            echo $args['index'];
            ?>
</i>
					<?php 
        }
        ?>
					
				</div>
			</div>
		</div>
		<?php 
    }