diff -r 2f6f6f7551ca -r 32102edaa81b web/wp-content/plugins/xili-language/xili-xl-bbp-addon.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/wp-content/plugins/xili-language/xili-xl-bbp-addon.php Mon Nov 19 18:26:13 2012 +0100 @@ -0,0 +1,307 @@ +__construct(); } + + /** + * PHP 5 Constructor + */ + function __construct(){ + + $this->debug = ( defined ('WP_DEBUG') ) ? WP_DEBUG : false ; + + load_plugin_textdomain( 'xili_xl_bbp_addon', false, $this->plugin_folder.'/languages' ); + + register_activation_hook( __FILE__, array(&$this,'get_xili_settings') ); // first activation + + $this->url = plugins_url(basename(__FILE__), __FILE__); + $this->urlpath = plugins_url('', __FILE__); + + //Initialize the options + $this->get_xili_settings(); + //Admin menu + + add_action( 'admin_menu', array(&$this, 'admin_menu_link') ); + add_action( 'admin_init', array(&$this, 'admin_init') ); + + if ( is_admin() ) { + add_filter ( 'xiliml_manage_column_name', array(&$this,'xiliml_manage_column_name'), 10, 3); + add_filter ( 'xiliml_language_translated_in_column', array(&$this,'xiliml_language_translated_in_column'), 10, 3); + } + //Actions both side + + add_action( 'init', array(&$this,'plugin_init') ); + add_action( 'bbp_enqueue_scripts', array(&$this,'bbp_custom_css_enqueue') ); + + + // front-end side + + add_action( 'xiliml_add_frontend_mofiles', array(&$this,'xiliml_add_frontend_mofiles'), 10 ,2); + if ( ! is_admin() ) { + add_action( 'save_post', array(&$this,'bbp_save_topic_or_reply'), 10, 2 ); + add_action( 'parse_query', array(&$this,'bbpress_parse_query') ); // fixe issues in bbp 2.1 + } + } + + function plugin_init() { + $this->get_xili_settings(); + } + + + /** + * Retrieves the plugin options from the database. + * @return array + */ + function get_xili_settings() { + if (!$xili_settings = get_option( $this->settings_name )) { + $xili_settings = array( + 'css-theme-folder' => false, + 'version'=> $this->xili_settings_ver // see on top class + ); + update_option( $this->settings_name, $xili_settings); + } + $this->xili_settings = $xili_settings; + } + + /** change default style - inspired from Jared Atchison **/ + function bbp_custom_css_enqueue(){ + if ( isset( $this->xili_settings['css-theme-folder'] ) && $this->xili_settings['css-theme-folder'] ){ + // Unregister default bbPress CSS + wp_deregister_style( 'bbp-default-bbpress' ); + + // Register new CSS file in our active theme directory + wp_enqueue_style( 'bbp-default-bbpress', get_stylesheet_directory_uri() . '/bbpress.css' ); + } + } + + + /** change bbp mo file **/ + function xiliml_add_frontend_mofiles ( $theme_domain, $cur_iso_lang ) { // only called in front-end + + unload_textdomain( 'bbpress' ); + + //error_log ( $theme_domain . '--------------' . $cur_iso_lang ); + load_textdomain( 'bbpress', WP_LANG_DIR . '/bbpress/bbpress-'.$cur_iso_lang.'.mo' ); + } + + + + function bbp_save_topic_or_reply ( $post_ID, $post ) { + global $xili_language; + //test if topic or reply + if ( in_array ( $post->post_type, array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) ) ) { + // get language of parent forum + $parent_lang = $xili_language->get_post_language ( $post->post_parent ) ; + // set taxonomy to language + if ( $parent_lang != '') { + wp_set_object_terms( $post_ID, $parent_lang, TAXONAME ); + } + } + } + + + /** + * fixe issue in bbPress 2.1 + */ + function bbpress_parse_query ( $wp_query ) { + $bbp = bbpress() ; + if ( isset ( $wp_query->query_vars['post_type' ] ) && version_compare( $bbp->version, '2.2', '<') ) { + // announced to be fixed in bbp 2.2 - tracs 1947 - 4216 + if ( is_array ( $wp_query->query_vars['post_type' ] ) ) { + if ( $wp_query->query_vars['post_type' ] = array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) ) { + //error_log (' QUERY '.serialize ( $wp_query->query_vars['post_type' ] )); + $wp_query->is_home = false ; + } + } + } + } + + + function xiliml_manage_column_name ( $ends, $cols, $post_type ) { + if ( in_array ( $post_type, array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() ) ) ) { + //error_log ( '----------->'.$post_type); + $ends = array( 'author', 'comments', 'date', 'rel', 'visible'); + } + return $ends; + } + + function xiliml_language_translated_in_column ( $output, $result, $post_type ) { + + if ( in_array ( $post_type, array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() ) ) ) { + $output = ''; + if ( $result == '' ) { + $output .= '.' ; + } else { + $output .= __('linked in:', 'xili_xl_bbp_addon') ; + $output .= ' ' . $result .''; + } + } + + return $output; + } + + /** + * Adds the options subpanel + */ + function admin_menu_link() { + add_options_page( $this->plugin_name, __($this->display_plugin_name, 'xili_xl_bbp_addon'), 'manage_options', __FILE__, array(&$this,'admin_options_page')); + add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array(&$this, 'filter_plugin_actions'), 10, 2 ); + } + + /** + * Admin init - section - fields + */ + function admin_init() { + register_setting ($this->settings_name, $this->settings_name, array(&$this,'xili_settings_validate_options') ); + add_settings_section ( $this->settings_list.'_section_1', __('List of options ', 'xili_xl_bbp_addon') , array(&$this,'xili_settings_section_1_draw') , $this->settings_list ); + + add_settings_field ( $this->settings_list.'_css-theme-folder', __('bbPress default style file in theme', 'xili_xl_bbp_addon'), array(&$this,'xili_settings_field_1_draw'), $this->settings_list, $this->settings_list.'_section_1'); + + } + + function xili_settings_section_1_draw () { + echo '
'. __('This plugin shipped with xili-language package is an addon to activate multilingual features to bbPress with xili-language. Some other options are possible.', 'xili_xl_bbp_addon') . '
'; + + } + + function xili_settings_field_1_draw () { + // not checked - not saved in settings + $checked = ( isset ( $this->xili_settings['css-theme-folder'] ) && $this->xili_settings['css-theme-folder'] ) ? "checked='checked'" : ""; + + echo ""; + + } + + function xili_settings_validate_options ( $input ) { + + $valid = $input; + $valid['version'] = $this->xili_settings_ver ; // because not in input ! + return $valid; + } + + /** + * Adds the Settings link to the plugin activate/deactivate page + */ + function filter_plugin_actions($links, $file) { + $settings_link = '' . __('Settings') . ''; + array_unshift( $links, $settings_link ); // before other links + + return $links; + } + + /** + * Adds settings/options page + */ + function admin_options_page() { ?> +';
+ echo ''.__( 'Installation of both xili-language AND bbPress is not completed.', 'xili_language_errors' ) . '';
+ echo '
';
+ echo '