? 182069_comment_service.patch
? cache_clear.patch
? services/comment_service.module
Index: services/comment_service.inc
===================================================================
RCS file: services/comment_service.inc
diff -N services/comment_service.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ services/comment_service.inc	8 Mar 2009 02:27:31 -0000
@@ -0,0 +1,106 @@
+<?php
+// $Id$
+/**
+ * @author Services Dev Team
+ * @file
+ *  Link commenting functionality to services module.
+ */
+
+/**
+ * Adds a new comment to a node and returns the cid.
+ *
+ * If a cid is specified in $comment->cid then that comment is edited.
+ *
+ * @param $comment
+ *   An array matching the form values that would be submitted in the comment 
+ *   edit form.
+ * @return
+ *   Unique identifier for the comment (cid) or FALSE if there was a problem.
+ */
+function comment_service_save($comment) {
+  global $user;
+
+  // If a cid is present then the user is trying to edit an existing comment.
+  if (isset($comment['cid']) && ($comment['cid'] != 0)) {
+    $initial_comment = _comment_load($comment['cid']);
+    $admin = user_access("administer comments");
+
+    if ($initial_comment->uid == 0 && !$admin) {
+      return services_error(t("Anonymous comments can't be edited"));
+    }
+
+    if (($initial_comment->uid != $user->uid || comment_num_replies($comment->cid) != 0) && !$admin) {
+      return services_error(t("User does not have permission to edit this comment"));
+    }
+  }
+
+  $comment['uid'] = $user->uid;
+  $comment['name'] = $user->name;
+  $comment['timestamp'] = time();
+
+  return comment_save($comment);
+}
+
+/**
+ * Returns the comments of a specified node.
+ *
+ * @param $nid
+ *   Unique identifier for the node.
+ * @param $count
+ *   Number of comments to return.
+ * @param $start
+ *   Which comment to start with. if present, $start and $count are used together
+ *   to create a LIMIT clause for selecting comments. This could be used to do paging.
+ * @return
+ *   An array of comment objects.
+ */
+function comment_service_load_node_comments($nid, $count = 0, $start = 0, $fields = array()) {
+  $comments = array();
+  $limit = ((int)$count > 0 ? ' LIMIT '. (int)$start .', '. (int)$count .' ' : '');
+
+  $result = db_query("SELECT cid FROM {comments} WHERE nid = %d ORDER BY thread DESC". $limit, $nid);
+  while ($comment = db_fetch_array($result)) {
+    $comments[] = _comment_load($comment['cid']);
+  }
+
+  return $comments;
+}
+
+/**
+ * Returns a specified comment
+ *
+ * @param $cid
+ *   Unique identifier for the specified comment
+ * @return
+ *   The comment object 
+ */
+function comment_service_load($cid) {
+  $cid = db_result(db_query("SELECT cid FROM {comments} WHERE cid = %d", $cid));
+  return _comment_load($cid);
+}
+
+/**
+ * Returns the number of comments on a given node id.
+ *
+ * @param $nid
+ *   Unique identifier for the specified node.
+ * @return
+ *   Number of comments that node has.
+ */
+function comment_service_node_comments_count_all($nid) {
+  return comment_num_all($nid);
+}
+
+/**
+ * Returns the number of new comments on a given node id since timestamp.
+ *
+ * @param $nid
+ *   Unique identifier for the specified node.
+ * @param $since
+ *   Timestamp to indicate what nodes are new. Defaults to time of last user acces to node.
+ * @return
+ *   Number of comments that node has.
+ */
+function comment_service_node_comments_count_new($nid, $since = 0) {
+  return comment_num_new($nid, $timestamp);
+}
Index: services/comment_service.info
===================================================================
RCS file: services/comment_service.info
diff -N services/comment_service.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ services/comment_service.info	8 Mar 2009 02:27:31 -0000
@@ -0,0 +1,7 @@
+; $Id$
+name = Comment Service
+description = Provides a comment service.
+package = Services - services
+dependencies[] = services
+dependencies[] = comment
+core = 6.x
