From 833a6e86ea17d40444ae32cd6c92b9359f383e71 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 14 Feb 2010 17:00:14 +0100 Subject: [PATCH 1/1] Add Group::getLogo() and Profile::getPhoto() based on PlImage. Signed-off-by: Florent Bruneau --- classes/group.php | 10 ++++++++++ classes/profile.php | 29 ++++++++++++++++++++++++++++- classes/userfilter.php | 6 ++++-- core | 2 +- modules/carnet/contacts.pdf.inc.php | 15 ++++++--------- modules/profile.php | 26 +++----------------------- modules/xnetgrp.php | 10 +--------- 7 files changed, 53 insertions(+), 45 deletions(-) diff --git a/classes/group.php b/classes/group.php index 4f3f0b7..a44ab6d 100644 --- a/classes/group.php +++ b/classes/group.php @@ -71,6 +71,16 @@ class Group return $this->getUF(true, $extra_cond, $sort); } + public function getLogo($fallback = true) + { + if (!empty($this->logo)) { + return PlImage::fromData($this->logo, $this->logo_mime); + } else if ($fallback) { + return PlImage::fromFile(dirname(__FILE__).'/../htdocs/images/dflt_carre.jpg', 'image/jpeg'); + } + return null; + } + static public function get($id) { if (!$id) { diff --git a/classes/profile.php b/classes/profile.php index bf06501..0ce66e7 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -167,6 +167,32 @@ class Profile } + /* Photo + */ + public function getPhoto($fallback = true) + { + /* TODO: migrate photo table to profile_photo, change uid to pid + */ + $cond = ''; + if ($this->visibility) { + $cond = ' AND pub IN ' . XDB::formatArray($this->visibility); + } + $res = XDB::query('SELECT * + FROM photo + WHERE attachmime IN (\'jpeg\', \'png\') + ' . $cond . ' AND uid = {?}', + $this->id()); + if ($res->numRows() > 0) { + $photo = $res->fetchOneAssoc(); + return PlImage::fromData($photo['attach'], 'image/' . $photo['attachmime'], + $photo['x'], $photo['y']); + } else if ($fallback) { + return PlImage::fromFile(dirname(__FILE__).'/../htdocs/images/none.png', + 'image/png'); + } + return null; + } + /* Addresses */ public function getAddresses($flags, $limit = null) @@ -341,7 +367,7 @@ class Profile IF(pn_uf.name IS NULL, pn_f.name, pn_uf.name) AS firstname_usual, IF(pn_ul.name IS NULL, pn_l.name, pn_ul.name) AS lastname_usual, pd.promo AS promo, pd.short_name, pd.directory_name AS full_name, - pp.display_tel AS mobile, pp.pub AS mobile_pub + pp.display_tel AS mobile, pp.pub AS mobile_pub, ph.pub AS photo_pub FROM profiles AS p INNER JOIN profile_display AS pd ON (pd.pid = p.pid) INNER JOIN profile_education AS pe ON (pe.uid = p.pid AND FIND_IN_SET(\'primary\', pe.flags)) @@ -356,6 +382,7 @@ class Profile LEFT JOIN profile_name AS pn_n ON (pn_n.pid = p.pid AND pn_n.typeid = ' . self::getNameTypeId('nickname', true) . ') LEFT JOIN profile_phones AS pp ON (pp.uid = p.pid AND pp.link_type = \'user\' AND tel_type = \'mobile\') + LEFT JOIN photo AS ph ON (ph.uid = p.pid) WHERE p.pid IN ' . XDB::formatArray($pids) . ' GROUP BY p.pid'); } diff --git a/classes/userfilter.php b/classes/userfilter.php index 2c8385b..8d8378c 100644 --- a/classes/userfilter.php +++ b/classes/userfilter.php @@ -1665,12 +1665,14 @@ class UserFilter extends PlFilter public function getUIDs($limit = null) { - return $this->getUIDList(null, self::defaultLimit($limit)); + $limit = self::defaultLimit($limit); + return $this->getUIDList(null, $limit); } public function getPIDs($limit = null) { - return $this->getPIDList(null, self::defaultLimit($limit)); + $limit = self::defaultLimit($limit); + return $this->getPIDList(null, $limit); } public function getUsers($limit = null) diff --git a/core b/core index e174681..6f58e06 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit e1746810b6aeaba3332ff99acdbf7ff3c2e9ada6 +Subproject commit 6f58e0613a47d9eeb5004c992e6c59b7cf9ec0ea diff --git a/modules/carnet/contacts.pdf.inc.php b/modules/carnet/contacts.pdf.inc.php index 616030e..eb902dc 100644 --- a/modules/carnet/contacts.pdf.inc.php +++ b/modules/carnet/contacts.pdf.inc.php @@ -283,19 +283,16 @@ class ContactsPDF extends FPDF $ok = false; if ($wp) { - $res = XDB::query("SELECT * FROM photo WHERE attachmime IN ('jpeg', 'png') AND uid={?}", - $profile->pid); - if ($i = $res->numRows()) { + $photo = $profile->getPhoto(false); + if ($photo) { $old2 = clone $self; - $photo = $res->fetchOneAssoc(); - $width = $photo['x'] * 20/$photo['y']; - $GLOBALS['p' . $profile->pid] = $photo['attach']; - + $width = $photo->width() * 20 / $photo->height(); $_x = $self->getX(); $_y = $self->getY(); $self->Cell(0, 20, '', '', 0, '', 1); error_reporting(0); - $self->Image("var://p" . $profile->pid, $_x, $_y, $width, 20, $photo['attachmime']); + $mime = explode('/', $photo->mimeType()); + $self->Image($photo->path(), $_x, $_y, $width, 20, $mime[1]); error_reporting($self->report); if ($self->error) { @@ -303,7 +300,7 @@ class ContactsPDF extends FPDF } else { $self->setX($_x); $self->Cell($width, 20, '', "T"); - $h = 20 / $self->wordwrap($nom, 90-$width); + $h = 20 / $self->wordwrap($nom, 90 - $width); $self->MultiCell(0, $h, $nom, 'T', 'C'); $ok = true; } diff --git a/modules/profile.php b/modules/profile.php index 4c62e1a..e994d3a 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -89,36 +89,16 @@ class ProfileModule extends PLModule } // Retrieve the photo and its mime type. - $photo_data = null; - $photo_type = null; - if ($req && S::logged()) { include 'validations.inc.php'; $myphoto = PhotoReq::get_request($user->id()); - if ($myphoto) { - $photo_data = $myphoto->data; - $photo_type = $myphoto->mimetype; - } + $photo = PlImage::fromData($myphoto->data, $myphoto->mimetype); } else { - $res = XDB::query( - "SELECT attachmime, attach, pub - FROM photo - WHERE uid = {?}", $user->id()); - list($photo_type, $photo_data, $photo_pub) = $res->fetchOneRow(); - if ($photo_pub != 'public' && !S::logged()) { - $photo_type = $photo_data = null; - } + $photo = $user->profile()->getPhoto(true); } // Display the photo, or a default one when not available. - if ($photo_type && $photo_data != null) { - pl_cached_dynamic_content_headers("image/$photo_type"); - echo $photo_data; - } else { - pl_cached_dynamic_content_headers("image/png"); - echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png'); - } - exit; + $photo->send(); } function handler_medal(&$page, $mid) diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index e56eb83..eda32c1 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -129,15 +129,7 @@ class XnetGrpModule extends PLModule function handler_logo(&$page) { global $globals; - - $res = XDB::query("SELECT logo, logo_mime - FROM groups - WHERE id = {?}", - $globals->asso('id')); - list($logo, $logo_mime) = $res->fetchOneRow(); - - pl_cached_dynamic_content_headers(empty($logo) ? "image/jpeg" : $logo_mime); - exit; + $globals->asso()->getLogo()->send(); } function handler_site(&$page) -- 2.1.4