webcontrol.php
author Dan
Sun, 23 Mar 2008 15:24:06 -0400
changeset 1 cddc2ba706d6
parent 0 c63de9eb7045
child 2 860ba7141641
permissions -rw-r--r--
Preliminary groundwork for AJAX interface

<?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 = false;
$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('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 = mt_rand(1025, 65534); // 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('scripts', 'dir', './scripts');
  $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");
}