/** * list past dates attached to some anchor * * @param string the anchor (e.g., 'section:123') * @param int the offset from the start of the list; usually, 0 or 1 * @param int the number of items to display * @param string the list variant, if any * @return NULL on error, else an ordered array with $url => ($prefix, $label, $suffix, $type, $icon, $date) */ public static function &list_past_for_anchor($anchor, $offset = 0, $count = 100, $variant = 'family') { global $context; // restrict the query to addressable content $where = Articles::get_sql_where(); // put only published pages in boxes if ($variant == 'boxes') { $where .= " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')"; // provide published pages to anonymous surfers } elseif (!Surfer::is_logged()) { $where .= " AND NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')"; // logged surfers that are non-associates are restricted to their own articles, plus published articles } elseif (!Surfer::is_empowered()) { $where .= " AND ((articles.create_id=" . Surfer::get_id() . ") OR (NOT ((articles.publish_date is NULL) OR (articles.publish_date <= '0000-00-00'))" . " AND (articles.publish_date < '" . $context['now'] . "')))"; } // now $match = gmstrftime('%Y-%m-%d'); // the request $query = "SELECT dates.date_stamp as date_stamp, articles.* FROM " . SQL::table_name('dates') . " as dates" . ", " . SQL::table_name('articles') . " AS articles" . " WHERE ((dates.anchor_type LIKE 'article') AND (dates.anchor_id = articles.id))" . "\tAND (dates.date_stamp < '" . SQL::escape($match) . "') AND (articles.anchor LIKE '" . SQL::escape($anchor) . "') AND " . $where . " ORDER BY dates.date_stamp DESC LIMIT " . $offset . ',' . $count; // the list of dates $output =& Dates::list_selected(SQL::query($query), $variant); return $output; }