Ejemplo n.º 1
0
 function article_rows($status, $time, $search, $searchsticky, $section, $category, $excerpted, $month, $author, $keywords, $custom, $frontpage, $sort)
 {
     $where = array();
     if ($status) {
         $where['status'] = $status;
     } elseif ($searchsticky) {
         $where[] = 'status >= 4';
     } else {
         $where['status'] = 4;
     }
     if ($search) {
         include_once txpath . '/publish/search.php';
         $s_filter = $searchall ? filterSearch() : '';
         $match = ", " . db_match('Title,Body', doSlash($q));
         $words = preg_split('/\\s+/', $q);
         foreach ($words as $w) {
             $where[] = "(Title " . db_rlike() . " '" . doSlash(preg_quote($w)) . "' or Body " . db_rlike() . " '" . doSlash(preg_quote($w)) . "')";
         }
         #$search = " and " . join(' and ', $rlike) . " $s_filter";
         $where[] = $s_filter;
         // searchall=0 can be used to show search results for the current section only
         if ($searchall) {
             $section = '';
         }
         if (!$sort) {
             $sort = 'score';
         }
     }
     // ..etc..
 }
Ejemplo n.º 2
0
function search($q)
{
    global $prefs;
    $url = $prefs['siteurl'];
    extract($prefs);
    $s_filter = filterSearch();
    $form = fetch('form', 'txp_form', 'name', 'search_results');
    // lose this eventually - only used if search_results form is missing
    $form = !$form ? legacy_form() : $form;
    $rs = safe_rows("*, ID as thisid, unix_timestamp(Posted) as posted, Title as title,\n\t\t\tmatch (Title,Body) against ('{$q}') as score", "textpattern", "(Title rlike '{$q}' or Body rlike '{$q}') {$s_filter}\n\t\t\tand Status = 4 and Posted <=now() order by score desc limit 40");
    if ($rs) {
        $result_rows = count($rs);
        $text = $result_rows == 1 ? gTxt('article_found') : gTxt('articles_found');
    } else {
        $result_rows = 0;
        $text = gTxt('articles_found');
    }
    $results[] = graf($result_rows . ' ' . $text);
    if ($result_rows > 0) {
        foreach ($rs as $a) {
            extract($a);
            $result_date = safe_strftime($archive_dateformat, $posted);
            $uTitle = $url_title ? $url_title : stripSpace($Title);
            $hurl = permlinkurl($a);
            $result_url = '<a href="' . $hurl . '">' . $hurl . '</a>';
            $result_title = '<a href="' . $hurl . '">' . $Title . '</a>';
            $result = preg_replace("/>\\s*</", "> <", $Body_html);
            preg_match_all("/\\s.{1,50}" . preg_quote($q) . ".{1,50}\\s/i", $result, $concat);
            $concat = join(" ... ", $concat[0]);
            $concat = strip_tags($concat);
            $concat = preg_replace('/^[^>]+>/U', "", $concat);
            $concat = preg_replace("/({$q})/i", "<strong>\$1</strong>", $concat);
            $result_excerpt = $concat ? "... " . $concat . " ..." : '';
            $glob['search_result_title'] = $result_title;
            $glob['search_result_excerpt'] = $result_excerpt;
            $glob['search_result_url'] = $result_url;
            $glob['search_result_date'] = $result_date;
            $GLOBALS['this_result'] = $glob;
            $thisresult = $form;
            $results[] = parse($thisresult);
        }
    }
    return is_array($results) ? join('', $results) : '';
}
Ejemplo n.º 3
0
/**
 * Performs searching and returns results.
 *
 * This is now performed by doArticles().
 *
 * @param      string $q
 * @deprecated in 4.0.4
 * @see        doArticles()
 */
function search($q)
{
    global $prefs;
    $url = $prefs['siteurl'];
    extract($prefs);
    $s_filter = filterSearch();
    $form = fetch('form', 'txp_form', 'name', 'search_results');
    // Lose this eventually - only used if search_results form is missing.
    $form = !$form ? legacy_form() : $form;
    $rs = safe_rows("*, ID AS thisid, UNIX_TIMESTAMP(Posted) AS posted, Title AS title,\n        MATCH (Title,Body) AGAINST ('{$q}') AS score", 'textpattern', "(Title RLIKE '{$q}' OR Body RLIKE '{$q}') {$s_filter}\n        AND Status = 4 AND Posted <= " . now('posted') . " ORDER BY score DESC LIMIT 40");
    if ($rs) {
        $result_rows = count($rs);
        $text = $result_rows == 1 ? gTxt('article_found') : gTxt('articles_found');
    } else {
        $result_rows = 0;
        $text = gTxt('articles_found');
    }
    $results[] = graf($result_rows . ' ' . $text);
    if ($result_rows > 0) {
        foreach ($rs as $a) {
            extract($a);
            $result_date = safe_strftime($archive_dateformat, $posted);
            $uTitle = $url_title ? $url_title : stripSpace($Title);
            $hurl = permlinkurl($a);
            $result_url = '<a href="' . $hurl . '">' . $hurl . '</a>';
            $result_title = '<a href="' . $hurl . '">' . $Title . '</a>';
            $result = preg_replace("/>\\s*</", "> <", $Body_html);
            preg_match_all("/\\s.{1,50}" . preg_quote($q) . ".{1,50}\\s/i", $result, $concat);
            $concat = join(" ... ", $concat[0]);
            $concat = strip_tags($concat);
            $concat = preg_replace('/^[^>]+>/U', "", $concat);
            $concat = preg_replace("/({$q})/i", "<strong>\$1</strong>", $concat);
            $result_excerpt = $concat ? "... " . $concat . " ..." : '';
            $glob['search_result_title'] = $result_title;
            $glob['search_result_excerpt'] = $result_excerpt;
            $glob['search_result_url'] = $result_url;
            $glob['search_result_date'] = $result_date;
            $GLOBALS['this_result'] = $glob;
            $thisresult = $form;
            $results[] = parse($thisresult);
        }
    }
    return is_array($results) ? join('', $results) : '';
}
Ejemplo n.º 4
0
function search($q)
{
    global $prefs;
    $url = $prefs['siteurl'];
    extract($prefs);
    $s_filter = filterSearch();
    $form = fetch('form', 'txp_form', 'name', 'search_results');
    // lose this eventually - only used if search_results form is missing
    $form = !$form ? legacy_form() : $form;
    $rs = safe_rows("ID, Title, Body_html, Section, unix_timestamp(Posted) as uPosted, \n\t\t\tmatch (Title,Body) against ('{$q}') as score", "textpattern", "Title rlike '{$q}' or Body rlike '{$q}' {$s_filter}\n\t\t\tand Status = 4 and Posted <=now() order by score desc limit 40");
    if ($rs) {
        $result_rows = count($rs);
        $text = $result_rows == 1 ? gTxt('article_found') : gTxt('articles_found');
    } else {
        $result_rows = 0;
        $text = gTxt('articles_found');
    }
    $results[] = graf($result_rows . ' ' . $text);
    if ($result_rows > 0) {
        foreach ($rs as $a) {
            extract($a);
            $result_date = date("j M Y", $uPosted);
            $hurl = $url_mode ? $siteurl . $path_from_root . $Section . '/' . $ID . '/' . stripSpace($Title) : $siteurl . $path_from_root . 'index.php?id=' . $ID;
            $result_url = '<a href="http://' . $hurl . '">' . $hurl . '</a>';
            $result_title = '<a href="http://' . $hurl . '">' . $Title . '</a>';
            $result = preg_replace("/>\\s*</", "> <", $Body_html);
            preg_match_all("/\\s.{0,50}" . $q . ".{0,50}\\s/i", $result, $concat);
            $concat = implode(" ... ", $concat[0]);
            $concat = strip_tags($concat);
            $concat = preg_replace('/^[^>]+>/U', "", $concat);
            $concat = preg_replace("/({$q})/i", "<strong>\$1</strong>", $concat);
            $result_excerpt = $concat ? "... " . $concat . " ..." : '';
            $glob['search_result_title'] = $result_title;
            $glob['search_result_excerpt'] = $result_excerpt;
            $glob['search_result_url'] = $result_url;
            $glob['search_result_date'] = $result_date;
            $GLOBALS['this_result'] = $glob;
            $thisresult = $form;
            $results[] = parse($thisresult);
        }
    }
    return is_array($results) ? join('', $results) : '';
}
Ejemplo n.º 5
0
function doArticles($atts, $iscustom, $thing = null)
{
    global $pretext, $prefs;
    extract($pretext);
    extract($prefs);
    $customFields = getCustomFields();
    $customlAtts = array_null(array_flip($customFields));
    if ($iscustom) {
        $extralAtts = array('category' => '', 'section' => '', 'excerpted' => '', 'author' => '', 'month' => '', 'expired' => $publish_expired_articles, 'id' => '', 'exclude' => '');
    } else {
        $extralAtts = array('listform' => '', 'searchform' => '', 'searchall' => 1, 'searchsticky' => 0, 'pageby' => '', 'pgonly' => 0);
    }
    // Getting attributes.
    $theAtts = lAtts(array('form' => 'default', 'limit' => 10, 'sort' => '', 'sortby' => '', 'sortdir' => '', 'keywords' => '', 'time' => 'past', 'status' => STATUS_LIVE, 'allowoverride' => !$q and !$iscustom, 'offset' => 0, 'wraptag' => '', 'break' => '', 'label' => '', 'labeltag' => '', 'class' => '') + $customlAtts + $extralAtts, $atts);
    // For the txp:article tag, some attributes are taken from globals;
    // override them, then stash all filter attributes.
    if (!$iscustom) {
        $theAtts['category'] = $c ? $c : '';
        $theAtts['section'] = $s && $s != 'default' ? $s : '';
        $theAtts['author'] = !empty($author) ? $author : '';
        $theAtts['month'] = !empty($month) ? $month : '';
        $theAtts['frontpage'] = $s && $s == 'default' ? true : false;
        $theAtts['excerpted'] = 0;
        $theAtts['exclude'] = 0;
        $theAtts['expired'] = $publish_expired_articles;
        filterAtts($theAtts);
    } else {
        $theAtts['frontpage'] = false;
    }
    extract($theAtts);
    // If a listform is specified, $thing is for doArticle() - hence ignore here.
    if (!empty($listform)) {
        $thing = '';
    }
    $pageby = empty($pageby) ? $limit : $pageby;
    // Treat sticky articles differently wrt search filtering, etc.
    $status = in_array(strtolower($status), array('sticky', STATUS_STICKY)) ? STATUS_STICKY : STATUS_LIVE;
    $issticky = $status == STATUS_STICKY;
    // Give control to search, if necessary.
    if ($q && !$iscustom && !$issticky) {
        include_once txpath . '/publish/search.php';
        $s_filter = $searchall ? filterSearch() : '';
        $q = trim($q);
        $quoted = $q[0] === '"' && $q[strlen($q) - 1] === '"';
        $q = doSlash($quoted ? trim(trim($q, '"')) : $q);
        // Searchable article fields are limited to the columns of the
        // textpattern table and a matching fulltext index must exist.
        $cols = do_list_unique($searchable_article_fields);
        if (empty($cols) or $cols[0] == '') {
            $cols = array('Title', 'Body');
        }
        $match = ", MATCH (`" . join("`, `", $cols) . "`) AGAINST ('{$q}') AS score";
        $search_terms = preg_replace('/\\s+/', ' ', str_replace(array('\\', '%', '_', '\''), array('\\\\', '\\%', '\\_', '\\\''), $q));
        if ($quoted || empty($m) || $m === 'exact') {
            for ($i = 0; $i < count($cols); $i++) {
                $cols[$i] = "`{$cols[$i]}` LIKE '%{$search_terms}%'";
            }
        } else {
            $colJoin = $m === 'any' ? "OR" : "AND";
            $search_terms = explode(' ', $search_terms);
            for ($i = 0; $i < count($cols); $i++) {
                $like = array();
                foreach ($search_terms as $search_term) {
                    $like[] = "`{$cols[$i]}` LIKE '%{$search_term}%'";
                }
                $cols[$i] = "(" . join(" {$colJoin} ", $like) . ")";
            }
        }
        $cols = join(" OR ", $cols);
        $search = " AND ({$cols}) {$s_filter}";
        // searchall=0 can be used to show search results for the current
        // section only.
        if ($searchall) {
            $section = '';
        }
        if (!$sort) {
            $sort = "score DESC";
        }
    } else {
        $match = $search = '';
        if (!$sort) {
            $sort = "Posted DESC";
        }
    }
    // For backwards compatibility. sortby and sortdir are deprecated.
    if ($sortby) {
        trigger_error(gTxt('deprecated_attribute', array('{name}' => 'sortby')), E_USER_NOTICE);
        if (!$sortdir) {
            $sortdir = "DESC";
        } else {
            trigger_error(gTxt('deprecated_attribute', array('{name}' => 'sortdir')), E_USER_NOTICE);
        }
        $sort = "{$sortby} {$sortdir}";
    } elseif ($sortdir) {
        trigger_error(gTxt('deprecated_attribute', array('{name}' => 'sortdir')), E_USER_NOTICE);
        $sort = "Posted {$sortdir}";
    }
    // Building query parts.
    $frontpage = ($frontpage and (!$q or $issticky)) ? filterFrontPage() : '';
    $category = join("','", doSlash(do_list_unique($category)));
    $category = !$category ? '' : " AND (Category1 IN ('" . $category . "') OR Category2 IN ('" . $category . "'))";
    $section = !$section ? '' : " AND Section IN ('" . join("','", doSlash(do_list_unique($section))) . "')";
    $excerpted = !$excerpted ? '' : " AND Excerpt !=''";
    $author = !$author ? '' : " AND AuthorID IN ('" . join("','", doSlash(do_list_unique($author))) . "')";
    $month = !$month ? '' : " AND Posted LIKE '" . doSlash($month) . "%'";
    $ids = $id ? array_map('intval', do_list_unique($id)) : array();
    $exclude = $exclude ? array_map('intval', do_list_unique($exclude)) : array();
    $id = (!$id ? '' : " AND ID IN (" . join(',', $ids) . ")") . (!$exclude ? '' : " AND ID NOT IN (" . join(',', $exclude) . ")");
    switch ($time) {
        case 'any':
            $time = "";
            break;
        case 'future':
            $time = " AND Posted > " . now('posted');
            break;
        default:
            $time = " AND Posted <= " . now('posted');
    }
    if (!$expired) {
        $time .= " AND (" . now('expires') . " <= Expires OR Expires = " . NULLDATETIME . ")";
    }
    $custom = '';
    if ($customFields) {
        foreach ($customFields as $cField) {
            if (isset($atts[$cField])) {
                $customPairs[$cField] = $atts[$cField];
            }
        }
        if (!empty($customPairs)) {
            $custom = buildCustomSql($customFields, $customPairs);
        }
    }
    // Allow keywords for no-custom articles. That tagging mode, you know.
    if ($keywords) {
        $keys = doSlash(do_list_unique($keywords));
        foreach ($keys as $key) {
            $keyparts[] = "FIND_IN_SET('" . $key . "', Keywords)";
        }
        $keywords = " AND (" . join(' or ', $keyparts) . ")";
    }
    if ($q and $searchsticky) {
        $statusq = " AND Status >= " . STATUS_LIVE;
    } elseif ($id) {
        $statusq = " AND Status >= " . STATUS_LIVE;
    } else {
        $statusq = " AND Status = " . intval($status);
    }
    $where = "1 = 1" . $statusq . $time . $search . $id . $category . $section . $excerpted . $month . $author . $keywords . $custom . $frontpage;
    // Do not paginate if we are on a custom list.
    if (!$iscustom and !$issticky) {
        $grand_total = safe_count('textpattern', $where);
        $total = $grand_total - $offset;
        $numPages = ceil($total / $pageby);
        $pg = !$pg ? 1 : $pg;
        $pgoffset = $offset + ($pg - 1) * $pageby;
        // Send paging info to txp:newer and txp:older.
        $pageout['pg'] = $pg;
        $pageout['numPages'] = $numPages;
        $pageout['s'] = $s;
        $pageout['c'] = $c;
        $pageout['context'] = 'article';
        $pageout['grand_total'] = $grand_total;
        $pageout['total'] = $total;
        global $thispage;
        if (empty($thispage)) {
            $thispage = $pageout;
        }
        if ($pgonly) {
            return;
        }
    } else {
        $pgoffset = $offset;
    }
    // Preserve order of custom article ids unless 'sort' attribute is set.
    if (!empty($atts['id']) && empty($atts['sort'])) {
        $safe_sort = "FIELD(id, " . join(',', $ids) . ")";
    } else {
        $safe_sort = doSlash($sort);
    }
    $rs = safe_rows_start("*, UNIX_TIMESTAMP(Posted) AS uPosted, UNIX_TIMESTAMP(Expires) AS uExpires, UNIX_TIMESTAMP(LastMod) AS uLastMod" . $match, 'textpattern', "{$where} ORDER BY {$safe_sort} LIMIT " . intval($pgoffset) . ", " . intval($limit));
    // Get the form name.
    if ($q and !$iscustom and !$issticky) {
        $fname = $searchform ? $searchform : 'search_results';
    } else {
        $fname = !empty($listform) ? $listform : $form;
    }
    if ($rs) {
        $count = 0;
        $last = numRows($rs);
        $articles = array();
        while ($a = nextRow($rs)) {
            ++$count;
            populateArticleData($a);
            global $thisarticle, $uPosted, $limit;
            $thisarticle['is_first'] = $count == 1;
            $thisarticle['is_last'] = $count == $last;
            // Article form preview.
            if (txpinterface === 'admin' && ps('Form')) {
                doAuth();
                if (!has_privs('form')) {
                    txp_status_header('401 Unauthorized');
                    exit(hed('401 Unauthorized', 1) . graf(gTxt('restricted_area')));
                }
                $articles[] = parse(gps('Form'));
            } elseif ($allowoverride and $a['override_form']) {
                $articles[] = parse_form($a['override_form']);
            } else {
                $articles[] = $thing ? parse($thing) : parse_form($fname);
            }
            // Sending these to paging_link(); Required?
            $uPosted = $a['uPosted'];
            unset($GLOBALS['thisarticle']);
        }
        return doLabel($label, $labeltag) . doWrap($articles, $wraptag, $break, $class);
    }
}
Ejemplo n.º 6
0
function doArticles($atts, $iscustom, $thing = NULL)
{
    global $pretext, $prefs;
    extract($pretext);
    extract($prefs);
    $customFields = getCustomFields();
    $customlAtts = array_null(array_flip($customFields));
    //getting attributes
    $theAtts = lAtts(array('form' => 'default', 'listform' => '', 'searchform' => '', 'limit' => 10, 'pageby' => '', 'category' => '', 'section' => '', 'excerpted' => '', 'author' => '', 'sort' => '', 'sortby' => '', 'sortdir' => '', 'month' => '', 'keywords' => '', 'frontpage' => '', 'id' => '', 'time' => 'past', 'status' => '4', 'pgonly' => 0, 'searchall' => 1, 'searchsticky' => 0, 'allowoverride' => !$q and !$iscustom, 'offset' => 0, 'wraptag' => '', 'break' => '', 'label' => '', 'labeltag' => '', 'class' => '') + $customlAtts, $atts);
    // if an article ID is specified, treat it as a custom list
    $iscustom = !empty($theAtts['id']) ? true : $iscustom;
    //for the txp:article tag, some attributes are taken from globals;
    //override them before extract
    if (!$iscustom) {
        $theAtts['category'] = $c ? $c : '';
        $theAtts['section'] = $s && $s != 'default' ? $s : '';
        $theAtts['author'] = !empty($author) ? $author : '';
        $theAtts['month'] = !empty($month) ? $month : '';
        $theAtts['frontpage'] = $s && $s == 'default' ? true : false;
        $theAtts['excerpted'] = '';
    }
    extract($theAtts);
    // if a listform is specified, $thing is for doArticle() - hence ignore here.
    if (!empty($listform)) {
        $thing = '';
    }
    $pageby = empty($pageby) ? $limit : $pageby;
    // treat sticky articles differently wrt search filtering, etc
    $status = in_array(strtolower($status), array('sticky', '5')) ? 5 : 4;
    $issticky = $status == 5;
    // give control to search, if necessary
    if ($q && !$iscustom && !$issticky) {
        include_once txpath . '/publish/search.php';
        $s_filter = $searchall ? filterSearch() : '';
        $q = doSlash($q);
        // searchable article fields are limited to the columns of
        // the textpattern table and a matching fulltext index must exist.
        $cols = do_list($searchable_article_fields);
        if (empty($cols) or $cols[0] == '') {
            $cols = array('Title', 'Body');
        }
        $match = ', match (`' . join('`, `', $cols) . "`) against ('{$q}') as score";
        for ($i = 0; $i < count($cols); $i++) {
            $cols[$i] = "`{$cols[$i]}` rlike '{$q}'";
        }
        $cols = join(" or ", $cols);
        $search = " and ({$cols}) {$s_filter}";
        // searchall=0 can be used to show search results for the current section only
        if ($searchall) {
            $section = '';
        }
        if (!$sort) {
            $sort = 'score desc';
        }
    } else {
        $match = $search = '';
        if (!$sort) {
            $sort = 'Posted desc';
        }
    }
    // for backwards compatibility
    // sortby and sortdir are deprecated
    if ($sortby) {
        if (!$sortdir) {
            $sortdir = 'desc';
        }
        $sort = "{$sortby} {$sortdir}";
    } elseif ($sortdir) {
        $sort = "Posted {$sortdir}";
    }
    //Building query parts
    $frontpage = ($frontpage and (!$q or $issticky)) ? filterFrontPage() : '';
    $category = join("','", doSlash(do_list($category)));
    $category = !$category ? '' : " and (Category1 IN ('" . $category . "') or Category2 IN ('" . $category . "'))";
    $section = !$section ? '' : " and Section IN ('" . join("','", doSlash(do_list($section))) . "')";
    $excerpted = $excerpted == 'y' ? " and Excerpt !=''" : '';
    $author = !$author ? '' : " and AuthorID IN ('" . join("','", doSlash(do_list($author))) . "')";
    $month = !$month ? '' : " and Posted like '" . doSlash($month) . "%'";
    $id = !$id ? '' : " and ID IN (" . join(',', array_map('intval', do_list($id))) . ")";
    switch ($time) {
        case 'any':
            $time = "";
            break;
        case 'future':
            $time = " and Posted > now()";
            break;
        default:
            $time = " and Posted <= now()";
    }
    if (!$publish_expired_articles) {
        $time .= " and (now() <= Expires or Expires = " . NULLDATETIME . ")";
    }
    $custom = '';
    if ($customFields) {
        foreach ($customFields as $cField) {
            if (isset($atts[$cField])) {
                $customPairs[$cField] = $atts[$cField];
            }
        }
        if (!empty($customPairs)) {
            $custom = buildCustomSql($customFields, $customPairs);
        }
    }
    //Allow keywords for no-custom articles. That tagging mode, you know
    if ($keywords) {
        $keys = doSlash(do_list($keywords));
        foreach ($keys as $key) {
            $keyparts[] = "FIND_IN_SET('" . $key . "',Keywords)";
        }
        $keywords = " and (" . join(' or ', $keyparts) . ")";
    }
    if ($q and $searchsticky) {
        $statusq = ' and Status >= 4';
    } elseif ($id) {
        $statusq = ' and Status >= 4';
    } else {
        $statusq = ' and Status = ' . intval($status);
    }
    $where = "1=1" . $statusq . $time . $search . $id . $category . $section . $excerpted . $month . $author . $keywords . $custom . $frontpage;
    //do not paginate if we are on a custom list
    if (!$iscustom and !$issticky) {
        $grand_total = safe_count('textpattern', $where);
        $total = $grand_total - $offset;
        $numPages = ceil($total / $pageby);
        $pg = !$pg ? 1 : $pg;
        $pgoffset = $offset + ($pg - 1) * $pageby;
        // send paging info to txp:newer and txp:older
        $pageout['pg'] = $pg;
        $pageout['numPages'] = $numPages;
        $pageout['s'] = $s;
        $pageout['c'] = $c;
        $pageout['grand_total'] = $grand_total;
        $pageout['total'] = $total;
        global $thispage;
        if (empty($thispage)) {
            $thispage = $pageout;
        }
        if ($pgonly) {
            return;
        }
    } else {
        $pgoffset = $offset;
    }
    $rs = safe_rows_start("*, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires, unix_timestamp(LastMod) as uLastMod" . $match, 'textpattern', $where . ' order by ' . doSlash($sort) . ' limit ' . intval($pgoffset) . ', ' . intval($limit));
    // get the form name
    if ($q and !$iscustom and !$issticky) {
        $fname = $searchform ? $searchform : 'search_results';
    } else {
        $fname = $listform ? $listform : $form;
    }
    if ($rs) {
        $count = 0;
        $last = numRows($rs);
        $articles = array();
        while ($a = nextRow($rs)) {
            ++$count;
            populateArticleData($a);
            global $thisarticle, $uPosted, $limit;
            $thisarticle['is_first'] = $count == 1;
            $thisarticle['is_last'] = $count == $last;
            if (@constant('txpinterface') === 'admin' and gps('Form')) {
                $articles[] = parse(gps('Form'));
            } elseif ($allowoverride and $a['override_form']) {
                $articles[] = parse_form($a['override_form']);
            } else {
                $articles[] = $thing ? parse($thing) : parse_form($fname);
            }
            // sending these to paging_link(); Required?
            $uPosted = $a['uPosted'];
            unset($GLOBALS['thisarticle']);
        }
        return doLabel($label, $labeltag) . doWrap($articles, $wraptag, $break, $class);
    }
}
Ejemplo n.º 7
0
function doArticles($atts, $iscustom)
{
    global $pretext, $prefs, $txpcfg;
    extract($pretext);
    extract($prefs);
    //getting attributes
    $theAtts = lAtts(array('form' => 'default', 'limit' => 10, 'pageby' => '', 'category' => '', 'section' => '', 'excerpted' => '', 'author' => '', 'sortby' => '', 'sortdir' => 'desc', 'month' => '', 'keywords' => '', 'frontpage' => '', 'id' => '', 'time' => 'past', 'status' => '4', 'pgonly' => 0, 'searchall' => 1, 'allowoverride' => !$q and !$iscustom, 'offset' => 0), $atts);
    // if an article ID is specified, treat it as a custom list
    $iscustom = !empty($theAtts['id']) ? true : $iscustom;
    //for the txp:article tag, some attributes are taken from globals;
    //override them before extract
    if (!$iscustom) {
        $theAtts['category'] = $c ? $c : '';
        $theAtts['section'] = $s && $s != 'default' ? $s : '';
        $theAtts['author'] = !empty($author) ? $author : '';
        $theAtts['month'] = !empty($month) ? $month : '';
        $theAtts['frontpage'] = $s && $s == 'default' ? true : false;
        $theAtts['excerpted'] = '';
    }
    extract($theAtts);
    $pageby = empty($pageby) ? $limit : $pageby;
    // treat sticky articles differently wrt search filtering, etc
    if (!is_numeric($status)) {
        $status = getStatusNum($status);
    }
    $issticky = $status == 5;
    //give control to search, if necesary
    if ($q && !$iscustom && !$issticky) {
        include_once txpath . '/publish/search.php';
        $s_filter = $searchall ? filterSearch() : '';
        $q = doSlash($q);
        $match = ", match (Title,Body) against ('{$q}') as score";
        $search = " and (Title rlike '{$q}' or Body rlike '{$q}') {$s_filter}";
        // searchall=0 can be used to show search results for the current section only
        if ($searchall) {
            $section = '';
        }
        if (!$sortby) {
            $sortby = 'score';
        }
    } else {
        $match = $search = '';
        if (!$sortby) {
            $sortby = 'Posted';
        }
    }
    //Building query parts
    $frontpage = ($frontpage and !$q) ? filterFrontPage() : '';
    $category = !$category ? '' : " and ((Category1='" . doslash($category) . "') or (Category2='" . doSlash($category) . "')) ";
    $section = !$section ? '' : " and Section = '" . doslash($section) . "'";
    $excerpted = $excerpted == 'y' ? " and Excerpt !=''" : '';
    $author = !$author ? '' : " and AuthorID = '" . doslash($author) . "'";
    $month = !$month ? '' : " and Posted like '" . doSlash($month) . "%'";
    $id = !$id ? '' : " and ID = '" . intval($id) . "'";
    switch ($time) {
        case 'any':
            $time = "";
            break;
        case 'future':
            $time = " and Posted > now()";
            break;
        default:
            $time = " and Posted < now()";
    }
    if (!is_numeric($status)) {
        $status = getStatusNum($status);
    }
    $custom = '';
    // trying custom fields here
    $customFields = getCustomFields();
    if ($customFields) {
        foreach ($customFields as $cField) {
            if (isset($atts[$cField])) {
                $customPairs[$cField] = $atts[$cField];
            }
        }
        if (!empty($customPairs)) {
            $custom = buildCustomSql($customFields, $customPairs);
        } else {
            $custom = '';
        }
    }
    //Allow keywords for no-custom articles. That tagging mode, you know
    if ($keywords) {
        $keys = split(',', $keywords);
        foreach ($keys as $key) {
            $keyparts[] = " Keywords like '%" . doSlash(trim($key)) . "%'";
        }
        $keywords = " and (" . join(' or ', $keyparts) . ")";
    }
    $where = "1" . ($id ? " and Status >= '4'" : " and Status='" . doSlash($status) . "'") . $time . $search . $id . $category . $section . $excerpted . $month . $author . $keywords . $custom . $frontpage;
    //do not paginate if we are on a custom list
    if (!$iscustom and !$issticky) {
        $total = safe_count('textpattern', $where) - $offset;
        $numPages = ceil($total / $pageby);
        $pg = !$pg ? 1 : $pg;
        $pgoffset = $offset + ($pg - 1) * $pageby . ', ';
        // send paging info to txp:newer and txp:older
        $pageout['pg'] = $pg;
        $pageout['numPages'] = $numPages;
        $pageout['s'] = $s;
        $pageout['c'] = $c;
        $pageout['total'] = $total;
        $GLOBALS['thispage'] = $pageout;
        if ($pgonly) {
            return;
        }
    } else {
        $pgoffset = $offset . ', ';
    }
    $rs = safe_rows_start("*, unix_timestamp(Posted) as uPosted" . $match, 'textpattern', $where . ' order by ' . doslash($sortby) . ' ' . doSlash($sortdir) . ' limit ' . doSlash($pgoffset . $limit));
    // alternative form override for search or list
    if ($q and !$iscustom and !$issticky) {
        $form = gAtt($atts, 'searchform', 'search_results');
    } else {
        $form = gAtt($atts, 'listform', $form);
    }
    // might be a form preview, otherwise grab it from the db
    $form = isset($_POST['Form']) ? gps('Form') : fetch_form($form);
    if ($rs) {
        $count = 0;
        $articles = array();
        while ($a = nextRow($rs)) {
            ++$count;
            populateArticleData($a);
            $GLOBALS['thisarticle']['is_first'] = $count == 1;
            $GLOBALS['thisarticle']['is_last'] = $count == numRows($rs);
            // define the article form
            $article = ($allowoverride and $a['override_form']) ? fetch_form($a['override_form']) : $form;
            $articles[] = parse($article);
            // sending these to paging_link(); Required?
            $GLOBALS['uPosted'] = $a['uPosted'];
            $GLOBALS['limit'] = $limit;
            unset($GLOBALS['thisarticle']);
            unset($GLOBALS['theseatts']);
            //Required?
        }
        return join('', $articles);
    }
}
Ejemplo n.º 8
0
function doArticles($atts, $iscustom)
{
    global $pretext, $prefs, $txpcfg, $DB;
    extract($pretext);
    extract($prefs);
    $customFields = getCustomFields();
    $customlAtts = array_null(array_flip($customFields));
    //getting attributes
    $theAtts = lAtts(array('form' => 'default', 'listform' => '', 'searchform' => '', 'limit' => 10, 'pageby' => '', 'category' => '', 'section' => '', 'excerpted' => 0, 'author' => '', 'sort' => '', 'month' => '', 'keywords' => '', 'frontpage' => '', 'id' => '', 'time' => 'past', 'status' => '4', 'pgonly' => 0, 'searchall' => 1, 'searchsticky' => 0, 'allowoverride' => !$q and !$iscustom, 'offset' => 0) + $customlAtts, $atts);
    // if an article ID is specified, treat it as a custom list
    $iscustom = !empty($theAtts['id']) ? true : $iscustom;
    //for the txp:article tag, some attributes are taken from globals;
    //override them before extract
    if (!$iscustom) {
        $theAtts['category'] = $c ? $c : '';
        $theAtts['section'] = $s && $s != 'default' ? $s : '';
        $theAtts['author'] = !empty($author) ? $author : '';
        $theAtts['month'] = !empty($month) ? $month : '';
        $theAtts['frontpage'] = $s && $s == 'default' ? true : false;
        $theAtts['excerpted'] = 0;
    }
    extract($theAtts);
    $pageby = empty($pageby) ? $limit : $pageby;
    // treat sticky articles differently wrt search filtering, etc
    if (!is_numeric($status)) {
        $status = getStatusNum($status);
    }
    $issticky = $status == 5;
    //give control to search, if necesary
    if ($q && !$iscustom && !$issticky) {
        include_once txpath . '/publish/search.php';
        $s_filter = $searchall ? filterSearch() : '';
        $match = ", " . $DB->match('Title,Body', doSlash($q));
        $words = preg_split('/\\s+/', $q);
        foreach ($words as $w) {
            $rlike[] = "(Title " . $DB->rlike() . " '" . doSlash(preg_quote($w)) . "' or Body " . $DB->rlike() . " '" . doSlash(preg_quote($w)) . "')";
        }
        $search = " and " . join(' and ', $rlike) . " {$s_filter}";
        // searchall=0 can be used to show search results for the current section only
        if ($searchall) {
            $section = '';
        }
        if (!$sort) {
            $sort = 'score desc';
        }
    } else {
        $match = $search = '';
        if (!$sort) {
            $sort = 'Posted desc';
        }
    }
    //Building query parts
    $frontpage = ($frontpage and (!$q or $issticky)) ? filterFrontPage() : '';
    $category = join("','", doSlash(do_list($category)));
    $category = !$category ? '' : " and (Category1 IN ('" . $category . "') or Category2 IN ('" . $category . "'))";
    $section = !$section ? '' : " and Section IN ('" . join("','", doSlash(do_list($section))) . "')";
    $excerpted = !$excerpted ? '' : " and Excerpt !=''";
    $author = !$author ? '' : " and AuthorID IN ('" . join("','", doSlash(do_list($author))) . "')";
    $month = !$month ? '' : " and Posted like '" . doSlash($month) . "%'";
    $id = !$id ? '' : " and ID = '" . intval($id) . "'";
    switch ($time) {
        case 'any':
            $time = "";
            break;
        case 'future':
            $time = " and Posted > now()";
            break;
        default:
            $time = " and Posted <= now()";
    }
    if (!$publish_expired_articles) {
        $time .= " and (now() <= Expires or Expires = " . NULLDATETIME . ")";
    }
    $custom = '';
    if ($customFields) {
        foreach ($customFields as $cField) {
            if (isset($atts[$cField])) {
                $customPairs[$cField] = $atts[$cField];
            }
        }
        if (!empty($customPairs)) {
            $custom = buildCustomSql($customFields, $customPairs);
        }
    }
    //Allow keywords for no-custom articles. That tagging mode, you know
    if ($keywords) {
        $keys = doSlash(do_list($keywords));
        foreach ($keys as $key) {
            $keyparts[] = "FIND_IN_SET('" . $key . "',Keywords)";
        }
        $keywords = " and (" . join(' or ', $keyparts) . ")";
    }
    if ($q and $searchsticky) {
        $statusq = ' and Status >= 4';
    } elseif ($id) {
        $statusq = ' and Status >= 4';
    } else {
        $statusq = ' and Status = ' . intval($status);
    }
    $where = "1=1" . $statusq . $time . $search . $id . $category . $section . $excerpted . $month . $author . $keywords . $custom . $frontpage;
    //do not paginate if we are on a custom list
    if (!$iscustom and !$issticky) {
        $grand_total = safe_count('textpattern', $where);
        $total = $grand_total - $offset;
        $numPages = ceil($total / $pageby);
        $pg = !$pg ? 1 : $pg;
        $pgoffset = $offset + ($pg - 1) * $pageby;
        // send paging info to txp:newer and txp:older
        $pageout['pg'] = $pg;
        $pageout['numPages'] = $numPages;
        $pageout['s'] = $s;
        $pageout['c'] = $c;
        $pageout['grand_total'] = $grand_total;
        $pageout['total'] = $total;
        global $thispage;
        if (empty($thispage)) {
            $thispage = $pageout;
        }
        if ($pgonly) {
            return;
        }
    } else {
        $pgoffset = $offset;
    }
    $rs = safe_rows_start("*, unix_timestamp(Posted) as uPosted, unix_timestamp(Expires) as uExpires" . $match, 'textpattern', $where . ' order by ' . doslash($sort) . ' ' . $DB->limit(intval($limit), intval($pgoffset)));
    // alternative form override for search or list
    if ($q and !$iscustom and !$issticky) {
        $fname = $searchform ? $searchform : 'search_results';
    } else {
        $fname = $listform ? $listform : $form;
    }
    if ($rs) {
        $count = 0;
        $articles = array();
        while ($a = nextRow($rs)) {
            ++$count;
            populateArticleData($a);
            global $thisarticle, $uPosted, $limit;
            $thisarticle['is_first'] = $count == 1;
            $thisarticle['is_last'] = $count == numRows($rs);
            if (@constant('txpinterface') === 'admin' and gps('Form')) {
                $articles[] = parse(gps('Form'));
            } elseif ($allowoverride and $a['override_form']) {
                $articles[] = parse_form($a['override_form']);
            } else {
                $articles[] = parse_form($fname);
            }
            // sending these to paging_link(); Required?
            $uPosted = $a['uPosted'];
            unset($GLOBALS['thisarticle']);
        }
        return join('', $articles);
    }
}
Ejemplo n.º 9
0
require "enum.php";
$db = new mysql_db(SERVER, USERNAME, PASSWORD, DATABASE);
// $_POST["keywords"] should be the search keyword
$key = "";
if (!isset($_POST["keywords"])) {
    $words = $_POST["key"];
    $key = $words;
    $type = $_POST["type"];
    $category = $_POST["category"];
    $time = $_POST["date"];
    if ($time == 1) {
        $start = (new \DateTime())->modify('-24 hours');
        $starttime = $start->format('Y-m-d H:i:s');
    } else {
        if ($time == 2) {
            $start = (new \DateTime())->modify('-30 days');
            $starttime = $start->format('Y-m-d H:i:s');
        } else {
            $starttime = "";
        }
    }
    $result = filterSearch($words, $type, $category, $starttime);
} else {
    $key = $_POST["keywords"];
    $result = search($_POST["keywords"]);
}
render("search_template.php", ["title" => "Search Result", "result" => $result, "key" => $key, "keywords" => getKeywords()]);
$db->sql_close();
?>