Limpieza
git-svn-id: https://192.168.0.254/svn/Proyectos.ASong2U_Web/trunk@27 cd1a4ea2-8c7f-e448-aada-19d1fee9e1d6
@ -1,314 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Functions for BP activities
|
||||
* @todo Check activity loop and google translate button
|
||||
*/
|
||||
|
||||
/**
|
||||
* Before saving activity hook.
|
||||
*
|
||||
* @param <type> $item
|
||||
*/
|
||||
function bpml_activities_bp_activity_before_save_hook($item) {
|
||||
if ($item->type == 'new_blog') {
|
||||
global $sitepress;
|
||||
$item->action = bpml_filter_hrefs_from_to($item->action, ICL_LANGUAGE_CODE,
|
||||
$sitepress->get_default_language(), -1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves activity language.
|
||||
*
|
||||
* @global <type> $sitepress
|
||||
* @param <type> $item
|
||||
*/
|
||||
function bpml_activities_bp_activity_after_save_hook($item) {
|
||||
switch ($item->type) {
|
||||
case 'new_blog_post':
|
||||
$lang = bpml_get_item_language($item);
|
||||
if (empty($lang)) {
|
||||
return FALSE;
|
||||
} else if (!empty($lang['language'])) {
|
||||
bp_activity_update_meta($item->id, 'bpml_lang', $lang['language']);
|
||||
} else {
|
||||
bp_activity_update_meta($item->id, 'bpml_lang', $lang['default_language']);
|
||||
}
|
||||
if (!empty($lang['recorded_language'])) {
|
||||
bp_activity_update_meta($item->id, 'bpml_lang_recorded', $lang['recorded_language']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'new_blog_comment':
|
||||
$lang = bpml_get_item_language($item, 'comment');
|
||||
if (empty($lang)) {
|
||||
return FALSE;
|
||||
} else if (!empty($lang['language'])) {
|
||||
bp_activity_update_meta($item->id, 'bpml_lang', $lang['language']);
|
||||
} else {
|
||||
bp_activity_update_meta($item->id, 'bpml_lang', $lang['default_language']);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (defined('ICL_LANGUAGE_CODE')) {
|
||||
bp_activity_update_meta($item->id, 'bpml_lang', ICL_LANGUAGE_CODE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
bpml_activities_clear_cache($item->item_id, 'bpml_google_translation', 'main');
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers indicator that we're in activity loop.
|
||||
*/
|
||||
function bpml_activities_bp_before_activity_loop_hook() {
|
||||
global $bpml_in_activity_loop;
|
||||
$bpml_in_activity_loop = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters activities.
|
||||
*
|
||||
* @todo This filter is called twice on favorites page via hook
|
||||
* 'bp_activity_get_specific'. See if that is a problem.
|
||||
*
|
||||
* @global $sitepress $sitepress
|
||||
* @param <type> $activity
|
||||
* @param <type> $r
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_activities_bp_activity_get_filter($activity, $r = NULL) {
|
||||
global $sitepress, $bpml_in_activity_loop;
|
||||
static $cache = array();
|
||||
$default_language = $sitepress->get_default_language();
|
||||
$current_language = $sitepress->get_current_language();
|
||||
foreach ($activity['activities'] as $key => $result) {
|
||||
if (isset($cache[$result->id])) {
|
||||
$activity['activities'][$key] = $cache[$result->id];
|
||||
continue;
|
||||
}
|
||||
$activity['activities'][$key] = bpml_activities_translate_activity($result, $default_language, $current_language);
|
||||
if ($activity['activities'][$key] == FALSE) {
|
||||
unset($activity['activities'][$key]);
|
||||
} else {
|
||||
$cache[$result->id] = $activity['activities'][$key];
|
||||
}
|
||||
}
|
||||
// if (!empty($bpml_in_activity_loop) && function_exists('bpml_google_translate_button')) {
|
||||
if (function_exists('bpml_google_translate_button')) {
|
||||
echo bpml_google_translate_button();
|
||||
}
|
||||
$activity['total'] = count($activity['activities']);
|
||||
return $activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates activity entry.
|
||||
*
|
||||
* @param <type> $result
|
||||
* @param <type> $default_language
|
||||
* @param <type> $current_language
|
||||
* @param <type> $options
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_activities_translate_activity($result, $default_language, $current_language) {
|
||||
global $bpml;
|
||||
// Record activity if isn't registered
|
||||
if (!isset($bpml['collected_activities'][$result->type])) {
|
||||
$bpml['collected_activities'][$result->type] = bpml_collected_activities_defaults();
|
||||
bpml_save_setting('collected_activities', $bpml['collected_activities']);
|
||||
bpml_store_admin_notice($result->type, '<p>New activities to handle: ' . $result->type . '</p>');
|
||||
}
|
||||
// Set options for current activity type (merge to cover missing options)
|
||||
$type_options = array_merge(bpml_collected_activities_defaults(), $bpml['collected_activities'][$result->type]);
|
||||
|
||||
// Get language
|
||||
$lang = bp_activity_get_meta($result->id, 'bpml_lang');
|
||||
$lang_recorded = bp_activity_get_meta($result->id, 'bpml_lang_recorded');
|
||||
|
||||
// Set/fix orphans (missing lang)
|
||||
if (empty($lang)) {
|
||||
if ($bpml['activities']['orphans_fix']) {
|
||||
$lang = bpml_activities_fix_orphan_activity($result, $default_language);
|
||||
bpml_debug('<p>Orphaned activity FIXED ID:' . $result->id . ' (Missing language - assigning \'' . $lang . '\')</p>');
|
||||
} else {
|
||||
bpml_debug('<p>Orphaned activity ID:' . $result->id . ' (Missing language - setting \'' . $default_language . '\')</p>');
|
||||
$lang = $default_language;
|
||||
}
|
||||
if (!$bpml['activities']['orphans_fix']
|
||||
&& ($bpml['activities']['display_orphans'] === 'none'
|
||||
|| ($bpml['activities']['display_orphans'] === 'default'
|
||||
&& $current_language != $default_language))) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter activities
|
||||
if (($bpml['activities']['filter'] && $lang == $current_language)
|
||||
|| (!$bpml['activities']['filter'])) {
|
||||
|
||||
$result->lang = $lang;
|
||||
if (!empty($lang_recorded)) {
|
||||
$result->lang_recorded = $lang_recorded;
|
||||
}
|
||||
|
||||
// Process children
|
||||
if (!empty($result->children)) {
|
||||
foreach ($result->children as $child_key => $child) {
|
||||
$result->children[$child_key] = bpml_activities_translate_activity($child, $default_language, $current_language, $options);
|
||||
}
|
||||
}
|
||||
|
||||
// Filter links
|
||||
if (0 !== intval($type_options['translate_links'])) {
|
||||
$result->action = bpml_filter_hrefs($result->action, $result->lang, intval($type_options['translate_links']));
|
||||
}
|
||||
|
||||
// Apply filters to activity
|
||||
$result = apply_filters('bpml_activity_filter', $result, $default_language, $current_language, $type_options);
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
function bpml_activities_fix_orphan_activity($item, $default_language) {
|
||||
switch ($item->type) {
|
||||
case 'new_blog_post':
|
||||
$lang = bpml_get_item_language($item, 'post_post', TRUE);
|
||||
if (empty($lang)) {
|
||||
bp_activity_update_meta($item->id, 'bpml_lang', $default_language);
|
||||
} else if (!empty($lang['language'])) {
|
||||
bp_activity_update_meta($item->id, 'bpml_lang', $lang['language']);
|
||||
} else {
|
||||
bp_activity_update_meta($item->id, 'bpml_lang', $lang['default_language']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'new_blog_comment':
|
||||
$lang = bpml_get_item_language($item, 'comment', TRUE);
|
||||
if (empty($lang)) {
|
||||
bp_activity_update_meta($item->id, 'bpml_lang', $default_language);
|
||||
} else if (!empty($lang['language'])) {
|
||||
bp_activity_update_meta($item->id, 'bpml_lang', $lang['language']);
|
||||
} else {
|
||||
bp_activity_update_meta($item->id, 'bpml_lang', $lang['default_language']);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
bp_activity_update_meta($item->id, 'bpml_lang', $default_language);
|
||||
break;
|
||||
}
|
||||
bp_activity_update_meta($result->id, 'bpml_lang_orphan', $default_language);
|
||||
bpml_activities_clear_cache($item->item_id, 'bpml_google_translation', 'main');
|
||||
return bp_activity_get_meta($item->id, 'bpml_lang');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns default collected activity settings.
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_collected_activities_defaults() {
|
||||
return array(
|
||||
'translate_title' => 0,
|
||||
'translate_title_cache' => 0,
|
||||
'translate_content' => 0,
|
||||
'translate_content_cache' => 0,
|
||||
'translate_links' => 0
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears activity cache
|
||||
*
|
||||
* @global <type> $wpdb
|
||||
* @param <type> $ID
|
||||
* @param <type> $type
|
||||
*/
|
||||
function bpml_activities_clear_cache($ID, $type = 'bpml_google_translation',
|
||||
$blog_id = NULL) {
|
||||
if ($blog_id == 'main' && !is_main_site()) {
|
||||
global $current_site;
|
||||
$blog_id = $current_site->blog_id;
|
||||
} else if ($blog_id == 'main') {
|
||||
$blog_id = NULL;
|
||||
}
|
||||
if (!is_null($blog_id)) {
|
||||
switch_to_blog($blog_id);
|
||||
}
|
||||
global $wpdb;
|
||||
if ($ID == 'all') {
|
||||
$wpdb->query("DELETE FROM {$wpdb->prefix}bp_activity_meta WHERE meta_key='" . $type . "'");
|
||||
} else {
|
||||
$wpdb->query("DELETE FROM {$wpdb->prefix}bp_activity_meta WHERE meta_key='" . $type . "' AND activity_id=" . $ID);
|
||||
}
|
||||
if (!is_null($blog_id)) {
|
||||
restore_current_blog();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all BPML activity data.
|
||||
*/
|
||||
function bpml_activities_clear_all_data($ID = 'all') {
|
||||
bpml_activities_clear_cache($ID, 'bpml_google_translation');
|
||||
bpml_activities_clear_cache($ID, 'bpml_lang');
|
||||
bpml_activities_clear_cache($ID, 'bpml_lang_recorded');
|
||||
bpml_activities_clear_cache($ID, 'bpml_lang_orphan');
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin language assign dropdown for single activity.
|
||||
*
|
||||
* @global <type> $activities_template
|
||||
* @global $sitepress
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_activities_assign_language_dropdown() {
|
||||
if (!current_user_can('administrator')) {
|
||||
return '';
|
||||
}
|
||||
global $activities_template, $sitepress;
|
||||
$langs = $sitepress->get_active_languages();
|
||||
$data = '';
|
||||
foreach ($langs as $lang) {
|
||||
$selected = $activities_template->activity->lang == $lang['code'] ? ' selected="selected"' : '';
|
||||
$data .= '<option value="' . $lang['code'] . '"' . $selected . '>' . $lang['english_name'] . '</option>';
|
||||
}
|
||||
|
||||
echo '<li class="bpml-activity-assign-language-wrapper"><form class="bpml-activity-assign-language" action="' . admin_url() . '/admin-ajax.php" method="post">';
|
||||
echo '<select name="bpml-activity-assign-language[' . $activities_template->activity->id . ']">' . $data . '</select> <input type="submit" value="Change language" /><span style="margin-left:10px;" class="bmp-ajax-update"></span></form></li>';
|
||||
}
|
||||
|
||||
/**
|
||||
* BPML activities AJAX process.
|
||||
*/
|
||||
function bpml_activities_ajax() {
|
||||
if (current_user_can('administrator') && isset($_POST['bpml-activity-assign-language'])) {
|
||||
$ID = key($_POST['bpml-activity-assign-language']);
|
||||
$lang = $_POST['bpml-activity-assign-language'][$ID];
|
||||
bp_activity_update_meta($ID, 'bpml_lang', $lang);
|
||||
bpml_activities_clear_cache($ID, 'bpml_google_translation');
|
||||
echo json_encode(array('output' => 'Language assigned'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates latest update on the fly.
|
||||
*
|
||||
* @global <type> $bpml
|
||||
* @param <type> $content
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_bp_get_activity_latest_update_filter($content) {
|
||||
global $bpml;
|
||||
if ($bpml['activities']['enable_google_translation'] === 0) {
|
||||
return $content;
|
||||
}
|
||||
require_once dirname(__FILE__) . '/google-translate.php';
|
||||
return bpml_google_translate($content, '', ICL_LANGUAGE_CODE);
|
||||
}
|
||||
@ -1,306 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Admin form functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Processes admin page submit.
|
||||
*
|
||||
* @global <type> $wpdb
|
||||
*/
|
||||
function bpml_admin_save_settings_submit() {
|
||||
if (current_user_can('manage_options') && wp_verify_nonce(isset($_POST['_wpnonce']), 'bpml_save_options') && isset($_POST['bpml'])) {
|
||||
if (isset($_POST['bpml_clear_google_cache'])) {
|
||||
bpml_activities_clear_cache('all', 'bpml_google_translation');
|
||||
bpml_store_admin_notice('settings_saved', '<p>Cache cleared</p>');
|
||||
} else if (isset($_POST['bpml_clear_all_activity_data'])) {
|
||||
bpml_activities_clear_all_data();
|
||||
bpml_store_admin_notice('settings_saved', '<p>Activities data cleared</p>');
|
||||
} else if (isset($_POST['bpml_admin_clear_activity_translations_single'])) {
|
||||
bpml_admin_clear_activity_translations_single(key($_POST['bpml_admin_clear_activity_translations_single']));
|
||||
bpml_store_admin_notice('settings_saved', '<p>Activity data cleared</p>');
|
||||
} else if (isset($_POST['bpml_admin_clear_activity_data_single'])) {
|
||||
bpml_admin_clear_activity_data_single(key($_POST['bpml_admin_clear_activity_data_single']));
|
||||
bpml_store_admin_notice('settings_saved', '<p>Activity data cleared</p>');
|
||||
} else if (isset($_POST['bpml_reset_options'])) {
|
||||
bpml_save_settings(bpml_default_settings());
|
||||
bpml_store_admin_notice('settings_saved', '<p>Settings set to default</p>');
|
||||
} else {
|
||||
bpml_admin_save_settings_submit_recursive(&$_POST['bpml']);
|
||||
bpml_save_settings($_POST['bpml']);
|
||||
do_action('bpml_settings_saved', $_POST['bpml']);
|
||||
bpml_store_admin_notice('settings_saved', '<p>Settings saved</p>');
|
||||
}
|
||||
wp_redirect(admin_url('options-general.php?page=bpml'));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets POST values.
|
||||
*
|
||||
* @param <type> $array
|
||||
*/
|
||||
function bpml_admin_save_settings_submit_recursive(&$array) {
|
||||
foreach ($array as $key => &$value) {
|
||||
if (is_array($value)) {
|
||||
bpml_admin_save_settings_submit_recursive(&$value);
|
||||
} else if ($value == '0' || $value == '1' || $value == '-1') {
|
||||
$value = intval($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders admin page.
|
||||
*
|
||||
* @global <type> $bpml
|
||||
*/
|
||||
function bpml_admin_page() {
|
||||
bpml_delete_setting('admin_notices');
|
||||
global $bpml;
|
||||
echo '<div class="wrap">
|
||||
<div id="icon-options-general" class="icon32"><br /></div>
|
||||
<h2>BuddyPress Multilingual</h2><div class="bpml-admin-form">';
|
||||
echo '<form action="" method="post">';
|
||||
wp_nonce_field('bpml_save_options');
|
||||
|
||||
echo '<h2>General</h2>';
|
||||
|
||||
echo 'Enable debugging <em>(visible on frontend for admin only)</em><br />';
|
||||
echo '<label><input type="radio" name="bpml[debug]" value="1"';
|
||||
if ($bpml['debug'])
|
||||
echo ' checked="checked"';
|
||||
echo '/> Yes</label> ';
|
||||
echo '<label><input type="radio" name="bpml[debug]" value="0"';
|
||||
if (!$bpml['debug'])
|
||||
echo ' checked="checked"';
|
||||
echo '/> No</label>';
|
||||
|
||||
echo '<br /><br />';
|
||||
|
||||
do_action('bpml_settings_form_before');
|
||||
|
||||
echo '<h2>Activities</h2>';
|
||||
|
||||
echo 'Filter activity entries per language<br /><em>Default: No (activities are all displayed and optionally translated)</em><br />';
|
||||
echo '<label><input type="radio" name="bpml[activities][filter]" value="1"';
|
||||
if ($bpml['activities']['filter'])
|
||||
echo ' checked="checked"';
|
||||
echo '/> Yes</label> ';
|
||||
echo '<label><input type="radio" name="bpml[activities][filter]" value="0"';
|
||||
if (!$bpml['activities']['filter'])
|
||||
echo ' checked="checked"';
|
||||
echo '/> No</label>';
|
||||
|
||||
echo '<br /><br />';
|
||||
|
||||
echo '<input type="submit" value="Clear all BPML language activity data" name="bpml_clear_all_activity_data" class="submit button-secondary" onclick="if (confirm(\'Are you sure?\\nAll activities will loose language data!\') == false) { return false; }" />';
|
||||
|
||||
echo '<br /><br />';
|
||||
|
||||
echo 'Show activity language assign dropdown for admin<br />';
|
||||
echo '<label><input type="radio" name="bpml[activities][show_activity_switcher]" value="1"';
|
||||
if ($bpml['activities']['show_activity_switcher'])
|
||||
echo ' checked="checked"';
|
||||
echo '/> Yes</label> ';
|
||||
echo '<label><input type="radio" name="bpml[activities][show_activity_switcher]" value="0"';
|
||||
if (!$bpml['activities']['show_activity_switcher'])
|
||||
echo ' checked="checked"';
|
||||
echo '/> No</label>';
|
||||
|
||||
echo '<br /><br />';
|
||||
|
||||
echo 'Display activity updates without language in:<br />';
|
||||
echo '<label><input type="radio" name="bpml[activities][display_orphans]" value="default"';
|
||||
if ($bpml['activities']['display_orphans'] === 'default')
|
||||
echo ' checked="checked"';
|
||||
echo '/> Default language</label> ';
|
||||
echo '<label><input type="radio" name="bpml[activities][display_orphans]" value="all"';
|
||||
if ($bpml['activities']['display_orphans'] === 'all')
|
||||
echo ' checked="checked"';
|
||||
echo '/> All languages</label> ';
|
||||
echo '<label><input type="radio" name="bpml[activities][display_orphans]" value="none"';
|
||||
if ($bpml['activities']['display_orphans'] === 'none')
|
||||
echo ' checked="checked"';
|
||||
echo '/> Don\'t display</label>';
|
||||
|
||||
echo '<br /><br />';
|
||||
|
||||
echo 'Auto-assing default language to activities without language data<br />';
|
||||
echo '<label><input type="radio" name="bpml[activities][orphans_fix]" value="1"';
|
||||
if ($bpml['activities']['orphans_fix'])
|
||||
echo ' checked="checked"';
|
||||
echo '/> Yes</label> ';
|
||||
echo '<label><input type="radio" name="bpml[activities][orphans_fix]" value="0"';
|
||||
if (!$bpml['activities']['orphans_fix'])
|
||||
echo ' checked="checked"';
|
||||
echo '/> No</label>';
|
||||
|
||||
echo '<br /><br />';
|
||||
|
||||
echo 'Enable Google Translation for titles and content<br /><em>will not be used if filtering is enabled</em><br />';
|
||||
echo '<label><input type="radio" class="bpml-show-collected-activities" name="bpml[activities][enable_google_translation]" value="store"';
|
||||
if ($bpml['activities']['enable_google_translation'] === 'store')
|
||||
echo ' checked="checked"';
|
||||
echo '/> Store in DB</label> ';
|
||||
echo '<label><input type="radio" class="bpml-show-collected-activities" name="bpml[activities][enable_google_translation]" value="js"';
|
||||
if ($bpml['activities']['enable_google_translation'] === 'js')
|
||||
echo ' checked="checked"';
|
||||
echo '/> Use as JS (enable user control)</label> ';
|
||||
echo '<label><input type="radio" class="bpml-hide-collected-activities" name="bpml[activities][enable_google_translation]" value="0"';
|
||||
if (!$bpml['activities']['enable_google_translation'])
|
||||
echo ' checked="checked"';
|
||||
echo '/> No</label>';
|
||||
echo ' <input type="submit" value="Clear cached translations" name="bpml_clear_google_cache" class="submit button-secondary" />';
|
||||
|
||||
echo '<br /><br />';
|
||||
|
||||
echo '<div id="bpml-collected-activities">';
|
||||
echo '<strong>Collected activities:</strong><br />';
|
||||
echo '<em>Soon as some activity is registered on site it will be displayed here.</em><br /><br />';
|
||||
echo '<a href="javascript:void(0);" id="bpml-activities-select-all">Set all for translation</a> | ';
|
||||
echo '<a href="javascript:void(0);" id="bpml-activities-clear-all">Clear all</a><br /><br />';
|
||||
ksort($bpml['collected_activities']);
|
||||
foreach ($bpml['collected_activities'] as $type => $activity) {
|
||||
|
||||
echo '<table class="bpml-collected-activities-wrapper">';
|
||||
|
||||
echo '<tr><td colspan="3"><div class="bpml-collected-activities-title">' . $type . '</div></td></tr>';
|
||||
|
||||
echo '<tr>';
|
||||
|
||||
echo '<td><label class="bpml-activities-link-option">Translate links <select name="bpml[collected_activities][' . $type . '][translate_links]">';
|
||||
echo '<option value="0"';
|
||||
if (0 == intval($activity['translate_links'])) {
|
||||
echo ' selected="selected" ';
|
||||
}
|
||||
echo '>No</option>';
|
||||
echo '<option value="-1"';
|
||||
if (-1 == intval($activity['translate_links'])) {
|
||||
echo ' selected="selected" ';
|
||||
}
|
||||
echo '>All</option>';
|
||||
for ($index = 1; $index < 6; $index++) {
|
||||
echo '<option';
|
||||
if ($index == $activity['translate_links']) {
|
||||
echo ' selected="selected" ';
|
||||
}
|
||||
echo ' value="' . $index . '">Limit to ' . $index . ' </option>';
|
||||
}
|
||||
echo '</select></label></td>';
|
||||
|
||||
echo '<td><div class="bpml-activities-hide-titlecontent-option"><label><input type="checkbox" name="bpml[collected_activities][' . $type . '][translate_title]" value="1"';
|
||||
echo (isset($activity['translate_title']) && $activity['translate_title']) ? ' checked="checked"' : '';
|
||||
echo ' />';
|
||||
echo ' Translate title </label></div>';
|
||||
|
||||
echo '<div class="bpml-activities-hide-cache-option"><label><input type="checkbox" name="bpml[collected_activities][' . $type . '][translate_title_cache]" value="1"';
|
||||
echo (isset($activity['translate_title_cache']) && $activity['translate_title_cache']) ? ' checked="checked"' : '';
|
||||
echo ' />';
|
||||
echo ' Cache title translation </label></div></td>';
|
||||
|
||||
echo '<td><div class="bpml-activities-hide-titlecontent-option"><label><input type="checkbox" name="bpml[collected_activities][' . $type . '][translate_content]" value="1"';
|
||||
echo (isset($activity['translate_content']) && $activity['translate_content']) ? ' checked="checked"' : '';
|
||||
echo ' />';
|
||||
echo ' Translate content </label></div>';
|
||||
|
||||
echo '<div class="bpml-activities-hide-cache-option"><label><input type="checkbox" name="bpml[collected_activities][' . $type . '][translate_content_cache]" value="1"';
|
||||
echo (isset($activity['translate_content_cache']) && $activity['translate_content_cache']) ? ' checked="checked"' : '';
|
||||
echo ' />';
|
||||
echo ' Cache content translation </label></div></td>';
|
||||
|
||||
echo '</tr>';
|
||||
echo '<tr><td colspan="3">
|
||||
<input type="submit" value="Clear cached translations" name="bpml_admin_clear_activity_translations_single[' . $type . ']" class="submit button-secondary" onclick="if (confirm(\'Are you sure?\\nThis activity will loose cached translation!\') == false) { return false; }" />
|
||||
<input type="submit" value="Clear all data" name="bpml_admin_clear_activity_data_single[' . $type . ']" class="submit button-secondary" onclick="if (confirm(\'Are you sure?\\nThis activity will loose language data!\') == false) { return false; }" />
|
||||
</td></tr>';
|
||||
|
||||
do_action('bpml_settings_form_collected_activities', $type, $activity);
|
||||
|
||||
echo '</table>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
do_action('bpml_settings_form_after');
|
||||
|
||||
echo '<br /><br /><input type="submit" value="Save Settings" name="bpml_save_options" class="submit button-primary" />';
|
||||
echo ' <input type="submit" value="Reset Settings" name="bpml_reset_options" class="submit button-secondary" onclick="if (confirm(\'Are you sure?\\nAll custom settings will be lost!\') == false) { return false; }" />';
|
||||
echo '</form>';
|
||||
echo '</div></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears cached translation by activity type.
|
||||
*
|
||||
* @global $wpdb
|
||||
* @param <type> $type
|
||||
*/
|
||||
function bpml_admin_clear_activity_translations_single($type) {
|
||||
global $wpdb;
|
||||
$results = $wpdb->get_results("SELECT id from {$wpdb->prefix}bp_activity WHERE type='" . $type . "'");
|
||||
foreach ($results as $key => $result) {
|
||||
bpml_activities_clear_cache($result->id, 'bpml_google_translation');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears cached data by activity type.
|
||||
*
|
||||
* @global $wpdb
|
||||
* @param <type> $type
|
||||
*/
|
||||
function bpml_admin_clear_activity_data_single($type) {
|
||||
global $wpdb;
|
||||
$results = $wpdb->get_results("SELECT id FROM {$wpdb->prefix}bp_activity WHERE type='" . $type . "'");
|
||||
foreach ($results as $key => $result) {
|
||||
bpml_activities_clear_cache($result->id, 'bpml_google_translation');
|
||||
bpml_activities_clear_cache($result->id, 'bpml_lang');
|
||||
bpml_activities_clear_cache($result->id, 'bpml_lang_recorded');
|
||||
bpml_activities_clear_cache($result->id, 'bpml_lang_orphan');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin form hook.
|
||||
*
|
||||
* @global $bpml
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_profiles_admin_form() {
|
||||
global $bpml;
|
||||
echo '<h2>Profile fields</h2>';
|
||||
echo '<label><input type="radio" name="bpml[profiles][translation]" value="no"' . (($bpml['profiles']['translation'] == 'no' || !isset($bpml['profiles']['translation'])) ? ' checked="checked"' : '') . ' /> No translation</label> <br />';
|
||||
echo '<label><input type="radio" name="bpml[profiles][translation]" value="user"' . ($bpml['profiles']['translation'] == 'user' ? ' checked="checked"' : '') . ' /> Allow user to translate</label> <br />';
|
||||
|
||||
echo '<br /><br />';
|
||||
|
||||
echo 'Select fields that can be translated:';
|
||||
// get fields
|
||||
$groups = BP_XProfile_Group::get(array(
|
||||
'fetch_fields' => true
|
||||
));
|
||||
if (empty($groups)) {
|
||||
echo 'No profile fields.';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
foreach ($groups as $group) {
|
||||
if (empty($group->fields)) {
|
||||
echo 'No fields in this group';
|
||||
continue;
|
||||
}
|
||||
echo '<h4>' . $group->name . '</h4>';
|
||||
foreach ($group->fields as $field) {
|
||||
$checked = isset($bpml['profiles']['fields'][$field->id]) ? ' checked="checked"' : '';
|
||||
echo '<label><input type="checkbox" name="bpml[profiles][fields][' . $field->id . ']" value="1"' . $checked . ' /> ' . $field->name . '</label> ';
|
||||
}
|
||||
}
|
||||
|
||||
echo '<br /><br /><br />Translate field titles<br />';
|
||||
$checked = isset($bpml['profiles']['translate_fields_title']) ? ' checked="checked"' : '';
|
||||
echo '<label><input type="checkbox" name="bpml[profiles][translate_fields_title]" value="1"' . $checked . ' /> Yes</label> ';
|
||||
|
||||
echo '<br /><br /><input type="submit" value="Save Settings" name="bpml_save_options" class="submit button-primary" />';
|
||||
echo '<br /><br />';
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Admin functions
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adds admin menu
|
||||
*/
|
||||
function bpml_admin_menu() {
|
||||
add_options_page(
|
||||
'BuddyPress Multilingual',
|
||||
'BuddyPress Multilingual',
|
||||
'manage_options',
|
||||
'bpml',
|
||||
'bpml_admin_page');
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders stored admin notices.
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_admin_show_stored_admin_notices() {
|
||||
$messages = bpml_get_setting('admin_notices');
|
||||
if (empty($messages)) {
|
||||
return '';
|
||||
}
|
||||
foreach ($messages as $message) {
|
||||
bpml_admin_message($message, 'updated', 'all_admin_notices');
|
||||
}
|
||||
}
|
||||
@ -1,315 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Frontend functions
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test function.
|
||||
*
|
||||
* @param <type> $a
|
||||
*/
|
||||
function bpml_test($a = '') {
|
||||
echo '<pre>'; print_r($a); echo '</pre>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Before BP header hook.
|
||||
*
|
||||
* Activate site_url() filter.
|
||||
*/
|
||||
function bpml_bp_before_header_hook() {
|
||||
add_filter('site_url', 'bpml_site_url_filter', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* After BP footer hook.
|
||||
*
|
||||
* Remove site_url() filter.
|
||||
*/
|
||||
function bpml_bp_after_footer_hook() {
|
||||
remove_filter('site_url', 'bpml_site_url_filter', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters site_url() calls.
|
||||
*
|
||||
* @global $sitepress
|
||||
* @param <type> $url
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_site_url_filter($url, $path = '') {
|
||||
global $sitepress;
|
||||
return rtrim($sitepress->convert_url($url), '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes site_url() filter when redirecting to random blog.
|
||||
*/
|
||||
function bpml_blogs_redirect_to_random_blog() {
|
||||
global $bp;
|
||||
if ($bp->current_component == $bp->blogs->slug && isset($_GET['random-blog'])) {
|
||||
remove_filter('site_url', 'bpml_site_url_filter', 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters BuddyPress root domain.
|
||||
*
|
||||
* @global $sitepress $sitepress
|
||||
* @param <type> $url
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_bp_core_get_root_domain_filter($url) {
|
||||
global $sitepress;
|
||||
return rtrim($sitepress->convert_url($url), '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters admin URL (removes language).
|
||||
*
|
||||
* @global $sitepress $sitepress
|
||||
* @param <type> $url
|
||||
* @param <type> $path
|
||||
* @param <type> $blog_id
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_admin_url_filter($url, $path, $blog_id) {
|
||||
$url = str_replace('/' . ICL_LANGUAGE_CODE . '/wp-admin', '/wp-admin/', $url);
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates all links in given string.
|
||||
*
|
||||
* @global <type> $bpml_filter_hrefs_lang
|
||||
* @param <type> $string
|
||||
* @param <type> $lang
|
||||
* @param <type> $limit
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_filter_hrefs($string = '', $lang = '', $limit = -1,
|
||||
$position = NULL) {
|
||||
global $bpml_filter_hrefs_lang, $bpml_filter_hrefs_count;
|
||||
$bpml_filter_hrefs_count = 0;
|
||||
$bpml_filter_hrefs_lang = $lang;
|
||||
if (!is_null($position)) {
|
||||
global $bpml_filter_hrefs_position;
|
||||
$bpml_filter_hrefs_position = $position;
|
||||
}
|
||||
$return = preg_replace_callback('/href=["\'](.+?)["\']/', 'bpml_filter_href_matches', $string, $limit);
|
||||
$bpml_filter_hrefs_count = 0;
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates all links in given string from to.
|
||||
*
|
||||
* @global <type> $bpml_filter_hrefs_lang
|
||||
* @param <type> $string
|
||||
* @param <type> $lang
|
||||
* @param <type> $limit
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_filter_hrefs_from_to($string = '', $lang_from = '', $lang_to = '',
|
||||
$limit = -1, $position = NULL) {
|
||||
global $bpml_filter_hrefs_lang, $bpml_filter_hrefs_lang_to, $bpml_filter_hrefs_count;
|
||||
$bpml_filter_hrefs_count = 0;
|
||||
$bpml_filter_hrefs_lang = $lang_from;
|
||||
$bpml_filter_hrefs_lang_to = $lang_to;
|
||||
if (!is_null($position)) {
|
||||
global $bpml_filter_hrefs_position;
|
||||
$bpml_filter_hrefs_position = $position;
|
||||
}
|
||||
$return = preg_replace_callback('/href=["\'](.+?)["\']/', 'bpml_filter_href_matches', $string, $limit);
|
||||
$bpml_filter_hrefs_count = 0;
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates links in matches provided from bpml_filter_hrefs().
|
||||
*
|
||||
* @global $sitepress $sitepress
|
||||
* @global $bpml_filter_hrefs_lang
|
||||
* @param <type> $match
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_filter_href_matches($match = array()) {
|
||||
global $sitepress, $bpml_filter_hrefs_lang, $bpml_filter_hrefs_lang_to, $bpml_filter_hrefs_position, $bpml_filter_hrefs_count;
|
||||
|
||||
if (!empty($bpml_filter_hrefs_position)) {
|
||||
if ($bpml_filter_hrefs_count != $bpml_filter_hrefs_position) {
|
||||
$bpml_filter_hrefs_count += 1;
|
||||
return $match[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($bpml_filter_hrefs_lang_to)) {
|
||||
$lang_to = ($bpml_filter_hrefs_lang_to == $sitepress->get_default_language()) ? '' : $bpml_filter_hrefs_lang_to . '/';
|
||||
$converted = preg_replace('/\/' . $bpml_filter_hrefs_lang . '\//', '/' . $lang_to, $match[1], 1);
|
||||
} else if ($sitepress->get_current_language() != $sitepress->get_default_language()) {
|
||||
if ($bpml_filter_hrefs_lang !== $sitepress->get_default_language()) {
|
||||
$converted = preg_replace('/\/' . $bpml_filter_hrefs_lang . '\//', '/' . $sitepress->get_current_language() . '/', $match[1], 1);
|
||||
} else {
|
||||
$converted = $sitepress->convert_url($match[1]);
|
||||
}
|
||||
// Check doubled
|
||||
$converted = preg_replace('/\/' . $sitepress->get_current_language() . '\/' . $sitepress->get_current_language() . '\//', '/' . $sitepress->get_current_language() . '/', $converted, 1);
|
||||
} else {
|
||||
$replace = !empty($bpml_filter_hrefs_lang) ? '/\/' . $bpml_filter_hrefs_lang . '\//' : '/\//';
|
||||
$converted = preg_replace($replace, '/', $match[1], 1);
|
||||
}
|
||||
return str_replace($match[1], $converted, $match[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters bp_uri.
|
||||
*
|
||||
* This URI is important for BuddyPress.
|
||||
* By that it determines some components and actions.
|
||||
* We remove language component so BP can determine things right.
|
||||
*
|
||||
* @param <type> $url
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_bp_uri_filter($url) {
|
||||
global $sitepress;
|
||||
$default_language = $sitepress->get_default_language();
|
||||
if ($default_language == ICL_LANGUAGE_CODE) {
|
||||
return $url;
|
||||
}
|
||||
return preg_replace('/\/' . ICL_LANGUAGE_CODE . '\//', '/', $url, 1);
|
||||
|
||||
echo $default_language;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters WPML languages switcher.
|
||||
*
|
||||
* This filtering is performed on BP pages
|
||||
* where WPML actually don't detect any post/page.
|
||||
*
|
||||
* @global <type> $sitepress
|
||||
* @global <type> $bp
|
||||
* @global <type> $bp_unfiltered_uri
|
||||
* @global <type> $post
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_icl_ls_languages_filter($langs) {
|
||||
global $sitepress, $bp, $bp_unfiltered_uri, $post;
|
||||
$default_language = $sitepress->get_default_language();
|
||||
|
||||
foreach($bp->active_components as $key => $value){
|
||||
$components[] = $key;
|
||||
}
|
||||
|
||||
if(!isset($bp_unfiltered_uri[0])){
|
||||
$bp_unfiltered_uri[0] = '';
|
||||
}
|
||||
|
||||
// Unset the languages for missing translations
|
||||
if(!in_array($bp_unfiltered_uri[0], $components)) {
|
||||
foreach ($langs as $key => $lang) {
|
||||
$url = ($default_language !== $key) ? $url = get_option('home') . "/$key/" : $url = get_option('home') . "/";
|
||||
if($url == $langs[$key]['url']){
|
||||
if(!is_home() && !is_front_page($post->ID)){
|
||||
unset($langs[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $langs;
|
||||
}
|
||||
|
||||
// Recreates language selector - the all components should have all languages
|
||||
if(version_compare(BP_VERSION, '1.2.9') >= 0){
|
||||
$langs = $sitepress->get_active_languages();
|
||||
$url = '';
|
||||
foreach($bp_unfiltered_uri as $key => $path){
|
||||
$url .= '/' . $path;
|
||||
}
|
||||
|
||||
$homepage = get_option('home');
|
||||
$urlToFlags = ICL_PLUGIN_URL . '/res/flags/';
|
||||
foreach ($langs as $key => $lang) {
|
||||
$langs[$key]['country_flag_url'] = $urlToFlags . "$key.png";
|
||||
$langs[$key]['language_code'] = $key;
|
||||
$langs[$key]['translated_name'] = $lang['english_name'];
|
||||
|
||||
if($default_language == $key){
|
||||
$langs[$key]['url'] = $homepage . $url;
|
||||
} else {
|
||||
$langs[$key]['url'] = $homepage . '/' . $lang['code'] . $url;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!in_array($bp_unfiltered_uri[0], $bp->root_components)) {
|
||||
return $langs;
|
||||
}
|
||||
|
||||
foreach ($langs as $key => $lang) {
|
||||
$langs[$key]['url'] = $sitepress->convert_url(get_option('home')
|
||||
. '/' . implode('/', $bp_unfiltered_uri), $lang['language_code']);
|
||||
}
|
||||
}
|
||||
return $langs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores/returns debug messages.
|
||||
*
|
||||
* @staticvar array $messages
|
||||
* @param <type> $message
|
||||
* @param <type> $class
|
||||
* @return array
|
||||
*/
|
||||
function bpml_debug($message, $class = 'bpml-debug-updated') {
|
||||
if (!current_user_can('administrator') || !defined('BPML_DEBUG') || !BPML_DEBUG) {
|
||||
return '';
|
||||
}
|
||||
static $messages = array();
|
||||
if ($message == 'get') {
|
||||
return $messages;
|
||||
}
|
||||
$messages[] = array('message' => $message, 'class' => 'updated bpml-debug ' . $class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Header hook.
|
||||
*/
|
||||
function bpml_wp_head_hook() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders debug info.
|
||||
*
|
||||
* @global $bp
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_wp_footer() {
|
||||
|
||||
if (!current_user_can('administrator') || !defined('BPML_DEBUG') || !BPML_DEBUG) {
|
||||
return '';
|
||||
}
|
||||
|
||||
echo '<div id="bpml-debug"><h2>BPML Debug</h2>';
|
||||
$messages = bpml_debug('get');
|
||||
foreach ($messages as $message) {
|
||||
echo bpml_message($message['message'], $message['class']);
|
||||
}
|
||||
global $bp, $bpml;
|
||||
|
||||
var_dump($bpml);
|
||||
|
||||
echo '<pre>';
|
||||
echo '
|
||||
BPML Settings
|
||||
';
|
||||
var_dump($bpml);
|
||||
echo '
|
||||
|
||||
BuddyPress ';
|
||||
print_r($bp);
|
||||
echo '</pre></div>';
|
||||
|
||||
}
|
||||
@ -1,220 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Google translation functions
|
||||
* @todo Auto detect
|
||||
* @todo Check activity loop and google translate button
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sets AJAX indicator.
|
||||
*
|
||||
* @global boolean $bpml_google_translate_ajax
|
||||
*/
|
||||
function bpml_google_translate_indicate_ajax() {
|
||||
global $bpml_google_translate_ajax;
|
||||
$bpml_google_translate_ajax = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Google translated contents.
|
||||
*
|
||||
* @param <type> $result
|
||||
* @param <type> $default_language
|
||||
* @param <type> $current_language
|
||||
* @param <type> $options
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_google_translate_activity_filter($result, $default_language,
|
||||
$current_language, $type_options) {
|
||||
|
||||
$to_translate_title = FALSE;
|
||||
$to_translate_content = FALSE;
|
||||
|
||||
if ((!empty($result->lang_recorded))) {
|
||||
if ($result->lang_recorded != $current_language && $type_options['translate_title']) {
|
||||
$to_translate_title = TRUE;
|
||||
}
|
||||
} else if ($result->lang != $current_language && $type_options['translate_title']) {
|
||||
$to_translate_title = TRUE;
|
||||
}
|
||||
|
||||
if ($result->lang != $current_language && !empty($result->content) && $type_options['translate_content']) {
|
||||
$to_translate_content = TRUE;
|
||||
}
|
||||
|
||||
// Apply display filters
|
||||
$result->action = apply_filters('bp_get_activity_action', $result->action);
|
||||
if (!empty($result->content)) {
|
||||
$result->content = apply_filters('bp_get_activity_content_body', $result->content);
|
||||
}
|
||||
|
||||
global $bpml;
|
||||
// Stored in DB
|
||||
if ($bpml['activities']['enable_google_translation'] === 'store') {
|
||||
// Store original values
|
||||
$original_translation_title = $result->action;
|
||||
$original_translation_content = $result->content;
|
||||
// Check if cached
|
||||
$translation = bp_activity_get_meta($result->id, 'bpml_google_translation');
|
||||
|
||||
// Translate title
|
||||
if ($to_translate_title && $type_options['translate_title_cache']) {
|
||||
if (empty($translation) || !isset($translation[$current_language]) || !isset($translation[$current_language]['title'])) {
|
||||
bpml_debug('<p>Fetched Google translation for activity title ID:' . $result->id . ' (original lang \'' . $result->lang . '\', current lang \'' . $current_language . '\')</p>');
|
||||
// Translate with Google
|
||||
if (!empty($result->lang_recorded)) {
|
||||
$translation_title = bpml_google_translate($result->action, $result->lang_recorded, $current_language);
|
||||
} else {
|
||||
$translation_title = bpml_google_translate($result->action, $result->lang, $current_language);
|
||||
}
|
||||
$translation[$current_language]['title'] = $translation_title;
|
||||
// Set cache
|
||||
bp_activity_update_meta($result->id, 'bpml_google_translation', $translation);
|
||||
} else {
|
||||
bpml_debug('<p>Cached Google translation for activity title ID:' . $result->id . ' (original lang \'' . $result->lang . '\', current lang \'' . $current_language . '\')</p>');
|
||||
$translation_title = $translation[$current_language]['title'];
|
||||
}
|
||||
} else if ($to_translate_title) {
|
||||
if (!empty($result->lang_recorded)) {
|
||||
$translation_title = bpml_google_translate($result->action, $result->lang_recorded, $current_language);
|
||||
} else {
|
||||
$translation_title = bpml_google_translate($result->action, $result->lang, $current_language);
|
||||
}
|
||||
}
|
||||
|
||||
// Translate content
|
||||
if ($to_translate_content && $type_options['translate_content_cache']) {
|
||||
if (empty($translation) || !isset($translation[$current_language]) || !isset($translation[$current_language]['content'])) {
|
||||
bpml_debug('<p>Fetched Google translation for activity content ID:' . $result->id . ' (original lang \'' . $result->lang . '\', current lang \'' . $current_language . '\')</p>');
|
||||
// Translate with Google
|
||||
$translation_content = bpml_google_translate($result->content, $result->lang, $current_language);
|
||||
$translation[$current_language]['content'] = $translation_content;
|
||||
// Set cache
|
||||
bp_activity_update_meta($result->id, 'bpml_google_translation', $translation);
|
||||
} else {
|
||||
bpml_debug('<p>Cached Google translation for activity content ID:' . $result->id . ' (original lang \'' . $result->lang . '\', current lang \'' . $current_language . '\')</p>');
|
||||
$translation_content = $translation[$current_language]['content'];
|
||||
}
|
||||
} else if ($to_translate_content) {
|
||||
$translation_content = bpml_google_translate($result->content, $result->lang, $current_language);
|
||||
}
|
||||
|
||||
// Wrap contents
|
||||
if ($to_translate_title) {
|
||||
$result->action = '<div class="bpml-translation-original-toggle bpml-translation-original-toggle-title bpml-translation-original-toggle-lang-' . $result->lang . '"><a href="#">' . __('Translation', 'bpml') . '</a></div><div class="bpml-translation-original-wrapper bpml-translation-original-wrapper-title">' . $original_translation_title . '</div>' . $translation_title;
|
||||
}
|
||||
if ($to_translate_content) {
|
||||
$result->content = '<div class="bpml-translation-original-toggle bpml-translation-original-toggle-content bpml-translation-original-toggle-lang-' . $result->lang . '"><a href="#">' . __('Translation', 'bpml') . '</a></div><div class="bpml-translation-original-wrapper bpml-translation-original-wrapper-content">' . $original_translation_content . '</div>' . $translation_content;
|
||||
}
|
||||
} else if ($bpml['activities']['enable_google_translation'] === 'js') {
|
||||
|
||||
// Translate with JS (wrap contents)
|
||||
|
||||
if ($to_translate_title) {
|
||||
if (!empty($result->lang_recorded)) {
|
||||
$result->action = bpml_google_translate_wrap($result->action, $result->lang_recorded);
|
||||
} else {
|
||||
$result->action = bpml_google_translate_wrap($result->action, $result->lang);
|
||||
}
|
||||
}
|
||||
if ($to_translate_content) {
|
||||
$result->content = bpml_google_translate_wrap($result->content, $result->lang);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates strings using Google Translate.
|
||||
*
|
||||
* @staticvar string $client
|
||||
* @param <type> $item
|
||||
* @param <type> $current_language
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_google_translate($content, $from_language, $to_language) {
|
||||
static $client = NULL;
|
||||
if (is_null($client)) {
|
||||
$client = new WP_Http();
|
||||
}
|
||||
$gtranslateurl = 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=%s&langpair=%s|%s';
|
||||
$url = sprintf($gtranslateurl, urlencode($content), $from_language, $to_language);
|
||||
$url = str_replace('|', '%7C', $url);
|
||||
$response = $client->request($url);
|
||||
if (!is_wp_error($response) && $response['response']['code'] == '200' && $response['response']['code'] == '403') {
|
||||
$translation = json_decode($response['body']);
|
||||
|
||||
$content = $translation->responseData->translatedText;
|
||||
} else {
|
||||
$content = null;
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders Google translate control button.
|
||||
*
|
||||
* Only rendered once per page.
|
||||
*
|
||||
* @global <type> $bpml_google_translate_js
|
||||
* @staticvar boolean $called
|
||||
* @param string $output
|
||||
* @return string
|
||||
*/
|
||||
function bpml_google_translate_button($output = '') {
|
||||
global $bpml_google_translate_js, $bpml_in_activity_loop;
|
||||
// if (empty($bpml_in_activity_loop)) {
|
||||
// return '';
|
||||
// }
|
||||
static $called = FALSE;
|
||||
if ($called) {
|
||||
return '';
|
||||
}
|
||||
$called = TRUE;
|
||||
if (!empty($bpml_google_translate_js)) {
|
||||
$output .= '<div id="bpml_google_sectional_element"></div>' . bpml_google_translate_js();
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps content in divs found by Google translate.
|
||||
*
|
||||
* @global boolean $bpml_google_translate_js
|
||||
* Sets flag that translate button is needed
|
||||
* @param <type> $content
|
||||
* @param <type> $lang
|
||||
* @param <type> $element
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_google_translate_wrap($content, $lang, $element = 'div') {
|
||||
global $bpml_google_translate_js, $bpml_google_translate_ajax;
|
||||
$suffix = !empty($bpml_google_translate_ajax) ? '-ajax' : '';
|
||||
$bpml_google_translate_js = TRUE;
|
||||
return '<div class="bpml-goog-trans-section' . $suffix . '" lang="' . $lang . '"><div class="bpml-goog-trans-control' . $suffix . '"></div>' . $content . '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns JS needed for Google translate.
|
||||
*
|
||||
* @param string $lang
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_google_translate_js($lang = NULL) {
|
||||
if (is_null($lang)) {
|
||||
$lang = ICL_LANGUAGE_CODE;
|
||||
}
|
||||
global $bpml_google_translate_ajax;
|
||||
$suffix = !empty($bpml_google_translate_ajax) ? '-ajax' : '';
|
||||
return '<script type=\'text/javascript\'>
|
||||
function googleSectionalElementInit() {
|
||||
new google.translate.SectionalElement({
|
||||
sectionalNodeClassName: "bpml-goog-trans-section' . $suffix . '",
|
||||
controlNodeClassName: "bpml-goog-trans-control' . $suffix . '",
|
||||
background: "#ffffcc"
|
||||
}, "bpml_google_sectional_element");
|
||||
}
|
||||
</script>
|
||||
<script src="http://translate.google.com/translate_a/element.js?cb=googleSectionalElementInit&ug=section&hl=' . $lang . '"></script>';
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Code in progress/test
|
||||
*/
|
||||
/*
|
||||
* TODOS
|
||||
* - translation for group title
|
||||
* - translation for group description
|
||||
*
|
||||
*/
|
||||
|
||||
if ($options['groups']['translate_name']) {
|
||||
add_filter('bp_get_group_name', 'bpml_bp_get_group_name_filter', 9999);
|
||||
}
|
||||
if ($options['groups']['translate_description']) {
|
||||
add_filter('bp_get_group_description', 'bpml_bp_get_group_description_filter', 9999);
|
||||
// add_filter('bp_get_group_description_excerpt', 'bpml_bp_get_group_description_filter', 9999);
|
||||
}
|
||||
|
||||
// Groups
|
||||
|
||||
add_filter('bpml_default_settings', 'bpml_groups_default_settings');
|
||||
|
||||
function bpml_groups_default_settings() {
|
||||
return array('groups' => array(
|
||||
'filter' => 0,
|
||||
'display_orphans' => 'all',
|
||||
'orphans_fix' => 0,
|
||||
'translate_name' => 0,
|
||||
'translate_description' => 0,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
function bpml_bp_get_group_name_filter($name) {
|
||||
global $bp, $sitepress;
|
||||
$default_language = $sitepress->get_default_language();
|
||||
$original_language = groups_get_groupmeta($bp->groups->current_group->id, 'bpml_lang');
|
||||
if ($original_language == ICL_LANGUAGE_CODE) {
|
||||
return $name;
|
||||
}
|
||||
$options = bpml_settings();
|
||||
if ($options['groups']['translate_name'] === 'google_translate_store') {
|
||||
$translations = groups_get_groupmeta($bp->groups->current_group->id, 'bpml_google_translation');
|
||||
if (!isset($translations[ICL_LANGUAGE_CODE])) {
|
||||
bpml_google_translate_wrap($name);
|
||||
}
|
||||
} else if ($options['groups']['translate_name'] === 'google_translate_js') {
|
||||
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
@ -1,197 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Profile functions
|
||||
* @todo delete field hook NO HOOK
|
||||
*/
|
||||
|
||||
/**
|
||||
* Init hook.
|
||||
*/
|
||||
function bpml_profiles_init() {}
|
||||
|
||||
/**
|
||||
* Adds translation options on 'Edit Profile' page.
|
||||
*
|
||||
* @global <type> $bp
|
||||
* @global <type> $bpml
|
||||
* @global <type> $sitepress
|
||||
* @global boolean $bpml_profiles_field_value_suppress_filter
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_profiles_bp_after_profile_edit_content_hook() {
|
||||
global $bp, $bpml, $sitepress, $bpml_profiles_field_value_suppress_filter;
|
||||
$bpml_profiles_field_value_suppress_filter = TRUE;
|
||||
require_once dirname(__FILE__) . '/google-translate.php';
|
||||
$default_language = $sitepress->get_default_language();
|
||||
$langs = $sitepress->get_active_languages();
|
||||
$group = BP_XProfile_Group::get(array(
|
||||
'fetch_fields' => true,
|
||||
'profile_group_id' => $bp->action_variables[1],
|
||||
'fetch_field_data' => true
|
||||
));
|
||||
echo '<a name="bpml-translate-fields"> </a><br /><h4>Translate fields</h4>';
|
||||
foreach ($group[0]->fields as $field) {
|
||||
if (!isset($bpml['profiles']['fields'][$field->id]) || empty($field->data->value)) {
|
||||
continue;
|
||||
}
|
||||
echo '<div><a href="javascript:void(0);" onclick="jQuery(this).next(\'div\').toggle();">' . $field->name . '</a><div style="display:none;">';
|
||||
foreach ($langs as $lang) {
|
||||
if ($lang['code'] == $default_language) {
|
||||
continue;
|
||||
}
|
||||
echo '<input class="bpml-profiles-field-toggle-button" type="button" onclick="jQuery(\'#bpml-profiles-form-field-' . $field->id . '-' . $lang['code'] . '\').toggle();" value="' . $lang['english_name'] . '" />';
|
||||
echo '<form style="display:none;margin:0;" id="bpml-profiles-form-field-' . $field->id . '-' . $lang['code'] . '" class="bpml-form-ajax standard-form" method="post" action="' . admin_url('admin-ajax.php') . '">';
|
||||
echo $field->type == 'textarea' ? '<textarea class="bpml-profiles-field-content" name="content" cols="40" rows="5">' . apply_filters('bp_get_the_profile_field_edit_value', bpml_profiles_get_field_translation($field->id, $lang['code'], $field->data->value)) . '</textarea>' : '<input type="text" class="bpml-profiles-field-content" name="content" value="' . apply_filters('bp_get_the_profile_field_edit_value', bpml_profiles_get_field_translation($field->id, $lang['code'], $field->data->value)) . '" />';
|
||||
echo '
|
||||
<br />
|
||||
<input type="hidden" value="' . $field->id . '" name="bpml_profiles_translate_field" />
|
||||
<input type="hidden" value="' . $lang['code'] . '" name="bpml_profiles_translate_field_lang" />
|
||||
<input type="hidden" name="dummy" class="bpml_profiles_translate_field_google_translated" value="' . bpml_google_translate(apply_filters('bp_get_the_profile_field_edit_value', $field->data->value), $default_language, $lang['code']) . '" />
|
||||
<input type="submit" value="Save translation" name="bpml_profiles_translate_field" />
|
||||
<input type="submit" value="Get translation from Google" name="bpml_profiles_translate_with_google" class="bpml_profiles_translate_with_google" />
|
||||
<div class="bmp-ajax-update"></div>
|
||||
</form><br />';
|
||||
}
|
||||
echo '</div></div>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes AJAX call for updating field translation.
|
||||
*
|
||||
* @global <type> $current_user
|
||||
*/
|
||||
function bpml_profiles_ajax() {
|
||||
if (isset($_POST['bpml_profiles_translate_field']) && is_user_logged_in()) {
|
||||
global $current_user;
|
||||
$field_id = $_POST['bpml_profiles_translate_field'];
|
||||
$lang = $_POST['bpml_profiles_translate_field_lang'];
|
||||
bpml_profile_update_translation($current_user->ID, $field_id, $lang, $_POST['content']);
|
||||
echo json_encode(array('output' => 'Done'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates field translation.
|
||||
*
|
||||
* @global $wpdb $wpdb
|
||||
* @param <type> $user_id
|
||||
* @param <type> $field_id
|
||||
* @param <type> $lang
|
||||
* @param <type> $content
|
||||
*/
|
||||
function bpml_profile_update_translation($user_id, $field_id, $lang, $content) {
|
||||
global $wpdb;
|
||||
$exists = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->prefix}bp_xprofile_data_bpml WHERE field_id=%d AND user_id=%d AND lang=%s", $field_id, $user_id, $lang));
|
||||
|
||||
if (empty($exists)) {
|
||||
$wpdb->insert($wpdb->prefix . 'bp_xprofile_data_bpml', array(
|
||||
'field_id' => $field_id,
|
||||
'user_id' => $user_id,
|
||||
'lang' => $lang,
|
||||
'value' => $content,
|
||||
), array('%d', '%d', '%s', '%s'));
|
||||
} else {
|
||||
$wpdb->update($wpdb->prefix . 'bp_xprofile_data_bpml', array(
|
||||
'value' => $_POST['content']
|
||||
), array(
|
||||
'user_id' => $user_id,
|
||||
'field_id' => $field_id,
|
||||
'lang' => $lang),
|
||||
array('%s'),
|
||||
array('%d', '%d', '%s'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches field translation.
|
||||
*
|
||||
* @global $wpdb $wpdb
|
||||
* @global $bpml
|
||||
* @global $sitepress
|
||||
* @global boolean $bpml_profiles_field_value_suppress_filter
|
||||
* @param <type> $field_id
|
||||
* @param <type> $lang
|
||||
* @param <type> $value
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_profiles_get_field_translation($field_id, $lang, $value = '') {
|
||||
global $wpdb, $bpml, $sitepress, $bpml_profiles_field_value_suppress_filter;
|
||||
if ($sitepress->get_default_language() == $lang) {
|
||||
return $value;
|
||||
}
|
||||
$translation = apply_filters('bp_get_the_profile_field_edit_value', $wpdb->get_var($wpdb->prepare("SELECT value FROM {$wpdb->prefix}bp_xprofile_data_bpml WHERE field_id=%d and lang=%s", $field_id, $lang)));
|
||||
if (empty($translation)) {
|
||||
bpml_debug('Missing tranlsation for field: ' . $field_id);
|
||||
if ($bpml['profiles']['translation']['user-missing'] && empty($bpml_profiles_field_value_suppress_filter)) {
|
||||
require_once dirname(__FILE__) . '/google-translate.php';
|
||||
$value = bpml_google_translate(apply_filters('bp_get_the_profile_field_edit_value', $value), $sitepress->get_default_language(), $lang);
|
||||
bpml_debug('Fetching Google translation for field: ' . $field_id);
|
||||
}
|
||||
return $value;
|
||||
} else {
|
||||
return $translation;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Profilae field value filter.
|
||||
*
|
||||
* @global $sitepress
|
||||
* @global $bpml
|
||||
* @global boolean $bpml_profiles_field_value_suppress_filter
|
||||
* @param <type> $value
|
||||
* @param <type> $type
|
||||
* @param <type> $field_id
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_profiles_bp_get_the_profile_field_value_filter($value, $type,
|
||||
$field_id) {
|
||||
global $sitepress, $bpml, $bpml_profiles_field_value_suppress_filter;
|
||||
if (!empty($bpml_profiles_field_value_suppress_filter)) {
|
||||
return $value;
|
||||
}
|
||||
if (!isset($bpml['profiles']['fields'][$field_id])) {
|
||||
return $value;
|
||||
}
|
||||
$lang = $sitepress->get_current_language();
|
||||
$value = bpml_profiles_get_field_translation($field_id, $lang, $value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notices user about changed fields.
|
||||
*
|
||||
* @param <type> $field
|
||||
*/
|
||||
function bpml_xprofile_data_before_save_hook($field) {
|
||||
bpml_store_frontend_notice('profile-field-updated', '<a href="#bpml-translate-fields">Check if fields need translation updated.</a>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates field names.
|
||||
*
|
||||
* @global $sitepress
|
||||
* @global <type> $field
|
||||
* @staticvar array $cache
|
||||
* @param <type> $name
|
||||
* @return array
|
||||
*/
|
||||
function bpml_bp_get_the_profile_field_name_filter($name) {
|
||||
global $sitepress, $field;
|
||||
if ($sitepress->get_default_language() == ICL_LANGUAGE_CODE) {
|
||||
return $name;
|
||||
}
|
||||
static $cache = NULL;
|
||||
if (is_null($cache)) {
|
||||
$cache = get_option('bpml_profile_fileds_names', array());
|
||||
}
|
||||
if (isset($cache[$field->id][ICL_LANGUAGE_CODE])) {
|
||||
return $cache[$field->id][ICL_LANGUAGE_CODE];
|
||||
}
|
||||
require_once dirname(__FILE__) . '/google-translate.php';
|
||||
$name = bpml_google_translate($name, $sitepress->get_default_language(), ICL_LANGUAGE_CODE);
|
||||
$cache[$field->id][ICL_LANGUAGE_CODE] = $name;
|
||||
update_option('bpml_profile_fileds_names', $cache);
|
||||
return $name;
|
||||
}
|
||||
@ -1,101 +0,0 @@
|
||||
=== Plugin Name ===
|
||||
Contributors: icanlocalize, jozik
|
||||
Donate link: http://wpml.org/documentation/related-projects/buddypress-multilingual/
|
||||
Tags: i18n, translation, localization, language, multilingual, WPML, BuddyPress
|
||||
Requires at least: 3.0
|
||||
Tested up to: 3.3.1
|
||||
Stable tag: 1.3.0
|
||||
|
||||
BuddyPress Multilingual allows BuddyPress sites to run fully multilingual using the WPML plugin.
|
||||
|
||||
== Description ==
|
||||
|
||||
The plugin allows building multilingual BuddyPress sites. It works with single-site or multi-site BuddyPress installs. Both the main site and child blogs can run multilingual.
|
||||
|
||||
Guest blogs can choose their language and create multilingual contents. Additionally, each guest can choose the admin language individually.
|
||||
|
||||
This plugin requires [WPML](http://wpml.org/). It uses WPML's language API and hooks to BuddyPress to make it multilingual.
|
||||
|
||||
Requirements:
|
||||
|
||||
* WPML 2.4.2 or higher. You must enable 'languages per directories'.
|
||||
* Supports BuddyPress versions up to 1.5.x
|
||||
|
||||
= Features =
|
||||
|
||||
* Enables multilingual BuddyPress components
|
||||
* Filters all links to maintain right language selection
|
||||
* Records language and allows Google translation for BuddyPress activity component
|
||||
* Allows translation control for each type of activity
|
||||
|
||||
= New! Customize BuddyPress further using Types and Views =
|
||||
|
||||
BPML is now compatible with [Types - The Custom Types and Custom Fields Plugin](http://wp-types.com/home/types-manage-post-types-taxonomy-and-custom-fields/) and [Views - The Custom Content Display Plugin](http://wp-types.com/). Types and Views allow you to customize BuddyPress futher by controlling custom content and displaying it any way you choose.
|
||||
|
||||
= Need Support? =
|
||||
|
||||
Please submit support requests to **[WPML forum](http://forum.wpml.org)**. Remember to report:
|
||||
|
||||
* The versions of BuddyPress, WPML and WordPress that you're using.
|
||||
* A URL to your site, where we can see the problem happening.
|
||||
* A description of what you expect to see and what you're seeing in practice.
|
||||
|
||||
== Installation ==
|
||||
|
||||
1. Unzip and upload contents of sitepress-bp.zip file to the `/wp-content/plugins/` directory.
|
||||
2. Activate the plugin through the Network 'Plugins' menu in WordPress (only available as 'Network' plugin).
|
||||
3. Enable WPML (can be enabled before this BuddyPress Multilingual).
|
||||
4. To set preferences go to Settings/BuddyPress Multilingual on main blog.
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= Why do I need to enable languages per directories? =
|
||||
|
||||
BuddyPress itself uses virtual directories for its elements. The only way we managed to add language information is by adding a language prefix to paths.
|
||||
|
||||
For example, /fr/members/ to the French members list.
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. Multilingual main BuddyPress page.
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.3.0 =
|
||||
* Support BP 1.5.x
|
||||
* Language selector doesn't appear on the home page when a page is selected as the front page
|
||||
* Pages widget exclude function doesn't work in the right way
|
||||
* Small fix on main navigation menu
|
||||
|
||||
= 1.2.1 =
|
||||
* Supports BP 1.2
|
||||
|
||||
= 1.1.0 =
|
||||
* Added translation support for XProfile fields
|
||||
|
||||
= 1.0.1 =
|
||||
* Supports BuddyPress 1.2.8 and WP Network mode
|
||||
* Added Google translation and translation control for BuddyPress activities
|
||||
|
||||
= 1.0.0 =
|
||||
* Supports BuddyPress 1.2
|
||||
|
||||
= 0.9.2 =
|
||||
* Bugfixes
|
||||
|
||||
= 0.9.1 =
|
||||
* Bugfixes
|
||||
|
||||
= 0.9 =
|
||||
* First public release. Supports BuddyPress 1.0
|
||||
|
||||
= 0.1.0 =
|
||||
* Developers version, not recommended for production sites - feedback welcome!
|
||||
|
||||
== Upgrade Notice ==
|
||||
|
||||
= 1.1.0 =
|
||||
* Runs on BuddyPress 1.2.8
|
||||
|
||||
= 1.3.0 =
|
||||
* Runs with BuddyPress 1.5.x
|
||||
|
Before Width: | Height: | Size: 23 KiB |
@ -1,92 +0,0 @@
|
||||
|
||||
jQuery(document).ready(function() {
|
||||
jQuery('.bpml-translation-original-toggle a').click(function(){
|
||||
jQuery(this).parent().next().toggle();
|
||||
return false;
|
||||
});
|
||||
bpmlAdminToggleCollectedActivities();
|
||||
jQuery('.bpml-show-collected-activities').click(function(){
|
||||
if (jQuery(this).val() == 'store') {
|
||||
jQuery('.bpml-activities-hide-cache-option, .bpml-activities-hide-titlecontent-option').fadeIn();
|
||||
} else {
|
||||
jQuery('.bpml-activities-hide-cache-option').fadeOut();
|
||||
jQuery('.bpml-activities-hide-titlecontent-option').fadeIn();
|
||||
}
|
||||
});
|
||||
jQuery('.bpml-hide-collected-activities').click(function(){
|
||||
jQuery('.bpml-activities-hide-cache-option, .bpml-activities-hide-titlecontent-option').fadeOut();
|
||||
});
|
||||
jQuery('#bpml-activities-select-all').click(function(){
|
||||
jQuery('#bpml-collected-activities input').attr('checked', 1);
|
||||
jQuery('#bpml-collected-activities select').val(-1);
|
||||
});
|
||||
jQuery('#bpml-activities-clear-all').click(function(){
|
||||
jQuery('#bpml-collected-activities input').attr('checked', 0);
|
||||
jQuery('#bpml-collected-activities select').val(0);
|
||||
});
|
||||
jQuery('.bpml-activity-assign-language').live('submit', function(){
|
||||
var form = jQuery(this);
|
||||
jQuery.ajax({
|
||||
url: jQuery(this).attr('action'),
|
||||
type: 'post',
|
||||
data: jQuery(this).serialize(jQuery(this))+'&action=bpml_ajax',
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
beforeSend: function(){
|
||||
form.children('.bmp-ajax-update').html('Processing...').show();
|
||||
},
|
||||
success: function(data){
|
||||
if (data.output != 'undefined') {
|
||||
form.children('.bmp-ajax-update').html(data.output).delay(2000).fadeOut();
|
||||
} else if (data.error != 'undefined') {
|
||||
form.children('.bmp-ajax-update').html(data.error).delay(2000).fadeOut();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
jQuery('.bpml-form-ajax').live('submit', function(){
|
||||
var form = jQuery(this);
|
||||
jQuery.ajax({
|
||||
url: jQuery(this).attr('action'),
|
||||
type: 'post',
|
||||
data: jQuery(this).serialize(jQuery(this))+'&action=bpml_ajax',
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
beforeSend: function(){
|
||||
form.children('.bmp-ajax-update').html('Processing...').show();
|
||||
},
|
||||
success: function(data){
|
||||
if (data.output != 'undefined') {
|
||||
form.children('.bmp-ajax-update').html(data.output).delay(2000).fadeOut();
|
||||
} else if (data.error != 'undefined') {
|
||||
form.children('.bmp-ajax-update').html(data.error).delay(2000).fadeOut();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
jQuery('.bpml_profiles_translate_with_google').click(function() {
|
||||
jQuery(this).parent().find('textarea').val(jQuery(this).parent().find('.bpml_profiles_translate_field_google_translated').val());
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
function bpmlAdminToggleCollectedActivities() {
|
||||
var val = jQuery("input:radio[name='bpml[activities][enable_google_translation]']:checked").val();
|
||||
if (val != 0) {
|
||||
if (val == 'store') {
|
||||
jQuery('.bpml-activities-hide-cache-option, .bpml-activities-hide-titlecontent-option').show();
|
||||
} else {
|
||||
jQuery('.bpml-activities-hide-cache-option').hide();
|
||||
jQuery('.bpml-activities-hide-titlecontent-option').show();
|
||||
}
|
||||
} else {
|
||||
jQuery('.bpml-activities-hide-cache-option, .bpml-activities-hide-titlecontent-option').hide();
|
||||
}
|
||||
jQuery('#bpml-collected-activities').slideDown();
|
||||
}
|
||||
@ -1,567 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: BuddyPress Multilingual
|
||||
Plugin URI: http://wpml.org/?page_id=2890
|
||||
Description: BuddyPress Multilingual. <a href="http://wpml.org/?page_id=2890">Documentation</a>.
|
||||
Author: OnTheGoSystems
|
||||
Author URI: http://www.onthegosystems.com
|
||||
Version: 1.3.0
|
||||
Network: true
|
||||
*/
|
||||
|
||||
/*
|
||||
BuddyPress Multilingual is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
BuddyPress Multilingual is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with BuddyPress Multilingual. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define constants
|
||||
*/
|
||||
define('BPML_VERSION', '1.3.0');
|
||||
define('BPML_PLUGIN_URL', plugins_url(basename(dirname(__FILE__))));
|
||||
|
||||
add_action('plugins_loaded', 'bpml_plugins_loaded_hook', 0);
|
||||
add_action('plugins_loaded', 'bpml_init_check', 11);
|
||||
|
||||
/**
|
||||
* Trigger this before anything.
|
||||
*
|
||||
* Force getting cookie language on:
|
||||
* Search
|
||||
* AJAX call
|
||||
*/
|
||||
function bpml_plugins_loaded_hook() {
|
||||
if (defined('BP_VERSION') && defined('ICL_SITEPRESS_VERSION')) {
|
||||
if (!is_admin() && (isset($_POST['search-terms']) || isset($_REQUEST['action'])
|
||||
|| (defined('DOING_AJAX') && DOING_AJAX))) {
|
||||
add_filter('icl_set_current_language', 'bpml_get_cookie_lang');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns WPML cookie.
|
||||
*
|
||||
* @global $sitepress
|
||||
* @param <type> $lang
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_get_cookie_lang($lang = '') {
|
||||
global $sitepress;
|
||||
$lang_cookie = $sitepress->get_language_cookie();
|
||||
if (empty($lang_cookie)) {
|
||||
return empty($lang) ? ICL_LANGUAGE_CODE : $lang;
|
||||
}
|
||||
return $lang_cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if necessary conditions are met.
|
||||
*
|
||||
* @global <type> $sitepress_settings
|
||||
*/
|
||||
function bpml_init_check() {
|
||||
global $sitepress_settings;
|
||||
if (defined('BP_VERSION') && defined('ICL_SITEPRESS_VERSION')) {
|
||||
if ((!isset($sitepress_settings['language_negotiation_type'])
|
||||
|| $sitepress_settings['language_negotiation_type'] != 1)
|
||||
&& is_main_site()) {
|
||||
bpml_admin_message('<p>' . __('For BuddyPress Multilingual to work you must set WPML language negotiation to "languages in different directories".') . '</p>');
|
||||
} else {
|
||||
|
||||
global $bpml;
|
||||
$bpml = bpml_get_settings();
|
||||
define('BPML_DEBUG', bpml_get_setting('debug', 0));
|
||||
|
||||
// Site wide
|
||||
include_once dirname(__FILE__) . '/activities.php';
|
||||
add_action('bp_activity_after_save', 'bpml_activities_bp_activity_after_save_hook');
|
||||
add_action('bp_activity_before_save', 'bpml_activities_bp_activity_before_save_hook');
|
||||
|
||||
// Main blog
|
||||
if (is_main_site ()) {
|
||||
// Profiles
|
||||
if (isset($bpml['profiles']) && $bpml['profiles']['translation'] != 'no') {
|
||||
require_once dirname(__FILE__) . '/profiles.php';
|
||||
if (!is_admin() && isset($bpml['profiles']['translate_fields_title'])) {
|
||||
add_filter('bp_get_the_profile_field_name', 'bpml_bp_get_the_profile_field_name_filter');
|
||||
}
|
||||
add_action('xprofile_data_before_save', 'bpml_xprofile_data_before_save_hook');
|
||||
add_action('init', 'bpml_profiles_init');
|
||||
add_action('bp_after_profile_edit_content', 'bpml_profiles_bp_after_profile_edit_content_hook');
|
||||
add_action('bpml_ajax', 'bpml_profiles_ajax');
|
||||
add_filter('bp_get_the_profile_field_value', 'bpml_profiles_bp_get_the_profile_field_value_filter', 0, 3);
|
||||
}
|
||||
|
||||
if (!is_admin()) {
|
||||
require_once dirname(__FILE__) . '/frontend.php';
|
||||
add_action('wp_head', 'bpml_wp_head_hook');
|
||||
add_action('wp_footer', 'bpml_wp_footer', 9999);
|
||||
add_action('wp', 'bpml_blogs_redirect_to_random_blog', 0);
|
||||
add_action('bp_before_activity_loop', 'bpml_activities_bp_before_activity_loop_hook');
|
||||
add_action('bp_core_render_message', 'bpml_show_frontend_notices');
|
||||
|
||||
// Filter site_url on regular pages
|
||||
add_action('bp_before_header', 'bpml_bp_before_header_hook');
|
||||
add_action('bp_after_footer', 'bpml_bp_after_footer_hook');
|
||||
|
||||
// Force filtering site_url on:
|
||||
// Search
|
||||
// AJAX call
|
||||
if (isset($_POST['search-terms']) || isset($_REQUEST['action']) || (defined('DOING_AJAX') && DOING_AJAX)) {
|
||||
add_filter('site_url', 'bpml_site_url_filter', 0);
|
||||
}
|
||||
|
||||
// Filters main navigation menu
|
||||
if(version_compare(BP_VERSION, '1.2.9') >= 0){
|
||||
add_filter( 'wp_list_pages', 'nav_menu_filter' );
|
||||
}
|
||||
|
||||
add_filter('admin_url', 'bpml_admin_url_filter', 0, 3);
|
||||
add_filter('bp_core_get_root_domain', 'bpml_bp_core_get_root_domain_filter', 0);
|
||||
add_filter('bp_uri', 'bpml_bp_uri_filter', 0);
|
||||
add_filter('icl_ls_languages', 'bpml_icl_ls_languages_filter');
|
||||
add_filter('bp_activity_get', 'bpml_activities_bp_activity_get_filter', 10, 2);
|
||||
add_filter('bp_activity_get_specific', 'bpml_activities_bp_activity_get_filter', 10, 2);
|
||||
add_filter('bp_get_activity_latest_update', 'bpml_bp_get_activity_latest_update_filter');
|
||||
|
||||
if ($bpml['activities']['show_activity_switcher']) {
|
||||
add_action('bp_before_activity_entry', 'bpml_activities_assign_language_dropdown');
|
||||
}
|
||||
|
||||
if ($bpml['activities']['enable_google_translation']) {
|
||||
require_once dirname(__FILE__) . '/google-translate.php';
|
||||
add_filter('bpml_activity_filter', 'bpml_google_translate_activity_filter', 10, 5);
|
||||
add_action('wp_ajax_activity_widget_filter', 'bpml_google_translate_indicate_ajax');
|
||||
add_action('wp_ajax_activity_get_older_updates', 'bpml_google_translate_indicate_ajax');
|
||||
}
|
||||
|
||||
add_action('init', 'additional_css_js');
|
||||
} else {
|
||||
require_once dirname(__FILE__) . '/admin.php';
|
||||
$version = get_option('bpml_version', FALSE);
|
||||
if (empty($version) || version_compare($version, BPML_VERSION, '<')) {
|
||||
require_once dirname(__FILE__) . '/upgrade.php';
|
||||
bpml_upgrade();
|
||||
}
|
||||
add_action('admin_init', 'bpml_admin_show_stored_admin_notices');
|
||||
add_action('admin_menu', 'bpml_admin_menu');
|
||||
if (isset($_GET['page']) && $_GET['page'] == 'bpml') {
|
||||
require_once dirname(__FILE__) . '/admin-form.php';
|
||||
add_action('bpml_settings_form_before', 'bpml_profiles_admin_form');
|
||||
add_action('admin_init', 'bpml_admin_save_settings_submit');
|
||||
add_action('admin_init', 'admin_additional_css_js');
|
||||
}
|
||||
}
|
||||
add_action('wp_ajax_bpml_ajax', 'bpml_ajax');
|
||||
add_action('bpml_ajax', 'bpml_activities_ajax');
|
||||
}
|
||||
}
|
||||
} else if (is_main_site ()) {
|
||||
bpml_admin_message('<p>' . __('For BuddyPress Multilingual to work you must enable WPML and BuddyPress.') . '</p>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds hook for CSS styles and jQuery to client-side.
|
||||
*
|
||||
*/
|
||||
function additional_css_js() {
|
||||
wp_enqueue_style('sitepress-language-switcher', ICL_PLUGIN_URL . '/res/css/language-selector.css', array(), ICL_SITEPRESS_VERSION);
|
||||
wp_enqueue_style('bpml', BPML_PLUGIN_URL . '/style.css', array(), BPML_VERSION);
|
||||
wp_enqueue_script('bpml', BPML_PLUGIN_URL . '/scripts.js', array('jquery'), BPML_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds hook for Admin CSS styles and jQuery to admin-side.
|
||||
*
|
||||
*/
|
||||
function admin_additional_css_js() {
|
||||
wp_enqueue_style('bpml', BPML_PLUGIN_URL . '/style.css', array(), BPML_VERSION);
|
||||
wp_enqueue_script('bpml', BPML_PLUGIN_URL . '/scripts.js', array('jquery'), BPML_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTML output for admin message.
|
||||
*
|
||||
* @param <type> $message
|
||||
* @param <type> $class
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_message($message, $class = 'updated', $ID = NULL) {
|
||||
$ID = is_null($ID) ? '' : ' id="' . $ID . '"';
|
||||
return '<div class="message ' . $class . '"' . $ID . '>' . $message . '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds hook for admin_notices.
|
||||
*
|
||||
* @param <type> $message
|
||||
* @param <type> $class
|
||||
*/
|
||||
function bpml_admin_message($message, $class = 'updated',
|
||||
$action = 'admin_notices') {
|
||||
add_action($action, create_function('$a=1', 'echo \'<div class="message ' . $class . '">' . $message . '</div>\';'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns default BPML settings.
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_default_settings() {
|
||||
return array(
|
||||
'debug' => 0,
|
||||
'activities' => array(
|
||||
'filter' => 0,
|
||||
'display_orphans' => 'all',
|
||||
'orphans_fix' => 0,
|
||||
'enable_google_translation' => 0,
|
||||
'show_activity_switcher' => 0,
|
||||
),
|
||||
'collected_activities' => array(
|
||||
'activity_update' => array(
|
||||
'translate_title' => 1,
|
||||
'translate_title_cache' => 1,
|
||||
'translate_content' => 1,
|
||||
'translate_content_cache' => 1,
|
||||
'translate_links' => -1
|
||||
),
|
||||
'friendship_created' => array(
|
||||
'translate_title' => 1,
|
||||
'translate_title_cache' => 1,
|
||||
'translate_content' => 1,
|
||||
'translate_content_cache' => 1,
|
||||
'translate_links' => -1
|
||||
),
|
||||
'joined_group' => array(
|
||||
'translate_title' => 1,
|
||||
'translate_title_cache' => 1,
|
||||
'translate_content' => 1,
|
||||
'translate_content_cache' => 1,
|
||||
'translate_links' => -1
|
||||
),
|
||||
'created_group' => array(
|
||||
'translate_title' => 1,
|
||||
'translate_title_cache' => 1,
|
||||
'translate_content' => 1,
|
||||
'translate_content_cache' => 1,
|
||||
'translate_links' => -1
|
||||
),
|
||||
'new_blog' => array(
|
||||
'translate_title' => 1,
|
||||
'translate_title_cache' => 1,
|
||||
'translate_content' => 1,
|
||||
'translate_content_cache' => 1,
|
||||
'translate_links' => -1
|
||||
),
|
||||
'new_blog_post' => array(
|
||||
'translate_title' => 1,
|
||||
'translate_title_cache' => 1,
|
||||
'translate_content' => 1,
|
||||
'translate_content_cache' => 1,
|
||||
'translate_links' => 1
|
||||
),
|
||||
'new_blog_comment' => array(
|
||||
'translate_title' => 1,
|
||||
'translate_title_cache' => 1,
|
||||
'translate_content' => 1,
|
||||
'translate_content_cache' => 1,
|
||||
'translate_links' => 1
|
||||
),
|
||||
'activity_comment' => array(
|
||||
'translate_title' => 1,
|
||||
'translate_title_cache' => 1,
|
||||
'translate_content' => 1,
|
||||
'translate_content_cache' => 1,
|
||||
'translate_links' => -1
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all settings.
|
||||
*
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_get_settings() {
|
||||
return apply_filters('bpml_default_settings',
|
||||
get_option('bpml', bpml_default_settings()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns specific setting.
|
||||
*
|
||||
* @global <type> $bpml
|
||||
* @param <type> $ID
|
||||
* @param <type> $default
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_get_setting($ID, $default = NULL) {
|
||||
global $bpml;
|
||||
if (isset($bpml[$ID])) {
|
||||
return $bpml[$ID];
|
||||
} else if (!is_null($default)) {
|
||||
$bpml[$ID] = $default;
|
||||
bpml_save_setting($ID, $default);
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all settings.
|
||||
*
|
||||
* @global array $bpml
|
||||
* @param <type> $data
|
||||
*/
|
||||
function bpml_save_settings($data) {
|
||||
global $bpml;
|
||||
$bpml = $data;
|
||||
update_option('bpml', $bpml);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves specific setting.
|
||||
*
|
||||
* @global array $bpml
|
||||
* @param <type> $ID
|
||||
* @param <type> $data
|
||||
*/
|
||||
function bpml_save_setting($ID, $data) {
|
||||
global $bpml;
|
||||
$bpml[$ID] = $data;
|
||||
update_option('bpml', $bpml);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes specific setting.
|
||||
*
|
||||
* @global $bpml
|
||||
* @param <type> $ID
|
||||
*/
|
||||
function bpml_delete_setting($ID) {
|
||||
global $bpml;
|
||||
if (isset($bpml[$ID])) {
|
||||
unset($bpml[$ID]);
|
||||
update_option('bpml', $bpml);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches admin notices.
|
||||
*
|
||||
* Notices are kept until BPML admin page is visited.
|
||||
*
|
||||
* @global array $bpml
|
||||
* @param <type> $ID
|
||||
* @param <type> $message
|
||||
*/
|
||||
function bpml_store_admin_notice($ID, $message) {
|
||||
global $bpml;
|
||||
$bpml['admin_notices'][$ID] = $message;
|
||||
bpml_save_setting('admin_notices', $bpml['admin_notices']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches frontend notices.
|
||||
*
|
||||
* @global array $bpml
|
||||
* @param <type> $ID
|
||||
* @param <type> $message
|
||||
*/
|
||||
function bpml_store_frontend_notice($ID, $message) {
|
||||
global $bpml;
|
||||
if (!isset($bpml['frontend_notices'])) {
|
||||
$bpml['frontend_notices'] = array();
|
||||
}
|
||||
$bpml['frontend_notices'][$ID] = $message;
|
||||
bpml_save_setting('frontend_notices', $bpml['frontend_notices']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays frontend notices.
|
||||
*
|
||||
* @global array $bpml
|
||||
* @param <type> $ID
|
||||
* @param <type> $message
|
||||
*/
|
||||
function bpml_show_frontend_notices() {
|
||||
global $bpml;
|
||||
if (empty($bpml['frontend_notices'])) {
|
||||
return '';
|
||||
}
|
||||
foreach ($bpml['frontend_notices'] as $message) {
|
||||
echo bpml_message('<p>' . $message . '</p>', 'bpml-frontend-notice');
|
||||
}
|
||||
bpml_delete_setting('frontend_notices');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches WPML language data from subblogs.
|
||||
*
|
||||
* @global <type> $wpdb
|
||||
* @param <type> $blog_id
|
||||
* @param <type> $type
|
||||
* @param <type> $element_id
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_get_wpml_language_data($blog_id, $type = 'post_post',
|
||||
$element_id = NULL, $switch_db = FALSE) {
|
||||
static $sitepress_settings = array();
|
||||
|
||||
if (isset($sitepress_settings[$blog_id][$type][$element_id])) {
|
||||
return $sitepress_settings[$blog_id][$type][$element_id];
|
||||
}
|
||||
|
||||
$result = array();
|
||||
if ($switch_db) {
|
||||
switch_to_blog($blog_id);
|
||||
}
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . 'icl_translations';
|
||||
if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
|
||||
if ($switch_db) {
|
||||
restore_current_blog();
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
if (!isset($sitepress_settings[$blog_id])) {
|
||||
$fetch = unserialize($wpdb->get_var("SELECT option_value FROM {$wpdb->prefix}options WHERE option_name='icl_sitepress_settings'"));
|
||||
$sitepress_settings[$blog_id]['default_language'] = $fetch['default_language'];
|
||||
}
|
||||
switch ($type) {
|
||||
case 'comment':
|
||||
$post_id = $wpdb->get_var("SELECT comment_post_ID FROM {$wpdb->prefix}comments WHERE comment_ID=" . $element_id);
|
||||
$post_type = 'post_' . $wpdb->get_var("SELECT post_type FROM {$wpdb->prefix}posts WHERE ID=" . $post_id);
|
||||
$result['language'] = $wpdb->get_var("SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE element_type='" . $post_type . "' AND element_id=" . $post_id);
|
||||
break;
|
||||
|
||||
default:
|
||||
$result['language'] = $wpdb->get_var("SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE element_type='" . $type . "' AND element_id=" . $element_id);
|
||||
break;
|
||||
}
|
||||
$result['default_language'] = $sitepress_settings[$blog_id]['default_language'];
|
||||
$sitepress_settings[$blog_id][$type][$element_id] = $result;
|
||||
if ($switch_db) {
|
||||
restore_current_blog();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to get language data for item.
|
||||
*
|
||||
* @global <type> $sitepress
|
||||
* @param <type> $item
|
||||
* @param <type> $type
|
||||
* @param <type> $switch_db
|
||||
* @return <type>
|
||||
*/
|
||||
function bpml_get_item_language($item = NULL, $type = 'post_post',
|
||||
$switch_db = FALSE) {
|
||||
$lang = array();
|
||||
global $sitepress;
|
||||
if ($type == 'post_post' && !empty($sitepress) && isset($_POST['icl_post_language'])) { // In moment of save if WPML is active
|
||||
$lang['language'] = $_POST['icl_post_language'];
|
||||
$lang['default_language'] = $sitepress->get_default_language();
|
||||
$lang['recorded_language'] = $sitepress->get_current_language();
|
||||
} else if (!is_null($item)) { // Check in DB
|
||||
$lang = bpml_get_wpml_language_data($item->item_id, $type, $item->secondary_item_id, $switch_db);
|
||||
if (!empty($lang)) {
|
||||
$lang['recorded_language'] = $lang['default_language'];
|
||||
}
|
||||
}
|
||||
// Try to get WPLANG
|
||||
if (empty($lang) && !empty($sitepress)) {
|
||||
$temp = get_site_option('WPLANG');
|
||||
if (!empty($temp)) {
|
||||
if (strlen($temp) > 2) {
|
||||
$temp = $wpdb->get_var("SELECT code FROM {$wpdb->prefix}icl_locale_map WHERE locale='" . $temp . "'");
|
||||
}
|
||||
$lang['default_language'] = $lang['language'] = $lang['recorded_language'] = $temp;
|
||||
}
|
||||
}
|
||||
// Try to get RSS lang
|
||||
if (empty($lang)) {
|
||||
$temp = get_site_option('rss_language');
|
||||
if (!empty($temp)) {
|
||||
$lang['default_language'] = $lang['language'] = $lang['recorded_language'] = $temp;
|
||||
}
|
||||
}
|
||||
return $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* BPML AJAX hook.
|
||||
*/
|
||||
function bpml_ajax() {
|
||||
do_action('bpml_ajax');
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Filters main navigation menu
|
||||
*
|
||||
* @global <type> $sitepress
|
||||
* @global <type> $bp
|
||||
* @global <type> $sitepress_settings
|
||||
* @param <type> $items
|
||||
* @return <type> $items
|
||||
*/
|
||||
function nav_menu_filter($items) {
|
||||
global $sitepress, $bp, $sitepress_settings;
|
||||
$default_language = $sitepress->get_default_language();
|
||||
$additionalItems = '';
|
||||
|
||||
foreach($bp->active_components as $component => $value){
|
||||
$pos = @strpos($items, $component);
|
||||
$show_menu = ($pos !== false) ? $show_menu = false : $show_menu = true;
|
||||
}
|
||||
|
||||
if(bp_is_page( BP_ACTIVITY_SLUG ) || bp_is_page( BP_MEMBERS_SLUG ) || bp_is_page( BP_GROUPS_SLUG ) || bp_is_page( BP_FORUMS_SLUG ) || bp_is_page( BP_BLOGS_SLUG ))
|
||||
$currentLang = '/' . ICL_LANGUAGE_CODE;
|
||||
else
|
||||
bp_is_user() ? $currentLang = '/' . ICL_LANGUAGE_CODE : $currentLang = '';
|
||||
|
||||
if( $show_menu ){
|
||||
$item_class = ( bp_is_page( BP_ACTIVITY_SLUG ) ) ? $activity_class = 'current_page_item' : $activity_class = '';
|
||||
$item_class = ( bp_is_page( BP_MEMBERS_SLUG ) ) || bp_is_user() ? $members_class = 'current_page_item' : $members_class = '';
|
||||
$item_class = ( bp_is_page( BP_GROUPS_SLUG ) ) || bp_is_group() ? $groups_class = 'current_page_item' : $groups_class = '';
|
||||
$item_class = ( bp_is_page( BP_FORUMS_SLUG ) ) ? $forums_class = 'current_page_item' : $forums_class = '';
|
||||
$item_class = ( bp_is_page( BP_BLOGS_SLUG ) ) ? $blogs_class = 'current_page_item' : $blogs_class = '';
|
||||
|
||||
if(!$currentLang == '') : $currentLang = $currentLang . '/'; endif;
|
||||
if($default_language == ICL_LANGUAGE_CODE) : $currentLang = $currentLang = '/'; endif;
|
||||
|
||||
if ( bp_is_active( 'activity' ) ) :
|
||||
$additionalItems .= '<li class="'. $activity_class .'"><a href="'. home_url() . $currentLang . BP_ACTIVITY_SLUG .'">' . __('Activity') . '</a></li>';
|
||||
endif;
|
||||
if ( bp_is_active( 'groups' ) ) :
|
||||
$additionalItems .= '<li class="'. $groups_class .'"><a href="'. home_url() . $currentLang . BP_GROUPS_SLUG .'">' . __('Groups') . '</a></li>';
|
||||
endif;
|
||||
$additionalItems .= '<li class="'. $members_class .'"><a href="'. home_url() . $currentLang . BP_MEMBERS_SLUG .'">' . __('Members') . '</a></li>';
|
||||
if ( bp_is_active( 'forums' ) ) :
|
||||
$additionalItems .= '<li class="'. $forums_class .'"><a href="'. home_url() . $currentLang . BP_FORUMS_SLUG .'">' . __('Forums') . '</a></li>';
|
||||
endif;
|
||||
if ( bp_is_active( 'blogs' ) && is_multisite() ) :
|
||||
$additionalItems .= '<li class="'. $blogs_class .'"><a href="'. home_url() . $currentLang . BP_BLOGS_SLUG .'">' . __('Blogs') . '</a></li>';
|
||||
endif;
|
||||
}
|
||||
|
||||
$items = $additionalItems . $items;
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
@ -1,117 +0,0 @@
|
||||
#bpml-debug {
|
||||
margin: 10px;
|
||||
}
|
||||
.bpml-debug {
|
||||
padding: 5px;
|
||||
margin: 0 0 10px 0;
|
||||
-moz-border-radius: 3px 3px 3px 3px;
|
||||
}
|
||||
.bpml-debug-updated {
|
||||
border: 1px solid #FFFFE0;
|
||||
background-color: #FFFFE0;
|
||||
color: #000000;
|
||||
}
|
||||
.bpml-debug-error {
|
||||
border: 1px solid #FFFFFF;
|
||||
background-color: #cc0000;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
#bpml_google_sectional_element {
|
||||
margin-bottom: 10px;
|
||||
border-left: 1px dotted #cccccc;
|
||||
border-bottom: 1px dotted #cccccc;
|
||||
padding: 0 15px;
|
||||
}
|
||||
/*.activity-header .bpml-goog-trans-control,*/
|
||||
/*.activity-header .bpml-goog-trans-control div,*/
|
||||
.activity-header .bpml-goog-trans-section,
|
||||
.activity-header .bpml-goog-trans-section p,
|
||||
.activity-header .bpml-goog-trans-control
|
||||
/*.activity-header .bpml-goog-trans-section div */
|
||||
{
|
||||
float: left;
|
||||
}
|
||||
.activity-inreplyto .bpml-goog-trans-section,
|
||||
.activity-inreplyto .bpml-goog-trans-section p,
|
||||
.activity-inreplyto .bpml-goog-trans-control
|
||||
{
|
||||
/* float: right;*/
|
||||
}
|
||||
.activity-inreplyto .goog-te-sectional-gadget-link-text {
|
||||
margin-right: 5px;
|
||||
}
|
||||
.bpml-translation-original-toggle-title {
|
||||
float: left;
|
||||
margin-right: 5px;
|
||||
/* font-size: 0.8em;*/
|
||||
}
|
||||
.bpml-translation-original-toggle-content {
|
||||
margin-right: 5px;
|
||||
/* font-size: 0.8em;*/
|
||||
}
|
||||
.bpml-translation-original-wrapper {
|
||||
display: none;
|
||||
}
|
||||
.bpml-translation-original-wrapper-content {
|
||||
color: #000000;
|
||||
background-color: #fbfafa;
|
||||
border: 1px solid #cccccc;
|
||||
padding: 5px 15px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.bpml-admin-form {
|
||||
background-color: #ffffff;
|
||||
border: 1px solid #cccccc;
|
||||
padding: 10px 25px;
|
||||
}
|
||||
.bpml-admin-form h4 {
|
||||
margin: 10px 0 5px 0;
|
||||
}
|
||||
#bpml-collected-activities {
|
||||
display: none;
|
||||
}
|
||||
.bpml-collected-activities-wrapper {
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #eeeeee;
|
||||
padding: 0;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.bpml-collected-activities-wrapper td {
|
||||
padding: 2px 10px;
|
||||
padding-right: 10px;
|
||||
}
|
||||
.bpml-collected-activities-wrapper tr:first-child td {
|
||||
border-bottom: 1px solid #eeeeee;
|
||||
background-color: #eeeeee;
|
||||
}
|
||||
.bpml-collected-activities-title {
|
||||
font-style: italic;
|
||||
}
|
||||
ul.item-list li.bpml-activity-assign-language-wrapper {
|
||||
border-bottom: 0px;
|
||||
}
|
||||
.bpml-activity-assign-language-wrapper form {
|
||||
margin: 0;
|
||||
}
|
||||
.bpml-profiles-field-toggle-button {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
div.bpml-frontend-notice p {
|
||||
background: none repeat scroll 0 0 #DFFCD9;
|
||||
color: #1A9B00;
|
||||
display: block;
|
||||
font-size: 12px;
|
||||
padding: 10px 15px;
|
||||
-moz-border-radius: 3px 3px 3px 3px;
|
||||
border-bottom: 1px solid #C4E9BD;
|
||||
border-right: 1px solid #C4E9BD;
|
||||
font-weight: normal;
|
||||
margin-top: 6px;
|
||||
text-decoration: none;
|
||||
}
|
||||
div.bpml-frontend-notice {
|
||||
clear: both;
|
||||
}
|
||||
div.bpml-frontend-notice {
|
||||
margin: 15px 0;
|
||||
}
|
||||
@ -1,101 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* Upgrade code
|
||||
*/
|
||||
|
||||
function bpml_upgrade() {
|
||||
$upgrade_failed = FALSE;
|
||||
$upgrade_debug = array();
|
||||
$version = get_option('bpml_version', FALSE);
|
||||
if (empty($version)) {
|
||||
$version = BPML_VERSION;
|
||||
bpml_install();
|
||||
}
|
||||
if (version_compare($version, BPML_VERSION, '<')) {
|
||||
$first_step = str_replace('.', '', $version);
|
||||
$last_step = str_replace('.', '', BPML_VERSION);
|
||||
for ($index = $first_step; $index <= $last_step; $index++) {
|
||||
if (function_exists('bpml_upgrade_' . $index)) {
|
||||
$response = call_user_func('bpml_upgrade_' . $index);
|
||||
if ($response !== TRUE) {
|
||||
$upgrade_failed = TRUE;
|
||||
$upgrade_debug[$first_step][$index] = $response;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($upgrade_failed == TRUE) {
|
||||
update_option('bpml_upgrade_debug', $upgrade_debug);
|
||||
bpml_store_admin_notice('upgrade_error', '<p>BuddyPress Multilingual: There has been problems with upgrade.</p>');
|
||||
}
|
||||
update_option('bpml_version', BPML_VERSION);
|
||||
}
|
||||
|
||||
function bpml_install() {
|
||||
global $wpdb, $bpml;
|
||||
|
||||
bpml_save_settings($bpml);
|
||||
|
||||
// Profiles
|
||||
$table_name = $wpdb->prefix . "bp_xprofile_data_bpml";
|
||||
if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
|
||||
$sql = "CREATE TABLE " . $table_name . " (
|
||||
id bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
field_id bigint(20) NOT NULL,
|
||||
user_id bigint(20) NOT NULL,
|
||||
value longtext,
|
||||
lang varchar(10) NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY field_id (field_id),
|
||||
KEY user_id (user_id),
|
||||
KEY lang (lang)
|
||||
);";
|
||||
|
||||
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
||||
dbDelta($sql);
|
||||
}
|
||||
|
||||
// For users had 1.0.1 and earlier
|
||||
bpml_upgrade_110();
|
||||
}
|
||||
|
||||
function bpml_upgrade_110() {
|
||||
global $bpml, $wpdb;
|
||||
|
||||
// New activity
|
||||
if (!isset($bpml['collected_activities']['new_blog'])) {
|
||||
$bpml['collected_activities']['new_blog'] = array(
|
||||
'translate_title' => 1,
|
||||
'translate_title_cache' => 1,
|
||||
'translate_content' => 1,
|
||||
'translate_content_cache' => 1,
|
||||
'translate_links' => -1
|
||||
);
|
||||
}
|
||||
|
||||
// Profiles
|
||||
$table_name = $wpdb->prefix . "bp_xprofile_data_bpml";
|
||||
if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
|
||||
$sql = "CREATE TABLE " . $table_name . " (
|
||||
id bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
field_id bigint(20) NOT NULL,
|
||||
user_id bigint(20) NOT NULL,
|
||||
value longtext,
|
||||
lang varchar(10) NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY field_id (field_id),
|
||||
KEY user_id (user_id),
|
||||
KEY lang (lang)
|
||||
);";
|
||||
|
||||
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
||||
dbDelta($sql);
|
||||
}
|
||||
if (!isset($bpml['profiles'])) {
|
||||
$bpml['profiles'] = array('translation' => 'no');
|
||||
}
|
||||
|
||||
bpml_save_settings($bpml);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 7.7 KiB |
|
Before Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 34 KiB |