XPressME Integration Kit

Trac

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

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

r76 の続き 
XOOPSグループに対する権限設定でログイン毎に権限を更新するか、初回ログイン時のみ設定するかを選択できるようにした。
権限の選択に「WordPressのデフォルト権限」を追加

File size: 12.5 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 $groupe_role_serial;
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        }
51       
52        function SettingValueRead()
53        {
54                global $xoops_db;
55                $options = get_option('xpressme_option');
56                if (!$options) {
57                        $this->setDefault();
58                        $this->SettingValueWrite('add_new');
59                } else {
60                        foreach ($options as $option_name => $option_value){
61                                $this-> {$option_name} = $option_value;
62                        }
63                }
64                if (!empty($xoops_db))  // at install trap
65                        $this->GroupeRoleRead();
66        }
67       
68                // mode 0:add  1:update
69        function SettingValueWrite($mode)
70        {
71                $write_options = array (
72                        'is_use_xoops_upload_path' => $this->is_use_xoops_upload_path ,
73                        'is_theme_sidebar_disp' => $this->is_theme_sidebar_disp ,
74                        'is_save_post_revision' => $this->is_save_post_revision ,
75                        'is_postnavi_title_disp' => $this->is_postnavi_title_disp ,
76                        'is_left_postnavi_old' => $this->is_left_postnavi_old ,
77                        'old_post_link_text' => $this->old_post_link_text ,
78                        'newer_post_link_text' => $this->newer_post_link_text,
79                        'is_author_view_count' => $this->is_author_view_count
80                );
81                if ($mode == 'add_new') {
82                        add_option('xpressme_option', $write_options);
83                } else {                       
84                        update_option("xpressme_option", $write_options);
85                }
86        }
87       
88        function GroupeRoleRead() {
89                global $xoops_db;
90               
91                // table sync
92                $table = get_wp_prefix() . 'group_role';
93                $xoops_group = get_xoops_prefix() . 'groups';
94                $sql=  "SELECT * FROM $table";
95                $before_groupes = $xoops_db->get_results($sql);
96               
97                $sql = "DELETE FROM $table";
98                $xoops_db->query($sql);
99               
100               
101                $sql=  "SELECT * FROM $xoops_group WHERE group_type <> 'Anonymous'";
102                $groupes = $xoops_db->get_results($sql);
103                $insert_sql = '';
104                foreach ($groupes as $groupe) {
105                        $role = '';
106                        foreach ($before_groupes as $before_groupe) {
107                                if ($groupe->groupid == $before_groupe->groupid) {
108                                        $role = $before_groupe->role;
109                                        $login_all = $before_groupe->login_all;
110                                }
111                        }
112                       
113                        $insert_sql  = "INSERT INTO  $table ";
114                        $insert_sql .= "(groupid , name , description , group_type , role , login_all) ";
115                        $insert_sql .= "VALUES (";
116                        $insert_sql .= $groupe->groupid . ', ';
117                        $insert_sql .= "'" . $groupe->name . "' , ";
118                        $insert_sql .= "'" . $groupe->description . "' , ";
119                        $insert_sql .= "'" . $groupe->group_type . "' , ";
120                        $insert_sql .= "'" . $role . "' , ";
121                        $insert_sql .= $login_all . ")";
122                        $xoops_db->query($insert_sql);
123                }
124               
125                $sql=  "SELECT * FROM $table";
126               
127                $this->groupe_role =  $xoops_db->get_results($sql);
128                        $sql=  "SELECT * FROM $table"; 
129        }
130       
131        function ReadPostData()
132        {
133                $this->is_use_xoops_upload_path = stripslashes(trim($_POST['ch_is_use_xoops_upload_path']));
134                $this->is_theme_sidebar_disp = stripslashes(trim($_POST['ch_is_theme_sidebar_disp']));
135                $this->is_save_post_revision = stripslashes(trim($_POST['ch_is_save_post_revision']));
136                $this->is_postnavi_title_disp = stripslashes(trim($_POST['ch_is_postnavi_title_disp']));
137                $this->is_left_postnavi_old = stripslashes(trim($_POST['ch_is_left_postnavi_old']));
138                $this->old_post_link_text = stripslashes($_POST['ch_old_post_link_text']);
139                if(empty($this->old_post_link_text)) $this->old_post_link_text = __('to Old Post', 'xpressme');
140                $this->newer_post_link_text = stripslashes($_POST['ch_newer_post_link_text']);
141                if(empty($this->newer_post_link_text)) $this->newer_post_link_text = __('to Newer Post', 'xpressme');
142                $this->is_author_view_count = stripslashes(trim($_POST['ch_is_author_view_count']));
143               
144                global $xoops_db;
145                $table = get_wp_prefix() . 'group_role';       
146//              $sql=  "SELECT * FROM $table"; 
147//              $this->groupe_role =  $xoops_db->get_results($sql);  // before Read
148               
149                foreach ($this->groupe_role as $groupe) {
150                        $post_name = 'role_gid_' . $groupe->groupid;
151                        $role = stripslashes(trim($_POST[$post_name]));
152                        $post_name = 'login_all_gid_' . $groupe->groupid;
153                        $login_all = stripslashes(trim($_POST[$post_name]));
154                        if (empty($login_all)) $login_all = '0';
155                        $groupe->role = $role;
156                        $groupe->login_all = $login_all;
157                        $update_sql  = "UPDATE  $table ";
158                        $update_sql .= 'SET ';
159                        $update_sql .= "role  = '$role' , ";
160                        $update_sql .= "login_all  = $login_all ";
161                        $update_sql .= "WHERE (groupid = '$groupe->groupid' )";
162                        $xoops_db->query($update_sql);                 
163                }
164        }
165       
166        function yes_no_radio_option($option_name,$option_desc,$yes = '',$no= ''){
167                if (empty( $yes ))  $yes = __('YES','xpressme') ;
168                if (empty( $no ))  $no = __('NO','xpressme') ;
169                $value = $this->{$option_name};
170                $ans_name = 'ch_' . $option_name;
171               
172                $form  =  "<tr>\n";
173                $form .=  '<th><label for="images_to_link">' . $option_desc . "</label></th>\n";
174                $form .=  "<td>\n";
175                if ($value){
176                        $form .= "<label><input type='radio' name='". $ans_name . "' value='1' checked='checked' />" . $yes ."</label><br />\n";
177                        $form .= "<label><input type='radio' name='". $ans_name . "' value='0' />". $no . "</label>\n";
178                }else{
179                        $form .= "<label><input type='radio' name='". $ans_name . "' value='1' />" . $yes . "</label><br />\n";
180                        $form .= "<label><input type='radio' name='". $ans_name . "' value='0' checked='checked' />". $no ."</label>\n";
181                }
182                $form .=  "</td>\n";
183                $form .=  "</tr><tr>\n";
184                       
185            return $form;
186       
187        }
188
189        function text_option($option_name,$option_desc){
190                $value = $this->{$option_name};
191                $ans_name = 'ch_' . $option_name;
192               
193                $form  =  "<tr>\n";
194                $form .=  '<th><label for="images_to_link">' . $option_desc . "</label></th>\n";
195                $form .=  "<td>\n";
196                $form .= '<label> <input name="'. $ans_name . '" type="text" size="25" maxlength="50" value="'  . $value . '" /></label>'."\n";
197                $form .=  "</td>\n";
198                $form .=  "</tr><tr>\n";
199                       
200            return $form;
201       
202        }
203       
204        function groupe_role_option(){
205                global $wp_roles , $xoops_db;
206               
207                $form = '';
208                $form .= '<tr><th><label for="role">' .__('Role Setting at Login', 'xpressme') . '</label></th>';
209                $form .= '<td>';
210                $form .= "<table>\n";
211                $form .= '<tr><td>' . __('XOOPS Groupe', 'xpressme') . '</td><td>' . __('WordPress Role', 'xpressme') . '</td><td>' . __('Role is set at each login', 'xpressme') . "</td></tr>\n";
212                foreach ($this->groupe_role as $groupe) {
213                        $form .= "<tr>";
214                        $form .= "<td> $groupe->name </td>";
215                        $form .= "<td>\n" . '<select name="role_gid_'.$groupe->groupid . '" id="role_gid_' . $groupe->groupid . '">' . "\n";
216                        $role_list = '';
217                        $group_has_role = false;
218               
219                        $select_value = $groupe->role;
220               
221                        foreach($wp_roles->role_names as $role => $name) {
222                                $name = translate_with_context($name);
223                                if ( $role == $select_value) {
224                                        $selected = ' selected="selected"';
225                                        $group_has_role = true;
226                                } else {
227                                        $selected = '';
228                                }
229                                $role_list .= "<option value=\"{$role}\"{$selected}>{$name}</option>\n";
230                        }
231                        if ( $group_has_role ) {
232                                $role_list .= '<option value="default">' . __('Default Role of WordPress', 'xpressme') . "</option>\n";
233                                $role_list .= '<option value="">' . __('Group User Doesn\'t Register', 'xpressme') . "</option>\n";
234                        } else {
235                                if ($select_value == 'default'){
236                                        $role_list .= '<option value="default" selected="selected">' . __('Default Role of WordPress', 'xpressme') . "</option>\n";     
237                                        $role_list .= '<option value="">' . __('Group User Doesn\'t Register', 'xpressme') . "</option>\n";
238                                } else {
239                                        $role_list .= '<option value="default">' . __('Default Role of WordPress', 'xpressme') . "</option>\n";                                 
240                                        $role_list .= '<option value="" selected="selected">' . __('Group User Doesn\'t Register', 'xpressme') . "</option>\n";
241                                }
242                        }
243                        $form .= $role_list . "</select>\n</td>";
244                        if ($groupe->login_all){
245                                $form .= '<td> <input type="checkbox" name="login_all_gid_' . $groupe->groupid . '" value="1" checked ></td>';
246                        } else {
247                                $form .= '<td> <input type="checkbox" name="login_all_gid_' . $groupe->groupid . '" value="1"></td>';
248                        }
249                        $form .= "</tr>\n";     
250                }
251                $form .= "</table></td></tr>\n";
252            return $form;
253
254        }
255               
256        function option_page()
257        {
258
259                if (!empty($_POST['submit_update'])) {
260                        $this->ReadPostData();
261                        $this->SettingValueWrite('update');
262                } else if (isset($_POST['submit_reset'])) {
263                        $this->fck_setDefault();
264                        $this->SettingValueWrite('update');
265                }
266
267               
268                echo    '<div class="wrap">'."\n";
269                echo            '<div id="icon-options-general" class="icon32"><br /></div>'."\n";
270                echo            '<h2>' . __('XPressME Configuration Page', 'xpressme') . "</h2>\n";
271                echo            '<form method="post" action="' . $_SERVER["REQUEST_URI"] . '">'."\n" ;
272                echo                    '<table class="form-table">'."\n";
273                echo                            $this->yes_no_radio_option('is_use_xoops_upload_path',
274                                                                                                __('Media Upload Base Path','xpressme'),
275                                                                                                __('Use XOOPS UPLOAD PATH','xpressme'),
276                                                                                                __('USE WordPress BASE_PATH','xpressme')
277                                                                                                );
278                echo                            $this->yes_no_radio_option('is_theme_sidebar_disp',
279                                                                                                __('Thema Sidebar Display','xpressme'),
280                                                                                                __('YES','xpressme'),
281                                                                                                __('NO','xpressme')
282                                                                                                );
283                echo                            $this->yes_no_radio_option('is_save_post_revision',
284                                                                                                __('The change tracking of the post is preserved','xpressme'),
285                                                                                                __('YES','xpressme'),
286                                                                                                __('NO','xpressme')
287                                                                                                );
288                echo                            $this->text_option('old_post_link_text',
289                                                                                                __('Display Navi Title of Old Post Link','xpressme')
290                                                                                                );
291                echo                            $this->text_option('newer_post_link_text',
292                                                                                                __('Display Navi Title of Newer Post Link','xpressme')
293                                                                                                );
294                echo                            $this->yes_no_radio_option('is_postnavi_title_disp',
295                                                                                                __('Select Display name of PostNavi Link','xpressme'),
296                                                                                                __('Title of post','xpressme'),
297                                                                                                __('Title of Navi','xpressme')
298                                                                                                );
299                echo                            $this->yes_no_radio_option('is_left_postnavi_old',
300                                                                                                __('Adjustment of Navi link display position','xpressme'),
301                                                                                                __("'Old Post Link' is displayed in the left, and 'Newer Post Link' is displayed in the right",'xpressme'),
302                                                                                                __("'Newer Post Link' is displayed in the left, and 'Old Post Link' is displayed in the right",'xpressme')
303                                                                                                );
304                echo                            $this->yes_no_radio_option('is_author_view_count',
305                                                                                                __('Is the posts author views counted?','xpressme'),
306                                                                                                __('YES','xpressme'),
307                                                                                                __('NO','xpressme')             
308                                                                                                );
309                echo                            $this->groupe_role_option();                           
310//              $this->is_use_xoops_upload_path_html();
311                echo                    "</table>\n";
312               
313                echo            '<p class="submit">'."\n";
314                echo            '<input type="submit" value= "' . __('Update Config', 'xpressme') . '" name="submit_update" />' ."\n";
315                echo            '<input type="submit" value= "' . __('Preset Config', 'xpressme') . '" name="submit_reset" />' ."\n";
316                echo            "</p>\n";
317
318                echo            "</form>\n" ;
319                echo    "</div>\n";
320        }
321       
322        function xpress_upload_filter($uploads)
323        {
324                if ($this->is_use_xoops_upload_path){
325                        if (!defined("XOOPS_UPLOAD_PATH"))
326                                define("XOOPS_UPLOAD_PATH", XOOPS_ROOT_PATH."/uploads");
327                        if (!defined("XOOPS_UPLOAD_URL"))
328                                define("XOOPS_UPLOAD_URL", XOOPS_URL."/uploads");
329
330                        $wordpress_dir = ABSPATH ;
331                        $xoops_dir = XOOPS_UPLOAD_PATH . '/';
332                        $wordpress_base_url = get_option( 'siteurl' );
333                        $xoops_upload_url = XOOPS_UPLOAD_URL;
334                       
335                        $uploads[path] =  str_replace ($wordpress_dir, $xoops_dir, $uploads[path]);
336                        $uploads[basedir] = str_replace ($wordpress_dir, $xoops_dir, $uploads[basedir]);
337                        $uploads[url] = str_replace ($wordpress_base_url, $xoops_upload_url, $uploads[url]);
338                        $uploads[baseurl] = str_replace ($wordpress_base_url, $xoops_upload_url, $uploads[baseurl]);
339                }
340                return $uploads;
341        }       
342
343}
344?>
Note: See TracBrowser for help on using the repository browser.