XPressME Integration Kit

Trac

source: trunk/wp-content/plugins/xpressme/xpressme_class.php @ 99

Last change on this file since 99 was 99, checked in by toemon, 15 years ago

D3Forumのフォーラムリストボックスからコメント統合を選択するための設定画面を作成
設定値はXPressME_Classクラスの
is_use_d3forum;
d3forum_module_dir;
d3forum_forum_id;
d3forum_external_link_format;
プロパティーから取得できます。

File size: 18.0 KB
Line 
1<?php
2
3load_plugin_textdomain('xpressme', 'wp-content/plugins/xpressme/language');
4
5class 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        var $is_use_d3forum;
18        var $d3forum_module_dir;
19        var $d3forum_forum_id;
20        var $d3forum_external_link_format;
21        //constructor
22        function XPressME_Class()
23        {
24                global $xoops_db;
25               
26                $this->setdefault();    //not setting propaty load
27                $this->SettingValueRead();
28        }
29
30
31        function add_option_page()
32        {
33                add_options_page('XPressME', __('XPressME Settings', 'xpressme'), 8, 'xpressme_config', array(&$this, 'option_page'));
34        }
35       
36        function add_admin_head()
37        {
38                // add header text
39        }
40
41       
42                //Set Default Value     
43        function setDefault()
44        {
45                $this->is_use_xoops_upload_path = true;
46                $this->is_theme_sidebar_disp = true;
47                $this->is_save_post_revision = true;
48                $this->is_postnavi_title_disp = true;
49                $this->is_left_postnavi_old = true;
50                $this->old_post_link_text = __('to Old Post', 'xpressme');
51                $this->newer_post_link_text = __('to Newer Post', 'xpressme');
52                $this->is_author_view_count = false;
53                $this->is_sql_debug = false;
54                $this->is_use_d3forum = false;
55                $this->d3forum_module_dir = '';
56                $this->d3forum_forum_id = '';
57                $this->d3forum_external_link_format = get_xpress_dir_name() . '::xpressD3commentContent';
58        }
59       
60        function SettingValueRead()
61        {
62                global $xoops_db;
63                $options = get_option('xpressme_option');
64                if (!$options) {
65                        $this->setDefault();
66                        $this->SettingValueWrite('add_new');
67                } else {
68                        foreach ($options as $option_name => $option_value){
69                                $this-> {$option_name} = $option_value;
70                        }
71                }
72                if (!empty($xoops_db))  // at install trap
73                        $this->GroupeRoleRead();
74        }
75       
76                // mode 0:add  1:update
77        function SettingValueWrite($mode)
78        {
79                $write_options = array (
80                        'is_use_xoops_upload_path' => $this->is_use_xoops_upload_path ,
81                        'is_theme_sidebar_disp' => $this->is_theme_sidebar_disp ,
82                        'is_save_post_revision' => $this->is_save_post_revision ,
83                        'is_postnavi_title_disp' => $this->is_postnavi_title_disp ,
84                        'is_left_postnavi_old' => $this->is_left_postnavi_old ,
85                        'old_post_link_text' => $this->old_post_link_text ,
86                        'newer_post_link_text' => $this->newer_post_link_text,
87                        'is_author_view_count' => $this->is_author_view_count,
88                        'is_sql_debug' => $this->is_sql_debug,
89                        'is_use_d3forum' =>     $this->is_use_d3forum,
90                        'd3forum_module_dir' => $this->d3forum_module_dir,
91                        'd3forum_forum_id' => $this->d3forum_forum_id,
92                        'd3forum_external_link_format' => $this->d3forum_external_link_format
93                );
94                if ($mode == 'add_new') {
95                        add_option('xpressme_option', $write_options);
96                } else {                       
97                        update_option("xpressme_option", $write_options);
98                }
99        }
100       
101        function GroupeRoleRead() {
102                global $xoops_db;
103               
104                // table sync
105                $table = get_wp_prefix() . 'group_role';
106                $xoops_group = get_xoops_prefix() . 'groups';
107                $sql=  "SELECT * FROM $table";
108                $before_groupes = $xoops_db->get_results($sql);
109               
110                $sql = "DELETE FROM $table";
111                $xoops_db->query($sql);
112               
113               
114                $sql=  "SELECT * FROM $xoops_group WHERE group_type <> 'Anonymous'";
115                $groupes = $xoops_db->get_results($sql);
116                $insert_sql = '';
117                foreach ($groupes as $groupe) {
118                        $role = '';
119                        foreach ($before_groupes as $before_groupe) {
120                                if ($groupe->groupid == $before_groupe->groupid) {
121                                        $role = $before_groupe->role;
122                                        $login_all = $before_groupe->login_all;
123                                }
124                        }
125                       
126                        $insert_sql  = "INSERT INTO  $table ";
127                        $insert_sql .= "(groupid , name , description , group_type , role , login_all) ";
128                        $insert_sql .= "VALUES (";
129                        $insert_sql .= $groupe->groupid . ', ';
130                        $insert_sql .= "'" . $groupe->name . "' , ";
131                        $insert_sql .= "'" . $groupe->description . "' , ";
132                        $insert_sql .= "'" . $groupe->group_type . "' , ";
133                        $insert_sql .= "'" . $role . "' , '";
134                        $insert_sql .= $login_all . "')";
135                        $xoops_db->query($insert_sql);
136                }
137               
138                $sql=  "SELECT * FROM $table";
139               
140                $this->groupe_role =  $xoops_db->get_results($sql);
141                        $sql=  "SELECT * FROM $table"; 
142        }
143       
144        function ReadPostData()
145        {
146                $this->is_use_xoops_upload_path = stripslashes(trim($_POST['ch_is_use_xoops_upload_path']));
147                $this->is_theme_sidebar_disp = stripslashes(trim($_POST['ch_is_theme_sidebar_disp']));
148                $this->is_save_post_revision = stripslashes(trim($_POST['ch_is_save_post_revision']));
149                $this->is_postnavi_title_disp = stripslashes(trim($_POST['ch_is_postnavi_title_disp']));
150                $this->is_left_postnavi_old = stripslashes(trim($_POST['ch_is_left_postnavi_old']));
151                $this->old_post_link_text = stripslashes($_POST['ch_old_post_link_text']);
152                if(empty($this->old_post_link_text)) $this->old_post_link_text = __('to Old Post', 'xpressme');
153                $this->newer_post_link_text = stripslashes($_POST['ch_newer_post_link_text']);
154                if(empty($this->newer_post_link_text)) $this->newer_post_link_text = __('to Newer Post', 'xpressme');
155                $this->is_author_view_count = stripslashes(trim($_POST['ch_is_author_view_count']));
156                $this->is_sql_debug = stripslashes(trim($_POST['ch_is_sql_debug']));
157                //d3forum
158                $d3forum_select = stripslashes(trim($_POST['ch_d3forum']));
159                if ($d3forum_select == 'none') {
160                        $this->is_use_d3forum = false;
161                        $this->d3forum_module_dir = '';
162                        $this->d3forum_forum_id = '';
163                        $this->d3forum_external_link_format = get_xpress_dir_name() . '::xpressD3commentContent';
164                } else {
165                        $d3f_set = explode('|', $d3forum_select);
166                        $this->is_use_d3forum = true;
167                        $this->d3forum_module_dir = $d3f_set[1];
168                        $this->d3forum_forum_id = $d3f_set[2];
169                        $this->d3forum_external_link_format = get_xpress_dir_name() . '::xpressD3commentContent';
170                }
171               
172                global $xoops_db;
173                $table = get_wp_prefix() . 'group_role';       
174//              $sql=  "SELECT * FROM $table"; 
175//              $this->groupe_role =  $xoops_db->get_results($sql);  // before Read
176               
177                foreach ($this->groupe_role as $groupe) {
178                        $post_name = 'role_gid_' . $groupe->groupid;
179                        $role = stripslashes(trim($_POST[$post_name]));
180                        $post_name = 'login_all_gid_' . $groupe->groupid;
181                        $login_all = stripslashes(trim($_POST[$post_name]));
182                        if (empty($login_all)) $login_all = '0';
183                        $groupe->role = $role;
184                        $groupe->login_all = $login_all;
185                        $update_sql  = "UPDATE  $table ";
186                        $update_sql .= 'SET ';
187                        $update_sql .= "role  = '$role' , ";
188                        $update_sql .= "login_all  = $login_all ";
189                        $update_sql .= "WHERE (groupid = '$groupe->groupid' )";
190                        $xoops_db->query($update_sql);                 
191                }
192        }
193       
194        function yes_no_radio_option($option_name,$option_desc,$yes = '',$no= ''){
195                if (empty( $yes ))  $yes = __('YES','xpressme') ;
196                if (empty( $no ))  $no = __('NO','xpressme') ;
197                $value = $this->{$option_name};
198                $ans_name = 'ch_' . $option_name;
199               
200                $form  =  "<tr>\n";
201                $form .=  '<th><label for="images_to_link">' . $option_desc . "</label></th>\n";
202                $form .=  "<td>\n";
203                if ($value){
204                        $form .= "<label><input type='radio' name='". $ans_name . "' value='1' checked='checked' />" . $yes ."</label><br />\n";
205                        $form .= "<label><input type='radio' name='". $ans_name . "' value='0' />". $no . "</label>\n";
206                }else{
207                        $form .= "<label><input type='radio' name='". $ans_name . "' value='1' />" . $yes . "</label><br />\n";
208                        $form .= "<label><input type='radio' name='". $ans_name . "' value='0' checked='checked' />". $no ."</label>\n";
209                }
210                $form .=  "</td>\n";
211                $form .=  "</tr><tr>\n";
212                       
213            return $form;
214       
215        }
216
217        function text_option($option_name,$option_desc){
218                $value = $this->{$option_name};
219                $ans_name = 'ch_' . $option_name;
220               
221                $form  =  "<tr>\n";
222                $form .=  '<th><label for="images_to_link">' . $option_desc . "</label></th>\n";
223                $form .=  "<td>\n";
224                $form .= '<label> <input name="'. $ans_name . '" type="text" size="25" maxlength="50" value="'  . $value . '" /></label>'."\n";
225                $form .=  "</td>\n";
226                $form .=  "</tr><tr>\n";
227                       
228            return $form;
229       
230        }
231       
232        function groupe_role_option(){
233                global $wp_roles , $xoops_db;
234               
235                $form = '';
236                $form .= '<tr><th><label for="role">' .__('Role Setting at Login', 'xpressme') . '</label></th>';
237                $form .= '<td>';
238                $form .= "<table>\n";
239                $form .= '<tr><td>' . __('XOOPS Groupe', 'xpressme') . '</td><td>' . __('WordPress Role', 'xpressme') . '</td><td>' . __('Role is set at each login', 'xpressme') . "</td></tr>\n";
240                foreach ($this->groupe_role as $groupe) {
241                        $form .= "<tr>";
242                        $form .= "<td> $groupe->name </td>";
243                        $form .= "<td>\n" . '<select name="role_gid_'.$groupe->groupid . '" id="role_gid_' . $groupe->groupid . '">' . "\n";
244                        $role_list = '';
245                        $group_has_role = false;
246               
247                        $select_value = $groupe->role;
248               
249                        foreach($wp_roles->role_names as $role => $name) {
250                                $name = translate_with_context($name);
251                                if ( $role == $select_value) {
252                                        $selected = ' selected="selected"';
253                                        $group_has_role = true;
254                                } else {
255                                        $selected = '';
256                                }
257                                $role_list .= "<option value=\"{$role}\"{$selected}>{$name}</option>\n";
258                        }
259                        if ( $group_has_role ) {
260                                $role_list .= '<option value="default">' . __('Default Role of WordPress', 'xpressme') . "</option>\n";
261                                $role_list .= '<option value="">' . __('Group User Doesn\'t Register', 'xpressme') . "</option>\n";
262                        } else {
263                                if ($select_value == 'default'){
264                                        $role_list .= '<option value="default" selected="selected">' . __('Default Role of WordPress', 'xpressme') . "</option>\n";     
265                                        $role_list .= '<option value="">' . __('Group User Doesn\'t Register', 'xpressme') . "</option>\n";
266                                } else {
267                                        $role_list .= '<option value="default">' . __('Default Role of WordPress', 'xpressme') . "</option>\n";                                 
268                                        $role_list .= '<option value="" selected="selected">' . __('Group User Doesn\'t Register', 'xpressme') . "</option>\n";
269                                }
270                        }
271                        $form .= $role_list . "</select>\n</td>";
272                        if ($groupe->login_all){
273                                $form .= '<td> <input type="checkbox" name="login_all_gid_' . $groupe->groupid . '" value="1" checked ></td>';
274                        } else {
275                                $form .= '<td> <input type="checkbox" name="login_all_gid_' . $groupe->groupid . '" value="1"></td>';
276                        }
277                        $form .= "</tr>\n";     
278                }
279                $form .= "</table></td></tr>\n";
280            return $form;
281
282        }
283       
284        function d3forum_option(){
285                global $xoops_db;
286               
287                $d3frum_list = array();
288                $module_dir_path = get_xoops_root_path();
289               
290                $forum_list  = '<select name="ch_d3forum">' . "\n";
291               
292                if ($this->is_use_d3forum != true)
293                        $selected = ' selected="selected"';
294                else
295                        $selected = '';
296                $forum_list .= '<option value="none"' . $selected . '>' . __('Do Not Comment Integration.', 'xpressme') . "</option>\n";
297
298                // Form making for forum selection of D3forum
299                $modules_table = get_xoops_prefix() .'modules';
300                $sql = "SELECT mid,name,isactive,dirname FROM $modules_table WHERE isactive = 1";
301                $modules = $xoops_db->get_results($sql);
302                foreach ($modules as $module) {
303                        $file_path = $module_dir_path . '/modules/' . $module->dirname . '/mytrustdirname.php';                 
304                        if (! file_exists($file_path)) continue;
305                        $array_files = file($file_path);
306                        // It is checked whether there is character string "$mytrustdirname ='d3forum'"in the file.
307                        foreach ($array_files as $aeey_file){
308                                if( preg_match( "/\s*($mytrustdirname)\s*(=)\s*([\"'])(d3forum)([\"'])/", $aeey_file ) ) {
309                                        $forums_tb = get_xoops_prefix() . $module->dirname . '_forums';
310                                        $cat_tb = get_xoops_prefix() . $module->dirname . '_categories';
311                                        $sql= "SELECT * FROM $forums_tb LEFT JOIN $cat_tb ON $forums_tb.cat_id = $cat_tb.cat_id";
312                                        $forums = $xoops_db->get_results($sql);
313                                        foreach ($forums as $forum) {
314                                                if (($module->dirname == $this->d3forum_module_dir) &&  ($forum->forum_id == $this->d3forum_forum_id))
315                                                        $selected = ' selected="selected"';
316                                                else
317                                                        $selected = '';
318                                                $forum_div = 'forum|' . $module->dirname . '|' .  $forum->forum_id;
319                                                $forum_select = "$module->name($module->dirname) $forum->cat_title-$forum->forum_title(ID=$forum->forum_id)";
320                                                $forum_list .= '<option value="' . $forum_div . '" ' . $selected . '>' . $forum_select . "</option>\n";
321                                        }
322                                        break;
323                                }
324                        }
325                        $form .= '<br>';                       
326                }
327                $forum_list .= '</select>' . "\n";
328
329                $form  = '<tr>' . "\n";
330                $form .= '<th><label for="d3forum">' .__('Comment integration with D3Forum', 'xpressme') . '</label></th>' . "\n";
331                $form .=  "<td>\n";
332                $form .=  __('Select the forum of D3Forum that does the comment integration from the following lists.', 'xpressme') ."<br />\n";
333                $form .=  $forum_list."\n";
334                $form .= '<br /><br /><br /><br /><br /><br /><br />';
335                $form .=  "</td>\n";
336                $form .=  "</tr><tr>\n";
337                return $form;
338        }
339
340        function option_page()
341        {
342
343                if (!empty($_POST['submit_update'])) {
344                        $this->ReadPostData();
345                        $this->SettingValueWrite('update');
346                } else if (isset($_POST['submit_reset'])) {
347                        $this->fck_setDefault();
348                        $this->SettingValueWrite('update');
349                }
350
351               
352                echo    '<div class="wrap">'."\n";
353                echo            '<div id="icon-options-general" class="icon32"><br /></div>'."\n";
354                echo            '<h2>' . __('XPressME Configuration Page', 'xpressme') . "</h2>\n";
355                echo            '<form method="post" action="' . $_SERVER["REQUEST_URI"] . '">'."\n" ;
356                echo                    '<table class="form-table">'."\n";
357                echo                            $this->yes_no_radio_option('is_use_xoops_upload_path',
358                                                                                                __('Media Upload Base Path','xpressme'),
359                                                                                                __('Use XOOPS UPLOAD PATH','xpressme'),
360                                                                                                __('USE WordPress BASE_PATH','xpressme')
361                                                                                                );
362                echo                            $this->yes_no_radio_option('is_theme_sidebar_disp',
363                                                                                                __('Thema Sidebar Display','xpressme'),
364                                                                                                __('YES','xpressme'),
365                                                                                                __('NO','xpressme')
366                                                                                                );
367                echo                            $this->yes_no_radio_option('is_save_post_revision',
368                                                                                                __('The change tracking of the post is preserved','xpressme'),
369                                                                                                __('YES','xpressme'),
370                                                                                                __('NO','xpressme')
371                                                                                                );
372                echo                            $this->text_option('old_post_link_text',
373                                                                                                __('Display Navi Title of Old Post Link','xpressme')
374                                                                                                );
375                echo                            $this->text_option('newer_post_link_text',
376                                                                                                __('Display Navi Title of Newer Post Link','xpressme')
377                                                                                                );
378                echo                            $this->yes_no_radio_option('is_postnavi_title_disp',
379                                                                                                __('Select Display name of PostNavi Link','xpressme'),
380                                                                                                __('Title of post','xpressme'),
381                                                                                                __('Title of Navi','xpressme')
382                                                                                                );
383                echo                            $this->yes_no_radio_option('is_left_postnavi_old',
384                                                                                                __('Adjustment of Navi link display position','xpressme'),
385                                                                                                __("'Old Post Link' is displayed in the left, and 'Newer Post Link' is displayed in the right",'xpressme'),
386                                                                                                __("'Newer Post Link' is displayed in the left, and 'Old Post Link' is displayed in the right",'xpressme')
387                                                                                                );
388                echo                            $this->yes_no_radio_option('is_author_view_count',
389                                                                                                __('Is the posts author views counted?','xpressme'),
390                                                                                                __('YES','xpressme'),
391                                                                                                __('NO','xpressme')             
392                                                                                                );
393                echo                            $this->yes_no_radio_option('is_sql_debug',
394                                                                                                __('Is SQL debugging window displayed?','xpressme'),
395                                                                                                __('YES','xpressme'),
396                                                                                                __('NO','xpressme')             
397                                                                                                );
398               
399                echo                            $this->groupe_role_option();           
400               
401                echo                            $this->d3forum_option();               
402//              $this->is_use_xoops_upload_path_html();
403                echo                    "</table>\n";
404               
405                echo            '<p class="submit">'."\n";
406                echo            '<input type="submit" value= "' . __('Update Config', 'xpressme') . '" name="submit_update" />' ."\n";
407                echo            '<input type="submit" value= "' . __('Preset Config', 'xpressme') . '" name="submit_reset" />' ."\n";
408                echo            "</p>\n";
409
410                echo            "</form>\n" ;
411                echo    "</div>\n";
412        }
413       
414        function xpress_upload_filter($uploads)
415        {
416                global $xoops_config;
417                if ($this->is_use_xoops_upload_path){
418                        $wordpress_dir = ABSPATH ;
419                        $xoops_dir = $xoops_config->xoops_upload_path . '/';
420                        $wordpress_base_url = get_option( 'siteurl' );
421                        $xoops_upload_url = $xoops_config->xoops_upload_url;
422                       
423                        $uploads[path] =  str_replace ($wordpress_dir, $xoops_dir, $uploads[path]);
424                        $uploads[basedir] = str_replace ($wordpress_dir, $xoops_dir, $uploads[basedir]);
425                        $uploads[url] = str_replace ($wordpress_base_url, $xoops_upload_url, $uploads[url]);
426                        $uploads[baseurl] = str_replace ($wordpress_base_url, $xoops_upload_url, $uploads[baseurl]);
427                }
428                return $uploads;
429        }
430
431        // SQL DEBUG TEST
432        function is_sql_debug_permission()
433        {
434                global $current_user;
435
436                if (!is_object($current_user)) return false;
437                if ($this->is_sql_debug && ($current_user->user_level >= 10))
438                        return true;
439                else
440                        return false;
441        }
442       
443        function xpress_sql_debug($query_strings)
444        {
445                if ($this->is_sql_debug_permission()){
446                        if (empty($GLOBALS['XPress_SQL_Query'])) $GLOBALS['XPress_SQL_Query'] = '';
447                        $GLOBALS['XPress_SQL_Query'] .= $query_strings . '<br />';
448                }
449                return $query_strings;
450        }
451       
452        function displayDebugLog()
453        {
454                if ($this->is_sql_debug_permission()){
455                        $content = '';
456                        $content .= '<html><head><meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" />';
457                        $content .= '<meta http-equiv="content-language" content="'._LANGCODE.'" />' ;
458                        $content .= '<title>XPressME SQL DEBUG</title>' ;
459                        $content .= '</head><body>';
460                        $content .= $GLOBALS['XPress_SQL_Query'];
461                        $content .= '<div style="text-align:center;"><input class="formButton" value="CLOSE" type="button" onclick="javascript:window.close();" /></div></body></html>';
462
463                        echo '<script type="text/javascript">
464                                <!--//
465                                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");
466                                xpress_debug_window.document.clear();
467                                xpress_debug_window.focus();
468                                ';
469                        $lines = preg_split("/(\r\n|\r|\n)( *)/", $content);
470                        foreach ($lines as $line) {
471                                echo 'xpress_debug_window.document.writeln("'.str_replace('"', '\"', $line).'");';
472                        }
473                        echo '
474                                xpress_debug_window.document.close();
475                                //-->
476                        </script>';
477                }
478        }       
479
480}
481?>
Note: See TracBrowser for help on using the repository browser.