/[drupal]/contributions/modules/tribune/tribune.json.inc
ViewVC logotype

Contents of /contributions/modules/tribune/tribune.json.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (show annotations) (download) (as text)
Fri Nov 28 12:59:32 2008 UTC (11 months, 4 weeks ago) by seeschloss
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +2 -2 lines
File MIME type: text/x-php
removed many old variable_gets
1 <?php
2 // vim:filetype=php expandtab tabstop=2 softtabstop=2 shiftwidth=2 autoindent smartindent
3 // $Id: tribune.json.inc,v 1.7 2008/11/28 10:22:53 seeschloss Exp $
4
5 /**
6 * Prints one post in JSON format, does not print moderated posts
7 */
8 function tribune_print_json_post($id, $node) {
9 if ($id and $post = tribune_get_post($node, $id) and !$post['moderated']) {
10 $user = user_load_self(array());
11 $login = $user[1]->name;
12 $self = ($post['login'] && $post['login'] == $login);
13
14 print tribune_get_json_post($post, $self);
15 }
16 exit();
17 }
18
19 /**
20 * Prints the new posts since $last_time in JSON format
21 * @params $last_id The post ID from which to display posts (exclusively)
22 */
23 function tribune_print_json_newposts($last_time, $node) {
24 $posts = tribune_get_new_posts($node, $last_time);
25
26 $user = user_load_self(array());
27 $login = $user[1]->name;
28
29 $contents = "{ 'time': ". time() .",\n".
30 " 'help': [\n";
31 if (is_array($_SESSION['tribune_filters_help'])) foreach ($_SESSION['tribune_filters_help'] as $filter_name => $filter_help) {
32 if ($filter_help['changed']) {
33 $contents .= "{ 'filter': \"". str_replace(array("\\", "\n", "\""), array("\\\\", " ", "\\\""), $filter_name) ."\",\n".
34 " 'string': \"". str_replace(array("\\", "\n", "\""), array("\\\\", " ", "\\\""), t($filter_help['string'])) ."\"},\n";
35 $_SESSION['tribune_filters_help'][$filter_name]['changed'] = FALSE;
36 }
37 }
38 $contents .= "\n],".
39 " 'posts': [\n";
40
41 if (sizeof($posts) > 0) foreach ($posts as $post) {
42 $self = ($post['login'] && $post['login'] == $login);
43
44 $contents .= tribune_get_json_post($post, $node, $self) .",";
45
46 $_tribune_current_post_id = -1;
47 }
48
49 $contents .= "\n]}";
50
51 print $contents;
52 exit();
53 }
54
55 /**
56 * Returns a JSON string with the contents of a post
57 */
58 function tribune_get_json_post($post, $node, $self = FALSE) {
59 $contents = "";
60
61 $class = 'tribune-post';
62
63 if ($self) {
64 $class .= ' tribune-self-post';
65 }
66
67 if ($post['moderated'] and !tribune_access("moderate tribune", $node)) {
68 $contents .= "{ 'moderated': ". $post['moderated'] .",\n".
69 " 'id': ". $post['post_id'] ." }\n";
70 }
71 else {
72 $contents .= "{ 'text': \"". str_replace(array("\\", "\n", "\""), array("\\\\", " ", "\\\""), theme('tribune_post', $post, $node)) ."\",\n".
73 " 'classes': \"". $class ."\",\n".
74 " 'ref': \"". tribune_post_title($post['referenced_by']) ."\",\n".
75 " 'login': \"". $post['login'] ."\",\n".
76 " 'moderated': ". $post['moderated'] .",\n".
77 " 'id': ". $post['post_id'] ." }\n";
78 }
79
80 return $contents;
81 }
82

  ViewVC Help
Powered by ViewVC 1.1.2