/** * Create the dbus-object & -proxy */ public function __construct() { if (extension_loaded('dbus') === true) { $oDbus = new \Dbus(\Dbus::BUS_SESSION, true); $this->_oProxy = $oDbus->createProxy('org.freedesktop.Notifications', '/org/freedesktop/Notifications', 'org.freedesktop.Notifications'); } }
protected function notify($title, $message) { if (!class_exists('Dbus', false)) { return; } $d = new \Dbus(\Dbus::BUS_SESSION); $n = $d->createProxy('org.freedesktop.Notifications', '/org/freedesktop/Notifications', 'org.freedesktop.Notifications'); $n->Notify('Twircd_Util_DbusLog', new \DBusUInt32(0), 'twircd', "TwIRCd: " . $title, $message, new \DBusArray(\DBus::STRING, array()), new \DBusDict(\DBus::VARIANT, array()), 1500); }
/** * @return bool * @see http://derickrethans.nl/talks/dbus-ipc10s.pdf * @throws \BadFunctionCallException */ public function send() { if (!extension_loaded('dbus')) { throw new \BadFunctionCallException('dbus extension is not available'); } $dbus = new \Dbus(\Dbus::BUS_SESSION); $notification = $dbus->createProxy("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications"); $id = $notification->Notify($this->appName, new \DBusUInt32(0), $this->icon, $this->summary, $this->body, new \DBusArray(\DBus::STRING, array()), new \DBusDict(\DBus::VARIANT, array()), 1000); return $id > 0; }
/** * Is called when PDepend has finished the logging process. * * @return void */ public function endLogProcess() { if (extension_loaded('dbus') === false) { return; } $dbus = new Dbus(Dbus::BUS_SESSION); $proxy = $dbus->createProxy("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications"); $proxy->Notify('PDepend', new DBusUInt32(0), 'pdepend', 'PDepend', sprintf('%d files analyzed in %s minutes...', $this->parsedFiles, date('i:s', time() - $this->startTime)), new DBusArray(DBus::STRING, array()), new DBusDict(DBus::VARIANT, array()), 1000); }
<?php require_once 'vendor/autoload.php'; class SkypeBot { static function notify($a) { global $n; $engine = new \Inviqa\SkypeEngine($n); try { $engine->parse($a); } catch (Exception $e) { echo $e->getMessage() . PHP_EOL; } } } $d = new Dbus(Dbus::BUS_SESSION, true); $n = $d->createProxy("com.Skype.API", "/com/Skype", "com.Skype.API"); $n->Invoke("NAME PHP"); $n->Invoke("PROTOCOL 7"); $d->registerObject('/com/Skype/Client', 'com.Skype.API.Client', 'SkypeBot'); do { $s = $d->waitLoop(1000); } while (true);
/** * */ protected function notify() { $d = new Dbus(Dbus::BUS_SESSION); $n = $d->createProxy('org.freedesktop.Notifications', '/org/freedesktop/Notifications', 'org.freedesktop.Notifications'); $n->Notify('PHPUnit_Util_Log_DBUS', new DBusUInt32(0), 'phpunit', 'PHPUnit Test Report', sprintf("Suite: %s\n%d tests run in %s minutes.\n%d errors, %d failures", $this->suiteName, $this->tests, date('i:s', time() - $this->startTime), $this->errors, $this->failures), new DBusArray(DBus::STRING, array()), new DBusDict(DBus::VARIANT, array()), 1000); }
$pt = new patterns(); Define('DEVIDER', 'и'); $last_day = date('d-M-y'); $last_minute = date('H:i'); $old_message = $latest_message = ''; $tmp = SQLSelectOne("SELECT * FROM shouts WHERE MEMBER_ID = 0 ORDER BY ADDED DESC"); $latest_message = $tmp['MESSAGE']; $old_message = $latest_message; //проверяем, запущен ли Скайп. Если нет - пока вываливаемся //Инициализируем Dbus $dbus = new Dbus(Dbus::BUS_SESSION, true); //Попытка вызова методов. Если ошибка - значит нам не удалось к скайпу подключиться for ($i = 0; $i < 5; $i++) { try { //Подключаемся к скайпу $n = $dbus->createProxy('com.Skype.API', '/com/Skype', 'com.Skype.API'); //Имя нашей программы, авторизация в скайпе $n->Invoke('NAME MajorDoMo'); //Используем последний протокол $n->Invoke('PROTOCOL 8'); break; } catch (Exception $e) { DebMes('Skype error : ' . $e->getCode() . '. Error message: ' . $e->getMessage()); $n = null; } sleep(5); } if (i >= 5) { $n = $dbus = null; DebMes('Skype error : 5 попыток'); $db->Disconnect();
<?php $dbus = new Dbus(Dbus::BUS_SESSION); $interface = "im.pidgin.purple.PurpleInterface"; $method = "ReceivedImMsg"; $dbus->addWatch($interface, $method); $proxy = $dbus->createProxy("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject", "im.pidgin.purple.PurpleInterface"); $kill = false; do { $signal = $dbus->waitLoop(1000); if ($signal instanceof DbusSignal) { if ($signal->matches($interface, $method)) { /** * Contents of the recieved data, see: * http://developer.pidgin.im/doxygen/dev/html/pages.html * http://developer.pidgin.im/doxygen/dev/html/conversation-signals.html * data: * 0 => the reciever account * 1 => the user sending the message * 2 => the message * 3 => the IM conversation * 4 => flags */ $data = $signal->getData()->getData(); $receiver = $data[0]; $sender = $data[1]; $message = $data[2]; $conversation = $data[3]; $responseMessage = "I'm sorry Dave. I'm affraid I can't do that."; // 2034 is *my* account's number, yours will be different // 3681 is the account number from which *I* accept messages
<?php $content = implode(file("ui.html"), ""); //tell astrologic to start streaming $dbus = new Dbus(Dbus::BUS_SYSTEM); $proxy = $dbus->createProxy("info.echord.Astromobile.AstroLogic", "/AstroLogic", "info.echord.Astromobile.AstroLogic"); $proxy->startWebVideo(); //display locations for navigation requests $locations = $proxy->getLocations(); $locationSelector = '<select name="location" id="locationSelector">'; foreach ($locations->getData() as $loc) { $locationSelector .= '<option value="' . $loc . '" >' . $loc . '</option>'; } $locationSelector .= '<option value="User">User</option>'; $locationSelector .= '</select>'; $content = preg_replace("/{{locationselector}}/i", $locationSelector, $content); echo $content;
<?php $d = new Dbus(); $n = $d->createProxy("org.gnome.ScreenSaver", "/org/gnome/ScreenSaver", "org.gnome.ScreenSaver"); var_dump($n->GetActive()); $n->SetActive(true); var_dump($n->GetActive()); sleep(5); $n->SetActive(false); ?>
# En Windows habilitar COM en php.ini: extension=c:\PHP\ext\php_com_dotnet.dll # Para Linux instalar: sudo pecl install dbus-0.1.1 # Registrar/iniciar python controlador.py --register (Windows), --dbus (Linux) error_reporting(-1); try { # Crear objeto interface con el componente del controlador fiscal: if (@class_exists('COM')) { echo "creando interface ..."; $ctrl = new COM('PyFiscalPrinter') or die("No se puede crear el objeto"); echo "interface creada version {$ctrl->Version}\n"; # habilitar excecpciones (capturarlas con un bloque try/except), ver abajo: $ctrl->LanzarExcepciones = true; } else { if (@class_exists('Dbus')) { $dbus = new Dbus(Dbus::BUS_SESSION, true); $ctrl = $dbus->createProxy("ar.com.pyfiscalprinter.Service", "/ar/com/pyfiscalprinter/Object", "ar.com.pyfiscalprinter.Interface"); } else { echo "No existe soporte para COM (Windows) o DBus (Linux) \n"; exit(1); } } # Iniciar conexión con el controlador fiscal: $marca = "epson"; // configurar "hasar" o "epson" $modelo = "epsonlx300+"; // "tickeadoras", "epsonlx300+", "tm-220-af" // "615", "715v1", "715v2", "320" $puerto = "dummy"; // "COM1", "COM2", etc. o "/dev/ttyS0" en linux $equipo = ""; // IP si no esta conectada a esta máquina
private function _notify() { if (extension_loaded('dbus') === false) { return; } $d = new Dbus(Dbus::BUS_SESSION); $n = $d->createProxy("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications"); $n->Notify('Whitewashing_PHPUnit', new DBusUInt32(0), 'phpunit', 'PHPUnit Test-Run Report', sprintf("Suite: %s\n%d tests run in %s minutes.\n%d errors, %d failures...", $this->_suiteName, $this->_tests, date('i:s', time() - $this->_startTime), $this->_errors, $this->_failures), new DBusArray(DBus::STRING, array()), new DBusDict(DBus::VARIANT, array()), 1000); }
<?php define('NM', "org.freedesktop.NetworkManager"); $d = new Dbus(Dbus::BUS_SYSTEM, true); $n = $d->createProxy(NM, "/org/freedesktop/NetworkManager", NM); $wifi = array(); foreach ($n->GetDevices()->getData() as $device) { $device = $device->getData(); $dev = $d->createProxy(NM, $device, "org.freedesktop.DBus.Properties"); $type = $dev->Get(NM . ".Device", "DeviceType")->getData(); if ($type == 2) { $wifiDev = $d->createProxy(NM, $device, NM . ".Device.Wireless"); foreach ($wifiDev->GetAccessPoints()->getData() as $ap) { $apDev = $d->createProxy(NM, $ap->getData(), "org.freedesktop.DBus.Properties"); $props = $apDev->GetAll(NM . ".AccessPoint")->getData(); $ssid = ''; foreach ($props['Ssid']->getData()->getData() as $n) { $ssid .= chr($n); } $wifi[] = array('ssid' => $ssid, "mac_address" => $props['HwAddress']->getData()); } } } $request = array('version' => '1.1.0', 'host' => 'example.com', 'wifi_towers' => $wifi); $c = curl_init(); curl_setopt($c, CURLOPT_URL, 'https://www.google.com/loc/json'); curl_setopt($c, CURLOPT_POST, 1); curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($request)); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); $result = json_decode(curl_exec($c))->location; echo "<a href='http://openstreetmap.org/?lat={$result->latitude}&lon={$result->longitude}&zoom=18'>here</a>\n";
<?php $d = new Dbus(Dbus::BUS_SESSION); $n = $d->createProxy("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications"); $id = $n->Notify('Testapp', new DBusUInt32(0), 'iceweasel', 'Testing http://ez.no', 'Test Notification', new DBusArray(DBus::STRING, array()), new DBusDict(DBus::VARIANT, array('x' => new DBusVariant(500), 'y' => new DBusVariant(500), 'desktop-entry' => new DBusVariant('rhythmbox'))), 1000); echo $id[0], "\n";
<?php $dbus = new Dbus(); $proxy = $dbus->createProxy("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject", "org.freedesktop.DBus.Introspectable"); $data = $proxy->Introspect(); file_put_contents('introspect.xml', $data);