functions.php
author Dan
Tue, 01 Jul 2008 04:17:46 -0400
changeset 23 08225c2eb0b6
parent 16 23d4cf2f183b
child 32 86140ed9087d
permissions -rw-r--r--
Added support for multipart forms, file uploads, and fatal exceptions in PhpHttpd; fixed wrong license tag on WebServer class
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
     1
<?php
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
     2
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
     3
/**
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
     4
 * Utility functions
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
     5
 * 
6
5f35ebc4f9bb First release version. Renamed to Greyhound and readme/license files added.
Dan
parents: 5
diff changeset
     6
 * Greyhound - real web management for Amarok
5
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
     7
 * Copyright (C) 2008 Dan Fuhry
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
     8
 *
5
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
     9
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
    10
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
    11
 *
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
    13
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    14
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    15
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    16
/**
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    17
 * Utility/reporting functions
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    18
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    19
 
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    20
/**
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    21
 * Report a fatal error and exit
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    22
 * @param string Error message
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    23
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    24
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    25
function burnout($msg)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    26
{
9
63a257541313 Moved all Greyhound output to stderr so it will show up in AmaroK error messages; corrected some HTML bugs in the readme
Dan
parents: 8
diff changeset
    27
  $h = @fopen('php://stderr', 'w');
63a257541313 Moved all Greyhound output to stderr so it will show up in AmaroK error messages; corrected some HTML bugs in the readme
Dan
parents: 8
diff changeset
    28
  fwrite($h, "\x1B[31;1m[Greyhound] fatal: \x1B[37;1m");
63a257541313 Moved all Greyhound output to stderr so it will show up in AmaroK error messages; corrected some HTML bugs in the readme
Dan
parents: 8
diff changeset
    29
  fwrite($h, "$msg\x1B[0m\n");
63a257541313 Moved all Greyhound output to stderr so it will show up in AmaroK error messages; corrected some HTML bugs in the readme
Dan
parents: 8
diff changeset
    30
  fclose($h);
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    31
  exit(1);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    32
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    33
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    34
/**
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    35
 * Print a stylized status message, compatible with Linux consoles
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    36
 * @param string Status message
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    37
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    38
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    39
function status($msg)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    40
{
9
63a257541313 Moved all Greyhound output to stderr so it will show up in AmaroK error messages; corrected some HTML bugs in the readme
Dan
parents: 8
diff changeset
    41
  $h = @fopen('php://stderr', 'w');
16
23d4cf2f183b Disabled forking/keep-alive code, firefox doesn't seem to like the way it waits for requests
Dan
parents: 15
diff changeset
    42
  $label = ( defined('HTTPD_WS_CHILD') ) ? 'Child ' . substr(strval(getmypid()), -3) : 'Greyhound';
15
2adca0f363fd Added multi-threading/forking/keep-alive support to webserver. w00t, feeling all POSIX-happy today!
Dan
parents: 14
diff changeset
    43
  fwrite($h, "\x1B[32;1m[$label] \x1B[32;0m$msg\x1B[0m\n");
9
63a257541313 Moved all Greyhound output to stderr so it will show up in AmaroK error messages; corrected some HTML bugs in the readme
Dan
parents: 8
diff changeset
    44
  fclose($h);
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    45
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    46
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    47
/**
13
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    48
 * Print a stylized warning message, compatible with Linux consoles
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    49
 * @param string message message
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    50
 */
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    51
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    52
function warning($msg)
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    53
{
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    54
  $h = @fopen('php://stderr', 'w');
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    55
  fwrite($h, "\x1B[33;1m[Greyhound] \x1B[0m\x1B[33mWarning:\x1B[0m $msg\n");
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    56
  fclose($h);
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    57
}
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    58
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    59
/**
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    60
 * Performs an action with DCOP.
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    61
 * @param string DCOP component, e.g. player, playlist, playlistbrowser, ...
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    62
 * @param string Action to perform, e.g. stop, play, ...
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    63
 * @param string additional parameters... (NOT IMPLEMENTED)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    64
 * @return mixed output of DCOP command
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    65
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    66
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    67
function dcop_action($component, $action)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    68
{
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    69
  $tmpfile = tempnam('amaweb', '');
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    70
  if ( !$tmpfile )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    71
    burnout('tempnam() failed us');
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    72
  system("dcop amarok $component $action > $tmpfile");
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    73
  $output = @file_get_contents($tmpfile);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    74
  @unlink($tmpfile);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    75
  $output = trim($output);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    76
  
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    77
  // detect type of output
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    78
  if ( $output == 'true' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    79
    return true;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    80
  else if ( $output == 'false' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    81
    return false;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    82
  else if ( preg_match('/^-?[0-9]+/', $output) )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    83
    return intval($output);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    84
  else
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    85
    return $output;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    86
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    87
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    88
/**
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    89
 * Rebuilds the copy of the playlist in RAM
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    90
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    91
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    92
$playlist_last_md5 = '';
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    93
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    94
function rebuild_playlist()
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    95
{
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    96
  // import what we need
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    97
  global $homedir, $playlist;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    98
  // sync and load the playlist file
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    99
  $playlist_file = dcop_action('playlist', 'saveCurrentPlaylist');
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   100
  // check MD5 - if it's not changed, exit to save CPU cycles
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   101
  global $playlist_last_md5;
5
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   102
  $effective_md5 = md5_playlist_file($playlist_file);
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   103
  if ( $playlist_last_md5 == $effective_md5 )
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   104
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   105
    return true;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   106
  }
14
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   107
  status('Rebuilding playlist cache');
5
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   108
  $playlist_last_md5 = $effective_md5;
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   109
  // start XML parser
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   110
  try
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   111
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   112
    $xml = simplexml_load_file($playlist_file);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   113
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   114
  catch ( Exception $e )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   115
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   116
    burnout("Caught exception trying to load playlist file:\n$e");
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   117
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   118
  $attribs = $xml->attributes();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   119
  if ( @$attribs['product'] != 'Amarok' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   120
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   121
    burnout('Playlist is not in Amarok format');
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   122
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   123
  $playlist = array();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   124
  foreach ( $xml->children() as $child )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   125
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   126
    $attribs = $child->attributes();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   127
    $item = array(
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   128
        'uri'    => $attribs['uri'],
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   129
        'title'  => strval($child->Title),
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   130
        'artist' => strval($child->Artist),
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   131
        'album'  => strval($child->Album),
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   132
        'length' => seconds_to_str(intval($child->Length)),
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   133
        'length_int' => intval($child->Length)
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   134
      );
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   135
    $playlist[] = $item;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   136
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   137
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   138
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   139
/**
5
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   140
 * Builds the correct MD5 check for the specified playlist XML file. This is designed to base on the list of actual tracks, disregarding
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   141
 * the rest of the text in the XML file.
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   142
 * @param string Path to playlist
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   143
 * @return string hash
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   144
 */
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   145
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   146
function md5_playlist_file($file)
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   147
{
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   148
  $contents = @file_get_contents($file);
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   149
  if ( empty($contents) )
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   150
    return false;
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   151
  $count = preg_match_all('/uniqueid="([a-fA-F0-9]+?)"/', $contents, $matches);
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   152
  $matches = implode("", $matches[1]);
14
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   153
  if ( empty($matches) )
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   154
  {
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   155
    // sometimes current.xml has blank unique IDs
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   156
    $count = preg_match_all('/url="([^"]+?)"/', $contents, $matches);
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   157
    $matches = implode("", $matches[1]);
7a1573676cc4 Added jump-to-current function in iphone theme; fixed md5('') call if unique IDs empty in playlist XML file
Dan
parents: 13
diff changeset
   158
  }
5
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   159
  return md5($matches);
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   160
}
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   161
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   162
/**
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   163
 * Converts a number to minute:second format
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   164
 * @param int Seconds
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   165
 * @return string format: mm:ss
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   166
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   167
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   168
function seconds_to_str($secs)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   169
{
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   170
  $seconds = $secs % 60;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   171
  $minutes = ( $secs - $seconds ) / 60;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   172
  $seconds = strval($seconds);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   173
  $minutes = strval($minutes);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   174
  if ( strlen($seconds) < 2 )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   175
    $seconds = "0$seconds";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   176
  if ( strlen($minutes) < 2 )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   177
    $minutes = "0$minutes";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   178
  return "$minutes:$seconds";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   179
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   180
4
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   181
/**
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   182
 * Loads the specified theme into Smarty
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   183
 * @param string Theme ID
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   184
 * @return object Smarty object
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   185
 */
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   186
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   187
function load_theme($theme_id)
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   188
{
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   189
  global $httpd;
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   190
  static $smarty = array();
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   191
  if ( !isset($smarty[$theme_id]) )
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   192
  {
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   193
    $smarty[$theme_id] = new Smarty();
8
a8d108f37363 Modified to trap signals properly and not write to the root directory (only working directory)
Dan
parents: 6
diff changeset
   194
    $smarty[$theme_id]->template_dir = GREY_ROOT . "/themes/$theme_id";
a8d108f37363 Modified to trap signals properly and not write to the root directory (only working directory)
Dan
parents: 6
diff changeset
   195
    if ( !is_dir("./compiled/$theme_id") )
a8d108f37363 Modified to trap signals properly and not write to the root directory (only working directory)
Dan
parents: 6
diff changeset
   196
      @mkdir("./compiled/$theme_id");
a8d108f37363 Modified to trap signals properly and not write to the root directory (only working directory)
Dan
parents: 6
diff changeset
   197
    $smarty[$theme_id]->compile_dir  = "./compiled/$theme_id";
4
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   198
    $smarty[$theme_id]->config_dir = "./config";
8
a8d108f37363 Modified to trap signals properly and not write to the root directory (only working directory)
Dan
parents: 6
diff changeset
   199
    $httpd->add_handler("themes/$theme_id", 'dir', GREY_ROOT . "/themes/$theme_id");
4
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   200
  }
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   201
  return $smarty[$theme_id];
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   202
}