esc_html__('Right Sidebar', 'toocheke'), 'id' => 'right-sidebar', 'description' => esc_html__('Add widgets here that will be displayed in the right sidebar.', 'toocheke'), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', )); register_sidebar(array( 'name' => esc_html__('Top Content Area', 'toocheke'), 'id' => 'home-left-top', 'description' => esc_html__('Add widgets here that will be displayed in the main content area on the left of the home page(above "Latest Comics, "Latest Posts", "Latest Chapters", and "Latest Collections")', 'toocheke'), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', )); register_sidebar(array( 'name' => esc_html__('Bottom Content Area ', 'toocheke'), 'id' => 'home-left-bottom', 'description' => esc_html__('Add widgets here that will be displayed in the main content area on the left of the home page(below "Latest Comics, "Latest Posts", "Latest Chapters", and "Latest Collections")', 'toocheke'), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', )); register_sidebar(array( 'name' => esc_html__('Above Comic Series', 'toocheke'), 'id' => 'home-above-series', 'description' => esc_html__('Add widgets here that will be displayed in the main content area on the left of the home page(above "Comic Series")', 'toocheke'), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', )); register_sidebar(array( 'name' => esc_html__('Below Comic Series', 'toocheke'), 'id' => 'home-below-series', 'description' => esc_html__('Add widgets here that will be displayed in the main content area on the left of the home page(below "Comic Series")', 'toocheke'), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', )); register_sidebar(array( 'name' => esc_html__('Above Comic', 'toocheke'), 'id' => 'above-comic', 'description' => esc_html__('Add widgets here that will be displayed above the comic', 'toocheke'), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', )); register_sidebar(array( 'name' => esc_html__('Below Comic', 'toocheke'), 'id' => 'below-comic', 'description' => esc_html__('Add widgets here that will be displayed below the comic', 'toocheke'), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', )); } add_action('widgets_init', 'toocheke_widgets_init'); /* * About Widget */ if (!function_exists('toocheke_load_about_widget')): function toocheke_load_about_widget() { register_widget('toocheke_about_widget'); } endif; add_action('widgets_init', 'toocheke_load_about_widget'); if (!class_exists('toocheke_about_widget')): class toocheke_about_widget extends WP_Widget { public function __construct() { $widget_details = array( 'classname' => 'toocheke_about_widget', 'description' => esc_html__('Creates an about section consisting of a title, image/avatar, and a description. Ideal for the right sidebar on the Toocheke WP theme.', 'toocheke'), ); parent::__construct('toocheke_about_widget', 'Toocheke: About Us', $widget_details); add_action('admin_enqueue_scripts', array($this, 'toocheke_about_us_widget_assets')); } public function toocheke_about_us_widget_assets() { wp_enqueue_script('media-upload'); wp_enqueue_script('thickbox'); wp_enqueue_script('toocheke-bootstrap', get_template_directory_uri() . '/dist/js/toocheke-media-upload.js', array('jquery'), '20190508', true); wp_enqueue_style('thickbox'); } public function widget($args, $instance) { $allowed_tags = array( 'section' => array( 'id' => array(), 'class' => array(), ), 'h4' => array( 'class' => array(), ), ); echo wp_kses($args['before_widget'], $allowed_tags); if (!empty($instance['title'])) { $title = !empty($instance['title']) ? $instance['title'] : ''; $title = apply_filters('widget_title', $title, $instance, $this->id_base); echo wp_kses($args['before_title'], $allowed_tags) . wp_kses($title, $allowed_tags) . wp_kses($args['after_title'], $allowed_tags); } ?> ' class='about-avatar'>

'toocheke_social_media social-links', 'description' => esc_html__('Add links to your social media profiles. Ideally for the right sidebar on the Toocheke WP theme. ', 'toocheke'), ); parent::__construct('toocheke_social_media', 'Toocheke: Social', $widget_details); } public function widget($args, $instance) { $allowed_tags = array( 'section' => array( 'id' => array(), 'class' => array(), ), 'h4' => array( 'class' => array(), ), ); echo wp_kses($args['before_widget'], $allowed_tags); if (!empty($instance['title'])) { $title = !empty($instance['title']) ? $instance['title'] : ''; $title = apply_filters('widget_title', $title, $instance, $this->id_base); echo wp_kses($args['before_title'], $allowed_tags) . wp_kses($title, $allowed_tags) . wp_kses($args['after_title'], $allowed_tags); } ?>

" id="get_field_id('rss_url')); ?>" name="get_field_name('rss_url')); ?>" type="text" value="" />

'widget_calendar', 'description' => __('A calendar of your comics. Ideally for the right sidebar on the Toocheke WP theme.', 'toocheke')); parent::__construct('toocheke-calendar', __('Toocheke Calendar', 'toocheke'), $widget_ops); } public function widget($args, $instance) { $title = apply_filters('widget_title', empty($instance['title']) ? __('Calendar', 'toocheke') : $instance['title'], $instance, $this->id_base); $posttype = 'comic'; add_filter('get_calendar', array($this, 'toocheke_get_comic_calendar'), 10, 3); add_filter('month_link', array($this, 'toocheke_get_month_link'), 10, 3); add_filter('day_link', array($this, 'toocheke_get_day_link'), 10, 4); $allowed_tags = array( 'section' => array( 'id' => array(), 'class' => array(), ), 'h4' => array( 'class' => array(), ), ); echo wp_kses($args['before_widget'], $allowed_tags); if ($title) { echo wp_kses($args['before_title'], $allowed_tags) . wp_kses($title, $allowed_tags) . wp_kses($args['after_title'], $allowed_tags); } if (0 === self::$instance) { echo '
'; } else { echo '
'; } get_calendar(); echo '
'; echo wp_kses($args['after_widget'], $allowed_tags); remove_filter('get_calendar', array($this, 'toocheke_get_comic_calendar')); remove_filter('month_link', array($this, 'toocheke_get_month_link')); remove_filter('day_link', array($this, 'toocheke_get_day_link')); self::$instance++; } public function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = sanitize_text_field($new_instance['title']); return $instance; } public function form($instance) { $instance = wp_parse_args((array) $instance, array('title' => '')); $title = isset($instance['title']) ? sanitize_text_field($instance['title']) : ''; $posttype = 'comic'; ?>

option_name); $posttype = 'comic'; // Quick check. If we have no posts at all, abort! if (!$posts) { // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = '$posttype' AND post_status = 'publish' LIMIT 1"); } if (isset($_GET['w'])) { $w = (int) $_GET['w']; } // week_begins = 0 stands for Sunday $week_begins = (int) get_option('start_of_week'); $ts = current_time('timestamp'); // Let's figure out when we are if (!empty($monthnum) && !empty($year)) { $thismonth = zeroise(intval($monthnum), 2); $thisyear = (int) $year; } elseif (!empty($w)) { // We need to get the month from MySQL $thisyear = (int) substr($m, 0, 4); // it seems MySQL's weeks disagree with PHP's $d = (($w - 1) * 7) + 6; // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')"); } elseif (!empty($m)) { $thisyear = (int) substr($m, 0, 4); if (strlen($m) < 6) { $thismonth = '01'; } else { $thismonth = zeroise((int) substr($m, 4, 2), 2); } } else { $thisyear = gmdate('Y', $ts); $thismonth = gmdate('m', $ts); } $unixmonth = mktime(0, 0, 0, $thismonth, 1, $thisyear); $last_day = date('t', $unixmonth); // Get the next and previous month and year with at least one post // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts WHERE post_date < '$thisyear-$thismonth-01' AND post_type = '$posttype' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' AND post_type = '$posttype' AND post_status = 'publish' ORDER BY post_date ASC LIMIT 1"); /* translators: Calendar caption: 1: month name, 2: 4-digit year */ $calendar_caption = _x('%1$s %2$s', 'calendar caption', 'toocheke'); $calendar_output = ''; $myweek = array(); for ($wdcount = 0; $wdcount <= 6; $wdcount++) { $myweek[] = $wp_locale->get_weekday(($wdcount + $week_begins) % 7); } foreach ($myweek as $wd) { $day_name = $initial ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd); $wd = esc_attr($wd); $calendar_output .= "\n\t\t"; } $calendar_output .= ' '; if ($previous) { $calendar_output .= "\n\t\t" . ''; } else { $calendar_output .= "\n\t\t" . ''; } $calendar_output .= "\n\t\t" . ''; if ($next) { $calendar_output .= "\n\t\t" . ''; } else { $calendar_output .= "\n\t\t" . ''; } $calendar_output .= ' '; $daywithpost = array(); // Get days with posts // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' AND post_type = '$posttype' AND post_status = 'publish' AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N); if ($dayswithposts) { foreach ((array) $dayswithposts as $daywith) { $daywithpost[] = $daywith[0]; } } // See how much we should pad in the beginning $pad = calendar_week_mod(date('w', $unixmonth) - $week_begins); if (0 != $pad) { $calendar_output .= "\n\t\t" . ''; } $newrow = false; $daysinmonth = (int) date('t', $unixmonth); for ($day = 1; $day <= $daysinmonth; ++$day) { if (isset($newrow) && $newrow) { $calendar_output .= "\n\t\n\t\n\t\t"; } $newrow = false; if ($day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp'))) { $calendar_output .= ''; if (6 == calendar_week_mod(date('w', mktime(0, 0, 0, $thismonth, $day, $thisyear)) - $week_begins)) { $newrow = true; } } $pad = 7 - calendar_week_mod(date('w', mktime(0, 0, 0, $thismonth, $day, $thisyear)) - $week_begins); if (0 != $pad && 7 != $pad) { $calendar_output .= "\n\t\t" . ''; } $calendar_output .= "\n\t\n\t\n\t
' . sprintf( $calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth) ) . '
$day_name
« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '  ' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' » 
 
'; } else { $calendar_output .= ''; } if (in_array($day, $daywithpost)) { // any posts today? // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment $date_format = date(_x('F j, Y', 'daily archives date format', 'toocheke'), strtotime("{$thisyear}-{$thismonth}-{$day}")); // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment $label = sprintf(__('Posts published on %s', 'toocheke'), $date_format); $calendar_output .= sprintf( '%s', get_day_link($thisyear, $thismonth, $day), // $this->get_comic_day_link( $posttype, $thisyear, $thismonth, $day ), esc_attr($label), $day ); } else { $calendar_output .= $day; } $calendar_output .= ' 
"; if ($echo) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $calendar_output; } else { return $calendar_output; } } public function toocheke_get_day_link($daylink, $year, $month, $day) { global $wp_rewrite; $options = get_option($this->option_name); $posttype = 'comic'; if (!$year) { $year = gmdate('Y', current_time('timestamp')); } if (!$month) { $month = gmdate('m', current_time('timestamp')); } if (!$day) { $day = gmdate('j', current_time('timestamp')); } $daylink = $wp_rewrite->get_day_permastruct(); if (!empty($daylink)) { $front = preg_replace('/\/$/', '', $wp_rewrite->front); $daylink = str_replace('%year%', $year, $daylink); $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink); $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink); if ('post' == $posttype) { $daylink = home_url(user_trailingslashit($daylink, 'day')); } else { $type_obj = get_post_type_object($posttype); $archive_name = 'comic'; if ($front) { $new_front = $type_obj->rewrite['with_front'] ? $front : ''; $daylink = str_replace($front, $new_front . '/' . $archive_name, $daylink); $daylink = home_url(user_trailingslashit($daylink, 'day')); } else { $daylink = home_url(user_trailingslashit($archive_name . $daylink, 'day')); } } } else { $daylink = home_url('?post_type=' . $posttype . '&m=' . $year . zeroise($month, 2) . zeroise($day, 2)); } return $daylink; } public function toocheke_get_month_link($monthlink, $year, $month) { global $wp_rewrite; $options = get_option($this->option_name); $posttype = 'comic'; if (!$year) { $year = gmdate('Y', current_time('timestamp')); } if (!$month) { $month = gmdate('m', current_time('timestamp')); } $monthlink = $wp_rewrite->get_month_permastruct(); if (!empty($monthlink)) { $front = preg_replace('/\/$/', '', $wp_rewrite->front); $monthlink = str_replace('%year%', $year, $monthlink); $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink); if ('post' == $posttype) { $monthlink = home_url(user_trailingslashit($monthlink, 'month')); } else { $type_obj = get_post_type_object($posttype); $archive_name = !empty($type_obj->rewrite['slug']) ? $type_obj->rewrite['slug'] : $posttype; if ($front) { $new_front = $type_obj->rewrite['with_front'] ? $front : ''; $monthlink = str_replace($front, $new_front . '/' . $archive_name, $monthlink); $monthlink = home_url(user_trailingslashit($monthlink, 'month')); } else { $monthlink = home_url(user_trailingslashit($archive_name . $monthlink, 'month')); } } } else { $monthlink = home_url('?post_type=' . $posttype . '&m=' . $year . zeroise($month, 2)); } return $monthlink; } } endif; //Calendar Widget ends here /* * Top Ten Comics Widget */ if (!function_exists('toocheke_load_top_10_comics_widget')): function toocheke_load_top_10_comics_widget() { register_widget('toocheke_top_10_comics_widget'); } endif; add_action('widgets_init', 'toocheke_load_top_10_comics_widget'); if (!class_exists('toocheke_top_10_comics_widget')): class toocheke_top_10_comics_widget extends WP_Widget { public function __construct() { $widget_details = array( 'classname' => 'toocheke_top_10_comics_widget', 'description' => esc_html__('Creates a top 10 comics section consisting of a title, and a list of the 10 comics. Ideal for the right sidebar on the Toocheke WP theme.', 'toocheke'), ); parent::__construct('toocheke_top_10_comics_widget', 'Toocheke: Top 10 Comics', $widget_details); } public function widget($args, $instance) { $series_id = null; $series_id = isset($_GET['sid']) ? (int) $_GET['sid'] : null; if ('series' === get_post_type()) { $series_id = get_the_ID(); } $allowed_tags = array( 'section' => array( 'id' => array(), 'class' => array(), ), 'h4' => array( 'class' => array(), ), ); echo wp_kses($args['before_widget'], $allowed_tags); if (!empty($instance['title'])) { $title = !empty($instance['title']) ? $instance['title'] : ''; $title = apply_filters('widget_title', $title, $instance, $this->id_base); echo wp_kses($args['before_title'], $allowed_tags) . wp_kses($title, $allowed_tags) . wp_kses($args['after_title'], $allowed_tags); } $comic_args = array( 'post_parent' => $series_id, 'post_type' => 'comic', 'post_status' => 'publish', 'posts_per_page' => 10, 'meta_key' => 'post_views_count', 'meta_query' => array( array( 'key' => 'post_views_count', 'value' => 0, 'compare' => '>', ), ), 'orderby' => 'meta_value_num', 'order' => 'DESC', ); $popular_comics = new WP_Query($comic_args); ?> have_posts()): ?>

'toocheke_latest_10_comics_widget', 'description' => esc_html__('Creates a latest comics section consisting of a title, and a list of the latest 10 comics. Ideal for the right sidebar on the Toocheke WP theme.', 'toocheke'), ); parent::__construct('toocheke_latest_10_comics_widget', 'Toocheke: Latest Comics', $widget_details); } public function widget($args, $instance) { $series_id = null; $series_id = isset($_GET['sid']) ? (int) $_GET['sid'] : null; if ('series' === get_post_type()) { $series_id = get_the_ID(); } $allowed_tags = array( 'section' => array( 'id' => array(), 'class' => array(), ), 'h4' => array( 'class' => array(), ), ); echo wp_kses($args['before_widget'], $allowed_tags); if (!empty($instance['title'])) { $title = !empty($instance['title']) ? $instance['title'] : ''; $title = apply_filters('widget_title', $title, $instance, $this->id_base); echo wp_kses($args['before_title'], $allowed_tags) . wp_kses($title, $allowed_tags) . wp_kses($args['after_title'], $allowed_tags); } $comic_args = array( 'post_parent' => $series_id, 'post_type' => 'comic', 'post_status' => 'publish', 'posts_per_page' => 10, 'meta_key' => 'post_views_count', 'orderby' => 'post_date', 'order' => 'DESC', ); $popular_comics = new WP_Query($comic_args); ?> have_posts()): ?>

'toocheke_comic_tags_widget', 'description' => esc_html__('Creates comic tags cloud.', 'toocheke'), ); parent::__construct('toocheke_comic_tags_widget', 'Toocheke: Comic Tags Cloud', $widget_details); } public function widget($args, $instance) { $allowed_tags = array( 'section' => array( 'id' => array(), 'class' => array(), ), 'h4' => array( 'class' => array(), ), ); echo wp_kses($args['before_widget'], $allowed_tags); if (!empty($instance['title'])) { $title = !empty($instance['title']) ? $instance['title'] : ''; $title = apply_filters('widget_title', $title, $instance, $this->id_base); echo wp_kses($args['before_title'], $allowed_tags) . wp_kses($title, $allowed_tags) . wp_kses($args['after_title'], $allowed_tags); } ?> 'comic_tags'); wp_tag_cloud($cloud_args); ?>

'toocheke_comic_locations_widget', 'description' => esc_html__('Creates locations cloud.', 'toocheke'), ); parent::__construct('toocheke_comic_locations_widget', 'Toocheke: Locations Cloud', $widget_details); } public function widget($args, $instance) { $allowed_tags = array( 'section' => array( 'id' => array(), 'class' => array(), ), 'h4' => array( 'class' => array(), ), ); echo wp_kses($args['before_widget'], $allowed_tags); if (!empty($instance['title'])) { $title = !empty($instance['title']) ? $instance['title'] : ''; $title = apply_filters('widget_title', $title, $instance, $this->id_base); echo wp_kses($args['before_title'], $allowed_tags) . wp_kses($title, $allowed_tags) . wp_kses($args['after_title'], $allowed_tags); } ?> 'comic_locations'); wp_tag_cloud($cloud_args); ?>

'toocheke_comic_characters_widget', 'description' => esc_html__('Creates characters cloud.', 'toocheke'), ); parent::__construct('toocheke_comic_characters_widget', 'Toocheke: Characters Cloud', $widget_details); } public function widget($args, $instance) { $allowed_tags = array( 'section' => array( 'id' => array(), 'class' => array(), ), 'h4' => array( 'class' => array(), ), ); echo wp_kses($args['before_widget'], $allowed_tags); if (!empty($instance['title'])) { $title = !empty($instance['title']) ? $instance['title'] : ''; $title = apply_filters('widget_title', $title, $instance, $this->id_base); echo wp_kses($args['before_title'], $allowed_tags) . wp_kses($title, $allowed_tags) . wp_kses($args['after_title'], $allowed_tags); } ?> 'comic_characters'); wp_tag_cloud($cloud_args); ?>