function file_type(&$row) { global $current_File; // Instantiate a File object for this line: $current_File = new File($row->file_root_type, $row->file_root_ID, $row->file_path); // COPY (FUNC) needed for following columns // Flow meta data into File object: $current_File->load_meta(false, $row); return $current_File->get_preview_thumb('fulltype'); }
function display_subtype(&$row) { if (empty($row->file_ID)) { return ''; } global $current_File; // Instantiate a File object for this line: $current_File = new File($row->file_root_type, $row->file_root_ID, $row->file_path); // COPY! // Flow meta data into File object: $current_File->load_meta(false, $row); return $current_File->get_preview_thumb('fulltype'); }
/** * Instantiate a DataObject from a table row and then cache it. * * @param Object Database row * @return Object */ function &instantiate(&$db_row) { // Get ID of the object we'ere preparing to instantiate... $obj_ID = $db_row->{$this->dbIDname}; if (!empty($obj_ID)) { // If the object ID is valid: if (!isset($this->cache[$obj_ID])) { // If not already cached: // Instantiate a File object for this line: $current_File = new File($db_row->file_root_type, $db_row->file_root_ID, $db_row->file_path); // COPY! // Flow meta data into File object: $current_File->load_meta(false, $db_row); $this->add($current_File); } else { // Already cached: $current_File =& $this->cache[$obj_ID]; // Flow meta data into File object: $current_File->load_meta(false, $db_row); } } return $this->cache[$obj_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(); } }