示例#1
0
/**
 * Find an adjacent article relative to a provided threshold level
 *
 * @param scalar $threshold The value to compare against
 * @param string $s string Optional section restriction
 * @param string $type string Find lesser or greater neighbour? Possible values: '<' (previous, default) or '>' (next)
 * @param array $atts Attribute of article at threshold
 * @param string $threshold_type 'cooked': Use $threshold as SQL clause; 'raw': Use $threshold as an escapable scalar
 * @return array|string An array populated with article data, or the empty string in case of no matches
 */
function getNeighbour($threshold, $s, $type, $atts = array(), $threshold_type = 'raw')
{
    global $prefs;
    static $cache = array();
    $key = md5($threshold . $s . $type . join(n, $atts));
    if (isset($cache[$key])) {
        return $cache[$key];
    }
    extract($atts);
    $expired = $expired && $prefs['publish_expired_articles'];
    $customFields = getCustomFields();
    //Building query parts
    // lifted from publish.php. This is somewhat embarrassing, isn't it?
    $ids = array_map('intval', do_list($id));
    $id = !$id ? '' : " and ID IN (" . join(',', $ids) . ")";
    switch ($time) {
        case 'any':
            $time = "";
            break;
        case 'future':
            $time = " and Posted > now()";
            break;
        default:
            $time = " and Posted <= now()";
    }
    if (!$expired) {
        $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);
        }
    }
    if ($keywords) {
        $keys = doSlash(do_list($keywords));
        foreach ($keys as $key) {
            $keyparts[] = "FIND_IN_SET('" . $key . "',Keywords)";
        }
        $keywords = " and (" . join(' or ', $keyparts) . ")";
    }
    // invert $type for ascending sortdir
    $types = array('>' => array('desc' => '>', 'asc' => '<'), '<' => array('desc' => '<', 'asc' => '>'));
    $type = $type == '>' ? $types['>'][$sortdir] : $types['<'][$sortdir];
    // escape threshold and treat it as a string unless explicitly told otherwise
    if ($threshold_type != 'cooked') {
        $threshold = "'" . doSlash($threshold) . "'";
    }
    $safe_name = safe_pfx('textpattern');
    $q = array("select ID, Title, url_title, unix_timestamp(Posted) as uposted\n\t\t\tfrom " . $safe_name . " where {$sortby} {$type} " . $threshold, $s != '' && $s != 'default' ? "and Section = '" . doSlash($s) . "'" : filterFrontPage(), $id, $time, $custom, $keywords, 'and Status=4', 'order by ' . $sortby, $type == '<' ? 'desc' : 'asc', 'limit 1');
    $cache[$key] = getRow(join(n . ' ', $q));
    return is_array($cache[$key]) ? $cache[$key] : '';
}
示例#2
0
function getNeighbour($Posted, $s, $type)
{
    global $prefs;
    extract($prefs);
    $expired = $publish_expired_articles ? '' : ' and (now() <= Expires or Expires = ' . NULLDATETIME . ')';
    $type = $type == '>' ? '>' : '<';
    $safe_name = safe_pfx('textpattern');
    $q = array("select ID, Title, url_title, unix_timestamp(Posted) as uposted\n\t\t\tfrom " . $safe_name . " where Posted {$type} '" . doSlash($Posted) . "'", $s != '' && $s != 'default' ? "and Section = '" . doSlash($s) . "'" : filterFrontPage(), 'and Status=4 and Posted < now()' . $expired . ' order by Posted', $type == '<' ? 'desc' : 'asc', 'limit 1');
    $out = getRow(join(' ', $q));
    return is_array($out) ? $out : '';
}
示例#3
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);
    }
}
示例#4
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' => '', 'expired' => $publish_expired_articles, '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 = 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($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($category)));
    $category = !$category ? '' : " and (Category1 IN ('" . $category . "') or Category2 IN ('" . $category . "'))";
    $section = !$section ? '' : " and Section IN ('" . join("','", doSlash(do_list($section))) . "')";
    $excerpted = $excerpted == 'y' || $excerpted == '1' ? " and Excerpt !=''" : '';
    $author = !$author ? '' : " and AuthorID IN ('" . join("','", doSlash(do_list($author))) . "')";
    $month = !$month ? '' : " and Posted like '" . doSlash($month) . "%'";
    $ids = array_map('intval', do_list($id));
    $id = !$id ? '' : " and ID IN (" . join(',', $ids) . ")";
    switch ($time) {
        case 'any':
            $time = "";
            break;
        case 'future':
            $time = " and Posted > now()";
            break;
        default:
            $time = " and Posted <= now()";
    }
    if (!$expired) {
        $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['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 = $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;
            filterAtts($theAtts);
            // 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);
    }
}
/**
 * Find an adjacent article relative to a provided threshold level.
 *
 * @param  scalar $threshold      The value to compare against
 * @param  string $s              Optional section restriction
 * @param  string $type           Lesser or greater neighbour? Either '<' (previous) or '>' (next)
 * @param  array  $atts           Attribute of article at threshold
 * @param  string $threshold_type 'cooked': Use $threshold as SQL clause; 'raw': Use $threshold as an escapable scalar
 * @return array|bool An array populated with article data, or 'false' in case of no matches
 */
function getNeighbour($threshold, $s, $type, $atts = array(), $threshold_type = 'raw')
{
    global $prefs;
    static $cache = array();
    $key = md5($threshold . $s . $type . join(n, $atts));
    if (isset($cache[$key])) {
        return $cache[$key];
    }
    extract($atts);
    $expired = $expired && $prefs['publish_expired_articles'];
    $customFields = getCustomFields();
    // Building query parts; lifted from publish.php.
    $ids = array_map('intval', do_list($id));
    $id = !$id ? '' : " AND ID IN (" . join(',', $ids) . ")";
    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);
        }
    }
    if ($keywords) {
        $keys = doSlash(do_list($keywords));
        foreach ($keys as $key) {
            $keyparts[] = "FIND_IN_SET('" . $key . "', Keywords)";
        }
        $keywords = " AND (" . join(" OR ", $keyparts) . ")";
    }
    $sortdir = strtolower($sortdir);
    // Invert $type for ascending sortdir.
    $types = array('>' => array('desc' => '>', 'asc' => '<'), '<' => array('desc' => '<', 'asc' => '>'));
    $type = $type == '>' ? $types['>'][$sortdir] : $types['<'][$sortdir];
    // Escape threshold and treat it as a string unless explicitly told otherwise.
    if ($threshold_type != 'cooked') {
        $threshold = "'" . doSlash($threshold) . "'";
    }
    $safe_name = safe_pfx('textpattern');
    $q = array("SELECT ID AS thisid, Section AS section, Title AS title, url_title, UNIX_TIMESTAMP(Posted) AS posted\n            FROM {$safe_name} WHERE {$sortby} {$type} {$threshold}", $s != '' && $s != 'default' ? "AND Section = '" . doSlash($s) . "'" : filterFrontPage(), $id, $time, $custom, $keywords, "AND Status = 4", "ORDER BY {$sortby}", $type == '<' ? "DESC" : "ASC", "LIMIT 1");
    $cache[$key] = getRow(join(n . ' ', $q));
    return is_array($cache[$key]) ? $cache[$key] : false;
}
示例#6
0
function getNeighbour($Posted, $s, $type)
{
    $type = $type == '>' ? '>' : '<';
    $safe_name = safe_pfx('textpattern');
    $q = array("select ID, Title, url_title, unix_timestamp(Posted) as uposted\n\t\t\tfrom " . $safe_name . " where Posted {$type} '" . doSlash($Posted) . "'", $s != '' && $s != 'default' ? "and Section = '" . doSlash($s) . "'" : filterFrontPage(), 'and Status=4 and Posted < now() order by Posted', $type == '<' ? 'desc' : 'asc', 'limit 1');
    $out = getRow(join(' ', $q));
    return is_array($out) ? $out : '';
}
示例#7
0
function getNextPrev($id, $Posted, $s)
{
    static $next, $cache;
    // If next/prev tags are placed before an article tag on a list page, we
    // have to guess what the current article is
    if (!$id) {
        $current = safe_row('ID, Posted', 'textpattern', '1=1 ' . ($s != '' && $s != 'default' ? "Section = '" . doSlash($s) . "'" : filterFrontPage()) . 'and Status=4 and Posted < now() order by Posted desc limit 1');
        if ($current) {
            $id = $current['ID'];
            $Posted = $current['Posted'];
        }
    }
    if (@isset($cache[$next[$id]])) {
        $thenext = $cache[$next[$id]];
    } else {
        $thenext = getNeighbour($Posted, $s, '>');
    }
    $out['next_id'] = $thenext ? $thenext['ID'] : '';
    $out['next_title'] = $thenext ? $thenext['Title'] : '';
    $out['next_utitle'] = $thenext ? $thenext['url_title'] : '';
    $out['next_posted'] = $thenext ? $thenext['uposted'] : '';
    $theprev = getNeighbour($Posted, $s, '<');
    $out['prev_id'] = $theprev ? $theprev['ID'] : '';
    $out['prev_title'] = $theprev ? $theprev['Title'] : '';
    $out['prev_utitle'] = $theprev ? $theprev['url_title'] : '';
    $out['prev_posted'] = $theprev ? $theprev['uposted'] : '';
    if ($theprev) {
        $cache[$theprev['ID']] = $theprev;
        $next[$theprev['ID']] = $id;
    }
    return $out;
}
示例#8
0
function doHomeArticles($atts, $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, 'category' => '', 'section' => '', 'excerpted' => '', 'author' => '', 'sort' => '', 'month' => '', 'keywords' => '', 'frontpage' => '', 'time' => 'past', 'pgonly' => 0, 'searchall' => 1, 'allowoverride' => true, 'offset' => 0, 'wraptag' => '', 'break' => '', 'label' => '', 'labeltag' => '', 'class' => '') + $customlAtts, $atts);
    $theAtts['category'] = $c ? $c : '';
    $theAtts['section'] = $s && $s != 'default' && $s != 'home' ? $s : '';
    $theAtts['author'] = !empty($author) ? $author : '';
    $theAtts['month'] = !empty($month) ? $month : '';
    $theAtts['frontpage'] = $s && $s == 'home' ? 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;
    $match = $search = '';
    if (!$sort) {
        $sort = 'Posted desc';
    }
    //Building query parts
    $frontpage = 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);
        }
    }
    $statusq = ' and Status = 5';
    $where = "1=1" . $statusq . $time . $search . $category . $section . $excerpted . $month . $author . $keywords . $custom . $frontpage;
    $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 0' . intval($limit));
    // get the form name
    $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);
    }
}
示例#9
0
function getNeighbour($Posted, $s, $type)
{
    $q = array("select ID, Title, url_title, unix_timestamp(Posted) as uposted\n\t\t\tfrom " . PFX . "textpattern where Posted {$type} '{$Posted}'", $s != '' && $s != 'default' ? "and Section = '{$s}'" : filterFrontPage(), 'and Status=4 and Posted < now() order by Posted', $type == '<' ? 'desc' : 'asc', 'limit 1');
    $out = getRow(join(' ', $q));
    return is_array($out) ? $out : '';
}
示例#10
0
function article_custom($atts)
{
    global $pretext, $prefs;
    extract($prefs);
    extract($pretext);
    if (is_array($atts)) {
        extract($atts);
    }
    $GLOBALS['is_article_list'] = true;
    $form = empty($form) ? 'default' : $form;
    $form = empty($listform) ? $form : $listform;
    $limit = empty($limit) ? '10' : $limit;
    $category = empty($category) ? '' : doSlash($category);
    $section = empty($section) ? '' : doSlash($section);
    $excerpted = empty($excerpted) ? '' : $excerpted;
    $author = empty($author) ? '' : doSlash($author);
    $sortby = empty($sortby) ? 'Posted' : $sortby;
    $sortdir = empty($sortdir) ? 'desc' : $sortdir;
    $month = empty($month) ? '' : $month;
    $keywords = empty($keywords) ? '' : doSlash($keywords);
    $frontpage = empty($frontpage) ? '' : filterFrontPage();
    $category = !$category ? '' : " and ((Category1='" . $category . "') or (Category2='" . $category . "')) ";
    $section = !$section ? '' : " and Section = '{$section}'";
    $excerpted = $excerpted == 'y' ? " and Excerpt !=''" : '';
    $author = !$author ? '' : " and AuthorID = '{$author}'";
    $month = !$month ? '' : " and Posted like '{$month}%'";
    if ($keywords) {
        $keys = split(',', $keywords);
        foreach ($keys as $key) {
            $keyparts[] = " Keywords like '%" . trim($key) . "%'";
        }
        $keywords = " and (" . join(' or ', $keyparts) . ")";
    }
    $Form = fetch('Form', 'txp_form', 'name', $form);
    $rs = safe_rows("*, unix_timestamp(Posted) as uPosted", "textpattern", "1 and Status=4 and Posted < now() " . $category . $section . $excerpted . $month . $author . $keywords . $frontpage . ' order by ' . $sortby . ' ' . $sortdir . ' limit ' . $limit);
    if ($rs) {
        foreach ($rs as $a) {
            extract($a);
            $com_count = safe_field('count(*)', 'txp_discuss', "parentid='{$ID}'");
            $author = fetch('RealName', 'txp_users', "name", $AuthorID);
            $author = !$author ? $AuthorID : $author;
            $out['thisid'] = $ID;
            $out['posted'] = $uPosted;
            $out['if_comments'] = ($Annotate or $com_count) ? true : false;
            $out['comments_invite'] = ($Annotate or $com_count) ? formatCommentsInvite($AnnotateInvite, $Section, $ID) : '';
            $out['comments_count'] = $com_count;
            $out['author'] = $author;
            $out['permlink'] = formatPermLink($ID, $Section);
            $out['body'] = parse($Body_html);
            $out['excerpt'] = $Excerpt;
            $out['title'] = $Title;
            $out['url_title'] = $url_title;
            $out['category1'] = $Category1;
            $out['category2'] = $Category2;
            $out['section'] = $Section;
            $out['keywords'] = $Keywords;
            $out['article_image'] = $Image;
            $GLOBALS['thisarticle'] = $out;
            $article = $Form;
            // quick check for things not pulled from the db
            $article = doPermlink($article, $out['permlink'], $Title, $url_title);
            $articles[] = parse($article);
            // sending these to paging_link();
            $GLOBALS['uPosted'] = $uPosted;
            $GLOBALS['limit'] = $limit;
            unset($GLOBALS['thisarticle']);
        }
        return join('', $articles);
    }
}