[geeklog-cvs] geeklog: Implemented PLG_getItemInfo for the Calendar plugin
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Mon Dec 22 05:51:33 EST 2008
details: http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/b54a1c596ed1
changeset: 6571:b54a1c596ed1
user: Dirk Haun <dirk at haun-online.de>
date: Sat Dec 20 19:39:16 2008 +0100
description:
Implemented PLG_getItemInfo for the Calendar plugin
diffstat:
1 file changed, 131 insertions(+)
plugins/calendar/functions.inc | 131 ++++++++++++++++++++++++++++++++++++++++
diffs (139 lines):
diff -r b8bacdfde384 -r b54a1c596ed1 plugins/calendar/functions.inc
--- a/plugins/calendar/functions.inc Sat Dec 20 16:30:35 2008 +0100
+++ b/plugins/calendar/functions.inc Sat Dec 20 19:39:16 2008 +0100
@@ -1810,4 +1810,135 @@
return $retval;
}
+/**
+* Return information for an event
+*
+* @param string $eid event ID or '*'
+* @param string $what comma-separated list of properties
+* @param int $uid if > 0: only return items accessible by user
+* @param array $options (reserved for future extensions)
+* @return mixed string or array of strings with the information
+*
+*/
+function plugin_getiteminfo_calendar($eid, $what, $uid = 0, $options = array())
+{
+ global $_CONF, $_TABLES;
+
+ // parse $what to see what we need to pull from the database
+ $properties = explode(',', $what);
+ $fields = array();
+ foreach ($properties as $p) {
+ switch ($p) {
+ // no date! we don't keep track of the _item's_ create/modify dates!
+ case 'description':
+ case 'excerpt':
+ $fields[] = 'description';
+ break;
+ case 'id':
+ $fields[] = 'eid';
+ break;
+ case 'title':
+ $fields[] = 'title';
+ break;
+ case 'url':
+ if ($eid == '*') {
+ // in this case, we need the eid to build the URL
+ $fields[] = 'eid';
+ }
+ break;
+ default:
+ // nothing to do
+ break;
+ }
+ }
+
+ $fields = array_unique($fields);
+
+ if (count($fields) == 0) {
+ $retval = array();
+
+ return $retval;
+ }
+
+ // prepare SQL request
+ if ($eid == '*') {
+ $where = '';
+ $permOp = 'WHERE';
+ } else {
+ $where = " WHERE eid = '$eid'";
+ $permOp = 'AND';
+ }
+ if ($uid > 0) {
+ $permSql = COM_getPermSql($permOp, $uid);
+ } else {
+ $permSql = COM_getPermSql($permOp);
+ }
+ $sql = "SELECT " . implode(',', $fields)
+ . " FROM {$_TABLES['events']}" . $where . $permSql;
+ if ($eid != '*') {
+ $sql .= ' LIMIT 1';
+ }
+
+ $result = DB_query($sql);
+ $numRows = DB_numRows($result);
+
+ $retval = array();
+ for ($i = 0; $i < $numRows; $i++) {
+ $A = DB_fetchArray($result);
+
+ $props = array();
+ foreach ($properties as $p) {
+ switch ($p) {
+ case 'description':
+ case 'excerpt':
+ $props[$p] = $A['description'];
+ break;
+ case 'id':
+ $props['id'] = $A['eid'];
+ break;
+ case 'title':
+ $props['title'] = stripslashes($A['title']);
+ break;
+ case 'url':
+ if (empty($A['eid'])) {
+ $props['url'] = $_CONF['site_url'] . '/calendar/event.php?'
+ . 'eid=' . $eid;
+ } else {
+ $props['url'] = $_CONF['site_url'] . '/calendar/event.php?'
+ . 'eid=' . $A['eid'];
+ }
+ break;
+ default:
+ // return empty string for unknown properties
+ $props[$p] = '';
+ break;
+ }
+ }
+
+ $mapped = array();
+ foreach ($props as $key => $value) {
+ if ($eid == '*') {
+ if ($value != '') {
+ $mapped[$key] = $value;
+ }
+ } else {
+ $mapped[] = $value;
+ }
+ }
+
+ if ($eid == '*') {
+ $retval[] = $mapped;
+ } else {
+ $retval = $mapped;
+ break;
+ }
+ }
+
+ if (($eid != '*') && (count($retval) == 1)) {
+ $retval = $retval[0];
+ }
+
+ return $retval;
+}
+
?>
More information about the geeklog-cvs
mailing list