first commit

This commit is contained in:
DESKTOP-GBA0BK8\Admin
2023-04-08 12:19:53 -04:00
commit 7c8c8b1c76
4586 changed files with 2050693 additions and 0 deletions
@@ -0,0 +1,268 @@
<?php
namespace WPC\Widgets;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use WP_Query;
if (!defined('ABSPATH')) exit; // Exit if accessed directly
class CustomPostGrid extends Widget_Base {
public function get_name(){
return 'custom-post-grid';
}
public function get_title(){
return 'Custom Post Grid';
}
public function get_icon(){
return 'fa fa-th';
}
public function get_categories(){
return ['basic'];
}
protected function _register_controls(){
$this->start_controls_section(
'section_content',
[
'label' => 'Settings',
]
);
$this->end_controls_section();
}
protected function render(){
$settings = $this->get_settings_for_display();
$location = get_user_location();
$current_country = $location['country_code'];
// default settings
$post_filter = 'recent';
$posts_per_page = 6;
$page = 1;
if (!empty($_GET['post_filter'])) {
$post_filter = $_GET['post_filter'];
}
if (!empty($_GET['page_no'])) {
$page = $_GET['page_no'];
}
$args = [
'posts_per_page' => $posts_per_page,
'post_type' => 'post',
'post_status' => array('publish'),
'paged' => $page,
];
if ($post_filter == 'recent') {
$args = array_merge($args, [
'ignore_sticky_posts' => 1,
'orderby' => 'post_date',
'order' => 'DESC',
]);
} else if ($post_filter == 'newest') {
$args = array_merge($args, [
'ignore_sticky_posts' => 0,
'orderby' => 'post_date',
'order' => 'DESC',
]);
} else if ($post_filter == 'trending') {
$args = array_merge($args, [
'ignore_sticky_posts' => 1,
'orderby' => 'ID',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'is_trending',
'value' => '1',
'compare' => '=='
)
)
]);
} else if ($post_filter == 'hottest_stories') {
$args = array_merge($args, [
'ignore_sticky_posts' => 1,
'meta_key' => 'float_post_views_count',
'orderby' => 'meta_value_num',
'order' => 'DESC'
]);
} else if ($post_filter == 'oldest') {
$args = array_merge($args, [
'ignore_sticky_posts' => 1,
'order' => 'ASC'
]);
}
// Insert query by country
if (isset($args['meta_query'])) {
$metaQuery = $args['meta_query'];
$metaQuery = array_merge($metaQuery, [
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'key' => 'location',
'value' => $current_country,
'compare' => 'LIKE',
),
array(
'key'=> 'location',
'compare' => 'NOT EXISTS'
),
array(
'key'=> 'location',
'value' => '',
'compare' => '='
)
)
]);
$args['meta_query'] = $metaQuery;
} else {
$args = array_merge($args, [
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'location',
'value' => $current_country,
'compare' => 'LIKE',
),
array(
'key'=> 'location',
'compare' => 'NOT EXISTS'
),
array(
'key'=> 'location',
'value' => '',
'compare' => '='
)
)
]);
}
$count_query_args = $args;
$count_query_args['posts_per_page'] = -1;
$post_query = new WP_Query( $args );
$count_query = new WP_Query($count_query_args);
$posts = $post_query->posts;
$count = $count_query->post_count;
if ($count === 0 || $count < $posts_per_page) {
$total_page = 0;
} else {
$total_page = intval($count) / intval($posts_per_page);
$total_page = $total_page / intval($total_page) > 0 ? intval($total_page) + 1 : intval($total_page);
}
$filterMap = [
'recent' => 'Recent',
'trending' => 'Trending',
'hottest_stories' => 'Hottest Stories',
'newest' => 'Newest',
'oldest' => 'Oldest'
];
// Filter block
$html =
'<div class="filter-wrapper">
<h2>' . $filterMap[$post_filter] . '</h2>
<div class="dropdown">
<button onclick="customDropdown()" class="dropbtn"><i id="icon" class="filter-icon fas fa-sliders-h"></i></button>
<div id="myDropdown" class="dropdown-content">
<a href="/?post_filter=recent">Recent</a>
<a href="/?post_filter=trending">Trending</a>
<a href="/?post_filter=hottest_stories">Hottest Stories</a>
<a href="/?post_filter=newest">Newest</a>
<a href="/?post_filter=oldest">Oldest</a>
</div>
</div>
</div>';
// End filter block
// Post grid block
$html .= '<div class="custom-post-grid-block">';
foreach ($posts as $post) {
// Get co-authors
$authors = [];
$co_authors = get_coauthors($post->ID);
foreach($co_authors as $co_author) {
if(get_class($co_author) !== 'WP_User') {
array_push($authors, $co_author->display_name);
continue;
}
array_push($authors, $co_author->data->display_name);
}
if (empty($authors)) {
$post_author = get_the_author_meta( 'display_name' , get_post_field('post_author') );
array_push($authors, $post_author);
}
$authors = join(', ', $authors);
$post_content = strip_tags( $post->post_content );
$post_content = strip_shortcodes( $post_content );
$post_content = str_replace( array("\n", "\r", "\t"), ' ', $post_content );
$post_content = trim( $post_content );
$post_content = mb_substr( $post_content, 0, 300, 'utf8' );
$comment_count = '';
if ($post->comment_count) {
$comment_count = '<i class="icon-bubble" aria-hidden="true"></i>' . $post->comment_count;
}
$html .=
'<div class="post-wrapper">
<div>
<a href="' . get_permalink($post->ID) . '">
<div class="thumbnail" style="background-image: url(' . get_the_post_thumbnail_url($post->ID) . ');"></div>
</a>
</div>
<div class="content-wrapper">
<h2 class="title">
<a class="text-truncate-2-line" href="' . get_permalink($post->ID) . '" title="'. $post->post_title .'">
' . $post->post_title . '
</a>
</h2>
<div class="meta text-truncate-1-line" title="' . $authors . ' - ' . get_the_date( 'F j, Y', $post->ID ) . '">
' . $authors . ' - ' . get_the_date( 'F j, Y', $post->ID ) . ' ' . $comment_count .'
</div>
<p class="post-content text-truncate-2-line">' . $post_content . '</p>
<a class="read-more" href="' . get_permalink($post->ID) .'">Read More ></a>
</div>
</div>';
}
$html .= '</div>';
// End post grid block
// Pagination block
$html .= '<div class="custom-pagination">';
$html .= '<ul>';
for ($i = 1; $i <= $total_page; $i++) {
$html .= '<a href="/?post_filter=' . $post_filter . '&page_no=' . $i . '" class="' . ($i === intval($page) ? 'is-active' : '') . '" data-page="'. $i . '"><li>' . $i . '</li></a>';
}
$html .= '</ul>';
$html .= '</div>';
// End pagination block
echo $html;
}
}
@@ -0,0 +1,329 @@
<?php
namespace WPC\Widgets;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use WP_Query;
if (!defined('ABSPATH')) exit; // Exit if accessed directly
class FeatureArticle extends Widget_Base
{
public function get_name()
{
return 'feature-article';
}
public function get_title()
{
return 'Feature Article';
}
public function get_icon()
{
return 'fas fa-image';
}
public function get_categories()
{
return ['basic'];
}
protected function _register_controls()
{
$this->start_controls_section('section_content', ['label' => 'Settings', ]);
$this->add_control(
'feature_article',
[
'label' => __( 'Feature article', 'plugin-name' ),
'type' => \Elementor\Controls_Manager::SELECT,
'options' => [
'manual' => __( 'Manual', 'plugin-name' ),
'auto' => __( 'Auto', 'plugin-name' ),
],
'default' => 'manual',
]
);
$this->add_control(
'post_select',
[
'label' => __( 'Post select', 'plugin-name' ),
'type' => \Elementor\Controls_Manager::SELECT,
'options' => $this->getPublishedPosts(),
'placeholder' => 'Select post',
'condition' => [
'feature_article' => 'manual'
]
]
);
$this->add_control(
'swap_day',
[
'label' => __( 'Swap day', 'plugin-name' ),
'type' => \Elementor\Controls_Manager::SELECT,
'options' => [
'0' => 'Sunday',
'1' => 'Monday',
'2' => 'Tuesday',
'3' => 'Wednesday',
'4' => 'Thursday',
'5' => 'Friday',
'6' => 'Saturday'
],
'default' => '1',
'condition' => [
'feature_article' => 'auto'
]
]
);
$this->end_controls_section();
$this->start_controls_section(
'style_section',
[
'label' => __( 'Style', 'plugin-name' ),
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'title_color',
[
'label' => __( 'Title Color', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::COLOR,
'scheme' => [
'type' => \Elementor\Scheme_Color::get_type(),
'value' => \Elementor\Scheme_Color::COLOR_1,
],
'selectors' => [
'{{WRAPPER}} .title' => 'color: {{VALUE}}',
],
'default' => '#FFFFFF'
]
);
$this->add_control(
'divider_color',
[
'label' => __( 'Divider Color', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::COLOR,
'scheme' => [
'type' => \Elementor\Scheme_Color::get_type(),
'value' => \Elementor\Scheme_Color::COLOR_1,
],
'selectors' => [
'{{WRAPPER}} .divider' => 'border-top: 2px solid {{VALUE}}',
],
'default' => '#FFFFFF'
]
);
$this->add_control(
'article_meta_color',
[
'label' => __( 'Meta Color', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::COLOR,
'scheme' => [
'type' => \Elementor\Scheme_Color::get_type(),
'value' => \Elementor\Scheme_Color::COLOR_1,
],
'selectors' => [
'{{WRAPPER}} .article-meta' => 'color: {{VALUE}}',
],
'default' => '#FFFFFF'
]
);
$this->add_control(
'read_more_color',
[
'label' => __( 'Read More Color', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::COLOR,
'scheme' => [
'type' => \Elementor\Scheme_Color::get_type(),
'value' => \Elementor\Scheme_Color::COLOR_1,
],
'selectors' => [
'{{WRAPPER}} .read-more' => 'color: {{VALUE}}; border: 1px solid {{VALUE}};',
],
'default' => '#FFFFFF'
]
);
$this->end_controls_section();
}
protected function render()
{
global $wpdb;
$settings = $this->get_settings_for_display();
$post_id = null;
if ($settings['feature_article'] === 'auto') {
$article_setting = $wpdb->get_results(
'
SELECT *
FROM wp_feature_article
LIMIT 1
'
)[0];
if (empty($article_setting)) {
$wpdb->insert(
'wp_feature_article',
[
'post_id' => $this->getRandomPostID(),
'swap_day' => $settings['swap_day'],
'last_swap' => date('Y-m-d H:i:s')
]
);
} else {
if ($settings['swap_day'] === $article_setting->swap_day
&& date('Y-m-d') > date('Y-m-d', strtotime($article_setting->last_swap))
&& date('w') === $article_setting->swap_day) {
$wpdb->update(
'wp_feature_article',
[
'post_id' => $this->getRandomPostID(),
'swap_day' => $settings['swap_day'],
'last_swap' => date('Y-m-d H:i:s')
],
[
'swap_day' => $settings['swap_day']
]
);
}
if ($settings['swap_day'] !== $article_setting->swap_day) {
$wpdb->update(
'wp_feature_article',
[
'post_id' => $this->getRandomPostID(),
'swap_day' => $settings['swap_day'],
'last_swap' => date('Y-m-d H:i:s')
],
[
'swap_day' => $article_setting->swap_day,
]
);
}
}
$article_setting = $wpdb->get_results(
'
SELECT *
FROM wp_feature_article
LIMIT 1
'
)[0];
$post_id = $article_setting->post_id;
} else {
$post_id = $settings['post_select'];
}
$query = new WP_Query(['p' => $post_id]);
$post = $query->posts[0];
$html =
'<div class="feature-article-block text-center" style="background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url(' . get_the_post_thumbnail_url($post->ID) . ');">
<div class="content-wrapper">';
// Get categories
$categories = get_the_category($post->ID);
$categories_template_arr = [];
if (!empty($categories)) {
$html .= '<div class="category-wrapper d-none d-md-block text-uppercase">';
foreach ($categories as $category) {
$category = '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->name ) . '</a>';
array_push($categories_template_arr, $category);
}
$html .= join(' / ', $categories_template_arr);
$html .= '</div>';
}
// Get co-authors
$authors = [];
$co_authors = get_coauthors($post->ID);
foreach($co_authors as $co_author) {
if(get_class($co_author) !== 'WP_User') {
array_push($authors, $co_author->display_name);
continue;
}
array_push($authors, $co_author->data->display_name);
}
if (empty($authors)) {
$post_author = get_the_author_meta( 'display_name' , get_post_field('post_author') );
array_push($authors, $post_author);
}
$authors = join(', ', $authors);
$html .=
'<div class="divider"></div>
<a href="' . get_permalink($post->ID) . '"><h2 class="title text-truncate-2-line" title="' . $post->post_title . '">' . $post->post_title . '</h2></a>
<div class="divider"></div>
<p class="article-meta text-uppercase text-truncate" title="' . $authors . '">' . get_the_date( 'F j, Y', $post->ID ) . ' by ' . $authors . '</p>
<a class="read-more text-uppercase" href="' . get_permalink($post->ID) . '">Read more</a>
</div>
</div>';
echo $html;
}
protected function getPublishedPosts() {
$result = [];
$args = [
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 1000,
'ignore_sticky_posts' => 1,
'orderby' => 'post_date',
'order' => 'DESC',
];
$post_query = new WP_Query( $args );
$posts = $post_query->posts;
foreach ($posts as $post) {
$result += [$post->ID => $post->post_title];
}
return $result;
}
protected function getRandomPostID() {
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 1,
'orderby' => 'rand'
);
$query = new WP_Query ( $args );
$random_post = $query->posts[0];
return $random_post->ID;
}
}
@@ -0,0 +1,107 @@
<?php
class Float_Widget_Recent_Post extends WP_Widget {
public function __construct() {
$widget_ops = array(
'classname' => 'float_widget_recent_entries',
'description' => __( 'Your site&#8217;s most recent Posts.' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'float-recent-posts', __( 'Float Recent Posts' ), $widget_ops );
$this->alt_option_name = 'float_widget_recent_entries';
}
public function widget( $args, $instance ) {
if ( ! isset( $args['widget_id'] ) ) {
$args['widget_id'] = $this->id;
}
$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
if ( ! $number ) {
$number = 5;
}
$r = new WP_Query(
apply_filters(
'widget_posts_args',
array(
'posts_per_page' => $number,
'no_found_rows' => true,
'post_status' => 'publish',
'ignore_sticky_posts' => true,
),
$instance
)
);
if ( ! $r->have_posts() ) {
return;
}
?>
<?php echo $args['before_widget']; ?>
<?php
if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
}
?>
<ul class="oceanwp-recent-posts clr">
<?php foreach ( $r->posts as $recent_post ) : ?>
<?php
$post_title = get_the_title( $recent_post->ID );
$title = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
?>
<li class="clr">
<?php if (has_post_thumbnail( $recent_post->ID )) : ?>
<a href="<?php the_permalink( $recent_post->ID ); ?>" title="<?php echo $post_title; ?>" class="recent-posts-thumbnail">
<img width="150" height="150" src="<?php echo get_the_post_thumbnail_url( $recent_post->ID, 'thumbnail' ); ?>" class="attachment-thumbnail size-thumbnail wp-post-image" alt="<?php echo $post_title; ?>" loading="lazy" itemprop="image">
<span class="overlay"></span>
</a>
<?php endif; ?>
<div class="recent-posts-details clr">
<div class="recent-posts-details-inner clr">
<a href="<?php the_permalink( $recent_post->ID ); ?>" title="<?php echo $post_title; ?>" class="recent-posts-title"><?php echo $post_title; ?></a>
<div class="recent-posts-info clr">
<div class="recent-posts-date"><?php echo get_the_date( 'F j, Y', $recent_post->ID ) ?><span class="sep">/</span></div>
<div class="recent-posts-comments"><a href="<?php echo get_comments_link( $recent_post->ID ); ?>"><?php echo get_comments_number( $recent_post->ID ) ?> Comments</a></div>
</div>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php
echo $args['after_widget'];
}
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = sanitize_text_field( $new_instance['title'] );
$instance['number'] = (int) $new_instance['number'];
return $instance;
}
public function form( $instance ) {
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
?>
<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" placeholder="Recent Posts" /></p>
<p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label>
<input class="tiny-text" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="number" step="1" min="1" value="<?php echo $number; ?>" size="3" /></p>
<?php
}
}
// Register the widget
function float_widget_recent_post_function() {
register_widget( 'Float_Widget_Recent_Post' );
}
add_action( 'widgets_init', 'float_widget_recent_post_function' );
?>
@@ -0,0 +1,62 @@
<?php
namespace WPC\Widgets;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
if (!defined('ABSPATH')) exit; // Exit if accessed directly
class StoreBlock extends Widget_Base {
public function get_name(){
return 'store-block';
}
public function get_title(){
return 'Store Block';
}
public function get_icon(){
return 'fab fa-app-store';
}
public function get_categories(){
return ['basic'];
}
protected function _register_controls(){
$this->start_controls_section(
'section_content',
[
'label' => 'Settings',
]
);
$this->end_controls_section();
}
protected function render(){
$settings = $this->get_settings_for_display();
// Store block
$html =
'<div class="store-block">
<p class="title text-center"><strong>Download</strong> the Float app now.</p>
<div class="download-btn-wrapper d-flex flex-wrap justify-content-around mx-auto">
<a class="mx-2 mb-2" href="https://smart.link/afcjz898yquo8" target="_blank">
<img src="https://blog.float.sg/wp-content/themes/float/images/google.svg" alt="google-img">
</a>
<a class="mx-2 mb-2" href="https://smart.link/afcjz898yquo8" target="_blank">
<img src="https://blog.float.sg/wp-content/themes/float/images/apple.svg" alt="apple-img">
</a>
</div>
</div>';
// End store block
echo $html;
}
}