'."\n";
return $result;
}
function podPress_getCoverArt($mediafile) {
$fileinfo = podPress_getID3tags($mediafile, false, 500000);
if(isset($fileinfo['id3v2']['APIC'][0])) {
$ref = $fileinfo['id3v2']['APIC'][0];
} elseif(isset($fileinfo['id3v2']['PIC'][0])) {
$ref = $fileinfo['id3v2']['PIC'][0];
} else {
$ref['image_mime'] = 'image/jpeg';
$ref['datalength'] = @filesize('images/powered_by_podpress.png');
$ref['data'] = @file_get_contents('images/powered_by_podpress.png');
}
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');
header('Content-type: '.$ref['image_mime']);
// header('Content-Disposition: attachment; filename="coverart.png"');
header("Content-Length: ".$ref['datalength']);
set_time_limit(0);
echo $ref['data'];
}
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];
}
}
$id3formats = array('mp3', 'ogg', 'avi', 'mov', '.qt', 'mp4', 'm4v', 'm4a', 'wma', 'wmv', 'mpg', 'peg', 'flv', 'swf');
if(in_array(strtolower(substr($mediafile, -3, 3)), $id3formats)) {
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);
}
}
$fileinfo = podPress_getID3tags($uriFileName, true);
podPress_var_dump('end of the duration retrieval');
return $fileinfo['playtime_string'];
}
}
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;
$start_time = array_sum(explode(chr(32), microtime()));
$uriFileName = podPress_ResolveReDirects($uriFileName);
$aURL = parse_url(urldecode($uriFileName));
if($aURL['scheme'] != 'http') {
return;
}
$sHost = $aURL['host'];
$sFilepath = (isset($aURL['path']) ? $aURL['path'] : '/') . (isset($aURL['query']) ? '?' . $aURL['query'] : '');
$nPort = isset($aURL['port']) ? $aURL['port'] : 80;
$fpRemote = @fsockopen($sHost, $nPort, $errno, $errstr, 30);
if( $fpRemote ) {
if($getHeaders) {
podPress_var_dump('podPress_downloadFile - get only the header');
$sHeaders = "HEAD " . $sFilepath . " HTTP/1.1\r\n";
$sHeaders .= "Host: ". $sHost . "\r\n";
$sHeaders .= "Connection: Close\r\n\r\n";
// 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');
return $header;
} else {
podPress_var_dump('podPress_downloadFile - download the file');
$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);
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;
}
$j++;
}
$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);
// if the download was stop due to a timelimit then it is most likely not complete. Delete the file that getID3 will produce an error message
if (TRUE === $aborttimelimit) {
@unlink($localtempfilename);
$localtempfilename = 'stop due to time limit: '.$max_time;
}
// Closing the socket
fclose($fpRemote);
podPress_var_dump('podPress_downloadFile - (file) before return');
// return the name of the temp file
return $localtempfilename;
}
} else {
if ($getHeaders) {
podPress_var_dump('podPress_downloadFile - fpRemote = false | getHeaders = true');
if ($fp_remote = @fopen($uriFileName, 'rb')) {
$content = fread($fp_remote, 2048);
fclose($fp_remote);
if(!empty($content)) {
return $content;
}
}
if (function_exists('curl_init') && $ch = curl_init($aURL['scheme'].'://'.$aURL['host'])) {
$fp = fopen($sFilepath, 'w');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
$content = curl_exec($ch);
curl_close($ch);
fclose($fp);
return $content;
}
return '';
} else {
podPress_var_dump('podPress_downloadFile - fpRemote = false | getHeaders = false');
return '';
}
}
}
function podPress_getFileSize($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];
}
}
$systemFileName = $podPress->convertPodcastFileNameToSystemPath($mediafile);
if(file_exists($systemFileName)) {
return filesize($systemFileName);
}
// if it is a remote file then get the file size from the header information:
$uriFileName = $podPress->convertPodcastFileNameToValidWebPath($mediafile);
// Request headers
$sRemoteHeaders = podPress_downloadFile($uriFileName, true);
// Parsing the headers
preg_match('/Content-Length:\s([0-9].+?)\s/', $sRemoteHeaders, $aMatches);
if(isset($aMatches[1])) {
return (int)$aMatches[1];
} else {
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");
$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;
}
}
?>