-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathdw-question-answer.php
277 lines (224 loc) · 8.97 KB
/
dw-question-answer.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
<?php
/**
* Plugin Name: DW Question Answer
* Description: A WordPress plugin was make by DesignWall.com to build an Question Answer system for support, asking and comunitcate with your customer
* Author: DesignWall
* Author URI: http://www.designwall.com
* Version: 1.5.7
* Text Domain: dw-question-answer
* @since 1.4.0
*/
if ( !class_exists( 'DW_Question_Answer' ) ) :
class DW_Question_Answer {
private $last_update = 180720161357; //last update time of the plugin
public function __construct() {
$this->define_constants();
$this->includes();
$this->dir = DWQA_DIR;
$this->uri = DWQA_URI;
$this->temp_dir = DWQA_TEMP_DIR;
$this->temp_uri = DWQA_TEMP_URL;
$this->stylesheet_dir = DWQA_STYLESHEET_DIR;
$this->stylesheet_uri = DWQA_STYLESHEET_URL;
$this->version = '1.5.7';
// load posttype
$this->question = new DWQA_Posts_Question();
$this->answer = new DWQA_Posts_Answer();
$this->comment = new DWQA_Posts_Comment();
$this->ajax = new DWQA_Ajax();
$this->handle = new DWQA_Handle();
$this->permission = new DWQA_Permission();
$this->status = new DWQA_Status();
$this->shortcode = new DWQA_Shortcode();
$this->template = new DWQA_Template();
$this->settings = new DWQA_Settings();
$this->editor = new DWQA_Editor();
$this->user = new DWQA_User();
$this->notifications = new DWQA_Notifications();
$this->akismet = new DWQA_Akismet();
$this->autoclosure = new DWQA_Autoclosure();
$this->filter = new DWQA_Filter();
$this->session = new DWQA_Session();
$this->metaboxes = new DWQA_Metaboxes();
$this->helptab = new DWQA_Helptab();
$this->pointer_helper = new DWQA_PointerHelper();
new DWQA_Admin_Extensions();
new DWQA_Admin_Welcome();
// All init action of plugin will be included in
add_action( 'init', array( $this, 'init' ) );
add_action( 'widgets_init', array( $this, 'widgets_init' ) );
add_filter( 'plugin_action_links', array( $this, 'go_pro' ), 10, 2 );
add_filter( 'plugin_row_meta', array( $this, 'plugin_rows_meta' ), 10, 2 );
register_activation_hook( __FILE__, array( $this, 'activate_hook' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate_hook' ) );
add_action( 'bp_include', array($this,'dwqa_setup_buddypress'), 10 );
}
public function dwqa_setup_buddypress(){
// Include the BuddyPress Component
require( DWQA_DIR . 'inc/extend/buddypress/loader.php' );
// Instantiate BuddyPress for bbPress
$this->DWQA_Buddypress = new DWQA_QA_Component();
}
public static function instance() {
static $instance = null;
if ( is_null( $instance ) ) {
$instance = new self();
}
return $instance;
}
public function includes() {
require_once DWQA_DIR . 'inc/autoload.php';
require_once DWQA_DIR . 'inc/helper/functions.php';
//require_once DWQA_DIR . 'upgrades/upgrades.php';
require_once DWQA_DIR . 'inc/deprecated.php';
require_once DWQA_DIR . 'inc/helper/plugin-compatibility.php';
require_once DWQA_DIR . 'inc/helper/theme-compatibility.php';
require_once DWQA_DIR . 'inc/widgets/Closed_Question.php';
require_once DWQA_DIR . 'inc/widgets/Latest_Question.php';
require_once DWQA_DIR . 'inc/widgets/Popular_Question.php';
require_once DWQA_DIR . 'inc/widgets/Related_Question.php';
}
public function define_constants() {
$defines = array(
'DWQA_DIR' => plugin_dir_path( __FILE__ ),
'DWQA_URI' => plugin_dir_url( __FILE__ ),
'DWQA_TEMP_DIR' => trailingslashit( get_template_directory() ),
'DWQA_TEMP_URL' => trailingslashit( get_template_directory_uri() ),
'DWQA_STYLESHEET_DIR' => trailingslashit( get_stylesheet_directory() ),
'DWQA_STYLESHEET_URL' => trailingslashit( get_stylesheet_directory_uri() ),
);
foreach( $defines as $k => $v ) {
if ( !defined( $k ) ) {
define( $k, $v );
}
}
}
public function widgets_init() {
$widgets = array(
'DWQA_Widgets_Closed_Question',
'DWQA_Widgets_Latest_Question',
'DWQA_Widgets_Popular_Question',
'DWQA_Widgets_Related_Question'
);
foreach( $widgets as $widget ) {
register_widget( $widget );
}
}
public function init() {
global $dwqa_sript_vars, $dwqa_template, $dwqa_general_settings;
$active_template = $this->template->get_template();
//Load translate text domain
// load_plugin_textdomain( 'dw-question-answer', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
// load_plugin_textdomain( 'dw-question-answer');
$locale = get_locale();
$mo = 'dw-question-answer-' . $locale . '.mo';
load_textdomain( 'dw-question-answer', WP_LANG_DIR . '/dw-question-answer/' . $mo );
load_textdomain( 'dw-question-answer', plugin_dir_path( __FILE__ ) . 'languages/' . $mo );
load_plugin_textdomain( 'dw-question-answer' );
//Scripts var
$question_category_rewrite = $dwqa_general_settings['question-category-rewrite'];
$question_category_rewrite = $question_category_rewrite ? $question_category_rewrite : 'question-category';
$question_tag_rewrite = $dwqa_general_settings['question-tag-rewrite'];
$question_tag_rewrite = $question_tag_rewrite ? $question_tag_rewrite : 'question-tag';
$dwqa_sript_vars = array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
);
$this->flush_rules();
}
// Update rewrite url when active plugin
public function activate_hook() {
$this->permission->prepare_permission_caps();
flush_rewrite_rules();
//Auto create question page
$options = get_option( 'dwqa_options' );
if ( ! isset( $options['pages']['archive-question'] ) || ( isset( $options['pages']['archive-question'] ) && ! get_post( $options['pages']['archive-question'] ) ) ) {
$args = array(
'post_title' => __( 'DWQA Questions', 'dw-question-answer' ),
'post_type' => 'page',
'post_status' => 'publish',
'post_content' => '[dwqa-list-questions]',
);
$question_page = get_page_by_path( sanitize_title( $args['post_title'] ) );
if ( ! $question_page ) {
$options['pages']['archive-question'] = wp_insert_post( $args );
} else {
// Page exists
$options['pages']['archive-question'] = $question_page->ID;
}
}
if ( ! isset( $options['pages']['submit-question'] ) || ( isset( $options['pages']['submit-question'] ) && ! get_post( $options['pages']['submit-question'] ) ) ) {
$args = array(
'post_title' => __( 'DWQA Ask Question', 'dw-question-answer' ),
'post_type' => 'page',
'post_status' => 'publish',
'post_content' => '[dwqa-submit-question-form]',
);
$ask_page = get_page_by_path( sanitize_title( $args['post_title'] ) );
if ( ! $ask_page ) {
$options['pages']['submit-question'] = wp_insert_post( $args );
} else {
// Page exists
$options['pages']['submit-question'] = $ask_page->ID;
}
}
// Valid page content to ensure shortcode was inserted
$questions_page_content = get_post_field( 'post_content', $options['pages']['archive-question'] );
if ( strpos( $questions_page_content, '[dwqa-list-questions]' ) === false ) {
$questions_page_content = str_replace( '[dwqa-submit-question-form]', '', $questions_page_content );
wp_update_post( array(
'ID' => $options['pages']['archive-question'],
'post_content' => $questions_page_content . '[dwqa-list-questions]',
) );
}
$submit_question_content = get_post_field( 'post_content', $options['pages']['submit-question'] );
if ( strpos( $submit_question_content, '[dwqa-submit-question-form]' ) === false ) {
$submit_question_content = str_replace( '[dwqa-list-questions]', '', $submit_question_content );
wp_update_post( array(
'ID' => $options['pages']['submit-question'],
'post_content' => $submit_question_content . '[dwqa-submit-question-form]',
) );
}
update_option( 'dwqa_options', $options );
update_option( 'dwqa_plugin_activated', true );
// dwqa_posttype_init();
//update option delay email
update_option('dwqa_enable_email_delay', true);
}
public function deactivate_hook() {
$this->permission->remove_permision_caps();
wp_clear_scheduled_hook( 'dwqa_hourly_event' );
flush_rewrite_rules();
}
public function flush_rules() {
if ( get_option( 'dwqa_plugin_activated', false ) || get_option( 'dwqa_plugin_upgraded', false ) ) {
delete_option( 'dwqa_plugin_upgraded' );
flush_rewrite_rules();
}
}
public function get_last_update() {
return $this->last_update;
}
public function go_pro( $actions, $file ) {
$file_name = plugin_basename( __FILE__ );
if ( $file == $file_name ) {
$actions['dwqa_go_pro'] = '<a href="http://bit.ly/dwqa-pro" style="color: red; font-weight: bold">Go Pro!</a>';
$action = $actions['dwqa_go_pro'];
unset( $actions['dwqa_go_pro'] );
array_unshift( $actions, $action );
}
return $actions;
}
public function plugin_rows_meta( $meta, $file ) {
$file_name = plugin_basename( __FILE__ );
if ( $file == $file_name ) {
$meta['extensions'] = '<a href="'.admin_url( 'edit.php?post_type=dwqa-question&page=dwqa-extensions' ).'">Extensions</a>';
// $meta['facebook'] = '<a href="">Facebook</a>';
}
return $meta;
}
}
function dwqa() {
return DW_Question_Answer::instance();
}
$GLOBALS['dwqa'] = dwqa();
endif;