main.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. Meteor.startup(function() {
  2. reCAPTCHA.config({
  3. publickey: '6LcVxg0TAAAAAE18vBiH00UAyaJggsmLm890SjZl'
  4. });
  5. Avatar.setOptions({
  6. fallbackType: "initials",
  7. defaultImageUrl: "/notes.png",
  8. generateCSS: true,
  9. imageSizes: {
  10. 'header': 40
  11. }
  12. });
  13. });
  14. Deps.autorun(function() {
  15. Meteor.subscribe("queues");
  16. Meteor.subscribe("reports");
  17. Meteor.subscribe("chat");
  18. Meteor.subscribe("playlists");
  19. Meteor.subscribe("songs");
  20. Meteor.subscribe("alerts");
  21. Meteor.subscribe("rooms");
  22. Meteor.subscribe("private_rooms");
  23. Meteor.subscribe("private_playlists");
  24. Meteor.subscribe("news");
  25. Meteor.subscribe("userData", Meteor.userId());
  26. Meteor.subscribe("usernames");
  27. });
  28. Handlebars.registerHelper("isAdmin", function(argument){
  29. if (Meteor.user() && Meteor.user().profile) {
  30. return Meteor.user().profile.rank === "admin";
  31. } else {
  32. return false;
  33. }
  34. });
  35. Handlebars.registerHelper("isModerator", function(argument){
  36. if (Meteor.user() && Meteor.user().profile && (Meteor.user().profile.rank === "admin" || Meteor.user().profile.rank === "moderator")) {
  37. return true;
  38. } else {
  39. return false;
  40. }
  41. });
  42. Handlebars.registerHelper("isAllowedInPrivateRoom", function(name){
  43. var room = PrivateRooms.findOne({name: name});
  44. if (Meteor.user() &&
  45. Meteor.user().profile &&
  46. room &&
  47. ((Meteor.user().profile.rank === "admin" || Meteor.user().profile.rank === "moderator") || (room.allowed.indexOf(Meteor.userId()) !== -1 || room.owner === Meteor.userId()))) {
  48. return true;
  49. } else {
  50. return false;
  51. }
  52. });
  53. Handlebars.registerHelper("isPrivateRoomOwner", function(name){
  54. var room = PrivateRooms.findOne({name: name});
  55. if (Meteor.user() &&
  56. Meteor.user().profile &&
  57. room &&
  58. ((Meteor.user().profile.rank === "admin" || Meteor.user().profile.rank === "moderator") || room.owner === Meteor.userId())) {
  59. return true;
  60. } else {
  61. return false;
  62. }
  63. });
  64. Handlebars.registerHelper("initials", function(argument){
  65. var user = Meteor.user();
  66. if (user !== undefined) {
  67. return user.profile.username[0].toUpperCase();
  68. } else {
  69. return "";
  70. }
  71. });
  72. /* Global collection helpers */
  73. Handlebars.registerHelper("rooms", function(){
  74. return Rooms.find({});
  75. });
  76. Handlebars.registerHelper("privateRooms", function(){
  77. return PrivateRooms.find({});
  78. });
  79. Handlebars.registerHelper("songs", function(){
  80. return Songs.find({});
  81. });
  82. Handlebars.registerHelper('active', function(path) {
  83. return curPath() == path ? 'active' : '';
  84. });
  85. Handlebars.registerHelper('isLoggedIn', function(path) {
  86. return Meteor.userId();
  87. });
  88. Handlebars.registerHelper('getUsernameFromId', function(id) {
  89. return Meteor.users.findOne(id).profile.username;
  90. });
  91. UI.registerHelper("formatTime", function(seconds) {
  92. var d = moment.duration(parseInt(seconds), 'seconds');
  93. return d.minutes() + ":" + ("0" + d.seconds()).slice(-2);
  94. });
  95. Template.registerHelper("rtime", function(date) {
  96. Session.get("time");
  97. if (date) {
  98. return moment(date).fromNow();
  99. }
  100. });
  101. var allAlertSub = undefined;
  102. var YTPlayer = undefined;
  103. var previewEndSongTimeout = undefined;
  104. var hpSound = undefined;
  105. var songsArr = [];
  106. var parts = location.href.split('/');
  107. var id = parts.pop();
  108. var type = id.toLowerCase();
  109. curPath=function(){var c=window.location.pathname;var b=c.slice(0,-1);var a=c.slice(-1);if(b==""){return"/"}else{if(a=="/"){return b}else{return c}}};
  110. function gup( name, url ) {
  111. if (!url) url = location.href;
  112. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  113. var regexS = "[\\?&]"+name+"=([^&#]*)";
  114. var regex = new RegExp( regexS );
  115. var results = regex.exec( url );
  116. return results == null ? null : results[1];
  117. }
  118. var ban_interval = Meteor.setInterval(function() {
  119. var userId = Meteor.userId();
  120. if (userId !== undefined) {
  121. var userData = Meteor.user();
  122. if (localStorage.getItem("banned") === "true") {
  123. if (userData !== undefined && userData !== null && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
  124. var ban = userData.punishments.ban;
  125. if (new Date(ban.bannedUntil).getTime() <= new Date().getTime()) {
  126. Meteor.call("isBanned", function(err, res) {
  127. if (res === false) {
  128. localStorage.setItem("banned", false);
  129. Meteor._reload.reload();
  130. }
  131. });
  132. }
  133. } else {
  134. localStorage.setItem("banned", false);
  135. Meteor._reload.reload();
  136. }
  137. } else {
  138. if (userData !== undefined && userData !== null && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
  139. localStorage.setItem("banned", true);
  140. Meteor._reload.reload();
  141. }
  142. }
  143. }
  144. }, 1000);