Browse Source

Init commit; Admin panel + verification and widget

root 6 years ago
parent
commit
efd234a6b7

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "gogs-php-api-client"]
+	path = gogs-php-api-client
+	url = giaever@git.giaever.org:joachimmg/gogs-php-api-client.git

+ 3 - 0
_inc/widget.css

@@ -0,0 +1,3 @@
+.gawpp_widget .hidden {
+    display: none !important;
+}

+ 358 - 0
class.gogs-api-wpp-admin.php

@@ -0,0 +1,358 @@
+<?php
+
+class Gogs_API_Plugin_Admin {
+    private static $init = false;
+
+    public static function init() {
+        if (self::$init)
+            return;
+
+        self::init_hooks();
+    }
+
+    private static function init_hooks() {
+        self::$init = true;
+        add_action("admin_init", array(__CLASS__, "admin_init"), 5);
+        add_action("admin_menu", array(__CLASS__, "admin_menu"), 5);
+    }
+
+    public static function admin_init() {
+
+        load_plugin_textdomain(GAWPP_TEXT_DOMAIN);
+
+        register_setting("gawpp", "gawpp_url", function(string $url) use ($verified) {
+
+            $rurl = esc_url_raw($url);
+
+            if (empty($rurl))
+                add_settings_error(
+                    "gawpp_messages",
+                    "gawpp_message",
+                    esc_html(
+                        sprintf(__("Url %s is invalid", GAWPP_TEXT_DOMAIN), 
+                            $url
+                        )
+                    ),
+                    "error"
+                );
+
+            if (($pos = strrpos($rurl, "/api/v")))
+                $rurl = substr($rurl, 0, $pos);
+
+            return empty($rurl = rtrim($rurl, "/")) ? false : $rurl;
+        });
+
+        register_setting("gawpp", "gawpp_token", function(string $token) use ($verified) {
+
+            if(preg_match("/^[0-9a-f]{40}$/i", $token))
+                return $token;
+
+            add_settings_error(
+                "gawpp_messages",
+                "gawpp_message",
+                esc_html(
+                    sprintf(__("The token \"%s\" is not a valid sha1-hash", GAWPP_TEXT_DOMAIN), $token)
+                ),
+                "error"
+            );
+
+            return false;
+        });
+
+        register_setting("gawpp", "gawpp_apiv", function(string $apiv) use ($verified) {
+            $apiv = explode(":", $apiv);
+
+            if (count($apiv) == 2 && is_numeric($apiv[0])) {
+                $idx = intval($apiv[0]);
+
+                if ($idx >= 0) {
+                    $opts = Gogs_API_Plugin::get_api_supported();
+
+                    if (isset($opts[$idx]) && $opts[$idx]["path"] == $apiv[1])
+                        return $opts[$idx]["path"];
+                }
+            }
+
+            add_settings_error(
+                "gawpp_messages",
+                "gawpp_message",
+                esc_html(
+                    sprintf(__("The api version selected \"%s\" is not supported", GAWPP_TEXT_DOMAIN), join(":", $apiv))
+                ),
+                "error"
+            );
+
+            return false;
+        });
+
+        register_setting("gawpp", "gawpp_usr", function(string $user){
+
+            if (empty(trim($user)))
+                return false;
+
+            if (preg_match("/[a-z0-9\\_\\-i\\.]+$/i", $user))
+                return $user;
+
+            add_settings_error(
+                "gawpp_messages",
+                "gawpp_message",
+                esc_html(
+                    __("The username must be valid alpha or numeric or dash(-_) or dot characters", GAWPP_TEXT_DOMAIN)
+                ),
+                "error"
+            );
+        });
+
+        register_setting("gawpp", "gawpp_credit", function(string $opt){
+
+            if (empty(trim($opt)))
+                return "yes";
+
+            if (in_array($opt, array("yes", "no")))
+                return $opt;
+
+            return "yes";
+        });
+
+        add_settings_section(
+            "gawpp_config",
+            __("Required", GAWPP_TEXT_DOMAIN),
+            function(array $args) {
+                echo sprintf(
+                    '<p id="%s">%s</p>', 
+                    esc_attr($args["id"]), 
+                    esc_html__(
+                        "Information about your Gogs-site that Gogs API WPPlugin need to know to make queries. It's recommended to fill in these fields first, to ensure you have entered the required fields correctly before filling out the optional fields.", 
+                        GAWPP_TEXT_DOMAIN
+                    )
+                );
+            },
+            "gawpp"
+        );
+
+        $field = function(array $args) {
+            $options = get_option("gawpp_" . $args["id"]);
+            echo sprintf(
+                '<input type="text" id="%1$s" name="gawpp_%1$s" class="%2$s"%3$s%4$s%5$s/>',
+                esc_attr($args["label_for"]),
+                esc_attr($args["class"]),
+                (isset($args["placeholder"]) && !empty($args["placeholder"]) ?
+                    sprintf(' placeholder="%s"', esc_attr($args["placeholder"])) : null
+                ),
+                (isset($args["data"]) && !empty($args["data"]) ?
+                    sprintf(' data-custom="%s"', esc_attr($args["data"])) : null
+                ),
+                (($value = Gogs_API_Plugin::get_option($args["label_for"])) != false ?
+                    sprintf(' value="%s"', $value) : null
+                )
+            );
+        };
+
+        add_settings_field(
+            "gawpp_url",
+            __("Gogs URL", GAWPP_TEXT_DOMAIN),
+            $field,
+            "gawpp",
+            "gawpp_config",
+            array(
+                'label_for' => "url",
+                'class' => "regular-text code",
+                'data' => "",
+                'placeholder' => 'https://git.domain.tld'
+            ),
+            trim(GAWPP_GOGS_LOGO)
+        );
+
+        add_settings_field(
+            "gawpp_token",
+            __("Application token", GAWPP_TEXT_DOMAIN),
+            $field,
+            "gawpp",
+            "gawpp_config",
+            array(
+                'label_for' => "token",
+                'class' => "regular-text code",
+                'data' => "",
+                'placeholder' => 'e.g c7397d798d241d6462ac992680fa6648d83132ab'
+            )
+        );
+
+        add_settings_field(
+            "gawpp_apiv",
+            __("API version", GAWPP_TEXT_DOMAIN),
+            function (array $args) {
+                $selected = Gogs_API_Plugin::get_api_path();
+                echo sprintf('<select id="%1$s" name="gawpp_%1$s" class="%2$s">%3$s</select>',
+                    $args["label_for"],
+                    $args["class"],
+                    (function() use ($args, $selected) {
+                        $opts = array();
+                        foreach(Gogs_API_Plugin::get_api_supported() as $key => $opt)
+                            $opts[] = sprintf('<option value="%d:%s"%s>API %s: %s</value>', 
+                                (int)$key, 
+                                esc_attr($opt["path"]),
+                                $selected == $opt["path"] ? " selected" : "",
+                                esc_html($opt["name"]),
+                                esc_html($opt["path"]) 
+                            );
+                        return join($opts);
+                    })()
+                );
+            },
+            "gawpp",
+            "gawpp_config",
+            array(
+                'label_for' => "apiv",
+                'class' => "regular-text code"
+            )
+        );
+
+        add_settings_section(
+            "gawpp_config_optional",
+            __("Optional", GAWPP_TEXT_DOMAIN),
+            function(array $args) {
+                echo sprintf(
+                    '<p id="%s">%s</p>', 
+                    esc_attr($args["id"]), 
+                    esc_html__(
+                        "Information you can add to change the experience and/or behaviour, but you should first fill out (and save!) the required fields to ensure you have entered them correctly. Otherwise it can be tricky to find out which field you have entered incorrectly, e.g if the username is unknown for your Gogs-site, Gogs API will return \"Not found\" - which is the same status code if the API URL is wrong.", 
+                        GAWPP_TEXT_DOMAIN
+                    )
+                );
+            },
+            "gawpp"
+        );
+
+        add_settings_field(
+            "gawpp_usr",
+            __("Gogs user", GAWPP_TEXT_DOMAIN),
+            $field,
+            "gawpp",
+            "gawpp_config_optional",
+            array(
+                'label_for' => "usr",
+                'class' => "regular-text code",
+                'data' => "",
+                'placeholder' => 'optional'
+            )
+        );
+
+        add_settings_field(
+            "gawpp_credit",
+            __("Allow credit", GAWPP_TEXT_DOMAIN),
+            function(array $args) {
+
+                $selected = Gogs_API_Plugin::get_option($args["label_for"]);
+
+                $inputs = array();
+                foreach(array("yes", "no") as $opt)
+                    $inputs[] = sprintf('<input type="radio" name="gawpp_%1$s" id="%2$s_%1$s" value="%2$s"%3$s%4$s/><label for="%2$s_%1$s">%5$s</label>',
+                        $args["label_for"],
+                        $opt,
+                        !empty($args["class"]) ? sprintf(' class="%s"', esc_attr($args["class"])) : null,
+                        (function() use ($selected, $opt) {
+                            if (empty($selected) && $opt == "yes")
+                                return ' checked';
+                            else if ($selected == $opt)
+                                return ' checked';
+                            return null;
+                        })(),
+                        ucfirst(esc_html__($opt, GAWPP_TEXT_DOMAIN)) . ", " . (
+                            $opt == "yes" ?
+                            __("of course I'll give you credit!", GAWPP_TEXT_DOMAIN) :
+                            sprintf('%s <a href="https://www.paypal.me/joachimmgok/86nok">%s</a>!',
+                                __("but I'll consider to", GAWPP_TEXT_DOMAIN),
+                                __("buy you a beer", GAWP_TEXT_DOMAIN)
+                            )
+                        )
+                    );
+                echo '<p>' . join("<br />", $inputs) . "</p><p class=\"description\">Similar to the credit shown below.</p>";
+            },
+            "gawpp",
+            "gawpp_config_optional",
+            array(
+                'label_for' => "credit",
+                'class' => "regular-text code",
+            )
+        );
+    }
+
+    public static function admin_menu() {
+
+        $hook = add_menu_page(
+            "Gogs API", 
+            "Gogs API options", 
+            "manage_options", 
+            "gawpp", 
+            array(__CLASS__, "display_page"),
+            GAWPP_GOGS_LOGO
+        );
+
+        add_action("load-$hook", array(__CLASS__, "display_help"));
+
+    }
+
+	public static function get_page_url($action = 'config') {
+
+		$args = array('page' => 'gawpp');
+
+		return add_query_arg( $args, admin_url('admin.php'));
+	}
+
+    public static function display_page() {
+        include GAWPP_DIR . "views/config.php";
+    }
+
+    public static function display_help() {
+
+        $screen = get_current_screen();
+
+        if (current_user_can("manage_options")) {
+            $screen->add_help_tab(
+                array(
+                    "id" => "overview",
+                    "title" => __("Overview", GAWPP_TEXT_DOMAIN),
+                    "content" => 
+                        "<p><strong>" . esc_html(__("Gogs API WPP", GAWPP_TEXT_DOMAIN)) . "</strong></p>" .
+                        "<p>Gogs API Wordpress Plugin lets you query you Gogs installation and show this data in you blog.</p>"
+                )
+            );
+
+            $screen->add_help_tab(
+                array(
+                    "id" => "setup",
+                    "title" => __("Setup", GAWPP_TEXT_DOMAIN),
+                    "content" =>
+                    "<p><strong>" . esc_html(__("Gogs API WPP Setup", GAWPP_TEXT_DOMAIN)) . "</strong></p>" . <<<EOF
+<p>To setup Gogs API WPP you must have an application token generated from your Gogs-account.</p>
+<ol>
+    <li>Generate application token from you Gogs settings and store it securely. You will only be able to read it once!</li>
+    <li>Ensure your Gogs installation supports Gogs API v1.</li>
+    <li>Enter the URL for you Gogs page, without the /api/v1/ postfix - we'll add it for you, and your application token.</li>
+    <li>If you want to list things for another user than the owner of the application token, specify the username, but you can leave it blank to operate on the authorized user. <strong>Please note</strong> that only public content (repos, organization/team memberships etc) will be listet on a specified user. <strong>This also if applies to your user, if you specify the username</strong>.</li>
+</ol>
+EOF
+                )
+            );
+        } 
+    }
+
+    public static function notify_setup_missing(string $resp = null) {
+        add_action("admin_notices", function() use ($resp) {
+            $screen = get_current_screen();
+            if ($screen->id == "toplevel_page_gawpp")
+                return;
+
+            echo sprintf('<div class="notice notice-warning"><p class="wp-clearfix"><strong>%1$s</strong> %2$s%5$s <a href="%3$s" title="%4$s" class="button button-primary alignright">%4$s</a></p></div>',
+                __("Almost done!", GAWPP_TEXT_DOMAIN),
+                __("Gogs API Wordpress Plugin needs additional setup to work.", GAWPP_TEXT_DOMAIN),
+                self::get_page_url("config"),
+                __("Complete setup", GAWPP_TEXT_DOMAIN),
+                !empty($resp) ? (
+                    " <em>" . esc_html($resp) . "</em>"
+                ) : null
+            );
+        });
+    }
+}
+?>

+ 214 - 0
class.gogs-api-wpp-widget.php

@@ -0,0 +1,214 @@
+<?php
+
+class TimeAgo extends DateInterval {
+
+    public static function set(DateInterval $obj) {
+        return unserialize(sprintf(
+            'O:%d:"%s"%s',
+            strlen(__CLASS__),
+            __CLASS__,
+            strstr(strstr(serialize($obj), '"'), ':')
+        ));
+    }
+
+    public function __toString() {
+        $str = array();
+
+        if (($y = $this->format("%y")) > 0)
+            $str["y"] = sprintf("%d %s", $y, _n("year", "years", $y, GAWPP_TEXT_DOMAIN));
+
+        if (($m = $this->format("%m")) > 0)
+            $str["m"] = sprintf("%d %s", $m, _n("month", "months", $m, GAWPP_TEXT_DOMAIN));
+
+        if (($d = $this->format("%d")) > 0)
+            $str["d"] = sprintf("%d %s", $d, _n("day", "days", $d, GAWPP_TEXT_DOMAIN));
+
+        if (empty($str) && ($h = $this->format("%h")) > 0)
+            $str["h"] = sprintf("%d %s", $h, _n("hour", "hours", $h, GAWPP_TEXT_DOMAIN));
+
+        if ((empty($str) || isset($str["h"])) && ($i = $this->format("%i")) > 0)
+            $str["i"] = sprintf("%d %s", $i, _n("minute", "minutes", $i, GAWPP_TEXT_DOMAIN));
+
+        if ((empty($str) || isset($str["i"])) && ($s = $this->format("%s")) > 0)
+            $str["s"] = sprintf("%d %s", $s, _n("second", "seconds", $s, GAWPP_TEXT_DOMAIN));
+
+        return join($str);
+    }
+}
+
+class Gogs_API_Plugin_Widget extends WP_Widget {
+    const DEFAULT_AMOUNT = 10;
+
+    private static $types = array(
+        "repos" => "Show repositories",
+        "user" => "Show user profile"
+    );
+
+    public function __construct() {
+        parent::__construct(
+            "gawpp_widget",
+            esc_html__("Gogs API WPPlugin", GAWPP_TEXT_DOMAIN),
+            array(
+                "classname" => "gawpp_widget",
+                "description" => __("Gogs GIT", GAWPP_TEXT_DOMAIN),
+            )
+        );
+    }
+
+    public function widget($args, $instance) {
+        wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
+        wp_enqueue_style($this->name, plugins_url("_inc/widget.css", __FILE__));
+
+        try {
+            $user = Gogs_API_Plugin::user();
+
+            switch($this->instance_get($instance, "type")) {
+            case "repos":
+
+                $limit = (int)$this->instance_get($instance, "amount", self::DEFAULT_AMOUNT);
+
+                $i = 0;
+
+                $out = array();
+                $now = new DateTime();
+                foreach($user->repos()->load()->all() as $key => $repo) {
+                    $out[] = $this->partial("repo",
+                        $repo->html_url,
+                        $repo->name,
+                        $repo->description,
+                        $repo->stars_count,
+                        $repo->forks_count,
+                        !$repo->private ? " hidden" : "",
+                        TimeAgo::set(
+                            $now->diff(
+                                new DateTime(!empty($repo->updated_at) ? $repo->updated_at : $repo->created_ad)
+                            )
+                        ) . $repo->updated_at
+                    );
+                }
+
+                echo $this->view("repos", $args,
+                    $this->instance_get($instance, "title", $args["widget_name"]),
+                    join($out)
+                );
+                break;
+            case "user":
+                echo $user->username;
+                break;
+            }
+        } catch (Exception $e) {
+            echo $e->getMessage();
+        }
+    }
+
+    private function partial(string $type, ...$args) {
+        ob_start();
+        include(GAWPP_DIR . "views/widget-" . $type . ".php");
+        $page = ob_get_contents();
+        ob_end_clean();
+
+        $matches = array();
+
+        $count = count($args);
+
+        if ($matches_count = preg_match_all('/[\\%][a-z0-9][\\$a-z]{0,2}/s', $page, $matches)) {   
+
+            $identicals = array();
+
+            foreach($matches[0] as $match)
+                $identicals[$match] = true;
+
+            $matches_count = count($identicals);
+
+            if ($count == $matches_count)
+                return sprintf($page, ...$args);
+        }
+
+        return __CLASS__ . "::template::partial error (" . $matches_count . "!=" . $count .")";
+    }
+
+    public function view(string $type, array $tmpl_args, ...$args) {
+        ob_start();
+        include(GAWPP_DIR . "views/widget-" . $type . ".php");
+        $page = ob_get_contents();
+        ob_end_clean();
+
+        $tmpl_args_arr = array(
+            isset($tmpl_args["before_widget"]) ? $tmpl_args["before_widget"] : sprintf('<section id="%s" class="widget %s">', $this->id, $this->id_base),
+            isset($tmpl_args["before_title"]) ? $tmpl_args["before_title"] : '<h2 class="widget-title">',
+            isset($tmpl_args["after_title"]) ? $tmpl_args["after_title"] : '</h2>',
+            isset($tmpl_args["after_widget"]) ? $tmpl_args["after_widget"] : '</section>'
+        );
+
+        $matches = array();
+
+        $count = count($tmpl_args_arr) + count($args);
+
+        if ($matches_count = preg_match_all('/[\\%][a-z0-9][\\$a-z]{0,2}/s', $page, $matches)) {   
+
+            $identicals = array();
+
+            foreach($matches[0] as $match)
+                $identicals[$match] = true;
+
+            $matches_count = count($identicals);
+
+            if ($count == $matches_count)
+                return sprintf($page, ...$tmpl_args_arr, ...$args);
+        }
+
+        return __CLASS__ . "::template error (" . $matches_count . "!=" . $count .")";
+    }
+
+    public function get_field_id($name) {
+        return parent::get_field_id("widget_" . $name);
+    }
+
+    public function get_field_name($name) {
+        return parent::get_field_name("widget_" . $name);
+    }
+
+    public function instance_get(array $instance, $name, $default = false) {
+        return isset($instance["widget_" . $name]) ? $instance["widget_" . $name] : $default;
+    }
+
+    public function form($instance) {
+        echo sprintf(
+            '<p><label for="%1$s">%2$s</label><input class="widefat" type="text" id="%1$s" name="%3$s" placeholder="%4$s: %5$s"%6$s/></p>',
+            esc_attr($this->get_field_id("title")),
+            esc_attr__("Widget title:", GAWPP_TEXT_DOMAIN),
+            esc_attr($this->get_field_name("title")),
+            __("Default", GAWPP_TEXT_DOMAIN),
+            esc_html($this->name),
+            !empty($title = $this->instance_get($instance, "title", false)) ? (
+                sprintf(' value="%s"', $title)
+            ) : null
+        );
+
+        echo sprintf(
+            '<p><label for="%1$s">%2$s</label><select class="widefat" id="%1$s" name="%3$s">%4$s</select></p>',
+            esc_attr($this->get_field_id("type")),
+            esc_attr__("Widget type:", GAWPP_TEXT_DOMAIN),
+            esc_attr($this->get_field_name("type")),
+            (function() use ($instance) {
+                $opts = array();
+                foreach (self::$types as $key => $type)
+                    $opts[] = sprintf('<option value="%s"%s>%s</option>', 
+                        $key, 
+                        !$this->instance_get($instance, "type") || $this->instance_get($instance, "type") == $key ? " selected" : "",
+                        $type
+                    );
+
+                return join($opts);
+            })()
+        );
+
+        echo sprintf(
+            '<p><label for="%1$s">%2$s</label><input class="widefat" type="number" id="%1$s" name="%3$s" value="%4$s" /></p>',
+            esc_attr($this->get_field_id("amount")),
+            esc_attr__("Amount:", GAWPP_TEXT_DOMAIN),
+            esc_attr($this->get_field_name("amount")),
+            esc_html($this->instance_get($instance, "amount", 10))
+        );
+    }
+}       

+ 123 - 0
class.gogs-api-wpp.php

@@ -0,0 +1,123 @@
+<?php
+
+require GAWPP_DIR . "gogs-php-api-client/src/gpac.php";
+
+class Gogs_API_Plugin { 
+
+    private static $versions_supported = array(
+         array("name" => "v1", "path" => "/api/v1")
+    );
+
+    private static $client = false;
+    private static $user = false;
+
+    public static function init() {
+        if (!self::$client && !empty(self::get_url()) && !empty(self::get_token())) {
+            if(($resp = self::verify()) !== true)
+                Gogs_API_Plugin_Admin::notify_setup_missing($resp);
+        } else {
+            Gogs_API_Plugin_Admin::notify_setup_missing();
+        }
+    }
+
+    public static function user() {
+        return self::$user;
+    }
+
+    public static function get_url() {
+        return self::get_option("url", false); 
+    }
+
+    public static function get_token() {
+        return self::get_option("token", false);
+    }
+
+    public static function get_user() {
+        return self::get_option("usr", false);
+    }
+
+    public static function get_api_path() {
+        return self::get_option("apiv", self::$versions_supported[0]["path"]);
+    }
+
+    public static function get_credit(bool $force = false, bool $formatted = false) {
+        if (($cred = self::get_option("credit", "yes")) && ($force || !$cred || $cred == 'yes')) {
+            $data = get_plugin_data(GAWPP_DIR . "gogs-api-wpp.php");
+            $credit = array(
+                "plugin" => array(
+                    "name" => esc_html($data["Name"]),
+                    "uri" => esc_attr($data["PluginURI"]),
+                    "version" => esc_html($data["Version"]),
+                    "fyear" => 2017,
+                    "nyear" => (int)date("Y"),
+                ), "author" => array(
+                    "name" => esc_html($data["AuthorName"]),
+                    "uri" => esc_attr($data["AuthorURI"])
+                )
+            );
+
+            if ($formatted)
+                return sprintf('<a href="%1$s" title="%2$s">%2$s</a> &copy; %3$s <a href="%4$s" title="%5$s">%5$s</a>',
+                    $credit["plugin"]["uri"],
+                    $credit["plugin"]["name"],
+                    (function() use ($credit) {
+                        if ($credit["plugin"]["fyear"] != $credit["plugin"]["nyear"])
+                            return sprintf("%d - %d", $credit["plugin"]["fyear"], $credit["plugin"]["nyear"]);
+
+                        return sprintf("%d", $credit["plugin"]["fyear"]);
+                    })(),
+                    $credit["author"]["uri"],
+                    $credit["author"]["name"]
+                );
+
+            return $credit;
+        }
+        return null;
+    }
+
+    public static function get_api_supported() {
+        return self::$versions_supported;
+    }
+
+    public static function get_option(string $name, $default = false) {
+        return !empty($ret = get_option("gawpp_" . $name, $default)) ? $ret : $default;
+    }
+
+    private static function set_option(string $name, string $value, string $autol = 'yes') {
+        return update_option("gawpp_" . $name, $value, $autol);
+    }
+
+    private static function del_option(string $name) {
+        return delete_option("gawpp_" . $name);
+    }
+
+    public static function verify() {
+        self::$client = new Gogs\API\Client(
+            self::get_url() . self::get_api_path(),
+            self::get_token()
+        );
+
+        try {
+            self::$user = self::$client->user(self::get_user())->load();
+        } catch (Gogs\Lib\Curl\Exception\HTTPUnexpectedResponse $e) {
+            return (string)$e->getMessage();
+        }
+
+        return true;
+    }
+
+    public static function on_activate() {
+        register_setting("gawpp", "gawpp_url");
+        register_setting("gawpp", "gawpp_token");
+        register_setting("gawpp", "gawpp_usr");
+    }
+
+    public static function on_deactivate() {
+        self::del_option("url");
+        self::del_option("token");
+        self::del_option("usr");
+        unregister_setting("gawpp", "gawpp_url");
+        unregister_setting("gawpp", "gawpp_token");
+        unregister_setting("gawpp", "gawpp_usr");
+    }
+}

File diff suppressed because it is too large
+ 31 - 0
gogs-api-wpp.php


+ 1 - 0
gogs-php-api-client

@@ -0,0 +1 @@
+Subproject commit 9d242c3d4399e9157abdf3c5ecab0e73f2ea99ec

+ 55 - 0
views/config.php

@@ -0,0 +1,55 @@
+<?php 
+gawpp_access();
+
+if (!gawpp_manage()) return;
+
+if (isset($_GET["settings-updated"])) {
+    $errors = count(get_settings_errors("gawpp_messages"));
+
+    add_settings_error(
+        "gawpp_messages", 
+        "gawpp_message", 
+        sprintf(
+            esc_html__("Settings saved%s!", GAWPP_TEXT_DOMAIN), 
+            (function($errors) {
+                switch ($errors) {
+                case 0:
+                    return null;
+                default:
+                    return sprintf(
+                        __(", but with %d %s", GAWPP_TEXT_DOMAIN), 
+                        $errors, 
+                        _n("error", "errors", $errors, GAWPP_TEXT_DOMAIN)
+                    );
+                }
+            })($errors)
+        ),
+        "updated"
+    );
+
+    if ($errors == 0) {
+        if (!empty($err = Gogs_API_Plugin::verify()) && is_string($err))
+            add_settings_error(
+                "gawpp_messages", 
+                "gawpp_messages", 
+                sprintf("%s", esc_html($err)),
+                "error"
+            );
+    }
+
+}
+
+settings_errors("gawpp_messages");
+
+?>
+<div class="wrap">
+    <h1><?=esc_html(get_admin_page_title());?></h1>
+    <form action="options.php" method="post">
+        <?php 
+            settings_fields("gawpp");
+            do_settings_sections("gawpp");
+            submit_button("Save configuration");
+        ?>
+    </form>
+    <center><?=Gogs_API_Plugin::get_credit(true, true);?></center>
+</div>

+ 0 - 0
views/notice.php


+ 16 - 0
views/widget-repo.php

@@ -0,0 +1,16 @@
+<dl class="row">
+    <dt class="name col-sm-3">
+        <a href="%1$s" title="%2$s">%2$s</a>
+    </dt>
+    <dd class="details col-sm-9">
+        <span>
+            <i class="fa fa-lock%6$s"></i>
+            <i class="fa fa-star"></i> %4$s
+            <i class="fa fa-code-fork" aria-hidden="true">%5$s</i>
+            %7$s
+        </span>
+    </dd>
+    <dd class="description col-sm-9">
+        %3$s
+    </dd>
+</dl>

+ 6 - 0
views/widget-repos.php

@@ -0,0 +1,6 @@
+%1$s
+    %2$s%5$s%3$s
+    <dl class="row">
+        %6$s
+    </dl>
+%4$s

Some files were not shown because too many files changed in this diff