//Sample Shell PHP program for talking to the Skype API
//Requires ActiveX support, and hence PHP on Windows

<?php

class _ISkypeEvents {
  var $terminated = false;
  var $attached = false;

  function ApplicationConnecting( &$pApp, &$pUsers ) {
    /* Fired on application connecting users change. */
  }

  function ApplicationDatagram( &$pApp, &$pStream, $Text ) {
    /* Fired on application datagram. */
  }

  function ApplicationReceiving( &$pApp, &$pStreams )  {
    /* Fired on application receiving data. */
  }

  function ApplicationSending( &$pApp, &$pStreams ) {
    /* Fired on application sending data. */
  }

  function ApplicationStreams( &$pApp, &$pStreams ) {
    /* Fired on application streams change. */
  }

  function AttachmentStatus($status) {
    /* Fired on attachment status change. */
    if ($status == 0) {
      $this->attached = true;
    }
  }
  
  function AutoAway( $Automatic ) {
    /* Fired on auto away status change. */
  }

  function CallDtmfReceived( &$pCall, $code ) {
    /* Fired on call dtmf pressed. */
  }

  function CallHistory() {
    /* Fired on call history change. */
  }

  function CallStatus( &$pCall, $Status ) {
    /* Fired on call status change. */
  }

  function Command( &$pCommand ) {
    /* Fired on Skype API command message. */
  }

  function ConnectionStatus( $Status ) {
    /* Fired on connection status change. */
  }

  function ContactsFocused( $UserHandle ) {
    /* Fired on contacts focus received or lost. */
  }

  function Error( &$pCommand, $Number, $Description ) {
    /* Fired on Skype API error message. */
  }

  function GroupDeleted($GroupId ) {
    /* Fired when group is deleted. */
  }

  function GroupExpanded( &$pGroup, $Expanded ) {
    /* Fired on group selection status change. */
  }

  function GroupUsers( &$pGroup, &$pUsers ) {
    /* Fired on group user list change. */
  }

  function GroupVisible( &$pGroup, $Visible ) {
    /* Fired on group visibility status change. */
  }

  function MessageHistory( $Username ) {
    /* Fired on message history change. */
  }

  function MessageStatus( &$pMessage, $Status ) {
    /* Fired on message status change. */
  }

  function Mute( $Mute )  {
    /* Fired on mute status change. */
  }

  function OnlineStatus( &$pUser, $Status ) {
    /* Fired on user online status change. */
  }

  function Reply( &$pCommand ) {
    /* Fired on Skype API reply message. */
  }

  function UserStatus( $Status ) {
    /* Fired on user status change. */
  }

  function UserMood( &*pUser, $MoodText) {
    /* Fired on user status change. */
  }

  function VoicemailStatus( &$pMail, $Status ) {
    /* Fired on voicemail status change. */
  }
} //_ISkypeEvents

// Create skype object
$skype = new COM("Skype4COM.Skype");

// Create sink object
$sink =& new _ISkypeEvents($com);

// Connect to sink
com_event_sink($skype, $sink, "_ISkypeEvents");

// Start minimized and without splash screen
if (!$skype->client()->isRunning()) {
  $skype->client()->start(true, true);
}

print "start attach";
//Attach to Skype
$skype->attach(5,false);

//process messages to catch the attachment
com_message_pump(1000);

//Main Loop
if ($sink->attached) {

  //Do initialisation here

  //Message loop. Set $sink->terminated to true to quit
  while(!$sink->terminated) {
    com_message_pump(1);
  }
}

//clear up
$skype = null;

?>