Exemplo n.º 1
0
        if ($image_results && $out == 'xml') {
            $media_results = $image_results;
        }
        $audio_results = media($query, $link, 'audio', $all, $urlx, $title, $image_dir, 'foundAudio', 'normSearch', 'notes60.gif', $mode, $media_only, $type, $category, $catid, $mark, $db, $prefix, $domain);
        //  prepare media results for XML output file
        if ($audio_results && $out == 'xml') {
            $media_results = array_merge($media_results, $audio_results);
        }
        $video_results = media($query, $link, 'video', $all, $urlx, $title, $image_dir, 'foundVideo', 'normSearch', 'film60.gif', $mode, $media_only, $type, $category, $catid, $mark, $db, $prefix, $domain);
        //  prepare media results for XML output file
        if ($video_results && $out == 'xml') {
            $media_results = array_merge($media_results, $video_results);
        }
        //  if activated, prepare the XML result file
        if ($out == 'xml' && $xml_name) {
            media_xml($media_results, count($media_results), $query, round(getmicrotime() - $start_all, 3));
        }
        echo "\n                <br /><br />\n                <a class=\"navup\" href=\"#top\" title=\"Jump to Page Top\">" . $sph_messages['top'] . "</a>\n                ";
        break;
}
// if selected in Admin settings, show 'Most Popular Searches'
if ($most_pop == 1) {
    $bgcolor = 'odrow';
    $count = 0;
    //  get most popular queries sorted by count of searches
    $sql_query = "SELECT query, count(*) as c,\n                                    date_format(max(time),\n                                    '%Y-%m-%d %H:%i:%s'),\n                                    avg(results), media\n                                    from " . $mysql_table_prefix . "query_log\n                                    group by query order by c desc";
    /*
             //  use the following for sorting by 'Last queried'
             $sql_query = "SELECT query, count(*) as c,
             date_format(max(time),
             '%Y-%m-%d %H:%i:%s'),
Exemplo n.º 2
0
function media_only($query, $start, $media_only, $type, $category, $catid, $mark, $db, $prefix, $domain)
{
    global $db_con, $mysql_table_prefix, $debug, $debug_user, $admin_dir, $include_dir, $case_sensitive;
    global $results_per_page, $image_dir, $sph_messages, $dbu_act, $template, $template_dir, $index_id3;
    global $use_cache, $mediacache_dir, $mcache_size, $max_cmresults, $max_results;
    global $dbu_act, $db1_slv, $db2_slv, $db3_slv, $db4_slv, $db5_slv, $elapsed;
    global $mytitle, $show_categories, $has_categories, $checked_cat, $tpl, $checked_all;
    global $adv, $advanced_search, $show_media, $description, $embedded;
    global $out, $xml_dir, $xml_name, $vowels, $noacc_el, $translit_el, $delim, $viking;
    global $cat_sel, $cat_sel0, $cat_sel0a, $cat_sel1, $cat_sel2, $cat_sel3, $cat_sel4, $cat_sel_all;
    //error_reporting (E_ALL);      //  for debug only
    $orig_query = $query;
    $starttime = getmicrotime();
    $query = str_replace('*', '', $query);
    //      kill wildcards, as media search already includes it
    if ($domain) {
        //  prepare the mysql query for domain search
        $domain_qry = "AND link_addr like '%" . $domain . "%'";
    } else {
        $domain_qry = "";
    }
    if (!$category) {
        $category = '0';
    }
    if ($debug_user == '1') {
        $slv1 = '';
        $slv2 = '';
        $slv3 = '';
        $slv4 = '';
        $slv5 = '';
        if ($db1_slv == 1) {
            $slv1 = '1,';
        }
        if ($db2_slv == 1) {
            $slv2 = '2,';
        }
        if ($db3_slv == 1) {
            $slv3 = '3,';
        }
        if ($db4_slv == 1) {
            $slv4 = '4,';
        }
        if ($db5_slv == 1) {
            $slv5 = '5';
        }
        echo "      <small>Results from database " . $slv1 . " " . $slv2 . " " . $slv3 . " " . $slv4 . " " . $slv5 . "</small>\n          <br />\n    ";
    }
    // if cached results should be used
    $cache_query = str_replace('"', '', $query);
    if (!$domain && $use_cache == '1' && !preg_match("/!|\\/|\\*|\\~|#|%|<|>|\\(|\\)|{|}|\\[|\\]|\\^|\\\\/", $cache_query)) {
        $cache_ok = '1';
        if (!is_dir($mediacache_dir)) {
            mkdir($mediacache_dir, 0777);
            //if not exist, try to create folder for media cache
            if (!is_dir($mediacache_dir)) {
                echo "<br />Unable to create folder for media cache<br />";
                $cache_ok = '';
            }
        }
        $no_cache = '1';
        if (is_dir($mediacache_dir)) {
            $rd_handle = fopen("" . $mediacache_dir . "/" . $cache_query . "_" . $type . "_" . $category . "_" . $cat_sel0 . "_" . $cat_sel0a . "_" . $cat_sel1 . "_" . $cat_sel2 . "_" . $cat_sel3 . "_" . $cat_sel4 . ".txt", "r+b");
            if ($rd_handle) {
                $cache_result = file_get_contents("" . $mediacache_dir . "/" . $cache_query . "_" . $type . "_" . $category . "_" . $cat_sel0 . "_" . $cat_sel0a . "_" . $cat_sel1 . "_" . $cat_sel2 . "_" . $cat_sel3 . "_" . $cat_sel4 . ".txt");
                if ($cache_result) {
                    $no_cache = '';
                    if ($debug_user == '1') {
                        echo "<small>Results found in cache</small><br />";
                    }
                    //  update cache-file with new modified date and time
                    file_put_contents("" . $mediacache_dir . "/" . $cache_query . "_" . $type . "_" . $category . "_" . $cat_sel0 . "_" . $cat_sel0a . "_" . $cat_sel1 . "_" . $cat_sel2 . "_" . $cat_sel3 . "_" . $cat_sel4 . ".txt", $cache_result);
                    //  make file content readable for result listing
                    $media_results = unserialize($cache_result);
                }
            }
            fclose($rd_handle);
        }
        //      get fresh results, because no cached result for this query available
        if ($no_cache == '1') {
            if ($debug_user == '1') {
                echo "<small>No results found in cache.<br />Get fresh result from database.</small><br />";
            }
            $media_results = all_fresh($query, $domain_qry, $mysql_table_prefix, $catid, $prefix);
            $media_count = count($media_results);
            //      if query did not match any media object
            if ($media_count < '1') {
                $msg = str_replace('%query', htmlentities(utf8_decode($query)), $sph_messages["noMediaMatch"]);
                //   display no media results found
                include "" . $template_dir . "/html/200_no media found.html";
                return '';
            }
        }
        $media_results = array_slice($media_results, 0, $max_cmresults);
        //  reduce to max allowed results per query
        if ($cache_ok == '1' && $no_cache == '1' && $media_results[0][2]) {
            //      create new cache file for new query input
            $wr_handle = fopen("" . $mediacache_dir . "/" . $cache_query . "_" . $type . "_" . $category . "_" . $cat_sel0 . "_" . $cat_sel0a . "_" . $cat_sel1 . "_" . $cat_sel2 . "_" . $cat_sel3 . "_" . $cat_sel4 . ".txt", "r");
            if (!$wr_handle) {
                //   create new cache file for current query input
                $result_string = serialize($media_results);
                if ($debug_user == '1') {
                    echo "<small>Create new result files and thumbnails for media cache.</small><br />";
                }
                $new_handle = fopen("" . $mediacache_dir . "/" . $cache_query . "_" . $type . "_" . $category . "_" . $cat_sel0 . "_" . $cat_sel0a . "_" . $cat_sel1 . "_" . $cat_sel2 . "_" . $cat_sel3 . "_" . $cat_sel4 . ".txt", "wb");
                if (!fwrite($new_handle, $result_string)) {
                    echo "<br />Unable to write into media cache<br />";
                }
                fclose($new_handle);
            } else {
                fclose($wr_handle);
            }
            //      get total size and time of creation for each cache file
            $size = '0';
            $all = array();
            $all_keys = array();
            $all_vals = array();
            if ($handle = opendir($mediacache_dir)) {
                while (false !== ($file = readdir($handle))) {
                    if ($file != "." && $file != "..") {
                        $size = $size + filesize("" . $mediacache_dir . "/" . $file . "");
                        $created = filemtime("" . $mediacache_dir . "/" . $file . "");
                        $all_vals[] = $file;
                        $all_keys[] = $created;
                    }
                }
            }
            $cache_size = $mcache_size * 1048576;
            //  cache size in Byte
            if ($size > $cache_size) {
                $all = array_combine($all_keys, $all_vals);
                ksort($all);
                //  find oldest cache file
                $del = current($all);
                @unlink("" . $mediacache_dir . "/" . $del . "");
                // delete oldest cache file
                if ($debug_user == '1') {
                    echo "<small>Cache overflow. Delete least significant file in cache ({$del})</small><br />";
                }
            }
            closedir($handle);
        }
    } else {
        //      get fresh results without cache
        $media_results = all_fresh($query, $domain_qry, $mysql_table_prefix, $catid, $prefix);
    }
    //  limit amount of results in result listing shown for pure media search
    $media_results = array_slice($media_results, 0, $max_results, TRUE);
    //  save info to query_log
    $endtime = getmicrotime() - $starttime;
    $media_count = count($media_results);
    $time = round($endtime, 3);
    $client_ip = $_SERVER['REMOTE_ADDR'];
    $orig_query = str_replace("*", "", $orig_query);
    //  remove wildcard character
    saveToLog(addslashes($orig_query), $time, $media_count, $client_ip, 1);
    //  if activated, prepare the XML result file
    if ($out == 'xml' && $xml_name) {
        media_xml($media_results, $media_count, $orig_query, $time);
    }
    //  single result option for wikinger-reisen.de
    if ($media_count == 1 && $viking) {
        require_once "wikinger.php";
        $search = 1;
        $media_only = 1;
        $client_ip = $_SERVER['REMOTE_ADDR'];
        $url = $media_results[0][2];
        //  URL of first result
        viking_option($url, $query, $search, $media_only, $category, $type, $db, $results_per_page, $prefix, $client_ip);
    }
    //      if query did not match any media object
    if ($media_count < '1') {
        //$msg = str_replace ('%query', htmlentities(utf8_decode($query)), $sph_messages["noMediaMatch"]);
        $msg = str_replace('%query', $orig_query, $sph_messages["noMediaMatch"]);
        //   display no media results found
        include "" . $template_dir . "/html/200_no media found.html";
        return '';
    }
    //Prepare results for listing
    $pages = ceil($media_count / $results_per_page);
    // Calculate count of required pages
    $class = "odrow";
    if (empty($start)) {
        $start = '1';
    }
    // As $start is not yet defined this is required for the first result page
    if ($start == '1') {
        $from = '0';
        // Also for first page in order not to multipy with 0
    } else {
        $from = ($start - 1) * $results_per_page;
        // First $num_row of actual page
    }
    $to = $media_count;
    // Last $num_row of actual page
    $rest = $media_count - $start;
    if ($media_count > $results_per_page) {
        // Display more then one page?
        $rest = $media_count - $from;
        $to = $from + $rest;
        // $to for last page
        if ($rest > $results_per_page) {
            $to = $from + $results_per_page;
        }
        // Calculate $num_row of actual page
    }
    //  result listing starts here
    if ($media_count > '0') {
        $fromm = $from + 1;
        $result = $sph_messages['Results'];
        $result = str_replace('%from', $from, $result);
        $result = str_replace('%to', $to, $result);
        $result = str_replace('%all', $media_count, $result);
        $matchword = $sph_messages["matches"];
        if ($media_count == 1) {
            $matchword = $sph_messages["match"];
        } else {
            $matchword = $sph_messages["matches"];
        }
        //  should we show the elapsed time in header?
        if ($elapsed) {
            $result = str_replace('%matchword', $matchword, $result);
            $result = str_replace('%secs', $time, $result);
        } else {
            $result = '';
            if ($media_count > 1) {
                $result = "" . $sph_messages['matches'] . " " . $from . " - " . $to . " " . $sph_messages['from'] . " " . $media_count . "";
            }
        }
        //  get name for valid catid
        $row = array();
        $row['category'] = '';
        if ($category != '-1') {
            $sql_query = "SELECT * from " . $mysql_table_prefix . "categories\n                                                where category_id = '{$catid}'";
            $reso = $db_con->query($sql_query);
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            if ($reso->num_rows) {
                $row = $reso->fetch_array(MYSQL_ASSOC);
            }
        }
        //   display header for media-only results
        include "" . $template_dir . "/html/110_media-only header.html";
        //  loop through all results
        for ($i = $from; $i < $to; $i++) {
            $this_media = $media_results[$i];
            //      prepare current object-link for media counter
            $media_crypt = str_replace("&", "-_-", $this_media[3]);
            //  crypt the & character
            $media_click = "{$include_dir}/media_counter.php?url={$media_crypt}&amp;query={$query}&amp;db={$db}&amp;prefix={$prefix}&amp;client_ip={$client_ip}";
            //  redirect users click in order to update Most Popular Media
            //      prepare current page-link for click counter
            $link_crypt = str_replace("&", "-_-", $this_media[2]);
            $link_click = "{$include_dir}/click_counter.php?url={$link_crypt}&amp;query={$query}&amp;db={$db}&amp;prefix={$prefix}&amp;client_ip={$client_ip}";
            //  redirect users click in order to update Most Popular Links
            $media_title = $this_media[5];
            //  media title
            $thumb_link = utf8_encode($this_media[4]);
            //  link to thumbnail
            $i_1 = $i + 1;
            //  so table output does not start with zero
            $title = array();
            $sql_query = "SELECT title from " . $mysql_table_prefix . "links where link_id = " . $this_media[1] . "";
            //   if available get title of current page
            $result = $db_con->query($sql_query);
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            if ($result->num_rows > '0') {
                $row = $result->fetch_array(MYSQLI_ASSOC);
                $page_title = $row["title"];
                // presents the page title
                $img_name = substr($this_media[3], strrpos($this_media[3], "/") + 1);
            }
            if ($class == "odrow") {
                $class = "evrow";
            } else {
                $class = "odrow";
            }
            //   display  media-only result listing
            include "" . $template_dir . "/html/120_media-only results.html";
        }
        //   display  end of result listing and links to other result pages
        include "" . $template_dir . "/html/190_more media-results.html";
    }
    return;
}