functions.php
author Dan
Tue, 26 May 2009 15:26:59 -0400
changeset 72 b8730fcd64a9
parent 69 73780a159e15
child 74 7719085707d8
permissions -rw-r--r--
Some UI changes I don't feel like auditing over and over until I understand (commiting some very old changes here)
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
{
69
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
    93
  file_put_contents('php://stderr', "[dcop] start...");
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
    94
  if ( function_exists('proc_open') )
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
    95
  {
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
    96
    $descriptorspec = array(
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
    97
        0 => array('pipe', 'r'),
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
    98
        1 => array('pipe', 'w'),
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
    99
        2 => array('pipe', 'w')
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   100
      );
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   101
    $dcop_command = "dcop amarok $component $action";
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   102
    $dcop_process = proc_open($dcop_command, $descriptorspec, $dcop_pipes);
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   103
    do
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   104
    {
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   105
      $status = proc_get_status($dcop_process);
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   106
      usleep(2000);
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   107
    } while ( $status['running'] );
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   108
    pcntl_waitpid($status['pid'], $status);
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   109
    $output = fgets($dcop_pipes[1], 1024);
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   110
    proc_close($dcop_process);
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   111
  }
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   112
  else
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   113
  {
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   114
    $tmpfile = tempnam('amaweb', '');
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   115
    if ( !$tmpfile )
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   116
      burnout('tempnam() failed us');
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   117
    
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   118
    // This is freezing up for some reason.
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   119
    system("dcop amarok $component $action > $tmpfile");
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   120
    $output = @file_get_contents($tmpfile);
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   121
    @unlink($tmpfile);
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   122
  }
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   123
  file_put_contents('php://stderr', "got it...\r");
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   124
  $output = trim($output);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   125
  
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   126
  // detect type of output
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   127
  if ( $output == 'true' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   128
    return true;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   129
  else if ( $output == 'false' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   130
    return false;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   131
  else if ( preg_match('/^-?[0-9]+/', $output) )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   132
    return intval($output);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   133
  else
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   134
    return $output;
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
/**
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   138
 * 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
   139
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   140
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   141
$playlist_last_md5 = '';
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   142
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   143
function rebuild_playlist()
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
  // 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
   146
  global $playlist, $amarok_home;
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   147
  // sync and load the playlist file
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   148
  $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
   149
  // 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
   150
  if ( !$amarok_home )
3b4aef1efff6 Removed requirement for detecting home directory; artwork fetcher relies on return from saveCurrentPlaylist now
Dan
parents: 32
diff changeset
   151
    $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
   152
  // 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
   153
  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
   154
  $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
   155
  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
   156
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   157
    return true;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
   158
  }
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
   159
  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
   160
  $playlist_last_md5 = $effective_md5;
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   161
  // start XML parser
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   162
  try
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   163
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   164
    $xml = simplexml_load_file($playlist_file);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   165
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   166
  catch ( Exception $e )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   167
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   168
    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
   169
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   170
  $attribs = $xml->attributes();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   171
  if ( @$attribs['product'] != 'Amarok' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   172
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   173
    burnout('Playlist is not in Amarok format');
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   174
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   175
  $playlist = array();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   176
  foreach ( $xml->children() as $child )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   177
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   178
    $attribs = $child->attributes();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   179
    $item = array(
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   180
        'uri'    => $attribs['uri'],
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   181
        'title'  => strval($child->Title),
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   182
        'artist' => strval($child->Artist),
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   183
        '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
   184
        '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
   185
        'length_int' => intval($child->Length)
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   186
      );
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   187
    $playlist[] = $item;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   188
  }
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
   189
  // 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
   190
  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
   191
  {
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
   192
    global $httpd;
69
73780a159e15 DCOP: added safeguards for mysterious zombie behavior
Dan
parents: 64
diff changeset
   193
    posix_kill($httpd->parent_pid, SIGHUP);
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
   194
  }
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   195
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   196
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   197
/**
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
   198
 * 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
   199
 * 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
   200
 * @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
   201
 * @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
   202
 */
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
   203
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
   204
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
   205
{
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
   206
  $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
   207
  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
   208
    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
   209
  $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
   210
  $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
   211
  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
   212
  {
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
   213
    // 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
   214
    $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
   215
    $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
   216
  }
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
   217
  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
   218
}
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
   219
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
   220
/**
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   221
 * Converts a number to minute:second format
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   222
 * @param int Seconds
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   223
 * @return string format: mm:ss
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   224
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   225
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   226
function seconds_to_str($secs)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   227
{
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   228
  $seconds = $secs % 60;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   229
  $minutes = ( $secs - $seconds ) / 60;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   230
  $seconds = strval($seconds);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   231
  $minutes = strval($minutes);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   232
  if ( strlen($seconds) < 2 )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   233
    $seconds = "0$seconds";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   234
  if ( strlen($minutes) < 2 )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   235
    $minutes = "0$minutes";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   236
  return "$minutes:$seconds";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   237
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   238
4
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   239
/**
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   240
 * Loads the specified theme into Smarty
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   241
 * @param string Theme ID
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   242
 * @return object Smarty object
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   243
 */
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   244
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   245
function load_theme($theme_id)
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   246
{
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   247
  global $httpd;
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   248
  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
   249
  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
   250
  {
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
    $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
   252
    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
   253
  }
4
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   254
  if ( !isset($smarty[$theme_id]) )
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   255
  {
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   256
    $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
   257
    $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
   258
    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
   259
      @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
   260
    $smarty[$theme_id]->compile_dir  = "./compiled/$theme_id";
4
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   261
    $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
   262
    $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
   263
  }
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   264
  return $smarty[$theme_id];
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   265
}
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
   266
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
 * 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
   269
 * @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
   270
 * @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
   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
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
   274
{
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
  $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
   276
  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
   277
    // 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
   278
    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
   279
    
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
  $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
   281
  $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
   282
  $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
   283
  $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
   284
  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
   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
    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
   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
      $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
   289
      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
   290
      {
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
        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
   292
      }
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
    }
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
  }
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
  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
   296
}
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
   297
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
   298
/**
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
   299
 * 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
   300
 */
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
   301
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
   302
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
   303
{
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
   304
  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
   305
  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
   306
  
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
   307
  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
   308
  {
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
   309
    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
   310
  }
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
   311
  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
   312
  {
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
   313
    // 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
   314
    // 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
   315
    // 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
   316
    
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
   317
    if ( @is_dir(GREY_ROOT . '/.hg') )
64
ee64bb096f56 A few miscellaneous fixes including modifying WebServer to write data in chunks (improved performance and reliability on a slow connection)
Dan
parents: 57
diff changeset
   318
    {
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
   319
      require(GREY_ROOT . '/config.dev.php');
64
ee64bb096f56 A few miscellaneous fixes including modifying WebServer to write data in chunks (improved performance and reliability on a slow connection)
Dan
parents: 57
diff changeset
   320
    }
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
   321
    else
64
ee64bb096f56 A few miscellaneous fixes including modifying WebServer to write data in chunks (improved performance and reliability on a slow connection)
Dan
parents: 57
diff changeset
   322
    {
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
   323
      require(GREY_ROOT . '/config.php');
64
ee64bb096f56 A few miscellaneous fixes including modifying WebServer to write data in chunks (improved performance and reliability on a slow connection)
Dan
parents: 57
diff changeset
   324
    }
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
   325
  }
52
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   326
  
57
31ce64a3ff6c Some backend changes to webserver to allow IPv6 binding
Dan
parents: 52
diff changeset
   327
  foreach ( array('public', 'enable_ipv4', 'enable_ipv6', 'allowcontrol', 'theme', 'allow_fork', 'use_auth', 'auth_data', 'configpass') as $var )
52
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   328
  {
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   329
    if ( isset($$var) )
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   330
    {
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   331
      $GLOBALS[$var] = $$var;
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   332
    }
ab3541465382 Fixed globals from config file not being properly loaded from grey_reload_config()
Dan
parents: 50
diff changeset
   333
  }
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
   334
}
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
   335