Source Code

00001: <?php
00002: /**
00003:  * URL callbacks example
00004:  * that send notifications to Growl using the new GNTP/1.0 protocol
00005:  *
00006:  * The callback url will be opened in the user's default browser.
00007:  * Unlike socket callbacks, URL callbacks are only triggered if the notification
00008:  * is clicked (CLICK|CLICKED), not for CLOSE|CLOSED or TIMEOUT|TIMEDOUT actions.
00009:  *
00010:  * PHP version 5
00011:  *
00012:  * @category Networking
00013:  * @package  Net_Growl
00014:  * @author   Laurent Laville <pear@laurent-laville.org>
00015:  * @author   Bertrand Mansion <bmansion@mamasam.com>
00016:  * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
00017:  * @version  CVS: Release: @package_version@
00018:  * @link     http://growl.laurent-laville.org/
00019:  * @since    File available since Release 2.0.0b2
00020:  */
00021:
00022: require_once 'Net/Growl.php';
00023:
00024: // Notification Type definitions
00025: define('GROWL_NOTIFY_STATUS', 'GROWL_NOTIFY_STATUS');
00026: define('GROWL_NOTIFY_PHPERROR', 'GROWL_NOTIFY_PHPERROR');
00027:
00028: // define a PHP application that sends notifications to Growl
00029:
00030: $app = new Net_Growl_Application(
00031:     'PHP App Example using GNTP',
00032:     array(
00033:         GROWL_NOTIFY_STATUS => array(
00034:             'display' => 'Status',
00035:         ),
00036:
00037:         GROWL_NOTIFY_PHPERROR => array(
00038:             'icon' => 'http://www.laurent-laville.org/growl/images/firephp.png',
00039:             'display' => 'Error-Log'
00040:         )
00041:     ),
00042:     'mamasam'
00043: );
00044:
00045:
00046: try {
00047:     $growl = Net_Growl::singleton(
00048:         $app,
00049:         null, null,
00050:         array(
00051:             'host'     => '192.168.1.2',
00052:             'protocol' => 'tcp', 'port' => Net_Growl::GNTP_PORT,
00053:             'AppIcon'  => 'http://www.laurent-laville.org/growl/images/Help.png',
00054:             'encryptionAlgorithm'   => 'AES',
00055:             'passwordHashAlgorithm' => 'SHA256',
00056:             'debug' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'netgrowl.log'
00057:         )
00058:     );
00059:     $growl->register();
00060:
00061:     $name        = GROWL_NOTIFY_STATUS;
00062:     $title       = 'Congratulation';
00063:     $description = "Congratulation! You are successfull install PHP/NetGrowl.";
00064:     $options     = array(
00065:         'ID'                  => 123456,
00066:         'CallbackContext'     => 'this is my context',
00067:         'CallbackContextType' => 'STRING',
00068:         'CallbackTarget'      => 'http://growl.laurent-laville.org/parseUrl.php'
00069:                                . '?hello=world',
00070:         'sticky'              => true,
00071:     );
00072:     $growl->notify($name, $title, $description, $options);
00073:
00074:     $name        = GROWL_NOTIFY_PHPERROR;
00075:     $title       = 'PHP Error';
00076:     $description = 'You have a new PHP error in your script P at line N';
00077:     $options     = array(
00078:         'priority' => Net_Growl::PRIORITY_HIGH,
00079:     );
00080:     $growl->notify($name, $title, $description, $options);
00081:
00082:     $name        = GROWL_NOTIFY_STATUS;
00083:     $title       = 'Welcome';
00084:     $description = "Welcome in PHP/GNTP world ! \n"
00085:                  . "New GNTP protocol add icon support.";
00086:     $options     = array(
00087:         'icon'   => 'http://www.laurent-laville.org/growl/images/unknown.png',
00088:         'sticky' => false,
00089:     );
00090:     $growl->notify($name, $title, $description, $options);
00091:
00092:     var_export($growl);
00093:
00094: } catch (Net_Growl_Exception $e) {
00095:     echo 'Caught Growl exception: ' . $e->getMessage() . PHP_EOL;
00096: }
00097: ?>