PageRenderTime 39ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/frontend/display.php

https://github.com/jinzora/jinzora3
PHP | 3219 lines | 2052 code | 366 blank | 801 comment | 517 complexity | 11d4534f2cc9625a3be12f4edcf97bb6 MD5 | raw file
  1. <?php if (!defined(JZ_SECURE_ACCESS)) die ('Security breach detected.');
  2. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3. * JINZORA | Web-based Media Streamer
  4. *
  5. * Jinzora is a Web-based media streamer, primarily desgined to stream MP3s
  6. * (but can be used for any media file that can stream from HTTP).
  7. * Jinzora can be integrated into a CMS site, run as a standalone application,
  8. * or integrated into any PHP website. It is released under the GNU GPL.
  9. *
  10. * Jinzora Author:
  11. * Ross Carlson: ross@jasbone.com
  12. * http://www.jinzora.org
  13. * Documentation: http://www.jinzora.org/docs
  14. * Support: http://www.jinzora.org/forum
  15. * Downloads: http://www.jinzora.org/downloads
  16. * License: GNU GPL <http://www.gnu.org/copyleft/gpl.html>
  17. *
  18. * Contributors:
  19. * Please see http://www.jinzora.org/modules.php?op=modload&name=jz_whois&file=index
  20. *
  21. * Code Purpose: This page contains all the album display related functions
  22. * Created: 9.24.03 by Ross Carlson
  23. *
  24. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  25. /**
  26. * Pulls the correct PHP code for a given block.
  27. * Attempts to use the given frontend,
  28. * but falls back to code in frontend/blocks.
  29. *
  30. * The usual call is: include(jzBlock("name"));
  31. * We do this because doing the include inside this function
  32. * can mess with variables required by the block code.
  33. *
  34. * @author Ben Dodson
  35. * @ since 8/21/2006
  36. */
  37. function jzBlock($block) {
  38. global $fe;
  39. if (false !== strstr($block,'..') ||
  40. false !== strstr($block,'/') ||
  41. false !== strstr($block,'\\')) {
  42. die("Security breach detected (jzBlock)");
  43. }
  44. if (file_exists($file = dirname(__FILE__).'/frontends/'.$fe->name.'/blocks/'.$block.'.php')) {
  45. return $file;
  46. } else {
  47. return dirname(__FILE__).'/blocks/'.$block.'.php';
  48. }
  49. }
  50. function jzTemplate($smarty, $template) {
  51. global $fe;
  52. if (false !== strstr($template,'..') ||
  53. false !== strstr($template,'/') ||
  54. false !== strstr($template,'\\')) {
  55. die("Security breach detected (jzTemplate)");
  56. }
  57. if (file_exists($file = dirname(__FILE__).'/frontends/'.$fe->name.'/templates/'.$template.'.tpl')) {
  58. $smarty->display($file);
  59. }
  60. else if (file_exists($file = SMARTY_ROOT. 'templates/'.$fe->name.'/'. $template. '.tpl')) {
  61. $smarty->display($file);
  62. } else {
  63. $smarty->display(SMARTY_ROOT. 'templates/blocks/'. $template. '.tpl');
  64. }
  65. }
  66. /**
  67. * Handles the code for a popup function. Similar to
  68. * the block-handling function.
  69. *
  70. * @author Ben Dodson
  71. * @ since 8/21/2006
  72. */
  73. function jzPopup($block) {
  74. global $include_path;
  75. if (false !== strstr($block,'..') ||
  76. false !== strstr($block,'/') ||
  77. false !== strstr($block,'\\')) {
  78. die("Security breach detected (jzBlock)");
  79. }
  80. return $include_path.'popups/'.$block.'.php';
  81. }
  82. class jzDisplay {
  83. /**
  84. * Constructor for the class.
  85. *
  86. * @author Ben Dodson
  87. * @version 10/27/04
  88. * @since 10/27/04
  89. */
  90. function jzDisplay() {
  91. }
  92. function startCache($func, $params, $age = false){
  93. if (func_num_args() > 2) {
  94. $moreargs = func_get_args();
  95. $moreags = array_slice($moreargs,2);
  96. } else {
  97. $moreargs = false;
  98. }
  99. return $this->_internalCacheFunc(true,$func,$params,$moreargs,$age);
  100. }
  101. function endCache(){
  102. return $this->_internalCacheFunc(false);
  103. }
  104. // This function is internal to the cache functions.
  105. // We use this so we can create a static variable across both functions.
  106. function _internalCacheFunc($start, $func = false, $params = false, $moreargs = false, $age = false) {
  107. global $cache_age_days,$gzip_page_cache,$enable_page_caching;
  108. static $signature_stack = array();
  109. if ($enable_page_caching == "false") {
  110. return false;
  111. }
  112. if ($start) {
  113. // START THE CACHE
  114. $cacheFile = $this->createCachedPageName($func,$params,$moreargs);
  115. // Did they specify an age?
  116. if ($age && is_numeric($age)){
  117. $cache_age_days = $age;
  118. }
  119. if (is_file($cacheFile) and (time() - filemtime($cacheFile)) < ($cache_age_days * 86400)){
  120. if ($gzip_page_cache == "true"){
  121. $fp = gzopen($cacheFile,'r');
  122. gzpassthru($fp);
  123. } else {
  124. include_once($cacheFile);
  125. }
  126. return true;
  127. } else {
  128. if (is_object($params)){
  129. writeLogData("messages","Cache: Building cache for: ". $params->getName(). " type: ". $func);
  130. }
  131. ob_start();
  132. array_push($signature_stack,$cacheFile);
  133. }
  134. } else {
  135. // END THE CACHE
  136. $cacheFile = array_pop($signature_stack);
  137. if ($gzip_page_cache == "true"){
  138. $fp = gzopen($cacheFile, 'w');
  139. gzwrite($fp, ob_get_contents());
  140. gzclose($fp);
  141. } else {
  142. $fp = fopen($cacheFile, 'w');
  143. fwrite($fp, ob_get_contents());
  144. fclose($fp);
  145. }
  146. ob_end_flush();
  147. }
  148. }
  149. function createCachedPageName($func,$params,$moreargs){
  150. global $web_root, $root_dir, $jzUSER, $security_key, $skin, $my_frontend, $enable_page_caching;
  151. if ($enable_page_caching == "false") {
  152. return false;
  153. }
  154. $signature = $skin . $my_frontend . $security_key . $func . serialize($params);
  155. if ($moreargs !== false) {
  156. for ($i = 0; $i < sizeof($moreargs); $i++) {
  157. $signature .= $moreargs[$i];
  158. }
  159. }
  160. $name="";
  161. if (is_object($params)){
  162. $name = ".". md5($params->getName());
  163. }
  164. // Let's create the page
  165. $pName = $web_root. $root_dir. "/temp/cache/". md5($signature . "-". $jzUSER->getID()). $name. ".html";
  166. // Now do we need to kill this file?
  167. if ($_SESSION['jz_purge_file_cache'] == "true"){
  168. @unlink($pName);
  169. }
  170. return $pName;
  171. }
  172. function purgeCachedPage($node){
  173. global $web_root, $root_dir, $jzUSER,$include_path;
  174. $name="";
  175. if (is_object($node)){
  176. $name = md5($node->getName());
  177. }
  178. if (0 == strlen($name)) {
  179. return;
  180. }
  181. $d = @dir($include_path . "temp/cache");
  182. if ($d !== false) {
  183. while (false !== ($entry = $d->read())) {
  184. if (stristr($entry,$name)){
  185. @unlink($include_path."temp/cache/". $entry);
  186. }
  187. }
  188. }
  189. }
  190. /*
  191. * Displays the shopping purchase button using the shopping service
  192. *
  193. * @author Ross Carlson
  194. * @since 12.02.05
  195. * @version 12.02.05
  196. * @param $node The node we are looking at
  197. **/
  198. function purchaseButton($node){
  199. global $enable_shopping, $jzSERVICES;
  200. // Is shopping enabled?
  201. if ($enable_shopping <> "true"){
  202. return;
  203. }
  204. // Let's create the shopping service
  205. echo $jzSERVICES->createShoppingLink($node);
  206. }
  207. /*
  208. * Displays a button to allow the user to add this item to their favorites
  209. *
  210. * @author Ross Carlson
  211. * @since 12.17.05
  212. * @version 12.17.05
  213. * @param $node The node they are adding
  214. **/
  215. function addToFavButton($node, $return = false){
  216. global $img_add_fav, $enable_favorites;
  217. if ($enable_favorites <> "true"){return;}
  218. $arr = array();
  219. $arr['action'] = "popup";
  220. $arr['ptype'] = "addtofavorites";
  221. $arr['jz_path'] = $node->getPath("String");
  222. $retVal = '<a onClick="openPopup(' . "'". urlize($arr) ."'" . ',350,150); return false;" href="javascript:;">';
  223. $retVal .= $img_add_fav;
  224. $retVal .= "</a>";
  225. if ($return){
  226. return $retVal;
  227. } else {
  228. echo $retVal;
  229. }
  230. }
  231. /*
  232. * Displays the media mangement dropdown
  233. *
  234. * @author Ross Carlson
  235. * @since 4.16.05
  236. * @version 4.16.05
  237. * @param $array An array of the names of the tabs
  238. **/
  239. function displayTabs($array){
  240. ?>
  241. <style>
  242. .tab{
  243. border: thin solid <?php echo jz_fg_color; ?>;
  244. position: absolute;
  245. top: 40;
  246. width: 140;
  247. text-align: center;
  248. color: <?php echo jz_font_color; ?>;
  249. font-weight: bold;
  250. padding: 3;
  251. cursor: pointer;
  252. cursor: hand;
  253. }
  254. .panel{
  255. position: absolute;
  256. top: 70;
  257. width: 95%;
  258. z-index: 1;
  259. visibility: hidden;
  260. overflow: auto;
  261. }
  262. </style>
  263. <script language="JavaScript">
  264. var currentPanel;
  265. function showPanel(panelNum) {
  266. //hide visible panel, show selected panel,
  267. //set tab
  268. if (currentPanel != null) {
  269. hidePanel();
  270. }
  271. document.getElementById('panel'+panelNum).style.visibility = 'visible';
  272. currentPanel = panelNum;
  273. setState(panelNum);
  274. }
  275. function hidePanel() {
  276. //hide visible panel, unhilite tab
  277. document.getElementById('panel'+currentPanel).style.visibility = 'hidden';
  278. document.getElementById('tab'+currentPanel).style.backgroundColor = '<?php echo jz_pg_bg_color; ?>';
  279. document.getElementById('tab'+currentPanel).style.color = '<?php echo jz_font_color; ?>';
  280. }
  281. function setState(tabNum) {
  282. if (tabNum==currentPanel) {
  283. document.getElementById('tab'+tabNum).style.backgroundColor = '<?php echo jz_fg_color; ?>';
  284. document.getElementById('tab'+tabNum).style.color = '<?php echo jz_font_color; ?>';
  285. } else {
  286. document.getElementById('tab'+tabNum).style.backgroundColor = '<?php echo jz_pg_bg_color; ?>';
  287. document.getElementById('tab'+tabNum).style.color = '<?php echo jz_font_color; ?>';
  288. }
  289. }
  290. function hover(tab) {
  291. tab.style.backgroundColor = '<?php echo jz_fg_color; ?>';
  292. }
  293. </script>
  294. <?php
  295. $i=1;
  296. $c=5;
  297. foreach ($array as $item){
  298. echo '<div id="tab'. $i. '" class="tab" style="left: '. $c. ';" onClick="showPanel('. $i. ');" onMouseOver="hover(this);" onMouseOut="setState('. $i. ')">'. $item. '</div>';
  299. $c=$c+147;
  300. $i++;
  301. }
  302. }
  303. /*
  304. * Displays the media mangement dropdown
  305. *
  306. * @author Ross Carlson
  307. * @since 4.16.05
  308. * @version 4.16.05
  309. * @param $node The node we are looking at
  310. **/
  311. function systemToolsDropdown($node){
  312. global $this_page;
  313. if (!is_object($node)) {
  314. $node = new jzMediaNode();
  315. }
  316. ?>
  317. <form action="<?php echo $this_page; ?>" method="GET" name="toolsform">
  318. <select class="jz_select" name="action" style="width:125px" onChange="openPopup(this.form.action.options[this.selectedIndex].value, 450, 450, false, 'SystemTools')">
  319. <?php
  320. // Now let's setup the values
  321. $url_array = array();
  322. $url_array['jz_path'] = $node->getPath("String");
  323. $url_array['action'] = "popup";
  324. ?>
  325. <option value="">System Tools</option>
  326. <option value="<?php $url_array['ptype'] = "mediamanager"; echo urlize($url_array); ?>"><?php echo word("Media Manager"); ?></option>
  327. <option value="<?php $url_array['ptype'] = "usermanager"; echo urlize($url_array); ?>"><?php echo word("User Manager"); ?></option>
  328. <option value="<?php $url_array['ptype'] = "sitesettings"; echo urlize($url_array); ?>"><?php echo word("Settings Manager"); ?></option>
  329. <option value="<?php $url_array['ptype'] = "sitenews"; echo urlize($url_array); ?>"><?php echo word("Manage Site News"); ?></option>
  330. <option value="<?php $url_array['ptype'] = "nodestats"; unset($url_array['jz_path']); echo urlize($url_array); ?>"><?php echo word("Show Full Site Stats"); ?></option>
  331. <option value="<?php $url_array['ptype'] = "dupfinder"; echo urlize($url_array); ?>"><?php echo word("Duplicate Finder"); ?></option>
  332. </select>
  333. </form>
  334. <?php
  335. }
  336. /*
  337. * Displays the media mangement dropdown
  338. *
  339. * @author Ross Carlson
  340. * @since 4.16.05
  341. * @version 4.16.05
  342. * @param $node The node we are looking at
  343. **/
  344. function mediaManagementDropdown($node){
  345. global $jzUSER, $allow_filesystem_modify, $resize_images, $enable_podcast_subscribe, $root_dir;
  346. ?>
  347. <form action="<?php echo $root_dir. "/popup.php"; ?>" method="GET" name="mediamanform">
  348. <select class="jz_select" name="action" style="width:125px" onChange="openPopup(this.form.action.options[this.selectedIndex].value, 400, 400, false, 'MediaManagement')">
  349. <?php
  350. // Now let's setup the values
  351. $url_array = array();
  352. $url_array['jz_path'] = $node->getPath("String");
  353. $url_array['action'] = "popup";
  354. ?>
  355. <option value=""><?php echo word("Media Management"); ?></option>
  356. <option value="<?php $url_array['ptype'] = "scanformedia"; echo urlize($url_array); ?>"><?php echo word("Rescan Media"); ?></option>
  357. <?php
  358. // Can they add media?
  359. if (checkPermission($jzUSER,"upload",$node->getPath("String")) and $allow_filesystem_modify == "true") {
  360. ?>
  361. <option value="<?php $url_array['ptype'] = "uploadmedia"; echo urlize($url_array); ?>"><?php echo word("Add Media"); ?></option>
  362. <?php
  363. }
  364. ?>
  365. <?php
  366. if ($node->getPType() == "album"){
  367. ?>
  368. <option value="<?php $url_array['ptype'] = "bulkedit"; echo urlize($url_array); ?>"><?php echo word("Bulk Edit"); ?></option>
  369. <?php
  370. }
  371. ?>
  372. <option value="<?php $url_array['ptype'] = "addlinktrack"; echo urlize($url_array); ?>"><?php echo word("Add Link Track"); ?></option>
  373. <?php
  374. if ($enable_podcast_subscribe == "true"){
  375. ?>
  376. <option value="<?php $url_array['ptype'] = "addpodcast"; echo urlize($url_array); ?>"><?php echo word("Podcast Manager"); ?></option>
  377. <?php
  378. }
  379. ?>
  380. <option value="<?php $url_array['ptype'] = "setptype"; echo urlize($url_array); ?>"><?php echo word("Set Page Type"); ?></option>
  381. <option value="<?php $url_array['ptype'] = "searchlyrics"; echo urlize($url_array); ?>"><?php echo word("Retrieve Lyrics"); ?></option>
  382. <option value="<?php $url_array['ptype'] = "getmetadata"; echo urlize($url_array); ?>"><?php echo word("Retrieve Meta Data"); ?></option>
  383. <?php
  384. if ($node->getPType() == "album"){
  385. ?>
  386. <option value="<?php $url_array['ptype'] = "getalbumart"; echo urlize($url_array); ?>"><?php echo word("Search for Album Art"); ?></option>
  387. <?php
  388. }
  389. ?>
  390. <?php
  391. if ($resize_images == "true"){
  392. ?>
  393. <option value="<?php $url_array['ptype'] = "resizeart"; echo urlize($url_array); ?>"><?php echo word("Resize All Art"); ?></option>
  394. <?php
  395. }
  396. ?>
  397. <option value="<?php $url_array['ptype'] = "autorenumber"; echo urlize($url_array); ?>"><?php echo word("Auto Renumber"); ?></option>
  398. <?php
  399. if (($jzUSER->getSetting('admin') === true || $jzUSER->getSetting('home_admin') == true)
  400. and ($node->getPType() == "artist" or $node->getPType() == "album")) {
  401. ?>
  402. <option value="<?php $url_array['ptype'] = "iteminfo"; echo urlize($url_array); ?>"><?php echo word("Item Information"); ?></option>
  403. <?php
  404. }
  405. ?>
  406. <option value="<?php $url_array['ptype'] = "retagger"; echo urlize($url_array); ?>"><?php echo word("Retag Tracks"); ?></option>
  407. <?php
  408. if ($node->getPType() == "artist" or $node->getPType() == "album"){
  409. // Ok, is it already featured?
  410. if (!$node->isFeatured()){
  411. $url_array['ptype'] = "addfeatured";
  412. echo '<option value="'. urlize($url_array). '">'. word("Add to Featured"). '</option>';
  413. } else {
  414. $url_array['ptype'] = "removefeatured";
  415. echo '<option value="'. urlize($url_array). '">'. word("Remove from Featured"). '</option>';
  416. }
  417. }
  418. ?>
  419. <?php
  420. $url_array['ptype'] = "artfromtags";
  421. echo '<option value="'. urlize($url_array). '">'. word("Pull art from Tag Data"). '</option>';
  422. ?>
  423. <?php
  424. if ($node->getPType() == "album"){
  425. ?>
  426. <option value="<?php $url_array['ptype'] = "pdfcover"; echo urlize($url_array); ?>"><?php echo word("Create PDF Cover"); ?></option>
  427. <!--<option value="<?php $url_array['ptype'] = "burncd"; echo urlize($url_array); ?>"><?php echo word("Burn CD"); ?></option>-->
  428. <?php
  429. }
  430. ?>
  431. </select>
  432. </form>
  433. <?php
  434. }
  435. /*
  436. * Displays the browse dropdown boxes
  437. *
  438. * @author Ross Carlson
  439. * @since 4.16.05
  440. * @version 4.16.05
  441. **/
  442. function displayBrowseDropdown(){
  443. global $this_page, $hierarchy;
  444. $lvls = @implode("|",$hierarchy);
  445. ?>
  446. <form action="<?php echo $this_page; ?>" method="GET">
  447. <?php
  448. $this->hiddenPageVars();
  449. ?>
  450. <select class="jz_select" name="action" style="width:125px" onChange="openPopup(this.form.action.options[this.selectedIndex].value, 250, 400, false, 'MediaManagement')">
  451. <?php
  452. // Now let's setup the values
  453. $url_array = array();
  454. $url_array['action'] = "popup";
  455. ?>
  456. <option value=""><?php echo word("Browse"); ?></option>
  457. <?php
  458. if (stristr($lvls,"genre")){
  459. echo '<option value="';
  460. $url_array['ptype'] = "genre";
  461. echo urlize($url_array). '">'. word("All Genres"). ' ('. number_format($_SESSION['jz_num_genres']). ')</option>'. "\n";
  462. }
  463. if (stristr($lvls,"artist")){
  464. echo '<option value="';
  465. $url_array['ptype'] = "artist";
  466. echo urlize($url_array). '">'. word("All Artists"). ' ('. number_format($_SESSION['jz_num_artists']). ')</option>'. "\n";
  467. }
  468. if (stristr($lvls,"album")){
  469. echo '<option value="';
  470. $url_array['ptype'] = "album";
  471. echo urlize($url_array). '">'. word("All Albums"). ' ('. number_format($_SESSION['jz_num_albums']). ')</option>'. "\n";
  472. }
  473. echo '<option value="';
  474. $url_array['ptype'] = "track";
  475. echo urlize($url_array). '">'. word("All Tracks"). ' ('. number_format($_SESSION['jz_num_tracks']). ')</option>'. "\n";
  476. ?>
  477. </select>
  478. </form>
  479. <?php
  480. }
  481. /*
  482. * Returns the HTML code for a fancy Overlib tooltip
  483. *
  484. * @author Ross Carlson
  485. * @since 4.05.05
  486. * @version 4.05.05
  487. * @param $path The path in the filesystem or the URL to the image
  488. **/
  489. function returnToolTip($body, $title){
  490. $overCode = "'". $body. "', CAPTION, '<nobr>". $title. "</nobr>', DELAY, 300, HAUTO, VAUTO, CAPCOLOR, '". jz_font_color. "', BORDER, 2, BGCOLOR, '". jz_pg_bg_color. "', TEXTCOLOR, '". jz_font_color. "', FGCOLOR, '". jz_fg_color. "'";
  491. return ' onmouseover="return overlib('. $overCode. ');" onmouseout="return nd();"';
  492. }
  493. /*
  494. * Returns the text for the deminesions of an image
  495. *
  496. * @author Ross Carlson
  497. * @since 3.18.05
  498. * @version 3.18.05
  499. * @param $path The path in the filesystem or the URL to the image
  500. **/
  501. function returnImageDimensions($path){
  502. $image = @imagecreatefromjpeg($path);
  503. if ($image){
  504. return imagesx($image). "x". imagesy($image);
  505. } else {
  506. return false;
  507. }
  508. }
  509. /*
  510. * Displays the discussion icon
  511. *
  512. * @author Ross Carlson
  513. * @since 3.18.05
  514. * @version 3.18.05
  515. * @param $node The item (node) we are viewing
  516. **/
  517. function displayDiscussIcon($node){
  518. global $img_discuss, $img_discuss_dis;
  519. $item = new jzMediaElement($node->getPath('String'));
  520. $arr = array();
  521. $arr['action'] = "popup";
  522. $arr['ptype'] = "discussitem";
  523. $arr['jz_path'] = $item->getPath("String");
  524. echo '<a onClick="openPopup(' . "'". urlize($arr) ."'" . ',450,300); return false;" href="javascript:;">';
  525. if ($item->getDiscussion() == ""){
  526. echo $img_discuss_dis;
  527. } else {
  528. echo $img_discuss;
  529. }
  530. echo "</a>";
  531. }
  532. /*
  533. * Displays the previous artists/album this user has browsed
  534. *
  535. * @author Ben Dodson
  536. * @since 2/2/05
  537. * @version 2/2/05
  538. * @param $node The node we are viewing
  539. * @param $type The type of drop down to return, Artist or Album
  540. **/
  541. function displayPrevDropdown($node, $type){
  542. global $jzUSER, $this_page, $cms_mode;
  543. // Let's start the form
  544. echo '<form action="'. $this_page. '" method="GET">'. "\n";
  545. $this->hiddenPageVars();
  546. echo '<select style="width:125px" class="jz_select" name="'. jz_encode('jz_path'). '" onChange="form.submit();">';
  547. if ($type == "artist"){
  548. echo '<option value="">'. word("Previous Artists"). '</option>';
  549. }
  550. if ($type == "album"){
  551. echo '<option value="">'. word("Previous Albums"). '</option>';
  552. }
  553. // Now let's load the users history
  554. $oldHist = $jzUSER->loadData('history');
  555. // Now let's parse that our
  556. $hArr = explode("\n",$oldHist);
  557. $allArtists = "";
  558. for ($i=0; $i < count($hArr); $i++){
  559. // Now let's break that out
  560. $dArr = explode("|",$hArr[$i]);
  561. if ($dArr[0] == $type and !stristr($allArtists,"|". $dArr[1]) and ($node->getName() <> $dArr[1])){
  562. // Now let's display the option
  563. echo '<option value="'. jz_encode($dArr[2]). '">'. $dArr[1]. '</option>';
  564. $allArtists .= "|". $dArr[1];
  565. }
  566. }
  567. echo '</select>';
  568. echo '</form>';
  569. }
  570. /* Starts a settings table.
  571. *
  572. * @author Ben Dodson
  573. * @since 2/2/05
  574. * @version 2/2/05
  575. *
  576. **/
  577. function openSettingsTable($action) {
  578. echo '<table>';
  579. echo '<form action="'.$action.'" method="POST">'."\n";
  580. }
  581. /* Closes a settings table.
  582. *
  583. * @author Ben Dodson
  584. * @since 2/2/05
  585. * @version 2/2/05
  586. * @param writeable: if the file isn't writeable, don't show the update button.
  587. **/
  588. function closeSettingsTable($writeable = true) {
  589. echo '<tr><td colspan="2">';
  590. echo '<table align="center"><tr width="50%"><td>';
  591. if ($writeable) {
  592. echo '<input type="submit" class="jz_submit" name="update_postsettings" value="Update">';
  593. } else {
  594. echo "&nbsp;";
  595. }
  596. echo '</td><td width="50%">';
  597. //echo '<input type="submit" value="Close" name="close" onClick="window.close();opener.location.reload(true);" class="jz_submit">';
  598. echo "&nbsp;";
  599. echo '</td></tr></table></tr>';
  600. echo '</form></table>'."\n";
  601. }
  602. /**
  603. * Completely handles a field for a setting.
  604. * This function will display a checkbox.
  605. * for a certain variable.
  606. * It also updates the $settings_file variable to modify the setting.
  607. *
  608. * @author Ben Dodson
  609. * @version 3/10/05
  610. * @since 3/10/05
  611. **/
  612. function settingsCheckbox($label, $varname, &$settings_array, $show_complete = true) {
  613. // See if the array needs to be updated (from a form submit)
  614. $fieldname = "edit_" . $varname;
  615. if (isset($_POST[$fieldname])) {
  616. $settings_array[$varname] = "true";
  617. if ($show_complete === false) {
  618. return;
  619. }
  620. } else if (isset($_POST['update_postsettings'])) {
  621. // Form was submitted and the box was unchecked; it's false.
  622. $settings_array[$varname] = "false";
  623. if ($show_complete === false) {
  624. return;
  625. }
  626. }
  627. echo '<tr><td align="right" valign="top" width="30%">'."\n";
  628. echo $label . '&nbsp;';
  629. echo '</td><td align="left" width="70%">';
  630. echo '<input type="checkbox" name="'.$fieldname.'" class="jz_checkbox"';
  631. if (isset($settings_array[$varname]) &&
  632. ($settings_array[$varname] === true || $settings_array[$varname] == "true")) {
  633. echo ' checked';
  634. }
  635. echo '>';
  636. echo "</td></tr>\n";
  637. }
  638. /**
  639. * Completely handles a field for a setting.
  640. * This function will display a form field
  641. * for a certain variable.
  642. * It also updates the $settings_file variable to modify the setting.
  643. *
  644. * @author Ben Dodson
  645. * @version 2/2/05
  646. * @since 2/2/05
  647. **/
  648. function settingsTextbox($label, $varname, &$settings_array, $show_complete = true) {
  649. // See if the array needs to be updated (from a form submit)
  650. $fieldname = "edit_" . $varname;
  651. if (isset($_POST[$fieldname])) {
  652. $settings_array[$varname] = $_POST[$fieldname];
  653. if ($show_complete === false) {
  654. return;
  655. }
  656. }
  657. echo '<tr><td align="right" valign="top" width="30%">'."\n";
  658. echo $label . '&nbsp;';
  659. echo '</td><td align="left" width="70%">';
  660. echo '<input name="'.$fieldname.'" class="jz_input"';
  661. if (isset($settings_array[$varname])) {
  662. echo ' value="' . htmlentities($settings_array[$varname]) . '"';
  663. }
  664. echo '>';
  665. echo "</td></tr>\n";
  666. }
  667. /**
  668. * Completely handles a field for a setting.
  669. * This function will display a dropdown
  670. * for a certain variable with given options.
  671. * The options are in an array, IE array(field1, field2)
  672. * It also updates the $settings_file variable to modify the setting.
  673. *
  674. * @author Ben Dodson
  675. * @version 2/2/05
  676. * @since 2/2/05
  677. **/
  678. function settingsDropdown($label, $varname, $options, &$settings_array, $show_complete = true) {
  679. // See if the array needs to be updated (from a form submit)
  680. $fieldname = "edit_" . $varname;
  681. if (isset($_POST[$fieldname])) {
  682. $settings_array[$varname] = $_POST[$fieldname];
  683. if ($show_complete === false) {
  684. return;
  685. }
  686. }
  687. echo '<tr><td align="right" valign="top" width="30%">'."\n";
  688. echo $label . '&nbsp;';
  689. echo '</td><td align="left" width="70%">';
  690. echo '<select name="'.$fieldname.'" class="jz_input">';
  691. foreach ($options as $type) {
  692. echo '<option value="'.htmlentities($type).'"';
  693. if ($settings_array[$varname] == $type) {
  694. echo " selected";
  695. }
  696. echo '>' . $type . '</option>';
  697. }
  698. echo '</select>';
  699. echo "</td></tr>\n";
  700. }
  701. /**
  702. * Completely handles a field for a setting.
  703. * This function will display a dropdown
  704. * for a certain variable with given options.
  705. * The options are the contents of directory $dir
  706. * $type is either "dir" or "file"
  707. *
  708. * @author Ben Dodson
  709. * @version 2/2/05
  710. * @since 2/2/05
  711. **/
  712. function settingsDropdownDirectory($label, $varname, $directory, $type = "dir", &$settings_array, $show_complete = true) {
  713. // See if the array needs to be updated (from a form submit)
  714. $fieldname = "edit_" . $varname;
  715. if (isset($_POST[$fieldname])) {
  716. $settings_array[$varname] = $_POST[$fieldname];
  717. if ($show_complete === false) {
  718. return;
  719. }
  720. }
  721. echo '<tr><td align="right" valign="top" width="30%">'."\n";
  722. echo $label . '&nbsp;';
  723. echo '</td><td align="left" width="70%">';
  724. echo '<select name="'.$fieldname.'" class="jz_input">';
  725. $entries = readDirInfo($directory,$type);
  726. foreach ($entries as $entry) {
  727. if ($entry == "CVS") {
  728. continue;
  729. }
  730. if ($type == "file") {
  731. $entry = str_replace(".php","",$entry);
  732. }
  733. echo '<option value="'.htmlentities($entry).'"';
  734. if ($settings_array[$varname] == $entry) {
  735. echo " selected";
  736. }
  737. echo '>';
  738. echo $entry;
  739. echo '</option>';
  740. }
  741. echo '</select>';
  742. echo "</td></tr>\n";
  743. }
  744. /**
  745. * Ugly PHP Scripty way to get a link
  746. * for a jukebox action. Returns an open
  747. * tag that performs a jukebox action
  748. * (play/pause/etc.).
  749. *
  750. * @author Ben Dodson
  751. * @since 1/7/08
  752. **/
  753. function getOpenJukeboxActionTag($type) {
  754. if (defined('NO_AJAX_JUKEBOX')) {
  755. $arr = array();
  756. $arr['action'] = "jukebox";
  757. $arr['subaction'] = "jukebox-command";
  758. $arr['command'] = $type;
  759. $arr['ptype'] = "jukebox";
  760. $arr['jz_path'] = isset($_GET['jz_path']) ? $_GET['jz_path'] : '';
  761. if (isset($_GET['frame'])){
  762. $arr['frame'] = $_GET['frame'];
  763. }
  764. return '<a href="'. urlize($arr). '"';
  765. } else {
  766. // AJAX:
  767. return '<a href="javascript:;" onClick="sendJukeboxRequest(\''.$type.'\'); return false;"';
  768. }
  769. }
  770. /**
  771. * Displays the Jukebox play button
  772. *
  773. *
  774. * @author Ross Carlson
  775. * @version 2/9/05
  776. * @since 2/9/05
  777. * @param $node the Node we are looking at
  778. * @param $type The type of button to display
  779. */
  780. function displayJukeboxButton($type){
  781. global $img_jb_play, $img_jb_pause, $img_jb_stop,
  782. $img_jb_previous, $img_jb_next, $img_jb_random_play,
  783. $img_jb_clear,$img_jb_repeat,$img_jb_no_repeat;
  784. $image = 'img_jb_'.$type;
  785. $aTag = $this->getOpenJukeboxActionTag($type);
  786. echo $aTag . '>'.$$image.'</a>';
  787. }
  788. /*
  789. * Checks to see if the resample dropdown should be shown.
  790. * Also sets the variables required for resampling.
  791. *
  792. * @author Ben Dodson
  793. * @since 8/16/2006
  794. */
  795. function wantResampleDropdown($node) {
  796. global $allow_resample, $resampleRates, $this_page, $jzUSER, $no_resample_subnets;
  797. if ($allow_resample <> "true"){return false;}
  798. if (!checkPermission($jzUSER,'stream',$node->getPath("String"))) {
  799. return false;
  800. }
  801. if (checkPlayback() == "jukebox") {
  802. return false;
  803. }
  804. if (isset($no_resample_subnets) && $no_resample_subnets <> "" && preg_match("/^${no_resample_subnets}$/", $_SERVER['REMOTE_ADDR'])) {
  805. return false;
  806. }
  807. // Now let's see if they set the resample rate
  808. if (isset($_POST['jz_resample'])){
  809. // Ok, its set so let's set the session var for it
  810. $_SESSION['jz_resample_rate'] = $_POST['jz_resample'];
  811. }
  812. if (isset($_SESSION['jz_resample_rate'])){
  813. if ($_SESSION['jz_resample_rate'] == ""){
  814. unset($_SESSION['jz_resample_rate']);
  815. }
  816. }
  817. if ($jzUSER->getSetting('resample_lock')){
  818. $_SESSION['jz_resample_rate'] = $jzUSER->getSetting('resample_rate');
  819. return false;
  820. }
  821. return true;
  822. }
  823. /**
  824. * Displays the resample dropdown box and related code
  825. *
  826. *
  827. * @author Ross Carlson
  828. * @version 11/21/04
  829. * @since 11/21/04
  830. * @param $node The node that we are getting the rating for
  831. */
  832. function displayResampleDropdown($node, $title = true, $return = false){
  833. global $allow_resample, $resampleRates, $this_page, $jzUSER,$fe;
  834. // First let's see if we should not show this
  835. if (!$this->wantResampleDropdown($node)) {
  836. return;
  837. }
  838. if ($return) {
  839. ob_start();
  840. }
  841. $smarty = smartySetup();
  842. if ($title !== false){
  843. if ($title === true) {
  844. $title = "";
  845. $title .= '<font style="font-size:11px">';
  846. $title .= word("Resample Rate:");
  847. $title .= '</font><br>';
  848. }
  849. }
  850. $smarty->assign('title',$title);
  851. $arr = array();
  852. $arr['jz_path'] = $_GET['jz_path'];
  853. if (defined('NO_AJAX')) {
  854. $smarty->assign('onchange','form.submit()');
  855. } else {
  856. $smarty->assign('onchange',"return setResample(document.getElementById('resamplerate').value);");
  857. }
  858. $smarty->assign('form_action',urlize($arr));
  859. if (isset($_SESSION['jz_resample_rate'])){
  860. $smarty->assign('cur_rate',$_SESSION['jz_resample_rate']);
  861. } else {
  862. $smarty->assign('cur_rate','');
  863. }
  864. $smarty->assign('resample_rates',explode("|",$resampleRates));
  865. jzTemplate($smarty, 'block-resample');
  866. if ($return) {
  867. $var = ob_get_contents();
  868. ob_end_clean();
  869. return $var;
  870. }
  871. }
  872. /**
  873. * The dropdown for the interface selector
  874. *
  875. * @author Ben Dodson
  876. * @version 3/17/05
  877. * @since 3/17/05
  878. *
  879. **/
  880. function interfaceDropdown() {
  881. global $this_page,$include_path;
  882. ?>
  883. <form action=<?php echo $_SERVER['PHP_SELF'] ?> method="GET" name="interface">
  884. <?php
  885. $this->hiddenVariableField("jz_path");
  886. //$this->hiddenVariableField("theme");
  887. $this->hiddenPageVars();
  888. ?>
  889. <select class="jz_select" name="<?php echo jz_encode("set_frontend"); ?>" style="width:125px" onChange="submit();" >
  890. <option value=""><?php echo word('Interface') ?></option>
  891. <?php
  892. // Now let's get all the possibles
  893. $retArray = readDirInfo($include_path. "frontend/frontends","dir");
  894. sort($retArray);
  895. for ($c=0; $c < count($retArray); $c++){
  896. $entry = $retArray[$c];
  897. // Let's make sure this isn't the local directory we're looking at
  898. if ($entry == "." || $entry == ".." || $entry == "CVS" || $entry == "jukezora") { continue;}
  899. echo '<option value="'. jz_encode(str_replace(".php","",$entry)). '">'. str_replace(".php","",$entry). '</option>'. "\n";
  900. }
  901. ?>
  902. </select>
  903. </form>
  904. <?php
  905. }
  906. /**
  907. * The dropdown for the language selector.
  908. *
  909. * @author Ben Dodson
  910. * @since 3/17/05
  911. * @version 3/17/05
  912. *
  913. **/
  914. function languageDropdown() {
  915. global $web_root,$root_dir,$this_page;
  916. ?>
  917. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET" name="language">
  918. <?php
  919. $this->hiddenVariableField("jz_path");
  920. $this->hiddenPageVars();
  921. // Now let's get all the possibles
  922. $languages = getLanguageList();
  923. ?>
  924. <select class="jz_select" name="<?php echo jz_encode("set_language"); ?>" style="width:125px" onChange="submit()">
  925. <option value="">Language</option>
  926. <?php
  927. foreach ($languages as $language) {
  928. echo '<option value="'. jz_encode(str_replace(".php","",$language)). '">'. str_replace(".php","",$language). '</option>'. "\n";
  929. }
  930. ?>
  931. </select>
  932. </form>
  933. <?php
  934. }
  935. /**
  936. * The dropdown for the style selector.
  937. *
  938. * @author Ben Dodson
  939. * @since 3/17/05
  940. * @version 3/17/05
  941. *
  942. **/
  943. function styleDropdown() {
  944. global $this_page,$include_path, $cms_mode;
  945. // Not in CMS mode...
  946. if ($cms_mode == "true"){
  947. return;
  948. }
  949. ?>
  950. <form action="<?php echo $this_page; ?>" method="GET" name="style">
  951. <?php
  952. $this->hiddenVariableField('jz_path');
  953. $this->hiddenPageVars();
  954. $this->hiddenVariableField('frontend');
  955. ?>
  956. <select class="jz_select" name="<?php echo jz_encode("set_theme"); ?>" style="width:125px" onChange="submit()">
  957. <option value=""><?php echo word("Style"); ?></option>
  958. <?php
  959. // Now let's get all the possibles
  960. $retArray = readDirInfo($include_path. "style","dir");
  961. sort($retArray);
  962. for ($c=0; $c < count($retArray); $c++){
  963. $entry = $retArray[$c];
  964. // Let's make sure this isn't the local directory we're looking at
  965. if ($entry == "." || $entry == "..") { continue;}
  966. if (!stristr($entry,"images") and !stristr($entry,"cms-theme") and !stristr($entry,"CVS")){
  967. echo '<option value="'. jz_encode(str_replace(".php","",$entry)). '">'. str_replace(".php","",$entry). '</option>'. "\n";
  968. }
  969. }
  970. ?>
  971. </select>
  972. </form>
  973. <?php
  974. return;
  975. ?>
  976. <script>
  977. function setActiveStyleSheet(title) {
  978. var i, a, main;
  979. for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  980. if(a.getAttribute("rel").indexOf("style") != -1
  981. && a.getAttribute("title")) {
  982. a.disabled = true;
  983. if(a.getAttribute("title") == title) a.disabled = false;
  984. }
  985. }
  986. }
  987. function selectStyle (vCookieName, vSelection) {
  988. //WRITE COOKIE
  989. //makeCookie(vCookieName, vSelection, 90, '/');
  990. //ACTIVE SELECTED ALTERNAT STYLE SHEET
  991. setActiveStyleSheet(vSelection)
  992. }
  993. if (document.cookie.indexOf('layout=')!=-1) {
  994. css = readCookie('layout');
  995. //ACTIVATE SELECTED STYLE SHEET
  996. setActiveStyleSheet(css)
  997. }
  998. </script>
  999. <select class="jz_select" onchange="var v=this.options[this.selectedIndex].value; if (v != '') selectStyle('style', v);" style="width:125px" >
  1000. <option value=""><?php echo word("Style"); ?></option>
  1001. <?php
  1002. $styles = readDirInfo($include_path. "style", "dir");
  1003. foreach ($styles as $style){
  1004. echo '<option value="'. $style. '">'. ucwords($style). '</option>';
  1005. }
  1006. ?>
  1007. </select>
  1008. <?php
  1009. }
  1010. /**
  1011. * Displays the button to allow for an item to be rated
  1012. *
  1013. *
  1014. * @author Ross Carlson
  1015. * @version 11/20/04
  1016. * @since 11/20/04
  1017. * @param $node The node that we are getting the rating for
  1018. * @param $return Should we return the code or echo (default to echo)
  1019. */
  1020. function rateButton($node, $return = false){
  1021. global $img_rate, $jzUSER, $img_rate_dis, $enable_ratings;
  1022. // First off can they rate?
  1023. if (!$jzUSER->getSetting('stream')){
  1024. return;
  1025. }
  1026. if ($enable_ratings <> "true"){
  1027. return;
  1028. }
  1029. $arr = array();
  1030. $arr['action'] = "popup";
  1031. $arr['ptype'] = "rateitem";
  1032. $arr['jz_path'] = $node->getPath("String");
  1033. $retVal = '<a onClick="openPopup(' . "'". urlize($arr) ."'" . ',350,150); return false;" href="javascript:;">';
  1034. $retVal .= $img_rate;
  1035. $retVal .= "</a>";
  1036. if ($return){
  1037. return $retVal;
  1038. } else {
  1039. echo $retVal;
  1040. }
  1041. }
  1042. function emailButton($node) {
  1043. global $img_email,$this_site;
  1044. $arr = array();
  1045. $arr['action'] = "playlist";
  1046. $arr['jz_path'] = $node->getPath("String");
  1047. if ($node->isLeaf()) {
  1048. $arr['type'] = "track";
  1049. }
  1050. $link = $this_site. urlencode(urlize($arr));
  1051. $artist = getInformation($node,"artist");
  1052. $album = getInformation($node,"album");
  1053. // hack : make 'album' trackname if that's what we're playing.
  1054. if ($node->isLeaf()) {
  1055. $album = $node->getName();
  1056. }
  1057. $mailLink = "mailto:?subject=". $artist. " - ". $album. "&body=Click to play ".
  1058. $artist. " - ". $album . ":%0D%0A%0D%0A".
  1059. $link. "%0D%0A%0D%0APowered%20by%20Jinzora%20%0D%0AJinzora%20::%20Free%20Your%20Media%0D%0Ahttp://www.jinzora.org";
  1060. ?>
  1061. <a class="jz_track_table_songs_href" href="<?php echo $mailLink; ?>"><?php echo $img_email; ?></a>
  1062. <?php
  1063. }
  1064. /**
  1065. * Displays or returns the rating for an object
  1066. *
  1067. *
  1068. * @author Ross Carlson
  1069. * @version 11/20/04
  1070. * @since 11/20/04
  1071. * @param $node The node that we are getting the rating for
  1072. * @param $return Return the data or display (true = return)
  1073. */
  1074. function rating($node, $return = false){
  1075. global $img_star_full, $img_star_half_empty, $img_star_left, $img_star_right, $img_star_full_empty, $include_path, $img_star_full_raw, $img_star_empty_raw;
  1076. // Let's increment the counter
  1077. $_SESSION['jz_stars_group']++;
  1078. // Let's grab the rating from the node
  1079. $rating = estimateRating($node->getRating());
  1080. // First lets see if we should just return if this is nothing
  1081. if (!$rating){return;}
  1082. // Now let's start the rating icon
  1083. $retVal .= $img_star_left;
  1084. $total_rating = $rating;
  1085. for ($i = floor($rating); $i > 0; $i--){
  1086. $retVal .= $img_star_full;
  1087. }
  1088. if ($rating - floor($rating) > 0.25){
  1089. $retVal .= $img_star_half_empty;
  1090. }
  1091. // Now we need to finish this off to make 5
  1092. for ($i = ceil($rating); $i < 5; $i++) {
  1093. $retVal .= $img_star_full_empty;
  1094. }
  1095. // Now let's finish it off
  1096. $retVal .= $img_star_right;
  1097. if ($return){
  1098. return $retVal;
  1099. } else {
  1100. echo $retVal;
  1101. }
  1102. }
  1103. // strlen() that ignores html text
  1104. function plaintextStrlen( $text ) {
  1105. $stripped = preg_replace( '/<.*?>/', "", $text );
  1106. return strlen( $stripped );
  1107. }
  1108. // substr() that ignores html text
  1109. // TODO: change this so that the signature matches that of substr (e.g., add $begin)
  1110. function plaintextSubstr( $text, $end ) {
  1111. if ($text === false) return false;
  1112. // Only need to search starting from the first html tag
  1113. $currentPos = strpos( $text, "<" );
  1114. if( !$currentPos || $currentPos > $end ) {
  1115. // Plain text (or html occurs after $end); just return a substring
  1116. return substr( $text, 0, $end );
  1117. }
  1118. // Number of chars of non-body data we've seen so far
  1119. $nonDisplayTextCounter = 0;
  1120. // Used to keep track of whether we're looking at plain text or tag body text
  1121. $inTagBody = false;
  1122. $textFullLength = strlen( $text );
  1123. while( $currentPos <= $textFullLength ) {
  1124. // CASE 1: Tag opening
  1125. if( $text[$currentPos] == '<' ) {
  1126. if( !$inTagBody ) {
  1127. $inTagBody = true;
  1128. $nonDisplayTextCounter++;
  1129. } else {
  1130. // This is only reachable for malformatted html, e.g. "<a = <stuff>"
  1131. writeLogData( "messages", "Warning: found possibly malformatted open tag." );
  1132. }
  1133. // CASE 2: Tag closing
  1134. } else if( $text[$currentPos] == '>' ) {
  1135. if( $inTagBody ) {
  1136. $inTagBody = false;
  1137. $nonDisplayTextCounter++;
  1138. } else {
  1139. // Malformatted html (e.g. "<b> stuff >") or real greater-than symbol meaning
  1140. writeLogData( "messages", "Warning: found possibly malformatted close tag." );
  1141. }
  1142. // Case 3: plain text, either body text or tag text
  1143. } else {
  1144. if( $inTagBody ) {
  1145. $nonDisplayTextCounter++;
  1146. }
  1147. }
  1148. // Stop once we find $end characters
  1149. if( ($currentPos-$nonDisplayTextCounter) == $end ) {
  1150. break;
  1151. }
  1152. $currentPos++;
  1153. }
  1154. return substr( $text, 0, $currentPos);
  1155. }
  1156. /**
  1157. * Returns a shortened version of the given $text.
  1158. *
  1159. *
  1160. * @author Ross Carlson
  1161. * @version 11/17/04
  1162. * @since 11/17/04
  1163. * @param $text string The text that we want to truncate
  1164. * @param $length int The length for the text to be truncated to
  1165. */
  1166. function returnShortName($text, $length){
  1167. if ($text === false) return false;
  1168. if( $this->plaintextStrlen( $text ) <= $length ) {
  1169. return $text;
  1170. } else {
  1171. // Ok, we need to make sure we don't break within a tag
  1172. $shortName = $this->plaintextSubstr( $text, $length );
  1173. $retText = substr($text,0,strlen( $shortName ) );
  1174. while (strrpos($retText,">") < strrpos($retText,"<")){
  1175. // Ok, we were in a tag, so we need to increase until we aren't
  1176. $length = $length -1;
  1177. $retText = substr($text,0,$length);
  1178. }
  1179. return trim($retText). "...";
  1180. }
  1181. }
  1182. /**
  1183. * Displays a link for the node. (or a playlink for the path)
  1184. *
  1185. *
  1186. * @author Ben Dodson
  1187. * @version 11/4/04
  1188. * @since 11/4/04
  1189. */
  1190. function link($node, $text = false, $title = false, $class = false, $return = false, $linkonly = false, $playRandom = false, $playlist = false, $target = false) {
  1191. if (!is_object($node)) {
  1192. return false;
  1193. }
  1194. $arr = array();
  1195. $arr['jz_path'] = $node->getPath("String");
  1196. if ($node->isLeaf()) {
  1197. $this->playLink($node, $text, $title, $class, $return);
  1198. return;
  1199. }
  1200. if ($playRandom){
  1201. $arr['mode'] = "random";
  1202. }
  1203. if ($playlist){
  1204. $arr['action'] = "playlist";
  1205. }
  1206. if (isset($_GET['frame'])){
  1207. $arr['frame'] = $_GET['frame'];
  1208. }
  1209. if (!defined('NO_AJAX_LINKS')) {
  1210. $arr['maindiv'] = "true";
  1211. }
  1212. // Let's start the link
  1213. if (!$linkonly){
  1214. if (defined('NO_AJAX_LINKS')) {
  1215. $linkText = '<a href="' . urlize($arr). '"';
  1216. } else {
  1217. $linkText = '<a href="javascript:maindiv(\''.urlencode(urlize($arr)).'\')"';
  1218. }
  1219. } else {
  1220. if (defined('NO_AJAX_LINKS')) {
  1221. $linkText = urlize($arr);
  1222. } else {
  1223. $linkText = 'javascript:maindiv(\''.urlencode(urlize($arr)).'\')';
  1224. }
  1225. return $linkText;
  1226. }
  1227. // Did they pass text or do we need to figure it out?
  1228. if (!$text) {
  1229. $text = $node->getName();
  1230. if (!$node->isLeaf())
  1231. if ($node->getSubNodeCount() <> 0)
  1232. $text .= " (" . $node->getSubNodeCount() . ")";
  1233. }
  1234. // Did they pass a title?
  1235. if ($title){
  1236. $linkText .= ' title="'. $title. '" alt="'. $title. '"';
  1237. }
  1238. // Did they pass a class?
  1239. if ($class){
  1240. $linkText .= ' class="'. $class. '"';
  1241. }
  1242. // Did they want a target?
  1243. if ($target){
  1244. $linkText .= ' target="'. $target. '"';
  1245. }
  1246. // Now let's finish out
  1247. $linkText .= '>'. $text. '</a>';
  1248. // Now let's echo it out
  1249. if (!$return){
  1250. echo $linkText;
  1251. } else {
  1252. return $linkText;
  1253. }
  1254. }
  1255. /**
  1256. * Displays a link for the node. (or a playlink for the path)
  1257. *
  1258. *
  1259. * @author Ben Dodson
  1260. * @version 11/30/04
  1261. * @since 11/30/04
  1262. * @param $node Object the node we are looking at
  1263. * @param $test String The text for the link
  1264. * @param $title String The title of the line
  1265. * @param $class String the class for the link
  1266. * @param $return Bolean Return or not (defalt to false)
  1267. */
  1268. // returns an assoc array with keys 'href' and 'onclick'
  1269. function getOpenAddToListTag($e) {
  1270. if ($e->isLeaf()) {
  1271. $type = 'track';
  1272. } else {
  1273. $type = 'node';
  1274. }
  1275. return "<a href=\"\" onclick=\"ajax_direct_call('".urlize(array('action'=>'addToPlaylist','jz_path'=>$e->getPath('String'),'type'=>$type))."',updatePlaylist_cb); return false;\" ";
  1276. }
  1277. function getOpenPlayTag($node, $random = false, $limit = 0) {
  1278. global $jzUSER,$jzSERVICES,$jukebox;
  1279. if (!is_object($node)){return;}
  1280. // do they have permissions or should we just do text?
  1281. if ($node instanceof jzMediaElement && !checkPermission($jzUSER,"play",$node->getPath("String"))) {
  1282. return null;
  1283. }
  1284. $href = $node->getPlayHREF($random,$limit);
  1285. // Let's start the link
  1286. if (defined('NO_AJAX_JUKEBOX') || $jukebox == "false") {
  1287. $linkText = '<a href="' . $href. '"';
  1288. // Now are they using a popup player?
  1289. if (checkPlayback() == "embedded"){
  1290. // Ok, let's put the popup in the href
  1291. // We need to get this from the embedded player
  1292. $linkText .= $jzSERVICES->returnPlayerHref();
  1293. }
  1294. } else {
  1295. $linkText = '<a href="'. htmlentities($href) . '"';
  1296. $linkText .= "onclick=\"return playbackLink('".htmlentities($href)."')\"";
  1297. }
  1298. return $linkText;
  1299. }
  1300. function playLink($node, $text = false, $title = false, $class = false, $return = false, $random = false, $linkOnly = false, $clips = false, $limit = 0) {
  1301. global $jzUSER, $jzSERVICES,$jukebox;
  1302. $linkText = $this->getOpenPlayTag($node,$random,$limit);
  1303. if ($linkText == null) return null;
  1304. // Did they pass a title?
  1305. if ($title){
  1306. $linkText .= ' title="'. $title. '" alt="'. $title. '"';
  1307. }
  1308. if ($class){
  1309. $linkText .= ' class="'. $class. '"';
  1310. }
  1311. // Now let's finish out
  1312. $linkText .= '>'. $text. '</a>';
  1313. // Now let's echo it out
  1314. if (!$return){
  1315. echo $linkText;
  1316. } else {
  1317. return $linkText;
  1318. }
  1319. }
  1320. /**
  1321. * Displays a podcast link for a node
  1322. *
  1323. *
  1324. * @author Ross Carlson
  1325. * @version 7/8/2005
  1326. * @since 7/8/2005
  1327. * @param $node Object the node we are looking at
  1328. */
  1329. function podcastLink($node, $return = true) {
  1330. global $root_dir, $img_podcast, $enable_podcast, $web_dirs, $this_site;
  1331. if (!is_object($node)){return;}
  1332. if ($enable_podcast <> "true"){return;}
  1333. $site = str_replace("http://","",$this_site);
  1334. $site = str_replace("https://","",$site);
  1335. if ($return){
  1336. return '<a href="itpc://'. $site. $root_dir. '/podcast.rss?jz_path='. $node->getPath("String"). '">'. $img_podcast. '</a>';
  1337. } else {
  1338. echo '<a href="itpc://'. $site. $root_dir. '/podcast.rss?jz_path='. $node->getPath("String"). '">'. $img_podcast. '</a>';
  1339. }
  1340. }
  1341. /**
  1342. * Displays a download button for the node or track or playlist.
  1343. *
  1344. *
  1345. * @author Ross Carlson
  1346. * @version 12/01/04
  1347. * @since 12/01/04
  1348. */
  1349. function downloadButton($node, $return = false, $returnImage = false, $showSize = false, $linkOnly = false) {
  1350. global $img_download, $img_download_dis, $jzUSER, $jzSERVICES, $allow_resample_downloads, $allow_resample, $display_downloads;
  1351. if ($display_downloads == "false") {
  1352. return;
  1353. }
  1354. if (!$jzUSER->getSetting('download')){
  1355. if ($return){
  1356. return $img_download_dis;
  1357. } else {
  1358. echo $img_download_dis;
  1359. return;
  1360. }
  1361. }
  1362. if (!($node->getType() == "jzPlaylist" || $node->isLeaf() || $node->getPType() == "album")) return;
  1363. $arr = array();
  1364. $arr['action'] = "download";
  1365. if (isset($_GET['frame'])){
  1366. $arr['frame'] = $_GET['frame'];
  1367. }
  1368. if ($node->getType() == "jzPlaylist") {
  1369. $arr['type'] = "playlist";
  1370. $arr['jz_pl_id'] = $node->getID();
  1371. } else {
  1372. $arr['jz_path'] = $node->getPath("String");
  1373. if ($node->isLeaf()) {
  1374. $arr['type'] = "track";
  1375. }
  1376. }
  1377. // NOTE: be careful because this could be a downloadButton for a jzPlaylist.
  1378. //$fileExt = substr($node->getPath("String"),-3);
  1379. // Now let's get the stats so we'll know how big this album is
  1380. if ($showSize){
  1381. $size = $node->getStats("total_size_str");
  1382. }
  1383. // Now, do we need to make this a popup page?
  1384. // This is used for transcoding downloading
  1385. // First is this an album or a track?
  1386. if ($node->getType() <> "jzPlaylist"){
  1387. if (!$node->isLeaf()){
  1388. // Ok, it's an album so we need to get the first track from it
  1389. // We'll assume all the tracks are the same format
  1390. $tracks = $node->getSubNodes("tracks",-1,false,1);
  1391. // Now let's make sure we got data back
  1392. if (is_object($tracks[0])){
  1393. $trackPath = $tracks[0]->getPath("string");
  1394. } else {
  1395. $trackPath = NULL;
  1396. }
  1397. } else {
  1398. $trackPath = $node->getPath("String");
  1399. }
  1400. }
  1401. if ($jzSERVICES->isResampleable($trackPath) and $allow_resample_downloads == "true" and $allow_resample == "true"){
  1402. $arr['action'] = "popup";
  1403. $arr['ptype'] = "downloadtranscode";
  1404. $arr['jz_path'] = $node->getPath("String");
  1405. $popupAddon = ' target="_blank" onclick="openPopup(this, 400, 400); return false;" ';
  1406. } else {
  1407. $popupAddon = "";
  1408. }
  1409. if ($linkOnly){
  1410. return urlize($arr);
  1411. }
  1412. if (!$return){
  1413. $message = word("Download"). ": ". $node->getName();
  1414. if (isset($size)){
  1415. $message .= " : ". $size;
  1416. }
  1417. if ($returnImage) {
  1418. return '<a title="'. $message. '" href="'. urlize($arr) . '" '. $popupAddon. '>' . $img_download . '</a>';
  1419. }
  1420. echo '<a title="'. $message. '" href="'. urlize($arr). '"'. $popupAddon. '>';
  1421. echo $img_download;
  1422. echo "</a>";
  1423. } else {
  1424. if ($returnImage) {
  1425. return '<a title="'. $message. '" href="'. urlize($arr) . '" '. $popupAddon. '>'. $img_download. '</a>';
  1426. } else {
  1427. return urlize($arr);
  1428. }
  1429. }
  1430. }
  1431. /**
  1432. * Displays a clip play button for the node or track or playlist.
  1433. *
  1434. *
  1435. * @author Ross Carlson
  1436. * @version 3/07/05
  1437. * @since 3/07/05
  1438. * @param $node the Node we are looking at
  1439. */
  1440. function clipPlayButton($node) {
  1441. global $img_clip, $jzUSER, $jzSERVICES;
  1442. if ($node->getType() == "jzPlaylist" || !$node->isLeaf()) {
  1443. return;
  1444. }
  1445. $arr = array();
  1446. $arr['action'] = "playlist";
  1447. if (isset($_GET['frame'])){
  1448. $arr['frame'] = $_GET['frame'];
  1449. }
  1450. $arr['jz_path'] = $node->getPath("String");
  1451. $arr['type'] = "track";
  1452. $arr['clip'] = "true";
  1453. echo '<a href="' . urlize($arr) . '"';
  1454. // Now are they using a popup player?
  1455. if (checkPlayback() == "embedded"){
  1456. // Ok, let's put the popup in the href
  1457. echo $jzSERVICES->returnPlayerHref();
  1458. }
  1459. echo '>';
  1460. echo $img_clip;
  1461. echo "</a>";
  1462. }
  1463. /**
  1464. * Displays a lofi play button for the node or track or playlist.
  1465. *
  1466. *
  1467. * @author Ross Carlson
  1468. * @version 3/07/05
  1469. * @since 3/07/05
  1470. * @param $node the Node we are looking at
  1471. */
  1472. function lofiPlayButton($node, $limit = false, $text = false, $onclick = false) {
  1473. global $img_lofi, $jzUSER, $jzSERVICES;
  1474. if ($jzUSER->getSetting('lofi') === false) {
  1475. //return;
  1476. }
  1477. $arr = array();
  1478. $arr['action'] = "playlist";
  1479. if (isset($_GET['frame'])){
  1480. $arr['frame'] = $_GET['frame'];
  1481. }
  1482. if ($node->getType() == "jzPlaylist") {
  1483. $arr['type'] = "playlist";
  1484. $arr['pl_id'] = $node->getID();
  1485. } else {
  1486. $arr['jz_path'] = $node->getPath("String");
  1487. if ($node->isLeaf()) {
  1488. $arr['type'] = "track";
  1489. } else {
  1490. if ($limit !== false) {
  1491. $arr['limit'] = $limit;
  1492. }
  1493. }
  1494. }
  1495. echo '<a href="' . urlize($arr) . '"';
  1496. if ($onclick){
  1497. echo 'onclick="'. $onclick. '"';
  1498. }
  1499. // Now are they using a popup player?
  1500. if (checkPlayback() == "embedded"){
  1501. // Ok, let's put the popup in the href
  1502. echo $jzSERVICES->returnPlayerHref();
  1503. }
  1504. echo '>';
  1505. echo $img_lofi;
  1506. echo "</a>";
  1507. }
  1508. /**
  1509. * Displays a play button for the node or track or playlist.
  1510. *
  1511. *
  1512. * @author Ben Dodson
  1513. * @version 1/15/05
  1514. * @since 11/4/04
  1515. * @param $node the Node we are looking at
  1516. * @param $limit should we limit the items to play (default is false)
  1517. * @param $text The text to display in the link
  1518. */
  1519. function playButton($node, $limit = false, $text = false, $onclick = false, $return = false) {
  1520. global $img_play, $img_play_dis, $jzUSER, $jzSERVICES,$jukebox;
  1521. if (!is_object($node)) {
  1522. return false;
  1523. }
  1524. if ($node->getType() == "jzMediaNode" || $node->getType() == "jzMediaTrack") {
  1525. $path = $node->getPath("string");
  1526. } else {
  1527. $path = "";
  1528. }
  1529. // First we need to know if this is a view only user or not
  1530. if (checkPermission($jzUSER,'play',$path) === false){
  1531. if ($return){
  1532. return $return;
  1533. } else {
  1534. echo $img_play_dis;
  1535. return;
  1536. }
  1537. }
  1538. $retVal='';
  1539. $arr = array();
  1540. $arr['action'] = "playlist";
  1541. if (isset($_GET['frame'])){
  1542. $arr['frame'] = $_GET['frame'];
  1543. }
  1544. if ($node->getType() == "jzPlaylist") {
  1545. $arr['type'] = "playlist";
  1546. $arr['pl_id'] = $node->getID();
  1547. } else {
  1548. $arr['jz_path'] = $node->getPath("String");
  1549. if ($node->isLeaf()) {
  1550. $arr['type'] = "track";
  1551. } else {
  1552. if ($limit !== false) {
  1553. $arr['limit'] = $limit;
  1554. }
  1555. }
  1556. }
  1557. if (!defined('NO_AJAX_JUKEBOX') && $jukebox != "false") {
  1558. $retVal .= '<a href="'. htmlentities(urlize($arr)) . '"';
  1559. $retVal .= " onClick=\"return playbackLink('".htmlentities(urlize($arr))."')\"";
  1560. } else {
  1561. $retVal .= '<a href="' . urlize($arr) . '"';
  1562. if ($onclick){
  1563. $retVal .= ' onclick="'. $onclick. '" ';
  1564. }
  1565. // Now are they using a popup player?
  1566. if (checkPlayback() == "embedded"){
  1567. // Ok, let's put the popup in the href
  1568. $retVal .= $jzSERVICES->returnPlayerHref();
  1569. }
  1570. }
  1571. $retVal .= '>';
  1572. if ($text === false) {
  1573. $retVal .= $img_play;
  1574. } else {
  1575. $retVal .= $text;
  1576. }
  1577. $retVal .= "</a>";
  1578. if ($return){
  1579. return $retVal;
  1580. } else {
  1581. echo $retVal;
  1582. }
  1583. }
  1584. /*
  1585. * Track information button
  1586. *
  1587. * @author Ben Dodson
  1588. * @since 2/20/05
  1589. * @version 2/20/05
  1590. *
  1591. **/
  1592. function infoButton($track) {
  1593. global $img_more;
  1594. $arr = array();
  1595. $arr['action'] = "popup";
  1596. $arr['ptype'] = "trackinfo";
  1597. $arr['jz_path'] = $track->getPath("String");
  1598. $link = urlize($arr);
  1599. echo '<a href="' . $link . '" target="_blank" onclick="openPopup(this, 375, 650); return false;">' . $img_more . '</a>';
  1600. }
  1601. /*
  1602. * Displays a button linking to the home page.
  1603. *
  1604. **/
  1605. function homeButton() {
  1606. global $img_home;
  1607. echo '<a href="' . urlize(array()) . '">';
  1608. echo $img_home;
  1609. echo '</a>';
  1610. }
  1611. /**
  1612. * Displays a the radio button for the node and it's similar nodes
  1613. *
  1614. *
  1615. * @author Ross Carlson
  1616. * @version 01/15/05
  1617. * @since 01/10/05
  1618. */
  1619. function radioPlayButton($node, $limit = false, $text = false) {
  1620. global $img_play, $jzUSER, $img_play_dis, $jzSERVICES;
  1621. if (checkPermission($jzUSER,'play',$node->getPath('String')) === false){
  1622. echo $img_play_dis;
  1623. return;
  1624. }
  1625. $simArray = $jzSERVICES->getSimilar($node);
  1626. $simArray = seperateSimilar($simArray);
  1627. if (sizeof($simArray['matches']) == 0) {
  1628. return false;
  1629. }
  1630. $arr = array();
  1631. $arr['action'] = "playlist";
  1632. $arr['mode'] = "radio";
  1633. if ($limit !== false) {
  1634. $arr['limit'] = $limit;
  1635. }
  1636. if ($node->getType() == "jzPlaylist") {
  1637. $arr['type'] = "playlist";
  1638. } else {
  1639. $arr['jz_path'] = $node->getPath("String");
  1640. }
  1641. echo '<a href="' . urlize($arr) . '"';
  1642. // Now are they using a popup player?
  1643. if (checkPlayback() == "embedded"){
  1644. // Ok, let's put the popup in the href
  1645. echo $jzSERVICES->returnPlayerHref();
  1646. }
  1647. echo '>';
  1648. if ($text === false) {
  1649. echo $img_play;
  1650. }
  1651. else {
  1652. echo $text;
  1653. }
  1654. echo "</a>";
  1655. return true;
  1656. }
  1657. /**
  1658. * Displays a random play button for the node.
  1659. *
  1660. *
  1661. * @author Ben Dodson
  1662. * @version 1/15/05
  1663. * @since 11/4/04
  1664. */
  1665. function randomPlayButton($node, $limit = false, $text = false, $onclick = false, $return = false) {
  1666. global $img_random_play, $img_random_play_dis, $jzUSER, $jzSERVICES,$jukebox;
  1667. if (!is_object($node)) {
  1668. return false;
  1669. }
  1670. if ($node->getType() == "jzMediaNode" || $node->getType() == "jzMediaTrack") {
  1671. $path = $node->getPath("string");
  1672. } else {
  1673. $path = "";
  1674. }
  1675. // First we need to know if this is a view only user or not
  1676. if (checkPermission($jzUSER,'play',$path) === false){
  1677. if ($return){
  1678. return $img_random_play_dis;
  1679. } else {
  1680. echo $img_random_play_dis;
  1681. return;
  1682. }
  1683. }
  1684. $retVal='';
  1685. $arr = array();
  1686. $arr['action'] = "playlist";
  1687. $arr['mode'] = "random";
  1688. if ($limit !== false) {
  1689. $arr['limit'] = $limit;
  1690. }
  1691. if (isset($_GET['frame'])){
  1692. $arr['frame'] = $_GET['frame'];
  1693. }
  1694. if ($node->getType() == "jzPlaylist") {
  1695. $arr['type'] = "playlist";
  1696. } else {
  1697. $arr['jz_path'] = $node->getPath("String");
  1698. }
  1699. // So links can be copy/pasted when not in jukebox:
  1700. if ($jukebox == "false") {
  1701. $retVal .= '<a href="' . urlize($arr) . '"';
  1702. if ($onclick){
  1703. $retVal .= 'onclick="'. $onclick. '"';
  1704. }
  1705. // Now are they using a popup player?
  1706. if (checkPlayback() == "embedded"){
  1707. // Ok, let's put the popup in the href
  1708. $retVal .= $jzSERVICES->returnPlayerHref();
  1709. }
  1710. } else {
  1711. $retVal .= '<a href="'. htmlentities(urlize($arr)) . '"';
  1712. $retVal .= " onClick=\"return playbackLink('".htmlentities(urlize($arr))."')\"";
  1713. }
  1714. $retVal .= '>';
  1715. if ($text === false) {
  1716. $retVal .= $img_random_play;
  1717. } else {
  1718. $retVal .= $text;
  1719. }
  1720. $retVal .= "</a>";
  1721. if ($return){
  1722. return $retVal;
  1723. } else {
  1724. echo $retVal;
  1725. }
  1726. }
  1727. /**
  1728. * Displays a button for the node's statistics
  1729. *
  1730. * @author Ben Dodson, Ross Carlson
  1731. * @since 1/29/05
  1732. * @version 1/29/05
  1733. *
  1734. **/
  1735. function statsButton($node, $text = false, $return = false) {
  1736. global $img_more, $jzUSER;
  1737. if (!$jzUSER->getSetting('admin')){return;}
  1738. $arr = array();
  1739. $arr['jz_path'] = $node->getPath("String");
  1740. $arr['action'] = "popup";
  1741. $arr['ptype'] = "nodestats";
  1742. if ($text === false) {
  1743. $text = $img_more;
  1744. }
  1745. $linkText = ' <a href="'. urlize($arr). '" onclick="openPopup(this, 450, 450); return false;">'. $text. '</a>';
  1746. if ($return) {
  1747. return $linkText;
  1748. }
  1749. else {
  1750. echo $linkText;
  1751. }
  1752. }
  1753. /**
  1754. * Displays a button to add the jz_list to the currently chosen playlist.
  1755. *
  1756. * @author Ben Dodson
  1757. * @version 1/12/05
  1758. * @since 1/12/05
  1759. **/
  1760. function addListButton($return = false){
  1761. global $root_dir, $skin,$this_page;
  1762. static $my_id = 0;
  1763. $label = 'addbutton'.++$my_id;
  1764. $retVar = '<input type="button" style="display:none;" id="'.$label.'" value="true" name="' . jz_encode("addList") . '"/>';
  1765. $onclick = 'submitPlaybackForm(document.getElementById(\''.$label.'\'), \'' . htmlentities($this_page) . '\')';
  1766. $retVar .= icon('add',array( 'title'=> word('Add to'),
  1767. 'onclick'=> $onclick
  1768. )
  1769. );
  1770. if ($return){
  1771. return $retVar;
  1772. } else {
  1773. echo $retVar;
  1774. }
  1775. }
  1776. /**
  1777. * Displays a select box with all the playlists listed
  1778. *
  1779. * @author Ross Carlson
  1780. * @version 1/13/05
  1781. * @since 1/13/05
  1782. * @param $width the width, in pixels, of the select box
  1783. * @param onclick: whether or not to submit on select.
  1784. * @param type: the type of playlists to show: static|dynamic|all
  1785. **/
  1786. function playlistSelect($width, $onchange = false, $type = "static", $session_pl = true, $varname = "jz_playlist", $return = false){
  1787. global $jzUSER;
  1788. $display = new jzDisplay();
  1789. $retVal = "";
  1790. $retVal .= $display->openSelect($varname, $width, $onchange, true);
  1791. if ($session_pl && ($type != "dynamic")) {
  1792. $retVal .= '<option value= "session">'. word(" - Session Playlist - "). '</option>'. "\n";
  1793. }
  1794. $lists = $jzUSER->listPlaylists($type);
  1795. foreach ($lists as $id=>$pname) {
  1796. $retVal .= '<option value="'.$id.'"';
  1797. if ($_SESSION['jz_playlist'] == $id) { $retVal .= " selected"; }
  1798. $retVal .= '>' . $pname . '</option>'."\n";
  1799. }
  1800. $retVal .= $display->closeSelect(true);
  1801. if ($return){
  1802. return $retVal;
  1803. } else {
  1804. echo $retVal;
  1805. }
  1806. }
  1807. /**
  1808. * Displays a button to play the jz_list as a playlist.
  1809. *
  1810. * @author Ben Dodson
  1811. * @version 1/12/05
  1812. * @since 1/12/05
  1813. * @param $random Should the playlist we create be random?
  1814. **/
  1815. function sendListButton($random = false, $return = true) {
  1816. global $root_dir, $skin,$this_page;
  1817. static $my_id = 0;
  1818. $label = 'playnowbutton'.++$my_id;
  1819. $retVal = '<input type="button" style="display:none;" id="'.$label.'" value="true" name="';
  1820. if ($random){
  1821. $retVal .= jz_encode("sendListRandom");
  1822. $title = word("Randomize selected");
  1823. $icon = 'random';
  1824. } else {
  1825. $retVal .= jz_encode("sendList");
  1826. $title = word("Play selected");
  1827. $icon = 'play';
  1828. }
  1829. $retVal .= '"';
  1830. $onclick = 'submitPlaybackForm(document.getElementById(\''.$label.'\'), \'' . htmlentities($this_page) . '\')';
  1831. $retVal .= icon($icon,array( 'title'=> word($title),
  1832. 'onclick'=> $onclick
  1833. )
  1834. );
  1835. if ($return) {
  1836. return $retVal;
  1837. } else {
  1838. echo $retVal;
  1839. }
  1840. }
  1841. /**
  1842. * A form button to play the current playlist.
  1843. *
  1844. * @author Ben Dodson
  1845. * @since 4/23/05
  1846. **/
  1847. function playListButton($return = false) {
  1848. global $jzSERVICES,$this_page;
  1849. static $my_id = 0;
  1850. $label = "playlistbutton" . ++$my_id;
  1851. $retVal = '<input id="'.$label.'" style="display:none;" type="submit" name="'.jz_encode("playplaylist").'" value="'.jz_encode('normal').'">';
  1852. if (!defined('NO_AJAX_JUKEBOX')) {
  1853. $onclick = 'submitPlaybackForm(document.getElementById(\''.$label.'\'), \'' . htmlentities($this_page) . '\')';
  1854. } else if (checkPlayback() == "embedded"){
  1855. // Ok, let's put the popup in the href
  1856. $onclick = $this->embeddedFormHandler('playlistForm');
  1857. }
  1858. $retVal .= icon('play',array( 'title'=> word('Play'),
  1859. 'onclick'=> $onclick
  1860. )
  1861. );
  1862. if ($return){
  1863. return $retVal;
  1864. } else {
  1865. echo $retVal;
  1866. }
  1867. }
  1868. /**
  1869. * A form button to play the current playlist randomly.
  1870. *
  1871. * @author Ben Dodson
  1872. * @since 4/23/05
  1873. **/
  1874. function randomListButton($return = false) {
  1875. global $this_page;
  1876. static $my_id = 0;
  1877. $label = "randomizebutton" . ++$my_id;
  1878. $retVal = '<input type="submit" style="display:none;" name="'.jz_encode("playplaylist").'" value="'.jz_encode('random').'">';
  1879. if (!defined('NO_AJAX_JUKEBOX')) {
  1880. $onclick = 'submitPlaybackForm(document.getElementById(\''.$label.'\'), \'' . htmlentities($this_page) . '\')';
  1881. } else if (checkPlayback() == "embedded"){
  1882. // Ok, let's put the popup in the href
  1883. $onclick = $this->embeddedFormHandler('playlistForm');
  1884. }
  1885. $retVal .= icon('random',array( 'title'=> word('Play Random'),
  1886. 'onclick'=> $onclick
  1887. )
  1888. );
  1889. if ($return){
  1890. return $retVal;
  1891. } else {
  1892. echo $retVal;
  1893. }
  1894. }
  1895. /**
  1896. * A form button to download the current playlist.
  1897. *
  1898. * @author Ben Dodson
  1899. * @since 4/23/05
  1900. **/
  1901. function downloadListButton($return = false) {
  1902. global $this_page;
  1903. static $my_id = 0;
  1904. $label = "downloadbutton" . ++$my_id;
  1905. $retVal = '<input type="submit" style="display:none;" id="'.$label.'" name="'.jz_encode("downloadlist").'" value="'.jz_encode('true').'">';
  1906. $onclick = 'submitPlaybackForm(document.getElementById(\''.$label.'\'), \'' . htmlentities($this_page) . '\')';
  1907. $retVal .= icon('download',array( 'title'=> word('Download Playlist'),
  1908. 'onclick'=> $onclick
  1909. )
  1910. );
  1911. if ($return){
  1912. return $retVal;
  1913. } else {
  1914. echo $retVal;
  1915. }
  1916. }
  1917. /**
  1918. * A form button to create a new playlist.
  1919. *
  1920. * @author Ben Dodson
  1921. * @since 4/23/05
  1922. **/
  1923. function createListButton($return = false) {
  1924. global $this_page;
  1925. static $my_id = 0;
  1926. $label = "createbutton" . ++$my_id;
  1927. $retVal = '<input type="submit" style="display:none;" id="'.$label.'" name="'.jz_encode("createlist").'" value="'.jz_encode('true').'"';
  1928. $retVal .= " onclick=\"variablePrompt('playlistForm','playlistname','".word('Please enter a name for your playlist.')."')\">";
  1929. $onclick = 'submitPlaybackForm(document.getElementById(\''.$label.'\'), \'' . htmlentities($this_page) . '\')';
  1930. $retVal .= icon('add',array( 'title'=> word('Create Playlist'),
  1931. 'onclick'=> $onclick
  1932. )
  1933. );
  1934. if ($return){
  1935. return $retVal;
  1936. } else {
  1937. echo $retVal;
  1938. }
  1939. }
  1940. /**
  1941. * Displays the login/logout link.
  1942. *
  1943. * @author Ben Dodson
  1944. * @version 1/17/05
  1945. * @since 1/17/05
  1946. *
  1947. */
  1948. function loginLink($logintext = false, $logouttext = false, $registration = true, $regtext = false, $return_link = false) {
  1949. global $jzUSER, $http_auth_enable;
  1950. if (isset($http_auth_enable) && $http_auth_enable == "true") {
  1951. if ($return_link) {
  1952. return "";
  1953. } else {
  1954. return;
  1955. }
  1956. }
  1957. $array = array();
  1958. if ($jzUSER->getID() == $jzUSER->lookupUID('NOBODY')) {
  1959. $array['action'] = "login";
  1960. if ($logintext === false) {
  1961. $text = word("Login");
  1962. } else {
  1963. $text = $logintext;
  1964. }
  1965. } else {
  1966. $array['action'] = "logout";
  1967. if ($logouttext === false) {
  1968. $text = word("Logout");
  1969. } else {
  1970. $text = $logouttext;
  1971. }
  1972. }
  1973. $string = "";
  1974. $string .= '<a class="jz_header_table_href" href="'. urlize($array) .'">' . $text . '</a>';
  1975. if ($jzUSER->getID() == $jzUSER->lookupUID('NOBODY')) {
  1976. $be = new jzBackend();
  1977. $data = $be->loadData('registration');
  1978. if ($data['allow_registration'] == "true") {
  1979. if ($regtext === false) {
  1980. $regtext = word("Register");
  1981. }
  1982. $array['action'] = "register";
  1983. $string .= ' | ';
  1984. $string .= '<a class="jz_header_table_href" href="'. urlize($array) .'">' . $regtext . '</a>';
  1985. }
  1986. }
  1987. if ($return_link) {
  1988. return $string;
  1989. } else {
  1990. echo $string;
  1991. }
  1992. }
  1993. /**
  1994. * Displays a link for the specified popup.
  1995. * $type is one of: genre, artist, album
  1996. *
  1997. *
  1998. * @author Ben Dodson
  1999. * @version 11/7/04
  2000. * @since 10/27/04
  2001. */
  2002. function popupLink($type, $text = false, $return = false, $linkOnly = false){
  2003. global $img_slim_pop, $img_more,$this_page,$root_dir,$jzUSER,$img_playlist,$include_path, $img_tools;
  2004. $args = array();
  2005. $args['action'] = "popup";
  2006. $tag = 'target="_blank"';
  2007. $root = &new jzMediaNode();
  2008. switch ($type) {
  2009. case "genre":
  2010. $args['ptype'] = "genre";
  2011. // fill args here.
  2012. $tag .= " onclick=\"openPopup(this, 400, 400, false, 'Genres'); return false;\"";
  2013. if ($text === false) {
  2014. if (!isset($_SESSION['jz_num_genres'])){
  2015. $_SESSION['jz_num_genres'] = $root->getSubNodeCount("nodes",distanceTo("genre"));
  2016. }
  2017. $text = "Genres: " . number_format($_SESSION['jz_num_genres']);
  2018. }
  2019. break;
  2020. case "artist":
  2021. $args['ptype'] = "artist";
  2022. $tag .= " onclick=\"openPopup(this, 400, 400, false, 'Artists'); return false;\"";
  2023. if ($text === false) {
  2024. if (!isset($_SESSION['jz_num_artists'])){
  2025. $_SESSION['jz_num_artists'] = $root->getSubNodeCount("nodes",distanceTo("artist"));
  2026. }
  2027. $text = "Artists: " . number_format($_SESSION['jz_num_artists']);
  2028. }
  2029. break;
  2030. case "album":
  2031. $args['ptype'] = "album";
  2032. $tag .= " onclick=\"openPopup(this, 400, 400, false, 'Albums'); return false;\"";
  2033. if ($text === false) {
  2034. if (!isset($_SESSION['jz_num_albums'])){
  2035. $_SESSION['jz_num_albums'] = $root->getSubNodeCount("nodes",distanceTo("album"));
  2036. }
  2037. $text = "Albums: " . number_format($_SESSION['jz_num_albums']);
  2038. }
  2039. break;
  2040. case "track":
  2041. $args['ptype'] = "track";
  2042. $tag .= " onclick=\"openPopup(this, 400, 400, false, 'Tracks'); return false;\"";
  2043. if ($text === false) {
  2044. if (!isset($_SESSION['jz_num_tracks'])){
  2045. $_SESSION['jz_num_tracks'] = $root->getSubNodeCount("tracks",-1);
  2046. }
  2047. $text = "Tracks: " . number_format($_SESSION['jz_num_tracks']);
  2048. }
  2049. break;
  2050. case "preferences":
  2051. if ($jzUSER->getSetting('edit_prefs') == false) {
  2052. return;
  2053. }
  2054. $args['ptype'] = "preferences";
  2055. $tag .= " onclick=\"openPopup(this, 300, 400); return false;\"";
  2056. if ($text === false) {
  2057. $text = word("Prefs");
  2058. }
  2059. break;
  2060. case "slimzora":
  2061. $url = $root_dir . "/slim.php";
  2062. if (isset($_GET['jz_path'])) {
  2063. $url .= "?" . jz_encode("jz_path") ."=". jz_encode($_GET['jz_path']);
  2064. }
  2065. $tag .= " onclick=\"openPopup(this, 300, 400, false, 'Slimzora'); return false;\"";
  2066. if ($text === false) {
  2067. $text = $img_slim_pop;
  2068. }
  2069. if ($linkOnly){
  2070. return $url;
  2071. }
  2072. echo "<a class=\"jz_header_table_href\" href=\"".$url."\" $tag>$text</a>";
  2073. return;
  2074. case "jukezora":
  2075. if ($text === false) {
  2076. $text = "Jukezora";
  2077. }
  2078. $linky = $include_path."jukezora.php";
  2079. $jukezora_link = '<a class="jz_header_table_href" href="javascript:;" onClick="openPopup(\''.$linky.'\',320,600); return false;" title="Launch Jukezora">'.$text.'</a>';
  2080. if ($return) { return $jukezora_link; }
  2081. else {
  2082. echo $jukezora_link;
  2083. }
  2084. return;
  2085. break;
  2086. case "docs":
  2087. $args['ptype'] = "docs";
  2088. $tag .= " onclick=\"openPopup(this, 550, 600); return false;\"";
  2089. $text = $img_more;
  2090. break;
  2091. case "admintools":
  2092. if ($jzUSER->getSetting('admin') == true){
  2093. $args['ptype'] = "admintools";
  2094. $args['jz_path'] = $_GET['jz_path'];
  2095. $tag .= " onclick=\"openPopup(this, 550, 600); return false;\"";
  2096. $text = $img_tools;
  2097. }
  2098. break;
  2099. case "plmanager":
  2100. $args['ptype'] = "playlistedit";
  2101. $tag .= "onClick=\"openPopup(this,600,600); return false;\"";
  2102. if ($text === false) {
  2103. $text = $img_playlist;
  2104. }
  2105. break;
  2106. }
  2107. if ($return) {
  2108. if ($linkOnly){
  2109. return urlize($args);
  2110. } else {
  2111. return "<a class=\"jz_header_table_href\" href=\"".urlize($args)."\" $tag>$text</a>";
  2112. }
  2113. } else {
  2114. echo "<a class=\"jz_header_table_href\" href=\"".urlize($args)."\" $tag>$text</a>";
  2115. }
  2116. }
  2117. /**
  2118. * Displays or returns an image.
  2119. *
  2120. * @author Ben Dodson
  2121. * @version 11/10/04
  2122. * @since 11/10/04
  2123. * @param $path: path to the image
  2124. * @param $alt: alt text to display.
  2125. * @param $width: width for resize
  2126. * @param $height: height for resize
  2127. * @method: how to resize:
  2128. * -limit: constrained resize that does not exceed the width or height, if either is given.
  2129. * if the image is smaller, do not enlarge.
  2130. *
  2131. * -fit: constrained resize that locks to the specified width or height (only 1 should be given)
  2132. * if the image is smaller, enlarge it.
  2133. *
  2134. * -fixed: resize to the given width and height and do not constrain.
  2135. * @param gd: use GD if available for the resize (otherwise, just set the html tag)
  2136. * @param save: if gd is set, save our resized image over our old one.
  2137. */
  2138. function image($path, $alt = false, $width = false, $height = false, $method = "limit", $gd = false, $save = false, $align = false, $hspace = false, $vspace = false, $border = "0") {
  2139. echo $this->returnImage($path,$alt,$width,$height,$method,$gd,$save,$align,$hspace,$vspace,$border);
  2140. }
  2141. /**
  2142. * Resizes and image if it needs it
  2143. *
  2144. * @author Ross Carlson
  2145. * @version 2/24/05
  2146. * @since 2/24/05
  2147. * @param $path: path to the image
  2148. * @param $width: the new width for the image
  2149. * @param $height: the new height for the image
  2150. */
  2151. function resizeImage($path, $destination_width, $destination_height){
  2152. global $keep_porportions;
  2153. // First we need to be sure that they have GD support
  2154. if (gd_version() == 0){
  2155. return false;
  2156. }
  2157. // Ok, now let's resize
  2158. $image = $path;
  2159. $new_image = $path. ".new";
  2160. // Let's grab the source image that was uploaded to work with it
  2161. $src_img = @imagecreatefromjpeg($image);
  2162. if ($src_img){
  2163. // Let's get the width and height of the source image
  2164. $src_width = imagesx($src_img); $src_height = imagesy($src_img);
  2165. // Let's set the width and height of the new image we'll create
  2166. $dest_width = $destination_width; $dest_height = $destination_height;
  2167. // Now if the picture isn't a standard resolution (like 640x480) we
  2168. // need to find out what the new image size will be by figuring
  2169. // out which of the two numbers is higher and using that as the scale
  2170. // First let's make sure they wanted to keep the porportions or not
  2171. if ($keep_porportions == "true"){
  2172. if ($src_width > $src_height){
  2173. /* ok so the width is the bigger number so the width doesn't change
  2174. We need to figure out the percent of change by dividing the source width
  2175. by the dest width */
  2176. $scale = $src_width / $destination_width;
  2177. $dest_height = $src_height / $scale;
  2178. } else {
  2179. /* ok so the width is the bigger number so the width doesn't change
  2180. We need to figure out the percent of change by dividing the source width
  2181. by the dest width */
  2182. $scale = $src_height / $destination_height;
  2183. $dest_width = $src_width / $scale;
  2184. }
  2185. } else {
  2186. $dest_height = $destination_height;
  2187. $dest_width = $destination_width;
  2188. }
  2189. // Now let's create our destination image with our new height/width
  2190. if (gd_version() >= 2) {
  2191. $dest_img = imageCreateTrueColor($dest_width, $dest_height);
  2192. } else {
  2193. $dest_img = imageCreate($dest_width, $dest_height);
  2194. }
  2195. /* Now let's copy the data from the old picture to the new one with the new settings */
  2196. if (gd_version() >= 2) {
  2197. imageCopyResampled($dest_img, $src_img, 0, 0, 0 ,0, $dest_width, $dest_height, $src_width, $src_height);
  2198. } else {
  2199. imageCopyResized($dest_img, $src_img, 0, 0, 0 ,0, $dest_width, $dest_height, $src_width, $src_height);
  2200. }
  2201. /* Now let's create our new image */
  2202. @imagejpeg($dest_img, $new_image);
  2203. /* Now let's clean up all our temp images */
  2204. imagedestroy($src_img);
  2205. imagedestroy($dest_img);
  2206. // Now we need to kill the old image and move the new one into it's place
  2207. unlink($image);
  2208. rename($new_image,substr($new_image,0,-4));
  2209. return true;
  2210. } else {
  2211. return false;
  2212. }
  2213. }
  2214. /**
  2215. * Same as the above, but returns it instead of displaying it.
  2216. * Useful for use in links.
  2217. *
  2218. * @author Ben Dodson
  2219. * @version 11/10/04
  2220. * @since 11/10/04
  2221. */
  2222. function returnImage ($path, $alt = false, $width = false, $height = false, $method = "limit", $gd = false, $save = false, $align = false, $hspace = false, $vspace = false, $border = "0", $class = false, $linkOnly = false) {
  2223. global $album_img_width, $album_img_height, $allow_filesystem_modify, $root_dir;
  2224. $art = jzCreateLink($path,"image");
  2225. if ($linkOnly){
  2226. return $art;
  2227. }
  2228. $tag = "";
  2229. if ($alt !== false)
  2230. $tag .= "alt=\"$alt\" ";
  2231. $tag .= "title=\"$alt\" ";
  2232. if ($method == "fixed") {
  2233. if ($width !== false)
  2234. $tag .="width=\"$width\" ";
  2235. if ($height !== false)
  2236. $tag .= "height=\"$height\"";
  2237. } else {
  2238. $size = @getimagesize($path);
  2239. $displaywidth = $size[0];
  2240. $displayheight = $size[1];
  2241. if ($size && $size[0] > 0 && $size[1] > 0) {
  2242. switch ($method) {
  2243. case "limit":
  2244. if ($width !== false && $width < $displaywidth) {
  2245. $displayheight = (int)($displayheight * $width / $displaywidth);
  2246. $displaywidth = $width;
  2247. } if ($height && $height < $displayheight) {
  2248. $displaywidth = (int)($displaywidth * $height / $displayheight);
  2249. $displayheight = $height;
  2250. }
  2251. $tag .= "width=\"$displaywidth\" height=\"$displayheight\"";
  2252. break;
  2253. case "fit":
  2254. if ($width !== false) {
  2255. $displayheight = (int)($displayheight * $width / $displaywidth);
  2256. $displaywidth = $width;
  2257. } else if ($height !== false) {
  2258. $displaywidth = (int)($displaywidth * $height / $displayheight);
  2259. $displayheight = $height;
  2260. }
  2261. $tag .= "width=\"$displaywidth\" height=\"$displayheight\"";
  2262. break;
  2263. }
  2264. }
  2265. }
  2266. if ($align){
  2267. $tag .= ' align="'. $align. '" '; }
  2268. if ($vspace){
  2269. $tag .= 'vspace="'. $vspace. '" '; }
  2270. if ($hspace){
  2271. $tag .= ' hspace="'. $hspace. '" '; }
  2272. if ($class){
  2273. $tag .= ' class="'. $class. '" '; }
  2274. // Now let's set the border
  2275. $tag .= ' border="'. $border. '" ';
  2276. return "<img src=\"" . $art . "\" $tag>";
  2277. }
  2278. /**
  2279. * Shows a dropdown.
  2280. *
  2281. * Example:
  2282. *
  2283. * $display = &new jzDisplay();
  2284. * $display->dropdown("genre");
  2285. *
  2286. * @author Ben Dodson
  2287. * @version 10/27/04
  2288. * @since 10/27/04
  2289. */
  2290. function dropdown ($type, $on_submit=true, $select_name="jz_path", $root = false, $return = false) {
  2291. global $hierarchy, $quick_list_truncate;
  2292. $TRUNC = 12;
  2293. $var = $type . "-dropdown";
  2294. $string = "";
  2295. $width = "130px";
  2296. $retVar = '<select name="'. jz_encode($select_name) . '"';
  2297. if ($on_submit) {
  2298. $retVar .= ' onChange="submit()"';
  2299. }
  2300. $retVar .= ' class="jz_select" style="width: '. $width. ';">'. "\n";
  2301. $retVar .= $this->optionList($type,false,true,$root);
  2302. $retVar .= "</select>\n";
  2303. // Now let's set the cached variable
  2304. $_SESSION[$var] = $retVar;
  2305. // Now let's display
  2306. if ($return){
  2307. return $retVar;
  2308. } else {
  2309. echo $retVar;
  2310. }
  2311. }
  2312. /**
  2313. * Echos a list of items of the given type.
  2314. *
  2315. * @author Ben Dodson
  2316. * @version 1/12/05
  2317. * @since 1/12/05
  2318. * @param $type the type of the dropdown (genre/artist/album/track)
  2319. * @param $chosen the preselected value (default none)
  2320. * @param $returnOnly Should we return the value vs echo it
  2321. */
  2322. function optionList($type, $chosen = false, $returnOnly = false, $node = false) {
  2323. global $hierarchy, $quick_list_truncate;
  2324. $string = "";
  2325. if ($node === false) {
  2326. $node = &new jzMediaNode();
  2327. }
  2328. if ($type == "track" || $type == "tracks") {
  2329. $rettype = "leaves";
  2330. $dis = -1;
  2331. } else {
  2332. $rettype = "nodes";
  2333. $dis = distanceTo($type);
  2334. }
  2335. if (!isset($_SESSION['jz_cache_'. $type])){
  2336. $array = $node->getSubNodes($rettype,$dis);
  2337. for ($ctr=0; $ctr < count($array); $ctr++){
  2338. $title = $array[$ctr]->getName();
  2339. $path = $array[$ctr]->getPath("String");
  2340. $parent = $array[$ctr]->getParent();
  2341. $_SESSION['jz_cache_'. $type][$ctr]['title'] = $title;
  2342. $_SESSION['jz_cache_'. $type][$ctr]['path'] = $path;
  2343. $_SESSION['jz_cache_'. $type][$ctr]['parent'] = $parent->getName();
  2344. }
  2345. }
  2346. $array = $_SESSION['jz_cache_'. $type];
  2347. if ($chosen === false) {
  2348. $string .= '<option value="" selected>'. word("Please Choose..."). '</option>';
  2349. }
  2350. for ($ctr=0; $ctr < count($array); $ctr++){
  2351. $title = $array[$ctr]['title'];
  2352. if (strlen($array[$ctr]['title']) > $quick_list_truncate + 3) {
  2353. $title = substr($array[$ctr]['title'],0,$quick_list_truncate). "...";
  2354. }
  2355. $string .= '<option value="'. jz_encode($array[$ctr]['path']) . '"';
  2356. $string .= '>' . $title . '</option>'. "\n";
  2357. }
  2358. if ($returnOnly){
  2359. return $string;
  2360. } else {
  2361. echo $string;
  2362. }
  2363. }
  2364. /**
  2365. * Starts a 'select' box.
  2366. *
  2367. * @author Ben Dodson
  2368. * @version 1/12/05
  2369. * @since 1/12/05
  2370. */
  2371. function openSelect($name, $width = 100,$onchange = false, $return = false) {
  2372. $retVal ='<select';
  2373. $retVal .= ' class="jz_select"';
  2374. $retVal .= ' name=' . $name;
  2375. $retVal .= ' style="width:'. $width . 'px;"';
  2376. if ($onchange) {
  2377. $retVal .= ' onChange="submit()"';
  2378. }
  2379. $retVal .= '>';
  2380. if ($return){
  2381. return $retVal;
  2382. } else {
  2383. echo $retVal;
  2384. }
  2385. }
  2386. /**
  2387. * Closes a 'select' box.
  2388. *
  2389. * @author Ben Dodson
  2390. * @version 1/12/05
  2391. * @since 1/12/05
  2392. */
  2393. function closeSelect($return = false) {
  2394. if ($return){
  2395. return '</select>';
  2396. } else {
  2397. echo '</select>';
  2398. }
  2399. }
  2400. /**
  2401. * Sets up the pages AJAX functions.
  2402. *
  2403. * @author Ben Dodson
  2404. * @version 1/12/05
  2405. * @since 1/12/05
  2406. */
  2407. function handleAJAX() {
  2408. global $include_path,$jukebox,$my_frontend;
  2409. // AJAX:
  2410. $ajax_list = array();
  2411. @include_once($include_path."frontend/frontends/${my_frontend}/ajax.php");
  2412. @include_once($include_path."frontend/frontends/${my_frontend}/ajax_scripts.php");
  2413. @include_once($include_path."frontend/ajax.php");
  2414. @include_once($include_path."frontend/ajax_scripts.php");
  2415. if ($jukebox == "true") {
  2416. include_once($include_path."jukebox/ajax.php");
  2417. include_once($include_path."jukebox/ajax_scripts.php");
  2418. }
  2419. if (sizeof($ajax_list > 0)) { // This frontend has AJAX functions:
  2420. global $sajax_debug_mode, $sajax_export_list, $sajax_request_type, $sajax_remote_uri;
  2421. $sajax_debug_mode = 0;
  2422. include_once($include_path."lib/Sajax.php");
  2423. sajax_init();
  2424. for ($i = 0; $i < sizeof($ajax_list); $i++) {
  2425. sajax_export($ajax_list[$i]);
  2426. }
  2427. echo "\n<script>\n";
  2428. sajax_show_javascript();
  2429. echo "\n</script>\n";
  2430. }
  2431. }
  2432. /**
  2433. * Display the standard javascript
  2434. *
  2435. * @author Ross Carlson
  2436. * @version 5/04/05
  2437. * @since 5/04/05
  2438. */
  2439. function displayJavascript(){
  2440. global $root_dir;
  2441. echo returnJavascript();
  2442. }
  2443. /**
  2444. * Preheader stuff. Things this function handles:
  2445. * title, css, javascript
  2446. * 'morejs' allows you to add page-specific javascript to a page.
  2447. *
  2448. * **should this also set the page width?
  2449. *
  2450. * @author Ben Dodson
  2451. * @version 11/29/04
  2452. * @since 11/29/04
  2453. */
  2454. function preheader ($title = false, $width = "100%", $align = "left", $js = true, $gzip = true, $cms_open = true, $minimal_theme = false) {
  2455. global $css, $cms_type, $site_title, $include_path,
  2456. $root_dir, $node, $live_update, $gzip_handler,
  2457. $jzSERVICES, $skin,$ajax_list,$jukebox,$my_frontend,
  2458. $secure_links;
  2459. // Are they doing gzip compression?
  2460. if (($gzip_handler == "true" and $gzip == true) and $cms_type <> "mambo" and $cms_type <> "cpgnuke") {
  2461. @ob_start('ob_gzhandler');
  2462. }
  2463. $fe = new jzFrontend();
  2464. $display = new jzDisplay();
  2465. $smarty = smartySetup();
  2466. // Now let's see if we need to open a CMS or not?
  2467. if ($cms_open) {
  2468. $jzSERVICES->cmsOpen();
  2469. }
  2470. $css = $jzSERVICES->cmsCSS();
  2471. $showHeader = false;
  2472. if (!isset($cms_mode) || $cms_mode === false || $cms_mode == "false") {
  2473. $showHeader = true;
  2474. $smarty->assign('favicon', $include_path. 'style/favicon.ico');
  2475. $smarty->assign('site_title', $site_title);
  2476. if ($title !== false){
  2477. $smarty->assign('site_title', $site_title. " - ". str_replace("</nobr>","",str_replace("<nobr>","",str_replace("<br>"," ",$title))));
  2478. }
  2479. $smarty->assign('rss_link', $include_path. 'rss.php?type=most-played');
  2480. }
  2481. $smarty->assign('root_dir', $root_dir);
  2482. if (!$minimal_theme) {
  2483. $smarty->assign('css', $css);
  2484. }
  2485. $smarty->assign('skin', $skin);
  2486. $smarty->assign('secure_links', $secure_links);
  2487. $smarty->assign('fav_icon', $root_dir . '/style/favicon.ico');
  2488. // Now let's display the template
  2489. if ($showHeader){
  2490. $smarty->display(SMARTY_ROOT. 'templates/slick/header-pre.tpl');
  2491. }
  2492. // AJAX:
  2493. $this->handleAJAX();
  2494. // Required for overlibs / wherever colors are needed in raw HTML.
  2495. $define_only = true;
  2496. if ($minimal_theme){
  2497. $define_only = true;
  2498. }
  2499. include($css);
  2500. unset($define_only);
  2501. //!! Stuff that requires database is safe beyond this point. !!//
  2502. if ($live_update == "true" && !(isset($_GET['action']) && $_GET['action'] == "search")){
  2503. updateNodeCache($node);
  2504. }
  2505. if (!(isset($_GET['action']) && $_GET['action'] == "search")) {
  2506. handlePageView($node);
  2507. }
  2508. }
  2509. /** Displays a hidden field for the given variable
  2510. * if it is currently set via post/get vars, it keeps that value
  2511. * or it may be set to the given value.
  2512. *
  2513. * @author Ben Dodson
  2514. */
  2515. function hiddenVariableField($type, $value = false, $encode = true, $return = false) {
  2516. if ($value !== false) {
  2517. if ($encode) {
  2518. $retVal = '<input type="hidden" name="' . htmlentities(jz_encode($type)) . '" value="' . htmlentities(jz_encode($value)) . '">';
  2519. } else {
  2520. $retVal = '<input type="hidden" name="' . htmlentities($type) . '" value="' . htmlentities($value) . '">';
  2521. }
  2522. } else if (isset($_POST[$type])) {
  2523. if ($encode) {
  2524. $retVal = '<input type="hidden" name="' . jz_encode($type) . '" value="' . jz_encode($_POST[$type]) . '">';
  2525. } else {
  2526. $retVal = '<input type="hidden" name="' . $type . '" value="' . $_POST[$type] . '">';
  2527. }
  2528. } else if(isset($_GET[$type])) {
  2529. if ($encode) {
  2530. $retVal = '<input type="hidden" name="' . jz_encode($type) . '" value="' . jz_encode($_GET[$type]) . '">';
  2531. } else {
  2532. $retVal = '<input type="hidden" name="' . $type . '" value="' . $_GET[$type] . '">';
  2533. }
  2534. }
  2535. if ($return){
  2536. return $retVal;
  2537. } else {
  2538. echo $retVal;
  2539. }
  2540. }
  2541. /**
  2542. * turns CMS GET variables into hidden fields
  2543. * This helps make a GET-based form possible with a CMS.
  2544. *
  2545. * @author Ben Dodson
  2546. * @version 6/1/05
  2547. * @since 6/1/05
  2548. **/
  2549. function hiddenPageVars($return = false) {
  2550. global $cms_mode,$cms_type,$jzSERVICES,$this_page;
  2551. /*
  2552. $ar = $jzSERVICES->cmsGETVars();
  2553. foreach ($ar as $id => $val) {
  2554. $this->hiddenVariableField($id,$val,false);
  2555. }
  2556. */
  2557. // Make it pull straight from a 'good' base URL so we don't miss anything.
  2558. $url = urlize();
  2559. $url = explode("?",$url);
  2560. $url = $url[1];
  2561. $url = explode("&",$url);
  2562. $ret = '';
  2563. foreach ($url as $entry) {
  2564. $t = explode("=",$entry);
  2565. if ($return){
  2566. $ret .= $this->hiddenVariableField(urldecode($t[0]),urldecode($t[1]),false,true);
  2567. } else {
  2568. $this->hiddenVariableField(urldecode($t[0]),urldecode($t[1]),false);
  2569. }
  2570. }
  2571. if ($return){
  2572. return $ret;
  2573. }
  2574. }
  2575. /**
  2576. * Echos the extra code needed
  2577. * to make the embedded player
  2578. * work in a new window during
  2579. * a form submit.
  2580. *
  2581. * @author Ben Dodson
  2582. * @version 4/17/05
  2583. * @since 4/17/05
  2584. **/
  2585. function embeddedFormHandler($formname = false) {
  2586. global $jzUSER, $jzSERVICES;
  2587. if ($formname === false) {
  2588. $formname = "albumForm";
  2589. }
  2590. if (checkPlayback() == "embedded") {
  2591. // Ok, let's put the popup in the href
  2592. return $jzSERVICES->returnPlayerFormLink($formname);
  2593. }
  2594. }
  2595. }
  2596. // EVERYTHING HERE IS OLD AND [HOPEFULLY] NOT NEEDED.
  2597. // I left it because I didn't want to break anything, since
  2598. // this is more of a proof of concept than anything else.
  2599. // Now let's put in all the standard display functions...
  2600. /**
  2601. * returns the HTML code for the CMS stylesheet
  2602. *
  2603. * @author Ross Carlson
  2604. * @version 04/29/04
  2605. * @since 04/29/04
  2606. * @return returns HTML code for the javascript includes
  2607. */
  2608. function returnCMSCSS(){
  2609. global $bgcolor1, $bgcolor3;
  2610. return "<style type=\"text/css\">.jz_row1 { background-color:$bgcolor1; } .jz_row2 { background-color:$bgcolor3; }</style>";
  2611. }
  2612. /**
  2613. * returns the HTML code for the stylesheet
  2614. *
  2615. * @author Ross Carlson
  2616. * @version 04/29/04
  2617. * @since 04/29/04
  2618. * @return returns HTML code for the javascript includes
  2619. */
  2620. function returnCSS(){
  2621. global $css;
  2622. return $css;
  2623. }
  2624. /**
  2625. * returns the HTML code to close the head
  2626. *
  2627. * @author Ross Carlson
  2628. * @version 04/29/04
  2629. * @since 04/29/04
  2630. * @return returns HTML code for the javascript includes
  2631. */
  2632. function returnCloseHTMLHead(){
  2633. return '</head>';
  2634. }
  2635. /**
  2636. * returns the HTML code to open the HEAD tag
  2637. *
  2638. * @author Ross Carlson
  2639. * @version 04/29/04
  2640. * @since 04/29/04
  2641. * @return returns HTML code for the javascript includes
  2642. */
  2643. function returnHTMLHead($title){
  2644. global $root_dir, $site_title;
  2645. $site = $_SERVER["HTTP_HOST"];
  2646. if ($_SERVER['HTTPS'] == "on"){ $site = "https://". $site; } else { $site = "http://". $site; }
  2647. return '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><link rel="shortcut icon" href="'. $root_dir. '/style/favicon.ico">'. "\n".
  2648. '<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>'. "\n".
  2649. $site_title. " - ". str_replace("</nobr>","",str_replace("<nobr>","",str_replace("<br>"," ",$title))). "</title>". "\n".
  2650. '<link rel="alternate" type="application/rss+xml" title="Jinzora Most Played" href="'. $root_dir. '/rss.php?type=most-played">'. "\n";
  2651. }
  2652. /**
  2653. * returns the HTML code for the Javascript includes
  2654. *
  2655. * @author Ross Carlson
  2656. * @version 04/29/04
  2657. * @since 04/29/04
  2658. * @return returns HTML code for the javascript includes
  2659. */
  2660. function returnJavascript(){
  2661. global $root_dir, $enable_ratings;
  2662. $js = '<script type="text/javascript" src="'. $root_dir. '/lib/jinzora.js"></script>'.
  2663. '<script type="text/javascript" src="'. $root_dir. '/lib/overlib.js"></script>'.
  2664. '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'.
  2665. '<script type="text/javascript" src="'. $root_dir. '/lib/jquery/jquery.js"></script>';
  2666. if ($enable_ratings == "true") {
  2667. $js .= '<script type="text/javascript" src="'. $root_dir. '/lib/jquery/rater.js"></script>'.
  2668. '<link rel="stylesheet" type="text/css" href="'. $root_dir. '/lib/jquery/rater/rater.css.php" />';
  2669. }
  2670. return $js;
  2671. }
  2672. /**
  2673. * returns the HTML code to block right clicking
  2674. *
  2675. * @author Ross Carlson
  2676. * @version 04/29/04
  2677. * @since 04/29/04
  2678. * @return returns HTML (javascript) code to block right clicks
  2679. */
  2680. function displaySecureLinks(){
  2681. global $secure_links;
  2682. if ($secure_links == "true"){
  2683. $retVal = '<SCRIPT LANGUAGE="JavaScript1.1">'. "\n";
  2684. $retVal .= 'function noContext(){return false;}'. "\n";
  2685. $retVal .= 'document.oncontextmenu = noContext;'. "\n";
  2686. $retVal .= '// -->'. "\n";
  2687. $retVal .= '</script>'. "\n";
  2688. return $retVal;
  2689. } else {
  2690. return false;
  2691. }
  2692. }
  2693. /**
  2694. * returns the HTML for a drop down list of any type.
  2695. *
  2696. * @author Ben Dodson, Ross Carlson
  2697. * @version 6/9/04
  2698. * @since 6/9/04
  2699. * @param $onclick Should the select box submit on click?
  2700. * @param $boxname What is the name of the select box
  2701. * @param $width Width in pixels
  2702. * @param $type Type of dropdown
  2703. * @param $path Restraining path (defaults to empty). Can be string or array.
  2704. */
  2705. // TODO:
  2706. // 1) Test this; where is it being called from?
  2707. // Why is /display.php's functions still being called?
  2708. function returnSelect($onclick, $boxname, $width, $type = "genre", $node = false){
  2709. global $hierarchy, $quick_list_truncate;
  2710. if ($node === false) {
  2711. $node = &new jzMediaNode();
  2712. }
  2713. $i = 0;
  2714. while ($i < sizeof($hierarchy)) {
  2715. if ($hierarchy[$i] == $type) {
  2716. if ($type == "track") {
  2717. $rettype = "leaves";
  2718. } else {
  2719. $rettype = "nodes";
  2720. }
  2721. $array = $node->getSubNodes($rettype,$i - $node->getLevel(),false,0);
  2722. if ($onclick){
  2723. $retVal = '<select name="'. $boxname. '" onChange="submit()" class="jz_select" style="width: '. $width. 'px;">'. "\n";
  2724. } else {
  2725. $retVal = '<select name="'. $boxname. '" class="jz_select" style="width: '. $width. 'px;">'. "\n";
  2726. }
  2727. $retVal .= '<option value="" selected>'. word("Please Choose..."). '</option>';
  2728. for ($ctr=0; $ctr < count($array); $ctr++){
  2729. $fulltitle = $array[$ctr]->getName();
  2730. $title = $fulltitle;
  2731. if (strlen($title) > $quick_list_truncate + 3) {
  2732. $title = substr($title,0,$quick_list_truncate). "...";
  2733. }
  2734. $retVal .= '<option value="'. $fulltitle. '">'. $title. '</option>'. "\n";
  2735. }
  2736. $retVal .= '</select>'. "\n";
  2737. return $retVal;
  2738. }
  2739. }
  2740. return;
  2741. }
  2742. /**
  2743. * returns the HTML for the drop down list of Albums
  2744. *
  2745. * @author Ross Carlson
  2746. * @version 6/9/04
  2747. * @since 04/29/04
  2748. * @param $onclick Should the select box submit on click?
  2749. * @param $boxname What is the name of the select box
  2750. * @param $width Width in pixels
  2751. */
  2752. // If this fails miserably,
  2753. // we have the code in /display.php.
  2754. function returnAlbumSelect($onclick, $boxname, $width){
  2755. return returnSelect($onclick,$boxname,$width,"album");
  2756. }
  2757. /**
  2758. * returns the HTML for the drop down list of Artists
  2759. *
  2760. * @author Ross Carlson
  2761. * @version 04/29/04
  2762. * @since 04/29/04
  2763. * @param $onclick Should the select box submit on click?
  2764. * @param $boxname What is the name of the select box
  2765. * @param $width Width in pixels
  2766. */
  2767. function returnArtistSelect($onclick, $boxname, $width){
  2768. return returnSelect($onclick,$boxname,$width,"artist");
  2769. }
  2770. /**
  2771. * returns the HTML for the drop down list of Genres
  2772. *
  2773. * @author Ross Carlson
  2774. * @version 04/29/04
  2775. * @since 04/29/04
  2776. * @param $onclick Should the select box submit on click?
  2777. * @param $boxname What is the name of the select box
  2778. * @param $width Width in pixels
  2779. */
  2780. function returnGenreSelect($onclick, $boxname, $width){
  2781. return returnSelect($onclick,$boxname,$width,"genre");
  2782. }
  2783. /* This function displays the login page then authenticaes the user for admin level access */
  2784. function displayLogin(){
  2785. global $main_table_width, $cellspacing, $this_page, $url_seperator;
  2786. // Let's show the header
  2787. displayHeader(word("Login"));
  2788. $formAction = $this_page;
  2789. ?>
  2790. <form action="<?php echo $formAction; ?>" method="post">
  2791. <input type="hidden" name="returnPage" value="<?php echo $_GET['return']; ?>">
  2792. <table width="<?php echo $main_table_width; ?>%" cellpadding="<?php echo $cellspacing; ?>" cellspacing="0" border="0">
  2793. <tr>
  2794. <td width="50%" align="right">
  2795. <font size="2">
  2796. <?php echo word("Username"); ?>
  2797. </font>
  2798. </td>
  2799. <td width="50%">
  2800. <input class="jz_input" type="text" name="username">
  2801. </td>
  2802. </tr>
  2803. <tr>
  2804. <td width="50%" align="right">
  2805. <font size="2">
  2806. <?php echo word("Password"); ?>
  2807. </font>
  2808. </td>
  2809. <td width="50%">
  2810. <input class="jz_input" type="password" name="admin_pass">
  2811. </td>
  2812. </tr>
  2813. <tr>
  2814. <td width="50%" align="right">
  2815. </td>
  2816. <td width="50%">
  2817. <font size="2">
  2818. <input class="jz_checkbox" type="checkbox" name="remember_me"> <?php echo word("Remember me"); ?>
  2819. </font>
  2820. </td>
  2821. </tr>
  2822. <tr>
  2823. <td width="100%" colspan="2" align="center">
  2824. <input class="jz_submit" type="submit" name="submit_login" value="<?php echo word("Login"); ?>">
  2825. </td>
  2826. </tr>
  2827. </table>
  2828. </form>
  2829. <?php
  2830. }
  2831. ?>