}
// sort extensions by title, this will break with non-ascii symbols no doubt
if (sizeof($extension_titles) > 1) {
    asort($extension_titles, SORT_STRING);
    $temp = array();
    foreach ($extension_titles as $ext_id => $ext_title) {
        $temp[$ext_id] = $extensions[$ext_id];
    }
    $extensions = $temp;
    // clean up
    unset($temp);
    unset($extension_titles);
}
// uploading
if ($site->fdat['op'] == "upload") {
    $ext = new extension_upload();
}
if ($site->fdat['upload']) {
    verify_form_token();
    $ext->tmp_location = $site->absolute_path . "shared/" . time() . "_" . rand(1, 837838);
    $ext->extensions_folder = $site->absolute_path . "extensions";
    $ext->overwrite_extension = $site->fdat['overwrite'];
    $ext->unpack_extension('extension');
    // variable is the array name in $_FILES where the file resides.
    $ext->find_file('extension.config.php');
    if ($ext->validate_extension()) {
        sync_extensions();
        $synced = 1;
    }
    $zip = new archive();
    $zip->deltree($ext->tmp_location);
	$temp = array();
	
	foreach($extension_titles as $ext_id => $ext_title)
	{
		$temp[$ext_id] = $extensions[$ext_id];
	}
	$extensions = $temp;
	
	// clean up
	unset($temp);
	unset($extension_titles);
}

// uploading
if($site->fdat['op'] == "upload"){
	$ext = new extension_upload();
}

if($site->fdat['upload']){

	$ext->tmp_location=$site->absolute_path."shared/".time()."_".rand(1,837838);
	$ext->extensions_folder=$site->absolute_path."extensions";
	$ext->overwrite_extension=$site->fdat['overwrite'];
	$ext->unpack_extension('extension'); // variable is the array name in $_FILES where the file resides.
	$ext->find_file('extension.config.php');
	if($ext->validate_extension()){
		sync_extensions();
		$synced = 1;
	}
	$zip= new archive();
	$zip->deltree($ext->tmp_location);