本文整理汇总了PHP中make_user_directory函数的典型用法代码示例。如果您正苦于以下问题:PHP make_user_directory函数的具体用法?PHP make_user_directory怎么用?PHP make_user_directory使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_user_directory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beginPreferences
public function beginPreferences()
{
// バックアップ作成先ディレクトリの初期値としてユーザディレクトリをセット (存在しなければここで作成)
$userdir = make_user_directory($GLOBALS['USER']->id);
if (!$userdir) {
throw SharingCart_Exception('User directory creation failure');
}
$this->setZipDir($userdir);
}
示例2: useredit_update_picture
function useredit_update_picture(&$usernew, &$userform)
{
global $CFG;
if (isset($usernew->deletepicture) and $usernew->deletepicture) {
$location = make_user_directory($usernew->id, true);
@remove_dir($location);
set_field('user', 'picture', 0, 'id', $usernew->id);
} else {
if ($usernew->picture = save_profile_image($usernew->id, $userform->get_um(), 'user')) {
set_field('user', 'picture', 1, 'id', $usernew->id);
}
}
}
示例3: useredit_update_picture
function useredit_update_picture(&$usernew, $userform)
{
global $CFG, $DB;
if (isset($usernew->deletepicture) and $usernew->deletepicture) {
$location = make_user_directory($usernew->id, true);
@remove_dir($location);
$DB->set_field('user', 'picture', 0, array('id' => $usernew->id));
} else {
if ($userform->get_new_filename('imagefile')) {
$usernew->picture = (int) save_profile_image($usernew->id, $userform, 'user', 'imagefile');
$DB->set_field('user', 'picture', $usernew->picture, array('id' => $usernew->id));
}
}
}
示例4: create_profile_image_destination
/**
* Given an upload manager with the right settings, this function performs a virus scan, and then scales and crops
* it and saves it in the right place to be a "user" or "group" image.
*
* @global object
* @param int $id user or group id
* @param string $dir type of entity - groups, user, ...
* @return string $destination (profile image destination path) or false on error
*/
function create_profile_image_destination($id, $dir = 'user')
{
global $CFG;
umask(00);
if (!file_exists($CFG->dataroot . '/' . $dir)) {
if (!mkdir($CFG->dataroot . '/' . $dir, $CFG->directorypermissions)) {
return false;
}
}
if ($dir == 'user') {
$destination = make_user_directory($id, true);
} else {
$destination = "{$CFG->dataroot}/{$dir}/{$id}";
}
if (!file_exists($destination)) {
if (!make_upload_directory(str_replace($CFG->dataroot . '/', '', $destination))) {
return false;
}
}
return $destination;
}
示例5: redirect
<?php
// $Id: pix.php,v 1.16.2.3 2008/11/01 22:49:23 skodak Exp $
// This function fetches user pictures from the data directory
// Syntax: pix.php/userid/f1.jpg or pix.php/userid/f2.jpg
// OR: ?file=userid/f1.jpg or ?file=userid/f2.jpg
require_once '../config.php';
require_once $CFG->libdir . '/filelib.php';
if (!empty($CFG->forcelogin) and !isloggedin()) {
// protect images if login required and not logged in;
// do not use require_login() because it is expensive and not suitable here anyway
redirect($CFG->pixpath . '/u/f1.png');
}
// disable moodle specific debug messages
disable_debugging();
$relativepath = get_file_argument('pix.php');
$args = explode('/', trim($relativepath, '/'));
if (count($args) == 2) {
$userid = (int) $args[0];
// do not serve images of deleted users
if ($user = get_record('user', 'id', $userid, 'deleted', 0, 'picture', 1)) {
$image = $args[1];
$pathname = make_user_directory($userid, true) . "/{$image}";
if (file_exists($pathname) and !is_dir($pathname)) {
send_file($pathname, $image);
}
}
}
// picture was deleted - use default instead
redirect($CFG->pixpath . '/u/f1.png');
示例6: SharingCart_RepositoryException
break;
}
}
if (empty($config[$repo_id])) {
throw new SharingCart_RepositoryException('Repository settings was missing');
}
if (empty($config[$repo_id]->url)) {
throw new SharingCart_RepositoryException('Repository URL was missing');
}
if (empty($config[$repo_id]->instance)) {
throw new SharingCart_RepositoryException('Repository course ID was missing');
}
if (empty($config[$repo_id]->username)) {
throw new SharingCart_RepositoryException('Repository username was missing');
}
$zip_path = make_user_directory($USER->id, true) . '/' . $sharing_cart->file;
$zip_data = file_get_contents($zip_path);
$form = new MoodleQuickForm('upload', 'post', $config[$repo_id]->url . '/course/format/repository/material.php');
$form->addElement('hidden', 'mode', 'upload');
$form->addElement('hidden', 'id', $config[$repo_id]->instance);
$form->addElement('hidden', 'username', $config[$repo_id]->username);
$form->addElement('hidden', 'password', $config[$repo_id]->password);
$form->addElement('hidden', 'icon', $sharing_cart->icon);
$form->addElement('hidden', 'type', $sharing_cart->name);
$form->addElement('hidden', 'title', $sharing_cart->text);
$form->addElement('hidden', 'file', base64_encode($zip_data));
$form->addElement('hidden', 'sha1', sha1($zip_data));
$form->addElement('hidden', 'usersite', $CFG->wwwroot);
$form->addElement('hidden', 'sitename', $SITE->fullname);
$icon = sharing_cart_lib::get_icon($sharing_cart->name, $sharing_cart->icon);
$text = '<span class="icon">' . $icon . '</span><span>' . $sharing_cart->text . '</span>';
示例7: restore_user_files
function restore_user_files($restore)
{
global $CFG;
$status = true;
$counter = 0;
// 'users' is the old users folder, 'user' is the new one, with a new hierarchy. Detect which one is here and treat accordingly
//in CFG->dataroot
$dest_dir = $CFG->dataroot . "/user";
$status = check_dir_exists($dest_dir, true);
//Now, we iterate over "user_files" records to check if that user dir must be
//copied (and renamed) to the "users" dir.
$rootdir = $CFG->dataroot . "/temp/backup/" . $restore->backup_unique_code . "/user_files";
//Check if directory exists
$userlist = array();
if (is_dir($rootdir) && ($list = list_directories($rootdir))) {
$counter = 0;
foreach ($list as $dir) {
// If there are directories in this folder, we are in the new user hierarchy
if ($newlist = list_directories("{$rootdir}/{$dir}")) {
foreach ($newlist as $olduserid) {
$userlist[$olduserid] = "{$rootdir}/{$dir}/{$olduserid}";
}
} else {
$userlist[$dir] = "{$rootdir}/{$dir}";
}
}
foreach ($userlist as $olduserid => $backup_location) {
//Look for dir like username in backup_ids
//If that user exists in backup_ids
if ($user = backup_getid($restore->backup_unique_code, "user", $olduserid)) {
//Only if user has been created now or if it existed previously, but he hasn't got an image (see bug 1123)
$newuserdir = make_user_directory($user->new_id, true);
// Doesn't create the folder, just returns the location
// restore images if new user or image does not exist yet
if (!empty($user->new) or !check_dir_exists($newuserdir)) {
if (make_user_directory($user->new_id)) {
// Creates the folder
$status = backup_copy_file($backup_location, $newuserdir, true);
$counter++;
}
//Do some output
if ($counter % 2 == 0) {
if (!defined('RESTORE_SILENTLY')) {
echo ".";
if ($counter % 40 == 0) {
echo "<br />";
}
}
backup_flush(300);
}
}
}
}
}
//If status is ok and whe have dirs created, returns counter to inform
if ($status and $counter) {
return $counter;
} else {
return $status;
}
}
示例8: notify
// Look for old moodledata/users directory
$oldusersdir = $CFG->dataroot . '/users';
if (!file_exists($oldusersdir)) {
notify('The old directory for user profile images (' . $oldusersdir . ') does not exist. Pictures cannot be restored!');
} else {
// Find user profile images that are not yet in the new directory
$folders = get_directory_list($oldusersdir, '', false, true, false);
$restored_count = 0;
foreach ($folders as $userid) {
$olddir = $oldusersdir . '/' . $userid;
$files = get_directory_list($olddir);
if (empty($files)) {
continue;
}
// Create new user directory
if (!($newdir = make_user_directory($userid))) {
// some weird directory - do not stop the upgrade, just ignore it
continue;
}
// Move contents of old directory to new one
if (file_exists($olddir) && file_exists($newdir)) {
$restored = false;
foreach ($files as $file) {
if (!file_exists($newdir . '/' . $file)) {
copy($olddir . '/' . $file, $newdir . '/' . $file);
verbose("Moved {$olddir}/{$file} into {$newdir}/{$file}");
$restored = true;
}
}
if ($restored) {
$restored_count++;
示例9: beginPreferences
public function beginPreferences()
{
// バックアップ作成先ディレクトリの初期値としてユーザディレクトリをセット
$this->setZipDir(make_user_directory($GLOBALS['USER']->id, TRUE));
}
示例10: xmldb_main_upgrade
//.........这里部分代码省略.........
if ($result && $oldversion < 2007021504) {
if (empty($CFG->enablegroupings) and !empty($CFG->group_version)) {
// delete all groupings - they do not work yet :-(
// while keeping all existing groups
require_once "{$CFG->dirroot}/group/db/upgrade.php";
undo_groupings();
}
}
if ($result && $oldversion < 2007021505) {
// Get the role id of the "Auth. User" role and check if the default role id is different
$userrole = get_record('role', 'shortname', 'user');
$defaultroleid = $CFG->defaultuserroleid;
if ($defaultroleid != $userrole->id) {
// Add in the new moodle/my:manageblocks capibility to the default user role
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
assign_capability('moodle/my:manageblocks', CAP_ALLOW, $defaultroleid, $context->id);
}
}
if ($result && $oldversion < 2007021511) {
// Small update of guest user to be 100% sure it has the correct mnethostid (MDL-10375)
set_field('user', 'mnethostid', $CFG->mnet_localhost_id, 'username', 'guest');
}
if ($result && $oldversion < 2007021532) {
// Get list of users by browsing moodledata/user
$oldusersdir = $CFG->dataroot . '/users';
$folders = get_directory_list($oldusersdir, '', false, true, false);
foreach ($folders as $userid) {
$olddir = $oldusersdir . '/' . $userid;
$files = get_directory_list($olddir);
if (empty($files)) {
continue;
}
// Create new user directory
if (!($newdir = make_user_directory($userid))) {
$result = false;
break;
}
// Move contents of old directory to new one
if (file_exists($olddir) && file_exists($newdir)) {
foreach ($files as $file) {
copy($olddir . '/' . $file, $newdir . '/' . $file);
}
} else {
notify("Could not move the contents of {$olddir} into {$newdir}!");
$result = false;
break;
}
}
// Leave a README in old users directory
$readmefilename = $oldusersdir . '/README.txt';
if ($handle = fopen($readmefilename, 'w+b')) {
if (!fwrite($handle, get_string('olduserdirectory'))) {
// Could not write to the readme file. No cause for huge concern
notify("Could not write to the README.txt file in {$readmefilename}.");
}
fclose($handle);
} else {
// Could not create the readme file. No cause for huge concern
notify("Could not create the README.txt file in {$readmefilename}.");
}
}
if ($result && $oldversion < 2007021534) {
/// Changing precision of field dst_time on table timezone to (6)
$table = new XMLDBTable('timezone');
$field = new XMLDBField('dst_time');
$field->setAttributes(XMLDB_TYPE_CHAR, '6', null, XMLDB_NOTNULL, null, null, null, '00:00', 'dst_skipweeks');
示例11: foreach
' . SharingCart_Repository::getString('begin_transfer') . '
</div>
<form action="transfer.php" method="post">
<div style="display:none;">
<input type="hidden" name="repository" value="' . $repository . '" />
<input type="hidden" name="usercourse" value="' . $usercourse . '" />
<input type="hidden" name="sessionkey" value="' . $sessionkey . '" />
</div>
<table>';
foreach ($materials as $id => $fields) {
// フィールドを分解
// @see /course/format/repository/RepositoryMaterial.php # download()
list($sha1, $type, $icon, $text) = explode('|', $fields, 4);
// ダウンロードボタンがクリックされたら、教材ファイルをHTTP通信により取得
if (!empty($downloads[$id])) {
$user_dir = make_user_directory($USER->id);
$temp_dir = make_upload_directory('temp/download', false);
$zip_name = SharingCart_Repository::getDownloadName($id);
if (!is_dir($user_dir) || !is_dir($temp_dir)) {
throw new SharingCart_RepositoryException('Directory creation failure');
}
if (is_file($user_dir . '/' . $zip_name)) {
throw new SharingCart_RepositoryException('File already exists');
}
$response_header = FileTransfer::downloadFile($temp_dir . '/' . $zip_name, $repository_wwwroot . '/course/format/repository/material.php', array('mode' => 'transfer', 'material' => $id, 'sessionkey' => $sessionkey));
// ダウンロードしたファイルのハッシュを比較してダウンロード成功かチェック
if (sha1_file($temp_dir . '/' . $zip_name) == $sha1) {
if (!rename($temp_dir . '/' . $zip_name, $user_dir . '/' . $zip_name)) {
throw new SharingCart_RepositoryException('File rename failure');
}
$sharing_cart = new stdClass();
示例12: require_login
require_once '../../config.php';
require_once './sharing_cart_table.php';
require_once './sharing_cart_lib.php';
global $DB;
//error_reporting(E_ALL);
require_login();
$course_id = required_param('course', PARAM_INT);
$return_to = $CFG->wwwroot . '/course/view.php?id=' . $course_id;
// 続行可能な通知メッセージがあれば直接リダイレクトせずにそれを表示
$notifications = array();
if (is_array($delete = optional_param('delete'))) {
// 削除実行
// SQLインジェクション対策のためintvalでフィルタリング
$delete_ids = array_map('intval', array_keys($delete)) or print_error('err_shared_id', 'block_sharing_cart', $return_to);
$items = $DB->get_records_select('sharing_cart', 'user = ' . $USER->id . ' AND ' . 'id IN (' . implode(',', $delete_ids) . ')') or print_error('err_shared_id', 'block_sharing_cart', $return_to);
$user_dir = make_user_directory($USER->id, true);
// ファイル削除に成功したIDのみをDB削除に渡す
$delete_ids = array();
foreach ($items as $id => $item) {
if (@unlink($user_dir . '/' . $item->file)) {
$delete_ids[] = $id;
} else {
$notifications[] = get_string('err_delete', 'block_sharing_cart');
}
}
delete_records_select('sharing_cart', 'id IN (' . implode(',', $delete_ids) . ')');
sharing_cart_table::renumber($USER->id);
if (count($notifications)) {
notice(implode('<br />', $notifications), $return_to);
} else {
redirect($return_to);
示例13: test_make_user_directory
function test_make_user_directory()
{
global $CFG;
// Test success conditions
$this->assertEqual("{$CFG->dataroot}/user/0/0", make_user_directory(0, true));
$this->assertEqual("{$CFG->dataroot}/user/0/1", make_user_directory(1, true));
$this->assertEqual("{$CFG->dataroot}/user/0/999", make_user_directory(999, true));
$this->assertEqual("{$CFG->dataroot}/user/1000/1000", make_user_directory(1000, true));
$this->assertEqual("{$CFG->dataroot}/user/2147483000/2147483647", make_user_directory(2147483647, true));
// Largest int possible
// Test fail conditions
$this->assertFalse(make_user_directory(2147483648, true));
// outside int boundary
$this->assertFalse(make_user_directory(-1, true));
$this->assertFalse(make_user_directory('string', true));
$this->assertFalse(make_user_directory(false, true));
$this->assertFalse(make_user_directory(true, true));
}
示例14: xmldb_main_upgrade
//.........这里部分代码省略.........
$table->addIndexInfo('courseid-name', XMLDB_INDEX_UNIQUE, array('courseid', 'name'));
/// Launch create table for grade_settings
$result = $result && create_table($table);
upgrade_main_savepoint($result, 2007100803);
}
/// cleanup in user_lastaccess
if ($result && $oldversion < 2007100902) {
$sql = "DELETE\n FROM {$CFG->prefix}user_lastaccess\n WHERE NOT EXISTS (SELECT 'x'\n FROM {$CFG->prefix}course c\n WHERE c.id = {$CFG->prefix}user_lastaccess.courseid)";
execute_sql($sql);
upgrade_main_savepoint($result, 2007100902);
}
/// drop old gradebook tables
if ($result && $oldversion < 2007100903) {
$tables = array('grade_category', 'grade_item', 'grade_letter', 'grade_preferences', 'grade_exceptions');
foreach ($tables as $table) {
$table = new XMLDBTable($table);
if (table_exists($table)) {
drop_table($table);
}
}
upgrade_main_savepoint($result, 2007100903);
}
if ($result && $oldversion < 2007101500 && !file_exists($CFG->dataroot . '/user')) {
// Get list of users by browsing moodledata/user
$oldusersdir = $CFG->dataroot . '/users';
$folders = get_directory_list($oldusersdir, '', false, true, false);
foreach ($folders as $userid) {
$olddir = $oldusersdir . '/' . $userid;
$files = get_directory_list($olddir);
if (empty($files)) {
continue;
}
// Create new user directory
if (!($newdir = make_user_directory($userid))) {
// some weird directory - do not stop the upgrade, just ignore it
continue;
}
// Move contents of old directory to new one
if (file_exists($olddir) && file_exists($newdir)) {
foreach ($files as $file) {
copy($olddir . '/' . $file, $newdir . '/' . $file);
}
} else {
notify("Could not move the contents of {$olddir} into {$newdir}!");
$result = false;
break;
}
}
// Leave a README in old users directory
$readmefilename = $oldusersdir . '/README.txt';
if ($handle = fopen($readmefilename, 'w+b')) {
if (!fwrite($handle, get_string('olduserdirectory'))) {
// Could not write to the readme file. No cause for huge concern
notify("Could not write to the README.txt file in {$readmefilename}.");
}
fclose($handle);
} else {
// Could not create the readme file. No cause for huge concern
notify("Could not create the README.txt file in {$readmefilename}.");
}
}
if ($result && $oldversion < 2007101502) {
/// try to remove duplicate entries
$SQL = "SELECT userid, itemid, COUNT(*)\n FROM {$CFG->prefix}grade_grades\n GROUP BY userid, itemid\n HAVING COUNT( * ) >1";
// duplicates found
if ($rs = get_recordset_sql($SQL)) {
示例15: fetch_user_image
/**
* Returns the user's image as a base64 encoded string.
*
* @param int $userid The id of the user
* @return string The encoded image
*/
function fetch_user_image($username)
{
global $CFG, $DB;
if ($user = $DB->get_record('user', array('username' => $username, 'mnethostid' => $CFG->mnet_localhost_id))) {
$filename1 = make_user_directory($user->id, true) . "/f1.jpg";
$filename2 = make_user_directory($user->id, true) . "/f2.jpg";
$return = array();
if (file_exists($filename1)) {
$return['f1'] = base64_encode(file_get_contents($filename1));
}
if (file_exists($filename2)) {
$return['f2'] = base64_encode(file_get_contents($filename2));
}
return $return;
}
return false;
}