index.php 18 KB

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