$search_for = trim(array_get_index($_GET, 'quick-search-for', ''));
// If we are searching for something
if ($search_for != '') {
    // check for a url first
    $asset_by_url = $GLOBALS['SQ_SYSTEM']->am->getAssetFromURL('', strip_url($search_for, TRUE), TRUE, TRUE);
    if (!empty($asset_by_url) && ($asset_by_url->type() != 'file' || !$asset_by_url->readAccess())) {
        $asset_by_url = NULL;
    }
    if (assert_valid_assetid($search_for, '', TRUE, FALSE)) {
        $asset_by_id = $GLOBALS['SQ_SYSTEM']->am->getAsset($search_for, '', TRUE);
        if (!empty($asset_by_id) && ($asset_by_id->type() != 'file' || !$asset_by_id->readAccess())) {
            $asset_by_id = NULL;
        }
    }
    // Only search for files (strict type check)
    $results = Backend_Search::processSearch($search_for, array(), array('file' => FALSE));
    $html = '';
    $found_asset_line = '';
    if (!empty($asset_by_url)) {
        $found_asset =& $asset_by_url;
        $found_asset_line .= '<strong>' . 'Matched on URL:' . '</strong>';
    }
    if (!empty($asset_by_id)) {
        $found_asset =& $asset_by_id;
        $found_asset_line .= '<strong>' . 'Matched on Asset ID:' . '</strong>';
    }
    if (!empty($found_asset)) {
        $asset_name = $found_asset->name;
        $found_asset_line .= '<div class="search-result">';
        $found_asset_line .= get_asset_tag_line($found_asset->id, 'javascript:set_asset_finder_from_search(\'' . $found_asset->id . '\', \'' . htmlspecialchars($asset_name, ENT_QUOTES) . '\', \'\', \'0\');');
        $found_asset_line .= '</div>';
 if (!empty($asset_by_id)) {
     $found_asset =& $asset_by_id;
     $found_asset_line .= '<strong>' . 'Matched on Asset ID:' . '</strong>';
 }
 if (!empty($found_asset)) {
     $asset_title = $found_asset->attr('title');
     $asset_alt = addslashes($found_asset->attr('alt'));
     $asset_width = $found_asset->attr('width');
     $asset_height = $found_asset->attr('height');
     $asset_name = $found_asset->name;
     $found_asset_line .= '<div class="search-result">';
     $found_asset_line .= get_asset_tag_line($found_asset->id, 'javascript:set_asset_finder_from_search(\'' . $found_asset->id . '\', \'' . htmlspecialchars($asset_title, ENT_QUOTES) . '\', \'\', \'0\', \'' . $asset_name . '\', \'' . $asset_alt . '\', \'' . $asset_width . '\', \'' . $asset_height . '\');');
     $found_asset_line .= '</div>';
 } else {
     // Only search for images
     $results = Backend_Search::processSearch($search_for, array(), array('image' => TRUE));
     if (!empty($results)) {
         $result_list = array();
         foreach ($results as $result_assetid => $result_detail) {
             $tag_line = get_asset_tag_line($result_assetid);
             $this_detail = array();
             foreach ($result_detail as $result_component_name => $result_component) {
                 foreach ($result_component as $name => $value) {
                     $name_detail = '';
                     switch ($result_component_name) {
                         case 'contents':
                             $name_detail = 'Asset Contents';
                             break;
                         case 'metadata':
                         case 'schema':
                             $name_detail = ($result_component_name == 'schema' ? 'Default ' : '') . 'Metadata: ';
 if (!empty($asset_by_id)) {
     $found_asset =& $asset_by_id;
     $found_asset_line .= '<strong>' . 'Matched on Asset ID:' . '</strong>';
 }
 // Make sure the user has read permission on the found asset
 if (!empty($found_asset) && !$found_asset->readAccess()) {
     $found_asset = NULL;
     $found_asset_line = '';
 }
 if (!empty($found_asset)) {
     $asset_name = $found_asset->name;
     $found_asset_line .= '<div class="search-result">';
     $found_asset_line .= get_asset_tag_line($found_asset->id, 'javascript:set_asset_finder_from_search(\'' . $found_asset->id . '\', \'' . htmlspecialchars($asset_name, ENT_QUOTES) . '\', \'\', \'0\',\'' . $found_asset->type() . '\')');
     $found_asset_line .= '</div>';
 } else {
     $results = Backend_Search::processSearch($search_for);
     if (!empty($results)) {
         $result_list = array();
         foreach ($results as $result_assetid => $result_detail) {
             $tag_line = get_asset_tag_line($result_assetid);
             $this_detail = array();
             foreach ($result_detail as $result_component_name => $result_component) {
                 foreach ($result_component as $name => $value) {
                     $name_detail = '';
                     switch ($result_component_name) {
                         case 'contents':
                             $name_detail = 'Asset Contents';
                             break;
                         case 'metadata':
                         case 'schema':
                             $name_detail = ($result_component_name == 'schema' ? 'Default ' : '') . 'Metadata: ';