/** * Checks if the absolute path (directory) given is really under the * checker path (directory) * @param string Absolute path to be checked (with trailing slash) * @param string Checker path under which the path should be (absolute path, with trailing slash, get it from api_get_path(SYS_COURSE_PATH)) * @return bool True if the path is under the checker, false otherwise */ public static function check_abs_path($abs_path, $checker_path) { if (empty($checker_path)) { return false; } // The checker path must be set. $true_path = str_replace("\\", '/', realpath($abs_path)); $found = strpos($true_path . '/', $checker_path); if ($found === 0) { return true; } else { // Code specific to Windows and case-insensitive behaviour if (api_is_windows_os()) { $found = stripos($true_path . '/', $checker_path); if ($found === 0) { return true; } } // Code specific to courses directory stored on other disk. /* $checker_path = str_replace(api_get_path(SYS_COURSE_PATH), $_configuration['symbolic_course_folder_abs'], $checker_path); $found = strpos($true_path.'/', $checker_path); if ($found === 0) { return true; }*/ } return false; }
/** * Checks if the absolute path (directory) given is really under the * checker path (directory) * @param string Absolute path to be checked (with trailing slash) * @param string Checker path under which the path should be (absolute path, with trailing slash, get it from api_get_path(SYS_COURSE_PATH)) * @return bool True if the path is under the checker, false otherwise */ public static function check_abs_path($abs_path, $checker_path) { // The checker path must be set. if (empty($checker_path)) { return false; } $true_path = str_replace("\\", '/', realpath($abs_path)); $checker_path = str_replace("\\", '/', realpath($checker_path)); $found = strpos($true_path.'/', $checker_path); if ($found === 0) { return true; } else { // Code specific to Windows and case-insensitive behaviour if (api_is_windows_os()) { $found = stripos($true_path.'/', $checker_path); if ($found === 0) { return true; } } } return false; }
function display_default() { $message = get_lang('RemoveOldDatabaseMessage'); $message_table = get_lang('RemoveOldTables'); $message_table .= "<br />" . implode(' , ', self::get_tables_to_delete()); $token = Security::get_token(); $url = $this->url(array(self::PARAM_ACTION => 'drop_old_databases', self::PARAM_SECURITY_TOKEN => $token)); $url_table = $this->url(array(self::PARAM_ACTION => 'drop_old_tables', self::PARAM_SECURITY_TOKEN => $token)); $go = get_lang('Go'); $access_url_id = api_get_current_access_url_id(); $message2 = ''; if ($access_url_id === 1) { if (api_is_windows_os()) { $message2 .= get_lang('SpaceUsedOnSystemCannotBeMeasuredOnWindows'); } else { $dir = api_get_path(SYS_PATH); $du = exec('du -sh ' . $dir, $err); list($size, $none) = explode("\t", $du); $limit = $_configuration[$url]['hosting_limit_disk_space']; $message2 .= sprintf(get_lang('TotalSpaceUsedByPortalXLimitIsYMB'), $size, $limit); } } if (!empty($message2)) { $message2 = '<li>' . $message2 . '</li>'; } echo <<<EOT <ul> <li> <div>{$message}</div> <a class="btn" href={$url}>{$go}</a> </li> <li> <div>{$message_table}</div> <a class="btn" href={$url_table}>{$go}</a> </li> {$message2} </ul> EOT; }
define('LOG_GRADEBOOK_UNLOCKED', 'gradebook_unlocked'); define('LOG_GRADEBOOK_ID', 'gradebook_id'); define('LOG_WIKI_PAGE_ID', 'wiki_page_id'); define('LOG_EXERCISE_ID', 'exercise_id'); define('LOG_EXERCISE_AND_USER_ID', 'exercise_and_user_id'); define('LOG_LP_ID', 'lp_id'); define('LOG_EXERCISE_ATTEMPT_QUESTION_ID', 'exercise_a_q_id'); define('LOG_MY_FOLDER_PATH', 'path'); define('LOG_MY_FOLDER_NEW_PATH', 'new_path'); define('USERNAME_PURIFIER', '/[^0-9A-Za-z_\\.]/'); //used when login_is_email setting is true define('USERNAME_PURIFIER_MAIL', '/[^0-9A-Za-z_\\.@]/'); define('USERNAME_PURIFIER_SHALLOW', '/\\s/'); // This constant is a result of Windows OS detection, it has a boolean value: // true whether the server runs on Windows OS, false otherwise. define('IS_WINDOWS_OS', api_is_windows_os()); // Checks for installed optional php-extensions. define('INTL_INSTALLED', function_exists('intl_get_error_code')); // intl extension (from PECL), it is installed by default as of PHP 5.3.0 define('ICONV_INSTALLED', function_exists('iconv')); // iconv extension, for PHP5 on Windows it is installed by default. define('MBSTRING_INSTALLED', function_exists('mb_strlen')); // mbstring extension. // Patterns for processing paths. // Examples: define('REPEATED_SLASHES_PURIFIER', '/\\/{2,}/'); // $path = preg_replace(REPEATED_SLASHES_PURIFIER, '/', $path); define('VALID_WEB_PATH', '/https?:\\/\\/[^\\/]*(\\/.*)?/i'); // $is_valid_path = preg_match(VALID_WEB_PATH, $path); define('VALID_WEB_SERVER_BASE', '/https?:\\/\\/[^\\/]*/i'); // $new_path = preg_replace(VALID_WEB_SERVER_BASE, $new_base, $path); // Constants for api_get_path() and api_get_path_type(), etc. - registered path types.
} if ($cvs) { if (!empty($userscourse)) { $userscourse = api_substr($userscourse, 0, api_strlen($userscourse) - 1); } $courses .= $userscourse . ']|'; } else { $courses .= "\t\t</Course>\n"; } } if (!empty($courses) && $cvs) { $courses = api_substr($courses, 0, api_strlen($courses) - 1); } $add .= $courses; if ($cvs) { $breakline = api_is_windows_os() ? "\r\n" : "\n"; $add .= ";{$breakline}"; } else { $add .= "\t</Session>\n"; } fputs($fp, $add); } if (!$cvs) { fputs($fp, "</Sessions>\n"); } fclose($fp); $errorMsg = get_lang('UserListHasBeenExported') . '<br/><a class="btn" href="' . $archiveURL . $archiveFile . '">' . get_lang('ClickHereToDownloadTheFile') . '</a>'; } } // display the header Display::display_header($tool_name);
/** * Search options * TODO: support for multiple site. aka $_configuration['access_url'] == 1 * @author Marco Villegas <*****@*****.**> */ function handle_search() { global $SettingsStored, $_configuration; require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; $search_enabled = api_get_setting('search.search_enabled'); $form = new FormValidator('search-options', 'post', api_get_self() . '?category=Search'); $values = api_get_settings_options('search_enabled'); $form->addElement('header', null, get_lang('SearchEnabledTitle')); $group = array(); if (is_array($values)) { foreach ($values as $key => $value) { $element =& $form->createElement('radio', 'search_enabled', '', get_lang($value['display_text']), $value['value']); $group[] = $element; } } //SearchEnabledComment $form->addGroup($group, 'search_enabled', array(get_lang('SearchEnabledTitle'), get_lang('SearchEnabledComment')), '<br />', false); $search_enabled = api_get_setting('search.search_enabled'); if ($form->validate()) { $formvalues = $form->exportValues(); $r = api_set_settings_category('Search', 'false', $_configuration['access_url']); // Save the settings. foreach ($formvalues as $key => $value) { $result = api_set_setting($key, $value, null, null); } $search_enabled = $formvalues['search_enabled']; Display::display_confirmation_message($SettingsStored); } $specific_fields = get_specific_field_list(); if ($search_enabled == 'true') { $values = api_get_settings_options('search_show_unlinked_results'); $group = array(); foreach ($values as $key => $value) { $element =& $form->createElement('radio', 'search_show_unlinked_results', '', get_lang($value['display_text']), $value['value']); $group[] = $element; } $form->addGroup($group, 'search_show_unlinked_results', array(get_lang('SearchShowUnlinkedResultsTitle'), get_lang('SearchShowUnlinkedResultsComment')), '', false); $default_values['search_show_unlinked_results'] = api_get_setting('search_show_unlinked_results'); $sf_values = array(); foreach ($specific_fields as $sf) { $sf_values[$sf['code']] = $sf['name']; } $group = array(); $url = Display::div(Display::url(get_lang('AddSpecificSearchField'), 'specific_fields.php'), array('class' => 'sectioncomment')); if (empty($sf_values)) { $form->addElement('html', get_lang('SearchPrefilterPrefix') . $url); } else { $form->addElement('select', 'search_prefilter_prefix', array(get_lang('SearchPrefilterPrefix'), $url), $sf_values, ''); $default_values['search_prefilter_prefix'] = api_get_setting('search_prefilter_prefix'); } } $default_values['search_enabled'] = $search_enabled; $form->addButtonSave(get_lang('Save')); $form->setDefaults($default_values); echo '<div id="search-options-form">'; $form->display(); echo '</div>'; if ($search_enabled == 'true') { $xapian_path = api_get_path(SYS_UPLOAD_PATH) . 'plugins/xapian/searchdb'; /* @todo Test the Xapian connection if (extension_loaded('xapian')) { require_once 'xapian.php'; try { $db = new XapianDatabase($xapian_path.'/'); } catch (Exception $e) { var_dump($e->getMessage()); } require_once api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php'; require_once api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php'; require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; $indexable = new IndexableChunk(); $indexable->addValue("content", 'Test'); $di = new DokeosIndexer(); $di->connectDb(NULL, NULL, 'english'); $di->addChunk($indexable); $did = $di->index(); } */ $xapian_loaded = Display::return_icon('bullet_green.gif', get_lang('Ok')); $dir_exists = Display::return_icon('bullet_green.gif', get_lang('Ok')); $dir_is_writable = Display::return_icon('bullet_green.gif', get_lang('Ok')); $specific_fields_exists = Display::return_icon('bullet_green.gif', get_lang('Ok')); //Testing specific fields if (empty($specific_fields)) { $specific_fields_exists = Display::return_icon('bullet_red.gif', get_lang('AddSpecificSearchField')); } //Testing xapian extension if (!extension_loaded('xapian')) { $xapian_loaded = Display::return_icon('bullet_red.gif', get_lang('Error')); } //Testing xapian searchdb path if (!is_dir($xapian_path)) { $dir_exists = Display::return_icon('bullet_red.gif', get_lang('Error')); } //Testing xapian searchdb path is writable if (!is_writable($xapian_path)) { $dir_is_writable = Display::return_icon('bullet_red.gif', get_lang('Error')); } $data[] = array(get_lang('XapianModuleInstalled'), $xapian_loaded); $data[] = array(get_lang('DirectoryExists') . ' - ' . $xapian_path, $dir_exists); $data[] = array(get_lang('IsWritable') . ' - ' . $xapian_path, $dir_is_writable); $data[] = array(get_lang('SpecificSearchFieldsAvailable'), $specific_fields_exists); echo Display::tag('h3', get_lang('Settings')); $table = new SortableTableFromArray($data); $table->set_header(0, get_lang('Setting'), false); $table->set_header(1, get_lang('Status'), false); echo $table->display(); //@todo windows support if (api_is_windows_os() == false) { $list_of_programs = array('pdftotext', 'ps2pdf', 'catdoc', 'html2text', 'unrtf', 'catppt', 'xls2csv'); foreach ($list_of_programs as $program) { $output = $ret_val = null; exec("which {$program}", $output, $ret_val); $icon = Display::return_icon('bullet_red.gif', get_lang('NotInstalled')); if (!empty($output[0])) { $icon = Display::return_icon('bullet_green.gif', get_lang('Installed')); } $data2[] = array($program, $output[0], $icon); } echo Display::tag('h3', get_lang('ProgramsNeededToConvertFiles')); $table = new SortableTableFromArray($data2); $table->set_header(0, get_lang('Program'), false); $table->set_header(1, get_lang('Path'), false); $table->set_header(2, get_lang('Status'), false); echo $table->display(); } else { Display::display_warning_message(get_lang('YouAreUsingChamiloInAWindowsPlatformSadlyYouCantConvertDocumentsInOrderToSearchTheContentUsingThisTool')); } } }
<?php require_once '../main/inc/global.inc.php'; var_dump(api_is_windows_os()); //echo (api_is_windows_os()?'true':'false');
/** * Moves a file or a directory to an other area * * @author - Hugues Peeters <*****@*****.**> * @param - $source (String) - the path of file or directory to move * @param - $target (String) - the path of the new area * @param bool $forceMove Whether to force a move or to make a copy (safer but slower) and then delete the original * @param bool $moveContent In some cases (including migrations), we need to move the *content* and not the folder itself * @return - bolean - true if the move succeed * bolean - false otherwise. * @see - move() uses check_name_exist() and copyDirTo() functions */ function move($source, $target, $forceMove = false, $moveContent = false) { if (check_name_exist($source)) { $file_name = basename($source); $isWindowsOS = api_is_windows_os(); $canExec = function_exists('exec'); /* File case */ if (is_file($source)) { if ($forceMove && !$isWindowsOS && $canExec) { exec('mv ' . $source . ' ' . $target . '/' . $file_name); } else { copy($source, $target . '/' . $file_name); unlink($source); } return true; } elseif (is_dir($source)) { /* Directory */ if ($forceMove && !$isWindowsOS && $canExec) { if ($moveContent) { $base = basename($source); exec('mv ' . $source . '/* ' . $target . $base . '/'); exec('rm -rf ' . $source); } else { exec('mv $source $target'); } } else { copyDirTo($source, $target); } return true; } } else { return false; } }