Version 3.1.4

This commit is contained in:
Neo committed 2025-12-19 00:32:22 -08:00
1 parent 1d4720f3e2
commit ae5c01cc78
2563 files changed
+283048 -240689

No files matched your search

@@ -1,19 +1,21 @@
<?php
/**
* <pre>
* Invision Power Services
* IP.Board v3.0.5
* IP.Board v3.1.4
* Extended Member Functions. Disparate functions that are not required
* on every page view.
* Last Updated: $Date: 2009-09-22 17:31:43 -0400 (Tue, 22 Sep 2009) $
* Last Updated: $Date: 2010-08-05 19:11:01 -0400 (Thu, 05 Aug 2010) $
* </pre>
*
* @author $Author: josh $ (Original: MattMecham)
* @author $Author: bfarber $ (Original: MattMecham)
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.iinvisionpower.com/community/board/license.html
* @package Invision Power Board
* @link http://www.iinvisionpower.com
* @license http://www.invisionpower.com/community/board/license.html
* @package IP.Board
* @link http://www.invisionpower.com
* @since Tuesday 1st March 2005 (11:52)
* @version $Revision: 5141 $
* @version $Revision: 6731 $
*
*/
@@ -147,7 +149,7 @@ class memberFunctions
// So, lets do the converteroo
//-----------------------------------------
IPSMember::save( $member['member_id'], array( 'core' => array( 'name' => $name, 'members_l_username' => mb_strtolower( $name ), 'members_seo_name' => $_seoName ) ) );
IPSMember::save( $member['member_id'], array( 'core' => array( 'name' => $name, 'members_l_username' => mb_strtolower( $name ) ) ) );
$this->DB->force_data_type = array( 'member_name' => 'string' );
$this->DB->update( 'moderators', array( 'member_name' => $name ), "member_id=" . $member['member_id'] );
@@ -253,11 +255,11 @@ class memberFunctions
{
if( $field == 'members_display_name' )
{
return array( 'members_display_name' => $cleanedName['name'], 'errors' => array( 'dname' => ipsRegistry::getClass( 'class_localization' )->words['reg_error_username_taken'] ) );
return array( 'members_display_name' => $cleanedName['name'], 'errors' => array( 'dname' => 'reg_error_username_taken' ) );
}
else
{
return array( 'username' => $cleanedName['name'], 'errors' => array( 'username' => ipsRegistry::getClass( 'class_localization' )->words['reg_error_username_taken'] ) );
return array( 'username' => $cleanedName['name'], 'errors' => array( 'username' => 'reg_error_username_taken' ) );
}
}
}
@@ -272,11 +274,11 @@ class memberFunctions
switch( $e->getMessage() )
{
case 'NO_NAME':
return array( 'members_display_name' => $cleanedName['name'], 'errors' => array( 'dname' => ipsRegistry::getClass( 'class_localization' )->words['reg_error_no_name'] ) );
return array( 'members_display_name' => $cleanedName['name'], 'errors' => array( 'dname' => 'reg_error_no_name' ) );
break;
case 'ILLEGAL_CHARS':
return array( 'members_display_name' => $cleanedName['name'], 'errors' => array( 'dname' => ipsRegistry::getClass( 'class_localization' )->words['reg_error_chars'] ) );
return array( 'members_display_name' => $cleanedName['name'], 'errors' => array( 'dname' => 'reg_error_chars' ) );
break;
}
}
@@ -285,11 +287,11 @@ class memberFunctions
switch( $e->getMessage() )
{
case 'NO_NAME':
return array( 'username' => $cleanedName['name'], 'errors' => array( 'username' => ipsRegistry::getClass( 'class_localization' )->words['reg_error_username_none'] ) );
return array( 'username' => $cleanedName['name'], 'errors' => array( 'username' => 'reg_error_username_none' ) );
break;
case 'ILLEGAL_CHARS':
return array( 'username' => $cleanedName['name'], 'errors' => array( 'username' => ipsRegistry::getClass( 'class_localization' )->words['reg_error_chars'] ) );
return array( 'username' => $cleanedName['name'], 'errors' => array( 'username' => 'reg_error_chars' ) );
break;
}
}
@@ -332,7 +334,7 @@ class memberFunctions
$error = "";
$banFilters = array();
$_timeCheck = time() - 86400 * $this->memberData['g_dname_date'];
$member = ( isset( $member['member_id'] ) ) ? $member : $this->memberData;
$member = is_array($member) ? $member : array();
$checkField = ( $field == 'members_display_name' ) ? 'members_l_display_name' : 'members_l_username';
//-----------------------------------------
@@ -373,14 +375,17 @@ class memberFunctions
// Grab # changes > 24 hours
//-----------------------------------------
$name_count = $this->DB->buildAndFetch( array( 'select' => 'COUNT(*) as count, MIN(dname_date) as min_date', 'from' => 'dnames_change', 'where' => "dname_member_id=" . $member['member_id'] . " AND dname_date > $_timeCheck" ) );
$name_count['count'] = intval( $name_count['count'] );
$name_count['min_date'] = intval( $name_count['min_date'] ) ? intval( $name_count['min_date'] ) : $_timeCheck;
if ( intval( $name_count['count'] ) >= $member['g_dname_changes'] )
if( $member['member_id'] )
{
throw new Exception( "NO_MORE_CHANGES" );
$name_count = $this->DB->buildAndFetch( array( 'select' => 'COUNT(*) as count, MIN(dname_date) as min_date', 'from' => 'dnames_change', 'where' => "dname_member_id=" . $member['member_id'] . " AND dname_date > $_timeCheck" ) );
$name_count['count'] = intval( $name_count['count'] );
$name_count['min_date'] = intval( $name_count['min_date'] ) ? intval( $name_count['min_date'] ) : $_timeCheck;
if ( intval( $name_count['count'] ) >= $member['g_dname_changes'] )
{
throw new Exception( "NO_MORE_CHANGES" );
}
}
}
@@ -426,12 +431,30 @@ class memberFunctions
// Check for existing name.
//-----------------------------------------
/* Load the handler if it's not present */
if( ! $this->han_login )
{
$classToLoad = IPSLib::loadLibrary( IPS_ROOT_PATH . 'sources/handlers/han_login.php', 'han_login' );
$this->han_login = new $classToLoad( $this->registry );
$this->han_login->init();
}
if( $member['member_id'] )
{
$this->han_login->nameExistsCheck( $name, $member, $checkField );
if( $this->han_login->return_code AND $this->han_login->return_code != 'METHOD_NOT_DEFINED' AND $this->han_login->return_code != 'NAME_NOT_IN_USE' )
{
return TRUE;
}
}
$this->DB->build( array(
'select' => "{$field}, member_id",
'from' => 'members',
'where' => $checkField . "='". $this->DB->addSlashes( mb_strtolower($name) )."' AND member_id != ".$member['member_id'],
'where' => $checkField . "='" . $this->DB->addSlashes( mb_strtolower($name) ) . "'" . ( $member['member_id'] ? " AND member_id != " . $member['member_id'] : '' ),
'limit' => array( 0,1 ) ) );
$this->DB->execute();
//-----------------------------------------
@@ -446,7 +469,7 @@ class memberFunctions
//-----------------------------------------
// Not allowed to select another's log in name
//-----------------------------------------
if ( $field == 'members_display_name' AND $this->settings['auth_dnames_nologinname'] )
{
$check_name = $this->DB->buildAndFetch( array( 'select' => "{$field}, member_id",
@@ -456,7 +479,7 @@ class memberFunctions
if ( $this->DB->getTotalRows() )
{
if ( $member['member_id'] AND $check_name['member_id'] != $member['member_id'] )
if ( !$member['member_id'] OR $check_name['member_id'] != $member['member_id'] )
{
return TRUE;
}
@@ -464,7 +487,7 @@ class memberFunctions
}
if ( $field == 'name' AND $this->settings['auth_dnames_nologinname'] )
{
{
$check_name = $this->DB->buildAndFetch( array( 'select' => "{$field}, member_id",
'from' => 'members',
'where' => "members_l_display_name='" . $this->DB->addSlashes( mb_strtolower($name) ) . "'",
@@ -472,20 +495,20 @@ class memberFunctions
if ( $this->DB->getTotalRows() )
{
if ( $member['member_id'] AND $check_name['member_id'] != $member['member_id'] )
if ( !$member['member_id'] OR $check_name['member_id'] != $member['member_id'] )
{
return TRUE;
}
}
}
//-----------------------------------------
// Test for unicode name
//-----------------------------------------
$unicodeName = $this->_getUnicodeName( $name );
if ( $unicodeName != $name )
//-----------------------------------------
// Test for unicode name
//-----------------------------------------
$unicodeName = $this->_getUnicodeName( $name );
if ( $unicodeName != $name )
{
//-----------------------------------------
// Check for existing name.
@@ -493,7 +516,7 @@ class memberFunctions
$this->DB->build( array( 'select' => "members_display_name, member_id, email",
'from' => 'members',
'where' => $checkField . "='". $this->DB->addSlashes( mb_strtolower($unicodeName) )."' AND member_id != ".$member['member_id'],
'where' => $checkField . "='". $this->DB->addSlashes( mb_strtolower($unicodeName) ) . "'" . ( $member['member_id'] ? " AND member_id != " . $member['member_id'] : '' ),
'limit' => array( 0,1 ) ) );
$this->DB->execute();
@@ -600,13 +623,14 @@ class memberFunctions
if( ipsRegistry::$settings['username_characters'] )
{
$check_against = preg_quote( ipsRegistry::$settings['username_characters'], "/" );
if( !preg_match( "/^[" . $check_against . "]+$/i", $name ) )
$check_against = str_replace( '\-', '-', $check_against ); // Fix for bug #20998
if( !preg_match( "/^[" . $check_against . "]+$/iu", $name ) )
{
return array( 'name' => $original, 'errors' => array( str_replace( '{chars}', ipsRegistry::$settings['username_characters'], ipsRegistry::$settings['username_errormsg'] ) ) );
}
}
//-----------------------------------------
// Manually check against bad chars
//-----------------------------------------
@@ -794,7 +818,7 @@ class memberFunctions
$upload->out_file_name = 'photo-'.$member_id;
$upload->out_file_dir = $upload_path;
$upload->max_file_size = ($p_max * 1024) * 8; // Allow xtra for compression
$upload->max_file_size = $p_max * 1024;
$upload->upload_form_field = 'upload_photo';
//-----------------------------------------
@@ -876,60 +900,71 @@ class memberFunctions
{
$imageDimensions = getimagesize( $upload_path . '/' . $real_name );
//-----------------------------------------
// Main photo
//-----------------------------------------
if( $imageDimensions[0] > $p_width OR $imageDimensions[1] > $p_height )
{
//-----------------------------------------
// Main photo
//-----------------------------------------
require_once( IPS_KERNEL_PATH."classImage.php" );
require_once( IPS_KERNEL_PATH."classImageGd.php" );
$image = new classImageGd();
$image->init( array(
'image_path' => $upload_path,
'image_file' => $real_name,
) );
'image_path' => $upload_path,
'image_file' => $real_name,
) );
$return = $image->resizeImage( $p_width, $p_height );
$image->writeImage( $upload_path . '/' . 'photo-'.$member_id . '.' . $upload->file_extension );
$t_real_name = $return['thumb_location'] ? $return['thumb_location'] : $real_name;
$im['img_width'] = $return['newWidth'] ? $return['newWidth'] : $image->cur_dimensions['width'];
$im['img_height'] = $return['newHeight'] ? $return['newHeight'] : $image->cur_dimensions['height'];
//-----------------------------------------
// MINI photo
//-----------------------------------------
$image->init( array(
'image_path' => $upload_path,
'image_file' => $t_real_name,
) );
$return = $image->resizeImage( $t_width, $t_height );
$image->writeImage( $upload_path . '/' . 'photo-thumb-'.$member_id . '.' . $upload->file_extension );
$t_im['img_width'] = $return['newWidth'];
$t_im['img_height'] = $return['newHeight'];
$t_im['img_location'] = count($return) ? 'photo-thumb-'.$member_id . '.' . $upload->file_extension : $real_name;
}
else
{
$im['img_width'] = $imageDimensions[0];
$im['img_height'] = $imageDimensions[1];
}
//-----------------------------------------
// MINI photo
//-----------------------------------------
if( $imageDimensions[0] > $t_width OR $imageDimensions[1] > $t_height )
{
require_once( IPS_KERNEL_PATH . "classImage.php" );
require_once( IPS_KERNEL_PATH . "classImageGd.php" );
$image = new classImageGd();
//-----------------------------------------
// Mini photo
//-----------------------------------------
$image->init( array(
'image_path' => $upload_path,
'image_file' => $t_real_name,
) );
$return = $image->resizeImage( $t_width, $t_height );
$image->writeImage( $upload_path . '/' . 'photo-thumb-'.$member_id . '.' . $upload->file_extension );
$t_im['img_width'] = $return['newWidth'];
$t_im['img_height'] = $return['newHeight'];
$t_im['img_location'] = count($return) ? 'photo-thumb-'.$member_id . '.' . $upload->file_extension : $real_name;
}
else
{
$_data = IPSLib::scaleImage( array(
'max_height' => $t_height,
'max_width' => $t_width,
'cur_width' => $im['img_width'],
'cur_height' => $im['img_height']
) );
$_data = IPSLib::scaleImage( array( 'max_height' => $t_height,
'max_width' => $t_width,
'cur_width' => $im['img_width'],
'cur_height' => $im['img_height'] ) );
$t_im['img_width'] = $_data['img_width'];
$t_im['img_width'] = $_data['img_width'];
$t_im['img_height'] = $_data['img_height'];
$t_im['img_location'] = $real_name;
}
@@ -1011,6 +1046,222 @@ class memberFunctions
return $return;
}
/**
* Upload background image
* Assumes all security checks have been performed by this point
*
* @access public
* @param integer [Optional] member id instead of current member
* @return array [ error (error message), status (status message [ok/fail] ) ]
*/
public function uploadBackgroundImage( $member_id = 0 )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$return = array( 'error' => '',
'status' => '',
'final_location' => '' );
$member_id = $member_id ? intval($member_id) : intval( $this->memberData['member_id'] );
$p_max = $this->memberData['g_max_bgimg_upload'] ? intval( $this->memberData['g_max_bgimg_upload'] ) : 999999999;
$real_name = '';
$upload_dir = '';
$final_location = '';
if( ! $member_id )
{
return array( 'status' => 'cannot_find_member' );
}
//-----------------------------------------
// Sort out upload dir
//-----------------------------------------
/* Fix for bug 5075 */
$this->settings['upload_dir'] = str_replace( '&#46;', '.', $this->settings['upload_dir'] );
$upload_path = $this->settings['upload_dir'];
# Preserve original path
$_upload_path = $this->settings['upload_dir'];
//-----------------------------------------
// Already a dir?
//-----------------------------------------
if ( ! file_exists( $upload_path . "/bgimages" ) )
{
if ( @mkdir( $upload_path . "/bgimages", 0777 ) )
{
@file_put_contents( $upload_path . '/bgimages/index.html', '' );
@chmod( $upload_path . "/bgimages", 0777 );
# Set path and dir correct
$upload_path .= "/bgimages";
$upload_dir = "bgimages/";
}
else
{
# Set path and dir correct
$upload_dir = "";
}
}
else
{
# Set path and dir correct
$upload_path .= "/bgimages";
$upload_dir = "bgimages/";
}
//-----------------------------------------
// Lets check for an uploaded photo..
//-----------------------------------------
if ( $_FILES['bg_upload']['name'] != "" and ($_FILES['bg_upload']['name'] != "none" ) )
{
//-----------------------------------------
// Are we allowed to upload this photo?
//-----------------------------------------
if ( $p_max < 0 )
{
$return['status'] = 'fail';
$return['error'] = 'no_bgimg_upload_permission';
}
//-----------------------------------------
// Remove any uploaded photos...
//-----------------------------------------
$this->removeUploadedBackgroundImages( $member_id );
$real_name = 'bgimg-'.$member_id;
//-----------------------------------------
// Load the library
//-----------------------------------------
require_once( IPS_KERNEL_PATH.'classUpload.php' );
$upload = new classUpload();
//-----------------------------------------
// Set up the variables
//-----------------------------------------
$upload->out_file_name = 'bgimg-'.$member_id;
$upload->out_file_dir = $upload_path;
$upload->max_file_size = $p_max * 1024;
$upload->upload_form_field = 'bg_upload';
//-----------------------------------------
// Populate allowed extensions
//-----------------------------------------
if ( is_array( $this->cache->getCache('attachtypes') ) and count( $this->cache->getCache('attachtypes') ) )
{
foreach( $this->cache->getCache('attachtypes') as $data )
{
if ( $data['atype_photo'] )
{
if( $data['atype_extension'] == 'swf' AND $this->settings['disable_flash'] )
{
continue;
}
$upload->allowed_file_ext[] = $data['atype_extension'];
}
}
}
//-----------------------------------------
// Upload...
//-----------------------------------------
$upload->process();
//-----------------------------------------
// Error?
//-----------------------------------------
if ( $upload->error_no )
{
switch( $upload->error_no )
{
case 1:
// No upload
$return['status'] = 'fail';
$return['error'] = 'upload_failed';
break;
case 2:
// Invalid file ext
$return['status'] = 'fail';
$return['error'] = 'invalid_file_extension';
break;
case 3:
// Too big...
$return['status'] = 'fail';
$return['error'] = 'upload_to_big';
break;
case 4:
// Cannot move uploaded file
$return['status'] = 'fail';
$return['error'] = 'upload_failed';
break;
case 5:
// Possible XSS attack (image isn't an image)
$return['status'] = 'fail';
$return['error'] = 'upload_failed';
break;
}
return $return;
}
//-----------------------------------------
// Still here?
//-----------------------------------------
$real_name = $upload->parsed_file_name;
$t_real_name = $upload->parsed_file_name;
//-----------------------------------------
// Check the file size (after compression)
//-----------------------------------------
if ( filesize( $upload_path . "/" . $real_name ) > ( $p_max * 1024 ) )
{
@unlink( $upload_path . "/" . $real_name );
// Too big...
$return['status'] = 'fail';
$return['error'] = 'upload_to_big';
return $return;
}
//-----------------------------------------
// Main
//-----------------------------------------
$final_location = $upload_dir . $real_name;
}
else
{
$return['status'] = 'ok';
return $return;
}
//-----------------------------------------
// Return...
//-----------------------------------------
$return['final_location'] = $final_location;
$return['status'] = 'ok';
return $return;
}
/**
* Remove member uploaded photos
@@ -1027,10 +1278,7 @@ class memberFunctions
//-----------------------------------------
$upload_path = $upload_path ? $upload_path : $this->settings['upload_dir'];
# Preserve original path
$_upload_path = $this->settings['upload_dir'];
//-----------------------------------------
// Already a dir?
//-----------------------------------------
@@ -1044,35 +1292,79 @@ class memberFunctions
# Set path and dir correct
$upload_path .= "/profile";
$upload_dir = "profile/";
}
else
{
# Set path and dir correct
$upload_dir = "";
}
}
else
{
# Set path and dir correct
$upload_path .= "/profile";
$upload_dir = "profile/";
}
//-----------------------------------------
// Go...
//-----------------------------------------
foreach( array( 'swf', 'jpg', 'jpeg', 'gif', 'png' ) as $ext )
{
if ( @file_exists( $upload_path."/photo-".$id.".".$ext ) )
{
@unlink( $upload_path."/photo-".$id.".".$ext );
}
if ( @file_exists( $upload_path."/photo-thumb-".$id.".".$ext ) )
//-----------------------------------------
// Only try to delete if we didn't just create dir
//-----------------------------------------
foreach( array( 'swf', 'jpg', 'jpeg', 'gif', 'png' ) as $ext )
{
@unlink( $upload_path."/photo-thumb-".$id.".".$ext );
if ( @file_exists( $upload_path."/photo-".$id.".".$ext ) )
{
@unlink( $upload_path."/photo-".$id.".".$ext );
}
if ( @file_exists( $upload_path."/photo-thumb-".$id.".".$ext ) )
{
@unlink( $upload_path."/photo-thumb-".$id.".".$ext );
}
}
}
}
/**
* Remove member uploaded background images
*
* @access public
* @param integer Member ID
* @param string [Optional] Directory to check
* @return array [ error (error message), status (status message [ok/fail] ) ]
*/
public function removeUploadedBackgroundImages( $id, $upload_path='' )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$upload_path = $upload_path ? $upload_path : $this->settings['upload_dir'];
//-----------------------------------------
// Already a dir?
//-----------------------------------------
if ( ! file_exists( $upload_path . "/bgimages" ) )
{
if ( @mkdir( $upload_path . "/bgimages", 0777 ) )
{
@file_put_contents( $upload_path . '/index.html', '' );
@chmod( $upload_path . "/bgimages", 0777 );
# Set path and dir correct
$upload_path .= "/bgimages";
}
}
else
{
# Set path and dir correct
$upload_path .= "/bgimages";
//-----------------------------------------
// Only should bother trying to delete if we didn't
// just create the folder
//-----------------------------------------
foreach( array( 'swf', 'jpg', 'jpeg', 'gif', 'png' ) as $ext )
{
if ( @file_exists( $upload_path."/bgimg-".$id.".".$ext ) )
{
@unlink( $upload_path."/bgimg-".$id.".".$ext );
}
}
}
}
@@ -1207,7 +1499,7 @@ class memberFunctions
$upload->out_file_name = $real_name;
$upload->out_file_dir = $this->settings['upload_dir'];
$upload->max_file_size = ($this->settings['avup_size_max'] * 1024) * 8; // Allow xtra for compression
$upload->max_file_size = $this->settings['avup_size_max'] * 1024;
$upload->upload_form_field = $uploadFieldName;
//-----------------------------------------
@@ -1388,8 +1680,16 @@ class memberFunctions
$directory .= '/';
}
}
$filename = preg_replace( "/[^\s\w\._\-\[\]\(\)]/", "", urldecode( $this->request[$avatarGalleryImage] ) );
// BUG #20822
if( function_exists( 'mb_ereg_replace' ) )
{
$filename = mb_ereg_replace( "/[^\s\w\._\-\[\]\(\)]/", "", urldecode( $this->request[$avatarGalleryImage] ) );
}
else
{
$filename = preg_replace( "/[^\s\w\._\-\[\]\(\)]/", "", urldecode( $this->request[$avatarGalleryImage] ) );
}
if( file_exists( DOC_IPS_ROOT_PATH . PUBLIC_DIRECTORY . '/style_avatars/' . $directory . $filename ) )
{
@@ -1447,7 +1747,7 @@ class memberFunctions
*/
public function getHostedAvatarsFromCategory( $catName )
{
//$catName = IPSText::alphanumericalClean( $catName ); // Commented out because alphanumericalClean removes spaces
$catName = IPSText::alphanumericalClean( $catName, ' ' ); // Commented out because alphanumericalClean removes spaces
$images = array();
$path = '';
@@ -1540,8 +1840,8 @@ class memberFunctions
*/
private function _sortAvatars( $a, $b )
{
$aa = strtolower($a[1]);
$bb = strtolower($b[1]);
$aa = mb_strtolower($a[1]);
$bb = mb_strtolower($b[1]);
if ( $aa == $bb ) return 0;