aboutsummaryrefslogtreecommitdiff
path: root/mod/translation_editor/actions
diff options
context:
space:
mode:
Diffstat (limited to 'mod/translation_editor/actions')
-rw-r--r--mod/translation_editor/actions/add_custom_key.php64
-rw-r--r--mod/translation_editor/actions/add_language.php19
-rw-r--r--mod/translation_editor/actions/delete.php20
-rw-r--r--mod/translation_editor/actions/delete_language.php26
-rw-r--r--mod/translation_editor/actions/disable_languages.php23
-rw-r--r--mod/translation_editor/actions/make_translation_editor.php23
-rw-r--r--mod/translation_editor/actions/merge.php29
-rw-r--r--mod/translation_editor/actions/translate.php76
-rw-r--r--mod/translation_editor/actions/translate_search.php84
-rw-r--r--mod/translation_editor/actions/unmake_translation_editor.php20
10 files changed, 384 insertions, 0 deletions
diff --git a/mod/translation_editor/actions/add_custom_key.php b/mod/translation_editor/actions/add_custom_key.php
new file mode 100644
index 000000000..47269dfd2
--- /dev/null
+++ b/mod/translation_editor/actions/add_custom_key.php
@@ -0,0 +1,64 @@
+<?php
+ global $CONFIG;
+
+ admin_gatekeeper();
+
+ $key = get_input("key");
+ $translation = get_input("translation");
+
+ if(!empty($key) && !empty($translation)){
+ if(!is_numeric($key)){
+ if(preg_match("/^[a-zA-Z0-9_:]{1,}$/", $key)){
+ $exists = false;
+ if(array_key_exists($key, $CONFIG->translations["en"])){
+ $exists = true;
+ }
+
+ if(!$exists){
+ // save
+
+ $custom_translations = array();
+
+ if($custom_translations = translation_editor_get_plugin("en", "custom_keys")){
+ $custom_translations = $custom_translations["en"];
+ }
+
+ $custom_translations[$key] = $translation;
+
+ $base_dir = elgg_get_data_path() . "translation_editor" . DIRECTORY_SEPARATOR;
+ if(!file_exists($base_dir)){
+ mkdir($base_dir);
+ }
+
+ $location = $base_dir . "custom_keys" . DIRECTORY_SEPARATOR;
+ if(!file_exists($location)){
+ mkdir($location);
+ }
+
+ $file_contents = "<?php" . PHP_EOL;
+ $file_contents .= '$language = ';
+ $file_contents .= var_export($custom_translations, true);
+ $file_contents .= ';' . PHP_EOL;
+ $file_contents .= 'add_translation("en", $language);' . PHP_EOL;
+ $file_contents .= "?>";
+
+ if(file_put_contents($location . "en.php", $file_contents)){
+
+ system_message(elgg_echo("translation_editor:action:add_custom_key:success"));
+ } else {
+ register_error(elgg_echo("translation_editor:action:add_custom_key:file_error"));
+ }
+ } else {
+ register_error(elgg_echo("translation_editor:action:add_custom_key:exists"));
+ }
+ } else {
+ register_error(elgg_echo("translation_editor:action:add_custom_key:invalid_chars"));
+ }
+ } else {
+ register_error(elgg_echo("translation_editor:action:add_custom_key:key_numeric"));
+ }
+ } else {
+ register_error(elgg_echo("translation_editor:action:add_custom_key:missing_input"));
+ }
+
+ forward(REFERER); \ No newline at end of file
diff --git a/mod/translation_editor/actions/add_language.php b/mod/translation_editor/actions/add_language.php
new file mode 100644
index 000000000..4b324bee6
--- /dev/null
+++ b/mod/translation_editor/actions/add_language.php
@@ -0,0 +1,19 @@
+<?php
+
+ admin_gatekeeper();
+
+ $code = get_input("code");
+ if(!empty($code)){
+ if($custom_languages = elgg_get_plugin_setting("custom_languages", "translation_editor")){
+ $custom_languages = explode(",", $custom_languages);
+ $custom_languages[] = $code;
+
+ $code = implode(",", array_unique($custom_languages));
+
+ }
+
+ elgg_set_plugin_setting("custom_languages", $code, "translation_editor");
+ system_message(elgg_echo("translation_editor:action:add_language:success"));
+ }
+
+ forward(REFERER); \ No newline at end of file
diff --git a/mod/translation_editor/actions/delete.php b/mod/translation_editor/actions/delete.php
new file mode 100644
index 000000000..b965150e9
--- /dev/null
+++ b/mod/translation_editor/actions/delete.php
@@ -0,0 +1,20 @@
+<?php
+ admin_gatekeeper();
+
+ $lang = get_input("current_language");
+ $plugin = get_input("plugin");
+
+ if(!empty($lang) && !empty($plugin)){
+ if(translation_editor_delete_translation($lang, $plugin)){
+ // merge translations
+ translation_editor_merge_translations($lang, true);
+
+ system_message(elgg_echo("translation_editor:action:delete:success"));
+ } else {
+ register_error(elgg_echo("translation_editor:action:delete:error:delete"));
+ }
+ } else {
+ register_error(elgg_echo("translation_editor:action:delete:error:input"));
+ }
+
+ forward("translation_editor/" . $lang);
diff --git a/mod/translation_editor/actions/delete_language.php b/mod/translation_editor/actions/delete_language.php
new file mode 100644
index 000000000..77b8441f5
--- /dev/null
+++ b/mod/translation_editor/actions/delete_language.php
@@ -0,0 +1,26 @@
+<?php
+
+ admin_gatekeeper();
+
+ $language = get_input("language");
+ if(!empty($language) && ($language != "en")){
+
+ $completeness = translation_editor_get_language_completeness($language);
+ if($completeness == 0){
+ if($custom_languages = elgg_get_plugin_setting("custom_languages", "translation_editor")){
+ $custom_languages = explode(",", $custom_languages);
+
+ $index = array_search($language, $custom_languages);
+ if($index !== false ){
+ unset($custom_languages[$index]);
+
+ $code = implode(",", array_unique($custom_languages));
+
+ elgg_set_plugin_setting("custom_languages", $code, "translation_editor");
+ system_message(elgg_echo("translation_editor:action:delete_language:success"));
+ }
+ }
+ }
+ }
+
+ forward(REFERER); \ No newline at end of file
diff --git a/mod/translation_editor/actions/disable_languages.php b/mod/translation_editor/actions/disable_languages.php
new file mode 100644
index 000000000..04c3235f6
--- /dev/null
+++ b/mod/translation_editor/actions/disable_languages.php
@@ -0,0 +1,23 @@
+<?php
+
+ /**
+ * jQuery call to disable a set of languages
+ */
+
+ if(elgg_is_admin_logged_in()){
+ $disabled_languages = get_input("disabled_languages");
+
+ if(!empty($disabled_languages)){
+ if(is_array($disabled_languages)){
+ $temp_string = implode(",", $disabled_languages);
+ } else {
+ $temp_string = $disabled_languages;
+ }
+
+ elgg_set_plugin_setting(TRANSLATION_EDITOR_DISABLED_LANGUAGE, $temp_string, "translation_editor");
+ } else {
+ elgg_unset_plugin_setting(TRANSLATION_EDITOR_DISABLED_LANGUAGE, "translation_editor");
+ }
+ }
+
+ exit(); \ No newline at end of file
diff --git a/mod/translation_editor/actions/make_translation_editor.php b/mod/translation_editor/actions/make_translation_editor.php
new file mode 100644
index 000000000..5a5640c66
--- /dev/null
+++ b/mod/translation_editor/actions/make_translation_editor.php
@@ -0,0 +1,23 @@
+<?php
+
+ admin_gatekeeper();
+
+ $result = false;
+
+ $user = get_input("user");
+ $role = "translation_editor";
+
+ $user = get_entity($user);
+ if($user instanceof ElggUser){
+ if(create_metadata($user->guid, $role, true, "integer", $user->guid, ACCESS_PUBLIC)){
+ $result = true;
+ }
+ }
+
+ if(!$result){
+ register_error(elgg_echo("translation_editor:action:make_translation_editor:error"));
+ } else {
+ system_message(elgg_echo("translation_editor:action:make_translation_editor:success"));
+ }
+
+ forward(REFERER); \ No newline at end of file
diff --git a/mod/translation_editor/actions/merge.php b/mod/translation_editor/actions/merge.php
new file mode 100644
index 000000000..db1e75276
--- /dev/null
+++ b/mod/translation_editor/actions/merge.php
@@ -0,0 +1,29 @@
+<?php
+ gatekeeper();
+
+ $current_language = get_input("current_language");
+ $plugin = get_input("plugin");
+
+ if(translation_editor_is_translation_editor()){
+
+ // We'll be outputting a CSV
+ header("Content-Type: text/plain");
+
+ // It will be called $lang.php
+ header('Content-Disposition: attachment; filename="' . $current_language . '.php"');
+
+ $translation = translation_editor_get_plugin($current_language, $plugin);
+ $translation = $translation['current_language'];
+
+ echo "<?php" . PHP_EOL;
+ echo '$language = ';
+ echo var_export($translation);
+ echo ';' . PHP_EOL;
+ echo 'add_translation("' . $current_language . '", $language);' . PHP_EOL;
+
+ exit();
+
+ } else {
+ register_error(elgg_echo("transation_editor:action:translate:error:not_authorized"));
+ forward(REFERER);
+ }
diff --git a/mod/translation_editor/actions/translate.php b/mod/translation_editor/actions/translate.php
new file mode 100644
index 000000000..973d050d4
--- /dev/null
+++ b/mod/translation_editor/actions/translate.php
@@ -0,0 +1,76 @@
+<?php
+ global $CONFIG;
+
+ //action_gatekeeper();
+ gatekeeper();
+
+ // Fixes for KSES filtering
+ // fix to allow javascript in href
+ $CONFIG->allowedprotocols[] = "javascript";
+
+ // fix allowed tags
+ $CONFIG->allowedtags["a"]["onclick"] = array();
+ $CONFIG->allowedtags["span"]["id"] = array();
+
+ // get inputs
+ $current_language = get_input("current_language");
+ $translate_input = get_input("translation");
+ $plugin = get_input("plugin");
+ $jquery = get_input("jquery", false);
+
+ // Preparing jQuery result
+ $json_result = array();
+ $json_result["result"] = false;
+
+ if(translation_editor_is_translation_editor()){
+ if(!empty($current_language) && !empty($translate_input) && !empty($plugin)){
+ $translated = translation_editor_compare_translations($current_language, $translate_input);
+
+ if(!empty($translated)){
+ if(translation_editor_write_translation($current_language, $plugin, $translated)){
+ if(!$jquery){
+ system_message(elgg_echo("translation_editor:action:translate:success"));
+ } else {
+ $json_result["result"] = true;
+ }
+ } else {
+ if(!$jquery){
+ register_error(elgg_echo("translation_editor:action:translate:error:write"));
+ }
+ }
+ } else {
+ translation_editor_delete_translation($current_language, $plugin);
+ if(!$jquery){
+ system_message(elgg_echo("translation_editor:action:translate:no_changed_values"));
+ } else {
+ $json_result["result"] = true;
+ }
+ }
+
+ // merge translations
+ translation_editor_merge_translations($current_language, true);
+ } else {
+ if(!$jquery){
+ register_error(elgg_echo("translation_editor:action:translate:error:input"));
+ }
+ }
+ } else {
+ if(!$jquery){
+ register_error(elgg_echo("translation_editor:action:translate:error:not_authorized"));
+ }
+ }
+
+ if(!$jquery){
+ forward(REFERER);
+ } else {
+ // Send JSON data
+ $json_string = json_encode($json_result);
+
+ header("Content-Type: application/json; charset=UTF-8");
+ header("Content-Length: " . strlen($json_string));
+ header("Cache-Control: no-cache");
+ header("Pragma: no-cache");
+
+ echo $json_string;
+ exit();
+ }
diff --git a/mod/translation_editor/actions/translate_search.php b/mod/translation_editor/actions/translate_search.php
new file mode 100644
index 000000000..623828b39
--- /dev/null
+++ b/mod/translation_editor/actions/translate_search.php
@@ -0,0 +1,84 @@
+<?php
+ global $CONFIG;
+
+ //action_gatekeeper();
+ gatekeeper();
+
+ // Fixes for KSES filtering
+ // fix to allow javascript in href
+ $CONFIG->allowedprotocols[] = "javascript";
+
+ // fix allowed tags
+ $CONFIG->allowedtags["a"]["onclick"] = array();
+ $CONFIG->allowedtags["span"]["id"] = array();
+
+ // get inputs
+ $current_language = get_input("current_language");
+ $translation = get_input("translation");
+ $jquery = get_input("jquery", false);
+
+ // Preparing jQuery result
+ $json_result = array();
+ $json_result["result"] = false;
+
+ if(translation_editor_is_translation_editor()){
+ $trans = get_installed_translations();
+
+ if(!empty($current_language) && !empty($translation) && array_key_exists($current_language, $trans)){
+ foreach($translation as $plugin => $translate_input){
+ // merge with existing custom translations
+ if($custom_translation = translation_editor_read_translation($current_language, $plugin)){
+ $translate_input = array_merge($custom_translation, $translate_input);
+ }
+
+ $translated = translation_editor_compare_translations($current_language, $translate_input);
+
+ if(!empty($translated)){
+ if(translation_editor_write_translation($current_language, $plugin, $translated)){
+ if(!$jquery){
+ system_message(elgg_echo("translation_editor:action:translate:success"));
+ } else {
+ $json_result["result"] = true;
+ }
+ } else {
+ if(!$jquery){
+ register_error(elgg_echo("translation_editor:action:translate:error:write"));
+ }
+ }
+ } else {
+ translation_editor_delete_translation($current_language, $plugin);
+ if(!$jquery){
+ system_message(elgg_echo("translation_editor:action:translate:no_changed_values"));
+ } else {
+ $json_result["result"] = true;
+ }
+ }
+ }
+
+ // merge translations
+ translation_editor_merge_translations($current_language, true);
+ } else {
+ if(!$jquery){
+ register_error(elgg_echo("translation_editor:action:translate:error:input"));
+ }
+ }
+ } else {
+ if(!$jquery){
+ register_error(elgg_echo("translation_editor:action:translate:error:not_authorized"));
+ }
+ }
+
+ if(!$jquery){
+ forward(REFERER);
+ } else {
+ // Send JSON data
+ $json_string = json_encode($json_result);
+
+ header("Content-Type: application/json; charset=UTF-8");
+ header("Content-Length: " . strlen($json_string));
+ header("Cache-Control: no-cache");
+ header("Pragma: no-cache");
+
+ echo $json_string;
+ exit();
+ }
diff --git a/mod/translation_editor/actions/unmake_translation_editor.php b/mod/translation_editor/actions/unmake_translation_editor.php
new file mode 100644
index 000000000..1872d7f6c
--- /dev/null
+++ b/mod/translation_editor/actions/unmake_translation_editor.php
@@ -0,0 +1,20 @@
+<?php
+
+ admin_gatekeeper();
+
+ $result = false;
+
+ $user = get_input("user");
+ $user = get_entity($user);
+
+ if($user instanceof ElggUser){
+ unset($user->translation_editor);
+ $result = true;
+ }
+
+ if(!$result){
+ register_error(elgg_echo("translation_editor:action:unmake_translation_editor:error"));
+ } else {
+ system_message(elgg_echo("translation_editor:action:unmake_translation_editor:success"));
+ }
+ forward(REFERER);