| 34 |
/** |
/** |
| 35 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 36 |
*/ |
*/ |
| 37 |
function webfm_help($section) { |
function webfm_help($path, $args) { |
| 38 |
switch ($section) { |
switch ($path) { |
| 39 |
case 'admin/help#webfm': |
case 'admin/help#webfm': |
| 40 |
$output = t(' |
$output = t(' |
| 41 |
<p>Web File Manager (WebFM) implements a hierarchical filesystem unlike the traditional flat filesystem used to date by Drupal. WebFM allows administrators to arrange files on the server in the same way they do on their local storage drives which greatly enhances the manageability of large collections of documents. Directory access is set by role and file access is controllable by file owners or module administrators.</p> |
<p>Web File Manager (WebFM) implements a hierarchical filesystem unlike the traditional flat filesystem used to date by Drupal. WebFM allows administrators to arrange files on the server in the same way they do on their local storage drives which greatly enhances the manageability of large collections of documents. Directory access is set by role and file access is controllable by file owners or module administrators.</p> |
| 111 |
<li>Disable the module on the /admin/build/modules page</li> |
<li>Disable the module on the /admin/build/modules page</li> |
| 112 |
<li>Click on the uninstall tab and select the module for removal. This will automatically drop the webfm_file and webfm_attach tables as well as all configuration variables. <i><strong>NOTE:</strong></i> This action will permanently discard all attachment and metedata information and cannot be undone. Execute the first step only if you wish to restore WebFM later without loss of data.</li> |
<li>Click on the uninstall tab and select the module for removal. This will automatically drop the webfm_file and webfm_attach tables as well as all configuration variables. <i><strong>NOTE:</strong></i> This action will permanently discard all attachment and metedata information and cannot be undone. Execute the first step only if you wish to restore WebFM later without loss of data.</li> |
| 113 |
</ol> |
</ol> |
| 114 |
<h2>Onunload event handling in template</h2> |
'); |
|
<p>To explicitly destroy the event closures to minimize browser memory leaks an unload event needs to fire. Unfortunately the control of the body tag happens in the template. Add this function to template.php:</p> |
|
|
<pre> |
|
|
function phptemplate_unload() { |
|
|
if(module_exists(\'webfm\')) { |
|
|
$path = $_SERVER[\'REQUEST_URI\']; |
|
|
if((strstr($path, \'webfm\')) || |
|
|
(strstr($path, \'node\') && strstr($path, \'edit\'))) |
|
|
print \' onunload="Webfm.unregisterAllEvents();"\'; |
|
|
} |
|
|
} |
|
|
} |
|
|
</pre> |
|
|
<p>Add the following inside the php tag of the body tag of page.tpl.php: |
|
|
<pre> |
|
|
print phptemplate_unload(); |
|
|
</pre></p> |
|
|
', |
|
|
array('%file-sys' => url('admin/settings/file-system'))); |
|
| 115 |
return $output; |
return $output; |
| 116 |
|
|
| 117 |
case 'admin/modules#description': |
case 'admin/modules#description': |
| 377 |
if(isset($show_files) && is_array($show_files)) { |
if(isset($show_files) && is_array($show_files)) { |
| 378 |
$node->content['webfm_attachments'] = array( |
$node->content['webfm_attachments'] = array( |
| 379 |
'#value' => theme('webfm_attachments', $show_files), |
'#value' => theme('webfm_attachments', $show_files), |
| 380 |
'#weight' => 10); |
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'webfm_attachments') : 10, |
| 381 |
|
); |
| 382 |
|
|
| 383 |
drupal_add_css(drupal_get_path('module', 'webfm').'/css/webfm.css'); |
drupal_add_css(drupal_get_path('module', 'webfm').'/css/webfm.css'); |
| 384 |
} |
} |
| 385 |
} |
} |
| 391 |
$modulepath = drupal_get_path('module', 'webfm'); |
$modulepath = drupal_get_path('module', 'webfm'); |
| 392 |
drupal_add_js($modulepath .'/js/webfm.js'); |
drupal_add_js($modulepath .'/js/webfm.js'); |
| 393 |
drupal_add_css($modulepath .'/css/webfm.css'); |
drupal_add_css($modulepath .'/css/webfm.css'); |
| 394 |
if(is_null($inline_js)) { |
// Output drupal config data as inline javascript |
| 395 |
$clean_url = variable_get('clean_url', 0); |
$clean_url = variable_get('clean_url', 0); |
| 396 |
$clean = (($clean_url == 0) || ($clean_url == '0')) ? FALSE : TRUE; |
$clean = (($clean_url == 0) || ($clean_url == '0')) ? FALSE : TRUE; |
| 397 |
$inline_js = webfm_inline_js($base_url, $base_path, $clean, $user->uid); |
webfm_inline_js($base_url, $base_path, $clean, $user->uid); |
|
} |
|
| 398 |
break; |
break; |
| 399 |
|
|
| 400 |
case 'insert': |
case 'insert': |
| 409 |
webfm_dbinsert_attach($node->nid, $fid, $i++); |
webfm_dbinsert_attach($node->nid, $fid, $i++); |
| 410 |
} |
} |
| 411 |
} |
} |
| 412 |
|
if (module_exists('og') && variable_get('webfm_og_auto', 0) == 1) { |
| 413 |
|
$groups = og_all_groups_options(); |
| 414 |
|
if ($groups[$node->nid]) { |
| 415 |
|
// make the node title into a suitable directory name |
| 416 |
|
$group_directory = webfm_get_group_directory($node); |
| 417 |
|
$group_root_dir = file_directory_path().webfm_get_root_path().'/'.$group_directory; |
| 418 |
|
file_check_directory($group_root_dir, FILE_CREATE_DIRECTORY, 'root_dir_group_'.$node->nid); |
| 419 |
|
variable_set('root_dir_group_'. $node->nid, $group_directory); |
| 420 |
|
} |
| 421 |
|
} |
| 422 |
break; |
break; |
| 423 |
|
|
| 424 |
case 'update': |
case 'update': |
| 436 |
} |
} |
| 437 |
} |
} |
| 438 |
|
|
| 439 |
|
/** |
| 440 |
|
* Implementation of hook_content_extra_fields(). |
| 441 |
|
*/ |
| 442 |
|
function webfm_content_extra_fields($type) { |
| 443 |
|
$extras['webfm_attachments'] = array( |
| 444 |
|
'label' => t('Webfm Attachments'), |
| 445 |
|
'description' => t('Displays the attachments as table'), |
| 446 |
|
'weight' => 10, |
| 447 |
|
); |
| 448 |
|
return $extras; |
| 449 |
|
} |
| 450 |
|
|
| 451 |
|
|
| 452 |
/** |
/** |
| 453 |
* Implementation of hook_form_alter(). |
* Implementation of hook_form_alter(). |
| 454 |
*/ |
*/ |
| 483 |
$modulepath = drupal_get_path('module', 'webfm'); |
$modulepath = drupal_get_path('module', 'webfm'); |
| 484 |
drupal_add_js($modulepath.'/js/webfm.js'); |
drupal_add_js($modulepath.'/js/webfm.js'); |
| 485 |
drupal_add_css($modulepath.'/css/webfm.css'); |
drupal_add_css($modulepath.'/css/webfm.css'); |
| 486 |
if(is_null($inline_js)) { |
// Output drupal config data as inline javascript |
| 487 |
$clean_url = variable_get('clean_url', 0); |
$clean_url = variable_get('clean_url', 0); |
| 488 |
$clean = (($clean_url == 0) || ($clean_url == '0')) ? FALSE : TRUE; |
$clean = (($clean_url == 0) || ($clean_url == '0')) ? FALSE : TRUE; |
| 489 |
$inline_js = webfm_inline_js($base_url, $base_path, $clean, $user->uid); |
webfm_inline_js($base_url, $base_path, $clean, $user->uid); |
|
} |
|
| 490 |
|
|
| 491 |
// Attachments fieldset |
// Attachments fieldset |
| 492 |
$form['webfm-attach']['#theme'] = 'webfm_upload_form'; |
$form['webfm-attach']['#theme'] = 'webfm_upload_form'; |
| 544 |
} |
} |
| 545 |
} |
} |
| 546 |
|
|
| 547 |
|
function webfm_get_group_directory($node) { |
| 548 |
|
$group_directory = drupal_strtolower(trim($node->title)); |
| 549 |
|
$group_directory = str_replace(array(' ', '-'), '_', $group_directory); |
| 550 |
|
return preg_replace('/[^a-z0-9_]/', '', $group_directory); |
| 551 |
|
} |
| 552 |
|
|
| 553 |
function webfm_link_output() { |
function webfm_link_output() { |
| 554 |
|
global $user; |
| 555 |
|
|
| 556 |
if($user->uid == 1 || user_access('administer webfm')) { |
if($user->uid == 1 || user_access('administer webfm')) { |
| 557 |
// Settings link - accessible only #1 user or module administrator |
// Settings link - accessible only #1 user or module administrator |
| 558 |
$settings_link = t('[<a href="@link">settings...</a>]',array('@link'=>url("admin/settings/webfm"))); |
$settings_link = t('[<a href="@link">settings...</a>]',array('@link'=>url("admin/settings/webfm"))); |
| 565 |
// Debug link - available only if enabled in settings |
// Debug link - available only if enabled in settings |
| 566 |
$debug_link = (drupal_to_js(variable_get('webfm_debug',''))) ? t('[<a href=# id="webfm-debug-link">debug</a>]') : ''; |
$debug_link = (drupal_to_js(variable_get('webfm_debug',''))) ? t('[<a href=# id="webfm-debug-link">debug</a>]') : ''; |
| 567 |
|
|
|
|
|
| 568 |
return $debug_link.$settings_link.$help_link; |
return $debug_link.$settings_link.$help_link; |
| 569 |
} |
} |
| 570 |
|
|
| 772 |
//Get the destination path from the edit-webfmuploadpath hidden field in the upload form |
//Get the destination path from the edit-webfmuploadpath hidden field in the upload form |
| 773 |
$json_data = array(); |
$json_data = array(); |
| 774 |
$fid = ''; |
$fid = ''; |
| 775 |
if($_POST['webfmuploadpath']) { |
if(isset($_POST['webfmuploadpath'])) { |
| 776 |
$root_dir = (($user->uid == 1) || user_access('administer webfm'))? file_directory_path() : file_directory_path().webfm_get_root_path(); |
$root_dir = (($user->uid == 1) || user_access('administer webfm'))? file_directory_path() : file_directory_path().webfm_get_root_path(); |
| 777 |
$dest = $root_dir.$_POST['webfmuploadpath']; |
$dest = $root_dir.$_POST['webfmuploadpath']; |
| 778 |
// Save new file uploads to tmp dir. |
// Save new file uploads to tmp dir. |
| 798 |
webfm_file_mod_access($webfm_file_row)) { |
webfm_file_mod_access($webfm_file_row)) { |
| 799 |
$json_data['html'] = webfm_reload_upload('webfm/upload', webfm_version_form($file->filename)); |
$json_data['html'] = webfm_reload_upload('webfm/upload', webfm_version_form($file->filename)); |
| 800 |
} else { |
} else { |
| 801 |
drupal_set_message(t('Permission denied to overwrite existing file'), error); |
drupal_set_message(t('Permission denied to overwrite existing file'), 'error'); |
| 802 |
} |
} |
| 803 |
} else { |
} else { |
| 804 |
// Overwrite of an existing file that is not in the database |
// Overwrite of an existing file that is not in the database |
| 807 |
// file was inserted into the database |
// file was inserted into the database |
| 808 |
drupal_set_message($msg); |
drupal_set_message($msg); |
| 809 |
} else { |
} else { |
| 810 |
drupal_set_message($msg, error); |
drupal_set_message($msg, 'error'); |
| 811 |
} |
} |
| 812 |
} |
} |
| 813 |
} else if(file_move($file, $dest)) { |
} else if(file_move($file, $dest)) { |
| 817 |
drupal_set_message(t('Upload Success')); |
drupal_set_message(t('Upload Success')); |
| 818 |
} else { |
} else { |
| 819 |
file_delete($file->filepath); |
file_delete($file->filepath); |
| 820 |
drupal_set_message($db_err, error); |
drupal_set_message($db_err, 'error'); |
| 821 |
} |
} |
| 822 |
} else { |
} else { |
| 823 |
drupal_set_message(t('file_move to %path failed', array('%path' => $dest)), error); |
drupal_set_message(t('file_move to %path failed', array('%path' => $dest)), 'error'); |
| 824 |
} |
} |
| 825 |
} else { |
} else { |
| 826 |
foreach($err_arr as $err) { |
foreach($err_arr as $err) { |
| 827 |
drupal_set_message($err, error); |
drupal_set_message($err, 'error'); |
| 828 |
} |
} |
| 829 |
} |
} |
| 830 |
} else { |
} else { |
| 831 |
if(!isset($_FILES['files']) || $_FILES['files']['name']['webfm_upload'] == '') { |
if(!isset($_FILES['files']) || $_FILES['files']['name']['webfm_upload'] == '') { |
| 832 |
drupal_set_message(t('Please click "Browse" and select a file to upload before clicking the upload button.'), error); |
drupal_set_message(t('Please click "Browse" and select a file to upload before clicking the upload button.'), 'error'); |
| 833 |
} |
} |
| 834 |
} |
} |
| 835 |
} else { |
} else { |
| 836 |
drupal_set_message(t('Invalid upload path'), error); |
drupal_set_message(t('Invalid upload path'), 'error'); |
| 837 |
} |
} |
| 838 |
|
|
| 839 |
if(!isset($json_data['html'])) |
if(!isset($json_data['html'])) |
| 914 |
} else { |
} else { |
| 915 |
$err = t('No root directory set in WebFM settings for this role'); |
$err = t('No root directory set in WebFM settings for this role'); |
| 916 |
} |
} |
| 917 |
|
if(module_exists('og')) { |
| 918 |
|
//clear static array of groups with directories ($webfm_roots cached only for 'read' op) |
| 919 |
|
$webfm_group_roots = webfm_get_group_root_dirs(TRUE); |
| 920 |
|
if(count($webfm_group_roots)) { |
| 921 |
|
foreach ($webfm_group_roots as $key => $sub_root) { |
| 922 |
|
//Build webfm directory tree(s) for WEBFM_USER |
| 923 |
|
if(!empty($sub_root)) { |
| 924 |
|
$sub_root_path = $root_dir.$sub_root; |
| 925 |
|
if(is_dir($sub_root_path)) { |
| 926 |
|
$current = $sub_root; |
| 927 |
|
unset($_SESSION['tree_'.$current]); |
| 928 |
|
$trees[$key] = webfm_tree($root_dir, $current); |
| 929 |
|
} |
| 930 |
|
} |
| 931 |
|
} |
| 932 |
|
} else { |
| 933 |
|
$err = t('No root directory set in WebFM settings for this group'); |
| 934 |
|
} |
| 935 |
|
} |
| 936 |
} |
} |
| 937 |
|
|
| 938 |
if(count($trees)) { |
if(count($trees)) { |
| 958 |
(array_key_exists($root_role, $webfm_roots))) { |
(array_key_exists($root_role, $webfm_roots))) { |
| 959 |
$current = "/".$root; |
$current = "/".$root; |
| 960 |
} |
} |
| 961 |
|
if(module_exists('og')) { |
| 962 |
|
$webfm_group_roots = webfm_get_group_root_dirs(); |
| 963 |
|
$root_group = trim(rawurldecode($_POST["param0"])); |
| 964 |
|
if(($root = variable_get("root_dir_group_". $root_group, '')) && |
| 965 |
|
(array_key_exists($root_group, $webfm_group_roots))) { |
| 966 |
|
$current = "/". $root; |
| 967 |
|
} |
| 968 |
|
} |
| 969 |
} |
} |
| 970 |
if(!isset($current)) { |
if(!isset($current)) { |
| 971 |
webfm_json(array('status' => FALSE, 'data' => t('unknown tree'))); |
webfm_json(array('status' => FALSE, 'data' => t('unknown tree'))); |
| 993 |
exit(); |
exit(); |
| 994 |
} |
} |
| 995 |
|
|
| 996 |
// Test access rights |
if(!is_dir($root_dir.$param0)) { |
| 997 |
$perm_flag = FALSE; |
webfm_json(array('status' => FALSE, 'data' => $root_dir.$param0.t(' path does not exist - refresh required'))); |
| 998 |
if($webfm_perm == WEBFM_ADMIN) { |
exit(); |
|
// WEBFM_ADMIN always has access |
|
|
if(webfm_check_path($param0, $webfm_root_path)) { |
|
|
$perm_flag = TRUE; |
|
|
} |
|
|
} else { |
|
|
// If WEBFM_USER, test that read path is inside a legit root dir |
|
|
$webfm_roots = webfm_get_root_dirs(); |
|
|
foreach($webfm_roots as $key => $sub_root) { |
|
|
// The read path must be contained within a legitimate role root dir for this user |
|
|
if($sub_root && webfm_check_path($param0, $sub_root)) { |
|
|
$perm_flag = TRUE; |
|
|
break; |
|
|
} |
|
|
} |
|
| 999 |
} |
} |
| 1000 |
|
|
| 1001 |
if($perm_flag) { |
//Build current directory listings |
| 1002 |
if(!is_dir($root_dir.$param0)) { |
$dirlist = new webfm_build_dir_list($param0, $webfm_perm); |
| 1003 |
webfm_json(array('status' => FALSE, 'data' => $root_dir.$param0.t(' path does not exist - refresh required'))); |
if($dirlist->get_breadcrumb()) { |
| 1004 |
exit(); |
webfm_json(array('status' => TRUE, 'current' => $param0, 'bcrumb' => $dirlist->get_breadcrumb(), 'dirs' => $dirlist->get_dir_listing(), 'files' => $dirlist->get_file_listing(), 'user' => $user->uid, 'admin' => $webfm_perm == WEBFM_ADMIN)); |
|
} |
|
|
|
|
|
//Build current directory listings |
|
|
$dirlist = new webfm_build_dir_list($root_dir, $param0, $webfm_perm); |
|
|
if($dirlist->get_breadcrumb()) { |
|
|
webfm_json(array('status' => TRUE, 'current' => $param0, 'bcrumb' => $dirlist->get_breadcrumb(), 'dirs' => $dirlist->get_dir_listing(), 'files' => $dirlist->get_file_listing(), 'user' => $user->uid, 'admin' => $webfm_perm == WEBFM_ADMIN)); |
|
|
} else { |
|
|
//invalid directory |
|
|
webfm_json(array('status' => FALSE, 'data' => t('invalid dir'))); |
|
|
} |
|
| 1005 |
} else { |
} else { |
| 1006 |
webfm_json(array('status' => FALSE, 'data' => t('forbidden dir'))); |
//invalid directory |
| 1007 |
|
webfm_json(array('status' => FALSE, 'data' => t('invalid dir'))); |
| 1008 |
} |
} |
| 1009 |
} else { |
} else { |
| 1010 |
webfm_json(array('status' => FALSE, 'data' => t('insufficient params'))); |
webfm_json(array('status' => FALSE, 'data' => t('insufficient params'))); |
| 1183 |
$meta['u'] = $file->uid; |
$meta['u'] = $file->uid; |
| 1184 |
} |
} |
| 1185 |
} |
} |
| 1186 |
$query = 'SELECT name FROM {users} WHERE uid = %d'; |
if($file->uid > 0) { |
| 1187 |
$meta['un'] = db_result(db_query($query, $file->uid)); |
$query = 'SELECT name FROM {users} WHERE uid = %d'; |
| 1188 |
|
$meta['un'] = db_result(db_query($query, $file->uid)); |
| 1189 |
|
} else { |
| 1190 |
|
$meta['un'] = t('anonymous'); |
| 1191 |
|
} |
| 1192 |
$meta['n'] = strrev(substr(strrev($file->fpath), 0, strpos(strrev($file->fpath), '/'))); |
$meta['n'] = strrev(substr(strrev($file->fpath), 0, strpos(strrev($file->fpath), '/'))); |
| 1193 |
$meta['t'] = $file->ftitle; |
$meta['t'] = $file->ftitle; |
| 1194 |
$meta['d'] = $file->fdesc; |
$meta['d'] = $file->fdesc; |
| 1196 |
$meta['p'] = $file->fpublisher; |
$meta['p'] = $file->fpublisher; |
| 1197 |
$meta['f'] = $file->fformat; |
$meta['f'] = $file->fformat; |
| 1198 |
$meta['c'] = $file->dl_cnt; |
$meta['c'] = $file->dl_cnt; |
| 1199 |
if($i = @getimagesize($file->fpath)) { |
if((list($width, $height, $type, $attr) = @getimagesize($file->fpath)) !== false) { |
| 1200 |
if(($i[0] != 0) && ($i[1] != 0)) { |
if(($width != 0) && ($height != 0)) { |
| 1201 |
$meta['i'] = (int)$i[2]; |
$meta['i'] = $type; |
| 1202 |
$meta['w'] = (int)$i[0]; |
$meta['w'] = $width; |
| 1203 |
$meta['h'] = (int)$i[1]; |
$meta['h'] = $height; |
| 1204 |
} |
} |
| 1205 |
} |
} |
| 1206 |
if($file->perm & WEBFM_FILE_ACCESS_PUBLIC_VIEW) { |
if($file->perm & WEBFM_FILE_ACCESS_PUBLIC_VIEW) { |
| 1222 |
break; |
break; |
| 1223 |
|
|
| 1224 |
//Change file metadata |
//Change file metadata |
| 1225 |
|
//TODO: update changes in UI |
| 1226 |
case "putmeta": |
case "putmeta": |
| 1227 |
if(isset($_POST["param0"]) && isset($_POST["param1"])) { |
if(isset($_POST["param0"]) && isset($_POST["param1"])) { |
| 1228 |
//permission check in webfm_putmeta so single access to webfm_file table |
//permission check in webfm_putmeta so single access to webfm_file table |
| 1229 |
|
//Set WEBFM_ADMIN to uid=1 for purpose of file ownership |
| 1230 |
$ret = webfm_putmeta(rawurldecode($_POST["param0"]), rawurldecode($_POST["param1"]), ($webfm_perm == WEBFM_ADMIN)?1:$user->uid, $err); |
$ret = webfm_putmeta(rawurldecode($_POST["param0"]), rawurldecode($_POST["param1"]), ($webfm_perm == WEBFM_ADMIN)?1:$user->uid, $err); |
| 1231 |
webfm_json(array('status' => $ret, 'data' => $err)); |
webfm_json(array('status' => $ret, 'data' => $err)); |
| 1232 |
} else { |
} else { |
| 1650 |
|
|
| 1651 |
module_invoke_all('webfm_extend_js'); |
module_invoke_all('webfm_extend_js'); |
| 1652 |
|
|
| 1653 |
if(is_null($inline_js)) { |
// Output drupal config data as inline javascript |
| 1654 |
global $user; |
$clean_url = variable_get('clean_url', 0); |
| 1655 |
$clean_url = variable_get('clean_url', 0); |
$clean = (($clean_url == 0) || ($clean_url == '0')) ? FALSE : TRUE; |
| 1656 |
$clean = (($clean_url == 0) || ($clean_url == '0')) ? FALSE : TRUE; |
webfm_inline_js($base_url, $base_path, $clean, $user->uid); |
|
$inline_js = webfm_inline_js($base_url, $base_path, $clean, $user->uid); |
|
|
} |
|
| 1657 |
|
|
| 1658 |
$links = webfm_link_output(); |
$links = webfm_link_output(); |
| 1659 |
$upload = ''; |
$upload = ''; |
| 1732 |
* Function to pass base_url, icon directory, debug and cleanurl flags |
* Function to pass base_url, icon directory, debug and cleanurl flags |
| 1733 |
*/ |
*/ |
| 1734 |
function webfm_inline_js($base_url, $base_path, $clean_url, $uid) { |
function webfm_inline_js($base_url, $base_path, $clean_url, $uid) { |
| 1735 |
$js = '<script type="text/javascript">function getBaseUrl(){return '.drupal_to_js($base_url).';} function getBasePath(){return '.drupal_to_js($base_path).';} function getWebfmIconDir(){return '.drupal_to_js($base_url."/".variable_get('webfm_icon_dir', drupal_get_path('module', 'webfm').'/image/icon')).';} function getWebfmCleanUrl(){return '.drupal_to_js($clean_url).'; }function getWebfmIETreeOffset(){return '.drupal_to_js(variable_get('webfm_ie_dd_tree_offset', '')).';}function getWebfmIEListOffset(){return '.drupal_to_js(variable_get('webfm_ie_dd_list_offset', '')).';} function getWebfmUid(){return '.drupal_to_js($uid).';} function getWebfmDateFormat(){return '.drupal_to_js(variable_get('webfm_date_format', WEBFM_DATE_FORMAT_DAY)).';} function getWebfmMetaName(){return '.drupal_to_js(variable_get('webfm_display_title', '')).';}</script>' ; |
$js = 'function getBaseUrl(){return '. drupal_to_js($base_url) .';} function getBasePath(){return '. drupal_to_js($base_path) .';} function getWebfmIconDir(){return '. drupal_to_js($base_url .'/'. variable_get('webfm_icon_dir', drupal_get_path('module', 'webfm') .'/image/icon')) .';} function getWebfmCleanUrl(){return '.drupal_to_js($clean_url).'; }function getWebfmIETreeOffset(){return '.drupal_to_js(variable_get('webfm_ie_dd_tree_offset', '')).';}function getWebfmIEListOffset(){return '.drupal_to_js(variable_get('webfm_ie_dd_list_offset', '')).';} function getWebfmUid(){return '.drupal_to_js($uid).';} function getWebfmDateFormat(){return '.drupal_to_js(variable_get('webfm_date_format', WEBFM_DATE_FORMAT_DAY)).';} function getWebfmMetaName(){return '.drupal_to_js(variable_get('webfm_display_title', '')).';} function getWebfmOwnerColumn(){return '.drupal_to_js(variable_get('webfm_display_owner', '')).';}' ; |
| 1736 |
|
drupal_add_js($js, 'inline'); |
|
drupal_set_html_head($js); |
|
|
return $js; |
|
| 1737 |
} |
} |
| 1738 |
|
|
| 1739 |
/** |
/** |
| 1793 |
foreach($user->roles as $rid => $role) { |
foreach($user->roles as $rid => $role) { |
| 1794 |
if(array_key_exists($rid, $webfm_access_roles)) { |
if(array_key_exists($rid, $webfm_access_roles)) { |
| 1795 |
// Roles with 'access webfm' perm that user possesses |
// Roles with 'access webfm' perm that user possesses |
| 1796 |
$path = variable_get("root_dir_".$rid, ''); |
$path = variable_get('root_dir_'.$rid, ''); |
| 1797 |
if(!empty($path)) { |
if(!empty($path)) { |
| 1798 |
// Prevent redundant trees for roles with common root dir |
// Prevent redundant trees for roles with common root dir |
| 1799 |
if(!in_array($path, $webfm_roots)) { |
if(!in_array($path, $webfm_roots)) { |
| 1800 |
$webfm_roots[$rid] = "/".$path; |
$webfm_roots[$rid] = '/'.$path; |
| 1801 |
} |
} |
| 1802 |
} |
} |
| 1803 |
} |
} |
| 1804 |
} |
} |
| 1805 |
//If anonymous role has webfm access... |
//If anonymous role has webfm access... |
| 1806 |
if(array_key_exists(1, $webfm_access_roles)) { |
if(array_key_exists(1, $webfm_access_roles)) { |
| 1807 |
$path = variable_get("root_dir_1", ''); |
$path = variable_get('root_dir_1', ''); |
| 1808 |
if(!empty($path)) { |
if(!empty($path)) { |
| 1809 |
$webfm_roots[1] = "/".$path; |
$webfm_roots[1] = '/'.$path; |
| 1810 |
} |
} |
| 1811 |
} |
} |
| 1812 |
|
|
| 1813 |
return $webfm_roots; |
return $webfm_roots; |
| 1814 |
} |
} |
| 1815 |
|
|
| 1816 |
|
/** |
| 1817 |
|
* Helper function to get array of group root directories for a user |
| 1818 |
|
*/ |
| 1819 |
|
function webfm_get_group_root_dirs($flush = FALSE) { |
| 1820 |
|
global $user; |
| 1821 |
|
static $webfm_roots = array(); |
| 1822 |
|
static $webfm_access_groups = array(); |
| 1823 |
|
//add per group directories |
| 1824 |
|
if($flush) { |
| 1825 |
|
$webfm_access_groups = array(); |
| 1826 |
|
} |
| 1827 |
|
// Roles with 'access webfm' perm |
| 1828 |
|
if(!count($webfm_access_groups)) { |
| 1829 |
|
$webfm_roots = array(); |
| 1830 |
|
foreach($user->og_groups as $key => $group) { |
| 1831 |
|
if($group['is_active']) { |
| 1832 |
|
// Groups with directories that user is active in |
| 1833 |
|
$path = variable_get('root_dir_group_'. $key, ''); |
| 1834 |
|
if(!empty($path)) { |
| 1835 |
|
// Prevent redundant trees for groups with common root dir |
| 1836 |
|
if(!in_array($path, $webfm_roots)) { |
| 1837 |
|
$webfm_roots[$key] = '/'.$path; |
| 1838 |
|
} |
| 1839 |
|
} |
| 1840 |
|
} |
| 1841 |
|
} |
| 1842 |
|
} |
| 1843 |
|
return $webfm_roots; |
| 1844 |
|
} |
| 1845 |
|
|
| 1846 |
/** |
/** |
| 1847 |
* Helper function to determine if a webfm_file record is modifiable by a |
* Helper function to determine if a webfm_file record is modifiable by a |
| 1848 |
* user with 'access webfm' |
* user with 'access webfm' |
| 1865 |
return FALSE; |
return FALSE; |
| 1866 |
} |
} |
| 1867 |
|
|
| 1868 |
|
/** |
| 1869 |
|
* Helper function to determine if a webfm_file record is attachable by a |
| 1870 |
|
* user with 'access webfm' |
| 1871 |
|
*/ |
| 1872 |
function webfm_file_att_access($webfm_file) { |
function webfm_file_att_access($webfm_file) { |
| 1873 |
if((int)$webfm_file->perm & WEBFM_FILE_ACCESS_ROLE_ATTACH) { |
if((int)$webfm_file->perm & WEBFM_FILE_ACCESS_ROLE_ATTACH) { |
| 1874 |
return webfm_path_access($webfm_file->fpath); |
return webfm_path_access($webfm_file->fpath); |
| 1889 |
return TRUE; |
return TRUE; |
| 1890 |
} |
} |
| 1891 |
} |
} |
| 1892 |
|
//alternatively the read path may be in a legitimate group root dir for this user |
| 1893 |
|
if(module_exists('og')) { |
| 1894 |
|
$webfm_group_roots = webfm_get_group_root_dirs(); |
| 1895 |
|
foreach($webfm_group_roots as $key => $sub_root) { |
| 1896 |
|
// The read path must be contained within a legitimate role root dir for this user |
| 1897 |
|
if(webfm_check_path($path, $root_dir.$sub_root)) { |
| 1898 |
|
return TRUE; |
| 1899 |
|
} |
| 1900 |
|
} |
| 1901 |
|
} |
| 1902 |
|
|
| 1903 |
return FALSE; |
return FALSE; |
| 1904 |
} |
} |
| 1905 |
|
|
| 1947 |
var $breadcrumb = array(); |
var $breadcrumb = array(); |
| 1948 |
|
|
| 1949 |
//Constructor |
//Constructor |
| 1950 |
function webfm_build_dir_list($root, $path, $perm) { |
function webfm_build_dir_list($path, $perm) { |
| 1951 |
global $user; |
global $user; |
| 1952 |
$bl = array('.', '..', '.htaccess'); |
$bl = array('.', '..', '.htaccess'); |
| 1953 |
$_dirs = array(); |
$_dirs = array(); |
| 1954 |
$_files = array(); |
$_fils = array(); |
| 1955 |
|
// Admins do not have webfm root hidden |
| 1956 |
|
$root = ($perm == WEBFM_ADMIN)? file_directory_path() : file_directory_path().webfm_get_root_path(); |
| 1957 |
|
if(substr($path, 0, 1) != '/') |
| 1958 |
|
$path = '/'.$path; |
| 1959 |
$full_path = $root.$path; |
$full_path = $root.$path; |
| 1960 |
|
|
| 1961 |
if(is_dir($full_path)) { |
if(is_dir($full_path)) { |
| 1962 |
chdir($full_path); |
// Test access rights |
| 1963 |
if($handle = opendir('.')) { |
$perm_flag = FALSE; |
| 1964 |
|
if($perm == WEBFM_ADMIN) { |
| 1965 |
|
// WEBFM_ADMIN always has access |
| 1966 |
|
if(webfm_check_path($path, $webfm_root_path)) { |
| 1967 |
|
$perm_flag = TRUE; |
| 1968 |
|
} |
| 1969 |
|
} else { |
| 1970 |
|
// If WEBFM_USER, test that read path is inside a legit root dir |
| 1971 |
|
$webfm_roots = webfm_get_root_dirs(); |
| 1972 |
|
foreach($webfm_roots as $key => $sub_root) { |
| 1973 |
|
// The read path must be contained within a legitimate role root dir for this user |
| 1974 |
|
if($sub_root && webfm_check_path($path, $sub_root)) { |
| 1975 |
|
$perm_flag = TRUE; |
| 1976 |
|
break; |
| 1977 |
|
} |
| 1978 |
|
} |
| 1979 |
|
} |
| 1980 |
|
if(!$perm_flag && module_exists('og')) { |
| 1981 |
|
$webfm_group_roots = webfm_get_group_root_dirs(); |
| 1982 |
|
foreach($webfm_group_roots as $key => $sub_root) { |
| 1983 |
|
// The read path must be contained within a legitimate group root dir for this user |
| 1984 |
|
if($sub_root && webfm_check_path($path, $sub_root)) { |
| 1985 |
|
$perm_flag = TRUE; |
| 1986 |
|
break; |
| 1987 |
|
} |
| 1988 |
|
} |
| 1989 |
|
} |
| 1990 |
|
|
| 1991 |
|
if($perm_flag && $handle = opendir($full_path)) { |
| 1992 |
// breadcrumb keeps file-sys root hidden |
// breadcrumb keeps file-sys root hidden |
| 1993 |
$non_root_arr = explode('/', trim($path, '/')); |
$non_root_arr = explode('/', trim($path, '/')); |
| 1994 |
foreach($non_root_arr as $piece) { |
foreach($non_root_arr as $piece) { |
| 1998 |
while(($readdir = readdir($handle)) !== false) { |
while(($readdir = readdir($handle)) !== false) { |
| 1999 |
// check that directory element is readable and not in black list |
// check that directory element is readable and not in black list |
| 2000 |
if(!in_array(strtolower($readdir), $bl)){ |
if(!in_array(strtolower($readdir), $bl)){ |
| 2001 |
if(is_dir($readdir)) |
if(is_dir($full_path.'/'.$readdir)) |
| 2002 |
$_dirs[] = $readdir; |
$_dirs[] = $readdir; |
| 2003 |
if(is_file($readdir)) |
else if(is_file($full_path.'/'.$readdir)) |
| 2004 |
$_files[] = $readdir; |
$_fils[] = $readdir; |
| 2005 |
} |
} |
| 2006 |
} |
} |
| 2007 |
closedir($handle); |
closedir($handle); |
| 2008 |
} |
} |
| 2009 |
|
|
| 2010 |
if(is_array($_dirs)) { |
if(is_array($_dirs)) { |
| 2011 |
foreach($_dirs as $dir) { |
foreach($_dirs as $dir) { |
| 2012 |
$dd = new stdClass(); |
$dd = new stdClass(); |
| 2013 |
$dd->n = $dir; |
$dd->n = $dir; |
| 2014 |
$dd->p = $path."/".$dir; |
$dd->p = $path."/".$dir; |
| 2015 |
$dd->m = (filemtime($dir)) ? @filemtime($dir) : ""; |
$dd->m = (filemtime($full_path.'/'.$dir)) ? @filemtime($full_path.'/'.$dir) : ""; |
| 2016 |
$this->dirs[] = $dd; |
$this->dirs[] = $dd; |
| 2017 |
} |
} |
| 2018 |
} |
} |
| 2019 |
if(is_array($_files)) { |
if(is_array($_fils)) { |
| 2020 |
foreach($_files as $file) { |
foreach($_fils as $filename) { |
| 2021 |
if($_file = webfm_get_file_record('', $full_path.'/'.$file)) { |
$file = $full_path.'/'.$filename; |
| 2022 |
|
if($_file = webfm_get_file_record('', $file)) { |
| 2023 |
if(($perm == WEBFM_ADMIN) || |
if(($perm == WEBFM_ADMIN) || |
| 2024 |
($_file->uid == $user->uid) || |
($_file->uid == $user->uid) || |
| 2025 |
((int)$_file->perm & WEBFM_FILE_ACCESS_ROLE_FULL) || |
((int)$_file->perm & WEBFM_FILE_ACCESS_ROLE_FULL) || |
| 2033 |
} else { |
} else { |
| 2034 |
$fd->u = $_file->uid; |
$fd->u = $_file->uid; |
| 2035 |
} |
} |
| 2036 |
$_query = 'SELECT name FROM {users} WHERE uid = %d'; |
if($_file->uid > 0) { |
| 2037 |
$fd->un = db_result(db_query($_query, $_file->uid)); |
$_query = 'SELECT name FROM {users} WHERE uid = %d'; |
| 2038 |
|
$fd->un = db_result(db_query($_query, $_file->uid)); |
| 2039 |
|
} else { |
| 2040 |
|
$fd->un = t('anonymous'); |
| 2041 |
|
} |
| 2042 |
$fd->m = @filemtime($file); |
$fd->m = @filemtime($file); |
| 2043 |
$fd->s = @filesize($file); |
$fd->s = @filesize($file); |
| 2044 |
} else { |
} else { |
| 2048 |
} else if($perm == WEBFM_ADMIN) { |
} else if($perm == WEBFM_ADMIN) { |
| 2049 |
$fd = new stdClass(); |
$fd = new stdClass(); |
| 2050 |
$fd->id = 0; //invalid fid signals no db entry |
$fd->id = 0; //invalid fid signals no db entry |
| 2051 |
$fd->u = 0; //file has no owner |
$fd->u = ''; //file has no owner |
| 2052 |
|
$fd->un = ''; |
|
$_query = 'SELECT name FROM {users} WHERE uid = %d'; |
|
|
$fd->un = db_result(db_query($_query, $fd->u)); |
|
|
|
|
| 2053 |
$fd->m = @filemtime($file); |
$fd->m = @filemtime($file); |
| 2054 |
$fd->s = @filesize($file); |
$fd->s = @filesize($file); |
| 2055 |
} else { |
} else { |
| 2056 |
// permission denied to view this file |
// permission denied to view this file |
| 2057 |
continue; |
continue; |
| 2058 |
} |
} |
|
|
|
| 2059 |
if(variable_get('webfm_display_title', '') && $_file->ftitle) { |
if(variable_get('webfm_display_title', '') && $_file->ftitle) { |
| 2060 |
$fd->ftitle = urldecode($_file->ftitle); |
$fd->ftitle = urldecode($_file->ftitle); |
| 2061 |
} |
} |
| 2062 |
$fd->n = $file; |
$fd->n = $filename; |
| 2063 |
$fd->p = $path; |
$fd->p = $path; |
| 2064 |
$fd->i = 0; |
$fd->i = 0; |
| 2065 |
if(strpos($file, ".") === FALSE) { |
|
| 2066 |
|
if(strpos($filename, ".") === FALSE) { |
| 2067 |
$fd->e = ""; |
$fd->e = ""; |
| 2068 |
} else { |
} else { |
| 2069 |
$fd->e = array_pop(explode('.', $file)); |
$fd->e = array_pop(explode('.', $filename)); |
| 2070 |
$mime_type = file_get_mimetype($file); |
$mime_type = file_get_mimetype($file); |
| 2071 |
if(preg_match('/^image/', $mime_type)) { |
if(preg_match('/^image/', $mime_type)) { |
| 2072 |
if(!function_exists('exif_imagetype')) { |
if(!function_exists('exif_imagetype')) { |
| 2073 |
if($i = @getimagesize($file)) { |
if((list($width, $height, $type, $attr) = @getimagesize($file)) !== false) { |
| 2074 |
//if valid width/height... |
//if valid width/height... |
| 2075 |
if(($i[0] != 0) && ($i[1] != 0)) { |
if(($width != 0) && ($height != 0)) { |
| 2076 |
//return type |
//return type |
| 2077 |
$fd->i = $i[2]; |
$fd->i = $type; |
| 2078 |
} |
} |
| 2079 |
} |
} |
| 2080 |
} else if($i = @exif_imagetype($file)) { |
} else if($i = @exif_imagetype($file)) { |
| 2203 |
$this->s = $file->fsize; |
$this->s = $file->fsize; |
| 2204 |
|
|
| 2205 |
$this->uid = $file->uid; |
$this->uid = $file->uid; |
| 2206 |
$_query = 'SELECT name FROM {users} WHERE uid = %d'; |
if($file->uid > 0) { |
| 2207 |
$this->un = db_result(db_query($_query, $file->uid)); |
$_query = 'SELECT name FROM {users} WHERE uid = %d'; |
| 2208 |
|
$this->un = db_result(db_query($_query, $file->uid)); |
| 2209 |
|
} else { |
| 2210 |
|
$this->un = t('anonymous'); |
| 2211 |
|
} |
| 2212 |
// urldecode required for fields where user input is urlencoded |
// urldecode required for fields where user input is urlencoded |
| 2213 |
$this->ftitle = urldecode($file->ftitle); |
$this->ftitle = urldecode($file->ftitle); |
| 2214 |
$this->fdesc = urldecode($file->fdesc); |
$this->fdesc = urldecode($file->fdesc); |
| 2561 |
$result = db_query($query, $values); |
$result = db_query($query, $values); |
| 2562 |
|
|
| 2563 |
if($result === FALSE){ |
if($result === FALSE){ |
| 2564 |
drupal_set_message(t('webfm_dbupdate_file() err: fid=%fid', array('%fid' => $fid)), error); |
drupal_set_message(t('webfm_dbupdate_file() err: fid=%fid', array('%fid' => $fid)), 'error'); |
| 2565 |
return FALSE; |
return FALSE; |
| 2566 |
} |
} |
| 2567 |
_webfm_file_alias('update', $metadata, $fid); |
_webfm_file_alias('update', $metadata, $fid); |
| 2769 |
// Check that requested uid exists |
// Check that requested uid exists |
| 2770 |
$query = "SELECT uid FROM {users} WHERE uid = %d"; |
$query = "SELECT uid FROM {users} WHERE uid = %d"; |
| 2771 |
$result = db_result(db_query($query, $uid_val)); |
$result = db_result(db_query($query, $uid_val)); |
| 2772 |
if(count($result) > 0) { |
if($result != NULL) { |
| 2773 |
$metadata[$metadata_key_arr[$key]['field']] = $uid_val; |
$metadata[$metadata_key_arr[$key]['field']] = $result; |
| 2774 |
} else { |
} else { |
| 2775 |
$err = "user not found"; |
$err = t('user not found'); |
| 2776 |
return FALSE; |
return FALSE; |
| 2777 |
} |
} |
| 2778 |
} else { |
} else { |
| 2779 |
$err = "invalid data"; |
$err = t('invalid data'); |
| 2780 |
return FALSE; |
return FALSE; |
| 2781 |
} |
} |
| 2782 |
} else { |
} else { |
| 2783 |
$err = "permission denied"; |
$err = t('permission denied'); |
| 2784 |
return FALSE; |
return FALSE; |
| 2785 |
} |
} |
| 2786 |
} else { |
} else { |
| 2791 |
if(count($metadata)) { |
if(count($metadata)) { |
| 2792 |
$ret = webfm_dbupdate_file($fid, '', $metadata); |
$ret = webfm_dbupdate_file($fid, '', $metadata); |
| 2793 |
if($ret) { |
if($ret) { |
| 2794 |
$err = "metadata updated"; |
$err = t('metadata updated'); |
| 2795 |
return TRUE; |
return TRUE; |
| 2796 |
} else { |
} else { |
| 2797 |
$err = "webfm_dbupdate_file fail"; |
$err = t('metadata update fail'); |
| 2798 |
} |
} |
| 2799 |
} else { |
} else { |
| 2800 |
if(!strlen($err)) { |
if(!strlen($err)) { |
| 2801 |
$err = "no update required"; |
$err = t('no update required'); |
| 2802 |
} |
} |
| 2803 |
return TRUE; |
return TRUE; |
| 2804 |
} |
} |
| 2805 |
} else { |
} else { |
| 2806 |
$err = "permission denied"; |
$err = t('permission denied'); |
| 2807 |
} |
} |
| 2808 |
} else { |
} else { |
| 2809 |
$err = "file not found"; |
$err = t('file not found'); |
| 2810 |
} |
} |
| 2811 |
return FALSE; |
return FALSE; |
| 2812 |
} |
} |
| 2840 |
$query = 'DELETE FROM {webfm_file} WHERE fid = %d'; |
$query = 'DELETE FROM {webfm_file} WHERE fid = %d'; |
| 2841 |
$result = db_query($query, $fid); |
$result = db_query($query, $fid); |
| 2842 |
if($result === FALSE){ |
if($result === FALSE){ |
| 2843 |
drupal_set_message(t('Query Failed: Could not delete file %fid .', array('%fid' => $fid), error)); |
drupal_set_message(t('Query Failed: Could not delete file %fid .', array('%fid' => $fid), 'error')); |
| 2844 |
return FALSE; |
return FALSE; |
| 2845 |
} |
} |
| 2846 |
return TRUE; |
return TRUE; |