From 557c38177150d5aa0378fba6faf1588f2c8c7856 Mon Sep 17 00:00:00 2001 From: danix Date: Wed, 11 Jul 2018 12:22:50 +0200 Subject: [PATCH 1/1] initial commit --- danixland-wporg-stats.php | 327 ++++++++++++++++++++++++++++++++++++++ i18n/index.php | 1 + index.php | 1 + js/index.php | 1 + readme.txt | 84 ++++++++++ 5 files changed, 414 insertions(+) create mode 100644 danixland-wporg-stats.php create mode 100644 i18n/index.php create mode 100644 index.php create mode 100644 js/index.php create mode 100644 readme.txt diff --git a/danixland-wporg-stats.php b/danixland-wporg-stats.php new file mode 100644 index 0000000..e22aeb1 --- /dev/null +++ b/danixland-wporg-stats.php @@ -0,0 +1,327 @@ + true, + 'rating' => false, + 'description' => false, + 'short_description' => false, + 'donate_link' => false, + 'tags' => false, + 'sections' => false, + 'homepage' => true, + 'added' => false, + 'last_updated' => false, + 'compatibility' => false, + 'tested' => false, + 'requires' => false, + 'downloadlink' => false, + ); + $args = (object) array( 'author' => $author, 'fields' => $fields ); + $request = array( 'action' => 'query_plugins', 'timeout' => 15, 'request' => serialize( $args) ); + $response = wp_remote_post( $url, array( 'body' => $request ) ); + $plugins_info = unserialize( $response['body'] ); + $result = array(); + $total_dl = ''; + $total_avg = ''; + if ( isset( $plugins_info ) ) { + # let's build our array of data to return + foreach ($plugins_info->plugins as $plugin) { + $pl_name = $plugin->slug; + $pl_dirlink = 'https://wordpress.org/plugins/' . $pl_name; + $pl_icon = 'https://ps.w.org/' . $pl_name . '/assets/icon-256x256.png'; + $pl_download = $plugin->download_link; + $pl_downloaded = $plugin->downloaded; + $pl_home = $plugin->homepage; + $pl_voters = $plugin->num_ratings; + $pl_stars = $plugin->ratings; + $avg_vote = ($pl_stars[1] + $pl_stars[2] * 2 + $pl_stars[3] * 3 + $pl_stars[4] * 4 + $pl_stars[5] * 5) / $pl_voters; + $pl_avg_vote = ( ! is_int($avg_vote) ? 0 : $avg_vote ); + $total_dl += $pl_downloaded; + $total_avg += $pl_avg_vote; + $result[$pl_name] = array( + 'dir_link' => $pl_dirlink, + 'dl_link' => $pl_download, + 'home_link' => $pl_home, + 'icon' => $pl_icon, + 'downloaded' => $pl_downloaded, + 'voters' => $pl_voters, + 'avg_rating' => $pl_avg_vote + ); + } + $avg = $total_avg / count($plugins_info->plugins); + $result['total_plugins'] = count($plugins_info->plugins); + $result['total_downloads'] = $total_dl; + $result['average_rating'] = round( $avg, 2); + return $result; + } + return array(); +} + +/** + * This function will execute with the scheduled cron job and update the data inside the option + * @since 0.1 + */ +function dnxwporg_save_plugins_stats() { + + $author = get_option('dnxwporg_author'); + $plugins = dnxwporg_get_plugins_stats( $author ); + update_option( 'dnxwporg_plugins_stats', $plugins ); +} +add_action( 'dnxwporg_save_plugins_stats', 'dnxwporg_save_plugins_stats' ); + +/** + * we schedule the cron if it's not yet scheduled + * @since 0.1 + */ +if ( ! wp_next_scheduled( 'dnxwporg_save_plugins_stats' ) ) { + wp_schedule_event( 1407110400, 'daily', 'dnxwporg_save_plugins_stats' ); // 1407110400 is 08 / 4 / 2014 @ 0:0:0 UTC +} + +/** + * Add function to widgets_init that'll load our widget. + * @since 0.1 + */ +add_action( 'widgets_init', 'danixland_wporg_widget' ); + +/** + * Register our widget. + * 'dnx_WPOrg' is the widget class used below. + * + * @since 0.1 + */ +function danixland_wporg_widget() { + register_widget( 'dnx_WPOrg' ); +} + +/** + * dnx_WPOrg class. + * This class handles everything that needs to be handled with the widget: + * the settings, form, display, and update. Nice! + * + * @since 0.1 + */ +class dnx_WPOrg extends WP_Widget { + + + /** + * Widget setup. + */ + public function __construct() { + parent::__construct( + 'danixland-wporg-stats', + __( 'danixland WP.org Stats', 'dnxwporg' ), + array( + 'customize_selective_refresh' => true, + 'description' => __('Use this widget to display statistics about your WP.org hosted plugins on your site', 'dnxwporg'), + ) + ); + } + + /** + * Displays the setup form for the widget in the widgets page + */ + public function form( $instance ) { + $defaults = array( + 'title' => __( 'WP.org Plugins Stats', 'dnxwporg' ), + 'author' => get_option( 'dnxwporg_author' ), + 'description' => get_option( 'dnxwporg_description' ), + 'desc_content' => get_option( 'dnxwporg_desc_content' ), + 'link_wporg' => get_option( 'dnxwporg_linkto' ), + 'use_icons' => get_option( 'dnxwporg_use_icons' ) + ); + $instance = wp_parse_args( (array) $instance, $defaults ); + extract( $instance, EXTR_SKIP ); + ?> + +

+ + +

+

+ + +

+

+ id="dnxwporg_use_desc" name="get_field_name( 'description' ); ?>" /> + + + +

+

+ id="get_field_id( 'link_wporg' ); ?>" name="get_field_name( 'link_wporg' ); ?>" /> + +

+

+ id="get_field_id( 'use_icons' ); ?>" name="get_field_name( 'use_icons' ); ?>" /> + +

+ +
+ +
+ +

%s plugin with %s total downloads and an average rating of %s', '%s contributed %s plugins with %s total downloads and an average rating of %s', $plugins['total_plugins'], 'dnxwporg' ), $author, $plugins['total_plugins'], $plugins['total_downloads'], $plugins['average_rating'] ); ?>

+ +

+ +
+ +
+
    + $data) { + if (is_array($data) ) : ?> +
  • + + + <?php echo $name; ?> + + + +

    + + +

    +
  • + +
+
+
+ diff --git a/i18n/index.php b/i18n/index.php new file mode 100644 index 0000000..cb66473 --- /dev/null +++ b/i18n/index.php @@ -0,0 +1 @@ +Directory Access Prohibited'); ?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..cb66473 --- /dev/null +++ b/index.php @@ -0,0 +1 @@ +Directory Access Prohibited'); ?> \ No newline at end of file diff --git a/js/index.php b/js/index.php new file mode 100644 index 0000000..cb66473 --- /dev/null +++ b/js/index.php @@ -0,0 +1 @@ +Directory Access Prohibited'); ?> \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..45c6ec9 --- /dev/null +++ b/readme.txt @@ -0,0 +1,84 @@ +=== danixland-wporg-stats === +Contributors: danixland +Donate link: http://danix.xyz +Tags: widget, sidebar, links, plugins, list +Requires at least: 4.6 +Tested up to: 4.9.6 +Stable tag: 1.0 + +This widget will display a list of plugins by the same author hosted on the WordPress.org plugins directory. + +== Description == + +danixland-wporg.stats is a plugin that adds a new widget to be used on the Sidebar (or wherever you like). +This widget will show a list of plugins by the same author, hosted on the WordPress Plugins directory. It uses the wordpress.org API to fetch all the details and it's able to show links to the plugin page on wordpress.org or to the URI specified by the author inside the plugin itself. Other stats displayed by the plugin are the total number of downloads for all the plugins and soon the plugin will be able to display even more stats. +If an author has used the assets directory to store the plugin's icons, danixland-wporg-stats is able to fetch and display the icons as well. + + +== Installation == + +Installing danixland-wporg.stats is straightforward and requires just a few seconds: + +If you use the **"Add New Plugin"** pane from your dashboard just install it and activate it, then proceed to the last step and configure it. +Otherwise follow these steps: + +1. Download the latest version of the plugin. +1. If using the "Install Plugins->Upload" section on the WordPress admin area just upload the zip file, otherwise unpack the zip file and upload the **"danixland-wporg-stats"** directory inside the "wp-content/plugins" directory of your WordPress installation using your favourite ftp client. +1. Activate the plugin through the 'Plugins' menu in WordPress. +1. Add the widget to your sidebar from Appearance->Widgets. +1. Configure the widget options through the panel which can be accessed from the Appearance->Widgets page. + +== Frequently Asked Questions == + += What can I do to customize even more the appearance of the widget? = + +The code generated by the plugin is wrapped in an HTML element with class `widget_danixland-wporg-stats`, what kind of element is decided by your theme, if unsure ask his creator. Inside this element you'll find the content of the widget wrapped inside a div with class `dnxwporg-container`. +Contained in that element you'll find a div with the description and following there's a list of links for the plugins. + +Here's every single id and class used in this plugin: + +* `.widget_danixland-wporg-stats` +* `.dnxwporg_container` +* `.dnxwporg_description` +* `.dnxwporg-pl-count` +* `.dnxwporg-pl-dloads` +* `.dnxwporg-pl-link-desc` + += I'm stuck with your plugin and don't seem to be able to customize it/make it work, can you help me? = + +Of course, you can ask for help on [the forums](http://wordpress.org/support/) or write a comment on the main article for this plugin on [my site](https://danix.xyz/?p=3745), I'll reply ASAP ;) + += I'd like this plugin to be translated in my language, can you do this for me? = + +This plugin ships with a .POT file that can be used to create a translation of the plugin in your language, so if you're familiar with english you can help by providing a translation and it will be added to future versions of the plugin along with a link to your site on these pages ;) + +To provide a translation simply edit the file "danixland-wporg.stats.pot" and fill every line with the traduction in your language, then save it as *yourlanguagecode.po* (E.G. it_IT.po for Italian), then contact me via the forums or my site and I'll tell you how to send this file to me. I'll add your translation ASAP. + +A number of softwares exists to help you with .po files, like [POEdit](http://sourceforge.net/projects/poedit/) or [Lokalize](http://userbase.kde.org/Lokalize "for kde users") + +####If you have any other questions feel free to ask + +== Screenshots == + +1. The plugin widget as seen in the admin area. +2. The widget with standard description as seen in the twentysixteen theme. +3. The widget rocking a custom description. + +== Changelog == + += 1.0 = +* This is the first version of the plugin. + +== Upgrade Notice == + += 1.0 = +No upgrade since this is the first version ;) + + + +== ToDo list == + +* I'll work on supporting themes as well. +* custom tags inside the description +* average download, average rating and more stats coming soon +* I'm open to suggestions, so don't be shy. -- 2.20.1