~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
<?php
// $Id$

/**
 * @file
 * Cron function
 *
 * The cron for this module is large so it's in it's own file.
 */

/**
 * Cron function
 */
function udcountdown_cron_run() {
  $cache = file_directory_path() . "/countdown/";
  $pointerver = trim(file_get_contents('http://edge.launchpad.net/ubuntu-drupal-countdown/misc/release-version/+download/pointer'));
  $pointer = 'https://launchpad.net/ubuntu-drupal-countdown/banners/' . $pointerver;

  udcountdown_checkver($cache, $pointer);
}

/**
 * Check if banner source changed
 */
function udcountdown_checkver($cache, $pointer) {
  $cur = curl_init();
  curl_setopt($cur, CURLOPT_URL, $pointer .  '/+download/rv');
  curl_setopt($cur, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($cur, CURLOPT_FOLLOWLOCATION, TRUE);
  $curval = curl_exec($cur);
  curl_close($cur);
  $curval = trim($curval);

  $relver = variable_get('udcountdown_relver', FALSE);

  if ($relver != $curval) {
    udcountdown_pullver($cache, $pointer);
    variable_set('udcountdown_relver', $curval);
  }
}

/**
 * Pull latest banner source
 */
function udcountdown_pullver($cache, $pointer) {
  shell_exec('rm -rf ' . $cache);
  shell_exec('/usr/bin/wget -nd -m -P ' . $cache . ' ' . $pointer . '/+download/banners.tgz');
  shell_exec('cd ' . $cache . '; tar zxf banners.tgz ');
}