Browse Source

Merge pull request #296 from Yoshi2889/release-2.1

Integrate Rank Image Drop Down, move stars to images/membericons
emanuele45 11 years ago
parent
commit
ada15b432e

+ 1 - 1
Sources/Display.php

@@ -1812,4 +1812,4 @@ function QuickInTopicModeration()
 	redirectexit(!empty($topicGone) ? 'board=' . $board : 'topic=' . $topic . '.' . $_REQUEST['start']);
 }
 
-?>
+?>

+ 2 - 2
Sources/Load.php

@@ -1182,7 +1182,7 @@ function loadMemberContext($user, $display_custom_fields = false)
 			'group_id' => $profile['id_group'],
 			'post_group' => $profile['post_group'],
 			'post_group_color' => $profile['post_group_color'],
-			'group_icons' => str_repeat('<img src="' . str_replace('$language', $context['user']['language'], isset($profile['icons'][1]) ? $settings['images_url'] . '/' . $profile['icons'][1] : '') . '" alt="*" />', empty($profile['icons'][0]) || empty($profile['icons'][1]) ? 0 : $profile['icons'][0]),
+			'group_icons' => str_repeat('<img src="' . str_replace('$language', $context['user']['language'], isset($profile['icons'][1]) ? $settings['images_url'] . '/membericons/' . $profile['icons'][1] : '') . '" alt="*" />', empty($profile['icons'][0]) || empty($profile['icons'][1]) ? 0 : $profile['icons'][0]),
 			'warning' => $profile['warning'],
 			'warning_status' => !empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $profile['warning'] ? 'mute' : (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $profile['warning'] ? 'moderate' : (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $profile['warning'] ? 'watch' : (''))),
 			'local_time' => timeformat(time() + ($profile['time_offset'] - $user_info['time_offset']) * 3600, false),
@@ -2947,4 +2947,4 @@ function get_memcached_server($level = 3)
 		get_memcached_server($level - 1);
 }
 
-?>
+?>

+ 36 - 2
Sources/ManageMembergroups.php

@@ -628,7 +628,7 @@ function DeleteMembergroup()
  */
 function EditMembergroup()
 {
-	global $context, $txt, $sourcedir, $modSettings, $smcFunc;
+	global $context, $txt, $sourcedir, $modSettings, $smcFunc, $settings;
 
 	$_REQUEST['group'] = isset($_REQUEST['group']) && $_REQUEST['group'] > 0 ? (int) $_REQUEST['group'] : 0;
 
@@ -1078,6 +1078,40 @@ function EditMembergroup()
 		if ($max_boards == 1)
 			$max_boards = 2;
 	}
+	
+	// Get a list of all the image formats we can select.
+	$imageExts = array('png', 'jpg', 'jpeg', 'bmp', 'gif');
+	
+	// Scan the directory.
+	$context['possible_icons'] = array();
+	if ($files = scandir($settings['default_theme_dir'] . '/images/membericons'))
+	{
+		// Loop through every file in the directory.
+		foreach ($files as $value)
+		{
+			// Grab the image extension.
+			$ext = pathinfo($settings['default_theme_dir'] . '/images/membericons/' . $value, PATHINFO_EXTENSION);
+			
+			// If the extension is not empty, and it is valid, 
+			if (!empty($ext) && in_array($ext, $imageExts))
+			{
+				// Get the size of the image.
+				$image_info = getimagesize($settings['default_theme_dir'] . '/images/membericons/' . $value);
+				
+				// If this is bigger than 128 in width or 32 in height, skip this one.
+				if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32)
+					continue;
+					
+				// Else it's valid. Add it in.
+				else
+					$context['possible_icons'][] = $value;
+			}
+		}
+	}
+	
+	// Insert our JS, if we have possible icons.
+	if (!empty($context['possible_icons']))
+		loadJavascriptFile('icondropdown.js', array('validate' => true));
 
 	// Finally, get all the groups this could be inherited off.
 	$request = $smcFunc['db_query']('', '
@@ -1157,4 +1191,4 @@ function ModifyMembergroupsettings()
 	prepareDBSettingContext($config_vars);
 }
 
-?>
+?>

+ 2 - 2
Sources/Subs-Membergroups.php

@@ -702,7 +702,7 @@ function list_getMembergroups($start, $items_per_page, $sort, $membergroup_type)
 			'type' => $row['group_type'],
 			'num_members' => $row['num_members'],
 			'moderators' => array(),
-			'icons' => !empty($row['icons'][0]) && !empty($row['icons'][1]) ? str_repeat('<img src="' . $settings['images_url'] . '/' . $row['icons'][1] . '" alt="*" />', $row['icons'][0]) : '',
+			'icons' => !empty($row['icons'][0]) && !empty($row['icons'][1]) ? str_repeat('<img src="' . $settings['images_url'] . '/membericons/' . $row['icons'][1] . '" alt="*" />', $row['icons'][0]) : '',
 		);
 
 		$context['can_moderate'] |= $row['can_moderate'];
@@ -794,4 +794,4 @@ function list_getMembergroups($start, $items_per_page, $sort, $membergroup_type)
 	return $groups;
 }
 
-?>
+?>

+ 29 - 6
Themes/default/ManageMembergroups.template.php

@@ -269,17 +269,40 @@ function template_edit_group()
 							<label for="icon_count_input"><strong>', $txt['membergroups_icon_count'], ':</strong></label>
 						</dt>
 						<dd>
-							<input type="text" name="icon_count" id="icon_count_input" value="', $context['group']['icon_count'], '" size="4" onkeyup="if (this.value.length > 2) this.value = 99;" onkeydown="this.onkeyup();" onchange="if (this.value != 0) this.form.icon_image.onchange();" class="input_text" />
-						</dd>
+							<input type="text" name="icon_count" id="icon_count_input" value="', $context['group']['icon_count'], '" size="4" class="input_text" />
+						</dd>';
+        
+        // Do we have any possible icons to select from?
+       	if (!empty($context['possible_icons']))
+       	{
+       		echo '
 						<dt>
 							<label for="icon_image_input"><strong>', $txt['membergroups_icon_image'], ':</strong></label><br />
 							<span class="smalltext">', $txt['membergroups_icon_image_note'], '</span>
 						</dt>
 						<dd>
 							', $txt['membergroups_images_url'], '
-							<input type="text" name="icon_image" id="icon_image_input" value="', $context['group']['icon_image'], '" onchange="if (this.value &amp;&amp; this.form.icon_count.value == 0) this.form.icon_count.value = 1; else if (!this.value) this.form.icon_count.value = 0; document.getElementById(\'star_preview\').src = smf_images_url + \'/\' + (this.value &amp;&amp; this.form.icon_count.value > 0 ? this.value.replace(/\$language/g, \'', $context['user']['language'], '\') : \'blank.png\');" size="20" class="input_text" />
-							<img id="star_preview" src="', $settings['images_url'], '/', $context['group']['icon_image'] == '' ? 'blank.png' : $context['group']['icon_image'], '" alt="*" />
-						</dd>
+							<select name="icon_image" id="icon_image_input">';
+
+		// For every possible icon, create an option.
+		foreach ($context['possible_icons'] as $icon)
+		{
+			echo '
+								<option value="', $icon, '"', $context['group']['icon_image'] == $icon ? ' selected="selected"' : '', '>', $icon, '</option>';
+		}
+	
+		echo '
+							</select>
+							<img id="icon_preview" src="" alt="*" />
+						</dd>';
+	}
+	
+	// No? Hide the entire control.
+	else
+		echo '
+						<input type="hidden" name="icon_image" value="" />';
+						
+	echo '
 						<dt>
 							<label for="max_messages_input"><strong>', $txt['membergroups_max_messages'], ':</strong></label><br />
 							<span class="smalltext">', $txt['membergroups_max_messages_note'], '</span>
@@ -684,4 +707,4 @@ function template_group_request_reason()
 	</div>';
 }
 
-?>
+?>

BIN
Themes/default/images/membericons/blank.png


+ 0 - 0
Themes/default/images/icon.png → Themes/default/images/membericons/icon.png


+ 0 - 0
Themes/default/images/iconadmin.png → Themes/default/images/membericons/iconadmin.png


+ 0 - 0
Themes/default/images/icongmod.png → Themes/default/images/membericons/icongmod.png


+ 0 - 0
Themes/default/images/iconmod.png → Themes/default/images/membericons/iconmod.png


+ 3 - 3
Themes/default/languages/ManageMembers.english.php

@@ -49,7 +49,7 @@ $txt['membergroups_min_posts'] = 'Required posts';
 $txt['membergroups_online_color'] = 'Color in online list';
 $txt['membergroups_icon_count'] = 'Number of icon images';
 $txt['membergroups_icon_image'] = 'Icon image filename';
-$txt['membergroups_icon_image_note'] = 'you can use $language for the language of the user';
+$txt['membergroups_icon_image_note'] = 'You can upload custom images to the default theme directory to be able to select them here.';
 $txt['membergroups_max_messages'] = 'Max personal messages';
 $txt['membergroups_max_messages_note'] = '0 = unlimited';
 $txt['membergroups_edit_save'] = 'Save';
@@ -74,7 +74,7 @@ $txt['membergroups_postgroups'] = 'Post groups';
 $txt['membergroups_settings'] = 'Membergroup Settings';
 $txt['groups_manage_membergroups'] = 'Groups allowed to change membergroups';
 $txt['membergroups_select_permission_type'] = 'Select permission profile';
-$txt['membergroups_images_url'] = '{theme URL}/images/';
+$txt['membergroups_images_url'] = 'Themes/{theme}/images/membericons/';
 $txt['membergroups_select_visible_boards'] = 'Show boards';
 $txt['membergroups_members_top'] = 'Members';
 $txt['membergroups_name'] = 'Name';
@@ -127,4 +127,4 @@ $txt['dont_check_for_duplicate'] = 'Don\'t check for duplicates';
 $txt['duplicates'] = 'Duplicates';
 
 $txt['not_activated'] = 'Not activated';
-?>
+?>

+ 34 - 0
Themes/default/scripts/icondropdown.js

@@ -0,0 +1,34 @@
+$(document).ready(function()
+{	
+	$('#icon_count_input').change(function ()
+	{
+		var select_box = $('select#icon_image_input option:selected').val();
+		var icon_count = $('#icon_count_input');
+		if (icon_count.val() == 0 && select_box != 'blank.png')
+			icon_count.val(1);
+			
+		if (icon_count.val().length > 2)
+			icon_count.val(99);
+	});
+	
+	$('#icon_image_input').change(function ()
+	{
+		refreshIconPreview();
+	});
+
+	refreshIconPreview();
+});
+
+function refreshIconPreview()
+{
+	// Get the icon count element.
+	var icon_count = $('#icon_count_input');
+	var select_box = $('select#icon_image_input').val();
+
+	// If it's empty, set it to 1.
+	if (icon_count.val() == 0 && select_box != 'blank.png')
+		icon_count.val(1);
+
+	// Update the icon preview.
+	$('#icon_preview').attr('src', smf_default_theme_url + '/images/membericons/' + select_box);
+}