summaryrefslogtreecommitdiff
path: root/includes/bit_setup_inc.php
blob: 7738a6eab48ca6b0d732733ac61d11159a937c6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php

/**
 * required setup
 */
namespace Bitweaver;

$pRegisterHash = [
	'package_name' => 'languages',
	'package_path' => dirname( dirname( __FILE__ ) ).'/',
	'service' => LIBERTY_SERVICE_TRANSLATION,
	'required_package'=> true,
];
define( 'LANGUAGES_PKG_NAME', $pRegisterHash['package_name'] );
define( 'LANGUAGES_PKG_URL', BIT_ROOT_URL . basename( $pRegisterHash['package_path'] ) . '/' );
$gBitSystem->registerPackage( $pRegisterHash );

// **********  BABELFISH  ************
if ($gBitSystem->isFeatureActive('babelfish') ) {
	require_once LANGUAGES_PKG_CLASS_PATH.'Babelfish.php';
	$gBitSmarty->assign('babelfish_links', \Babelfish::links( $gBitSystem->getConfig('language', 'en') ));
}
if ($gBitSystem->isFeatureActive('babelfish_logo') ) {
	require_once LANGUAGES_PKG_CLASS_PATH.'Babelfish.php';
	$gBitSmarty->assign('babelfish_logo', \Babelfish::logo($gBitLanguage->mLanguage));
}
if( $gBitSystem->isPackageActive( 'languages' ) && $gBitUser->hasPermission( 'p_languages_edit' ) ) {
	$menuHash = [
		'package_name'  => LANGUAGES_PKG_NAME,
		'index_url'     => LANGUAGES_PKG_URL.'edit_languages.php',
		'menu_template' => 'bitpackage:languages/menu_languages.tpl',
	];
	$gBitSystem->registerAppMenu( $menuHash );
}

if( $gBitSystem->isFeatureActive( 'users_preferences' ) && $gBitUser->isRegistered() ) {
	if( $gBitSystem->isFeatureActive( 'users_change_language' ) ) {
		if( $userLang = $gBitUser->getPreference( 'bitlanguage' ) ) {
			$gBitLanguage->setLanguage( $userLang );
		}
	}
}

// oe=XX global request parameter where XX is an enabled language code that overrides everything else
// oe is Output Encoding, which is the var google uses
if( !empty( $_REQUEST['oe'] ) && !empty( $gBitLanguage->mLanguageList[$_REQUEST['oe']] ) ) {
	$gBitLanguage->setLanguage( $_REQUEST['oe'] );
}

$gBitSmarty->assign('gBitLanguage', $gBitLanguage);
$gBitSmarty->assign('bitlanguage', $gBitLanguage->mLanguage);

if( !empty( $gLibertySystem ) && $gBitSystem->isFeatureActive( 'i18n_content_translation' ) ) {
	require_once LANGUAGES_PKG_CLASS_PATH.'LibertyTranslations.php';
	$gLibertySystem->registerService( LIBERTY_SERVICE_TRANSLATION, LANGUAGES_PKG_NAME, [
		'content_display_function' => 'translation_content_display',
		//'content_preview_function' => 'translation_content_edit',
		'content_edit_function' => 'translation_content_edit',
		'content_store_function' => 'translation_content_store',
		'content_expunge_function' => 'translation_content_exunge',
		//'content_list_sql_function' => 'translation_content_list',
		//'content_load_sql_function' => 'translation_content_load',
		'content_edit_mini_tpl' => 'bitpackage:languages/select_translations.tpl',
		'content_icon_tpl' => 'bitpackage:languages/i18n_service_icons.tpl',
	] );

	if( !empty( $_POST['i18n']['translate'] ) ) {
		$get = BitBase::verifyId( $_POST['i18n']['to_id'] )
			? '&content_id='.$_POST['i18n']['to_id']
			: 'i18n[lang_code]='.$_POST['i18n']['to_id'];

		if( BitBase::verifyId( $_POST['i18n']['translation_id'] ) ) {
			$get .= '&i18n[translation_id]='.$_POST['i18n']['translation_id'];
		}
		if( !empty( $_POST['i18n']['google'] ) ) {
			$get .= '&i18n[google]=1';
		}
		$get .= '&i18n[from_id]='.$_POST['i18n']['from_id'];
		header( 'Location: '.$_SERVER['SCRIPT_NAME'].'?'.$get );
		die;
	}
}