Skip to content

Commit

Permalink
First pass at supporting saving original contact photos after resize.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Nov 20, 2015
1 parent 8c5e8ad commit c76cc56
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 15 deletions.
6 changes: 6 additions & 0 deletions turba/config/attributes.php
Expand Up @@ -136,6 +136,12 @@
'required' => false,
'params' => array('show_upload' => true, 'show_keeporig' => true, 'max_filesize' => null),
);
$attributes['photo_orig'] = array(
'label' => _("Original Photo"),
'type' => 'image',
'required' => false,
'params' => array('show_upload' => false, 'show_keeporig' => true, 'max_filesize' => null),
);
$attributes['phototype'] = array(
'label' => _("Photo MIME Type"),
'type' => 'text',
Expand Down
13 changes: 12 additions & 1 deletion turba/config/conf.xml
Expand Up @@ -51,7 +51,18 @@
<configheader>Tag Settings</configheader>
<configboolean name="enabled" desc="Enable tagging?">true</configboolean>
</configsection>

<configsection name="photos">
<configheader>Photo settings</configheader>
<configdescription>If the contact source contains contact photos what size
should the photos be resized to when automatically resizing (like during
import). If there are separate fields configured in the backend for resized
and original images the original will be saved. Additionally, if the resized
data is missing, but the original data is present then the image will be
automatically resized and saved when viewing the contact for the first time.
</configdescription>
<configinteger name="height" desc="Height">250</configinteger>
<configinteger name="width" desc="Width">250</configinteger>
</configsection>
<configsection name="pager">
<configheader>Alpha Pager Settings</configheader>
<configlist name="special" required="false" desc="An list containing any
Expand Down
20 changes: 20 additions & 0 deletions turba/docs/UPGRADING
Expand Up @@ -45,6 +45,26 @@ outdated.
Upgrading Turba from 4.2 to 4.3
===============================

Attribute Changes
-----------------

- The "photo_orig" attribute has been added to store original versions of
images that were resized. Any attribute of type "image" can be expanded to
support this by also adding an attribute with the string "_orig" appended
to the attribute name. If an entry does not contain any "photo" data, but
does contain the "photo_orig" data, the "photo" data will automatically be
populated with a resized version of the data (see Configuration changes).


Configuration Options (conf.php)
--------------------------------

- The following options have been added::

$conf['photos']['height']
$conf['photos']['width']


API Changes
-----------

Expand Down
11 changes: 8 additions & 3 deletions turba/lib/Form/AddContact.php
Expand Up @@ -65,9 +65,14 @@ public function execute()
/* Form valid, save data. */
$this->getInfo($this->_vars, $info);
foreach ($info['object'] as $info_key => $info_val) {
if ($GLOBALS['attributes'][$info_key]['type'] == 'image' && !empty($info_val['file'])) {
$this->_contact->setValue($info_key, file_get_contents($info_val['file']));
$this->_contact->setValue($info_key . 'type', $info_val['type']);
if ($GLOBALS['attributes'][$info_key]['type'] == 'image') {
if (!empty($info_val['file'])) {
$this->_contact->setValue($info_key, file_get_contents($info_val['file']));
$this->_contact->setValue($info_key . 'type', $info_val['type']);
}
if (!empty($info_val['orig_file'])) {
$this->_contact->setValue($info_key . '_orig', file_get_contents($info_val['orig_file']));
}
} else {
$this->_contact->setValue($info_key, $info_val);
}
Expand Down
34 changes: 25 additions & 9 deletions turba/lib/Object.php
Expand Up @@ -125,7 +125,7 @@ public function getGuid($delimiter = ':')
*/
public function getValue($attribute)
{
global $attributes, $injector;
global $attributes, $injector, $conf;

if (isset($this->attributes[$attribute]) &&
($hooks = $injector->getInstance('Horde_Core_Hooks')) &&
Expand All @@ -144,16 +144,24 @@ public function getValue($attribute)
$args[] = $this->getValue($field);
}
return Turba::formatCompositeField($this->driver->map[$attribute]['format'], $args);
} elseif (!isset($this->attributes[$attribute])) {
if (isset($attributes[$attribute]) &&
($attributes[$attribute]['type'] == 'Turba:TurbaTags') &&
($uid = $this->getValue('__uid'))) {
$this->synchronizeTags($injector->getInstance('Turba_Tagger')->getTags($uid, 'contact'));
} else {
return null;
}
} elseif (isset($attributes[$attribute]) &&
($attributes[$attribute]['type'] == 'image')) {
// If there is no [$attribute], but we have a $attribute . '_orig',
// then populate the $attribute data using default resizing config.
if (empty($this->attributes[$attribute])) {
if (!empty($this->attributes[$attribute . '_orig']) &&
(!empty($conf['photos']['height']) || !empty($conf['photos']['width']))) {
// Do resizing
$img = $injector->getInstance('Horde_Core_Factory_Image')->create(
array(
'data' => $this->attributes[$attribute . '_orig'],
'type' => 'jpeg'
));
$img->resize($conf['photos']['width'], $conf['photos']['height']);
$this->attributes[$attribute] = $img->raw(true);
$this->store();
}
}
return empty($this->attributes[$attribute])
? null
: array(
Expand All @@ -162,6 +170,14 @@ public function getValue($attribute)
'file' => basename(Horde::getTempFile('horde_form_', false, '', false, true))
)
);
} elseif (!isset($this->attributes[$attribute])) {
if (isset($attributes[$attribute]) &&
($attributes[$attribute]['type'] == 'Turba:TurbaTags') &&
($uid = $this->getValue('__uid'))) {
$this->synchronizeTags($injector->getInstance('Turba_Tagger')->getTags($uid, 'contact'));
} else {
return null;
}
}

return $this->attributes[$attribute];
Expand Down
47 changes: 47 additions & 0 deletions turba/migration/12_turba_upgrade_originalphotos.php
@@ -0,0 +1,47 @@
<?php
/**
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/apache ASL
* @package Turba
*/

require_once __DIR__ . '/../lib/Turba.php';

/**
* Add hierarchcal related columns to the legacy sql share driver
*
* Copyright 2011-2015 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (ASL). If you
* did not receive this file, see http://www.horde.org/licenses/apache.
*
* @author Michael J. Rubinsky <mrubinsk@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/apache ASL
* @package Turba
*/
class TurbaUpgradeoriginalphotos extends Horde_Db_Migration_Base
{
/**
* Upgrade.
*/
public function up()
{
$t = $this->_connection->table('turba_objects');
$cols = array_keys($t->getColumns());

if (!in_array('object_photoorig', $cols)) {
$this->addColumn('turba_objects', 'object_photoorig', 'binary');
}
}

/**
* Downgrade
*/
public function down()
{
$this->removeColumn('turba_objects', 'object_photoorig');
}

}
6 changes: 4 additions & 2 deletions turba/package.xml
Expand Up @@ -28,7 +28,7 @@
<email>chuck@horde.org</email>
<active>no</active>
</lead>
<date>2014-09-05</date>
<date>2015-11-20</date>
<version>
<release>4.3.0</release>
<api>4.0.0</api>
Expand Down Expand Up @@ -469,6 +469,7 @@
<file name="9_turba_upgrade_schema.php" role="horde" />
<file name="10_turba_upgrade_categoriestotags.php" role="horde" />
<file name="11_turba_upgrade_parents.php" role="horde" />
<file name="12_turba_upgrade_originalphotos.php" role="horde" />
</dir> <!-- /migration -->
<dir name="scripts">
<dir name="ldap">
Expand Down Expand Up @@ -1085,6 +1086,7 @@
<install as="turba/migration/9_turba_upgrade_schema.php" name="migration/9_turba_upgrade_schema.php" />
<install as="turba/migration/10_turba_upgrade_categoriestotags.php" name="migration/10_turba_upgrade_categoriestotags.php" />
<install as="turba/migration/11_turba_upgrade_parents.php" name="migration/11_turba_upgrade_parents.php" />
<install as="turba/migration/12_turba_upgrade_originalphotos.php" name="migration/12_turba_upgrade_originalphotos.php" />
<install as="scripts/.htaccess" name="scripts/.htaccess" />
<install as="scripts/Turba.reg" name="scripts/Turba.reg" />
<install as="scripts/ldap/addou" name="scripts/ldap/addou" />
Expand Down Expand Up @@ -1985,7 +1987,7 @@
</notes>
</release>
<release>
<date>2014-06-04</date>
<date>2015-11-20</date>
<version>
<release>4.3.0</release>
<api>4.0.0</api>
Expand Down

0 comments on commit c76cc56

Please sign in to comment.