webcontrol.php
author Dan
Sun, 23 Mar 2008 22:03:57 -0400
changeset 4 cde92f6ec29f
parent 3 e7447a6044ec
child 5 9b96265b5918
permissions -rw-r--r--
Should be completely iPhone/iPod Touch-friendly now :)

<?php

/**
 * Web control interface script for Amarok
 * Written by Dan Fuhry - 2008
 *
 * This script is in the public domain. Use it for good, not evil.
 */

$public = true;
$allowcontrol = true;
$theme = 'funkymonkey';

@ini_set('display_errors', 'on');

// include files
require('functions.php');

// start up...

status('Starting WebControl v0.1-hg');
status('loading files');

require('webserver.php');
define('SMARTY_DIR', './smarty/');
require('smarty/Smarty.class.php');
require('playlist.php');
require('json.php');
require('ajax.php');

status('initializing Smarty');
$smarty = new Smarty();
$smarty->template_dir = "./themes/$theme";
$smarty->compile_dir = "./themes/$theme/compiled";
$smarty->cache_dir = "./cache";
$smarty->config_dir = "./config";

status('doing home directory detection');

// get home directory

if ( !isset($_ENV['HOME']) )
{
  burnout('Could not get your home directory');
}

$homedir =& $_ENV['HOME'];

status('initializing playlist');

// init playlist object
$playlist = array();
rebuild_playlist();

// startup webserver
$ip = ( $public ) ? '0.0.0.0' : '127.0.0.1';
$port = 7447;

try
{
  status('starting PhpHttpd');
  $httpd = new WebServer($ip, $port);
  
  // setup handlers
  status('initializing handlers');
  $httpd->add_handler('index', 'function', 'amarok_playlist');
  $httpd->add_handler('action.json', 'function', 'ajax_request_handler');
  $httpd->add_handler('scripts', 'dir', './scripts');
  $httpd->add_handler('favicon.ico', 'file', './amarok_icon.ico');
  $httpd->add_handler('apple-touch-icon.png', 'file', './apple-touch-icon.png');
  $httpd->add_handler("themes/$theme", 'dir', "./themes/$theme");
  $httpd->allow_dir_list = true;
  $httpd->default_document = 'index';
  
  status("Entering main server loop - ^C to interrupt, listening on port $port");
  $httpd->serve();
}
catch( Exception $e )
{
  burnout("Exception caught while running webserver:\n$e");
}