Пример #1
0
 function connect()
 {
     $connect_to = $this->host ? $this->host : $this->server;
     $this->log(LOG_INFO, "Connecting to {$connect_to} on port {$this->port}");
     $this->conn = jabber_connect($this->resource);
     if (!$this->conn) {
         return false;
     }
     $this->conn->setReconnectTimeout(600);
     jabber_send_presence("Send me a message to post a notice", 'available', null, 'available', 100);
     return !$this->conn->isDisconnected();
 }
Пример #2
0
 function start()
 {
     # Low priority; we don't want to receive messages
     $this->log(LOG_INFO, "INITIALIZE");
     $this->conn = jabber_connect($this->_id);
     if ($this->conn) {
         $this->conn->addEventHandler('message', 'forward_message', $this);
         $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this);
         $this->conn->setReconnectTimeout(600);
         jabber_send_presence("Send me a message to post a notice", 'available', null, 'available', -1);
     }
     return !is_null($this->conn);
 }
Пример #3
0
 /**
  * Initialize connection to server.
  * @return boolean true on success
  */
 public function start($master)
 {
     parent::start($master);
     $this->switchSite();
     require_once INSTALLDIR . "/lib/jabber.php";
     # Low priority; we don't want to receive messages
     common_log(LOG_INFO, "INITIALIZE");
     $this->conn = jabber_connect($this->resource);
     if (empty($this->conn)) {
         common_log(LOG_ERR, "Couldn't connect to server.");
         return false;
     }
     $this->log(LOG_DEBUG, "Initializing stanza handlers.");
     $this->conn->addEventHandler('message', 'handle_message', $this);
     $this->conn->addEventHandler('presence', 'handle_presence', $this);
     $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this);
     $this->conn->setReconnectTimeout(600);
     jabber_send_presence("Send me a message to post a notice", 'available', null, 'available', 100);
     return !is_null($this->conn);
 }
Пример #4
0
/**
 * sends a "special" presence stanza on the Jabber network
 *
 * @param string $type   Type of presence
 * @param string $to     JID to send presence to
 * @param string $show   show value for presence
 * @param string $status status value for presence
 *
 * @return boolean success flag
 *
 * @see jabber_send_presence()
 */
function jabber_special_presence($type, $to = null, $show = null, $status = null)
{
    // FIXME: why use this instead of jabber_send_presence()?
    $conn = jabber_connect();
    $to = htmlspecialchars($to);
    $status = htmlspecialchars($status);
    $out = "<presence";
    if ($to) {
        $out .= " to='{$to}'";
    }
    if ($type) {
        $out .= " type='{$type}'";
    }
    if ($show == 'available' and !$status) {
        $out .= "/>";
    } else {
        $out .= ">";
        if ($show && $show != 'available') {
            $out .= "<show>{$show}</show>";
        }
        if ($status) {
            $out .= "<status>{$status}</status>";
        }
        $out .= "</presence>";
    }
    $conn->send($out);
}
Пример #5
0
/**
 * send a notice to all public listeners
 *
 * For notices that are generated on the local system (by users), we can optionally
 * forward them to remote listeners by XMPP.
 *
 * @param Notice $notice notice to broadcast
 *
 * @return boolean success flag
 */
function jabber_public_notice($notice)
{
    // Now, users who want everything
    $public = common_config('xmpp', 'public');
    // FIXME PRIV don't send out private messages here
    // XXX: should we send out non-local messages if public,localonly
    // = false? I think not
    if ($public && $notice->is_local) {
        $profile = Profile::staticGet($notice->profile_id);
        if (!$profile) {
            common_log(LOG_WARNING, 'Refusing to broadcast notice with ' . 'unknown profile ' . common_log_objstring($notice), __FILE__);
            return false;
        }
        $msg = jabber_format_notice($profile, $notice);
        $entry = jabber_format_entry($profile, $notice);
        $conn = jabber_connect();
        foreach ($public as $address) {
            common_log(LOG_INFO, 'Sending notice ' . $notice->id . ' to public listener ' . $address, __FILE__);
            $conn->message($address, $msg, 'chat', null, $entry);
            $conn->processTime(0);
        }
        $profile->free();
    }
    return true;
}