summaryrefslogtreecommitdiff
path: root/gengo_synonyms_page.php
blob: 2e02818f274b41b03037a68f5d282444fa46afaf (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
if (!current_user_can('configure_gengo')) {
	die( __('You do not have sufficient permissions to access this page.') );
}

if ($_POST['gengo_synonyms_submit'] && !empty($_POST['update_synonyms'])) {
	foreach ($_POST['update_synonyms'] as $term_id) {
		foreach ($gengo->languages as $language_id => $entry) {
			$synonym = $_POST[$term_id . '_' . $language_id];
			$sanitised = sanitize_title($synonym);
			$wpdb->query("UPDATE $gengo->term2syn_table SET synonym = '$synonym', sanitised = '$sanitised' WHERE term_id = $term_id AND language_id = $language_id");
		}
	}
	$gengo->update_message(__("Category translations updated.", GENGO_DOMAIN));
}
elseif ($_POST['gengo_synblock_submit']) {
	if (-1 == $_POST['gengo_synblock_name']) {
		if (!$block_name = $_POST['gengo_new_synblock']) {
			$gengo->error_message(__("Please specify a name for the new snippet.", GENGO_DOMAIN));
			$synblock_failed = true;
		} elseif ($block_name == $wpdb->get_var("SELECT block_name FROM $gengo->synblock_table WHERE block_name = '$block_name' LIMIT 1")) {
			$gengo->error_message(sprintf(__("Snippet '%s' already exists, please choose another name.", GENGO_DOMAIN), $block_name));
			$synblock_failed = true;
		} else {
			foreach ($gengo->languages as $language_id => $entry) $values[] = "('$block_name', $language_id, '" . str_replace("\n", '<br />', $_POST['synblock_' . $language_id]) . "')";
			if ($values) $wpdb->query("INSERT INTO $gengo->synblock_table(block_name, language_id, text) VALUES " . implode(', ', $values));
			$gengo->update_message(sprintf(__("Snippet '%s' created.", GENGO_DOMAIN), $block_name));
		}
	} else {
		$block_name = $_POST['gengo_synblock_name'];
		foreach ($gengo->languages as $language_id => $entry) {
			$text = str_replace("\n", '<br />', $_POST['synblock_' . $language_id]);
			$wpdb->query("UPDATE $gengo->synblock_table SET text = '$text' WHERE block_name = '$block_name' AND language_id = $language_id");
		}
		$gengo->update_message(sprintf(__("Snippet '%s' updated.", GENGO_DOMAIN), $block_name));
	}
}
elseif ($_POST['gengo_delete_synblock']) {
  $block_name = $_POST['gengo_synblock_name'];
	if (!$affected = $wpdb->query("DELETE FROM $gengo->synblock_table WHERE block_name = '$block_name'")) $gengo->error_message(sprintf(__("Synonym block '%s' does not exist.", GENGO_DOMAIN), $block_name));
	else $gengo->update_message(sprintf(__("Snippet '%s' deleted.", GENGO_DOMAIN), $block_name));
}
?>

<?php
$flagC = $flagLC = $flagT = $flagS = "";
$show = $_REQUEST['show'];	
switch($show):
	case "snippets":			$flagS=' class="current"'; break;
	case "tags":				$flagT=' class="current"'; $taxonomy = 'post_tag'; break;
	case "link_categories":			$flagLC=' class="current"'; $taxonomy = 'link_category'; break;
	case "categories": case "":	$flagC=' class="current"'; $taxonomy='category'; break;
endswitch;

if($show=="tags" || $show=="categories" || $show=="link_categories" || $show==""): ?>

<div class="wrap">
<h2><?php _e("Taxonomy Translations", GENGO_DOMAIN); ?></h2>
<ul class="subsubsub">
	<li><a href='admin.php?page=gengo/gengo_synonyms_page.php&amp;show=categories'<?php echo $flagC;?>><?php _e('Categories', GENGO_DOMAIN) ?></a> |</li>
	<li><a href='admin.php?page=gengo/gengo_synonyms_page.php&amp;show=link_categories'<?php echo $flagLC;?>><?php _e('Link Categories', GENGO_DOMAIN) ?></a> |</li>
	<li><a href='admin.php?page=gengo/gengo_synonyms_page.php&amp;show=tags'<?php echo $flagT;?>><?php _e('Tags', GENGO_DOMAIN) ?></a> |</li>
	<li><a href='admin.php?page=gengo/gengo_synonyms_page.php&amp;show=snippets'<?php echo $flagS;?>><?php _e('Snippets', GENGO_DOMAIN) ?></a></li>
</ul>

		<div class="tablenav">
			<div class="alignleft">
<p><?php _e("Add translations for taxonomy terms here to translate your categories, tags and permalinks.  The underlying term will be used for display and permalink purposes if there is no synonym specified for a language.  Editing the underlying term does not alter these translations.", GENGO_DOMAIN); ?></p>
			</div>
			<div class="tablenav-pages">
			</div>
		</div>
<br/>
<?php
if ($results = $wpdb->get_results("SELECT ts.term_id, ts.language_id, ts.synonym FROM $gengo->term2syn_table AS ts LEFT JOIN $wpdb->term_taxonomy AS tt ON ts.term_id = tt.term_id WHERE tt.taxonomy = '$taxonomy' ORDER BY term_id, language_id")) {
	?>
	<form id="gengo_synonyms_form" method="post">
	<div class="extender" style="">
	<table class="widefat" id="gengo_synonyms_table">
	<thead>
	<tr>
		<th scope="col">&nbsp;</th>
		<th scope="col">ID</th>
		<?php
		foreach ($gengo->languages as $entry) {
			?>
			<th scope="col"><?php echo $entry->language ?></th>
			<?php
		}
		?>
	</tr>
	</thead>
	<?php
	$num = count($results);
	$dimtext = array(1=>"",2=>"",3=>"",4=>"11px",5=>"11px");
	foreach ($results as $result) {
		if ($previous_id != $result->term_id) {
			// Starting a new row.
			if ($previous_id) { ?></tr><?php }
			?>
			<tr>
			<th scope="row" class="check-column"><input type="checkbox" name="update_synonyms[]" id="check_<?php echo $result->term_id ?>" value="<?php echo $result->term_id ?>" /></td>
			<td><?php echo $result->term_id ?></td>
			<?php
		}
		?>
		<td><input  style="font-size:11px;margin:0px;padding:3px;" type="text" name="<?php echo $result->term_id . "_" . $result->language_id ?>" value="<?php echo $result->synonym ?>" onkeydown="gengo_set_synonym_checkbox(<?php echo $result->term_id ?>)" /></td>
		<?php
		$previous_id = $result->term_id;
	}
	?>
	</tr>
	</table>
	</div>
	<p class="submit">
	<input type="submit" id="gengo_synonyms_submit" name="gengo_synonyms_submit" value="<?php _e('Update Checked', GENGO_DOMAIN) ?>" />
	</p>
	</form>
	</div>
	<div class="wrap"><p><strong><?php _e('Note:', GENGO_DOMAIN) ?></strong> <?php _e('These are only translations.  Changing these values will <strong>not</strong> alter the underlying term.', GENGO_DOMAIN) ?></p>
	<?php
} else {
	?>
	<p><?php _e('No languages defined yet.', GENGO_DOMAIN) ?></p>
	<?php
}
?>
</div>

<?php elseif($show=="snippets"): ?>

<?php
if ($count = count($gengo->languages)) {
	$block_names = $wpdb->get_col("SELECT DISTINCT block_name FROM $gengo->synblock_table");
	$block_list = '<option value="-1">' . __('(Add New Snippet)', GENGO_DOMAIN) . '</option>';
	foreach ($block_names as $block_name) $block_list .= "<option value=\"$block_name\">$block_name</option>";
?>
<script type="text/javascript">
var add_button_text = '<?php _e('Add Snippet', GENGO_DOMAIN) ?>';
var update_button_text = '<?php _e('Update Snippet', GENGO_DOMAIN) ?>';
</script>
<div class="wrap" id="gengo_snippets">
<h2><?php _e('Taxonomy Translations', GENGO_DOMAIN); ?></h2>
<ul class="subsubsub">
	<li><a href='admin.php?page=gengo/gengo_synonyms_page.php&amp;show=categories'<?php echo $flagC;?>><?php _e('Categories', GENGO_DOMAIN) ?></a> |</li>
	<li><a href='admin.php?page=gengo/gengo_synonyms_page.php&amp;show=link_categories'<?php echo $flagLC;?>><?php _e('Link Categories', GENGO_DOMAIN) ?></a> |</li>
	<li><a href='admin.php?page=gengo/gengo_synonyms_page.php&amp;show=tags'<?php echo $flagT;?>><?php _e('Tags', GENGO_DOMAIN) ?></a> |</li>
	<li><a href='admin.php?page=gengo/gengo_synonyms_page.php&amp;show=snippets'<?php echo $flagS;?>><?php _e('Snippets', GENGO_DOMAIN) ?></a></li>
</ul>
		<div class="tablenav">
			<div class="alignleft">
<p><?php _e("Snippets are small blocks of translated text for use throughout your site.  You can display these blocks anywhere by using <code>gengo_snippet('snippet_name')</code> in your template.", GENGO_DOMAIN); ?></p>
			</div>
			<div class="tablenav-pages">
			</div>
		</div>

<form id="gengo_synblocks_form" method="post">
<p style="float: left"><label for="gengo_synblock_name"><?php _e('Snippet Name:', GENGO_DOMAIN) ?></label></p>

<p><select id="gengo_synblock_name" name="gengo_synblock_name" onchange="gengo_get_synblock(this.value);"><?php echo $block_list ?></select></p>

<p style="float: left; margin-left: 50px" id="gengo_new_synblock_block"><label for="gengo_new_synblock"><?php _e('New Snippet Name:', GENGO_DOMAIN) ?></label><br />
<input type="text" id="gengo_new_synblock" name="gengo_new_synblock" /></p>

<?php
foreach ($gengo->languages as $language_id => $entry) {
	?>
	<p style="clear: both"><label for="synblock_<?php echo $language_id ?>"><?php echo $entry->language ?>:</label><br />
	<textarea id="synblock_<?php echo $language_id ?>" name="synblock_<?php echo $language_id ?>" style="width: 75%"><?php if ($synblock_failed) echo $_POST['synblock_' . $language_id]; ?></textarea></p>
	<?php
}
?>
<p class="submit">
<input style="float: left; display: none;" type="submit" id="deletepost" name="gengo_delete_synblock" value="<?php _e('Delete Snippet', GENGO_DOMAIN) ?>" onclick="return confirm('<?php _e("You are about to delete this snippet.\\n\'Cancel\' to stop, \'OK\' to delete", GENGO_DOMAIN) ?>')" />
<input type="submit" name="gengo_synblock_submit" id="gengo_synblock_submit" value="<?php _e('Add Snippet', GENGO_DOMAIN) ?>" />
</p>
</form>
<?php
} else {
	?>
	<p><?php _e('No languages defined yet.', GENGO_DOMAIN) ?></p>
	<?php
}
?>
</div>

<?php endif; ?>