mirror of https://github.com/movim/movim
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.9 KiB
103 lines
3.9 KiB
<?php
|
|
|
|
class Attachment extends DatajarBase {
|
|
protected $key;
|
|
protected $jid;
|
|
|
|
protected $node;
|
|
protected $attachmentid;
|
|
|
|
protected $title;
|
|
protected $type;
|
|
|
|
protected $length;
|
|
|
|
protected $link;
|
|
protected $thumb;
|
|
|
|
protected function type_init() {
|
|
$this->key = DatajarType::varchar(128);
|
|
$this->jid = DatajarType::varchar(128);
|
|
|
|
$this->node = DatajarType::varchar(128);
|
|
$this->attachmentid = DatajarType::varchar(128);
|
|
|
|
$this->title = DatajarType::varchar(128);
|
|
$this->type = DatajarType::varchar(128);
|
|
|
|
$this->length = DatajarType::int();
|
|
|
|
$this->link = DatajarType::varchar(128);
|
|
$this->thumb = DatajarType::varchar(128);
|
|
}
|
|
|
|
public function getData($data) {
|
|
return $this->$data->getval();
|
|
}
|
|
}
|
|
|
|
class AttachmentHandler {
|
|
static function getAttachment($key, $node) {
|
|
global $sdb;
|
|
$attachment = $sdb->select('Attachment', array('key' => $key, 'node'=> $node));
|
|
if($attachment != false)
|
|
return $attachment;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
function saveAttachment($array, $jid, $from, $node) {
|
|
global $sdb;
|
|
$attachment = $sdb->select('Attachment', array(
|
|
'key' => $jid,
|
|
'jid' => $from,
|
|
'node'=> $node,
|
|
'attachmentid' => sha1($array['@attributes']['href'].
|
|
$array['@attributes']['title'].
|
|
$array['@attributes']['length'])
|
|
));
|
|
|
|
if($attachment == false) {
|
|
$attachment = new Attachment();
|
|
$attachment->key = $jid;
|
|
$attachment->jid = $from;
|
|
|
|
$attachment->node = $node;
|
|
$attachment->attachmentid = sha1($array['@attributes']['href'].
|
|
$array['@attributes']['title'].
|
|
$array['@attributes']['length']);
|
|
|
|
$attachment->title = $array['@attributes']['title'];
|
|
$attachment->type = $array['@attributes']['type'];
|
|
|
|
$attachment->length = $array['@attributes']['length'];
|
|
|
|
$attachment->link = $array['@attributes']['href'];
|
|
$attachment->thumb = $array['link'][0]['@attributes']['href'];
|
|
|
|
$sdb->save($attachment);
|
|
} else {
|
|
global $sdb;
|
|
$attachment = new Attachment();
|
|
$sdb->load($attachment, array(
|
|
'key' => $jid,
|
|
'jid' => $from,
|
|
'node'=> $node,
|
|
'attachmentid' => sha1($array['@attributes']['href'].
|
|
$array['@attributes']['title'].
|
|
$array['@attributes']['length'])
|
|
));
|
|
|
|
$attachment->title = $array['@attributes']['title'];
|
|
$attachment->type = $array['@attributes']['type'];
|
|
|
|
$attachment->length = $array['@attributes']['length'];
|
|
|
|
$attachment->link = $array['@attributes']['href'];
|
|
$attachment->thumb = $array['link'][0]['@attributes']['href'];
|
|
|
|
$sdb->save($attachment);
|
|
|
|
}
|
|
}
|
|
}
|