Example #1
0
/**
 * Pipe an article's neighbor into a form.
 * 
 * @param array $atts
 * @param string $atts['form']
 * @param string $atts['type'] Valid: "prev" or "next"
 */
function jmd_neighbor($atts)
{
    global $thisarticle, $next_id, $prev_id, $jmd_neighbor;
    extract(lAtts(array('form' => '', 'type' => ''), $atts));
    assert_article();
    if ($type == ('next' || 'prev')) {
        if ($type == 'next' && $next_id) {
            $id = $next_id;
        }
        if ($type == 'prev' && $prev_id) {
            $id = $prev_id;
        }
        if (isset($id)) {
            $jmd_neighbor = new JMD_Neighbor();
            return $jmd_neighbor->article($id, $form, $type);
        }
    } else {
        trigger_error('No type was set');
    }
}
Example #2
0
/**
 * Find next and previous articles relative to a provided threshold level
 *
 * @param int $id The "pivot" article's id; use zero (0) to indicate $thisarticle
 * @param scalar $threshold The value to compare against if $id != 0
 * @param string $s string Optional section restriction if $id != 0
 * @return array An array populated with article data from the next and previous article
 */
function getNextPrev($id = 0, $threshold = null, $s = '')
{
    if ($id !== 0) {
        // Pivot is specific article by ID: In lack of further information, revert to default sort order 'Posted desc'
        $atts = filterAtts(array('sortby' => 'Posted', 'sortdir' => 'desc'));
    } else {
        // Pivot is $thisarticle: Use article attributes to find its neighbours
        assert_article();
        global $thisarticle;
        if (!is_array($thisarticle)) {
            return array();
        }
        $atts = filterAtts();
        $m = preg_split('/\\s+/', $atts['sort']);
        if (empty($m[0]) || count($m) > 2 || preg_match('/[),]/', $m[0])) {
            // Either no explicit sort order or a complex clause, e.g. 'foo asc, bar desc' or 'FUNC(foo,bar) asc'
            // Fall back to chronologically descending order
            $atts['sortby'] = 'Posted';
            $atts['sortdir'] = 'desc';
        } else {
            // sort is like 'foo asc'
            $atts['sortby'] = $m[0];
            $atts['sortdir'] = isset($m[1]) && strtolower($m[1]) == 'desc' ? 'desc' : 'asc';
        }
        // atts w/ special treatment
        switch ($atts['sortby']) {
            case 'Posted':
                $threshold = 'from_unixtime(' . doSlash($thisarticle['posted']) . ')';
                $threshold_type = 'cooked';
                break;
            case 'Expires':
                $threshold = 'from_unixtime(' . doSlash($thisarticle['expires']) . ')';
                $threshold_type = 'cooked';
                break;
            case 'LastMod':
                $threshold = 'from_unixtime(' . doSlash($thisarticle['modified']) . ')';
                $threshold_type = 'cooked';
                break;
            default:
                // retrieve current threshold value per sort column from $thisarticle
                $acm = array_flip(article_column_map());
                $key = $acm[$atts['sortby']];
                $threshold = $thisarticle[$key];
                $threshold_type = 'raw';
                break;
        }
        $s = $thisarticle['section'];
    }
    $thenext = getNeighbour($threshold, $s, '>', $atts, $threshold_type);
    $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($threshold, $s, '<', $atts, $threshold_type);
    $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'] : '';
    return $out;
}
/**
 * Find next and previous articles relative to a provided threshold level.
 *
 * @param  int    $id        The "pivot" article's id; use zero (0) to indicate $thisarticle
 * @param  scalar $threshold The value to compare against if $id != 0
 * @param  string $s         Optional section restriction if $id != 0
 * @return array An array populated with article data
 */
function getNextPrev($id = 0, $threshold = null, $s = '')
{
    if ($id !== 0) {
        // Pivot is specific article by ID: In lack of further information,
        // revert to default sort order 'Posted desc'.
        $atts = filterAtts(array('sortby' => "Posted", 'sortdir' => "DESC"));
    } else {
        // Pivot is $thisarticle: Use article attributes to find its neighbours.
        assert_article();
        global $thisarticle;
        if (!is_array($thisarticle)) {
            return array();
        }
        $atts = filterAtts();
        $m = preg_split('/\\s+/', $atts['sort']);
        // If in doubt, fall back to chronologically descending order.
        if (empty($m[0]) || count($m) > 2 || !preg_match('/^(?:[0-9a-zA-Z$_\\x{0080}-\\x{FFFF}]+|`[\\x{0001}-\\x{FFFF}]+`)$/u', $m[0])) {
            $atts['sortby'] = "Posted";
            $atts['sortdir'] = "DESC";
        } else {
            // Sort is like 'foo asc'.
            $atts['sortby'] = $m[0];
            $atts['sortdir'] = isset($m[1]) && strtolower($m[1]) == 'desc' ? "DESC" : "ASC";
        }
        // Attributes with special treatment.
        switch ($atts['sortby']) {
            case 'Posted':
                $threshold = "FROM_UNIXTIME(" . doSlash($thisarticle['posted']) . ")";
                $threshold_type = 'cooked';
                break;
            case 'Expires':
                $threshold = "FROM_UNIXTIME(" . doSlash($thisarticle['expires']) . ")";
                $threshold_type = 'cooked';
                break;
            case 'LastMod':
                $threshold = "FROM_UNIXTIME(" . doSlash($thisarticle['modified']) . ")";
                $threshold_type = 'cooked';
                break;
            default:
                // Retrieve current threshold value per sort column from $thisarticle.
                $acm = array_flip(article_column_map());
                $key = $acm[$atts['sortby']];
                $threshold = $thisarticle[$key];
                $threshold_type = 'raw';
                break;
        }
        $s = $thisarticle['section'];
    }
    $out['next'] = getNeighbour($threshold, $s, '>', $atts, $threshold_type);
    $out['prev'] = getNeighbour($threshold, $s, '<', $atts, $threshold_type);
    return $out;
}
Example #4
0
/**
 * Fetch meta description from the given (or automatic) context.
 *
 * Category context may be refined by specifying the content type as well
 * after a dot. e.g. category.image to check image context category.
 *
 * @param string $type Flavour of meta content to fetch (section, category, article)
 */
function getMetaDescription($type = null)
{
    global $thisarticle, $thiscategory, $thissection, $c, $s, $context;
    $content = '';
    if ($type === null) {
        if ($thiscategory) {
            $content = $thiscategory['description'];
        } elseif ($thissection) {
            $content = $thissection['description'];
        } elseif ($thisarticle) {
            $content = $thisarticle['description'];
        } elseif ($c) {
            $content = safe_field('description', 'txp_category', "name = '" . doSlash($c) . "' AND type = '" . doSlash($context) . "'");
        } elseif ($s) {
            $content = safe_field('description', 'txp_section', "name = '" . doSlash($s) . "'");
        }
    } else {
        if (strpos($type, 'category') === 0) {
            // Category context.
            if ($thiscategory) {
                $content = $thiscategory['description'];
            } else {
                $thisContext = $context;
                $catParts = do_list($type, '.');
                if (isset($catParts[1])) {
                    $thisContext = $catParts[1];
                }
                $clause = " AND type = '" . $thisContext . "'";
                $content = safe_field('description', 'txp_category', "name = '" . doSlash($c) . "'" . $clause);
            }
        } elseif ($type === 'section') {
            $theSection = $thissection ? $thissection : $s;
            $content = safe_field('description', 'txp_section', "name = '" . doSlash($theSection) . "'");
        } elseif ($type === 'article') {
            assert_article();
            $content = $thisarticle ? $thisarticle['description'] : '';
        }
    }
    return $content;
}
Example #5
0
function yab_shop_custom_field($atts)
{
    global $thisarticle, $prefs;
    assert_article();
    extract(lAtts(array('name' => @$prefs['custom_1_set'], 'default' => ''), $atts));
    $currency = yab_shop_config('currency');
    $name = strtolower($name);
    $custom_field_price_name = strtolower(yab_shop_config('custom_field_price_name'));
    if (!empty($thisarticle[$name])) {
        if ($name == $custom_field_price_name) {
            $out = $thisarticle[$name];
            $out = yab_shop_replace_commas($out);
            $out = yab_shop_currency_out($currency, 'cur') . yab_shop_currency_out($currency, 'toform', $out);
        } else {
            $out = $thisarticle[$name];
            $out = explode(';', $out);
            $out = str_replace('--', ': ' . yab_shop_currency_out($currency, 'cur'), $out);
            $out = yab_shop_type_select_custom($out, $name);
        }
    } else {
        $out = $default;
    }
    return $out;
}
Example #6
0
function if_last_article($atts, $thing)
{
    global $thisarticle;
    assert_article();
    return parse(EvalElse($thing, !empty($thisarticle['is_last'])));
}
function sed_comments($atts)
{
    global $thisarticle, $prefs, $comment_preview, $pretext;
    extract($prefs);
    extract(lAtts(array('id' => @$pretext['id'], 'form' => 'comments', 'wraptag' => $comments_are_ol ? 'ol' : '', 'break' => $comments_are_ol ? 'li' : 'div', 'class' => __FUNCTION__, 'breakclass' => '', 'sort' => 'posted ASC'), $atts));
    assert_article();
    if (is_array($thisarticle)) {
        extract($thisarticle);
    }
    if (@$thisid) {
        $id = $thisid;
    }
    #
    #	Extract the sed article overrides...
    #	Access the custom field that houses the vars and explode the string on ';' boundaries.
    #
    $sed_vars = _sed_cp_get_sed_vars(@$thisarticle['sed per-article vars']);
    $sed_vars = lAtts(array('sed_delay' => '0', 'sed_ttl' => '', 'sed_on_cull' => 'hide', 'sed_ttl_grace' => ''), $sed_vars);
    extract($sed_vars);
    if (!empty($comment_preview)) {
        $preview = psas(array('name', 'email', 'web', 'message', 'parentid', 'remember'));
        $preview['time'] = time();
        $preview['discussid'] = 0;
        $preview['message'] = markup_comment($preview['message']);
        $GLOBALS['thiscomment'] = $preview;
        $comments[] = parse_form($form) . n;
        unset($GLOBALS['thiscomment']);
        $out = doWrap($comments, $wraptag, $break, $class, $breakclass);
    } else {
        $rs = safe_rows_start("*, unix_timestamp(posted) as time", "txp_discuss", 'parentid=' . intval($id) . ' and visible=' . VISIBLE . ' order by ' . doSlash($sort));
        $out = '';
        if ($rs) {
            $comments = array();
            $culled_comments = array();
            while ($vars = nextRow($rs)) {
                $culled = false;
                $show = true;
                $extra = '';
                $now = time();
                $remaining = '';
                #
                #	If the comment is in a deleting page then check if it is to be culled...
                #
                if (!empty($sed_ttl)) {
                    $do_cull_check = true;
                    #
                    #	Are we in any grace period???
                    #
                    if (!empty($sed_ttl_grace) && 0 != $sed_ttl_grace) {
                        $do_cull_check = _sed_cp_if_outside_period($thisarticle['posted'], $sed_ttl_grace, $vars['time'], $remaining);
                    }
                    #
                    #	If not then do the cull checking...
                    #
                    if ($do_cull_check) {
                        $culled = _sed_cp_if_outside_period($vars['time'], $sed_ttl, $now, $remaining);
                    }
                    #
                    #	Display how long to go before culling.
                    #
                    if ($do_cull_check && !$culled) {
                        $vars['message'] .= "<br/><br/><strong>[MARKED FOR DELETION IN {$remaining}.]</strong>";
                    }
                }
                if ($culled) {
                    $extra .= ' culled';
                    $culled_comments[] = $vars;
                    $vars['time'] = $now;
                    $vars['message'] .= "<br/><br/><strong>[DELETED.]</strong>";
                } else {
                    #
                    #	See if the comment is in its "hidden" period.
                    #	This is to try and discourage spam-robots that immediately see if their posts appear live.
                    #
                    if (!empty($sed_delay) && $sed_delay > '0') {
                        $show = _sed_cp_if_outside_period($vars['time'], $sed_delay, $now, $remaining);
                    }
                    #
                    #	Still hidden so show a place-holder comment instead.
                    #
                    if (!$show) {
                        $extra .= ' delay_queue';
                        $vars['name'] = "[DELAYED]";
                        $vars['time'] = $now;
                        $vars['message'] = "A comment has been recorded and is in the delay queue.";
                        $vars['message'] .= "<br/><br/><strong>[REVEALED IN {$remaining}.]</strong>";
                    }
                }
                #
                #	Save the additional css class markup for this comment in the vars before parsing the comment form.
                #
                $vars['sed_class_extra'] = $extra;
                $GLOBALS['thiscomment'] = $vars;
                $comments[] = parse_form($form) . n;
                unset($GLOBALS['thiscomment']);
            }
            $out .= doWrap($comments, $wraptag, $break, $class, $breakclass);
            #
            #	Process the culled list...
            #
            if (!empty($culled_comments)) {
                foreach ($culled_comments as $comment) {
                    if ('delete' == $sed_on_cull) {
                        _sed_cp_delete_comment($comment);
                    } else {
                        _sed_cp_update_comment($comment, $sed_on_cull);
                    }
                }
                update_comments_count($id);
            }
        }
    }
    return $out;
}
Example #8
0
function sed_pcf_for_each_value($atts, $thing)
{
    global $thisarticle;
    assert_article();
    $def_custom_name = 'custom1';
    extract($merged = lAtts(array('debug' => 0, 'name' => $def_custom_name, 'id' => '', 'form' => '', 'label' => '', 'labeltag' => '', 'wraptag' => 'ul', 'break' => 'li', 'class' => ''), $atts));
    if ($debug) {
        echo dmp($merged);
    }
    $field = @$thisarticle[$name];
    if (empty($field)) {
        if ($debug) {
            echo "Returning early - nothing to do in CF[{$name}].";
        }
        return '';
    }
    if (empty($class)) {
        $class = $name;
    }
    if (!empty($form)) {
        # grab the form (if any)
        $thing = fetch_form($form);
    }
    if (empty($thing)) {
        # if no form, and no enclosed thing, use built-in formula...
        $thing = '{value}';
    }
    $out = array();
    $field = do_list($field);
    foreach ($field as $value) {
        $out[] = parse(str_replace('{value}', $value, $thing));
    }
    return doLabel($label, $labeltag) . doWrap($out, $wraptag, $break, $class, '', '', '', $id);
}
function peg_comments($atts)
{
    global $thisarticle, $thiscomment, $prefs;
    extract(lAtts(array('form' => 'comments', 'wraptag' => $prefs['comments_are_ol'] ? 'ol' : '', 'break' => $prefs['comments_are_ol'] ? 'li' : 'div', 'class' => 'comments', 'breakclass' => '', 'limit' => 0, 'offset' => 0, 'sort' => 'posted ASC'), $atts));
    assert_article();
    // extract($thisarticle);
    if (!$thisarticle['comments_count']) {
        return '';
    }
    $thisid = intval($thisarticle['thisid']);
    // $txp_discuss = safe_pfx('txp_discuss');
    // $peg_discuss = safe_pfx('peg_discuss');
    if (!empty($thiscomment)) {
        $peg_children = $thiscomment['peg_children'];
    } else {
        // safe_query("CREATE TEMPORARY TABLE $peg_discuss (SELECT * FROM $txp_discuss WHERE parentid=$thisid AND visible=".VISIBLE.")");
        $rs = safe_rows('discussid, peg_children', 'txp_discuss', "parentid={$thisid} AND visible=" . VISIBLE);
        $peg_children = $rows = array();
        foreach ($rs as $vars) {
            $rows[] = $vars['discussid'];
            if ($vars['peg_children']) {
                $peg_children = array_merge($peg_children, explode(',', $vars['peg_children']));
            }
        }
        $peg_children = implode(',', $peg_children ? array_diff($rows, $peg_children) : $rows);
    }
    if (empty($peg_children)) {
        return '';
    }
    $qparts = "discussid IN({$peg_children}) AND parentid={$thisid} AND visible=" . VISIBLE . ($sort ? " ORDER BY {$sort}" : '') . ($limit || $offset ? ' LIMIT ' . intval($offset) . ', ' . intval($limit) : '');
    $rs = safe_rows('*, unix_timestamp(posted) as time', 'txp_discuss', $qparts);
    $out = '';
    if ($rs) {
        foreach ($rs as $vars) {
            $GLOBALS['thiscomment'] = $vars;
            $comments[] = peg_parse_form_recursively($form) . n;
            unset($GLOBALS['thiscomment']);
        }
        $out .= doWrap($comments, $wraptag, $break, $class, $breakclass);
    }
    return $out;
}
Example #10
0
function zem_article_event($atts, $thing = NULL)
{
    global $thisarticle, $zem_thiseventcal;
    extract(lAtts(array('wraptag' => '', 'break' => '', 'class' => __FUNCTION__, 'breakclass' => '', 'label' => '', 'labeltag' => '', 'form' => 'zem_event_display', 'limit' => ''), $atts));
    assert_article();
    if ($thing === NULL) {
        $thing = fetch_form($form);
    }
    $where = "article_id='" . doSlash($thisarticle['thisid']) . "' and " . safe_pfx('zem_event_calendar') . ".id=" . safe_pfx('zem_event_date') . ".event_id";
    $lim = '';
    if (intval($limit)) {
        $lim = ' limit ' . intval($limit);
    }
    $rs = safe_rows_start('*', 'zem_event_calendar,zem_event_date', $where . $lim);
    $out = array();
    while ($row = nextRow($rs)) {
        $zem_thiseventcal = $row;
        $out[] = parse($thing);
        $zem_thiseventcal = NULL;
    }
    if ($out) {
        return doTag($label, $labeltag, $class) . doWrap($out, $wraptag, $break, $class, $breakclass);
    }
}