helpers.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. Template.admin.helpers({
  2. queueCount: function () {
  3. return Queues.find().count();
  4. },
  5. genreQueue: function(type) {
  6. if (type === "none") {
  7. return Queues.find({genres: []}).count();
  8. } else {
  9. return Queues.find({genres: type}).count();
  10. }
  11. },
  12. alertsList: function() {
  13. return Alerts.find({});
  14. },
  15. queues: function () {
  16. var queues = Queues.find({}).fetch();
  17. return queues;
  18. },
  19. usersOnline: function () {
  20. Meteor.call("getUserNum", function (err, num) {
  21. if (err) {
  22. console.log(err);
  23. }
  24. Session.set("userNum", num);
  25. });
  26. return Session.get("userNum");
  27. },
  28. roomUserNum: function () {
  29. var type = this.type;
  30. var userNum = Rooms.findOne({type: type}).users;
  31. return userNum;
  32. },
  33. allUsers: function () {
  34. Meteor.call("getTotalUsers", function (err, num) {
  35. Session.set("allUsers", num);
  36. })
  37. return Session.get("allUsers");
  38. },
  39. playlists: function () {
  40. var playlists = Playlists.find({}).fetch();
  41. playlists.map(function (playlist) {
  42. if (Rooms.find({type: playlist.type}).count() !== 1) {
  43. return;
  44. } else {
  45. playlist.display = Rooms.findOne({type: playlist.type}).display;
  46. return playlist;
  47. }
  48. });
  49. return playlists;
  50. },
  51. reportsCount: function (room) {
  52. room = room.toLowerCase();
  53. var reports = Reports.findOne({room: room});
  54. return reports && "report" in reports ? reports.report.length : 0;
  55. }
  56. });
  57. Template.alerts.helpers({
  58. alerts: function () {
  59. var alerts = Alerts.find({active: true}).fetch();
  60. alerts = alerts.map(function(alert) {
  61. alert.description = replaceURLWithHTMLLinksBlank(alert.description);
  62. return alert;
  63. });
  64. return alerts;
  65. }
  66. });
  67. Template.banned.helpers({
  68. bannedAt: function () {
  69. if (Session.get("ban") !== undefined) {
  70. return Session.get("ban").bannedAt;
  71. }
  72. },
  73. bannedBy: function () {
  74. if (Session.get("ban") !== undefined) {
  75. return Session.get("ban").bannedBy;
  76. }
  77. },
  78. bannedUntil: function () {
  79. if (Session.get("ban") !== undefined) {
  80. return Session.get("ban").bannedUntil;
  81. }
  82. },
  83. bannedReason: function () {
  84. if (Session.get("ban") !== undefined) {
  85. return Session.get("ban").bannedReason;
  86. }
  87. }
  88. });
  89. Template.feedback.helpers({
  90. feedback: function () {
  91. return Feedback.find().fetch().reverse();
  92. }
  93. })
  94. Template.header.helpers({
  95. userId: function () {
  96. return Meteor.userId();
  97. }
  98. });
  99. Template.home.helpers({
  100. currentSong: function () {
  101. var type = this.type;
  102. var room = Rooms.findOne({type: type});
  103. if (room !== undefined) {
  104. return room.currentSong;
  105. } else {
  106. return false;
  107. }
  108. },
  109. userNum: function () {
  110. var type = this.type;
  111. var userNum = Rooms.findOne({type: type}).users;
  112. return userNum;
  113. },
  114. currentPrivateSong: function () {
  115. var name = this.name;
  116. var room = CommunityStations.findOne({name: name});
  117. if (room !== undefined) {
  118. return room.currentSong;
  119. } else {
  120. return false;
  121. }
  122. },
  123. userPrivateNum: function () {
  124. var name = this.name;
  125. var userNum = CommunityStations.findOne({name: name}).users;
  126. return userNum;
  127. }
  128. });
  129. Template.playlist.helpers({
  130. playlist_songs: function () {
  131. var songIDs = Playlists.find({"type": Session.get("type")}).fetch()[0].songs
  132. var data = [];
  133. songIDs.forEach(function(id){
  134. var song = Songs.findOne({"mid": id});
  135. data.push(song);
  136. })
  137. if (data !== undefined) {
  138. data.map(function (song) {
  139. if (Session.get("currentSong") !== undefined && song.mid === Session.get("currentSong").mid) {
  140. song.current = true;
  141. } else {
  142. song.current = false;
  143. }
  144. return song;
  145. });
  146. return data;
  147. } else {
  148. return [];
  149. }
  150. },
  151. nextSong: function(){
  152. var song;
  153. var data = Playlists.find({"type": Session.get("type")}).fetch()[0].songs;
  154. for(var i = 0; i < data.length; i++){
  155. if(Session.get("currentSong") !== undefined && data[i] === Session.get("currentSong").mid){
  156. if(i === data.length - 1){
  157. song = Songs.findOne({"mid": data[0]});
  158. Session.set("nextSong", [song])
  159. } else{
  160. song = Songs.findOne({"mid": data[i+1]});
  161. Session.set("nextSong", [song]);
  162. }
  163. }
  164. }
  165. return Session.get("nextSong");
  166. }
  167. });
  168. Template.profile.helpers({
  169. "real_name": function () {
  170. return Session.get("real_name");
  171. },
  172. "username": function () {
  173. return Session.get("username")
  174. },
  175. "first_joined": function () {
  176. return moment(Session.get("first_joined")).format("DD/MM/YYYY");
  177. },
  178. "rank": function () {
  179. return Session.get("rank");
  180. },
  181. "songs_requested": function () {
  182. return Session.get("songs_requested");
  183. },
  184. loaded: function () {
  185. return Session.get("loaded");
  186. },
  187. likedSongs: function () {
  188. var likedArr = [];
  189. var liked = Session.get("liked");
  190. if (liked !== undefined) {
  191. liked.forEach(function (mid) {
  192. Songs.find().forEach(function (data) {
  193. if (data.mid === mid) {
  194. likedArr.push({title: data.title, artist: data.artist});
  195. }
  196. });
  197. });
  198. }
  199. return likedArr;
  200. },
  201. dislikedSongs: function () {
  202. var dislikedArr = [];
  203. var disliked = Session.get("disliked");
  204. if (disliked !== undefined) {
  205. disliked.forEach(function (mid) {
  206. Songs.find().forEach(function (data) {
  207. if (data.mid === mid) {
  208. dislikedArr.push({title: data.title, artist: data.artist});
  209. }
  210. });
  211. });
  212. }
  213. return dislikedArr;
  214. },
  215. isUser: function () {
  216. var parts = Router.current().url.split('/');
  217. var username = parts.pop();
  218. if (username === Meteor.user().profile.username) {
  219. return true;
  220. }
  221. }
  222. });
  223. Template.queues.helpers({
  224. songs: function () {
  225. return Queues.find({}).fetch();
  226. },
  227. song_image: function() {
  228. return Session.get("image_url");
  229. }
  230. });
  231. Template.news.helpers({
  232. articles: function() {
  233. var articles = News.find().fetch().reverse();
  234. articles = articles.map(function(article) {
  235. article.content = replaceURLWithHTMLLinksBlank(article.content);
  236. return article;
  237. });
  238. return articles;
  239. }
  240. });
  241. Template.manageSongs.helpers({
  242. songs: function () {
  243. var noGenres = Session.get("showNoGenres");
  244. var genres = Session.get("showGenres");
  245. if (noGenres === true && genres === true) {
  246. return Songs.find();
  247. } else if (noGenres === true && genres === false) {
  248. return Songs.find({genres: []});
  249. } else {
  250. return Songs.find({$where : "this.genres.length > 0"});
  251. }
  252. },
  253. song_image: function() {
  254. return Session.get("image_url");
  255. }
  256. });
  257. Template.manageStation.helpers({
  258. editingDesc: function() {
  259. return Session.get("editingDesc");
  260. },
  261. description: function() {
  262. var parts = location.href.split('/');
  263. parts.pop();
  264. var id = parts.pop();
  265. var type = id.toLowerCase();
  266. return Rooms.findOne({type: type}).roomDesc;
  267. },
  268. songs: function () {
  269. var parts = location.href.split('/');
  270. parts.pop();
  271. var id = parts.pop();
  272. var type = id.toLowerCase();
  273. var playlist = Playlists.findOne({type: type});
  274. var songs = [];
  275. if (playlist !== undefined && playlist.songs !== undefined) {
  276. playlist.songs.forEach(function(songMid) {
  277. songs.push(Songs.findOne({mid: songMid}));
  278. });
  279. }
  280. return songs;
  281. },
  282. song_image: function() {
  283. return Session.get("image_url");
  284. },
  285. genre: function() {
  286. var parts = location.href.split('/');
  287. parts.pop();
  288. var id = parts.pop();
  289. var type = id.toLowerCase();
  290. return type;
  291. },
  292. reports: function() {
  293. var parts = location.href.split('/');
  294. parts.pop();
  295. var id = parts.pop();
  296. var query = {room: id.toLowerCase()};
  297. var reports = Reports.find(query).fetch();
  298. return reports;
  299. }
  300. });
  301. Template.room.helpers({
  302. currentSongR: function() {
  303. return Session.get("currentSongR");
  304. },
  305. previousSongR: function() {
  306. return Session.get("previousSongR");
  307. },
  308. editingSong: function() {
  309. return Session.get("editingSong");
  310. },
  311. singleVideoResults: function () {
  312. return Session.get("songResults");
  313. },
  314. singleVideoResultsActive: function() {
  315. var songs = Session.get("songResults");
  316. if (songs !== undefined && songs.length > 0) {
  317. return true;
  318. } else {
  319. return false;
  320. }
  321. },
  322. importPlaylistVideos: function () {
  323. return Session.get("songResults");
  324. },
  325. playlistImportVideosActive: function() {
  326. var songs = Session.get("songResults");
  327. if (songs !== undefined && songs.length > 0) {
  328. return true;
  329. } else {
  330. return false;
  331. }
  332. },
  333. singleVideo: function () {
  334. return Session.get("si_or_pl") === "singleVideo";
  335. },
  336. chat: function () {
  337. Meteor.setTimeout(function () {
  338. var elem = document.getElementById('chat');
  339. if (elem !== undefined && elem !== null) {
  340. elem.scrollTop = elem.scrollHeight;
  341. }
  342. }, 100);
  343. return Chat.find({type: Session.get("type")}, {sort: {time: -1}, limit: 50}).fetch().reverse();
  344. },
  345. globalChat: function () {
  346. Meteor.setTimeout(function () {
  347. var elem = document.getElementById('global-chat');
  348. if (elem !== undefined && elem !== null) {
  349. elem.scrollTop = elem.scrollHeight;
  350. }
  351. }, 100);
  352. var messages = Chat.find({type: "global"}, {sort: {time: -1}, limit: 50}).fetch().reverse();
  353. messages = messages.map(function(message) {
  354. message.message = replaceURLWithHTMLLinks(message.message);
  355. return message;
  356. });
  357. return messages;
  358. },
  359. likes: function () {
  360. var playlist = Songs.find({"genres": Session.get("type")}).fetch();
  361. var likes = 0;
  362. playlist.forEach(function (song) {
  363. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  364. likes = song.likes;
  365. return;
  366. }
  367. });
  368. return likes;
  369. },
  370. dislikes: function () {
  371. var playlist = Songs.find({"genres": Session.get("type")}).fetch();
  372. var dislikes = 0;
  373. playlist.forEach(function (song) {
  374. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  375. dislikes = song.dislikes;
  376. return;
  377. }
  378. });
  379. return dislikes;
  380. },
  381. liked: function () {
  382. if (Meteor.userId()) {
  383. var currentSong = Session.get("currentSong");
  384. if (currentSong && Meteor.user().profile.liked.indexOf(currentSong.mid) !== -1) {
  385. return "liked";
  386. } else {
  387. return "";
  388. }
  389. } else {
  390. "";
  391. }
  392. },
  393. disliked: function () {
  394. if (Meteor.userId()) {
  395. var currentSong = Session.get("currentSong");
  396. if (currentSong && Meteor.user().profile.disliked.indexOf(currentSong.mid) !== -1) {
  397. return "disliked";
  398. } else {
  399. return "";
  400. }
  401. } else {
  402. "";
  403. }
  404. },
  405. type: function () {
  406. var parts = location.href.split('/');
  407. var id = parts.pop().toLowerCase();
  408. return Rooms.findOne({type: id}).display;
  409. },
  410. users: function () {
  411. var parts = location.href.split('/');
  412. var id = parts.pop().toLowerCase();
  413. return Rooms.findOne({type: id}).users;
  414. },
  415. title: function () {
  416. return Session.get("title");
  417. },
  418. artist: function () {
  419. return Session.get("artist");
  420. },
  421. loaded: function () {
  422. return Session.get("loaded");
  423. },
  424. paused: function () {
  425. var room = Rooms.findOne({type: Session.get("type")});
  426. if (room !== undefined) {
  427. return room.state === "paused";
  428. } else {
  429. return false;
  430. }
  431. },
  432. private: function () {
  433. var room = Rooms.findOne({type: Session.get("type")});
  434. if (room !== undefined) {
  435. return room.private === true;
  436. } else {
  437. return false;
  438. }
  439. //return Rooms.findOne({type: Session.get("type")}).private === true;
  440. },
  441. currentSong: function(){
  442. return Session.get("currentSong");
  443. },
  444. reportingSong: function() {
  445. if (!Session.get("reportPrevious")) {
  446. return Session.get("currentSongR");
  447. } else {
  448. return Session.get("previousSongR");
  449. }
  450. },
  451. reportSong: function(){
  452. Meteor.setInterval(function(){
  453. if($("#report-song").is(":checked")){
  454. Session.set("reportSong", true)
  455. } else { Session.set("reportSong", false) }
  456. }, 500);
  457. return Session.get("reportSong");
  458. },
  459. reportSongOther: function(){
  460. Meteor.setInterval(function(){
  461. if($("#report-song-other").is(":checked")){
  462. Session.set("reportSongOther", true)
  463. } else { Session.set("reportSongOther", false) }
  464. }, 500);
  465. return Session.get("reportSongOther");
  466. },
  467. reportTitle: function(){
  468. Meteor.setInterval(function(){
  469. if($("#report-title").is(":checked")){
  470. Session.set("reportTitle", true)
  471. } else { Session.set("reportTitle", false) }
  472. }, 500);
  473. return Session.get("reportTitle");
  474. },
  475. reportTitleOther: function(){
  476. Meteor.setInterval(function(){
  477. if($("#report-title-other").is(":checked")){
  478. Session.set("reportTitleOther", true)
  479. } else { Session.set("reportTitleOther", false) }
  480. }, 500);
  481. return Session.get("reportTitleOther");
  482. },
  483. reportArtist: function(){
  484. Meteor.setInterval(function(){
  485. if($("#report-artist").is(":checked")){
  486. Session.set("reportArtist", true)
  487. } else { Session.set("reportArtist", false) }
  488. }, 500);
  489. return Session.get("reportArtist");
  490. },
  491. reportArtistOther: function(){
  492. Meteor.setInterval(function(){
  493. if($("#report-artist-other").is(":checked")){
  494. Session.set("reportArtistOther", true)
  495. } else { Session.set("reportArtistOther", false) }
  496. }, 500);
  497. return Session.get("reportArtistOther");
  498. },
  499. reportDuration: function(){
  500. Meteor.setInterval(function(){
  501. if($("#report-duration").is(":checked")){
  502. Session.set("reportDuration", true)
  503. } else { Session.set("reportDuration", false) }
  504. }, 500);
  505. return Session.get("reportDuration");
  506. },
  507. reportDurationOther: function(){
  508. Meteor.setInterval(function(){
  509. if($("#report-duration-other").is(":checked")){
  510. Session.set("reportDurationOther", true)
  511. } else { Session.set("reportDurationOther", false) }
  512. }, 500);
  513. return Session.get("reportDurationOther");
  514. },
  515. reportAlbumart: function(){
  516. Meteor.setInterval(function(){
  517. if($("#report-albumart").is(":checked")){
  518. Session.set("reportAlbumart", true)
  519. } else { Session.set("reportAlbumart", false) }
  520. }, 500);
  521. return Session.get("reportAlbumart");
  522. },
  523. reportAlbumartOther: function(){
  524. Meteor.setInterval(function(){
  525. if($("#report-albumart-other").is(":checked")){
  526. Session.set("reportAlbumartOther", true)
  527. } else { Session.set("reportAlbumartOther", false) }
  528. }, 500);
  529. return Session.get("reportAlbumartOther");
  530. },
  531. reportOther: function(){
  532. Meteor.setInterval(function(){
  533. if($("#report-other").is(":checked")){
  534. Session.set("reportOther", true)
  535. } else { Session.set("reportOther", false) }
  536. }, 500);
  537. return Session.get("reportOther");
  538. },
  539. votes: function () {
  540. return Rooms.findOne({type: Session.get("type")}).votes;
  541. },
  542. usersInRoom: function(){
  543. var userList = [];
  544. var roomUserList = Rooms.findOne({type: Session.get("type")}).userList;
  545. roomUserList.forEach(function(user){
  546. if(userList.indexOf(user) === -1){
  547. userList.push(user);
  548. }
  549. })
  550. return userList;
  551. }
  552. });
  553. Template.communityStation.helpers({
  554. playlistQueueSelected: function(name) {
  555. return Session.get("playlistQueueName") === name;
  556. },
  557. getUsername: function(id) {
  558. return Meteor.users.findOne(id).profile.username;
  559. },
  560. queue: function() {
  561. var name = Session.get("CommunityStationName");
  562. var room = CommunityStations.findOne({name: name});
  563. if (room !== undefined && room.partyModeEnabled === true) {
  564. return room.queue;
  565. } else {
  566. return [];
  567. }
  568. },
  569. noCurrentSong: function() {
  570. return Session.get("noCurrentSong");
  571. },
  572. noCurrentSongHidden: function() {
  573. if (Session.get("noCurrentSong")) {
  574. return "hidden";
  575. } else {
  576. return "";
  577. }
  578. },
  579. partyModeChecked: function() {
  580. var name = Session.get("CommunityStationName");
  581. var room = CommunityStations.findOne({name: name});
  582. if (room !== undefined && room.partyModeEnabled === true) {
  583. return "checked";
  584. } else {
  585. return "";
  586. }
  587. },
  588. queueLockedChecked: function() {
  589. var name = Session.get("CommunityStationName");
  590. var room = CommunityStations.findOne({name: name});
  591. if (room !== undefined && room.queueLocked === true) {
  592. return "checked";
  593. } else {
  594. return "";
  595. }
  596. },
  597. partyModeEnabled: function() {
  598. var name = Session.get("CommunityStationName");
  599. var room = CommunityStations.findOne({name: name});
  600. if (room !== undefined && room.partyModeEnabled === true) {
  601. return true;
  602. } else {
  603. return false;
  604. }
  605. },
  606. partyModeEnabledHidden: function() {
  607. var name = Session.get("CommunityStationName");
  608. var room = CommunityStations.findOne({name: name});
  609. if (room !== undefined && room.partyModeEnabled === true) {
  610. return "";
  611. } else {
  612. return "hidden";
  613. }
  614. },
  615. singleVideoResults: function() {
  616. return Session.get("songResults");
  617. },
  618. singleVideoResultsQueue: function() {
  619. return Session.get("songResultsQueue");
  620. },
  621. singleVideoResultsActive: function() {
  622. var songs = Session.get("songResults");
  623. if (songs !== undefined && songs.length > 0) {
  624. return true;
  625. } else {
  626. return false;
  627. }
  628. },
  629. singleVideoResultsActiveQueue: function() {
  630. var songs = Session.get("songResultsQueue");
  631. if (songs !== undefined && songs.length > 0) {
  632. return true;
  633. } else {
  634. return false;
  635. }
  636. },
  637. hasMoreThanOne: function(array) {
  638. if (array.length > 1) {
  639. return true;
  640. } else {
  641. return false;
  642. }
  643. },
  644. isFirst: function(object, array) {
  645. if (_.isEqual(array[0], object) && array.length > 1) {
  646. return true;
  647. } else {
  648. return false;
  649. }
  650. },
  651. isLast: function(object, array) {
  652. if (_.isEqual(array[array.length - 1], object) && array.length > 1) {
  653. return true;
  654. } else {
  655. return false;
  656. }
  657. },
  658. communityStationOwnerName: function() {
  659. var room = CommunityStations.findOne({name: Session.get("CommunityStationName")});
  660. if (room !== undefined) {
  661. return Meteor.users.findOne(room.owner).profile.username;
  662. } else {
  663. return "";
  664. }
  665. },
  666. editingPlaylist: function() {
  667. return PrivatePlaylists.findOne({owner: Meteor.userId(), name: Session.get("editingPlaylistName")});
  668. },
  669. isPlaylistSelected: function(roomName, playlistName) {
  670. return CommunityStations.findOne({name: roomName}).playlist === playlistName;
  671. },
  672. getSelected: function(val1, val2) {
  673. if (val1 === val2) {
  674. return "selected";
  675. } else {
  676. return "";
  677. }
  678. },
  679. globalChat: function () {
  680. Meteor.setTimeout(function () {
  681. var elem = document.getElementById('global-chat');
  682. if (elem !== undefined && elem !== null) {
  683. elem.scrollTop = elem.scrollHeight;
  684. }
  685. }, 100);
  686. var messages = Chat.find({type: "global"}, {sort: {time: -1}, limit: 50}).fetch().reverse();
  687. messages = messages.map(function(message) {
  688. message.message = replaceURLWithHTMLLinks(message.message);
  689. return message;
  690. });
  691. return messages;
  692. },
  693. communityStationDisplayName: function () {
  694. var parts = location.href.split('/');
  695. var id = parts.pop().toLowerCase();
  696. return CommunityStations.findOne({name: id}).displayName;
  697. },
  698. name: function () {
  699. var parts = location.href.split('/');
  700. var id = parts.pop().toLowerCase();
  701. return id;
  702. },
  703. users: function () {
  704. var parts = location.href.split('/');
  705. var id = parts.pop().toLowerCase();
  706. return CommunityStations.findOne({name: id}).userList.length;
  707. },
  708. allowed: function () {
  709. var parts = location.href.split('/');
  710. var id = parts.pop().toLowerCase();
  711. var arr = [];
  712. CommunityStations.findOne({name: id}).allowed.forEach(function(allowed) {
  713. arr.push({name: Meteor.users.findOne(allowed).profile.username, id: allowed});
  714. });
  715. return arr;
  716. },
  717. playlists: function () {
  718. return PrivatePlaylists.find({owner: Meteor.userId()});
  719. },
  720. title: function () {
  721. return Session.get("title");
  722. },
  723. loaded: function () {
  724. return Session.get("loaded");
  725. },
  726. paused: function () {
  727. var room = CommunityStations.findOne({name: Session.get("CommunityStationName")});
  728. if (room !== undefined) {
  729. return room.state === "paused";
  730. } else {
  731. return false;
  732. }
  733. },
  734. private: function () {
  735. var room = CommunityStations.findOne({name: Session.get("CommunityStationName")});
  736. if (room !== undefined) {
  737. return room.private;
  738. } else {
  739. return 1;
  740. }
  741. },
  742. playing: function() {
  743. var room = CommunityStations.findOne({name: Session.get("CommunityStationName")});
  744. if (room !== undefined) {
  745. return room.state === "playing";
  746. } else {
  747. return false;
  748. }
  749. },
  750. playingHidden: function() {
  751. var room = CommunityStations.findOne({name: Session.get("CommunityStationName")});
  752. if (room !== undefined) {
  753. return (room.state === "playing") ? "hidden" : "";
  754. } else {
  755. return "";
  756. }
  757. },
  758. pausedHidden: function() {
  759. var room = CommunityStations.findOne({name: Session.get("CommunityStationName")});
  760. if (room !== undefined) {
  761. return (room.state === "paused") ? "hidden" : "";
  762. } else {
  763. return "";
  764. }
  765. },
  766. currentSong: function(){
  767. return Session.get("currentSong");
  768. },
  769. votes: function () {
  770. var room = CommunityStations.findOne({name: Session.get("CommunityStationName")});
  771. if (room !== undefined) {
  772. return room.votes;
  773. } else {
  774. return 0;
  775. }
  776. },
  777. usersInRoom: function() {
  778. var userList = [];
  779. var room = CommunityStations.findOne({name: Session.get("CommunityStationName")});
  780. if (room !== undefined) {
  781. var roomUserList = room.userList;
  782. roomUserList.forEach(function (user) {
  783. if (userList.indexOf(user) === -1) {
  784. userList.push(user);
  785. }
  786. })
  787. }
  788. return userList;
  789. },
  790. room: function() {
  791. var parts = location.href.split('/');
  792. var id = parts.pop().toLowerCase();
  793. setTimeout(function() {
  794. Materialize.updateTextFields();
  795. }, 100);
  796. return CommunityStations.findOne({name: id});
  797. },
  798. importingPlaylist: function() {
  799. return Session.get("importingPlaylist");
  800. }
  801. });
  802. Template.settings.helpers({
  803. username: function () {
  804. if (Meteor.user() !== undefined) {
  805. return Meteor.user().profile.username;
  806. } else {
  807. return "";
  808. }
  809. }
  810. });
  811. function replaceURLWithHTMLLinks(text) {
  812. var re = /(\(.*?)?\b((?:https?|ftp|file):\/\/[-a-z0-9+&@#\/%?=~_()|!:,.;]*[-a-z0-9+&@#\/%=~_()|])/ig;
  813. return text.replace(re, function(match, lParens, url) {
  814. var rParens = '';
  815. lParens = lParens || '';
  816. // Try to strip the same number of right parens from url
  817. // as there are left parens. Here, lParenCounter must be
  818. // a RegExp object. You cannot use a literal
  819. // while (/\(/g.exec(lParens)) { ... }
  820. // because an object is needed to store the lastIndex state.
  821. var lParenCounter = /\(/g;
  822. while (lParenCounter.exec(lParens)) {
  823. var m;
  824. // We want m[1] to be greedy, unless a period precedes the
  825. // right parenthesis. These tests cannot be simplified as
  826. // /(.*)(\.?\).*)/.exec(url)
  827. // because if (.*) is greedy then \.? never gets a chance.
  828. if (m = /(.*)(\.\).*)/.exec(url) ||
  829. /(.*)(\).*)/.exec(url)) {
  830. url = m[1];
  831. rParens = m[2] + rParens;
  832. }
  833. }
  834. return lParens + "<a style='font-size: 18px; padding: 0; display: inline;' target='_blank' href='" + url + "'>" + url + "</a>" + rParens;
  835. });
  836. }
  837. function replaceURLWithHTMLLinksBlank(text) {
  838. var re = /(\(.*?)?\b((?:https?|ftp|file):\/\/[-a-z0-9+&@#\/%?=~_()|!:,.;]*[-a-z0-9+&@#\/%=~_()|])/ig;
  839. return text.replace(re, function(match, lParens, url) {
  840. var rParens = '';
  841. lParens = lParens || '';
  842. // Try to strip the same number of right parens from url
  843. // as there are left parens. Here, lParenCounter must be
  844. // a RegExp object. You cannot use a literal
  845. // while (/\(/g.exec(lParens)) { ... }
  846. // because an object is needed to store the lastIndex state.
  847. var lParenCounter = /\(/g;
  848. while (lParenCounter.exec(lParens)) {
  849. var m;
  850. // We want m[1] to be greedy, unless a period precedes the
  851. // right parenthesis. These tests cannot be simplified as
  852. // /(.*)(\.?\).*)/.exec(url)
  853. // because if (.*) is greedy then \.? never gets a chance.
  854. if (m = /(.*)(\.\).*)/.exec(url) ||
  855. /(.*)(\).*)/.exec(url)) {
  856. url = m[1];
  857. rParens = m[2] + rParens;
  858. }
  859. }
  860. return lParens + "<a href='" + url + "'>" + url + "</a>" + rParens;
  861. });
  862. }