| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: audio_playlist.module,v 1.8 2008/10/02 18:43:14 drewish Exp $ 3 4 /** 5 * @file 6 * This module provides a quick method of adding audio files to other nodes (that allow audio attachments). 7 */ 8 9 10 /** 11 * Implementation of hook_help(). 12 */ 13 function audio_playlist_help($section, $arg) { 14 switch ($section) { 15 case 'admin/help#audio_playlist': 16 return t('This module provides a quick method of adding audio files to other nodes (that allow audio attachments).'); 17 } 18 } 19 20 21 /** 22 * Implementation of hook_link(). 23 */ 24 function audio_playlist_link($type, $node = NULL, $teaser = FALSE) { 25 global $base_url; 26 global $user; 27 28 $links = array(); 29 if ($node->type == 'audio') { 30 if ((node_access('update', $node) || user_access('attach any existing audio file')) && (user_access('attach audio to own playlists') || user_access('attach audio to any playlist'))) { 31 $links['audio_playlist_add_link'] = array( 32 'title' => t('Add to playlist'), 33 'href' => "audio_playlist/$node->nid", 34 'query' => 'destination='. $_GET['q'], 35 'attributes' => array('title' => t('Add to playlist')), 36 ); 37 } 38 } 39 40 return $links; 41 } 42 43 /** 44 * Implementation of hook_perm 45 */ 46 function audio_playlist_perm() { 47 return array( 48 'attach audio to own playlists', 49 'attach audio to any playlist', 50 ); 51 } 52 53 /** 54 * Implementation of hook_menu(). 55 */ 56 function audio_playlist_menu() { 57 $items = array(); 58 59 $items['audio_playlist/%node'] = array( 60 'title' => 'Add audio file to a playlist', 61 'page callback' => 'drupal_get_form', 62 'page arguments' => array('audio_playlist_add_form', 1), 63 'access callback' => 'audio_playlist_access', 64 'type' => MENU_CALLBACK, 65 ); 66 67 return $items; 68 } 69 70 /** 71 * Access callback to for the add playlist form. 72 */ 73 function audio_playlist_access() { 74 return user_access('attach audio to own playlists') || user_access('attach audio to any playlist'); 75 } 76 77 function audio_playlist_add_form($node = NULL) { 78 // make sure things are properly setup 79 if (!audio_playlist_get_playlist_types()) { 80 drupal_set_message("At least one content type must have <a href='!url'>audio attachments enabled</a> for playlists to work.", array('!url' => url('admin/content/types'))); 81 return; 82 } 83 84 // First try to pass the audio file through the URL, if that fails show a select box to choose an audio file. 85 if (is_numeric(arg(1))) { 86 $node = node_load(arg(1)); 87 if ($node->type == 'audio') { 88 $form['audio_playlist']['aid'] = array( 89 '#type' => 'value', 90 '#value' => $node->nid, 91 ); 92 $form['audio_playlist']['aid_name'] = array( 93 '#type' => 'item', 94 '#title' => t("Audio file"), 95 '#value' => $node->title, 96 ); 97 } 98 else { 99 drupal_set_message("Sorry, but only audio files can be added to a playlist."); 100 } 101 } 102 else { 103 // show a select box if audio isn't passed through URL 104 $form['audio_playlist']['aid'] = array( 105 '#type' => 'select', 106 '#title' => t('Select audio file'), 107 '#options' => audio_attach_get_audio_nodes(), 108 '#description' => t('Choose an audio file to add to a playlist.') 109 ); 110 } 111 112 $form['audio_playlist']['playlists'] = array( 113 '#type' => 'checkboxes', 114 '#title' => t('Add to playlist(s)'), 115 '#options' => audio_playlist_get_playlist_nodes(), 116 '#description' => t('Select which playlists you want to add this file to.'), 117 ); 118 119 $form['submit'] = array('#type' => 'submit', '#value' => t('Add to playlist')); 120 121 return $form; 122 } 123 124 function audio_playlist_add_form_submit($form, &$form_state) { 125 if ($form_state['values']['aid'] != 0) { 126 foreach ($form_state['values']['playlists'] as $nid => $checked) { 127 if ($checked) { 128 audio_attach_add_child($nid, $form_state['values']['aid']); 129 } 130 } 131 drupal_set_message("Added to playlist."); 132 } 133 else { 134 drupal_set_message("Please select an audio file.", "error"); 135 } 136 } 137 138 /** 139 * Fetch an array of all candidate referenced nodes, for use in presenting the selection form to the user. 140 */ 141 function audio_playlist_get_playlist_nodes() { 142 global $user; 143 144 $playlist_types = audio_playlist_get_playlist_types(); 145 if (empty($playlist_types)) { 146 return FALSE; 147 } 148 $types = array(); 149 foreach ($playlist_types as $type) { 150 $types[]= "type = '$type' "; 151 } 152 $types = implode('OR ', $types); 153 $sql = "SELECT n.nid, n.title FROM {node} n WHERE n.status=1 AND $types "; 154 $sql .= !user_access("attach audio to any playlist") ? "AND n.uid = $user->uid " : ""; 155 $sql .= "ORDER BY n.sticky DESC, n.title ASC"; 156 $rows = array(); 157 $result = db_query(db_rewrite_sql($sql)); 158 while ($row = db_fetch_object($result)) { 159 $node = node_load($row->nid); 160 $rows[$node->nid] = $node->title ."<small> " . l("(i)", 'node/'. $node->nid, array("target" => "_blank")) ."</small>"; 161 } 162 return $rows; 163 } 164 165 /** 166 * Return the content types which have audio_attach enabled. 167 */ 168 function audio_playlist_get_playlist_types() { 169 $node_types = node_get_types(); 170 $playlist_types = array(); 171 foreach ($node_types as $type => $name) { 172 if (variable_get('audio_attach_'. $type, 0)) { 173 $playlist_types[] = $type; 174 } 175 } 176 return $playlist_types; 177 } 178
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |