Fix attachment handling in database driver; move attachment_get hook execution to main class (where other attachment related hooks are triggered, too)
This commit is contained in:
parent
53210ec192
commit
325bae250d
3 changed files with 26 additions and 34 deletions
|
@ -995,7 +995,7 @@ class calendar extends rcube_plugin
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($_SESSION['calendar_attachment']);
|
$this->rc->session->remove('calendar_attachment');
|
||||||
|
|
||||||
if ($attachment) {
|
if ($attachment) {
|
||||||
$mimetype = strtolower($attachment['mimetype']);
|
$mimetype = strtolower($attachment['mimetype']);
|
||||||
|
@ -1041,8 +1041,9 @@ class calendar extends rcube_plugin
|
||||||
$filename = addcslashes($filename, '"');
|
$filename = addcslashes($filename, '"');
|
||||||
|
|
||||||
$disposition = !empty($_GET['_download']) ? 'attachment' : 'inline';
|
$disposition = !empty($_GET['_download']) ? 'attachment' : 'inline';
|
||||||
|
|
||||||
header("Content-Disposition: $disposition; filename=\"$filename\"");
|
header("Content-Disposition: $disposition; filename=\"$filename\"");
|
||||||
|
|
||||||
|
echo $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
@ -1080,7 +1081,7 @@ class calendar extends rcube_plugin
|
||||||
if (!empty($_SESSION['event_session']['attachments'])) {
|
if (!empty($_SESSION['event_session']['attachments'])) {
|
||||||
foreach ($_SESSION['event_session']['attachments'] as $id => $attachment) {
|
foreach ($_SESSION['event_session']['attachments'] as $id => $attachment) {
|
||||||
if (is_array($event['attachments']) && in_array($id, $event['attachments'])) {
|
if (is_array($event['attachments']) && in_array($id, $event['attachments'])) {
|
||||||
$attachments[$id] = $attachment;
|
$attachments[$id] = $this->rc->plugins->exec_hook('attachment_get', $attachment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,12 +213,6 @@ class database_driver extends calendar_driver
|
||||||
// add attachments
|
// add attachments
|
||||||
if (!empty($event['attachments'])) {
|
if (!empty($event['attachments'])) {
|
||||||
foreach ($event['attachments'] as $attachment) {
|
foreach ($event['attachments'] as $attachment) {
|
||||||
$attachment = $this->rc->plugins->exec_hook('attachment_get', $attachment);
|
|
||||||
|
|
||||||
if (!$attachment['data']) {
|
|
||||||
$attachments['data'] = file_get_contents($attachment['path']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->add_attachment($attachment, $event_id);
|
$this->add_attachment($attachment, $event_id);
|
||||||
unset($attachment);
|
unset($attachment);
|
||||||
}
|
}
|
||||||
|
@ -419,12 +413,6 @@ class database_driver extends calendar_driver
|
||||||
// add attachments
|
// add attachments
|
||||||
if ($success && !empty($event['attachments'])) {
|
if ($success && !empty($event['attachments'])) {
|
||||||
foreach ($event['attachments'] as $attachment) {
|
foreach ($event['attachments'] as $attachment) {
|
||||||
$attachment = $this->rc->plugins->exec_hook('attachment_get', $attachment);
|
|
||||||
|
|
||||||
if (!$attachment['data']) {
|
|
||||||
$attachments['data'] = file_get_contents($attachment['path']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->add_attachment($attachment, $event['id']);
|
$this->add_attachment($attachment, $event['id']);
|
||||||
unset($attachment);
|
unset($attachment);
|
||||||
}
|
}
|
||||||
|
@ -643,10 +631,12 @@ class database_driver extends calendar_driver
|
||||||
$events = array();
|
$events = array();
|
||||||
if (!empty($calendar_ids)) {
|
if (!empty($calendar_ids)) {
|
||||||
$result = $this->rc->db->query(sprintf(
|
$result = $this->rc->db->query(sprintf(
|
||||||
"SELECT * FROM " . $this->db_events . "
|
"SELECT e.*, COUNT(a.attachment_id) AS _attachments FROM " . $this->db_events . " AS e
|
||||||
WHERE calendar_id IN (%s)
|
LEFT JOIN " . $this->db_attachments . " AS a ON (a.event_id = e.event_id)
|
||||||
AND start <= %s AND end >= %s
|
WHERE e.calendar_id IN (%s)
|
||||||
%s",
|
AND e.start <= %s AND e.end >= %s
|
||||||
|
%s
|
||||||
|
GROUP BY e.event_id",
|
||||||
join(',', $calendar_ids),
|
join(',', $calendar_ids),
|
||||||
$this->rc->db->fromunixtime($end),
|
$this->rc->db->fromunixtime($end),
|
||||||
$this->rc->db->fromunixtime($start),
|
$this->rc->db->fromunixtime($start),
|
||||||
|
@ -689,7 +679,10 @@ class database_driver extends calendar_driver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($event['event_id'], $event['calendar_id'], $event['notifyat']);
|
if ($event['_attachments'] > 0)
|
||||||
|
$event['attachments'] = (array)$this->list_attachments($event);
|
||||||
|
|
||||||
|
unset($event['event_id'], $event['calendar_id'], $event['notifyat'], $event['_attachments']);
|
||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -770,16 +763,18 @@ class database_driver extends calendar_driver
|
||||||
*/
|
*/
|
||||||
private function add_attachment($attachment, $event_id)
|
private function add_attachment($attachment, $event_id)
|
||||||
{
|
{
|
||||||
$query = $this->rc->db->query(sprintf(
|
$data = $attachment['data'] ? $attachment['data'] : file_get_contents($attachment['path']);
|
||||||
|
|
||||||
|
$query = $this->rc->db->query(
|
||||||
"INSERT INTO " . $this->db_attachments .
|
"INSERT INTO " . $this->db_attachments .
|
||||||
" (event_id, filename, mimetype, size, data)" .
|
" (event_id, filename, mimetype, size, data)" .
|
||||||
" VALUES (?, ?, ?, ?, ?)",
|
" VALUES (?, ?, ?, ?, ?)",
|
||||||
$event_id,
|
$event_id,
|
||||||
$attachment['name'],
|
$attachment['name'],
|
||||||
$attachment['mimetype'],
|
$attachment['mimetype'],
|
||||||
strlen($attachment['data']),
|
strlen($data),
|
||||||
base64_encode($attachment['data'])
|
base64_encode($data)
|
||||||
));
|
);
|
||||||
|
|
||||||
return $this->rc->db->affected_rows($query);
|
return $this->rc->db->affected_rows($query);
|
||||||
}
|
}
|
||||||
|
@ -813,10 +808,10 @@ class database_driver extends calendar_driver
|
||||||
$result = $this->rc->db->query(
|
$result = $this->rc->db->query(
|
||||||
"SELECT attachment_id AS id, filename AS name, mimetype, size " .
|
"SELECT attachment_id AS id, filename AS name, mimetype, size " .
|
||||||
" FROM " . $this->db_attachments .
|
" FROM " . $this->db_attachments .
|
||||||
" WHERE user_id=?".
|
" WHERE event_id IN (SELECT event_id FROM " . $this->db_events .
|
||||||
" AND event_id=?".
|
" WHERE event_id=?" .
|
||||||
"ORDER BY filename",
|
" AND calendar_id IN (" . $this->calendar_ids . "))".
|
||||||
$this->rc->user->ID,
|
" ORDER BY filename",
|
||||||
$event['id']
|
$event['id']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -838,7 +833,7 @@ class database_driver extends calendar_driver
|
||||||
"SELECT attachment_id AS id, filename AS name, mimetype, size " .
|
"SELECT attachment_id AS id, filename AS name, mimetype, size " .
|
||||||
" FROM " . $this->db_attachments .
|
" FROM " . $this->db_attachments .
|
||||||
" WHERE attachment_id=?".
|
" WHERE attachment_id=?".
|
||||||
" AND event_id=?".
|
" AND event_id=?",
|
||||||
$id,
|
$id,
|
||||||
$event['id']
|
$event['id']
|
||||||
);
|
);
|
||||||
|
@ -861,7 +856,7 @@ class database_driver extends calendar_driver
|
||||||
"SELECT data " .
|
"SELECT data " .
|
||||||
" FROM " . $this->db_attachments .
|
" FROM " . $this->db_attachments .
|
||||||
" WHERE attachment_id=?".
|
" WHERE attachment_id=?".
|
||||||
" AND event_id=?".
|
" AND event_id=?",
|
||||||
$id,
|
$id,
|
||||||
$event['id']
|
$event['id']
|
||||||
);
|
);
|
||||||
|
|
|
@ -235,8 +235,6 @@ class kolab_driver extends calendar_driver
|
||||||
foreach ($event['attachments'] as $idx => $attachment) {
|
foreach ($event['attachments'] as $idx => $attachment) {
|
||||||
// we'll read file contacts into memory, Horde/Kolab classes does the same
|
// we'll read file contacts into memory, Horde/Kolab classes does the same
|
||||||
// So we cannot save memory, rcube_imap class can do this better
|
// So we cannot save memory, rcube_imap class can do this better
|
||||||
$attachment = $this->cal->rc->plugins->exec_hook('attachment_get', $attachment);
|
|
||||||
|
|
||||||
$event['attachments'][$idx]['content'] = $attachment['data'] ? $attachment['data'] : file_get_contents($attachment['path']);
|
$event['attachments'][$idx]['content'] = $attachment['data'] ? $attachment['data'] : file_get_contents($attachment['path']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,8 +361,6 @@ class kolab_driver extends calendar_driver
|
||||||
foreach ($event['attachments'] as $attachment) {
|
foreach ($event['attachments'] as $attachment) {
|
||||||
// we'll read file contacts into memory, Horde/Kolab classes does the same
|
// we'll read file contacts into memory, Horde/Kolab classes does the same
|
||||||
// So we cannot save memory, rcube_imap class can do this better
|
// So we cannot save memory, rcube_imap class can do this better
|
||||||
$attachment = $this->cal->rc->plugins->exec_hook('attachment_get', $attachment);
|
|
||||||
|
|
||||||
$attachments[] = array(
|
$attachments[] = array(
|
||||||
'name' => $attachment['name'],
|
'name' => $attachment['name'],
|
||||||
'type' => $attachment['mimetype'],
|
'type' => $attachment['mimetype'],
|
||||||
|
|
Loading…
Add table
Reference in a new issue