[geeklog-cvs] geeklog: Implemented PLG_getItemInfo for the Static Pages plugin

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


details:   http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/b8bacdfde384
changeset: 6570:b8bacdfde384
user:      Dirk Haun <dirk at haun-online.de>
date:      Sat Dec 20 16:30:35 2008 +0100
description:
Implemented PLG_getItemInfo for the Static Pages plugin

diffstat:

1 file changed, 141 insertions(+), 2 deletions(-)
plugins/staticpages/functions.inc |  143 ++++++++++++++++++++++++++++++++++++-

diffs (155 lines):

diff -r 0d0c4bff08d5 -r b8bacdfde384 plugins/staticpages/functions.inc
--- a/plugins/staticpages/functions.inc	Sat Dec 20 15:41:14 2008 +0100
+++ b/plugins/staticpages/functions.inc	Sat Dec 20 16:30:35 2008 +0100
@@ -1213,10 +1213,149 @@
 /**
  * Return true since this plugin supports webservices
  *
- * @return  bool	True, of webservices are supported
+ * @return  bool	True, if webservices are supported
  */
-function plugin_wsEnabled_staticpages() {
+function plugin_wsEnabled_staticpages()
+{
     return true;
 }
 
+/**
+* Return information for a static page
+*
+* @param    string  $sp_id      static page 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_staticpages($sp_id, $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(sp_date) AS unixdate';
+            break;
+        case 'description':
+        case 'excerpt':
+            $fields[] = 'sp_content';
+            $fields[] = 'sp_php';
+            break;
+        case 'id':
+            $fields[] = 'sp_id';
+            break;
+        case 'title':
+            $fields[] = 'sp_title';
+            break;
+        case 'url':
+            if ($sp_id == '*') {
+                // in this case, we need the sp_id to build the URL
+                $fields[] = 'sp_id';
+            }
+            break;
+        default:
+            // nothing to do
+            break;
+        }
+    }
+
+    $fields = array_unique($fields);
+
+    if (count($fields) == 0) {
+        $retval = array();
+
+        return $retval;
+    }
+
+    // prepare SQL request
+    if ($sp_id == '*') {
+        $where = '';
+        $permOp = 'WHERE';
+    } else {
+        $where = " WHERE sp_id = '$sp_id'";
+        $permOp = 'AND';
+    }
+    if ($uid > 0) {
+        $permSql = COM_getPermSql($permOp, $uid);
+    } else {
+        $permSql = COM_getPermSql($permOp);
+    }
+    $sql = "SELECT " . implode(',', $fields)
+            . " FROM {$_TABLES['staticpage']}" . $where . $permSql;
+    if ($sp_id != '*') {
+        $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] = SP_render_content(stripslashes($A['sp_content']),
+                                                            $A['sp_php']);
+                break;
+            case 'id':
+                $props['id'] = $A['sp_id'];
+                break;
+            case 'title':
+                $props['title'] = stripslashes($A['sp_title']);
+                break;
+            case 'url':
+                if (empty($A['sp_id'])) {
+                    $props['url'] = COM_buildUrl($_CONF['site_url']
+                            . '/staticpages/index.php?page=' . $sp_id);
+                } else {
+                    $props['url'] = COM_buildUrl($_CONF['site_url']
+                            . '/staticpages/index.php?page=' . $A['sp_id']);
+                }
+                break;
+            default:
+                // return empty string for unknown properties
+                $props[$p] = '';
+                break;
+            }
+        }
+
+        $mapped = array();
+        foreach ($props as $key => $value) {
+            if ($sp_id == '*') {
+                if ($value != '') {
+                    $mapped[$key] = $value;
+                }
+            } else {
+                $mapped[] = $value;
+            }
+        }
+
+        if ($sp_id == '*') {
+            $retval[] = $mapped;
+        } else {
+            $retval = $mapped;
+            break;
+        }
+    }
+
+    if (($sp_id != '*') && (count($retval) == 1)) {
+        $retval = $retval[0];
+    }
+
+    return $retval;
+}
+
 ?>



More information about the geeklog-cvs mailing list