PageRenderTime 59ms CodeModel.GetById 41ms RepoModel.GetById 0ms app.codeStats 1ms

/zina/index.php

https://bitbucket.org/helmespc/zina2
PHP | 8728 lines | 7679 code | 784 blank | 265 comment | 1937 complexity | 4dc2c0ccfb281ef63c4d9f19b3b2d65f MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3. * ZINA2 (Zina2 is not Zina)
  4. *
  5. * Zina2 is a graphical interface to your MP3 collection, a personal
  6. * jukebox, an MP3 streamer. It can run on its own, embeded into an
  7. * existing website, or as a Drupal/Joomla/Wordpress/etc. module.
  8. *
  9. * https://bitbucket.org/helmespc/zina2
  10. * Author: Patrick Helmes <helmespc@gmail.com>
  11. * Support: https://bitbucket.org/helmespc/zina2/wiki/Home
  12. * License: GNU GPL2 <http://www.gnu.org/copyleft/gpl.html>
  13. *
  14. * This Software is a fork of Zina (is not Andromeda):
  15. * http://www.pancake.org/zina
  16. * Author: Ryan Lathouwers <ryanlath@pacbell.net>
  17. * Support: http://sourceforge.net/projects/zina/
  18. * License: GNU GPL2 <http://www.gnu.org/copyleft/gpl.html>
  19. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  20. define('ZINA_VERSION', '1.0b1');
  21. #TODO:
  22. # - INSTRUCTIONS for cron for caches
  23. #todo
  24. # - uninstall? -> at least delete cache files created by webuser!
  25. # - check settings descriptions...
  26. # - normalize function names
  27. # - organize files
  28. # - comment functions?
  29. # - look and remove unused language crap?
  30. #TODO-EXTRA:
  31. # - if clean urls... drop l=8&m=1 for songs???
  32. # - See Also -> external links?
  33. # - multiple mp3 dirs
  34. # - Check output_buffering php.ini setting for video stuff?
  35. #TEST:
  36. # - pos
  37. function zina($conf) {
  38. global $zc;
  39. zina_init($conf);
  40. $path = isset($_GET['p']) ? zrawurldecode($_GET['p']) : null;
  41. $level = isset($_GET['l']) ? $_GET['l'] : null;
  42. $m = isset($_GET['m']) ? $_GET['m'] : null;
  43. $imgsrc = isset($_GET['img']) ? $_GET['img'] : null;
  44. $playlist = isset($_POST['playlist']) ? $_POST['playlist'] : (isset($_GET['pl']) ? $_GET['pl'] : null);
  45. $songs = isset($_POST['mp3s']) ? $_POST['mp3s'] : (isset($_GET['mp3s']) ? $_GET['mp3s'] : array());
  46. $path = preg_replace("|(/){2,}|",'$1',trim($path,'/'));
  47. // Validate path doesn't contain '..' and is a valid location under mp3_dir
  48. $badpath = false;
  49. if (strstr($path,'..') && !zfile_check_location($zc['mp3_dir'].'/'.$path, $zc['mp3_dir'])) {
  50. $badpath = true;
  51. }
  52. // Validate that the imgsrc doesn't contain a '..', unless level is 11 or 7
  53. if (!$badpath && strstr($imgsrc,'..')) {
  54. $badpath = true;
  55. if ($level == 11) {
  56. $badpath = (!zfile_check_location($zc['mp3_dir'].'/'.$path, $zc['mp3_dir']));
  57. }
  58. elseif ($level == 7) {
  59. if (isset($_GET['it'])) {
  60. if ($_GET['it'] == 'genre') {
  61. }
  62. elseif (in_array($_GET['it'], array('sub','dir','full','search'))) {
  63. $badpath = (!zfile_check_location($zc['mp3_dir'].'/'.$path, $zc['mp3_dir']));
  64. }
  65. }
  66. }
  67. }
  68. // Validate that the playlist doesn't contain a '..'
  69. if (!$badpath && strstr($playlist,'..')) {
  70. $badpath = true;
  71. }
  72. // Validate song paths
  73. if (!$badpath && !empty($songs) && is_array($songs)) {
  74. foreach ($songs as $song) {
  75. if (strstr($song,'..') && !zfile_check_location($zc['mp3_dir'].'/'.$path, $zc['mp3_dir'])) {
  76. $badpath = true;
  77. break;
  78. }
  79. }
  80. }
  81. // If the path is bad, fail
  82. if ($badpath) {
  83. zina_debug(zt('Bad path: @path', array('@path'=>$path)));
  84. return zina_not_found();
  85. }
  86. // Set the current directory based on the URL
  87. $zc['cur_dir'] = $zc['mp3_dir']. (!empty($path) ? '/'.$path : '');
  88. if (!empty($path) && !file_exists($zc['cur_dir'])) {
  89. $file_not_found = true;
  90. if (substr($path,-3) == '.lp') {
  91. $tmp_path = substr($path, 0, strlen($path) -3);
  92. if (file_exists($zc['mp3_dir'].'/'.$tmp_path)) {
  93. $file_not_found = false;
  94. $zc['cur_dir'] = $zc['mp3_dir'].'/'.$tmp_path;
  95. }
  96. }
  97. elseif ($zc['sitemap'] && $path == $zc['sitemap_file']) {
  98. $level = 51;
  99. $path = '';
  100. $zc['cur_dir'] = $zc['mp3_dir'];
  101. $file_not_found = false;
  102. }
  103. elseif ($zc['rss'] && basename($path) == $zc['rss_file']) {
  104. $level = 50;
  105. $path = substr($path,0,-(strlen($zc['rss_file'])+1));
  106. $zc['cur_dir'] = $zc['mp3_dir'].'/'.$path;
  107. if (file_exists($zc['cur_dir'])) {
  108. $file_not_found = false;
  109. }
  110. }
  111. elseif ($zc['stats_rss'] && $zc['database'] && basename($path) == 'stats.xml') {
  112. zina_stats_feed($path);
  113. }
  114. elseif ($zc['playlists'] && $zc['database'] && basename($path) == 'pls.xml') {
  115. $pls_id = dirname($path);
  116. if (zina_validate('int',$pls_id)) {
  117. zina_playlist_feed($pls_id);
  118. }
  119. }
  120. elseif ($level == 46 && basename($path) == 'zina_id3_zina.jpg') {
  121. $file_not_found = false;
  122. $tmp_path = dirname($path);
  123. $tmp_path = $zc['mp3_dir'].(!empty($tmp_path) ? '/'.$tmp_path : '');
  124. if (file_exists($tmp_path) && is_dir($tmp_path)) {
  125. $file_not_found = false;
  126. }
  127. }
  128. // Handle file not found
  129. if ($file_not_found) {
  130. $tmp_path = utf8_decode($path);
  131. $tmp_cur_dir = $zc['mp3_dir']. (!empty($tmp_path) ? '/'.$tmp_path : '');
  132. if (file_exists($tmp_cur_dir)) {
  133. $path = $tmp_path;
  134. $zc['cur_dir'] = $tmp_cur_dir;
  135. }
  136. else {
  137. if (substr($path,-11) != 'favicon.ico') {
  138. zina_debug(zt('Path does not exist: @path', array('@path'=>$path)));
  139. }
  140. return zina_not_found();
  141. }
  142. }
  143. }
  144. #todo: validate?
  145. if ($zc['settings_override']) {
  146. $override_file = $zc['cur_dir'].'/'.$zc['settings_override_file'];
  147. if (file_exists($override_file)) {
  148. $override = false;
  149. if (($dir_xml = file_get_contents($override_file)) !== false) {
  150. $dir_settings = xml_to_array($dir_xml, 'settings');
  151. if (!empty($dir_settings[0])) {
  152. foreach($dir_settings[0] as $key => $val) {
  153. if (isset($zc[$key])) {
  154. $zc[$key] = $val;
  155. }
  156. }
  157. $override = true;
  158. }
  159. }
  160. if (!$override) {
  161. zina_set_message(zt('Cannot read override file.'), 'error');
  162. return zina_access_denied();
  163. }
  164. }
  165. }
  166. /*
  167. * MAIN
  168. *
  169. * Determines what zina does.
  170. */
  171. 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))) {
  172. # ADMIN FUNCTIONS
  173. if (!$zc['is_admin']) return zina_access_denied();
  174. #todo: needed?
  175. #header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
  176. #header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT');
  177. #header('Cache-Control: no-cache, must-revalidate, max-age=0');
  178. #header('Pragma: no-cache');
  179. switch($level) {
  180. Case 18 : # INSTALL OR UPDATE DB
  181. if ($zc['database'] && ($m == 'update' || $m == 'install')) {
  182. $file = $zc['zina_dir_abs'].'/'.$m.'.php';
  183. if ($zc['database'] && file_exists($file)) {
  184. require_once($file);
  185. if ($m == 'install') {
  186. $result = zina_install_database();
  187. } else {
  188. $result = zina_updates_execute();
  189. }
  190. if ($result) {
  191. if ($m == 'install') zvar_set('version', ZINA_VERSION);
  192. zina_set_message(zt('Database @m succeeded!',array('@m'=>$m)));
  193. } else {
  194. zina_set_message(zt('Database @m failed!', array('@m'=>$m)),'error');
  195. }
  196. } else {
  197. zina_set_message(zt('Cannot @m the database...either no database connection or the file does not exist.',array('@m'=>$m)), 'error');
  198. }
  199. zina_goto('', 'l=20');
  200. }
  201. return zina_not_found();
  202. break;
  203. Case 19 : # try to manually submit last.fm queue
  204. if ($zc['lastfm']) {
  205. require_once($zc['zina_dir_abs'].'/extras/scrobbler.class.php');
  206. @set_time_limit($zc['timeout']);
  207. $scrobbler = new scrobbler($zc['lastfm_username'],$zc['lastfm_password']);
  208. $scrobbler->handshake_socket_timeout = 2;
  209. $scrobbler->submit_socket_timeout = 30;
  210. $scrobbler->queued_tracks = zina_set_scrobbler_queue();
  211. if ($scrobbler->submit_tracks()) {
  212. zina_set_message(zt('Queued Last.fm tracks submitted successfully.'));
  213. zina_set_scrobbler_queue(array(), true);
  214. } else {
  215. zina_set_message(zt('Queued Last.fm tracks failed:').$scrobbler->error_msg,'warn');
  216. }
  217. zina_goto('', 'l=20');
  218. }
  219. break;
  220. Case 20 : # CFG
  221. return zina_page_main($path, 'config');
  222. break;
  223. Case 21 : # CFG POST
  224. if (zina_write_settings()) {
  225. zina_set_message(zt('Settings updated.'));
  226. } else {
  227. zina_set_message(zt('Your settings were not saved!'),'error');
  228. }
  229. zina_goto('', 'l=20');
  230. break;
  231. Case 26 : # regen
  232. require_once($zc['zina_dir_abs'].'/batch.php');
  233. @trigger_error('');
  234. $error = false;
  235. if ($m == 1) { # dir/files caches
  236. if ($zc['database']) {
  237. foreach(array('dirs','files_assoc') as $type) {
  238. $operations[] = array('zina_core_cache_batch', array($type, '', array('force'=>true)));
  239. }
  240. if ($zc['low']) {
  241. foreach(array('files_assoc') as $type) {
  242. $operations[] = array('zina_core_cache_batch', array($type, '', array('force'=>true, 'low'=>true)));
  243. }
  244. }
  245. $batch = array(
  246. 'title' => zt('Regenerating directory and file caches.'),
  247. 'finished_message' => zt('Caches generated successfully.'),
  248. 'operations' => $operations,
  249. );
  250. zbatch_set($batch);
  251. zbatch_process();
  252. } else {
  253. foreach(array('dirs','files_assoc') as $type) zina_core_cache($type, '', array('force'=>true));
  254. if ($zc['low']) {
  255. foreach(array('files_assoc') as $type) zina_core_cache($type, '', array('force'=>true,'low'=>true));
  256. }
  257. $message = zt('Cache generated successfully.');
  258. }
  259. } elseif ($m == 2) { # genre cache
  260. #todo: use db or cache but not both? for genres? for dirs/files?
  261. if ($zc['database']) {
  262. $operations = array();
  263. $operations[] = array('zina_core_cache_batch', array('genre', '', array('force'=>true)));
  264. $operations[] = array('zdb_genre_populate', array(time()));
  265. $batch = array(
  266. 'title' => zt('Regenerating genre caches.'),
  267. 'finished_message' => zt('Genre cache generated successfully.'),
  268. 'operations' => $operations,
  269. );
  270. zbatch_set($batch);
  271. zbatch_process();
  272. } else {
  273. $message = zt('Genre cache generated successfully.');
  274. zina_core_cache('genre', '', array('force'=>true));
  275. }
  276. } elseif ($m == 3 || $m == 4) { # populate missing
  277. #TODO: combine 3 & 4... combine 1,3&4?
  278. if ($zc['database']) {
  279. $runtime = time();
  280. $operations = array();
  281. foreach(array('dirs','files_assoc') as $type) {
  282. $operations[] = array('zina_core_cache_batch', array($type, '', array('force'=>true)));
  283. }
  284. if ($m == 3) {
  285. $regen = false;
  286. $title = zt('Populating database with missing entries.');
  287. $finished = zt('Database populated.');
  288. } else { # 4
  289. $regen = true;
  290. $title = zt('Synchronising database');
  291. $finished = zt('Synchronized database.');
  292. }
  293. $operations[] = array('zdb_populate_batch', array($regen));
  294. $operations[] = array('zdb_search_playlist_populate', array($runtime));
  295. $operations[] = array('zdb_genre_populate', array($runtime));
  296. $batch = array(
  297. 'title' => $title,
  298. 'finished_message' => $finished,
  299. 'finished' => 'zdb_populate_finished',
  300. 'operations' => $operations,
  301. );
  302. zbatch_set($batch);
  303. zbatch_process();
  304. }
  305. } elseif ($m == 5) { # image from id3 tags
  306. $operations[] = array('zbatch_extract_images', array());
  307. $batch = array(
  308. 'title' => zt('Extracting images from id3 tags.'),
  309. 'finished_message' => zt('Images extracted successfully.'),
  310. 'operations' => $operations,
  311. 'finished' => 'zbatch_extract_images_finished',
  312. );
  313. zbatch_set($batch);
  314. zbatch_process();
  315. } else {
  316. $error = true;
  317. zina_set_message(zt('Invalid option'), 'error');
  318. }
  319. $e = error_get_last();
  320. if ($error || ($e['type'] < 2048 && !empty($e['message']))) {
  321. #todo: ? zunserialize throws error on older custom_files...
  322. if (!empty($e['message'])) zina_set_message(zt('PHP returned an error[@type]: @message', array('@type'=>$e['type'], '@message'=>$e['message'])), 'error');
  323. } else {
  324. zina_set_message($message);
  325. }
  326. zina_goto('','l=20');
  327. break;
  328. Case 27 : # Find and Clean
  329. if ($zc['database']) {
  330. if ($_POST && !zina_token_sess_check()) return zina_page_main($path);
  331. if (!empty($_POST['zfileids'])) zdb_clean('file',$_POST['zfileids']);
  332. if (!empty($_POST['zdirids'])) zdb_clean('dir',$_POST['zdirids']);
  333. if ($_POST) {
  334. zina_set_message(zt('Database cleaned.'));
  335. zina_goto('', 'l=20');
  336. } else {
  337. return zina_page_main($path, 'clean');
  338. }
  339. }
  340. break;
  341. Case 33 : # DELETE SITEMAP
  342. $file = $zc['cache_dir_public_abs'].'/'.$zc['sitemap_file'];
  343. if (file_exists($file) && @unlink($file)) {
  344. zina_set_message(zt('Sitemap cached file deleted successfully'));
  345. } else {
  346. zina_set_message(zt('Sitemap cached file could not be deleted'),'warn');
  347. }
  348. zina_goto('', 'l=20');
  349. break;
  350. Case 30 :# DELETE TMPL CACHE
  351. Case 31 :# DELETE IMGS CACHE
  352. Case 34 :# DELETE ZIP CACHE
  353. $func = array(
  354. '30'=> array(
  355. 'dir' => $zc['cache_tmpl_dir'],
  356. 'text' => zt('Template cache files deleted.'),
  357. ),
  358. '31'=> array(
  359. 'dir' => $zc['cache_imgs_dir'],
  360. 'text' => zt('Images cache files deleted.'),
  361. ),
  362. '34'=> array(
  363. 'dir' => $zc['cache_zip_dir'],
  364. 'text' => zt('Compressed cache files deleted.'),
  365. ),
  366. );
  367. if (zina_delete_files($func[$level]['dir'])) {
  368. zina_set_message($func[$level]['text']);
  369. }
  370. zina_goto('', 'l=20');
  371. break;
  372. Case 32 : #get language phrases for translation
  373. $files = array('index.php', 'theme.php', 'database.php', 'lang-cfg.php');
  374. $source = '';
  375. foreach($files as $file) {
  376. $source .= file_get_contents($zc['zina_dir_abs'].'/'.$file);
  377. }
  378. if (preg_match_all("/zt\('(.*?)'(\)|,)/is", $source, $matches)) {
  379. $reduced = array_unique($matches[1]);
  380. $instr = array(
  381. zt('These are most of the translation strings currently in Zina.'),
  382. zt('Save this file to LANGCODE.php and modify it.'),
  383. zt('Format: \'english words\' => \'your translation\'')."\n *",
  384. zt('You do not have to do them all (just delete the lines you do not do).'),
  385. zt('If you are making a new translation or completing an older one, move the file to the "lang" directory.'),
  386. zt('If languages.txt file exists in your cache directory, delete it.'),
  387. zt('Or a copy in your theme folder will override the default language file.'),
  388. zt('English users can change wording/phrasings this way.')."\n *",
  389. zt('Test it out.')."\n *",
  390. zt('If you would like it to be included in Zina, please email it to: <@email>', array('@email'=>'ryanlath@pacbell.net')),
  391. );
  392. $text = '<?php'."\n".
  393. "/*\n * ".zt('Zina Translation Instructions')."\n *\n";
  394. foreach($instr as $i) {
  395. $text .= ' * '.$i."\n";
  396. }
  397. $lang = zina_get_languages();
  398. $language = (isset($lang[$zc['lang']])) ? $lang[$zc['lang']] : zt('Language');
  399. $text .= " */\n\n".'$language = "'.$language.'";'."\n\n";
  400. $text .= '$lang[\''.$zc['lang'].'\'] = array('."\n";
  401. foreach ($reduced as $en) {
  402. $text .= "\t'".$en."' => '";
  403. if ($zc['lang'] != 'en') {
  404. $trans = zt($en);
  405. if ($trans != $en) {
  406. $text .= $trans;
  407. }
  408. }
  409. $text .= "',\n";
  410. }
  411. $text .= ");\n?".">";
  412. while(@ob_end_clean());
  413. header('Content-type: text/plain');
  414. if (!$zc['debug']) header('Content-Disposition: attachment; filename="'.$zc['lang'].'.php"');
  415. echo $text;
  416. exit;
  417. } else {
  418. zina_set_message(zt('Nothing Found'),'error');
  419. zina_goto('', 'l=20');
  420. }
  421. break;
  422. Case 42 : # Add Custom Playlist Title
  423. if (!zina_token_sess_check()) return zina_page_main($path);
  424. zina_write_playlist($songs, str_replace('/',' - ',$path).'.m3u', 't');
  425. if ($zc['cache_tmpl']) {
  426. if (!zina_delete_tmpl_file(zina_get_tmpl_cache_file($path)))
  427. zina_debug(zt('Could not delete cache file'));
  428. }
  429. zina_goto($_SERVER['HTTP_REFERER']);
  430. break;
  431. Case 45 : # sync database to mp3 files...
  432. $files_assoc = zina_core_cache('files_assoc', $path);
  433. if (isset($files_assoc[$path])) {
  434. $files = $files_assoc[$path];
  435. foreach($files as $file) {
  436. zdb_log_stat('insertonly', $path, $file, null, true, true);
  437. }
  438. } else {
  439. zdb_log_stat('insertonly', $path, null, null, true, true);
  440. }
  441. zina_goto($path);
  442. break;
  443. Case 47 : # regen statistics
  444. if ($zc['database']) {
  445. zdb_stats_generate(time());
  446. zina_goto('', 'l=20');
  447. }
  448. break;
  449. Case 48 :
  450. if ($zc['genres'] && $zc['database']) {
  451. return zina_page_main($path, 'genre_hierarchy');
  452. }
  453. break;
  454. Case 49 :
  455. if ($zc['genres'] && $zc['database']) {
  456. if (!zina_token_sess_check()) return zina_page_main($path);
  457. zdb_genres_save($_POST);
  458. #todo: check for errors?
  459. zina_set_message(zt('Genre hierarchy saved.'));
  460. zina_goto('', 'l=48');
  461. }
  462. break;
  463. Case 52 :
  464. if ($zc['genres'] && $zc['database']) {
  465. if (zina_validate('int',$m)) {
  466. if (zdb_genre_delete($m)) zina_set_message(zt('Genre deleted.'));
  467. }
  468. zina_goto('', 'l=48');
  469. }
  470. break;
  471. Case 58 :
  472. return zina_page_main($path, 'edit_images');
  473. break;
  474. Case 59 : # ajax return images
  475. @session_write_close();
  476. if (!$zc['debug']) while(@ob_end_clean());
  477. echo zina_content_3rd_images($path, $m);
  478. exit;
  479. break;
  480. Case 60 : # Delete Image
  481. $file = $zc['mp3_dir'] .'/'.$path;
  482. $result = zt('Could not delete file.');
  483. if (preg_match('/\.('.$zc['ext_graphic'].')$/i', $path) && file_exists($file)) {
  484. if (@unlink($file)) {
  485. $result = zt('Deleted: @file', array('@file'=>$file));
  486. $other = zdb_get_others($path);
  487. if (isset($other['image']) && $other['image'] == basename($path)) {
  488. $image = zina_get_dir_item(dirname($path),'/\.('.$zc['ext_graphic'].')$/i');
  489. zdb_update_others(array('image'=>$image), dirname($path));
  490. }
  491. }
  492. }
  493. echo $result;
  494. exit;
  495. break;
  496. Case 61 : # Save Image
  497. $result = zt('Failed');
  498. if (is_writeable($zc['cur_dir'])) {
  499. if (($image = file_get_contents($imgsrc)) !== false) {
  500. $filename = $zc['cur_dir'].'/'.basename($imgsrc);
  501. $i=1;
  502. while (file_exists($filename)) {
  503. $filename = $zc['cur_dir'].'/copy'.$i.'_'.basename($imgsrc);
  504. }
  505. if (file_put_contents($filename, $image)) {
  506. $result = zt('Image Saved: @src -> @dest', array('@src'=> $imgsrc, '@dest' => $filename));
  507. if (isset($_SESSION['zina_missing'][$path])) unset($_SESSION['zina_missing'][$path]);
  508. }
  509. }
  510. }
  511. if (!$zc['debug']) while(@ob_end_clean());
  512. echo $result;
  513. exit;
  514. break;
  515. Case 62 : # Find album art
  516. $missing = zina_search_dirs_for_missing_images();
  517. if (!empty($missing)) {
  518. $_SESSION['zina_missing'] = $missing;
  519. zina_goto(current($missing),'l=58');
  520. } else {
  521. zina_set_message(zt('No missing artist/album artwork.'));
  522. unset($_SESSION['zina_missing']);
  523. zina_goto('', 'l=20');
  524. }
  525. exit;
  526. break;
  527. Case 63 : # Close Album Art
  528. unset($_SESSION['zina_missing']);
  529. zina_goto($path);
  530. break;
  531. Case 64 :
  532. return zina_page_main('', 'help');
  533. break;
  534. Case 67 : # import textfile playlists into database...
  535. #remove in 3.0 / make part of upgrade
  536. if ($zc['database']) {
  537. $playlists = zina_get_playlists_custom();
  538. if (empty($playlists)) {
  539. zina_set_message(zt('No playlists to convert'));
  540. zina_goto('', 'l=20');
  541. }
  542. foreach($playlists as $playlist) {
  543. $filename = $zc['cache_pls_dir'].'/_zina_'.$playlist.'.m3u';
  544. if (file_exists($filename)) {
  545. $pls_id = zdbq_single("SELECT id FROM {playlists} WHERE title = '%s' AND user_id = %d", array($playlist, $zc['user_id']));
  546. if (!empty($pls_id)) {
  547. zina_set_message(zt('Playlist already exists: @pls', array('@pls'=>$playlist)));
  548. continue;
  549. }
  550. $genre_id = null;
  551. $dir_id = zdbq_single("SELECT id FROM {dirs} WHERE path = '%s' AND level = 1", array($playlist));
  552. if ($dir_id) {
  553. $image_type = 1;
  554. } else {
  555. $dir_id = null;
  556. $image_type = 0;
  557. }
  558. $mtime = filemtime($filename);
  559. if (zdbq("INSERT {playlists} (title, user_id, dir_id, genre_id, image_type, date_created, mtime) VALUES ('%s', %d, %d, '%s', '%s', %d, %d)",
  560. array($playlist, $zc['user_id'], $dir_id, $genre_id, $image_type, $mtime, $mtime))) {
  561. $pls_id = zdbq_single("SELECT id FROM {playlists} WHERE title = '%s' AND user_id = %d", array($playlist, $zc['user_id']));
  562. if (!empty($pls_id)) {
  563. $songs = zunserialize_alt(file_get_contents($filename));
  564. zina_playlist_insert($pls_id, $songs, 1);
  565. }
  566. }
  567. } else {
  568. zina_set_message(zt('Cannot open playlist: @pls', array('@pls'=>$playlist)));
  569. }
  570. }
  571. zina_goto('', 'l=20');
  572. }
  573. break;
  574. Case 71 : # edit tags
  575. require_once($zc['zina_dir_abs'].'/extras/tag_editor.php');
  576. return zina_page_main($path, 'edittags');
  577. break;
  578. Case 72 : # tag search
  579. Case 73 : # tag search
  580. require_once($zc['zina_dir_abs'].'/extras/tag_editor.php');
  581. if ($level == 72) {
  582. if (($result = zina_extras_tags_freedb_matches(rawurldecode($playlist))) !== false) {
  583. echo $result;
  584. }
  585. } else {
  586. if (($result = zina_extras_tags_freedb_match($_GET['cat'], $_GET['discid'])) !== false) {
  587. echo $result;
  588. }
  589. }
  590. exit;
  591. break;
  592. Case 75 : # delete file
  593. if (($path = zina_delete_file($zc['cur_dir'])) !== false) {
  594. zina_set_message(zt('Deleted file: @file', array('@file'=>$zc['cur_dir'])));
  595. }
  596. zina_goto($path);
  597. break;
  598. Case 76 : # delete dir
  599. if (!zfile_check_location($zc['cur_dir'], $zc['mp3_dir']) || !is_dir($zc['cur_dir'])) {
  600. zina_set_message(zt('Directory does not exist: @dir', array('@dir'=>$zc['cur_dir'])));
  601. zina_goto('');
  602. }
  603. $dir = zina_get_directory($path);
  604. if (!empty($dir['subdirs'])) {
  605. zina_set_message(zt('Cannot delete directory. Directory has subdirectories.'));
  606. zina_goto($path);
  607. }
  608. if (!empty($dir['files'])) {
  609. foreach($dir['files'] as $file => $xxx) {
  610. if (zina_delete_file($zc['mp3_dir'].'/'.$file)) zina_set_message(zt('Deleted file: @file', array('@file'=>$file)));
  611. }
  612. }
  613. if (zina_delete_directory($zc['cur_dir'])) {
  614. if ($zc['database']) {
  615. $id = zdbq_single("SELECT id FROM {dirs} WHERE path = '%s'", array($path));
  616. if (!empty($id)) zdb_remove('dir', $id);
  617. }
  618. } else {
  619. zina_set_message(zt('Cannot delete directory: @dir', array('@dir'=>$path)), 'error');
  620. }
  621. if (($pos = strrpos($path, '/')) == 0) {
  622. $path = '';
  623. } else {
  624. $path = substr($path, 0, $pos);
  625. }
  626. zina_goto($path);
  627. break;
  628. Case 78 :
  629. if ($path != '') return zina_page_main($path, 'rename_directory');
  630. break;
  631. } # end admin switch
  632. return zina_not_found();
  633. }
  634. elseif (in_array($level, array(3,5,6,7,8,10,11,12,16,17,25,53,54,56,57,66,68,70,74))) {
  635. # STREAM FUNCTIONS
  636. switch ($level) {
  637. Case 3 :
  638. if ($zc['cmp_sel']) {
  639. zina_send_zip_selected($songs, (isset($_GET['lf'])));
  640. }
  641. break;
  642. Case 5 :
  643. if ($zc['cmp_sel']) {
  644. zina_send_zip_selected_dir($path, (isset($_GET['c'])), (isset($_GET['lf'])));
  645. }
  646. break;
  647. Case 6 : # Return resampled MP3
  648. if ($zc['resample']) {
  649. if ($zc['database'] && $zc['stats']) zdb_log_stat('play', dirname($path), basename($path));
  650. zina_send_file_music($path, true);
  651. }
  652. break;
  653. Case 7 : # return resized image
  654. $type = isset($_GET['it']) ? $_GET['it'] : null;
  655. if (in_array($type, array('sub','dir','full','search','genre','genresearch','pls','plssearch'))) {
  656. $cache_file = $string = false;
  657. $text = null;
  658. if (empty($imgsrc)) {
  659. if ($type == 'genresearch' || $type == 'plssearch') $type = 'search';
  660. $tmp = $zc['theme_path_abs'].'/images';
  661. $imgsrc = ztheme('missing_image',$type);
  662. $text = ztheme('title',basename($path));
  663. } else {
  664. $res_out_type = ($zc['res_out_type'] == 'jpeg') ? 'jpg' : $zc['res_out_type'];
  665. if ($type == 'genre' || $type == 'genresearch') {
  666. if ($type == 'genresearch') $type = 'search';
  667. $tmp = $zc['theme_path_abs'].'/images';
  668. $genre_file = ztheme('image_genre', $imgsrc);
  669. if (file_exists($tmp.'/'.$genre_file)) {
  670. $imgsrc = $genre_file;
  671. } else {
  672. $text = strtoupper($imgsrc);
  673. $imgsrc = ztheme('missing_image','genre');
  674. }
  675. $cache_file = $zc['cache_imgs_dir'].'/'.$type.md5($tmp.'/'.$genre_file).'.'.$res_out_type;
  676. } elseif ($type == 'pls' || $type == 'plssearch') {
  677. $tmp = $zc['theme_path_abs'].'/images';
  678. $text = strtoupper($imgsrc);
  679. $imgsrc = ztheme('missing_image','playlist');
  680. $type = ($type == 'pls') ? 'sub' : 'search';
  681. #$cache_file = $zc['cache_imgs_dir'].'/'.$type.md5($tmp.'/'.$genre_file).'.'.$res_out_type;
  682. } elseif ($imgsrc == 'zina_id3_zina.jpg') {
  683. $subdir_file = zina_get_dir_item($zc['mp3_dir'].'/'.$path,'/\.('.$zc['ext_mus'].')$/i');
  684. $tmp = $zc['mp3_dir'].'/'.$path;
  685. if (!empty($subdir_file)) {
  686. $info = zina_get_file_info($zc['mp3_dir'].'/'.$path.'/'.$subdir_file, false, true, false, true);
  687. if (isset($info->image)) {
  688. $string = $info->image;
  689. $cache_file = $zc['cache_imgs_dir'].'/'.$type.md5($zc['mp3_dir'].'/'.$path.'/'.$imgsrc).'.'.$res_out_type;
  690. }
  691. }
  692. }
  693. else {
  694. $tmp = $zc['mp3_dir'].'/'.$path;
  695. $cache_file = $zc['cache_imgs_dir'].'/'.$type.md5($zc['mp3_dir'].'/'.$path.'/'.$imgsrc).'.'.$res_out_type;
  696. }
  697. if ($zc['cache_imgs'] && $cache_file) {
  698. if (file_exists($cache_file)) {
  699. while(@ob_end_clean());
  700. Header('Content-type: image/'.$zc['res_out_type']);
  701. readfile($cache_file);
  702. exit;
  703. }
  704. }
  705. }
  706. $image_source = $tmp.'/'.$imgsrc;
  707. if (!file_exists($image_source) && !$string) {
  708. $image_source = $zc['theme_path_abs'].'/images/'.ztheme('missing_image',$type);
  709. $text = zt('Error');
  710. $cache_file = $string = false;
  711. }
  712. zina_send_image_resized($image_source, $type, $text, $cache_file, $string);
  713. }
  714. break;
  715. Case 11 : # return img
  716. if ($zc['stream_int'] && preg_match('/\.('.$zc['ext_graphic'].')$/i', $imgsrc)) {
  717. $file = $zc['mp3_dir'].'/'.((!empty($path)) ? $path.'/' : '').$imgsrc;
  718. if (file_exists($file)) {
  719. @ob_end_clean();
  720. readfile($file);
  721. }
  722. }
  723. break;
  724. Case 8 : # RETURN PLAYLISTS
  725. if ($zc['play']) {
  726. if (!isset($m)) $m = isset($_POST['m']) ? $_POST['m'] : null;
  727. $lofi = (isset($_GET['lf']));
  728. $cus = (isset($_GET['c']));
  729. $num = isset($_POST['n']) ? $_POST['n'] : (isset($_GET['n']) ? $_GET['n'] : null);
  730. if (!in_array($num, $zc['ran_opts'])) $num = $zc['ran_opts_def'];
  731. if ($playlist == null && isset($_GET['playlist'])) $playlist = $_GET['playlist'];
  732. $random = (isset($_GET['rand']));
  733. $store = (isset($_GET['store']));
  734. switch($m) {
  735. Case 0 :
  736. zina_send_playlist_title($path, $cus, $lofi);
  737. break;
  738. Case 1 :
  739. zina_send_playlist_song($path, $lofi);
  740. break;
  741. Case 3 :
  742. zina_send_playlist_custom($playlist, $lofi, $random);
  743. break;
  744. Case 4 : # Random Albums
  745. zina_send_playlist_random($num,'t',$lofi, true, null, $playlist);
  746. break;
  747. Case 5 : # Random Songs
  748. zina_send_playlist_random($num,'s',$lofi, true, null, $playlist);
  749. break;
  750. Case 6 : # Random Songs By Year
  751. zina_send_playlist_random($num,'s',$lofi, true, null, null, $playlist);
  752. break;
  753. Case 7 :
  754. zina_send_playlist_selected($songs, $lofi, $store);
  755. break;
  756. Case 8 :
  757. zina_send_playlist_selected_random($songs, $lofi, $store);
  758. break;
  759. Case 10 : # Play Recursively & Recursively Random ($cus = random)
  760. zina_send_playlist_random(0,'s',$lofi,$cus,$path);
  761. break;
  762. Case 11 : # Random Songs via Rated Songs
  763. zina_send_playlist_random($num,'tt',$lofi, true, null, $playlist);
  764. break;
  765. Case 12 : # Random Songs via Rated Artists
  766. zina_send_playlist_random($num,'artist',$lofi, true, null, $playlist);
  767. break;
  768. }
  769. }
  770. break;
  771. Case 10 : # internal streaming
  772. if ($zc['play']) {
  773. if ($zc['remote'] && preg_match('/\.('.$zc['remote_ext'].')$/i', $path)) {
  774. $rem = new remoteFile($zc['mp3_dir'].'/'.$path, false, true);
  775. if (isset($rem->url)) {
  776. if ($zc['database'] && $zc['stats']) zdb_log_stat('play', dirname($path), basename($path));
  777. while(@ob_end_clean());
  778. header('Location: '.$rem->url);
  779. exit;
  780. }
  781. }
  782. elseif ($zc['play'] && $zc['stream_int']) {
  783. if ($zc['database'] && $zc['stats']) zdb_log_stat('play', dirname($path), basename($path));
  784. zina_send_file_music($path);
  785. }
  786. }
  787. break;
  788. Case 12 : # download mp3
  789. if ($zc['download'] && preg_match('/\.('.$zc['ext_mus'].')$/i', $path, $exts)) {
  790. $file = $zc['mp3_dir'].'/'.$path;
  791. if (file_exists($file)) {
  792. if ($zc['database'] && $zc['stats']) zdb_log_stat('down', dirname($path), basename($path));
  793. if ($zc['stream_int']) {
  794. $filename = html_entity_decode(zina_get_file_artist_title($file, $zc['mp3_id3'])).'.'.$exts[1];
  795. zina_set_header('Content-Type: application/force-download');
  796. zina_set_header('Content-Disposition: inline; filename="'.$filename.'"');
  797. zina_set_header('Content-Length: '.filesize($file));
  798. zina_set_header('Cache-control: private'); #IE seems to need this.
  799. zina_send_file($file);
  800. }
  801. else {
  802. zina_goto($path,NULL,NULL,TRUE,TRUE);
  803. }
  804. }
  805. }
  806. break;
  807. Case 16 : # VOTE
  808. if ($zc['database']) {
  809. $num = isset($_POST['n']) ? $_POST['n'] : (isset($_GET['n']) ? $_GET['n'] : null);
  810. if (zina_validate('int',$num) && $num <= 5 && ($num >= 1 || ($zc['user_id'] > 0 && $num == 0))) {
  811. if (preg_match('/\.('.$zc['ext_mus'].')$/i', $path) || ($zc['remote'] && preg_match('/\.('.$zc['remote_ext'].')$/i', $path))) {
  812. if ($zc['rating_files']) zdb_log_stat('vote',dirname($path), basename($path), $num);
  813. $path = dirname($path);
  814. }
  815. else {
  816. if ($zc['rating_dirs']) zdb_log_stat('vote',$path, null, $num);
  817. }
  818. if ($zc['cache_tmpl']) {
  819. if (!zina_delete_tmpl_file(zina_get_tmpl_cache_file($path))) zina_debug(zt('Cannot delete cache file'));
  820. }
  821. #todo: return 'error' on bad result
  822. echo ($num == 0) ? zt('Deleted') : zt('Thank you');
  823. }
  824. }
  825. break;
  826. Case 68 : # Vote Playlists
  827. if ($zc['database'] && $zc['pls_ratings']) {
  828. $num = isset($_POST['n']) ? $_POST['n'] : (isset($_GET['n']) ? $_GET['n'] : null);
  829. if (zina_validate('int',$num) && $num <= 5 && ($num >= 1 || ($zc['user_id'] > 0 && $num == 0))) {
  830. zdb_log_stat_playlist((int)$playlist, 'votes', $num);
  831. #todo: return 'error' on bad result
  832. echo ($num == 0) ? zt('Deleted') : zt('Thank you');
  833. }
  834. }
  835. break;
  836. Case 25 : # download MM
  837. if ($zc['mm'] && $zc['mm_down'] && preg_match('/\.('.$zc['mm_ext'].')$/i', $path, $exts)) {
  838. $file = $zc['mp3_dir'].'/'.$path;
  839. if (file_exists($file)) {
  840. if ($zc['stream_int']) {
  841. $ext = strtolower($exts[1]);
  842. zina_set_header('Content-Type: '.$zc['mm_types'][$ext]['mime']);
  843. $disposition = (isset($zc['mm_types'][$ext]['disposition'])) ? $zc['mm_types'][$ext]['disposition'] : 'attachment';
  844. zina_set_header('Content-Disposition: '.$disposition.'; filename="'.basename($path).'"');
  845. zina_set_header('Content-Length: '.filesize($file));
  846. zina_set_header('Cache-control: private'); #IE seems to need this.
  847. zina_send_file($file);
  848. }
  849. else {
  850. zina_goto($path,NULL,NULL,TRUE,TRUE);
  851. }
  852. }
  853. }
  854. break;
  855. Case 53 : # LIVE SEARCH RETURN
  856. $search_term = (isset($_GET['zinaq'])) ? $_GET['zinaq'] : '';
  857. if (strlen($search_term) >= $zc['search_min_chars']) {
  858. $num = isset($_GET['limit']) ? $_GET['limit'] : $zc['search_live_limit'];
  859. $num = (zina_validate('int', $num) && $num > 0 && $num < $zc['search_live_limit']) ? $num : $zc['search_live_limit'];
  860. if ($zc['db_search']) {
  861. $results = zdbq_array("SELECT i.title, i.type, i.context, i.id, i.path, i.genre ".
  862. ",if(i.type='playlist', p.image_type, FALSE) as image_type ".
  863. ",if(i.type='playlist', pd.path, FALSE) as image_path ".
  864. "FROM {search_index} AS i ".
  865. "LEFT OUTER JOIN {playlists} AS p ON (i.type = 'playlist' AND i.type_id = p.id) ".
  866. "LEFT OUTER JOIN {dirs} AS pd ON (i.type = 'playlist' AND i.type_id = p.id AND p.dir_id = pd.id) ".
  867. "WHERE i.title LIKE '%%%s%%' ".
  868. "ORDER BY i.title LIMIT %d",
  869. array($search_term, $num));
  870. }
  871. else {
  872. $results = zina_search_cache($search_term, $num);
  873. }
  874. if (!empty($results)) {
  875. if ($zc['search_images']) {
  876. foreach ($results as $key => $item) {
  877. $results[$key]['image'] = zina_content_search_image($item, 'search');
  878. }
  879. }
  880. foreach ($results as $item) {
  881. unset($item['image_type']);
  882. unset($item['image_path']);
  883. $item['type'] = zt(ucfirst($item['type']));
  884. echo implode('|', $item)."\n";
  885. }
  886. }
  887. }
  888. exit;
  889. break;
  890. Case 54 : # XML file info for flash app
  891. if ($zc['zinamp']) {
  892. $output = zina_get_file_xml($path);
  893. while(@ob_end_clean());
  894. header('Content-type: application/xml');
  895. echo $output;
  896. }
  897. break;
  898. Case 56 :
  899. if ($zc['zinamp'] && $zc['lastfm'] && isset($_GET['n'])) {
  900. zina_play_complete($path, intval($_GET['n']));
  901. }
  902. break;
  903. Case 57 : # 3rd party lyrics
  904. if ($zc['song_extras'] && in_array($m, $zc['song_es_exts'])) {
  905. @session_write_close();
  906. if ($zc['zinamp'] && $playlist == 'zinamp') {
  907. $content = zina_content_blurb($zina, $path, array('type'=>$m, 'return'=>true));
  908. if (isset($content['output']) && !empty($content['output'])) {
  909. if (!$zc['debug']) @ob_end_clean();
  910. echo nl2br($content['output']);
  911. exit;
  912. }
  913. }
  914. if (isset($zc['third_'.$m]) && $zc['third_'.$m]) {
  915. $info = array();
  916. zina_get_file_artist_title($zc['mp3_dir'].'/'.$path, true, $info);
  917. $lyr_opts = zina_get_extras_opts($m);
  918. $opts = explode(',', $zc['third_lyr_order']);
  919. $output = '';
  920. if (!empty($info['artist']) && !empty($info['title'])) {
  921. foreach($opts as $source) {
  922. if (!in_array($source, $lyr_opts)) continue;
  923. require_once($zc['zina_dir_abs'].'/extras/extras_'.$m.'_'.$source.'.php');
  924. $result = array();
  925. if (($result = call_user_func('zina_extras_'.$m.'_'.$source, $info['artist'], $info['title'])) !== false) {
  926. $output .= $result['output'];
  927. if ($zc['third_'.$m.'_save']) {
  928. zina_save_blurb($path, $m, $output, null, false);
  929. }
  930. $output = nl2br($output);
  931. if (isset($result['source'])) {
  932. $output .= ztheme('extras_source', $result['source']);
  933. }
  934. break;
  935. }
  936. }
  937. }
  938. if (empty($output)) {
  939. $output .= zt('No @type found.', array('@type'=>$zc['song_es'][$m]['name']));
  940. }
  941. if (!$zc['debug']) {
  942. while(@ob_end_clean());
  943. }
  944. echo $output;
  945. }
  946. }
  947. break;
  948. Case 66 :
  949. if ($zc['zinamp'] && $zc['lastfm']) {
  950. zina_zinamp_start($path);
  951. }
  952. break;
  953. Case 70 :
  954. if ($zc['playlists'] && $zc['database'] && zina_validate('int',$playlist)) {
  955. zina_playlist_feed($playlist);
  956. }
  957. break;
  958. Case 74:
  959. if (isset($_SESSION['zina_store'])) {
  960. $store = $_SESSION['zina_store'];
  961. unset($_SESSION['zina_store']);
  962. if (!empty($store)) {
  963. zina_send_playlist_content($store['type'], $store['content']);
  964. }
  965. }
  966. break;
  967. }
  968. exit;
  969. }
  970. else {
  971. # PAGE DISPLAYS (2,4,9,13,14,15,22,23,24,29,40,41,43,44,50,51,55,69,77,99,100,101,102)
  972. switch ($level) {
  973. Case 2 :
  974. if ($zc['playlists']) {
  975. return zina_page_main($path, 'playlists', array('pl'=>$playlist, 'id'=>$m));
  976. }
  977. break;
  978. Case 4 : # SEARCH
  979. if ($zc['search']) {
  980. return zina_page_main($path, 'search', array('m'=>$m));
  981. }
  982. break;
  983. Case 9 : # LOGIN
  984. if ($zc['login']) {
  985. if (isset($_POST['un']) && isset($_POST['up'])) {
  986. if (zina_check_password($_POST['un'], $_POST['up'])) {
  987. $_SESSION['za-'.ZINA_VERSION] = true;
  988. if ($zc['session']) { // standalone only
  989. $sess_id = zina_token_sess('1');
  990. setcookie('ZINA_SESSION', $sess_id, time() + (60*60*$zc['session_lifetime']), '/');
  991. $sess_file = $zc['cache_dir_private_abs'].'/sess_'.$sess_id;
  992. @touch($sess_file);
  993. }
  994. zina_goto($path);
  995. }
  996. else {
  997. sleep(3);
  998. $_SESSION['za-'.ZINA_VERSION] = false;
  999. zina_set_message(zt('Username and/or password are incorrect.'),'warn');
  1000. }
  1001. }
  1002. return zina_page_main($path, 'login');
  1003. }
  1004. break;
  1005. Case 13 : # Genre Listing
  1006. if ($zc['genres']) {
  1007. return zina_page_main($path, 'searchgenre');
  1008. }
  1009. break;
  1010. Case 14 : # Genres
  1011. if ($zc['genres']) {
  1012. return zina_page_main($path, 'genres');
  1013. }
  1014. break;
  1015. Case 15 : # STATS
  1016. if ($zc['database'] && $zc['stats'] && ($zc['stats_public'] || $zc['is_admin'])) {
  1017. $period = isset($_POST['period']) ? $_POST['period'] : null;
  1018. $type = isset($_POST['type']) ? $_POST['type'] : null;
  1019. return zina_page_main($path, 'stats', array('stat'=>$playlist, 'period'=>$period, 'type'=>$type));
  1020. }
  1021. break;
  1022. Case 22 : # VARIOUS EDIT WINDOWS
  1023. if ($zc['is_admin'] || (zina_cms_access('editor') && (in_array($m, array(1,2,3,4,6)) || in_array($m, $zc['song_es_exts'])))) {
  1024. return zina_page_main($path, 'blurb', array('type'=>$m, 'item'=>$playlist));
  1025. }
  1026. else {
  1027. return zina_access_denied();
  1028. }
  1029. break;
  1030. Case 23 : # VARIOUS EDIT WINDOWS SAVE
  1031. if (!zina_token_sess_check()) {
  1032. return zina_page_main($path);
  1033. }
  1034. if ($zc['is_admin'] || (zina_cms_access('editor') && (in_array($m, array(1,2,3,4,6)) || in_array($m, $zc['song_es_exts'])))) {
  1035. zina_save_blurb($path, $m, $songs, $playlist);
  1036. }
  1037. else {
  1038. return zina_access_denied();
  1039. }
  1040. break;
  1041. Case 77 :
  1042. if ($zc['is_admin'] || (zina_cms_access('editor'))) {
  1043. if (isset($_POST) && !empty($_POST) && !zina_token_sess_check()) {
  1044. return zina_access_denied();
  1045. }
  1046. return zina_page_main($path, 'dir_opts');
  1047. }
  1048. else {
  1049. return zina_access_denied();
  1050. }
  1051. break;
  1052. Case 24 : # PLAY MM
  1053. if ($zc['mm']) {
  1054. return zina_page_main($path, 'mm');
  1055. }
  1056. break;
  1057. Case 29 :# Song Extras
  1058. if ($zc['song_extras'] && in_array($m, $zc['song_es_exts'])) {
  1059. return zina_page_main($path, 'songextras', array('type'=>$m, 'item'=>null));
  1060. }
  1061. break;
  1062. Case 40 : # Add New Playlist && Add To Playlist
  1063. if (!zina_token_sess_check()) {
  1064. return zina_page_main($path);
  1065. }
  1066. if ($zc['database']) {
  1067. $access = zina_cms_access('edit_playlists', $zc['user_id']);
  1068. if (!($access || ($zc['session_pls'] && $playlist == 'zina_session_playlist'))) {
  1069. zina_set_message(zt('Not authorized'));
  1070. return zina_page_main($path);
  1071. }
  1072. if ($access && $playlist == 'new_zina_list') {
  1073. if (!$zc['is_admin']) {
  1074. $count = zdbq_single("SELECT COUNT(*) FROM {playlists} WHERE user_id = %d", array($zc['user_id']));
  1075. if ($count > $zc['pls_limit']) {
  1076. zina_set_message(zt('Cannot create playlist.').' '.zt('Maximum number of playlists reached.'));
  1077. return zina_page_main($path);
  1078. }
  1079. }
  1080. return zina_page_main($path, 'newplaylist',array('songs'=>$songs));
  1081. }
  1082. else {
  1083. if (isset($_POST['fromnew'])) {
  1084. if (($pls_id = zina_playlist_form_submit('insert')) !== false) {
  1085. $playlist = $pls_id;
  1086. $start = 1;
  1087. }
  1088. else {
  1089. $start = false;
  1090. }
  1091. }
  1092. else {
  1093. if ($playlist == 'zina_session_playlist') {
  1094. $existing = (isset($_SESSION['z_sp'])) ? unserialize_utf8($_SESSION['z_sp']) : array();
  1095. $start = count($existing);
  1096. }
  1097. else {
  1098. $start = zdbq_single("SELECT MAX(weight) FROM {playlists_map} WHERE playlist_id = %d", array($playlist, $zc['user_id']));
  1099. }
  1100. }
  1101. if ($start !== false) {
  1102. if (zina_playlist_insert($playlist, $songs, $start+1)) {
  1103. zina_set_message(zt('Added to playlist'));
  1104. }
  1105. else {
  1106. zina_set_message(zt('Could not add to playlist'), 'warn');
  1107. }
  1108. }
  1109. if (isset($_POST['fromnew'])) {
  1110. if (empty($path)) {
  1111. zina_goto('','l=2&pl='.rawurlencode($playlist));
  1112. }
  1113. else {
  1114. return zina_page_main($path);
  1115. }
  1116. }
  1117. else {
  1118. echo ztheme('messages');
  1119. exit;
  1120. }
  1121. }
  1122. }
  1123. elseif ($zc['is_admin'] || $zc['session_pls']) {
  1124. if (!$zc['is_admin']) {
  1125. $playlist = 'zina_session_playlist';
  1126. }
  1127. if ($playlist == 'new_zina_list') {
  1128. return zina_page_main($path, 'newplaylist',array('songs'=>$songs));
  1129. }
  1130. else {
  1131. zina_write_playlist($songs, '_zina_'.$playlist.'.m3u', 'a');
  1132. zina_set_message(zt('Added to playlist'));
  1133. if (isset($_POST['fromnew'])) {
  1134. if (empty($path)) {
  1135. zina_goto('','l=2&pl='.rawurlencode($playlist));
  1136. }
  1137. else {
  1138. return zina_page_main($path);
  1139. }
  1140. }
  1141. else {
  1142. echo ztheme('messages');
  1143. exit;
  1144. }
  1145. }
  1146. }
  1147. break;
  1148. Case 41 : # Update Playlist
  1149. if (!zina_token_sess_check()) {
  1150. return zina_page_main($path);
  1151. }
  1152. $order = isset($_POST['order']) ? $_POST['order'] : null;
  1153. if ($zc['database']) {
  1154. $pls_user_id = zdbq_single("SELECT user_id FROM {playlists} WHERE id = %d", array($playlist));
  1155. $access = zina_cms_access('edit_playlists', $pls_user_id);
  1156. if (!($access || ($zc['session_pls'] && $playlist == 'zina_session_playlist'))) {
  1157. zina_set_message(zt('Not authorized'));
  1158. return zina_page_main($path);
  1159. }
  1160. $songs = zina_reorder_playlist($songs, $order);
  1161. if ($playlist == 'zina_session_playlist') {
  1162. $_SESSION['z_sp'] = utf8_encode(serialize($songs));
  1163. }
  1164. else {
  1165. zdbq("DELETE FROM {playlists_map} WHERE playlist_id = %d", array($playlist));
  1166. foreach($songs as $weight => $type_id) {
  1167. if (preg_match('/\.lp$/i', $type_id)) {
  1168. $type = 'album';
  1169. $type_id = preg_replace('/\/\.lp$/i','',$type_id);
  1170. }
  1171. elseif (preg_match('/\.pls$/i', $type_id)) {
  1172. $type = 'playlist';
  1173. $type_id = preg_replace('/\.pls/i','',$type_id);
  1174. }
  1175. else {
  1176. $type = 'song';
  1177. }
  1178. if (!zdbq("INSERT {playlists_map} (playlist_id, type, type_id, weight) VALUES (%d, '%s', %d, %d)",
  1179. array($playlist, $type, $type_id, $weight+1))) {
  1180. zina_set_message(zt('Could not insert into playlist: @file', array('@file'=>$type_id)));
  1181. }
  1182. }
  1183. if (($sum_items = zdbq_single("SELECT COUNT(*) FROM {playlists_map} WHERE playlist_id = %d", array($playlist))) !== false) {
  1184. zdbq("UPDATE {playlists} SET sum_items = %d WHERE id = $playlist", array($sum_items, $playlist));
  1185. }
  1186. }
  1187. return zina_page_main($path, 'playlists',array('pl'=>$playlist));
  1188. }
  1189. elseif ($zc['is_admin'] || $zc['session_pls']) {
  1190. if (!$zc['is_admin']) {
  1191. $playlist = 'zina_session_playlist';
  1192. }
  1193. zina_write_playlist(zina_reorder_playlist($songs, $order), '_zina_'.$playlist.'.m3u');
  1194. return zina_page_main($path, 'playlists',array('pl'=>$playlist));
  1195. }
  1196. break;
  1197. Case 43 : # DELETE CUSTOM PLAYLIST
  1198. if ($zc['database'] && $playlist != 'zina_session_playlist') {
  1199. if ($zc['is_admin'] || $zc['pls_user']) {
  1200. if ($zc['is_admin']) {
  1201. $access = true;
  1202. }
  1203. else {
  1204. $access = zdbq_single("SELECT 1 FROM {playlists} WHERE id = %d AND user_id = %d", array($playlist, $zc['user_id']));
  1205. }
  1206. if ($access) {
  1207. zdbq("DELETE FROM {playlists_map} WHERE playlist_id = %d", array($playlist));
  1208. zdbq("DELETE FROM {playlists} WHERE id = %d", array($playlist));
  1209. zina_set_message(zt('Playlist deleted'));
  1210. zina_goto('','l=2');
  1211. }
  1212. }
  1213. }
  1214. else {
  1215. if ($zc['is_admin'] || $zc['session_pls']) {
  1216. if (!$zc['is_admin']) $playlist = 'zina_session_playlist';
  1217. zina_delete_playlist_custom($playlist);
  1218. zina_goto('','l=2');
  1219. }
  1220. }
  1221. break;
  1222. Case 44 : # EDIT PLAYLIST
  1223. if ($_POST && !zina_token_sess_check()) {
  1224. return zina_page_main($path);
  1225. }
  1226. if (!($zc['playlists'] && ($zc['is_admin'] || ($zc['pls_user'] && $zc['user_id'] > 0)))) {
  1227. return zina_access_denied();
  1228. }
  1229. $playlist_new = isset($_POST['playlist_new']) ? $_POST['playlist_new'] : '';
  1230. return zina_page_main($path, 'renameplaylist', array('playlist'=>$playlist, 'new'=>$playlist_new));
  1231. break;
  1232. case 46 :
  1233. if ($zc['res_full_img'] && preg_match('/\.('.$zc['ext_graphic'].')$/i', $path)) {
  1234. return zina_page_main($path, 'image');
  1235. }
  1236. break;
  1237. Case 50 : #podcast
  1238. if ($zc['rss']) {
  1239. #TODO: make common output function...
  1240. while(@ob_end_clean());
  1241. header('Content-type: application/xml');
  1242. echo zina_content_rss($path);
  1243. exit;
  1244. }
  1245. break;
  1246. Case 51 : # SITEMAP
  1247. if ($zc['sitemap']) {
  1248. $output = zina_cache('sitemap', 'zina_content_sitemap', null, ($zc['sitemap'] == 2));
  1249. while(@ob_end_clean());
  1250. header('Content-type: text/xml');
  1251. echo $output;
  1252. exit;
  1253. }
  1254. break;
  1255. Case 99 : # logout
  1256. session_unregister('za-'.ZINA_VERSION);
  1257. if ($zc['session']) {
  1258. if (isset($_COOKIE['ZINA_SESSION'])) {
  1259. $sess_file = $zc['cache_dir_private_abs'].'/sess_'.zcheck_plain($_COOKIE['ZINA_SESSION']);
  1260. setcookie('ZINA_SESSION', $_COOKIE['ZINA_SESSION'], time() - 42000, '/');
  1261. if (file_exists($sess_file)) {
  1262. @unlink($sess_file);
  1263. }
  1264. }
  1265. # remove expired sessions
  1266. $old_sessions = glob($zc['cache_dir_private_abs']."/sess_*");
  1267. if (is_array($old_sessions)) {
  1268. foreach ($old_sessions as $filename) {
  1269. if (filemtime($filename) + (60*60*$zc['session_lifetime']) < time()) {
  1270. @unlink($filename);
  1271. }
  1272. }
  1273. }
  1274. }
  1275. zina_set_message(zt('Logged out succesfully.'));
  1276. zina_goto($path);
  1277. break;
  1278. case 55 :
  1279. #todo: move to stream?
  1280. if ($zc['zinamp'] == 2) {
  1281. $content = ztheme('zinamp');
  1282. zina_set_js('inline',
  1283. 'window.onunload = function() {'.
  1284. 'zina_cookie("zinamp_window", "screenX="+window.screenX+",screenY="+window.screenY, {expires:7});'.
  1285. '};');
  1286. $zina = zina_page_simple('zinamp', $content);
  1287. echo ztheme('page_zinamp', $zina);
  1288. exit;
  1289. }
  1290. break;
  1291. case 100 :
  1292. if ($zc['zinamp']==3) {
  1293. $content = ztheme('jplayer');
  1294. zina_set_js('inline',
  1295. 'window.onunload = function() {'.
  1296. 'zina_cookie("jplayer_window", "screenX="+window.screenX+",screenY="+window.screenY, {expires:7});'.
  1297. '};');
  1298. $zina = zina_page_simple('jplayer', $content);
  1299. echo ztheme('page_jplayer', $zina);
  1300. exit;
  1301. }
  1302. break;
  1303. case 101 : # Start Scrobble
  1304. if ($zc['zinamp']==3) {
  1305. zina_add_now_playing($path);
  1306. }
  1307. break;
  1308. case 102 : # Complete Scrobble
  1309. if ($zc['zinamp']==3) {
  1310. zina_complete_scrobble($path);
  1311. }
  1312. break;
  1313. Case 65 :
  1314. require_once($zc['zina_dir_abs'].'/batch.php');
  1315. $output = _zbatch_page();
  1316. if ($output === FALSE) {
  1317. return zina_access_denied();
  1318. }
  1319. elseif (isset($output)) {
  1320. zina_set_css('file', 'extras/progress.css');
  1321. return zina_page_simple(zbatch_set_title(), $output);
  1322. }
  1323. return;
  1324. Case 69 : # Year Listing
  1325. if ($zc['db_search']) {
  1326. return zina_page_main($path, 'searchyear');
  1327. }
  1328. break;
  1329. default : # MAIN PAGE
  1330. # Allows files to stream without l=8 (for RSS and prettiness)
  1331. if (is_file($zc['cur_dir']) && $zc['play'] && (($zc['stream_int'] && preg_match('/\.('.$zc['ext_mus'].')$/i', $path)) ||
  1332. ($zc['remote'] && preg_match('/\.('.$zc['remote_ext'].')$/i', $path, $matches)))) {
  1333. if ($zc['database'] && $zc['stats']) zdb_log_stat('play', dirname($path), basename($path));
  1334. zina_send_file_music($path);
  1335. }
  1336. if (is_file($zc['cur_dir']) && $zc['rss'] && basename($path) == $zc['rss_file']) {
  1337. $output = file_get_contents($zc['cur_dir']);
  1338. $outpu

Large files files are truncated, but you can click here to view the full file