functions.php
author Dan
Sun, 23 Mar 2008 23:55:50 -0400
changeset 8 a8d108f37363
parent 6 5f35ebc4f9bb
child 9 63a257541313
permissions -rw-r--r--
Modified to trap signals properly and not write to the root directory (only working directory)
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
{
6
5f35ebc4f9bb First release version. Renamed to Greyhound and readme/license files added.
Dan
parents: 5
diff changeset
    27
  echo "\x1B[31;1m[Greyhound] fatal: \x1B[37;1m";
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    28
  echo "$msg\x1B[0m\n";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    29
  exit(1);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    30
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    31
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    32
/**
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    33
 * Print a stylized status message, compatible with Linux consoles
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    34
 * @param string Status message
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    35
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    36
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    37
function status($msg)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    38
{
6
5f35ebc4f9bb First release version. Renamed to Greyhound and readme/license files added.
Dan
parents: 5
diff changeset
    39
  echo "\x1B[32;1m[Greyhound] \x1B[32;0m$msg\x1B[0m\n";
0
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
/**
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    43
 * Performs an action with DCOP.
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    44
 * @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
    45
 * @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
    46
 * @param string additional parameters... (NOT IMPLEMENTED)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    47
 * @return mixed output of DCOP command
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    48
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    49
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    50
function dcop_action($component, $action)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    51
{
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    52
  $tmpfile = tempnam('amaweb', '');
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    53
  if ( !$tmpfile )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    54
    burnout('tempnam() failed us');
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    55
  system("dcop amarok $component $action > $tmpfile");
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    56
  $output = @file_get_contents($tmpfile);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    57
  @unlink($tmpfile);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    58
  $output = trim($output);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    59
  
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    60
  // detect type of output
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    61
  if ( $output == 'true' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    62
    return true;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    63
  else if ( $output == 'false' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    64
    return false;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    65
  else if ( preg_match('/^-?[0-9]+/', $output) )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    66
    return intval($output);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    67
  else
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    68
    return $output;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    69
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    70
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    71
/**
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    72
 * 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
    73
 */
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    74
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    75
$playlist_last_md5 = '';
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    76
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    77
function rebuild_playlist()
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    78
{
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    79
  // import what we need
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    80
  global $homedir, $playlist;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    81
  // sync and load the playlist file
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    82
  $playlist_file = dcop_action('playlist', 'saveCurrentPlaylist');
2
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    83
  // 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
    84
  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
    85
  $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
    86
  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
    87
  {
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    88
    return true;
860ba7141641 Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents: 0
diff changeset
    89
  }
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
    90
  $playlist_last_md5 = $effective_md5;
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    91
  // start XML parser
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    92
  try
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    93
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    94
    $xml = simplexml_load_file($playlist_file);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    95
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    96
  catch ( Exception $e )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    97
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
    98
    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
    99
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   100
  $attribs = $xml->attributes();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   101
  if ( @$attribs['product'] != 'Amarok' )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   102
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   103
    burnout('Playlist is not in Amarok format');
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   104
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   105
  $playlist = array();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   106
  foreach ( $xml->children() as $child )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   107
  {
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   108
    $attribs = $child->attributes();
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   109
    $item = array(
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   110
        'uri'    => $attribs['uri'],
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   111
        'title'  => strval($child->Title),
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   112
        'artist' => strval($child->Artist),
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   113
        '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
   114
        '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
   115
        'length_int' => intval($child->Length)
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   116
      );
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   117
    $playlist[] = $item;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   118
  }
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   119
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   120
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   121
/**
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
   122
 * 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
   123
 * 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
   124
 * @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
   125
 * @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
   126
 */
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
   127
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
   128
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
   129
{
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
  $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
   131
  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
   132
    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
   133
  $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
   134
  $matches = implode("", $matches[1]);
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   135
  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
   136
}
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
   137
9b96265b5918 Relicensed to GPLv2. Previous revisions should not be downloaded as they do not contain copies of appropriate licenses, which will be added in a later commit. Completed interface for mobile devices.
Dan
parents: 4
diff changeset
   138
/**
0
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   139
 * Converts a number to minute:second format
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   140
 * @param int Seconds
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   141
 * @return string format: mm:ss
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
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   144
function seconds_to_str($secs)
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   145
{
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   146
  $seconds = $secs % 60;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   147
  $minutes = ( $secs - $seconds ) / 60;
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   148
  $seconds = strval($seconds);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   149
  $minutes = strval($minutes);
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   150
  if ( strlen($seconds) < 2 )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   151
    $seconds = "0$seconds";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   152
  if ( strlen($minutes) < 2 )
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   153
    $minutes = "0$minutes";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   154
  return "$minutes:$seconds";
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   155
}
c63de9eb7045 First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff changeset
   156
4
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   157
/**
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   158
 * Loads the specified theme into Smarty
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   159
 * @param string Theme ID
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   160
 * @return object Smarty object
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   161
 */
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   162
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   163
function load_theme($theme_id)
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   164
{
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   165
  global $httpd;
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   166
  static $smarty = array();
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   167
  if ( !isset($smarty[$theme_id]) )
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   168
  {
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   169
    $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
   170
    $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
   171
    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
   172
      @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
   173
    $smarty[$theme_id]->compile_dir  = "./compiled/$theme_id";
4
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   174
    $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
   175
    $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
   176
  }
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   177
  return $smarty[$theme_id];
cde92f6ec29f Should be completely iPhone/iPod Touch-friendly now :)
Dan
parents: 2
diff changeset
   178
}