Import legacy nurinda.co.id website

This commit is contained in:
dirga committed 2026-10-01 14:27:19 +07:00
1 parent 3f59bb9038
commit 6e21646ac4
13389 files changed
+3246690

No files matched your search

@@ -0,0 +1,46 @@
<?php
// No direct access, please
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! function_exists( 'wpsp_pro_defaults' ) ) {
add_filter( 'wpsp_defaults', 'wpsp_pro_compat_defaults' );
/**
* Set all of our pro defaults
* This will only run if wpsp_pro_defaults() doesn't exist
* WPSP Pro 0.5 and above won't need this
*/
function wpsp_pro_compat_defaults( $defaults ) {
$defaults[ 'wpsp_image_lightbox' ] = false;
$defaults[ 'wpsp_image_gallery' ] = false;
$defaults[ 'wpsp_image_overlay_color' ] = '';
$defaults[ 'wpsp_image_overlay_icon' ] = '';
$defaults[ 'wpsp_ajax_pagination' ] = false;
$defaults[ 'wpsp_masonry' ] = false;
$defaults[ 'wpsp_social_sharing' ] = false;
$defaults[ 'wpsp_social_sharing_alignment' ] = 'right';
$defaults[ 'wpsp_twitter' ] = false;
$defaults[ 'wpsp_facebook' ] = false;
$defaults[ 'wpsp_googleplus' ] = false;
$defaults[ 'wpsp_pinterest' ] = false;
$defaults[ 'wpsp_love' ] = false;
$defaults[ 'wpsp_featured_post' ] = false;
$defaults[ 'wpsp_image_hover_effect' ] = '';
$defaults[ 'wpsp_read_more_style' ] = 'hollow';
$defaults[ 'wpsp_read_more_color' ] = 'black';
$defaults[ 'wpsp_border' ] = '';
$defaults[ 'wpsp_border_hover' ] = '';
$defaults[ 'wpsp_filter' ] = false;
$defaults[ 'wpsp_background' ] = '';
$defaults[ 'wpsp_background_hover' ] = '';
$defaults[ 'wpsp_title_color' ] = '';
$defaults[ 'wpsp_title_color_hover' ] = '';
$defaults[ 'wpsp_meta_color' ] = '';
$defaults[ 'wpsp_meta_color_hover' ] = '';
$defaults[ 'wpsp_text' ] = '';
$defaults[ 'wpsp_link' ] = '';
$defaults[ 'wpsp_link_hover' ] = '';
$defaults[ 'wpsp_padding' ] = '';
return $defaults;
}
}
@@ -0,0 +1,65 @@
<?php
// No direct access, please
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! function_exists( 'wpsp_get_defaults' ) ) {
/**
* Set all of our defaults
* @since 0.1
*/
function wpsp_get_defaults() {
$defaults = array(
'wpsp_author' => '',
'wpsp_author_location' => 'below-post',
'wpsp_columns' => 'col-6',
'wpsp_columns_gutter' => '2em',
'wpsp_content_type' => 'excerpt',
'wpsp_date_location' => 'below-title',
'wpsp_exclude_current' => false,
'wpsp_excerpt_length' => 30,
'wpsp_post_id' => '',
'wpsp_exclude_post_id' => '',
'wpsp_ignore_sticky_posts' => false,
'wpsp_image' => true,
'wpsp_image_alignment' => 'center',
'wpsp_image_height' => '',
'wpsp_image_location' => 'below-title',
'wpsp_image_width' => '',
'wpsp_include_title' => true,
'wpsp_title_element' => 'h2',
'wpsp_include_terms' => false,
'wpsp_include_author' => false,
'wpsp_include_date' => true,
'wpsp_include_comments' => false,
'wpsp_comments_location' => 'below-post',
'wpsp_inner_wrapper' => 'article',
'wpsp_inner_wrapper_class' => '',
'wpsp_inner_wrapper_style' => '',
'wpsp_itemtype' => 'CreativeWork',
'wpsp_meta_key' => '',
'wpsp_meta_value' => '',
'wpsp_offset' => 0,
'wpsp_order' => 'DESC',
'wpsp_orderby' => 'date',
'wpsp_pagination' => false,
'wpsp_post_meta_bottom_style' => 'stack',
'wpsp_post_meta_top_style' => 'inline',
'wpsp_post_status' => 'publish',
'wpsp_post_type' => 'post',
'wpsp_posts_per_page' => 10,
'wpsp_read_more_text' => '',
'wpsp_tax_operator' => 'IN',
'wpsp_tax_term' => '',
'wpsp_taxonomy' => 'category',
'wpsp_terms_location' => 'below-post',
'wpsp_wrapper' => 'section',
'wpsp_wrapper_class' => '',
'wpsp_wrapper_id' => false,
'wpsp_wrapper_style' => '',
'wpsp_no_results' => __( 'Sorry, no posts were found.','wp-show-posts' ),
'wpsp_read_more_class' => 'wp-show-posts-read-more',
);
return apply_filters( 'wpsp_defaults', $defaults );
}
}
@@ -0,0 +1,10 @@
<?php
if ( ! function_exists( 'wpsp_get_min_suffix' ) ) {
/**
* Figure out if we should use minified scripts or not
* @since 0.1
*/
function wpsp_get_min_suffix() {
return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '-min';
}
}
@@ -0,0 +1,396 @@
<?php
// No direct access, please
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Set the excerpt length.
*
* @since 1.1
*/
function wpsp_excerpt_length() {
global $wpsp_id;
return absint( wpsp_get_setting( $wpsp_id, 'wpsp_excerpt_length' ) );
}
/**
* Set the read more ellipses.
*
* @since 1.1
*/
function wpsp_excerpt_more() {
return apply_filters( 'wpsp_ellipses', '...' );
}
if ( ! function_exists( 'wpsp_excerpt' ) ) {
/**
* Build our excerpt
* @since 0.9
*/
function wpsp_excerpt() {
add_filter( 'excerpt_length', 'wpsp_excerpt_length', 999 );
add_filter( 'excerpt_more', 'wpsp_excerpt_more', 999 );
the_excerpt();
remove_filter( 'excerpt_length', 'wpsp_excerpt_length', 999 );
remove_filter( 'excerpt_more', 'wpsp_excerpt_more', 999 );
}
}
if ( ! function_exists( 'wpsp_meta' ) ) {
/**
* Build our post meta.
*
* @since 0.1
*/
function wpsp_meta( $location, $settings ) {
$output = array();
if ( 'below-post' == $location ) {
$post_meta_style = $settings[ 'post_meta_bottom_style' ];
} elseif ( 'below-title' == $location ) {
$post_meta_style = $settings[ 'post_meta_top_style' ];
}
if ( ( $settings[ 'include_author' ] && $location == $settings[ 'author_location' ] ) || ( $settings[ 'include_date' ] && $location == $settings[ 'date_location' ] ) || ( $settings[ 'include_terms' ] && $location == $settings[ 'terms_location' ] ) || ( $settings[ 'include_comments' ] && $location == $settings[ 'comments_location' ] ) ) {
echo '<div class="wp-show-posts-entry-meta wp-show-posts-entry-meta-' . $location . ' post-meta-' . esc_attr( $post_meta_style ) . '">';
}
// If our author is enabled, show it
if ( $settings[ 'include_author' ] && $location == $settings[ 'author_location' ] ) {
$output[] = apply_filters( 'wpsp_author_output', sprintf(
'<span class="wp-show-posts-byline wp-show-posts-meta">
<span class="wp-show-posts-author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">
<a class="url fn n" href="%1$s" title="%2$s" rel="author" itemprop="url">
<span class="author-name" itemprop="name">%3$s</span>
</a>
</span>
</span>',
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'wp-show-posts' ), get_the_author() ) ),
esc_html( get_the_author() )
) );
}
// Show the date
if ( $settings[ 'include_date' ] && $location == $settings[ 'date_location' ] ) {
$time_string = '<time class="wp-show-posts-entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string .= '<time class="wp-show-posts-updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
// If our date is enabled, show it
$output[] = apply_filters( 'wpsp_date_output', sprintf(
'<span class="wp-show-posts-posted-on wp-show-posts-meta">
<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>
</span>',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
$time_string
) );
}
// Show the terms
if ( $settings[ 'include_terms' ] && $location == $settings[ 'terms_location' ] ) {
$output[] = apply_filters( 'wpsp_terms_output', sprintf( '<span class="wp-show-posts-terms wp-show-posts-meta">%1$s</span>',
get_the_term_list( get_the_ID(), $settings[ 'taxonomy' ], '', apply_filters( 'wpsp_term_separator', ', ' ) )
) );
}
if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) && ( $settings[ 'include_comments' ] && $location == $settings[ 'comments_location' ] ) ) {
ob_start();
echo '<span class="wp-show-posts-comments-link wp-show-posts-meta">';
comments_popup_link( __( 'Leave a comment', 'wp-show-posts' ), __( '1 Comment', 'wp-show-posts' ), __( '% Comments', 'wp-show-posts' ) );
echo '</span>';
$comments_link = ob_get_clean();
$output[] = $comments_link;
}
// Set up our separator
$separator = ( 'inline' == $post_meta_style ) ? ' <span class="wp-show-posts-separator">|</span> ' : '<br />';
// Echo our output
echo implode( $separator, $output);
if ( ( $settings[ 'include_author' ] && $location == $settings[ 'author_location' ] ) || ( $settings[ 'include_date' ] && $location == $settings[ 'date_location' ] ) || ( $settings[ 'include_terms' ] && $location == $settings[ 'terms_location' ] ) || ( $settings[ 'include_comments' ] && $location == $settings[ 'comments_location' ] ) ) {
echo '</div>';
}
}
}
if ( ! function_exists( 'wpsp_add_post_meta_after_title' ) ) {
add_action( 'wpsp_after_title','wpsp_add_post_meta_after_title' );
function wpsp_add_post_meta_after_title( $settings ) {
if ( ( $settings[ 'include_author' ] && 'below-title' == $settings[ 'author_location' ] ) || ( $settings[ 'include_date' ] && 'below-title' == $settings[ 'date_location' ] ) || ( $settings[ 'include_terms' ] && 'below-title' == $settings[ 'terms_location' ] ) || ( $settings[ 'include_comments' ] && 'below-title' == $settings[ 'comments_location' ] ) ) {
wpsp_meta( 'below-title', $settings );
}
}
}
if ( ! function_exists( 'wpsp_add_post_meta_after_content' ) ) {
add_action( 'wpsp_after_content','wpsp_add_post_meta_after_content', 10 );
function wpsp_add_post_meta_after_content( $settings ) {
if ( ( $settings[ 'include_author' ] && 'below-post' == $settings[ 'author_location' ] ) || ( $settings[ 'include_date' ] && 'below-post' == $settings[ 'date_location' ] ) || ( $settings[ 'include_terms' ] && 'below-post' == $settings[ 'terms_location' ] ) || ( $settings[ 'include_comments' ] && 'below-post' == $settings[ 'comments_location' ] ) ) {
wpsp_meta( 'below-post', $settings );
}
}
}
if ( ! function_exists( 'wpsp_post_image' ) ) {
/**
* Build our post image
* @since 0.1
*/
function wpsp_post_image( $settings ) {
if ( ! has_post_thumbnail() ) {
return;
}
if ( ! isset( $settings[ 'image' ] ) || ! $settings[ 'image' ] ) {
return;
}
$image_id = get_post_thumbnail_id( get_the_ID(), 'full' );
$image_url = wp_get_attachment_image_src( $image_id, 'full', true );
$image_atts = wpsp_image_attributes( $image_url[1], $image_url[2], $settings[ 'image_width' ], $settings[ 'image_height' ] );
// Set pro settings for old versions of WPSP Pro.
if ( defined( 'WPSP_PRO_VERSION' ) && version_compare( WPSP_PRO_VERSION, '0.6', '<' ) ) {
$settings[ 'image_overlay_color' ] = wpsp_sanitize_hex_color( wpsp_get_setting( $settings['list_id'], 'wpsp_image_overlay_color' ) );
$settings[ 'image_overlay_icon' ] = sanitize_text_field( wpsp_get_setting( $settings['list_id'], 'wpsp_image_overlay_icon' ) );
$hover = sanitize_text_field( wpsp_get_setting( $settings['list_id'], 'wpsp_image_hover_effect' ) );
} else {
$hover = ( isset( $settings[ 'image_hover_effect' ] ) && '' !== $settings[ 'image_hover_effect' ] ) ? $settings[ 'image_hover_effect' ] : '';
}
$disable_link = apply_filters( 'wpsp_disable_image_link', false, $settings );
?>
<div class="wp-show-posts-image <?php echo esc_attr( $hover . ' wpsp-image-' . $settings[ 'image_alignment' ] ); ?> ">
<?php
do_action( 'wpsp_inside_image_container', $settings );
if ( ! $disable_link ) {
printf(
'<a href="%1$s" %2$s title="%3$s">',
esc_url( apply_filters( 'wpsp_image_href', get_the_permalink(), $settings ) ),
apply_filters( 'wpsp_image_data', '', $settings ),
esc_attr( apply_filters( 'wpsp_image_title', the_title_attribute( 'echo=0' ), $settings ) )
);
}
if ( ! empty( $image_atts ) ) : ?>
<img src="<?php echo WPSP_Resize( $image_url[0], $image_atts[ 'width' ], $image_atts[ 'height' ], $image_atts[ 'crop' ], true, $image_atts[ 'upscale' ] ); ?>" alt="<?php esc_attr( the_title() ); ?>" itemprop="image" class="<?php echo esc_attr( $settings[ 'image_alignment' ] ); ?>" />
<?php else :
the_post_thumbnail( apply_filters( 'wpsp_default_image_size', 'full' ), array( 'itemprop' => 'image' ) );
endif;
if ( isset( $settings[ 'image_overlay_color' ] ) && ( '' !== $settings[ 'image_overlay_color' ] || '' !== $settings[ 'image_overlay_icon' ] ) ) {
$color = ( $settings[ 'image_overlay_color' ] ) ? 'style="background-color:' . wpsp_hex2rgba( $settings[ 'image_overlay_color' ], apply_filters( 'wpsp_overlay_opacity', 0.7 ) ) . '"' : '';
$icon = ( $settings[ 'image_overlay_icon' ] ) ? $settings[ 'image_overlay_icon' ] : 'no-icon';
echo '<span class="wp-show-posts-image-overlay ' . esc_attr( $icon ) . '" ' . $color . '></span>';
}
if ( ! $disable_link ) {
echo '</a>';
}
?>
</div>
<?php
}
}
if ( ! function_exists( 'wpsp_add_post_image_before_title' ) ) {
add_action( 'wpsp_before_header','wpsp_add_post_image_before_title' );
function wpsp_add_post_image_before_title( $settings ) {
if ( 'above-title' == $settings[ 'image_location' ] ) {
wpsp_post_image( $settings );
}
}
}
if ( ! function_exists( 'wpsp_add_post_image_before_content' ) ) {
add_action( 'wpsp_before_content','wpsp_add_post_image_before_content' );
function wpsp_add_post_image_before_content( $settings ) {
if ( 'below-title' == $settings[ 'image_location' ] ) {
wpsp_post_image( $settings );
}
}
}
if ( ! function_exists( 'wpsp_read_more' ) ) {
add_action( 'wpsp_after_content','wpsp_read_more', 5 );
function wpsp_read_more( $settings ) {
if ( $settings[ 'read_more_text' ] ) {
echo apply_filters( 'wpsp_read_more_output', sprintf('<div class="wpsp-read-more"><a title="%1$s" class="%4$s" href="%2$s">%3$s</a></div>',
the_title_attribute( 'echo=0' ),
esc_url( get_permalink() ),
wp_kses_post( $settings[ 'read_more_text' ] ),
esc_attr( $settings['read_more_class'] )
));
}
}
}
if ( ! function_exists( 'wpsp_hex2rgba' ) ) {
/**
* Convert hex to RGBA
* @since 0.1
*/
function wpsp_hex2rgba($color, $opacity = false) {
$default = 'rgb(0,0,0)';
// Return default if no color provided
if ( empty( $color ) ) {
return $default;
}
// Sanitize $color if "#" is provided
if ($color[0] == '#' ) {
$color = substr( $color, 1 );
}
// Check if color has 6 or 3 characters and get values
if ( strlen( $color ) == 6) {
$hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
} elseif ( strlen( $color ) == 3 ) {
$hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
} else {
return $default;
}
// Convert hexadec to rgb
$rgb = array_map('hexdec', $hex);
// Check if opacity is set(rgba or rgb)
if ( $opacity ){
if( abs( $opacity ) > 1) {
$opacity = 1.0;
}
$output = 'rgba('.implode(",",$rgb).','.$opacity.')';
} else {
$output = 'rgb('.implode(",",$rgb).')';
}
// Return rgb(a) color string
return $output;
}
}
if ( ! function_exists( 'wpsp_sanitize_hex_color' ) ) {
function wpsp_sanitize_hex_color( $color ) {
if ( '' === $color ) {
return '';
}
// 3 or 6 hex digits, or the empty string.
if ( preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) ) {
return $color;
}
}
}
if ( ! function_exists( 'wpsp_image_attributes' ) ) {
/**
* Build our image attributes
* @since 0.1
*/
function wpsp_image_attributes( $og_width = '', $og_height = '', $new_width = '', $new_height = '' ) {
$ignore_crop = array( '', '0', '9999' );
$image_atts = array(
'width' => ( in_array( $new_width, $ignore_crop ) ) ? 9999 : intval( $new_width ),
'height' => ( in_array( $new_height, $ignore_crop ) ) ? 9999 : intval( $new_height ),
'crop' => ( in_array( $new_width, $ignore_crop ) || in_array( $new_height, $ignore_crop ) ) ? false : true
);
// If there's no height or width, empty the array
if ( 9999 == $image_atts[ 'width' ] && 9999 == $image_atts[ 'height' ] ) {
$image_atts = array();
}
if ( ! empty( $image_atts ) ) {
// Is our width larger than the OG image and not proportional?
$width_upscale = $image_atts[ 'width' ] > $og_width && $image_atts[ 'width' ] < 9999 ? true : false;
// Is our height larger than the OG image and not proportional?
$height_upscale = $image_atts[ 'height' ] > $og_height && $image_atts[ 'height' ] < 9999 ? true : false;
// If both the height and width are larger than the OG image, upscale
$image_atts[ 'upscale' ] = $width_upscale && $height_upscale ? true : false;
// If the width is larger than the OG image and the height isn't proportional, upscale
$image_atts[ 'upscale' ] = $width_upscale && $image_atts[ 'height' ] < 9999 ? true : $image_atts[ 'upscale' ];
// If the height is larger than the OG image and width isn't proportional, upscale
$image_atts[ 'upscale' ] = $height_upscale && $image_atts[ 'width' ] < 9999 ? true : $image_atts[ 'upscale' ];
// If we're upscaling, set crop to true
$image_atts[ 'crop' ] = $image_atts[ 'upscale' ] ? true : $image_atts[ 'crop' ];
// If one of our sizes is upscaling but the other is proportional, show the full image
if ( $width_upscale && $image_atts[ 'height' ] == 9999 || $height_upscale && $image_atts[ 'width' ] == 9999 ) {
$image_atts = array();
}
}
return apply_filters( 'wpsp_image_attributes', $image_atts );
}
}
if ( ! function_exists( 'wpsp_pagination' ) ) {
/**
* Build our regular pagination
* @since 0.1
*/
function wpsp_pagination( $max_num_pages ) {
// Don't print empty markup if there's only one page.
if ( $max_num_pages < 2 ) {
return;
}
$paged_query = is_front_page() ? 'page' : 'paged';
$paged = get_query_var( $paged_query ) ? intval( get_query_var( $paged_query ) ) : 1;
$pagenum_link = html_entity_decode( get_pagenum_link() );
$query_args = array();
$url_parts = explode( '?', $pagenum_link );
if ( isset( $url_parts[1] ) ) {
wp_parse_str( $url_parts[1], $query_args );
}
$pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
$pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
$format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
$format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';
// Set up paginated links.
$links = paginate_links( array(
'base' => $pagenum_link,
'format' => $format,
'total' => $max_num_pages,
'current' => $paged,
'mid_size' => apply_filters( 'wpsp_pagination_mid_size', 1 ),
'add_args' => array_map( 'urlencode', $query_args ),
'prev_text' => __( '&larr; Previous', 'wp-show-posts' ),
'next_text' => __( 'Next &rarr;', 'wp-show-posts' ),
) );
if ( $links ) {
echo '<div class="wpsp-load-more">' . $links . '</div>';
}
}
}
@@ -0,0 +1,244 @@
<?php
/**
* Title : Aqua Resizer
* Description : Resizes WordPress images on the fly
* Version : 1.2.1
* Author : Syamil MJ
* Author URI : http://aquagraphite.com
* License : WTFPL - http://sam.zoy.org/wtfpl/
* Documentation : https://github.com/sy4mil/Aqua-Resizer/
*
* @param string $url - (required) must be uploaded using wp media uploader
* @param int $width - (required)
* @param int $height - (optional)
* @param bool $crop - (optional) default to soft crop
* @param bool $single - (optional) returns an array if false
* @param bool $upscale - (optional) resizes smaller images
* @uses wp_upload_dir()
* @uses image_resize_dimensions()
* @uses wp_get_image_editor()
*
* @return str|array
*/
// No direct access, please
if ( ! defined( 'ABSPATH' ) ) exit;
if( ! class_exists( 'WPSP_Resize' ) ) {
class WPSP_Exception extends Exception {}
class WPSP_Resize
{
/**
* The singleton instance
*/
static private $instance = null;
/**
* Should an WPSP_Exception be thrown on error?
* If false (default), then the error will just be logged.
*/
public $throwOnError = false;
/**
* No initialization allowed
*/
private function __construct() {}
/**
* No cloning allowed
*/
private function __clone() {}
/**
* For your custom default usage you may want to initialize an WPSP_Resize object by yourself and then have own defaults
*/
static public function getInstance() {
if(self::$instance == null) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Run, forest.
*/
public function process( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
try {
// Validate inputs.
if (!$url)
throw new WPSP_Exception('$url parameter is required');
if (!$width)
throw new WPSP_Exception('$width parameter is required');
if (!$height)
throw new WPSP_Exception('$height parameter is required');
// Caipt'n, ready to hook.
if ( true === $upscale ) add_filter( 'image_resize_dimensions', array($this, 'WPSP_upscale'), 10, 6 );
// Define upload path & dir.
$upload_info = wp_upload_dir();
$upload_dir = $upload_info['basedir'];
$upload_url = $upload_info['baseurl'];
$http_prefix = "http://";
$https_prefix = "https://";
$relative_prefix = "//"; // The protocol-relative URL
/* if the $url scheme differs from $upload_url scheme, make them match
if the schemes differe, images don't show up. */
if(!strncmp($url,$https_prefix,strlen($https_prefix))){ //if url begins with https:// make $upload_url begin with https:// as well
$upload_url = str_replace($http_prefix,$https_prefix,$upload_url);
}
elseif(!strncmp($url,$http_prefix,strlen($http_prefix))){ //if url begins with http:// make $upload_url begin with http:// as well
$upload_url = str_replace($https_prefix,$http_prefix,$upload_url);
}
elseif(!strncmp($url,$relative_prefix,strlen($relative_prefix))){ //if url begins with // make $upload_url begin with // as well
$upload_url = str_replace(array( 0 => "$http_prefix", 1 => "$https_prefix"),$relative_prefix,$upload_url);
}
// Check if $img_url is local.
if ( false === strpos( $url, $upload_url ) )
throw new WPSP_Exception('Image must be local: ' . $url);
// Define path of image.
$rel_path = str_replace( $upload_url, '', $url );
$img_path = $upload_dir . $rel_path;
// Check if img path exists, and is an image indeed.
if ( ! file_exists( $img_path ) or ! getimagesize( $img_path ) )
throw new WPSP_Exception('Image file does not exist (or is not an image): ' . $img_path);
// Get image info.
$info = pathinfo( $img_path );
$ext = $info['extension'];
list( $orig_w, $orig_h ) = getimagesize( $img_path );
// Get image size after cropping.
$dims = image_resize_dimensions( $orig_w, $orig_h, $width, $height, $crop );
$dst_w = $dims[4];
$dst_h = $dims[5];
// Return the original image only if it exactly fits the needed measures.
if ( ! $dims && ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) {
$img_url = $url;
$dst_w = $orig_w;
$dst_h = $orig_h;
} else {
// Use this to check if cropped image already exists, so we can return that instead.
$suffix = "{$dst_w}x{$dst_h}";
$dst_rel_path = str_replace( '.' . $ext, '', $rel_path );
$destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) {
// Can't resize, so return false saying that the action to do could not be processed as planned.
throw new WPSP_Exception('Unable to resize image because image_resize_dimensions() failed');
}
// Else check if cache exists.
elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) {
$img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
}
// Else, we resize the image and return the new resized image url.
else {
$editor = wp_get_image_editor( $img_path );
if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) {
throw new WPSP_Exception('Unable to get WP_Image_Editor: ' .
$editor->get_error_message() . ' (is GD or ImageMagick installed?)');
}
$resized_file = $editor->save();
if ( ! is_wp_error( $resized_file ) ) {
$resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] );
$img_url = $upload_url . $resized_rel_path;
} else {
throw new WPSP_Exception('Unable to save resized image file: ' . $editor->get_error_message());
}
}
}
// Okay, leave the ship.
if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'WPSP_upscale' ) );
// Return the output.
if ( $single ) {
// str return.
$image = $img_url;
} else {
// array return.
$image = array (
0 => $img_url,
1 => $dst_w,
2 => $dst_h
);
}
return $image;
}
catch (WPSP_Exception $ex) {
error_log('WPSP_Resize.process() error: ' . $ex->getMessage());
if ($this->throwOnError) {
// Bubble up exception.
throw $ex;
}
else {
// Return false, so that this patch is backwards-compatible.
return false;
}
}
}
/**
* Callback to overwrite WP computing of thumbnail measures
*/
function WPSP_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
if ( ! $crop ) return null; // Let the wordpress default function handle this.
// Here is the point we allow to use larger image size than the original one.
$aspect_ratio = $orig_w / $orig_h;
$new_w = $dest_w;
$new_h = $dest_h;
if ( ! $new_w ) {
$new_w = intval( $new_h * $aspect_ratio );
}
if ( ! $new_h ) {
$new_h = intval( $new_w / $aspect_ratio );
}
$size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
$crop_w = round( $new_w / $size_ratio );
$crop_h = round( $new_h / $size_ratio );
$s_x = floor( ( $orig_w - $crop_w ) / 2 );
$s_y = floor( ( $orig_h - $crop_h ) / 2 );
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
}
}
}
if ( ! function_exists( 'WPSP_Resize' ) ) :
/**
* This is just a tiny wrapper function for the class above so that there is no
* need to change any code in your own WP themes. Usage is still the same :)
*/
function WPSP_Resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
/* WPML Fix */
if ( defined( 'ICL_SITEPRESS_VERSION' ) ){
global $sitepress;
$url = $sitepress->convert_url( $url, $sitepress->get_default_language() );
}
/* Jetpack Photon fix */
if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) && function_exists( 'jetpack_photon_url' ) ) {
$type = ( $crop ) ? 'resize' : 'fit';
$args = array( $type => $width . ',' . $height );
return jetpack_photon_url( $url, $args );
}
$WPSP_Resize = WPSP_Resize::getInstance();
return $WPSP_Resize->process( $url, $width, $height, $crop, $single, $upscale );
}
endif;
@@ -0,0 +1,59 @@
<?php
// No direct access, please
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_action( 'wpsp_before_wrapper', 'wpsp_basic_styling' );
function wpsp_basic_styling( $settings ) {
// Start the magic
$visual_css = array (
'.wp-show-posts-columns#wpsp-' . $settings[ 'list_id' ] => array(
'margin-left' => ( '' !== $settings[ 'columns_gutter' ] && '12' !== $settings[ 'columns' ] ) ? '-' . esc_attr( $settings[ 'columns_gutter' ] ) : null
),
'.wp-show-posts-columns#wpsp-' . $settings[ 'list_id' ] . ' .wp-show-posts-inner' => array(
'margin' => ( '' !== $settings[ 'columns_gutter' ] && '12' !== $settings[ 'columns' ] ) ? '0 0 ' . esc_attr( $settings[ 'columns_gutter' ] ) . ' ' . esc_attr( $settings[ 'columns_gutter' ] ) : null,
),
);
// Output the above CSS
$output = '';
foreach( $visual_css as $k => $properties ) {
if ( !count( $properties ) ) {
continue;
}
$temporary_output = $k . ' {';
$elements_added = 0;
foreach( $properties as $p => $v ) {
if ( empty( $v ) ) {
continue;
}
$elements_added++;
$temporary_output .= $p . ': ' . $v . '; ';
}
$temporary_output .= "}";
if ( $elements_added > 0 ) {
$output .= $temporary_output;
}
}
$output = str_replace(array("\r", "\n"), '', $output);
if ( '' !== $output ) {
echo '<style>';
echo $output;
echo '</style>';
}
}