/** * Constructor * * Will fail if non existent User or Blog is requested. * But specific access permissions on (threfore existence of) this User or Blog should have been tested before anyway. * * @param string Root type: 'user', 'group' or 'collection' * @param integer ID of the user, the group or the collection the file belongs to... * @param boolean Create the directory, if it does not exist yet? */ function FileRoot($root_type, $root_in_type_ID, $create = true) { // Store type: $this->type = $root_type; // Store ID in type: $this->in_type_ID = $root_in_type_ID; // Generate unique ID: $this->ID = FileRoot::gen_ID($root_type, $root_in_type_ID); switch ($root_type) { case 'user': $UserCache =& get_Cache('UserCache'); $User =& $UserCache->get_by_ID($root_in_type_ID); $this->name = $User->get('preferredname'); //.' ('. /* TRANS: short for "user" */ T_('u').')'; $this->ads_path = $User->get_media_dir($create); $this->ads_url = $User->get_media_url(); return; case 'collection': $BlogCache =& get_Cache('BlogCache'); /** * @var Blog */ $Blog =& $BlogCache->get_by_ID($root_in_type_ID); $this->name = $Blog->get('shortname'); //.' ('. /* TRANS: short for "blog" */ T_('b').')'; $this->ads_path = $Blog->get_media_dir($create); $this->ads_url = $Blog->get_media_url(); return; case 'skins': // fp> some stuff here should go out of here... but I don't know where to put it yet. I'll see after the Skin refactoring. global $Settings, $Debuglog; /** * @var User */ global $current_User; if (!$Settings->get('fm_enable_roots_skins')) { // Skins root is disabled: $Debuglog->add('Attempt to access skins dir, but this feature is globally disabled', 'files'); } elseif (!$current_User->check_perm('templates')) { // No perm to access templates: $Debuglog->add('Attempt to access skins dir, but no permission', 'files'); } else { global $skins_path, $skins_url; $this->name = T_('Skins'); $this->ads_path = $skins_path; $this->ads_url = $skins_url; } return; } debug_die("Root_type={$root_type} not supported"); }
/** * Import user's avatar * * @param integer User ID (from b2evo) * @param string Path avatars * @param string File name of user's avatar */ function phpbb_import_avatar($user_ID, $path_avatars, $user_avatar) { global $DB, $tableprefix; if (!empty($user_avatar) && file_exists($path_avatars . $user_avatar)) { // Import user's avatar $FileRootCache =& get_FileRootCache(); $root_ID = FileRoot::gen_ID('user', $user_ID); $imported_file_ID = copy_file($path_avatars . $user_avatar, $root_ID, 'profile_pictures', false); if (!empty($imported_file_ID)) { // Update user's avatar mysql_query('UPDATE ' . $tableprefix . 'users SET user_avatar_file_ID = ' . $DB->quote($imported_file_ID) . ' WHERE user_ID = ' . $DB->quote($user_ID) . ' AND user_avatar_file_ID IS NULL', $DB->dbhandle); } } }
/** * Get a FileRoot (cached). * * @param string Root type: 'user', 'group', 'collection' or 'absolute' * @param integer ID of the user, the group or the collection the file belongs to... * @param boolean Create the directory, if it does not exist yet? * @return FileRoot|false FileRoot on success, false on failure (ads_path is false). */ function &get_by_type_and_ID($root_type, $root_in_type_ID, $create = false) { $root_ID = FileRoot::gen_ID($root_type, $root_in_type_ID); if (!isset($this->cache[$root_ID])) { // Not in Cache, let's instantiate: $Root = new FileRoot($root_type, $root_in_type_ID, $create); // COPY (func) if (empty($Root->ads_path)) { $Root = false; } $this->cache[$root_ID] =& $Root; } return $this->cache[$root_ID]; }
/** * Get link to edit files * * @param string link (false on error) */ function get_filemanager_link() { load_class('/files/model/_fileroot.class.php'); return 'admin.php?ctrl=files&root=' . FileRoot::gen_ID('collection', $this->ID); }
} if (!empty($checked_attachments)) { // cut the last comma $checked_attachments = substr($checked_attachments, 0, strlen($checked_attachments) - 1); } } if ($commented_Item->can_attach() && ($action == 'preview' || $ok) && !empty($_FILES['uploadfile']) && !empty($_FILES['uploadfile']['size']) && !empty($_FILES['uploadfile']['size'][0])) { // attaching files is permitted $FileRootCache =& get_FileRootCache(); if (is_logged_in()) { // registered user $root = FileRoot::gen_ID('user', $current_User->ID); $path = 'comments/p' . $commented_Item->ID; } else { // anonymous user $root = FileRoot::gen_ID('collection', $commented_Item->Blog->ID); $path = 'anonymous_comments/p' . $commented_Item->ID; } // process upload $result = process_upload($root, $path, true, false, false, false); if (!empty($result)) { $uploadedFiles = $result['uploadedFiles']; if (!empty($result['failedFiles'])) { // upload failed $Messages->add(T_('Couldn\'t attach selected file:') . $result['failedFiles'][0], 'warning'); } if (!empty($uploadedFiles)) { // upload succeeded foreach ($uploadedFiles as $File) { if (empty($preview_attachments)) { $preview_attachments = $File->ID;
/** * Constructor * * Will fail if non existent User or Blog is requested. * But specific access permissions on (threfore existence of) this User or Blog should have been tested before anyway. * * @param string Root type: 'user', 'group' or 'collection' * @param integer ID of the user, the group or the collection the file belongs to... * @param boolean Create the directory, if it does not exist yet? */ function FileRoot($root_type, $root_in_type_ID, $create = true) { /** * @var User */ global $current_User; global $Messages; global $Settings, $Debuglog; global $Blog; // Store type: $this->type = $root_type; // Store ID in type: $this->in_type_ID = $root_in_type_ID; // Generate unique ID: $this->ID = FileRoot::gen_ID($root_type, $root_in_type_ID); switch ($root_type) { case 'user': $UserCache =& get_UserCache(); if (!($User =& $UserCache->get_by_ID($root_in_type_ID, false, false))) { // User not found return false; } $this->name = $User->get('login'); //.' ('. /* TRANS: short for "user" */ T_('u').')'; $this->ads_path = $User->get_media_dir($create); $this->ads_url = $User->get_media_url(); return; case 'collection': $BlogCache =& get_BlogCache(); if (!($Blog =& $BlogCache->get_by_ID($root_in_type_ID, false, false))) { // Blog not found return false; } $this->name = $Blog->get('shortname'); //.' ('. /* TRANS: short for "blog" */ T_('b').')'; $this->ads_path = $Blog->get_media_dir($create); $this->ads_url = $Blog->get_media_url(); return; case 'shared': // fp> TODO: handle multiple shared directories global $media_path, $media_url; $rds_shared_subdir = 'shared/global/'; $ads_shared_dir = $media_path . $rds_shared_subdir; if (!$Settings->get('fm_enable_roots_shared')) { // Shared dir is disabled: $Debuglog->add('Attempt to access shared dir, but this feature is globally disabled', 'files'); } elseif (!mkdir_r($ads_shared_dir)) { // Only display error on an admin page: if (is_admin_page()) { $Messages->add(sprintf(T_('The directory «%s» could not be created.'), $rds_shared_subdir) . get_manual_link('directory_creation_error'), 'error'); } } else { $this->name = T_('Shared'); $this->ads_path = $ads_shared_dir; if (isset($Blog)) { // (for now) Let's make shared files appear as being part of the currently displayed blog: $this->ads_url = $Blog->get_local_media_url() . 'shared/global/'; } else { $this->ads_url = $media_url . 'shared/global/'; } } return; case 'skins': // fp> some stuff here should go out of here... but I don't know where to put it yet. I'll see after the Skin refactoring. if (!$Settings->get('fm_enable_roots_skins')) { // Skins root is disabled: $Debuglog->add('Attempt to access skins dir, but this feature is globally disabled', 'files'); } elseif (empty($current_User) || !$current_User->check_perm('templates')) { // No perm to access templates: $Debuglog->add('Attempt to access skins dir, but no permission', 'files'); } else { global $skins_path, $skins_url; $this->name = T_('Skins'); $this->ads_path = $skins_path; if (isset($Blog)) { // (for now) Let's make skin files appear as being part of the currently displayed blog: $this->ads_url = $Blog->get_local_skins_url(); } else { $this->ads_url = $skins_url; } } return; } debug_die("Invalid root type"); }
/** * Get link to edit files * * @param string link (false on error) */ function get_filemanager_link() { global $admin_url; load_class('/files/model/_fileroot.class.php', 'FileRoot'); return $admin_url . '?ctrl=files&root=' . FileRoot::gen_ID('collection', $this->ID); }
/** * Update user avatar file to the currently uploaded file * * @return mixed true on success, allowed action otherwise. */ function update_avatar_from_upload() { global $current_User, $Messages, $Settings; if (!$current_User->can_moderate_user($this->ID) && $this->ID != $current_User->ID) { // user is only allowed to update him/herself $Messages->add(T_('You are only allowed to update your own profile!'), 'error'); return 'view'; } // process upload $FileRootCache =& get_FileRootCache(); $root = FileRoot::gen_ID('user', $this->ID); $result = process_upload($root, 'profile_pictures', true, false, true, false, $Settings->get('min_picture_size')); if (empty($result)) { $Messages->add(T_('You don\'t have permission to selected user file root.'), 'error'); return 'view'; } $uploadedFiles = $result['uploadedFiles']; if (!empty($uploadedFiles)) { // upload was successful $File = $uploadedFiles[0]; $duplicated_files = $File->get_duplicated_files(array('root_ID' => $this->ID)); if (!empty($duplicated_files)) { // The file is the duplicate of other profile picture, we should delete it $File->dbdelete(); $Messages->add(T_('It seems you are trying to upload the same profile picture twice.'), 'error'); return 'edit'; } elseif ($File->is_image()) { // uploaded file is an image $LinkOwner = new LinkUser($this); $File->link_to_Object($LinkOwner); $avatar_changed = false; if (empty($this->avatar_file_ID)) { // set uploaded image as avatar $this->set('avatar_file_ID', $File->ID, true); // update profileupdate_date, because a publicly visible user property was changed $this->set_profileupdate_date(); $this->dbupdate(); $avatar_changed = true; $Messages->add(T_('Profile picture has been changed.'), 'success'); } else { // User already has the avatar $Messages->add(T_('New picture has been uploaded.'), 'success'); } // Clear previous Links to load new uploaded file $LinkOwner->clear_Links(); // Send notification email about the changes of user account $this->send_account_changed_notification($avatar_changed, $File->ID); return true; } else { // uploaded file is not an image, delete the file $Messages->add(T_('The file you uploaded does not seem to be an image.')); $File->unlink(); } } $failedFiles = $result['failedFiles']; if (!empty($failedFiles)) { $Messages->add($failedFiles[0]); } return 'edit'; }
/** * Import user's avatar * * @param integer User ID (from b2evo) * @param string Path avatars * @param string File name of user's avatar */ function phpbb_import_avatar($user_ID, $path_avatars, $user_avatar) { global $DB, $tableprefix; if (!empty($user_avatar) && file_exists($path_avatars . $user_avatar)) { // Import user's avatar $FileRootCache =& get_FileRootCache(); $root_ID = FileRoot::gen_ID('user', $user_ID); $imported_file_ID = copy_file($path_avatars . $user_avatar, $root_ID, 'profile_pictures', false); if (!empty($imported_file_ID)) { // Update user's avatar mysqli_query($DB->dbhandle, 'UPDATE ' . $tableprefix . 'users SET user_avatar_file_ID = ' . $DB->quote($imported_file_ID) . ' WHERE user_ID = ' . $DB->quote($user_ID) . ' AND user_avatar_file_ID IS NULL'); // Insert a link with new file global $localtimenow; mysql_query($DB->dbhandle, 'INSERT INTO ' . $tableprefix . 'links ( link_datecreated, link_datemodified, link_creator_user_ID, link_lastedit_user_ID, link_usr_ID, link_file_ID ) VALUES ( ' . $DB->quote(date('Y-m-d H:i:s', $localtimenow)) . ', ' . $DB->quote(date('Y-m-d H:i:s', $localtimenow)) . ', ' . $DB->quote($user_ID) . ', ' . $DB->quote($user_ID) . ', ' . $DB->quote($user_ID) . ', ' . $DB->quote($imported_file_ID) . ' )'); } } }
/** * Save to disk and attach to user * * @param object User (User MUST BE created in DB) * @param string content of image file * @param boolean TRUE - to expand photos to a square */ function userimg_attach_photo(&$User, $image_content, $expand_pics) { if (empty($image_content)) { // No image content: return; } // Load FileRoot class: load_class('files/model/_fileroot.class.php', 'FileRoot'); // Try to create FileRoot for the user: $FileRootCache =& get_FileRootCache(); $fileroot_ID = FileRoot::gen_ID('user', $User->ID); $user_FileRoot =& $FileRootCache->get_by_ID($fileroot_ID, true); if (!$user_FileRoot) { // Impossible to create FileRoot for the User $this->debug_log(sprintf('FileRoot cannot be created for User #%s', $User->ID)); // Exit here: return; } // Try to create a folder for image: $folder_name = 'profile_pictures'; // Folder name in user dir where we should store image file $image_name = 'ldap.jpg'; // File name of the image file $folder_path = $user_FileRoot->ads_path . $folder_name; $image_path = $folder_path . '/' . $image_name; if (!mkdir_r($folder_path)) { // Folder cannot be created $this->debug_log(sprintf('Cannot create image folder <b>%s</b>', $folder_path)); // Exit here: return; } // Create/rewrite image file: $image_handle = fopen($image_path, 'w+'); if ($image_handle === false) { // File cannot be created $this->debug_log(sprintf('Cannot create image file <b>%s</b>', $image_path)); // Exit here: return; } // Write image content in the file: fwrite($image_handle, $image_content); fclose($image_handle); // Create file object to work with image: $File = new File('user', $User->ID, $folder_name . '/' . $image_name); $File->rm_cache(); $File->load_meta(true); if ($expand_pics) { // Expand a photo to a square: $this->userimg_expand_to_square($File); } // Link image file to the user: $LinkOwner = new LinkUser($User); $File->link_to_Object($LinkOwner); $avatar_file_ID = $User->get('avatar_file_ID'); if (empty($avatar_file_ID)) { // If user has no main avatar yet then use this new one: $User->set('avatar_file_ID', $File->ID); $User->dbupdate(); } }
$title = $current_File->dget('title'); if ($title !== '') { $r .= '<span class="filemeta"> - ' . $title . '</span>'; } return $r; } $Results->cols[] = array('th' => T_('Destination'), 'td' => '%display_link()%', 'td_class' => 'fm_filename'); $Results->cols[] = array('th' => T_('Link ID'), 'td' => '$link_ID$', 'th_class' => 'shrinkwrap', 'td_class' => 'shrinkwrap'); if ($current_User->check_perm('files', 'view', false, $Blog->ID)) { $Results->cols[] = array('th' => T_('Actions'), 'td_class' => 'shrinkwrap', 'td' => '%link_actions( #link_ID#, {ROW_IDX_TYPE}, "' . $LinkOwner->type . '" )%'); } $Results->cols[] = array('th' => T_('Position'), 'td_class' => 'shrinkwrap', 'td' => '%display_link_position( {row} )%'); // Add attr "id" to handle quick uploader $compact_results_params = $AdminUI->get_template('compact_results'); $compact_results_params['body_start'] = str_replace('<tbody', '<tbody id="filelist_tbody"', $compact_results_params['body_start']); $compact_results_params['no_results_start'] = str_replace('<tbody', '<tbody id="filelist_tbody"', $compact_results_params['no_results_start']); $Results->display($compact_results_params); // Print out JavaScript to change a link position echo_link_position_js(); if ($Results->total_pages == 0) { // If no results we should get a template of headers in order to add it on first quick upload ob_start(); $Results->display_col_headers(); $table_headers = ob_get_clean(); } else { // Headers are already on the page $table_headers = ''; } // Display a button to quick upload the files by drag&drop method display_dragdrop_upload_button(array('before' => '<div id="fileuploader_form">', 'after' => '</div>', 'fileroot_ID' => FileRoot::gen_ID('collection', $Blog->ID), 'path' => '/quick-uploads/' . ($LinkOwner->type == 'item' ? 'p' : 'c') . $LinkOwner->link_Object->ID . '/', 'list_style' => 'table', 'template_filerow' => '<table><tr>' . '<td class="firstcol shrinkwrap qq-upload-image"><span class="qq-upload-spinner"> </span></td>' . '<td class="qq-upload-file fm_filename"> </td>' . '<td class="qq-upload-link-id shrinkwrap"> </td>' . '<td class="qq-upload-link-actions shrinkwrap">' . '<div class="qq-upload-status">' . TS_('Uploading...') . '<span class="qq-upload-spinner"></span>' . '<span class="qq-upload-size"></span>' . '<a class="qq-upload-cancel" href="#">' . TS_('Cancel') . '</a>' . '</div>' . '</td>' . '<td class="qq-upload-link-position lastcol shrinkwrap"></td>' . '</tr></table>', 'display_support_msg' => false, 'additional_dropzone' => '#filelist_tbody', 'filename_before' => '', 'LinkOwner' => $LinkOwner, 'display_status_success' => false, 'status_conflict_place' => 'before_button', 'conflict_file_format' => 'full_path_link', 'resize_frame' => true, 'table_headers' => $table_headers));