aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/avatar
diff options
context:
space:
mode:
authorjaviexin <javiexin@gmail.com>2015-07-03 21:39:36 +0200
committerjaviexin <javiexin@gmail.com>2015-07-03 21:39:36 +0200
commite0efd5ee576b10be1b826ee3971212a4bdd0b498 (patch)
treef70ce1b8cc65a8d3ac175e730fce14e5618f9b3c /phpBB/phpbb/avatar
parent558d604d83fd5ded2edc854a9944ad0d1188e2e5 (diff)
downloadforums-e0efd5ee576b10be1b826ee3971212a4bdd0b498.tar
forums-e0efd5ee576b10be1b826ee3971212a4bdd0b498.tar.gz
forums-e0efd5ee576b10be1b826ee3971212a4bdd0b498.tar.bz2
forums-e0efd5ee576b10be1b826ee3971212a4bdd0b498.tar.xz
forums-e0efd5ee576b10be1b826ee3971212a4bdd0b498.zip
[ticket/13981] Add events to capture avatar deletion or overwriting
PHPBB3-13981
Diffstat (limited to 'phpBB/phpbb/avatar')
-rw-r--r--phpBB/phpbb/avatar/driver/upload.php58
1 files changed, 52 insertions, 6 deletions
diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php
index ee36243844..a1ea339371 100644
--- a/phpBB/phpbb/avatar/driver/upload.php
+++ b/phpBB/phpbb/avatar/driver/upload.php
@@ -80,6 +80,8 @@ class upload extends \phpbb\avatar\driver\driver
*/
public function process_form($request, $template, $user, $row, &$error)
{
+ global $phpbb_dispatcher;
+
if (!$this->can_upload())
{
return false;
@@ -151,13 +153,34 @@ class upload extends \phpbb\avatar\driver\driver
$destination = '';
}
- // Move file and overwrite any existing image
- $file->move_file($destination, true);
+ /**
+ * Before overwriting an existing avatar with a newly uploaded avatar
+ *
+ * @event core.avatar_driver_upload_overwrite_before
+ * @var string destination Destination directory where the file is going to be moved
+ * @var string prefix Prefix for the avatar filename
+ * @var array row Array with avatar row data
+ * @var array error Array of errors, if filled in by this event file will not be moved
+ * @since 3.1.6-RC1
+ */
+ $vars = array(
+ 'destination',
+ 'prefix',
+ 'row',
+ 'error',
+ );
+ extract($phpbb_dispatcher->trigger_event('core.avatar_driver_upload_overwrite_before', compact($vars)));
+
+ if (!sizeof($error))
+ {
+ // Move file and overwrite any existing image
+ $file->move_file($destination, true);
+ }
- if (sizeof($file->error))
+ $error = array_merge($error, $file->error);
+ if (sizeof($error))
{
$file->remove();
- $error = array_merge($error, $file->error);
return false;
}
@@ -185,10 +208,33 @@ class upload extends \phpbb\avatar\driver\driver
*/
public function delete($row)
{
+ global $phpbb_dispatcher;
+
+ $error = array();
+ $destination = $this->config['avatar_path'];
+ $prefix = $this->config['avatar_salt'] . '_';
$ext = substr(strrchr($row['avatar'], '.'), 1);
- $filename = $this->phpbb_root_path . $this->config['avatar_path'] . '/' . $this->config['avatar_salt'] . '_' . $row['id'] . '.' . $ext;
+ $filename = $this->phpbb_root_path . $destination . '/' . $prefix . $row['id'] . '.' . $ext;
+
+ /**
+ * Before deleting an existing avatar
+ *
+ * @event core.avatar_driver_upload_delete_before
+ * @var string destination Destination directory where the file is going to be deleted
+ * @var string prefix Prefix for the avatar filename
+ * @var array row Array with avatar row data
+ * @var array error Array of errors, if filled in by this event file will not be deleted
+ * @since 3.1.6-RC1
+ */
+ $vars = array(
+ 'destination',
+ 'prefix',
+ 'row',
+ 'error',
+ );
+ extract($phpbb_dispatcher->trigger_event('core.avatar_driver_upload_delete_before', compact($vars)));
- if (file_exists($filename))
+ if (!sizeof($error) && file_exists($filename))
{
@unlink($filename);
}