示例#1
0
function lAtts($pairs, $atts)
{
    foreach ($pairs as $name => $default) {
        $out[$name] = gAtt($atts, $name, $default);
    }
    return $out ? $out : false;
}
示例#2
0
function if_comments_disallowed($atts, $thing)
{
    global $thisarticle, $pretext;
    $id = gAtt($atts, 'id', gps('id'));
    if ($thisarticle['thisid']) {
        $id = $thisarticle['thisid'];
    }
    if (!$id && @$pretext['id']) {
        $id = $pretext['id'];
    }
    return !checkCommentsAllowed($id) ? parse($thing) : '';
}
示例#3
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);
    }
}
function sed_if_comments($atts, $thing)
{
    global $thisarticle, $pretext;
    $count = 0;
    if (!isset($thisarticle)) {
        $id = gAtt($atts, 'id', gps('id'));
        if (!$id && @$pretext['id']) {
            $id = $pretext['id'];
        }
        if (isset($id)) {
            $count = safe_field('comments_count', 'textpattern', "id={$id}");
        }
    } else {
        $count = $thisarticle['comments_count'];
    }
    return parse(EvalElse($thing, $count > 0));
}
示例#5
0
function lAtts($pairs, $atts, $warn = 1)
{
    global $production_status;
    foreach ($pairs as $name => $default) {
        $out[$name] = gAtt($atts, $name, $default);
    }
    if ($warn and ($production_status == 'debug' or $production_status == 'testing')) {
        foreach (array_diff(array_keys($atts), array_keys($pairs)) as $a) {
            trigger_error(gTxt('unknown_attribute', array('{att}' => $a)));
        }
    }
    return $out ? $out : false;
}
示例#6
0
function sed_copyright_date($atts)
{
    #	Outputs a blank string, a year or a year range according to
    # the $atts input. By default will output a year range where the
    # start year is the year of the first posted article in the TXP
    # article database table and the end year is either...
    # 1. The year from the lasmod date from the global variables
    # or
    # 2. The year that the last change to the article DB table was
    # committed
    #
    #	Of these, option 1 is faster but is not available to us if
    # the TXP installation has comments updating the lastmod date.
    global $thisarticle;
    global $prefs;
    global $is_article_list;
    global $sed_copyright_owner;
    $result = '';
    $sed_copyright_owner = '';
    extract(lAtts(array('debug' => '', 'custom' => '', 'start_year' => '', 'end_year' => '', 'date_type' => 'range', 'owner' => $prefs['sitename'], 'owner_href' => '', 'owner_title' => '', 'copy_text' => '&copy;', 'order' => 'cdo', 'wraptag' => '', 'class' => 'copyright', 'custom' => ''), $atts));
    $start_extra = '';
    # Holds extra debug strings from date access routines.
    $end_extra = '';
    # Holds extra debug strings from date access routines.
    if (!empty($debug)) {
        echo "<br/>=== Copyright Date: Start Attributes ===<br/>\n";
        print_r($atts);
        echo "<br/>=== Copyright Date:  End  Attributes ===<br/>\n";
        print_r("First post query:[" . SED_FIRST_POST_QUERY . "], Last mod query:[" . SED_LAST_MOD_QUERY . "]");
        echo "<br/>=== Copyright Date:  End  Attributes ===<br/>\n";
    }
    #	Call the date access routines. These will access the cached date variables if needed and also give extra information
    # for debug in the $_extra strings.
    if (empty($custom) or true == $is_article_list) {
        $start = _get_start_year($start_year, $start_extra);
        $end = _get_end_year($end_year, $end_extra);
    } else {
        #	This section deals with article copyright processing. It looks in the named custom field for a section called 'copyright' and pulls
        # any needed details from it. Defaults to the posted date and article author but that can be overidden.
        #	copyright(attrib1='val1';attrib2='val2')
        #	Valid attributes are...
        #		owner 	(if not supplied defaults to the article author.)
        #		owner_href and owner_title.
        #		start	(if missing defaults to the year the article was posted)
        #		end		(if missing defaults to the start year)
        #
        $packed_string = @$thisarticle[$custom];
        $vars = sed_lib_extract_packed_variable_section('copyright', $packed_string);
        $title = gAtt($vars, 'owner_title');
        $href = gAtt($vars, 'owner_href');
        $sed_copyright_owner = gAtt($vars, 'owner', get_author_name($thisarticle['authorid']));
        if ($sed_copyright_owner and isset($href) and isset($title)) {
            $sed_copyright_owner = _sed_build_href($sed_copyright_owner, $href, $title);
        }
        $start = gAtt($vars, 'start', date('Y', $thisarticle['posted']));
        $end = gAtt($vars, 'start', $start);
        $start_extra = '(start from custom field)';
        $end_extra = '(end from custom field)';
    }
    #	Only ouput the extra debug info if needed.
    if (empty($debug)) {
        $start_extra = '';
        $end_extra = '';
    }
    #	If a range has been requested and the start year is the same as the end year then compress the format...
    if ($date_type == 'range' and $start === $end and $start_extra === $end_extra) {
        $date_type = 'end';
    }
    #	Do any other compressions as needed...
    if (empty($start) && empty($end)) {
        $date_type = 'none';
    }
    if (empty($start) && !empty($end)) {
        $date_type = 'end';
    }
    if (!empty($start) && empty($end)) {
        $date_type = 'start';
    }
    #	Format the resulting date string...
    switch ($date_type) {
        case 'range':
            $result = $start_extra . $start . '-' . $end_extra . $end;
            break;
        case 'start':
            $result = $start_extra . $start;
            break;
        case 'end':
            $result = $end_extra . $end;
            break;
        case 'none':
            $result = '';
    }
    return $result;
}