main.js 5.3 KB

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