<?php

// Dropdown Filter URLs
$page_url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$short_page_url = $_SERVER["REQUEST_URI"];
$cat_id = get_query_var('cat');
$category_url = get_category_link($cat_id);

if($gp_settings['page_var'] == "homepage") {
	$category_url = home_url().'?';
} elseif(is_search()) {
	$category_url = $category_url.'?s='.esc_html($s).'&amp;';
} else {
	if(get_option("permalink_structure")) {
		$category_url = $category_url.'?';
	} else { 
		$category_url = $category_url.'&amp;';	
	}
}

?>

<div id="dropdown-filter">
	
	<div class="order-by-text"><?php _e('Order By', 'gp_lang'); ?>:</div>
		
	<form class="order-by-form">
		<select>
			<option value="<?php echo $category_url; ?>orderby=date"<?php if(preg_match('/orderby=date/', $page_url)) { ?> selected<?php } ?>><?php _e('Date', 'gp_lang'); ?></option>		
			<option value="<?php echo $category_url; ?>orderby=title"<?php if(preg_match('/orderby=title/', $page_url)) { ?> selected<?php } ?>><?php _e('Title', 'gp_lang'); ?></option>								
			<?php if($gp_settings['orderby_site_score'] == true) { ?><option value="<?php echo $category_url; ?>gdsr_sort=review"<?php if(preg_match('/gdsr_sort=review/', $page_url)) { ?> selected<?php } ?>><?php _e('Site Score', 'gp_lang'); ?></option><?php } ?>			
			<?php if($gp_settings['orderby_user_score'] == true) { ?><option value="<?php echo $category_url; ?>gdsr_sort=rating"<?php if(preg_match('/gdsr_sort=rating/', $page_url)) { ?> selected<?php } ?>><?php _e('User Score', 'gp_lang'); ?></option><?php } ?>								
		</select>
	</form>
	
	<div class="order-text"><?php _e('Order', 'gp_lang'); ?>:</div>

	<form class="order-form">
		<select>
			<option value="<?php if(preg_match('/orderby=/', $page_url) OR preg_match('/gdsr_sort=/', $page_url) OR !get_option("permalink_structure")) { ?><?php echo $short_page_url; ?>&order=desc&gdsr_order=desc<?php } else { ?><?php echo $short_page_url; ?>?order=desc<?php } ?>"<?php if(preg_match('/order=desc/', $page_url)) { ?> selected<?php } ?>><?php _e('Descending', 'gp_lang'); ?></option>							
			<option value="<?php if(preg_match('/orderby=/', $page_url) OR preg_match('/gdsr_sort=/', $page_url) OR !get_option("permalink_structure")) { ?><?php echo $short_page_url; ?>&order=asc&gdsr_order=asc<?php } else { ?><?php echo $short_page_url; ?>?order=asc<?php } ?>" <?php if(preg_match('/order=asc/', $page_url)) { ?> selected<?php } ?>><?php _e('Ascending', 'gp_lang'); ?></option>				
		</select>
	</form>

</div>