~ubuntu-drupal-devs/ubuntu-drupal-countdown/6.x

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
// $Id$

/*
 * @file
 * Drupal Module: Ubuntu Release Countdown
 * Ubuntu Countdown displays a customizable block to inform the visitor
 * when a new version of Ubuntu will be released. It will contain the
 * ability to display either of the four options created by the Web
 * Presence team or one of your own.
 */

/**
 * Implementation of hook_perm - Defines user permissions.
 * The suggested naming convention for permissions is "action_verb modulename".
 *
 * @return An array of permissions strings.
 *
 * @ingroup base
 */

function udcountdown_perm() {
  return array('administer udcountdown', 'view udcountdown');
}

/**
 * Implementation of hook_help - Provides online user help.
 *
 * @param $path A Drupal menu router path the help is being requested for
 * @param $arg
 * @return A localized string containing the help text.
 *
 * @ingroup base
 */

function udcountdown_help($path, $arg) {
  switch ($path) {
    case 'admin/help#udcountdown':
      $output = t('<p>Ubuntu Release Countdown is a module that will allow Drupal administrators to add a code block that displays the countdown until '
                . 'the next version of Ubuntu. It allows you to use any of the precoded options, or your own. The available options are listed on the '
                . '!link.</p>'
                . '<p>To use planet, go to admin/settings/udcountdown and note the following sections.</p>'
                . 'Standard Settings:'
                . '<ul>'
                . '<li>Display Option - This allows you to pick which banner will be used. The first option allows you to use your own custom code. '
                . 'The rest of the options are pulled from the !link on the Ubuntu website.</li>'
                . '<li>Custom Code - If you do not like the available options, you can add your own custom code here.</li>'
                . '</ul>', array('!link' => l(t('countdown section'), 'http://www.ubuntu.com/getubuntu/contdown')));

      return $output;
  }
}

function udcountdown_menu() {

  $items = array();

  $items['admin/settings/udcountdown'] = array(
    'title' => 'UD Countdown Settings',
    'description' => 'Set the various options for the Ubuntu Release Countdown module.',
    'weight' => '0',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('udcountdown_admin_settings'),
    'access arguments' => array('administer udcountdown'),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'udcountdown_settings.inc',
  );
  $items['admin/settings/udcountdown/settings'] = array(
    'title' => 'Standard',
    'description' => 'Set the various options for the Ubuntu Release Countdown module.',
    'weight' => '0',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('udcountdown_admin_settings'),
    'access arguments' => array('administer udcountdown'),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'file' => 'udcountdown_settings.inc',
  );

  return $items;
}

/**
 * Implementation of hook_cron().
 */
function udcountdown_cron() {
  module_load_include('inc', 'udcountdown', 'udcountdown_cron');
  udcountdown_cron_run();
}

/**
 * Implementation of hook_block().
 */
function udcountdown_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == "list") {
    $block[0]["info"] = t('Ubuntu Release Countdown');
  }
  elseif ($op == 'view') {
    $block_content = '<div id="udcountdown" class="udcountdown">';
    $block_content .= udcountdown_content();
    $block_content .= '</div>';

    $block['subject'] = t('Ubuntu Release Countdown');
    $block['content'] = $block_content;
  }
  return $block;
}

/**
 * Create the block content
 */
function udcountdown_content() {
  $cache = file_directory_path() . '/countdown/';

  // Grab the specified data
  $opt = variable_get('udcountdown_option', 1);
  if (0 == $opt) {
    $rcc = variable_get('udcountdown_custom', '');
  }
  elseif (is_numeric($opt)) {
    $file = $cache . $opt;
    $rcc = file_get_contents($file);
  }
  else {
    $rcc = variable_get('udcountdown_custom', '');
  }

  // Handle JavaScript Disabled browsers
  if (ereg('script|iframe', $rcc)) {
    $rfile = $cache . 'noscript';
    $file = fopen($rfile, 'r');
    $rcc .= '<noscript>' . file_get_contents($rfile) . '</noscript>';
    fclose($file);
  }

  return $rcc;
}