functions.php
author Dan
Wed, 26 Mar 2008 11:10:20 -0400
changeset 13 b5db2345c397
parent 9 63a257541313
child 14 7a1573676cc4
permissions -rw-r--r--
Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
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');
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
    42
  fwrite($h, "\x1B[32;1m[Greyhound] \x1B[32;0m$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
    43
  fclose($h);
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    44
}
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
/**
13
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    47
 * 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
    48
 * @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
    49
 */
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
function warning($msg)
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    52
{
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    53
  $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
    54
  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
    55
  fclose($h);
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    56
}
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
/**
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    59
 * Performs an action with DCOP.
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    60
 * @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
    61
 * @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
    62
 * @param string additional parameters... (NOT IMPLEMENTED)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    63
 * @return mixed output of DCOP command
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    64
 */
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
function dcop_action($component, $action)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    67
{
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    68
  $tmpfile = tempnam('amaweb', '');
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    69
  if ( !$tmpfile )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    70
    burnout('tempnam() failed us');
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    71
  system("dcop amarok $component $action > $tmpfile");
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    72
  $output = @file_get_contents($tmpfile);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    73
  @unlink($tmpfile);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    74
  $output = trim($output);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    75
  
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    76
  // detect type of output
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    77
  if ( $output == 'true' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    78
    return true;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    79
  else if ( $output == 'false' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    80
    return false;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    81
  else if ( preg_match('/^-?[0-9]+/', $output) )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    82
    return intval($output);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    83
  else
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    84
    return $output;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    85
}
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
 * 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
    89
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    90
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    91
$playlist_last_md5 = '';
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    92
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    93
function rebuild_playlist()
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    94
{
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    95
  // import what we need
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    96
  global $homedir, $playlist;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    97
  // sync and load the playlist file
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    98
  $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
    99
  // 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
   100
  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
   101
  $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
   102
  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
   103
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   104
    return true;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   105
  }
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
   106
  $playlist_last_md5 = $effective_md5;
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   107
  // start XML parser
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   108
  try
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   109
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   110
    $xml = simplexml_load_file($playlist_file);
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
  catch ( Exception $e )
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
    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
   115
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   116
  $attribs = $xml->attributes();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   117
  if ( @$attribs['product'] != 'Amarok' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   118
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   119
    burnout('Playlist is not in Amarok format');
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
  $playlist = array();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   122
  foreach ( $xml->children() as $child )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   123
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   124
    $attribs = $child->attributes();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   125
    $item = array(
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   126
        'uri'    => $attribs['uri'],
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   127
        'title'  => strval($child->Title),
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   128
        'artist' => strval($child->Artist),
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   129
        '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
   130
        '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
   131
        'length_int' => intval($child->Length)
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   132
      );
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   133
    $playlist[] = $item;
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
}
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
/**
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
   138
 * 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
   139
 * 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
   140
 * @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
   141
 * @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
   142
 */
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
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
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
   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
  $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
   147
  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
   148
    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
   149
  $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
   150
  $matches = implode("", $matches[1]);
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
  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
   152
}
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
   153
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
   154
/**
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   155
 * Converts a number to minute:second format
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   156
 * @param int Seconds
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   157
 * @return string format: mm:ss
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   158
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   159
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   160
function seconds_to_str($secs)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   161
{
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   162
  $seconds = $secs % 60;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   163
  $minutes = ( $secs - $seconds ) / 60;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   164
  $seconds = strval($seconds);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   165
  $minutes = strval($minutes);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   166
  if ( strlen($seconds) < 2 )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   167
    $seconds = "0$seconds";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   168
  if ( strlen($minutes) < 2 )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   169
    $minutes = "0$minutes";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   170
  return "$minutes:$seconds";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   171
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   172
4
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   173
/**
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   174
 * Loads the specified theme into Smarty
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   175
 * @param string Theme ID
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   176
 * @return object Smarty object
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   177
 */
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   178
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   179
function load_theme($theme_id)
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   180
{
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   181
  global $httpd;
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   182
  static $smarty = array();
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   183
  if ( !isset($smarty[$theme_id]) )
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   184
  {
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   185
    $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
   186
    $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
   187
    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
   188
      @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
   189
    $smarty[$theme_id]->compile_dir  = "./compiled/$theme_id";
4
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   190
    $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
   191
    $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
   192
  }
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   193
  return $smarty[$theme_id];
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   194
}