/** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown() { // Delete activities foreach ($this->juliet->getActivities($this->julietJID) as $activity) { $this->juliet->deleteActivity($activity->id); } foreach ($this->alice->getActivities($this->aliceJID) as $activity) { $this->alice->deleteActivity($activity->id); } foreach ($this->romeo->getActivities($this->romeoJID) as $activity) { $this->romeo->deleteActivity($activity->id); } $this->alice->disconnect(); $this->juliet->disconnect(); $this->romeo->disconnect(); $this->deleteUser('testalice', 'secretAlice'); // TODO Workaround because of testRemove() try { $this->deleteUser('testjuliet', 'secretJuliet'); } catch (\Exception $e) { } $this->deleteUser('testromeo', 'secretRomeo'); }
/** * Jaxl core constructor * * Jaxl instance configures itself using the constants inside your application jaxl.ini. * However, passed array of configuration options overrides the value inside jaxl.ini. * If no configuration are found or passed for a particular value, * Jaxl falls back to default config options. * * @param $config Array of configuration options * @todo Use DNS SRV lookup to set $jaxl->host from provided domain info */ function __construct($config = array()) { global $jaxl_instance_cnt; parent::__construct($config); $this->uid = ++$jaxl_instance_cnt; $this->ip = gethostbyname(php_uname('n')); $this->config = $config; $this->pid = getmypid(); /* Mandatory params to be supplied either by jaxl.ini constants or constructor $config array */ $this->user = $this->getConfigByPriority(@$config['user'], "JAXL_USER_NAME", $this->user); $this->pass = $this->getConfigByPriority(@$config['pass'], "JAXL_USER_PASS", $this->pass); $this->domain = $this->getConfigByPriority(@$config['domain'], "JAXL_HOST_DOMAIN", $this->domain); $this->bareJid = $this->user . "@" . $this->domain; /* Optional params if not configured using jaxl.ini or $config take default values */ $this->host = $this->getConfigByPriority(@$config['host'], "JAXL_HOST_NAME", $this->domain); $this->port = $this->getConfigByPriority(@$config['port'], "JAXL_HOST_PORT", $this->port); $this->resource = $this->getConfigByPriority(@$config['resource'], "JAXL_USER_RESC", "jaxl." . $this->uid . "." . $this->clocked); $this->status = $this->getConfigByPriority(@$config['status'], "JAXL_USER_STATUS", $this->status); $this->logLevel = $this->getConfigByPriority(@$config['logLevel'], "JAXL_LOG_LEVEL", $this->logLevel); $this->logRotate = $this->getConfigByPriority(@$config['logRotate'], "JAXL_LOG_ROTATE", $this->logRotate); $this->logPath = $this->getConfigByPriority(@$config['logPath'], "JAXL_LOG_PATH", $this->logPath); if (!file_exists($this->logPath) && !touch($this->logPath)) { throw new JAXLException("Log file " . $this->logPath . " doesn't exists"); } $this->pidPath = $this->getConfigByPriority(@$config['pidPath'], "JAXL_PID_PATH", $this->pidPath); $this->mode = $this->getConfigByPriority(@$config['mode'], "JAXL_MODE", PHP_SAPI == "cli" ? PHP_SAPI : "cgi"); if ($this->mode == "cli" && !file_exists($this->pidPath) && !touch($this->pidPath)) { throw new JAXLException("Pid file " . $this->pidPath . " doesn't exists"); } /* Resolve temporary folder path */ if (function_exists('sys_get_temp_dir')) { $this->tmpPath = sys_get_temp_dir(); } $this->tmpPath = $this->getConfigByPriority(@$config['tmpPath'], "JAXL_TMP_PATH", $this->tmpPath); if ($this->tmpPath && !file_exists($this->tmpPath)) { throw new JAXLException("Tmp directory " . $this->tmpPath . " doesn't exists"); } /* Handle pre-choosen auth type mechanism */ $this->authType = $this->getConfigByPriority(@$config['authType'], "JAXL_AUTH_TYPE", $this->authType); if ($this->authType) { $this->addPlugin('jaxl_get_auth_mech', array($this, 'doAuth')); } /* Presence handling */ $this->trackPresence = isset($config['trackPresence']) ? $config['trackPresence'] : true; $this->autoSubscribe = isset($config['autoSubscribe']) ? $config['autoSubscribe'] : false; $this->addPlugin('jaxl_get_presence', array($this, '_handlePresence'), 0); /* Optional params which can be configured only via constructor $config */ $this->sigh = isset($config['sigh']) ? $config['sigh'] : true; $this->dumpStat = isset($config['dumpStat']) ? $config['dumpStat'] : 300; /* Configure instance for platforms */ $this->configure($config); /* Initialize xml to array class (will deprecate in future) */ $this->xml = new XML(); /* Initialize JAXLCron and register core jobs */ JAXLCron::init($this); if ($this->dumpStat) { JAXLCron::add(array($this, 'dumpStat'), $this->dumpStat); } if ($this->logRotate) { JAXLCron::add(array('JAXLog', 'logRotate'), $this->logRotate); } /* include recommended XEP's for every XMPP entity */ $this->requires(array('JAXL0030', 'JAXL0128')); /* initialize multi-core instance holder */ if ($jaxl_instance_cnt == 1) { $this->instances = array('xmpp' => array()); } $this->instances['xmpp'][] = $this; }
* Execute this script from a terminal window * Send a Jabber IM to tpg_tester@jabber.org * Profit! * * Send "quit" to end the script */ // Test Comment for git commit include "xmpphp/xmpp.php"; // test account information $host = 'jabber.org'; $port = 5222; $username = '******'; $password = '******'; $resource = 'xmpphp'; $server = null; $xmpp = new XMPP($host, $port, $username, $password, $resource, $server, true, LOGGING_INFO); $xmpp->connect(); while (!$xmpp->disconnected) { $payloads = $xmpp->processUntil(array('message', 'presence', 'end_stream', 'session_start')); foreach ($payloads as $event) { $pl = $event[1]; switch ($event[0]) { case 'message': echo "---------------------------------------------------------------------------------\n"; echo "Message from: {$pl['from']}\n"; if ($pl['subject']) { echo "Subject: {$pl['subject']}\n"; } echo $pl['body'] . "\n"; echo "---------------------------------------------------------------------------------\n"; $xmpp->message($pl['from'], "Thanks for sending me \"{$pl['body']}\".", $pl['type']);
/** * Jaxl core constructor * * Jaxl instance configures itself using the constants inside your application jaxl.ini. * However, passed array of configuration options overrides the value inside jaxl.ini. * If no configuration are found or passed for a particular value, * Jaxl falls back to default config options. * * @param $config Array of configuration options * @todo Use DNS SRV lookup to set $jaxl->host from provided domain info */ function __construct($config = array()) { $this->mode = PHP_SAPI == "cli" ? PHP_SAPI : "cgi"; $this->pid = getmypid(); $this->config = $config; $this->ip = gethostbyname(php_uname('n')); /* Mandatory params to be supplied either by jaxl.ini constants or constructor $config array */ $this->user = $this->getConfigByPriority($config['user'], "JAXL_USER_NAME", $this->user); $this->pass = $this->getConfigByPriority($config['pass'], "JAXL_USER_PASS", $this->pass); $this->domain = $this->getConfigByPriority($config['domain'], "JAXL_HOST_DOMAIN", $this->domain); $this->bareJid = $this->user . "@" . $this->domain; /* Optional params if not configured using jaxl.ini or $config take default values */ $this->host = $this->getConfigByPriority($config['host'], "JAXL_HOST_NAME", $this->domain); $this->port = $this->getConfigByPriority($config['port'], "JAXL_HOST_PORT", $this->port); $this->resource = $this->getConfigByPriority($config['resource'], "JAXL_USER_RESC", "jaxl." . time()); $this->logLevel = $this->getConfigByPriority($config['logLevel'], "JAXL_LOG_LEVEL", $this->logLevel); $this->logRotate = $this->getConfigByPriority($config['logRotate'], "JAXL_LOG_ROTATE", $this->logRotate); $this->logPath = $this->getConfigByPriority($config['logPath'], "JAXL_LOG_PATH", $this->logPath); $this->pidPath = $this->getConfigByPriority($config['pidPath'], "JAXL_PID_PATH", $this->pidPath); $this->tmpPath = $this->getConfigByPriority($config['tmpPath'], "JAXL_TMP_PATH", sys_get_temp_dir()); /* Handle pre-choosen auth type mechanism */ $this->authType = $this->getConfigByPriority($config['authType'], "JAXL_AUTH_TYPE", $this->authType); if ($this->authType) { JAXLPlugin::add('jaxl_get_auth_mech', array($this, 'doAuth')); } /* Optional params which can be configured only via constructor $config */ $this->sigh = isset($config['sigh']) ? $config['sigh'] : true; $this->dumpStat = isset($config['dumpStat']) ? $config['dumpStat'] : 300; /* Configure instance for platforms and call parent construct */ $this->configure($config); parent::__construct($config); $this->xml = new XML(); /* Initialize JAXLCron and register instance cron jobs */ JAXLCron::init(); if ($this->dumpStat) { JAXLCron::add(array($this, 'dumpStat'), $this->dumpStat); } if ($this->logRotate) { JAXLCron::add(array('JAXLog', 'logRotate'), $this->logRotate); } // include service discovery XEP-0030 and it's extensions, recommended for every XMPP entity $this->requires(array('JAXL0030', 'JAXL0128')); }
function __construct($config = array()) { $this->configure($config); parent::__construct($config); $this->xml = new XML(); }
#!/usr/bin/php <?php // The Daemon that listens, dispatches, and gracefully fails over. // Considered going all OOP on this bitch; just didn't make sense in this case. // 99 lines, with this comment. Procedural programming FTW! require_once dirname(__FILE__) . '/../conf/twitterpg.conf.php'; require_once dirname(__FILE__) . '/../classes/xmpphp/xmpp.php'; define('DAEMON_LISTENING', 'listening'); define('DAEMON_TRANSFERRING', 'transferring'); define('DAEMON_READY', 'ready'); define('PROCESS_TIMEOUT', 10); define('DEBUG', true); $conn = new XMPP(XMPP_HOST, XMPP_PORT, XMPP_USERNAME, XMPP_PASSWORD, 'trnd', XMPP_SERVER, DEBUG, LOGGING_INFO); function connect() { global $conn; $conn->connect(); $conn->processUntil('session_start', PROCESS_TIMEOUT); return true; } $first_daemon = true; $processing = false; $awaiting_transfer = false; $transfer_pending = false; $magic = false; for (connect(), $conn->presence(DAEMON_READY), $me = explode('/', $conn->fulljid); !$conn->disconnected; $evs = $conn->processUntil(array('message', 'presence'), PROCESS_TIMEOUT)) { if (is_array($evs)) { foreach ($evs as $ev) { $type = $ev[0]; $pl = $ev[1]; switch ($type) {
/** * @return void */ public function execute() { $this->connection->disconnect(); }
/** * send_notification * * Send notification when new order is received * * @access public * @return void */ function send_notification($title, $message, $url = '') { if (!class_exists('XMPP_Api')) { include_once 'xmpp.class.php'; } $webi_conf['user'] = $this->user; $webi_conf['pass'] = $this->pass; $webi_conf['host'] = $this->host; $webi_conf['port'] = $this->port; $webi_conf['domain'] = $this->domain; $webi_conf['logtxt'] = false; $webi_conf['log_file_name'] = "loggerxmpp.log"; $webi_conf['tls_off'] = 0; $xmpp = new XMPP($webi_conf); $xmpp->connect(); $this->add_log(__('Sending: ', 'wc_xmpp') . "\nТема: " . substr(get_bloginfo('wpurl'), 7, 999) . " " . $title . "\nСообщение: " . $message); try { $rec = explode(';', $this->rec); for ($i = 0; $i < count($rec); $i++) { $this->add_log(__('Rec: ', 'wc_xmpp') . "\n" . $rec[$i]); $xmpp->sendMessage($rec[$i], substr(get_bloginfo('wpurl'), 7, 999) . " " . $title . "\n" . $message); } } catch (Exception $e) { $this->add_log(sprintf(__('Error: Caught exception from send method: %s', 'wc_xmpp'), $e->getMessage())); } }