greyhound.php
author Dan
Sun, 23 Mar 2008 23:17:06 -0400
changeset 7 3ba432f8390b
parent 6 webcontrol.php@5f35ebc4f9bb
child 8 a8d108f37363
permissions -rwxr-xr-x
Modified to fit Amarok script specifications.

#!/usr/bin/env php
<?php

/**
 * Greyhound - real web management for Amarok
 * Copyright (C) 2008 Dan Fuhry
 *
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
 */

$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");
}