-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchabok-io.php
214 lines (182 loc) · 6.17 KB
/
chabok-io.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
<?php
/**
* Plugin Name: Chabok Integration
* Version: 1.0.0-beta
* Author: Chabok Team
* Description: This plugin provides Chabok integration features such as Push notifications and tracking.
* Plugin URI: https://doc.chabok.io/wordpress/
* Author URI: https://chabok.io/
* Text Domain: chabok-io
* Domain Path: languages
*
* Chabok Integration is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* any later version.
*
* Chabok Integration is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Chabok Integration.
*
* @author Ehsān Forqāni <ehsaan@riseup.net> (https://ehsaan.dev/)
*/
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'ChabokIO' ) ):
/**
* Chabok Integration core class.
* @package ChabokIO
* @category Core
*/
final class ChabokIO {
/**
* @var ChabokIO The one true ChabokIO.
*/
private static $instance;
/**
* @var Chabok_API Chabok API instance.
*/
public $api;
/**
* Retrieves the main ChabokIO instance.
*
* Insures that only one instance of ChabokIO class exists in memory
* at any one time. Also prevents needing to define globals all over the place.
*
* @static
* @staticvar ChabokIO $instance
* @uses ChabokIO::setup_constants() Setup the constants needed.
* @uses ChabokIO::includes() Include the required files.
* @uses ChabokIO::load_textdomain() Load the language files.
* @see chabok_io()
* @return object|ChabokIO The one true ChabokIO class instance
*/
public static function instance() {
if ( ! isset( self::$instance ) || ! ! ( self::$instance instanceof ChabokIO ) ) {
self::$instance = new ChabokIO;
self::$instance ->setup_constants();
add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ), 1 );
self::$instance->includes();
self::$instance->api = new Chabok_API();
}
return self::$instance;
}
/**
* Throw error on object clone.
*
* The whole idea of the singleton design pattern is that there is a single
* object. Therefore, we don't want the object to be cloned.
*
* @access protected
* @return void
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Forbidden', 'chabok-io' ), '1.0' );
}
/**
* Disable unserializing of the class.
*
* @access protected
* @return void
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Forbidden', 'chabok-io' ), '1.0' );
}
/**
* Setup the plugin constants.
*
* @access private
* @return void
*/
private function setup_constants() {
if ( ! defined( 'CHABOK_ROOT' ) ) {
define( 'CHABOK_ROOT', __FILE__ );
}
if ( ! defined( 'CHABOK_DIR' ) ) {
define( 'CHABOK_DIR', plugin_dir_path( CHABOK_ROOT ) );
}
if ( ! defined( 'CHABOK_URL' ) ) {
define( 'CHABOK_URL', plugin_dir_url( CHABOK_ROOT ) );
}
if ( ! defined( 'CHABOK_VER' ) ) {
define( 'CHABOK_VER', '1.0.0-beta' );
}
}
/**
* Include the required files to get
* the plugin working.
*
* @access private
* @return void
*/
private function includes() {
global $chabok_options;
require_once CHABOK_DIR . 'includes/register-settings.php';
$chabok_options = chabok_get_options();
require_once CHABOK_DIR . 'includes/functions.php';
require_once CHABOK_DIR . 'includes/class-chabok-api.php';
require_once CHABOK_DIR . 'includes/meta-box.php';
require_once CHABOK_DIR . 'includes/enqueues.php';
require_once CHABOK_DIR . 'includes/rewrite.php';
require_once CHABOK_DIR . 'includes/attribution.php';
require_once CHABOK_DIR . 'includes/tracking.php';
require_once CHABOK_DIR . 'includes/user-devices.php';
require_once CHABOK_DIR . 'includes/auto-update.php';
}
/**
* Loads the plugin language files.
*
* @return void
*/
public function load_textdomain() {
global $wp_version;
/*
* Due to the introduction of language packs through translate.wordpress.org, loading our textdomain is complex.
*
* To support existing translation files from before the change, we must look for translation files in several places and under several names.
*
* - wp-content/languages/plugins/chabok-io (introduced with language packs)
* - wp-content/languages/chabok-io/ (custom folder we have supported since 1.4)
* - wp-content/plugins/chabok-io/languages/
*
* In wp-content/languages/chabok-io/ we must look for "chabok-io-{lang}_{country}.mo"
* In wp-content/languages/plugins/chabok-io/ we only need to look for "chabok-io-{lang}_{country}.mo" as that is the new structure
* In wp-content/plugins/chabok-io/languages/, we must look for both naming conventions. This is done by filtering "load_textdomain_mofile"
*/
// Set filter for the languages directory of plugin.
$lang_dir = dirname( plugin_basename( CHABOK_ROOT ) ) . '/languages/';
$lang_dir = apply_filters( 'chabok_languages_directory', $lang_dir );
$get_locale = get_locale();
if ( $wp_version >= 4.7 ) {
$get_locale = get_user_locale();
}
$locale = apply_filters( 'plugin_locale', $get_locale, 'chabok-io' );
$mofile = sprintf( '%1$s-%2$s.mo', 'chabok-io', $locale );
// Look for wp-content/languages/chabok-io/chabok-io-{lang}_{country}.mo
$mofile_global1 = WP_LANG_DIR . '/chabok-io/chabok-io-' . $locale . '.mo';
// Look for wp-content/languages/plugins/chabok-io
$mofile_global2 = WP_LANG_DIR . '/plugins/chabok-io/' . $mofile;
if ( file_exists( $mofile_global1 ) ) {
load_textdomain( 'chabok-io', $mofile_global1 );
} elseif ( file_exists( $mofile_global2 ) ) {
load_textdomain( 'chabok-io', $mofile_global2 );
} else {
// Load the default language files.
load_plugin_textdomain( 'chabok-io', false, $lang_dir );
}
}
}
endif; // End if class_exists check.
/**
* The main function for that returns ChabokIO
*
* @return object|ChabokIO The one true ChabokIO instance.
*/
function chabok_io() {
return ChabokIO::instance();
}
// Get it running!
chabok_io();