Browse Source

Integrate Rank Image Drop Down, move stars to images/stars

Signed-off-by: Rick Kerkhof <[email protected]>
Rick Kerkhof 12 years ago
parent
commit
48e541ce4f

+ 1 - 1
Sources/Display.php

@@ -1815,4 +1815,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'] . '/stars/' . $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),
@@ -2881,4 +2881,4 @@ function get_memcached_server($level = 3)
 		get_memcached_server($level - 1);
 }
 
-?>
+?>

+ 37 - 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,41 @@ 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['possibleStars'] = array();
+	if ($files = scandir($settings['default_theme_dir'] . '/images/stars'))
+	{
+		// Loop through every file in the directory.
+		foreach ($files as $value)
+		{
+			// Grab the image extension.
+			$ext = pathinfo($settings['default_theme_dir'] . '/images/stars/' . $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/stars/' . $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['possibleStars'][] = $value;
+			}
+		}
+	}
+	
+	// Insert our JS, if we have possible stars.
+	if (!empty($context['possibleStars']))
+		$context['html_headers'] .= '
+	<script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/stardropdown.js"></script>';
 
 	// Finally, get all the groups this could be inherited off.
 	$request = $smcFunc['db_query']('', '
@@ -1157,4 +1192,4 @@ function ModifyMembergroupsettings()
 	prepareDBSettingContext($config_vars);
 }
 
-?>
+?>

+ 2 - 2
Sources/Subs-Membergroups.php

@@ -703,7 +703,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'] . '/stars/' . $row['icons'][1] . '" alt="*" />', $row['icons'][0]) : '',
 		);
 
 		$context['can_moderate'] |= $row['can_moderate'];
@@ -795,4 +795,4 @@ function list_getMembergroups($start, $items_per_page, $sort, $membergroup_type)
 	return $groups;
 }
 
-?>
+?>

+ 28 - 5
Themes/default/ManageMembergroups.template.php

@@ -270,16 +270,39 @@ function template_edit_group()
 						</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>
+						</dd>';
+        
+        // Do we have any possible stars to select from?
+       	if (!empty($context['possibleStars']))
+       	{
+       		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 star, create an option.
+		foreach ($context['possibleStars'] as $star)
+		{
+			echo '
+								<option value="', $star, '"', $context['group']['icon_image'] == $star ? ' selected="selected"' : '', '>', $star, '</option>';
+		}
+	
+		echo '
+							</select>
+							<img id="star_preview" src="', $settings['images_url'], '/stars/', $context['group']['star_image'] == '' ? 'blank.png' : $context['group']['star_image'], '" 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/stars/blank.png


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


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


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


+ 0 - 0
Themes/default/images/iconmod.png → Themes/default/images/stars/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/stars/';
 $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';
-?>
+?>

+ 20 - 0
Themes/default/scripts/stardropdown.js

@@ -0,0 +1,20 @@
+window.onload = function()
+{
+	document.getElementById('icon_image_input').onchange = function()
+	{
+		// Get the star count element.
+		var star_count = document.getElementById('icon_count_input');
+		var select_box = document.getElementById('icon_image_input');
+	
+		// If it's empty, set it to 1.
+		if (select_box.value && star_count.value == 0)
+			star_count.value = 1;
+	
+		// Else set it to 0 if the select box is empty(?)
+		else if (!select_box.value)
+			star_count.value = 0;
+	
+		// Update the star preview.
+		document.getElementById('star_preview').src = smf_default_theme_url + '/images/stars/' + ((select_box.value && star_count.value > 0) ? select_box.value : 'blank.gif');
+	}
+}