/[drupal]/contributions/modules/discography/discography.module
ViewVC logotype

Contents of /contributions/modules/discography/discography.module

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


Revision 1.1 - (show annotations) (download) (as text)
Fri May 6 01:53:04 2005 UTC (4 years, 6 months ago) by mike3k
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
Initial release
1 <?php
2 /* $Id$ */
3
4 /**
5 * This module defines a new node type, discography, which includes an artist field,
6 * optional track listing, availability information, and links to purchase from
7 * Amazon or iTunes Music Store.
8 *
9 * Requires amazon_items module.
10 */
11
12 require_once "includes/AmazonProduct.class.inc";
13 require_once "includes/AmazonSearchEngine.class.inc";
14
15 /**
16 *
17 * generates an iTMS clickable link
18 *
19 */
20 function _itms_link($ITMS,$title,$icon="itunes.png") {
21 return '<a href="'.$ITMS.'"><img src="'.drupal_get_path('module','discography').'/'.$icon.'" alt="iTunes" valign="middle"></a>';
22 }
23
24 /**
25 *
26 * Generates an Amazon Affiliate link for a specified ASIN.
27 * if $icon is null, the album image from Amazon will be used
28 *
29 */
30 function _amazon_link($ASIN,$icon="amazon.png") {
31 $result = "";
32 $am_affid = variable_get("amazon_items_affid", "none");
33 $SE = new AmazonSearchEngine($am_affid, $am_affid, "2.0");
34 $SE->server = variable_get("amazon_items_server", "xml.amazon.com");
35 $SE->searchAsin((trim($ASIN)));
36 if (count($SE->results) == 1) {
37 $result = '<a href="'.$SE->results[0]->url.'" target="_blank">';
38 if ($icon == NULL) {
39 $result .= '<img src="'.$SE->results[0]->ImageUrlMedium.'" alt="buy from Amazon"></a>';
40 }
41 else {
42 $result .= '<img src="'.drupal_get_path('module','discography').'/'.$icon.'" alt="buy from Amazon" valign="middle"></a>';
43 }
44 }
45 return $result;
46 }
47
48 function discography_html_head() {
49 $css = '<style type="text/css" media="screen">';
50 $css .= '.discography { }\n';
51 $css .= '.tracks { border: 1px solid #000; margin-left: 2em; padding: 5px }\n';
52 $css .= '</style>';
53
54 return $css;
55 }
56
57 function discography_help($section = "admin/help#discography") {
58 switch($section) {
59 case "admin/help#discography":
60 return t("<p>The discography module allows you to create a list of albums including artist information");
61
62 case "admin/modules#description":
63 return t("A discography module for album lists");
64
65 case "node/add#discography":
66 return t("Allows you to enter an artist's discography");
67 }
68 }
69
70 function discography_menu($may_cache) {
71
72
73 $items = array();
74
75 $items[] = array('path' => 'discography',
76 'title' => t("discography"),
77 'callback' => 'discography_page',
78 'access' => user_access('access content'),
79 'type' => MENU_CALLBACK);
80
81 return $items;
82 }
83
84 function discography_link($type, $node = 0) {
85 $links = array();
86
87 if ($type == 'page' && user_access('access content')) {
88 $links[] = l(t('discography'),'discography');
89 }
90
91 return $links;
92 }
93
94 function discography_perm() {
95 return array("create discography");
96 }
97
98 /**
99 *
100 * Returns a formatted list of albums for the specified artist
101 * Purchase links for Amazon or iTMS are shown if available
102 *
103 */
104 function _albums_for_artist($artist) {
105 $q = 'select n.nid, n.title, d.ITMS, d.ASIN, d.year from node n, discography d where n.nid=d.nid and d.artist="'.$artist.'"'; // order by n.title';
106 $res = db_query($q);
107 $content = '<div style="margin-left: 2em;">';
108 while ($itm = db_fetch_object($res)) {
109 if ($itm->year != 0) {
110 $year = ' (' . $itm->year . ')';
111 }
112 else {
113 $year = '';
114 }
115 $content .= l($itm->title.$year, "node/".$itm->nid);
116 if ($itm->ITMS != "") {
117 $content .= "&nbsp;&bull;&nbsp;"._itms_link($itm->ITMS,$itm->title);
118 }
119 if ($itm->ASIN != "") {
120 $content .= "&nbsp;&bull;&nbsp;"._amazon_link($itm->ASIN);
121 }
122 $content .= "<br />";
123 }
124 $content .= "</div>";
125 return $content;
126 }
127
128 /**
129 *
130 * Prints the full list of albums.
131 * If $artist is null, only artist names will be shown as clickable links
132 * if $artist is "all", albums will be listed for all artists
133 * if $artist is anything else, albums matching that artist will be listed
134 *
135 */
136 function discography_page($artist = NULL) {
137
138 if ((strcasecmp($artist, "All") == 0) || ($artist == NULL)) {
139 $q1 = "select artist from discography group by artist";
140
141 $content = ($artist==NULL)? "<p><h3>Click on artist to see albums</h3><p>" :"";
142 $res1 = db_query($q1);
143 while ($a = db_fetch_object($res1)) {
144 $content .= '<p><h2>';
145 if ($artist != NULL) {
146 $content .= $a->artist.'</h2><p>';
147 $content .= _albums_for_artist($a->artist);
148 }
149 else {
150 $content .= l($a->artist,"discography/".$a->artist).'</h2><p>';
151 }
152 }
153 }
154 else {
155 $content = "<p><h2>Discography for ".$artist.":</h2><p>";
156 $content .= _albums_for_artist($artist);
157 }
158 print theme("page",$content);
159 }
160
161 function discography_node_types() {
162 return array("discography");
163 }
164
165 function discography_node_name($node) {
166 return t("discography");
167 }
168
169 function discography_block($op = "list", $delta = 0) {
170 }
171
172 /**
173 *
174 * Generate a detail page for an artist
175 *
176 */
177 function discography_content($node, $teaser = FALSE)
178 {
179
180 $node = node_prepare($node, $teaser);
181
182 $ASIN = $node->ASIN;
183 $ITMS = $node->ITMS;
184 if ($node->year != 0) {
185 $year = ' (' . $node->year . ')';
186 }
187 else {
188 $year = '';
189 }
190
191 $content = '<h3>' . $node->title . $year . ' - ';
192 $content .= $node->artist;
193 if ($node->cassette) {
194 $content .= '&nbsp;&nbsp;<img src="'.drupal_get_path('module','discography'). '/cassette.png" valign="middle">';
195 }
196 if ($node->CD) {
197 $content .= '&nbsp;&nbsp;<img src="'.drupal_get_path('module','discography').'/cd.png" valign="middle">';
198 }
199 $content .= "</h3>";
200 $content .= '<div class="discography">' . check_output($node->body) . '</div>';
201 if ($node->tracks) {
202 $content .= '<div style="border: 1px solid #000; margin-left: 2em; margin-right: 4em; padding: 5px">';
203 $content .= "<h5>Track Listing:</h5>";
204 $content .= check_output($node->tracks) . '</div>';
205 }
206
207 if ($ASIN != "") {
208 $content .= "<p>"._amazon_link($ASIN,NULL);
209 }
210 if ($ITMS != "") {
211 $content .= "<p>"._itms_link($ITMS,$node->title);
212 }
213 $node->teaser = $node->title . $year . " - ". $node->artist;
214 $node->body = $content;
215
216 return $node;
217 }
218
219 function discography_view(&$node, $teaser = FALSE, $page = FALSE) {
220 $node = discography_content($node, $teaser);
221 return theme('node', $node, $teaser, $page);
222 }
223
224 function discography_access($op, $node) {
225 switch($op) {
226 case 'view':
227 return $node->status;
228 case 'create':
229 return user_access("create discography");
230 }
231 }
232
233 function discography_form(&$node, &$param) {
234
235 $output .= form_textfield(t("Artist"), "artist", $node->artist, 60, 128, t("") . ($error['artist'] ? $error["artist"] : ''));
236 $output .= form_textfield(t("Catalog Info"),"label",$node->label, 32, 32, t(""));
237 $output .= form_textfield(t("Year"),"year",$node->year,8,8,t(""));
238 $output .= form_checkbox(t("Available on cassette"),"cassette",1,$node->cassette);
239 $output .= form_checkbox(t("Available on CD"),"CD",1,$node->CD);
240 $output .= form_textarea(t('Track Listing'),'tracks', $node->tracks,60,20,'',NULL,FALSE);
241 $output .= form_textarea(t('More info'), 'body', $node->body, 60, 20, '', NULL, FALSE);
242 $output .= form_textfield(t('ITMS Link'), 'ITMS', $node->ITMS, 60,128, t('URL for iTunes Music Store, which you can find with <a href="http://phobos.apple.com/WebObjects/MZSearch.woa/wa/itmsLinkMaker" target="_blank">iTMS Link Maker</a>'));
243 $output .= form_textfield(t('Amazon ASIN'), 'ASIN', $node->ASIN, 16, 16, t("Amazon item number"));
244 $output .= filter_form('format', $node->format);
245
246 return $output;
247 }
248
249 function discography_insert($node) {
250 db_query("insert into {discography} (nid, artist, year, label, ITMS, ASIN, tracks, cassette, CD, DVD) values ('%d', '%s', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
251 $node->nid, $node->artist, $node->year, $node->label, $node->ITMS, $node->ASIN, $node->tracks, $node->cassette, $node->CD, $node->DVD);
252 }
253
254 function discography_update($node) {
255 db_query("update {discography} set artist='%s',year='%d', label='%s', ITMS='%s', ASIN='%s', tracks='%s', cassette='%s', CD='%s', DVD='%s' where nid='%d'",
256 $node->artist, $node->year, $node->label, $node->ITMS, $node->ASIN, $node->tracks, $node->cassette, $node->CD, $node->DVD, $node->nid);
257 }
258
259 function discography_delete($node) {
260 db_query("delete from {discography} where nid='%d'",$node->nid);
261 }
262
263 function discography_load($node) {
264 $discography = db_fetch_object(db_query("SELECT artist, label, year, ITMS, ASIN, tracks, cassette, CD, DVD FROM {discography} WHERE nid = '%d'",$node->nid));
265 return $discography;
266 }
267
268
269 ?>

  ViewVC Help
Powered by ViewVC 1.1.2