function webdictionary_edit_language_form($code) { global $DB; global $website; global $theme; global $events; $navibars = new navibars(); $naviforms = new naviforms(); $navibars->title(t(21, 'Dictionary') . ' / ' . t(602, 'Edit language')); $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(0);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>')); $navibars->add_actions(array('<a href="?fid=webdictionary&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>')); $navibars->form(); $navibars->add_tab(t(188, "Translate")); $navibars->add_tab_content($naviforms->hidden('form-sent', 'true')); $origin = ""; foreach ($website->languages_list as $l) { if ($l == $code) { continue; } else { $origin = $l; break; } } // retrieve original theme translations, if any $theme->get_translations(); $dict_dest = array(); foreach ($theme->dictionaries as $otext) { if ($otext['lang'] == $code) { $dict_dest[$otext['node_id']] = $otext['text']; } } // retrieve existing database dictionary translations $DB->query(' SELECT * FROM nv_webdictionary WHERE ( (node_type = "global") OR (node_type = "theme" AND theme= "' . $theme->name . '") ) AND website = ' . $website->id . ' '); $db_trans = $DB->result(); foreach ($db_trans as $otext) { $text_id = $otext->node_id; if ($otext->node_type == "theme") { $text_id = $otext->subtype; } if ($otext->lang == $code) { $dict_dest[$text_id] = $otext->text; } else { if ($otext->lang == $origin && $otext->node_type == "global") { array_push($theme->dictionaries, array("source" => $text_id, "node_id" => $text_id, "text" => $otext->text, "lang" => $otext->lang)); } } } $extensions_translations = array(); $extensions = extension::list_installed(); if (!is_array($extensions)) { $extensions = array(); } foreach ($extensions as $extension) { $ext = new extension(); $ext->load($extension['code']); $extension_translations = $ext->get_translations(); // load all translations of the extension $extensions_translations = array_merge($extensions_translations, $extension_translations); } $DB->query(' SELECT * FROM nv_webdictionary WHERE node_type = "extension" AND website = ' . $website->id, 'array'); $resultset = $DB->result(); for ($dbrs = 0; $dbrs < count($resultset); $dbrs++) { $found = false; for ($trs = 0; $trs < count($extensions_translations); $trs++) { if ($resultset[$dbrs]['node_type'] == "extension" && $resultset[$dbrs]['extension'] == $extensions_translations[$trs]['extension'] && $resultset[$dbrs]['subtype'] == $extensions_translations[$trs]['node_id'] && $resultset[$dbrs]['lang'] == $extensions_translations[$trs]['lang']) { $found = true; $extensions_translations[$trs]['text'] = $resultset[$dbrs]['text']; } } // translation was not included in the extension languages, so we need to add it to our array if (!$found) { $extensions_translations[] = array('extension' => $resultset[$dbrs]['extension'], 'source' => 'extension.' . $resultset[$dbrs]['extension'] . '.' . $resultset[$dbrs]['subtype'], 'node_id' => $resultset[$dbrs]['subtype'], 'lang' => $resultset[$dbrs]['lang'], 'text' => $resultset[$dbrs]['text']); } } // generate table $table = '<table class="box-table">'; $table .= '<tr><th>' . t(237, "Code") . '</th><th>' . language::name_by_code($origin) . '</th><th>' . language::name_by_code($code) . '</th></tr>'; foreach ($theme->dictionaries as $otext) { if ($otext['lang'] == $origin) { $translation = $dict_dest[$otext['node_id']]; if (is_numeric($otext['source'])) { $otext['source'] = 'global.' . $otext['source']; } // note: PHP does not allow using dots in $_POST variable names, unless they are used in an array $table .= ' <tr> <td>' . $otext['node_id'] . '</textarea></td> <td><textarea rows="2" cols="60" disabled="disabled">' . $otext['text'] . '</textarea></td> <td><textarea name="data[' . $code . '.' . $otext['source'] . ']" rows="2" cols="60">' . $translation . '</textarea></td> </tr> '; } } foreach ($extensions_translations as $otext) { if ($otext['lang'] == $origin) { $translation = ""; foreach ($extensions_translations as $dtext) { if ($otext['source'] == $dtext['source'] && $dtext['lang'] == $code) { $translation = $dtext['text']; } } $table .= ' <tr> <td>' . $otext['source'] . '</textarea></td> <td><textarea rows="2" cols="60" disabled="disabled">' . $otext['text'] . '</textarea></td> <td><textarea name="data[' . $code . '.' . $otext['source'] . ']" rows="2" cols="60">' . $translation . '</textarea></td> </tr> '; } } $table .= '</table>'; $navibars->add_tab_content($table); return $navibars->generate(); }
public function load($id) { global $DB; global $website; global $theme; if (is_numeric($id)) { if ($DB->query('SELECT * FROM nv_webdictionary WHERE node_id = ' . intval($id) . ' AND node_type = ' . protect('global') . ' AND website = ' . $website->id)) { $data = $DB->result(); $this->load_from_resultset($data); // there will be as many entries as languages enabled } } else { // id can be a theme string or a translation path (example: extension.seotab.check_url_on_facebook) $path = explode(".", $id, 3); if ($path[0] == 'extension') { $extension = new extension(); $extension->load($path[1]); $id = $path[2]; // $id is a theme string that may be in the database or/and the theme json dictionary $extension_dictionary = $extension->get_translations(); $this->id = $id; $this->node_type = 'extension'; $this->extension = $extension->code; $this->extension_name = $extension->title; $this->node_id = $id; $this->subtype = $id; $this->website = $website->id; $this->text = array(); foreach ($extension_dictionary as $word) { if ($word['node_id'] == $id) { $this->text[$word['lang']] = $word['text']; } } // we need to load the database versions of the theme strings // node_id is not used in database with theme strings $DB->query(' SELECT lang, text FROM nv_webdictionary WHERE node_type = "extension" AND extension = ' . protect($this->extension) . ' AND subtype = ' . protect($this->subtype) . ' AND website = ' . $website->id); $data = $DB->result(); if (!is_array($data)) { $data = array(); } foreach ($data as $item) { $this->text[$item->lang] = $item->text; } } else { $id = $path[2]; // $id is a theme string that may be in the database or/and the theme json dictionary $theme_dictionary = $theme->get_translations(); $this->id = $id; $this->node_type = 'theme'; $this->node_id = $id; $this->theme = $theme->name; $this->subtype = $id; $this->website = $website->id; $this->text = array(); foreach ($theme_dictionary as $word) { if ($word['node_id'] == $id) { $this->text[$word['lang']] = $word['text']; } } // we need to load the database versions of the theme strings // node_id is not used in database with theme strings $DB->query(' SELECT lang, text FROM nv_webdictionary WHERE node_type = "theme" AND theme = ' . protect($theme->name) . ' AND subtype = ' . protect($this->subtype) . ' AND website = ' . $website->id); $data = $DB->result(); if (!is_array($data)) { $data = array(); } foreach ($data as $item) { $this->text[$item->lang] = $item->text; } } } }