[geeklog-cvs] geeklog: Implemented PLG_getItemInfo for the Links plugin

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Mon Dec 22 05:51:34 EST 2008


details:   http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/67a914873db2
changeset: 6572:67a914873db2
user:      Dirk Haun <dirk at haun-online.de>
date:      Sun Dec 21 09:27:23 2008 +0100
description:
Implemented PLG_getItemInfo for the Links plugin

diffstat:

1 file changed, 137 insertions(+)
plugins/links/functions.inc |  137 +++++++++++++++++++++++++++++++++++++++++++

diffs (145 lines):

diff -r b54a1c596ed1 -r 67a914873db2 plugins/links/functions.inc
--- a/plugins/links/functions.inc	Sat Dec 20 19:39:16 2008 +0100
+++ b/plugins/links/functions.inc	Sun Dec 21 09:27:23 2008 +0100
@@ -1442,4 +1442,141 @@
     return $retval;
 }
 
+/**
+* Return information for a link
+*
+* @param    string  $lid        link 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_links($lid, $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) {
+        case 'date-modified':
+            $fields[] = 'UNIX_TIMESTAMP(date) AS unixdate';
+            break;
+        case 'description':
+        case 'excerpt':
+            $fields[] = 'description';
+            break;
+        case 'id':
+            $fields[] = 'lid';
+            break;
+        case 'title':
+            $fields[] = 'title';
+            break;
+        case 'url':
+            if ($lid == '*') {
+                // in this case, we need the lid to build the URL
+                $fields[] = 'lid';
+            }
+            break;
+        default:
+            // nothing to do
+            break;
+        }
+    }
+
+    $fields = array_unique($fields);
+
+    if (count($fields) == 0) {
+        $retval = array();
+
+        return $retval;
+    }
+
+    // prepare SQL request
+    if ($lid == '*') {
+        $where = '';
+        $permOp = 'WHERE';
+    } else {
+        $where = " WHERE lid = '$lid'";
+        $permOp = 'AND';
+    }
+    if ($uid > 0) {
+        $permSql = COM_getPermSql($permOp, $uid);
+    } else {
+        $permSql = COM_getPermSql($permOp);
+    }
+    $sql = "SELECT " . implode(',', $fields)
+            . " FROM {$_TABLES['links']}" . $where . $permSql;
+    if ($lid != '*') {
+        $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 'date-modified':
+                $props['date-modified'] = $A['unixdate'];
+                break;
+            case 'description':
+            case 'excerpt':
+                $props[$p] = stripslashes($A['description']);
+                break;
+            case 'id':
+                $props['id'] = $A['lid'];
+                break;
+            case 'title':
+                $props['title'] = stripslashes($A['title']);
+                break;
+            case 'url':
+                if (empty($A['lid'])) {
+                    $props['url'] = COM_buildUrl($_CONF['site_url']
+                            . '/links/portal.php?what=link&item=' . $lid);
+                } else {
+                    $props['url'] = COM_buildUrl($_CONF['site_url']
+                            . '/links/portal.php?what=link&item='
+                            . $A['lid']);
+                }
+                break;
+            default:
+                // return empty string for unknown properties
+                $props[$p] = '';
+                break;
+            }
+        }
+
+        $mapped = array();
+        foreach ($props as $key => $value) {
+            if ($lid == '*') {
+                if ($value != '') {
+                    $mapped[$key] = $value;
+                }
+            } else {
+                $mapped[] = $value;
+            }
+        }
+
+        if ($lid == '*') {
+            $retval[] = $mapped;
+        } else {
+            $retval = $mapped;
+            break;
+        }
+    }
+
+    if (($lid != '*') && (count($retval) == 1)) {
+        $retval = $retval[0];
+    }
+
+    return $retval;
+}
+
 ?>



More information about the geeklog-cvs mailing list