function ajaxSend($to, $pack, $file) { if (!$this->validateJid($to)) { return; } list($key, $ext) = explode('.', $file); $filepath = dirname(__FILE__) . '/stickers/' . $pack . '/' . $key . '.png'; if (!file_exists($filepath)) { return; } // We get the base64 $base64 = base64_encode(file_get_contents($filepath)); // Caching the picture if (!file_exists(CACHE_PATH . md5($key) . '.png')) { $p = new Picture(); $p->fromBase($base64); $p->set($key, 'png'); } // Creating a message $m = new \Modl\Message(); $m->session = $this->user->getLogin(); $m->jidto = echapJid($to); $m->jidfrom = $this->user->getLogin(); $m->sticker = $key; $m->body = $this->__('sticker.sent'); $m->published = gmdate('Y-m-d H:i:s'); $session = \Session::start(); $m->id = Uuid::uuid4(); $m->type = 'chat'; $m->resource = $session->get('resource'); // Sending the sticker $html = "<p><img alt='Sticker' src='cid:sha1+" . $key . "@bob.xmpp.org'/></p>"; $p = new Publish(); $p->setTo($m->jidto)->setContent($m->body)->setHTML($html)->setId($m->id)->request(); $md = new \Modl\MessageDAO(); $md->set($m); // Sending it to Chat $packet = new Moxl\Xec\Payload\Packet(); $packet->content = $m; $c = new Chat(); $c->onMessage($packet); }
/** * @brief Send a message * * @param string $to * @param string $message * @return void */ function ajaxSendMessage($to, $message, $muc = false, $resource = false) { if ($message == '') { return; } $m = new \Modl\Message(); $m->session = $this->user->getLogin(); $m->jidto = echapJid($to); $m->jidfrom = $this->user->getLogin(); $session = \Sessionx::start(); $m->type = 'chat'; $m->resource = $session->resource; if ($muc) { $m->type = 'groupchat'; $s = Session::start(); $m->resource = $s->get('username'); if ($m->resource == null) { $m->resource = $session->user; } $m->jidfrom = $to; } $m->body = rawurldecode($message); $m->html = prepareString($m->body, false, true); $m->published = gmdate('Y-m-d H:i:s'); $m->delivered = gmdate('Y-m-d H:i:s'); if ($resource != false) { $to = $to . '/' . $resource; } // We decode URL codes to send the correct message to the XMPP server $p = new Publish(); $p->setTo($to); //$p->setHTML($m->html); $p->setContent(htmlspecialchars($m->body)); if ($muc) { $p->setMuc(); } $p->request(); /* Is it really clean ? */ if (!$p->getMuc()) { if (!preg_match('#^\\?OTR#', $m->body)) { $md = new \Modl\MessageDAO(); $md->set($m); } $packet = new Moxl\Xec\Payload\Packet(); $packet->content = $m; $this->onMessage($packet); } }
/** * @brief Send a message * * @param string $to * @param string $message * @return void */ function ajaxSendMessage($to, $message, $muc = false, $resource = false, $replace = false) { $body = trim(rawurldecode($message)); if ($body == '' || $body == '/me') { return; } $m = new \Modl\Message(); $m->session = $this->user->getLogin(); $m->jidto = echapJid($to); $m->jidfrom = $this->user->getLogin(); if ($replace != false) { $m->newid = Uuid::uuid4(); $m->id = $replace->id; $m->edited = true; $m->published = $replace->published; $m->delivered = $replace->delivered; } else { $m->id = Uuid::uuid4(); $m->published = gmdate('Y-m-d H:i:s'); } $session = \Session::start(); $m->type = 'chat'; $m->resource = $session->get('resource'); if ($muc) { $m->type = 'groupchat'; $m->resource = $session->get('username'); $m->jidfrom = $to; } $m->body = $body; $m->checkPicture(); //$m->html = prepareString($m->body, false, true); if ($resource != false) { $to = $to . '/' . $resource; } // We decode URL codes to send the correct message to the XMPP server $p = new Publish(); $p->setTo($to); //$p->setHTML($m->html); $p->setContent($m->body); if ($replace != false) { $p->setId($m->newid); $p->setReplace($m->id); } else { $p->setId($m->id); } if ($muc) { $p->setMuc(); } $p->request(); /* Is it really clean ? */ if (!$p->getMuc()) { if (!preg_match('#^\\?OTR#', $m->body)) { $md = new \Modl\MessageDAO(); $md->set($m); } $packet = new Moxl\Xec\Payload\Packet(); $packet->content = $m; $this->onMessage($packet); } }