/[drupal]/contributions/modules/audio/contrib/itunes/audio_itunes.module
ViewVC logotype

Diff of /contributions/modules/audio/contrib/itunes/audio_itunes.module

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

revision 1.5 by drewish, Fri Aug 3 02:41:13 2007 UTC revision 1.6 by drewish, Sun May 25 17:21:27 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: audio_itunes.module,v 1.4 2007/05/30 15:52:23 drewish Exp $  // $Id: audio_itunes.module,v 1.5 2007/08/03 02:41:13 drewish Exp $
3    
4  define('AUDIO_ITUNES_EXPLICIT_YES', 1);  define('AUDIO_ITUNES_EXPLICIT_YES', 1);
5  define('AUDIO_ITUNES_EXPLICIT_CLEAN', 2);  define('AUDIO_ITUNES_EXPLICIT_CLEAN', 2);
6    
7  function audio_itunes_menu($may_cache) {  function audio_itunes_menu() {
8    $items = array();    $items = array();
9    if (!$may_cache) {  
10      /* FIXME: Get this into an access callback
11      // insert a iTunes tab on views our argument handler      // insert a iTunes tab on views our argument handler
12      if (user_access('administer views') &&      if (user_access('administer views') &&
13          arg(0) == 'admin' &&  arg(1) == 'build' && arg(2) == 'views') {          arg(0) == 'admin' &&  arg(1) == 'build' && arg(2) == 'views') {
14        if ($view = views_load_view(arg(3))) {        if ($view = views_load_view(arg(3))) {
15          foreach ($view->argument as $index => $argument) {          foreach ($view->argument as $index => $argument) {
16            if ($argument['type'] == 'audio_itunes_feed') {            if ($argument['type'] == 'audio_itunes_feed') {
             $items[] = array(  
               'path' => 'admin/build/views/'. arg(3) .'/itunes',  
               'title' => t('iTunes'),  
               'callback' => 'drupal_get_form',  
               'callback arguments' => array('audio_itunes_channel_form', $view->vid),  
               'type' => MENU_LOCAL_TASK  
             );  
17              break;              break;
18            }            }
19          }          }
20        }        }
21      }      }
22    }    }
23       */
24    
25      $items['admin/build/views/%view/itunes'] = array(
26        'title' => 'iTunes',
27        'page callback' => 'drupal_get_form',
28        'page arguments' => array('audio_itunes_channel_form', 1),
29        'type' => MENU_LOCAL_TASK,
30      );
31    
32    return $items;    return $items;
33  }  }
# Line 34  function audio_itunes_menu($may_cache) { Line 36  function audio_itunes_menu($may_cache) {
36   * Implementation of hook_form_alter() so we can add our image fields to the   * Implementation of hook_form_alter() so we can add our image fields to the
37   * audio node form.   * audio node form.
38   */   */
39  function audio_itunes_form_alter($form_id, &$form) {  function audio_itunes_form_alter(&$form, &$form_state, $form_id) {
40    // We only alter audio node edit forms    // We only alter audio node edit forms
41    if ($form_id == 'audio_node_form') {    if ($form_id == 'audio_node_form') {
42      $node = $form['#node'];      $node = $form['#node'];
43    
44      $form['audio_itunes'] = array(      $form['audio_itunes'] = array(
45        '#type' => 'fieldset', '#title' => t('iTunes feed information'),        '#type' => 'fieldset', '#title' => t('iTunes feed information'),
46        '#collapsible'=> TRUE,        '#collapsible' => TRUE,
47        '#description' => t('iTunes specific information.'),        '#description' => t('iTunes specific information.'),
48        '#weight' => 0,        '#weight' => 0,
49        '#tree' => TRUE,        '#tree' => TRUE,
# Line 208  function audio_itunes_channel_form($view Line 210  function audio_itunes_channel_form($view
210    $form['owner'] = array(    $form['owner'] = array(
211      '#type' => 'fieldset',      '#type' => 'fieldset',
212      '#title' => t('Owner'),      '#title' => t('Owner'),
213      '#collapsible'=> FALSE,      '#collapsible' => FALSE,
214      '#tree' => FALSE,      '#tree' => FALSE,
215      '#description' => t("Apple uses this information to contact the owner of the podcast for communication specifically about their podcast. It will not be publicly displayed but it may be picked up by spammers."),      '#description' => t("Apple uses this information to contact the owner of the podcast for communication specifically about their podcast. It will not be publicly displayed but it may be picked up by spammers."),
216    );    );
# Line 231  function audio_itunes_channel_form($view Line 233  function audio_itunes_channel_form($view
233    return $form;    return $form;
234  }  }
235    
236  function audio_itunes_channel_form_validate($form_id, $values) {  function audio_itunes_channel_form_validate($form, &$form_state) {
237    if (!empty($values['image_url'])) {    if (!empty($form_state['values']['image_url'])) {
238      if (!valid_url($values['image_url'])) {      if (!valid_url($form_state['values']['image_url'])) {
239        form_set_error('image_url', t('The image URL must be a valid URL.'));        form_set_error('image_url', t('The image URL must be a valid URL.'));
240      }      }
241      else {      else {
242        $url = parse_url($values['image_url']);        $url = parse_url($form_state['values']['image_url']);
243        $ext = strtolower(pathinfo($url['path'], PATHINFO_EXTENSION));        $ext = strtolower(pathinfo($url['path'], PATHINFO_EXTENSION));
244        if (!isset($url['path']) || ($ext != 'jpg' && $ext != 'png')) {        if (!isset($url['path']) || ($ext != 'jpg' && $ext != 'png')) {
245          form_set_error('image_url', t('The URL must specify a file ending with <code>.jpg</code> or <code>.png</code>.'));          form_set_error('image_url', t('The URL must specify a file ending with <code>.jpg</code> or <code>.png</code>.'));
246        }        }
247      }      }
248    }    }
249    if (!empty($values['owner_email']) && !valid_email_address($values['owner_email'])) {    if (!empty($form_state['values']['owner_email']) && !valid_email_address($form_state['values']['owner_email'])) {
250      form_set_error('owner_email', t('The owner email must be a valid email address.'));      form_set_error('owner_email', t('The owner email must be a valid email address.'));
251    }    }
252  }  }
253    
254  function audio_itunes_channel_form_submit($form_id, $values) {  function audio_itunes_channel_form_submit($form, &$form_state) {
255    if ($values['view_id']) {    if ($form_state['values']['view_id']) {
256      // delete and insert rather than updating in case the node doesn't have an existing record      // delete and insert rather than updating in case the node doesn't have an existing record
257      db_query("DELETE FROM {audio_itunes_channel} WHERE view_id = %d", $values['view_id']);      db_query("DELETE FROM {audio_itunes_channel} WHERE view_id = %d", $form_state['values']['view_id']);
258      db_query("INSERT INTO {audio_itunes_channel} (view_id, subtitle, summary, author, copyright, owner_name, owner_email, image_url, block, explicit) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)",      db_query("INSERT INTO {audio_itunes_channel} (view_id, subtitle, summary, author, copyright, owner_name, owner_email, image_url, block, explicit) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)",
259        $values['view_id'], $values['subtitle'], $values['summary'], $values['author'], $values['copyright'], $values['owner_name'], $values['owner_email'], $values['image_url'], $values['block'], $values['explicit']);        $form_state['values']['view_id'], $form_state['values']['subtitle'], $form_state['values']['summary'], $form_state['values']['author'], $form_state['values']['copyright'], $form_state['values']['owner_name'], $form_state['values']['owner_email'], $form_state['values']['image_url'], $form_state['values']['block'], $form_state['values']['explicit']);
260    }    }
261  }  }
262    
# Line 326  function audio_itunes_views_arguments() Line 328  function audio_itunes_views_arguments()
328   * handler for our own RSS argument; mimics the feed selector   * handler for our own RSS argument; mimics the feed selector
329   */   */
330  function audio_itunes_arg_handler($op, &$query, $argtype, $arg = '') {  function audio_itunes_arg_handler($op, &$query, $argtype, $arg = '') {
331    switch($op) {    switch ($op) {
332      case 'summary':      case 'summary':
333      case 'sort':      case 'sort':
334      case 'link':      case 'link':
# Line 398  function audio_itunes_views_feed_argumen Line 400  function audio_itunes_views_feed_argumen
400  }  }
401    
402  /**  /**
403   * plugin that actually displays an RSS feed   * Implementation of hook_theme
404     */
405    function audio_itunes_theme() {
406      return array(
407        'audio_itunes_feed' => array(
408          'arguments' => array('view', 'nodes', 'type'),
409        ),
410      );
411    }
412    
413    /**
414     * Plugin that actually displays an RSS feed
415   */   */
416  function theme_audio_itunes_feed($view, $nodes, $type) {  function theme_audio_itunes_feed($view, $nodes, $type) {
417    if ($type == 'block') {    if ($type == 'block') {
# Line 411  function theme_audio_itunes_feed($view, Line 424  function theme_audio_itunes_feed($view,
424      // a check_plain isn't required on these because format_rss_channel      // a check_plain isn't required on these because format_rss_channel
425      // already does this.      // already does this.
426      'title'       => views_get_title($view, 'page'),      'title'       => views_get_title($view, 'page'),
427      'link'        => url($view->feed_url ? $view->feed_url : $view->real_url, NULL, NULL, true),      'link'        => url($view->feed_url ? $view->feed_url : $view->real_url, array('absolute' => true)),
428      'description' => $view->description,      'description' => $view->description,
429    );    );
430    
# Line 423  function theme_audio_itunes_feed($view, Line 436  function theme_audio_itunes_feed($view,
436    foreach ($nodes as $node) {    foreach ($nodes as $node) {
437      // Load the specified node:      // Load the specified node:
438      $item = node_load($node->nid);      $item = node_load($node->nid);
439      $link = url("node/$node->nid", NULL, NULL, 1);      $link = url("node/$node->nid", array('absolute' => TRUE));
440    
441      if ($item_length != 'title') {      if ($item_length != 'title') {
442        $teaser = ($item_length == 'teaser') ? TRUE : FALSE;        $teaser = ($item_length == 'teaser') ? TRUE : FALSE;
# Line 442  function theme_audio_itunes_feed($view, Line 455  function theme_audio_itunes_feed($view,
455    
456      // Allow modules to add additional item fields      // Allow modules to add additional item fields
457      $extra = node_invoke_nodeapi($item, 'rss item');      $extra = node_invoke_nodeapi($item, 'rss item');
458      $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' =>  date('r', $item->created)), array('key' => 'dc:creator', 'value' => $item->name), array('key' => 'guid', 'value' => $item->nid . ' at ' . $base_url, 'attributes' => array('isPermaLink' => 'false'))));      $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' =>  date('r', $item->created)), array('key' => 'dc:creator', 'value' => $item->name), array('key' => 'guid', 'value' => $item->nid .' at '. $base_url, 'attributes' => array('isPermaLink' => 'false'))));
459      foreach ($extra as $element) {      foreach ($extra as $element) {
460        if ($element['namespace']) {        if ($element['namespace']) {
461          $namespaces = array_merge($namespaces, $element['namespace']);          $namespaces = array_merge($namespaces, $element['namespace']);
# Line 457  function theme_audio_itunes_feed($view, Line 470  function theme_audio_itunes_feed($view,
470        case 'teaser':        case 'teaser':
471          $item_text = $item->teaser;          $item_text = $item->teaser;
472          if ($item->readmore) {          if ($item->readmore) {
473            $item_text .= '<p>'. l(t('read more'), 'node/'. $item->nid, NULL, NULL, NULL, TRUE) .'</p>';            $item_text .= '<p>'. l(t('read more'), 'node/'. $item->nid, array('html' => TRUE)) .'</p>';
474          }          }
475          break;          break;
476        case 'title':        case 'title':
# Line 477  function theme_audio_itunes_feed($view, Line 490  function theme_audio_itunes_feed($view,
490    );    );
491    $channel = array_merge($channel_defaults, $channel);    $channel = array_merge($channel_defaults, $channel);
492    
493    $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";    $output = '<?xml version="1.0" encoding="utf-8"?>'."\n";
494    $output .= "<rss version=\"". $channel["version"] . "\" xml:base=\"". $base_url ."\" ". implode(' ', $namespaces) .">\n";    $output .= '<rss version="'. $channel["version"] .'" xml:base="'. $base_url .'" '. implode(' ', $namespaces) .">\n";
495    $output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language'], audio_itunes_feed_channel_arguments($view));    $output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language'], audio_itunes_feed_channel_arguments($view));
496    $output .= "</rss>\n";    $output .= "</rss>\n";
497    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.3