本文整理汇总了PHP中api_detect_encoding函数的典型用法代码示例。如果您正苦于以下问题:PHP api_detect_encoding函数的具体用法?PHP api_detect_encoding怎么用?PHP api_detect_encoding使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了api_detect_encoding函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: api_detect_encoding_html
/**
* Detects encoding of html-formatted text.
* @param string $string The input html-formatted text.
* @return string Returns the detected encoding.
*/
function api_detect_encoding_html($string) {
if (@preg_match('/<head.*(<meta[^>]*content=[^>]*>).*<\/head>/si', $string, $matches)) {
if (@preg_match('/<meta[^>]*charset=(.*)["\';][^>]*>/si', $matches[1], $matches)) {
return api_refine_encoding_id(trim($matches[1]));
}
}
return api_detect_encoding(api_html_to_text($string));
}
示例2: csv_to_array
/**
* Reads a CSV-file into an array. The first line of the CSV-file should contain the array-keys.
* The encoding of the input file is tried to be detected.
* The elements of the returned array are encoded in the system encoding.
* Example:
* FirstName;LastName;Email
* John;Doe;john.doe@mail.com
* Adam;Adams;adam@mail.com
* returns
* $result [0]['FirstName'] = 'John';
* $result [0]['LastName'] = 'Doe';
* $result [0]['Email'] = 'john.doe@mail. com';
* $result [1]['FirstName'] = 'Adam';
* ...
* @param string $filename The path to the CSV-file which should be imported.
* @return array Returns an array (in the system encoding) that contains all data from the CSV-file.
*
*
* @deprecated use cvs_reader instead
*/
static function csv_to_array($filename, $csv_order = 'vertical')
{
$result = array();
// Encoding detection.
$handle = fopen($filename, 'r');
if ($handle === false) {
return $result;
}
$buffer = array();
$i = 0;
while (!feof($handle) && $i < 200) {
// We assume that 200 lines are enough for encoding detection.
$buffer[] = fgets($handle);
$i++;
}
fclose($handle);
$buffer = implode("\n", $buffer);
$from_encoding = api_detect_encoding($buffer);
unset($buffer);
// Reading the file, parsing and importing csv data.
$handle = fopen($filename, 'r');
if ($handle === false) {
return $result;
}
if ($csv_order == 'vertical') {
$keys = Text::api_fgetcsv($handle, null, ';');
foreach ($keys as $key => &$key_value) {
$key_value = api_to_system_encoding($key_value, $from_encoding);
}
}
while (($row_tmp = Text::api_fgetcsv($handle, null, ';')) !== false) {
$row = array();
// Avoid empty lines in csv
if (is_array($row_tmp) && count($row_tmp) > 0 && $row_tmp[0] != '') {
if (!is_null($row_tmp[0])) {
if ($csv_order == 'vertical') {
foreach ($row_tmp as $index => $value) {
$row[$keys[$index]] = api_to_system_encoding($value, $from_encoding);
}
} else {
$first = null;
$count = 1;
foreach ($row_tmp as $index => $value) {
if ($count == 1) {
$first = $value;
} else {
$row[$first][] = api_to_system_encoding($value, $from_encoding);
}
$count++;
}
}
$result[] = $row;
}
}
}
fclose($handle);
return $result;
}
示例3: restore
/**
* Restore a course.
* @param string The code of the Chamilo-course in
* @param int The session id
* @param bool Course settings are going to be restore?
*/
public function restore($destination_course_code = '', $session_id = 0, $update_course_settings = false, $respect_base_content = false)
{
if ($destination_course_code == '') {
$course_info = api_get_course_info();
$this->destination_course_info = $course_info;
$this->course->destination_path = $course_info['path'];
} else {
$course_info = api_get_course_info($destination_course_code);
$this->destination_course_info = $course_info;
$this->course->destination_path = $course_info['path'];
}
$this->destination_course_id = $course_info['real_id'];
//Getting first teacher (for the forums)
$teacher_list = CourseManager::get_teacher_list_from_course_code($course_info['real_id']);
$this->first_teacher_id = api_get_user_id();
if (!empty($teacher_list)) {
foreach ($teacher_list as $teacher) {
$this->first_teacher_id = $teacher['user_id'];
break;
}
}
if (empty($this->course)) {
return false;
}
// Source platform encoding - reading/detection
// The correspondent data field has been added as of version 1.8.6.1
if (empty($this->course->encoding)) {
// The archive has been created by a system which is prior to 1.8.6.1 version.
// In this case we have to detect the encoding.
$sample_text = $this->course->get_sample_text() . "\n";
// Let us exclude ASCII lines, probably they are English texts.
$sample_text = explode("\n", $sample_text);
foreach ($sample_text as $key => &$line) {
if (api_is_valid_ascii($line)) {
unset($sample_text[$key]);
}
}
$sample_text = join("\n", $sample_text);
$this->course->encoding = api_detect_encoding($sample_text, $course_info['language']);
}
// Encoding conversion of the course, if it is needed.
$this->course->to_system_encoding();
foreach ($this->tools_to_restore as $tool) {
$function_build = 'restore_' . $tool;
$this->{$function_build}($session_id, $respect_base_content, $destination_course_code);
}
if ($update_course_settings) {
$this->restore_course_settings($destination_course_code);
}
// Restore the item properties
$table = Database::get_course_table(TABLE_ITEM_PROPERTY);
$condition_session = "";
if (!empty($session_id)) {
$condition_session = " , id_session='" . intval($session_id) . "'";
}
foreach ($this->course->resources as $type => $resources) {
if (is_array($resources)) {
foreach ($resources as $id => $resource) {
foreach ($resource->item_properties as $property) {
// First check if there isn't allready a record for this resource
$sql = "SELECT * FROM {$table} WHERE c_id = " . $this->destination_course_id . " AND tool = '" . $property['tool'] . "' AND ref = '" . $resource->destination_id . "'";
$res = Database::query($sql);
if (Database::num_rows($res) == 0) {
// The to_group_id and to_user_id are set to default values as users/groups possibly not exist in the target course
$sql = "INSERT INTO {$table} SET\n\t\t\t\t\t\t\t\t\tc_id \t\t\t\t= '" . $this->destination_course_id . "',\n\t\t\t\t\t\t\t\t\ttool \t\t\t\t= '" . self::DBUTF8escapestring($property['tool']) . "',\n\t\t\t\t\t\t\t\t\tinsert_user_id \t\t= '" . self::DBUTF8escapestring($property['insert_user_id']) . "',\n\t\t\t\t\t\t\t\t\tinsert_date \t\t= '" . self::DBUTF8escapestring($property['insert_date']) . "',\n\t\t\t\t\t\t\t\t\tlastedit_date \t\t= '" . self::DBUTF8escapestring($property['lastedit_date']) . "',\n\t\t\t\t\t\t\t\t\tref \t\t\t\t= '" . self::DBUTF8escapestring($resource->destination_id) . "',\n\t\t\t\t\t\t\t\t\tlastedit_type \t\t= '" . self::DBUTF8escapestring($property['lastedit_type']) . "',\n\t\t\t\t\t\t\t\t\tlastedit_user_id \t= '" . self::DBUTF8escapestring($property['lastedit_user_id']) . "',\n\t\t\t\t\t\t\t\t\tvisibility \t\t\t= '" . self::DBUTF8escapestring($property['visibility']) . "',\n\t\t\t\t\t\t\t\t\tstart_visible \t\t= '" . self::DBUTF8escapestring($property['start_visible']) . "',\n\t\t\t\t\t\t\t\t\tend_visible \t\t= '" . self::DBUTF8escapestring($property['end_visible']) . "',\n\t\t\t\t\t\t\t\t\tto_user_id \t\t= '" . self::DBUTF8escapestring($property['to_user_id']) . "',\n\t\t\t\t\t\t\t\t\tto_group_id \t\t= '0' {$condition_session}";
Database::query($sql);
}
}
}
}
}
}
示例4: string_send_for_download
/**
* This function streams a string to the client for download.
* You have to ensure that the calling script then stops processing (exit();)
* otherwise it may cause subsequent use of the page to want to download
* other pages in php rather than interpreting them.
*
* @param string $full_string The string contents
* @param boolean $forced Whether "save" mode is forced (or opening directly authorized)
* @param string $name The name of the file in the end (including extension)
*
* @return false if file doesn't exist, true if stream succeeded
*/
public static function string_send_for_download($full_string, $forced = false, $name = '')
{
$filename = $name;
$len = strlen($full_string);
if ($forced) {
//force the browser to save the file instead of opening it
header('Content-type: application/octet-stream');
//header('Content-Type: application/force-download');
header('Content-length: ' . $len);
if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
header('Content-Disposition: filename= ' . $filename);
} else {
header('Content-Disposition: attachment; filename= ' . $filename);
}
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
header('Pragma: ');
header('Cache-Control: ');
header('Cache-Control: public');
// IE cannot download from sessions without a cache
}
header('Content-Description: ' . $filename);
header('Content-transfer-encoding: binary');
echo $full_string;
return true;
//You have to ensure that the calling script then stops processing (exit();)
//otherwise it may cause subsequent use of the page to want to download
//other pages in php rather than interpreting them.
} else {
//no forced download, just let the browser decide what to do according to the mimetype
$content_type = self::file_get_mime_type($filename);
header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
switch ($content_type) {
case 'text/html':
$encoding = @api_detect_encoding_html($full_string);
if (!empty($encoding)) {
$content_type .= '; charset=' . $encoding;
}
break;
case 'text/plain':
$encoding = @api_detect_encoding(strip_tags($full_string));
if (!empty($encoding)) {
$content_type .= '; charset=' . $encoding;
}
break;
}
header('Content-type: ' . $content_type);
header('Content-Length: ' . $len);
$user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($user_agent, 'msie')) {
header('Content-Disposition: ; filename= ' . $filename);
} else {
header('Content-Disposition: inline; filename= ' . $filename);
}
echo $full_string;
//You have to ensure that the calling script then stops processing (exit();)
//otherwise it may cause subsequent use of the page to want to download
//other pages in php rather than interpreting them.
return true;
}
}
示例5: detect_manifest_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);
}
示例6: api_get_current_access_url_id
if (api_is_multiple_url_enabled()) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url_info = api_get_access_url($access_url_id);
$url = api_remove_trailing_slash(preg_replace('/https?:\\/\\//i', '', $url_info['url']));
$clean_url = api_replace_dangerous_char($url);
$clean_url = str_replace('/', '-', $clean_url);
$clean_url .= '/';
$home_old = api_get_path(SYS_APP_PATH) . 'home/';
$home = api_get_path(SYS_APP_PATH) . 'home/' . $clean_url;
}
}
if (file_exists($home . 'register_top_' . $user_selected_language . '.html')) {
$home_top_temp = @(string) file_get_contents($home . 'register_top_' . $user_selected_language . '.html');
$open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
$open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
if (!empty($open)) {
$content = '<div class="well_border">' . $open . '</div>';
}
}
// Forbidden to self-register
if ($isNotAllowedHere) {
api_not_allowed(true, get_lang('RegistrationDisabled'));
}
if (api_get_setting('registration.allow_registration') == 'approval') {
$content .= Display::return_message(get_lang('YourAccountHasToBeApproved'));
}
//if openid was not found
if (!empty($_GET['openid_msg']) && $_GET['openid_msg'] == 'idnotfound') {
$content .= Display::return_message(get_lang('OpenIDCouldNotBeFoundPleaseRegister'));
}
示例7: returnHomePage
/**
* Return the homepage, including announcements
* @return string The portal's homepage as an HTML string
* @assert () != ''
*/
public function returnHomePage()
{
// Including the page for the news
$html = null;
$home = api_get_path(SYS_DATA_PATH) . api_get_home_path();
$home_top_temp = null;
if (!empty($_GET['include']) && preg_match('/^[a-zA-Z0-9_-]*\\.html$/', $_GET['include'])) {
$open = @(string) file_get_contents(api_get_path(SYS_PATH) . $home . $_GET['include']);
$html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
} else {
$user_selected_language = api_get_user_language();
if (!file_exists($home . 'home_news_' . $user_selected_language . '.html')) {
if (file_exists($home . 'home_top.html')) {
$home_top_temp = file($home . 'home_top.html');
} else {
//$home_top_temp = file('home/'.'home_top.html');
}
if (!empty($home_top_temp)) {
$home_top_temp = implode('', $home_top_temp);
}
} else {
if (file_exists($home . 'home_top_' . $user_selected_language . '.html')) {
$home_top_temp = file_get_contents($home . 'home_top_' . $user_selected_language . '.html');
} else {
$home_top_temp = file_get_contents($home . 'home_top.html');
}
}
if (empty($home_top_temp) && api_is_platform_admin()) {
$home_top_temp = get_lang('PortalHomepageDefaultIntroduction');
}
$open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
if (!empty($open)) {
$html = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
}
}
return $html;
}
示例8: return_help
function return_help() {
$user_selected_language = api_get_interface_language();
$sys_path = api_get_path(SYS_PATH);
$platformLanguage = api_get_setting('platformLanguage');
// Help section.
/* Hide right menu "general" and other parts on anonymous right menu. */
if (!isset($user_selected_language)) {
$user_selected_language = $platformLanguage;
}
$html = null;
$home_menu = @(string)file_get_contents($sys_path.$this->home.'home_menu_'.$user_selected_language.'.html');
if (!empty($home_menu)) {
$home_menu_content = '<ul class="nav nav-list">';
$home_menu_content .= api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
$home_menu_content .= '</ul>';
$html .= self::show_right_block(get_lang('MenuGeneral'), $home_menu_content, 'help_block');
}
return $html;
}
示例9: array
if (file_exists($homep . $mtloggedin . '_' . $lang . $ext)) {
$home_menu = @file($homep . $mtloggedin . '_' . $lang . $ext);
} else {
$home_menu = @file($homep . $mtloggedin . $ext);
}
if (empty($home_menu)) {
if (file_exists($homep . $menutabs . '_' . $lang . $ext)) {
$home_menu = @file($homep . $menutabs . '_' . $lang . $ext);
}
}
if (empty($home_menu)) {
$home_menu = array();
}
if (!empty($home_menu)) {
$home_menu = implode("\n", $home_menu);
$home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
$home_menu = explode("\n", $home_menu);
}
$link_list = '';
$tab_counter = 0;
foreach ($home_menu as $enreg) {
$enreg = trim($enreg);
if (!empty($enreg)) {
$edit_link = ' <a href="' . $selfUrl . '?action=edit_tabs&link_index=' . $tab_counter . '" ><span>' . Display::return_icon('edit.png', get_lang('Edit')) . '</span></a>';
$delete_link = ' <a href="' . $selfUrl . '?action=delete_tabs&link_index=' . $tab_counter . '" onclick="javascript: if(!confirm(\'' . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)) . '\')) return false;"><span>' . Display::return_icon('delete.png', get_lang('Delete')) . '</span></a>';
$tab_string = str_replace(array('href="' . api_get_path(WEB_PATH) . 'index.php?include=', '</li>'), array('href="' . api_get_path(WEB_CODE_PATH) . 'admin/' . basename($selfUrl) . '?action=open_link&link=', $edit_link . $delete_link . '</li>'), $enreg);
$tab_string = str_replace(array('<li>', '</li>', 'class="hide_menu"', 'hide_menu'), '', $tab_string);
$link_list .= Display::tag('li', $tab_string, array('class' => 'list-group-item'));
$tab_counter++;
}
}
示例10: return_menu
function return_menu()
{
$navigation = return_navigation_array();
$navigation = $navigation['navigation'];
// Displaying the tabs
$lang = '';
//el for "Edit Language"
if (!empty($_SESSION['user_language_choice'])) {
$lang = $_SESSION['user_language_choice'];
} elseif (!empty($_SESSION['_user']['language'])) {
$lang = $_SESSION['_user']['language'];
} else {
$lang = get_setting('platformLanguage');
}
//Preparing home folder for multiple urls
if (api_get_multiple_access_url()) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url_info = api_get_access_url($access_url_id);
$url = api_remove_trailing_slash(preg_replace('/https?:\\/\\//i', '', $url_info['url']));
$clean_url = replace_dangerous_char($url);
$clean_url = str_replace('/', '-', $clean_url);
$clean_url .= '/';
$homep = api_get_path(SYS_PATH) . 'home/' . $clean_url;
//homep for Home Path
//we create the new dir for the new sites
if (!is_dir($homep)) {
mkdir($homep, api_get_permissions_for_new_directories());
}
}
} else {
$homep = api_get_path(SYS_PATH) . 'home/';
}
$ext = '.html';
$menutabs = 'home_tabs';
$mtloggedin = 'home_tabs_logged_in';
$home_top = '';
if (is_file($homep . $menutabs . '_' . $lang . $ext) && is_readable($homep . $menutabs . '_' . $lang . $ext)) {
$home_top = @(string) file_get_contents($homep . $menutabs . '_' . $lang . $ext);
} elseif (is_file($homep . $menutabs . $lang . $ext) && is_readable($homep . $menutabs . $lang . $ext)) {
$home_top = @(string) file_get_contents($homep . $menutabs . $lang . $ext);
} else {
//$errorMsg = get_lang('HomePageFilesNotReadable');
}
$home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
$open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top);
$open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
$open_mtloggedin = '';
if (api_get_user_id() && !api_is_anonymous()) {
if (is_file($homep . $mtloggedin . '_' . $lang . $ext) && is_readable($homep . $mtloggedin . '_' . $lang . $ext)) {
$home_top = @(string) file_get_contents($homep . $mtloggedin . '_' . $lang . $ext);
$home_top = str_replace('::private', '', $home_top);
} elseif (is_file($homep . $mtloggedin . $lang . $ext) && is_readable($homep . $mtloggedin . $lang . $ext)) {
$home_top = @(string) file_get_contents($homep . $mtloggedin . $lang . $ext);
$home_top = str_replace('::private', '', $home_top);
} else {
//$errorMsg = get_lang('HomePageFilesNotReadable');
}
$home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
$open_mtloggedin = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top);
$open_mtloggedin = api_to_system_encoding($open_mtloggedin, api_detect_encoding(strip_tags($open_mtloggedin)));
}
$lis = '';
if (!empty($open) or !empty($open_mtloggedin)) {
if (strpos($open . $open_mtloggedin, 'show_menu') === false) {
if (api_is_anonymous()) {
$navigation[SECTION_CAMPUS] = null;
}
} else {
//$lis .= Display::tag('li', $open);
if (api_get_user_id() && !api_is_anonymous()) {
$lis .= $open_mtloggedin;
} else {
$lis .= $open;
}
}
}
if (count($navigation) > 0 || !empty($lis)) {
$pre_lis = '';
foreach ($navigation as $section => $navigation_info) {
$key = !empty($navigation_info['key']) ? 'tab-' . $navigation_info['key'] : '';
if (isset($GLOBALS['this_section'])) {
$current = $section == $GLOBALS['this_section'] ? ' id="current" class="active ' . $key . '" ' : ' class="' . $key . '"';
} else {
$current = '';
}
if (!empty($navigation_info['title'])) {
$pre_lis .= '<li' . $current . '><a href="' . $navigation_info['url'] . '" target="_top">' . $navigation_info['title'] . '</a></li>';
}
}
$lis = $pre_lis . $lis;
}
$menu = null;
if (!empty($lis)) {
$menu .= $lis;
}
return $menu;
}
示例11: downloadMP3_pediaphon
/**
* This function save a post into a file mp3 from pediaphon services
*
* @param $filepath
* @param $dir
* @author Juan Carlos Raña Trabado <herodoto@telefonica.net>
* @version january 2011, chamilo 1.8.8
*/
function downloadMP3_pediaphon($filepath, $dir)
{
$location = 'create_audio.php?' . api_get_cidreq() . '&id=' . Security::remove_XSS($_POST['document_id']) . '&dt2a=pediaphon';
//security
if (!isset($_POST['lang']) && !isset($_POST['text']) && !isset($_POST['title']) && !isset($filepath) && !isset($dir)) {
echo '<script>window.location.href="' . $location . '"</script>';
return;
}
global $_course, $_user;
$clean_title = trim($_POST['title']);
$clean_title = Database::escape_string($clean_title);
$clean_text = trim($_POST['text']);
$clean_voices = Security::remove_XSS($_POST['voices']);
if (empty($clean_title) || empty($clean_text) || empty($clean_voices)) {
echo '<script>window.location.href="' . $location . '"</script>';
return;
}
$clean_title = Security::remove_XSS($clean_title);
$clean_title = Database::escape_string($clean_title);
$clean_title = str_replace(' ', '_', $clean_title);
//compound file names
$clean_text = Security::remove_XSS($clean_text);
$clean_lang = Security::remove_XSS($_POST['lang']);
$clean_speed = Security::remove_XSS($_POST['speed']);
$extension = 'mp3';
$audio_filename = $clean_title . '.' . $extension;
$audio_title = str_replace('_', ' ', $clean_title);
//prevent duplicates
if (file_exists($filepath . '/' . $clean_title . '.' . $extension)) {
$i = 1;
while (file_exists($filepath . '/' . $clean_title . '_' . $i . '.' . $extension)) {
$i++;
}
$audio_filename = $clean_title . '_' . $i . '.' . $extension;
$audio_title = $clean_title . '_' . $i . '.' . $extension;
$audio_title = str_replace('_', ' ', $audio_title);
}
$documentPath = $filepath . '/' . $audio_filename;
//prev for a fine unicode, borrowed from main api TODO:clean
// Safe replacements for some non-letter characters (whitout blank spaces)
$search = array("", "\t", "\n", "\r", "\v", '/', "\\", '"', "'", '?', '*', '>', '<', '|', ':', '$', '(', ')', '^', '[', ']', '#', '+', '&', '%');
$replace = array('', '_', '_', '_', '_', '-', '-', '-', '_', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
$filename = $clean_text;
// Encoding detection.
$encoding = api_detect_encoding($filename);
// Converting html-entities into encoded characters.
$filename = api_html_entity_decode($filename, ENT_QUOTES, $encoding);
// Transliteration to ASCII letters, they are not dangerous for filesystems.
$filename = api_transliterate($filename, 'x', $encoding);
// Replacing remaining dangerous non-letter characters.
$clean_text = str_replace($search, $replace, $filename);
//adding the file
if ($clean_lang == 'de') {
$url_pediaphon = 'http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice.cgi';
$find_t2v = '/http\\:\\/\\/www\\.pediaphon\\.org\\/\\~bischoff\\/radiopedia\\/mp3\\/(.*)\\.mp3\\"/';
} else {
$url_pediaphon = 'http://www.pediaphon.org/~bischoff/radiopedia/sprich_multivoice_' . $clean_lang . '.cgi';
//en, es, fr
$find_t2v = '/http\\:\\/\\/www\\.pediaphon\\.org\\/\\~bischoff\\/radiopedia\\/mp3\\/' . $clean_lang . '\\/(.*)\\.mp3\\"/';
}
$data = "stimme=" . $clean_voices . "&inputtext=" . $clean_text . "&speed=" . $clean_speed . "&go=speak";
$opts = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencoded\r\n", "Content-Length: " . strlen($data) . "\r\n", 'content' => $data));
$context = stream_context_create($opts);
// Download the whole HTML page
$previous_returntext2voice = file_get_contents($url_pediaphon, false, $context);
//extract the audio file path
$search_source = preg_match($find_t2v, $previous_returntext2voice, $hits);
$souce_end = substr($hits[0], 0, -1);
//download file
$returntext2voice = file_get_contents($souce_end);
//save file
$f = @file_put_contents($documentPath, $returntext2voice);
if ($f === false && !empty($php_errormsg)) {
error_log($php_errormsg);
}
//add document to database
$current_session_id = api_get_session_id();
$groupId = $_SESSION['_gid'];
$file_size = filesize($documentPath);
$relativeUrlPath = $dir;
$doc_id = add_document($_course, $relativeUrlPath . $audio_filename, 'file', filesize($documentPath), $audio_title);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], $groupId, null, null, null, $current_session_id);
Display::display_confirmation_message(get_lang('DocumentCreated'));
//return to location
echo '<script>window.location.href="' . $location . '"</script>';
}
示例12: api_get_path
echo ' <a href="faq.php?edit=true"><img src="' . api_get_path(WEB_IMG_PATH) . 'edit.png" /></a>';
}
echo Display::page_header(get_lang('Faq'));
$faq_file = 'faq.html';
if (!empty($_GET['edit']) && $_GET['edit'] == 'true' && api_is_platform_admin()) {
$form = new FormValidator('set_faq', 'post', 'faq.php?edit=true');
$form->addHtmlEditor('faq_content', null, false, false, array('ToolbarSet' => 'FAQ', 'Width' => '100%', 'Height' => '300'));
$form->addButtonSave(get_lang('Ok'), 'faq_submit');
$faq_content = @(string) file_get_contents(api_get_path(SYS_APP_PATH) . 'home/faq.html');
$faq_content = api_to_system_encoding($faq_content, api_detect_encoding(strip_tags($faq_content)));
$form->setDefaults(array('faq_content' => $faq_content));
if ($form->validate()) {
$content = $form->getSubmitValue('faq_content');
$fpath = api_get_path(SYS_APP_PATH) . 'home/' . $faq_file;
if (is_file($fpath) && is_writeable($fpath)) {
$fp = fopen(api_get_path(SYS_APP_PATH) . 'home/' . $faq_file, 'w');
fwrite($fp, $content);
fclose($fp);
} else {
Display::display_warning_message(get_lang('WarningFaqFileNonWriteable'));
}
echo $content;
} else {
$form->display();
}
} else {
$faq_content = @(string) file_get_contents(api_get_path(SYS_APP_PATH) . 'home/' . $faq_file);
$faq_content = api_to_system_encoding($faq_content, api_detect_encoding(strip_tags($faq_content)));
echo $faq_content;
}
Display::display_footer();
示例13: _encodeUTF16
function _encodeUTF16($string, $check = false)
{
//var_dump($this->_defaultEncoding.' '.$this->_encoderFunction.' '.$from);
if ($check) {
$from = api_detect_encoding($string);
$string = api_convert_encoding($string, $this->_defaultEncoding, $from);
return $string;
}
$string = api_convert_encoding($string, $this->_defaultEncoding, 'UTF-16LE');
return $string;
/*
* Default behaviour
if ($this->_defaultEncoding){
switch ($this->_encoderFunction){
case 'iconv' : $result = iconv('UTF-16LE', $this->_defaultEncoding, $string);
break;
case 'iconv' : $result = mb_convert_encoding($string, $this->_defaultEncoding, 'UTF-16LE' );
break;
}
}
return $result;
*/
}
示例14: api_replace_dangerous_char
/**
* Replaces "forbidden" characters in a filename string.
*
* @author Hugues Peeters <peeters@ipm.ucl.ac.be>
* @author René Haentjens, UGent (RH)
* @author Ivan Tcholakov, JUN-2009. Transliteration functionality has been added.
* @param string $filename The filename string.
* @param string $strict (optional) When it is 'strict', all non-ASCII charaters will be replaced. Additional ASCII replacemets will be done too.
* @return string The cleaned filename.
*/
function api_replace_dangerous_char($filename, $strict = 'loose')
{
// Safe replacements for some non-letter characters.
static $search = array("", ' ', "\t", "\n", "\r", "\v", '/', "\\", '"', "'", '?', '*', '>', '<', '|', ':', '$', '(', ')', '^', '[', ']', '#', '+', '&', '%');
static $replace = array('', '_', '_', '_', '_', '_', '-', '-', '-', '_', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-');
// Encoding detection.
$encoding = api_detect_encoding($filename);
// Converting html-entities into encoded characters.
$filename = api_html_entity_decode($filename, ENT_QUOTES, $encoding);
// Transliteration to ASCII letters, they are not dangerous for filesystems.
$filename = api_transliterate($filename, 'x', $encoding);
// Trimming leading/trailing whitespace.
$filename = trim($filename);
// Trimming any leading/trailing dots.
$filename = trim($filename, '.');
$filename = trim($filename);
// Replacing remaining dangerous non-letter characters.
$filename = str_replace($search, $replace, $filename);
if ($strict == 'strict') {
//$filename = str_replace('-', '_', $filename); // See task #1848.
//$filename = preg_replace('/[^0-9A-Za-z_.\-]/', '', $filename);
//Removing "_" character see BT#3628
$filename = preg_replace('/[^0-9A-Za-z.\\-_]/', '', $filename);
}
// Length is to be limited, so the file name to be acceptable by some operating systems.
$extension = (string) strrchr($filename, '.');
$extension_len = strlen($extension);
if ($extension_len > 0 && $extension_len < 250) {
$filename = substr($filename, 0, -$extension_len);
return substr($filename, 0, 250 - $extension_len) . $extension;
}
return substr($filename, 0, 250);
}
示例15: returnMenu
/**
* @return null|string
*/
public function returnMenu()
{
return null;
$navigation = $this->navigation_array;
$navigation = $navigation['navigation'];
// Displaying the tabs
$lang = api_get_user_language();
// Preparing home folder for multiple urls
if (api_get_multiple_access_url()) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url_info = api_get_current_access_url_info();
$url = api_remove_trailing_slash(preg_replace('/https?:\\/\\//i', '', $url_info['url']));
$clean_url = api_replace_dangerous_char($url);
$clean_url = str_replace('/', '-', $clean_url);
$clean_url .= '/';
$homep = $this->app['path.data'] . 'home/' . $clean_url;
//homep for Home Path
//we create the new dir for the new sites
if (!is_dir($homep)) {
mkdir($homep, api_get_permissions_for_new_directories());
}
}
} else {
$homep = $this->app['path.data'] . 'home/';
}
$ext = '.html';
$menutabs = 'home_tabs';
$home_top = '';
if (is_file($homep . $menutabs . '_' . $lang . $ext) && is_readable($homep . $menutabs . '_' . $lang . $ext)) {
$home_top = @(string) file_get_contents($homep . $menutabs . '_' . $lang . $ext);
} elseif (is_file($homep . $menutabs . $lang . $ext) && is_readable($homep . $menutabs . $lang . $ext)) {
$home_top = @(string) file_get_contents($homep . $menutabs . $lang . $ext);
}
$home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
$open = str_replace('{rel_path}', $this->app['path.data'], $home_top);
$open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
$lis = '';
if (!empty($open)) {
if (strpos($open, 'show_menu') === false) {
if (api_is_anonymous()) {
$navigation[SECTION_CAMPUS] = null;
}
} else {
$lis .= $open;
}
}
if (count($navigation) > 0 || !empty($lis)) {
$pre_lis = '';
foreach ($navigation as $section => $navigation_info) {
if (isset($GLOBALS['this_section'])) {
$current = $section == $GLOBALS['this_section'] ? ' id="current" class="active" ' : '';
} else {
$current = '';
}
if (!empty($navigation_info['title'])) {
$pre_lis .= '<li' . $current . ' ><a href="' . $navigation_info['url'] . '" target="_top">' . $navigation_info['title'] . '</a></li>';
}
}
$lis = $pre_lis . $lis;
}
$menu = null;
if (!empty($lis)) {
$menu .= $lis;
}
return $menu;
}