Browse Source

Initial commit

master
trader418 6 months ago
parent
commit
8c63344890
3 changed files with 103 additions and 0 deletions
  1. +27
    -0
      gitea-plugin/gitea-plugin.php
  2. +9
    -0
      gitea-plugin/gitea.api.php
  3. +67
    -0
      gitea-plugin/giteaWidget.php

+ 27
- 0
gitea-plugin/gitea-plugin.php View File

@@ -0,0 +1,27 @@
<?php
/**
* Plugin Name: Gitea Showcase Plugin
* Plugin URI: https://trader418.me/
* Description: Add a widget to showcase Gitea repos
* Version: 1.0
* Author: trader418
* Author URI: https://trader418.me/
**/
add_action( 'admin_menu', 'Gitea_Showcase_menu' );
function Gitea_Showcase_menu() {
add_menu_page( 'Gitea Showcase Title', 'Gitea Showcase', 'manage_options', 'GiteaShowcase', 'Gitea_Showcase_options', "icondoesntexist" );
}
function Gitea_Showcase_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
echo '<div class="wrap">';
echo '<h1>The unofficial Gitea showcase plugin was created by Trader418. https://trader418.me</h1>';
echo '<p>It may not be a fully featured plugin but it works for what I need :)</p>';
echo '</div>';
}
require('giteaWidget.php');
function register_gitea_showcase() {
register_widget( 'Gitea_Showcase_Widget' );
}
add_action( 'widgets_init', 'register_gitea_showcase' );

+ 9
- 0
gitea-plugin/gitea.api.php View File

@@ -0,0 +1,9 @@
<?PHP
function cGet($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}

+ 67
- 0
gitea-plugin/giteaWidget.php View File

@@ -0,0 +1,67 @@
<?PHP
class Gitea_Showcase_Widget extends WP_Widget {

public function __construct() {
parent::__construct(
'Gitea_Showcase_Widget',
__( 'Gitea Showcase Widget', 'text_domain' ),
array(
'customize_selective_refresh' => true,
)
);
}
public function form( $instance ) {
$defaults = array(
'url' => '',
'username' => '',
);
extract( wp_parse_args( ( array ) $instance, $defaults ) ); ?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'url' ) ); ?>"><?php _e( 'Gitea URL', 'text_domain' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'url' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'url' ) ); ?>" type="text" value="<?php echo esc_attr( $url ); ?>" />
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'username' ) ); ?>"><?php _e( 'Gitea username', 'text_domain' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'username' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'username' ) ); ?>" type="text" value="<?php echo esc_attr( $username ); ?>" />
</p>
<?PHP
}
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['url'] = isset( $new_instance['url'] ) ? wp_strip_all_tags( $new_instance['url'] ) : '';
$instance['username'] = isset( $new_instance['username'] ) ? wp_strip_all_tags( $new_instance['username'] ) : '';
return $instance;
}

public function widget( $args, $instance ) {
extract( $args );
$url = isset( $instance['url'] ) ? apply_filters( 'widget_url', $instance['url'] ) : '';
$username = isset( $instance['username'] ) ? apply_filters( 'widget_username', $instance['username'] ) : '';
echo $before_widget;
echo '<div class="widget-text wp_widget_plugin_box">';
?>
<h3 class="widget-title"><span>My Popular Gitea Repo's</span></h3>
<?PHP
if ( $url && $username ) {
require('gitea.api.php');
$_res = json_decode(cGet($url."/api/v1/users/". $username ."/repos"), true);
echo '<ul>';
if (is_array($_res)) {
foreach($_res as $repo){
if ($repo['mirror'] != 1) {
echo "<li>";
echo "<a href='".$repo['html_url']."' target='_blank'>".$repo['name']."</a>";
echo "</li>";
}
}
}
echo "</ul>";
} else {
?>Error, please check the Gitea URL you have set<?PHP
}
echo '</div>';
echo $after_widget;
}
}

Loading…
Cancel
Save