This commit is contained in:
2024-05-20 15:37:46 +03:00
commit 00b7dbd0b7
10404 changed files with 3285853 additions and 0 deletions

View File

@ -0,0 +1,75 @@
<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Admin Pages Class
*
* Handles generic Admin functionailties
*
* @package Easy Post Views Count
* @since 1.0.0
*/
class Epvc_Admin {
public function __construct() {
add_action( 'admin_menu', array( $this, 'epvc_ltable_add_menu_page' ) );
add_action( 'admin_init', array($this, 'epvc_register_plugin_settings') );
}
/**
* Creat menu page
*
* Adding required menu pages and submenu pages
* to manage the plugin functionality
*
* @package Easy Post Views Count
* @since 1.0.0
*/
public function epvc_ltable_add_menu_page() {
$epvc_setting = add_menu_page( __( 'Easy Post Views Count', 'epvc' ), __( 'Easy Post Views Count', 'epvc' ), 'manage_options','epvc-settings', array($this, 'epvc_display_settings') , EPVC_PLUGIN_URL . '/images/icon.jpg' );
}
/**
* Includes Settings List
*
* Including File for Settings List
*
* @package Easy Post Views Count
* @since 1.0.0
*/
public function epvc_display_settings() {
include_once( EPVC_ADMIN_DIR . '/forms/epvc-settings.php' );
}
/**
* Register settings
*
* Register plugin settings
*
* @package Easy Post Views Count
* @since 1.0.0
*/
public function epvc_register_plugin_settings() {
register_setting( 'epvc-plugin-settings', 'epvc_settings', array($this, 'epvc_validate_settings_input') );
}
/**
* Validation and update
*
* Validate settings input adn update options
*
* @package Easy Post Views Count
* @since 1.0.0
*/
public function epvc_validate_settings_input( $input ) {
add_settings_error( 'epvc-notices', '', __( 'Settings have been saved successfully!.', 'epvc' ), 'updated' );
return $input;
}
}
return new Epvc_Admin();

View File

@ -0,0 +1,101 @@
<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Post count html
*
* The html markup for the post count
*
* @package Easy Post Views Count
* @since 1.0.0
*/
global $epvc_settings;
$args = array(
'public' => true
);
$post_types = get_post_types( $args, 'names', 'and' );
?>
<div class="wrap wpeob-settings">
<h1 class="wp-heading-inline"><?php esc_html_e( 'Easy post count settings', 'epvc' ); ?></h1>
<?php
// Print error messages
settings_errors(); ?>
<form method="post" id="epvc-settings-form" action="options.php">
<?php settings_fields( 'epvc-plugin-settings' ); ?>
<div class="metabox-holder">
<div class="meta-box-sortables ui-sortable">
<div class="postbox">
<div class="handlediv" title="<?php _e( 'Click to toggle', 'epvc' ); ?>"><br /></div>
<h3 class="hndle">
<span style='vertical-align: top;'><?php esc_html_e( 'Settings', 'epvc' ); ?></span>
</h3>
<div class="inside">
<table class="form-table fh-profile-upload-options">
<tr>
<th><label for="image"><?php _e('Enable for Post Types', 'epvc') ?></label></th>
<td>
<input type="hidden" name="epvc_settings[post_types]" value="no" class="regular-text" />
<?php foreach( $post_types as $post_type ){ ?>
<label><input type="checkbox" name="epvc_settings[post_types][<?php echo $post_type; ?>]" value="yes" class="regular-text" <?php if(!empty( $epvc_settings['post_types']) && $epvc_settings['post_types'] != 'no' && in_array( $post_type , array_keys($epvc_settings['post_types']) ) ) echo 'checked'; ?>/> <?php echo ucfirst($post_type); ?>
</label><br>
<?php } ?>
</td>
</tr>
<tr>
<th><label for="image"><?php _e('Display (Icon,Label)', 'epvc') ?></th>
<td>
<input type="hidden" name="epvc_settings[display_icon]" value="no" class="regular-text" />
<input type="hidden" name="epvc_settings[display_label]" value="no" class="regular-text" />
<label><input type="checkbox" name="epvc_settings[display_icon]" value="yes" class="regular-text" <?php if($epvc_settings['display_icon'] == 'yes' ) echo 'checked'; ?>/> <?php _e( 'Icon', 'epvc' ); ?></label>
<label><input type="checkbox" name="epvc_settings[display_label]" value="yes" class="regular-text" <?php if($epvc_settings['display_label'] == 'yes' ) echo 'checked'; ?>/> <?php _e( 'Label', 'epvc' ); ?></label>
</td>
</tr>
<tr>
<th><label for="image"><?php _e('Label text', 'epvc') ?></th>
<td>
<input type="text" name="epvc_settings[label_text]" value="<?php echo esc_attr($epvc_settings['label_text']); ?>" class="regular-text" /><br />
</td>
</tr>
<tr>
<th><label for="image"><?php _e('Position', 'epvc') ?></th>
<td>
<select name="epvc_settings[position]">
<option value="no">Select Postion</option>
<option value="before_content" <?php if( $epvc_settings['position'] == 'before_content' ) echo 'selected'; ?> >Before Content</option>
<option value="after_content" <?php if( $epvc_settings['position'] == 'after_content' ) echo 'selected'; ?> >After Content</option>
</select>
</td>
</tr>
<tr>
<th><label for="image"><?php _e('Exclude login users', 'epvc') ?></th>
<td>
<input type="hidden" name="epvc_settings[login_users]" value="no" class="regular-text" />
<input type="checkbox" name="epvc_settings[login_users]" value="yes" class="regular-text" <?php if($epvc_settings['login_users'] == 'yes' ) echo 'checked'; ?>/>
</td>
</tr>
<tr>
<th><label for="image"><?php _e('Exclude IPs', 'epvc') ?></th>
<td>
<textarea style="height: 100px;width: 362px;" name="epvc_settings[ips]"><?php echo esc_attr($epvc_settings['ips']); ?></textarea>
<p class="description">Add comma(,) seprator to each ips if multiple ips</p>
</td>
</tr>
</table>
<?php
if ( empty( $GLOBALS['hide_save_button'] ) ) :
submit_button( __( 'Save Changes', 'epvc' ), 'primary', 'epvc-settings-save-button' );
endif; ?>
</div>
</div>
</div>
</div>
</form>
</div>

View File

@ -0,0 +1,156 @@
<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Public Class
*
* Class for post views count
*
* @package Easy Post Views Count
* @since 1.0.0
*/
class Epvc_public {
public function __construct() {
// To update post views count
add_action( 'wp', array($this, 'epvc_update_post_count') , 100);
// Display post views count
add_filter( "the_content", array($this, "epvc_display_post_views") );
// Print style for views icon
add_action( "wp_print_styles", array($this, "epvc_print_style") );
// Shortcode to print post views cout
// Shortcode : [epvc_views id=""]
add_shortcode( 'epvc_views', array($this, 'epvc_display_post_views_shortcode') );
}
/**
* Post count update
*
* Update post views count
*
* @package Easy Post Views Count
* @since 1.0.0
*/
function epvc_update_post_count(){
global $post, $epvc_settings;
if( is_singular() ){
$post_types = is_array($epvc_settings['post_types'])?$epvc_settings['post_types']:array();
$login_users = sanitize_text_field($epvc_settings['login_users']);
$ips = sanitize_text_field($epvc_settings['ips']);
$excluded_ips = array();
if( !empty($ips) ){
$excluded_ips = array_filter( explode(",", $ips) );
}
$storedIds = array();
if( isset($_COOKIE['epvc_post_views']) && $_COOKIE['epvc_post_views'] != 'null' ) {
$storedIds = json_decode( $_COOKIE['epvc_post_views'] );
$postIds = json_decode( $_COOKIE['epvc_post_views']);
}
if( in_array( $post->post_type, array_keys($post_types) ) && !in_array( $_SERVER['REMOTE_ADDR'] , $excluded_ips ) && !in_array($post->ID ,$storedIds) ){
$postCount = get_post_meta( $post->ID, 'post_count_'.$post->ID, true );
if( $login_users == 'yes' && is_user_logged_in() ){
} else {
$postCount = !empty($postCount)?$postCount+1:1;
$postIds[] = $post->ID;
setcookie("epvc_post_views", json_encode($postIds) , time()+3600*24*365*10, '/');
}
update_post_meta( $post->ID, 'post_count_'.$post->ID, $postCount );
}
}
}
/**
* Post content display
*
* Display post views
*
* @package Easy Post Views Count
* @since 1.0.0
*/
function epvc_display_post_views( $content ){
global $epvc_settings;
$position = $epvc_settings['position'];
$CountContent = epvc_display_post_views();
if( $position == 'after_content' ){
$postContent = $content.$CountContent;
} else if( $position == 'before_content' ) {
$postContent = $CountContent.$content;
} else {
$postContent = $content;
}
return $postContent;
}
/**
* Post views count style
*
* Css for post count icon
*
* @package Easy Post Views Count
* @since 1.0.0
*/
function epvc_print_style(){
?>
<style type="text/css">
.epvc-eye {
margin-right: 3px;
width: 13px;
display: inline-block;
height: 13px;
border: solid 1px #000;
border-radius: 75% 15%;
position: relative;
transform: rotate(45deg);
}
.epvc-eye:before {
content: '';
display: block;
position: absolute;
width: 5px;
height: 5px;
border: solid 1px #000;
border-radius: 50%;
left: 3px;
top: 3px;
}
</style>
<?php
}
/**
* Shortcode
*
* Get post view shortcode
*
* @package Easy Post Views Count
* @since 1.0.0
*/
function epvc_display_post_views_shortcode( $atts, $content ){
// Getting attributes of shortcode
extract( shortcode_atts( array(
'id' => '',
), $atts ) );
ob_start();
echo epvc_display_post_views( $id );
$content .= ob_get_clean();
return $content;
}
}
return new Epvc_public();

View File

@ -0,0 +1,47 @@
<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/**
* Scripts Class
*
* Function for post views count html
*
* @package Easy Post Views Count
* @since 1.0.0
*/
function epvc_display_post_views( $post_id = '' ){
global $post, $epvc_settings;
if( empty($post_id) ){
$post_id = isset( $post->id ) ? $post->id : '';
} else {
$post = get_post( $post_id );
}
$post_types = is_array($epvc_settings['post_types'])?$epvc_settings['post_types']:array();
$display_icon = $epvc_settings['display_icon'];
$display_label = $epvc_settings['display_label'];
$label_text = sanitize_text_field( $epvc_settings['label_text'] );
$position = $epvc_settings['position'];
if( in_array( $post->post_type, array_keys($post_types) ) ){
$postCount = get_post_meta( $post->ID, 'post_count_'.$post->ID, true );
$postCount = !empty($postCount)?$postCount:0;
$label = '';
$icon = '';
if( $display_label == 'yes' ){
$label = "<span class='epvc-label'> ".$label_text."</span>";
}
if( $display_icon == 'yes' ){
$icon = "<span class='epvc-eye'></span> ";
}
$epvcCount = "<div class='epvc-post-count'>".$icon.' <span class="epvc-count"> '.number_format_i18n( $postCount ).'</span>'.$label."</div>";
return $epvcCount;
}
}