XPressME Integration Kit

Trac

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

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

設定画面のレイアウトと言語ファイルメンテナンス

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