XPressME Integration Kit

Trac

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

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

xpressmeプラグイン側で、XOOPSグループに対する権限設定を行うためのデータベースと設定画面を追加
(まだ完全に動いてません)

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