?> :</p> <pre> <b>id</b>;<b>parent_id</b>;<b>name</b>;<b>description</b> <b>2</b>;<b>1</b>;<b>Chamilo Expert</b>;Chamilo is an open source LMS;<br /> </pre> <!--p><?php echo get_lang('XMLMustLookLike') . ' (' . get_lang('MandatoryFields') . ')'; ?> :</p> <blockquote> <pre> <?xml version="1.0" encoding="<?php echo api_refine_encoding_id(api_get_system_encoding()); ?> "?> <Skills> <Skill> <b><id>n</id></b> <b><parent_id>n</parent_id></b> <b><name>xxx</name></b> <description>xxx</description> </Skill> </Skills> </pre> </blockquote--> <?php Display::display_footer();
/** * Converts character encoding of a xml-formatted text. If inside the text the encoding is declared, it is modified accordingly. * @param string $string The text being converted. * @param string $to_encoding The encoding that text is being converted to. * @param string $from_encoding (optional) The encoding that text is being converted from. If the value is empty, it is tried to be detected then. * @return string Returns the converted xml-text. */ function _api_convert_encoding_xml(&$string, $to_encoding, $from_encoding) { if (empty($from_encoding)) { $from_encoding = api_detect_encoding_xml($string); } $to_encoding = api_refine_encoding_id($to_encoding); if (!preg_match('/<\\?xml.*\\?>/m', $string, $matches)) { return api_convert_encoding('<?xml version="1.0" encoding="' . $to_encoding . '"?>' . "\n" . $string, $to_encoding, $from_encoding); } if (!preg_match(_PCRE_XML_ENCODING, $string)) { if (strpos($matches[0], 'standalone') !== false) { // The encoding option should precede the standalone option, othewise DOMDocument fails to load the document. $replace = str_replace('standalone', ' encoding="' . $to_encoding . '" standalone', $matches[0]); } else { $replace = str_replace('?>', ' encoding="' . $to_encoding . '"?>', $matches[0]); } return api_convert_encoding(str_replace($matches[0], $replace, $string), $to_encoding, $from_encoding); } global $_api_encoding; $_api_encoding = api_refine_encoding_id($to_encoding); return api_convert_encoding(preg_replace_callback(_PCRE_XML_ENCODING, '_api_convert_encoding_xml_callback', $string), $to_encoding, $from_encoding); }
/** * Sets the encoding * @param string New encoding * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed. */ public function set_encoding($enc = 'UTF-8') { if ($this->debug > 0) { error_log('New LP - In learnpath::set_encoding()', 0); } $course_id = api_get_course_int_id(); /* // Deprecated code (Chamilo 1.8.8). $enc = strtoupper($enc); $encodings = array ( 'UTF-8', 'ISO-8859-1', 'ISO-8859-15', 'cp1251', 'cp1252', 'KOI8-R', 'BIG5', 'GB2312', 'Shift_JIS', 'EUC-JP', '' ); if (in_array($enc, $encodings)) { // TODO: Incorrect comparison, fix it. $lp = $this->get_id(); if ($lp != 0) { $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN); $sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = " . $lp; $res = Database::query($sql); return $res; } } return false; */ $enc = api_refine_encoding_id($enc); if (empty($enc)) { $enc = api_get_system_encoding(); } if (api_is_encoding_supported($enc)) { $lp = $this->get_id(); if ($lp != 0) { $tbl_lp = Database::get_course_table(TABLE_LP_MAIN); $sql = "UPDATE {$tbl_lp} SET default_encoding = '{$enc}' WHERE c_id = " . $course_id . " AND id = " . $lp; $res = Database::query($sql); return $res; } } return false; }
function _api_convert_encoding_supports($encoding) { static $supports = array(); if (!isset($supports[$encoding])) { $supports[$encoding] = _api_get_character_map_name(api_refine_encoding_id($encoding)) != ''; } return $supports[$encoding]; }
/** * Detects the encoding of a given manifest (a xml-text). * It is possible the encoding of the manifest to be wrongly declared or * not to be declared at all. The proposed method tries to resolve these problems. * @param string $xml The input xml-text. * @return string The detected value of the input xml. */ private function detect_manifest_encoding(&$xml) { if (api_is_valid_utf8($xml)) { return 'UTF-8'; } if (preg_match(_PCRE_XML_ENCODING, $xml, $matches)) { $declared_encoding = api_refine_encoding_id($matches[1]); } else { $declared_encoding = ''; } if (!empty($declared_encoding) && !api_is_utf8($declared_encoding)) { return $declared_encoding; } $test_string = ''; if (preg_match_all('/<langstring[^>]*>(.*)<\\/langstring>/m', $xml, $matches)) { $test_string = implode("\n", $matches[1]); unset($matches); } if (preg_match_all('/<title[^>]*>(.*)<\\/title>/m', $xml, $matches)) { $test_string .= "\n" . implode("\n", $matches[1]); unset($matches); } if (empty($test_string)) { $test_string = $xml; } return api_detect_encoding($test_string); }
?> <p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p> <blockquote> <pre> <b>LastName</b>;<b>FirstName</b>;<b>Email</b>;UserName;Password;OfficialCode;PhoneNumber; <b>Montoya</b>;<b>Julio</b>;<b>info@localhost</b>;jmontoya;123456789;code1;3141516 <b>Doewing</b>;<b>Johny</b>;<b>info@localhost</b>;jdoewing;123456789;code2;3141516 </pre> </blockquote> <p><?php echo get_lang('XMLMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p> <blockquote> <pre> <?xml version="1.0" encoding="<?php echo api_refine_encoding_id(api_get_system_encoding()); ?>"?> <Contacts> <Contact> <b><LastName>Montoya</LastName></b> <b><FirstName>Julio</FirstName></b> <b><Email>info@localhost</Email></b> <UserName>jmontoya</UserName> <Password>123456</Password> <OfficialCode>code1</OfficialCode> <PhoneNumber>3141516</PhoneNumber> </Contact> </Contacts> </pre> </blockquote> <?php /*
/** * Sets the encoding * @param string New encoding * TODO (as of Chamilo 1.8.8): Check in the future whether this method is needed. */ public function set_encoding($enc = 'UTF-8') { if ($this->debug > 0) { error_log('New LP - In learnpath::set_encoding()', 0); } $course_id = api_get_course_int_id(); $enc = api_refine_encoding_id($enc); if (empty($enc)) { $enc = api_get_system_encoding(); } if (api_is_encoding_supported($enc)) { $lp = $this->get_id(); if ($lp != 0) { $tbl_lp = Database::get_course_table(TABLE_LP_MAIN); $sql = "UPDATE {$tbl_lp} SET default_encoding = '{$enc}' WHERE c_id = " . $course_id . " AND id = " . $lp; $res = Database::query($sql); return $res; } } return false; }
function generate_settings_form($settings, $settings_by_access_list) { global $_configuration, $settings_to_avoid, $convert_byte_to_mega_list; $table_settings_current = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); $form = new FormValidator('settings', 'post', 'settings.php?category=' . Security::remove_XSS($_GET['category'])); $form->addElement('hidden', 'search_field', !empty($_GET['search_field']) ? Security::remove_XSS($_GET['search_field']) : null); $url_id = api_get_current_access_url_id(); if (!empty($_configuration['multiple_access_urls']) && api_is_global_platform_admin() && $url_id == 1) { $group = array(); $group[] = $form->createElement('button', 'mark_all', get_lang('MarkAll')); $group[] = $form->createElement('button', 'unmark_all', get_lang('UnmarkAll')); $form->addGroup($group, 'buttons_in_action_right'); } $default_values = array(); $url_info = api_get_access_url($url_id); $i = 0; foreach ($settings as $row) { if (in_array($row['variable'], array_keys($settings_to_avoid))) { continue; } if (!empty($_configuration['multiple_access_urls'])) { if (api_is_global_platform_admin()) { if ($row['access_url_locked'] == 0) { if ($url_id == 1) { if ($row['access_url_changeable'] == '1') { $form->addElement('html', '<div style="float: right;"><a class="share_this_setting" data_status = "0" data_to_send = "' . $row['variable'] . '" href="javascript:void(0);">' . Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')) . '</a></div>'); } else { $form->addElement('html', '<div style="float: right;"><a class="share_this_setting" data_status = "1" data_to_send = "' . $row['variable'] . '" href="javascript:void(0);">' . Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')) . '</a></div>'); } } else { if ($row['access_url_changeable'] == '1') { $form->addElement('html', '<div style="float: right;">' . Display::return_icon('shared_setting.png', get_lang('ChangeSharedSetting')) . '</div>'); } else { $form->addElement('html', '<div style="float: right;">' . Display::return_icon('shared_setting_na.png', get_lang('ChangeSharedSetting')) . '</div>'); } } } } } $hideme = array(); $hide_element = false; if ($_configuration['access_url'] != 1) { if ($row['access_url_changeable'] == 0) { // We hide the element in other cases (checkbox, radiobutton) we 'freeze' the element. $hide_element = true; $hideme = array('disabled'); } elseif ($url_info['active'] == 1) { // We show the elements. if (empty($row['variable'])) { $row['variable'] = 0; } if (empty($row['subkey'])) { $row['subkey'] = 0; } if (empty($row['category'])) { $row['category'] = 0; } if (is_array($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']])) { // We are sure that the other site have a selected value. if ($settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value'] != '') { $row['selected_value'] = $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']]['selected_value']; } } // There is no else{} statement because we load the default $row['selected_value'] of the main Chamilo site. } } switch ($row['type']) { case 'textfield': if (in_array($row['variable'], $convert_byte_to_mega_list)) { $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment']), get_lang('MB')), array('class' => 'span1', 'maxlength' => '8')); $form->applyFilter($row['variable'], 'html_filter'); $default_values[$row['variable']] = round($row['selected_value'] / 1024 / 1024, 1); } elseif ($row['variable'] == 'account_valid_duration') { $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('maxlength' => '5')); $form->applyFilter($row['variable'], 'html_filter'); $default_values[$row['variable']] = $row['selected_value']; // For platform character set selection: Conversion of the textfield to a select box with valid values. } elseif ($row['variable'] == 'platform_charset') { $current_system_encoding = api_refine_encoding_id(trim($row['selected_value'])); $valid_encodings = array_flip(api_get_valid_encodings()); if (!isset($valid_encodings[$current_system_encoding])) { $is_alias_encoding = false; foreach ($valid_encodings as $encoding) { if (api_equal_encodings($encoding, $current_system_encoding)) { $is_alias_encoding = true; $current_system_encoding = $encoding; break; } } if (!$is_alias_encoding) { $valid_encodings[$current_system_encoding] = $current_system_encoding; } } foreach ($valid_encodings as $key => &$encoding) { if (api_is_encoding_supported($key) && Database::is_encoding_supported($key)) { $encoding = $key; } else { unset($valid_encodings[$key]); } } $form->addElement('select', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), $valid_encodings); $default_values[$row['variable']] = $current_system_encoding; } else { $hideme['class'] = 'span4'; $form->addElement('text', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), $hideme); $form->applyFilter($row['variable'], 'html_filter'); $default_values[$row['variable']] = $row['selected_value']; } break; case 'textarea': if ($row['variable'] == 'header_extra_content') { $file = api_get_path(SYS_PATH) . api_get_home_path() . 'header_extra_content.txt'; $value = ''; if (file_exists($file)) { $value = file_get_contents($file); } $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('class' => 'span6', 'rows' => '10'), $hideme); $default_values[$row['variable']] = $value; } elseif ($row['variable'] == 'footer_extra_content') { $file = api_get_path(SYS_PATH) . api_get_home_path() . 'footer_extra_content.txt'; $value = ''; if (file_exists($file)) { $value = file_get_contents($file); } $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('rows' => '10', 'class' => 'span6'), $hideme); $default_values[$row['variable']] = $value; } else { $form->addElement('textarea', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), array('rows' => '10', 'class' => 'span6'), $hideme); $default_values[$row['variable']] = $row['selected_value']; } break; case 'radio': $values = api_get_settings_options($row['variable']); $group = array(); if (is_array($values)) { foreach ($values as $key => $value) { $element =& $form->createElement('radio', $row['variable'], '', get_lang($value['display_text']), $value['value']); if ($hide_element) { $element->freeze(); } $group[] = $element; } } $form->addGroup($group, $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), '', false); //julio $default_values[$row['variable']] = $row['selected_value']; break; case 'checkbox': // 1. We collect all the options of this variable. $sql = "SELECT * FROM {$table_settings_current} WHERE variable='" . $row['variable'] . "' AND access_url = 1"; $result = Database::query($sql); $group = array(); while ($rowkeys = Database::fetch_array($result)) { //if ($rowkeys['variable'] == 'course_create_active_tools' && $rowkeys['subkey'] == 'enable_search') { continue; } // Profile tab option should be hidden when the social tool is enabled. if (api_get_setting('allow_social_tool') == 'true') { if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_profile') { continue; } } // Hiding the gradebook option. if ($rowkeys['variable'] == 'show_tabs' && $rowkeys['subkey'] == 'my_gradebook') { continue; } $element =& $form->createElement('checkbox', $rowkeys['subkey'], '', get_lang($rowkeys['subkeytext'])); if ($row['access_url_changeable'] == 1) { // 2. We look into the DB if there is a setting for a specific access_url. $access_url = $_configuration['access_url']; if (empty($access_url)) { $access_url = 1; } $sql = "SELECT selected_value FROM {$table_settings_current} WHERE variable='" . $rowkeys['variable'] . "' AND subkey='" . $rowkeys['subkey'] . "' AND subkeytext='" . $rowkeys['subkeytext'] . "' AND access_url = {$access_url}"; $result_access = Database::query($sql); $row_access = Database::fetch_array($result_access); if ($row_access['selected_value'] == 'true' && !$form->isSubmitted()) { $element->setChecked(true); } } else { if ($rowkeys['selected_value'] == 'true' && !$form->isSubmitted()) { $element->setChecked(true); } } if ($hide_element) { $element->freeze(); } $group[] = $element; } $form->addGroup($group, $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), ''); break; case 'link': $form->addElement('static', null, array(get_lang($row['title']), get_lang($row['comment'])), get_lang('CurrentValue') . ' : ' . $row['selected_value'], $hideme); break; case 'select': /* * To populate the list of options, the select type dynamically calls a function that must be called select_ + the name of the variable being displayed. * The functions being called must be added to the file settings.lib.php. */ $form->addElement('select', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), call_user_func('select_' . $row['variable']), $hideme); $default_values[$row['variable']] = $row['selected_value']; break; case 'custom': break; } switch ($row['variable']) { case 'pdf_export_watermark_enable': $url = PDF::get_watermark(null); if ($url != false) { $delete_url = '<a href="?delete_watermark">' . get_lang('DelImage') . ' ' . Display::return_icon('delete.png', get_lang('DelImage')) . '</a>'; $form->addElement('html', '<div style="max-height:100px; max-width:100px; margin-left:162px; margin-bottom:10px; clear:both;"><img src="' . $url . '" style="margin-bottom:10px;" />' . $delete_url . '</div>'); } $form->addElement('file', 'pdf_export_watermark_path', get_lang('AddWaterMark')); $allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif'); $form->addRule('pdf_export_watermark_path', get_lang('OnlyImagesAllowed') . ' (' . implode(',', $allowed_picture_types) . ')', 'filetype', $allowed_picture_types); break; case 'timezone_value': $timezone = $row['selected_value']; if (empty($timezone)) { $timezone = _api_get_timezone(); } $form->addElement('html', sprintf(get_lang('LocalTimeUsingPortalTimezoneXIsY'), $timezone, api_get_local_time())); break; } } // end for if (!empty($settings)) { $form->setDefaults($default_values); } $form->addElement('button', 'submit_fixed_in_bottom', get_lang('SaveSettings'), 'class="save"'); return $form; }
/** * Detects encoding of plain text. * @param string $string The input text. * @param string $language (optional) The language of the input text, provided if it is known. * @return string Returns the detected encoding. */ function api_detect_encoding($string, $language = null) { // Testing against valid UTF-8 first. if (api_is_valid_utf8($string)) { return 'UTF-8'; } $result = null; $delta_points_min = LANGUAGE_DETECT_MAX_DELTA; // Testing non-UTF-8 encodings. $encodings = api_get_valid_encodings(); foreach ($encodings as &$encoding) { if (api_is_encoding_supported($encoding) && !api_is_utf8($encoding)) { $stringToParse = api_substr($string, 0, LANGUAGE_DETECT_MAX_LENGTH, $encoding); $strintToParse2 = _api_generate_n_grams($stringToParse, $encoding); $result_array = _api_compare_n_grams($strintToParse2, $encoding); if (!empty($result_array)) { list($key, $delta_points) = each($result_array); if ($delta_points < $delta_points_min) { $pos = strpos($key, ':'); $result_encoding = api_refine_encoding_id(substr($key, $pos + 1)); if (api_equal_encodings($encoding, $result_encoding)) { if ($string == api_utf8_decode(api_utf8_encode($string, $encoding), $encoding)) { $delta_points_min = $delta_points; $result = $encoding; } } } } } } // "Broken" UTF-8 texts are to be detected as UTF-8. // This functionality is enabled when language of the text is known. $language = api_purify_language_id((string) $language); if (!empty($language)) { $encoding = 'UTF-8'; $result_array =& _api_compare_n_grams(_api_generate_n_grams(api_substr($string, 0, LANGUAGE_DETECT_MAX_LENGTH, $encoding), $encoding), $encoding); if (!empty($result_array)) { list($key, $delta_points) = each($result_array); if ($delta_points < $delta_points_min) { $pos = strpos($key, ':'); $result_encoding = api_refine_encoding_id(substr($key, $pos + 1)); $result_language = substr($key, 0, $pos); if ($language == $result_language && api_is_utf8($result_encoding)) { $delta_points_min = $delta_points; $result = $encoding; } } } } return $result; }