home-js.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <?PHP
  2. /**
  3. * Copyright (c) 2016, 2024, 5 Mode
  4. *
  5. * This file is part of Musicing.
  6. *
  7. * Musicing is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Musicing is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Musicing. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. * home-js.php
  21. *
  22. * Musicing js for the Home page.
  23. *
  24. * @author Daniele Bonini <my25mb@aol.com>
  25. * @copyrights (c) 2016, 2024, 5 Mode
  26. */
  27. require "../../../Private/core/init.inc";
  28. header("Content-Type: text/javascript");
  29. // PARAMETERS AND VARIABLES INIT
  30. $lang = APP_DEF_LANG;
  31. $lang1 = substr(filter_input(INPUT_GET, "hl")??"", 0, 5);
  32. $lang1= strip_tags($lang1);
  33. if ($lang1 !== PHP_STR) {
  34. $lang = $lang1;
  35. }
  36. $shortLang = getShortLang($lang);
  37. $AVATAR_NAME=filter_input(INPUT_GET, "av")??"";
  38. $AVATAR_NAME= strip_tags($AVATAR_NAME);
  39. $CURRENT_VIEW=filter_input(INPUT_GET, "cv")??"";
  40. $CURRENT_VIEW= strip_tags($CURRENT_VIEW);
  41. $CUDOZ=filter_input(INPUT_GET, "cu")??"";
  42. $CUDOZ= strip_tags($CUDOZ);
  43. ?>
  44. var myToolsOnIntID;
  45. function showHowTo() {
  46. <?PHP if ($lang == PHP_EN): ?>
  47. alert("Here how to manage your avatars in Musicing\n" +
  48. "- Type in the url of your avatar like http://" + "<?PHP echo($_SERVER['HTTP_HOST']);?>" + "/<your avatar>.\n" +
  49. "- Login with your pasword.\n" +
  50. "- Drag-n-drop in the browser window all the resources you like: \n" +
  51. " a. Drop in mp3 files to shape your music blog, in the form 'Playlist~Song Title.mp3';\n" +
  52. " a. Drop in pic to shape your gallery; the first one as yr avatar picture.\n" +
  53. " b. Drop in texts with link separeted by <ENTER> to shape your friends.\n" +
  54. "\n" +
  55. "Enjoy!");
  56. <?PHP elseif ($lang == PHP_IT): ?>
  57. alert("Ecco come gestire i tuoi avatar in Musicing:\n" +
  58. "- Scrivi l'url del tuo avatar come http://" + "<?PHP echo($_SERVER['HTTP_HOST']);?>" + "/<tuo avatar>.\n" +
  59. "- Loggati con la pasword.\n" +
  60. "- Fai il drag-n-drop nella finestra del browser di tutte le risorse che ritieni: \n" +
  61. " a. Trascina .mp3 file per creare il tuo blog musicale, attenendoti a 'Playlist~Titolo Canzone.mp3'\n" +
  62. " b. Trascina le tue immagini per creare la galleria, la prima sara' il tuo avatar.\n" +
  63. " b. Trascina link da testo separati da <INVIO> per creare i tuoi amici.\n" +
  64. "\n" +
  65. "Buon proseguimento!");
  66. <?PHP elseif ($lang == PHP_CN): ?>
  67. alert("在这里如何免费管理您的化身:\n" +
  68. "- 以以下格式输入阿凡达的URLhttp://" + "<?PHP echo($_SERVER['HTTP_HOST']);?>" + "/<你的头像>.\n" +
  69. "- 使用密码登录.\n" +
  70. "- 在浏览器窗口中拖动n-drop您喜欢的所有资源: \n" +
  71. " a. 放入.txt文件以形成您的博客:'Playlist~Song Title.mp3'.\n" +
  72. " b. 放入图片以塑造画廊; 第一个作为您的头像.\n" +
  73. " b. 删除带有链接<enter>分隔的链接以塑造您的朋友的文本.\n" +
  74. "\n" +
  75. "Enjoy!");
  76. <?PHP endif; ?>
  77. }
  78. function playSample() {
  79. //document.getElementById("myPlayer").src = "http://<?PHP echo(APP_HOST);?>/media/sample.mp3";
  80. document.getElementById("myPlayer").src = "/audio?av=<?PHP echo($AVATAR_NAME); ?>&f=/sample.mp3";
  81. document.getElementById("myPlayer").volume = 1;
  82. document.getElementById("myPlayer").play();
  83. }
  84. function playSong(playlist, song) {
  85. //document.getElementById("myPlayer").src = "http://<?PHP echo(APP_HOST);?>/media/" + encodeURI(playlist) + "/" + song;
  86. document.getElementById("myPlayer").src = "/audio?av=<?PHP echo($AVATAR_NAME); ?>&f=/" + encodeURI(playlist) + "/" + song;
  87. document.getElementById("myPlayer").volume = 1;
  88. document.getElementById("myPlayer").play();
  89. }
  90. function stopSong() {
  91. stopPlayList();
  92. document.getElementById("myPlayer").pause();
  93. }
  94. var curPlayF = -1;
  95. var ih;
  96. function playList(playlist, allowed, onclick) {
  97. if (allowed) {
  98. if (onclick) {
  99. if ($(".play-list-img2").attr("src") ==="/res/stopicon.png") {
  100. stopPlayList();
  101. return;
  102. }
  103. }
  104. if (document.getElementById("myPlayer").readyState===0 || document.getElementById("myPlayer").ended || document.getElementById("myPlayer").paused) {
  105. $(".play-list-img2").attr("src","/res/stopicon.png");
  106. curPlayF++;
  107. if (document.getElementsByClassName("playf"+playlist)[curPlayF]) {
  108. $(document.getElementsByClassName("playf"+playlist)[curPlayF]).click();
  109. clearInterval(ih);
  110. ih = setInterval("playList("+playlist+", true, false)", 5000);
  111. } else {
  112. //stopPlayList();
  113. curPlayF = -1;
  114. }
  115. }
  116. }
  117. return;
  118. }
  119. function stopPlayList() {
  120. curPlayF = -1;
  121. clearInterval(ih);
  122. $(".play-list-img").attr("src","/res/playicon.png");
  123. $(".play-list-img2").attr("src","/res/playicon.png");
  124. document.getElementById("myPlayer").pause();
  125. }
  126. function settingsOn() {
  127. $(".settingson").hide();
  128. $(".magicjar1").show();
  129. $(".magicjar2").show();
  130. $(".magicjar3").show();
  131. $(".settingsoff").show();
  132. setTimeout("settingsOff()",6000);
  133. }
  134. function settingsOff() {
  135. $(".settingsoff").hide("slow");
  136. $(".magicjar1").hide("slow");
  137. $(".magicjar2").hide("slow");
  138. $(".magicjar3").hide("slow");
  139. $(".settingson").show();
  140. }
  141. function toolsOn() {
  142. settingsOn();
  143. $(".tools").show("slow");
  144. clearInterval(myToolsOnIntID);
  145. }
  146. function setJar1On() {
  147. $(".magicjar1").css("background","url(/res/magicjar1.png)");
  148. $(".magicjar1").css("background-size","120px 120px");
  149. document.getElementsByClassName("magicjar1")[0].onclick=setJar1Off;
  150. document.getElementById("txtMagicJar1").value="1";
  151. document.getElementById("frmUpload").submit();
  152. }
  153. function setJar1Off() {
  154. $(".magicjar1").css("background","url(/res/magicjar1dis.png)");
  155. $(".magicjar1").css("background-size","120px 120px");
  156. document.getElementsByClassName("magicjar1")[0].onclick=setJar1On;
  157. document.getElementById("txtMagicJar1").value="0";
  158. document.getElementById("frmUpload").submit();
  159. }
  160. function setJar2On() {
  161. $(".magicjar2").css("background","url(/res/magicjar2.png)");
  162. $(".magicjar2").css("background-size","120px 120px");
  163. document.getElementsByClassName("magicjar2")[0].onclick=setJar2Off;
  164. document.getElementById("txtMagicJar2").value="1";
  165. document.getElementById("frmUpload").submit();
  166. }
  167. function setJar2Off() {
  168. $(".magicjar2").css("background","url(/res/magicjar2dis.png)");
  169. $(".magicjar2").css("background-size","120px 120px");
  170. document.getElementsByClassName("magicjar2")[0].onclick=setJar2On;
  171. document.getElementById("txtMagicJar2").value="0";
  172. document.getElementById("frmUpload").submit();
  173. }
  174. function setJar3On() {
  175. $(".magicjar3").css("background","url(/res/magicjar3.png)");
  176. $(".magicjar3").css("background-size","120px 120px");
  177. document.getElementsByClassName("magicjar3")[0].onclick=setJar3Off;
  178. document.getElementById("txtMagicJar3").value="1";
  179. document.getElementById("frmUpload").submit();
  180. }
  181. function setJar3Off() {
  182. $(".magicjar3").css("background","url(/res/magicjar3dis.png)");
  183. $(".magicjar3").css("background-size","120px 120px");
  184. document.getElementsByClassName("magicjar3")[0].onclick=setJar3On;
  185. document.getElementById("txtMagicJar3").value="0";
  186. }
  187. function startApp() {
  188. hidePassword();
  189. }
  190. function hidePassword() {
  191. $("#passworddisplay").css("visibility","hidden");
  192. }
  193. /*
  194. * call to startApp
  195. *
  196. * @returns void
  197. */
  198. function _startApp() {
  199. setTimeout("startApp()", 1000);
  200. }
  201. /*
  202. * Display the current hash for the config file
  203. *
  204. * @returns void
  205. */
  206. function showEncodedPassword() {
  207. if ($("#Password").val() === "") {
  208. $("#Password").addClass("emptyfield");
  209. return;
  210. }
  211. //if ($("#Salt").val() === "") {
  212. // $("#Salt").addClass("emptyfield");
  213. // return;
  214. //}
  215. passw = encryptSha2( $("#Password").val() + $("#Salt").val());
  216. msg = "<?PHP echo(getResource0("Please set your hash in the config file with this value", $lang, "/js/home-js.php"));?>:";
  217. alert(msg + "\n\n" + passw);
  218. }
  219. function changeLang(tthis) {
  220. window.open("/<?PHP echo($AVATAR_NAME);?>?hl="+$(tthis).val(),"_self");
  221. }
  222. function adminView() {
  223. document.getElementById("_reqView").value="<?PHP echo(ADMIN_VIEW);?>";
  224. document.getElementById("frmUpload").submit();
  225. }
  226. function privateView() {
  227. document.getElementById("_reqView").value="<?PHP echo(PRIVATE_VIEW);?>";
  228. document.getElementById("frmUpload").submit();
  229. }
  230. function reload() {
  231. //window.location.reload();
  232. document.getElementById("frmUpload").submit();
  233. }
  234. $("div.dragover").on("dragover", function(e) {
  235. e.stopPropagation();
  236. e.preventDefault();
  237. e.originalEvent.dataTransfer.dropEffect = "copy";
  238. return false;
  239. });
  240. $("div.dragover").on("drop", function(e) {
  241. e.stopPropagation();
  242. e.preventDefault();
  243. // Get the current Upload form obejct..
  244. var form = document.getElementById("frmUpload");
  245. // Create a FormData object including the actual form data..
  246. var fd = new FormData(form);
  247. // Get the array of files dropped..
  248. var dt = e.originalEvent.dataTransfer;
  249. var files = dt.files;
  250. var count = files.length;
  251. //alert("File Count: " + count + "\n");
  252. if (count !== 0) {
  253. for (var i = 0; i < count; i++) {
  254. //alert(" File " + i + ":\n(" + (typeof files[i]) + ") : <" + files[i] + " > " +
  255. // files[i].name + " " + files[i].size + " " + files[i].type + "\n");
  256. if (files[i].size > <?PHP echo(APP_FILE_MAX_SIZE); ?>) {
  257. alert("ERROR: file size (" + files[i].size +") exceeds app limit: <?PHP echo(APP_FILE_MAX_SIZE); ?>");
  258. return;
  259. }
  260. if (files[i].size > <?PHP echo(ini_get('upload_max_filesize'));?>) {
  261. alert("ERROR: file size (" + files[i].size +") exceeds PHP upload limit: <?PHP echo(ini_get('upload_max_filesize')); ?>");
  262. return;
  263. }
  264. if (files[i].size > <?PHP echo(ini_get('post_max_size'));?>) {
  265. alert("ERROR: file size (" + files[i].size +") exceeds PHP post limit: <?PHP echo(ini_get('post_max_size')); ?>");
  266. return;
  267. }
  268. fd.append("filesdd[]", files[i]);
  269. }
  270. // Submit of the FormData..
  271. $.ajax("/<?PHP echo($AVATAR_NAME);?>", {
  272. method: "POST",
  273. processData: false,
  274. contentType: false,
  275. data: fd//,
  276. //success: function (data) {
  277. //$("body").html(data);
  278. //}
  279. });
  280. setTimeout("reload()", 2000);
  281. } else {
  282. mytext = e.originalEvent.dataTransfer.getData('text/plain');
  283. re = new RegExp(/(https?:\/\/)([\da-z\.-]+)\.([a-z\.]{2,8})(\/?.+)?$/gum);
  284. matches = mytext.matchAll(re);
  285. ffriends="";
  286. if (matches !== null) {
  287. for(const match of matches) {
  288. if (ffriends==="") {
  289. ffriends+=match[0];
  290. } else {
  291. ffriends+="|"+match[0];
  292. }
  293. }
  294. }
  295. if (ffriends!=="") {
  296. //fd.append("f", ffriends);
  297. document.getElementById("f").value = ffriends;
  298. //alert(document.getElementById("f").value);
  299. document.getElementById("frmUpload").submit();
  300. } else {
  301. //alert("ale!");
  302. }
  303. }
  304. return false;
  305. });
  306. function setContentPos() {
  307. h=parseInt(window.innerHeight);
  308. w=parseInt(window.innerWidth);
  309. <?PHP if ($CURRENT_VIEW ==ADMIN_VIEW): ?>
  310. $("#picavatar").css("top", ((h - 255) / 2) + "px");
  311. $("#picavatar").css("left", ((w - 255) / 2) + "px");
  312. $("#picavatar").css("display", "inline");
  313. <?PHP else: ?>
  314. if (window.innerWidth<800) {
  315. $("#cudoz").css("display", "none");
  316. } else {
  317. $("#cudoz").css("display", "inline");
  318. }
  319. <?PHP endif; ?>
  320. $(".dragover").css("height", h + "px");
  321. $(".dragover").css("width", w + "px");
  322. newleft=parseInt(window.innerWidth - 145);
  323. $(".tools").css("left",newleft+"px");
  324. mytop = parseInt(window.innerHeight - ($("#passworddisplay").height() + 60));
  325. $("#passworddisplay").css("top", mytop+"px");
  326. }
  327. function setFooterPos() {
  328. if (document.getElementById("footerCont")) {
  329. tollerance = 16;
  330. $("#footerCont").css("top", parseInt( window.innerHeight - $("#footerCont").height() - tollerance ) + "px");
  331. $("#footer1").css("top", parseInt( window.innerHeight - $("#footer1").height() - tollerance ) + "px");
  332. $("#footer2").css("top", parseInt( window.innerHeight - $("#footer2").height() - tollerance ) + "px");
  333. $("#footer2").css("left", parseInt( window.innerWidth - $("#footer2").width() - tollerance ) + "px");
  334. $("#footer").css("top", parseInt( window.innerHeight - $("#footer").height() - tollerance ) + "px");
  335. }
  336. }
  337. window.addEventListener("load", function() {
  338. setTimeout("setContentPos()", 500);
  339. setTimeout("setFooterPos()", 1000);
  340. <?PHP if ($CURRENT_VIEW ==ADMIN_VIEW): ?>
  341. myToolsOnIntID = setInterval("toolsOn()", 2000);
  342. <?PHP else: ?>
  343. // display cudoz
  344. //for (i=1;i<=<?PHP echo($CUDOZ);?>;i++) {
  345. // $("#cudozentry"+i).get(0).src="/res/chicca_<?PHP echo($shortLang);?>.png";
  346. //}
  347. <?PHP endif; ?>
  348. setTimeout("_startApp()", 10000);
  349. }, true);
  350. window.addEventListener("resize", function() {
  351. setTimeout("setContentPos()", 500);
  352. setTimeout("setFooterPos()", 1000);
  353. }, true);