[dev] Gollem patch for Shared Folders
Joel Vandal
jvandal at infoteck.qc.ca
Sat Jan 17 06:33:22 PST 2004
Hi all!
This patch allow to use the share class to create Shared Folders with Gollem. I've made a lot of test and use this patch w/ the file VFS backend since more that 1 year without problem.
This patch now also add support for other backend that require credential (like username/password/email/...) but I've not made exhaustive tests w/ other backend (like ftp, sql, musql).
Core team are probably more experimented PHP developper that I can and they will be able to fix little dependency (like hook for userid) or extend/test it to all vfs backend.
I hope that this patch respect coding standard of Horde! :) I wish that this patch will be included in future HEAD cvs release :)
Attachment:
gollem.diff.txt : patch for manager.php lib/base.php lib/Gollem.php, ...
gollem.tar : new file added (like folders.php, browse.php, ...)
--
Joel Vandal Infoteck Internet
http://www.infoteck.qc.ca Tel. 819-370-3232
jvandal at infoteck.qc.ca Fax. 819-370-3624
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gollem.tar
Type: application/octet-stream
Size: 30720 bytes
Desc: not available
Url : http://lists.horde.org/archives/dev/attachments/20040117/29b50376/gollem-0001.obj
-------------- next part --------------
Index: manager.php
===================================================================
RCS file: /repository/gollem/manager.php,v
retrieving revision 1.99
diff -p --unified=3 -r1.99 manager.php
--- manager.php 1 Jan 2004 15:14:58 -0000 1.99
+++ manager.php 17 Jan 2004 14:08:22 -0000
@@ -22,6 +22,13 @@ $actionID = Util::getFormData('actionID'
$backend_key = Gollem::getCurrentBackend();
$backend_dir = Gollem::getDir($backend_key);
+if (!empty($backend_key)) {
+ if (Gollem::createSession($backend_key) && Gollem::changeDir($backend_key)) {
+ }
+}
+
+$folder_id = $prefs->getValue('default_folder');
+
/* Check if session is setup for driver and check if person is
* authenticated for driver. */
Gollem::checkGollemAuth($backend_key);
@@ -190,6 +197,14 @@ foreach ($used_backends as $key => $curB
}
}
+/* Set the current folder in a global setting */
+if (count($GLOBALS['display_folders']) > 0) {
+ $folder_id = $GLOBALS['display_folders'][0];
+} else {
+ $folder_id = Auth::getAuth();
+}
+$GLOBALS['curfolder'] = $GLOBALS['gollem_shares']->getShare($folder_id);
+
require GOLLEM_TEMPLATES . '/common-header.inc';
Gollem::menu();
require_once $registry->getParam('templates', 'horde') . '/contents/open_view_win.js';
@@ -331,6 +346,9 @@ foreach ($info as $backkey => $vars) {
} else {
require GOLLEM_TEMPLATES . '/manager/empty_dir.inc';
}
+
+ echo Gollem::buildFolderLegend();
+
require GOLLEM_TEMPLATES . '/manager/footer.inc';
}
Index: prefs.php
===================================================================
RCS file: /repository/gollem/prefs.php,v
retrieving revision 1.41
diff -p --unified=3 -r1.41 prefs.php
--- prefs.php 1 Jan 2004 15:14:59 -0000 1.41
+++ prefs.php 17 Jan 2004 14:08:23 -0000
@@ -10,6 +10,22 @@
* did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
*/
+function handle_folderselect($updated)
+{
+ global $prefs;
+
+ $default_folder = Util::getFormData('default_folder');
+ if (!is_null($default_folder)) {
+ $folders = Gollem::listSharedFolders();
+ if (is_array($folders) && array_key_exists($default_folder, $folders)) {
+ $prefs->setValue('default_folder', $default_folder);
+ $updated = true;
+ }
+ }
+ return $updated;
+}
+
+
function handle_columnselect($updated)
{
global $prefs;
Index: config/prefs.php.dist
===================================================================
RCS file: /repository/gollem/config/prefs.php.dist,v
retrieving revision 1.26
diff -p --unified=3 -r1.26 prefs.php.dist
--- config/prefs.php.dist 21 Nov 2003 21:53:46 -0000 1.26
+++ config/prefs.php.dist 17 Jan 2004 14:08:23 -0000
@@ -15,6 +15,48 @@ $prefGroups['display'] = array(
'members' => array('show_dotfiles', 'columnselect', 'sortby', 'sortdir',
'sortdirsfirst'));
+$prefGroups['share'] = array(
+ 'column' => _("Shared Folder Management"),
+ 'label' => _("Shared Folder"),
+ 'desc' => _("Manage multiple shared folder."),
+ 'members' => array('shareselect'));
+if (Auth::getAuth()) {
+$prefGroups['share']['members'][] = 'folders_link';
+}
+
+// default folder selection widget
+$_prefs['shareselect'] = array('type' => 'special');
+
+// default folder
+// Set locked to true if you don't want users to have multiple folders.
+$_prefs['default_folder'] = array(
+ 'value' => Auth::getAuth(),
+ 'locked' => false,
+ 'shared' => true,
+ 'type' => 'implicit');
+
+// Link to the folder management
+if (Auth::getAuth()) {
+$_prefs['folders_link'] = array(
+ 'type' => 'link',
+ 'url' => 'folders.php',
+ 'img' => 'gollem.gif',
+ 'desc' => _("Edit your folders."));
+}
+
+// store the folders to diplay
+$_prefs['display_folders'] = array(
+ 'value' => 'a:0:{}',
+ 'locked' => false,
+ 'shared' => false,
+ 'type' => 'implicit');
+
+// store the uid for shared folders (from _gollem_hook_uid)
+$_prefs['uid'] = array(
+ 'value' => '',
+ 'locked' => true,
+ 'shared' => true,
+ 'type' => 'implicit');
// show dotfiles?
$_prefs['show_dotfiles'] = array(
Index: lib/Gollem.php
===================================================================
RCS file: /repository/gollem/lib/Gollem.php,v
retrieving revision 1.110
diff -p --unified=3 -r1.110 Gollem.php
--- lib/Gollem.php 13 Dec 2003 00:10:18 -0000 1.110
+++ lib/Gollem.php 17 Jan 2004 14:08:23 -0000
@@ -130,7 +130,24 @@ class Gollem {
$ptr['params']['port'] = $port;
}
}
-
+
+ $_folder = '';
+ if ($ptr['params']['shared'] && count($GLOBALS['display_folders']) > 0) {
+
+ $folder_id = $GLOBALS['display_folders'][0];
+
+ $_share = $GLOBALS['gollem_shares']->getShare($folder_id);
+ $_owner = $_share->get('owner');
+ $_username = $_share->get('username');
+ $_password = $_share->get('password');
+ $_folder = $_share->get('folder');
+
+ $share_uid = Horde::callHook('_gollem_hook_uid', array($_owner));
+ $ptr['params']['vfsroot'] = sprintf($ptr['params']['vfsroot'], $share_uid, $_folder);
+ } else {
+ $_owner = Auth::getAuth();
+ }
+
// Load VFS driver.
$vfs[$key] = &VFS::singleton($ptr['driver'], $ptr['params']);
@@ -439,6 +456,56 @@ class Gollem {
$res = strcasecmp($a['name'], $b['name']);
return $prefs->getValue('sortdir') ? ($res * -1) : $res;
}
+
+ /**
+ * Builds the category legend for the displayed folders.
+ *
+ * @return string The HTML table for the legend.
+ */
+ function buildFolderLegend()
+ {
+ if (count($GLOBALS['display_folders']) == 0) {
+ return '';
+ }
+
+ require_once HORDE_LIBS . 'Horde/Image.php';
+ $html = '<tr><td class="light">';
+ $html .= '<table border="0" cellpadding="0" cellspacing="4">';
+ foreach (Gollem::listSharedFolders() as $id => $folder) {
+ if (in_array($id, $GLOBALS['display_folders'])) {
+ $html .= '<tr><td class="legend"><b>' . $folder->get('name') . ':</b></td>';
+ $html .= '<td class="legend">' . $folder->get('owner') . '</td>';
+
+ $color = '#EEEEEE';
+ $html .= '<td class="legend" width="15" style="background-color: ' . $color . '; ';
+ $html .= 'border-color: ' . Horde_Image::modifyColor($color, -0x44) . '"> </td>';
+ $html .= "</tr>\n";
+ }
+ }
+
+ return $html . "</table></td></tr>\n";
+ }
+
+ /**
+ * List all shared folders a user has access to, according to
+ * several parameters/permission levels.
+ *
+ * @param optional boolean $owneronly Only return folders that this
+ * user owns? Defaults to false.
+ * @param optional integer $permission The permission to filter folders by.
+ *
+ * @return array The shared folder list.
+ */
+ function listSharedFolders($owneronly = false, $permission = PERMS_SHOW)
+ {
+ $folders = $GLOBALS['gollem_shares']->listShares(Auth::getAuth(), $permission, $owneronly);
+ if (is_a($folders, 'PEAR_Error')) {
+ Horde::logMessage($folders, __FILE__, __LINE__, PEAR_LOG_ERR);
+ return array();
+ }
+
+ return $folders;
+ }
function listFolder($backend_key, $dir = '')
{
@@ -707,11 +774,19 @@ class Gollem {
function menu()
{
global $notification, $conf, $registry, $backend_key;
+
+ $folders = Gollem::listSharedFolders();
require_once HORDE_BASE . '/lib/Menu.php';
require GOLLEM_TEMPLATES . '/menu/menu.inc';
/* Include the JavaScript for the help system (if enabled). */
Help::javascript();
+
+ // Check here for guest folders so that we don't get multiple
+ // messages after redirects, etc.
+ if (!Auth::getAuth() && !count(Gollem::listSharedFolders())) {
+ $notification->push(_("No folders are available to guests."));
+ }
$notification->notify();
}
Index: lib/base.php
===================================================================
RCS file: /repository/gollem/lib/base.php,v
retrieving revision 1.43
diff -p --unified=3 -r1.43 base.php
--- lib/base.php 24 Dec 2003 00:48:19 -0000 1.43
+++ lib/base.php 17 Jan 2004 14:08:23 -0000
@@ -64,5 +64,73 @@ require GOLLEM_BASE . '/config/backends.
// Help.
require_once HORDE_BASE . '/lib/Help.php';
+// Create a share instance.
+require_once HORDE_LIBS . 'Horde/Share.php';
+$GLOBALS['gollem_shares'] = &Horde_Share::singleton($registry->getApp());
+
+// Update the preference for which folders to display. If the user
+// doesn't have any selected folders for view then fall back to some
+// available folder.
+
+$GLOBALS['display_folders'] = unserialize($GLOBALS['prefs']->getValue('display_folders'));
+if (($d_note = Util::getFormData('display_folder')) !== null) {
+ if (in_array($d_note, $GLOBALS['display_folders'])) {
+ $key = array_search($d_note, $GLOBALS['display_folders']);
+ unset($GLOBALS['display_folders'][$key]);
+ } else {
+ $GLOBALS['display_folders'] = array();
+ $GLOBALS['display_folders'][] = $d_note;
+ }
+ $GLOBALS['prefs']->setValue('display_folders', serialize($GLOBALS['display_folders']));
+}
+
+//$GLOBALS['display_folders'] = array();
+//$GLOBALS['prefs']->getValue('display_folders'));
+//if (($d_note = Util::getFormData('display_folder')) !== null) {
+// $GLOBALS['display_folders'][] = $d_note;
+// $GLOBALS['prefs']->setValue('display_folders', serialize($GLOBALS['display_folders']));
+//}
+
+
+
+// Make sure all task lists exist now, to save on checking later.
+$_temp = $GLOBALS['display_folders'];
+$_all = Gollem::listSharedFolders();
+$GLOBALS['display_folders'] = array();
+foreach ($_temp as $id) {
+ if (isset($_all[$id])) {
+ $GLOBALS['display_folders'][] = $id;
+ }
+}
+
+if (count($GLOBALS['display_folders']) == 0) {
+ $lists = Gollem::listSharedFolders(true);
+ if (!Auth::getAuth()) {
+ // All folders for guests.
+ $GLOBALS['display_folders'] = array_keys($lists);
+ } elseif (!count($lists)) {
+ // Create a personal memo list
+ $GLOBALS['display_folders'] = array(Auth::getAuth());
+
+ // If this share doesn't exist then create it.
+ if (!$GLOBALS['gollem_shares']->exists(Auth::getAuth())) {
+ require_once HORDE_BASE . '/lib/Identity.php';
+ $identity = &new Identity();
+ $name = $identity->getValue('fullname');
+ if (trim($name) == '') {
+ $name = Auth::removeHook(Auth::getAuth());
+ }
+ $share = $GLOBALS['gollem_shares']->newShare(Auth::getAuth());
+ $share->setOwner(Auth::getAuth(), false);
+ $share->setShareName(sprintf(_("%s's Folder"), $name), false);
+ $GLOBALS['gollem_shares']->addShare($share);
+ }
+ }
+}
+
+$GLOBALS['prefs']->setValue('display_folders', serialize($GLOBALS['display_folders']));
+
+
+
// Start compression, if requested.
Horde::compressOutput();
Index: templates/manager/actions.inc
===================================================================
RCS file: /repository/gollem/templates/manager/actions.inc,v
retrieving revision 1.24
diff -p --unified=3 -r1.24 actions.inc
--- templates/manager/actions.inc 17 Nov 2003 21:28:33 -0000 1.24
+++ templates/manager/actions.inc 17 Jan 2004 14:08:27 -0000
@@ -2,7 +2,9 @@
<tr class="item"><td>
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
+ <?php if ($GLOBALS['curfolder']->hasPermission(Auth::getAuth(), PERMS_EDIT)) : ?>
<?php if ($j[$backend_key] == 1): ?>
+ <?php if ($prefs->getValue('multipleupload')) : ?>
<td width="40%" align="left" nowrap="nowrap">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
@@ -21,19 +23,29 @@
<td> <input name="file_upload_3" type="file" size="20" class="fixed" /></td>
</tr>
</table>
+ <?php else: ?>
+ <td width="40%" align"left" nowrap="nowrap">
+ <?php echo Help::link('gollem', 'file-upload') ?>
+ <input name="file_upload_1" type="file" size="20" class="fixed"/> <input type="button" class="button" onclick="<?php echo $backend_key ?>_uploadFile()" value="<?php echo _("Upload File") ?>" />
+ <?php endif; ?>
</td>
<?php endif; ?>
-
+ <?php endif; ?>
<td align="right" nowrap="nowrap">
<?php echo Help::link('gollem', 'file-actions') ?>
<select name="action<?php echo $j[$backend_key] ?>" onchange="<?php echo $backend_key ?>_chooseAction(<?php echo $j[$backend_key] ?>); document.<?php echo $backend_key?>_manager.action<?php echo $j[$backend_key] ?>.selectedIndex = 0;">
<option selected="selected"><?php echo _("Choose Action:") ?></option>
<option value="change_directory"><?php echo _("Change Directory") ?></option>
+ <?php if ($GLOBALS['curfolder']->hasPermission(Auth::getAuth(), PERMS_EDIT)) : ?>
<option value="create_folder"><?php echo _("Create Directory") ?></option>
+ <?php endif; ?>
+<?php if ($GLOBALS['curfolder']->hasPermission(Auth::getAuth(), PERMS_EDIT)) : ?>
<?php if (@count($list)): ?>
<option value="rename_items"><?php echo _("Rename Items") ?></option>
+ <?php if ($GLOBALS['curfolder']->hasPermission(Auth::getAuth(), PERMS_DELETE)) : ?>
<option value="delete_items"><?php echo _("Delete Items") ?></option>
- <option value="chmod_modify"><?php echo _("Chmod Items") ?></option>
+ <?php endif; ?>
+<!-- <option value="chmod_modify"><?php echo _("Chmod Items") ?></option> -->
<?php if ((empty($_SESSION['gollem']['cut']['selected'])) && (empty($_SESSION['gollem']['copy']['selected']))): ?>
<option value="cut_items"><?php echo _("Cut Items") ?></option>
<option value="copy_items"><?php echo _("Copy Items") ?></option>
@@ -42,6 +54,7 @@
<?php if ((!empty($_SESSION['gollem']['cut']['selected'])) || (!empty($_SESSION['gollem']['copy']['selected']))): ?>
<option value="paste_items"><?php echo _("Paste Items") ?></option>
<?php endif; ?>
+<?php endif; ?>
</select>
</td>
</tr>
Index: templates/menu/menu.inc
===================================================================
RCS file: /repository/gollem/templates/menu/menu.inc,v
retrieving revision 1.31
diff -p --unified=3 -r1.31 menu.inc
--- templates/menu/menu.inc 3 Oct 2003 21:23:54 -0000 1.31
+++ templates/menu/menu.inc 17 Jan 2004 14:08:27 -0000
@@ -5,7 +5,10 @@
/* Gollem menu items. */
Menu::printItem(Horde::applicationUrl('manager.php?dir=' . $_SESSION['gollem'][$backend_key]['home']), _("Home"), 'home.gif');
if (strstr($_SERVER['PHP_SELF'], 'manager.php')) {
- Menu::printItem('', _("Create Directory"), 'mkdir.gif', null, '', $backend_key . '_createFolder(); return false;');
+
+ if ($GLOBALS['curfolder']->hasPermission(Auth::getAuth(), PERMS_EDIT)) {
+ Menu::printItem('', _("Create Directory"), 'mkdir.gif', null, '', $backend_key . '_createFolder(); return false;');
+ }
Menu::printItem('', _("Change Directory"), 'cd.gif', null, '', $backend_key . '_changeDirectory(); return false;');
}
@@ -30,5 +33,31 @@ if (!Gollem::canAutoLogin()) {
}
?>
-<td width="100%"> </td>
+<td width="100%"> </td><!-- spacer -->
+
+<?php $prefs = $GLOBALS['prefs']; ?>
+<?php if (!$prefs->isLocked('default_folder') && (count($folders) > 1 || !count($GLOBALS['display_folders']))): ?>
+<?php Menu::printItem('#', _("Show"), 'gollem.gif', null, null, 'return listFoldersSubmit();', '__noselection'); ?>
+<td class="light" align="left">
+<form action="<?php echo Horde::applicationUrl('manager.php') ?>" method="post" name="foldersmenu">
+<?php Util::pformInput() ?>
+<select name="display_folder" onchange="listFoldersSubmit();">
+ <option value=""><?php echo _("Show Folders:") ?></option>
+<?php foreach ($folders as $id => $folder): ?>
+ <option value="<?php echo $id ?>"><?php echo (in_array($id, $GLOBALS['display_folders']) ? '* ' : '') . $folder->get('name') ?></option>
+<?php endforeach; ?>
+</select>
+</form>
+<script language="JavaScript" type="text/javascript">
+<!--
+var loading;
+function listFoldersSubmit()
+{
+ document.foldersmenu.submit();
+ return false;
+}
+// -->
+</script>
+</td>
+<?php endif; ?>
</tr></table></td></tr></table><br />
More information about the dev
mailing list