aboutsummaryrefslogtreecommitdiff
path: root/icecast_page.module
blob: f4cbf628c83d123ddfdc6dff4c9c516bddf2ab89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php

/**
 * @file
 *
 * Icecast page module.
 */

/**
 * Implements hook_menu()
 */
function icecast_page_menu() {
  /*
   *$items['blog'] = array(
   *  'title' => 'blogs',
   *  'page callback' => 'blog_page',
   *  'access arguments' => array('access content'),
   *  'type' => MENU_SUGGESTED_ITEM,
   *);
   */
  $items['stream'] = array(
    'title'            => 'Icecast Stream',
    'page callback'    => 'icecast_page',
    'access arguments' => array('access content'),
    'type'             => MENU_CALLBACK,
  );

  return $items;
}

/**
 * Implements hook_theme()
 */
function icecast_page_theme() {
  return array(
    'icecast_page' => array(
    'arguments'    => array('listen_url' => NULL),
    'template'     => 'icecast_page',                                                                  ),
    'qwebirc'      => array(
    'arguments'    => array('mount' => NULL),
    'template'     => 'qwebirc',                                                                  ),
    'icecast_page_footer' => array(
    'arguments'    => array('listen_url' => NULL),
    'template'     => 'icecast_page_footer',                                                                  ),
  );
}

/**                                                                                               
 * Page callback.
 *
 * @param $sid
 *   Stream Id.
 */
function icecast_page($sid = NULL) {
  $sid   = (int) $sid;
  $query = 'SELECT server_name, description, listen_url FROM {yp_stream} WHERE sid = %d';
  $result = db_fetch_array(db_query(db_rewrite_sql($query), $sid));

  if ($sid == NULL || empty($result['listen_url'])) {
    drupal_not_found();
    return;
  }

  drupal_set_title(t('Live: @server_name', array('@server_name' => check_plain($result['server_name']))));

  $mount  = basename($result['listen_url'], '.ogg');
  $mount  = basename($mount, '.ogv');
  $mount  = basename($mount, '.mp3');

  $output  = theme('icecast_page', $result['listen_url']);
  $output .= theme('qwebirc', $mount);
  $output .= theme('icecast_page_footer', $result['listen_url']);

  return $output;
}