Example #1
0
pdf_lineto($pdf, 121, -11);
pdf_moveto($pdf, 0, 121);
pdf_lineto($pdf, 0, 131);
pdf_moveto($pdf, 121, 121);
pdf_lineto($pdf, 121, 131);
pdf_moveto($pdf, -1, 0);
pdf_lineto($pdf, -11, 0);
pdf_moveto($pdf, -1, 120);
pdf_lineto($pdf, -11, 120);
pdf_moveto($pdf, 122, 0);
pdf_lineto($pdf, 132, 0);
pdf_moveto($pdf, 122, 120);
pdf_lineto($pdf, 132, 120);
pdf_stroke($pdf);
if ($bitmap['front_resolution'] >= $cfg['image_front_cover_treshold']) {
    $pdfdfimage = pdf_load_image($pdf, 'auto', $cfg['media_dir'] . $bitmap['image_front'], '');
    pdf_fit_image($pdf, $pdfdfimage, 0, 0, 'boxsize {121 120} position {50 50} fitmethod slice');
    $hash_data .= '-' . filesize($cfg['media_dir'] . $bitmap['image_front']) . '-' . filemtime($cfg['media_dir'] . $bitmap['image_front']);
}
//  +------------------------------------------------------------------------+
//  | Close and download PDF                                                 |
//  +------------------------------------------------------------------------+
pdf_end_page($pdf);
pdf_close($pdf);
$data = pdf_get_buffer($pdf);
pdf_delete($pdf);
$filename = $album['artist'] . ' - ' . $album['album'] . '.pdf';
$filename = downloadFilename($filename);
$etag = '"' . md5($hash_data) . '"';
streamData($data, 'application/pdf', 'inline', $filename, $etag);
updateCounter($album_id, NJB_COUNTER_COVER);
Example #2
0
function downloadTrack($track_id)
{
    global $cfg, $db;
    authenticate('access_download', true);
    $download_id = (int) get('download_id');
    if ($download_id != -1 && isset($cfg['encode_extension'][$download_id]) == false) {
        message(__FILE__, __LINE__, 'error', '[b]Unsupported input value for[/b][br]download_id');
    }
    $query = mysql_query('SELECT
		LOWER(SUBSTRING_INDEX(relative_file, ".", -1)) AS extension,
		relative_file,
		mime_type,
		miliseconds,
		filesize,
		audio_bitrate
		FROM track
		WHERE track_id = "' . mysql_real_escape_string($track_id) . '"');
    $track = mysql_fetch_assoc($query);
    if (sourceFile($track['extension'], $track['audio_bitrate'], $download_id)) {
        // Download source file
        $file = $cfg['media_dir'] . $track['relative_file'];
        $pathinfo = pathinfo($file);
        $filename = $pathinfo['basename'];
        $filename = downloadFilename($filename);
        streamFile($file, $track['mime_type'], 'attachment', $filename);
        return true;
    } elseif ($file = cacheGetFile($track_id, $download_id)) {
        // Download from cache
        $pathinfo = pathinfo($track['relative_file']);
        $filename = $pathinfo['filename'] . '.' . $cfg['encode_extension'][$download_id];
        $filename = downloadFilename($filename);
        cacheUpdateTag($track_id, $download_id, $file);
        streamFile($file, $cfg['encode_mime_type'][$download_id], 'attachment', $filename);
        return true;
    }
    ini_set('max_execution_time', 0);
    $query = mysql_query('SELECT album.artist_alphabetic, album.album, album.album_id
		FROM album, track
		WHERE track.album_id = album.album_id
		AND track_id = "' . mysql_real_escape_string($track_id) . '"');
    $album = mysql_fetch_assoc($query);
    if ($album == false) {
        message(__FILE__, __LINE__, 'error', '[b]Error[/b][br]track_id not found in database');
    }
    // formattedNavigator
    $nav = array();
    $nav['name'][] = 'Media';
    $nav['url'][] = 'index.php';
    $nav['name'][] = $album['artist_alphabetic'];
    $nav['url'][] = 'index.php?action=view2&artist=' . rawurlencode($album['artist_alphabetic']);
    $nav['name'][] = $album['album'];
    $nav['url'][] = 'index.php?action=view3&album_id=' . $album['album_id'];
    $nav['name'][] = 'Download track';
    require_once 'include/header.inc.php';
    ?>
<table cellspacing="0" cellpadding="0" class="border">
<tr class="header">
	<td class="space"></td>
	<td>Transcode to <?php 
    echo html($cfg['encode_name'][$download_id]);
    ?>
</td>
	<td class="textspace"></td>
	<td></td>
	<td class="textspace"></td>
	<td></td>
	<td class="space"></td>
</tr>
<tr class="line"><td colspan="7"></td></tr>
<?php 
    $query = mysql_query('SELECT title, artist FROM track WHERE track_id = "' . mysql_real_escape_string($track_id) . '"');
    $track = mysql_fetch_assoc($query);
    ?>
<tr class="odd">
	<td></td>
	<td><?php 
    echo html($track['artist']);
    ?>
</td>
	<td></td>
	<td><?php 
    echo html($track['title']);
    ?>
</td>
	<td></td>
	<td><span id="status"><img src="<?php 
    echo $cfg['img'];
    ?>
small_animated_progress.gif" alt="" class="small"></span></td>
	<td></td>
</tr>
<tr class="line"><td colspan="7"></td></tr>
<tr class="header">
	<td></td>
	<td colspan="5">Download</td>
	<td></td>
</tr>
<tr class="line"><td colspan="7"></td></tr>
<tr class="odd">
	<td></td>
	<td colspan="5"><span id="text">Prepare file</span></td>
	<td></td>
</tr>
</table>
<?php 
    $cfg['footer'] = 'dynamic';
    require 'include/footer.inc.php';
    $file = transcode($track_id, $download_id);
    $download_url = NJB_HOME_URL . 'download.php?action=downloadTrack&amp;track_id=' . rawurlencode($track_id) . '&amp;download_id=' . $download_id;
    $download_url .= '&amp;timestamp=' . dechex(time());
    echo '<script type="text/javascript">document.getElementById(\'status\').innerHTML=\'<img src="' . $cfg['img'] . 'small_check.png" alt="" class="small">\';</script>' . "\n";
    echo '<script type="text/javascript">document.getElementById(\'text\').innerHTML=\'<a href="' . $download_url . '"><img src="' . $cfg['img'] . 'small_download.png" alt="" class="small space">Download ' . $cfg['encode_extension'][$cfg['download_id']] . ' file (' . formattedSize(filesize($file)) . ')<\\/a>\';</script>' . "\n";
    echo '<iframe src="' . $download_url . '" width="0" height="0" scrolling="no" frameborder="0"></iframe>' . "\n";
    $cfg['footer'] = 'close';
    require 'include/footer.inc.php';
}
Example #3
0
function cacheGetFile($id, $profile)
{
    global $cfg, $db;
    $zip_hash = '';
    if (strpos($id, '_') === false) {
        $hash_data = '';
        $query = mysql_query('SELECT relative_file
			FROM track
			WHERE album_id	= "' . mysql_real_escape_string($id) . '"
			ORDER BY relative_file');
        while ($track = mysql_fetch_assoc($query)) {
            $pathinfo = pathinfo($track['relative_file']);
            $hash_data .= downloadFilename($pathinfo['filename'], true, true);
        }
        $zip_hash = md5($hash_data);
    }
    $query = mysql_query('SELECT create_time, filesize, filemtime, relative_file
		FROM cache
		WHERE id		= "' . mysql_real_escape_string($id) . '"
		AND zip_hash	= "' . mysql_real_escape_string($zip_hash) . '"
		AND profile		= ' . (int) $profile);
    $cache = mysql_fetch_assoc($query);
    $relative_file = $cache['relative_file'];
    $file = NJB_HOME_DIR . $cache['relative_file'];
    if (is_file($file) && filesize($file) == $cache['filesize'] && filemtimeCompare(filemtime($file), $cache['filemtime'])) {
        // File exist and has not changed
        if (strpos($id, '_') !== false && $profile >= 0) {
            // Update cache filename, except for zip and wave files
            $query = mysql_query('SELECT relative_file
				FROM track
				WHERE track_id	= "' . mysql_real_escape_string($id) . '"');
            $track = mysql_fetch_assoc($query);
            $cache_pathinfo = pathinfo($cache['relative_file']);
            $track_pathinfo = pathinfo($track['relative_file']);
            if ($cache_pathinfo['filename'] != $track_pathinfo['filename']) {
                $relative_file = $cache_pathinfo['dirname'] . '/' . $track_pathinfo['filename'] . '.' . $cache_pathinfo['extension'];
                rename($file, NJB_HOME_DIR . $relative_file) or message(__FILE__, __LINE__, 'error', '[b]Failed to rename file[/b][br]From: ' . $file . '[br]To: ' . NJB_HOME_DIR . relative_file);
                $file = NJB_HOME_DIR . $relative_file;
            }
        }
        mysql_query('UPDATE cache
			SET idle_time	= ' . (int) time() . ',
			relative_file	= "' . mysql_real_escape_string($relative_file) . '"
			WHERE id		= "' . mysql_real_escape_string($id) . '"
			AND  profile	= ' . (int) $profile);
        return $file;
    } elseif (is_file($file)) {
        // File exist and has changed
        if (@unlink($file) == false) {
            message(__FILE__, __LINE__, 'error', '[b]Failed to delete file:[/b][br]' . $file);
        }
        mysql_query('DELETE
			FROM cache
			WHERE id 		= "' . mysql_real_escape_string($id) . '"
			AND  profile	= ' . (int) $profile);
        return false;
    } else {
        // File does not exist
        return false;
    }
}