Ejemplo n.º 1
0
function optimizeForSearch()
{
    // used to build a string optimized for search
    $numargs = func_num_args();
    $text = '';
    if ($numargs) {
        for ($i = 0; $i < $numargs; $i++) {
            $text .= ' ' . func_get_arg($i);
        }
        $text = stripped_cache_content($text);
        $text = cleanUpSpecialHtmlEntities($text);
        $text = decode_entities($text);
        $text = str_replace(array('!', '"', "'", '.', '#', ';', '~', '+', '*', '%', '&', '$', '§', ':', '@', ',', '|'), ' ', $text);
        $text = preg_replace('/\\[.*?\\]/', '', $text);
        $text = preg_replace('/\\{.*?\\}/', '', $text);
        $text = strtoupper($text);
        $text = implode(' ', convertStringToArray($text, ' ', 'UNIQUE', false));
    }
    return $text;
}
Ejemplo n.º 2
0
function make_cloud($matches)
{
    global $phpwcms, $content;
    // use $matches for
    // $rendermode,$which_ID,$setLP,$landing
    $rendermode = trim($matches[1]);
    $which_ID = trim($matches[2]);
    $setLP = trim($matches[3]);
    $landing = isset($matches[4]) ? intval($matches[4]) : 0;
    $conf =& $content['tagcloud'];
    // check integrity of user_settings --- else use defaults +++ OG new style
    if (empty($conf['min'])) {
        $conf['min'] = 4;
    }
    if (empty($conf['min_chars'])) {
        $conf['min_chars'] = 4;
    }
    if (!isset($conf['sort'])) {
        $conf['sort'] = false;
    }
    if (empty($conf['inc_or_ex'])) {
        $conf['inc_or_ex'] = 0;
    }
    // avoid php notice: undefined variable
    if (empty($allmyhds)) {
        $allmyhds = '';
    }
    if (empty($allmycps)) {
        $allmycps = '';
    }
    if (empty($at)) {
        $at = '';
    }
    if (empty($ast)) {
        $ast = '';
    }
    if (empty($asm)) {
        $asm = '';
    }
    // avoid php notice: undefined index
    //if(isset($conf['add_t'])) {$auswert_t = $conf['add_t'];}
    // NOW, FINALLY IT'S TIME TO LET A FRESH BREEZE BLOWING UP PRETTY CLOUDS
    if (!empty($landing)) {
        // check if landing page has an article alias ( only versions > 1.3.5  else use fallback )
        // original code has been deleted because +++ o-ton OG: "so geht es schneller"
        $landalias = _dbGet('phpwcms_article', 'article_alias', "article_id=" . $landing . " AND article_alias != ''");
        // "So muss weitermachen...". Hey, here we are:
        if (!empty($landalias[0]['article_alias'])) {
            $aliasfound = $landalias[0]['article_alias'];
        }
        // second BREEZE BLOWING
        if (!empty($setLP)) {
            switch ($setLP) {
                case 'L':
                    if (isset($aliasfound)) {
                        $landing = 'index.php?' . $aliasfound . '#';
                    } else {
                        $landing = 'index.php?aid=' . $landing . '#';
                        //fallback for older versions
                        //$old_style		$landing = 'index.php?id=0,'. $landing . ',0,0,1,0#'; //much older versions
                    }
                    break;
                case 'S':
                    if (isset($aliasfound)) {
                        $landing = 'index.php?' . $aliasfound . '&amp;searchwords=';
                    } else {
                        $landing = 'index.php?aid=' . $landing . '&amp;searchwords=';
                        //fallback for older versions
                        //$old_style		$landing = 'index.php?id=0,'. $landing . ',0,0,1,0&amp;searchwords='; //much older versions
                    }
                    break;
            }
        } else {
            $landing = 'index.php#';
            echo "TagCloud ERROR: Wrong setup of RT! MISSING --> (L) = Landing page OR --> (S) = Search page";
        }
    } else {
        //die("TagCloud ERROR: Article_ID of your (L)Landing Page or your (S)Search Page is missing!");
        echo "TagCloud ERROR: Wrong setup of RT! Article ID of (L) = Landing Page or (S) = Search Page MISSING!";
        $landing = 'index.php#';
    }
    switch ($rendermode) {
        case 'E':
            //exclude array stuff by marcus@localhorst
            $excludeid = explode(',', $which_ID);
            $struct = array_keys($content['struct']);
            $only_cat_id = array_diff($struct, $excludeid);
            break;
        case 'I':
            $only_cat_id = explode(',', $which_ID);
            break;
        default:
            echo "TagCloud ERROR: Rendermode not defined! (I) = match all articles withIN named categories or vice versa (E) = exclude categories!";
            break;
    }
    if (is_array($only_cat_id)) {
        foreach ($only_cat_id as $slid) {
            $sql = "SELECT SQL_CACHE article_id";
            if ($conf['add_t']) {
                $sql .= ",article_title";
            }
            if ($conf['add_st']) {
                $sql .= ",article_subtitle";
            }
            if ($conf['add_sm']) {
                $sql .= ",article_summary";
            }
            $sql .= " FROM " . DB_PREPEND . "phpwcms_article WHERE article_cid={$slid}";
            $sql .= " AND article_public=1 AND article_aktiv=1 AND article_deleted=0";
            $sql .= " AND article_begin < NOW() AND article_end > NOW()";
            $result = _dbQuery($sql);
            foreach ($result as $row) {
                $ai = $row['article_id'];
                if ($conf['add_t']) {
                    $at = $row['article_title'];
                }
                if ($conf['add_st']) {
                    $ast = $row['article_subtitle'];
                }
                if ($conf['add_sm']) {
                    $asm = $row['article_summary'];
                }
                $allmyhds .= $at . ' ' . $ast . ' ' . $asm . ' ';
                $sec_sql = "SELECT SQL_CACHE acontent_html";
                if ($conf['add_cpt']) {
                    $sec_sql .= ",acontent_title";
                }
                if ($conf['add_cpst']) {
                    $sec_sql .= ",acontent_subtitle";
                }
                if ($conf['add_cptximg']) {
                    $sec_sql .= ",acontent_text";
                }
                $sec_sql .= " FROM " . DB_PREPEND . "phpwcms_articlecontent WHERE acontent_aid={$ai}";
                $sec_sql .= " AND acontent_visible=1 AND acontent_trash=0";
                $scd_result = _dbQuery($sec_sql);
                foreach ($scd_result as $scd_row) {
                    $allmycps .= $scd_row['acontent_html'] . ' ';
                    if ($conf['add_cpt']) {
                        $allmycps .= $scd_row['acontent_title'] . ' ';
                    }
                    if ($conf['add_cpst']) {
                        $allmycps .= $scd_row['acontent_subtitle'] . ' ';
                    }
                    if ($conf['add_cptximg']) {
                        $allmycps .= $scd_row['acontent_text'] . ' ';
                    }
                }
            }
        }
        /*****************************************************************
         * JOIN ALL the text of content --> Titles, Summary, CPs
         *****************************************************************/
        $tagtext = $allmyhds . $allmycps;
        /*****************************************************************
         * add NEWS when set =1
         *****************************************************************/
        if ($conf['news_to_cloud'] == 1) {
            $news_sql = "SELECT SQL_CACHE cnt_title, ";
            $news_sql .= "cnt_subtitle, cnt_teasertext, cnt_text";
            $news_sql .= " FROM " . DB_PREPEND . "phpwcms_content WHERE cnt_status=1";
            $news_sql .= " AND cnt_livedate < NOW() AND cnt_killdate > NOW()";
            $news_result = _dbQuery($news_sql);
            foreach ($news_result as $news_row) {
                $newscontent .= $news_row['cnt_title'] . ' ';
                $newscontent .= $news_row['cnt_subtitle'] . ' ';
                $newscontent .= $news_row['cnt_teasertext'] . ' ';
                $newscontent .= $news_row['cnt_text'] . ' ';
            }
            //article content plus news
            $tagtext = $tagtext . $newscontent;
        }
        /*****************************************************************
        	and do some convertions
        	*****************************************************************/
        $tagtext = clean_replacement_tags($tagtext);
        $tagtext = stripped_cache_content($tagtext);
        //delete not wantend and then str_all to lower
        if (phpwcms_seems_utf8($tagtext)) {
            $tagtext = strtolower_utf8(str_replace($conf['del_signs'], '', $tagtext));
        } else {
            $tagtext = strtolower(str_replace($conf['del_signs'], '', $tagtext));
        }
        $tagtext = explode(' ', $tagtext);
        //split in separate words
        $anzahl = array_count_values($tagtext);
        //count the words -- into new array
        $tags = array();
        switch ($conf['inc_or_ex']) {
            case '0':
                foreach ($anzahl as $key => $tagword) {
                    if ($tagword >= $conf['min'] && !in_array($key, $conf['exclude'])) {
                        //look if the word counts the required minimum and is not in the exclude list
                        if (strlen($key) >= $conf['min_chars']) {
                            //ignore words on web site that are NOT longer than (chief inspector even longer) defined in: var min_chars
                            $tags[$key] = $tagword;
                            //put them in a new array
                        }
                        // else { $this_word_out[$key] = $tagword; }
                    }
                }
                break;
            case '1':
                foreach ($anzahl as $key => $tagword) {
                    if ($tagword >= $conf['min'] && in_array($key, $conf['include'])) {
                        //look if the word counts the required minimum and is not in the exclude list
                        if (strlen($key) >= $conf['min_chars']) {
                            //ignore words on web site that are NOT longer than (chief inspector even longer) defined in: var min_chars
                            $tags[$key] = $tagword;
                            //now put them in a new array
                        }
                        // else { $this_word_out[$key] = $tagword; }
                    }
                }
                break;
            default:
                break;
        }
        if (!empty($tags)) {
            //unset($tags['phpwcms']); //if you want to override the value of words (in this case 'phpwcms'), uncomment it and put in your word
            //$weight = count($tags);
            $max_hits = max($tags);
            //tag with most hits
            if (!empty($max_hits)) {
                //$tags['phpwcms']=8; // put in again your deleted word and value from 4 lines above
                switch ($conf['sort']) {
                    case 'asc':
                        ksort($tags);
                        //sort them alphabetically
                        break;
                    case 'desc':
                        krsort($tags);
                        //sort them reverse alphabetically
                        break;
                    case 'random':
                        $keys = array_keys($tags);
                        shuffle($keys);
                        $random_words = array();
                        foreach ($keys as $key) {
                            $random_words[$key] = $tags[$key];
                        }
                        $tags = $random_words;
                        break;
                    default:
                        break;
                }
                // FULL BLOWN CLOUDS LIKE HORNBLOWER
                $tag_cloud = '<div class="' . $conf['class'] . '">';
                foreach ($tags as $key => $tagword) {
                    $key = html_specialchars($key);
                    // new maths by Heiko H.
                    $percent = round(100 * $tagword / $max_hits, 0);
                    $size = ceil($percent / 10);
                    // prepare TC font size for CSS
                    $tag_cloud .= '<a class="tcfs' . $size . '" href="' . PHPWCMS_URL . $landing . urlencode($key) . '">' . $key . '</a>';
                    if ($conf['showCount']) {
                        $tag_cloud .= $conf['SC_before'] . $tagword . $conf['SC_after'];
                    }
                    $tag_cloud .= '	' . LF;
                }
                $tag_cloud .= '</div>';
            }
        }
    }
    return $tag_cloud;
}