/[drupal]/contributions/sandbox/developmentseed/asyncapi/asyncapi.module
ViewVC logotype

Contents of /contributions/sandbox/developmentseed/asyncapi/asyncapi.module

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


Revision 1.4 - (show annotations) (download) (as text)
Fri Dec 8 15:23:36 2006 UTC (2 years, 11 months ago) by alexb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +0 -0 lines
File MIME type: text/x-php
adding new version of leech to sandbox, soon to be moved over to contrib -a
1 <?php
2 // $Id: asyncapi.module,v 1.1 2006/11/27 17:11:47 alexb Exp $
3
4 /**
5 * Implementation of hook_help().
6 */
7
8 function asyncapi_help($section) {
9 switch ($section) {
10 case 'admin/modules#description':
11 return t('Provides a api to load nodes and blocks asynchronously. Also provides Asynchronous Pagination.');
12 }
13 }
14
15 /**
16 * Implementation of hook_perm().
17 */
18 function asyncapi_perm() {
19 return array('asyncapi read nodeList', 'asyncapi create nodeList');
20 }
21
22
23 /**
24 * Implementation of hook_menu().
25 */
26 function asyncapi_menu($may_cache) {
27 $items = array();
28 if ($may_cache) {
29 $items[] = array(
30 'path' => 'asyncapi',
31 'title' => t('Async Node List'),
32 'access' => user_access('asyncapi read nodeList'),
33 'type' => MENU_NORMAL_ITEM,
34 'callback' => 'asyncapi_page'
35 );
36 $items[] = array(
37 'path' => 'asyncPage',
38 'title' => t('Async Pager'),
39 'access' => user_access('asyncapi read nodeList'),
40 'type' => MENU_NORMAL_ITEM,
41 'callback' => 'asyncapi_pager'
42 );
43 /*$items[] = array(
44 'path' => 'blocks',
45 'title' => t('blocks List'),
46 'access' => user_access('asyncapi read nodeList'),
47 'type' => MENU_NORMAL_ITEM,
48 'callback' => 'asyncapi_blocks'
49 );*/
50 }
51 else {
52 if (arg(0) == 'asyncapi' && arg(1) == 'node' && is_numeric(arg(2))) {
53 $node = node_load(arg(2));
54 if ($node->nid) {
55 $items[] = array('path' => 'asyncapi/node/'. arg(2), 'title' => t('view'),
56 'callback' => 'asyncapi_loadNode',
57 'access' => user_access('asyncapi read nodeList'),
58 'type' => MENU_CALLBACK);
59 }
60 }
61 }
62 return $items;
63 }
64
65 function asyncapi_add_js()
66 {
67 static $core_sent;
68 if (!$core_sent) {
69 $path = drupal_get_path('module', 'asyncapi');
70 drupal_add_js($path . '/js/asyncapi.js');
71 drupal_add_js($path . '/js/minmax.js');
72 drupal_set_html_head(theme_stylesheet_import(base_path() . $path .'/css/firefox.css'));
73 $tmp = '<script type="text/javascript">path = "'.$path.'";</script>';
74 drupal_set_html_head($tmp);
75 $core_sent = 1;
76 }
77 }
78
79 /**
80 * Menu callback. Display UI for loading, editing, and saving forms.
81 */
82 function asyncapi_page() {
83 asyncapi_add_js();
84
85 $output = '';
86 $listlength=50;
87 $result1 = pager_query(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.status = 1 AND n.promote = 1 ORDER BY n.created DESC"), $listlength);
88 while ($node = db_fetch_object($result1)) {
89 //$n = node_load(array('nid' => $node->nid));
90 $output .= '<br />'.theme('asyncapi', $node);
91 //$output .= node_view( $n,1);
92 }
93 //$output .= '<input id="asyncapi_currentLocation" value="" />';
94 return $output;
95 }
96
97
98 /**
99 * Menu callback. Load the requested node and send it.
100 */
101 function asyncapi_loadNode() {
102 drupal_set_header('Content-Type: text/javascript');
103 $ln = node_load(arg(2));
104 $v = array();
105 $v['node_view'] = node_view($ln,arg(3));
106 $ln = array_merge((array)$ln,(array)$v);
107 print drupal_to_js($ln);
108 exit();
109 }
110
111 function theme_asyncapi($node = array()) {
112 asyncapi_add_js();
113 $output = theme('asyncapi_node_placeholder',$node);
114 //Show teaser or not;
115 $t['asyncapi_show_teaser'] = true;
116 $node = array_merge((array)$node,(array)$t);
117 $output .= theme('load_node_button',$node);
118 return $output;
119 };
120
121 function theme_load_node_button($node)
122 {
123 return '<span class="asyncapi_add_button" id="asyncapi_button_'.$node['nid'].'" onclick="asyncapi.load(
124 {
125 \'type\' : \'node\',
126 \'nid\' : '.$node['nid'].',
127 \'refresh\' : false,
128 \'toggle\' : true,
129 \'teaser\' : '.(($node['asyncapi_show_teaser'] == true)? 1:0).',
130 \'callback\' : asyncapi.showLoadedNode,
131 \'showbuttontext\' : \'Show Item\',
132 \'hidebuttontext\' : \'Hide Item\'
133 })
134 "> Show Item</span></p>';
135 }
136
137 function theme_asyncapi_node_placeholder($node)
138 {
139 $path = drupal_get_path('module', 'asyncapi');
140 $output = '<div class="node"><h2 class="title" id="asyncapi_title_'.$node->nid.'" ><a href="'.(variable_get('clean_url', '0') ? '' : '?q=').'node/'.$node->nid.'" >' . $node->title . '</a></h2></div>';
141 $output .= '<div id="asyncapi_content_'.$node->nid.'" class="asyncapi_content" > <img src="/'.$path.'/images/loading.gif" height=20 width=20 /> Loading...</div>';
142 return $output;
143 }
144
145 function asyncapi_blocks()
146 {
147 global $theme_key;
148 init_theme();
149 $block_regions = system_region_list($theme_key);
150 $blks = array();
151
152 foreach ($block_regions as $reg=>$value) {
153 $blks[] = block_list($reg);
154 }
155
156 return var_export($blks,true);
157 }
158
159 function asyncapi_pager()
160 {
161 global $pager_total;
162 asyncapi_add_js();
163 $result = pager_query(db_rewrite_sql('SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), variable_get('default_nodes_main', 5));
164
165 if (db_num_rows($result)) {
166 drupal_add_link(array('rel' => 'alternate',
167 'type' => 'application/rss+xml',
168 'title' => t('RSS'),
169 'href' => url('rss.xml', NULL, NULL, TRUE)));
170
171 $temp = '';
172 while ($node = db_fetch_object($result)) {
173 $temp .= node_view(node_load($node->nid), 1);
174 }
175 if($_GET['page'])
176 {
177 if($pager_total[0] - 1 == $_GET['page'])
178 $output['last'] = true;
179 $output['content'] = '<div class="asyncapi_page" id="asyncapi_page_'.$_GET['page'].'">'.$temp.'</div>';
180 $output['page'] = $_GET['page'];
181 print drupal_to_js($output);
182 exit();
183 }
184 $output = '<div id="asyncapi_pager_content"><div class="asyncapi_page">'.$temp .'</div></div>';
185 $output .= theme('asyncapi_pager');
186 $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
187 }
188 return $output;
189 }
190
191
192 function theme_asyncapi_pager()
193 {
194 return '<div class="asyncapi_load_page_button" onclick="asyncapi.load(
195 {
196 \'type\' : \'page\',
197 \'callback\' : asyncapi.showPage
198 })
199 ">Load next few nodes...</div>';
200 }
201
202 function asyncapi_views_tables()
203 {
204
205 $tables['abcs'] = array(
206 'name' => 'node',
207 'fields' => array(
208 'asyncNodeButton' => array(
209 'name' => t('Async node Button'),
210 'handler' => array(
211 'views_handler_field_async_node_button_teaser' => t('Load Teaser'),
212 'views_handler_field_async_node_button' => t('Load Full Node')
213 ),
214 'notafield' => true,
215 ),
216 'asyncNodeContentPlaceholder' => array(
217 'name' => t('Async node Content Placeholder'),
218 'handler' => 'views_handler_field_async_node_content_placeholder',
219 'notafield' => true,
220 ),
221 ),
222 );
223 return $tables;
224 }
225
226 function views_handler_field_async_node_button($fieldinfo, $fielddata, $value, $data)
227 {
228 $output = '';
229 asyncapi_add_js();
230 $t['asyncapi_show_teaser'] = false;
231 $data = array_merge((array)$data,(array)$t);
232 $output .= theme('load_node_button',$data);
233 return $output;
234 }
235
236 function views_handler_field_async_node_button_teaser($fieldinfo, $fielddata, $value, $data)
237 {
238 $output = '';
239 asyncapi_add_js();
240 $t['asyncapi_show_teaser'] = true;
241 $data = array_merge((array)$data,(array)$t);
242 $output .= theme('load_node_button',$data);
243 return $output;
244 }
245
246 function views_handler_field_async_node_content_placeholder($fieldinfo, $fielddata, $value, $data)
247 {
248 $output ='';
249 $path = drupal_get_path('module', 'asyncapi');
250 $output .= theme('asyncapi_node_placeholder',$data);
251 return $output;
252 }
253
254 function asyncapi_views_arguments() {
255 $arguments = array( );
256 return $arguments;
257 }
258
259
260 function asyncapi_views_default_views() {
261 }
262

  ViewVC Help
Powered by ViewVC 1.1.2