WFU_PHP_ARRAY_MAXLEN ) $_SESSION['wfu_filepath_safe_storage'] = array(); //extract sort info from basedir $sort = ""; if ( $basedir !== false ) { $ret = wfu_extract_sortdata_from_path($basedir); $basedir = $ret['path']; $sort = $ret['sort']; } if ( $sort == "" ) $sort = 'name'; if ( substr($sort, 0, 1) == '-' ) $order = SORT_DESC; else $order = SORT_ASC; //adjust basedir to have a standard format if ( $basedir !== false ) { if ( substr($basedir, -1) != '/' ) $basedir .= '/'; if ( substr($basedir, 0, 1) == '/' ) $basedir = substr($basedir, 1); //calculate the absolute path of basedir knowing that basedir is relative to website root $basedir = wfu_path_rel2abs($basedir); if ( !file_exists($basedir) ) $basedir = false; } //set basedit to default value if empty if ( $basedir === false ) { $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" )); $basedir = ( isset($plugin_options['basedir']) ? $plugin_options['basedir'] : "" ); $temp_params = array( 'uploadpath' => $basedir, 'accessmethod' => 'normal', 'ftpinfo' => '', 'useftpdomain' => 'false' ); $basedir = wfu_upload_plugin_full_path($temp_params); } //find relative dir $reldir = str_replace(ABSPATH, "root/", $basedir); //save dir route to an array $parts = explode('/', $reldir); $route = array(); $prev = ""; foreach ( $parts as $part ) { $part = trim($part); if ( $part != "" ) { // if ( $part == 'root' && $prev == "" ) $prev = ABSPATH; if ( $part == 'root' && $prev == "" ) $prev = ""; else $prev .= $part.'/'; array_push($route, array( 'item' => $part, 'path' => $prev )); } } //calculate upper directory $updir = substr($basedir, 0, -1); $delim_pos = strrpos($updir, '/'); if ( $delim_pos !== false ) $updir = substr($updir, 0, $delim_pos + 1); $echo_str = "\n".'
'; $echo_str .= "\n\t".'

Wordpress File Upload Control Panel

'; $echo_str .= "\n\t".'
'; $echo_str .= wfu_generate_dashboard_menu("\n\t\t", "File Browser"); $echo_str .= "\n\t".'
'; $echo_str .= "\n\t\t".'Location: '; foreach ( $route as $item ) { // store dir path that we need to pass to other functions in session, instead of exposing it in the url $dir_code = wfu_safe_store_filepath($item['path']); $echo_str .= ''.$item['item'].''; $echo_str .= '/'; } //file browser header $echo_str .= "\n\t".'
'; // $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.$sort.']]'); // $echo_str .= "\n\t".'Create folder'; $echo_str .= "\n\t".'
'; $echo_str .= "\n\t\t".''; $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t".''; $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t\t".''; //find contents of current folder $dirlist = array(); $filelist = array(); if ( $handle = opendir($basedir) ) { $blacklist = array('.', '..'); while ( false !== ($file = readdir($handle)) ) if ( !in_array($file, $blacklist) ) { $filepath = $basedir.$file; $stat = stat($filepath); if ( is_dir($filepath) ) { array_push($dirlist, array( 'name' => $file, 'fullpath' => $filepath, 'mdate' => $stat['mtime'] )); } else { //find relative file record in database together with user data; //if the file is php, then file record is null meaning that the file can only be viewed //if file record is not found then the file can only be viewed if ( preg_match("/\.php$/", $filepath) ) $filerec = null; else $filerec = wfu_get_file_rec($filepath, true); //find user who uploaded the file $username = ''; if ( $filerec != null ) $username = wfu_get_username_by_id($filerec->uploaduserid); array_push($filelist, array( 'name' => $file, 'fullpath' => $filepath, 'size' => $stat['size'], 'mdate' => $stat['mtime'], 'user' => $username, 'filedata' => $filerec )); } } closedir($handle); } $dirsort = ( substr($sort, -4) == 'date' ? 'mdate' : substr($sort, -4) ); $filesort = $dirsort; $dirorder = $order; if ( $dirsort == 'size' ) { $dirsort = 'name'; $dirorder = SORT_ASC; } if ( $dirsort == 'user' ) { $dirsort = 'name'; $dirorder = SORT_ASC; } $dirlist = wfu_array_sort($dirlist, $dirsort, $dirorder); $filelist = wfu_array_sort($filelist, $filesort, $order); //show subfolders first if ( $reldir != "root/" ) { $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($updir)); $echo_str .= "\n\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t".''; } $ii = 1; foreach ( $dirlist as $dir ) { $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($dir['fullpath']).'[['.$sort.']]'); $echo_str .= "\n\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t".''; $ii ++; } //show contained files foreach ( $filelist as $file ) { if ( $file['filedata'] != null ) $file_code = wfu_safe_store_filepath(wfu_path_abs2rel($file['fullpath']).'[['.$sort.']]'); $echo_str .= "\n\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t".''; $ii ++; } $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t".'
'; $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.( substr($sort, -4) == 'name' ? ( $order == SORT_ASC ? '-name' : 'name' ) : 'name' ).']]'); $echo_str .= "\n\t\t\t\t\t\t".'Name'.( substr($sort, -4) == 'name' ? ( $order == SORT_ASC ? ' ↑' : ' ↓' ) : '' ).''; $echo_str .= "\n\t\t\t\t\t".''; $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.( substr($sort, -4) == 'size' ? ( $order == SORT_ASC ? '-size' : 'size' ) : 'size' ).']]'); $echo_str .= "\n\t\t\t\t\t\t".'Size'.( substr($sort, -4) == 'size' ? ( $order == SORT_ASC ? ' ↑' : ' ↓' ) : '' ).''; $echo_str .= "\n\t\t\t\t\t".''; $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.( substr($sort, -4) == 'date' ? ( $order == SORT_ASC ? '-date' : 'date' ) : 'date' ).']]'); $echo_str .= "\n\t\t\t\t\t\t".'Date'.( substr($sort, -4) == 'date' ? ( $order == SORT_ASC ? ' ↑' : ' ↓' ) : '' ).''; $echo_str .= "\n\t\t\t\t\t".''; $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.( substr($sort, -4) == 'user' ? ( $order == SORT_ASC ? '-user' : 'user' ) : 'user' ).']]'); $echo_str .= "\n\t\t\t\t\t\t".'Uploaded By'.( substr($sort, -4) == 'user' ? ( $order == SORT_ASC ? ' ↑' : ' ↓' ) : '' ).''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".'
'; $echo_str .= "\n\t\t\t\t\t\t".'..'; $echo_str .= "\n\t\t\t\t\t".'
'; $echo_str .= "\n\t\t\t\t\t\t".''.$dir['name'].''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".' '.date("d/m/Y H:i:s", $dir['mdate']).'
'; if ( $file['filedata'] != null ) $echo_str .= "\n\t\t\t\t\t\t".''.$file['name'].''; else $echo_str .= "\n\t\t\t\t\t\t".''.$file['name'].''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''.$file['size'].''.date("d/m/Y H:i:s", $file['mdate']).''.$file['user'].''; if ( $file['filedata'] != null ) { if ( count($file['filedata']->userdata) > 0 ) { $echo_str .= "\n\t\t\t\t\t\t".''; } } $echo_str .= "\n\t\t\t\t\t".'
'; $echo_str .= "\n\t\t".''; $echo_str .= "\n\t".'
'; $echo_str .= "\n\t".'
'; $echo_str .= "\n".'
'; return $echo_str; } function wfu_current_user_owes_file($filepath) { //first check if file has a restricted extension; for security reasons some file extensions cannot be owned if ( wfu_file_extension_restricted($filepath) ) return false; //then get file data from database, if exist $filerec = wfu_get_file_rec($filepath, false); if ( $filerec == null ) return false; $user = wp_get_current_user(); if ( 0 == $user->ID ) return false; if ( current_user_can('manage_options') ) return true; return false; } function wfu_current_user_allowed_action($action, $filepath) { //first get file data from database, if exist $filerec = wfu_get_file_rec($filepath, false); $user = wp_get_current_user(); if ( 0 == $user->ID ) return null; else $is_admin = current_user_can('manage_options'); if ( !$is_admin ) { return null; } return $user; } function wfu_current_user_allowed_action_remote($action, $filepath, $userid) { //first get file data from database, if exist $filerec = wfu_get_file_rec($filepath, false); if ( 0 == $userid ) return null; else $is_admin = user_can($userid, 'manage_options'); if ( !$is_admin ) { return null; } return true; } function wfu_rename_file_prompt($file_code, $type, $error) { if ( $type == 'dir' ) return; $siteurl = site_url(); $is_admin = current_user_can( 'manage_options' ); //check if user is allowed to view file details if ( !$is_admin ) { return; } $file_code = wfu_sanitize_code($file_code); $dec_file = wfu_get_filepath_from_safe($file_code); if ( $dec_file === false ) return; //first extract sort info from dec_file $ret = wfu_extract_sortdata_from_path($dec_file); $dec_file = wfu_path_rel2abs($ret['path']); if ( $type == 'dir' && substr($dec_file, -1) == '/' ) $dec_file = substr($dec_file, 0, -1); //check if user is allowed to perform this action if ( !wfu_current_user_owes_file($dec_file) ) return; $parts = pathinfo($dec_file); $newname = $parts['basename']; $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($parts['dirname']).'[['.$ret['sort'].']]'); $echo_str = "\n".'
'; if ( $error ) { $newname = $_SESSION['wfu_rename_file']['newname']; $echo_str .= "\n\t".'
'; $echo_str .= "\n\t\t".'

'.$_SESSION['wfu_rename_file_error'].'

'; $echo_str .= "\n\t".'
'; } $echo_str .= "\n\t".'
'; if ( $is_admin ) $echo_str .= "\n\t\t".'Go back'; $echo_str .= "\n\t".'
'; $echo_str .= "\n\t".'

Rename '.( $type == 'dir' ? 'Folder' : 'File' ).'

'; if ( $is_admin ) $echo_str .= "\n\t".'
'; $echo_str .= "\n\t\t".''; $echo_str .= "\n\t\t".''; $echo_str .= "\n\t\t".''; if ( $type == 'dir' ) $echo_str .= "\n\t\t".'
'; elseif ( $is_admin ) $echo_str .= "\n\t\t".'
'; $echo_str .= "\n\t\t".''; $echo_str .= "\n\t\t".'

'; $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t".'

'; $echo_str .= "\n\t".'
'; $echo_str .= "\n".'
'; return $echo_str; } function wfu_rename_file($file_code, $type) { if ( $type == 'dir' ) return; $user = wp_get_current_user(); $is_admin = current_user_can( 'manage_options' ); //check if user is allowed to view file details if ( !$is_admin ) { return; } $file_code = wfu_sanitize_code($file_code); $dec_file = wfu_get_filepath_from_safe($file_code); if ( $dec_file === false ) return; $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file)); if ( $type == 'dir' && substr($dec_file, -1) == '/' ) $dec_file = substr($dec_file, 0, -1); if ( !file_exists($dec_file) ) return; //check if user is allowed to perform this action if ( !wfu_current_user_owes_file($dec_file) ) return; $parts = pathinfo($dec_file); $error = ""; if ( isset($_POST['wfu_newname']) && isset($_POST['submit']) ) { if ( $_POST['submit'] == "Rename" && $_POST['wfu_newname'] != $parts['basename'] ) { $new_file = $parts['dirname'].'/'.$_POST['wfu_newname']; if ( $_POST['wfu_newname'] == "" ) $error = 'Error: New '.( $type == 'dir' ? 'folder ' : 'file' ).'name cannot be empty!'; elseif ( preg_match("/[^A-Za-z0-9_.#\-$]/", $_POST['wfu_newname']) ) $error = 'Error: name contained invalid characters that were stripped off! Please try again.'; elseif ( substr($_POST['wfu_newname'], -1 - strlen($parts['extension'])) != '.'.$parts['extension'] ) $error = 'Error: new and old file name extensions must be identical! Please correct.'; elseif ( wfu_file_extension_restricted($_POST['wfu_newname']) ) $error = 'Error: the new file name has an extension that is forbidden for security reasons. Please correct.'; elseif ( file_exists($new_file) ) $error = 'Error: The '.( $type == 'dir' ? 'folder' : 'file' ).' '.$_POST['wfu_newname'].' already exists! Please choose another one.'; else { //pre-log rename action if ( $type == 'file' ) $retid = wfu_log_action('rename:'.$new_file, $dec_file, $user->ID, '', 0, 0, '', null); //perform rename action if ( rename($dec_file, $new_file) == false ) $error = 'Error: Rename of '.( $type == 'dir' ? 'folder' : 'file' ).' '.$parts['basename'].' failed!'; //revert log action if file was not renamed if ( $type == 'file' && !file_exists($new_file) ) wfu_revert_log_action($retid); } } } if ( $error != "" ) { $_SESSION['wfu_rename_file_error'] = $error; $_SESSION['wfu_rename_file']['newname'] = preg_replace("/[^A-Za-z0-9_.#\-$]/", "", $_POST['wfu_newname']); } return ( $error == "" ); } function wfu_delete_file_prompt($file_code, $type) { if ( $type == 'dir' ) return; $siteurl = site_url(); $is_admin = current_user_can( 'manage_options' ); //check if user is allowed to view file details if ( !$is_admin ) { return; } $file_code = wfu_sanitize_code($file_code); $dec_file = wfu_get_filepath_from_safe($file_code); if ( $dec_file === false ) return; //first extract sort info from dec_file $ret = wfu_extract_sortdata_from_path($dec_file); $dec_file = wfu_path_rel2abs($ret['path']); if ( $type == 'dir' && substr($dec_file, -1) == '/' ) $dec_file = substr($dec_file, 0, -1); //check if user is allowed to perform this action if ( !wfu_current_user_owes_file($dec_file) ) return; $parts = pathinfo($dec_file); $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($parts['dirname']).'[['.$ret['sort'].']]'); $echo_str = "\n".'
'; $echo_str .= "\n\t".'
'; if ( $is_admin ) $echo_str .= "\n\t\t".'Go back'; $echo_str .= "\n\t".'
'; $echo_str .= "\n\t".'

Delete '.( $type == 'dir' ? 'Folder' : 'File' ).'

'; if ( $is_admin ) $echo_str .= "\n\t".'
'; $echo_str .= "\n\t\t".''; $echo_str .= "\n\t\t".''; $echo_str .= "\n\t\t".''; $echo_str .= "\n\t\t".'
'; $echo_str .= "\n\t\t".'

'; $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t".'

'; $echo_str .= "\n\t".'
'; $echo_str .= "\n".'
'; return $echo_str; } function wfu_delete_file($file_code, $type) { if ( $type == 'dir' ) return; $user = wp_get_current_user(); $is_admin = current_user_can( 'manage_options' ); //check if user is allowed to view file details if ( !$is_admin ) { return; } $file_code = wfu_sanitize_code($file_code); $dec_file = wfu_get_filepath_from_safe($file_code); if ( $dec_file === false ) return; $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file)); if ( $type == 'dir' && substr($dec_file, -1) == '/' ) $dec_file = substr($dec_file, 0, -1); //check if user is allowed to perform this action if ( !wfu_current_user_owes_file($dec_file) ) return; if ( isset($_POST['submit']) ) { if ( $_POST['submit'] == "Delete" ) { //pre-log delete action if ( $type == 'file' ) $retid = wfu_log_action('delete', $dec_file, $user->ID, '', 0, 0, '', null); if ( $type == 'dir' && $dec_file != "" ) wfu_delTree($dec_file); else unlink($dec_file); //revert log action if file has not been deleted if ( $type == 'file' && file_exists($dec_file) ) wfu_revert_log_action($retid); } } return true; } function wfu_create_dir_prompt($dir_code, $error) { return; $siteurl = site_url(); if ( !current_user_can( 'manage_options' ) ) return; $dir_code = wfu_sanitize_code($dir_code); $dec_dir = wfu_get_filepath_from_safe($dir_code); if ( $dec_dir === false ) return; //first extract sort info from dec_dir $ret = wfu_extract_sortdata_from_path($dec_dir); $dec_dir = wfu_path_rel2abs($ret['path']); if ( substr($dec_dir, -1) != '/' ) $dec_dir .= '/'; $newname = ''; $echo_str = "\n".'
'; if ( $error ) { $newname = $_SESSION['wfu_create_dir']['newname']; $echo_str .= "\n\t".'
'; $echo_str .= "\n\t\t".'

'.$_SESSION['wfu_create_dir_error'].'

'; $echo_str .= "\n\t".'
'; } $echo_str .= "\n\t".'
'; $echo_str .= "\n\t\t".'Go back'; $echo_str .= "\n\t".'
'; $echo_str .= "\n\t".'

Create Folder

'; $echo_str .= "\n\t".'
'; $echo_str .= "\n\t\t".''; $echo_str .= "\n\t\t".''; $echo_str .= "\n\t\t".'
'; $echo_str .= "\n\t\t".''; $echo_str .= "\n\t\t".'

'; $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t".'

'; $echo_str .= "\n\t".'
'; $echo_str .= "\n".'
'; return $echo_str; } function wfu_create_dir($dir_code) { return; if ( !current_user_can( 'manage_options' ) ) return; $dir_code = wfu_sanitize_code($dir_code); $dec_dir = wfu_get_filepath_from_safe($dir_code); if ( $dec_dir === false ) return; $dec_dir = wfu_path_rel2abs(wfu_flatten_path($dec_dir)); if ( substr($dec_dir, -1) != '/' ) $dec_dir .= '/'; if ( !file_exists($dec_dir) ) return; $error = ""; if ( isset($_POST['wfu_newname']) && isset($_POST['submit']) ) { if ( $_POST['submit'] == "Create" ) { $new_dir = $dec_dir.$_POST['wfu_newname']; if ( $_POST['wfu_newname'] == "" ) $error = 'Error: New folder name cannot be empty!'; elseif ( preg_match("/[^A-Za-z0-9_.#\-$]/", $_POST['wfu_newname']) ) $error = 'Error: name contained invalid characters that were stripped off! Please try again.'; elseif ( file_exists($new_dir) ) $error = 'Error: The folder '.$_POST['wfu_newname'].' already exists! Please choose another one.'; elseif ( mkdir($new_dir) == false ) $error = 'Error: Creation of folder '.$_POST['wfu_newname'].' failed!'; } } if ( $error != "" ) { $_SESSION['wfu_create_dir_error'] = $error; $_SESSION['wfu_create_dir']['newname'] = preg_replace("/[^A-Za-z0-9_.#\-$]/", "", $_POST['wfu_newname']); } return ( $error == "" ); } function wfu_file_details($file_code, $errorstatus) { global $wpdb; $table_name1 = $wpdb->prefix . "wfu_log"; $siteurl = site_url(); $user = wp_get_current_user(); $is_admin = current_user_can( 'manage_options' ); //check if user is allowed to view file details if ( !$is_admin ) { return; } $file_code = wfu_sanitize_code($file_code); $dec_file = wfu_get_filepath_from_safe($file_code); if ( $dec_file === false ) return; //extract file browser data from $file variable $ret = wfu_extract_sortdata_from_path($dec_file); $filepath = wfu_path_rel2abs($ret['path']); //check if user is allowed to perform this action if ( !wfu_current_user_owes_file($filepath) ) return; //get file data from database with user data $filedata = wfu_get_file_rec($filepath, true); if ( $filedata == null ) return; //get the username of the uploader $uploadername = wfu_get_username_by_id($filedata->uploaduserid); //extract sort info and construct contained dir $parts = pathinfo($filepath); $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($parts['dirname']).'[['.$ret['sort'].']]'); $stat = stat($filepath); $echo_str = '
'; if ( $errorstatus == 'error' ) { $echo_str .= "\n\t".'
'; $echo_str .= "\n\t\t".'

'.$_SESSION['wfu_filedetails_error'].'

'; $echo_str .= "\n\t".'
'; } //show file detais $echo_str .= "\n\t".'

Detais of File: '.$parts['basename'].'

'; $echo_str .= "\n\t".'
'; if ( $is_admin ) { $echo_str .= "\n\t\t".'Go back'; $echo_str .= "\n\t\t".'
'; } $echo_str .= "\n\t\t\t".'

Upload Details

'; $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t\t\t".''; if ( $is_admin ) { $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; } $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; if ( $is_admin ) { $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; } $echo_str .= "\n\t\t\t\t".''; $echo_str .= "\n\t\t\t".'
'; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".'
'; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".'
'; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".'
'; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".'
'; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".'
'; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".'
'; if ( $is_admin ) { //show history details $echo_str .= "\n\t\t\t".'

File History

'; $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t".''; $echo_str .= "\n\t\t\t".'
'; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; //read all linked records $filerecs = array(); array_push($filerecs, $filedata); $currec = $filedata; while ( $currec->linkedto > 0 ) { $currec = $wpdb->get_row('SELECT * FROM '.$table_name1.' WHERE idlog = '.$currec->linkedto); if ( $currec != null ) array_push($filerecs, $currec); else break; } //construct report from db records $rep = ''; foreach ( $filerecs as $filerec ) { $username = wfu_get_username_by_id($filerec->userid); $fileparts = pathinfo($filerec->filepath); if ( $rep != '' ) $rep .= "
"; $rep .= '['.$filerec->date_from.'] '; if ( $filerec->action == 'upload' ) $rep .= 'File uploaded with name '.$fileparts['basename'].' by user '.$username.''; elseif ( $filerec->action == 'download' ) $rep .= 'File downloaded by user '.$username.''; elseif ( $filerec->action == 'rename' ) $rep .= 'File renamed to '.$fileparts['basename'].' by user '.$username.''; elseif ( $filerec->action == 'delete' ) $rep .= 'File deleted by user '.$username.''; elseif ( $filerec->action == 'modify' ) $rep .= 'File userdata modified by user '.$username.''; } $echo_str .= "\n\t\t\t\t\t\t\t".'
'; $echo_str .= "\n\t\t\t\t\t\t\t".''.$rep.''; $echo_str .= "\n\t\t\t\t\t\t\t".'
'; $echo_str .= "\n\t\t\t\t\t\t".'
'; } $echo_str .= "\n\t\t\t".'

User Data Details

'; $echo_str .= "\n\t\t\t".''; $echo_str .= "\n\t\t\t\t".''; if ( count($filedata->userdata) > 0 ) { foreach ( $filedata->userdata as $userdata ) { $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; } } else { $echo_str .= "\n\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t".''; } $echo_str .= "\n\t\t\t\t".''; $echo_str .= "\n\t\t\t".'
'; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".''; // $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".'
'; $echo_str .= "\n\t\t\t\t\t\t\t".''; $echo_str .= "\n\t\t\t\t\t\t".'
'; if ( $is_admin ) { $echo_str .= "\n\t\t\t".'

'; $echo_str .= "\n\t\t\t\t".''; $echo_str .= "\n\t\t\t".'

'; } $echo_str .= "\n\t\t".'
'; $echo_str .= "\n\t".'
'; $handler = 'function() { wfu_Attach_FileDetails_Admin_Events(); }'; $echo_str .= "\n\t".''; $echo_str .= '
'; return $echo_str; } function wfu_edit_filedetails($file_code) { global $wpdb; $table_name2 = $wpdb->prefix . "wfu_userdata"; $user = wp_get_current_user(); $is_admin = current_user_can( 'manage_options' ); //check if user is allowed to view file details if ( !$is_admin ) { return; } $file_code = wfu_sanitize_code($file_code); $dec_file = wfu_get_filepath_from_safe($file_code); if ( $dec_file === false ) return; $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file)); //check if user is allowed to perform this action if ( !wfu_current_user_owes_file($dec_file) ) return; //get file data from database with user data $filedata = wfu_get_file_rec($dec_file, true); if ( $filedata == null ) return; if ( isset($_POST['submit']) ) { if ( $_POST['submit'] == "Update" ) { //check for errors $is_error = false; foreach ( $filedata->userdata as $userdata ) { if ( !isset($_POST['wfu_filedetails_userdata_'.$userdata->propkey]) ) { $is_error = true; break; } } if ( !$is_error ) { $now_date = date('Y-m-d H:i:s'); $userdata_count = 0; foreach ( $filedata->userdata as $userdata ) { $userdata_count ++; //make existing userdata record obsolete $wpdb->update($table_name2, array( 'date_to' => $now_date ), array( 'uploadid' => $userdata->uploadid, 'propkey' => $userdata->propkey ), array( '%s' ), array( '%s', '%s' ) ); //insert new userdata record $wpdb->insert($table_name2, array( 'uploadid' => $userdata->uploadid, 'property' => $userdata->property, 'propkey' => $userdata->propkey, 'propvalue' => $_POST['wfu_filedetails_userdata_'.$userdata->propkey], 'date_from' => $now_date, 'date_to' => 0 ), array( '%s', '%s', '%d', '%s', '%s', '%s' ) ); } if ( $userdata_count > 0 ) wfu_log_action('modify:'.$now_date, $dec_file, $user->ID, '', 0, 0, '', null); } } } return true; } ?>