index.php 19 KB

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