index.php 18 KB

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