function get_cats($parent)
{
    global $db_con, $db_con, $mysql_table_prefix, $debug;
    $sql_query = "SELECT * FROM " . $mysql_table_prefix . "categories WHERE parent_num={$parent}";
    $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;
    }
    $arr[] = $parent;
    if ($result->num_rows) {
        while ($row = $result->fetch_array(MYSQL_ASSOC)) {
            $id = $row['category_id'];
            $arr = add_arrays($arr, get_cats($id));
        }
    }
    return $arr;
}
function get_cats($parent)
{
    global $db;
    $query = "SELECT * FROM " . TABLE_PREFIX . "categories WHERE parent_num={$parent}";
    $result = $db->query($query);
    echo sql_errorstring(__FILE__, __LINE__);
    $arr[] = $parent;
    while ($row = $result->fetch()) {
        $id = $row[category_id];
        $arr = add_arrays($arr, get_cats($id));
    }
    return $arr;
}
function get_cats($parent)
{
    global $mysql_table_prefix;
    $query = "SELECT * FROM " . $mysql_table_prefix . "categories WHERE parent_num={$parent}";
    echo mysql_error();
    $result = mysql_query($query);
    $arr[] = $parent;
    while (mysql_num_rows($result) != "" && ($row = mysql_fetch_array($result))) {
        $id = $row[category_id];
        $arr = add_arrays($arr, get_cats($id));
    }
    return $arr;
}
Beispiel #4
0
function get_cats($parent)
{
    global $mysql_table_prefix, $mysqli_conn;
    $query = "SELECT * FROM " . $mysql_table_prefix . "categories WHERE parent_num={$parent}";
    echo mysql_error();
    $result = $mysqli_conn->query($query);
    $arr[] = $parent;
    if ($result->num_rows > 0) {
        while ($row = $result->fetch_array()) {
            $id = $row[category_id];
            $arr = add_arrays($arr, get_cats($id));
        }
    }
    return $arr;
}
Beispiel #5
0
function get_cats($parent)
{
    // global $db, DEBUG;
    $query = "SELECT * FROM " . TABLE_PREFIX . "categories WHERE parent_num={$parent}";
    $result = mysql_query($query);
    if (DEBUG > '0') {
        echo mysql_error();
    }
    $arr[] = $parent;
    if (mysql_num_rows($result) != '') {
        while ($row = mysql_fetch_array($result)) {
            $id = $row[category_id];
            $arr = add_arrays($arr, get_cats($id));
        }
    }
    return $arr;
}
Beispiel #6
0
function deletecat($cat_id)
{
    global $mysql_table_prefix;
    $list = implode(",", get_cats($cat_id));
    mysql_query("delete from " . $mysql_table_prefix . "categories where category_id in ({$list})");
    echo mysql_error();
    mysql_query("delete from " . $mysql_table_prefix . "site_category where category_id={$cat_id}");
    echo mysql_error();
    return "<center><b>Category deleted.</b></center>";
}
Beispiel #7
0
function search($searchstr, $category, $start, $per_page, $type, $domain)
{
    global $length_of_link_desc, $mysql_table_prefix, $show_meta_description, $merge_site_results, $stem_words, $did_you_mean_enabled;
    $possible_to_find = 1;
    $result = mysql_query("select domain_id from " . $mysql_table_prefix . "domains where domain = '{$domain}'");
    if (mysql_num_rows($result) > 0) {
        $thisrow = mysql_fetch_array($result);
        $domain_qry = "and domain = " . $thisrow[0];
    } else {
        $domain_qry = "";
    }
    //find all sites that should not be included in the result
    if (count($searchstr['+']) == 0) {
        return null;
    }
    $wordarray = $searchstr['-'];
    $notlist = array();
    $not_words = 0;
    while ($not_words < count($wordarray)) {
        if ($stem_words == 1) {
            $searchword = addslashes(stem($wordarray[$not_words]));
        } else {
            $searchword = addslashes($wordarray[$not_words]);
        }
        $wordmd5 = substr(md5($searchword), 0, 1);
        $query1 = "SELECT link_id from " . $mysql_table_prefix . "link_keyword{$wordmd5}, " . $mysql_table_prefix . "keywords where " . $mysql_table_prefix . "link_keyword{$wordmd5}.keyword_id= " . $mysql_table_prefix . "keywords.keyword_id and keyword='{$searchword}'";
        $result = mysql_query($query1);
        while ($row = mysql_fetch_row($result)) {
            $notlist[$not_words]['id'][$row[0]] = 1;
        }
        $not_words++;
    }
    //find all sites containing the search phrase
    $wordarray = $searchstr['+s'];
    $phrase_words = 0;
    while ($phrase_words < count($wordarray)) {
        $searchword = addslashes($wordarray[$phrase_words]);
        $query1 = "SELECT link_id from " . $mysql_table_prefix . "links where fulltxt like '% {$searchword}%'";
        echo mysql_error();
        $result = mysql_query($query1);
        $num_rows = mysql_num_rows($result);
        if ($num_rows == 0) {
            $possible_to_find = 0;
            break;
        }
        while ($row = mysql_fetch_row($result)) {
            $phraselist[$phrase_words]['id'][$row[0]] = 1;
        }
        $phrase_words++;
    }
    if ($category > 0 && $possible_to_find == 1) {
        $allcats = get_cats($category);
        $catlist = implode(",", $allcats);
        $query1 = "select link_id from " . $mysql_table_prefix . "links, " . $mysql_table_prefix . "sites, " . $mysql_table_prefix . "categories, " . $mysql_table_prefix . "site_category where " . $mysql_table_prefix . "links.site_id = " . $mysql_table_prefix . "sites.site_id and " . $mysql_table_prefix . "sites.site_id = " . $mysql_table_prefix . "site_category.site_id and " . $mysql_table_prefix . "site_category.category_id in ({$catlist})";
        $result = mysql_query($query1);
        echo mysql_error();
        $num_rows = mysql_num_rows($result);
        if ($num_rows == 0) {
            $possible_to_find = 0;
        }
        while ($row = mysql_fetch_row($result)) {
            $category_list[$row[0]] = 1;
        }
    }
    //find all sites that include the search word
    $wordarray = $searchstr['+'];
    $words = 0;
    $starttime = getmicrotime();
    while ($words < count($wordarray) && $possible_to_find == 1) {
        if ($stem_words == 1) {
            $searchword = addslashes(stem($wordarray[$words]));
        } else {
            $searchword = addslashes($wordarray[$words]);
        }
        $wordmd5 = substr(md5($searchword), 0, 1);
        $query1 = "SELECT distinct link_id, weight, domain from " . $mysql_table_prefix . "link_keyword{$wordmd5}, " . $mysql_table_prefix . "keywords where " . $mysql_table_prefix . "link_keyword{$wordmd5}.keyword_id= " . $mysql_table_prefix . "keywords.keyword_id and keyword='{$searchword}' {$domain_qry} order by weight desc";
        echo mysql_error();
        $result = mysql_query($query1);
        $num_rows = mysql_num_rows($result);
        if ($num_rows == 0) {
            if ($type != "or") {
                $possible_to_find = 0;
                break;
            }
        }
        if ($type == "or") {
            $indx = 0;
        } else {
            $indx = $words;
        }
        while ($row = mysql_fetch_row($result)) {
            $linklist[$indx]['id'][] = $row[0];
            $domains[$row[0]] = $row[2];
            $linklist[$indx]['weight'][$row[0]] = $row[1];
        }
        $words++;
    }
    if ($type == "or") {
        $words = 1;
    }
    $result_array_full = array();
    if ($possible_to_find != 0) {
        if ($words == 1 && $not_words == 0 && $category < 1) {
            //if there is only one search word, we already have the result
            $result_array_full = $linklist[0]['weight'];
        } else {
            //otherwise build an intersection of all the results
            $j = 1;
            $min = 0;
            while ($j < $words) {
                if (count($linklist[$min]['id']) > count($linklist[$j]['id'])) {
                    $min = $j;
                }
                $j++;
            }
            $j = 0;
            $temp_array = $linklist[$min]['id'];
            $count = 0;
            while ($j < count($temp_array)) {
                $k = 0;
                //and word counter
                $n = 0;
                //not word counter
                $o = 0;
                //phrase word counter
                $weight = 1;
                $break = 0;
                while ($k < $words && $break == 0) {
                    if ($linklist[$k]['weight'][$temp_array[$j]] > 0) {
                        $weight = $weight + $linklist[$k]['weight'][$temp_array[$j]];
                    } else {
                        $break = 1;
                    }
                    $k++;
                }
                while ($n < $not_words && $break == 0) {
                    if ($notlist[$n]['id'][$temp_array[$j]] > 0) {
                        $break = 1;
                    }
                    $n++;
                }
                while ($o < $phrase_words && $break == 0) {
                    if ($phraselist[$n]['id'][$temp_array[$j]] != 1) {
                        $break = 1;
                    }
                    $o++;
                }
                if ($break == 0 && $category > 0 && $category_list[$temp_array[$j]] != 1) {
                    $break = 1;
                }
                if ($break == 0) {
                    $result_array_full[$temp_array[$j]] = $weight;
                    $count++;
                }
                $j++;
            }
        }
    }
    $end = getmicrotime() - $starttime;
    if ((count($result_array_full) == 0 || $possible_to_find == 0) && $did_you_mean_enabled == 1) {
        reset($searchstr['+']);
        foreach ($searchstr['+'] as $word) {
            $word = addslashes($word);
            $result = mysql_query("select keyword from " . $mysql_table_prefix . "keywords where soundex(keyword) = soundex('{$word}')");
            $max_distance = 100;
            $near_word = "";
            while ($row = mysql_fetch_row($result)) {
                $distance = levenshtein($row[0], $word);
                if ($distance < $max_distance && $distance < 4) {
                    $max_distance = $distance;
                    $near_word = $row[0];
                }
            }
            if ($near_word != "" && $word != $near_word) {
                $near_words[$word] = $near_word;
            }
        }
        $res['did_you_mean'] = $near_words;
        return $res;
    }
    if (count($result_array_full) == 0) {
        return null;
    }
    arsort($result_array_full);
    if ($merge_site_results == 1 && $domain_qry == "") {
        while (list($key, $value) = each($result_array_full)) {
            if (!isset($domains_to_show[$domains[$key]])) {
                $result_array_temp[$key] = $value;
                $domains_to_show[$domains[$key]] = 1;
            } else {
                if ($domains_to_show[$domains[$key]] == 1) {
                    $domains_to_show[$domains[$key]] = array($key => $value);
                }
            }
        }
    } else {
        $result_array_temp = $result_array_full;
    }
    while (list($key, $value) = each($result_array_temp)) {
        $result_array[$key] = $value;
        if (isset($domains_to_show[$domains[$key]]) && $domains_to_show[$domains[$key]] != 1) {
            list($k, $v) = each($domains_to_show[$domains[$key]]);
            $result_array[$k] = $v;
        }
    }
    $results = count($result_array);
    $keys = array_keys($result_array);
    $maxweight = $result_array[$keys[0]];
    for ($i = ($start - 1) * $per_page; $i < min($results, ($start - 1) * $per_page + $per_page); $i++) {
        $in[] = $keys[$i];
    }
    if (!is_array($in)) {
        $res['results'] = $results;
        return $res;
    }
    $inlist = implode(",", $in);
    if ($length_of_link_desc == 0) {
        $fulltxt = "fulltxt";
    } else {
        $fulltxt = "substring(fulltxt, 1, {$length_of_link_desc})";
    }
    $query1 = "SELECT distinct link_id, url, title, description,  {$fulltxt}, size FROM " . $mysql_table_prefix . "links WHERE link_id in ({$inlist})";
    $result = mysql_query($query1);
    echo mysql_error();
    $i = 0;
    while ($row = mysql_fetch_row($result)) {
        $res[$i]['title'] = $row[2];
        $res[$i]['url'] = $row[1];
        if ($row[3] != null && $show_meta_description == 1) {
            $res[$i]['fulltxt'] = $row[3];
        } else {
            $res[$i]['fulltxt'] = $row[4];
        }
        $res[$i]['size'] = $row[5];
        $res[$i]['weight'] = $result_array[$row[0]];
        $dom_result = mysql_query("select domain from " . $mysql_table_prefix . "domains where domain_id='" . $domains[$row[0]] . "'");
        $dom_row = mysql_fetch_row($dom_result);
        $res[$i]['domain'] = $dom_row[0];
        $i++;
    }
    if ($merge_site_results && $domain_qry == "") {
        sort_with_domains($res);
    } else {
        usort($res, "cmp");
    }
    echo mysql_error();
    $res['maxweight'] = $maxweight;
    $res['results'] = $results;
    return $res;
    /**/
}
function search($searchstr, $category, $start, $per_page, $type, $domain)
{
    global $length_of_link_desc, $show_meta_description, $merge_site_results, $stem_words;
    global $did_you_mean_enabled, $did_you_mean_always;
    global $matchless, $equivalent, $language;
    global $db;
    $possible_to_find = 1;
    $stat = $db->prepare("SELECT domain_id FROM " . TABLE_PREFIX . "domains WHERE domain = :domain");
    $stat->execute(array(':domain' => $domain));
    if ($row = $stat->fetch()) {
        $domain_qry = "and domain = " . $row[0];
    } else {
        $domain_qry = "";
    }
    $stat->closeCursor();
    /* if there are no words to search for, quit */
    if (!isset($searchstr['+']) || count($searchstr['+']) == 0) {
        return null;
    }
    /* find all words that should _not_ be included in the result */
    if (isset($searchstr['-'])) {
        $wordarray = $searchstr['-'];
    } else {
        $wordarray = array();
    }
    $notlist = array();
    $not_words = 0;
    while ($not_words < count($wordarray)) {
        if ($stem_words == 1) {
            $searchword = stem($wordarray[$not_words]);
        } else {
            $searchword = $wordarray[$not_words];
        }
        $wordmd5 = substr(md5($searchword), 0, 1);
        $stat = $db->prepare("SELECT link_id from " . TABLE_PREFIX . "link_keyword{$wordmd5}, " . TABLE_PREFIX . "keywords where " . TABLE_PREFIX . "link_keyword{$wordmd5}.keyword_id= " . TABLE_PREFIX . "keywords.keyword_id and keyword = :keyword");
        $stat->execute(array(':keyword' => $searchword));
        while ($row = $stat->fetch()) {
            $notlist[$not_words]['id'][$row[0]] = 1;
        }
        $not_words++;
    }
    /* find all phrases */
    if (isset($searchstr['+s'])) {
        $wordarray = $searchstr['+s'];
    } else {
        $wordarray = array();
    }
    $phrase_words = 0;
    while ($phrase_words < count($wordarray)) {
        $searchword = $wordarray[$phrase_words];
        $searchword = str_replace("|", "", $searchword);
        $searchword = str_replace("%", "|%", $searchword);
        $searchword = str_replace("_", "|_", $searchword);
        $stat = $db->prepare("SELECT link_id from " . TABLE_PREFIX . "links where fulltxt like :keyword escape '|'");
        $stat->execute(array(':keyword' => "%" . $searchword . "%"));
        echo sql_errorstring(__FILE__, __LINE__);
        $row = $stat->fetch();
        if (!$row) {
            $possible_to_find = 0;
            $stat->closeCursor();
            break;
        }
        $phraselist[$phrase_words]['id'][$row[0]] = 1;
        while ($row = $stat->fetch()) {
            $phraselist[$phrase_words]['id'][$row[0]] = 1;
        }
        $phrase_words++;
    }
    if ($category > 0 && $possible_to_find == 1) {
        $allcats = get_cats($category);
        $catlist = implode(",", $allcats);
        $result = $db->query("SELECT link_id FROM " . TABLE_PREFIX . "links, " . TABLE_PREFIX . "sites, " . TABLE_PREFIX . "categories, " . TABLE_PREFIX . "site_category where " . TABLE_PREFIX . "links.site_id = " . TABLE_PREFIX . "sites.site_id and " . TABLE_PREFIX . "sites.site_id = " . TABLE_PREFIX . "site_category.site_id and " . TABLE_PREFIX . "site_category.category_id in ({$catlist})");
        echo sql_errorstring(__FILE__, __LINE__);
        $row = $result->fetch();
        if (!$row) {
            $possible_to_find = 0;
        } else {
            $category_list[$row[0]] = 1;
            while ($row = $result->fetch()) {
                $category_list[$row[0]] = 1;
            }
        }
        $result->closeCursor();
    }
    /* find individual words */
    $word_not_found = array();
    $wordarray = $searchstr['+'];
    $words = 0;
    while ($words < count($wordarray) && $possible_to_find == 1) {
        if ($stem_words == 1) {
            $searchword = stem($wordarray[$words]);
        } else {
            $searchword = $wordarray[$words];
        }
        $wordmd5 = substr(md5($searchword), 0, 1);
        $stat = $db->prepare("SELECT distinct link_id, weight, domain FROM " . TABLE_PREFIX . "link_keyword{$wordmd5}, " . TABLE_PREFIX . "keywords WHERE " . TABLE_PREFIX . "link_keyword{$wordmd5}.keyword_id= " . TABLE_PREFIX . "keywords.keyword_id AND keyword=:keyword {$domain_qry}\tORDER\tBY\tweight\tDESC");
        $stat->execute(array(':keyword' => $searchword));
        echo sql_errorstring(__FILE__, __LINE__);
        $row = $stat->fetch();
        if (!$row) {
            $word_not_found[$wordarray[$words]] = 1;
            if ($type != "or") {
                $possible_to_find = 0;
                $stat->closeCursor();
                break;
            }
        }
        if ($type == "or") {
            $indx = 0;
        } else {
            $indx = $words;
        }
        do {
            $linklist[$indx]['id'][] = $row[0];
            $domains[$row[0]] = $row[2];
            $linklist[$indx]['weight'][$row[0]] = $row[1];
        } while ($row = $stat->fetch());
        $words++;
    }
    if ($type == "or") {
        $words = 1;
    }
    $result_array_full = array();
    if ($possible_to_find != 0) {
        if ($words == 1 && $not_words == 0 && $category < 1) {
            //if there is only one search word, we already have the result
            $result_array_full = $linklist[0]['weight'];
        } else {
            //otherwise build an intersection of all the results
            $j = 1;
            $min = 0;
            while ($j < $words) {
                if (count($linklist[$min]['id']) > count($linklist[$j]['id'])) {
                    $min = $j;
                }
                $j++;
            }
            $j = 0;
            $temp_array = $linklist[$min]['id'];
            $count = 0;
            while ($j < count($temp_array)) {
                $k = 0;
                //and word counter
                $n = 0;
                //not word counter
                $o = 0;
                //phrase word counter
                $weight = 1;
                $break = 0;
                while ($k < $words && $break == 0) {
                    if (isset($linklist[$k]['weight'][$temp_array[$j]]) && $linklist[$k]['weight'][$temp_array[$j]] > 0) {
                        $weight = $weight + $linklist[$k]['weight'][$temp_array[$j]];
                    } else {
                        $break = 1;
                    }
                    $k++;
                }
                while ($n < $not_words && $break == 0) {
                    if ($notlist[$n]['id'][$temp_array[$j]] > 0) {
                        $break = 1;
                    }
                    $n++;
                }
                while ($o < $phrase_words && $break == 0) {
                    if (!isset($phraselist[$n]['id'][$temp_array[$j]]) || $phraselist[$n]['id'][$temp_array[$j]] != 1) {
                        $break = 1;
                    }
                    $o++;
                }
                if ($break == 0 && $category > 0 && $category_list[$temp_array[$j]] != 1) {
                    $break = 1;
                }
                if ($break == 0) {
                    $result_array_full[$temp_array[$j]] = $weight;
                    $count++;
                }
                $j++;
            }
        }
    }
    if ((count($result_array_full) == 0 || $possible_to_find == 0 || $did_you_mean_always == 1) && $did_you_mean_enabled == 1) {
        /* search for word pairs written as two words where a single words
           for example: when the user typed "full colour", also search for
           fullcolour and full-colour */
        for ($idx = 0; $idx < count($searchstr['+']) - 1; $idx++) {
            $word = $searchstr['+'][$idx] . " " . $searchstr['+'][$idx + 1];
            $near_word = $searchstr['+'][$idx] . $searchstr['+'][$idx + 1];
            /* words that are in the "nonpareil" list are excluded in searching
               for alternatives */
            if (!isset($matchless[$near_word])) {
                $stat = $db->prepare("SELECT keyword FROM " . TABLE_PREFIX . "keywords WHERE keyword=:keyword");
                if ($stat->execute(array(':keyword' => $near_word)) && ($row = $stat->fetch())) {
                    $near_words[$word] = latin1_to_html($near_word);
                    $stat->closeCursor();
                }
            }
            $near_word = $searchstr['+'][$idx] . "-" . $searchstr['+'][$idx + 1];
            if (!isset($matchless[$near_word])) {
                $stat = $db->prepare("SELECT keyword FROM " . TABLE_PREFIX . "keywords WHERE keyword=:keyword");
                if ($stat->execute(array(':keyword' => $near_word)) && ($row = $stat->fetch())) {
                    $near_words[$word] = latin1_to_html($near_word);
                    $stat->closeCursor();
                }
            }
        }
        /* then search for "near words" for the individual words */
        reset($searchstr['+']);
        foreach ($searchstr['+'] as $word) {
            /* words that are in the "nonpareil" list are excluded in searching
               for alternatives */
            if (isset($matchless[$word]) && $matchless[$word] == 1) {
                continue;
            }
            /* search for alternatives in the explicit equivalents word list first */
            if (isset($equivalent[$word]) && strlen($equivalent[$word]) > 0) {
                $near_words[$word] = latin1_to_html($equivalent[$word]);
                continue;
            }
            /* if there are misspelled words, show only alternatives for the
               misspelled words, (so, if the current word is not in the list
               of misspelled words, exclude it from the search for alternatives */
            if (count($word_not_found) > 0 && !(isset($word_not_found[$word]) && $word_not_found[$word] == 1)) {
                continue;
            }
            $word = sanitize($word);
            /* use the double-metaphone to find close words */
            $meta = double_metaphone($word);
            if (!isset($meta["primary"]) || strlen($meta["primary"]) == 0) {
                continue;
            }
            /* no metaphone, don't match anything */
            $where = "metaphone1='" . $meta["primary"] . "' OR metaphone2='" . $meta["primary"] . "'";
            if (isset($meta["secondary"]) && strlen($meta["secondary"]) > 0) {
                $where .= " OR metaphone1='" . $meta["secondary"] . "' OR metaphone2='" . $meta["secondary"] . "'";
            }
            $result = $db->query("SELECT keyword FROM " . TABLE_PREFIX . "keywords WHERE {$where}");
            /* adapted from http://www.mdj.us/web-development/php-programming/creating-better-search-suggestions-with-sphider/
               but using a double-metaphone filter (instead of SOUNDEX) and
               adding a filter for accented characters */
            $max_distance = 3;
            $max_similar = 0;
            $near_word = "";
            while ($result && ($row = $result->fetch())) {
                $item = $row[0];
                if (strcasecmp($item, $word) != 0) {
                    $distance = levenshtein($item, $word);
                    $distance_na = levenshtein(remove_accents($item), $word);
                    if ($distance_na < $distance) {
                        $distance = $distance_na;
                    }
                    if ($distance < $max_distance) {
                        $max_distance = $distance;
                        $near_word = $item;
                    }
                    if ($distance == $max_distance) {
                        $similar = similar_text($item, $word);
                        if ($similar >= $max_similar) {
                            $max_distance = $distance;
                            $max_similar = $similar;
                            $near_word = $item;
                        }
                    }
                }
            }
            if ($near_word != "") {
                $near_words[$word] = latin1_to_html($near_word);
            } else {
                if (isset($word_not_found[$word]) && $word_not_found[$word] == 1 && count($wordarray) > 1) {
                    $near_words[$word] = "/{$word}";
                }
            }
        }
        if (!isset($near_words)) {
            $near_words = "";
        }
        $res['did_you_mean'] = $near_words;
        if (count($result_array_full) == 0 || $possible_to_find == 0) {
            return $res;
        }
    }
    if (count($result_array_full) == 0) {
        return null;
    }
    arsort($result_array_full);
    if ($merge_site_results == 1 && $domain_qry == "") {
        while (list($key, $value) = each($result_array_full)) {
            if (!isset($domains_to_show[$domains[$key]])) {
                $result_array_temp[$key] = $value;
                $domains_to_show[$domains[$key]] = 1;
            } else {
                if ($domains_to_show[$domains[$key]] == 1) {
                    $domains_to_show[$domains[$key]] = array($key => $value);
                }
            }
        }
    } else {
        $result_array_temp = $result_array_full;
    }
    while (list($key, $value) = each($result_array_temp)) {
        $result_array[$key] = $value;
        if (isset($domains_to_show[$domains[$key]]) && $domains_to_show[$domains[$key]] != 1) {
            list($k, $v) = each($domains_to_show[$domains[$key]]);
            $result_array[$k] = $v;
        }
    }
    $results = count($result_array);
    $keys = array_keys($result_array);
    $maxweight = $result_array[$keys[0]];
    for ($i = ($start - 1) * $per_page; $i < min($results, ($start - 1) * $per_page + $per_page); $i++) {
        $in[] = $keys[$i];
    }
    if (!is_array($in)) {
        $res['results'] = $results;
        return $res;
    }
    $inlist = implode(",", $in);
    if ($length_of_link_desc == 0) {
        $fulltxt = "fulltxt";
    } else {
        $fulltxt = "substring(fulltxt, 1, {$length_of_link_desc})";
    }
    $query = "SELECT distinct link_id, url, title, description, language, {$fulltxt}, size FROM " . TABLE_PREFIX . "links WHERE link_id in ({$inlist})";
    $result = $db->query($query);
    echo sql_errorstring(__FILE__, __LINE__);
    $i = 0;
    while ($row = $result->fetch()) {
        $res[$i]['title'] = $row[2];
        $res[$i]['url'] = $row[1];
        if (isset($row[3]) && $row[3] != null && $show_meta_description == 1) {
            $res[$i]['summary'] = $row[3];
        } else {
            $res[$i]['summary'] = "";
        }
        $res[$i]['lang'] = $row[4];
        $res[$i]['fulltxt'] = $row[5];
        $res[$i]['size'] = $row[6];
        $res[$i]['weight'] = $result_array[$row[0]];
        /* if a language has been set for this page, and it is _not_ the
         * same language as the user language, decrease the weight
         */
        if (isset($row[4]) && $row[4] != null && strlen($row[4]) > 0 && strcasecmp($row[4], $language) != 0) {
            $res[$i]['weight'] *= 0.5;
        }
        $dom_result = $db->query("select domain from " . TABLE_PREFIX . "domains where domain_id='" . $domains[$row[0]] . "'");
        $dom_row = $dom_result->fetch();
        $res[$i]['domain'] = $dom_row[0];
        $i++;
    }
    if ($merge_site_results && $domain_qry == "") {
        sort_with_domains($res);
    } else {
        usort($res, "cmp");
    }
    echo sql_errorstring(__FILE__, __LINE__);
    /* sorting destroys the other columns in the array, restore */
    if (isset($near_words)) {
        $res['did_you_mean'] = $near_words;
    }
    $res['maxweight'] = $maxweight;
    $res['results'] = $results;
    return $res;
    /**/
}
function deletecat($cat_id)
{
    global $db;
    $list = implode(",", get_cats($cat_id));
    $db->exec("delete from " . TABLE_PREFIX . "categories where category_id in ({$list})");
    echo sql_errorstring(__FILE__, __LINE__);
    $db->exec("delete from " . TABLE_PREFIX . "site_category where category_id={$cat_id}");
    echo sql_errorstring(__FILE__, __LINE__);
    return "<center><b>Category deleted.</b></center>";
}
Beispiel #10
0
function deletecat($cat_id)
{
    $list = implode(",", get_cats($cat_id));
    mysql_query("delete from " . TABLE_PREFIX . "categories where category_id in ({$list})");
    if (DEBUG > '0') {
        echo mysql_error();
    }
    mysql_query("delete from " . TABLE_PREFIX . "site_category where category_id={$cat_id}");
    if (DEBUG > '0') {
        echo mysql_error();
    }
    return "<p class='msg'>Category deleted.</p>";
}
if (login_checklogin() && $_SESSION['userinfo']['wallpapers_ban'] > time()) {
    echo '<h1>Fel</h1>' . "\n";
    echo '<h2>Du får inte ladda upp fler bilder på ett tag! Läs i din gästbok för mer info.</h2>';
    ui_bottom();
    exit;
}
?>
<h2>Lägg till ny bakgrundsbild</h2>
<p style="color:red;">Alla fält är obligatoriska</p>
<form action="#" id="wallpapers_form" enctype="multipart/form-data" method="post">
<h5>Namn</h5>
<input type="text" class="textbox" id="form_title" name="title" />
<h5>Kategori</h5>
<select name="cat">
<?php 
echo get_cats(0);
?>
</select>
<h5>Licens</h5>
<select name="license">
<?php 
$query = 'SELECT id, title FROM ' . WALLPAPERS_LICENSE . ' WHERE is_removed = 0 ORDER BY id ASC';
$result = mysql_query($query) or report_sql_error($query, __FILE__, __LINE__);
if (mysql_num_rows($result) > 0) {
    while ($data = mysql_fetch_assoc($result)) {
        echo '<option value="' . $data['id'] . '">' . $data['title'] . '</option>' . "\n";
    }
}
?>
</select>
<h5>Upphovsrättsinnehavare</h5>
Beispiel #12
0
function search($searchstr, $category, $start, $per_page, $type, $domain)
{
    global $length_of_link_desc, $mysql_table_prefix, $show_meta_description, $sort_results, $query_hits;
    global $stem_words, $did_you_mean_enabled, $relevance, $query, $utf8, $wildcount, $type, $case_sensitive;
    $possible_to_find = 1;
    $result = mysql_query("select domain_id from " . $mysql_table_prefix . "domains where domain = '{$domain}'");
    if (mysql_num_rows($result) > 0) {
        $thisrow = mysql_fetch_array($result);
        $domain_qry = "and domain = " . $thisrow[0];
    } else {
        $domain_qry = "";
    }
    //find all sites that should not be included in the result
    if (count($searchstr['+']) == 0) {
        return null;
    }
    $wordarray = $searchstr['-'];
    $notlist = array();
    $not_words = 0;
    while ($not_words < count($wordarray)) {
        if ($stem_words == 1) {
            $searchword = addslashes(stem($wordarray[$not_words]));
        } else {
            $searchword = addslashes($wordarray[$not_words]);
        }
        $wordmd5 = substr(md5($searchword), 0, 1);
        $query1 = "SELECT link_id from " . $mysql_table_prefix . "link_keyword{$wordmd5}, " . $mysql_table_prefix . "keywords where " . $mysql_table_prefix . "link_keyword{$wordmd5}.keyword_id= " . $mysql_table_prefix . "keywords.keyword_id and keyword='{$searchword}'";
        $result = mysql_query($query1);
        while ($row = mysql_fetch_row($result)) {
            $notlist[$not_words]['id'][$row[0]] = 1;
        }
        $not_words++;
    }
    //find all sites containing the search phrase
    $wordarray = $searchstr['+s'];
    $phrase_words = 0;
    while ($phrase_words < count($wordarray)) {
        $searchword = addslashes($wordarray[$phrase_words]);
        $phrase_query = $searchword;
        if ($case_sensitive == '1') {
            $query1 = "SELECT link_id from " . $mysql_table_prefix . "links where fulltxt like '% {$searchword}%'";
        }
        if ($case_sensitive == '0') {
            $searchword = lower_case($searchword);
            $query1 = "SELECT link_id from " . $mysql_table_prefix . "links where CONVERT(LOWER(fulltxt)USING utf8) like '% {$searchword}%'";
        }
        /*
                   if ($utf8 =='0') {
                       $searchword = lower_case($searchword);
                       $query1 = "SELECT link_id from ".$mysql_table_prefix."links where LOWER(fulltxt) like '% $searchword%'";
                   } 
        */
        $result = mysql_query($query1);
        echo mysql_error();
        $num_rows = mysql_num_rows($result);
        if ($num_rows == 0) {
            $possible_to_find = 0;
            break;
        }
        while ($row = mysql_fetch_row($result)) {
            $value = $row[0];
            $phraselist[$phrase_words]['id'][$row[0]] = 1;
            $phraselist[$phrase_words]['val'][$row[0]] = $value;
        }
        $phrase_words++;
    }
    if ($category > 0 && $possible_to_find == 1) {
        $allcats = get_cats($category);
        $catlist = implode(",", $allcats);
        $query1 = "select link_id from " . $mysql_table_prefix . "links, " . $mysql_table_prefix . "sites, " . $mysql_table_prefix . "categories, " . $mysql_table_prefix . "site_category where " . $mysql_table_prefix . "links.site_id = " . $mysql_table_prefix . "sites.site_id and " . $mysql_table_prefix . "sites.site_id = " . $mysql_table_prefix . "site_category.site_id and " . $mysql_table_prefix . "site_category.category_id in ({$catlist})";
        $result = mysql_query($query1);
        echo mysql_error();
        $num_rows = mysql_num_rows($result);
        if ($num_rows == 0) {
            $possible_to_find = 0;
        }
        while ($row = mysql_fetch_row($result)) {
            $category_list[$row[0]] = 1;
        }
    }
    //find all sites that include the search word
    $wordarray = $searchstr['+'];
    $words = 0;
    $starttime = getmicrotime();
    $searchword = addslashes($wordarray[$words]);
    //  get only first word of search query
    $strictpos = strpos($searchword, '!');
    //   if  ! is in position 0, we have to search strict
    if ($strictpos === 0) {
        //    ****        for 'Strict search' enter here
        $searchword = str_replace('!', '', $searchword);
        $query = "SELECT keyword_id, keyword from " . $mysql_table_prefix . "keywords where keyword = '{$searchword}'";
        echo mysql_error();
        $result = mysql_query($query);
        $num_rows = mysql_num_rows($result);
        if ($num_rows == 0) {
            // if there was no searchword in table keywords
            $possible_to_find = 0;
            $break = 1;
        }
        if ($num_rows != 0) {
            // get all searchwords as keywords from table keywords
            $keyword_id = mysql_result($result, $i, "keyword_id");
            $keyword = mysql_result($result, $i, "keyword");
            $wordmd5 = substr(md5($keyword), 0, 1);
            // calculate attribute for link_keyword table
            if ($query_hits == '1') {
                //      get query hit results
                $query1 = "SELECT distinct link_id, hits, domain from " . $mysql_table_prefix . "link_keyword{$wordmd5}, " . $mysql_table_prefix . "keywords where " . $mysql_table_prefix . "link_keyword{$wordmd5}.keyword_id= " . $mysql_table_prefix . "keywords.keyword_id and keyword='{$searchword}' {$domain_qry} order by hits desc";
            } else {
                // get weight results
                $query1 = "SELECT link_id, weight, domain from " . $mysql_table_prefix . "link_keyword{$wordmd5}  where keyword_id = '{$keyword_id}' order by weight desc";
            }
            echo mysql_error();
            $reso = mysql_query($query1);
            $lines = mysql_num_rows($reso);
            if ($lines != 0) {
                $indx = $words;
            }
            while ($row = mysql_fetch_row($reso)) {
                $linklist[$indx]['id'][] = $row[0];
                $domains[$row[0]] = $row[2];
                $linklist[$indx]['weight'][$row[0]] = $row[1];
                if ($query_hits == '1') {
                    //      ensure that result is also available in full text
                    $txt_res = mysql_query("SELECT fulltxt FROM " . $mysql_table_prefix . "links where link_id = '{$row['0']}'");
                    echo mysql_error();
                    $full_txt = mysql_result($txt_res, 0);
                    //       get fulltxt  of this link ID
                    if ($utf8 == '0') {
                        $full_txt = lower_case($full_txt);
                    }
                    $foundit = strpos($full_txt, $searchword);
                    //      get first hit
                    if ($foundit) {
                        $page_hits = $linklist[$indx]['weight'][$row[0]];
                        $i = '0';
                        while ($i < $page_hits) {
                            //      find out if all results in full text are really strict
                            $found_in = strpos($full_txt, $searchword);
                            $tmp_front = substr($full_txt, $found_in - 1, 20);
                            //  one character before found match position
                            $pos = $found_in + strlen($searchword);
                            $tmp_behind = substr($full_txt, $pos, 20);
                            //  one character behind found match position
                            $full_txt = substr($full_txt, $pos);
                            //  get rest of fulltxt
                            //  check whether found match is realy strict
                            $found_before = preg_match("/[(a-z)-_*.\\/\\:&@\\w]/", substr($tmp_front, 0, 1));
                            $found_behind = preg_match("/[(a-z)-_*.,\\/\\:&@\\w]/", substr($tmp_behind, 0, 1));
                            if ($found_before == 1 || $found_behind == 1) {
                                //      correct count of hits
                                $linklist[$indx]['weight'][$row[0]] = $linklist[$indx]['weight'][$row[0]] - 1;
                            }
                            $i++;
                        }
                    } else {
                        $linklist[$indx]['weight'][$row[0]] = '0';
                        //      nothing found in full text. Hits = 0
                    }
                }
            }
            $words++;
        }
    } else {
        //****       if not strict-search try here
        $wild_correct = 0;
        $wildcount = substr_count($searchword, '*');
        if ($wildcount) {
            //  ****        for * wildcard , enter here
            $searchword = str_replace('*', '%', $searchword);
            $words = '0';
            $query = "SELECT keyword_id, keyword from " . $mysql_table_prefix . "keywords where keyword like '{$searchword}'";
            echo mysql_error();
            $result = mysql_query($query);
            $num_rows = mysql_num_rows($result);
            if ($num_rows == 0) {
                // if there was no searchword in table keywords
                $possible_to_find = 0;
                $break = 1;
            }
            if ($num_rows != 0) {
                global $all_wild;
                $all_wild = '';
                for ($i = 0; $i < $num_rows; $i++) {
                    // get all searchwords as keywords from table keywords
                    $keyword_id = mysql_result($result, $i, "keyword_id");
                    $keyword = mysql_result($result, $i, "keyword");
                    $all_wild = "{$all_wild} {$keyword}";
                    $wordmd5 = substr(md5($keyword), 0, 1);
                    // calculate attribute for link_keyword table
                    if ($query_hits == '1') {
                        //      get query hit results
                        $query1 = "SELECT link_id, hits, domain from " . $mysql_table_prefix . "link_keyword{$wordmd5}  where keyword_id = '{$keyword_id}' order by hits desc";
                    } else {
                        // get weight results
                        $query1 = "SELECT link_id, weight, domain from " . $mysql_table_prefix . "link_keyword{$wordmd5}  where keyword_id = '{$keyword_id}' order by weight desc";
                    }
                    echo mysql_error();
                    $reso = mysql_query($query1);
                    $lines = mysql_num_rows($reso);
                    if ($lines == 0) {
                        if ($type != "or") {
                            $possible_to_find = 0;
                            break;
                        }
                    }
                    if ($type == "or" && $query_hits == '0') {
                        $indx = 0;
                    } else {
                        $indx = $words;
                    }
                    while ($row = mysql_fetch_row($reso)) {
                        $linklist[$indx]['id'][] = $row[0];
                        $domains[$row[0]] = $row[2];
                        $linklist[$indx]['weight'][$row[0]] = $row[1];
                        if ($query_hits == '1') {
                            //      ensure that result is also available in fulltxt
                            $searchword = str_replace("%", '', $searchword);
                            $txt_res = mysql_query("SELECT fulltxt FROM " . $mysql_table_prefix . "links where link_id = '{$row['0']}'");
                            echo mysql_error();
                            $full_txt = mysql_result($txt_res, 0);
                            //       get fulltxt  of this link ID
                            $foundit = strpos($full_txt, $searchword);
                            if (!$foundit) {
                                $linklist[$indx]['weight'][$row[0]] = '0';
                                //      nothing found in full text. Hits = 0
                            }
                        }
                    }
                }
                $words++;
            }
        } else {
            //      if no wildcard, try here
            if ($type == 'tol') {
                //  *****         if tolerant search, enter here
                $acct_a = array("å", "â", "ä", "ä", "Ã\"ž", "Ä", "Ä", "ä", "á", "à", "&agrave;", "á", "&aacute;", "À", "&Agrave;", "Á", "&Aacute;");
                $base_a = array("a", "a", "a", "a", "A", "A", "A", "a", "a", "a", "a", "a", "a", "A", "A", "A", "A");
                $searchword = str_ireplace($acct_a, $base_a, $searchword);
                $acct_e = array("ê", "é", "è", "&egrave;", "é", "&eacute;", "È", "&Egrave;", "É", "&Eacute;");
                $base_e = array("e", "e", "e", "e", "e", "e", "E", "E", "E", "E");
                $searchword = str_ireplace($acct_e, $base_e, $searchword);
                $acct_i = array("ì", "&igrave;", "í", "&iacute;", "Ì", "&Igrave;", "Í", "&Iacute;", "ñ", "¡", "Ã'", "¿");
                $base_i = array("i", "i", "i", "i", "I", "I", "I", "I", "ñ", "¡", "Ñ", "¿");
                $searchword = str_ireplace($acct_i, $base_i, $searchword);
                $acct_o = array("ø", "Ø", "ô", "ó", "ò", "õ", "Ö", "ö", "ö", "ã¶", "ó", "ò", "&ograve;", "ó", "&oacute;", "Ò", "&Ograve;", "Ó", "&Oacute;");
                $base_o = array("o", "O", "o", "o", "o", "o", "O", "o", "o", "o", "Ö", "ö", "O", "o", "o", "O", "O", "O", "O");
                $searchword = str_ireplace($acct_o, $base_o, $searchword);
                $acct_u = array("ù", "ú", "û", "ü", "ü", "ÃÅ\\“", "Ãœ", "Ü", "ü", "ú", "ù", "&ugrave;", "ú", "&uacute;", "Ù", "&Ugrave;", "Ú", "&Uacute;");
                $base_u = array("u", "u", "u", "u", "u", "U", "U", "U", "u", "u", "u", "u", "u", "u", "U", "U", "U", "U");
                $searchword = str_ireplace($acct_u, $base_u, $searchword);
                $get = array("a", "e", "i", "o", "u");
                $out = array("%", "%", "%", "%", "%");
                $searchword = str_ireplace($get, $out, $searchword);
                $query = "SELECT keyword_id, keyword from " . $mysql_table_prefix . "keywords where keyword like '{$searchword}'";
                echo mysql_error();
                $result = mysql_query($query);
                $num_rows = mysql_num_rows($result);
                if ($num_rows == 0) {
                    // if there was no searchword in table keywords
                    $possible_to_find = 0;
                    $break = 1;
                }
                if ($num_rows != 0) {
                    global $all_wild;
                    $all_wild = '';
                    for ($i = 0; $i < $num_rows; $i++) {
                        // get all searchwords as keywords from table keywords
                        $keyword_id = mysql_result($result, $i, "keyword_id");
                        $keyword = mysql_result($result, $i, "keyword");
                        $all_wild = "{$all_wild} {$keyword}";
                        $wordmd5 = substr(md5($keyword), 0, 1);
                        // calculate attribute for link_keyword table
                        if ($query_hits == '1') {
                            //      get query hit results
                            $query1 = "SELECT link_id, hits, domain from " . $mysql_table_prefix . "link_keyword{$wordmd5} where keyword_id = '{$keyword_id}' order by hits desc";
                        } else {
                            // get weight results
                            $query1 = "SELECT link_id, weight, domain from " . $mysql_table_prefix . "link_keyword{$wordmd5} where keyword_id = '{$keyword_id}' order by weight desc";
                        }
                        echo mysql_error();
                        $reso = mysql_query($query1);
                        $lines = mysql_num_rows($reso);
                        if ($lines != 0) {
                            $indx = $words;
                        }
                        while ($row = mysql_fetch_row($reso)) {
                            $linklist[$indx]['id'][] = $row[0];
                            $domains[$row[0]] = $row[2];
                            $linklist[$indx]['weight'][$row[0]] = $row[1];
                        }
                        //$words++;
                    }
                    $words++;
                }
            } else {
                //      finally standard search
                $words = 0;
                while ($words < count($wordarray) && $possible_to_find == 1) {
                    if ($stem_words == 1) {
                        $searchword = addslashes(stem($wordarray[$words]));
                    } else {
                        $searchword = addslashes($wordarray[$words]);
                    }
                    $wordmd5 = substr(md5($searchword), 0, 1);
                    if ($query_hits == '1') {
                        //      get query hit results
                        $query1 = "SELECT distinct link_id, hits, domain from " . $mysql_table_prefix . "link_keyword{$wordmd5}, " . $mysql_table_prefix . "keywords where " . $mysql_table_prefix . "link_keyword{$wordmd5}.keyword_id= " . $mysql_table_prefix . "keywords.keyword_id and keyword='{$searchword}' {$domain_qry} order by hits desc";
                    } else {
                        // get weight results
                        $query1 = "SELECT distinct link_id, weight, domain from " . $mysql_table_prefix . "link_keyword{$wordmd5}, " . $mysql_table_prefix . "keywords where " . $mysql_table_prefix . "link_keyword{$wordmd5}.keyword_id= " . $mysql_table_prefix . "keywords.keyword_id and keyword='{$searchword}' {$domain_qry} order by weight desc";
                    }
                    echo mysql_error();
                    $result = mysql_query($query1);
                    $num_rows = mysql_num_rows($result);
                    if ($num_rows == 0) {
                        if ($type != "or") {
                            $possible_to_find = 0;
                            break;
                        }
                    }
                    if ($type == "or" && $query_hits == '0') {
                        $indx = 0;
                    } else {
                        $indx = $words;
                    }
                    while ($row = mysql_fetch_row($result)) {
                        $linklist[$indx]['id'][] = $row[0];
                        $domains[$row[0]] = $row[2];
                        $linklist[$indx]['weight'][$row[0]] = $row[1];
                        if ($query_hits == '1') {
                            //      ensure that result is also available in fulltxt
                            if ($type == 'phrase') {
                                if ($utf8 == '0') {
                                    $searchword = lower_case($phrase_query);
                                    //      get the whole phrase
                                } else {
                                    $searchword = $phrase_query;
                                }
                            }
                            $linklist[$indx]['weight'][$row[0]] = '0';
                            $txt_res = mysql_query("SELECT fulltxt FROM " . $mysql_table_prefix . "links where link_id = '{$row['0']}'");
                            echo mysql_error();
                            $full_txt = mysql_result($txt_res, 0);
                            //       get fulltxt  of this link ID
                            if ($case_sensitive == '0') {
                                $full_txt = lower_case($full_txt);
                            }
                            if (substr_count($full_txt, $searchword)) {
                                //  found complete phrase in full text?
                                $linklist[$indx]['weight'][$row[0]] = substr_count($full_txt, $searchword);
                                //      number of hits found in this full text
                            }
                        }
                    }
                    $words++;
                }
            }
        }
    }
    //  ***** end  different search modes
    if ($type == "or") {
        $words = 1;
    }
    $result_array_full = array();
    if ($words == 1 && $not_words == 0 && $category < 1) {
        // for OR-Sarch without query_hits and one word query, we already have the result
        $result_array_full = $linklist[0]['weight'];
    } else {
        //     otherwise build an intersection of all the results
        $j = 1;
        $min = 0;
        while ($j < $words) {
            if (count($linklist[$min]['id']) > count($linklist[$j]['id'])) {
                $min = $j;
            }
            $j++;
        }
        $j = 0;
        $temp_array = $linklist[$min]['id'];
        $count = 0;
        while ($j < count($temp_array)) {
            $k = 0;
            //and word counter
            $n = 0;
            //not word counter
            $o = 0;
            //phrase word counter
            if ($query_hits == '1') {
                $weight = 0;
            } else {
                $weight = 1;
            }
            $break = 0;
            if ($type == 'phrase' && $query_hits == '1') {
                // for PHRASE search: find out how often the phrase was found in fulltxt (not for weighting %  scores)
                while ($k < $words && $break == 0) {
                    if ($linklist[$k]['weight'][$temp_array[$j]] > 0) {
                        $weight = $linklist[$k]['weight'][$temp_array[$j]];
                    } else {
                        $break = 1;
                    }
                    $k++;
                }
            } else {
                // calculate weight for all other search modes
                while ($k < $words && $break == 0) {
                    if ($linklist[$k]['weight'][$temp_array[$j]] > 0) {
                        $weight = $weight + $linklist[$k]['weight'][$temp_array[$j]];
                    } else {
                        $break = 1;
                    }
                    $k++;
                }
            }
            while ($n < $not_words && $break == 0) {
                if ($notlist[$n]['id'][$temp_array[$j]] > 0) {
                    $break = 1;
                }
                $n++;
            }
            while ($o < $phrase_words && $break == 0) {
                if ($phraselist[$n]['id'][$temp_array[$j]] != 1) {
                    $break = 1;
                }
                $o++;
            }
            if ($break == 0 && $category > 0 && $category_list[$temp_array[$j]] != 1) {
                $break = 1;
            }
            if ($break == 0) {
                $result_array_full[$temp_array[$j]] = $weight;
                $count++;
            }
            $j++;
        }
    }
    //word == 1
    $end = getmicrotime() - $starttime;
    if ((count($result_array_full) == 0 || $possible_to_find == 0) && $did_you_mean_enabled == 1) {
        reset($searchstr['+']);
        foreach ($searchstr['+'] as $word) {
            $word2 = str_ireplace("Ã", "à", addslashes("{$word}"));
            $result = mysql_query("select keyword from " . $mysql_table_prefix . "keywords where soundex(keyword) = soundex('{$word2}%')");
            $max_distance = 100;
            $near_word = "";
            while ($row = mysql_fetch_row($result)) {
                $distance = levenshtein($row[0], $word);
                if ($distance < $max_distance && $distance < 10) {
                    $max_distance = $distance;
                    $near_word = $row[0];
                }
            }
            if ($near_word != "" && $word != $near_word) {
                $near_words[$word] = $near_word;
            }
        }
        $res['did_you_mean'] = $near_words;
        return $res;
    }
    if (count($result_array_full) == 0) {
        return null;
    }
    arsort($result_array_full);
    if ($sort_results == 4 && $domain_qry == "") {
        // output alla Google)
        while (list($key, $value) = each($result_array_full)) {
            if (!isset($domains_to_show[$domains[$key]])) {
                $result_array_temp[$key] = $value;
                $domains_to_show[$domains[$key]] = 1;
            } else {
                if ($domains_to_show[$domains[$key]] == 1) {
                    $domains_to_show[$domains[$key]] = array($key => $value);
                }
            }
        }
    } else {
        $result_array_temp = $result_array_full;
    }
    while (list($key, $value) = each($result_array_temp)) {
        $result_array[$key] = $value;
        if (isset($domains_to_show[$domains[$key]]) && $domains_to_show[$domains[$key]] != 1) {
            list($k, $v) = each($domains_to_show[$domains[$key]]);
            $result_array[$k] = $v;
        }
    }
    $keys = array_keys($result_array);
    $maxweight = $result_array[$keys[0]];
    $count = '0';
    foreach ($result_array as $row) {
        if ($query_hits == '0') {
            //    limit result output to min. relevance level
            $weight = number_format($row / $maxweight * 100, 0);
            if ($weight >= $relevance) {
                $count = $count + 1;
            }
        } else {
            if ($row > '0') {
                //      present results only if hits in full text
                $count = $count + 1;
            }
        }
    }
    if ($count != '0') {
        $result_array = array_chunk($result_array, $count, true);
        //      limit result output(weight > relevance level OR hits in fulltext > 0)
    }
    $result_array = $result_array[0];
    $results = count($result_array);
    for ($i = ($start - 1) * $per_page; $i < min($results, ($start - 1) * $per_page + $per_page); $i++) {
        $in[] = $keys[$i];
    }
    if (!is_array($in)) {
        $res['results'] = $results;
        return $res;
    }
    $inlist = implode(",", $in);
    if ($length_of_link_desc == 0) {
        $fulltxt = "fulltxt";
    } else {
        $fulltxt = "substring(fulltxt, 1, {$length_of_link_desc})";
    }
    $query1 = "SELECT distinct link_id, url, title, description,  {$fulltxt}, size, click_counter FROM " . $mysql_table_prefix . "links WHERE link_id in ({$inlist})";
    $result = mysql_query($query1);
    echo mysql_error();
    $i = 0;
    while ($row = mysql_fetch_row($result)) {
        $res[$i]['title'] = $row[2];
        $res[$i]['url'] = $row[1];
        if ($row[3] != null && $show_meta_description == 1) {
            $res[$i]['fulltxt'] = $row[3];
        } else {
            $res[$i]['fulltxt'] = $row[4];
        }
        $res[$i]['size'] = $row[5];
        $res[$i]['click_counter'] = $row[6];
        $res[$i]['weight'] = $result_array[$row[0]];
        $dom_result = mysql_query("select domain from " . $mysql_table_prefix . "domains where domain_id='" . $domains[$row[0]] . "'");
        $dom_row = mysql_fetch_row($dom_result);
        $res[$i]['domain'] = $dom_row[0];
        $urlparts = parse_url($res[$i]['url']);
        //$res[$i]['path'] = $urlparts['path'];    //      get full path
        $res[$i]['path'] = eregi_replace('([^/]+)$', "", $urlparts['path']);
        //      get path without filename
        $i++;
    }
    usort($res, "cmp_weight");
    //      standard output sorted by relevance (weight)
    $dom = $res[0]['domain'];
    if ($sort_results == '4' && $domain_qry == "" || $sort_results == '3') {
        //  output alla Google  OR  by domain name
        sort_with_domains($res);
    } else {
        if ($sort_results == '2') {
            //      enter here if 'Main URLs' on top of listing
            if ($dom == 'localhost') {
                //usort($res, "cmp_path_dot");
                //usort($res, "cmp_path_slash");
            } else {
                //usort($res, "cmp_dom_dot");     //      sort domains without dots on top
            }
        }
        if ($sort_results == '5') {
            //      enter here if 'Most Popular Click' on top of listing
            sort_by_bestclick($res);
        }
    }
    echo mysql_error();
    $res['maxweight'] = $maxweight;
    $res['results'] = $results;
    return $res;
}
function get_cats($val, $level = 0, $cat)
{
    $query = 'SELECT title, id FROM ' . WALLPAPERS_CATS . ' WHERE pid = ' . $val . ' AND is_removed = 0';
    $result = mysql_query($query) or report_sql_error($query, __FILE__, __LINE);
    $out = '';
    while ($row = mysql_fetch_assoc($result)) {
        if ($row['title'] != '') {
            $spaces = str_repeat('&nbsp;', $level * 4);
            $val = $row['id'];
            $out .= "\t" . '<option value="' . $val . '"' . ($row['id'] == $cat ? ' selected="selected"' : '') . '>' . $spaces . $row['title'] . '</option>' . "\n";
            $out .= get_cats($val, $level + 1, $cat);
        }
    }
    return $out;
}
Beispiel #14
0
                $query = 'UPDATE ' . WALLPAPERS_TABLE . ' SET title = "' . $_POST['title'] . '", cid = ' . intval($_POST['cat']) . ' WHERE id = ' . intval($_GET['id']);
                mysql_query($query) or report_sql_error($query, __FILE__, __LINE__);
                jscript_go_back();
            } else {
                if ($is_image) {
                    $cat = wallpapers_fetch(array('id' => intval($_GET['id']), 'limit' => 1));
                    $cat = $cat[0]['cid'];
                    echo rounded_corners_top();
                    echo '<h2>Admin</h2>' . "\n";
                    echo '<form action="' . $_SERVER['PHP_SELF'] . '?action=preview&id=' . intval($_GET['id']) . '" method="post">' . "\n";
                    echo '<h5>Titel</h5>
						<input type="text" name="title" value="' . $imagetitle . '" />' . "\n";
                    echo '<br />' . "\n";
                    echo '<h5>Kategori</h5>' . "\n";
                    echo '<select name="cat">' . "\n";
                    echo get_cats(0, 0, $cat);
                    echo '</select>' . "\n";
                    echo '<br />' . "\n";
                    echo '<input type="button" onclick="confirm(\'Sure?\') ? document.location.href=\'?action=delete&id=' . intval($_GET['id']) . '\' : false;" value="Radera" class="button" />' . "\n";
                    echo '<input type="submit" value="Spara" />';
                    echo rounded_corners_bottom();
                }
            }
            break;
        case 'delete':
            $query = 'SELECT c.extension, a.resolution_w AS width, a.resolution_h AS height FROM ' . WALLPAPERS_RES . ' AS a
				 LEFT JOIN ' . WALLPAPERS_RES_RELATION . ' AS b ON b.resolution_pid = a.id
				  LEFT JOIN ' . WALLPAPERS_TABLE . ' AS c ON c.id = b.pid
				   WHERE c.id = ' . intval($_GET['id']);
            $result = mysql_query($query) or report_sql_error($query, __FILE__, __LINE__);
            if (mysql_num_rows($result) > 0) {
Beispiel #15
0
function deletecat($cat_id)
{
    global $db_con, $mysql_table_prefix, $debug;
    $list = implode(",", get_cats($cat_id));
    $sql_query = "DELETE from " . $mysql_table_prefix . "categories where category_id in ({$list})";
    $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;
    }
    $sql_query = "DELETE from " . $mysql_table_prefix . "site_category where category_id={$cat_id}";
    $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;
    }
    return "<p class='msg'>Category deleted.</p>";
}
Beispiel #16
0
function show_list()
{
    $cats = get_cats();
    render("list", $cats);
}
Beispiel #17
0
 function get_cat_by_parents($array = array())
 {
     $cats = array();
     if (count(get_cats()) > 0) {
         $i = 0;
         foreach (get_cats() as $item) {
             if (in_array($item->parent, $array)) {
                 $cats[$i]['id'] = $item->id;
                 $cats[$i]['parent'] = $item->parent;
                 $cats[$i]['name'] = $item->name;
             }
             $i++;
         }
     }
     return $cats;
 }