'); } elseif(arg(0) == 'blog') { drupal_set_html_head(''); } else { drupal_set_html_head(''); } if ($may_cache) { $items[] = array('path' => 'gdata/feed', 'title' => t('gdata feed'), 'callback' => 'gdata_feed', 'access' => user_access('access content'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'blog/gdata/feed', 'title' => t('gdata blog feed'), 'callback' => 'gdata_blog_feed', 'access' => user_access('access content'), 'type' => MENU_CALLBACK); } if (is_numeric(arg(1))) { $items[] = array('path' => 'blog/'. arg(1) .'/gdata/feed', 'title' => t('gdata blog feed'), 'callback' => 'gdata_user_blog_feed', 'access' => user_access('access content'), 'type' => MENU_CALLBACK); } return $items; } /** * Produces an gdata (atom 1.0) feed for the front page content. */ function gdata_feed() { if(strpos(arg(2), 'gdata') === 0 || strpos(arg(2), 'feed') === 0) { die(drupal_not_found()); } global $base_url; $nodes = db_query_range("SELECT n.nid FROM {node} n WHERE n.promote = '1' AND n.status = '1' ORDER BY n.created DESC", 0, variable_get('atom_feed_entries', 15)); $feed_info = array(); $feed_info['title'] = strip_tags(variable_get('site_name', 'Drupal')); $feed_info['subtitle'] = strip_tags(variable_get('site_slogan', '')); $feed_info['html_url'] = $base_url; $feed_info['gdata_url'] = url('gdata/feed', NULL, NULL, true); _gdata_print_feed($nodes, $feed_info); } function gdata_blog_feed() { if(strpos(arg(3), 'gdata') === 0 || strpos(arg(3), 'feed') === 0) { die(drupal_not_found()); } $nodes = db_query_range("SELECT n.nid FROM {node} n WHERE n.type = 'blog' AND n.status = '1' ORDER BY n.created DESC", 0, variable_get('atom_feed_entries', 15)); $feed_info = array(); $feed_info['title'] = strip_tags(sprintf(t('%s blogs'), variable_get('site_name', 'Drupal'))); $feed_info['subtitle'] = strip_tags(variable_get('site_slogan', '')); $feed_info['html_url'] = url('blog', NULL, NULL, true); $feed_info['gdata_url'] = url('blog/gdata/feed', NULL, NULL, true); _gdata_print_feed($nodes, $feed_info); } function gdata_user_blog_feed() { if(strpos(arg(4), 'gdata') === 0 || strpos(arg(4), 'feed') === 0) { die(drupal_not_found()); } $user_result = db_query_range("SELECT u.name FROM {users} u WHERE u.uid = %d", arg(1), 0, 1); if(!$user = db_result($user_result)) { return drupal_not_found(); } $nodes = db_query_range("SELECT n.nid FROM {node} n WHERE n.type = 'blog' AND n.uid = %d AND n.status = '1' ORDER BY n.created DESC", arg(1), 0, variable_get('atom_feed_entries', 15)); $feed_info = array(); $feed_info['title'] = sprintf(t("%s's blog"), $user); $feed_info['html_url'] = url('blog/'. arg(1), NULL, NULL, true); $feed_info['gdata_url'] = url('blog/'. arg(1) .'/gdata/feed', NULL, NULL, true); _gdata_print_feed($nodes, $feed_info); } /** * prints feed information from query of either front page or blog content * * @param object $nodes query result * @param array feed information */ function _gdata_print_feed($nodes, $feed_info) { $output = ''; $last_mod = 0; while ($node = db_fetch_object($nodes)) { $item = node_load(array('nid' => $node->nid)); $link = url("node/$node->nid", NULL, NULL, true); if (node_hook($item, 'view')) { node_invoke($item, 'view', TRUE, FALSE); } else { $item = node_prepare($item, TRUE); } // Allow modules to change $node->teaser before viewing. node_invoke_nodeapi($item, 'view', true, false); $output .= " \n"; $output .= ' '. check_plain(strip_tags($item->title)) ."\n"; $output .= ' '. "\n"; $output .= ' '. $link ."\n"; $output .= ' '. _gdata_timestamp2w3dtf($item->created) ."\n"; $output .= ' '. _gdata_timestamp2w3dtf($item->changed) ."\n"; $last_mod = $item->changed; $output .= " \n"; if ($item->name) { $output .= ' '. $item->name ."\n"; } else { $output .= ' '. variable_get('anonymous', 'Anonymous') ."\n"; } $output .= " \n"; if (module_exist('taxonomy')) { $terms = taxonomy_node_get_terms($item->nid); foreach ($terms as $term) { $output .= ' '. "\n"; } } // Summary $output .= ' teaser); $output .= " ]]>\n"; // Body $output .= ' nid, variable_get('atom_ad_code', ''))) : ''; $output .= check_output($item->body); $output .= variable_get('atom_ad_location', 'off') == 'append' ? str_replace('%link', urlencode($link), str_replace('%id', $node->nid, variable_get('atom_ad_code', ''))) : ''; $output .= " ]]>\n"; $output .= " \n"; } drupal_set_header('Content-Type: application/xml'); print ''. "\n"; print ''. "\n"; print ' '. $feed_info['title'] ."\n"; print $feed_info['subtitle'] == '' ? '' : ' '. $feed_info['subtitle'] . "\n"; print ' '. "\n"; print ' '. "\n"; print ' '. $feed_info['gdata_url'] ."\n"; print ' '. _gdata_timestamp2w3dtf($last_mod) ."\n"; print $output; print "\n"; } /** * @return string */ function _gdata_timestamp2w3dtf($timestamp) { $tz = date("O", $timestamp); return date("Y-m-d", $timestamp) .'T'. date("H:i:s", $timestamp) . substr($tz, 0, 3) . ':' . substr($tz, 3, 2); } /** * Module configuration settings * * @return string of settings HTML or deny access */ function gdata_settings() { if (!user_access('administer gdata')) { die(drupal_access_denied()); } //$result = db_query('SELECT * FROM {gdata}'); $options = array('read','write','update','delete','search'); $modules_array = module_implements('gdata'); foreach ($modules_array as $module) { $module_details = module_invoke($module, 'gdata', 'info'); $form[$module] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Module ').$module, '#description' => $module_details['help'], ); $form[$module]['implements'] = array( '#type' => 'checkboxes', '#title' => t('What the module implements'), '#options' => $module_details['implements'], '#description' => t('You can set if this module should enable syndicatation, write, update, delete, etc.'), ); $form[$module]['path'] = array( '#type' => 'textfield', '#title' => t('The path for this module under /gfeed/'), '#default-value' => $module_details['path'], '#description' => t('If you set this is as "blog" for example then external user will be able to access blog module through GData at http://yoursite.com/gfeed/blog'), ); } } function gdata_gdata($op) { switch ($op) { case 'read': break; case 'write': break; case 'update': break; case 'delete': break; case 'search': break; /* * Return an array cantaining three elements 'implements', 'path', 'help': * 'implements' :: this is an array of the terms : * 'read', 'write', 'update', 'delete', 'search', in any order. Each * term signifies that, your module implements the feature. The * absence of any term means that feature is not implemented. * * 'path' :: this is the path under /gfeed/ that you want to handle. * Do NOT register this path with the normal node_menu( ) hook. * Also the administrator may change the path. All that is handled by * gdata module. If this is null then the name of module is used. * * 'help' :: this is a string which explains what your module does (incase * the administrator has forgotten it or is confused :) ) */ case 'info': $array = array( 'implements' => array('read','write'), 'path' => 'gdata_test', 'help' => t('This is just a testing of GData hook'), ); break; } return $array; }