home.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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', "SnipSwap - 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" style="margin-top:3%;margin-left:5%;margin-bottom:3%;margin-right:5%;min-height:400px;border:0px solid red;" 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. ?>
  73. <div class="link-div" style="width:250px; float:left; padding: 10px; margin:5px;" title="<?php echo($aLink['desc']); ?>" order="<?PHP echo($order);?>" onclick="selCube(this);openDetail()" draggable="true" ondragstart="onDragStart(this, event);" onmouseover="onMouseOver();">
  74. <div style="color:#ed6a43; padding-bottom:8px;"><?php echo($aLink['title']); ?></div>
  75. <a href="#"><img src="/res/code.png" style="width:232px; height:124px; border:1px solid darkgray;" alt="<?php echo($aLink['title']); ?>"></a><br>
  76. &nbsp;<a style="font-style:italic; color:green; font-size:10px; padding-top:5px;" 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>
  77. </div>
  78. <?php
  79. $iLink++;
  80. } ?>
  81. <?php
  82. if (Empty($aLinks)) {
  83. echo("<div class=\"no-link\" style=\"width:250px; float:left; padding: 10px;\">no link found</div>");
  84. }
  85. ?>
  86. </div>
  87. <?PHP echo("<script>$myCubeInitjs</script>"); ?>
  88. <button id="modalButton1" type="button" class="btn btn-primary" style="display:none;" data-toggle="modal" data-target="#modal1">Button #1</button>
  89. <div class="modal" tabindex="-1" role="dialog" id="modal1">
  90. <div class="modal-dialog modal-lg" role="document" style="width:80%;background-color:#FFFFFF;">
  91. <div class="modal-content" style="float:left;width:90%; height:90%;">
  92. <img src="/res/code.png" style="width:98%; vertical-align:top; opacity:0.2"></a>
  93. <div style="position:absolute; top:10px; padding:50px;">
  94. <table style="width:100%">
  95. <tr>
  96. <td style="width:100px;text-align:right;padding:10px;font-weight:900;">Title:&nbsp;</td><td width="700px"><input id="snip-detail-title" name="txtTitle" type="text" value="" style="width:98%;max-width:550px;font-weight:900;font-size:15px;border:2px solid #000000;" onkeyup="storeData(this)" readonly></td>
  97. </tr>
  98. <tr>
  99. <td style="width:100px;text-align:right;padding:10px;font-weight:900;">Description:&nbsp;</td><td width="700px"><input id="snip-detail-desc" name="txtDesc" type="text" value="" style="width:98%;max-width:550px;font-weight:900;font-size:15px;border:2px solid #000000;" onkeyup="storeData(this)" readonly></td>
  100. </tr>
  101. <tr>
  102. <td style="width:100px;text-align:right;padding:10px;font-weight:900;">Code:&nbsp;</td><td width="700px"><textarea id="snip-detail-code" class="snip-code" name="txtCode" style="width:98%;max-width:750px;height:350px;max-height:350px;font-weight:900;font-size:15px;border:2px solid #000000;" onkeyup="storeData(this)" readonly></textarea></td>
  103. </tr>
  104. <tr>
  105. <td style="width:100px;text-align:right;padding:10px;font-weight:900;">Tags:&nbsp;</td><td width="700px"><input id="snip-detail-tags" name="txtTags" type="text" value="" style="width:98%;max-width:550px;font-weight:900;font-size:15px;border:2px solid #000000;" onkeyup="storeData(this)" readonly></td>
  106. </tr>
  107. <tr>
  108. <td style="width:100px;text-align:right;padding:10px;font-weight:900;">Label (link):&nbsp;</td><td width="700px"><input id="snip-detail-label" name="txtLabel" type="text" value="" style="width:98%;max-width:550px;font-weight:900;font-size:15px;border:2px solid #000000;" onkeyup="storeData(this)" readonly></td>
  109. </tr>
  110. <tr>
  111. <td style="width:100px;text-align:right;padding:10px;font-weight:900;">Link:&nbsp;</td><td width="700px"><input id="snip-detail-link" name="txtLink" type="text" value="" style="width:98%;max-width:550px;font-weight:900;font-size:15px;border:2px solid #000000;" onkeyup="storeData(this)" readonly></td>
  112. </tr>
  113. <tr>
  114. <td style="width:100px;text-align:right;padding:10px;font-weight:900;">Email:&nbsp;</td><td width="700px"><input id="snip-detail-email" name="txtEmail" type="text" value="" style="width:98%;max-width:550px;font-weight:900;font-size:15px;border:2px solid #000000;" onkeyup="storeData(this)" readonly></td>
  115. </tr>
  116. <tr>
  117. <td style="width:100px;text-align:right;padding:10px;font-weight:900;">Cats:&nbsp;</td><td width="700px" style="padding-top:8px;font-weight:900;"><input id="snip-detail-cats" name="txtCats" type="text" value="" style="width:98%;max-width:550px;font-weight:900;font-size:15px;border:2px solid #000000;" onkeyup="storeData(this)" readonly><br><span style="font-size:10px;border-top:8px solid transparent;">space separated snip categories, "~" for subcategories.</span></td>
  118. </tr>
  119. <tr style="display: none;">
  120. <td style="width:100px;text-align:right;padding:10px;font-weight:900;">Guid:&nbsp;</td><td width="700px"><input id="snip-detail-guid" name="txtGuid" type="text" value="" style="width:98%;max-width:550px;font-weight:900;font-size:15px;border:2px solid #000000;" readonly></td>
  121. </tr>
  122. <tr>
  123. <td style="width:100px;text-align:right;padding:10px;font-weight:900;">Password:&nbsp;</td><td width="700px"><input id="snip-detail-password" name="txtPassword" type="text" value="" style="width:98%;max-width:550px;font-weight:900;font-size:15px;border:2px solid #000000;" onkeyup="checkPwd(this)"></td>
  124. </tr>
  125. </table>
  126. <input type="hidden" id="comp-pwd" value="">
  127. </div>
  128. </div>
  129. <div class="modal-toolbox" style="float:left;">
  130. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  131. </div>
  132. </div>
  133. </div>
  134. <script>
  135. /*
  136. * Interaction code
  137. */
  138. var oldtthis; // Old cube
  139. var lineOldVal = ""; // Old value for a detail line
  140. var lineNewVal = ""; // New value for a detail line
  141. var dataChanged = false;
  142. /*
  143. * Select the given cube
  144. *
  145. * @param <interfaceEl> selected cube
  146. * @returns void
  147. */
  148. function selCube(tthis) {
  149. _selCube(tthis);
  150. }
  151. function checkPwd(tthis) {
  152. if (encryptSha2($(tthis).val()) === $("#comp-pwd").val()) {
  153. $("#snip-detail-title").prop("readonly", false);
  154. $("#snip-detail-desc").prop("readonly", false);
  155. $("#snip-detail-code").prop("readonly", false);
  156. $("#snip-detail-tags").prop("readonly", false);
  157. $("#snip-detail-label").prop("readonly", false);
  158. $("#snip-detail-link").prop("readonly", false);
  159. $("#snip-detail-email").prop("readonly", false);
  160. $("#snip-detail-cats").prop("readonly", false);
  161. }
  162. }
  163. /*
  164. * Get the data for the given detail / face
  165. *
  166. * @param string xmlStr, the current cube xml data
  167. * @param string detail, the requested detail
  168. * @returns string, the detail data
  169. */
  170. function getDetailData(xmlStr, detail) {
  171. var ret = "";
  172. var re;
  173. detail = detail.toLowerCase();
  174. xmlStr = xmlStr.replace('<?xml version="1.0" encoding="UTF-8"?>',"");
  175. xmlStr = xmlStr.replace('<details>',"");
  176. xmlStr = xmlStr.replace('</details>',"");
  177. xmlStr = xmlStr.replaceAll('\n',"|||999");
  178. xmlStr = xmlStr.replaceAll(String.fromCharCode(9), "");
  179. xmlStr = xmlStr.replaceAll(String.fromCharCode(10), "|||999");
  180. xmlStr = xmlStr.replaceAll(String.fromCharCode(13), "|||999");
  181. xmlStr = xmlStr.replaceAll(" ", "");
  182. xmlStr = xmlStr.replaceAll(" ", "");
  183. xmlStr = escape(xmlStr);
  184. //xmlStr = xmlStr.replaceAll('\n',"|99");
  185. //xmlStr = xmlStr.replaceAll(String.fromCharCode(10), "|99");
  186. //xmlStr = xmlStr.replaceAll(String.fromCharCode(13), "|99");
  187. xmlStr = xmlStr.replaceAll("%0A", "");
  188. xmlStr = xmlStr.replaceAll("%20%20%20%20%20", "");
  189. xmlStr = xmlStr.replaceAll("%20%20%20%20%", "");
  190. xmlStr = xmlStr.replaceAll("%20%20%", "");
  191. //xmlStr = unescape(xmlStr);
  192. //alert("xmlStr="+xmlStr);
  193. switch (detail) {
  194. case "snippet":
  195. re = new RegExp("detail%20face%3D%22snippet%22.+/cats", "igsu");
  196. break;
  197. case "contacts":
  198. re = new RegExp("detail%20face%3D%22contacts%22.+/email", "igsu");
  199. break;
  200. case "other info":
  201. re = new RegExp("detail%20face%3D%22other%20info%22.+/guid", "igsu");
  202. break;
  203. case "password":
  204. re = new RegExp("detail%20face%3D%22password%22.+/password", "igsu");
  205. break;
  206. }
  207. s = re.exec(xmlStr);
  208. if (!s || s.length===0) {
  209. //ret = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Error! #1";
  210. alert("Error#1");
  211. return ret;
  212. }
  213. xmlStr = s[0];
  214. xmlStr = "<"+xmlStr+"></detail>";
  215. xmlStr = unescape(xmlStr);
  216. //alert(xmlStr);
  217. const parser = new DOMParser();
  218. const doc = parser.parseFromString(xmlStr, "text/xml");
  219. x = doc.getElementsByTagName("detail");
  220. if (x.length===0) {
  221. //ret = "Error! #2";
  222. alert("Error#2");
  223. return ret;
  224. }
  225. //ret += "<div style='padding:10px;'>";
  226. for (i = 0; i < x[0].childNodes.length; i++) {
  227. if (x[0].childNodes[i].nodeType === 1) {
  228. if (x[0].childNodes[i].nodeName === "code") {
  229. document.getElementById("snip-detail-" + x[0].childNodes[i].nodeName).innerHTML = htmlEncode(x[0].childNodes[i].textContent);
  230. } else if (x[0].childNodes[i].nodeName === "password") {
  231. document.getElementById("comp-pwd").value = htmlEncode(x[0].childNodes[i].textContent);
  232. } else {
  233. //alert(x[0].childNodes[i].nodeName);
  234. document.getElementById("snip-detail-" + x[0].childNodes[i].nodeName).value = x[0].childNodes[i].textContent;
  235. }
  236. }
  237. }
  238. //if ((detail==="pictures") || (detail==="menu")) {
  239. // ret += "<div style='padding-left:80px;clear:both;'><br>you can use eg. Goolge Drive or Microsoft OneDrive to host your pictures.</div>"
  240. //}
  241. //ret += "</div>";
  242. return ret;
  243. }
  244. /*
  245. * Store in the cube object the new data of the text control
  246. *
  247. * @param {InterfaceEl} tthis, the text control under editing
  248. * @returns void
  249. */
  250. function storeData(tthis) {
  251. lineNewVal = $(tthis).val();
  252. //alert(lineNewVal);
  253. nodeName = tthis.id;
  254. nodeName = nodeName.replace("snip-detail-","");
  255. //alert(nodeName);
  256. xmlStr = curcube.getxml();
  257. //$("#log").html($("#log").html() + "old=" + "/(\<" + nodeName + "\>).*(\<\/" + nodeName + "\>)/gs" + "\n");
  258. //$("#log").html($("#log").html() + "new=" + lineNewVal + "\n");
  259. //alert("<" + nodeName + ">" + lineNewVal + "</" + nodeName + ">");
  260. //re = "/(\<" + nodeName + "\>).*(\<\/" + nodeName + "\>)/gs";
  261. switch (nodeName) {
  262. case "title":
  263. re = /(\<title>).*(\<\/title>)/gs;
  264. break;
  265. case "desc":
  266. re = /(\<desc>).*(\<\/desc>)/gs;
  267. break;
  268. case "code":
  269. re = /(\<code>\<\!\[CDATA\[).*(\]\]\>\<\/code>)/gs;
  270. break;
  271. case "tags":
  272. re = /(\<tags>).*(\<\/tags>)/gs;
  273. break;
  274. case "cats":
  275. re = /(\<cats>).*(\<\/cats>)/gs;
  276. break;
  277. case "label":
  278. re = /(\<label>).*(\<\/label>)/gs;
  279. break;
  280. case "link":
  281. re = /(\<link>).*(\<\/link>)/gs;
  282. break;
  283. case "email":
  284. re = /(\<email>).*(\<\/email>)/gs;
  285. break;
  286. }
  287. xmlStr = xmlStr.replace(re, "$1" + lineNewVal + "$2");
  288. //xmlStr = xmlStr.replace("<" + nodeName + ">" + lineOldVal + "</" + nodeName + ">", "<" + nodeName + ">" + lineNewVal + "</" + nodeName + ">");
  289. //alert(xmlStr);
  290. curcube.xml = xmlStr;
  291. dataChanged = true;
  292. }
  293. function _saveData() {
  294. if (dataChanged) {
  295. curcube.savedata();
  296. dataChanged = false;
  297. }
  298. }
  299. setInterval("_saveData()", 1500);
  300. /*
  301. * Display the given data detail
  302. *
  303. * @param <interfaceEl> selected cube
  304. * @returns void
  305. */
  306. function openDetail() {
  307. //alert(curcube.getxml());
  308. myhtml = getDetailData(curcube.getxml(), "snippet") + getDetailData(curcube.getxml(), "contacts") + getDetailData(curcube.getxml(), "other info") + getDetailData(curcube.getxml(), "password");
  309. $('#modalButton1').click();
  310. }
  311. </script>
  312. <?php require APP_SCRIPT_PATH . "/footer.php";?>