| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Clicky Analytics |
| 4 |
* Plugin URI: https://deconf.com |
| 5 |
* Description: Displays Clicky Analytics reports into your Dashboard. Automatically inserts the tracking code in every page of your website. |
| 6 |
* Author: Alin Marcu |
| 7 |
* Version: 2.2.4 |
| 8 |
* Author URI: https://deconf.com |
| 9 |
* Text Domain: clicky-analytics |
| 10 |
* Domain Path: /languages |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly |
| 14 |
if ( ! defined( 'ABSPATH' ) ) |
| 15 |
exit(); |
| 16 |
|
| 17 |
// Plugin Version |
| 18 |
if ( ! defined( 'CAWP_CURRENT_VERSION' ) ) { |
| 19 |
define( 'CAWP_CURRENT_VERSION', '2.2.4' ); |
| 20 |
} |
| 21 |
|
| 22 |
if ( ! defined( 'CAWP_ENDPOINT_URL' ) ) { |
| 23 |
define( 'CAWP_ENDPOINT_URL', 'https://api.clicky.com/api/stats/4?' ); |
| 24 |
} |
| 25 |
|
| 26 |
if ( ! defined( 'CAWP_SITE_URL' ) ) { |
| 27 |
define( 'CAWP_SITE_URL', site_url( '/' ) ); |
| 28 |
} |
| 29 |
|
| 30 |
if ( ! class_exists( 'CAWP_Manager' ) ) { |
| 31 |
|
| 32 |
final class CAWP_Manager { |
| 33 |
|
| 34 |
private static $instance = null; |
| 35 |
|
| 36 |
public $config = null; |
| 37 |
|
| 38 |
public $frontend_actions = null; |
| 39 |
|
| 40 |
public $common_actions = null; |
| 41 |
|
| 42 |
public $backend_actions = null; |
| 43 |
|
| 44 |
public $frontend_item_reports = null; |
| 45 |
|
| 46 |
public $backend_setup = null; |
| 47 |
|
| 48 |
public $frontend_setup = null; |
| 49 |
|
| 50 |
public $backend_widgets = null; |
| 51 |
|
| 52 |
public $backend_item_reports = null; |
| 53 |
|
| 54 |
public $capi_controller = null; |
| 55 |
|
| 56 |
public $tracking = null; |
| 57 |
|
| 58 |
/** |
| 59 |
* Construct forbidden |
| 60 |
*/ |
| 61 |
private function __construct() { |
| 62 |
if ( null !== self::$instance ) { |
| 63 |
_doing_it_wrong( __FUNCTION__, __( "This is not allowed, read the documentation!", 'clicky-analytics' ), '4.6' ); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Clone warning |
| 69 |
*/ |
| 70 |
private function __clone() { |
| 71 |
_doing_it_wrong( __FUNCTION__, __( "This is not allowed, read the documentation!", 'clicky-analytics' ), '4.6' ); |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Wakeup warning |
| 76 |
*/ |
| 77 |
public function __wakeup() { |
| 78 |
_doing_it_wrong( __FUNCTION__, __( "This is not allowed, read the documentation!", 'clicky-analytics' ), '4.6' ); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Creates a single instance for CAWP and makes sure only one instance is present in memory. |
| 83 |
* |
| 84 |
* @return CAWP_Manager |
| 85 |
*/ |
| 86 |
public static function instance() { |
| 87 |
if ( null === self::$instance ) { |
| 88 |
self::$instance = new self(); |
| 89 |
self::$instance->setup(); |
| 90 |
self::$instance->config = new CAWP_Config(); |
| 91 |
} |
| 92 |
return self::$instance; |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Defines constants and loads required resources |
| 97 |
*/ |
| 98 |
private function setup() { |
| 99 |
|
| 100 |
// Plugin Path |
| 101 |
if ( ! defined( 'CAWP_DIR' ) ) { |
| 102 |
define( 'CAWP_DIR', plugin_dir_path( __FILE__ ) ); |
| 103 |
} |
| 104 |
|
| 105 |
// Plugin URL |
| 106 |
if ( ! defined( 'CAWP_URL' ) ) { |
| 107 |
define( 'CAWP_URL', plugin_dir_url( __FILE__ ) ); |
| 108 |
} |
| 109 |
|
| 110 |
// Plugin main File |
| 111 |
if ( ! defined( 'CAWP_FILE' ) ) { |
| 112 |
define( 'CAWP_FILE', __FILE__ ); |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Load Tools class |
| 117 |
*/ |
| 118 |
include_once ( CAWP_DIR . 'tools/tools.php' ); |
| 119 |
|
| 120 |
/** |
| 121 |
* Load Config class |
| 122 |
*/ |
| 123 |
include_once ( CAWP_DIR . 'config.php' ); |
| 124 |
|
| 125 |
/** |
| 126 |
* Load CAPI Controller class |
| 127 |
*/ |
| 128 |
include_once ( CAWP_DIR . 'tools/capi.php' ); |
| 129 |
|
| 130 |
/** |
| 131 |
* Plugin i18n |
| 132 |
*/ |
| 133 |
add_action( 'init', array( self::$instance, 'load_i18n' ) ); |
| 134 |
|
| 135 |
/** |
| 136 |
* Plugin Init |
| 137 |
*/ |
| 138 |
add_action( 'init', array( self::$instance, 'load' ) ); |
| 139 |
|
| 140 |
/** |
| 141 |
* Include Install |
| 142 |
*/ |
| 143 |
include_once ( CAWP_DIR . 'install/install.php' ); |
| 144 |
register_activation_hook( CAWP_FILE, array( 'CAWP_Install', 'install' ) ); |
| 145 |
|
| 146 |
/** |
| 147 |
* Include Uninstall |
| 148 |
*/ |
| 149 |
include_once ( CAWP_DIR . 'install/uninstall.php' ); |
| 150 |
register_uninstall_hook( CAWP_FILE, array( 'CAWP_Uninstall', 'uninstall' ) ); |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* Load i18n |
| 155 |
*/ |
| 156 |
public function load_i18n() { |
| 157 |
load_plugin_textdomain( 'clicky-analytics', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Conditional load |
| 162 |
*/ |
| 163 |
public function load() { |
| 164 |
if ( is_admin() ) { |
| 165 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
| 166 |
if ( CAWP_Tools::check_roles( self::$instance->config->options['access_back'] ) ) { |
| 167 |
/** |
| 168 |
* Load Backend ajax actions |
| 169 |
*/ |
| 170 |
include_once ( CAWP_DIR . 'admin/ajax-actions.php' ); |
| 171 |
self::$instance->backend_actions = new CAWP_Backend_Ajax(); |
| 172 |
} |
| 173 |
|
| 174 |
/** |
| 175 |
* Load Frontend ajax actions |
| 176 |
*/ |
| 177 |
include_once ( CAWP_DIR . 'front/ajax-actions.php' ); |
| 178 |
self::$instance->frontend_actions = new CAWP_Frontend_Ajax(); |
| 179 |
|
| 180 |
/** |
| 181 |
* Load Common ajax actions |
| 182 |
*/ |
| 183 |
include_once ( CAWP_DIR . 'common/ajax-actions.php' ); |
| 184 |
self::$instance->common_actions = new CAWP_Common_Ajax(); |
| 185 |
|
| 186 |
if ( self::$instance->config->options['backend_item_reports'] ) { |
| 187 |
/** |
| 188 |
* Load Backend Item Reports for Quick Edit |
| 189 |
*/ |
| 190 |
include_once ( CAWP_DIR . 'admin/item-reports.php' ); |
| 191 |
self::$instance->backend_item_reports = new CAWP_Backend_Item_Reports(); |
| 192 |
} |
| 193 |
} else if ( CAWP_Tools::check_roles( self::$instance->config->options['access_back'] ) ) { |
| 194 |
/** |
| 195 |
* Load Backend Setup |
| 196 |
*/ |
| 197 |
include_once ( CAWP_DIR . 'admin/setup.php' ); |
| 198 |
self::$instance->backend_setup = new CAWP_Backend_Setup(); |
| 199 |
|
| 200 |
if ( self::$instance->config->options['dashboard_widget'] ) { |
| 201 |
/** |
| 202 |
* Load Backend Widget |
| 203 |
*/ |
| 204 |
include_once ( CAWP_DIR . 'admin/widgets.php' ); |
| 205 |
self::$instance->backend_widgets = new CAWP_Backend_Widgets(); |
| 206 |
} |
| 207 |
|
| 208 |
if ( self::$instance->config->options['backend_item_reports'] ) { |
| 209 |
/** |
| 210 |
* Load Backend Item Reports |
| 211 |
*/ |
| 212 |
include_once ( CAWP_DIR . 'admin/item-reports.php' ); |
| 213 |
self::$instance->backend_item_reports = new CAWP_Backend_Item_Reports(); |
| 214 |
} |
| 215 |
} |
| 216 |
} else { |
| 217 |
if ( CAWP_Tools::check_roles( self::$instance->config->options['access_front'] ) ) { |
| 218 |
/** |
| 219 |
* Load Frontend Setup |
| 220 |
*/ |
| 221 |
include_once ( CAWP_DIR . 'front/setup.php' ); |
| 222 |
self::$instance->frontend_setup = new CAWP_Frontend_Setup(); |
| 223 |
|
| 224 |
if ( self::$instance->config->options['frontend_item_reports'] ) { |
| 225 |
/** |
| 226 |
* Load Frontend Item Reports |
| 227 |
*/ |
| 228 |
include_once ( CAWP_DIR . 'front/item-reports.php' ); |
| 229 |
self::$instance->frontend_item_reports = new CAWP_Frontend_Item_Reports(); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
if ( isset( self::$instance->config->options['siteid'] ) && self::$instance->config->options['siteid'] && (1 == self::$instance->config->options['tracking']) ) { |
| 234 |
/* |
| 235 |
* Load tracking |
| 236 |
*/ |
| 237 |
include_once ( CAWP_DIR . 'front/tracking.php' ); |
| 238 |
self::$instance->tracking = new CAWP_Tracking(); |
| 239 |
} |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
/** |
| 246 |
* Returns a unique instance of CAWP |
| 247 |
*/ |
| 248 |
function CAWP() { |
| 249 |
return CAWP_Manager::instance(); |
| 250 |
} |
| 251 |
|
| 252 |
/** |
| 253 |
* Start CAWP |
| 254 |
*/ |
| 255 |
CAWP(); |
| 256 |
|