-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContributer.php
337 lines (288 loc) · 14.5 KB
/
Contributer.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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
class Contributer {
private $plugin_directory;
private $plugin_url;
public function __construct( $file ) {
$this->plugin_directory = plugin_dir_path( $file );
$this->plugin_directory_rel = dirname( plugin_basename( $file ) );
$this->plugin_url = plugin_dir_url( $file );
add_action( 'init', array( $this, 'load_textdomain' ) );
//enque js scripts
add_action( 'wp_enqueue_scripts', array( $this, 'load_js' ) );
//enqeue css styles
add_action( 'wp_enqueue_scripts', array( $this, 'load_css' ) );
//add filter for custom avatars
add_filter( 'get_avatar' , array( $this, 'contributer_avatar' ) , 1 , 5 );
//loading core on init.
add_action( 'init', array( $this, 'load_plugin' ) );
}
public function load_plugin() {
new Sensei_Admin_Panel( $this->plugin_url.'/framework/modules/sensei-options', $this->define_page_options( $this->plugin_directory ) );
Sensei_Options::get_instance()->set_option( 'plugin_dir', $this->plugin_directory );
$login_renderer = new Contributer_Login( $this->plugin_directory );
add_shortcode( 'contributer_login', array( $login_renderer, 'contributer_login' ) );
$profile_renderer = new Contributer_Profile();
add_shortcode( 'contributer_profile', array( $profile_renderer, 'contributer_profile' ) );
$contribute_renderer = new Contributer_Contribute();
add_shortcode( 'contributer_contribute', array( $contribute_renderer, 'contributer_contribute' ) );
$this->register_user_custom_fields();
}
/**
* Load plugin textdomain.
*/
public function load_textdomain() {
load_plugin_textdomain( CONTR_PLUGIN_SLUG, false, $this->plugin_directory_rel . '/languages/' );
}
public function contributer_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
$user = false;
if ( is_numeric( $id_or_email ) ) {
$id = (int) $id_or_email;
$user = get_user_by( 'id' , $id );
}
elseif ( is_object( $id_or_email ) ) {
$id_or_email_reference_check = $id_or_email->user_id;
if ( ! empty( $id_or_email_reference_check ) ) {
$id = (int) $id_or_email->user_id;
$user = get_user_by( 'id' , $id );
}
}
else {
$user = get_user_by( 'email', $id_or_email );
}
if ( $user && is_object( $user ) ) {
$profile_image_id = get_user_meta( $user->ID, 'profile_image_attachment_id', true );
if ( empty( $profile_image_id ) ) {
$avatar = CONTR_URL_PATH . '/assets/img/default-profile-pic.jpg';
}
else {
$avatar = wp_get_attachment_url( $profile_image_id );
}
$avatar = "<img alt='{$alt}' src='{$avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
}
return $avatar;
}
public function load_css() {
wp_enqueue_style( 'contributer_login', $this->plugin_url.'/assets/css/main.css', false, '1.0' );
}
public function load_js() {
if ( is_user_logged_in() ) {
wp_enqueue_script( 'contributer_main', $this->plugin_url.'/assets/js/main.js', array( 'jquery', 'jquery-form' ), '1.0', true );
wp_localize_script( 'contributer_main', 'contributer_object', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'logged_off_with_recaptcha' => false
));
}
else {
$logged_off_with_recaptcha = false;
$sensei_instance = Sensei_Options::get_instance();
$google_recaptcha_secret_key = $sensei_instance->get_option( 'google_recaptcha_secret_key' );
$google_recaptcha_site_key = $sensei_instance->get_option( 'google_recaptcha_site_key' );
if (
$sensei_instance->get_option( 'post_publish_without_registration' ) &&
! empty( $google_recaptcha_secret_key ) &&
! empty( $google_recaptcha_site_key )
) {
$logged_off_with_recaptcha = true;
}
wp_enqueue_script( 'contributer_login', $this->plugin_url.'/assets/js/login.js', array( 'jquery' ), '1.0', true );
wp_localize_script( 'contributer_login', 'contributer_object', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'redirect_login_url' => Sensei_Options::get_instance()->get_option( 'redirect_login_url' ),
'facebook_app_id' => Sensei_Options::get_instance()->get_option( 'facebook_app_id' ),
'google_app_id' => Sensei_Options::get_instance()->get_option( 'google_app_id' ),
'facebook_login_nonce' => wp_create_nonce( 'facebook-login' ),
'logged_off_with_recaptcha' => $logged_off_with_recaptcha
));
if ( $sensei_instance->get_option( 'post_publish_without_registration' ) ) {
wp_enqueue_script( 'contributer_main', $this->plugin_url.'/assets/js/main.js', array( 'jquery', 'jquery-form' ), '1.0', true );
}
}
}
//enable condition checks and val expr checks in v2 for only settings page.
//currently it is executing for each call
public function define_page_options() {
$users = get_users( array( 'role' => 'administrator' ) );
$users_array = array();
foreach ( $users as $user ) {
$users_array[ $user->ID ] = $user->user_login;
}
reset( $users_array );
return array(
'page' => array(
'page_title' => __( 'Contributer Panel', CONTR_PLUGIN_SLUG ),
'menu_title' => __( 'Contributer Panel', CONTR_PLUGIN_SLUG ),
'capability' => 'manage_options',
'menu_slug' => 'contributer',
'icon_url' => false,
),
'tabs' => array(
//tab general
array(
'title' => __( 'General', CONTR_PLUGIN_SLUG ),
'id' => 'login',
'icon' => '',
'options' => array(
array(
'name' => __( 'Redirect after login', CONTR_PLUGIN_SLUG ),
'id' => 'redirect_login_url',
'desc' => __( 'Redirect url is place where user will be transfered after loggin is successfull. Homepage is default.', CONTR_PLUGIN_SLUG ),
'type' => 'text',
'value' => home_url(),
),
array(
'name' => __( 'Allow post publishing without registration/login', CONTR_PLUGIN_SLUG ),
'id' => 'post_publish_without_registration',
'desc' => __( 'Allow post publishing without registration/login', CONTR_PLUGIN_SLUG ),
'type' => 'checkbox',
'value' => false,
),
array(
'name' => __( 'Assign Author', CONTR_PLUGIN_SLUG ),
'id' => 'guest_post_author',
'type' => 'select',
'desc' => __( 'Assign Author', CONTR_PLUGIN_SLUG ),
'options' => $users_array,
'value' => key( $users_array ),
'condition' => array(
'type' => 'option',
'value' => 'post_publish_without_registration'
)
),
array(
'name' => __( 'Google reCaptcha Site Key', CONTR_PLUGIN_SLUG ),
'id' => 'google_recaptcha_site_key',
'desc' => __( 'Strongly recommended to use google reCapcha if you want to allow public posting. https://www.google.com/recaptcha/admin', CONTR_PLUGIN_SLUG ),
'type' => 'text',
'value' => '',
'condition' => array(
'type' => 'option',
'value' => 'post_publish_without_registration'
)
),
array(
'name' => __( 'Google reCaptcha Secret Key', CONTR_PLUGIN_SLUG ),
'id' => 'google_recaptcha_secret_key',
'desc' => __( 'Strongly recommended to use google reCapcha if you want to allow public posting. https://www.google.com/recaptcha/admin', CONTR_PLUGIN_SLUG ),
'type' => 'text',
'value' => '',
'condition' => array(
'type' => 'option',
'value' => 'post_publish_without_registration'
)
),
array(
'name' => __( 'Embed video into the content', CONTR_PLUGIN_SLUG ),
'id' => 'embed_video_into_content',
'desc' => __( 'Activate this if your theme's video post type does not feature a "video URL" custom field', CONTR_PLUGIN_SLUG ),
'type' => 'checkbox',
'value' => true,
'condition' => array(
'type' => 'custom',
'value' => array( $this, 'video_format_exists' ),
'disabled_type' => 'hidden'
)
),
)
),
//tab registration
array(
'title' => __( 'Socials', CONTR_PLUGIN_SLUG ),
'id' => 'socials',
'icon' => '',
'options' => array(
array(
'name' => __( 'Facebok APP id', CONTR_PLUGIN_SLUG ),
'id' => 'facebook_app_id',
'desc' => __( 'Please insert your facebook app id if you want to use facebook login.', CONTR_PLUGIN_SLUG ),
'type' => 'text',
'value' => ''
),
array(
'name' => __( 'Facebok APP secret', CONTR_PLUGIN_SLUG ),
'id' => 'facebook_app_secret',
'desc' => __( 'Please insert your facebook app secret if you want to use facebook login.', CONTR_PLUGIN_SLUG ),
'type' => 'text',
'value' => ''
),
array(
'name' => __( 'Google APP id', CONTR_PLUGIN_SLUG ),
'id' => 'google_app_id',
'desc' => __( 'Please insert your google app id if you want to use google+ login.', CONTR_PLUGIN_SLUG ),
'type' => 'text',
'value' => ''
),
array(
'name' => __( 'Google APP secret', CONTR_PLUGIN_SLUG ),
'id' => 'google_app_secret',
'desc' => __( 'Please insert your google app secret if you want to use google+ login.', CONTR_PLUGIN_SLUG ),
'type' => 'text',
'value' => ''
),
)
),
//tab shortcodes
array(
'title' => __( 'Shortcodes', CONTR_PLUGIN_SLUG ),
'id' => 'shortcodes',
'icon' => '',
'options' => array(
array(
'name' => __( 'Profile Page', CONTR_PLUGIN_SLUG ),
'id' => 'profile_page_shortcode',
'desc' => __( 'Copy & Paste this shortcode into the place where you want the profile settings page to be rendered', CONTR_PLUGIN_SLUG ),
'type' => 'text',
'value' => '[contributer_profile]',
),
array(
'name' => __( 'Contributing Page', CONTR_PLUGIN_SLUG ),
'id' => 'contribute_shortcode',
'desc' => __( 'Copy & Paste this shortcode into the place where you want the contributing form to be rendered', CONTR_PLUGIN_SLUG ),
'type' => 'text',
'value' => '[contributer_contribute]',
),
)
),
)
);
}
private function register_user_custom_fields() {
$fields = array(
array(
'title' => 'Social Links',
'fields' => array(
array(
'label' => 'Facebook',
'id' => 'facebook',
'type' => 'text',
'desc' => 'Please enter your facebook link.'
),
array(
'label' => 'Twitter',
'id' => 'twitter',
'type' => 'text',
'desc' => 'Please enter your twitter link.'
),
array(
'label' => 'Flickr',
'id' => 'flickr',
'type' => 'text',
'desc' => 'Please enter your flickr link.'
),
),
),
);
new User_Custom_Fields( $fields );
}
public function video_format_exists() {
$post_formats = get_theme_support( 'post-formats' );
if ( ! is_array( $post_formats[0] ) || empty( $post_formats[0] ) ) {
return;
}
if ( in_array( 'video', $post_formats[0] ) ) {
return true;
}
else {
return false;
}
}
}