first commit

This commit is contained in:
Roman Pyrih
2023-07-24 08:30:51 +02:00
commit c2e100a763
7128 changed files with 1622619 additions and 0 deletions

View File

@@ -0,0 +1,142 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( 'Direct access forbidden.' );
}
if ( ! function_exists( 'mwt_set_post_likes' ) ) :
/**
* Likes incrementor
*
* @param int $postID ID of the post.
*
* @return bool No success if cookies are disabled
*/
function mwt_set_post_likes( $postID ) {
if ( empty( $_COOKIE["$postID"] ) ) {
$count_key = 'mwt_post_likes_count';
$count = get_post_meta( $postID, $count_key, true );
if ( $count == '' ) {
$count = 0;
delete_post_meta( $postID, $count_key );
add_post_meta( $postID, $count_key, '1' );
} else {
$count ++;
update_post_meta( $postID, $count_key, $count );
}
setcookie( "$postID", "voted", strtotime( '+1 day' ), COOKIEPATH, COOKIE_DOMAIN, false ); // 86400 = 1 day
return true;
}
return false;
} //mwt_set_post_likes()
endif;
if ( ! function_exists( 'mwt_get_post_likes' ) ) :
/**
* Get likes value
*
* @param int $postID ID of the post.
*/
function mwt_get_post_likes( $postID ) {
$count_key = 'mwt_post_likes_count';
$count = get_post_meta( $postID, $count_key, true );
if ( $count == '' ) {
delete_post_meta( $postID, $count_key );
add_post_meta( $postID, $count_key, '0' );
return '0';
}
return $count;
} //mwt_get_post_likes()
endif;
if ( ! function_exists( 'mwt_print_post_likes' ) ) :
/**
* Get likes value
*
* @param int $count of likes of the post.
*/
function mwt_print_post_likes( $count ) {
$html = '';
if ( !is_single() ) {
echo $count;
} else {
if ( ! $count ) {
$html = '<span class="item-likes-count">0</span> <span class="item-likes-word">' . esc_html__( 'Likes', 'mwt' ) . '</span>';
}
if ( $count == 1 ) {
$html = '<span class="item-likes-count">1</span> <span class="item-likes-word">' . esc_html__( 'Like', 'mwt' ) . '</span>';
}
if ( $count > 1 ) {
$html = '<span class="item-likes-count">' . $count . '</span> <span class="item-likes-word">' . esc_html__( 'Likes', 'mwt' ) . '</span>';
}
}
return $html;
} //mwt_print_post_likes()
endif;
if ( ! function_exists( 'mwt_post_likes_scripts' ) ) :
// Add the JS
function mwt_post_likes_scripts() {
wp_enqueue_script( 'post-likes', plugin_dir_url(__FILE__) . '/static/js/mod-post-likes.js', array( 'jquery' ), '1.0.0', true );
wp_localize_script( 'post-likes', 'MyAjax', array(
// URL to wp-admin/admin-ajax.php to process the request
'ajaxurl' => admin_url( 'admin-ajax.php' ),
// generate a nonce with a unique ID "myajax-post-comment-nonce"
// so that you can check it later when an AJAX request is sent
'security' => wp_create_nonce( 'increment-post-likes' )//,
//'post_id' => get_the_ID()
) );
} //mwt_post_likes_scripts()
endif;
add_action( 'wp_enqueue_scripts', 'mwt_post_likes_scripts' );
if ( ! function_exists( 'mwt_inc_post_like_callback' ) ) :
// The function that handles the AJAX request
function mwt_inc_post_like_callback() {
check_ajax_referer( 'increment-post-likes', 'security' );
$pID = intval( $_POST['pID'] );
mwt_set_post_likes( $pID );
echo mwt_print_post_likes( mwt_get_post_likes( $pID ) );
die(); // this is required to return a proper result
} //mwt_inc_post_like_callback()
endif;
add_action( 'wp_ajax_add_like', 'mwt_inc_post_like_callback' );
add_action( 'wp_ajax_nopriv_add_like', 'mwt_inc_post_like_callback' );
if ( ! function_exists( 'mwt_post_like_button' ) ) :
/**
* Print like button
*/
function mwt_post_like_button( $postID ) {
$output = '';
if ( empty( $_COOKIE["$postID"] ) ) {
if ( is_single() ) {
$output = '<span data-id="' . $postID . '"><a href="" class="theme_button color4 no_bg_button like_button like_active_button"><i class="fa fa-heart-o"></i></a></span>';
} else {
$output = '<span data-id="' . $postID . '"><a href="" class="like_button like_active_button"><i class="fa fa-heart"></i></a></span>';
}
} else {
$output = '<span data-id="' . $postID . '"><span class="like_button"><i class="fa fa-check highlight4"></i></span></span>';
}
echo apply_filters( 'mwt_like_button', $output );
} //mwt_post_like_button()
endif;
add_action( 'mwt_post_meta', 'mwt_post_like_button', 10, 1 );
if ( ! function_exists( 'mwt_post_like_count' ) ) :
/**
* Print like counter value
*/
function mwt_post_like_count( $postID ) {
echo apply_filters( 'mwt_like_count', '<span class="votes_count votes_count_' . $postID . '">' . mwt_print_post_likes( mwt_get_post_likes( $postID ) ) . '</span>' );
} //mwt_post_like_count()
endif;
add_action( 'mwt_post_meta', 'mwt_post_like_count', 20, 1 );

View File

@@ -0,0 +1,79 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( 'Direct access forbidden.' );
}
// share buttons
if ( ! function_exists( 'mwt_share_this' ) ) :
/**
* Share article through social networks.
* bool $only_buttons
*/
function mwt_share_this( $only_buttons = false ) {
$share_buttons = array();
$share_buttons['share_facebook'] = '<a href="https://www.facebook.com/sharer.php?u=' . esc_url( get_permalink() ) . '" class="social-icon color-icon socicon-facebook" target="_blank"></a>';
$share_buttons['share_twitter'] = '<a href="https://twitter.com/intent/tweet?url=' . esc_url( get_permalink() ) . '" class="social-icon color-icon socicon-twitter" target="_blank"></a>';
$share_buttons['share_google_plus'] = '<a href="https://plus.google.com/share?url=' . esc_url( get_permalink() ) . '" class="social-icon color-icon socicon-google" target="_blank"></a>';
$share_buttons['share_pinterest'] = '<a href="https://pinterest.com/pin/create/bookmarklet/?url=' . esc_url( get_permalink() ) . '" class="social-icon color-icon socicon-pinterest" target="_blank"></a>';
$share_buttons['share_linkedin'] = '<a href="https://www.linkedin.com/shareArticle?url=' . esc_url( get_permalink() ) . '" class="social-icon color-icon socicon-linkedin" target="_blank"></a>';
$share_buttons['share_tumblr'] = '<a href="https://www.tumblr.com/widgets/share/tool?canonicalUrl=' . esc_url( get_permalink() ) . '" class="social-icon color-icon socicon-tumblr" target="_blank"></a>';
$share_buttons['share_reddit'] = '<a href="https://reddit.com/submit?url=' . esc_url( get_permalink() ) . '" class="social-icon color-icon socicon-reddit" target="_blank"></a>';
if ( function_exists( 'fw_get_db_customizer_option' ) ) {
if ( ! fw_get_db_customizer_option( 'share_facebook' ) ) {
unset( $share_buttons['share_facebook'] );
}
if ( ! fw_get_db_customizer_option( 'share_twitter' ) ) {
unset( $share_buttons['share_twitter'] );
}
if ( ! fw_get_db_customizer_option( 'share_google_plus' ) ) {
unset( $share_buttons['share_google_plus'] );
}
if ( ! fw_get_db_customizer_option( 'share_pinterest' ) ) {
unset( $share_buttons['share_pinterest'] );
}
if ( ! fw_get_db_customizer_option( 'share_linkedin' ) ) {
unset( $share_buttons['share_linkedin'] );
}
if ( ! fw_get_db_customizer_option( 'share_tumblr' ) ) {
unset( $share_buttons['share_tumblr'] );
}
if ( ! fw_get_db_customizer_option( 'share_reddit' ) ) {
unset( $share_buttons['share_reddit'] );
}
}
if ( ! empty ( $share_buttons ) ) :
$unique_id = uniqid();
if ( ! $only_buttons ) :
?>
<div class="dropdown inline-block">
<a href="#" data-target="#" id="share_button_<?php echo esc_attr( $unique_id ); ?>"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-share-alt" aria-hidden="true"></i> Share:</a>
<div class="dropdown-menu share-dropdown" aria-labelledby="share_button_<?php echo esc_attr( $unique_id ); ?>">
<?php endif; //only_buttons
?>
<div class="share_buttons">
<?php
foreach ( $share_buttons as $share_button ) :
echo wp_kses_post( $share_button );
endforeach;
?>
</div><!-- eof .share_buttons -->
<?php if ( ! $only_buttons ) : ?>
</div><!-- eof .dropdown-menu -->
</div><!-- eof .dropdown -->
<?php endif; //only_buttons
endif; // share_buttons
} //mwt_share_this()
endif; //function_exists

View File

@@ -0,0 +1,124 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( 'Direct access forbidden.' );
}
if ( ! function_exists( 'mwt_set_post_views' ) ) :
/**
* Counter incrementor
*
* @param int $postID ID of the post.
*/
function mwt_set_post_views( $postID ) {
$count_key = 'mwt_post_views_count';
$count = get_post_meta( $postID, $count_key, true );
if ( $count == '' ) {
$count = 0;
delete_post_meta( $postID, $count_key );
add_post_meta( $postID, $count_key, '1' );
} else {
$count ++;
update_post_meta( $postID, $count_key, $count );
}
} //mwt_set_post_views()
endif;
//To keep the count accurate, lets get rid of prefetching
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10 );
if ( ! function_exists( 'mwt_action_track_post_views' ) ) :
/**
* Post views tracker
*
* @param int $post_id ID of the post.
*/
function mwt_action_track_post_views( $post_id = '' ) {
if ( ! is_single() ) {
return;
}
if ( empty ( $post_id ) ) {
global $post;
$post_id = $post->ID;
}
mwt_set_post_views( $post_id );
} //mwt_action_track_post_views()
endif;
add_action( 'wp_head', 'mwt_action_track_post_views' );
if ( ! function_exists( 'mwt_get_post_views' ) ) :
/**
* Get counter value
*
* @param int $postID ID of the post.
*/
function mwt_get_post_views( $post_id ) {
$count_key = 'mwt_post_views_count';
$count = get_post_meta( $post_id, $count_key, true );
if ( $count == '' ) {
delete_post_meta( $post_id, $count_key );
add_post_meta( $post_id, $count_key, '0' );
return "0";
}
return number_format( $count, 0, ".", "," );
} //mwt_action_track_post_views()
endif;
if ( ! function_exists( 'mwt_filter_post_column_views' ) ) :
//Function that Adds a 'Views' Column to your Posts tab in WordPress Dashboard.
function mwt_filter_post_column_views( $newcolumn ) {
//Retrieves the translated string, if translation exists, and assign it to the 'default' array.
$newcolumn['post_views'] = esc_html__( 'Views', 'mwt' );
return $newcolumn;
} //mwt_filter_post_column_views()
endif;
if ( ! function_exists( 'mwt_action_post_custom_column_views' ) ) :
//Function that Populates the 'Views' Column with the number of views count.
function mwt_action_post_custom_column_views( $column_name, $id ) {
if ( $column_name === 'post_views' ) {
// Display the Post View Count of the current post.
// get_the_ID() - Returns the numeric ID of the current post.
echo mwt_get_post_views( get_the_ID() );
}
}
endif;
//Hooks a function to a specific filter action.
//applied to the list of columns to print on the manage posts screen.
add_filter( 'manage_posts_columns', 'mwt_filter_post_column_views' );
//Hooks a function to a specific action.
//allows you to add custom columns to the list post/custom post type pages.
//'10' default: specify the function's priority.
//and '2' is the number of the functions' arguments.
add_action( 'manage_posts_custom_column', 'mwt_action_post_custom_column_views', 10, 2 );
if ( ! function_exists( 'mwt_show_post_views_count' ) ) :
function mwt_show_post_views_count() {
$id = get_the_ID();
$number = mwt_get_post_views( $id );
$html = '';
if ( !is_single() ) {
$html = '<span class="item-views-count">' . $number . '</span>';
} else {
if ( ! $number ) {
$html = '<span class="item-views-count">0</span> <span class="item-views-word">' . esc_html__( 'Views', 'mwt' ) . '</span>';
}
if ( $number == 1 ) {
$html = '<span class="item-views-count">1</span> <span class="item-views-word">' . esc_html__( 'View', 'mwt' ) . '</span>';
}
if ( $number > 1 ) {
$html = '<span class="item-views-count">' . $number . '</span> <span class="item-views-word">' . esc_html__( 'Views', 'mwt' ) . '</span>';
}
}
echo wp_kses_post( $html );
} //mwt_show_post_views_count()
endif;

View File

@@ -0,0 +1,73 @@
<?php
/*
Plugin Name: Modern Web Templates theme addons
Description: Additional functions for mwtemplates theme
Version: 1.0.2
Author: mwtemplates
Author URI: https://themeforest.net/user/mwtemplates/
License: GPLv2 or later
*/
if ( ! function_exists( 'mwt_login_form' ) ) :
function mwt_login_form() {
$redirect_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$html = '';
if ( ! is_user_logged_in() ) {
$html = '
<form name="loginform" id="login-dropdown-loginform" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post">
<div class="form-group">
<label for="login-dropdown-user_login">' . esc_html__( 'Username', 'mwtemplates' ) . '</label>
<input type="text" name="log" id="login-dropdown-user_login" class="form-control" value="" placeholder="' . esc_html__( 'Login', 'mwtemplates' ) . '">
</div>
<div class="form-group">
<label for="login-dropdown-user_pass">' . esc_html__( 'Password', 'mwtemplates' ) . '</label>
<input type="password" name="pwd" id="login-dropdown-user_pass" class="form-control" value="" placeholder="' . esc_html__( 'Password', 'mwtemplates' ) . '">
</div>
<div class="checkbox">
<label>
<input name="rememberme" type="checkbox" id="login-dropdown-rememberme" value="forever"> ' . esc_html__( 'Remember Me', 'mwtemplates' ) . '
</label>
</div>
<input type="submit" name="wp-submit" id="login-dropdown-wp-submit" class="theme_button color1" value="' . esc_html__( 'Log In', 'mwtemplates' ) . '" />';
if ( get_option( 'users_can_register' ) ) {
$html .= ' <a href="' . esc_url( wp_registration_url() ) . '" class="theme_button color2">' . esc_html__( 'Register', 'mwtemplates' ) . '</a>';
}
$html .= '<input type="hidden" name="redirect_to" value="' . esc_url( $redirect_url ) . '" />
</form>';
$html .= '<a href="' . esc_url( wp_lostpassword_url( $redirect_url ) ) . '">' . esc_html__( 'Forgot Your Password?', 'mwtemplates' ) . '</a>';
} else {
$html = '<a href="' . esc_url( wp_logout_url( $redirect_url ) ) . '" class="theme_button color1">' . esc_html__( 'Log out', 'mwtemplates' ) . '</a>';
if ( current_user_can( 'read' ) ) {
$html .= ' <a href="' . admin_url() . '" class="theme_button color2">' . esc_html__( 'Site Admin', 'mwtemplates' ) . '</a>';
}
}
echo $html;
} //mwt_login_form()
endif;
//adding user social contacts
if ( ! function_exists( 'mwt_filter_modify_user_contact_methods' ) ):
function mwt_filter_modify_user_contact_methods( $profile_fields ) {
// Add new fields
$profile_fields['twitter'] = esc_html__( 'Twitter URL', 'mwtemplates' );
$profile_fields['facebook'] = esc_html__( 'Facebook URL', 'mwtemplates' );
$profile_fields['google_plus'] = esc_html__( 'Google+ URL', 'mwtemplates' );
$profile_fields['youtube'] = esc_html__( 'Youtube', 'mwtemplates' );
$profile_fields['position'] = esc_html__( 'Position', 'mwtemplates' );
return $profile_fields;
}
endif; //function_exists
add_filter( 'user_contactmethods', 'mwt_filter_modify_user_contact_methods' );
require_once plugin_dir_path( __FILE__ ) . '/mod-post-likes.php';
require_once plugin_dir_path( __FILE__ ) . '/mod-post-views.php';
require_once plugin_dir_path( __FILE__ ) . '/mod-post-share-buttons.php';

View File

@@ -0,0 +1,52 @@
jQuery(document).ready(function($) {
"use strict";
//like button
jQuery("a.like_button").click(function(e){
e.preventDefault();
var $this = jQuery(this);
if(!$this.hasClass('like_active_button')) {
//return;
}
var $parent = $this.parent();
var id = $parent.data('id'),
data = {
action: 'add_like',
security : MyAjax.security,
pID: id
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
var post_result = $.post(MyAjax.ajaxurl, data, function(response) {
$parent.html('<span class="like_button highlight4"><i class="fa fa-check"></i></span>');
jQuery('.votes_count_'+id).html(response);
}).done(function() {
}).fail(function(xhr, textStatus, errorThrown) {
console.log(xhr.responseText);
}).always(function() {
});
});
//$(".like_button").click(function(e){
// var id = $(this).parent().data('id'),
// data = {
// action: 'add_like',
// security : MyAjax.security,
// pID: id
// },
// parent = $(this).parent();
//
// // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
// var post_result = $.post(MyAjax.ajaxurl, data, function(response) {
// parent.html('<i class="rt-icon icon-heart3"></i>');
// $('.votes_count_'+id).html(response);
// }).done(function() {
//
// }).fail(function(xhr, textStatus, errorThrown) {
// console.log(xhr.responseText);
// }).always(function() {
// });
//
// e.preventDefault();
//});
});