main.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. Template.registerHelper('equals', function(var1, var2) {
  29. if (typeof var1 === "object") {
  30. return _.isEqual(var1, var2);
  31. } else {
  32. return var1 === var2;
  33. }
  34. }
  35. );
  36. Handlebars.registerHelper("isAdmin", function(argument){
  37. if (Meteor.user() && Meteor.user().profile) {
  38. return Meteor.user().profile.rank === "admin";
  39. } else {
  40. return false;
  41. }
  42. });
  43. Handlebars.registerHelper("isModerator", function(argument){
  44. if (Meteor.user() && Meteor.user().profile && (Meteor.user().profile.rank === "admin" || Meteor.user().profile.rank === "moderator")) {
  45. return true;
  46. } else {
  47. return false;
  48. }
  49. });
  50. Handlebars.registerHelper("isAllowedInPrivateRoom", function(name){
  51. var room = PrivateRooms.findOne({name: name});
  52. if (Meteor.user() &&
  53. Meteor.user().profile &&
  54. room &&
  55. ((Meteor.user().profile.rank === "admin" || Meteor.user().profile.rank === "moderator") || (room.allowed.indexOf(Meteor.userId()) !== -1 || room.owner === Meteor.userId()))) {
  56. return true;
  57. } else {
  58. return false;
  59. }
  60. });
  61. Handlebars.registerHelper("isPrivateRoomOwner", function(name){
  62. var room = PrivateRooms.findOne({name: name});
  63. if (Meteor.user() &&
  64. Meteor.user().profile &&
  65. room &&
  66. ((Meteor.user().profile.rank === "admin" || Meteor.user().profile.rank === "moderator") || room.owner === Meteor.userId())) {
  67. return true;
  68. } else {
  69. return false;
  70. }
  71. });
  72. Handlebars.registerHelper("initials", function(argument){
  73. var user = Meteor.user();
  74. if (user !== undefined) {
  75. return user.profile.username[0].toUpperCase();
  76. } else {
  77. return "";
  78. }
  79. });
  80. /* Global collection helpers */
  81. Handlebars.registerHelper("rooms", function(){
  82. return Rooms.find({});
  83. });
  84. Handlebars.registerHelper("privateRooms", function(){
  85. return PrivateRooms.find({});
  86. });
  87. Handlebars.registerHelper("songs", function(){
  88. return Songs.find({});
  89. });
  90. Handlebars.registerHelper('active', function(path) {
  91. return curPath() == path ? 'active' : '';
  92. });
  93. Handlebars.registerHelper('isLoggedIn', function(path) {
  94. return Meteor.userId();
  95. });
  96. Handlebars.registerHelper('getUsernameFromId', function(id) {
  97. return Meteor.users.findOne(id).profile.username;
  98. });
  99. UI.registerHelper("formatTime", function(seconds) {
  100. var d = moment.duration(parseInt(seconds), 'seconds');
  101. return d.minutes() + ":" + ("0" + d.seconds()).slice(-2);
  102. });
  103. Template.registerHelper("rtime", function(date) {
  104. Session.get("time");
  105. if (date) {
  106. return moment(date).fromNow();
  107. }
  108. });
  109. Template.registerHelper("getSelected", function(val1, val2) {
  110. if (val1 === val2) {
  111. return "selected";
  112. } else {
  113. return "";
  114. }
  115. });
  116. var allAlertSub = undefined;
  117. var YTPlayer = undefined;
  118. var previewEndSongTimeout = undefined;
  119. var hpSound = undefined;
  120. var songsArr = [];
  121. var parts = location.href.split('/');
  122. var id = parts.pop();
  123. var type = id.toLowerCase();
  124. 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}}};
  125. function gup( name, url ) {
  126. if (!url) url = location.href;
  127. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  128. var regexS = "[\\?&]"+name+"=([^&#]*)";
  129. var regex = new RegExp( regexS );
  130. var results = regex.exec( url );
  131. return results == null ? null : results[1];
  132. }
  133. var ban_interval = Meteor.setInterval(function() {
  134. var userId = Meteor.userId();
  135. if (userId !== undefined) {
  136. var userData = Meteor.user();
  137. if (localStorage.getItem("banned") === "true") {
  138. if (userData !== undefined && userData !== null && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
  139. var ban = userData.punishments.ban;
  140. if (new Date(ban.bannedUntil).getTime() <= new Date().getTime()) {
  141. Meteor.call("isBanned", function(err, res) {
  142. if (res === false) {
  143. localStorage.setItem("banned", false);
  144. Meteor._reload.reload();
  145. }
  146. });
  147. }
  148. } else {
  149. localStorage.setItem("banned", false);
  150. Meteor._reload.reload();
  151. }
  152. } else {
  153. if (userData !== undefined && userData !== null && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
  154. localStorage.setItem("banned", true);
  155. Meteor._reload.reload();
  156. }
  157. }
  158. }
  159. }, 1000);