#6261

mathewnephews
Participant
Points: 7

<?php
/* **************************************************************** */
/* RSS met images enclosed */
/* */
/* 1. Vraag een beeld op */
/* 2. Bepaal mime type en omvang */
/* 3. voeg een functie toe die extra de ‘enclosed’ tag echoot */
/* via add_action met als hook rss2_item */
/* **************************************************************** */
/* utility functions: url2filepath om straks de filesize op te kunnen vragen */
// this sets the sytem / or \ :
strstr( PHP_OS, “WIN”) ? $slash = “\\” : $slash = “/”;
// This is the location of the php file that contains this
// function. Usually this request is made to files/folders
// down the directory structure, so the php file that
// contains these functions is a good “where am i”
// reference point:
$WIMPY_BASE[‘path’][‘physical’] = getcwd();
$WIMPY_BASE[‘path’][‘www’] = “http://”.$_SERVER[‘HTTP_HOST’];
function url2filepath($theURL){
global $WIMPY_BASE, $slash;
$AtheFile = explode (“/”, $theURL);
$theFileName = array_pop($AtheFile);
$AwimpyPathWWW = explode (“/”, $WIMPY_BASE[‘path’][‘www’]);
$AtheFilePath = array_values (array_diff ($AtheFile, $AwimpyPathWWW));
if($AtheFilePath){
$theFilePath = $slash.implode($slash, $AtheFilePath).$slash.$theFileName;
} else {
$theFilePath = implode($slash, $AtheFilePath).$slash.$theFileName;
}
return ($WIMPY_BASE[‘path’][‘physical’].$theFilePath);
}
function filepath2url ($theFilepath){
global $WIMPY_BASE, $slash;
$AtheFile = explode ($slash, $theFilepath);
$theFileName = array_pop($AtheFile);
$AwimpyPathFILE = explode ($slash, $WIMPY_BASE[‘path’][‘physical’]);
$AtheFilePath = array_values (array_diff ($AtheFile, $AwimpyPathFILE));
$thFileURL = implode(“/”, $AtheFilePath).”/”.$theFileName;
return ($WIMPY_BASE[‘path’][‘www’].”$thFileURL”);
}
function add_featured_image_in_rss() {
if ( function_exists( ‘get_the_image’ ) && ( $featured_image = get_the_image(‘format=array&echo=0’) ) ) {
$featured_image[0] = $featured_image[‘url’];
} elseif ( function_exists( ‘has_post_thumbnail’ ) and has_post_thumbnail() ) {
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id(), ‘medium’ );
} elseif ( function_exists( ‘get_post_thumbnail_src’ ) ) {
$featured_image = get_post_thumbnail_src();
if ( preg_match( ‘|^<img src=”([^”]+)”|’, $featured_image[0], $m ) )
$featured_image[0] = $m[1];
} else {
$featured_image = false;
}
if ( ! empty( $featured_image ) ) {
// Get MIME Type
$pInfo = pathinfo($featured_image[0]);
$ext = $pInfo[‘extension’];
if($ext == ‘png’) {
$sMime = ‘image/png’;
}
else if($ext == ‘gif’) {
$sMime = ‘image/gif’;
}
else {
$sMime = ‘image/jpeg’;
}
// Get file size
$iSize = filesize(url2filepath( $featured_image[0]));
// Output
echo “\t” . ‘<enclosure url=”‘ . $featured_image[0] . ‘” length=”‘ . $iSize . ‘” type=”‘ . $sMime . ‘” />’ . “\n”;
}
}
add_action( ‘rss2_item’, ‘add_featured_image_in_rss’ );
?>

Attachments:
You must be logged in to view attached files.