functions.php
author Dan
Wed, 08 Oct 2008 21:22:48 -0400
changeset 55 b8a3c9c54fbe
parent 52 ab3541465382
child 57 31ce64a3ff6c
permissions -rw-r--r--
Added login and credentials JSON API for some... upcoming new features.
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
{
34
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    27
  global $use_colors;
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
    28
  $h = @fopen('php://stderr', 'w');
34
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    29
  if ( $use_colors )
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    30
  {
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    31
    fwrite($h, "\x1B[31;1m[Greyhound] fatal: \x1B[37;1m");
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    32
    fwrite($h, "$msg\x1B[0m\n");
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    33
  }
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    34
  else
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    35
  {
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    36
    fwrite($h, "[Greyhound] fatal: $msg\n");
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    37
  }
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
    38
  fclose($h);
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    39
  exit(1);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    40
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    41
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    42
/**
34
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    43
 * Print a stylized status message, compatible with Linux consoles. Falls back to no control characters if on unsupported terminal.
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    44
 * @param string Status message
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
function status($msg)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    48
{
34
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    49
  global $use_colors;
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
    50
  $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
    51
  $label = ( defined('HTTPD_WS_CHILD') ) ? 'Child ' . substr(strval(getmypid()), -3) : 'Greyhound';
34
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    52
  if ( $use_colors )
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    53
  {
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    54
    fwrite($h, "\x1B[32;1m[$label] \x1B[32;0m$msg\x1B[0m\n");
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    55
  }
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    56
  else
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    57
  {
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    58
    fwrite($h, "[$label] $msg\n");
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    59
  }
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
    60
  fclose($h);
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    61
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    62
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    63
/**
13
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    64
 * 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
    65
 * @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
    66
 */
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    67
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    68
function warning($msg)
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    69
{
34
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    70
  global $use_colors;
13
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    71
  $h = @fopen('php://stderr', 'w');
34
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    72
  if ( $use_colors )
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    73
  {
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    74
    fwrite($h, "\x1B[33;1m[Greyhound] \x1B[0m\x1B[33mWarning:\x1B[0m $msg\n");
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    75
  }
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    76
  else
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    77
  {
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    78
    fwrite($h, "[Greyhound] Warning: $msg\n");
3b817b961984 Merging changes from nighthawk; added support for dumb terminals
Dan
parents: 33
diff changeset
    79
  }
13
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    80
  fclose($h);
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    81
}
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    82
b5db2345c397 Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
Dan
parents: 9
diff changeset
    83
/**
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    84
 * Performs an action with DCOP.
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    85
 * @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
    86
 * @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
    87
 * @param string additional parameters... (NOT IMPLEMENTED)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    88
 * @return mixed output of DCOP command
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
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    91
function dcop_action($component, $action)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    92
{
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    93
  $tmpfile = tempnam('amaweb', '');
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    94
  if ( !$tmpfile )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    95
    burnout('tempnam() failed us');
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    96
  system("dcop amarok $component $action > $tmpfile");
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    97
  $output = @file_get_contents($tmpfile);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    98
  @unlink($tmpfile);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    99
  $output = trim($output);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   100
  
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   101
  // detect type of output
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   102
  if ( $output == 'true' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   103
    return true;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   104
  else if ( $output == 'false' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   105
    return false;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   106
  else if ( preg_match('/^-?[0-9]+/', $output) )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   107
    return intval($output);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   108
  else
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   109
    return $output;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   110
}
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
/**
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   113
 * 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
   114
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   115
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   116
$playlist_last_md5 = '';
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   117
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   118
function rebuild_playlist()
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   119
{
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   120
  // import what we need
33
3b4aef1efff6 Removed requirement for detecting home directory; artwork fetcher relies on return from saveCurrentPlaylist now
Dan
parents: 32
diff changeset
   121
  global $playlist, $amarok_home;
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   122
  // sync and load the playlist file
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   123
  $playlist_file = dcop_action('playlist', 'saveCurrentPlaylist');
33
3b4aef1efff6 Removed requirement for detecting home directory; artwork fetcher relies on return from saveCurrentPlaylist now
Dan
parents: 32
diff changeset
   124
  // do we have amarok's home?
3b4aef1efff6 Removed requirement for detecting home directory; artwork fetcher relies on return from saveCurrentPlaylist now
Dan
parents: 32
diff changeset
   125
  if ( !$amarok_home )
3b4aef1efff6 Removed requirement for detecting home directory; artwork fetcher relies on return from saveCurrentPlaylist now
Dan
parents: 32
diff changeset
   126
    $amarok_home = dirname($playlist_file);
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   127
  // 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
   128
  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
   129
  $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
   130
  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
   131
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   132
    return true;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   133
  }
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
   134
  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
   135
  $playlist_last_md5 = $effective_md5;
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   136
  // start XML parser
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   137
  try
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
    $xml = simplexml_load_file($playlist_file);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   140
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   141
  catch ( Exception $e )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   142
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   143
    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
   144
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   145
  $attribs = $xml->attributes();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   146
  if ( @$attribs['product'] != 'Amarok' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   147
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   148
    burnout('Playlist is not in Amarok format');
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   149
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   150
  $playlist = array();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   151
  foreach ( $xml->children() as $child )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   152
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   153
    $attribs = $child->attributes();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   154
    $item = array(
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   155
        'uri'    => $attribs['uri'],
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   156
        'title'  => strval($child->Title),
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   157
        'artist' => strval($child->Artist),
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   158
        '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
   159
        '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
   160
        'length_int' => intval($child->Length)
0
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
    $playlist[] = $item;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   163
  }
32
86140ed9087d Experimental: upon change to playlist, send SIGUSR1 to parent process and branch out to all children to force a playlist refresh
Dan
parents: 16
diff changeset
   164
  // if we're a child process, signal the parent to update
86140ed9087d Experimental: upon change to playlist, send SIGUSR1 to parent process and branch out to all children to force a playlist refresh
Dan
parents: 16
diff changeset
   165
  if ( defined('HTTPD_WS_CHILD') )
86140ed9087d Experimental: upon change to playlist, send SIGUSR1 to parent process and branch out to all children to force a playlist refresh
Dan
parents: 16
diff changeset
   166
  {
86140ed9087d Experimental: upon change to playlist, send SIGUSR1 to parent process and branch out to all children to force a playlist refresh
Dan
parents: 16
diff changeset
   167
    global $httpd;
86140ed9087d Experimental: upon change to playlist, send SIGUSR1 to parent process and branch out to all children to force a playlist refresh
Dan
parents: 16
diff changeset
   168
    posix_kill($httpd->parent_pid, SIGUSR1);
86140ed9087d Experimental: upon change to playlist, send SIGUSR1 to parent process and branch out to all children to force a playlist refresh
Dan
parents: 16
diff changeset
   169
  }
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   170
}
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
/**
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
   173
 * 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
   174
 * 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
   175
 * @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
   176
 * @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
   177
 */
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
   178
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
   179
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
   180
{
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
   181
  $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
   182
  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
   183
    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
   184
  $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
   185
  $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
   186
  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
   187
  {
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
   188
    // 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
   189
    $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
   190
    $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
   191
  }
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
   192
  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
   193
}
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
   194
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
   195
/**
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   196
 * Converts a number to minute:second format
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   197
 * @param int Seconds
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   198
 * @return string format: mm:ss
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   199
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   200
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   201
function seconds_to_str($secs)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   202
{
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   203
  $seconds = $secs % 60;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   204
  $minutes = ( $secs - $seconds ) / 60;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   205
  $seconds = strval($seconds);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   206
  $minutes = strval($minutes);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   207
  if ( strlen($seconds) < 2 )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   208
    $seconds = "0$seconds";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   209
  if ( strlen($minutes) < 2 )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   210
    $minutes = "0$minutes";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   211
  return "$minutes:$seconds";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   212
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   213
4
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   214
/**
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   215
 * Loads the specified theme into Smarty
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   216
 * @param string Theme ID
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   217
 * @return object Smarty object
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   218
 */
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   219
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   220
function load_theme($theme_id)
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   221
{
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   222
  global $httpd;
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   223
  static $smarty = array();
50
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   224
  if ( $theme_id === '__free__' )
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   225
  {
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   226
    $smarty = array();
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   227
    return false;
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   228
  }
4
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   229
  if ( !isset($smarty[$theme_id]) )
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   230
  {
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   231
    $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
   232
    $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
   233
    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
   234
      @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
   235
    $smarty[$theme_id]->compile_dir  = "./compiled/$theme_id";
4
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   236
    $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
   237
    $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
   238
  }
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   239
  return $smarty[$theme_id];
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   240
}
50
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   241
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   242
/**
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   243
 * Implementation of the "which" command in native PHP.
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   244
 * @param string command
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   245
 * @return string path to executable, or false on failure
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   246
 */
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   247
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   248
function which($executable)
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   249
{
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   250
  $path = ( isset($_ENV['PATH']) ) ? $_ENV['PATH'] : ( isset($_SERVER['PATH']) ? $_SERVER['PATH'] : false );
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   251
  if ( !$path )
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   252
    // couldn't get OS's PATH
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   253
    return false;
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   254
    
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   255
  $win32 = ( PHP_OS == 'WINNT' || PHP_OS == 'WIN32' );
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   256
  $extensions = $win32 ? array('.exe', '.com', '.bat') : array('');
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   257
  $separator = $win32 ? ';' : ':';
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   258
  $paths = explode($separator, $path);
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   259
  foreach ( $paths as $dir )
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   260
  {
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   261
    foreach ( $extensions as $ext )
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   262
    {
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   263
      $fullpath = "$dir/{$executable}{$ext}";
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   264
      if ( file_exists($fullpath) && is_executable($fullpath) )
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   265
      {
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   266
        return $fullpath;
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   267
      }
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   268
    }
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   269
  }
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   270
  return false;
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   271
}
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   272
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   273
/**
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   274
 * Reload the config.
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   275
 */
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   276
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   277
function grey_reload_config()
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   278
{
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   279
  global $httpd;
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   280
  status('reloading the config');
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   281
  
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   282
  if ( file_exists('./greyhound-config.php') )
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   283
  {
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   284
    require('./greyhound-config.php');
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   285
  }
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   286
  else
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   287
  {
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   288
    // ignore this, it allows using a different config file when a Mercurial repository
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   289
    // exists in Greyhound's root directory (to allow the devs to have their own config
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   290
    // separate from the default)
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   291
    
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   292
    if ( @is_dir(GREY_ROOT . '/.hg') )
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   293
      require(GREY_ROOT . '/config.dev.php');
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   294
    else
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   295
      require(GREY_ROOT . '/config.php');
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   296
  }
52
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   297
  
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   298
  foreach ( array('public', 'allowcontrol', 'theme', 'allow_fork', 'use_auth', 'auth_data', 'configpass') as $var )
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   299
  {
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   300
    if ( isset($$var) )
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   301
    {
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   302
      $GLOBALS[$var] = $$var;
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   303
    }
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   304
  }
50
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   305
}
1b4288399b1f Added graphical configuration, at this point only for the grey theme but others will follow soon. (This has been nearly done for two weeks or more but was on hold due to the bugs with multithreading)
Dan
parents: 34
diff changeset
   306