-
Notifications
You must be signed in to change notification settings - Fork 3
/
plugin.php
272 lines (236 loc) · 8.34 KB
/
plugin.php
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
/**
* BootstrapPress - Twitter Bootstrap for WordPress
*
* @author Abid Omar
* @version 0.0.5
* @package Main
*/
/*
Plugin Name: BootstrapPress
Plugin URI: http://costartpress.com
Description: BootstrapPress gives you the Twitter Bootstrap framework styles in WordPress.
Author: Abid Omar
Author URI: http://omarabid.com
Version: 0.0.5
Text Domain: wp-bs
License: GPLv3
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
if (!class_exists('wp_bs')) {
/**
* BootstrapPress Starter Class
*
* This is the plug-in Backbone class. This class is used to Initialize,
* Install, Activate, Deactivate and Uninstall the plug-in.
*/
class wp_bs
{
/**
* Plug-in Version
* @var string
*/
public $version = "0.0.5";
/**
* Minimal WordPress version required
* @var string
*/
public $wp_version = "3.5";
function __construct()
{
//
// 1. Check plugin requirements
//
if (!$this->check_requirements()) {
return;
}
//
// 2. Define constants and load dependencies
//
$this->define_constants();
$this->load_dependencies();
//
// 3. Activation hooks
//
register_activation_hook(__FILE__, array(&$this, 'activate'));
register_deactivation_hook(__FILE__, array(&$this, 'deactivate'));
register_uninstall_hook(__FILE__, 'wp_bs::uninstall');
//
// 4. i18n
//
add_action('init', array(&$this, 'i18n'));
//
// 5. Load Bootstrap files
//
add_action('wp_enqueue_scripts', array(&$this, 'load_bootstrap'));
//
// 6. Run the plugin!
//
add_action('plugins_loaded', array(&$this, 'start'));
//
// 7. Tracking code
//
add_action('admin_init', array(&$this, 'tracking'));
}
/**
* Checks that the WordPress setup meets the plugin requirements
* @global string $wp_version
* @return boolean
*/
private function check_requirements()
{
global $wp_version;
if (!version_compare($wp_version, $this->wp_version, '>=')) {
add_action('admin_notices', 'wp_bs::display_req_notice');
return false;
}
return true;
}
/**
* Display the requirement notice
* @static
*/
static function display_req_notice()
{
global $wp_bs;
echo '<div id="message" class="error"><p><strong>';
echo __('Sorry, BootstrapPress re requires WordPress ' . $wp_bs->wp_version . ' or higher.
Please upgrade your WordPress setup', 'wp-bs');
echo '</strong></p></div>';
}
/**
* Define Global Constants for the plug-in
*/
private function define_constants()
{
/* [bootstrappress/plugin.php] */
define('BS_BASENAME', plugin_basename(__FILE__));
/* [/devl/dev/wp-content/plugins/bootstrappress] */
define('BS_DIR', dirname(__FILE__));
/* [bootstrappress] */
define('BS_FOLDER', plugin_basename(dirname(__FILE__)));
/* [/devl/dev/wp-content/plugins/bootstrappress/] */
define('BS_ABSPATH', trailingslashit(str_replace("\\", "/", WP_PLUGIN_DIR . '/' . plugin_basename(dirname(__FILE__)))));
/* [http://bootstrappress.com/dev/wp-content/plugins/bootstrappress/] */
define('BS_URLPATH', trailingslashit(WP_PLUGIN_URL . '/' . plugin_basename(dirname(__FILE__))));
/* [http://bootstrappress.com/dev/wp-admin/] */
define('BS_ADMINPATH', get_admin_url());
}
/**
* Load required files for the plug-in
*/
private function load_dependencies()
{
// Admin Panel
if (is_admin()) {
}
// Front-End Site
require_once('shortcodes/sc.php');
}
/**
* Activate the plugin
*/
public function activate()
{
}
/**
* Deactivate the plugin
*/
public function deactivate()
{
}
/**
* First time activation
*/
public function install()
{
}
/**
* Uninstall the plugin
*/
static function uninstall()
{
}
/**
* Plugin Internationalization
*/
public function i18n()
{
load_plugin_textdomain('wp-bs', false, basename(dirname(__FILE__)) . '/lang/');
}
/**
* Load Bootstrap files
*/
public function load_bootstrap()
{
wp_enqueue_script('bs-core', BS_URLPATH . 'client/js/bootstrap.js', array('jquery'));
wp_enqueue_style('bs-core', BS_URLPATH . 'client/css/bootstrap.css');
}
/**
* Run the plugin!
*/
public function start()
{
}
/**
* Usage tracking code
*/
public function tracking()
{
// PressTrends Account API Key
$api_key = 'c1le7evp66kcn23g12rn9px0iuwchgysu13j';
$auth = 'dtxpccsysdngfkh6oztlj2aoehvdb23gi';
// Start of Metrics
global $wpdb;
$data = get_transient('presstrends_cache_data');
if (!$data || $data == '') {
$api_base = 'http://api.presstrends.io/index.php/api/pluginsites/update/auth/';
$url = $api_base . $auth . '/api/' . $api_key . '/';
$count_posts = wp_count_posts();
$count_pages = wp_count_posts('page');
$comments_count = wp_count_comments();
// wp_get_theme was introduced in 3.4, for compatibility with older versions, let's do a workaround for now.
if (function_exists('wp_get_theme')) {
$theme_data = wp_get_theme();
$theme_name = urlencode($theme_data->Name);
} else {
$theme_data = get_theme_data(get_stylesheet_directory() . '/style.css');
$theme_name = $theme_data['Name'];
}
$plugin_name = '&';
foreach (get_plugins() as $plugin_info) {
$plugin_name .= $plugin_info['Name'] . '&';
}
// CHANGE __FILE__ PATH IF LOCATED OUTSIDE MAIN PLUGIN FILE
$plugin_data = get_plugin_data(__FILE__);
$posts_with_comments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type='post' AND comment_count > 0");
$data = array(
'url' => stripslashes(str_replace(array('http://', '/', ':'), '', site_url())),
'posts' => $count_posts->publish,
'pages' => $count_pages->publish,
'comments' => $comments_count->total_comments,
'approved' => $comments_count->approved,
'spam' => $comments_count->spam,
'pingbacks' => $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_type = 'pingback'"),
'post_conversion' => ($count_posts->publish > 0 && $posts_with_comments > 0) ? number_format(($posts_with_comments / $count_posts->publish) * 100, 0, '.', '') : 0,
'theme_version' => $plugin_data['Version'],
'theme_name' => $theme_name,
'site_name' => str_replace(' ', '', get_bloginfo('name')),
'plugins' => count(get_option('active_plugins')),
'plugin' => urlencode($plugin_name),
'wpversion' => get_bloginfo('version'),
);
foreach ($data as $k => $v) {
$url .= $k . '/' . $v . '/';
}
wp_remote_get($url);
set_transient('presstrends_cache_data', $data, 60 * 60 * 24);
}
}
}
}
// Initialize a new instance of the class
$wp_bs = new wp_bs();