diff options
Diffstat (limited to 'danixland-wporg-stats.php')
| -rw-r--r-- | danixland-wporg-stats.php | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/danixland-wporg-stats.php b/danixland-wporg-stats.php index bad3d5c..f904dff 100644 --- a/danixland-wporg-stats.php +++ b/danixland-wporg-stats.php @@ -324,4 +324,122 @@ class dnx_WPOrg extends WP_Widget { }
}
+// Add Shortcode
+function dnxwporg_stats_shortcode() {
+
+ $author = sanitize_user(get_option('dnxwporg_author'), true);
+ $description = get_option('dnxwporg_description');
+ $desc_content = get_option('dnxwporg_desc_content');
+ $linkto = get_option('dnxwporg_linkto');
+ $use_icons = get_option('dnxwporg_use_icons');
+
+ /* we recover the data from the option if it is set, otherwhise we call the retrieve function directly */
+ $option_stats = get_option('dnxwporg_plugins_stats');
+ $plugins = ( false === $option_stats ? dnxwporg_get_plugins_stats() : $option_stats );
+
+ ob_start(); ?>
+
+ <div class="dnxwporg_container">
+ <?php if ($description) { ?>
+ <div class="dnxwporg_description">
+ <?php if (empty($desc_content)) : ?>
+ <p class="dnxwporg-pl-standard-desc"><?php printf( _n('%s contributed <span class="dnxwporg-pl-count">%s</span> plugin with <span class="dnxwporg-pl-dloads">%s</span> total downloads and an average rating of <span class="dnxwporg-pl-avg-rating">%s</span>', '%s contributed <span class="dnxwporg-pl-count">%s</span> plugins with <span class="dnxwporg-pl-dloads">%s</span> total downloads and an average rating of <span class="dnxwporg-pl-avg-rating">%s</span>', $plugins['total_plugins'], 'dnxwporg' ), $author, $plugins['total_plugins'], $plugins['total_downloads'], $plugins['average_rating'] ); ?></p>
+ <?php else : ?>
+ <p class="dnxwporg-pl-custom-desc"><?php echo $desc_content; ?></p>
+ <?php endif; ?>
+ </div>
+ <?php } ?>
+ <div class="dnxwporg_pl_list_container">
+ <ul class="dnxwporg_pl_list">
+ <?php foreach ($plugins as $name => $data) {
+ if (is_array($data) ) : ?>
+ <li class="dnxwporg_pl_item">
+ <a class="dnxwporg-pl-link" href="<?php echo ($linkto ? $data['dir_link'] : $data['home_link']) ?>">
+ <?php if ($use_icons) : ?>
+ <img class="dnxwporg-pl-link-icon" src="<?php echo $data['icon']; ?>" alt="<?php echo $name; ?>">
+ <?php endif; ?>
+ <span class="dnxwporg-pl-link-name"><?php echo $name; ?></span>
+ </a>
+ <p class="dnxwporg-pl-stats">
+ <span class="dnxwporg-pl-tot-dloads"><?php echo $data['downloaded']; ?></span>
+ <span class="dnxwporg-pl-avg-vote"><?php echo $data['avg_rating']; ?></span>
+ </p>
+ </li>
+ <?php endif;
+ } ?>
+ </ul>
+ </div>
+ </div>
+
+ <?php $output = ob_get_clean();
+ return $output;
+
+}
+add_shortcode( 'dnxwporg_stats', 'dnxwporg_stats_shortcode' );
+
+// Add Shortcode
+function dnxwporg_single_stats_shortcode( $atts ) {
+
+ // Attributes
+ $a = shortcode_atts(
+ array(
+ 'total_dl' => 0,
+ 'avg_dloads' => 0,
+ 'pl_count' => 0,
+ ),
+ $atts
+ );
+
+ /* we recover the data from the option if it is set, otherwhise we call the retrieve function directly */
+ $option_stats = get_option('dnxwporg_plugins_stats');
+ $plugins = ( false === $option_stats ? dnxwporg_get_plugins_stats() : $option_stats );
+
+ // Build the $output variable
+ $output = "";
+
+ if ($a['total_dl']) {
+ $output = $plugins['total_downloads'];
+ } elseif ($a['avg_dloads']) {
+ $output = $plugins['average_rating'];
+ } elseif ($a['pl_count']) {
+ $output = $plugins['total_plugins'];
+ }
+
+ return $output;
+
+}
+add_shortcode( 'dnxwporg_single_stat', 'dnxwporg_single_stats_shortcode' );
+
+/**
+ * Shortcode that returns the plugin icon if existing
+ */
+function dnxwporg_plugin_icon( $atts ) {
+
+ // Attributes
+ $a = shortcode_atts(
+ array(
+ 'plugin_name' => '',
+ ),
+ $atts
+ );
+
+ /* we recover the data from the option if it is set, otherwhise we call the retrieve function directly */
+ $option_stats = get_option('dnxwporg_plugins_stats');
+ $plugins = ( false === $option_stats ? dnxwporg_get_plugins_stats() : $option_stats );
+
+ $name = $a['plugin_name'];
+
+ // Build the $output variable
+ $output = "";
+
+ if (array_key_exists($name, $plugins) && ! empty($plugins[$name]['icon'])) {
+ $output = $plugins[$name]['icon'];
+ } else {
+ $output = "";
+ }
+
+ return $output;
+
+}
+add_shortcode( 'plugin_icon', 'dnxwporg_plugin_icon' );
?>
|
