New Links (Patch)
| Newsgroups | gmane.comp.horde.devel,gmane.comp.horde.whups |
|---|---|
| Message-ID | <[email protected]> |
Hello, I finally have what I started out with. :-) You can now links things into Turba. I changed registry.php.dist to include a link between nag and turba. I crosspost this to the whups list, because I saw a thread there from a while back that was asking for links into Turba. Maybe the whups developers/contributors might want to look into this. There is also an improvement to linking in general. If a reverse link is not read-only you couldn't add a proper link when you tried to go backwards. The code now handles this correctly. Regards, Jeroen __________________________________________________________ http://www.wanadoo.nl/ -- Horde developers mailing list Frequently Asked Questions: http://horde.org/faq/ To unsubscribe, mail: [email protected]
links2.diff
(application/octet-stream, 14.3 KB)
? turba/addlink.php
? turba/templates/addlink
Index: klutz/addlink.php
===================================================================
RCS file: /repository/klutz/addlink.php,v
retrieving revision 1.3
diff -u -r1.3 addlink.php
--- klutz/addlink.php 24 Feb 2003 21:47:51 -0000 1.3
+++ klutz/addlink.php 27 Feb 2003 21:22:01 -0000
@@ -13,8 +13,12 @@
define('KLUTZ_BASE', dirname(__FILE__));
require_once KLUTZ_BASE . '/lib/base.php';
-$link_type = Horde::getFormData('link_type');
$return_url = Horde::getFormData('url');
+$link_type = Horde::getFormData('link_type');
+$reverse = (substr($link_type,-8) == '/reverse') ? '/reverse' : '';
+if (!empty($reverse)) {
+ $link_type = substr($link_type,0,-8);
+}
$from_application = Horde::getFormData('from_application');
$from_parameters = @unserialize(Horde::getFormData('from_parameters'));
$to_application = Horde::getFormData('to_application');
@@ -23,7 +27,11 @@
$links = &Horde_Links::singleton($registry->getApp());
$to_parameters = @unserialize(Horde::getFormData('to_parameters'));
- $status = $links->addLink($from_application, $from_parameters, $to_application, $to_parameters, $link_type);
+ if (!empty($reverse)) {
+ $status = $links->addLink($to_application, $to_parameters, $from_application, $from_parameters, $link_type);
+ } else {
+ $status = $links->addLink($from_application, $from_parameters, $to_application, $to_parameters, $link_type);
+ }
if (is_a($status, 'PEAR_Error')) {
$notification->push($status, 'horde.error');
} elseif ($registry->hasMethod($to_application . '/getLinkSummary')) {
Index: lib/Links.php
===================================================================
RCS file: /repository/horde/lib/Links.php,v
retrieving revision 1.4
diff -u -r1.4 Links.php
--- lib/Links.php 25 Feb 2003 16:26:44 -0000 1.4
+++ lib/Links.php 27 Feb 2003 21:23:33 -0000
@@ -159,6 +159,7 @@
foreach ($this->_link_definitions as $link_type => $link_definition) {
$app = $this->_link_definitions[$link_type]['provider'];
$type = $this->_link_definitions[$link_type]['type'];
+ $reverse = (substr($link_type,-8) == '/reverse') ? '/reverse' : '';
require $registry->getParam('templates', 'horde') . '/links/header.inc';
require $registry->getParam('templates', 'horde') . '/links/links.inc';
require $registry->getParam('templates', 'horde') . '/links/footer.inc';
Index: nag/addlink.php
===================================================================
RCS file: /repository/nag/addlink.php,v
retrieving revision 1.3
diff -u -r1.3 addlink.php
--- nag/addlink.php 24 Feb 2003 21:47:54 -0000 1.3
+++ nag/addlink.php 27 Feb 2003 21:24:16 -0000
@@ -13,8 +13,12 @@
@define('NAG_BASE', dirname(__FILE__));
require_once NAG_BASE . '/lib/base.php';
-$link_type = Horde::getFormData('link_type');
$return_url = Horde::getFormData('url');
+$link_type = Horde::getFormData('link_type');
+$reverse = (substr($link_type,-8) == '/reverse') ? '/reverse' : '';
+if (!empty($reverse)) {
+ $link_type = substr($link_type,0,-8);
+}
$from_application = Horde::getFormData('from_application');
$from_parameters = @unserialize(Horde::getFormData('from_parameters'));
$to_application = Horde::getFormData('to_application');
@@ -23,7 +27,11 @@
$links = &Horde_Links::singleton($registry->getApp());
$to_parameters = @unserialize(Horde::getFormData('to_parameters'));
- $status = $links->addLink($from_application, $from_parameters, $to_application, $to_parameters, $link_type);
+ if (!empty($reverse)) {
+ $status = $links->addLink($to_application, $to_parameters, $from_application, $from_parameters, $link_type);
+ } else {
+ $status = $links->addLink($from_application, $from_parameters, $to_application, $to_parameters, $link_type);
+ }
if (is_a($status, 'PEAR_Error')) {
$notification->push($status, 'horde.error');
} elseif ($registry->hasMethod($to_application . '/getLinkSummary')) {
@@ -100,7 +108,7 @@
$addurl = Horde::addParameter($addurl, 'from_application', $from_application);
$addurl = Horde::addParameter($addurl, 'from_parameters', serialize($from_parameters));
$addurl = Horde::addParameter($addurl, 'url', $return_url);
- $addurl = Horde::addParameter($addurl, 'link_type', $link_type);
+ $addurl = Horde::addParameter($addurl, 'link_type', $link_type . $reverse);
$share = $GLOBALS['nag_shares']->getShare($task['tasklist_id']);
$owner = $task['tasklist_id'];
Index: templates/links/footer.inc
===================================================================
RCS file: /repository/horde/templates/links/footer.inc,v
retrieving revision 1.2
diff -u -r1.2 footer.inc
--- templates/links/footer.inc 24 Feb 2003 21:47:56 -0000 1.2
+++ templates/links/footer.inc 27 Feb 2003 21:25:41 -0000
@@ -1,6 +1,11 @@
<?php if ($registry->hasMethod($app . '/addLink') && !$this->_link_definitions[$link_type]['readonly']): ?>
<tr><td>
-<a href="<?php echo Horde::url($registry->link($app . '/addLink', array('url' => Horde::selfUrl(true, false, true), 'link_type' => $type, 'from_parameters'=> serialize($link_parameters), 'from_application' => $registry->getParam('provides')))) ?>" class="button"><?php echo _("Add") . ' ' . $link_definition['description'] ?></a>
+<a href="<?php echo Horde::url($registry->link($app . '/addLink',
+ array('url' => Horde::selfUrl(true, false, true),
+ 'from_parameters'=> serialize($link_parameters),
+ 'from_application' => $registry->getParam('provides'),
+ 'link_type' => $type . $reverse,
+ ))) ?>" class="button"><?php echo _("Add") . ' ' . $link_definition['description'] ?></a>
</tr></td>
<?php endif; ?>
</table>
Index: turba/displayobject.php
===================================================================
RCS file: /repository/turba/displayobject.php,v
retrieving revision 1.24
diff -u -r1.24 displayobject.php
--- turba/displayobject.php 18 Feb 2003 05:47:19 -0000 1.24
+++ turba/displayobject.php 27 Feb 2003 21:26:12 -0000
@@ -63,4 +63,11 @@
require TURBA_TEMPLATES . '/common-header.inc';
require TURBA_BASE . '/menu.php';
$displayform->renderInactive($r, $vars);
+ if ($links->listLinkTypes()) {
+ $links->viewLinks(array(
+ 'source' => (string)$source,
+ 'id' => (string)$key,
+ )
+ );
+ }
require TURBA_TEMPLATES . '/common-footer.inc';
Index: turba/lib/api.php
===================================================================
RCS file: /repository/turba/lib/api.php,v
retrieving revision 1.45
diff -u -r1.45 api.php
--- turba/lib/api.php 5 Feb 2003 03:03:51 -0000 1.45
+++ turba/lib/api.php 27 Feb 2003 21:26:18 -0000
@@ -15,6 +15,9 @@
$_services['show'] = array(
'link' => '%application%/displayobject.php?source=|source|&key=|key|');
+$_services['followLink'] = array(
+ 'link' => '%application%/displayobject.php?source=|source|&key=|id|');
+
$_services['search'] = array(
'args' => array('addresses', 'addressbooks', 'fields'),
'type' => 'array');
@@ -55,6 +58,41 @@
'args' => array(),
'type' => 'array');
+$_services['LinkParameters'] = array(
+ 'args' => array(),
+ 'type' => 'array');
+
+function _turba_LinkParameters() {
+ return array('source', 'id');
+}
+
+$_services['getFieldByLinkParameters'] = array(
+ 'args' => array_merge(_turba_LinkParameters(), array('field')),
+ 'type' => 'string');
+
+$_services['getLinkDescription'] = array(
+ 'args' => _turba_LinkParameters(),
+ 'type' => 'string');
+
+$_services['getLinkSummary'] = array(
+ 'args' => _turba_LinkParameters(),
+ 'type' => 'string');
+
+$_services['addLink'] = array(
+ 'link' => '%application%/addlink.php?link_type=|link_type|' .
+ ini_get('arg_separator.output') . 'from_application=|from_application|' .
+ ini_get('arg_separator.output') . 'from_parameters=|from_parameters|' .
+ ini_get('arg_separator.output') . 'url=|url|');
+
+$_services['deleteLink'] = array(
+ 'link' => 'deleteLink.php?' .
+ 'from_application=|from_application|' .
+ ini_get('arg_separator.output') . 'from_parameters=|from_parameters|' .
+ ini_get('arg_separator.output') . 'to_application=|to_application|' .
+ ini_get('arg_separator.output') . 'to_parameters=|to_parameters|' .
+ ini_get('arg_separator.output') . 'type=|type|' .
+ ini_get('arg_separator.output') . 'return_url=|url|');
+
function _turba_block($type, $params)
{
@define('TURBA_BASE', dirname(__FILE__) . '/..');
@@ -176,7 +214,7 @@
$attributes[$key]['type'] == 'email' &&
empty($seen[$name][trim(String::lower($att['name'])) . trim(String::lower($value))])) {
- $results[$name][] = array('name' => $att['name'], 'email' => $value, '__type' => 'Contact');
+ $results[$name][] = array('name' => $att['name'], 'email' => $value, '__type' => 'Contact', 'id' => $att['__key'], 'source' => $source);
$seen[$name][trim(String::lower($att['name'])) . trim(String::lower($value))] = true;
}
}
@@ -196,7 +234,7 @@
$email = $value;
}
}
- $results[$name][] = array('name' => $listatt['name'] . ' - ' . $att['name'], 'email' => $email);
+ $results[$name][] = array('name' => $listatt['name'] . ' - ' . $att['name'], 'email' => $email, 'id' => $att['__key'], 'source' => $source );
} else {
$email = '';
while ($ob = $members->next()) {
@@ -212,7 +250,7 @@
}
}
}
- $results[$name][] = array('name' => $listatt['name'], 'email' => $email);
+ $results[$name][] = array('name' => $listatt['name'], 'email' => $email, 'id' => $listatt['__key'], 'source' => $source);
}
}
}
@@ -401,6 +439,52 @@
return $result;
}
+function _turba_getFieldByLinkParameters($source, $id, $field) {
+ require_once dirname(__FILE__) . '/base.php';
+ include TURBA_BASE . '/config/attributes.php';
+ require_once TURBA_BASE . '/lib/Source.php';
+ global $cfgSources;
+
+ if (empty($id)) {
+ return PEAR::raiseError(_("Empty key"), 'horde.error');
+ }
+
+ if (empty($source)) {
+ return PEAR::raiseError(_("Empty source"), 'horde.error');
+ }
+
+ if (!isset($cfgSources[$source])) {
+ return PEAR::raiseError(_("Unknown source"), 'horde.error');
+ }
+
+ $count = 0;
+ $driver = &Turba_Source::singleton($source, $cfgSources[$source]);
+ if (PEAR::isError($driver)) {
+ return PEAR::raiseError(_("Failed to connect to the specified directory."), 'horde.error', null, null, $source);
+ } else {
+ $res = $driver->search(array('__key' => $id));
+ if (get_class($res) == 'turba_list') {
+ $count += $res->count();
+ if ($res->count() == 1) {
+ $ob = $res->next();
+ if ($ob->hasValue($field)) {
+ $result = $ob->getValue($field);
+ }
+ }
+ } else {
+ return PEAR::raiseError(_("Failed to search the specified directory."), 'horde.error', null, null, $source);
+ }
+ }
+
+ if ($count > 1) {
+ return PEAR::raiseError(_("More than 1 entry returned."), 'horde.warning', null, null, $source);
+ } elseif (!isset($result)) {
+ return PEAR::raiseError(sprintf(_("No %s entry found for %s."), $field, $id), 'horde.warning', null, null, $source);
+ }
+
+ return $result;
+}
+
function _turba_listField($field = '', $addressbooks = array())
{
require_once dirname(__FILE__) . '/base.php';
@@ -486,4 +570,22 @@
}
return;
+}
+
+function _turba_getLinkDescription($source, $id)
+{
+ $t = _turba_getFieldByLinkParameters($source, $id, $field = 'name');
+
+ return $t;
+}
+
+function _turba_getLinkSummary($source, $id)
+{
+ $t = _turba_getFieldByLinkParameters($source, $id, $field = 'name');
+
+ if (!PEAR::isError($t)) {
+ return $t;
+ } else {
+ return _("Contact not found.");
+ }
}
Index: turba/lib/base.php
===================================================================
RCS file: /repository/turba/lib/base.php,v
retrieving revision 1.40
diff -u -r1.40 base.php
--- turba/lib/base.php 22 Feb 2003 01:22:12 -0000 1.40
+++ turba/lib/base.php 27 Feb 2003 21:26:18 -0000
@@ -53,6 +53,10 @@
$notification = &Notification::singleton();
$notification->attach('status');
+// Links
+require_once HORDE_BASE . '/lib/Links.php';
+$links = &Horde_Links::singleton($registry->getApp());
+
// Don't allow access unless there is a Horde login, or guests are
// allowed.
if (!(Auth::getAuth() || $registry->allowGuests())) {
Index: config/registry.php.dist
===================================================================
RCS file: /repository/horde/config/registry.php.dist,v
retrieving revision 1.146
diff -u -r1.146 registry.php.dist
--- config/registry.php.dist 26 Feb 2003 17:37:30 -0000 1.146
+++ config/registry.php.dist 27 Feb 2003 21:33:36 -0000
@@ -195,6 +195,15 @@
'provider' => 'comics',
'description' => _("Funny note"),
),
+ 'client' => array(
+ 'provider' => 'contacts',
+ 'description' => _("Client"),
+ 'reverse' => array(
+ 'description' => _("Task"),
+ 'type' => 'task',
+ 'readonly' => false,
+ ),
+ ),
),
'menu_parent' => 'pim'
);
links2.zip
(application/x-zip-compressed, 3.9 KB) - not displayed