00001: <?php
00002: /**
00003: * Socket callbacks example
00004: * that send notifications to Growl using the new GNTP/1.0 protocol
00005: *
00006: * Callbacks are sent back to the sending application
00007: * when an action is taken in response to a notification.
00008: *
00009: * PHP version 5
00010: *
00011: * @category Networking
00012: * @package Net_Growl
00013: * @author Laurent Laville <pear@laurent-laville.org>
00014: * @author Bertrand Mansion <bmansion@mamasam.com>
00015: * @license http://www.opensource.org/licenses/bsd-license.php BSD
00016: * @version CVS: Release: @package_version@
00017: * @link http://growl.laurent-laville.org/
00018: * @since File available since Release 2.0.0b2
00019: */
00020:
00021: require_once 'Net/Growl.php';
00022:
00023: /**
00024: * Callback function when notification response is returned
00025: *
00026: * @param string $result Notification-Callback-Result: header, result
00027: * [CLICKED|CLOSED|TIMEDOUT] | [CLICK|CLOSE|TIMEOUT]
00028: * @param string $context Notification-Callback-Context: header, result
00029: * from the original request
00030: * @param string $type Notification-Callback-Context-Type: header, result
00031: * from the original request
00032: * @param string $timestamp Notification-Callback-Timestamp: header, result
00033: * The date and time the callback occurred
00034: *
00035: * @return void
00036: */
00037: function cbNotify($result, $context, $type, $timestamp)
00038: {
00039: printf(
00040: "Notification Callback Result => %s: %s (%s) at %s \n\n",
00041: $result, $context, $type, $timestamp
00042: );
00043: }
00044:
00045: // Notification Type definitions
00046: define('GROWL_NOTIFY_STATUS', 'GROWL_NOTIFY_STATUS');
00047: define('GROWL_NOTIFY_PHPERROR', 'GROWL_NOTIFY_PHPERROR');
00048:
00049: // define a PHP application that sends notifications to Growl
00050:
00051: $appName = 'PHP App Example using GNTP';
00052: $notifications = array(
00053: GROWL_NOTIFY_STATUS => array(
00054: 'display' => 'Status',
00055: ),
00056:
00057: GROWL_NOTIFY_PHPERROR => array(
00058: 'icon' => 'http://www.laurent-laville.org/growl/images/firephp.png',
00059: 'display' => 'Error-Log'
00060: )
00061: );
00062:
00063: $password = 'mamasam';
00064: $options = array(
00065: 'host' => '192.168.1.2',
00066: 'protocol' => 'tcp', 'port' => Net_Growl::GNTP_PORT,
00067: 'AppIcon' => 'http://www.laurent-laville.org/growl/images/Help.png',
00068: 'debug' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'netgrowl.log'
00069: );
00070:
00071: try {
00072: $growl = Net_Growl::singleton($appName, $notifications, $password, $options);
00073: $growl->register();
00074:
00075: $name = GROWL_NOTIFY_STATUS;
00076: $title = 'Congratulation';
00077: $description = 'Congratulation! You are successfull install PHP/NetGrowl.';
00078: $options = array(
00079: 'ID' => 123456,
00080: 'CallbackContext' => 'this is my context',
00081: 'CallbackContextType' => 'STRING',
00082: 'CallbackFunction' => 'cbNotify'
00083: );
00084: $growl->notify($name, $title, $description, $options);
00085:
00086: $name = GROWL_NOTIFY_PHPERROR;
00087: $title = 'PHP Error';
00088: $description = 'You have a new PHP error in your script P at line N';
00089: $options = array(
00090: 'priority' => Net_Growl::PRIORITY_HIGH,
00091: );
00092: $growl->notify($name, $title, $description, $options);
00093:
00094: $name = GROWL_NOTIFY_STATUS;
00095: $title = 'Welcome';
00096: $description = "Welcome in PHP/GNTP world ! \n"
00097: . "New GNTP protocol add icon support.";
00098: $options = array(
00099: 'icon' => 'http://www.laurent-laville.org/growl/images/unknown.png',
00100: 'sticky' => false,
00101: );
00102: $growl->notify($name, $title, $description, $options);
00103:
00104: var_export($growl);
00105:
00106: } catch (Net_Growl_Exception $e) {
00107: echo 'Caught Growl exception: ' . $e->getMessage() . PHP_EOL;
00108: }
00109: ?>