function hocwp_setup_widget_title($title, $instance = array(), $id_base = null) { $first_char = hocwp_get_first_char($title); $char = apply_filters('hocwp_hide_widget_title_special_char', '!'); if ($char === $first_char) { $remove = apply_filters('hocwp_remove_specific_widget_title', true); if ($remove) { $title = ''; } else { $title = '<span style="display: none">' . $title . '</span>'; } } return $title; }
public function widget($args, $instance) { $this->instance = $instance; $title_text = isset($instance['title']) ? $instance['title'] : ''; $first_char = hocwp_get_first_char($title_text); if ('!' === $first_char) { $title_text = ltrim($title_text, '!'); } $banner_image = isset($instance['banner_image']) ? $instance['banner_image'] : ''; $banner_url = isset($instance['banner_url']) ? $instance['banner_url'] : ''; $banner_image = hocwp_sanitize_media_value($banner_image); $banner_image = $banner_image['url']; if (!empty($banner_image)) { hocwp_widget_before($args, $instance); $img = new HOCWP_HTML('img'); $img->set_image_src($banner_image); $img->set_image_alt($title_text); $img->set_class('hocwp-banner-image'); $html = $img->build(); if (!empty($banner_url)) { $a = new HOCWP_HTML('a'); $a->set_class('hocwp-banner-link'); $a->set_attribute('title', $title_text); $a->set_href($banner_url); $a->set_text($html); $nofollow = hocwp_get_value_by_key($instance, 'nofollow', hocwp_get_value_by_key($this->args, 'nofollow')); if ((bool) $nofollow) { $a->set_attribute('rel', 'nofollow'); } $html = $a->build(); } $widget_html = apply_filters('hocwp_widget_banner_html', $html, $args, $instance, $this); echo $widget_html; hocwp_widget_after($args, $instance); } }
function hocwp_twitter_follow_button($args = array()) { $username = hocwp_get_value_by_key($args, 'username'); if (empty($username)) { $username = hocwp_get_value_by_key($args, 'account'); } $permalink = hocwp_get_value_by_key($args, 'permalink'); if (empty($permalink)) { $permalink = $username; } if (!empty($permalink) && !hocwp_is_url($permalink)) { $permalink = 'https://twitter.com/' . $permalink; } if (empty($permalink)) { $permalink = hocwp_get_option_by_name('hocwp_option_social', 'twitter_site'); } if (empty($permalink)) { return; } $show_screen_name = hocwp_get_value_by_key($args, 'show_screen_name'); $show_count = hocwp_get_value_by_key($args, 'show_count'); $show_count = hocwp_bool_to_string($show_count); if (empty($username)) { $username = hocwp_get_last_part_in_url($permalink); } if (!empty($username)) { $first_char = hocwp_get_first_char($username); if ('@' != $first_char) { $username = '******' . $username; } } $text = __('Follow', 'hocwp-theme'); if ($show_screen_name) { $username = $text . ' ' . $username; } else { $username = $text; } $username = trim($username); $size = hocwp_get_value_by_key($args, 'size'); $show_screen_name = hocwp_bool_to_string($show_screen_name); ?> <a data-show-screen-name="<?php echo $show_screen_name; ?> " data-size="<?php echo $size; ?> " href="<?php echo esc_url($permalink); ?> " class="twitter-follow-button" data-show-count="<?php echo $show_count; ?> "><?php echo $username; ?> </a> <script type="text/javascript"> window.twttr = (function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], t = window.twttr || {}; if (d.getElementById(id)) return t; js = d.createElement(s); js.id = id; js.src = "https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); t._e = []; t.ready = function (f) { t._e.push(f); }; return t; }(document, "script", "twitter-wjs")); </script> <?php }
function hocwp_crop_image_helper($args = array()) { $source = hocwp_get_value_by_key($args, 'source'); $dest = hocwp_get_value_by_key($args, 'dest'); $width = hocwp_get_value_by_key($args, 'width'); $height = hocwp_get_value_by_key($args, 'height'); $crop_center = (bool) hocwp_get_value_by_key($args, 'crop_center'); $x = absint(hocwp_get_value_by_key($args, 'x', 0)); $y = absint(hocwp_get_value_by_key($args, 'y', 0)); $info = pathinfo($source); $extension = hocwp_get_value_by_key($info, 'extension', 'jpg'); $image = null; switch ($extension) { case 'png': $image = imagecreatefrompng($source); break; case 'gif': $image = imagecreatefromgif($source); break; case 'jpeg': case 'jpg': $image = imagecreatefromjpeg($source); break; } if (null === $image) { return $dest; } $thumb_width = $width; $thumb_height = $height; $width = imagesx($image); $height = imagesy($image); $original_aspect = $width / $height; $thumb_aspect = $thumb_width / $thumb_height; if ($original_aspect >= $thumb_aspect) { $new_width = $width / ($height / $thumb_height); $new_height = $thumb_height; } else { $new_width = $thumb_width; $new_height = $height / ($width / $thumb_width); } $thumb = imagecreatetruecolor($thumb_width, $thumb_height); if ($crop_center) { $x = 0 - ($new_width - $thumb_width) / 2; $y = 0 - ($new_height - $thumb_height) / 2; } imagecopyresampled($thumb, $image, $x, $y, 0, 0, $new_width, $new_height, $width, $height); $quality = absint(apply_filters('hocwp_image_quality', 80)); if (!is_numeric($quality) || $quality < 0 || $quality > 100) { $quality = 80; } switch ($extension) { case 'png': $first_char = hocwp_get_first_char($quality); $quality = absint($first_char); imagepng($thumb, $dest, $quality); break; case 'gif': imagegif($thumb, $dest); break; case 'jpeg': case 'jpg': imagejpeg($thumb, $dest, $quality); break; } unset($image); unset($thumb); return $dest; }
function hocwp_get_current_url() { global $wp; $request = $wp->request; if (empty($request)) { $uri = basename($_SERVER['REQUEST_URI']); $first_char = hocwp_get_first_char($uri); if ('?' === $first_char) { $uri = hocwp_remove_first_char($uri, '?'); } else { $parts = explode('?', $uri); if (count($parts) == 2) { $uri = $parts[1]; } } $request = '?' . $uri; $current_url = trailingslashit(home_url()) . $request; } else { $current_url = trailingslashit(home_url($request)); } $current_url = apply_filters('hocwp_current_url', $current_url); return $current_url; }
function hocwp_build_css_rule($elements, $properties) { $elements = hocwp_to_array($elements); $properties = hocwp_to_array($properties); $before = ''; foreach ($elements as $element) { if (empty($element)) { continue; } $first_char = hocwp_get_first_char($element); if ('.' !== $first_char && strpos($element, '.') === false) { $element = '.' . $element; } $before .= $element . ','; } $before = trim($before, ','); $after = ''; foreach ($properties as $key => $property) { if (empty($key)) { continue; } $after .= $key . ':' . $property . ';'; } $after = trim($after, ';'); return $before . '{' . $after . '}'; }