-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pather-sourceforge-stats.php
More file actions
91 lines (73 loc) · 2.95 KB
/
er-sourceforge-stats.php
File metadata and controls
91 lines (73 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/*
Plugin Name: ER SourceForge Stats
Plugin URI: http://itekblog.com/wordpress-plugins/er-sourceforge-stats
Description: ER SourceForge Stats allows you to insert SourceForge download statistics into your page using a simple shortcode.
Version: 1.0.0
Author: ER (ET & RaveMaker)
Author URI: http://itekblog.com
License: GPL3
Copyright 2013 ER
*/
/**
* Main class for the plugin.
*
* @since 1.0.0
*
* @author ER (ET & RaveMaker)
*/
class ER_SourceForge_Stats {
public function __construct() {
// Include json parser
include 'ersfParser.php';
// define consts.
define('SOURCEFORGE_STATS_PLUGIN_SLUG', 'er-source-forge-stats');
define('SOURCEFORGE_STATS_PLUGIN_NAME', 'ER SourceForge Stats');
define('SOURCEFORGE_STATS_PLUGIN_SHORTCODE_NAME', 'sf');
// Create settings page.
add_action('admin_menu', array($this, 'create_admin_menu'));
if (!is_admin()) { // Only if no admin page.
// Add shortcode.
add_shortcode(SOURCEFORGE_STATS_PLUGIN_SHORTCODE_NAME, array($this, 'register_shortcode'));
}
}
public function register_shortcode($atts) {
extract(shortcode_atts(array(
'project' => 'erpxe',
'start_date' => '1999-01-01',
'end_date' => date('Y-m-d'),
'file' => '',
), $atts));
$JSON_URL = "";
if ($file=='') {
$JSON_URL = "http://sourceforge.net/projects/{$project}/files/stats/json?start_date={$start_date}&end_date={$end_date}";
} else {
$JSON_URL = "http://sourceforge.net/projects/{$project}/files/{$file}/stats/json?start_date={$start_date}&end_date={$end_date}";
}
$parser = new SimpleXmlParser();
return $parser->getData($JSON_URL);
}
public function assets() {
}
public function admin_assets() {
// name of settings page
$settings = 'settings_page_' . SOURCEFORGE_STATS_PLUGIN_SLUG;
// Bail out early if we are not on a page add/edit screen.
// First part (before &&) is checks if it is a page. second part to check if this is the settings page.
if ((!( 'post' == get_current_screen()->base && 'page' == get_current_screen()->id ) ) && (!( $settings == get_current_screen()->base && $settings == get_current_screen()->id ) ))
return;
}
public function create_admin_menu() {
$page_title = SOURCEFORGE_STATS_PLUGIN_NAME;
$menu_title = $page_title;
$capability = 'manage_options';
$menu_slug = SOURCEFORGE_STATS_PLUGIN_SLUG;
$function = array($this, 'create_setting_page');
add_options_page($page_title, $menu_title, $capability, $menu_slug, $function);
}
public function create_setting_page() {
include("howto.php");
}
}
// Instantiate the class.
$ersourceforgestats = new ER_SourceForge_Stats();