function wfu_get_file_rec($filepath, $include_userdata) { global $wpdb; $table_name1 = $wpdb->prefix . "wfu_log"; $table_name2 = $wpdb->prefix . "wfu_userdata"; $plugin_options = wfu_decode_plugin_options(get_option("wordpress_file_upload_options")); if (!file_exists($filepath)) { return null; } $relativepath = wfu_path_abs2rel($filepath); // if ( substr($relativepath, 0, 1) != '/' ) $relativepath = '/'.$relativepath; //if file hash is enabled, then search file based on its path and hash, otherwise find file based on its path and size if (isset($plugin_options['hashfiles']) && $plugin_options['hashfiles'] == '1') { $filehash = md5_file($filepath); $filerec = $wpdb->get_row('SELECT * FROM ' . $table_name1 . ' WHERE filepath = \'' . $relativepath . '\' AND filehash = \'' . $filehash . '\' AND date_to = 0 ORDER BY date_from DESC'); } else { $stat = stat($filepath); $filerec = $wpdb->get_row('SELECT * FROM ' . $table_name1 . ' WHERE filepath = \'' . $relativepath . '\' AND filesize = ' . $stat['size'] . ' AND date_to = 0 ORDER BY date_from DESC'); } //get user data if ($filerec != null && $include_userdata) { $filerec->userdata = null; if ($filerec->uploadid != '') { $filerec->userdata = $wpdb->get_results('SELECT * FROM ' . $table_name2 . ' WHERE uploadid = \'' . $filerec->uploadid . '\' AND date_to = 0'); } } return $filerec; }
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 = '<div class="regev_wrap">'; if ($errorstatus == 'error') { $echo_str .= "\n\t" . '<div class="error">'; $echo_str .= "\n\t\t" . '<p>' . $_SESSION['wfu_filedetails_error'] . '</p>'; $echo_str .= "\n\t" . '</div>'; } //show file detais $echo_str .= "\n\t" . '<h2>Detais of File: ' . $parts['basename'] . '</h2>'; $echo_str .= "\n\t" . '<div style="margin-top:10px;">'; if ($is_admin) { $echo_str .= "\n\t\t" . '<a href="' . $siteurl . '/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir=' . $dir_code . '" class="button" title="go back">Go back</a>'; $echo_str .= "\n\t\t" . '<form enctype="multipart/form-data" name="editfiledetails" id="editfiledetails" method="post" action="/wp-admin/options-general.php?page=wordpress_file_upload&action=edit_filedetails" class="validate">'; } $echo_str .= "\n\t\t\t" . '<h3 style="margin-bottom: 10px; margin-top: 40px;">Upload Details</h3>'; $echo_str .= "\n\t\t\t" . '<input type="hidden" name="action" value="edit_filedetails" />'; $echo_str .= "\n\t\t\t" . '<input type="hidden" name="dir" value="' . $dir_code . '">'; $echo_str .= "\n\t\t\t" . '<input type="hidden" name="file" value="' . $file_code . '">'; $echo_str .= "\n\t\t\t" . '<table class="form-table">'; $echo_str .= "\n\t\t\t\t" . '<tbody>'; if ($is_admin) { $echo_str .= "\n\t\t\t\t\t" . '<tr>'; $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>Full Path</label>'; $echo_str .= "\n\t\t\t\t\t\t" . '</th>'; $echo_str .= "\n\t\t\t\t\t\t" . '<td>'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<input type="text" value="' . $filepath . '" readonly="readonly" />'; $echo_str .= "\n\t\t\t\t\t\t" . '</td>'; $echo_str .= "\n\t\t\t\t\t" . '</tr>'; $echo_str .= "\n\t\t\t\t\t" . '<tr>'; $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>Uploaded From User</label>'; $echo_str .= "\n\t\t\t\t\t\t" . '</th>'; $echo_str .= "\n\t\t\t\t\t\t" . '<td>'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<input type="text" value="' . $uploadername . '" readonly="readonly" style="width:auto;" />'; $echo_str .= "\n\t\t\t\t\t\t" . '</td>'; $echo_str .= "\n\t\t\t\t\t" . '</tr>'; } $echo_str .= "\n\t\t\t\t\t" . '<tr>'; $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>File Size</label>'; $echo_str .= "\n\t\t\t\t\t\t" . '</th>'; $echo_str .= "\n\t\t\t\t\t\t" . '<td>'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<input type="text" value="' . $filedata->filesize . '" readonly="readonly" style="width:auto;" />'; $echo_str .= "\n\t\t\t\t\t\t" . '</td>'; $echo_str .= "\n\t\t\t\t\t" . '</tr>'; $echo_str .= "\n\t\t\t\t\t" . '<tr>'; $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>File Date</label>'; $echo_str .= "\n\t\t\t\t\t\t" . '</th>'; $echo_str .= "\n\t\t\t\t\t\t" . '<td>'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<input type="text" value="' . date("d/m/Y H:i:s", $stat['mtime']) . '" readonly="readonly" style="width:auto;" />'; $echo_str .= "\n\t\t\t\t\t\t" . '</td>'; $echo_str .= "\n\t\t\t\t\t" . '</tr>'; $echo_str .= "\n\t\t\t\t\t" . '<tr>'; $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>Uploaded From Page</label>'; $echo_str .= "\n\t\t\t\t\t\t" . '</th>'; $echo_str .= "\n\t\t\t\t\t\t" . '<td>'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<input type="text" value="' . get_the_title($filedata->pageid) . ' (' . $filedata->pageid . ')' . '" readonly="readonly" style="width:50%;" />'; $echo_str .= "\n\t\t\t\t\t\t" . '</td>'; $echo_str .= "\n\t\t\t\t\t" . '</tr>'; if ($is_admin) { $echo_str .= "\n\t\t\t\t\t" . '<tr>'; $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>Upload Plugin ID</label>'; $echo_str .= "\n\t\t\t\t\t\t" . '</th>'; $echo_str .= "\n\t\t\t\t\t\t" . '<td>'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<input type="text" value="' . $filedata->sid . '" readonly="readonly" style="width:auto;" />'; $echo_str .= "\n\t\t\t\t\t\t" . '</td>'; $echo_str .= "\n\t\t\t\t\t" . '</tr>'; } $echo_str .= "\n\t\t\t\t" . '</tbody>'; $echo_str .= "\n\t\t\t" . '</table>'; if ($is_admin) { //show history details $echo_str .= "\n\t\t\t" . '<h3 style="margin-bottom: 10px; margin-top: 40px;">File History</h3>'; $echo_str .= "\n\t\t\t" . '<table class="form-table">'; $echo_str .= "\n\t\t\t\t" . '<tbody>'; $echo_str .= "\n\t\t\t\t\t" . '<tr>'; $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<label></label>'; $echo_str .= "\n\t\t\t\t\t\t" . '</th>'; $echo_str .= "\n\t\t\t\t\t\t" . '<td>'; //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 .= "<br />"; } $rep .= '<strong>[' . $filerec->date_from . ']</strong> '; if ($filerec->action == 'upload') { $rep .= 'File uploaded with name <strong>' . $fileparts['basename'] . '</strong> by user <strong>' . $username . '</strong>'; } elseif ($filerec->action == 'download') { $rep .= 'File downloaded by user <strong>' . $username . '</strong>'; } elseif ($filerec->action == 'rename') { $rep .= 'File renamed to <strong>' . $fileparts['basename'] . '</strong> by user <strong>' . $username . '</strong>'; } elseif ($filerec->action == 'delete') { $rep .= 'File deleted by user <strong>' . $username . '</strong>'; } elseif ($filerec->action == 'modify') { $rep .= 'File userdata modified by user <strong>' . $username . '</strong>'; } } $echo_str .= "\n\t\t\t\t\t\t\t" . '<div style="border:1px solid #dfdfdf; border-radius:3px; width:50%; overflow:scroll; padding:6px; height:100px; background-color:#eee;">'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<span style="white-space:nowrap;">' . $rep . '</span>'; $echo_str .= "\n\t\t\t\t\t\t\t" . '</div>'; $echo_str .= "\n\t\t\t\t\t\t" . '</td>'; $echo_str .= "\n\t\t\t\t\t" . '</tr>'; $echo_str .= "\n\t\t\t\t" . '</tbody>'; $echo_str .= "\n\t\t\t" . '</table>'; } $echo_str .= "\n\t\t\t" . '<h3 style="margin-bottom: 10px; margin-top: 40px;">User Data Details</h3>'; $echo_str .= "\n\t\t\t" . '<table class="form-table">'; $echo_str .= "\n\t\t\t\t" . '<tbody>'; if (count($filedata->userdata) > 0) { foreach ($filedata->userdata as $userdata) { $echo_str .= "\n\t\t\t\t\t" . '<tr>'; $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>' . $userdata->property . '</label>'; $echo_str .= "\n\t\t\t\t\t\t" . '</th>'; $echo_str .= "\n\t\t\t\t\t\t" . '<td>'; // $echo_str .= "\n\t\t\t\t\t\t\t".'<input id="wfu_filedetails_userdata_value_'.$userdata->propkey.'" name="wfu_filedetails_userdata" type="text"'.( $is_admin ? '' : ' readonly="readonly"' ).' value="'.$userdata->propvalue.'" />'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<textarea id="wfu_filedetails_userdata_value_' . $userdata->propkey . '" name="wfu_filedetails_userdata" ' . ($is_admin ? '' : ' readonly="readonly"') . ' value="' . $userdata->propvalue . '">' . $userdata->propvalue . '</textarea>'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<input id="wfu_filedetails_userdata_default_' . $userdata->propkey . '" type="hidden" value="' . $userdata->propvalue . '" />'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<input id="wfu_filedetails_userdata_' . $userdata->propkey . '" name="wfu_filedetails_userdata_' . $userdata->propkey . '" type="hidden" value="' . $userdata->propvalue . '" />'; $echo_str .= "\n\t\t\t\t\t\t" . '</td>'; $echo_str .= "\n\t\t\t\t\t" . '</tr>'; } } else { $echo_str .= "\n\t\t\t\t\t" . '<tr>'; $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">'; $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>No user data</label>'; $echo_str .= "\n\t\t\t\t\t\t" . '</th>'; $echo_str .= "\n\t\t\t\t\t\t" . '<td></td>'; $echo_str .= "\n\t\t\t\t\t" . '</tr>'; } $echo_str .= "\n\t\t\t\t" . '</tbody>'; $echo_str .= "\n\t\t\t" . '</table>'; if ($is_admin) { $echo_str .= "\n\t\t\t" . '<p class="submit">'; $echo_str .= "\n\t\t\t\t" . '<input id="dp_filedetails_submit_fields" type="submit" class="button-primary" name="submit" value="Update" disabled="disabled" />'; $echo_str .= "\n\t\t\t" . '</p>'; } $echo_str .= "\n\t\t" . '</form>'; $echo_str .= "\n\t" . '</div>'; $handler = 'function() { wfu_Attach_FileDetails_Admin_Events(); }'; $echo_str .= "\n\t" . '<script type="text/javascript">if(window.addEventListener) { window.addEventListener("load", ' . $handler . ', false); } else if(window.attachEvent) { window.attachEvent("onload", ' . $handler . '); } else { window["onload"] = ' . $handler . '; }</script>'; $echo_str .= '</div>'; return $echo_str; }