index.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. <?php
  2. /**
  3. * API Help view.
  4. *
  5. * Shows API documentation.
  6. *
  7. * @category View
  8. * @var mixed[] $API API help structure.
  9. */
  10. ?>
  11. <?php
  12. include __DIR__ . "/api.php";
  13. ?>
  14. <!DOCTYPE html>
  15. <html lang='en'>
  16. <head>
  17. <meta content='text/html; charset=utf-8' http-equiv='content-type'/>
  18. <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1'/>
  19. <title>SWDB APIv2</title>
  20. <link rel='shortcut icon' href='<?=URL::IMG["LOGO"]?>sw.png'/>
  21. <!-- CSS -->
  22. <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
  23. <style>
  24. section#navbar{
  25. text-align: left;
  26. position: fixed;
  27. top: 0;
  28. left: 0;
  29. width: 15%;
  30. height: 100%;
  31. border-radius: 0;
  32. margin: 0 1em 0 0;
  33. padding: 0em 0.4em 0.1em 0.4em;
  34. border-left: 0;
  35. border-top: 0;
  36. border-bottom: 0;
  37. }
  38. section#navbar hr{
  39. height: 0em;
  40. padding: 0;
  41. margin: 0 1em;
  42. border: 0.01em solid #3105;
  43. border-radius: 1em;
  44. }
  45. section#navbar h1{
  46. text-align: center;
  47. margin-top: 0;
  48. }
  49. section#navbar h1 img{
  50. max-width: 100%;
  51. display: block;
  52. margin: auto auto -1em auto;
  53. }
  54. section#navbar h1 div{
  55. text-shadow: 0 0 0.5em #000000, 0 0 0.5em #000000, 0 0 0.2em #000000, 0 0 0.2em #000000;
  56. font-family: monospace, monospace;
  57. }
  58. section#navbar h1 div#swdb{
  59. font-weight: bold;
  60. font-size: 160%;
  61. margin-bottom: -0.2em;
  62. }
  63. section#navbar h1 div#api{
  64. font-style: italic;
  65. font-size: 110%;
  66. }
  67. section#navbar h3 {
  68. margin: 0.4em 0 0.2em 1em;
  69. border-left: 0.5em solid #3105;
  70. border-radius: 0.2em;
  71. padding-left: 0.3em;
  72. background-color: #00000000;
  73. transition: all .3s ease-in-out;
  74. }
  75. section#navbar h3:hover{
  76. background-color: #3105;
  77. }
  78. section#navbar h3 a{
  79. color: #cccccc
  80. }
  81. section#navbar h3:hover a{
  82. color: #ffffff
  83. }
  84. section#navbar ul {
  85. margin: 0.2em 0;
  86. list-style: none;
  87. }
  88. section#navbar ul li{
  89. border-left: 0.5em solid #3105;
  90. border-radius: 0.2em;
  91. padding-left: 0.3em;
  92. margin-bottom: 0.2em;
  93. background-color: #00000000;
  94. transition: all .3s ease-in-out;
  95. }
  96. section#navbar ul li:hover{
  97. background-color: #3105;
  98. }
  99. section#navbar ul li a{
  100. color: #cccccc
  101. }
  102. section#navbar ul li:hover a{
  103. color: #ffffff
  104. }
  105. section#navbar div#copyright{
  106. text-align: center;
  107. font-size: 70%;
  108. position: absolute;
  109. bottom: 1em;
  110. }
  111. section.category{
  112. margin: 2em 1em 1em 18%;
  113. }
  114. section.category h2{
  115. padding: 0.5em 3em;
  116. }
  117. section.category article{
  118. margin: 1.5em;
  119. padding-left: 1em;
  120. padding-right: 1em;
  121. text-align: left;
  122. }
  123. section.category article h3{
  124. vertical-align: bottom;
  125. }
  126. section.category article h3 span.description{
  127. font-style: italic;
  128. font-size: 90%;
  129. }
  130. section.category article:not(:last-child){
  131. padding-bottom: 1em;
  132. margin-bottom: 1em;
  133. border-bottom: 0.1em solid #ffffff66;
  134. }
  135. section.category article div.command span{
  136. display: inline-block;
  137. border-radius: 0.6em;
  138. padding: 0.3em 0.5em;
  139. border-width: 0.15em;
  140. border-style: solid;
  141. color: #ffffff;
  142. font-family: monospace, monospace;
  143. font-weight: bold;
  144. }
  145. section.category article div.command span.url{
  146. background-color: #292b36;
  147. border-color: #4b4d57;
  148. }
  149. section.category article div.command span.type{
  150. text-transform: uppercase;
  151. }
  152. section.category article div.command span.type_GET {
  153. background-color: #008000;
  154. border-color: #22a222;
  155. }
  156. section.category article div.command span.type_PUT {
  157. background-color: #e5c500;
  158. border-color: #f7e722;
  159. }
  160. section.category article div.command span.type_POST {
  161. background-color: #4070ec;
  162. border-color: #6292fe;
  163. }
  164. section.category article div.command span.type_DELETE {
  165. background-color: #ed0039;
  166. border-color: #ff225b;
  167. }
  168. section.category article table{
  169. border-collapse: collapse;
  170. width: 80%;
  171. border-radius: 0.5em;
  172. margin: 0.5em auto 1em auto;
  173. }
  174. section.category article table th {
  175. background-color: #331100;
  176. text-align: left;
  177. font-weight: bold;
  178. padding: 0.5em 1em;
  179. border: 0.1px solid #e0e0e0;
  180. }
  181. section.category article table td {
  182. background-color: #352413;
  183. vertical-align: top;
  184. padding: 0.2em 0.4em;
  185. border: #e0e0e0 1px solid;
  186. }
  187. section.category article table td.name {
  188. font-family: monospace, monospace;
  189. font-weight: bold;
  190. }
  191. section.category article table td.type {
  192. font-family: monospace, monospace;
  193. font-weight: bold;
  194. }
  195. section.category article table td.status {
  196. font-family: monospace, monospace;
  197. font-weight: bold;
  198. }
  199. section.category article table td.description span.optional {
  200. font-size: 90%;
  201. color: #bbbbbb;
  202. font-style: italic;
  203. }
  204. section#example{
  205. position: fixed;
  206. display: none;
  207. top: 15%;
  208. left: 20%;
  209. width: 60%;
  210. max-width: 90em;
  211. height: 70%;
  212. max-height: 30em;
  213. text-align: right;
  214. }
  215. section#example article{
  216. text-align: right;
  217. }
  218. section#example article pre#example_content{
  219. text-align: left;
  220. background-color: #292b36;
  221. border: 0.3em solid #4b4d57;
  222. border-radius: 0.8em;
  223. padding: 1em;
  224. max-height: 20em;
  225. overflow: scroll;
  226. }
  227. </style>
  228. <!-- Javascript -->
  229. <script>
  230. function showExample(command, status, example){
  231. document.getElementById('example_title').innerHTML = command + " HTTP status " + status + " response example";
  232. document.getElementById('example_content').innerHTML = JSON.stringify(JSON.parse(example), null, 4);
  233. document.getElementById('example').style.display = 'block';
  234. }
  235. function closeExample(command, status, example){
  236. document.getElementById('example').style.display = 'none';
  237. }
  238. </script>
  239. <!-- Meta tags -->
  240. <link rel='canonical' href='<?=URL::BASE?>API/v2/help/'/>
  241. <link rel='author' href='SWDB'/>
  242. <link rel='publisher' href='SWDB'/>
  243. <meta name='description' content='SWDB API v2 Documentation'/>
  244. <meta property='og:title' content='SWDB APIv2'/>
  245. <meta property='og:url' content='<?=URL::BASE?>API/v2/help/'/>
  246. <meta property='og:description' content='SWDB API v2 Documentation'/>
  247. <meta property='og:image' content='<?=URL::IMG["LOGO"]?>sw.png'/>
  248. <meta property='og:site_name' content='SWDB'/>
  249. <meta property='og:type' content='website'/>
  250. <meta property='og:locale' content='en'/>
  251. <meta name='twitter:card' content='summary'/>
  252. <meta name='twitter:title' content='SWDB APIv2'/>
  253. <meta name='twitter:description' content='SWDB API v2 Documentation'/>
  254. <meta name='twitter:image' content='<?=URL::IMG["LOGO"]?>sw.png'/>
  255. <meta name='twitter:url' content='<?=URL::BASE?>API/v2/help/'/>
  256. <meta name='robots' content='index follow'/>
  257. </head>
  258. <body>
  259. <section id='navbar' class='content'>
  260. <h1>
  261. <div id='swdb'>
  262. <img alt=' ' src='<?=URL::IMG["LOGO"]?>sw.png'/>
  263. SWDB
  264. </div>
  265. <div id='api'>
  266. API v2
  267. </div>
  268. </h1>
  269. <hr/>
  270. <?php
  271. foreach ($API["category"] as $category){
  272. ?>
  273. <h3>
  274. <a href='#category_<?=$category["name"]?>'>
  275. <?=$category["name"]?>
  276. </a>
  277. </h3>
  278. <ul>
  279. <?php
  280. foreach ($category["command"] as $command){
  281. ?>
  282. <li>
  283. <a href='#command_<?=$command["name"]?>' title='<?=$command["description"]?>'>
  284. <?=$command["name"]?>
  285. </a>
  286. </li>
  287. <?php
  288. }
  289. ?>
  290. </ul>
  291. <hr/>
  292. <?php
  293. }
  294. ?>
  295. <div id='copyright'>
  296. Version 2.1. Developed by <a href="https://inigovalentin.com">Iñigo Valentin</a>.
  297. <br/>
  298. <br/>
  299. Source code available on <a href="https://github.com">Github</a> under the GPLv3.
  300. <br/>
  301. <br/>
  302. Neither I nor this tool are affiliated with or endorsed by <a href="http://com2us.com/">Com2uS</a> in any way. The Summoners War logo and the monster images are property of their respective owners (Com2US, probably). Monsters images and info are parsed from <a href="https://swarfarm.com">https://swarfarm.com</a>.
  303. </div>
  304. </section>
  305. <?php
  306. foreach ($API["category"] as $category){
  307. ?>
  308. <section id='category_<?=$category["name"]?>' class='category content'>
  309. <h2>
  310. <?=$category["name"]?>
  311. </h2>
  312. <?php
  313. foreach ($category["command"] as $command){
  314. ?>
  315. <article id='command_<?=$command["name"]?>'>
  316. <h3>
  317. <?=$command["name"]?>
  318. <span class='description'>
  319. - <?=$command["description"]?>
  320. </span>
  321. </h3>
  322. <div class='command'>
  323. <span class='type type_<?=$command["type"]?>'>
  324. <?=$command["type"]?>
  325. </span>
  326. <span class='url'>
  327. <?=htmlspecialchars($command["url"])?>
  328. </span>
  329. </div>
  330. <table class='params'>
  331. <thead>
  332. <tr>
  333. <th class='header' colspan='3'>
  334. Parameters
  335. </th>
  336. </tr>
  337. <tr>
  338. <th class='name'>
  339. Parameter
  340. </th>
  341. <th class='type'>
  342. Type
  343. </th>
  344. <th class='description'>
  345. Description
  346. </th>
  347. </tr>
  348. </thead>
  349. <tbody>
  350. <?php
  351. foreach ($command["parameter"] as $param){
  352. ?>
  353. <tr>
  354. <td class='name'>
  355. <?=$param["key"]?>
  356. </td>
  357. <td class='type'>
  358. <?=$param["type"]?>
  359. </td>
  360. <td class='description'>
  361. <?=($param["optional"] ? "<span class='optional'>[Optional] </span>" : "")?>
  362. <?=$param["description"]?>
  363. </td>
  364. </tr>
  365. <?php
  366. }
  367. ?>
  368. </tbody>
  369. </table>
  370. <table class='success'>
  371. <thead>
  372. <tr>
  373. <th class='header' colspan='2'>
  374. Sucessfull Responses
  375. </th>
  376. </tr>
  377. <tr>
  378. <th class='status'>
  379. Status
  380. </th>
  381. <th class='description'>
  382. Description
  383. </th>
  384. </tr>
  385. </thead>
  386. <tbody>
  387. <?php
  388. foreach ($command["success"] as $status){
  389. ?>
  390. <tr>
  391. <td class='status'>
  392. HTTP/1.1 <?=$status["status"]?>
  393. </td>
  394. <td class='description'>
  395. <?=$status["description"]?>
  396. <?php
  397. if ($status["example"] != null){
  398. ?>
  399. <span class='fake_a' onclick="showExample('<?=$command["name"]?>', <?=$status["status"]?>, '<?=htmlspecialchars(json_decode($status["example"]), ENT_QUOTES)?>')">
  400. View example.
  401. </span>
  402. <?php
  403. }
  404. ?>
  405. </td>
  406. </tr>
  407. <?php
  408. }
  409. ?>
  410. </tbody>
  411. </table>
  412. <table class='error'>
  413. <thead>
  414. <tr>
  415. <th class='header' colspan='2'>
  416. Error Responses
  417. </th>
  418. </tr>
  419. <tr>
  420. <th class='status'>
  421. Status
  422. </th>
  423. <th class='description'>
  424. Description
  425. </th>
  426. </tr>
  427. </thead>
  428. <tbody>
  429. <?php
  430. foreach ($command["error"] as $status){
  431. ?>
  432. <tr>
  433. <td class='status'>
  434. HTTP/1.1 <?=$status["status"]?>
  435. </td>
  436. <td class='description'>
  437. <?=$status["description"]?>
  438. <?php
  439. if ($status["example"] != null){
  440. ?>
  441. <span class='fake_a' onclick="showExample('<?=$command["name"]?>', '<?=htmlspecialchars(json_decode($status["example"]), ENT_QUOTES)?>')">
  442. View example.
  443. </span>
  444. <?php
  445. }
  446. ?>
  447. </td>
  448. </tr>
  449. <?php
  450. }
  451. ?>
  452. </tbody>
  453. </table>
  454. </article>
  455. <?php
  456. }
  457. ?>
  458. </section>
  459. <section id='example' class='content'>
  460. <h2 id='example_title'>
  461. </h2>
  462. <article>
  463. <pre id='example_content'>
  464. </pre>
  465. <input type='button' value='Close' onClick='closeExample();'>
  466. </article>
  467. </section>
  468. <?php
  469. }
  470. ?>
  471. </body>
  472. </html>