Created
January 28, 2012 14:27
-
-
Save swvitaliy/1694510 to your computer and use it in GitHub Desktop.
Libnotify wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* libnotify.php | |
* Simple wrapper for libnotify library. Only for *nix. | |
* | |
* Author: swvitaliy | |
*/ | |
class Libnotify { | |
public static $icon_names = array( | |
'notification-audio-next', | |
'notification-audio-play', | |
'notification-audio-previous', | |
'notification-audio-volume-high', | |
'notification-audio-volume-low', | |
'notification-audio-volume-medium', | |
'notification-audio-volume-muted', | |
'notification-audio-volume-off', | |
'notification-battery-low', | |
'notification-device-eject', | |
'notification-device-firewire', | |
'notification-display-brightness-full', | |
'notification-display-brightness-high', | |
'notification-display-brightness-low', | |
'notification-display-brightness-medium', | |
'notification-display-brightness-off', | |
'notification-GSM-3G-full', | |
'notification-GSM-3G-high', | |
'notification-GSM-3G-low', | |
'notification-GSM-3G-medium', | |
'notification-GSM-3G-none', | |
'notification-GSM-disconnected', | |
'notification-GSM-EDGE-full', | |
'notification-GSM-EDGE-high', | |
'notification-GSM-EDGE-low', | |
'notification-GSM-EDGE-medium', | |
'notification-GSM-EDGE-none', | |
'notification-GSM-full', | |
'notification-GSM-H-full', | |
'notification-GSM-H-high', | |
'notification-GSM-high', | |
'notification-GSM-H-low', | |
'notification-GSM-H-medium', | |
'notification-GSM-H-none', | |
'notification-GSM-low', | |
'notification-GSM-medium', | |
'notification-GSM-none', | |
'notification-keyboard-brightness-full', | |
'notification-keyboard-brightness-high', | |
'notification-keyboard-brightness-low', | |
'notification-keyboard-brightness-medium', | |
'notification-keyboard-brightness-off', | |
'notification-message-email', | |
'notification-message-IM', | |
'notification-network-ethernet-connected', | |
'notification-network-ethernet-disconnected', | |
'notification-network-wireless-disconnected', | |
'notification-network-wireless-full', | |
'notification-network-wireless-high', | |
'notification-network-wireless-low', | |
'notification-network-wireless-medium', | |
'notification-network-wireless-none', | |
'notification-power-disconnected', | |
); | |
private static function _exec($cmd) { | |
ob_start(); | |
passthru($cmd); | |
$content_grabbed=ob_get_contents(); | |
ob_end_clean(); | |
return $content_grabbed; | |
} | |
public static function exists() { | |
return (bool)trim(self::_exec('dpkg -l | grep libnotify-bin')); | |
} | |
public static function send($summary, $body = NULL, $icon = NULL) { | |
$params = '"' . $summary . '" '; | |
if ($body !== NULL) | |
$params.= '"' . $body . '" '; | |
if ($icon !== NULL) { | |
if ( ! in_array($icon, self::$icon_names) && 0 !== strpos($icon, '/')) { | |
$icon = '"' . realpath(__DIR__ . '/' . $icon) . '" '; | |
} | |
$params.= " -i " . $icon; | |
} | |
return self::_exec('notify-send ' . $params); | |
} | |
} | |
if ( ! Libnotify::exists()) { | |
print('Please, execute sudo apt-get install libnotify-bin' . "\n" ); | |
die; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment