This repository was archived by the owner on Jan 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathavatar.php
More file actions
57 lines (44 loc) · 1.34 KB
/
avatar.php
File metadata and controls
57 lines (44 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
require '../vendor/autoload.php';
$config = require('config.inc.php');
error_reporting(-1);
use Fabiang\Xmpp\Client;
use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Protocol\User\Avatar;
use Fabiang\Xmpp\Protocol\User\AvatarMetadata;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
$logger = new Logger('xmpp');
$logger->pushHandler(new StreamHandler('xmpp.log', Logger::DEBUG));
$address = $config['connectionType'] . '://' . $config['host'] . ':' . $config['port'];
$login = $config['login'];//'testuser';
$password = '123456';
$options = new Options($address);
$options->setLogger($logger)
->setUsername($login)
->setPassword($config['password'])
->setVerifyPeer($config['verifyPeer']);
$client = new Client($options);
$client->connect();
$imagePath = 'avatar.png';
$avatar = new Avatar(
$login . '@' . $config['host'],
$imagePath
);
$url = '';
//$url = 'https://avatar.personal-site.com/64x64/testuser.png';
try {
$client->send($avatar);
// update avatar metadata
$meta = new AvatarMetadata(
$login . '@' . $config['host'],
$imagePath,
$url
);
$client->send($meta);
fwrite(STDOUT, 'Avatar was updated.' . PHP_EOL);
} catch (Exception $e) {
fwrite(STDOUT, 'Failed to update user avatar!' . PHP_EOL);
fwrite(STDOUT, $e->getMessage() . PHP_EOL);
}
$client->disconnect();