| 1 |
<?php
|
| 2 |
/* $Id */
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_help().
|
| 6 |
*/
|
| 7 |
function filebrowser_help($section) {
|
| 8 |
switch ($section) {
|
| 9 |
case 'admin/help#filebrowser':
|
| 10 |
case 'admin/settings/filebrowser':
|
| 11 |
return t("
|
| 12 |
<h3>Using a filebrowser</h3>
|
| 13 |
<p>The filebrowser module uses taxonomy to organize the uploaded files into hierarchy.
|
| 14 |
To create a filebrowser you first have to create a <a href=\"%taxonomy\">taxonomy vocabulary</a>.
|
| 15 |
When doing this, choose a sensible name for it (such as \"files\") and make sure under \"Types\" that \"upload file\" is selected.
|
| 16 |
Once you have done this, <a href=\"%taxo-terms\">add some terms</a> to it.
|
| 17 |
Each term will become a folder. If you fill in the description field, users will be given additonal information about the folder on the main folder page.
|
| 18 |
For example: \"project\" - \"Please add your project files here.\"</p>");
|
| 19 |
case 'admin/modules#description':
|
| 20 |
return t('Enable browsing files in filestore2 by taxonomy.');
|
| 21 |
}
|
| 22 |
}//filebrowser help
|
| 23 |
|
| 24 |
|
| 25 |
/**
|
| 26 |
* Implementation of hook_settings().
|
| 27 |
*/
|
| 28 |
function filebrowser_settings() {
|
| 29 |
$voc=variable_get('filebrowser_nav_vocabulary', '');
|
| 30 |
$type = variable_get('filebrowser_upload', 'filestore2');
|
| 31 |
$settings_function = 'filebrowser_'. $type . '_settings';
|
| 32 |
|
| 33 |
require_once( 'modules/filebrowser/'.$type.'.inc' ); if (module_exist('taxonomy')) {
|
| 34 |
$vocs[0] = '<'. t('none') .'>';
|
| 35 |
foreach (taxonomy_get_vocabularies(t("filestore2")) as $vid => $voc) {
|
| 36 |
$vocs[$vid] = $voc->name;
|
| 37 |
}
|
| 38 |
if ($voc) {
|
| 39 |
$output = form_select(t('Files Upload Method'), 'filebrowser_upload', variable_get('filebrowser_upload', 'flexinode'), drupal_map_assoc(array('filestore2','flexinode')));
|
| 40 |
$output .= form_select(t('Filebrowser vocabulary'), 'filebrowser_nav_vocabulary', variable_get('filebrowser_nav_vocabulary', ''), $vocs, t("The taxonomy vocabulary that will be used as the navigation tree. The vocabulary's terms define the folders."));
|
| 41 |
$output .= form_select(t('Files per page'), 'files_per_page', variable_get('files_per_page', 15), drupal_map_assoc(array(5, 10, 15, 20, 25, 50, 75, 100)), t('The default number of files displayed per page;'));
|
| 42 |
$output .= form_textarea(t('Filebrowser Help'), 'filebrowser_help', variable_get('filebrowser_help', ''), 80, 5);
|
| 43 |
$output .= function_exists($settings_function)? $settings_function():'';
|
| 44 |
} else {
|
| 45 |
$output .= t('Please select an upload method and make sure there is a vocabulary associated with it, default is filestore2');
|
| 46 |
$output .= form_select(t('Files Upload Method'), 'filebrowser_upload', variable_get('filesbrowser_upload', 'filestore2'), drupal_map_assoc(array('filestore2','flexinode')));
|
| 47 |
}
|
| 48 |
}
|
| 49 |
return $output;
|
| 50 |
}//filebrowser settings
|
| 51 |
|
| 52 |
/**
|
| 53 |
* Implementation of hook_menu().
|
| 54 |
*/
|
| 55 |
function filebrowser_menu() {
|
| 56 |
$items = array();
|
| 57 |
// By using the MENU_CALLBACK type, we can register the callback for this
|
| 58 |
// path but not have the item show up in the menu; the admin is not allowed
|
| 59 |
// to enable the item in the menu, either.
|
| 60 |
$items[] = array('path' => 'browser', 'title' => t('file browser'),
|
| 61 |
'callback' => 'filebrowser_browser',
|
| 62 |
'access' => 'access content',
|
| 63 |
'type' => MENU_CALLBACK | MENU_VISIBLE_IN_BREADCRUMB );
|
| 64 |
return $items;
|
| 65 |
}
|
| 66 |
|
| 67 |
/* browser page
|
| 68 |
*
|
| 69 |
*/
|
| 70 |
function filebrowser_browser($tid=0) {
|
| 71 |
$voc=variable_get('filebrowser_nav_vocabulary', '');
|
| 72 |
$type = variable_get('filebrowser_upload', 'filestore2');
|
| 73 |
$browser_function = $type . '_filebrowser';
|
| 74 |
require_once( 'modules/filebrowser/'.$type.'.inc' );
|
| 75 |
//what do we do in the case of an empty vocabulary
|
| 76 |
if($tid) {
|
| 77 |
$children = taxonomy_get_children($tid);
|
| 78 |
} else {
|
| 79 |
$children = taxonomy_get_tree($voc,0,-1,1);
|
| 80 |
}
|
| 81 |
$parents = taxonomy_get_parents_all($tid);
|
| 82 |
$result = $browser_function($tid);
|
| 83 |
$content= theme("filebrowser_display", $parents, $children, $result[header], $result[rows]);
|
| 84 |
print theme("page",$content);
|
| 85 |
}
|
| 86 |
|
| 87 |
|
| 88 |
/*browser themeing function
|
| 89 |
*/
|
| 90 |
function theme_filebrowser_display($parents, $children, $header, $rows) {
|
| 91 |
$type = variable_get('filebrowser_upload', 'filestore2');
|
| 92 |
$content_type = function_exists('filebrowser_'.$type.'_type')? call_user_func('filebrowser_'.$type.'_type'):$type;
|
| 93 |
$voc = taxonomy_get_vocabulary(variable_get('filebrowser_nav_vocabulary', ''));
|
| 94 |
$title = $voc->name;
|
| 95 |
|
| 96 |
// Breadcrumb navigation:
|
| 97 |
$breadcrumb[] = l(t('Home'), '');
|
| 98 |
$breadcrumb[] = l(t('file browser'), 'browser', array("longdesc"=>"taxonomy based file browser", "title"=>'file browser'));
|
| 99 |
|
| 100 |
if ($parents) {
|
| 101 |
$parents = array_reverse($parents);
|
| 102 |
foreach ($parents as $p) {
|
| 103 |
if ($p->tid == $tid) {
|
| 104 |
$title = $p->name;
|
| 105 |
}
|
| 106 |
else {
|
| 107 |
// $breadcrumb[] = array('path' => 'browser/'. $p->tid, 'title' => $p->name);
|
| 108 |
$breadcrumb[] = l($p->name,"browser/".$p->tid, array("longdesc"=>$p->description));
|
| 109 |
}
|
| 110 |
}
|
| 111 |
}
|
| 112 |
|
| 113 |
|
| 114 |
// $breadcrumb[] = array('path' => $_GET['q']);
|
| 115 |
drupal_set_breadcrumb($breadcrumb);
|
| 116 |
|
| 117 |
$children_list=array();
|
| 118 |
if($children) {
|
| 119 |
foreach($children as $c) {
|
| 120 |
if ($c->tid == $tid) {
|
| 121 |
$title = $c->name;
|
| 122 |
}
|
| 123 |
else {
|
| 124 |
$children_list[] = l($c->name,"browser/".$c->tid, array("long desc"=>$c->description));
|
| 125 |
}
|
| 126 |
}
|
| 127 |
}
|
| 128 |
|
| 129 |
drupal_set_html_head( theme_stylesheet_import("/modules/filebrowser/style.css"));
|
| 130 |
$output .= variable_get('filebrowser_help', '') . '<hr />';
|
| 131 |
$output .= '<ul class="file_browser_menu"><li >'. l(t('add folder'),'admin/taxonomy/add/term/'. variable_get('filebrowser_nav_vocabulary', '')) . '</li><li>'.l(t('upload a file'),'node/add/'.$content_type).'</li></ul>';
|
| 132 |
$output .= theme_filebrowser_children($children_list);
|
| 133 |
|
| 134 |
$output .= theme('filebrowser_files',$header, $rows);
|
| 135 |
$output.=theme("pager",NULL, variable_get('files_per_page',15));
|
| 136 |
global $pager_total;
|
| 137 |
return $output;
|
| 138 |
}
|
| 139 |
|
| 140 |
function theme_filebrowser_children($children){
|
| 141 |
$output .= "<ul class='folders'>";
|
| 142 |
foreach($children as $kid) {
|
| 143 |
$output .= "<li class='folder'>".$kid."</li>";
|
| 144 |
}
|
| 145 |
$output .= "</ul>";
|
| 146 |
return $output;
|
| 147 |
}
|
| 148 |
|
| 149 |
function theme_filebrowser_files($header,$files){
|
| 150 |
if(!$files) {
|
| 151 |
return;
|
| 152 |
}
|
| 153 |
return theme('table',$header,$files);
|
| 154 |
}
|
| 155 |
|
| 156 |
/*
|
| 157 |
* should be in taxonomy really
|
| 158 |
*/
|
| 159 |
function taxonomy_term_node_join() {
|
| 160 |
return ' LEFT JOIN {term_node} tn ON n.nid = tn.nid ';
|
| 161 |
}
|
| 162 |
|
| 163 |
/*
|
| 164 |
* should be in taxonomy really
|
| 165 |
*/
|
| 166 |
function taxonomy_term_node_where($tid) {
|
| 167 |
return isset($tid)?' tn.tid = '.$tid.' ':NULL;
|
| 168 |
}
|
| 169 |
?>
|