tiki-freetag_translate.php 4.51 KB
Newer Older
1
<?php
2
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
3
// 
4 5
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
6
// $Id$
7 8

require_once ('tiki-setup.php');
9
$access->check_feature(array('feature_freetags','freetags_multilingual','feature_multilingual'));
10
$access->check_permission('tiki_p_freetags_tag');
11 12 13 14 15 16 17 18 19

if( !isset($_REQUEST['type']))
	$_REQUEST['type'] = 'wiki page';
if( !isset($_REQUEST['objId']))
	$_REQUEST['objId'] = '';

$cat_type = $_REQUEST['type'];
$cat_objId = $_REQUEST['objId'];

20
if ($cat_type != 'wiki page' && $cat_type != 'article') {
21 22 23 24 25 26 27 28 29 30 31 32 33
	$smarty->assign('msg', tra("Not supported yet."));

	$smarty->display("error.tpl");
	die;
}

include_once "lib/freetag/freetaglib.php";
include_once "lib/multilingual/multilinguallib.php";

if ( $cat_objId ) {
	$info = $tikilib->get_page_info( $cat_objId );
} elseif (false&&$tiki_p_admin_freetags != 'y') {
	// Global tag edit only available to admins
34
	$smarty->assign('errortype', 401);
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 83 84 85 86 87 88
	$smarty->assign('msg', tra("You do not have permission to use this feature"));

	$smarty->display("error.tpl");
	die;
}

$smarty->assign( 'type', $cat_type );
$smarty->assign( 'objId', $cat_objId );

$smarty->assign( 'data', $info );

if( isset( $_REQUEST['save'] ) )
{
	// Process save
	if( isset( $_REQUEST['setlang'] )
		&& is_array( $_REQUEST['setlang'] ) )
	{
		foreach( $_REQUEST['setlang'] as $tagId => $lang )
			if( !empty( $lang ) )
				$freetaglib->set_tag_language( $tagId, $lang );
	}

	if( isset( $_REQUEST['newtag'] )
		&& isset( $_REQUEST['rootlang'] )
		&& is_array( $_REQUEST['newtag'] )
		&& is_array( $_REQUEST['rootlang'] ) )
	{
		foreach( $_REQUEST['newtag'] as $tagGroup => $list )
			if( is_array( $list ) && array_key_exists( $tagGroup, $_REQUEST['rootlang'] ) )
				foreach( $list as $lang => $tag )
				{
					$root = $_REQUEST['rootlang'][$tagGroup];
					if( !array_key_exists( $lang, $root ) )
						continue;

					$freetaglib->translate_tag( $root[$lang], $tagGroup, $lang, $tag );
				}
	}

	if( isset( $_REQUEST['clear'] ) && is_array( $_REQUEST['clear'] ) )
	{
		foreach( $_REQUEST['clear'] as $tag )
			$freetaglib->clear_tag_language_from_id( $tag );
	}
}
else
{
	// Form reload
	if( isset( $_REQUEST['newtag'] ) )
		$smarty->assign( 'newtags', $_REQUEST['newtag'] );
	if( isset( $_REQUEST['setlang'] ) )
		$smarty->assign( 'setlang', $_REQUEST['setlang'] );
}

89
$freetags_per_page = $prefs['maxRecords'];
90
$offset = intval($_REQUEST['offset']);
91 92 93 94 95 96
if ($offset < 0) {
	$offset = 0;
}
$smarty->assign('freetags_offset', $offset);
$smarty->assign('freetags_per_page', $freetags_per_page);

chealer's avatar
chealer committed
97
$languages = $multilinguallib->preferredLangs();
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
$used_languages = array();
foreach ($languages as $l)
	$used_languages[$l] = true;
if( array_key_exists( 'additional_languages', $_REQUEST )
	&& is_array( $_REQUEST['additional_languages'] ) )
	foreach( $_REQUEST['additional_languages'] as $lang )
		$used_languages[$lang] = true;
$used_languages = array_keys( $used_languages );

$allLanguages = $tikilib->list_languages();
// select roughly readable languages
$t_used_languages = array();
foreach ($allLanguages as $al) {
	foreach ($used_languages as $ul) {
		if (substr($al["value"],0,2) == substr($ul,0,2)) {
			$t_used_languages[] = $al["value"];
			break;
		}
	}
}
$used_languages = $t_used_languages;

120
$tagList = $freetaglib->get_object_tags_multilingual( $cat_type, $cat_objId, $used_languages, $offset, $freetags_per_page );
121 122 123 124 125 126 127 128 129 130

$rootlangs = array();
foreach( $tagList as $tagGroup ) {
	foreach( $tagGroup as $k => $tag )
	{
		array_merge($used_languages, array($k));
		if( $tag['tagset'] == $tag['tagId'] )
			$rootlangs[$tag['tagset']] = $tag['lang'];
	}
}
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146

$baseArgs = array(
	'type' => $cat_type,
	'objId' => $cat_objId,
	'additional_languages' => $used_languages,
);

$prev = http_build_query( array_merge( $baseArgs, array( 'offset' => $offset - $freetags_per_page ) ), '', '&' );
$next = http_build_query( array_merge( $baseArgs, array( 'offset' => $offset + $freetags_per_page ) ), '', '&' );

$smarty->assign( 'next', 'tiki-freetag_translate.php?' . $next );
if( $offset ) {
	$smarty->assign( 'previous', 'tiki-freetag_translate.php?' . $prev );
} else {
	$smarty->assign( 'previous', '' );
}
147 148 149 150 151 152 153 154 155
	
$smarty->assign( 'tagList', $tagList );
$smarty->assign( 'languageList', $used_languages );
$smarty->assign( 'fullLanguageList', $allLanguages );
$smarty->assign( 'rootlang', $rootlangs );

// Display the template
$smarty->assign('mid', 'tiki-freetag-translate.tpl');
$smarty->display("tiki.tpl");