/zina/index.php
PHP | 8314 lines | 7321 code | 756 blank | 237 comment | 1906 complexity | 2c50c0399391f1aad5e7e74d201f64dd MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * ZINA (Zina is not Andromeda)
- *
- * Zina is a graphical interface to your MP3 collection, a personal
- * jukebox, an MP3 streamer. It can run on its own, embeded into an
- * existing website, or as a Drupal/Joomla/Wordpress/etc. module.
- *
- * http://www.pancake.org/zina
- * Author: Ryan Lathouwers <ryanlath@pacbell.net>
- * Support: http://sourceforge.net/projects/zina/
- * License: GNU GPL2 <http://www.gnu.org/copyleft/gpl.html>
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- define('ZINA_VERSION', '2.0b22');
-
- #TODO:
- # - INSTRUCTIONS for cron for caches
-
- #todo
- # - uninstall? -> at least delete cache files created by webuser!
- # - check settings descriptions...
- # - normalize function names
- # - organize files
- # - comment functions?
- # - look and remove unused language crap?
-
- #TODO-EXTRA:
- # - if clean urls... drop l=8&m=1 for songs???
- # - See Also -> external links?
- # - multiple mp3 dirs
- # - Check output_buffering php.ini setting for video stuff?
-
- #TEST:
- # - pos
-
- function zina($conf) {
- global $zc;
-
- zina_init($conf);
-
- $path = isset($_GET['p']) ? zrawurldecode($_GET['p']) : null;
- $level = isset($_GET['l']) ? $_GET['l'] : null;
- $m = isset($_GET['m']) ? $_GET['m'] : null;
- $imgsrc = isset($_GET['img']) ? $_GET['img'] : null;
- $playlist = isset($_POST['playlist']) ? $_POST['playlist'] : (isset($_GET['pl']) ? $_GET['pl'] : null);
- $songs = isset($_POST['mp3s']) ? $_POST['mp3s'] : (isset($_GET['mp3s']) ? $_GET['mp3s'] : array());
-
- $path = preg_replace("|(/){2,}|",'$1',trim($path,'/'));
-
- $badpath = false;
- if (strstr($path,'..') && !zfile_check_location($zc['mp3_dir'].'/'.$path, $zc['mp3_dir'])) {
- $badpath = true;
- }
-
- if (!$badpath && strstr($imgsrc,'..')) {
- $badpath = true;
- if ($level == 11) {
- $badpath = (!zfile_check_location($zc['mp3_dir'].'/'.$path, $zc['mp3_dir']));
- } elseif ($level == 7) {
- if (isset($_GET['it'])) {
- if ($_GET['it'] == 'genre') {
- } elseif (in_array($_GET['it'], array('sub','dir','full','search'))) {
- $badpath = (!zfile_check_location($zc['mp3_dir'].'/'.$path, $zc['mp3_dir']));
- }
- }
- }
- }
-
- if (!$badpath && strstr($playlist,'..')) $badpath = true;
-
- if (!$badpath && !empty($songs) && is_array($songs)) {
- foreach ($songs as $song) {
- if (strstr($song,'..') && !zfile_check_location($zc['mp3_dir'].'/'.$path, $zc['mp3_dir'])) {
- $badpath = true;
- break;
- }
- }
- }
- if ($badpath) {
- zina_debug(zt('Bad path: @path', array('@path'=>$path)));
- return zina_not_found();
- }
-
- $zc['cur_dir'] = $zc['mp3_dir']. (!empty($path) ? '/'.$path : '');
-
- if (!empty($path) && !file_exists($zc['cur_dir'])) {
- $file_not_found = true;
- if (substr($path,-3) == '.lp') {
- $tmp_path = substr($path, 0, strlen($path) -3);
- if (file_exists($zc['mp3_dir'].'/'.$tmp_path)) {
- $file_not_found = false;
- $zc['cur_dir'] = $zc['mp3_dir'].'/'.$tmp_path;
- }
- } elseif ($zc['sitemap'] && $path == $zc['sitemap_file']) {
- $level = 51;
- $path = '';
- $zc['cur_dir'] = $zc['mp3_dir'];
- $file_not_found = false;
- } elseif ($zc['rss'] && basename($path) == $zc['rss_file']) {
- $level = 50;
- $path = substr($path,0,-(strlen($zc['rss_file'])+1));
- $zc['cur_dir'] = $zc['mp3_dir'].'/'.$path;
- if (file_exists($zc['cur_dir'])) $file_not_found = false;
- } elseif ($zc['stats_rss'] && $zc['database'] && basename($path) == 'stats.xml') {
- zina_stats_feed($path);
- } elseif ($zc['playlists'] && $zc['database'] && basename($path) == 'pls.xml') {
- $pls_id = dirname($path);
- if (zina_validate('int',$pls_id)) {
- zina_playlist_feed($pls_id);
- }
- } elseif ($level == 46 && basename($path) == 'zina_id3_zina.jpg') {
- $file_not_found = false;
- $tmp_path = dirname($path);
- $tmp_path = $zc['mp3_dir'].(!empty($tmp_path) ? '/'.$tmp_path : '');
- if (file_exists($tmp_path) && is_dir($tmp_path)) $file_not_found = false;
- }
-
- if ($file_not_found) {
- $tmp_path = utf8_decode($path);
- $tmp_cur_dir = $zc['mp3_dir']. (!empty($tmp_path) ? '/'.$tmp_path : '');
- if (file_exists($tmp_cur_dir)) {
- $path = $tmp_path;
- $zc['cur_dir'] = $tmp_cur_dir;
- } else {
- if (substr($path,-11) != 'favicon.ico') zina_debug(zt('Path does not exist: @path', array('@path'=>$path)));
- return zina_not_found();
- }
- }
- }
-
- #todo: validate?
- if ($zc['settings_override']) {
- $override_file = $zc['cur_dir'].'/'.$zc['settings_override_file'];
- if (file_exists($override_file)) {
- $override = false;
- if (($dir_xml = file_get_contents($override_file)) !== false) {
- $dir_settings = xml_to_array($dir_xml, 'settings');
- if (!empty($dir_settings[0])) {
- foreach($dir_settings[0] as $key => $val) {
- if (isset($zc[$key])) $zc[$key] = $val;
- }
- $override = true;
- }
- }
- if (!$override) {
- zina_set_message(zt('Cannot read override file.'), 'error');
- return zina_access_denied();
- }
- }
- }
-
- /*
- * MAIN
- *
- * Determines what zina does.
- */
- if (in_array($level, array(18,19,20,21,26,27,28,30,31,32,33,34,35,42,45,47,48,49,52,58,59,60,61,62,63,64,67,71,72,73,75,76,78))) {
- # ADMIN FUNCTIONS
-
- if (!$zc['is_admin']) return zina_access_denied();
- #todo: needed?
- #header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
- #header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT');
- #header('Cache-Control: no-cache, must-revalidate, max-age=0');
- #header('Pragma: no-cache');
-
- switch($level) {
-
- Case 18 : # INSTALL OR UPDATE DB
- if ($zc['database'] && ($m == 'update' || $m == 'install')) {
- $file = $zc['zina_dir_abs'].'/'.$m.'.php';
- if ($zc['database'] && file_exists($file)) {
- require_once($file);
- if ($m == 'install') {
- $result = zina_install_database();
- } else {
- $result = zina_updates_execute();
- }
- if ($result) {
- if ($m == 'install') zvar_set('version', ZINA_VERSION);
- zina_set_message(zt('Database @m succeeded!',array('@m'=>$m)));
- } else {
- zina_set_message(zt('Database @m failed!', array('@m'=>$m)),'error');
- }
- } else {
- zina_set_message(zt('Cannot @m the database...either no database connection or the file does not exist.',array('@m'=>$m)), 'error');
- }
- zina_goto('', 'l=20');
- }
- return zina_not_found();
- break;
-
- Case 19 : # try to manually submit last.fm queue
- if ($zc['lastfm']) {
- require_once($zc['zina_dir_abs'].'/extras/scrobbler.class.php');
- @set_time_limit($zc['timeout']);
-
- $scrobbler = new scrobbler($zc['lastfm_username'],$zc['lastfm_password']);
- $scrobbler->handshake_socket_timeout = 2;
- $scrobbler->submit_socket_timeout = 30;
- $scrobbler->queued_tracks = zina_set_scrobbler_queue();
- if ($scrobbler->submit_tracks()) {
- zina_set_message(zt('Queued Last.fm tracks submitted successfully.'));
- zina_set_scrobbler_queue(array(), true);
- } else {
- zina_set_message(zt('Queued Last.fm tracks failed:').$scrobbler->error_msg,'warn');
- }
- zina_goto('', 'l=20');
- }
- break;
-
- Case 20 : # CFG
- return zina_page_main($path, 'config');
- break;
-
- Case 21 : # CFG POST
- if (zina_write_settings()) {
- zina_set_message(zt('Settings updated.'));
- } else {
- zina_set_message(zt('Your settings were not saved!'),'error');
- }
- zina_goto('', 'l=20');
- break;
-
- Case 26 : # regen
- require_once($zc['zina_dir_abs'].'/batch.php');
- @trigger_error('');
- $error = false;
- if ($m == 1) { # dir/files caches
- if ($zc['database']) {
- foreach(array('dirs','files_assoc') as $type) {
- $operations[] = array('zina_core_cache_batch', array($type, '', array('force'=>true)));
- }
- if ($zc['low']) {
- foreach(array('files_assoc') as $type) {
- $operations[] = array('zina_core_cache_batch', array($type, '', array('force'=>true, 'low'=>true)));
- }
- }
-
- $batch = array(
- 'title' => zt('Regenerating directory and file caches.'),
- 'finished_message' => zt('Caches generated successfully.'),
- 'operations' => $operations,
- );
- zbatch_set($batch);
- zbatch_process();
- } else {
- foreach(array('dirs','files_assoc') as $type) zina_core_cache($type, '', array('force'=>true));
-
- if ($zc['low']) {
- foreach(array('files_assoc') as $type) zina_core_cache($type, '', array('force'=>true,'low'=>true));
- }
-
- $message = zt('Cache generated successfully.');
- }
- } elseif ($m == 2) { # genre cache
- #todo: use db or cache but not both? for genres? for dirs/files?
- if ($zc['database']) {
- $operations = array();
-
- $operations[] = array('zina_core_cache_batch', array('genre', '', array('force'=>true)));
- $operations[] = array('zdb_genre_populate', array(time()));
-
- $batch = array(
- 'title' => zt('Regenerating genre caches.'),
- 'finished_message' => zt('Genre cache generated successfully.'),
- 'operations' => $operations,
- );
- zbatch_set($batch);
- zbatch_process();
-
- } else {
- $message = zt('Genre cache generated successfully.');
- zina_core_cache('genre', '', array('force'=>true));
- }
- } elseif ($m == 3 || $m == 4) { # populate missing
- #TODO: combine 3 & 4... combine 1,3&4?
- if ($zc['database']) {
- $runtime = time();
- $operations = array();
-
- foreach(array('dirs','files_assoc') as $type) {
- $operations[] = array('zina_core_cache_batch', array($type, '', array('force'=>true)));
- }
-
- if ($m == 3) {
- $regen = false;
- $title = zt('Populating database with missing entries.');
- $finished = zt('Database populated.');
- } else { # 4
- $regen = true;
- $title = zt('Synchronising database');
- $finished = zt('Synchronized database.');
- }
-
- $operations[] = array('zdb_populate_batch', array($regen));
- $operations[] = array('zdb_search_playlist_populate', array($runtime));
- $operations[] = array('zdb_genre_populate', array($runtime));
-
- $batch = array(
- 'title' => $title,
- 'finished_message' => $finished,
- 'finished' => 'zdb_populate_finished',
- 'operations' => $operations,
- );
- zbatch_set($batch);
- zbatch_process();
- }
- } elseif ($m == 5) { # image from id3 tags
- $operations[] = array('zbatch_extract_images', array());
-
- $batch = array(
- 'title' => zt('Extracting images from id3 tags.'),
- 'finished_message' => zt('Images extracted successfully.'),
- 'operations' => $operations,
- 'finished' => 'zbatch_extract_images_finished',
- );
- zbatch_set($batch);
- zbatch_process();
- } else {
- $error = true;
- zina_set_message(zt('Invalid option'), 'error');
- }
- $e = error_get_last();
-
- if ($error || ($e['type'] < 2048 && !empty($e['message']))) {
- #todo: ? zunserialize throws error on older custom_files...
- if (!empty($e['message'])) zina_set_message(zt('PHP returned an error[@type]: @message', array('@type'=>$e['type'], '@message'=>$e['message'])), 'error');
- } else {
- zina_set_message($message);
- }
- zina_goto('','l=20');
- break;
-
- Case 27 : # Find and Clean
- if ($zc['database']) {
- if ($_POST && !zina_token_sess_check()) return zina_page_main($path);
-
- if (!empty($_POST['zfileids'])) zdb_clean('file',$_POST['zfileids']);
- if (!empty($_POST['zdirids'])) zdb_clean('dir',$_POST['zdirids']);
- if ($_POST) {
- zina_set_message(zt('Database cleaned.'));
- zina_goto('', 'l=20');
- } else {
- return zina_page_main($path, 'clean');
- }
- }
- break;
-
- Case 33 : # DELETE SITEMAP
- $file = $zc['cache_dir_public_abs'].'/'.$zc['sitemap_file'];
- if (file_exists($file) && @unlink($file)) {
- zina_set_message(zt('Sitemap cached file deleted successfully'));
- } else {
- zina_set_message(zt('Sitemap cached file could not be deleted'),'warn');
- }
- zina_goto('', 'l=20');
- break;
-
- Case 30 :# DELETE TMPL CACHE
- Case 31 :# DELETE IMGS CACHE
- Case 34 :# DELETE ZIP CACHE
- $func = array(
- '30'=> array(
- 'dir' => $zc['cache_tmpl_dir'],
- 'text' => zt('Template cache files deleted.'),
- ),
- '31'=> array(
- 'dir' => $zc['cache_imgs_dir'],
- 'text' => zt('Images cache files deleted.'),
- ),
- '34'=> array(
- 'dir' => $zc['cache_zip_dir'],
- 'text' => zt('Compressed cache files deleted.'),
- ),
- );
- if (zina_delete_files($func[$level]['dir'])) {
- zina_set_message($func[$level]['text']);
- }
- zina_goto('', 'l=20');
- break;
-
- Case 32 : #get language phrases for translation
- $files = array('index.php', 'theme.php', 'database.php', 'lang-cfg.php');
- $source = '';
- foreach($files as $file) {
- $source .= file_get_contents($zc['zina_dir_abs'].'/'.$file);
- }
-
- if (preg_match_all("/zt\('(.*?)'(\)|,)/is", $source, $matches)) {
- $reduced = array_unique($matches[1]);
- $instr = array(
- zt('These are most of the translation strings currently in Zina.'),
- zt('Save this file to LANGCODE.php and modify it.'),
- zt('Format: \'english words\' => \'your translation\'')."\n *",
- zt('You do not have to do them all (just delete the lines you do not do).'),
- zt('If you are making a new translation or completing an older one, move the file to the "lang" directory.'),
- zt('If languages.txt file exists in your cache directory, delete it.'),
- zt('Or a copy in your theme folder will override the default language file.'),
- zt('English users can change wording/phrasings this way.')."\n *",
- zt('Test it out.')."\n *",
- zt('If you would like it to be included in Zina, please email it: to: <@email>', array('@email'=>'ryanlath@pacbell.net')),
- );
-
- $text = '<?php'."\n".
- "/*\n * ".zt('Zina Translation Instructions')."\n *\n";
- foreach($instr as $i) {
- $text .= ' * '.$i."\n";
- }
- $lang = zina_get_languages();
- $language = (isset($lang[$zc['lang']])) ? $lang[$zc['lang']] : zt('Language');
- $text .= " */\n\n".'$language = "'.$language.'";'."\n\n";
- $text .= '$lang[\''.$zc['lang'].'\'] = array('."\n";
- foreach ($reduced as $en) {
- $text .= "\t'".$en."' => '";
- if ($zc['lang'] != 'en') {
- $trans = zt($en);
- if ($trans != $en) {
- $text .= $trans;
- }
- }
- $text .= "',\n";
- }
- $text .= ");\n?>";
-
- while(@ob_end_clean());
- header('Content-type: text/plain');
- if (!$zc['debug']) header('Content-Disposition: attachment; filename="'.$zc['lang'].'.php"');
- echo $text;
- exit;
- } else {
- zina_set_message(zt('Nothing Found'),'error');
- zina_goto('', 'l=20');
- }
- break;
-
- Case 42 : # Add Custom Playlist Title
- if (!zina_token_sess_check()) return zina_page_main($path);
-
- zina_write_playlist($songs, str_replace('/',' - ',$path).'.m3u', 't');
- if ($zc['cache_tmpl']) {
- if (!zina_delete_tmpl_file(zina_get_tmpl_cache_file($path)))
- zina_debug(zt('Could not delete cache file'));
- }
- zina_goto($_SERVER['HTTP_REFERER']);
- break;
-
- Case 45 : # sync database to mp3 files...
- $files_assoc = zina_core_cache('files_assoc', $path);
-
- if (isset($files_assoc[$path])) {
- $files = $files_assoc[$path];
- foreach($files as $file) {
- zdb_log_stat('insertonly', $path, $file, null, true, true);
- }
- } else {
- zdb_log_stat('insertonly', $path, null, null, true, true);
- }
- zina_goto($path);
- break;
-
- Case 47 : # regen statistics
- if ($zc['database']) {
- zdb_stats_generate(time());
- zina_goto('', 'l=20');
- }
- break;
-
- Case 48 :
- if ($zc['genres'] && $zc['database']) {
- return zina_page_main($path, 'genre_hierarchy');
- }
- break;
-
- Case 49 :
- if ($zc['genres'] && $zc['database']) {
- if (!zina_token_sess_check()) return zina_page_main($path);
- zdb_genres_save($_POST);
- #todo: check for errors?
- zina_set_message(zt('Genre hierarchy saved.'));
- zina_goto('', 'l=48');
- }
- break;
-
- Case 52 :
- if ($zc['genres'] && $zc['database']) {
- if (zina_validate('int',$m)) {
- if (zdb_genre_delete($m)) zina_set_message(zt('Genre deleted.'));
- }
- zina_goto('', 'l=48');
- }
- break;
-
- Case 58 :
- return zina_page_main($path, 'edit_images');
- break;
-
- Case 59 : # ajax return images
- @session_write_close();
- if (!$zc['debug']) while(@ob_end_clean());
- echo zina_content_3rd_images($path, $m);
- exit;
- break;
-
- Case 60 : # Delete Image
- $file = $zc['mp3_dir'] .'/'.$path;
- $result = zt('Could not delete file.');
- if (preg_match('/\.('.$zc['ext_graphic'].')$/i', $path) && file_exists($file)) {
- if (@unlink($file)) {
- $result = zt('Deleted: @file', array('@file'=>$file));
- $other = zdb_get_others($path);
- if (isset($other['image']) && $other['image'] == basename($path)) {
- $image = zina_get_dir_item(dirname($path),'/\.('.$zc['ext_graphic'].')$/i');
- zdb_update_others(array('image'=>$image), dirname($path));
- }
- }
- }
- echo $result;
- exit;
- break;
-
- Case 61 : # Save Image
- $result = zt('Failed');
- if (is_writeable($zc['cur_dir'])) {
- if (($image = file_get_contents($imgsrc)) !== false) {
- $filename = $zc['cur_dir'].'/'.basename($imgsrc);
- $i=1;
- while (file_exists($filename)) {
- $filename = $zc['cur_dir'].'/copy'.$i.'_'.basename($imgsrc);
- }
- if (file_put_contents($filename, $image)) {
- $result = zt('Image Saved: @src -> @dest', array('@src'=> $imgsrc, '@dest' => $filename));
- if (isset($_SESSION['zina_missing'][$path])) unset($_SESSION['zina_missing'][$path]);
- }
- }
- }
- if (!$zc['debug']) while(@ob_end_clean());
- echo $result;
- exit;
- break;
-
- Case 62 : # Find album art
- $missing = zina_search_dirs_for_missing_images();
- if (!empty($missing)) {
- $_SESSION['zina_missing'] = $missing;
- zina_goto(current($missing),'l=58');
- } else {
- zina_set_message(zt('No missing artist/album artwork.'));
- unset($_SESSION['zina_missing']);
- zina_goto('', 'l=20');
- }
- exit;
-
- break;
-
- Case 63 : # Close Album Art
- unset($_SESSION['zina_missing']);
- zina_goto($path);
- break;
-
- Case 64 :
- return zina_page_main('', 'help');
- break;
-
- Case 67 : # import textfile playlists into database...
- #remove in 3.0 / make part of upgrade
- if ($zc['database']) {
- $playlists = zina_get_playlists_custom();
- if (empty($playlists)) {
- zina_set_message(zt('No playlists to convert'));
- zina_goto('', 'l=20');
- }
- foreach($playlists as $playlist) {
- $filename = $zc['cache_pls_dir'].'/_zina_'.$playlist.'.m3u';
- if (file_exists($filename)) {
- $pls_id = zdbq_single("SELECT id FROM {playlists} WHERE title = '%s' AND user_id = %d", array($playlist, $zc['user_id']));
-
- if (!empty($pls_id)) {
- zina_set_message(zt('Playlist already exists: @pls', array('@pls'=>$playlist)));
- continue;
- }
- $genre_id = null;
- $dir_id = zdbq_single("SELECT id FROM {dirs} WHERE path = '%s' AND level = 1", array($playlist));
- if ($dir_id) {
- $image_type = 1;
- } else {
- $dir_id = null;
- $image_type = 0;
- }
- $mtime = filemtime($filename);
-
- if (zdbq("INSERT {playlists} (title, user_id, dir_id, genre_id, image_type, date_created, mtime) VALUES ('%s', %d, %d, '%s', '%s', %d, %d)",
- array($playlist, $zc['user_id'], $dir_id, $genre_id, $image_type, $mtime, $mtime))) {
-
- $pls_id = zdbq_single("SELECT id FROM {playlists} WHERE title = '%s' AND user_id = %d", array($playlist, $zc['user_id']));
- if (!empty($pls_id)) {
- $songs = zunserialize_alt(file_get_contents($filename));
- zina_playlist_insert($pls_id, $songs, 1);
- }
- }
- } else {
- zina_set_message(zt('Cannot open playlist: @pls', array('@pls'=>$playlist)));
- }
- }
- zina_goto('', 'l=20');
- }
- break;
-
- Case 71 : # edit tags
- require_once($zc['zina_dir_abs'].'/extras/tag_editor.php');
- return zina_page_main($path, 'edittags');
- break;
-
- Case 72 : # tag search
- Case 73 : # tag search
- require_once($zc['zina_dir_abs'].'/extras/tag_editor.php');
- if ($level == 72) {
- if (($result = zina_extras_tags_freedb_matches(rawurldecode($playlist))) !== false) {
- echo $result;
- }
- } else {
- if (($result = zina_extras_tags_freedb_match($_GET['cat'], $_GET['discid'])) !== false) {
- echo $result;
- }
- }
-
- exit;
- break;
-
- Case 75 : # delete file
- if (($path = zina_delete_file($zc['cur_dir'])) !== false) {
- zina_set_message(zt('Deleted file: @file', array('@file'=>$zc['cur_dir'])));
- }
- zina_goto($path);
-
- break;
- Case 76 : # delete dir
- if (!zfile_check_location($zc['cur_dir'], $zc['mp3_dir']) || !is_dir($zc['cur_dir'])) {
- zina_set_message(zt('Directory does not exist: @dir', array('@dir'=>$zc['cur_dir'])));
- zina_goto('');
- }
- $dir = zina_get_directory($path);
- if (!empty($dir['subdirs'])) {
- zina_set_message(zt('Cannot delete directory. Directory has subdirectories.'));
- zina_goto($path);
- }
-
- if (!empty($dir['files'])) {
- foreach($dir['files'] as $file => $xxx) {
- if (zina_delete_file($zc['mp3_dir'].'/'.$file)) zina_set_message(zt('Deleted file: @file', array('@file'=>$file)));
- }
- }
-
- if (zina_delete_directory($zc['cur_dir'])) {
- if ($zc['database']) {
- $id = zdbq_single("SELECT id FROM {dirs} WHERE path = '%s'", array($path));
- if (!empty($id)) zdb_remove('dir', $id);
- }
- } else {
- zina_set_message(zt('Cannot delete directory: @dir', array('@dir'=>$path)), 'error');
- }
-
- if (($pos = strrpos($path, '/')) == 0) {
- $path = '';
- } else {
- $path = substr($path, 0, $pos);
- }
- zina_goto($path);
-
- break;
-
- Case 78 :
- if ($path != '') return zina_page_main($path, 'rename_directory');
- break;
-
- } # end admin switch
-
- return zina_not_found();
-
- } elseif (in_array($level, array(3,5,6,7,8,10,11,12,16,17,25,53,54,56,57,66,68,70,74))) {
- # STREAM FUNCTIONS
-
- switch ($level) {
-
- Case 3 :
- if ($zc['cmp_sel']) {
- zina_send_zip_selected($songs, (isset($_GET['lf'])));
- }
- break;
-
- Case 5 :
- if ($zc['cmp_sel']) {
- zina_send_zip_selected_dir($path, (isset($_GET['c'])), (isset($_GET['lf'])));
- }
- break;
-
- Case 6 : # Return resampled MP3
- if ($zc['resample']) {
- if ($zc['database'] && $zc['stats']) zdb_log_stat('play', dirname($path), basename($path));
- zina_send_file_music($path, true);
- }
- break;
-
- Case 7 : # return resized image
- $type = isset($_GET['it']) ? $_GET['it'] : null;
-
- if (in_array($type, array('sub','dir','full','search','genre','genresearch','pls','plssearch'))) {
- $cache_file = $string = false;
- $text = null;
- if (empty($imgsrc)) {
- if ($type == 'genresearch' || $type == 'plssearch') $type = 'search';
- $tmp = $zc['theme_path_abs'].'/images';
- $imgsrc = ztheme('missing_image',$type);
- $text = ztheme('title',basename($path));
- } else {
- $res_out_type = ($zc['res_out_type'] == 'jpeg') ? 'jpg' : $zc['res_out_type'];
- if ($type == 'genre' || $type == 'genresearch') {
- if ($type == 'genresearch') $type = 'search';
- $tmp = $zc['theme_path_abs'].'/images';
- $genre_file = ztheme('image_genre', $imgsrc);
- if (file_exists($tmp.'/'.$genre_file)) {
- $imgsrc = $genre_file;
- } else {
- $text = strtoupper($imgsrc);
- $imgsrc = ztheme('missing_image','genre');
- }
- $cache_file = $zc['cache_imgs_dir'].'/'.$type.md5($tmp.'/'.$genre_file).'.'.$res_out_type;
- } elseif ($type == 'pls' || $type == 'plssearch') {
- $tmp = $zc['theme_path_abs'].'/images';
- $text = strtoupper($imgsrc);
- $imgsrc = ztheme('missing_image','playlist');
- $type = ($type == 'pls') ? 'sub' : 'search';
- #$cache_file = $zc['cache_imgs_dir'].'/'.$type.md5($tmp.'/'.$genre_file).'.'.$res_out_type;
- } elseif ($imgsrc == 'zina_id3_zina.jpg') {
- $subdir_file = zina_get_dir_item($zc['mp3_dir'].'/'.$path,'/\.('.$zc['ext_mus'].')$/i');
- $tmp = $zc['mp3_dir'].'/'.$path;
- if (!empty($subdir_file)) {
- $info = zina_get_file_info($zc['mp3_dir'].'/'.$path.'/'.$subdir_file, false, true, false, true);
- if (isset($info->image)) {
- $string = $info->image;
- $cache_file = $zc['cache_imgs_dir'].'/'.$type.md5($zc['mp3_dir'].'/'.$path.'/'.$imgsrc).'.'.$res_out_type;
- }
- }
- } else {
- $tmp = $zc['mp3_dir'].'/'.$path;
- $cache_file = $zc['cache_imgs_dir'].'/'.$type.md5($zc['mp3_dir'].'/'.$path.'/'.$imgsrc).'.'.$res_out_type;
- }
-
- if ($zc['cache_imgs'] && $cache_file) {
- if (file_exists($cache_file)) {
- while(@ob_end_clean());
- Header('Content-type: image/'.$zc['res_out_type']);
- readfile($cache_file);
- exit;
- }
- }
- }
-
- $image_source = $tmp.'/'.$imgsrc;
- if (!file_exists($image_source) && !$string) {
- $image_source = $zc['theme_path_abs'].'/images/'.ztheme('missing_image',$type);
- $text = zt('Error');
- $cache_file = $string = false;
- }
-
- zina_send_image_resized($image_source, $type, $text, $cache_file, $string);
- }
- break;
-
- Case 11 : # return img
- if ($zc['stream_int'] && preg_match('/\.('.$zc['ext_graphic'].')$/i', $imgsrc)) {
- $file = $zc['mp3_dir'].'/'.((!empty($path)) ? $path.'/' : '').$imgsrc;
- if (file_exists($file)) {
- @ob_end_clean();
- readfile($file);
- }
- }
- break;
-
- Case 8 : # RETURN PLAYLISTS
- if ($zc['play']) {
- if (!isset($m)) $m = isset($_POST['m']) ? $_POST['m'] : null;
- $lofi = (isset($_GET['lf']));
- $cus = (isset($_GET['c']));
- $num = isset($_POST['n']) ? $_POST['n'] : (isset($_GET['n']) ? $_GET['n'] : null);
- if (!in_array($num, $zc['ran_opts'])) $num = $zc['ran_opts_def'];
- if ($playlist == null && isset($_GET['playlist'])) $playlist = $_GET['playlist'];
- $random = (isset($_GET['rand']));
- $store = (isset($_GET['store']));
-
- switch($m) {
- Case 0 :
- zina_send_playlist_title($path, $cus, $lofi);
- break;
- Case 1 :
- zina_send_playlist_song($path, $lofi);
- break;
- Case 3 :
- zina_send_playlist_custom($playlist, $lofi, $random);
- break;
- Case 4 : # Random Albums
- zina_send_playlist_random($num,'t',$lofi, true, null, $playlist);
- break;
- Case 5 : # Random Songs
- zina_send_playlist_random($num,'s',$lofi, true, null, $playlist);
- break;
- Case 6 : # Random Songs By Year
- zina_send_playlist_random($num,'s',$lofi, true, null, null, $playlist);
- break;
- Case 7 :
- zina_send_playlist_selected($songs, $lofi, $store);
- break;
- Case 8 :
- zina_send_playlist_selected_random($songs, $lofi, $store);
- break;
- Case 10 : # Play Recursively & Recursively Random ($cus = random)
- zina_send_playlist_random(0,'s',$lofi,$cus,$path);
- break;
- Case 11 : # Random Songs via Rated Songs
- zina_send_playlist_random($num,'tt',$lofi, true, null, $playlist);
- break;
- Case 12 : # Random Songs via Rated Artists
- zina_send_playlist_random($num,'artist',$lofi, true, null, $playlist);
- break;
- }
- }
- break;
-
- Case 10 : # internal streaming
- if ($zc['play']) {
- if ($zc['remote'] && preg_match('/\.('.$zc['remote_ext'].')$/i', $path)) {
- $rem = new remoteFile($zc['mp3_dir'].'/'.$path, false, true);
- if (isset($rem->url)) {
- if ($zc['database'] && $zc['stats']) zdb_log_stat('play', dirname($path), basename($path));
- while(@ob_end_clean());
- header('Location: '.$rem->url);
- exit;
- }
- } elseif ($zc['play'] && $zc['stream_int']) {
- if ($zc['database'] && $zc['stats']) zdb_log_stat('play', dirname($path), basename($path));
- zina_send_file_music($path);
- }
- }
- break;
-
- Case 12 : # download mp3
- if ($zc['download'] && preg_match('/\.('.$zc['ext_mus'].')$/i', $path, $exts)) {
- $file = $zc['mp3_dir'].'/'.$path;
- if (file_exists($file)) {
- if ($zc['database'] && $zc['stats']) zdb_log_stat('down', dirname($path), basename($path));
- if ($zc['stream_int']) {
- $filename = html_entity_decode(zina_get_file_artist_title($file, $zc['mp3_id3'])).'.'.$exts[1];
- zina_set_header('Content-Type: application/force-download');
- zina_set_header('Content-Disposition: inline; filename="'.$filename.'"');
- zina_set_header('Content-Length: '.filesize($file));
- zina_set_header('Cache-control: private'); #IE seems to need this.
- zina_send_file($file);
- } else {
- zina_goto($path,NULL,NULL,TRUE,TRUE);
- }
- }
- }
- break;
-
- Case 16 : # VOTE
- if ($zc['database']) {
- $num = isset($_POST['n']) ? $_POST['n'] : (isset($_GET['n']) ? $_GET['n'] : null);
- if (zina_validate('int',$num) && $num <= 5 && ($num >= 1 || ($zc['user_id'] > 0 && $num == 0))) {
- if (preg_match('/\.('.$zc['ext_mus'].')$/i', $path) || ($zc['remote'] && preg_match('/\.('.$zc['remote_ext'].')$/i', $path))) {
- if ($zc['rating_files']) zdb_log_stat('vote',dirname($path), basename($path), $num);
- $path = dirname($path);
- } else {
- if ($zc['rating_dirs']) zdb_log_stat('vote',$path, null, $num);
- }
- if ($zc['cache_tmpl']) {
- if (!zina_delete_tmpl_file(zina_get_tmpl_cache_file($path))) zina_debug(zt('Cannot delete cache file'));
- }
- #todo: return 'error' on bad result
- echo ($num == 0) ? zt('Deleted') : zt('Thank you');
- }
- }
- break;
-
- Case 68 : # Vote Playlists
- if ($zc['database'] && $zc['pls_ratings']) {
- $num = isset($_POST['n']) ? $_POST['n'] : (isset($_GET['n']) ? $_GET['n'] : null);
- if (zina_validate('int',$num) && $num <= 5 && ($num >= 1 || ($zc['user_id'] > 0 && $num == 0))) {
- zdb_log_stat_playlist((int)$playlist, 'votes', $num);
- #todo: return 'error' on bad result
- echo ($num == 0) ? zt('Deleted') : zt('Thank you');
- }
- }
- break;
-
- Case 25 : # download MM
- if ($zc['mm'] && $zc['mm_down'] && preg_match('/\.('.$zc['mm_ext'].')$/i', $path, $exts)) {
- $file = $zc['mp3_dir'].'/'.$path;
- if (file_exists($file)) {
- if ($zc['stream_int']) {
- $ext = strtolower($exts[1]);
- zina_set_header('Content-Type: '.$zc['mm_types'][$ext]['mime']);
- $disposition = (isset($zc['mm_types'][$ext]['disposition'])) ? $zc['mm_types'][$ext]['disposition'] : 'attachment';
- zina_set_header('Content-Disposition: '.$disposition.'; filename="'.basename($path).'"');
- zina_set_header('Content-Length: '.filesize($file));
- zina_set_header('Cache-control: private'); #IE seems to need this.
- zina_send_file($file);
- } else {
- zina_goto($path,NULL,NULL,TRUE,TRUE);
- }
- }
- }
- break;
-
- Case 53 : # LIVE SEARCH RETURN
- $search_term = (isset($_GET['zinaq'])) ? $_GET['zinaq'] : '';
-
- if (strlen($search_term) >= $zc['search_min_chars']) {
- $num = isset($_GET['limit']) ? $_GET['limit'] : $zc['search_live_limit'];
- $num = (zina_validate('int', $num) && $num > 0 && $num < $zc['search_live_limit']) ? $num : $zc['search_live_limit'];
- if ($zc['db_search']) {
- $results = zdbq_array("SELECT i.title, i.type, i.context, i.id, i.path, i.genre ".
- ",if(i.type='playlist', p.image_type, FALSE) as image_type ".
- ",if(i.type='playlist', pd.path, FALSE) as image_path ".
- "FROM {search_index} AS i ".
- "LEFT OUTER JOIN {playlists} AS p ON (i.type = 'playlist' AND i.type_id = p.id) ".
- "LEFT OUTER JOIN {dirs} AS pd ON (i.type = 'playlist' AND i.type_id = p.id AND p.dir_id = pd.id) ".
- "WHERE i.title LIKE '%%%s%%' ".
- "ORDER BY i.title LIMIT %d",
- array($search_term, $num));
- } else {
- $results = zina_search_cache($search_term, $num);
- }
-
- if (!empty($results)) {
-
- if ($zc['search_images']) {
- foreach ($results as $key => $item) {
- $results[$key]['image'] = zina_content_search_image($item, 'search');
- }
- }
-
- foreach ($results as $item) {
- unset($item['image_type']);
- unset($item['image_path']);
- $item['type'] = zt(ucfirst($item['type']));
- echo implode('|', $item)."\n";
- }
- }
- }
- exit;
-
- break;
-
- Case 54 : # XML file info for flash app
- if ($zc['zinamp']) {
- $output = zina_get_file_xml($path);
- while(@ob_end_clean());
- header('Content-type: application/xml');
- echo $output;
- }
- break;
-
- Case 56 :
- if ($zc['zinamp'] && $zc['lastfm'] && isset($_GET['n'])) {
- zina_play_complete($path, intval($_GET['n']));
- }
- break;
-
- Case 57 : # 3rd party lyrics
- if ($zc['song_extras'] && in_array($m, $zc['song_es_exts'])) {
- @session_write_close();
- if ($zc['zinamp'] && $playlist == 'zinamp') {
- $content = zina_content_blurb($zina, $path, array('type'=>$m, 'return'=>true));
- if (isset($content['output']) && !empty($content['output'])) {
- if (!$zc['debug']) @ob_end_clean();
- echo nl2br($content['output']);
- exit;
- }
- }
- if (isset($zc['third_'.$m]) && $zc['third_'.$m]) {
- $info = array();
- zina_get_file_artist_title($zc['mp3_dir'].'/'.$path, true, $info);
- $lyr_opts = zina_get_extras_opts($m);
-
- $opts = explode(',', $zc['third_lyr_order']);
- $output = '';
-
- if (!empty($info['artist']) && !empty($info['title'])) {
- foreach($opts as $source) {
- if (!in_array($source, $lyr_opts)) continue;
- require_once($zc['zina_dir_abs'].'/extras/extras_'.$m.'_'.$source.'.php');
- $result = array();
-
- if (($result = call_user_func('zina_extras_'.$m.'_'.$source, $info['artist'], $info['title'])) !== false) {
- $output .= $result['output'];
- if ($zc['third_'.$m.'_save']) {
- zina_save_blurb($path, $m, $output, null, false);
- }
- $output = nl2br($output);
- if (isset($result['source'])) $output .= ztheme('extras_source', $result['source']);
- break;
- }
- }
- }
- if (empty($output)) $output .= zt('No @type found.', array('@type'=>$zc['song_es'][$m]['name']));
- if (!$zc['debug']) while(@ob_end_clean());
- echo $output;
- }
- }
- break;
-
- Case 66 :
- if ($zc['zinamp'] && $zc['lastfm']) {
- zina_zinamp_start($path);
- }
- break;
-
- Case 70 :
- if ($zc['playlists'] && $zc['database'] && zina_validate('int',$playlist)) {
- zina_playlist_feed($playlist);
- }
- break;
-
- Case 74:
- if (isset($_SESSION['zina_store'])) {
- $store = $_SESSION['zina_store'];
- unset($_SESSION['zina_store']);
- if (!empty($store)) {
- zina_send_playlist_content($store['type'], $store['content']);
- }
- }
- break;
- }
- exit;
-
- } else {
- # PAGE DISPLAYS (2,4,9,13,14,15,22,23,24,29,40,41,43,44,50,51,55,69,77,99)
-
- switch ($level) {
-
- Case 2 :
- if ($zc['playlists']) return zina_page_main($path, 'playlists', array('pl'=>$playlist, 'id'=>$m));
- break;
-
- Case 4 : # SEARCH
- if ($zc['search']) return zina_page_main($path, 'search', array('m'=>$m));
- break;
-
- Case 9 : # LOGIN
- if ($zc['login']) {
- if (isset($_POST['un']) && isset($_POST['up'])) {
- if (zina_check_password($_POST['un'], $_POST['up'])) {
- $_SESSION['za-'.ZINA_VERSION] = true;
- if ($zc['session']) { // standalone only
- $sess_id = zina_token_sess('1');
- setcookie('ZINA_SESSION', $sess_id, time() + (60*60*$zc['session_lifetime']), '/');
- $sess_file = $zc['cache_dir_private_abs'].'/sess_'.$sess_id;
- @touch($sess_file);
- }
- zina_goto($path);
- } else {
- sleep(3);
- $_SESSION['za-'.ZINA_VERSION] = false;
- zina_set_message(zt('Username and/or password are incorrect.'),'warn');
- }
- }
- return zina_page_main($path, 'login');
- }
- break;
-
- Case 13 : # Genre Listing
- if ($zc['genres']) return zina_page_main($path, 'searchgenre');
- break;
-
- Case 14 : # Genres
- if ($zc['genres']) return zina_page_main($path, 'genres');
- break;
-
- Case 15 : # STATS
- if ($zc['database'] && $zc['stats'] && ($zc['stats_public'] || $zc['is_admin'])) {
- $period = isset($_POST['period']) ? $_POST['period'] : null;
- $type = isset($_POST['type']) ? $_POST['type'] : null;
- return zina_page_main($path, 'stats', array('stat'=>$playlist, 'period'=>$period, 'type'=>$type));
- }
- break;
-
- Case 22 : # VARIOUS EDIT WINDOWS
- if ($zc['is_admin'] || (zina_cms_access('editor') && (in_array($m, array(1,2,3,4,6)) || in_array($m, $zc['song_es_exts'])))) {
- return zina_page_main($path, 'blurb', array('type'=>$m, 'item'=>$playlist));
- } else {
- return zina_access_denied();
- }
- break;
-
- Case 23 : # VARIOUS EDIT WINDOWS SAVE
- if (!zina_token_sess_check()) return zina_page_main($path);
- if ($zc['is_admin'] || (zina_cms_access('editor') && (in_array($m, array(1,2,3,4,6)) || in_array($m, $zc['song_es_exts'])))) {
- zina_save_blurb($path, $m, $songs, $playlist);
- } else {
- return zina_access_denied();
- }
- break;
-
- Case 77 :
- if ($zc['is_admin'] || (zina_cms_access('editor'))) {
- if (isset($_POST) && !empty($_POST) && !zina_token_sess_check()) return zina_access_denied();
-
- return zina_page_main($path, 'dir_opts');
- } else {
- return zina_access_denied();
- }
- break;
-
- Case 24 : # PLAY MM
- if ($zc['mm']) return zina_page_main($path, 'mm');
- break;
-
- Case 29 :# Song Extras
- if ($zc['song_extras'] && in_array($m, $zc['song_es_exts'])) {
- return zina_page_main($path, 'songextras', array('type'=>$m, 'item'=>null));
- }
- break;
-
- Case 40 : # Add New Playlist && Add To Playlist
- if (!zina_token_sess_check()) return zina_page_main($path);
-
- if ($zc['database']) {
- $access = zina_cms_access('edit_playlists', $zc['user_id']);
- if (!($access || ($zc['session_pls'] && $playlist == 'zina_session_playlist'))) {
- zina_set_message(zt('Not authorized'));
- return zina_page_main($path);
- }
- if ($access && $playlist == 'new_zina_list') {
- if (!$zc['is_admin']) {
- $count = zdbq_single("SELECT COUNT(*) FROM {playlists} WHERE user_id = %d", array($zc['user_id']));
- if ($count > $zc['pls_limit']) {
- zina_set_message(zt('Cannot create playlist.').' '.zt('Maximum number of playlists reached.'));
- return zina_page_main($path);
- }
- }
- return zina_page_main($path, 'newplaylist',array('songs'=>$songs));
- } else {
- if (isset($_POST['fromnew'])) {
- if (($pls_id = zina_playlist_form_submit('insert')) !== false) {
- $playlist = $pls_id;
- $start = 1;
- } else {
- $start = false;
- }
- } else {
- if ($playlist == 'zina_session_playlist') {
- $existing = (isset($_SESSION['z_sp'])) ? unserialize_utf8($_SESSION['z_sp']) : array();
- $start = count($existing);
- } else {
- $start = zdbq_single("SELECT MAX(weight) FROM {playlists_map} WHERE playlist_id = %d", array($playlist, $zc['user_id']));
- }
- }
- if ($start !== false) {
- if (zina_playlist_insert($playlist, $songs, $start+1)) {
- zina_set_message(zt('Added to playlist'));
- } else {
- zina_set_message(zt('Could not add to playlist'), 'warn');
- }
- }
-
- if (isset($_POST['fromnew'])) {
- if (empty($path)) {
- zina_goto('','l=2&pl='.rawurlencode($playlist));
- } else {
- return zina_page_main($path);
- }
- } else {
- echo ztheme('messages');
- exit;
- }
- }
- } elseif ($zc['is_admin'] || $zc['session_pls']) {
- if (!$zc['is_admin']) $playlist = 'zina_session_playlist';
- if ($playlist == 'new_zina_list') {
- return zina_page_main($path, 'newplaylist',array('songs'=>$songs));
- } else {
- zina_write_playlist($songs, '_zina_'.$playlist.'.m3u', 'a');
- zina_set_message(zt('Added to playlist'));
-
- if (isset($_POST['fromnew'])) {
- if (empty($path)) {
- zina_goto('','l=2&pl='.rawurlencode($playlist));
- } else {
- return zina_page_main($path);
- }
- } else {
- echo ztheme('messages');
- exit;
- }
- }
- }
- break;
-
- Case 41 : # Update Playlist
- if (!zina_token_sess_check()) return zina_page_main($path);
-
- $order = isset($_POST['order']) ? $_POST['order'] : null;
- if ($zc['database']) {
- $pls_user_id = zdbq_single("SELECT user_id FROM {playlists} WHERE id = %d", array($playlist));
- $access = zina_cms_access('edit_playlists', $pls_user_id);
-
- if (!($access || ($zc['session_pls'] && $playlist == 'zina_session_playlist'))) {
- zina_set_message(zt('Not authorized'));
- return zina_page_main($path);
- }
-
- $songs = zina_reorder_playlist($songs, $order);
- if ($playlist == 'zina_session_playlist') {
- $_SESSION['z_sp'] = utf8_encode(serialize($songs));
- } else {
- zdbq("DELETE FROM {playlists_map} WHERE playlist_id = %d", array($playlist));
- foreach($songs as $weight => $type_id) {
- if (preg_match('/\.lp$/i', $type_id)) {
- $type = 'album';
- $type_id = preg_replace('/\/\.lp$/i','',$type_id);
- } elseif (preg_match('/\.pls$/i', $type_id)) {
- $type = 'playlist';
- $type_id = preg_replace('/\.pls/i','',$type_id);
- } else {
- $type = 'song';
- }
- if (!zdbq("INSERT {playlists_map} (playlist_id, type, type_id, weight) VALUES (%d, '%s', %d, %d)",
- array($playlist, $type, $type_id, $weight+1))) {
- zina_set_message(zt('Could not insert into playlist: @file', array('@file'=>$type_id)));
- }
- }
- if (($sum_items = zdbq_single("SELECT COUNT(*) FROM {playlists_map} WHERE playlist_id = %d", array($playlist))) !== false) {
- zdbq("UPDATE {playlists} SET sum_items = %d WHERE id = $playlist", array($sum_items, $playlist));
- }
- }
- return zina_page_main($path, 'playlists',array('pl'=>$playlist));
- } elseif ($zc['is_admin'] || $zc['session_pls']) {
- if (!$zc['is_admin']) $playlist = 'zina_session_playlist';
- zina_write_playlist(zina_reorder_playlist($songs, $order), '_zina_'.$playlist.'.m3u');
- return zina_page_main($path, 'playlists',array('pl'=>$playlist));
- }
- break;
-
- Case 43 : # DELETE CUSTOM PLAYLIST
- if ($zc['database'] && $playlist != 'zina_session_playlist') {
- if ($zc['is_admin'] || $zc['pls_user']) {
- if ($zc['is_admin']) {
- $access = true;
- } else {
- $access = zdbq_single("SELECT 1 FROM {playlists} WHERE id = %d AND user_id = %d", array($playlist, $zc['user_id']));
- }
- if ($access) {
- zdbq("DELETE FROM {playlists_map} WHERE playlist_id = %d", array($playlist));
- zdbq("DELETE FROM {playlists} WHERE id = %d", array($playlist));
- zina_set_message(zt('Playlist deleted'));
- zina_goto('','l=2');
- }
- }
- } else {
- if ($zc['is_admin'] || $zc['session_pls']) {
- if (!$zc['is_admin']) $playlist = 'zina_session_playlist';
- zina_delete_playlist_custom($playlist);
- zina_goto('','l=2');
- }
- }
- break;
-
- Case 44 : # EDIT PLAYLIST
- if ($_POST && !zina_token_sess_check()) return zina_page_main($path);
- if (!($zc['playlists'] && ($zc['is_admin'] || ($zc['pls_user'] && $zc['user_id'] > 0)))) return zina_access_denied();
- $playlist_new = isset($_POST['playlist_new']) ? $_POST['playlist_new'] : '';
- return zina_page_main($path, 'renameplaylist', array('playlist'=>$playlist, 'new'=>$playlist_new));
- break;
-
- case 46 :
- if ($zc['res_full_img'] && preg_match('/\.('.$zc['ext_graphic'].')$/i', $path)) {
- return zina_page_main($path, 'image');
- }
- break;
-
- Case 50 : #podcast
- if ($zc['rss']) {
- #TODO: make common output function...
- while(@ob_end_clean());
- header('Content-type: application/xml');
- echo zina_content_rss($path);
- exit;
- }
- break;
-
- Case 51 : # SITEMAP
- if ($zc['sitemap']) {
- $output = zina_cache('sitemap', 'zina_content_sitemap', null, ($zc['sitemap'] == 2));
- while(@ob_end_clean());
- header('Content-type: text/xml');
- echo $output;
- exit;
- }
- break;
-
- Case 99 : # logout
- session_unregister('za-'.ZINA_VERSION);
- if ($zc['session']) {
- if (isset($_COOKIE['ZINA_SESSION'])) {
- $sess_file = $zc['cache_dir_private_abs'].'/sess_'.zcheck_plain($_COOKIE['ZINA_SESSION']);
- setcookie('ZINA_SESSION', $_COOKIE['ZINA_SESSION'], time() - 42000, '/');
- if (file_exists($sess_file)) @unlink($sess_file);
- }
-
- # remove expired sessions
- $old_sessions = glob($zc['cache_dir_private_abs']."/sess_*");
- if (is_array($old_sessions)) {
- foreach ($old_sessions as $filename) {
- if (filemtime($filename) + (60*60*$zc['session_lifetime']) < time()) {
- @unlink($filename);
- }
- }
- }
- }
-
- zina_set_message(zt('Logged out succesfully.'));
- zina_goto($path);
- break;
-
- case 55 :
- #todo: move to stream?
- if ($zc['zinamp'] == 2) {
- $content = ztheme('zinamp');
- zina_set_js('inline',
- 'window.onunload = function() {'.
- 'zina_cookie("zinamp_window", "screenX="+window.screenX+",screenY="+window.screenY, {expires:7});'.
- '};');
- $zina = zina_page_simple('zinamp', $content);
- echo ztheme('page_zinamp', $zina);
- exit;
- }
- break;
-
- Case 65 :
- require_once($zc['zina_dir_abs'].'/batch.php');
- $output = _zbatch_page();
- if ($output === FALSE) {
- return zina_access_denied();
- } elseif (isset($output)) {
- zina_set_css('file', 'extras/progress.css');
- return zina_page_simple(zbatch_set_title(), $output);
- }
- return;
-
- Case 69 : # Year Listing
- if ($zc['db_search']) return zina_page_main($path, 'searchyear');
- break;
-
-
- default : # MAIN PAGE
- # Allows files to stream without l=8 (for RSS and prettiness)
- if (is_file($zc['cur_dir']) && $zc['play'] && (($zc['stream_int'] && preg_match('/\.('.$zc['ext_mus'].')$/i', $path)) ||
- ($zc['remote'] && preg_match('/\.('.$zc['remote_ext'].')$/i', $path, $matches)))) {
- if ($zc['database'] && $zc['stats']) zdb_log_stat('play', dirname($path), basename($path));
- zina_send_file_music($path);
- }
-
- if (is_file($zc['cur_dir']) && $zc['rss'] && basename($path) == $zc['rss_file']) {
- $output = file_get_contents($zc['cur_dir']);
- $output = utf8_decode($output);
- header('Content-type: application/xml');
- echo $output;
- exit;
- }
-
- if (!is_dir($zc['cur_dir'])) return zina_not_found();
- if ($zc['database']) zdb_log_stat('view', $path);
- return zina_page_main($path);
- }
- return zina_not_found();
- }
- } #END MAIN
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * PAGES
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- function zina_page_main($path, $type='main', $opts=null) {
- global $zc;
- $page = zina_get_page_opt($path);
- $cat_sort = zina_get_catsort_opt($path);
-
- if ($zc['cache_tmpl']) {
- $cache_file = $zc['cache_tmpl_dir'].'/'.zina_get_tmpl_cache_file($path);
-
- if (!$zc['is_admin'] && $_SERVER['REQUEST_METHOD'] == 'GET' && file_exists($cache_file)) {
- $mtime = filemtime($cache_file);
- if ($mtime > filemtime($zc['cur_dir'].'/.') && $mtime + ($zc['cache_tmpl_expire'] * 86400) > time()) {
- $zina = unserialize(implode('', gzfile($cache_file)));
- $zina['cached'] = true;
- return $zina;
- }
- }
- }
-
- $zina = array();
- $zina['lang']['main_dir_title'] = zt($zc['main_dir_title']);
- $zina['embed'] = $zc['embed'];
- $zina['site_name'] = isset($zc['conf']['site_name']) ? $zc['conf']['site_name'] : '';
- $zina['amg'] = $zc['amg'];
- $zina['theme_path'] = zpath_to_theme();
- $zina['searchform'] = $zina['stats'] = $zina['genres'] = $random = '';
- $zina['charset'] = $zc['charset'];
- $zina['addthis'] = $zc['third_addthis'];
- $zina['addthis_id'] = $zc['third_addthis_id'];
- $zina['addthis_options'] = $zc['third_addthis_options'];
- $zina['addthis_path'] = $path;
- $zina['addthis_query'] = null;
-
- if ($zc['search']) {
- $search_term = isset($_POST['searchterm']) ? $_POST['searchterm'] : (isset($_GET['pl']) ? $_GET['pl'] : (isset($_GET['searchterm']) ? $_GET['searchterm'] : ''));
- $zina['searchform…
Large files files are truncated, but you can click here to view the full file