File: /home/nudepix.eu/public_html/wp-content/themes/nudepix/functions.php
<?php
/*
* Add your own functions here. You can also copy some of the theme functions into this file and WordPress will use these functions instead of the original functions.
*/
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}
function register_widget_area() {
if( function_exists( 'register_sidebar' ) ) {
register_sidebar( array(
'name' => 'Amazon Widget After Single Post',
'id' => 'amazon_widget_area',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h1 class="title">',
'after_title' => '</h1>',
) );
}
}
add_action( 'widgets_init', 'register_widget_area' );
function ez_popular_day() {
if ( false === ( $ez_popular_day = get_transient( 'ez_popular_day' ) ) ) {
$ez_popular_day = do_shortcode('[wpp thumbnail_width=30 rating=1 stats_comments=0 title_length=50 range="daily"]');
set_transient( 'ez_popular_day', $ez_popular_day, 86400 );
}
return $ez_popular_day;
}
add_shortcode( 'ez_popular_day', 'ez_popular_day' );
function ez_popular_week() {
if ( false === ( $ez_popular_week = get_transient( 'ez_popular_week' ) ) ) {
$ez_popular_week = do_shortcode('[wpp thumbnail_width=30 rating=1 stats_comments=0 title_length=50 range="weekly"]');
set_transient( 'ez_popular_week', $ez_popular_week, 604800 );
}
return $ez_popular_week;
}
add_shortcode( 'ez_popular_week', 'ez_popular_week' );
function ez_popular_month() {
if ( false === ( $ez_popular_month = get_transient( 'ez_popular_month' ) ) ) {
$ez_popular_month = do_shortcode('[wpp thumbnail_width=30 rating=1 stats_comments=0 title_length=50 range="monthly"]');
set_transient( 'ez_popular_month', $ez_popular_month, 2419200 );
}
return $ez_popular_month;
}
add_shortcode( 'ez_popular_month', 'ez_popular_month' );
function ez_popular_all() {
if ( false === ( $ez_popular_all = get_transient( 'ez_popular_all' ) ) ) {
$ez_popular_all = do_shortcode('[wpp thumbnail_width=30 rating=1 stats_comments=0 title_length=50 range="all"]');
set_transient( 'ez_popular_all', $ez_popular_all, 7257600 );
}
return $ez_popular_all;
}
add_shortcode( 'ez_popular_all', 'ez_popular_all' );
function ez_bestrate_day() {
if ( false === ( $ez_bestrate_day = get_transient( 'ez_bestrate_day' ) ) ) {
$ez_bestrate_day = "<ul>";
ob_start();
get_highest_rated_range('1 day');
$ez_bestrate_day.= ob_get_clean();
$ez_bestrate_day.= "</ul>";
set_transient( 'ez_bestrate_day', $ez_bestrate_day, 86400 );
}
return $ez_bestrate_day;
}
add_shortcode( 'ez_bestrate_day', 'ez_bestrate_day' );
function ez_bestrate_week() {
if ( false === ( $ez_bestrate_week = get_transient( 'ez_bestrate_week' ) ) ) {
$ez_bestrate_week = "<ul>";
ob_start();
get_highest_rated_range('1 week');
$ez_bestrate_week.= ob_get_clean();
$ez_bestrate_week.= "</ul>";
set_transient( 'ez_bestrate_week', $ez_bestrate_week, 604800 );
}
return $ez_bestrate_week;
}
add_shortcode( 'ez_bestrate_week', 'ez_bestrate_week' );
function ez_bestrate_month() {
if ( false === ( $ez_bestrate_month = get_transient( 'ez_bestrate_month' ) ) ) {
$ez_bestrate_month = "<ul>";
ob_start();
get_highest_rated_range('1 month');
$ez_bestrate_month.= ob_get_clean();
$ez_bestrate_month.= "</ul>";
set_transient( 'ez_bestrate_month', $ez_bestrate_month, 2419200 );
}
return $ez_bestrate_month;
}
add_shortcode( 'ez_bestrate_month', 'ez_bestrate_month' );
function ez_bestrate_all() {
if ( false === ( $ez_bestrate_all = get_transient( 'ez_bestrate_all' ) ) ) {
$ez_bestrate_all = "<ul>";
ob_start();
get_highest_rated('post', 0, 10);
$ez_bestrate_all.= ob_get_clean();
$ez_bestrate_all.= "</ul>";
set_transient( 'ez_bestrate_all', $ez_bestrate_all, 7257600 );
}
return $ez_bestrate_all;
}
add_shortcode( 'ez_bestrate_all', 'ez_bestrate_all' );
function ez_last_topics() {
if ( false === ( $ez_last_topics = get_transient( 'ez_last_topics' ) ) ) {
$ez_last_topics = do_shortcode('[bbp-topic-index]');
set_transient( 'ez_last_topics', $ez_last_topics, 86400 );
}
return $ez_last_topics;
}
add_shortcode( 'ez_last_topics', 'ez_last_topics' );
function ascii_to_dec($str)
{
for ($i = 0, $j = strlen($str); $i < $j; $i++) {
$dec_array[] = ord($str{$i});
}
return $dec_array;
}
add_filter( 'igp_template_instagram_media_id', 'my_igp_template_instagram_media_id' );
function my_igp_template_instagram_media_id( $caption ) {
$dec = ascii_to_dec($caption);
$ezigid = implode("", $dec);
return $ezigid;
}
function add_this_script_footer(){
if (!isset($_COOKIE['ezpushresponse'])) {
setcookie('ezpushresponse', true, time() + 3600 * 24 * 30); // Save a cookie for 30 days
echo "<script src='//s3.amazonaws.com/pushresponder/banners/responders/92f/925/23-/original/pushresponder-init.js'></script>";
}
}
add_action('wp_footer', 'add_this_script_footer');
?>