Ejemplo n.º 1
0
function search_articles($items, $conn)
{
    global $set, $db, $apx, $user;
    require_once BASEDIR . getmodulepath('articles') . 'functions.php';
    //Suchstrings generieren
    $tagmatches = articles_match_tags($items);
    foreach ($items as $item) {
        $tagmatch = array_shift($tagmatches);
        $search1[] = "( title LIKE '%" . addslashes_like($item) . "%' OR text LIKE '%" . addslashes_like($item) . "%' ) ";
        $search2[] = "( " . iif($tagmatch, " id IN (" . implode(',', $tagmatch) . ") OR ") . " title LIKE '%" . addslashes_like($item) . "%' OR subtitle LIKE '%" . addslashes_like($item) . "%' OR teaser LIKE '%" . addslashes_like($item) . "%' ) ";
    }
    $searchstring1 = "( " . implode($conn, $search1) . " )";
    $searchstring2 = "( " . implode($conn, $search2) . " )";
    //Seiten durchsuchen
    $data = $db->fetch("SELECT artid FROM " . PRE . "_articles_pages WHERE ( " . $searchstring1 . " ) GROUP BY artid");
    $artids = get_ids($data, 'artid');
    if (count($artids)) {
        $pageres = "id IN (" . @implode(',', $artids) . ") OR";
    }
    //Artikel durchsuchen
    $data = $db->fetch("SELECT id,type,title,subtitle FROM " . PRE . "_articles WHERE ( searchable='1' AND '" . time() . "' BETWEEN starttime AND endtime " . section_filter() . " AND ( " . $pageres . " " . $searchstring2 . " ) ) ORDER BY starttime DESC");
    if (count($data)) {
        foreach ($data as $res) {
            ++$i;
            //Wohin soll verlinkt werden?
            if ($res['type'] == 'normal') {
                $link2file = 'articles';
            } else {
                $link2file = $res['type'] . 's';
            }
            $link = mklink($link2file . '.php?id=' . $res['id'], $link2file . ',id' . $res['id'] . ',0' . urlformat($res['title']) . '.html');
            $result[$i]['TITLE'] = strip_tags($res['title']) . iif($res['subtitle'], ' - ' . strip_tags($res['subtitle']));
            $result[$i]['LINK'] = $link;
        }
    }
    return $result;
}
Ejemplo n.º 2
0
         $laststamp = date('Y/m/d', $res['starttime'] - TIMEDIFF);
     }
     $apx->tmpl->assign('ARTICLE', $tabledata);
     $apx->tmpl->parse('search_result');
 } else {
     $where = '';
     $pagewhere = '';
     //Alle Artikeltypen sind nicht gewählt
     if (!is_array($_REQUEST['type']) || !count($_REQUEST['type'])) {
         $_REQUEST['type'] = array('normal', 'preview', 'review');
     }
     //Suchbegriffe
     if ($_REQUEST['item']) {
         $items = array();
         $it = explode(' ', preg_replace('#[ ]{2,}#', ' ', trim($_REQUEST['item'])));
         $tagmatches = articles_match_tags($it);
         foreach ($it as $item) {
             if (trim($item)) {
                 $string = preg_replace('#[\\s_-]+#', '[^0-9a-zA-Z]*', $item);
                 if (preg_match('#^[0-9a-zA-Z]+$#', $string)) {
                     $items[] = " LIKE '%" . addslashes_like($string) . "%' ";
                 } else {
                     $items[] = " REGEXP '" . addslashes($string) . "' ";
                 }
             }
         }
         if ($_REQUEST['conn'] == 'or') {
             $conn = ' OR ';
         } else {
             $conn = ' AND ';
         }