2
0

helpers.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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. return Session.get("state") === "paused";
  426. },
  427. private: function () {
  428. return 1;
  429. //return Rooms.findOne({type: Session.get("type")}).private === true;
  430. },
  431. currentSong: function(){
  432. return Session.get("currentSong");
  433. },
  434. reportingSong: function() {
  435. if (!Session.get("reportPrevious")) {
  436. return Session.get("currentSongR");
  437. } else {
  438. return Session.get("previousSongR");
  439. }
  440. },
  441. reportSong: function(){
  442. Meteor.setInterval(function(){
  443. if($("#report-song").is(":checked")){
  444. Session.set("reportSong", true)
  445. } else { Session.set("reportSong", false) }
  446. }, 500);
  447. return Session.get("reportSong");
  448. },
  449. reportSongOther: function(){
  450. Meteor.setInterval(function(){
  451. if($("#report-song-other").is(":checked")){
  452. Session.set("reportSongOther", true)
  453. } else { Session.set("reportSongOther", false) }
  454. }, 500);
  455. return Session.get("reportSongOther");
  456. },
  457. reportTitle: function(){
  458. Meteor.setInterval(function(){
  459. if($("#report-title").is(":checked")){
  460. Session.set("reportTitle", true)
  461. } else { Session.set("reportTitle", false) }
  462. }, 500);
  463. return Session.get("reportTitle");
  464. },
  465. reportTitleOther: function(){
  466. Meteor.setInterval(function(){
  467. if($("#report-title-other").is(":checked")){
  468. Session.set("reportTitleOther", true)
  469. } else { Session.set("reportTitleOther", false) }
  470. }, 500);
  471. return Session.get("reportTitleOther");
  472. },
  473. reportArtist: function(){
  474. Meteor.setInterval(function(){
  475. if($("#report-artist").is(":checked")){
  476. Session.set("reportArtist", true)
  477. } else { Session.set("reportArtist", false) }
  478. }, 500);
  479. return Session.get("reportArtist");
  480. },
  481. reportArtistOther: function(){
  482. Meteor.setInterval(function(){
  483. if($("#report-artist-other").is(":checked")){
  484. Session.set("reportArtistOther", true)
  485. } else { Session.set("reportArtistOther", false) }
  486. }, 500);
  487. return Session.get("reportArtistOther");
  488. },
  489. reportDuration: function(){
  490. Meteor.setInterval(function(){
  491. if($("#report-duration").is(":checked")){
  492. Session.set("reportDuration", true)
  493. } else { Session.set("reportDuration", false) }
  494. }, 500);
  495. return Session.get("reportDuration");
  496. },
  497. reportDurationOther: function(){
  498. Meteor.setInterval(function(){
  499. if($("#report-duration-other").is(":checked")){
  500. Session.set("reportDurationOther", true)
  501. } else { Session.set("reportDurationOther", false) }
  502. }, 500);
  503. return Session.get("reportDurationOther");
  504. },
  505. reportAlbumart: function(){
  506. Meteor.setInterval(function(){
  507. if($("#report-albumart").is(":checked")){
  508. Session.set("reportAlbumart", true)
  509. } else { Session.set("reportAlbumart", false) }
  510. }, 500);
  511. return Session.get("reportAlbumart");
  512. },
  513. reportAlbumartOther: function(){
  514. Meteor.setInterval(function(){
  515. if($("#report-albumart-other").is(":checked")){
  516. Session.set("reportAlbumartOther", true)
  517. } else { Session.set("reportAlbumartOther", false) }
  518. }, 500);
  519. return Session.get("reportAlbumartOther");
  520. },
  521. reportOther: function(){
  522. Meteor.setInterval(function(){
  523. if($("#report-other").is(":checked")){
  524. Session.set("reportOther", true)
  525. } else { Session.set("reportOther", false) }
  526. }, 500);
  527. return Session.get("reportOther");
  528. },
  529. votes: function () {
  530. return Rooms.findOne({type: Session.get("type")}).votes;
  531. },
  532. usersInRoom: function(){
  533. var userList = [];
  534. var roomUserList = Rooms.findOne({type: Session.get("type")}).userList;
  535. roomUserList.forEach(function(user){
  536. if(userList.indexOf(user) === -1){
  537. userList.push(user);
  538. }
  539. })
  540. return userList;
  541. }
  542. });
  543. Template.communityStation.helpers({
  544. getUsername: function(id) {
  545. return Meteor.users.findOne(id).profile.username;
  546. },
  547. queue: function() {
  548. var name = Session.get("CommunityStationName");
  549. var room = CommunityStations.findOne({name: name});
  550. if (room !== undefined && room.partyModeEnabled === true) {
  551. return room.queue;
  552. } else {
  553. return [];
  554. }
  555. },
  556. noCurrentSong: function() {
  557. return Session.get("noCurrentSong");
  558. },
  559. noCurrentSongHidden: function() {
  560. if (Session.get("noCurrentSong")) {
  561. return "hidden";
  562. } else {
  563. return "";
  564. }
  565. },
  566. partyModeChecked: function() {
  567. var name = Session.get("CommunityStationName");
  568. var room = CommunityStations.findOne({name: name});
  569. if (room !== undefined && room.partyModeEnabled === true) {
  570. return "checked";
  571. } else {
  572. return "";
  573. }
  574. },
  575. queueLockedChecked: function() {
  576. var name = Session.get("CommunityStationName");
  577. var room = CommunityStations.findOne({name: name});
  578. if (room !== undefined && room.queueLocked === true) {
  579. return "checked";
  580. } else {
  581. return "";
  582. }
  583. },
  584. partyModeEnabled: function() {
  585. var name = Session.get("CommunityStationName");
  586. var room = CommunityStations.findOne({name: name});
  587. if (room !== undefined && room.partyModeEnabled === true) {
  588. return true;
  589. } else {
  590. return false;
  591. }
  592. },
  593. partyModeEnabledHidden: function() {
  594. var name = Session.get("CommunityStationName");
  595. var room = CommunityStations.findOne({name: name});
  596. if (room !== undefined && room.partyModeEnabled === true) {
  597. return "";
  598. } else {
  599. return "hidden";
  600. }
  601. },
  602. singleVideoResults: function() {
  603. return Session.get("songResults");
  604. },
  605. singleVideoResultsQueue: function() {
  606. return Session.get("songResultsQueue");
  607. },
  608. singleVideoResultsActive: function() {
  609. var songs = Session.get("songResults");
  610. if (songs !== undefined && songs.length > 0) {
  611. return true;
  612. } else {
  613. return false;
  614. }
  615. },
  616. singleVideoResultsActiveQueue: function() {
  617. var songs = Session.get("songResultsQueue");
  618. if (songs !== undefined && songs.length > 0) {
  619. return true;
  620. } else {
  621. return false;
  622. }
  623. },
  624. hasMoreThanOne: function(array) {
  625. if (array.length > 1) {
  626. return true;
  627. } else {
  628. return false;
  629. }
  630. },
  631. isFirst: function(object, array) {
  632. if (_.isEqual(array[0], object) && array.length > 1) {
  633. return true;
  634. } else {
  635. return false;
  636. }
  637. },
  638. isLast: function(object, array) {
  639. if (_.isEqual(array[array.length - 1], object) && array.length > 1) {
  640. return true;
  641. } else {
  642. return false;
  643. }
  644. },
  645. communityStationOwnerName: function() {
  646. var room = CommunityStations.findOne({name: Session.get("CommunityStationName")});
  647. if (room !== undefined) {
  648. return Meteor.users.findOne(room.owner).profile.username;
  649. } else {
  650. return "";
  651. }
  652. },
  653. editingPlaylist: function() {
  654. return PrivatePlaylists.findOne({owner: Meteor.userId(), name: Session.get("editingPlaylistName")});
  655. },
  656. isPlaylistSelected: function(roomName, playlistName) {
  657. return CommunityStations.findOne({name: roomName}).playlist === playlistName;
  658. },
  659. getSelected: function(val1, val2) {
  660. if (val1 === val2) {
  661. return "selected";
  662. } else {
  663. return "";
  664. }
  665. },
  666. globalChat: function () {
  667. Meteor.setTimeout(function () {
  668. var elem = document.getElementById('global-chat');
  669. if (elem !== undefined && elem !== null) {
  670. elem.scrollTop = elem.scrollHeight;
  671. }
  672. }, 100);
  673. var messages = Chat.find({type: "global"}, {sort: {time: -1}, limit: 50}).fetch().reverse();
  674. messages = messages.map(function(message) {
  675. message.message = replaceURLWithHTMLLinks(message.message);
  676. return message;
  677. });
  678. return messages;
  679. },
  680. communityStationDisplayName: function () {
  681. var parts = location.href.split('/');
  682. var id = parts.pop().toLowerCase();
  683. return CommunityStations.findOne({name: id}).displayName;
  684. },
  685. name: function () {
  686. var parts = location.href.split('/');
  687. var id = parts.pop().toLowerCase();
  688. return id;
  689. },
  690. users: function () {
  691. var parts = location.href.split('/');
  692. var id = parts.pop().toLowerCase();
  693. return CommunityStations.findOne({name: id}).userList.length;
  694. },
  695. allowed: function () {
  696. var parts = location.href.split('/');
  697. var id = parts.pop().toLowerCase();
  698. var arr = [];
  699. CommunityStations.findOne({name: id}).allowed.forEach(function(allowed) {
  700. arr.push({name: Meteor.users.findOne(allowed).profile.username, id: allowed});
  701. });
  702. return arr;
  703. },
  704. playlists: function () {
  705. return PrivatePlaylists.find({owner: Meteor.userId()});
  706. },
  707. title: function () {
  708. return Session.get("title");
  709. },
  710. loaded: function () {
  711. return Session.get("loaded");
  712. },
  713. paused: function () {
  714. var room = CommunityStations.findOne({name: Session.get("CommunityStationName")});
  715. if (room !== undefined) {
  716. return room.state === "paused";
  717. } else {
  718. return false;
  719. }
  720. },
  721. private: function () {
  722. var room = CommunityStations.findOne({name: Session.get("CommunityStationName")});
  723. if (room !== undefined) {
  724. return room.private;
  725. } else {
  726. return 1;
  727. }
  728. },
  729. playing: function() {
  730. var room = CommunityStations.findOne({name: Session.get("CommunityStationName")});
  731. if (room !== undefined) {
  732. return room.state === "playing";
  733. } else {
  734. return false;
  735. }
  736. },
  737. currentSong: function(){
  738. return Session.get("currentSong");
  739. },
  740. votes: function () {
  741. var room = CommunityStations.findOne({name: Session.get("CommunityStationName")});
  742. if (room !== undefined) {
  743. return room.votes;
  744. } else {
  745. return 0;
  746. }
  747. },
  748. usersInRoom: function() {
  749. var userList = [];
  750. var room = CommunityStations.findOne({name: Session.get("CommunityStationName")});
  751. if (room !== undefined) {
  752. var roomUserList = room.userList;
  753. roomUserList.forEach(function (user) {
  754. if (userList.indexOf(user) === -1) {
  755. userList.push(user);
  756. }
  757. })
  758. }
  759. return userList;
  760. },
  761. room: function() {
  762. var parts = location.href.split('/');
  763. var id = parts.pop().toLowerCase();
  764. setTimeout(function() {
  765. Materialize.updateTextFields();
  766. }, 100);
  767. return CommunityStations.findOne({name: id});
  768. }
  769. });
  770. Template.settings.helpers({
  771. username: function () {
  772. if (Meteor.user() !== undefined) {
  773. return Meteor.user().profile.username;
  774. } else {
  775. return "";
  776. }
  777. }
  778. });
  779. function replaceURLWithHTMLLinks(text) {
  780. var re = /(\(.*?)?\b((?:https?|ftp|file):\/\/[-a-z0-9+&@#\/%?=~_()|!:,.;]*[-a-z0-9+&@#\/%=~_()|])/ig;
  781. return text.replace(re, function(match, lParens, url) {
  782. var rParens = '';
  783. lParens = lParens || '';
  784. // Try to strip the same number of right parens from url
  785. // as there are left parens. Here, lParenCounter must be
  786. // a RegExp object. You cannot use a literal
  787. // while (/\(/g.exec(lParens)) { ... }
  788. // because an object is needed to store the lastIndex state.
  789. var lParenCounter = /\(/g;
  790. while (lParenCounter.exec(lParens)) {
  791. var m;
  792. // We want m[1] to be greedy, unless a period precedes the
  793. // right parenthesis. These tests cannot be simplified as
  794. // /(.*)(\.?\).*)/.exec(url)
  795. // because if (.*) is greedy then \.? never gets a chance.
  796. if (m = /(.*)(\.\).*)/.exec(url) ||
  797. /(.*)(\).*)/.exec(url)) {
  798. url = m[1];
  799. rParens = m[2] + rParens;
  800. }
  801. }
  802. return lParens + "<a style='font-size: 18px; padding: 0; display: inline;' target='_blank' href='" + url + "'>" + url + "</a>" + rParens;
  803. });
  804. }
  805. function replaceURLWithHTMLLinksBlank(text) {
  806. var re = /(\(.*?)?\b((?:https?|ftp|file):\/\/[-a-z0-9+&@#\/%?=~_()|!:,.;]*[-a-z0-9+&@#\/%=~_()|])/ig;
  807. return text.replace(re, function(match, lParens, url) {
  808. var rParens = '';
  809. lParens = lParens || '';
  810. // Try to strip the same number of right parens from url
  811. // as there are left parens. Here, lParenCounter must be
  812. // a RegExp object. You cannot use a literal
  813. // while (/\(/g.exec(lParens)) { ... }
  814. // because an object is needed to store the lastIndex state.
  815. var lParenCounter = /\(/g;
  816. while (lParenCounter.exec(lParens)) {
  817. var m;
  818. // We want m[1] to be greedy, unless a period precedes the
  819. // right parenthesis. These tests cannot be simplified as
  820. // /(.*)(\.?\).*)/.exec(url)
  821. // because if (.*) is greedy then \.? never gets a chance.
  822. if (m = /(.*)(\.\).*)/.exec(url) ||
  823. /(.*)(\).*)/.exec(url)) {
  824. url = m[1];
  825. rParens = m[2] + rParens;
  826. }
  827. }
  828. return lParens + "<a href='" + url + "'>" + url + "</a>" + rParens;
  829. });
  830. }