'."\n";
return $result;
//~ } else {
//~ return __('unknown', 'podpress');
//~ }
}
function podPress_getCoverArt($mediafile, $tmp_download_exists = FALSE) {
podPress_var_dump('podPress_getCoverArt - start');
if ( TRUE === $tmp_download_exists ) {
// if the local file is a tmp file of a download then delete it after retrieving the cover art
$fileinfo = podPress_getID3tags($mediafile, TRUE, 500000, TRUE, TRUE);
} else {
$fileinfo = podPress_getID3tags($mediafile, TRUE, 500000, TRUE, FALSE);
}
podPress_var_dump('podPress_getCoverArt - after getid3tags');
if ( isset($fileinfo['id3v2']['APIC'][0]) ) {
$ref = $fileinfo['id3v2']['APIC'][0];
if ( (FALSE == isset($ref['image_mime']) OR (isset($ref['image_mime']) AND empty($ref['image_mime']))) AND isset($ref['mime']) ) {
$ref['image_mime'] = $ref['mime'];
}
podPress_var_dump('podPress_getCoverArt - (id3v2 - APIC) '. $ref['image_mime']);
} elseif ( isset($fileinfo['id3v2']['PIC'][0]) ) {
$ref = $fileinfo['id3v2']['PIC'][0];
if ( (FALSE == isset($ref['image_mime']) OR (isset($ref['image_mime']) AND empty($ref['image_mime']))) AND isset($ref['mime']) ) {
$ref['image_mime'] = $ref['mime'];
}
podPress_var_dump('podPress_getCoverArt - (id3v2 - PIC) '. $ref['image_mime']);
} elseif ( isset($fileinfo['comments']['artwork'][0]) ) {
$ref['data'] = $fileinfo['comments']['artwork'][0];
podPress_var_dump('podPress_getCoverArt - (m4a comments) '. $ref['image_mime']);
} elseif ( isset($fileinfo['tags']['quicktime']['artwork'][0]) ) {
$ref['data'] = $fileinfo['tags']['quicktime']['artwork'][0];
podPress_var_dump('podPress_getCoverArt - (m4a tags) '. $ref['image_mime']);
} else {
$ref['image_mime'] = 'image/png';
$ref['datalength'] = @filesize('images/powered_by_podpress.png');
$ref['data'] = @file_get_contents('images/powered_by_podpress.png');
podPress_var_dump('podPress_getCoverArt - (default image) '. $ref['image_mime']);
}
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // some day in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT', false, 200);
if ( isset($ref['image_mime']) AND FALSE == empty($ref['image_mime']) ) {
header('Content-type: '.$ref['image_mime']);
}
if ( isset($ref['datalength']) AND FALSE == empty($ref['datalength']) ) {
header('Content-Length: '.$ref['datalength']);
}
//set_time_limit(0);
echo $ref['data'];
podPress_var_dump('podPress_getCoverArt - end');
}
function podPress_getDuration($mediafile) {
GLOBAL $podPress;
if($podPress->settings['enablePodangoIntegration']) {
if(substr($mediafile, 0, strlen('Podango:')) == 'Podango:') {
$fileNameParts = explode(':', $mediafile);
$mediafile = 'http://download.podango.com/mediatracker/555/'.$fileNameParts[3].'/'.$fileNameParts[4];
}
}
$allowed_ext = array('mp3', 'ogg', 'ogv', 'avi', 'mov', 'qt', 'mp4', 'm4v', 'm4a', 'wma', 'wmv', 'mpg', 'mpeg', 'flv', 'swf');
$ext = strtolower(end(explode('.', $mediafile)));
if (TRUE == in_array($ext, $allowed_ext)) {
podPress_var_dump('start of the duration retrieval');
$systemFileName = $podPress->convertPodcastFileNameToSystemPath($mediafile);
if(file_exists($systemFileName)) {
$uriFileName = $systemFileName;
} else {
$systemFileName = $podPress->TryToFindAbsFileName($mediafile);
if(FALSE !== $systemFileName) {
$uriFileName = $systemFileName;
} else {
$uriFileName = $podPress->convertPodcastFileNameToValidWebPath($mediafile);
}
}
podPress_var_dump('podPress_getDuration - file: '.$uriFileName);
$fileinfo = podPress_getID3tags($uriFileName, true);
podPress_var_dump('podPress_getDuration - playtime_string: '.$fileinfo['playtime_string']);
podPress_var_dump('end of the duration retrieval');
return trim($fileinfo['playtime_string']);
} else {
return __('UNKNOWN', 'podpress');
}
}
/**
* podPress_downloadFile - downloads the header a part or the whole file from a remote server (to give getID3() the chance to retrieve the ID3 information like duration etc.)
*
* @package podPress
* @since (unknown)
*
* @param string $uriFileName - the URL of the media file
* @param boolean $getHeaders - download only the header (TRUE) or more than that (FALSE)
* @param numeric $limitDownload - file size in kb to limit the amount data which should be downloaded from a remote media file (used in podPress_getCoverArt())
*
* return mixed - the full HTTP response header or the file name of the downloaded file
*/
function podPress_downloadFile($uriFileName, $getHeaders = false, $limitDownload = false) {
GLOBAL $podPress;
// some downloads may hit time limits -> lets find out these limits, stop the process a moment before and return an error message
// search for PHP time limits
$max_execution_time = intval(ini_get('max_execution_time'));
podPress_var_dump('podPress_downloadFile - max_execution_time: '.$max_execution_time);
$safety = 2; // seconds
// get the OS type on the server
$hairstick = php_uname();
$is_windows = stristr( $hairstick, 'win' );
// search for CPU time limits
if (FALSE === $is_windows) {
@exec('ulimit -t', $output) or $output[0] = 10;
$int_output = intval($output[0]);
podPress_var_dump('podPress_downloadFile - ulimit -t: '. $output[0].' - (int): '.$int_output);
if (is_string($output[0]) AND 10 > $int_output) {
$max_time = max(($safety+2), $max_execution_time); // if max_execution_time is somehow weird small
} else {
$max_time = min(intval($output[0]), $max_execution_time); // if the CPU limit is bigger than 10 then take the max. of the CPU limit and the max_execution_time
}
} else {
$max_time = $max_execution_time; // on Windows systems
}
podPress_var_dump('podPress_downloadFile - time limit: '.$max_time);
$aborttimelimit = FALSE;
$aborthttperror = FALSE;
$start_time = array_sum(explode(chr(32), microtime()));
podPress_var_dump('podPress_downloadFile - given URL: '.$uriFileName);
$uriFileName = podPress_ResolveReDirects($uriFileName);
$aURL = @parse_url($uriFileName);
if ( $aURL['scheme'] != 'http' ) {
podPress_var_dump('podPress_downloadFile - returning - not a http:// URL : '.var_export($aURL, TRUE));
return;
}
$sHost = $aURL['host'];
$sFilepath = (isset($aURL['path']) ? $aURL['path'] : '/') . (isset($aURL['query']) ? '?' . $aURL['query'] : '');
// mask white spaces in the file name
$sFilepath = str_replace(' ', '%20', $sFilepath);
$nPort = isset($aURL['port']) ? $aURL['port'] : 80;
if ( function_exists('fsockopen') ) {
$fpRemote = @fsockopen($sHost, $nPort, $errno, $errstr, 30);
} else {
$fpRemote = FALSE;
}
if ( FALSE !== $fpRemote ) {
if ( TRUE === $getHeaders ) {
podPress_var_dump('podPress_downloadFile - get only the header');
podPress_var_dump('podPress_downloadFile - ' . $sHost . $sFilepath);
$sHeaders = "HEAD " . $sFilepath . " HTTP/1.1\r\n";
$sHeaders .= "Host: ". $sHost . "\r\n";
$sHeaders .= "Connection: Close\r\n\r\n";
podPress_var_dump($sHeaders);
// Sending headers
fwrite($fpRemote, $sHeaders);
// Getting back the header information
$header = '';
$line = '';
$continue = true;
$soFar = 0;
// Processing the server answer (header) line by line
while(!feof($fpRemote) && $continue) {
$line = fgets($fpRemote, 1024);
$soFar = $soFar+1024;
if ($limitDownload !== false && $soFar > $limitDownload) {
$continue = false;
}
$header .= $line;
}
// Closing the socket
fclose($fpRemote);
podPress_var_dump('podPress_downloadFile - (header) before return');
podPress_var_dump($header);
return $header;
} else {
podPress_var_dump('podPress_downloadFile - download the file');
podPress_var_dump('podPress_downloadFile - ' . $sHost . $sFilepath);
$sHeaders = "GET " . $sFilepath . " HTTP/1.1\r\n";
$sHeaders .= "Host: ". $sHost . "\r\n";
$sHeaders .= "Connection: Close\r\n\r\n";
// Sending headers
fwrite($fpRemote, $sHeaders);
// determine a temp folder and temp file name
$ext = podPress_getFileExt($uriFileName);
$pos = strpos($ext, '?');
if($pos) {
$ext = substr($ext, 0, $pos);
}
// Trying to write into the servers temp folder. The temp file has to have the media files extension. Because getID3 does not work without it.
$localtempfilename = @tempnam('/tmp', 'getID3').'.'.$ext;
if (FALSE == $localtempfilename OR '.'.$ext == $localtempfilename) {
// If it is not possible to get the temp folder via tempnam() then try to write into the temp folder of podPress
$podPress->checkWritableTempFileDir();
$localtempfilename = $podPress->tempfilesystempath.'/podpress_tmp.'.$ext;
}
if (!$fp_local = @fopen($localtempfilename, 'wb')) {
// if it is not possible to open a temp file then return
// Closing the socket
fclose($fpRemote);
return '';
}
podPress_var_dump('podPress_downloadFile - (file) localtempfilename: '.$localtempfilename);
// Getting back header + content
$continue = true;
$is_body = false;
$soFar = 0;
$line = "";
$trimmed_line = "";
$step_time = array_sum(explode(chr(32), microtime()));
// Processing the server answer (header + content) line by line
while( !feof($fpRemote) && $continue ) {
$line = fgets($fpRemote, 1024);
$soFar = $soFar+1024;
// some times the answer of the remote server contains a HTTP header which should not be a part of the temp file
// after the HTTP should always be a empty line which is followed by the remote file - see http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4
if ($is_body) {
if($limitDownload !== false && $soFar > $limitDownload) {
$continue = false;
}
// write the content of the remote file into the temp file
fwrite($fp_local, $line);
} else {
$trimmed_line = Trim($line);
// contol the first line (chunk) of the header information
if ($soFar <= 1024) {
// check the HTTP status number
$HTTP_result = preg_match('/HTTP\/[0-9].[0-9] ([1-5][0-9][0-9])/', $trimmed_line, $headerMatches);
// If the HTTP status is not 200 then something with the filename (or URL) was not ok or something on the server was wrong.
if (isset($headerMatches[1]) AND '200' != $headerMatches[1]) {
podPress_var_dump('podPress_downloadFile - aborting - HTTP status: ' . $headerMatches[1]);
$aborthttperror = TRUE;
$continue = FALSE;
}
}
if ( FALSE !== empty($trimmed_line) ) {
// if the line is empty then the last line of the HTTP header of the server answer and the file content begins
$is_body = true;
}
}
$step_time = array_sum(explode(chr(32), microtime()));
if (($step_time - $start_time) >= ($max_time-$safety)) {
$continue = FALSE;
$aborttimelimit = TRUE;
podPress_var_dump('podPress_downloadFile - aborting download because of a time limit');
}
}
// Closing the temp file
fclose($fp_local);
// Closing the socket
fclose($fpRemote);
podPress_var_dump('podPress_downloadFile - (file) before return');
// return the name of the temp file
return $localtempfilename;
}
} else {
if ( TRUE === $getHeaders ) {
podPress_var_dump('podPress_downloadFile - fpRemote = false | getHeaders = true');
if ( TRUE == function_exists('curl_init') ) {
$ch = curl_init($uriFileName);
// make sure we get the header
curl_setopt($ch, CURLOPT_HEADER, TRUE);
// make it a http HEAD request
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
// add useragent
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13');
//Tell curl to write the response to a variable
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// The maximum number of seconds to allow cURL to wait for a connection.
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, min(10, $max_time-$safety));
// The maximum number of seconds to allow cURL functions to execute.
curl_setopt($ch, CURLOPT_TIMEOUT, ($max_time-$safety));
// Tell curl to stop when it encounters an error
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
$content = curl_exec($ch);
podPress_var_dump('podPress_downloadFile - cURL HTTP code: ' . var_export(curl_getinfo($ch, CURLINFO_HTTP_CODE), TRUE));
// Check if any error occured
if ( !curl_errno($ch) ) {
$bytes = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
$total_time = curl_getinfo($ch, CURLINFO_TOTAL_TIME);
podPress_var_dump('File size: ' . $bytes . ' bytes');
podPress_var_dump('Took ' . $total_time . ' seconds to send a request to ' . $url);
//clearstatcache();
}
@curl_close($ch);
podPress_var_dump($content);
return $content;
} else {
podPress_var_dump('podPress_downloadFile - cUrl is not available');
return '';
}
} else {
podPress_var_dump('podPress_downloadFile - fpRemote = false | getHeaders = false');
if ( TRUE == function_exists('curl_init') ) {
// determine a temp folder and temp file name
$ext = podPress_getFileExt($uriFileName);
$pos = strpos($ext, '?');
if($pos) {
$ext = substr($ext, 0, $pos);
}
// Trying to write into the servers temp folder. The temp file has to have the media files extension. Because getID3 does not work without it.
$localtempfilename = @tempnam('/tmp', 'getID3').'.'.$ext;
if (FALSE == $localtempfilename OR '.'.$ext == $localtempfilename) {
// If it is not possible to get the temp folder via tempnam() then try to write into the temp folder of podPress
$podPress->checkWritableTempFileDir();
$localtempfilename = $podPress->tempfilesystempath.'/podpress_tmp.'.$ext;
}
if (!$fp_local = @fopen($localtempfilename, 'wb')) {
// if it is not possible to open a temp file then return
podPress_var_dump('podPress_downloadFile - (file) it is not possible to open a temp file');
return '';
}
podPress_var_dump('podPress_downloadFile - (file) localtempfilename: '.$localtempfilename);
// starting cURL
$ch = curl_init($uriFileName);
podPress_var_dump('podPress_downloadFile - cURL HTTP code:');
podPress_var_dump( curl_getinfo($ch, CURLINFO_HTTP_CODE) );
// make sure we get the header
curl_setopt($ch, CURLOPT_HEADER, TRUE);
// make it a http GET request
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
// add useragent
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13');
if ( FALSE !== $limitDownload ) {
podPress_var_dump('podPress_downloadFile - download only that part: 0-'.$limitDownload);
curl_setopt($ch, CURLOPT_RANGE, '0-'.$limitDownload);
}
// Do not put the response into a variable. (Put it into a file.)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);
// the target file (handle) for the download
curl_setopt($ch, CURLOPT_FILE, $fp_local);
// The maximum number of seconds to allow cURL to wait for a connection.
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, min(10, $max_time-$safety));
// The maximum number of seconds to allow cURL functions to execute.
curl_setopt($ch, CURLOPT_TIMEOUT, ($max_time-$safety));
// Tell curl to stop when it encounters an error
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
@curl_exec($ch);
// If the HTTP status is not 200 then something with the filename (or URL) was not ok or something on the server was wrong.
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ( '200' != $http_code ) {
podPress_var_dump('podPress_downloadFile - aborting - HTTP status: ' . $http_code);
}
// Check if any error occured
if ( !curl_errno($ch) ) {
$bytes = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
$total_time = curl_getinfo($ch, CURLINFO_TOTAL_TIME);
podPress_var_dump('File size: ' . $bytes . ' bytes');
podPress_var_dump('Took ' . $total_time . ' seconds to send a request to ' . $url);
//clearstatcache();
}
@curl_close($ch);
// Closing the temp file
fclose($fp_local);
return $localtempfilename;
} else {
podPress_var_dump('podPress_downloadFile - cUrl is not available');
return '';
}
}
}
}
function podPress_getFileSize($mediafile) {
GLOBAL $podPress;
podPress_var_dump('start of the file size retrieval');
if($podPress->settings['enablePodangoIntegration']) {
if(substr($mediafile, 0, strlen('Podango:')) == 'Podango:') {
$fileNameParts = explode(':', $mediafile);
$mediafile = 'http://download.podango.com/mediatracker/555/'.$fileNameParts[3].'/'.$fileNameParts[4];
}
}
podPress_var_dump('podPress_getFileSize - media file: '.$mediafile);
$systemFileName = $podPress->convertPodcastFileNameToSystemPath($mediafile);
if(file_exists($systemFileName)) {
$filesize = filesize($systemFileName);
podPress_var_dump('end of the file size retrieval - (local file) file size: '.$filesize);
return $filesize;
}
// if it is a remote file then get the file size from the header information:
$uriFileName = $podPress->convertPodcastFileNameToValidWebPath($mediafile);
// Request only the HTTP header (second parameter is TRUE)
$sRemoteHeaders = podPress_downloadFile($uriFileName, TRUE);
// check the HTTP status number
$HTTP_result = preg_match('/HTTP\/[0-9].[0-9] ([1-5][0-9][0-9])/', $sRemoteHeaders, $headerMatches);
// If the HTTP status is not 200 then something with the filename (or URL) was not ok or something on the server was wrong. It is possible that the HTTP header contain in such cases sometimes a content-length. But if the status is not 200 then is most likely not the length of the media file.
if (isset($headerMatches[1]) AND '200' != $headerMatches[1]) {
podPress_var_dump('end of the file size retrieval - unable to retrieve the file size - '. $HTTP_result . ' - ' . $headerMatches[0]);
return;
} else {
// Parsing the headers
preg_match('/Content-Length:\s([0-9].+?)\s/', $sRemoteHeaders, $aMatches);
if ( isset($aMatches[1]) ) {
podPress_var_dump('end of the file size retrieval - file size: '.$aMatches[1]);
return (int)$aMatches[1];
} else {
podPress_var_dump('end of the file size retrieval - unable to retrieve the file size');
return;
}
}
}
/**
* podPress_var_dump - writes a variable into a log file in the podPress folder (helper function - only for development purposes)
*
* @package podPress
* @since 8.8.5 RC 2
*
* @param mixed $var
*/
function podPress_var_dump($var) {
if ( defined( 'PODPRESS_DEBUG_LOG' ) AND TRUE === constant( 'PODPRESS_DEBUG_LOG' ) ) {
// write the out put to the log file
$filename = PODPRESS_DIR.'/podpress_log.dat';
if ( is_file($filename) ) {
$result = @chmod($filename, 0777);
if (FALSE === $result) {
return sprintf(__('This PHP script has not the permission to use chmod for the %1$s file.', 'podpress'), $filename);
}
if ( (filesize($filename)/1024) > 100 ) { // delete the Logfile if it is bigger than 100 kByte
$result = @unlink($filename);
if (FALSE === $result) {
$returnmsg = sprintf(' '.__('This PHP script has not the permission to delete the %1$s file (unlink).', 'podpress'), $filename);
}
}
}
$handle = @fopen($filename, "a");
if ( FALSE !== $handle ) {
//@fputs($handle, '['.date('j.m.Y - H:i:s', time()).'] '.var_export($var, TRUE)."\n");
@fputs($handle, '['.date('j.m.Y - H:i:s').'] '.var_export($var, TRUE)."\n");
$status = @fclose($handle);
$returnmsg .= '';
} else {
$returnmsg .= sprintf(__('This PHP script has not the permission to use create or open the %1$s file for writing (fopen).', 'podpress'), $filename);
}
if ( is_file($filename) ) {
$result = @chmod($filename, 0644);
if (FALSE === $result) {
$returnmsg = sprintf(' '.__('This PHP script has not the permission to use chmod for the %1$s file.', 'podpress'), $filename);
}
}
return $returnmsg;
}
}
/** podPress_get_real_url - demasks an URL which is masked with the podPress stats scheme
* @package podPress
* @since 8.8.10.3 beta 5
* @param mixed $url - the masked url
* @param mixed $print - print (TRUE) or return the result (FALSE)
* @return string - the real URL
*/
function podPress_get_real_url($url, $count = TRUE, $print = TRUE) {
$requested = parse_url($url);
$requested = $requested['path'];
$realURL = 'false';
$pos = 0;
if ( $pos = strpos($requested, 'podpress_trac') ) {
if ( $pos == 0 ) {
$pos = strpos($requested, 'podpress_trac');
}
$pos = $pos+14;
if ( substr($requested, $pos, 1) == '/' ) {
$pos = $pos+1;
}
$requested = substr($requested, $pos);
$parts = explode('/', $requested);
if ( count($parts) == 4 ) {
$postID = $parts[1];
$mediaNum = $parts[2];
$filename = rawurlencode($parts[3]);
$method = $parts[0];
$allowedMethods = array('feed', 'play', 'web');
$realSysPath = false;
$statID = false;
if ( in_array($method, $allowedMethods) && is_numeric($postID) && is_numeric($mediaNum) ) {
$mediaFiles = podPress_get_post_meta($postID, '_podPressMedia', true);
if (isset($mediaFiles[$mediaNum]) ) {
if ( $mediaFiles[$mediaNum]['URI'] == urldecode($filename) ) {
$realURL = $filename;
} elseif ( podPress_getFileName($mediaFiles[$mediaNum]['URI']) == urldecode($filename) ) {
$realURL = $mediaFiles[$mediaNum]['URI'];
} elseif ( podPress_getFileName($mediaFiles[$mediaNum]['URI_torrent']) == urldecode($filename) ) {
$realURL = $mediaFiles[$mediaNum]['URI_torrent'];
}
}
}
if ( TRUE === $count ) {
$badextensions = array('.smi', '.jpg', '.png', '.gif');
if ($filename && !in_array(strtolower(substr($filename, -4)), $badextensions)) {
global $podPress;
podPress_StatCounter($postID, $filename, $method);
if ( $podPress->settings['statLogging'] == 'Full' || $podPress->settings['statLogging'] == 'FullPlus' ) {
$statID = podPress_StatCollector($postID, $filename, $method);
}
}
}
//~ $realSysPath = $podPress->convertPodcastFileNameToSystemPath(str_replace('%20', ' ', $realURL));
//~ if (FALSE === $realSysPath) {
//~ $realSysPath = $podPress->TryToFindAbsFileName(str_replace('%20', ' ', $realURL));
//~ }
//~ $realURL = $podPress->convertPodcastFileNameToValidWebPath($realURL);
//~ if ($podPress->settings['enable3rdPartyStats'] == 'PodTrac') {
//~ $realURL = str_replace(array('ftp://', 'http://', 'https://'), '', $realURL);
//~ $realURL = $podPress->podtrac_url.$realURL;
//~ } elseif( strtolower($podPress->settings['enable3rdPartyStats']) == 'blubrry' && !empty($podPress->settings['statBluBrryProgramKeyword'])) {
//~ $realURL = str_replace('http://', '', $realURL);
//~ $realURL = $podPress->blubrry_url.$podPress->settings['statBluBrryProgramKeyword'].'/'.$realURL;
//~ }
}
}
if ( TRUE === $print ) {
echo $realURL;
} else {
return $realURL;
}
}
?>