AbanteCart, Ideal OpenSource Ecommerce Solution http://www.AbanteCart.com Copyright © 2011-2016 Belavier Commerce LLC This source file is subject to Open Software License (OSL 3.0) License details is bundled with this package in the file LICENSE.txt. It is also available at this URL: <http://www.opensource.org/licenses/OSL-3.0> UPGRADE NOTE: Do not edit or add to this file if you wish to upgrade AbanteCart to newer versions in the future. If you wish to customize AbanteCart for your needs please refer to http://www.AbanteCart.com for more information. ------------------------------------------------------------------------------*/ if (!defined('DIR_CORE')) { header('Location: static_pages/'); } $language_code = 'ru'; $language_directory = 'russian'; $query = $this->db->query("SELECT language_id FROM " . DB_PREFIX . "languages WHERE code='" . $language_code . "' AND directory='" . $language_directory . "'"); $language_id = $query->row['language_id']; //delete menu $storefront_menu = new AMenu_Storefront(); $storefront_menu->deleteLanguage($language_id); //delete all other langauge related tables $lm = new ALanguageManager($this->registry, $language_code); $lm->deleteAllLanguageEntries($language_id); //delete langauge $this->db->query("DELETE FROM " . DB_PREFIX . "languages WHERE `code`='" . $language_code . "'"); $this->cache->remove('localization');
/** * Load needed data and build form for definitions add or edit * @param ARequest $request - Data from request object * @param array $data - from requester * @param AForm $form - form object * @return array ($data imputed processed and returned back) */ public function buildFormData(&$request, &$data, &$form) { $fields = array('language_key', 'language_value', 'block', 'section'); $language_definition_id = $request->get['language_definition_id']; $view_mode = 'all'; $main_block = false; //if existing definition disable edit for some fields $disable_attr = ''; if (has_value($language_definition_id)) { $disable_attr = ' readonly '; } $languages = $this->language->getAvailableLanguages(); $content_lang_id = $this->language->getContentLanguageID(); //load current content language to data foreach ($languages as $lang) { if ($view_mode != 'all' && $lang['language_id'] != $content_lang_id) { continue; } $data['languages'][$lang['language_id']] = $lang; } $def_det = array(); $all_defs = array(); //!!!! ATTENTION: Important to understand this process flow. See comments if (has_value($language_definition_id)) { // 1. language_definition_id is provided, load definition based on ID $def_det = $this->getLanguageDefinition($language_definition_id); if (empty($def_det)) { //this is incorrect ID redirect to create new $parms = '&view_mode=' . $view_mode; return array('redirect_params' => $parms); } //special case then main file is edited (english, russian, etc ). //Candidate for improvement. Rename these files to main.xml $main_block = $this->language->isMainBlock($def_det['block'], $def_det['language_id']); // 2. make sure we load all the langaues from XML in case they were not used yet. foreach ($languages as $lang) { $new_lang_obj = new ALanguageManager($this->registry, $lang['code'], $def_det['section']); if ($main_block) { $block_path = $lang['filename']; $block = $lang['filename']; } else { $block = $def_det['block']; $block_path = $new_lang_obj->convert_block_to_file($def_det['block']); if (empty($block_path)) { $block_path = $block; } } if ($block_path) { $new_lang_obj->_load($block_path); //now load definition for all languages to be available in the template $all_defs[] = $this->LoadDefinitionSetEmpty($def_det['section'], $block, $def_det['language_key'], $lang['language_id']); } } // 3. Redirect to correct definition for current content language selected //if different from selected language_definition_id if ($def_det['language_id'] != $content_lang_id) { if ($main_block) { $block = $data['languages'][$content_lang_id]['filename']; } else { $block = $def_det['block']; } $new_def = $this->LoadDefinitionSetEmpty($def_det['section'], $block, $def_det['language_key'], $content_lang_id); //if exists redirect with correct language_definition_id for content language if (has_value($new_def['language_definition_id'])) { $parms = '&view_mode=' . $view_mode; $parms .= '&language_definition_id=' . $new_def['language_definition_id']; return array('redirect_params' => $parms); } else { //alow to create new one with blank defintion value $def_det = $new_def; } } } foreach ($fields as $field) { if (isset($request->post[$field])) { $data[$field] = $request->post[$field]; } elseif (isset($def_det)) { $data[$field] = $def_det[$field]; } else { $data[$field] = ''; } } $data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_save'), 'style' => 'button1')); $data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2')); if ($disable_attr) { $section_txt = $this->language->get('text_storefront'); if ($data['section']) { $section_txt = $this->language->get('text_admin'); } $data['form']['fields']['section'] = $section_txt . $form->getFieldHtml(array('type' => 'hidden', 'name' => 'section', 'value' => $data['section'])); $data['form']['fields']['block'] = $data['block'] . $form->getFieldHtml(array('type' => 'hidden', 'name' => 'block', 'value' => $data['block'])); $data['form']['fields']['language_key'] = $data['language_key'] . $form->getFieldHtml(array('type' => 'hidden', 'name' => 'language_key', 'value' => $data['language_key'])); } else { $data['form']['fields']['section'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'section', 'options' => array(1 => $this->language->get('text_admin'), 0 => $this->language->get('text_storefront')), 'value' => $data['section'], 'required' => true)); $data['form']['fields']['block'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'block', 'value' => $data['block'], 'required' => true)); $data['form']['fields']['language_key'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'language_key', 'value' => $data['language_key'], 'required' => true)); } if ($main_block) { $data['form']['fields']['main_block'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'main_block', 'value' => 1)); } //load all language fields for this definition to be awailable in the template foreach ($data['languages'] as $i) { $value = ''; $id = ''; if (!empty($request->post['language_value'][$i['language_id']])) { $value = $request->post['language_value'][$i['language_id']]; foreach ($all_defs as $ii) { if ($ii['language_id'] == $i['language_id']) { $id = $ii['language_definition_id']; break; } } } else { if (!empty($all_defs)) { foreach ($all_defs as $ii) { if ($ii['language_id'] == $i['language_id']) { $value = $ii['language_value']; $id = $ii['language_definition_id']; break; } } } } $data['form']['fields']['language_value'][$i['language_id']] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'language_value[' . $i['language_id'] . ']', 'value' => $value, 'required' => true, 'style' => 'large-field')) . $form->getFieldHtml(array('type' => 'hidden', 'name' => 'language_definition_id[' . $i['language_id'] . ']', 'value' => $id)); } return array(); }
function do_work() { define('IS_ADMIN', true); $language = new ALanguageManager($this->registry, 'en'); //Load default language (1) English on install only. return $language->definitionAutoLoad(1, 'all', 'all'); }
public function edit() { $prj_id = $this->session->data['dev_tools_prj_id']; if (!$prj_id) { $this->redirect($this->html->getSecureURL('tool/developer_tools')); } $this->loadModel('tool/developer_tools'); $this->loadLanguage('developer_tools/developer_tools'); $config = $this->model_tool_developer_tools->getProjectConfig($prj_id); if ($this->request->is_POST()) { foreach ($this->request->post['keys'] as $language_name => $values) { if (!is_array($values)) { continue; } $path = DIR_EXT . $config['extension_txt_id'] . '/' . $this->request->get['section'] . '/language/' . $language_name . '/' . $this->request->get['block']; // for language extensions if ($language_name == $config['extension_txt_id']) { $path = DIR_EXT . $config['extension_txt_id'] . '/' . $this->request->get['section'] . '/language/' . $this->request->get['block']; } $this->model_tool_developer_tools->saveLanguageXML($path, $values); if ($this->model_tool_developer_tools->error) { $this->messages->saveNotice('Developer Tools Notice ("' . $this->request->get['block'] . '")', implode('<br>', $this->model_tool_developer_tools->error)); } $lm = new ALanguageManager($this->registry); $block = str_replace('.xml', '', $this->request->get['block']); $block = str_replace('/', '_', $block); $langs = $lm->getAvailableLanguages(); foreach ($langs as $lang) { $lm->definitionAutoLoad($lang['language_id'], $this->request->get['section'], $block, 'update'); } $this->data['success'] = $this->language->get('developer_tools_text_language_file_edit_success'); } $this->redirect($this->html->getSecureURL('tool/developer_tools_languages/edit', '&block=' . $this->request->get['block'] . '§ion=' . $this->request->get['section'])); } $language_files = $this->model_tool_developer_tools->getLanguageFiles($prj_id); if (!$language_files) { $this->session->data['warning'] = 'Project does not contain language files. To add it please use project <a href="' . $this->html->getSecureURL('tool/developer_tools/edit') . '">edit form</a>.'; $this->redirect($this->html->getSecureURL('tool/developer_tools/edit')); } //load tabs controller $tabs_obj = $this->dispatch('pages/tool/developer_tools_tabs', array('project')); $this->data['dev_tabs'] = $tabs_obj->dispatchGetOutput(); $tabs_obj = $this->dispatch('pages/tool/developer_tools_tabs/prjtabs', array('languages')); $this->data['prj_tabs'] = $tabs_obj->dispatchGetOutput(); $this->data['cancel'] = $this->html->getSecureURL('developer_tools_name'); $this->data['action'] = $this->html->getSecureURL('tool/developer_tools_languages/edit', '&block=' . $this->request->get['block'] . '§ion=' . $this->request->get['section']); $this->data['heading_title'] = $this->language->get('developer_tools_name'); $this->data['update'] = ''; $form = new AForm('HT'); $form->setForm(array('form_name' => 'extLanguageFrm', 'update' => $this->data['update'])); $this->data['form']['id'] = 'extLanguageFrm'; $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'extLanguageFrm', 'action' => $this->data['action'])); $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_save'), 'style' => 'button1')); $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2')); $pathes = $all_keys = array(); // pathes to xml-file foreach ($language_files as $section => $language) { if ($section == $this->request->get['section']) { foreach ($language as $lang => $file) { $languages[] = $lang; $pathes[$lang] = array('path' => '', 'keys' => array()); foreach ($file as $filename) { if ($filename == $this->request->get['block'] || $lang == $config['extension_txt_id'] && $lang . '/' . $filename == $this->request->get['block']) { $path = $section . '/language/' . $lang . '/' . $this->request->get['block']; // for language extensions write if ($lang == $config['extension_txt_id']) { $path = $section . '/language/' . $this->request->get['block']; } $keys = array(); if (is_file(DIR_EXT . $config['extension_txt_id'] . '/' . $path) && filesize(DIR_EXT . $config['extension_txt_id'] . '/' . $path)) { $xml = simplexml_load_file(DIR_EXT . $config['extension_txt_id'] . '/' . $path); foreach ($xml->definition as $def) { $keys[trim((string) $def->key)] = trim((string) $def->value); } // collect key names from all language variants $all_keys = array_merge($all_keys, array_keys($keys)); } $pathes[$lang] = array('path' => $path, 'keys' => $keys); break; } } } } } $all_keys = array_unique($all_keys); foreach ($all_keys as $key) { if (!$key) { continue; } foreach ($languages as $language_name) { $this->data['form']['fields'][$key][] = $language_name; $this->data['form']['fields'][$key][] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'keys[' . $language_name . '][' . $key . ']', 'value' => $pathes[$language_name]['keys'][$key], 'style' => 'large-field')); } } // build prototype for new key form elements $this->data['form']['proto']['newkey'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'newkey', 'value' => $config['extension_txt_id'] . '_', 'attr' => ' autocomplete="off" ')); foreach ($languages as $language_name) { $this->data['form']['proto']['field'][] = $language_name; $this->data['form']['proto']['field'][] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'keys[' . $language_name . '][]', 'value' => '', 'attr' => ' basename="keys[' . $language_name . ']" ')); } $this->data['heading_title'] = $this->language->get('developer_tools_name') . ' - ' . $this->language->get('developer_tools_text_language_file_edit') . ' - ' . $this->request->get['block']; $this->document->setTitle($this->data['heading_title']); $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => false)); $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('tool/developer_tools_languages'), 'text' => $this->language->get('developer_tools_name') . ' - ' . $this->language->get('developer_tools_text_languages'), 'separator' => ' :: ', 'current' => true)); $this->data['languages'] = $languages; $this->view->batchAssign($this->data); $this->processTemplate('pages/tool/developer_tools_language_edit.tpl'); }
public function edit() { $this->loadModel('tool/developer_tools'); $this->loadLanguage('developer_tools/developer_tools'); $prj_id = func_get_arg(0); $config = $this->model_tool_developer_tools->getProjectConfig($prj_id); if ($this->request->server['REQUEST_METHOD'] == 'POST') { foreach ($this->request->post['keys'] as $language_name => $values) { if (!is_array($values)) { continue; } $path = DIR_EXT . $config['extension_txt_id'] . '/' . $this->request->get['section'] . '/language/' . $language_name . '/' . $this->request->get['block']; // for language extensions if ($language_name == $config['extension_txt_id']) { $path = DIR_EXT . $config['extension_txt_id'] . '/' . $this->request->get['section'] . '/language/' . $this->request->get['block']; } $this->model_tool_developer_tools->saveLanguageXML($path, $values); if ($this->model_tool_developer_tools->error) { $this->messages->saveNotice('Developer Tools Notice ("' . $this->request->get['block'] . '")', implode('<br>', $this->model_tool_developer_tools->error)); } $lm = new ALanguageManager($this->registry); $block = str_replace('.xml', '', $this->request->get['block']); $block = str_replace('/', '_', $block); $lm->definitionAutoLoad('all', $this->request->get['section'], $block, 'update'); $this->data['success'] = $this->language->get('text_language_file_edit_success'); } } $this->view->assign('cancel', $this->html->getSecureURL('developer_tools_name')); $this->data['action'] = $this->html->getSecureURL('tool/developer_tools/edit', '&mode=languages&block=' . $this->request->get['block'] . '§ion=' . $this->request->get['section']); $this->data['heading_title'] = $this->language->get('developer_tools_name'); $this->data['update'] = ''; $form = new AForm('HT'); $form->setForm(array('form_name' => 'extLanguageFrm', 'update' => $this->data['update'])); $this->data['form']['id'] = 'extLanguageFrm'; $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'extLanguageFrm', 'action' => $this->data['action'])); $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_save'), 'style' => 'button1')); $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2')); $language_files = $this->model_tool_developer_tools->getLanguageFiles($prj_id); $pathes = $all_keys = array(); // pathes to xml-file foreach ($language_files as $section => $language) { if ($section == $this->request->get['section']) { foreach ($language as $lang => $file) { $languages[] = $lang; $pathes[$lang] = array('path' => '', 'keys' => array()); foreach ($file as $filename) { if ($filename == $this->request->get['block'] || $lang == $config['extension_txt_id'] && $lang . '/' . $filename == $this->request->get['block']) { $path = $section . '/language/' . $lang . '/' . $this->request->get['block']; // for language extensions write if ($lang == $config['extension_txt_id']) { $path = $section . '/language/' . $this->request->get['block']; } $keys = array(); if (is_file(DIR_EXT . $config['extension_txt_id'] . '/' . $path) && filesize(DIR_EXT . $config['extension_txt_id'] . '/' . $path)) { $xml = simplexml_load_file(DIR_EXT . $config['extension_txt_id'] . '/' . $path); foreach ($xml->definition as $def) { $keys[trim((string) $def->key)] = trim((string) $def->value); } // collect key names from all language variants $all_keys = array_merge($all_keys, array_keys($keys)); } $pathes[$lang] = array('path' => $path, 'keys' => $keys); break; } } } } } $all_keys = array_unique($all_keys); foreach ($all_keys as $key) { if (!$key) { continue; } $this->data['form']['fields'][$key]['text'] = $key; foreach ($languages as $language_name) { $this->data['form']['fields'][$key]['field'][$language_name] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'keys[' . $language_name . '][' . $key . ']', 'value' => $pathes[$language_name]['keys'][$key], 'style' => 'large-field')); } } // build prototype for new key form elements foreach ($languages as $language_name) { $this->data['form']['proto']['text'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'newkey', 'value' => '', 'attr' => ' autocomplete="off" ', 'style' => 'medium-field')); $this->data['form']['proto']['field'][$language_name] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'keys[' . $language_name . '][]', 'value' => '', 'attr' => ' basename="keys[' . $language_name . ']" ', 'style' => 'large-field')); } $this->data['heading'] = $this->language->get('text_language_file_edit') . ' - ' . $this->request->get['block']; $this->data['languages'] = $languages; $this->view->batchAssign($this->data); $this->processTemplate('responses/tool/developer_tools_language_edit.tpl'); }