1 | <?php
|
---|
2 |
|
---|
3 | load_plugin_textdomain('xpressme', 'wp-content/plugins/xpressme/language');
|
---|
4 |
|
---|
5 | class XPressME_Class{
|
---|
6 | var $pluginName = 'xpressme';
|
---|
7 | var $is_use_xoops_upload_path;
|
---|
8 | var $is_theme_sidebar_disp;
|
---|
9 | var $is_save_post_revision;
|
---|
10 | var $is_postnavi_title_disp;
|
---|
11 | var $is_left_postnavi_old;
|
---|
12 | var $old_post_link_text;
|
---|
13 | var $newer_post_link_text;
|
---|
14 | var $is_author_view_count;
|
---|
15 | var $is_sql_debug;
|
---|
16 | var $groupe_role;
|
---|
17 |
|
---|
18 | //constructor
|
---|
19 | function XPressME_Class()
|
---|
20 | {
|
---|
21 | global $xoops_db;
|
---|
22 |
|
---|
23 | $this->setdefault(); //not setting propaty load
|
---|
24 | $this->SettingValueRead();
|
---|
25 | }
|
---|
26 |
|
---|
27 |
|
---|
28 | function add_option_page()
|
---|
29 | {
|
---|
30 | add_options_page('XPressME', __('XPressME Settings', 'xpressme'), 8, 'xpressme_config', array(&$this, 'option_page'));
|
---|
31 | }
|
---|
32 |
|
---|
33 | function add_admin_head()
|
---|
34 | {
|
---|
35 | // add header text
|
---|
36 | }
|
---|
37 |
|
---|
38 |
|
---|
39 | //Set Default Value
|
---|
40 | function setDefault()
|
---|
41 | {
|
---|
42 | $this->is_use_xoops_upload_path = true;
|
---|
43 | $this->is_theme_sidebar_disp = true;
|
---|
44 | $this->is_save_post_revision = true;
|
---|
45 | $this->is_postnavi_title_disp = true;
|
---|
46 | $this->is_left_postnavi_old = true;
|
---|
47 | $this->old_post_link_text = __('to Old Post', 'xpressme');
|
---|
48 | $this->newer_post_link_text = __('to Newer Post', 'xpressme');
|
---|
49 | $this->is_author_view_count = false;
|
---|
50 | $this->is_sql_debug = false;
|
---|
51 | }
|
---|
52 |
|
---|
53 | function SettingValueRead()
|
---|
54 | {
|
---|
55 | global $xoops_db;
|
---|
56 | $options = get_option('xpressme_option');
|
---|
57 | if (!$options) {
|
---|
58 | $this->setDefault();
|
---|
59 | $this->SettingValueWrite('add_new');
|
---|
60 | } else {
|
---|
61 | foreach ($options as $option_name => $option_value){
|
---|
62 | $this-> {$option_name} = $option_value;
|
---|
63 | }
|
---|
64 | }
|
---|
65 | if (!empty($xoops_db)) // at install trap
|
---|
66 | $this->GroupeRoleRead();
|
---|
67 | }
|
---|
68 |
|
---|
69 | // mode 0:add 1:update
|
---|
70 | function SettingValueWrite($mode)
|
---|
71 | {
|
---|
72 | $write_options = array (
|
---|
73 | 'is_use_xoops_upload_path' => $this->is_use_xoops_upload_path ,
|
---|
74 | 'is_theme_sidebar_disp' => $this->is_theme_sidebar_disp ,
|
---|
75 | 'is_save_post_revision' => $this->is_save_post_revision ,
|
---|
76 | 'is_postnavi_title_disp' => $this->is_postnavi_title_disp ,
|
---|
77 | 'is_left_postnavi_old' => $this->is_left_postnavi_old ,
|
---|
78 | 'old_post_link_text' => $this->old_post_link_text ,
|
---|
79 | 'newer_post_link_text' => $this->newer_post_link_text,
|
---|
80 | 'is_author_view_count' => $this->is_author_view_count,
|
---|
81 | 'is_sql_debug' => $this->is_sql_debug
|
---|
82 | );
|
---|
83 | if ($mode == 'add_new') {
|
---|
84 | add_option('xpressme_option', $write_options);
|
---|
85 | } else {
|
---|
86 | update_option("xpressme_option", $write_options);
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | function GroupeRoleRead() {
|
---|
91 | global $xoops_db;
|
---|
92 |
|
---|
93 | // table sync
|
---|
94 | $table = get_wp_prefix() . 'group_role';
|
---|
95 | $xoops_group = get_xoops_prefix() . 'groups';
|
---|
96 | $sql= "SELECT * FROM $table";
|
---|
97 | $before_groupes = $xoops_db->get_results($sql);
|
---|
98 |
|
---|
99 | $sql = "DELETE FROM $table";
|
---|
100 | $xoops_db->query($sql);
|
---|
101 |
|
---|
102 |
|
---|
103 | $sql= "SELECT * FROM $xoops_group WHERE group_type <> 'Anonymous'";
|
---|
104 | $groupes = $xoops_db->get_results($sql);
|
---|
105 | $insert_sql = '';
|
---|
106 | foreach ($groupes as $groupe) {
|
---|
107 | $role = '';
|
---|
108 | foreach ($before_groupes as $before_groupe) {
|
---|
109 | if ($groupe->groupid == $before_groupe->groupid) {
|
---|
110 | $role = $before_groupe->role;
|
---|
111 | $login_all = $before_groupe->login_all;
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | $insert_sql = "INSERT INTO $table ";
|
---|
116 | $insert_sql .= "(groupid , name , description , group_type , role , login_all) ";
|
---|
117 | $insert_sql .= "VALUES (";
|
---|
118 | $insert_sql .= $groupe->groupid . ', ';
|
---|
119 | $insert_sql .= "'" . $groupe->name . "' , ";
|
---|
120 | $insert_sql .= "'" . $groupe->description . "' , ";
|
---|
121 | $insert_sql .= "'" . $groupe->group_type . "' , ";
|
---|
122 | $insert_sql .= "'" . $role . "' , '";
|
---|
123 | $insert_sql .= $login_all . "')";
|
---|
124 | $xoops_db->query($insert_sql);
|
---|
125 | }
|
---|
126 |
|
---|
127 | $sql= "SELECT * FROM $table";
|
---|
128 |
|
---|
129 | $this->groupe_role = $xoops_db->get_results($sql);
|
---|
130 | $sql= "SELECT * FROM $table";
|
---|
131 | }
|
---|
132 |
|
---|
133 | function ReadPostData()
|
---|
134 | {
|
---|
135 | $this->is_use_xoops_upload_path = stripslashes(trim($_POST['ch_is_use_xoops_upload_path']));
|
---|
136 | $this->is_theme_sidebar_disp = stripslashes(trim($_POST['ch_is_theme_sidebar_disp']));
|
---|
137 | $this->is_save_post_revision = stripslashes(trim($_POST['ch_is_save_post_revision']));
|
---|
138 | $this->is_postnavi_title_disp = stripslashes(trim($_POST['ch_is_postnavi_title_disp']));
|
---|
139 | $this->is_left_postnavi_old = stripslashes(trim($_POST['ch_is_left_postnavi_old']));
|
---|
140 | $this->old_post_link_text = stripslashes($_POST['ch_old_post_link_text']);
|
---|
141 | if(empty($this->old_post_link_text)) $this->old_post_link_text = __('to Old Post', 'xpressme');
|
---|
142 | $this->newer_post_link_text = stripslashes($_POST['ch_newer_post_link_text']);
|
---|
143 | if(empty($this->newer_post_link_text)) $this->newer_post_link_text = __('to Newer Post', 'xpressme');
|
---|
144 | $this->is_author_view_count = stripslashes(trim($_POST['ch_is_author_view_count']));
|
---|
145 | $this->is_sql_debug = stripslashes(trim($_POST['ch_is_sql_debug']));
|
---|
146 |
|
---|
147 | global $xoops_db;
|
---|
148 | $table = get_wp_prefix() . 'group_role';
|
---|
149 | // $sql= "SELECT * FROM $table";
|
---|
150 | // $this->groupe_role = $xoops_db->get_results($sql); // before Read
|
---|
151 |
|
---|
152 | foreach ($this->groupe_role as $groupe) {
|
---|
153 | $post_name = 'role_gid_' . $groupe->groupid;
|
---|
154 | $role = stripslashes(trim($_POST[$post_name]));
|
---|
155 | $post_name = 'login_all_gid_' . $groupe->groupid;
|
---|
156 | $login_all = stripslashes(trim($_POST[$post_name]));
|
---|
157 | if (empty($login_all)) $login_all = '0';
|
---|
158 | $groupe->role = $role;
|
---|
159 | $groupe->login_all = $login_all;
|
---|
160 | $update_sql = "UPDATE $table ";
|
---|
161 | $update_sql .= 'SET ';
|
---|
162 | $update_sql .= "role = '$role' , ";
|
---|
163 | $update_sql .= "login_all = $login_all ";
|
---|
164 | $update_sql .= "WHERE (groupid = '$groupe->groupid' )";
|
---|
165 | $xoops_db->query($update_sql);
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | function yes_no_radio_option($option_name,$option_desc,$yes = '',$no= ''){
|
---|
170 | if (empty( $yes )) $yes = __('YES','xpressme') ;
|
---|
171 | if (empty( $no )) $no = __('NO','xpressme') ;
|
---|
172 | $value = $this->{$option_name};
|
---|
173 | $ans_name = 'ch_' . $option_name;
|
---|
174 |
|
---|
175 | $form = "<tr>\n";
|
---|
176 | $form .= '<th><label for="images_to_link">' . $option_desc . "</label></th>\n";
|
---|
177 | $form .= "<td>\n";
|
---|
178 | if ($value){
|
---|
179 | $form .= "<label><input type='radio' name='". $ans_name . "' value='1' checked='checked' />" . $yes ."</label><br />\n";
|
---|
180 | $form .= "<label><input type='radio' name='". $ans_name . "' value='0' />". $no . "</label>\n";
|
---|
181 | }else{
|
---|
182 | $form .= "<label><input type='radio' name='". $ans_name . "' value='1' />" . $yes . "</label><br />\n";
|
---|
183 | $form .= "<label><input type='radio' name='". $ans_name . "' value='0' checked='checked' />". $no ."</label>\n";
|
---|
184 | }
|
---|
185 | $form .= "</td>\n";
|
---|
186 | $form .= "</tr><tr>\n";
|
---|
187 |
|
---|
188 | return $form;
|
---|
189 |
|
---|
190 | }
|
---|
191 |
|
---|
192 | function text_option($option_name,$option_desc){
|
---|
193 | $value = $this->{$option_name};
|
---|
194 | $ans_name = 'ch_' . $option_name;
|
---|
195 |
|
---|
196 | $form = "<tr>\n";
|
---|
197 | $form .= '<th><label for="images_to_link">' . $option_desc . "</label></th>\n";
|
---|
198 | $form .= "<td>\n";
|
---|
199 | $form .= '<label> <input name="'. $ans_name . '" type="text" size="25" maxlength="50" value="' . $value . '" /></label>'."\n";
|
---|
200 | $form .= "</td>\n";
|
---|
201 | $form .= "</tr><tr>\n";
|
---|
202 |
|
---|
203 | return $form;
|
---|
204 |
|
---|
205 | }
|
---|
206 |
|
---|
207 | function groupe_role_option(){
|
---|
208 | global $wp_roles , $xoops_db;
|
---|
209 |
|
---|
210 | $form = '';
|
---|
211 | $form .= '<tr><th><label for="role">' .__('Role Setting at Login', 'xpressme') . '</label></th>';
|
---|
212 | $form .= '<td>';
|
---|
213 | $form .= "<table>\n";
|
---|
214 | $form .= '<tr><td>' . __('XOOPS Groupe', 'xpressme') . '</td><td>' . __('WordPress Role', 'xpressme') . '</td><td>' . __('Role is set at each login', 'xpressme') . "</td></tr>\n";
|
---|
215 | foreach ($this->groupe_role as $groupe) {
|
---|
216 | $form .= "<tr>";
|
---|
217 | $form .= "<td> $groupe->name </td>";
|
---|
218 | $form .= "<td>\n" . '<select name="role_gid_'.$groupe->groupid . '" id="role_gid_' . $groupe->groupid . '">' . "\n";
|
---|
219 | $role_list = '';
|
---|
220 | $group_has_role = false;
|
---|
221 |
|
---|
222 | $select_value = $groupe->role;
|
---|
223 |
|
---|
224 | foreach($wp_roles->role_names as $role => $name) {
|
---|
225 | $name = translate_with_context($name);
|
---|
226 | if ( $role == $select_value) {
|
---|
227 | $selected = ' selected="selected"';
|
---|
228 | $group_has_role = true;
|
---|
229 | } else {
|
---|
230 | $selected = '';
|
---|
231 | }
|
---|
232 | $role_list .= "<option value=\"{$role}\"{$selected}>{$name}</option>\n";
|
---|
233 | }
|
---|
234 | if ( $group_has_role ) {
|
---|
235 | $role_list .= '<option value="default">' . __('Default Role of WordPress', 'xpressme') . "</option>\n";
|
---|
236 | $role_list .= '<option value="">' . __('Group User Doesn\'t Register', 'xpressme') . "</option>\n";
|
---|
237 | } else {
|
---|
238 | if ($select_value == 'default'){
|
---|
239 | $role_list .= '<option value="default" selected="selected">' . __('Default Role of WordPress', 'xpressme') . "</option>\n";
|
---|
240 | $role_list .= '<option value="">' . __('Group User Doesn\'t Register', 'xpressme') . "</option>\n";
|
---|
241 | } else {
|
---|
242 | $role_list .= '<option value="default">' . __('Default Role of WordPress', 'xpressme') . "</option>\n";
|
---|
243 | $role_list .= '<option value="" selected="selected">' . __('Group User Doesn\'t Register', 'xpressme') . "</option>\n";
|
---|
244 | }
|
---|
245 | }
|
---|
246 | $form .= $role_list . "</select>\n</td>";
|
---|
247 | if ($groupe->login_all){
|
---|
248 | $form .= '<td> <input type="checkbox" name="login_all_gid_' . $groupe->groupid . '" value="1" checked ></td>';
|
---|
249 | } else {
|
---|
250 | $form .= '<td> <input type="checkbox" name="login_all_gid_' . $groupe->groupid . '" value="1"></td>';
|
---|
251 | }
|
---|
252 | $form .= "</tr>\n";
|
---|
253 | }
|
---|
254 | $form .= "</table></td></tr>\n";
|
---|
255 | return $form;
|
---|
256 |
|
---|
257 | }
|
---|
258 |
|
---|
259 | function option_page()
|
---|
260 | {
|
---|
261 |
|
---|
262 | if (!empty($_POST['submit_update'])) {
|
---|
263 | $this->ReadPostData();
|
---|
264 | $this->SettingValueWrite('update');
|
---|
265 | } else if (isset($_POST['submit_reset'])) {
|
---|
266 | $this->fck_setDefault();
|
---|
267 | $this->SettingValueWrite('update');
|
---|
268 | }
|
---|
269 |
|
---|
270 |
|
---|
271 | echo '<div class="wrap">'."\n";
|
---|
272 | echo '<div id="icon-options-general" class="icon32"><br /></div>'."\n";
|
---|
273 | echo '<h2>' . __('XPressME Configuration Page', 'xpressme') . "</h2>\n";
|
---|
274 | echo '<form method="post" action="' . $_SERVER["REQUEST_URI"] . '">'."\n" ;
|
---|
275 | echo '<table class="form-table">'."\n";
|
---|
276 | echo $this->yes_no_radio_option('is_use_xoops_upload_path',
|
---|
277 | __('Media Upload Base Path','xpressme'),
|
---|
278 | __('Use XOOPS UPLOAD PATH','xpressme'),
|
---|
279 | __('USE WordPress BASE_PATH','xpressme')
|
---|
280 | );
|
---|
281 | echo $this->yes_no_radio_option('is_theme_sidebar_disp',
|
---|
282 | __('Thema Sidebar Display','xpressme'),
|
---|
283 | __('YES','xpressme'),
|
---|
284 | __('NO','xpressme')
|
---|
285 | );
|
---|
286 | echo $this->yes_no_radio_option('is_save_post_revision',
|
---|
287 | __('The change tracking of the post is preserved','xpressme'),
|
---|
288 | __('YES','xpressme'),
|
---|
289 | __('NO','xpressme')
|
---|
290 | );
|
---|
291 | echo $this->text_option('old_post_link_text',
|
---|
292 | __('Display Navi Title of Old Post Link','xpressme')
|
---|
293 | );
|
---|
294 | echo $this->text_option('newer_post_link_text',
|
---|
295 | __('Display Navi Title of Newer Post Link','xpressme')
|
---|
296 | );
|
---|
297 | echo $this->yes_no_radio_option('is_postnavi_title_disp',
|
---|
298 | __('Select Display name of PostNavi Link','xpressme'),
|
---|
299 | __('Title of post','xpressme'),
|
---|
300 | __('Title of Navi','xpressme')
|
---|
301 | );
|
---|
302 | echo $this->yes_no_radio_option('is_left_postnavi_old',
|
---|
303 | __('Adjustment of Navi link display position','xpressme'),
|
---|
304 | __("'Old Post Link' is displayed in the left, and 'Newer Post Link' is displayed in the right",'xpressme'),
|
---|
305 | __("'Newer Post Link' is displayed in the left, and 'Old Post Link' is displayed in the right",'xpressme')
|
---|
306 | );
|
---|
307 | echo $this->yes_no_radio_option('is_author_view_count',
|
---|
308 | __('Is the posts author views counted?','xpressme'),
|
---|
309 | __('YES','xpressme'),
|
---|
310 | __('NO','xpressme')
|
---|
311 | );
|
---|
312 | echo $this->yes_no_radio_option('is_sql_debug',
|
---|
313 | __('Is SQL debugging window displayed?','xpressme'),
|
---|
314 | __('YES','xpressme'),
|
---|
315 | __('NO','xpressme')
|
---|
316 | );
|
---|
317 |
|
---|
318 | echo $this->groupe_role_option();
|
---|
319 | // $this->is_use_xoops_upload_path_html();
|
---|
320 | echo "</table>\n";
|
---|
321 |
|
---|
322 | echo '<p class="submit">'."\n";
|
---|
323 | echo '<input type="submit" value= "' . __('Update Config', 'xpressme') . '" name="submit_update" />' ."\n";
|
---|
324 | echo '<input type="submit" value= "' . __('Preset Config', 'xpressme') . '" name="submit_reset" />' ."\n";
|
---|
325 | echo "</p>\n";
|
---|
326 |
|
---|
327 | echo "</form>\n" ;
|
---|
328 | echo "</div>\n";
|
---|
329 | }
|
---|
330 |
|
---|
331 | function xpress_upload_filter($uploads)
|
---|
332 | {
|
---|
333 | global $xoops_config;
|
---|
334 | if ($this->is_use_xoops_upload_path){
|
---|
335 | $wordpress_dir = ABSPATH ;
|
---|
336 | $xoops_dir = $xoops_config->xoops_upload_path . '/';
|
---|
337 | $wordpress_base_url = get_option( 'siteurl' );
|
---|
338 | $xoops_upload_url = $xoops_config->xoops_upload_url;
|
---|
339 |
|
---|
340 | $uploads[path] = str_replace ($wordpress_dir, $xoops_dir, $uploads[path]);
|
---|
341 | $uploads[basedir] = str_replace ($wordpress_dir, $xoops_dir, $uploads[basedir]);
|
---|
342 | $uploads[url] = str_replace ($wordpress_base_url, $xoops_upload_url, $uploads[url]);
|
---|
343 | $uploads[baseurl] = str_replace ($wordpress_base_url, $xoops_upload_url, $uploads[baseurl]);
|
---|
344 | }
|
---|
345 | return $uploads;
|
---|
346 | }
|
---|
347 |
|
---|
348 | // SQL DEBUG TEST
|
---|
349 | function is_sql_debug_permission()
|
---|
350 | {
|
---|
351 | global $current_user;
|
---|
352 |
|
---|
353 | if (!is_object($current_user)) return false;
|
---|
354 | if ($this->is_sql_debug && ($current_user->user_level >= 10))
|
---|
355 | return true;
|
---|
356 | else
|
---|
357 | return false;
|
---|
358 | }
|
---|
359 |
|
---|
360 | function xpress_sql_debug($query_strings)
|
---|
361 | {
|
---|
362 | if ($this->is_sql_debug_permission()){
|
---|
363 | if (empty($GLOBALS['XPress_SQL_Query'])) $GLOBALS['XPress_SQL_Query'] = '';
|
---|
364 | $GLOBALS['XPress_SQL_Query'] .= $query_strings . '<br />';
|
---|
365 | }
|
---|
366 | return $query_strings;
|
---|
367 | }
|
---|
368 |
|
---|
369 | function displayDebugLog()
|
---|
370 | {
|
---|
371 | if ($this->is_sql_debug_permission()){
|
---|
372 | $content = '';
|
---|
373 | $content .= '<html><head><meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" />';
|
---|
374 | $content .= '<meta http-equiv="content-language" content="'._LANGCODE.'" />' ;
|
---|
375 | $content .= '<title>XPressME SQL DEBUG</title>' ;
|
---|
376 | $content .= '</head><body>';
|
---|
377 | $content .= $GLOBALS['XPress_SQL_Query'];
|
---|
378 | $content .= '<div style="text-align:center;"><input class="formButton" value="CLOSE" type="button" onclick="javascript:window.close();" /></div></body></html>';
|
---|
379 |
|
---|
380 | echo '<script type="text/javascript">
|
---|
381 | <!--//
|
---|
382 | xpress_debug_window = window.open("", "xpress_debug", "width=680 , height=600 ,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no");
|
---|
383 | xpress_debug_window.document.clear();
|
---|
384 | xpress_debug_window.focus();
|
---|
385 | ';
|
---|
386 | $lines = preg_split("/(\r\n|\r|\n)( *)/", $content);
|
---|
387 | foreach ($lines as $line) {
|
---|
388 | echo 'xpress_debug_window.document.writeln("'.str_replace('"', '\"', $line).'");';
|
---|
389 | }
|
---|
390 | echo '
|
---|
391 | xpress_debug_window.document.close();
|
---|
392 | //-->
|
---|
393 | </script>';
|
---|
394 | }
|
---|
395 | }
|
---|
396 |
|
---|
397 | }
|
---|
398 | ?> |
---|