PageRenderTime 78ms CodeModel.GetById 21ms 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

Large files files are truncated, but you can click here to view the full 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 C…

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