Iñigo Valentin преди 6 години
родител
ревизия
1e6923c185
променени са 5 файла, в които са добавени 640 реда и са изтрити 36 реда
  1. 2 0
      application/API/v2/API_Controller.php
  2. 125 0
      application/API/v2/help/api.php
  3. 512 0
      application/API/v2/help/index.php
  4. 1 1
      application/API/v2/upload_profile.php
  5. 0 35
      phpdoc.xml

+ 2 - 0
application/API/v2/API_Controller.php

@@ -36,6 +36,8 @@
             else{
                 $command = strtolower($params[0]);
                 switch ($command){
+                    case "help":
+                        require_once(__DIR__ . "/help/index.php");
                     case "upload_profile":
                         require_once(__DIR__ . "/upload_profile.php");
                         break;

Файловите разлики са ограничени, защото са твърде много
+ 125 - 0
application/API/v2/help/api.php


+ 512 - 0
application/API/v2/help/index.php

@@ -0,0 +1,512 @@
+<?php
+    /**
+     * API Help view.
+     *
+     * Shows API documentation.
+     *
+     * @category View
+     */
+?>
+<?php
+    include __DIR__ . "/api.php";
+?>
+<!DOCTYPE html>
+<html lang='en'>
+    <head>
+        <meta content='text/html; charset=utf-8' http-equiv='content-type'/>
+        <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1'/>
+        <title>SWDB APIv2</title>
+        <link rel='shortcut icon' href='<?=URL::IMG["LOGO"]?>sw.png'/>
+        <!-- CSS -->
+        <link rel='stylesheet' type='text/css' href='<?=URL::CSS?>ui.css'/>
+        <style>
+
+            section#navbar{
+                text-align: left;
+                position: fixed;
+                top: 0;
+                left: 0;
+                width: 15%;
+                height: 100%;
+                border-radius: 0;
+                margin: 0 1em 0 0;
+                padding: 0em 0.4em 0.1em 0.4em;
+                border-left: 0;
+                border-top: 0;
+                border-bottom: 0;
+            }
+
+            section#navbar hr{
+                height: 0em;
+                padding: 0;
+                margin: 0 1em;
+                border: 0.01em solid #3105;
+                border-radius: 1em;
+            }
+
+            section#navbar h1{
+                text-align: center;
+                margin-top: 0;
+            }
+
+            section#navbar h1 img{
+                max-width: 100%;
+                display: block;
+                margin: auto auto -1em auto;
+            }
+
+            section#navbar h1 div{
+                text-shadow: 0 0 0.5em #000000, 0 0 0.5em #000000, 0 0 0.2em #000000, 0 0 0.2em #000000;
+                font-family: monospace, monospace;
+            }
+
+            section#navbar h1 div#swdb{
+                font-weight: bold;
+                font-size: 160%;
+                margin-bottom: -0.2em;
+            }
+
+            section#navbar h1 div#api{
+                font-style: italic;
+                font-size: 110%;
+            }
+
+            section#navbar h3 {
+                margin: 0.4em 0 0.2em 1em;
+                border-left: 0.5em solid #3105;
+                border-radius: 0.2em;
+                padding-left: 0.3em;
+                background-color: #00000000;
+                transition: all .3s ease-in-out;
+            }
+
+            section#navbar h3:hover{
+                background-color: #3105;
+            }
+
+            section#navbar h3 a{
+                color: #cccccc
+            }
+
+            section#navbar h3:hover a{
+                color: #ffffff
+            }
+
+            section#navbar ul {
+                margin: 0.2em 0;
+                list-style: none;
+            }
+
+            section#navbar ul li{
+                border-left: 0.5em solid #3105;
+                border-radius: 0.2em;
+                padding-left: 0.3em;
+                margin-bottom: 0.2em;
+                background-color: #00000000;
+                transition: all .3s ease-in-out;
+            }
+
+            section#navbar ul li:hover{
+                background-color: #3105;
+            }
+
+            section#navbar ul li a{
+                color: #cccccc
+            }
+
+            section#navbar ul li:hover a{
+                color: #ffffff
+            }
+
+            section#navbar div#copyright{
+                text-align: center;
+                font-size: 70%;
+                position: absolute;
+                bottom: 1em;
+            }
+
+            section.category{
+                margin: 2em 1em 1em 18%;
+            }
+
+            section.category h2{
+                padding: 0.5em 3em;
+            }
+
+            section.category article{
+                margin: 1.5em;
+                padding-left: 1em;
+                padding-right: 1em;
+                text-align: left;
+            }
+
+            section.category article h3{
+                vertical-align: bottom;
+            }
+
+            section.category article h3 span.description{
+                font-style: italic;
+                font-size: 90%;
+            }
+
+            section.category article:not(:last-child){
+                padding-bottom: 1em;
+                margin-bottom: 1em;
+                border-bottom: 0.1em solid #ffffff66;
+            }
+
+            section.category article div.command span{
+                display: inline-block;
+                border-radius: 0.6em;
+                padding: 0.3em 0.5em;
+                border-width: 0.15em;
+                border-style: solid;
+                color: #ffffff;
+                font-family: monospace, monospace;
+                font-weight: bold;
+            }
+
+            section.category article div.command span.url{
+                background-color: #292b36;
+                border-color: #4b4d57;
+            }
+
+            section.category article div.command span.type{
+                text-transform: uppercase;
+            }
+
+            section.category article div.command span.type_GET {
+                background-color: #008000;
+                border-color: #22a222;
+            }
+
+            section.category article div.command span.type_PUT {
+                background-color: #e5c500;
+                border-color: #f7e722;
+            }
+
+            section.category article div.command span.type_POST {
+                background-color: #4070ec;
+                border-color: #6292fe;
+            }
+
+            section.category article div.command span.type_DELETE {
+                background-color: #ed0039;
+                border-color: #ff225b;
+            }
+
+            section.category article table{
+                border-collapse: collapse;
+                width: 80%;
+                border-radius: 0.5em;
+                margin: 0.5em auto 1em auto;
+            }
+
+            section.category article table th {
+                background-color: #331100;
+                text-align: left;
+                font-weight: bold;
+                padding: 0.5em 1em;
+                border: 0.1px solid #e0e0e0;
+            }
+
+            section.category article table td {
+                background-color: #352413;
+                vertical-align: top;
+                padding: 0.2em 0.4em;
+                border: #e0e0e0 1px solid;
+            }
+
+            section.category article table td.name {
+                font-family: monospace, monospace;
+                font-weight: bold;
+            }
+
+            section.category article table td.type {
+                font-family: monospace, monospace;
+                font-weight: bold;
+            }
+
+            section.category article table td.status {
+                font-family: monospace, monospace;
+                font-weight: bold;
+            }
+
+            section.category article table td.description span.optional {
+                font-size: 90%;
+                color: #bbbbbb;
+                font-style: italic;
+            }
+
+            section#example{
+                position: fixed;
+                display: none;
+                top: 15%;
+                left: 20%;
+                width: 60%;
+                max-width: 90em;
+                height: 70%;
+                max-height: 30em;
+                text-align: right;
+            }
+
+            section#example article{
+                text-align: right;
+            }
+
+            section#example article pre#example_content{
+                text-align: left;
+                background-color: #292b36;
+                border: 0.3em solid #4b4d57;
+                border-radius: 0.8em;
+                padding: 1em;
+                max-height: 20em;
+                overflow: scroll;
+            }
+
+        </style>
+        <!-- Javascript -->
+        <script>
+            function showExample(command, status, example){
+                document.getElementById('example_title').innerHTML = command + " HTTP status " + status + " response example";
+                document.getElementById('example_content').innerHTML = JSON.stringify(JSON.parse(example), null, 4);
+                document.getElementById('example').style.display = 'block';
+            }
+            function closeExample(command, status, example){
+                document.getElementById('example').style.display = 'none';
+            }
+        </script>
+        <!-- Meta tags -->
+        <link rel='canonical' href='<?=URL::BASE?>API/v2/help/'/>
+        <link rel='author' href='SWDB'/>
+        <link rel='publisher' href='SWDB'/>
+        <meta name='description' content='SWDB API v2 Documentation'/>
+        <meta property='og:title' content='SWDB APIv2'/>
+        <meta property='og:url' content='<?=URL::BASE?>API/v2/help/'/>
+        <meta property='og:description' content='SWDB API v2 Documentation'/>
+        <meta property='og:image' content='<?=URL::IMG["LOGO"]?>sw.png'/>
+        <meta property='og:site_name' content='SWDB'/>
+        <meta property='og:type' content='website'/>
+        <meta property='og:locale' content='en'/>
+        <meta name='twitter:card' content='summary'/>
+        <meta name='twitter:title' content='SWDB APIv2'/>
+        <meta name='twitter:description' content='SWDB API v2 Documentation'/>
+        <meta name='twitter:image' content='<?=URL::IMG["LOGO"]?>sw.png'/>
+        <meta name='twitter:url' content='<?=URL::BASE?>API/v2/help/'/>
+        <meta name='robots' content='index follow'/>
+    </head>
+    <body>
+        <section id='navbar' class='content'>
+            <h1>
+                <div id='swdb'>
+                    <img alt=' ' src='<?=URL::IMG["LOGO"]?>sw.png'/>
+                    SWDB
+                </div>
+                <div id='api'>
+                    API v2
+                </div>
+            </h1>
+            <hr/>
+<?php
+            foreach ($API["category"] as $category){
+?>
+                <h3>
+                    <a href='#category_<?=$category["name"]?>'>
+                        <?=$category["name"]?>
+                    </a>
+                </h3>
+                <ul>
+<?php
+                    foreach ($category["command"] as $command){
+?>
+                        <li>
+                            <a href='#command_<?=$command["name"]?>' alt='<?=$command["description"]?>'>
+                                <?=$command["name"]?>
+                            </a>
+                        </li>
+<?php
+                    }
+?>
+                </ul>
+                <hr/>
+<?php
+            }
+?>
+            <div id='copyright'>
+                Version 2.1. Developed by <a href="https://inigovalentin.com">Iñigo Valentin</a>.
+                <br/>
+                <br/>
+                Source code available on <a href="https://github.com">Github</a> under the GPLv3.
+                <br/>
+                <br/>
+                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>.
+            </div>
+        </section>
+<?php
+        foreach ($API["category"] as $category){
+?>
+            <section id='category_<?=$category["name"]?>' class='category content'>
+                <h2>
+                    <?=$category["name"]?>
+                </h2>
+<?php
+                foreach ($category["command"] as $command){
+?>
+                    <article id='command_<?=$command["name"]?>'>
+                        <h3>
+                            <?=$command["name"]?>
+                            <span class='description'>
+                                - <?=$command["description"]?>
+                            </span>
+                        </h3>
+                        <div class='command'>
+                            <span class='type type_<?=$command["type"]?>'>
+                                <?=$command["type"]?>
+                            </span>
+                            <span class='url'>
+                                <?=htmlspecialchars($command["url"])?>
+                            </span>
+                        </div>
+                        <table class='params'>
+                            <thead>
+                                <tr>
+                                    <th class='header' colspan='3'>
+                                        Parameters
+                                    </th>
+                                </tr>
+                                <tr>
+                                    <th class='name'>
+                                        Parameter
+                                    </th>
+                                    <th class='type'>
+                                        Type
+                                    </th>
+                                    <th class='description'>
+                                        Description
+                                    </th>
+                                </tr>
+                            </thead>
+                            <tbody>
+<?php
+                                foreach ($command["parameter"] as $param){
+?>
+                                    <tr>
+                                        <td class='name'>
+                                            <?=$param["key"]?>
+                                        </td>
+                                        <td class='type'>
+                                            <?=$param["type"]?>
+                                        </td>
+                                        <td class='description'>
+                                            <?=($param["optional"] ? "<span class='optional'>[Optional] </span>" : "")?>
+                                            <?=$param["description"]?>
+                                        </td>
+                                    </tr>
+<?php
+                                }
+?>
+                            </tbody>
+                        </table>
+                        <table class='success'>
+                            <thead>
+                                <tr>
+                                    <th class='header' colspan='2'>
+                                        Sucessfull Responses
+                                    </th>
+                                </tr>
+                                <tr>
+                                    <th class='status'>
+                                        Status
+                                    </th>
+                                    <th class='description'>
+                                        Description
+                                    </th>
+                                </tr>
+                            </thead>
+                            <tbody>
+<?php
+                                foreach ($command["success"] as $status){
+?>
+                                    <tr>
+                                        <td class='status'>
+                                            HTTP/1.1 <?=$status["status"]?>
+                                        </td>
+                                        <td class='description'>
+                                            <?=$status["description"]?>
+<?php
+                                            if ($status["example"] != null){
+?>
+                                                <span class='fake_a' onclick="showExample('<?=$command["name"]?>', <?=$status["status"]?>, '<?=htmlspecialchars(json_decode($status["example"]), ENT_QUOTES)?>')">
+                                                    View example.
+                                                </span>
+<?php
+                                            }
+?>
+                                        </td>
+                                    </tr>
+<?php
+                                }
+?>
+                            </tbody>
+                        </table>
+                        <table class='error'>
+                            <thead>
+                                <tr>
+                                    <th class='header' colspan='2'>
+                                        Error Responses
+                                    </th>
+                                </tr>
+                                <tr>
+                                    <th class='status'>
+                                        Status
+                                    </th>
+                                    <th class='description'>
+                                        Description
+                                    </th>
+                                </tr>
+                            </thead>
+                            <tbody>
+<?php
+                                foreach ($command["error"] as $status){
+?>
+                                    <tr>
+                                        <td class='status'>
+                                            HTTP/1.1 <?=$status["status"]?>
+                                        </td>
+                                        <td class='description'>
+                                            <?=$status["description"]?>
+<?php
+                                            if ($status["example"] != null){
+?>
+                                                <span class='fake_a' onclick="showExample('<?=$command["name"]?>', '<?=htmlspecialchars(json_decode($status["example"]), ENT_QUOTES)?>')">
+                                                    View example.
+                                                </span>
+<?php
+                                            }
+?>
+                                        </td>
+                                    </tr>
+<?php
+                                }
+?>
+                            </tbody>
+                        </table>
+                    </article>
+<?php
+                }
+?>
+            </section>
+            <section id='example' class='content'>
+                <h2 id='example_title'>
+                </h2>
+                <article>
+                    <pre id='example_content'>
+                    </pre>
+                    <input type='button' value='Close' onClick='closeExample();'>
+                </article>
+            </section>
+<?php
+        }
+?>
+    </body>
+</html>

+ 1 - 1
application/API/v2/upload_profile.php

@@ -70,7 +70,7 @@
             return 500;
         }
 
-        if ($ret != 200){
+        if ($ret != 204){
             try{
                 http_response_code($ret);
                 return $ret;

+ 0 - 35
phpdoc.xml

@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<phpdoc>
-    <title>SWDB</title>
-    <parser>
-        <target>doc/.tmp</target>
-        <encoding>utf8</encoding>
-        <markers>
-            <item>TODO</item>
-            <item>FIXME</item>
-        </markers>
-        <extensions>
-            <extension>php</extension>
-            <extension>php3</extension>
-            <extension>phtml</extension>
-        </extensions>
-        <visibility></visibility>
-    </parser>
-    <transformer>
-        <target>doc</target>
-    </transformer>
-    <!--<logging>
-        <level>warn</level>
-        <paths>
-            <default>{APP_ROOT}/data/log/{DATE}.log</default>
-            <errors>{APP_ROOT}/data/log/{DATE}.errors.log</errors>
-        </paths>
-    </logging>-->
-    <transformations>
-        <!--<template name="responsive" />-->
-    </transformations>
-    <files>
-        <directory>.</directory>
-        <ignore>util/</ignore>
-    </files>
-</phpdoc>

Някои файлове не бяха показани, защото твърде много файлове са промени