fixed readme and changed stable version to 0.1 to publish to WP.org directory
[danixland-wporg-stats.git] / danixland-wporg-stats.php
index bad3d5c..f904dff 100644 (file)
@@ -324,4 +324,122 @@ class dnx_WPOrg extends WP_Widget {
        }\r
 }\r
 \r
+// Add Shortcode\r
+function dnxwporg_stats_shortcode() {\r
+\r
+       $author = sanitize_user(get_option('dnxwporg_author'), true);\r
+       $description = get_option('dnxwporg_description');\r
+       $desc_content = get_option('dnxwporg_desc_content');\r
+       $linkto = get_option('dnxwporg_linkto');\r
+       $use_icons = get_option('dnxwporg_use_icons');\r
+\r
+       /* we recover the data from the option if it is set, otherwhise we call the retrieve function directly */\r
+       $option_stats = get_option('dnxwporg_plugins_stats');\r
+    $plugins = ( false === $option_stats ? dnxwporg_get_plugins_stats() : $option_stats );\r
+\r
+    ob_start(); ?>\r
+\r
+    <div class="dnxwporg_container">\r
+           <?php if ($description) { ?>\r
+               <div class="dnxwporg_description">\r
+               <?php if (empty($desc_content)) : ?>\r
+                           <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>\r
+                       <?php else : ?>\r
+                               <p class="dnxwporg-pl-custom-desc"><?php echo $desc_content; ?></p>\r
+               <?php endif; ?>\r
+               </div>\r
+           <?php } ?>\r
+           <div class="dnxwporg_pl_list_container">\r
+                   <ul class="dnxwporg_pl_list">\r
+                   <?php foreach ($plugins as $name => $data) { \r
+                       if (is_array($data) ) : ?>\r
+                               <li class="dnxwporg_pl_item">\r
+                                       <a class="dnxwporg-pl-link" href="<?php echo ($linkto ? $data['dir_link'] : $data['home_link']) ?>">\r
+                                               <?php if ($use_icons) : ?>\r
+                                                       <img class="dnxwporg-pl-link-icon" src="<?php echo $data['icon']; ?>" alt="<?php echo $name; ?>">\r
+                                               <?php endif; ?>\r
+                                               <span class="dnxwporg-pl-link-name"><?php echo $name; ?></span>\r
+                                       </a>\r
+                                       <p class="dnxwporg-pl-stats">\r
+                                               <span class="dnxwporg-pl-tot-dloads"><?php echo $data['downloaded']; ?></span>\r
+                                               <span class="dnxwporg-pl-avg-vote"><?php echo $data['avg_rating']; ?></span>\r
+                                       </p>\r
+                               </li>\r
+                       <?php endif;\r
+                   } ?>\r
+                   </ul>\r
+           </div>\r
+    </div>\r
+       \r
+       <?php $output = ob_get_clean();\r
+       return $output;\r
+\r
+}\r
+add_shortcode( 'dnxwporg_stats', 'dnxwporg_stats_shortcode' );\r
+\r
+// Add Shortcode\r
+function dnxwporg_single_stats_shortcode( $atts ) {\r
+\r
+       // Attributes\r
+       $a = shortcode_atts(\r
+               array(\r
+                       'total_dl' => 0,\r
+                       'avg_dloads' => 0,\r
+                       'pl_count' => 0,\r
+               ),\r
+               $atts\r
+       );\r
+\r
+       /* we recover the data from the option if it is set, otherwhise we call the retrieve function directly */\r
+       $option_stats = get_option('dnxwporg_plugins_stats');\r
+    $plugins = ( false === $option_stats ? dnxwporg_get_plugins_stats() : $option_stats );\r
+       \r
+       // Build the $output variable\r
+       $output = "";\r
+\r
+       if ($a['total_dl']) {\r
+               $output = $plugins['total_downloads'];\r
+       } elseif ($a['avg_dloads']) {\r
+               $output = $plugins['average_rating'];\r
+       } elseif ($a['pl_count']) {\r
+               $output = $plugins['total_plugins'];\r
+       }\r
+\r
+       return $output;\r
+\r
+}\r
+add_shortcode( 'dnxwporg_single_stat', 'dnxwporg_single_stats_shortcode' );\r
+\r
+/**\r
+ * Shortcode that returns the plugin icon if existing\r
+ */\r
+function dnxwporg_plugin_icon( $atts ) {\r
+\r
+       // Attributes\r
+       $a = shortcode_atts(\r
+               array(\r
+                       'plugin_name' => '',\r
+               ),\r
+               $atts\r
+       );\r
+       \r
+       /* we recover the data from the option if it is set, otherwhise we call the retrieve function directly */\r
+       $option_stats = get_option('dnxwporg_plugins_stats');\r
+    $plugins = ( false === $option_stats ? dnxwporg_get_plugins_stats() : $option_stats );\r
+       \r
+       $name = $a['plugin_name'];\r
+\r
+       // Build the $output variable\r
+       $output = "";\r
+\r
+    if (array_key_exists($name, $plugins) && ! empty($plugins[$name]['icon'])) {\r
+       $output = $plugins[$name]['icon'];\r
+    } else {\r
+       $output = "";\r
+    }\r
+\r
+       return $output;\r
+\r
+}\r
+add_shortcode( 'plugin_icon', 'dnxwporg_plugin_icon' );\r
 ?>\r