home.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <?php
  2. /**
  3. * Copyright 2021, 2024 5 Mode
  4. *
  5. * This file is part of SnipSwap.
  6. *
  7. * SnipSwap 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. * SnipSwap 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 SnipSwap. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. * home.php
  21. *
  22. * Page Home.
  23. *
  24. * @author Daniele Bonini <my25mb@aol.com>
  25. * @copyrights (c) 2016, 2024, 5 Mode
  26. */
  27. use fivemode\fivemode\LinkUtil;
  28. define('PAGE_TITLE', "Swap Snippet - Home");
  29. function echo_label(string $label) {
  30. if (mb_strlen($label) > 25) {
  31. echo(left($label, 25) . "...");
  32. } else {
  33. echo($label);
  34. }
  35. }
  36. $q = (string)substr((string)filter_input1(INPUT_GET, "q", FILTER_SANITIZE_QM), 0, 100);
  37. $splash = filter_input(INPUT_GET, "splash");
  38. $curLocale = APP_LOCALE;
  39. ?>
  40. <script>
  41. <?PHP if ($splash === "1"):?>
  42. firstaccess = 1;
  43. <?PHP else: ?>
  44. firstaccess = 0;
  45. <?PHP endif ?>
  46. </script>
  47. <?php require APP_SCRIPT_PATH . "/header.php";?>
  48. <div id="linkContainer" cat="<?PHP echo($catMaskedPath);?>" ondragover="onDragOver(event);" ondrop="onDrop(this, event);">
  49. <?php
  50. //echo($q."=q***");
  51. //echo($catMaskedPath."=cat***");
  52. $allLinks = LinkUtil::getLinkList(PHP_STR, "*");
  53. $iLinkjs = 1;
  54. $myCubeInitjs= "";
  55. foreach($allLinks as $ainallLink) {
  56. $newFormalName = $ainallLink['name'];
  57. $myCubeInitjs .= "cubes[" . $iLinkjs . "-1] = new myCube( 'Snip#". $iLinkjs . "', '" . $newFormalName . "', '" . APP_HOST . "');\n";
  58. $myCubeInitjs .= "cubes[" . $iLinkjs . "-1].start();\n";
  59. $iLinkjs++;
  60. }
  61. $myCubeInitjs .= "totcubes=" . count($allLinks) . ";\n";
  62. $aLinks = LinkUtil::getLinkList($q, $catMaskedPath);
  63. $iLink = 0;
  64. foreach($aLinks as $aLink) {
  65. $order = 1;
  66. foreach ($allLinks as $ainallLink) {
  67. if ($ainallLink['name'] === $aLink['name']) {
  68. break;
  69. }
  70. $order++;
  71. }
  72. $serverName = $_SERVER['SERVER_NAME'];
  73. $relPath = "/#" . $aLink['title'];
  74. ?>
  75. <div id="<?php echo($aLink['title']);?>" class="link-div" title="<?php echo($aLink['desc']); ?>" order="<?PHP echo($order);?>" onclick="selCube(this);openDetail()" draggable="true" ondragstart="onDragStart(this, event);" onmouseover="onMouseOver();">
  76. <div class="link-title"><?php echo($aLink['title']); ?><div style="width:25px; float:right;" title="It's a beauty!"><a href="#" onclick="event.stopPropagation();selCube($(this).parent().parent().parent());storeBeauty('imgheart<?php echo($aLink['title']);?>');"><img id="imgheart<?php echo($aLink['title']);?>" src="/res/<?PHP echo(($aLink['beauty']==="0")?"un":"");?>heart.png" style="height:23px;"></a></div></div>
  77. <a href="#"><img class="link-img" src="/res/code.png" alt="<?php echo($aLink['title']); ?>"></a><br>
  78. <br>
  79. &nbsp;<a class="link-link" href="http://<?php echo(str_replace(PHP_TILDE, PHP_SLASH, $aLink['link']));?>"><?php echo_label(str_replace(PHP_TILDE, PHP_SLASH, $aLink['label']));?></a><br>
  80. <div style="position:relative;top:-25px;left:-2px;text-align:right;padding-right:1.5px;">
  81. <a href="https://www.facebook.com/sharer/sharer.php?u=http://<?PHP echo("{$serverName}{$relPath}");?>&t=" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;" target="_blank" title="Share on Facebook"><img src="/res/fb.png"></a>
  82. <a href="https://twitter.com/share?url=http://<?PHP echo("{$serverName}{$relPath}");?>&text=" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;" target="_blank" title="Share on Twitter"><img src="/res/twitter.png"></a>
  83. <a href="whatsapp://send?text=http://<?PHP echo("{$serverName}{$relPath}");?>" data-action="share/whatsapp/share" onClick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;" target="_blank" title="Share on whatsapp"><img src="/res/whatsapp.png"></a>
  84. </div>
  85. </div>
  86. <?php
  87. $iLink++;
  88. } ?>
  89. <?php
  90. if (Empty($aLinks)) {
  91. echo("<div class=\"no-link\" style=\"width:250px; float:left; padding: 10px;\">no link found</div>");
  92. }
  93. ?>
  94. </div>
  95. <div>
  96. <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  97. <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  98. </div>
  99. <?PHP echo("<script>$myCubeInitjs</script>"); ?>
  100. <button id="modalButton1" type="button" class="btn btn-primary" style="display:none;" data-toggle="modal" data-target="#modal1">Button #1</button>
  101. <div class="modal" tabindex="-1" role="dialog" id="modal1">
  102. <div class="modal-dialog modal-lg my-modal-dialog" role="document">
  103. <div class="modal-content my-modal-content">
  104. <img src="/res/code.png" style="width:98%; vertical-align:top; opacity:0.2"></a>
  105. <div style="position:absolute; top:10px; padding:50px;">
  106. <table style="width:100%">
  107. <tr>
  108. <td class="snip-detail-cell">Title:&nbsp;</td><td width="700px"><input class="snip-detail-field" id="snip-detail-title" name="txtTitle" type="text" value="" onkeyup="storeData(this)" readonly></td>
  109. </tr>
  110. <tr>
  111. <td class="snip-detail-cell">Description:&nbsp;</td><td width="700px"><input class="snip-detail-field" id="snip-detail-desc" name="txtDesc" type="text" value="" onkeyup="storeData(this)" readonly></td>
  112. </tr>
  113. <tr>
  114. <td class="snip-detail-cell">Code:&nbsp;</td><td width="700px"><textarea class="snip-detail-field snip-code" id="snip-detail-code" name="txtCode" style="max-width:750px;height:350px;max-height:350px;" onkeyup="storeData(this)" readonly></textarea></td>
  115. </tr>
  116. <tr>
  117. <td class="snip-detail-cell">Tags:&nbsp;</td><td width="700px"><input class="snip-detail-field" id="snip-detail-tags" name="txtTags" type="text" value="" onkeyup="storeData(this)" readonly></td>
  118. </tr>
  119. <tr>
  120. <td class="snip-detail-cell">Label (link):&nbsp;</td><td width="700px"><input class="snip-detail-field" id="snip-detail-label" name="txtLabel" type="text" value="" onkeyup="storeData(this)" readonly></td>
  121. </tr>
  122. <tr>
  123. <td class="snip-detail-cell">Link:&nbsp;</td><td width="700px"><input class="snip-detail-field" id="snip-detail-link" name="txtLink" type="text" value="" onkeyup="storeData(this)" readonly></td>
  124. </tr>
  125. <tr>
  126. <td class="snip-detail-cell">Email:&nbsp;</td><td width="700px"><input class="snip-detail-field" id="snip-detail-email" name="txtEmail" type="text" value="" onkeyup="storeData(this)" readonly></td>
  127. </tr>
  128. <tr>
  129. <td class="snip-detail-cell">Cats:&nbsp;</td><td width="700px" style="padding-top:8px;font-weight:900;"><input class="snip-detail-field" id="snip-detail-cats" name="txtCats" type="text" value="" onkeyup="storeData(this)" readonly><br><span style="font-size:10px;border-top:8px solid transparent;">space separated snip categories, "~" for subcategories.</span></td>
  130. </tr>
  131. <tr style="display: none;">
  132. <td class="snip-detail-cell">Guid:&nbsp;</td><td width="700px"><input class="snip-detail-field" id="snip-detail-guid" name="txtGuid" type="text" value="" readonly></td>
  133. </tr>
  134. <tr>
  135. <td class="snip-detail-cell">Password:&nbsp;</td><td width="700px"><input class="snip-detail-field" id="snip-detail-password" name="txtPassword" type="text" value="" onkeyup="checkPwd(this)"></td>
  136. </tr>
  137. </table>
  138. <input type="hidden" id="comp-pwd" value="">
  139. </div>
  140. </div>
  141. <div class="modal-toolbox" style="float:left;">
  142. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  143. </div>
  144. </div>
  145. </div>
  146. <script>
  147. /*
  148. * Interaction code
  149. */
  150. var oldtthis; // Old cube
  151. var lineOldVal = ""; // Old value for a detail line
  152. var lineNewVal = ""; // New value for a detail line
  153. var dataChanged = false;
  154. /*
  155. * Select the given cube
  156. *
  157. * @param <interfaceEl> selected cube
  158. * @returns void
  159. */
  160. function selCube(tthis) {
  161. _selCube(tthis);
  162. }
  163. function checkPwd(tthis) {
  164. if (encryptSha2($(tthis).val()) === $("#comp-pwd").val()) {
  165. $("#snip-detail-title").prop("readonly", false);
  166. $("#snip-detail-desc").prop("readonly", false);
  167. $("#snip-detail-code").prop("readonly", false);
  168. $("#snip-detail-tags").prop("readonly", false);
  169. $("#snip-detail-label").prop("readonly", false);
  170. $("#snip-detail-link").prop("readonly", false);
  171. $("#snip-detail-email").prop("readonly", false);
  172. $("#snip-detail-cats").prop("readonly", false);
  173. }
  174. }
  175. /*
  176. * Get the data for the given detail / face
  177. *
  178. * @param string xmlStr, the current cube xml data
  179. * @param string detail, the requested detail
  180. * @returns string, the detail data
  181. */
  182. function getDetailData(xmlStr, detail) {
  183. var ret = "";
  184. var re;
  185. detail = detail.toLowerCase();
  186. xmlStr = xmlStr.replace('<?xml version="1.0" encoding="UTF-8"?>',"");
  187. xmlStr = xmlStr.replace('<details>',"");
  188. xmlStr = xmlStr.replace('</details>',"");
  189. xmlStr = xmlStr.replaceAll('\n',"|||999");
  190. xmlStr = xmlStr.replaceAll(String.fromCharCode(9), "");
  191. xmlStr = xmlStr.replaceAll(String.fromCharCode(10), "|||999");
  192. xmlStr = xmlStr.replaceAll(String.fromCharCode(13), "|||999");
  193. xmlStr = xmlStr.replaceAll(" ", "");
  194. xmlStr = xmlStr.replaceAll(" ", "");
  195. xmlStr = escape(xmlStr);
  196. //xmlStr = xmlStr.replaceAll('\n',"|99");
  197. //xmlStr = xmlStr.replaceAll(String.fromCharCode(10), "|99");
  198. //xmlStr = xmlStr.replaceAll(String.fromCharCode(13), "|99");
  199. xmlStr = xmlStr.replaceAll("%0A", "");
  200. xmlStr = xmlStr.replaceAll("%20%20%20%20%20", "");
  201. xmlStr = xmlStr.replaceAll("%20%20%20%20%", "");
  202. xmlStr = xmlStr.replaceAll("%20%20%", "");
  203. //xmlStr = unescape(xmlStr);
  204. //alert("xmlStr="+xmlStr);
  205. switch (detail) {
  206. case "snippet":
  207. re = new RegExp("detail%20face%3D%22snippet%22.+/cats", "igsu");
  208. break;
  209. case "contacts":
  210. re = new RegExp("detail%20face%3D%22contacts%22.+/email", "igsu");
  211. break;
  212. case "other info":
  213. re = new RegExp("detail%20face%3D%22other%20info%22.+/guid", "igsu");
  214. break;
  215. case "password":
  216. re = new RegExp("detail%20face%3D%22password%22.+/password", "igsu");
  217. break;
  218. }
  219. s = re.exec(xmlStr);
  220. if (!s || s.length===0) {
  221. //ret = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Error! #1";
  222. alert("Error#1");
  223. return ret;
  224. }
  225. xmlStr = s[0];
  226. xmlStr = "<"+xmlStr+"></detail>";
  227. xmlStr = unescape(xmlStr);
  228. //alert(xmlStr);
  229. const parser = new DOMParser();
  230. const doc = parser.parseFromString(xmlStr, "text/xml");
  231. x = doc.getElementsByTagName("detail");
  232. if (x.length===0) {
  233. //ret = "Error! #2";
  234. alert("Error#2");
  235. return ret;
  236. }
  237. //ret += "<div style='padding:10px;'>";
  238. for (i = 0; i < x[0].childNodes.length; i++) {
  239. if (x[0].childNodes[i].nodeType === 1) {
  240. if (x[0].childNodes[i].nodeName === "code") {
  241. document.getElementById("snip-detail-" + x[0].childNodes[i].nodeName).innerHTML = htmlEncode(x[0].childNodes[i].textContent);
  242. } else if (x[0].childNodes[i].nodeName === "password") {
  243. document.getElementById("comp-pwd").value = htmlEncode(x[0].childNodes[i].textContent);
  244. } else if (x[0].childNodes[i].nodeName === "beauty") {
  245. // none
  246. } else {
  247. //alert(x[0].childNodes[i].nodeName);
  248. document.getElementById("snip-detail-" + x[0].childNodes[i].nodeName).value = x[0].childNodes[i].textContent;
  249. }
  250. }
  251. }
  252. //if ((detail==="pictures") || (detail==="menu")) {
  253. // ret += "<div style='padding-left:80px;clear:both;'><br>you can use eg. Goolge Drive or Microsoft OneDrive to host your pictures.</div>"
  254. //}
  255. //ret += "</div>";
  256. return ret;
  257. }
  258. /*
  259. * Store in the cube object the new data of the text control
  260. *
  261. * @param {InterfaceEl} tthis, the text control under editing
  262. * @returns void
  263. */
  264. function storeData(tthis) {
  265. lineNewVal = $(tthis).val();
  266. //alert(lineNewVal);
  267. nodeName = tthis.id;
  268. nodeName = nodeName.replace("snip-detail-","");
  269. //alert(nodeName);
  270. xmlStr = curcube.getxml();
  271. //$("#log").html($("#log").html() + "old=" + "/(\<" + nodeName + "\>).*(\<\/" + nodeName + "\>)/gs" + "\n");
  272. //$("#log").html($("#log").html() + "new=" + lineNewVal + "\n");
  273. //alert("<" + nodeName + ">" + lineNewVal + "</" + nodeName + ">");
  274. //re = "/(\<" + nodeName + "\>).*(\<\/" + nodeName + "\>)/gs";
  275. switch (nodeName) {
  276. case "title":
  277. re = /(\<title>).*(\<\/title>)/gs;
  278. break;
  279. case "desc":
  280. re = /(\<desc>).*(\<\/desc>)/gs;
  281. break;
  282. case "code":
  283. re = /(\<code>\<\!\[CDATA\[).*(\]\]\>\<\/code>)/gs;
  284. break;
  285. case "tags":
  286. re = /(\<tags>).*(\<\/tags>)/gs;
  287. break;
  288. case "cats":
  289. re = /(\<cats>).*(\<\/cats>)/gs;
  290. break;
  291. case "label":
  292. re = /(\<label>).*(\<\/label>)/gs;
  293. break;
  294. case "link":
  295. re = /(\<link>).*(\<\/link>)/gs;
  296. break;
  297. case "email":
  298. re = /(\<email>).*(\<\/email>)/gs;
  299. break;
  300. }
  301. xmlStr = xmlStr.replace(re, "$1" + lineNewVal + "$2");
  302. //xmlStr = xmlStr.replace("<" + nodeName + ">" + lineOldVal + "</" + nodeName + ">", "<" + nodeName + ">" + lineNewVal + "</" + nodeName + ">");
  303. //alert(xmlStr);
  304. curcube.xml = xmlStr;
  305. dataChanged = true;
  306. }
  307. function storeBeauty(beautyImageId) {
  308. var xmlStr = curcube.getxml();
  309. var beautyNewVal = "1";
  310. re = /(\<beauty>).*(\<\/beauty>)/gs;
  311. xmlStr = xmlStr.replace(re, "$1" + beautyNewVal + "$2");
  312. curcube.xml = xmlStr;
  313. $("#"+beautyImageId).attr("src","/res/heart.png");
  314. dataChanged = true;
  315. }
  316. function _saveData() {
  317. if (dataChanged) {
  318. curcube.savedata();
  319. dataChanged = false;
  320. }
  321. }
  322. setInterval("_saveData()", 1500);
  323. /*
  324. * Display the given data detail
  325. *
  326. * @param <interfaceEl> selected cube
  327. * @returns void
  328. */
  329. function openDetail() {
  330. //alert(curcube.getxml());
  331. myhtml = getDetailData(curcube.getxml(), "snippet") + getDetailData(curcube.getxml(), "contacts") + getDetailData(curcube.getxml(), "other info") + getDetailData(curcube.getxml(), "password");
  332. $('#modalButton1').click();
  333. }
  334. </script>
  335. <?php require APP_SCRIPT_PATH . "/footer.php";?>