XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/xpressme.php @ 402

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

WPMUでのメディアアップロード先をWordPressのアップロード先に固定 Fixes #224

File size: 17.6 KB
Line 
1<?php
2/*
3Plugin Name: Plugin for XPressME
4Plugin URI: http://ja.xpressme.info
5Description: Plugin for XPressME (custom function,filter,action)
6Author: toemon
7Version: 1.0
8Author URI: http://ja.xpressme.info
9*/
10require_once('xpressme_class.php');
11
12require_once dirname( __FILE__ ).'/include/custom_functions.php' ;              // XPressME functions for themes
13require_once dirname( __FILE__ ).'/include/xpress_common_functions.php' ;
14
15$xoops_db = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
16$xoops_db->prefix = get_xoops_prefix();
17$xoops_db->tables = array('modules', 'newblocks', 'users');
18
19$xpress_config = new XPressME_Class();
20
21require_once dirname( __FILE__ ).'/include/pluggable-override.php' ;
22require_once dirname( __FILE__ ).'/include/functions_for_wp_old.php' ;
23
24if (!is_wordpress_style() && ( !empty($xpress_config->theme_select) || $xpress_config->theme_select != 'use_wordpress_select') ){
25        add_filter('stylesheet', 'xpress_Stylesheet');
26        add_filter('template', 'xpress_ThemeTemplate');
27}
28function xpress_Stylesheet($stylesheet) {
29        global $xpress_config;
30        $theme = $xpress_config->theme_select;
31    $theme = get_theme($theme);
32
33    if (empty($theme)) {
34        return $stylesheet;
35    }
36    return $theme['Stylesheet'];
37}
38
39function xpress_ThemeTemplate($template) {
40        global $xpress_config;
41        $theme = $xpress_config->theme_select;
42    $theme = get_theme($theme);
43
44    if (empty($theme)) {
45        return $template;
46    }
47    return $theme['Template'];
48}
49
50function my_plugin_menu()
51{
52        global $xpress_config,$xoops_config;
53       
54        $plugin_url = WP_PLUGIN_URL."/xpressme/";
55
56        // Add a new top-level menu:
57        add_menu_page('XPressME','XPressME', 8, __FILE__, 'display_option_page' , $plugin_url.'/images/menu_icon.png');
58        // Add submenus to the custom top-level menu:
59        add_submenu_page(__FILE__, __('Display Settings', 'xpressme'), __('Display Settings', 'xpressme'), 8, __FILE__, 'display_option_page');
60        add_submenu_page(__FILE__, __('Integration Settings', 'xpressme'), __('Integration Settings', 'xpressme'), 8, 'integration_option_page', 'integration_option_page');
61        add_submenu_page(__FILE__, __('Other Settings', 'xpressme'), __('Other Settings', 'xpressme'), 8, 'other_option_page', 'other_option_page');
62//      if (function_exists('wp_remote_get'))
63                add_submenu_page(__FILE__, __('Upgrade', 'xpressme'), __('Upgrade', 'xpressme'), 8, 'upgrade_page', 'upgrade_page');
64        add_submenu_page(__FILE__, __('to Modules Admin', 'xpressme'), __('to Modules Admin', 'xpressme'), 8,  'redirect_xoops_admin', 'redirect_xoops_admin');
65}
66add_action('admin_menu', 'my_plugin_menu');
67
68add_filter("upload_dir",array(&$xpress_config, 'xpress_upload_filter'), 1);             // Change wp-include/wp_upload_dir()
69if (!$xpress_config->is_save_post_revision){
70        remove_action( 'pre_post_update', 'wp_save_post_revision' );                    // Not Save Post Revision
71}
72add_action("wp_meta" , "wp_meta_add_xpress_menu");                      // add xpress menu  in wp_meta
73       
74//Site URL check
75add_filter('option_home',                       "safe_site_url_filter");
76add_filter('option_siteurl',            "safe_site_url_filter");
77       
78
79//XOOPS Bloack Cache Refresh
80add_action("comment_post",      "block_cache_refresh");
81add_action("edit_comment",      "block_cache_refresh");
82add_action("wp_set_comment_status","block_cache_refresh"); //wp_delete_comment() at deleted
83add_action("deleted_post",      "block_cache_refresh");
84add_action("publish_post",      "block_cache_refresh");
85add_action("edit_post",         "block_cache_refresh");
86add_action("private_to_published",      "block_cache_refresh");
87add_action("transition_post_status", "block_cache_refresh");
88
89add_action("the_content",       "set_post_views_count");
90
91//XOOPS notifiction
92require_once dirname( __FILE__ ).'/include/notify_functions.php' ;
93add_action("transition_post_status",    "onaction_publish_post_notify" ,10 , 3);
94//      add_action("edit_post", "onaction_edit_post_notify");
95add_action("comment_post",      "onaction_comment_notify");
96//      add_action("approve_comment" , "onaction_comment_apobe_notify");
97add_action("wp_set_comment_status" , "onaction_comment_apobe_notify");
98
99// user data sync  user_sync_to_xoops($user_id)
100require_once dirname( __FILE__ ).'/include/user_sync_xoops.php' ;
101add_action('profile_update', 'user_sync_to_xoops');
102add_action('user_register', 'user_sync_to_xoops');
103//require_once('../include/custom_functions.php');
104
105//D3Forum Comment Integration
106if ($xpress_config->is_use_d3forum){
107        require_once dirname( __FILE__ ).'/include/d3forum_comment_synchro.php' ;
108        add_action("comment_post",      "onaction_comment_post");
109        add_action("edit_comment",      "onaction_edit_comment");
110        add_action("delete_comment","onaction_delete_comment");
111        add_action("delete_post",       "onaction_delete_post");
112        add_action("wp_set_comment_status" , "onaction_comment_apobe");
113       
114       
115        add_filter('comments_template', "disp_d3forum_comments" );
116
117}
118
119
120
121//The trackback and the pingback are excluded from the count of the comment.
122add_filter('get_comments_number', 'xpress_comment_count', 0);
123
124// Query filter for  MultiUser
125add_filter('query','xpress_query_filter');
126//add_action("init", "xpress_set_author_cookie");
127if(xpress_is_wp_version('<','2.1')){
128        // It is called before parse_request() makes $GET.
129        add_action("query_vars", "xpress_set_author_cookie");
130} else {
131        // It is called at the end of parse_request().
132        add_filter('request', 'xpress_set_author_cookie');
133}
134
135// SQL debug windows
136add_filter('query', array(&$xpress_config, 'xpress_sql_debug'));
137add_action('admin_footer', array(&$xpress_config, 'displayDebugLog'));
138add_action('wp_footer', array(&$xpress_config, 'displayDebugLog'));
139
140function redirect_xoops_admin()
141{
142        global $xoops_config,$xpress_config;
143        $xoops_admin_url = $xoops_config->module_url . '/admin/index.php';
144        wp_redirect($xoops_admin_url);
145}
146
147function display_option_page()
148{
149        global $xoops_config,$xpress_config;
150       
151                $xoops_admin_url = $xoops_config->module_url . '/admin/index.php';
152
153                $do_message ='';
154                if (!empty($_POST['submit_update'])) {
155                        $xpress_config->ReadPostData($_POST);
156                        $xpress_config->SettingValueWrite('update');
157                } else if (isset($_POST['submit_reset'])) {
158                        $xpress_config->setDefault();
159                        $xpress_config->SettingValueWrite('update');
160                }
161               
162                echo    '<div class="wrap">'."\n";
163                echo            '<div id="icon-options-general" class="icon32"><br /></div>'."\n";
164                echo            '<h2>' . __('XPressME Display Setting', 'xpressme') . "</h2><br>\n";
165//              echo            '<div align="right"><a href="' . $xoops_admin_url . '"><h3>'. __('to XOOPS Modules Admin Page', 'xpressme') . '</h3></a></div>';
166                echo            '<form method="post" action="' . $_SERVER["REQUEST_URI"] . '">'."\n" ;
167                echo                    '<table class="form-table">'."\n";
168                echo                            $xpress_config->viewer_type_option();
169                echo                            $xpress_config->yes_no_radio_option('is_theme_sidebar_disp',
170                                                                                                __('Thema Sidebar Display','xpressme'),
171                                                                                                __('YES','xpressme'),
172                                                                                                __('NO','xpressme')
173                                                                                                );
174                echo                            $xpress_config->single_post_navi_option();
175                echo                            $xpress_config->posts_page_navi_option();
176                echo                            $xpress_config->excerpt_option();
177                echo                            $xpress_config->dashboard_display_option();
178                echo                    "</table>\n";
179               
180                echo            '<p class="submit">'."\n";
181                echo            '<input type="submit" value= "' . __('Update Config', 'xpressme') . '" name="submit_update" />' ."\n";
182                echo            '<input type="submit" value= "' . __('Preset Config', 'xpressme') . '" name="submit_reset" />' ."\n";
183                echo            "</p>\n";
184
185                echo            "</form>\n" ;
186                echo    "</div>\n";
187}
188
189function integration_option_page()
190{
191        global $xoops_config,$xpress_config;
192       
193                $xoops_admin_url = $xoops_config->module_url . '/admin/index.php';
194
195                $do_message ='';
196                if (!empty($_POST['submit_update'])) {
197                        $xpress_config->ReadPostData($_POST);
198                        $xpress_config->SettingValueWrite('update');
199                } else if (isset($_POST['submit_reset'])) {
200                        $xpress_config->setDefault();
201                        $xpress_config->SettingValueWrite('update');
202                } else if (isset($_POST['export_d3f'])) {
203                        $do_message  = 'export(' . $xpress_config->d3forum_module_dir . '--ID=' . $xpress_config->d3forum_forum_id . ')................';
204                        $do_message .= wp_to_d3forum($xpress_config->d3forum_forum_id, $xpress_config->d3forum_module_dir);
205                        $do_message .= '....END';
206                } else if (isset($_POST['inport_d3f'])) {
207                        $do_message  = 'Import(' . $xpress_config->d3forum_module_dir . '--ID=' . $xpress_config->d3forum_forum_id . ')................';
208                        $do_message .= d3forum_to_wp($xpress_config->d3forum_forum_id, $xpress_config->d3forum_module_dir);
209                        $do_message .= '....END';
210                }               
211               
212                echo    '<div class="wrap">'."\n";
213                echo            '<div id="icon-options-general" class="icon32"><br /></div>'."\n";
214                echo            '<h2>' . __('XPressME Integration Setting', 'xpressme') . "</h2><br>\n";
215//              echo            '<div align="right"><a href="' . $xoops_admin_url . '"><h3>'. __('to XOOPS Modules Admin Page', 'xpressme') . '</h3></a></div>';
216                echo            '<form method="post" action="' . $_SERVER["REQUEST_URI"] . '">'."\n" ;
217                echo                    '<table class="form-table">'."\n";
218                $upload_title = __('Media Upload Base Path','xpressme');
219                if($xoops_config->is_wpmu) $upload_title = $upload_title . '(WPMU is not select)';
220                echo                            $xpress_config->yes_no_radio_option('is_use_xoops_upload_path',
221                                                                                                $upload_title,
222                                                                                                __('Use XOOPS UPLOAD PATH','xpressme'),
223                                                                                                __('USE WordPress BASE_PATH','xpressme'),
224                                                                                                $xoops_config->is_wpmu
225                                                                                                );
226               
227                echo                            $xpress_config->groupe_role_option();           
228               
229                echo                            $xpress_config->d3forum_option($do_message);           
230                echo                    "</table>\n";
231               
232                echo            '<p class="submit">'."\n";
233                echo            '<input type="submit" value= "' . __('Update Config', 'xpressme') . '" name="submit_update" />' ."\n";
234                echo            '<input type="submit" value= "' . __('Preset Config', 'xpressme') . '" name="submit_reset" />' ."\n";
235                echo            "</p>\n";
236
237                echo            "</form>\n" ;
238                echo    "</div>\n";
239}
240
241function other_option_page()
242{
243        global $xoops_config,$xpress_config;
244       
245                $xoops_admin_url = $xoops_config->module_url . '/admin/index.php';
246
247                $do_message ='';
248                if (!empty($_POST['submit_update'])) {
249                        $xpress_config->ReadPostData($_POST);
250                        $xpress_config->SettingValueWrite('update');
251                } else if (isset($_POST['submit_reset'])) {
252                        $xpress_config->setDefault();
253                        $xpress_config->SettingValueWrite('update');
254                }
255               
256                echo    '<div class="wrap">'."\n";
257                echo            '<div id="icon-options-general" class="icon32"><br /></div>'."\n";
258                echo            '<h2>' . __('XPressME Other Setting', 'xpressme') . "</h2><br>\n";
259//              echo            '<div align="right"><a href="' . $xoops_admin_url . '"><h3>'. __('to XOOPS Modules Admin Page', 'xpressme') . '</h3></a></div>';
260                echo            '<form method="post" action="' . $_SERVER["REQUEST_URI"] . '">'."\n" ;
261                echo                    '<table class="form-table">'."\n";
262                echo                            $xpress_config->yes_no_radio_option('is_save_post_revision',
263                                                                                                __('The change tracking of the post is preserved','xpressme'),
264                                                                                                __('YES','xpressme'),
265                                                                                                __('NO','xpressme')
266                                                                                                );
267               
268                echo                            $xpress_config->yes_no_radio_option('is_multi_user',
269                                                                                                __('Select Multi user mode','xpressme'),
270                                                                                                __('YES','xpressme'),
271                                                                                                __('NO','xpressme')
272                                                                                                );
273                echo                            $xpress_config->yes_no_radio_option('is_author_view_count',
274                                                                                                __('Is the posts author views counted?','xpressme'),
275                                                                                                __('YES','xpressme'),
276                                                                                                __('NO','xpressme')             
277                                                                                                );
278                echo                            $xpress_config->header_meta_option();
279                echo                            $xpress_config->yes_no_radio_option('is_sql_debug',
280                                                                                                __('Is SQL debugging window displayed?','xpressme'),
281                                                                                                __('YES','xpressme'),
282                                                                                                __('NO','xpressme')             
283                                                                                                );
284                echo                    "</table>\n";
285               
286                echo            '<p class="submit">'."\n";
287                echo            '<input type="submit" value= "' . __('Update Config', 'xpressme') . '" name="submit_update" />' ."\n";
288                echo            '<input type="submit" value= "' . __('Preset Config', 'xpressme') . '" name="submit_reset" />' ."\n";
289                echo            "</p>\n";
290
291                echo            "</form>\n" ;
292                echo    "</div>\n";
293}
294
295function upgrade_page()
296{
297        global $xoops_config,$xpress_config;
298       
299        $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
300        $check_url = "http://ja1.xpressme.info/version_check/?version=$xpress_version";
301
302        echo    '<div class="wrap">'."\n";
303        echo            '<div id="icon-options-general" class="icon32"><br /></div>'."\n";
304        echo            '<h2>' . __('XPressME Upgrade', 'xpressme') . "</h2><br>\n";
305       
306        if(get_xpress_latest_version()){
307                $latest = get_option('xpressme_latest_version');
308                if ($latest) {
309                        $site_url=$latest['url'];
310                        $package=$latest['package'];
311                        $latest_version=$latest['latest_version'];
312                        $check_time=$latest['check_time'];
313                }
314
315
316                if (version_compare($xpress_version, $latest_version, '>')){
317                                echo '<h3 class="response">';
318                                printf(__('You are using a XPressME Integration Kit development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.', 'xpressme') , $xpress_version , $site_url);
319                                echo '</h3>';
320
321                } else if (version_compare($xpress_version, $latest_version, '<')) {
322                        echo    '<h3 class="response">'. __('There is a new version of XPressME Integration Kit available for upgrade', 'xpressme') . '</h3>';
323                        echo '<p>';
324        //              printf(__('You can upgrade to version %s automatically or download the package and install it manually:'),$latest_version);
325                        printf(__('You can upgrade to version %s download the package and install it manually:', 'xpressme'),$latest_version);
326                        echo '</p>';
327                        echo '<a class="button" href="' . $package . '">';
328                        printf(__('Download %s', 'xpressme') , $latest_version);
329                        echo '</a>';
330                } else {
331                        echo    '<h3 class="response">'. __('You have the latest version of XPressME Integration Kit. You do not need to upgrade', 'xpressme') . '</h3>';
332                }
333        } else {
334                echo '<h3 class="response">';
335                printf(__('There is no response from <a href="%s">version check API</a> now. sorry, please confirm it after.', 'xpressme'),$check_url);
336                echo    "</div>\n";
337        }
338}
339
340function xp_remote_get($url, $headers = ""){
341        global $xoops_config;
342        $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
343
344        require_once( $xoops_config->module_path . '/wp-includes/class-snoopy.php');
345
346        // Snoopy is an HTTP client in PHP
347        $client = new Snoopy();
348        $client->agent = 'XPressME/' . $xpress_version;
349        $client->read_timeout = 2;
350        if (is_array($headers) ) {
351                $client->rawheaders = $headers;
352        }
353
354        @$client->fetch($url);
355        $response['response']['code'] = $client->status;
356        $response['body'] = $client->results;
357        return $response;
358        return $client;
359
360}
361
362function get_xpress_latest_version(){
363        global $wp_version, $wpdb, $wp_local_package;
364        global $xoops_config;
365       
366        $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
367
368        $check_url = "http://ja.xpressme.info/version_check/?version=$xpress_version";
369        $request_options = array(
370        'timeout' => 3,
371        'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
372        );
373
374        if (! function_exists('wp_remote_get')) {
375                $response = xp_remote_get($check_url);
376               
377                if (empty($response['body'])) return false;
378        } else {
379       
380                $response = wp_remote_get($check_url, $request_options);
381               
382                if ( is_wp_error( $response ) )
383                        return false;
384        }
385        if ( 200 != $response['response']['code'] )
386                return false;
387        $body = trim( $response['body'] );
388        $body = str_replace(array("\r\n", "\r"), "\n", $body);
389        $returns = explode("\n", $body);
390        $response = $returns[0];
391        if ( isset( $returns[1] ) )
392                $url = clean_url( $returns[1] );
393        if ( isset( $returns[2] ) )
394                $package = clean_url( $returns[2] );
395        if ( isset( $returns[3] ) )
396                $latest_version = $returns[3];
397
398        $write_options = array (
399                'url' => $url ,
400                'package' => $package ,
401                'latest_version' => $latest_version ,
402                'check_time' => time()
403        );
404       
405        $latest_version = get_option('xpressme_latest_version');
406        if (!$latest_version) {
407                add_option('xpressme_latest_version', $write_options);
408        } else {
409                update_option('xpressme_latest_version', $write_options);
410        }
411        return true;
412}
413
414function xpress_update_check() {
415        if ( defined('WP_INSTALLING') )
416                return;
417        global $pagenow;
418
419        $php_query_string = $_SERVER['QUERY_STRING'];
420
421        if ( 'admin.php' == $pagenow && 'page=upgrade_page' == $php_query_string)
422                return;
423
424        global $wp_version, $wpdb, $wp_local_package;
425        global $xoops_config;
426
427        $php_query_string = $_SERVER['QUERY_STRING'];
428        $xpress_version = $xoops_config->module_version . $xoops_config->module_codename;
429
430        $latest = get_option('xpressme_latest_version');
431        if (!$latest ) {
432                get_xpress_latest_version();
433                $latest = get_option('xpressme_latest_version');
434        }
435
436        if ($latest) {
437                $next_check = $latest['check_time'] + (60*60*24);
438                $now_time = time();
439                if ($next_check < $now_time ){
440                        get_xpress_latest_version();
441                        $latest = get_option('xpressme_latest_version');
442                }
443        }
444
445        if ($latest) {
446                $url=$latest['url'];
447                $package=$latest['package'];
448                $latest_version=$latest['latest_version'];
449                $check_time=$latest['check_time'];
450                $upgrade_page = $xoops_config->module_url . "/wp-admin/admin.php?page=upgrade_page";
451
452                if (version_compare($xpress_version, $latest_version, '<')) {
453                        if ( current_user_can('manage_options') ){
454                                $msg = sprintf( __('XPressME Integration Kit Version %1$s is available! <a href="%2$s">Please update now</a>.', 'xpressme'), $latest_version, $upgrade_page );
455                        } else {
456                                $msg = sprintf( __('XPressME Integration Kit Version %1$s is available! Please notify the site administrator.', 'xpressme'), $latest_version );
457                        }
458                        echo "<div id='update-nag'>$msg </div>";
459                }
460        }
461}
462
463add_action( 'admin_notices', 'xpress_update_check', 3 );
464
465include_once dirname( __FILE__ ).'/include/dashboard_feed.php' ;
466
467include_once dirname( __FILE__ ).'/xpressme_widget_class.php' ;
468
469?>
Note: See TracBrowser for help on using the repository browser.