summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BitUser.php132
-rw-r--r--my_images.php47
-rw-r--r--templates/my_images.tpl2
3 files changed, 106 insertions, 75 deletions
diff --git a/BitUser.php b/BitUser.php
index c1ed9bb..211f559 100644
--- a/BitUser.php
+++ b/BitUser.php
@@ -1,6 +1,6 @@
<?php
/**
- * $Header: /cvsroot/bitweaver/_bit_users/BitUser.php,v 1.155 2007/09/21 03:50:27 spiderr Exp $
+ * $Header: /cvsroot/bitweaver/_bit_users/BitUser.php,v 1.156 2007/09/26 09:24:22 squareing Exp $
*
* Lib for user administration, groups and permissions
* This lib uses pear so the constructor requieres
@@ -12,7 +12,7 @@
* All Rights Reserved. See copyright.txt for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
*
- * $Id: BitUser.php,v 1.155 2007/09/21 03:50:27 spiderr Exp $
+ * $Id: BitUser.php,v 1.156 2007/09/26 09:24:22 squareing Exp $
* @package users
*/
@@ -40,7 +40,7 @@ define("ACCOUNT_DISABLED", -6);
* Class that holds all information for a given user
*
* @author spider <spider@steelsun.com>
- * @version $Revision: 1.155 $
+ * @version $Revision: 1.156 $
* @package users
* @subpackage BitUser
*/
@@ -632,38 +632,19 @@ class BitUser extends LibertyAttachable {
$this->mInfo['content_id'] = $pParamHash['content_id'];
}
}
- $pParamHash['upload']['thumbnail'] = FALSE;
- if( isset($_FILES['fPortraitFile']) && is_uploaded_file( $_FILES['fPortraitFile']['tmp_name'] ) ) {
- $portraitHash = $pParamHash;
- $portraitHash['upload'] = $_FILES['fPortraitFile'];
- if( !$this->storePortrait( $portraitHash, (!empty( $portraitHash['fAutoAvatar'] ) ? TRUE : FALSE) ) ) {
- }
- }
- if( isset($_FILES['fAvatarFile']) && is_uploaded_file($_FILES['fAvatarFile']['tmp_name']) && $_FILES['fAvatarFile']['size'] > 0 ) {
- $avatarHash = $pParamHash;
- $avatarHash['upload'] = $_FILES['fAvatarFile'];
- $avatarHash['upload']['source_file'] = $_FILES['fAvatarFile']['tmp_name'];
- if( !$this->storeAvatar( $avatarHash ) ) {
- }
- }
+ $this->mDb->CompleteTrans();
- if( isset($_FILES['fLogoFile']) && is_uploaded_file($_FILES['fLogoFile']['tmp_name']) && $_FILES['fLogoFile']['size'] > 0 ) {
- $logoHash = $pParamHash;
- $logoHash['upload'] = $_FILES['fLogoFile'];
- $logoHash['upload']['source_file'] = $_FILES['fLogoFile']['tmp_name'];
- if( !$this->storeLogo( $logoHash ) ) {
- }
- }
+ // store any uploaded images
+ $pParamHash['upload']['thumbnail'] = FALSE; // i don't think this does anything - perhaps replace it by setting thumbnail_sizes
+ $this->storeImages( $pParamHash );
- $this->mDb->CompleteTrans();
$this->load( TRUE );
}
return( count( $this->mErrors ) == 0 );
}
-
// removes user and associated private data
function expunge() {
global $gBitSystem;
@@ -1196,6 +1177,14 @@ class BitUser extends LibertyAttachable {
// ============= image and file functions
+ /**
+ * getThumbnailUrl
+ *
+ * @param string $pSize
+ * @param array $pInfoHash
+ * @access public
+ * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ */
function getThumbnailUrl( $pSize='small', $pInfoHash=NULL ) {
$ret = '';
if( $pInfoHash ) {
@@ -1206,23 +1195,69 @@ class BitUser extends LibertyAttachable {
return $ret;
}
+ /**
+ * storeImages will store any user images - please note that uploaded files have to be in predefined keys in $_FILES
+ * $_FILES['fPortraitFile']
+ * $_FILES['fAutoAvatar']
+ * $_FILES['fLogoFile']
+ *
+ * @param array $pParamHash array of options
+ * @param boolean $pParamHash['fAutoAvatar'] automatically create avatar from portrait
+ * @access public
+ * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ */
+ function storeImages( $pParamHash ) {
+ if( isset( $_FILES['fPortraitFile'] ) && is_uploaded_file( $_FILES['fPortraitFile']['tmp_name'] ) && $_FILES['fPortraitFile']['size'] > 0 ) {
+ $portraitHash = $pParamHash;
+ $portraitHash['upload'] = $_FILES['fPortraitFile'];
+ if( !$this->storePortrait( $portraitHash, ( !empty( $portraitHash['fAutoAvatar'] ) ? TRUE : FALSE ))) {
+ }
+ }
+
+ if( isset( $_FILES['fAvatarFile'] ) && is_uploaded_file( $_FILES['fAvatarFile']['tmp_name'] ) && $_FILES['fAvatarFile']['size'] > 0 ) {
+ $avatarHash = $pParamHash;
+ $avatarHash['upload'] = $_FILES['fAvatarFile'];
+ $avatarHash['upload']['source_file'] = $_FILES['fAvatarFile']['tmp_name'];
+ if( !$this->storeAvatar( $avatarHash )) {
+ }
+ }
+
+ if( isset( $_FILES['fLogoFile'] ) && is_uploaded_file( $_FILES['fLogoFile']['tmp_name'] ) && $_FILES['fLogoFile']['size'] > 0 ) {
+ $logoHash = $pParamHash;
+ $logoHash['upload'] = $_FILES['fLogoFile'];
+ $logoHash['upload']['source_file'] = $_FILES['fLogoFile']['tmp_name'];
+ if( !$this->storeLogo( $logoHash )) {
+ }
+ }
+ }
- function storePortrait( &$pStorageHash, $pGenerateAvatar=FALSE ) {
+ /**
+ * storePortrait
+ *
+ * @param array $pStorageHash
+ * @param array $pGenerateAvatar
+ * @access public
+ * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ */
+ function storePortrait( &$pStorageHash, $pGenerateAvatar = FALSE ) {
if( $this->isValid() && count( $pStorageHash ) ) {
+ // make a copy before the uploaded file disappears
+ if( $pGenerateAvatar ) {
+ $avatarHash = $pStorageHash;
+ $avatarHash['upload']['tmp_name'] = $pStorageHash['upload']['tmp_name'].'.av';
+ copy( $pStorageHash['upload']['tmp_name'], $pStorageHash['upload']['tmp_name'].'.av' );
+ }
+
// setup the hash for central storage functions
$pStorageHash['upload']['max_width'] = PORTRAIT_MAX_DIM;
$pStorageHash['upload']['max_height'] = PORTRAIT_MAX_DIM;
- // $pStorageHash['upload']['dest_base_name'] = 'portrait';
$pStorageHash['upload']['dest_path'] = $this->getStorageBranch( 'self',$this->mUserId );
$pStorageHash['storage_type'] = STORAGE_IMAGE;
$pStorageHash['content_type_guid'] = BITUSER_CONTENT_TYPE_GUID;
$pStorageHash['attachment_id'] = !empty( $this->mInfo['portrait_attachment_id'] ) ? $this->mInfo['portrait_attachment_id'] : NULL;
- if( $pGenerateAvatar ) {
- copy($pStorageHash['upload']['tmp_name'],$pStorageHash['upload']['tmp_name'].'.av');
- $avatarHash = $pStorageHash;
- }
-
$pStorageHash['_files_override']['portrait'] = $pStorageHash['upload'];
+ // don't do the content thing
+ $pStorageHash['skip_content_store'] = TRUE;
if( LibertyAttachable::store( $pStorageHash ) ) {
$attachmentId = $pStorageHash['STORAGE']['bitfile']['portrait']['upload']['attachment_id'];
if( empty( $this->mInfo['portrait_attachment_id'] ) || $this->mInfo['portrait_attachment_id'] != $attachmentId ) {
@@ -1231,8 +1266,8 @@ class BitUser extends LibertyAttachable {
$this->mInfo['portrait_attachment_id'] = $attachmentId;
$pStorageHash['portrait_storage_path'] = $pStorageHash['upload']['dest_path'];
}
+
if( $pGenerateAvatar ) {
- $avatarHash['upload']['tmp_name'] = $pStorageHash['upload']['tmp_name'].'.av';
$this->storeAvatar( $avatarHash );
}
} else {
@@ -1242,18 +1277,25 @@ class BitUser extends LibertyAttachable {
return( count( $this->mErrors ) == 0 );
}
-
+ /**
+ * storeAvatar
+ *
+ * @param array $pStorageHash
+ * @access public
+ * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ */
function storeAvatar( &$pStorageHash ) {
if( $this->isValid() && count( $pStorageHash ) ) {
// setup the hash for central storage functions
$pStorageHash['upload']['max_width'] = AVATAR_MAX_DIM;
$pStorageHash['upload']['max_height'] = AVATAR_MAX_DIM;
- // $pStorageHash['upload']['dest_base_name'] = 'avatar';
$pStorageHash['upload']['dest_path'] = $this->getStorageBranch( 'self',$this->mUserId );
$pStorageHash['storage_type'] = STORAGE_IMAGE;
$pStorageHash['content_type_guid'] = BITUSER_CONTENT_TYPE_GUID;
$pStorageHash['attachment_id'] = !empty( $this->mInfo['avatar_attachment_id'] ) ? $this->mInfo['avatar_attachment_id'] : NULL;
$pStorageHash['_files_override']['avatar'] = $pStorageHash['upload'];
+ // don't do the content thing
+ $pStorageHash['skip_content_store'] = TRUE;
if( LibertyAttachable::store( $pStorageHash ) ) {
$attachmentId = $pStorageHash['STORAGE']['bitfile']['avatar']['upload']['attachment_id'];
if( empty( $this->mInfo['avatar_attachment_id'] ) || $this->mInfo['avatar_attachment_id'] != $attachmentId ) {
@@ -1269,7 +1311,13 @@ class BitUser extends LibertyAttachable {
return( count( $this->mErrors ) == 0 );
}
-
+ /**
+ * storeLogo
+ *
+ * @param array $pStorageHash
+ * @access public
+ * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ */
function storeLogo( &$pStorageHash ) {
if( $this->isValid() && count( $pStorageHash ) ) {
// setup the hash for central storage functions
@@ -1279,8 +1327,9 @@ class BitUser extends LibertyAttachable {
$pStorageHash['storage_type'] = STORAGE_IMAGE;
$pStorageHash['content_type_guid'] = BITUSER_CONTENT_TYPE_GUID;
$pStorageHash['attachment_id'] = $this->mInfo['logo_attachment_id'];
-
$pStorageHash['_files_override']['logo'] = $pStorageHash['upload'];
+ // don't do the content thing
+ $pStorageHash['skip_content_store'] = TRUE;
if( LibertyAttachable::store( $pStorageHash ) ) {
$attachmentId = $pStorageHash['STORAGE']['bitfile']['logo']['upload']['attachment_id'];
if($this->mInfo['logo_attachment_id'] != $attachmentId ) {
@@ -1295,6 +1344,13 @@ class BitUser extends LibertyAttachable {
return( count( $this->mErrors ) == 0 );
}
+ /**
+ * purgeImage
+ *
+ * @param array $pType
+ * @access public
+ * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ */
function purgeImage( $pType ) {
if( $this->isValid() && @$this->verifyId( $this->mInfo[$pType.'_attachment_id'] ) ) {
$this->mDb->StartTrans();
diff --git a/my_images.php b/my_images.php
index b42ec05..48674a0 100644
--- a/my_images.php
+++ b/my_images.php
@@ -1,6 +1,6 @@
<?php
/**
- * $Header: /cvsroot/bitweaver/_bit_users/my_images.php,v 1.10 2007/09/21 03:50:27 spiderr Exp $
+ * $Header: /cvsroot/bitweaver/_bit_users/my_images.php,v 1.11 2007/09/26 09:24:22 squareing Exp $
*
* Copyright (c) 2004 bitweaver.org
* Copyright (c) 2003 tikwiki.org
@@ -8,12 +8,10 @@
* All Rights Reserved. See copyright.txt for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
*
- * $Id: my_images.php,v 1.10 2007/09/21 03:50:27 spiderr Exp $
+ * $Id: my_images.php,v 1.11 2007/09/26 09:24:22 squareing Exp $
* @package users
* @subpackage functions
*/
-global $gEditMode;
-$gEditMode = 'images';
/**
* required setup
@@ -23,34 +21,22 @@ require_once( '../bit_setup_inc.php' );
// User preferences screen
$gBitSystem->verifyFeature( 'users_preferences' );
-if (!$gBitUser->isRegistered()) {
- $gBitSmarty->assign('msg', tra("You are not logged in"));
- $gBitSystem->display( 'error.tpl' );
- die;
+if( !$gBitUser->isRegistered() ) {
+ $gBitSystem->fatalError( tra( "You are not logged in" ));
}
-if (!isset($_REQUEST["showall"])) {
- $_REQUEST["showall"] = 'n';
-}
-
-include_once(USERS_PKG_PATH.'lookup_user_inc.php');
+include_once( USERS_PKG_PATH.'lookup_user_inc.php' );
-if ($gQueryUser->mUserId != $gBitUser->mUserId && !$gBitUser->object_has_permission($gBitUser->mUserId, $gQueryUser->mInfo['content_id'], 'bituser', 'p_users_admin')) {
- $gBitSmarty->assign('msg', tra('You do not have permission to edit this user\'s images'));
- $gBitSystem->display('error.tpl');
- die;
+if( $gQueryUser->mUserId != $gBitUser->mUserId ) {
+ $gBitSystem->fatalError( tra( "You do not have permission to edit this user's images" ));
}
-$gBitSmarty->assign('showall', $_REQUEST["showall"]);
-$userwatch = $gQueryUser->mUsername;
-$gBitSmarty->assign('userwatch', $userwatch);
-$_REQUEST["user_id"]=$gQueryUser->mUserId;
+$_REQUEST["user_id"] = $gQueryUser->mUserId;
// Upload avatar is processed here
if( !empty( $_REQUEST['fSubmitBio'] ) ) {
$gQueryUser->store( $_REQUEST );
- $url = $gQueryUser->getDisplayUrl( $gQueryUser->mInfo['login'] );
- header( "Location: ".$url );
+ bit_redirect( $gQueryUser->getDisplayUrl( $gQueryUser->mInfo['login'] ) );
} elseif( isset( $_REQUEST['fSubmitDeletePortait'] ) ) {
$gQueryUser->purgePortrait();
$gQueryUser->load();
@@ -62,20 +48,9 @@ if( !empty( $_REQUEST['fSubmitBio'] ) ) {
$gQueryUser->load();
}
-if (isset($_REQUEST["uselib"])) {
- $avatarHash['type'] = AVATAR_TYPE_LIBRARY;
- $avatarHash['avatar_lib_name'] = $_REQUEST["avatar"];
- $avatarHash['avatar_name'] = NULL;
- $avatarHash['avatar_size'] = NULL;
- $avatarHash['avatar_type'] = NULL;
- $avatarHash['avatar_data'] = NULL;
- $gQueryUser->storeAvatar( $avatarHash );
-}
-
// For some reason, we have to reassign here to make our changes to gBitUser->mInfo present in smarty.
// dunno why, but this fixes the bug. XOXO spiderr
-$gBitSmarty->assign_by_ref('gQueryUser', $gQueryUser);
-
-$gBitSystem->display( 'bitpackage:users/my_images.tpl');
+$gBitSmarty->assign_by_ref( 'gQueryUser', $gQueryUser );
+$gBitSystem->display( 'bitpackage:users/my_images.tpl', tra( 'Personal Images' ));
?>
diff --git a/templates/my_images.tpl b/templates/my_images.tpl
index dc61cf1..2137ee0 100644
--- a/templates/my_images.tpl
+++ b/templates/my_images.tpl
@@ -8,7 +8,7 @@
{include file="bitpackage:users/my_bitweaver_bar.tpl"}
<div class="body">
- {form enctype="multipart/form-data" method="post" legend="Upload personal Portrait, Avatar and Logo"}
+ {form enctype="multipart/form-data" legend="Upload personal Portrait, Avatar and Logo"}
{if $fHomepage}
<input type="hidden" name="fHomepage" value="{$fHomepage}"/>
{/if}