All pastes #83002 Raw Edit

brainless

public php v1 · immutable
·published 2006-07-09 06:23 UTC
rendered paste body
<?php/** * Implementation of hook_help * * @return string */function gdata_help($section) {  $output = '';  switch ($section) {    case 'admin/modules#description':      $output = t('Provides GData feed');      break;    case 'admin/settings/gdata':      if (user_access('administer gdata')) {        $output = t('GData Admin');      }      break;    case 'admin/help#gdata':      $output = t('This module provides GData feed... more help will come here');      break;  }  return $output;}/** * Valid permissions for the gdata module * * @return array An array of valid permissions for the gdata module */function gdata_perm() {  return array('administer gdata', 'insert with gdata', 'delete with gdata');}/** * Implementation of hook_menu * * @return array */function gdata_menu($may_cache) {  $items = array();  if(arg(0) == 'blog' && is_numeric(arg(1))) {    drupal_set_html_head('<link rel="alternate" type="application/atom+xml" title="GData" href="'. url('blog/'. arg(1) .'/gdata/feed', NULL, NULL, TRUE) .'" />');  }  elseif(arg(0) == 'blog') {    drupal_set_html_head('<link rel="alternate" type="application/atom+xml" title="GData" href="'. url('blog/gdata/feed', NULL, NULL, TRUE) .'" />');  }  else {    drupal_set_html_head('<link rel="alternate" type="application/atom+xml" title="GData" href="'. url('gdata/feed', NULL, NULL, TRUE) .'" />');  }  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 .= "  <entry>\n";    $output .= '    <title>'. check_plain(strip_tags($item->title)) ."</title>\n";    $output .= '    <link rel="alternate" type="text/html" href="'. $link .'" />'. "\n";    $output .= '    <id>'. $link ."</id>\n";    $output .= '    <published>'. _gdata_timestamp2w3dtf($item->created) ."</published>\n";    $output .= '    <updated>'. _gdata_timestamp2w3dtf($item->changed) ."</updated>\n";    $last_mod = $item->changed;    $output .= "    <author>\n";    if ($item->name) {      $output .= '      <name>'. $item->name ."</name>\n";    }    else {      $output .= '      <name>'. variable_get('anonymous', 'Anonymous') ."</name>\n";    }    $output .= "    </author>\n";    if (module_exist('taxonomy')) {      $terms = taxonomy_node_get_terms($item->nid);      foreach ($terms as $term) {        $output .= '    <category term="'. check_plain(strip_tags($term->name)) . '" />'. "\n";      }    }    // Summary    $output .= '    <summary type="html"><![CDATA[';    $output .= check_output($item->teaser);    $output .= "    ]]></summary>\n";    // Body    $output .= '    <content type="html"><![CDATA[';    $output .= variable_get('atom_ad_location', 'off') == 'prepend' ? str_replace('%link', urlencode($link), str_replace('%id', $node->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 .= "    ]]></content>\n";    $output .= "  </entry>\n";  }  drupal_set_header('Content-Type: application/xml');  print '<?xml version="1.0" encoding="utf-8"?>'. "\n";  print '<feed xmlns="http://www.w3.org/2005/Atom">'. "\n";  print '  <title>'. $feed_info['title'] ."</title>\n";  print $feed_info['subtitle'] == '' ? '' : '  <subtitle>'. $feed_info['subtitle'] . "</subtitle>\n";  print '  <link rel="alternate" type="text/html" href="'.$feed_info['html_url'] .'"/>'. "\n";  print '  <link rel="self" type="application/atom+xml" href="'. $feed_info['atom_url'] .'"/>'. "\n";  print '  <id>'. $feed_info['gdata_url'] ."</id>\n";  print '  <updated>'. _gdata_timestamp2w3dtf($last_mod) ."</updated>\n";  print $output;  print "</feed>\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;}