/** * Check if a context name already exists in the admin dictionary * If not then insert it * * @param array $array Associative array ('lang' => 'language code', 'name' => 'context name') * @param integer $xon Context status * @return void */ public function check_dictionary($array, $xon = 0) { // prepare post array $post = array('area' => 'admin', 'lang' => $array['lang'], 'what' => 'articles', 'xkey' => '_CONTEXT_' . strtoupper($array['name']), 'xval' => ucfirst($array['name']), 'xon' => $xon); // check if context exists $dict = new Dictionary_model(); $check = $dict->exists($post); // insert if (!$check) { $dict->insert($post); } }
/** * Perform the importing of words * * @access private * @param array $_post _POST array * @return void */ private function importing($_post) { $msg = null; // check permission $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_key_import', 0, 4); if (is_null($msg)) { // get key list($lang, $area, $what) = explode('-', $_post['what']); // handle _post $post = array('lang' => $_post['lang'], 'area' => $_post['area'], 'what' => $what, 'xon' => 1); // set the translator X4Core_core::auto_load('google_translate_library'); $translator = new GoogleTranslate($lang, $post['lang']); // get words to import $dict = new Dictionary_model(); if ($what == 'ALL') { // import all sections in an area $sections = $dict->get_sections($lang, $area); $result = true; foreach ($sections as $s) { // get words in section $words = $dict->get_words_to_import($lang, $area, $s->what, $post['lang'], $post['area']); if (!empty($words)) { $post['what'] = $s->what; // import foreach ($words as $i) { $post['xkey'] = $i->xkey; // try to translate if ($lang != $post['lang']) { $value = $translator->translate($i->xval); } else { $value = $i->xval; } // set the word $post['xval'] = $value; // insert $result = $dict->insert($post); // add permission if ($result[1]) { $amod = new Area_model(); $id_area = $amod->get_area_id($_post['area']); $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('dictionary', $array, $id_area); } } } } // set what for redirect $what = 'global'; } else { // import only one section $words = $dict->get_words_to_import($lang, $area, $what, $post['lang'], $post['area']); $result = true; // import foreach ($words as $i) { $post['xkey'] = $i->xkey; // try to translate if ($lang != $post['lang']) { $value = $translator->translate($i->xval); } else { $value = $i->xval; } // set the word $post['xval'] = $value; // insert $result = $dict->insert($post); // add permission if ($result[1]) { $amod = new Area_model(); $id_area = $amod->get_area_id($_post['area']); $perm = new Permission_model(); $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4); $res = $perm->pexec('dictionary', $array, $id_area); } } } $msg = AdmUtils_helper::set_msg($result); // set what update if ($result[1]) { $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'dictionary/keys/' . $post['lang'] . '/' . $post['area'] . '/' . $what, 'title' => null); } } $this->response($msg); }