本文整理汇总了PHP中api_get_permissions_for_new_directories函数的典型用法代码示例。如果您正苦于以下问题:PHP api_get_permissions_for_new_directories函数的具体用法?PHP api_get_permissions_for_new_directories怎么用?PHP api_get_permissions_for_new_directories使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了api_get_permissions_for_new_directories函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_user_folder
/**
* @return bool
*/
public function create_user_folder()
{
// COURSE123/exercises/session_id/exercise_id/question_id/user_id
if (empty($this->store_path)) {
return false;
}
//@todo use an array to create folders
$folders_to_create = array();
// Trying to create the courses/COURSE123/exercises/ dir just in case.
$directoryPermissions = api_get_permissions_for_new_directories();
if (!is_dir($this->store_path)) {
mkdir($this->store_path, $directoryPermissions);
}
if (!is_dir($this->store_path . $this->session_id)) {
mkdir($this->store_path . $this->session_id, $directoryPermissions);
}
if (!is_dir($this->store_path . $this->session_id . '/' . $this->exercise_id)) {
mkdir($this->store_path . $this->session_id . '/' . $this->exercise_id, $directoryPermissions);
}
if (!is_dir($this->store_path . $this->session_id . '/' . $this->exercise_id . '/' . $this->question_id)) {
mkdir($this->store_path . $this->session_id . '/' . $this->exercise_id . '/' . $this->question_id, $directoryPermissions);
}
if (!empty($this->user_id) && !is_dir($this->store_path . $this->session_id . '/' . $this->exercise_id . '/' . $this->question_id . '/' . $this->user_id)) {
mkdir($this->store_path . $this->session_id . '/' . $this->exercise_id . '/' . $this->question_id . '/' . $this->user_id, $directoryPermissions);
}
}
示例2: wsConvertPpt
/**
* Function to convert from ppt to png
* This function is used from Chamilo Rapid Lesson
*
* @param array $pptData
* @return string
*/
function wsConvertPpt($pptData)
{
$fileData = $pptData['file_data'];
$dataInfo = pathinfo($pptData['file_name']);
$fileName = basename($pptData['file_name'], '.' . $dataInfo['extension']);
$fullFileName = $pptData['file_name'];
$tempArchivePath = api_get_path(SYS_ARCHIVE_PATH);
$tempPath = $tempArchivePath . 'wsConvert/' . $fileName . '/';
$tempPathNewFiles = $tempArchivePath . 'wsConvert/' . $fileName . '-n/';
$perms = api_get_permissions_for_new_directories();
if (!is_dir($tempPath)) {
mkdir($tempPath, $perms, true);
}
if (!is_dir($tempPathNewFiles)) {
mkdir($tempPathNewFiles, $perms, true);
}
if (!is_dir($tempPathNewFiles . $fileName)) {
mkdir($tempPathNewFiles . $fileName, $perms, true);
}
$file = base64_decode($fileData);
file_put_contents($tempPath . $fullFileName, $file);
if (IS_WINDOWS_OS) {
// IS_WINDOWS_OS has been defined in main_api.lib.php
$converterPath = str_replace('/', '\\', api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png');
$classPath = $converterPath . ';' . $converterPath . '/jodconverter-2.2.2.jar;' . $converterPath . '/jodconverter-cli-2.2.2.jar';
$cmd = 'java -Dfile.encoding=UTF-8 -cp "' . $classPath . '" DokeosConverter';
} else {
$converterPath = api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png';
$classPath = ' -Dfile.encoding=UTF-8 -cp .:jodconverter-2.2.2.jar:jodconverter-cli-2.2.2.jar';
$cmd = 'cd ' . $converterPath . ' && java ' . $classPath . ' DokeosConverter';
}
$cmd .= ' -p ' . api_get_setting('service_ppt2lp', 'port');
$cmd .= ' -w 720 -h 540 -d oogie "' . $tempPath . $fullFileName . '" "' . $tempPathNewFiles . $fileName . '.html"';
$perms = api_get_permissions_for_new_files();
chmod($tempPathNewFiles . $fileName, $perms, true);
$files = array();
$return = 0;
$shell = exec($cmd, $files, $return);
if ($return === 0) {
$images = array();
foreach ($files as $file) {
$imageData = explode('||', $file);
$images[$imageData[1]] = base64_encode(file_get_contents($tempPathNewFiles . $fileName . '/' . $imageData[1]));
}
$data = array('files' => $files, 'images' => $images);
deleteDirectory($tempPath);
deleteDirectory($tempPathNewFiles);
return serialize($data);
} else {
deleteDirectory($tempPath);
deleteDirectory($tempPathNewFiles);
return false;
}
}
示例3: course
/**
*
* @param int $c_id
* @param string $sub_path
* @return FileStore
*/
static function course($c_id, $sub_path = '')
{
$sys_path = api_get_path(SYS_COURSE_PATH);
$course = api_get_course_info_by_id($c_id);
$course_path = $course['path'];
$path = $sys_path . $course_path . $sub_path;
if (!is_dir($path)) {
$mode = api_get_permissions_for_new_directories();
$success = mkdir($path, $mode, true);
if (!$success) {
return false;
}
}
return new self($path);
}
示例4: execute
/**
* @param Console\Input\InputInterface $input
* @param Console\Output\OutputInterface $output
* @return integer|null|boolean|void
*/
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
/** @var \Silex\Application $app */
$app = $this->getApplication()->getSilexApplication();
$theme = $input->getArgument('theme');
// Get all themes
if ($app['assetic.enabled'] == false || !isset($app['assetic.enabled'])) {
$output->writeln("<info>Assetic is not enabled. Change this value to true:</info> <comment>assetic.enabled = true</comment>");
return false;
}
$themes = $app['template']->getStyleSheetFolderList();
//$themes = array('chamilo', 'public_admin');
if (empty($theme)) {
$dialog = $this->getHelperSet()->get('dialog');
if (!$dialog->askConfirmation($output, '<question>Are you sure you want to dump css/js of all themes?</question>(y/N)', false)) {
return;
}
} else {
$themes = array($theme);
}
if (!is_dir($app['assetic.path_to_web'])) {
mkdir($app['assetic.path_to_web'], api_get_permissions_for_new_directories());
$output->writeln("<info>Creating folder in: </info><comment>" . $app['assetic.path_to_web'] . "</comment>");
}
foreach ($themes as $theme) {
if (is_dir($app['root_sys'] . 'main/css/' . $theme) && file_exists($app['root_sys'] . 'main/css/' . $theme . '/default.css')) {
$output->writeln("<info>Dumping theme: {$theme}</info>");
/** @var \SilexAssetic\Assetic\Dumper $dumper */
$dumper = $app['assetic.dumper'];
$app['assetic.output.path_to_css'] = 'css/' . $theme . '/style.css';
$params = array($app['root_sys'] . 'main/css/' . $theme => $app['assetic.input.path_to_assets'] . '/css/' . $theme);
$app['chamilo.filesystem']->copyFolders($params, $output);
if (isset($app['twig'])) {
//$dumper->addTwigAssets();
}
$dumper->dumpAssets();
} else {
$output->writeln("<info>Seems that theme: <comment>{$theme}</comment> doesn't have a <comment>{$theme}/default.css</comment> file. Skipping dump.</info>");
}
}
$output->writeln('<info>Dump finished</info>');
return true;
}
示例5: hotpotatoes_init
/**
* Creates a hotpotato directory.
*
* If a directory of that name already exists, don't create any. If a file of that name exists, remove it and create a directory.
* @param string Wanted path
* @return boolean Always true so far
*/
function hotpotatoes_init($base_work_dir)
{
//global $_course, $_user;
$document_path = $base_work_dir . '/';
if (!is_dir($document_path)) {
if (is_file($document_path)) {
@unlink($document_path);
}
@mkdir($document_path, api_get_permissions_for_new_directories());
return true;
} else {
return false;
}
//why create a .htaccess here?
//if (!is_file($document_path.".htacces"))
//{
// if (!($fp = fopen($document_path.".htaccess", "w"))) {
// }
// $str = "order deny,allow\nallow from all";
// if (!fwrite($fp,$str)) { }
//}
}
示例6: str_replace
$content = str_replace('</head>', '<style> body{margin:10px;}</style><link rel="stylesheet" href="./css/frames.css" type="text/css" /></head>', $content);
}
if ($fp = @fopen($filepath . $filename . '.' . $extension, 'w')) {
$content = str_replace(api_get_path(WEB_COURSE_PATH), $_configuration['url_append'] . '/courses/', $content);
// change the path of mp3 to absolute
// first regexp deals with ../../../ urls
// Disabled by Ivan Tcholakov.
//$content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content);
//second regexp deals with audio/ urls
// Disabled by Ivan Tcholakov.
//$content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content);
fputs($fp, $content);
fclose($fp);
chmod($filepath . $filename . '.' . $extension, api_get_permissions_for_new_files());
if (!is_dir($filepath . 'css')) {
mkdir($filepath . 'css', api_get_permissions_for_new_directories());
$doc_id = FileManager::add_document($_course, $dir . 'css', 'folder', 0, 'css');
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id'], null, null, null, null, $current_session_id);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id);
}
if (!is_file($filepath . 'css/frames.css')) {
// Make a copy of the current css for the new document
copy(api_get_path(SYS_CSS_PATH) . 'themes/' . api_get_setting('stylesheets') . '/frames.css', $filepath . 'css/frames.css');
$doc_id = FileManager::add_document($_course, $dir . 'css/frames.css', 'file', filesize($filepath . 'css/frames.css'), 'frames.css');
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentAdded', $_user['user_id'], null, null, null, null, $current_session_id);
api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id'], null, null, null, null, $current_session_id);
}
$file_size = filesize($filepath . $filename . '.' . $extension);
$save_file_path = $dir . $filename . '.' . $extension;
$document_id = FileManager::add_document($_course, $save_file_path, 'file', $file_size, $title, null, $readonly);
if ($document_id) {
示例7: FormValidator
}
$tpl->assign('displayCookieUsageWarning', true);
}
}
}
$tpl->assign('web_admin_ajax_url', $admin_ajax_url);
$tpl->assign('blocks', $blocks);
if (api_is_platform_admin()) {
$extraContentForm = new FormValidator('block_extra_data', 'post', '#', null, array('id' => 'block-extra-data', 'class' => ''), FormValidator::LAYOUT_BOX_NO_LABEL);
$extraContentFormRenderer = $extraContentForm->getDefaultRenderer();
if ($extraContentForm->validate()) {
$extraData = $extraContentForm->getSubmitValues();
$extraData = array_map(['Security', 'remove_XSS'], $extraData);
if (!empty($extraData['block'])) {
if (!is_dir($adminExtraContentDir)) {
mkdir($adminExtraContentDir, api_get_permissions_for_new_directories(), true);
}
if (!is_writable($adminExtraContentDir)) {
die;
}
$fullFilePath = $adminExtraContentDir . $extraData['block'];
$fullFilePath .= "_extra.html";
file_put_contents($fullFilePath, $extraData['extra_content']);
Header::location(api_get_self());
}
}
$extraContentForm->addTextarea('extra_content', null, ['id' => 'extra_content']);
$extraContentFormRenderer->setElementTemplate('<div class="form-group">{element}</div>', 'extra_content');
$extraContentForm->addElement('hidden', 'block', null, array('id' => 'extra-block'));
$extraContentForm->addButtonExport(get_lang('Save'), 'submit_extra_content');
$tpl->assign('extraDataForm', $extraContentForm->returnForm());
示例8: update_group_picture
/**
* Creates new group pictures in various sizes of a user, or deletes user pfotos.
* Note: This method relies on configuration setting from main/inc/conf/profile.conf.php
* @param int The group id
* @param string $file The common file name for the newly created photos.
* It will be checked and modified for compatibility with the file system.
* If full name is provided, path component is ignored.
* If an empty name is provided, then old user photos are deleted only,
* @see UserManager::delete_user_picture() as the prefered way for deletion.
* @param string $source_file The full system name of the image from which user photos will be created.
* @return string/bool Returns the resulting common file name of created images which usually should be stored in database.
* When an image is removed the function returns an empty string. In case of internal error or negative validation it returns FALSE.
*/
public function update_group_picture($group_id, $file = null, $source_file = null)
{
// Validation 1.
if (empty($group_id)) {
return false;
}
$delete = empty($file);
if (empty($source_file)) {
$source_file = $file;
}
// User-reserved directory where photos have to be placed.
$path_info = self::get_group_picture_path_by_id($group_id, 'system', true);
$path = $path_info['dir'];
// If this directory does not exist - we create it.
if (!file_exists($path)) {
@mkdir($path, api_get_permissions_for_new_directories(), true);
}
// The old photos (if any).
$old_file = $path_info['file'];
// Let us delete them.
if (!empty($old_file)) {
if (KEEP_THE_OLD_IMAGE_AFTER_CHANGE) {
$prefix = 'saved_' . date('Y_m_d_H_i_s') . '_' . uniqid('') . '_';
@rename($path . 'small_' . $old_file, $path . $prefix . 'small_' . $old_file);
@rename($path . 'medium_' . $old_file, $path . $prefix . 'medium_' . $old_file);
@rename($path . 'big_' . $old_file, $path . $prefix . 'big_' . $old_file);
@rename($path . $old_file, $path . $prefix . $old_file);
} else {
@unlink($path . 'small_' . $old_file);
@unlink($path . 'medium_' . $old_file);
@unlink($path . 'big_' . $old_file);
@unlink($path . $old_file);
}
}
// Exit if only deletion has been requested. Return an empty picture name.
if ($delete) {
return '';
}
// Validation 2.
$allowed_types = array('jpg', 'jpeg', 'png', 'gif');
$file = str_replace('\\', '/', $file);
$filename = ($pos = strrpos($file, '/')) !== false ? substr($file, $pos + 1) : $file;
$extension = strtolower(substr(strrchr($filename, '.'), 1));
if (!in_array($extension, $allowed_types)) {
return false;
}
// This is the common name for the new photos.
if (KEEP_THE_NAME_WHEN_CHANGE_IMAGE && !empty($old_file)) {
$old_extension = strtolower(substr(strrchr($old_file, '.'), 1));
$filename = in_array($old_extension, $allowed_types) ? substr($old_file, 0, -strlen($old_extension)) : $old_file;
$filename = substr($filename, -1) == '.' ? $filename . $extension : $filename . '.' . $extension;
} else {
$filename = api_replace_dangerous_char($filename);
if (PREFIX_IMAGE_FILENAME_WITH_UID) {
$filename = uniqid('') . '_' . $filename;
}
// We always prefix user photos with user ids, so on setting
// api_get_setting('split_users_upload_directory') === 'true'
// the correspondent directories to be found successfully.
$filename = $group_id . '_' . $filename;
}
// Storing the new photos in 4 versions with various sizes.
/*$image->resize(
// get original size and set width (widen) or height (heighten).
// width or height will be set maintaining aspect ratio.
$image->getSize()->widen( 700 )
);*/
// Usign the Imagine service
$imagine = new Imagine\Gd\Imagine();
$image = $imagine->open($source_file);
$options = array('quality' => 90);
//$image->resize(new Imagine\Image\Box(200, 200))->save($path.'big_'.$filename);
$image->resize($image->getSize()->widen(200))->save($path . 'big_' . $filename, $options);
$image = $imagine->open($source_file);
$image->resize(new Imagine\Image\Box(85, 85))->save($path . 'medium_' . $filename, $options);
$image = $imagine->open($source_file);
$image->resize(new Imagine\Image\Box(22, 22))->save($path . 'small_' . $filename);
/*
$small = self::resize_picture($source_file, 22);
$medium = self::resize_picture($source_file, 85);
$normal = self::resize_picture($source_file, 200);
$big = new Image($source_file); // This is the original picture.
$ok = $small && $small->send_image($path.'small_'.$filename)
&& $medium && $medium->send_image($path.'medium_'.$filename)
&& $normal && $normal->send_image($path.'big_'.$filename)
&& $big && $big->send_image($path.$filename);
//.........这里部分代码省略.........
示例9: convertCopyDocument
/**
* Used to convert copied from document
* @param string $originalPath
* @param string $convertedPath
* @param string $convertedTitle
* @return bool
*/
function convertCopyDocument($originalPath, $convertedPath, $convertedTitle)
{
$_course = api_get_course_info();
$ids = array();
$originalPathInfo = pathinfo($originalPath);
$convertedPathInfo = pathinfo($convertedPath);
$this->base_work_dir = $originalPathInfo['dirname'];
$this->file_path = $originalPathInfo['basename'];
$this->created_dir = $convertedPathInfo['basename'];
$ppt2lpHost = api_get_setting('ppt_to_lp.host');
$permissionFile = api_get_permissions_for_new_files();
$permissionFolder = api_get_permissions_for_new_directories();
if (file_exists($this->base_work_dir . '/' . $this->created_dir)) {
return $ids;
}
if ($ppt2lpHost == 'localhost') {
if (IS_WINDOWS_OS) {
// IS_WINDOWS_OS has been defined in main_api.lib.php
$converterPath = str_replace('/', '\\', api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png');
$classPath = $converterPath . ';' . $converterPath . '/jodconverter-2.2.2.jar;' . $converterPath . '/jodconverter-cli-2.2.2.jar';
$cmd = 'java -Dfile.encoding=UTF-8 -jar "' . $classPath . '/jodconverter-2.2.2.jar"';
} else {
$converterPath = api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png';
$classPath = ' -Dfile.encoding=UTF-8 -jar jodconverter-cli-2.2.2.jar';
$cmd = 'cd ' . $converterPath . ' && java ' . $classPath . ' ';
}
$cmd .= ' -p ' . api_get_setting('ppt_to_lp.port');
// Call to the function implemented by child.
$cmd .= ' "' . $this->base_work_dir . '/' . $this->file_path . '" "' . $this->base_work_dir . '/' . $this->created_dir . '"';
// To allow openoffice to manipulate docs.
@chmod($this->base_work_dir, $permissionFolder);
@chmod($this->base_work_dir . '/' . $this->file_path, $permissionFile);
$locale = $this->original_locale;
// TODO: Improve it because we're not sure this locale is present everywhere.
putenv('LC_ALL=' . $locale);
$files = array();
$return = 0;
$shell = exec($cmd, $files, $return);
// TODO: Chown is not working, root keep user privileges, should be www-data
@chown($this->base_work_dir . '/' . $this->created_dir, 'www-data');
@chmod($this->base_work_dir . '/' . $this->created_dir, $permissionFile);
if ($return != 0) {
// If the java application returns an error code.
switch ($return) {
// Can't connect to openoffice.
case 1:
$this->error = get_lang('CannotConnectToOpenOffice');
break;
// Conversion failed in openoffice.
// Conversion failed in openoffice.
case 2:
$this->error = get_lang('OogieConversionFailed');
break;
// Conversion can't be launch because command failed.
// Conversion can't be launch because command failed.
case 255:
$this->error = get_lang('OogieUnknownError');
break;
}
DocumentManager::delete_document($_course, $this->created_dir, $this->base_work_dir);
return false;
}
} else {
/*
* @TODO Create method to use webservice
// get result from webservices
$result = $this->_get_remote_ppt2lp_files($file);
$result = unserialize(base64_decode($result));
// Save remote images to server
chmod($this->base_work_dir.$this->created_dir, api_get_permissions_for_new_directories());
if (!empty($result['images'])) {
foreach ($result['images'] as $image => $img_data) {
$image_path = $this->base_work_dir.$this->created_dir;
@file_put_contents($image_path . '/' . $image, base64_decode($img_data));
@chmod($image_path . '/' . $image, 0777);
}
}
// files info
$files = $result['files'];
*/
}
if (file_exists($this->base_work_dir . '/' . $this->created_dir)) {
// Register Files to Document tool
$ids[] = add_document($_course, '/' . $this->created_dir, 'file', filesize($this->base_work_dir . '/' . $this->created_dir), $convertedTitle, sprintf(get_lang('FileConvertedFromXToY'), strtoupper($originalPathInfo['extension']), strtoupper($convertedPathInfo['extension'])), 0, true, null, api_get_session_id());
chmod($this->base_work_dir, $permissionFolder);
}
return $ids;
}
示例10: restore_works
/**
* Restore Work
*/
function restore_works($session_id = 0)
{
$perm = api_get_permissions_for_new_directories();
if ($this->course->has_resources(RESOURCE_WORK)) {
$table_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$table_work_assignment = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_WORK] as $id => $obj) {
// check resources inside html from fckeditor tool and copy correct urls into recipient course
$obj->params['description'] = DocumentManager::replace_urls_inside_content_html_from_copy_course($obj->params['description'], $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
$obj->params['id'] = null;
$obj->params['c_id'] = $this->destination_course_id;
$last_id = Database::insert($table_work, $obj->params);
// re-create dir
// @todo check security against injection of dir in crafted course backup here!
$path = $obj->params['url'];
$path = '/' . str_replace('/', '', substr($path, 1));
$destination_path = api_get_path(SYS_COURSE_PATH) . $this->course->destination_path . '/work' . $path;
$r = @mkdir($destination_path, $perm);
if ($r === false) {
error_log('Failed creating directory ' . $destination_path . ' in course restore for work tool');
}
if (is_numeric($last_id)) {
api_item_property_update($this->destination_course_info, 'work', $last_id, "DirectoryCreated", api_get_user_id());
}
}
}
}
示例11: fill_db_course
/**
* Fills the course database with some required content and example content.
* @param int Course (int) ID
* @param string Course directory name (e.g. 'ABC')
* @param string Language used for content (e.g. 'spanish')
* @param bool Whether to fill the course with example content
* @return bool False on error, true otherwise
* @version 1.2
* @assert (null, '', '', null) === false
* @assert (1, 'ABC', null, null) === false
* @assert (1, 'TEST', 'spanish', true) === true
*/
public static function fill_db_course($course_id, $course_repository, $language, $fill_with_exemplary_content = null)
{
if (is_null($fill_with_exemplary_content)) {
$fill_with_exemplary_content = api_get_setting('course.example_material_course_creation') != 'false';
}
$course_id = intval($course_id);
if (empty($course_id)) {
return false;
}
$entityManager = Database::getManager();
$course = $entityManager->getRepository('ChamiloCoreBundle:Course')->find($course_id);
$tools = array();
$settingsManager = CourseManager::getCourseSettingsManager();
$settingsManager->setCourse($course);
$toolList = CourseManager::getToolList();
$toolList = $toolList->getTools();
/** @var Chamilo\CourseBundle\Tool\BaseTool $tool */
foreach ($toolList as $tool) {
$visibility = self::string2binary(api_get_setting_in_list('course.active_tools_on_create', $tool->getName()));
$toolObject = new CTool();
$toolObject->setName($tool->getName())->setCategory($tool->getCategory())->setLink($tool->getLink())->setImage($tool->getImage())->setVisibility($visibility)->setAdmin(0)->setTarget($tool->getTarget());
$tools[] = $toolObject;
$settings = $settingsManager->loadSettings($tool->getName());
$settingsManager->saveSettings($tool->getName(), $settings);
}
$course->setTools($tools);
$entityManager->persist($course);
$entityManager->flush($course);
$courseInfo = api_get_course_info_by_id($course_id);
$now = api_get_utc_datetime(time());
$tbl_course_homepage = Database::get_course_table(TABLE_TOOL_LIST);
$TABLEINTROS = Database::get_course_table(TABLE_TOOL_INTRO);
$TABLEGROUPCATEGORIES = Database::get_course_table(TABLE_GROUP_CATEGORY);
$TABLEITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$TABLETOOLAGENDA = Database::get_course_table(TABLE_AGENDA);
$TABLETOOLANNOUNCEMENTS = Database::get_course_table(TABLE_ANNOUNCEMENT);
$TABLETOOLDOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$TABLETOOLLINK = Database::get_course_table(TABLE_LINK);
$TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST);
$TABLEQUIZQUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TABLEQUIZQUESTIONLIST = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TABLEQUIZANSWERSLIST = Database::get_course_table(TABLE_QUIZ_ANSWER);
$TABLESETTING = Database::get_course_table(TABLE_COURSE_SETTING);
$TABLEFORUMCATEGORIES = Database::get_course_table(TABLE_FORUM_CATEGORY);
$TABLEFORUMS = Database::get_course_table(TABLE_FORUM);
$TABLEFORUMTHREADS = Database::get_course_table(TABLE_FORUM_THREAD);
$TABLEFORUMPOSTS = Database::get_course_table(TABLE_FORUM_POST);
$TABLEGRADEBOOK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$TABLEGRADEBOOKLINK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$TABLEGRADEBOOKCERT = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$visible_for_all = 1;
$visible_for_course_admin = 0;
$visible_for_platform_admin = 2;
/* Course tools */
$alert = api_get_setting('exercise.email_alert_manager_on_new_quiz');
if ($alert === 'true') {
$defaultEmailExerciseAlert = 1;
} else {
$defaultEmailExerciseAlert = 0;
}
/* course_setting table (courseinfo tool) */
$settings = ['email_alert_manager_on_new_doc' => ['default' => 0, 'category' => 'work'], 'email_alert_on_new_doc_dropbox' => ['default' => 0, 'category' => 'dropbox'], 'allow_user_edit_agenda' => ['default' => 0, 'category' => 'agenda'], 'allow_user_edit_announcement' => ['default' => 0, 'category' => 'announcement'], 'email_alert_manager_on_new_quiz' => ['default' => $defaultEmailExerciseAlert, 'category' => 'quiz'], 'allow_user_image_forum' => ['default' => 1, 'category' => 'forum'], 'course_theme' => ['default' => '', 'category' => 'theme'], 'allow_learning_path_theme' => ['default' => 1, 'category' => 'theme'], 'allow_open_chat_window' => ['default' => 1, 'category' => 'chat'], 'email_alert_to_teacher_on_new_user_in_course' => ['default' => 0, 'category' => 'registration'], 'allow_user_view_user_list' => ['default' => 1, 'category' => 'user'], 'display_info_advance_inside_homecourse' => ['default' => 1, 'category' => 'thematic_advance'], 'email_alert_students_on_new_homework' => ['default' => 0, 'category' => 'work'], 'enable_lp_auto_launch' => ['default' => 0, 'category' => 'learning_path'], 'pdf_export_watermark_text' => ['default' => '', 'category' => 'learning_path'], 'allow_public_certificates' => ['default' => api_get_setting('course.allow_public_certificates') === 'true' ? 1 : '', 'category' => 'certificates'], 'documents_default_visibility' => ['default' => 'visible', 'category' => 'document']];
/*$counter = 1;
foreach ($settings as $variable => $setting) {
Database::query(
"INSERT INTO $TABLESETTING (id, c_id, variable, value, category)
VALUES ($counter, $course_id, '".$variable."', '".$setting['default']."', '".$setting['category']."')"
);
$counter++;
}*/
/* Course homepage tools for platform admin only */
/* Group tool */
Database::query("INSERT INTO {$TABLEGROUPCATEGORIES} (c_id, id, title , description, max_student, self_reg_allowed, self_unreg_allowed, groups_per_user, display_order)\n VALUES ({$course_id}, '2', '" . self::lang2db(get_lang('DefaultGroupCategory')) . "', '', '8', '0', '0', '0', '0');");
/* Example Material */
$language_interface = !empty($language_interface) ? $language_interface : api_get_setting('language.platform_language');
// Example material should be in the same language as the course is.
$language_interface_original = $language_interface;
$now = api_get_utc_datetime();
$files = [['path' => '/shared_folder', 'title' => get_lang('UserFolders'), 'filetype' => 'folder', 'size' => 0], ['path' => '/chat_files', 'title' => get_lang('ChatFiles'), 'filetype' => 'folder', 'size' => 0]];
$counter = 1;
foreach ($files as $file) {
self::insertDocument($course_id, $counter, $file);
$counter++;
}
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$perm = api_get_permissions_for_new_directories();
$perm_file = api_get_permissions_for_new_files();
$chat_path = $sys_course_path . $course_repository . '/document/chat_files';
//.........这里部分代码省略.........
示例12: replace_urls_inside_content_html_from_copy_course
/**
* Replace urls inside content html from a copy course
* @param string content html
* @param string origin course code
* @param string destination course directory
* @return string new content html with replaced urls or return false if content is not a string
*/
static function replace_urls_inside_content_html_from_copy_course($content_html, $origin_course_code, $destination_course_directory, $origin_course_path_from_zip = null, $origin_course_info_path = null)
{
if (empty($content_html)) {
return false;
}
$orig_source_html = DocumentManager::get_resources_from_source_html($content_html);
$orig_course_info = api_get_course_info($origin_course_code);
//Course does not exist in the current DB probably this cames from a zip file?
if (empty($orig_course_info)) {
if (!empty($origin_course_path_from_zip)) {
$orig_course_path = $origin_course_path_from_zip . '/';
$orig_course_info_path = $origin_course_info_path;
}
} else {
$orig_course_path = api_get_path(SYS_PATH) . 'courses/' . $orig_course_info['path'] . '/';
$orig_course_info_path = $orig_course_info['path'];
}
$destination_course_code = CourseManager::get_course_id_from_path($destination_course_directory);
$destination_course_info = api_get_course_info($destination_course_code);
$dest_course_path = api_get_path(SYS_COURSE_PATH) . $destination_course_directory . '/';
$user_id = api_get_user_id();
if (!empty($orig_source_html)) {
foreach ($orig_source_html as $source) {
// get information about source url
$real_orig_url = $source[0];
// url
$scope_url = $source[1];
// scope (local, remote)
$type_url = $source[2];
// tyle (rel, abs, url)
// Get path and query from origin url
$orig_parse_url = parse_url($real_orig_url);
$real_orig_path = isset($orig_parse_url['path']) ? $orig_parse_url['path'] : null;
$real_orig_query = isset($orig_parse_url['query']) ? $orig_parse_url['query'] : null;
// Replace origin course code by destination course code from origin url query
$dest_url_query = '';
if (!empty($real_orig_query)) {
$dest_url_query = '?' . $real_orig_query;
if (strpos($dest_url_query, $origin_course_code) !== false) {
$dest_url_query = str_replace($origin_course_code, $destination_course_code, $dest_url_query);
}
}
if ($scope_url == 'local') {
if ($type_url == 'abs' || $type_url == 'rel') {
$document_file = strstr($real_orig_path, 'document');
if (strpos($real_orig_path, $document_file) !== false) {
$origin_filepath = $orig_course_path . $document_file;
$destination_filepath = $dest_course_path . $document_file;
// copy origin file inside destination course
if (file_exists($origin_filepath)) {
$filepath_dir = dirname($destination_filepath);
if (!is_dir($filepath_dir)) {
$perm = api_get_permissions_for_new_directories();
$result = @mkdir($filepath_dir, $perm, true);
if ($result) {
$filepath_to_add = str_replace(array($dest_course_path, 'document'), '', $filepath_dir);
//Add to item properties to the new folder
$doc_id = FileManager::add_document($destination_course_info, $filepath_to_add, 'folder', 0, basename($filepath_to_add));
api_item_property_update($destination_course_info, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $user_id, null, null, null, null);
}
}
if (!file_exists($destination_filepath)) {
$result = @copy($origin_filepath, $destination_filepath);
if ($result) {
$filepath_to_add = str_replace(array($dest_course_path, 'document'), '', $destination_filepath);
$size = filesize($destination_filepath);
//Add to item properties to the file
$doc_id = FileManager::add_document($destination_course_info, $filepath_to_add, 'file', $size, basename($filepath_to_add));
api_item_property_update($destination_course_info, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $user_id, null, null, null, null);
}
}
}
// Replace origin course path by destination course path
if (strpos($content_html, $real_orig_url) !== false) {
//$origin_course_code
$url_course_path = str_replace($orig_course_info_path . '/' . $document_file, '', $real_orig_path);
$destination_url = $url_course_path . $destination_course_directory . '/' . $document_file . $dest_url_query;
//If the course code doesn't exist in the path? what we do? Nothing! see BT#1985
if (strpos($real_orig_path, $origin_course_code) === false) {
$url_course_path = $real_orig_path;
$destination_url = $real_orig_path;
}
$content_html = str_replace($real_orig_url, $destination_url, $content_html);
}
}
// replace origin course code by destination course code from origin url
if (strpos($real_orig_url, '?') === 0) {
$dest_url = str_replace($origin_course_code, $destination_course_code, $real_orig_url);
$content_html = str_replace($real_orig_url, $dest_url, $content_html);
}
} else {
if ($type_url == 'url') {
}
//.........这里部分代码省略.........
示例13: create_dummy_documents
/**
* Create dummy documents
*/
function create_dummy_documents()
{
$course = api_get_course_info();
$course_doc_path = $this->course->backup_path . '/document/';
$number_of_documents = rand(10, 30);
$extensions = array('html', 'doc');
$directories = array();
$property = $this->default_property;
$property['lastedit_type'] = 'DocumentAdded';
$property['tool'] = TOOL_DOCUMENT;
$doc_id = 0;
for ($doc_id = 1; $doc_id < $number_of_documents; $doc_id++) {
$path = '';
$doc_type = rand(0, count($extensions) - 1);
$extension = $extensions[$doc_type];
$filename = $this->get_dummy_content('title') . '_' . $doc_id . '.' . $extension;
$content = $this->get_dummy_content('text');
$dirs = rand(0, 3);
for ($i = 0; $i < $dirs; $i++) {
$path .= 'directory/';
$directories[$path] = 1;
}
$dir_to_make = $course_doc_path . $path;
if (!is_dir($dir_to_make)) {
@mkdir($dir_to_make, api_get_permissions_for_new_directories(), true);
}
$file = $course_doc_path . $path . $filename;
$fp = fopen($file, 'w');
fwrite($fp, $content);
fclose($fp);
$size = filesize($file);
$document = new Document($doc_id, '/' . $path . $filename, $this->get_dummy_content('description'), $this->get_dummy_content('title'), 'file', $size);
$document->item_properties[] = $property;
$this->course->add_resource($document);
}
foreach ($directories as $path => $flag) {
$path = substr($path, 0, strlen($path) - 1);
$document = new Document($doc_id++, '/' . $path, $this->get_dummy_content('description'), $this->get_dummy_content('title'), 'folder', 0);
$property['lastedit_type'] = 'FolderCreated';
$document->item_properties[] = $property;
$this->course->add_resource($document);
}
}
示例14: api_create_protected_dir
/**
* Create a new empty directory with index.html file
* @param string $name The new directory name
* @param string $parentDirectory Directory parent directory name
* @return boolean Return true if the directory was create. Otherwise return false
*/
function api_create_protected_dir($name, $parentDirectory)
{
$isCreated = false;
if (!is_writable($parentDirectory)) {
return false;
}
$fullPath = $parentDirectory . api_replace_dangerous_char($name);
if (mkdir($fullPath, api_get_permissions_for_new_directories(), true)) {
$fp = fopen($fullPath . '/index.html', 'w');
if ($fp) {
if (fwrite($fp, '<html><head></head><body></body></html>')) {
$isCreated = true;
}
}
fclose($fp);
}
return $isCreated;
}
示例15: create_zip
function create_zip()
{
$path = '';
if (empty($path)) {
$path = '/';
}
$remove_dir = $path != '/' ? substr($path, 0, strlen($path) - strlen(basename($path))) : '/';
$sys_archive_path = api_get_path(SYS_ARCHIVE_PATH);
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$temp_zip_dir = $sys_archive_path . "temp";
if (!is_dir($temp_zip_dir)) {
mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
} else {
$handle = opendir($temp_zip_dir);
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$Diff = (time() - filemtime("{$temp_zip_dir}/{$file}")) / 60 / 60;
//the "age" of the file in hours
if ($Diff > 4) {
unlink("{$temp_zip_dir}/{$file}");
}
//delete files older than 4 hours
}
}
closedir($handle);
}
$temp_zip_file = $temp_zip_dir . "/" . md5(time()) . ".zip";
//create zipfile of given directory
return array('PATH' => $path, 'PATH_TEMP_ARCHIVE' => $temp_zip_dir, 'PATH_COURSE' => $sys_course_path, 'TEMP_FILE_ZIP' => $temp_zip_file, 'PATH_REMOVE' => $remove_dir);
}