defaultPort, getJidLocalPart($jid), ($passwordEncrypted ? $this->decrypt($password) : $password), $this->defaultResource);
}
public function loginAndGetFileList() {
if ($this->login()) {
$this->getFileList();
}
}
public function deleteFile($fileurl) {
if (null == $fileurl || '' == $fileurl) {
throw new XMPPException('Missing fileurl');
}
$id = $this->getId();
$this->addIdHandler($id, 'deleteFileIqHandler');
$xml = "$fileurl";
$this->send($xml);
}
private function decrypt($password) {
$e = new Encryption(MCRYPT_BlOWFISH, MCRYPT_MODE_CBC);
return $e->decrypt($password, XMPPClient::ENCRYPTION_KEY);
}
public function login() {
try {
$this->connect(5);
$this->processUntil('session_start', 10);
session_start();
$_SESSION["authenticated"] = 'yeah';
$_SESSION["JID"] = $this->basejid;
$e = new Encryption(MCRYPT_BlOWFISH, MCRYPT_MODE_CBC);
$encryptedPassword = $e->encrypt($this->password, XMPPClient::ENCRYPTION_KEY);
$_SESSION["PASSWORD"] = $encryptedPassword;
return true;
} catch (XMPPException $e) {
echo $e->getMessage();
return false;
}
}
protected function getFileList() {
$id = $this->getId();
$this->addIdHandler($id, 'fileListIqHandler');
$this->send("");
$this->processUntil("list_loaded");
}
protected function fileListIqHandler($xml) {
$list = $xml->sub('list');
$fileList = [];
foreach ($list->subs as $fileXML) {
$file = [];
$file['url'] = $fileXML->sub('url')->data;
$file['timestamp'] = $fileXML->attrs['timestamp'];
$file['to'] = $fileXML->attrs['to'];
$file['from'] = $fileXML->attrs['from'];
$fileInfo = $fileXML->sub('file-info');
$file['filename'] = $fileInfo->sub('filename')->data;
$file['size'] = $fileInfo->sub('size')->data;
$file['type'] = $fileInfo->sub('content-type')->data;
$fileList[] = $file;
}
$this->event('list_loaded');
$_SESSION['FILE-LIST'] = $fileList;
header('Location: index.php');
}
protected function deleteFileIqHandler($xml) {
$deleted = $xml->sub('deleted');
if (null != $deleted) {
$data = ['error' => false, 'msg' => 'File successfully deleted'];
} else {
$error = $xml->sub('error');
$data = ['error' => true, 'msg' => $error->subs[0]->name."\n".$error->sub('text')->data];
}
sendHttpReturnCodeAndJson(200, $data);
}
}
?>