function print_excerpt2($mod_vars, $func_vars)
{
    extract($func_vars, EXTR_PREFIX_ALL, 'func');
    extract($mod_vars, EXTR_PREFIX_ALL, 'mod');
    global $TEXT;
    // check $mod_...vars
    if (!isset($mod_page_link)) {
        $mod_page_link = $func_page_link;
    }
    if (!isset($mod_page_link_target)) {
        $mod_page_link_target = "";
    }
    if (!isset($mod_page_title)) {
        $mod_page_title = $func_page_title;
    }
    if (!isset($mod_page_description)) {
        $mod_page_description = $func_page_description;
    }
    if (!isset($mod_page_modified_when)) {
        $mod_page_modified_when = $func_page_modified_when;
    }
    if (!isset($mod_page_modified_by)) {
        $mod_page_modified_by = $func_page_modified_by;
    }
    if (!isset($mod_text)) {
        $mod_text = "";
    }
    if (!isset($mod_max_excerpt_num)) {
        $mod_max_excerpt_num = $func_default_max_excerpt;
    }
    if (!isset($mod_pic_link)) {
        $mod_pic_link = "";
    }
    if (!isset($mod_no_highlight)) {
        $mod_no_highlight = false;
    }
    if (!isset($func_enable_flush)) {
        $func_enable_flush = false;
    }
    // set this in db: wb_search.cfg_enable_flush [READ THE DOC BEFORE]
    if (isset($mod_ext_charset)) {
        $mod_ext_charset = strtolower($mod_ext_charset);
    } else {
        $mod_ext_charset = '';
    }
    if ($mod_text == "") {
        return false;
    }
    if ($mod_no_highlight) {
        $mod_page_link_target = "&nohighlight=1" . $mod_page_link_target;
    }
    // clean the text:
    $mod_text = preg_replace('#<(br|dt|/dd|/?(?:h[1-6]|tr|table|p|li|ul|pre|code|div|hr))[^>]*>#i', '.', $mod_text);
    $mod_text = preg_replace('#<(!--.*--|style.*</style|script.*</script)>#iU', ' ', $mod_text);
    $mod_text = preg_replace('#\\[\\[.*?\\]\\]#', '', $mod_text);
    //Filter droplets from the page data
    // strip_tags() is called below
    if ($mod_ext_charset != '') {
        // data from external database may have a different charset
        require_once WB_PATH . '/framework/functions-utf8.php';
        switch ($mod_ext_charset) {
            case 'latin1':
            case 'cp1252':
                $mod_text = charset_to_utf8($mod_text, 'CP1252');
                break;
            case 'cp1251':
                $mod_text = charset_to_utf8($mod_text, 'CP1251');
                break;
            case 'latin2':
                $mod_text = charset_to_utf8($mod_text, 'ISO-8859-2');
                break;
            case 'hebrew':
                $mod_text = charset_to_utf8($mod_text, 'ISO-8859-8');
                break;
            case 'greek':
                $mod_text = charset_to_utf8($mod_text, 'ISO-8859-7');
                break;
            case 'latin5':
                $mod_text = charset_to_utf8($mod_text, 'ISO-8859-9');
                break;
            case 'latin7':
                $mod_text = charset_to_utf8($mod_text, 'ISO-8859-13');
                break;
            case 'utf8':
            default:
                $mod_text = charset_to_utf8($mod_text, 'UTF-8');
        }
    } else {
        $mod_text = entities_to_umlauts($mod_text, 'UTF-8');
    }
    $anchor_text = $mod_text;
    // make an copy containing html-tags
    $mod_text = strip_tags($mod_text);
    $mod_text = str_replace(array('&gt;', '&lt;', '&amp;', '&quot;', '&#039;', '&apos;', '&nbsp;'), array('>', '<', '&', '"', '\'', '\'', ' '), $mod_text);
    $mod_text = '.' . trim($mod_text) . '.';
    // Do a fast scan over $mod_text first. This may speedup things a lot.
    if ($func_search_match == 'all') {
        if (!is_all_matched($mod_text, $func_search_words)) {
            return false;
        }
    } elseif (!is_any_matched($mod_text, $func_search_words)) {
        return false;
    }
    // search for an better anchor - this have to be done before strip_tags() (may fail if search-string contains <, &, amp, gt, lt, ...)
    $anchor = make_url_target($mod_page_link_target, $anchor_text, $func_search_words);
    // make the link from $mod_page_link, add anchor
    $link = "";
    $link = page_link($mod_page_link);
    if (strpos($mod_page_link, 'http:') === FALSE) {
        $link .= make_url_searchstring($func_search_match, $func_search_url_array);
    }
    $link .= $anchor;
    // now get the excerpt
    $excerpt = "";
    $excerpt_array = array();
    if ($mod_max_excerpt_num > 0) {
        if (!($excerpt_array = get_excerpts($mod_text, $func_search_words, $mod_max_excerpt_num))) {
            return false;
        }
        $excerpt = prepare_excerpts($excerpt_array, $func_search_words, $mod_max_excerpt_num);
    }
    // handle thumbs - to deactivate this look in the module's search.php: $show_thumb (or maybe in the module's settings-page)
    if ($mod_pic_link != "") {
        if (isset($mod_special) && $mod_special == 'lightbox2_plus') {
            $excerpt = '<table class="excerpt_thumb" width="100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr><td width="110" valign="top">' . $mod_special_piclink . '<img src="' . WB_URL . '/' . MEDIA_DIRECTORY . $mod_pic_link . '" alt="" /></a></td><td>' . $excerpt . '</td></tr></tbody></table>';
        } else {
            $excerpt = '<table class="excerpt_thumb" width="100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr><td width="110" valign="top"><a href="' . $link . '"><img src="' . WB_URL . '/' . MEDIA_DIRECTORY . $mod_pic_link . '" alt="" /></a></td><td>' . $excerpt . '</td></tr></tbody></table>';
        }
    }
    // print-out the excerpt
    $vars = array();
    $values = array();
    list($date, $time) = get_page_modified($mod_page_modified_when);
    list($username, $displayname) = get_page_modified_by($mod_page_modified_by, $func_users);
    $vars = array('[LINK]', '[TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[DESCRIPTION]', '[USERNAME]', '[DISPLAY_NAME]', '[DATE]', '[TIME]', '[TEXT_LAST_UPDATED_BY]', '[TEXT_ON]', '[EXCERPT]');
    $values = array($link, $mod_page_title, $func_page_title, $func_page_menu_title, $mod_page_description, $username, $displayname, $date, $time, $TEXT['LAST_UPDATED_BY'], $TEXT['ON'], $excerpt);
    echo str_replace($vars, $values, $func_results_loop_string);
    if ($func_enable_flush) {
        // ATTN: this will bypass output-filters and may break template-layout or -filters
        ob_flush();
        flush();
    }
    return true;
}
示例#2
0
/**
 * This is the main function for all module search functions.
 * 
 * @param array $search_result - variables given from the module or droplep
 * @param array $search_parameter - variables given from the LEPTON search to the module
 * @return boolean true if the search result of the module match or false in all other cases
 */
function print_excerpt2($search_result, $search_parameter)
{
    // check the search result variables
    if ($search_result['text'] == "") {
        return false;
    }
    if (!isset($search_result['page_link'])) {
        $search_result['page_link'] = $search_parameter['page_link'];
    }
    if (!isset($search_result['page_link_target'])) {
        $search_result['page_link_target'] = "";
    }
    if (!isset($search_result['page_title'])) {
        $search_result['page_title'] = $search_parameter['page_title'];
    }
    if (!isset($search_result['page_description'])) {
        $search_result['page_description'] = $search_parameter['page_description'];
    }
    if (!isset($search_result['page_modified_when'])) {
        $search_result['page_modified_when'] = $search_parameter['page_modified_when'];
    }
    if (!isset($search_result['page_modified_by'])) {
        $search_result['page_modified_by'] = $search_parameter['page_modified_by'];
    }
    if (!isset($search_result['text'])) {
        $search_result['text'] = "";
    }
    if (!isset($search_result['max_excerpt_num'])) {
        $search_result['max_excerpt_num'] = $search_parameter['default_max_excerpt'];
    }
    // special: image links
    if (!isset($search_result['pic_link'])) {
        $search_result['pic_link'] = '';
    }
    if (!isset($search_result['image_link'])) {
        $search_result['image_link'] = $search_result['pic_link'];
    }
    if (!isset($search_result['no_highlight'])) {
        $search_result['no_highlight'] = false;
    }
    if (isset($search_result['ext_charset'])) {
        $search_result['ext_charset'] = strtolower($search_result['ext_charset']);
    } else {
        $search_result['ext_charset'] = '';
    }
    if ($search_result['no_highlight']) {
        // suppress highlighting of search results
        $search_result['page_link_target'] = "&amp;nohighlight=1" . $search_result['page_link_target'];
    }
    // clean the text:
    $search_result['text'] = preg_replace('#<(br|dt|/dd|/?(?:h[1-6]|tr|table|p|li|ul|pre|code|div|hr))[^>]*>#i', '.', $search_result['text']);
    $search_result['text'] = preg_replace('#<(!--.*--|style.*</style|script.*</script)>#iU', ' ', $search_result['text']);
    $search_result['text'] = preg_replace('#\\[\\[.*?\\]\\]#', '', $search_result['text']);
    //Filter droplets from the page data
    // strip_tags() is called below
    if ($search_result['ext_charset'] != '') {
        // data from external database may have a different charset
        require_once CAT_PATH . '/framework/functions-utf8.php';
        switch ($search_result['ext_charset']) {
            case 'latin1':
            case 'cp1252':
                $search_result['text'] = charset_to_utf8($search_result['text'], 'CP1252');
                break;
            case 'cp1251':
                $search_result['text'] = charset_to_utf8($search_result['text'], 'CP1251');
                break;
            case 'latin2':
                $search_result['text'] = charset_to_utf8($search_result['text'], 'ISO-8859-2');
                break;
            case 'hebrew':
                $search_result['text'] = charset_to_utf8($search_result['text'], 'ISO-8859-8');
                break;
            case 'greek':
                $search_result['text'] = charset_to_utf8($search_result['text'], 'ISO-8859-7');
                break;
            case 'latin5':
                $search_result['text'] = charset_to_utf8($search_result['text'], 'ISO-8859-9');
                break;
            case 'latin7':
                $search_result['text'] = charset_to_utf8($search_result['text'], 'ISO-8859-13');
                break;
            case 'utf8':
            default:
                $search_result['text'] = charset_to_utf8($search_result['text'], 'UTF-8');
        }
    } else {
        $search_result['text'] = entities_to_umlauts($search_result['text'], 'UTF-8');
    }
    $content_locked = '';
    $add_anchor = true;
    if (isset($_SESSION[SESSION_SEARCH_NON_PUBLIC_CONTENT])) {
        // show non-public contents, so add some extra informations
        if (isset($_SESSION[SESSION_SEARCH_LINK_NON_PUBLIC_CONTENT]) && !empty($_SESSION[SESSION_SEARCH_LINK_NON_PUBLIC_CONTENT])) {
            // link to a special page, defined in search as CFG_LINK_NON_PUBLIC_CONTENT
            $search_result['page_link'] = CAT_URL . $_SESSION[SESSION_SEARCH_LINK_NON_PUBLIC_CONTENT];
        } else {
            $search_result['page_link'] = '';
        }
        // $_SESSION reset
        unset($_SESSION[SESSION_SEARCH_NON_PUBLIC_CONTENT]);
        unset($_SESSION[SESSION_SEARCH_LINK_NON_PUBLIC_CONTENT]);
        $add_anchor = false;
    }
    $anchor_text = $search_result['text'];
    // make an copy containing html-tags
    $search_result['text'] = strip_tags($search_result['text']);
    $search_result['text'] = str_replace(array('&gt;', '&lt;', '&amp;', '&quot;', '&#039;', '&apos;', '&nbsp;'), array('>', '<', '&', '"', '\'', '\'', ' '), $search_result['text']);
    $search_result['text'] = '.' . trim($search_result['text']) . '.';
    // create empty image array
    $images = array();
    if ($search_parameter['settings'][CFG_SEARCH_IMAGES] || $search_parameter['settings'][CFG_CONTENT_IMAGE]) {
        // we need a image array for the search
        preg_match_all('/<img[^>]*>/', $anchor_text, $matches);
        foreach ($matches as $match) {
            foreach ($match as $img_tag) {
                // <img ...> zerlegen
                preg_match_all('/([a-zA-Z]*[a-zA-Z])\\s{0,3}[=]\\s{0,3}("[^"\\r\\n]*)"/', $img_tag, $attr);
                foreach ($attr as $attributes) {
                    $img = array();
                    foreach ($attributes as $attribut) {
                        if (strpos($attribut, "=") !== false) {
                            list($key, $value) = explode("=", $attribut);
                            $value = trim($value);
                            $value = substr($value, 1, strlen($value) - 2);
                            $img[strtolower(trim($key))] = trim($value);
                        }
                    }
                    if (isset($img['src'])) {
                        $images[] = $img;
                    }
                }
            }
        }
    }
    if (!$search_parameter['settings'][CFG_SEARCH_IMAGES] && $search_parameter['settings'][CFG_CONTENT_IMAGE] == CONTENT_IMAGE_NONE) {
        // Do a fast scan over the search result first. This may speedup things a lot.
        if ($search_parameter['search_match'] == SEARCH_TYPE_ALL) {
            if (!is_all_matched($search_result['text'], $search_parameter['search_words'])) {
                return false;
            }
        } elseif (!is_any_matched($search_result['text'], $search_parameter['search_words'])) {
            return false;
        }
    } else {
        // create a dummy string to check matches in the images
        $divider = '.';
        $image_text = '';
        foreach ($images as $image) {
            $file = basename($image['src']);
            $file = urldecode(substr($file, 0, strrpos($file, '.')));
            $alt = isset($image['alt']) && !empty($image['alt']) ? $image['alt'] : '';
            $title = isset($image['title']) && !empty($image['title']) ? $image['title'] : '';
            $image_text .= $alt == $title ? $divider . $alt . $divider . $file . $divider : $divider . $alt . $divider . $title . $divider . $file . $divider;
        }
        if ($search_parameter['search_match'] == SEARCH_TYPE_ALL) {
            if (!is_all_matched($search_result['text'] . $image_text, $search_parameter['search_words'])) {
                return false;
            }
        } elseif (!is_any_matched($search_result['text'] . $image_text, $search_parameter['search_words'])) {
            return false;
        }
    }
    // search for an better anchor - this have to be done before strip_tags() (may fail if search-string contains <, &, amp, gt, lt, ...)
    $anchor = make_url_target($search_result['page_link_target'], $anchor_text, $search_parameter['search_words']);
    // make the link from $mod_page_link, add anchor
    $link = "";
    if (!empty($search_result['page_link'])) {
        $link = page_link($search_result['page_link']);
        if (strpos($search_result['page_link'], 'http:') === false) {
            $link .= make_url_searchstring($search_parameter['search_match'], $search_parameter['search_url_array']);
        }
        // add anchor only if content is not locked!
        if ($add_anchor) {
            $link .= $anchor;
        }
    }
    // now get the excerpt
    $excerpt = "";
    $excerpt_array = array();
    // dont create excerpts if we are only searching for images!
    if ($search_parameter['search_match'] != SEARCH_TYPE_IMAGE && $search_result['max_excerpt_num'] > 0) {
        if (false !== ($excerpt_array = get_excerpts($search_result['text'], $search_parameter['search_words'], $search_result['max_excerpt_num']))) {
            $excerpt = prepare_excerpts($excerpt_array, $search_parameter['search_words'], $search_result['max_excerpt_num']);
        }
    }
    // no image matches now ...
    $image_match = false;
    $image_array = array();
    if ($search_parameter['settings'][CFG_SEARCH_IMAGES] || $search_parameter['search_match'] == SEARCH_TYPE_ALL) {
        // ok - now we are looking for matching images ...
        foreach ($images as $image) {
            $file = urldecode(basename($image['src']));
            $file = substr($file, 0, strrpos($file, '.'));
            $alt = isset($image['alt']) && !empty($image['alt']) ? $image['alt'] : '';
            $title = isset($image['title']) && !empty($image['title']) ? $image['title'] : '';
            $image_text = $alt == $title ? $divider . $alt . $divider . $file . $divider : $divider . $alt . $divider . $title . $divider . $file . $divider;
            if (false !== ($excerpt_array = get_excerpts($image_text, $search_parameter['search_words'], $search_result['max_excerpt_num']))) {
                // image match!
                $image_excerpt = prepare_excerpts($excerpt_array, $search_parameter['search_words'], $search_result['max_excerpt_num']);
                // accept only images with complete URL
                if (false === strpos($image['src'], CAT_URL)) {
                    continue;
                }
                $src = str_ireplace(CAT_URL, CAT_PATH, urldecode($image['src']));
                $target = CAT_PATH . '/temp/search/' . urldecode(basename($image['src']));
                makeThumbnail($src, $target, $search_parameter['settings'][CFG_THUMBS_WIDTH]);
                $image_array[] = array('excerpt' => $image_excerpt, 'src' => CAT_URL . '/temp/search/' . urldecode(basename($image['src'])), 'alt' => isset($image['alt']) ? $image['alt'] : '', 'title' => isset($image['title']) ? $image['title'] : '', 'width' => $search_parameter['settings'][CFG_THUMBS_WIDTH]);
                $image_match = true;
            }
        }
    }
    // leave here if nothing matches ...
    if (empty($excerpt) && !$image_match) {
        return false;
    }
    $thumb_array = array();
    // if no images are matching to the search it's possible to show a image
    // of the content or to use a desired image_link from the module
    $use_thumb = 0;
    if (!$image_match && ($search_parameter['settings'][CFG_CONTENT_IMAGE] != CONTENT_IMAGE_NONE || !empty($search_result['image_link']))) {
        if (!empty($search_result['image_link'])) {
            if (strpos($search_result['image_link'], CAT_URL) === false) {
                $src = CAT_PATH . MEDIA_DIRECTORY . DIRECTORY_SEPARATOR . $search_result['image_link'];
            } else {
                $src = str_ireplace(CAT_URL, CAT_PATH, $search_result['image_link']);
            }
            // the path to the temporary thumbnail
            $target = CAT_PATH . '/temp/search/' . basename($search_result['image_link']);
            // create a thumbnail and place it in the temporary directory
            if (makeThumbnail($src, $target, $search_parameter['settings'][CFG_THUMBS_WIDTH])) {
                $thumb_array = array('src' => CAT_URL . '/temp/search/' . urldecode(basename($search_result['image_link'])), 'alt' => $search_result['page_title'], 'title' => $search_result['page_title'], 'width' => $search_parameter['settings'][CFG_THUMBS_WIDTH]);
                $use_thumb = 1;
            } else {
                $use_thumb = 0;
            }
        } else {
            switch ($search_parameter['settings'][CFG_CONTENT_IMAGE]) {
                case CONTENT_IMAGE_FIRST:
                    $i = 0;
                    break;
                case CONTENT_IMAGE_LAST:
                    $i = count($images) - 1;
                    break;
                case CONTENT_IMAGE_RANDOM:
                    $i = rand(0, count($images) - 1);
                    break;
                default:
                    $i = 0;
            }
            if (isset($images[$i]['src']) && false !== strpos($images[$i]['src'], CAT_URL)) {
                $src = str_ireplace(CAT_URL, CAT_PATH, urldecode($images[$i]['src']));
                // the path to the temporary thumbnail
                $target = CAT_PATH . '/temp/search/' . urldecode(basename($images[$i]['src']));
                // create a thumbnail and place it in the temporary directory
                if (makeThumbnail($src, $target, $search_parameter['settings'][CFG_THUMBS_WIDTH])) {
                    $thumb_array = array('src' => CAT_URL . '/temp/search/' . urldecode(basename($images[$i]['src'])), 'alt' => isset($images[$i]['alt']) ? $images[$i]['alt'] : '', 'title' => isset($images[$i]['title']) ? $images[$i]['title'] : '', 'width' => $search_parameter['settings'][CFG_THUMBS_WIDTH]);
                    $use_thumb = 1;
                } else {
                    $use_thumb = 0;
                }
            } else {
                $use_thumb = 0;
            }
        }
    } else {
        $use_thumb = 0;
    }
    list($date, $time) = get_page_modified($search_result['page_modified_when']);
    list($username, $displayname) = get_page_modified_by($search_result['page_modified_by'], $search_parameter['users']);
    $item = array('page' => array('link' => $link, 'title' => $search_result['page_title'], 'description' => $search_result['page_description'], 'excerpt' => $excerpt, 'images' => array('items' => $image_array, 'count' => count($image_array)), 'thumb' => array('active' => $use_thumb, 'image' => $thumb_array), 'last_changed' => array('unix_time' => $search_result['page_modified_when'], 'date_formatted' => $date, 'time_formatted' => $time), 'visibility' => $search_parameter['page_visibility']), 'user' => array('name' => $username, 'display_name' => $displayname));
    // all search results are temporary saved in the $_SESSION['SEARCH_RESULT_ITEMS']
    if (!isset($_SESSION[SESSION_SEARCH_RESULT_ITEMS])) {
        $_SESSION[SESSION_SEARCH_RESULT_ITEMS] = array();
    }
    $_SESSION[SESSION_SEARCH_RESULT_ITEMS][] = $item;
    return true;
}