WARNING: error defining Custom Field on Page with Posts.');
if (strlen($info) > 0) echo('More info: '.$info.'
');
}
// # RUNTIME SAPI HELPER FUNCTIONS ============================================
function aspen_sapi_options_init() {
/* this will initialize the SAPI stuff, must be called from the admin_init cb function .
In reality, we really only need to register one setting - 'aspen_main_settings_group',
and the settings will be saved in the WP DB as 'aspen_main_settings'. The SAPI uses
the name param of any fields to figure out where to store the input value.
The validation will have to scan the ENTIRE list of options and lookup the kind of
validation each parameter needs.
*/
register_setting('aspen_settings_group', /* the group name of our settings */
apply_filters('aspen_options','aspen_settings'), /* the get_option name */
'aspen_validate_cb'); /* a validation call back */
}
function aspen_validate_cb($in) {
// keep the definition in runtime, load as needed at admin time
require_once( dirname( __FILE__ ) . '/lib-admin.php' );
return aspen_validate_all_options($in);
}
/*
================= nonce helpers =====================
*/
function aspen_submitted($submit_name) {
// do a nonce check for each form submit button
// pairs 1:1 with aspen_nonce_field
$nonce_act = $submit_name.'_act';
$nonce_name = $submit_name.'_nonce';
if (isset($_POST[$submit_name])) {
if (isset($_POST[$nonce_name]) && wp_verify_nonce($_POST[$nonce_name],$nonce_act)) {
return true;
} else {
die("WARNING: invalid form submit detected ($submit_name). Probably caused by session time-out, or, rarely, a failed security check. Please contact AspenTheme.com if you continue to receive this message.");
}
} else {
return false;
}
}
function aspen_nonce_field($submit_name,$echo = true) {
// pairs 1:1 with sumbitted
// will be one for each form submit button
return wp_nonce_field($submit_name.'_act',$submit_name.'_nonce',$echo);
}
// # PAGE WITH POSTS ==============================================================
function aspen_get_page() {
/* get the current posts display number
needed for when Page with Posts is front page
*/
$paged = get_query_var('paged');
if (!isset($paged) || empty($paged)) {
$paged = 1;
}
$page = get_query_var( 'page' );
if ( $page > 1)
$paged = $page;
return $paged;
}
function aspen_setup_post_args($args) {
/* setup WP_Query arg list */
$cats = aspen_get_page_categories();
if (!empty($cats)) $args['cat'] = $cats;
$tags = aspen_get_page_tags();
if (!empty($tags)) $args['tag'] = $tags;
$onepost = aspen_get_page_onepost();
if (!empty($onepost)) $args['name'] = $onepost;
$orderby = aspen_get_page_orderby();
if (!empty($orderby)) $args['orderby'] = $orderby;
$order = aspen_get_page_order();
if (!empty($order)) $args['order'] = $order;
$author_name = aspen_get_page_author();
if (!empty($author_name)) {
$nosp = str_replace(' ', '', $author_name);
$id_list=str_replace(',','',$nosp);
if (is_numeric($id_list)) {
$args['author'] = $author_name;
} else {
$args['author_name'] = $author_name;
}
}
$posts_per_page = aspen_get_page_posts_per();
if (!empty($posts_per_page)) $args['posts_per_page'] = $posts_per_page;
$post_type = aspen_get_per_page_value('pp_post_type');
if ($post_type)
$args['post_type'] = $post_type;
if (aspen_is_checked_page_opt('pp_hide_sticky')) $args['ignore_sticky_posts'] = true;
return $args;
}
function aspen_get_page_categories() {
$cats = aspen_get_per_page_value('pp_category');
if (empty($cats)) return '';
// now convert slugs to ids
return aspen_cat_slugs_to_ids($cats);
}
function aspen_cat_slugs_to_ids($cats) {
if (empty($cats)) return '';
// now convert slugs to numbers
$cats = str_replace(' ','',$cats);
$clist = explode(',',$cats); // break into a list
$cat_list = '';
foreach ($clist as $slug) {
$neg = 1; // not negative
if ($slug[0] == '-') {
$slug = substr($slug,1); // zap the -
$neg = -1;
}
if (strlen($slug) > 0 && is_numeric($slug)) { // allow both slug and id
$cat_id = $neg * (int)$slug;
if ($cat_list == '') $cat_list = strval($cat_id);
else $cat_list .= ','.strval($cat_id);
} else {
$cur_cat = get_category_by_slug($slug);
if ($cur_cat) {
$cat_id = $neg * (int)$cur_cat->cat_ID;
if ($cat_list == '') $cat_list = strval($cat_id);
else $cat_list .= ','.strval($cat_id);
}
}
}
if (empty($cat_list)) $cat_list='99999999';
return $cat_list;
}
function aspen_get_page_tags() {
$tags = aspen_get_per_page_value('pp_tag');
if (empty($tags)) return '';
return str_replace(' ','',$tags);
}
function aspen_get_page_onepost() {
$the_post = aspen_get_per_page_value('pp_onepost');
if (empty($the_post)) return '';
return $the_post;
}
function aspen_get_page_orderby() {
$orderby = aspen_get_per_page_value('pp_orderby');
if (empty($orderby)) return '';
if ($orderby == 'author' || $orderby == 'date' || $orderby == 'title' || $orderby == 'rand')
return $orderby;
aspen_page_posts_error('orderby must be author, date, title, or rand. You used: '. $orderby);
return '';
}
function aspen_get_page_order() {
$order = aspen_get_per_page_value('pp_sort_order');
if (empty($order)) return '';
if ($order == 'ASC' || $order == 'DESC')
return $order;
aspen_page_posts_error('order value must be ASC or DESC. You used: '. $order);
return '';
}
function aspen_get_page_posts_per() {
$ppp = aspen_get_per_page_value('pp_posts_per_page');
if (empty($ppp)) return '';
// now convert slugs to numbers
return $ppp;
}
function aspen_get_page_author() {
$author = aspen_get_per_page_value('pp_author');
if (empty($author)) return '';
return $author;
}
function aspen_add_q($q, $item, $tag='') {
if ($item == '') return $q;
if (!empty($q))
return $q . '&' . $tag . $item;
else
return $tag . $item;
}
// # FILTERS ==============================================================
// ============ validation filters ===============
function aspen_filter_textarea( $text ) {
// virtually all option text input from Aspen can be code, and thus must not be
// content filtered. Treat like code for now....
return aspen_filter_code($text);
}
function aspen_esc_textarea($text) {
echo esc_textarea(stripslashes($text));
}
function aspen_filter_code( $text ) {
static $aspen_allowedadmintags = array(
'address' => array(),
'a' => array(
'class' => array (),
'href' => array (),
'id' => array (),
'title' => array (),
'rel' => array (),
'rev' => array (),
'name' => array (),
'target' => array()),
'abbr' => array(
'class' => array (),
'title' => array ()),
'acronym' => array(
'title' => array ()),
'article' => array(
'align' => array (),
'class' => array (),
'dir' => array (),
'lang' => array(),
'style' => array (),
'xml:lang' => array(),
),
'aside' => array(
'align' => array (),
'class' => array (),
'dir' => array (),
'lang' => array(),
'style' => array (),
'xml:lang' => array(),
),
'b' => array(),
'big' => array(),
'blockquote' => array(
'id' => array (),
'cite' => array (),
'class' => array(),
'lang' => array(),
'xml:lang' => array()),
'br' => array (
'class' => array ()),
'button' => array(
'disabled' => array (),
'name' => array (),
'type' => array (),
'value' => array ()),
'caption' => array(
'align' => array (),
'class' => array ()),
'cite' => array (
'class' => array(),
'dir' => array(),
'lang' => array(),
'title' => array ()),
'code' => array (
'style' => array()),
'col' => array(
'align' => array (),
'char' => array (),
'charoff' => array (),
'span' => array (),
'dir' => array(),
'style' => array (),
'valign' => array (),
'width' => array ()),
'del' => array(
'datetime' => array ()),
'dd' => array(),
'details' => array(
'align' => array (),
'class' => array (),
'dir' => array (),
'lang' => array(),
'open' => array (),
'style' => array (),
'xml:lang' => array(),
),
'div' => array(
'align' => array (),
'class' => array (),
'dir' => array (),
'lang' => array(),
'style' => array (),
'xml:lang' => array()),
'dl' => array(),
'dt' => array(),
'em' => array(),
'fieldset' => array(),
'figure' => array(
'align' => array (),
'class' => array (),
'dir' => array (),
'lang' => array(),
'style' => array (),
'xml:lang' => array(),
),
'figcaption' => array(
'align' => array (),
'class' => array (),
'dir' => array (),
'lang' => array(),
'style' => array (),
'xml:lang' => array(),
),
'font' => array(
'color' => array (),
'face' => array (),
'size' => array ()),
'footer' => array(
'align' => array (),
'class' => array (),
'dir' => array (),
'lang' => array(),
'style' => array (),
'xml:lang' => array(),
),
'form' => array(
'action' => array (),
'accept' => array (),
'accept-charset' => array (),
'enctype' => array (),
'method' => array (),
'name' => array (),
'target' => array ()),
'h1' => array(
'align' => array (),
'class' => array (),
'id' => array (),
'style' => array ()),
'h2' => array (
'align' => array (),
'class' => array (),
'id' => array (),
'style' => array ()),
'h3' => array (
'align' => array (),
'class' => array (),
'id' => array (),
'style' => array ()),
'h4' => array (
'align' => array (),
'class' => array (),
'id' => array (),
'style' => array ()),
'h5' => array (
'align' => array (),
'class' => array (),
'id' => array (),
'style' => array ()),
'h6' => array (
'align' => array (),
'class' => array (),
'id' => array (),
'style' => array ()),
'header' => array(
'align' => array (),
'class' => array (),
'dir' => array (),
'lang' => array(),
'style' => array (),
'xml:lang' => array(),
),
'hr' => array (
'align' => array (),
'class' => array (),
'noshade' => array (),
'size' => array (),
'width' => array ()),
'i' => array(),
'img' => array(
'alt' => array (),
'align' => array (),
'border' => array (),
'class' => array (),
'height' => array (),
'hspace' => array (),
'longdesc' => array (),
'vspace' => array (),
'src' => array (),
'style' => array (),
'width' => array ()),
'ins' => array(
'datetime' => array (),
'cite' => array ()),
'kbd' => array(),
'label' => array(
'for' => array ()),
'legend' => array(
'align' => array ()),
'li' => array (
'align' => array (),
'class' => array ()),
'link' => array(),
'menu' => array (
'class' => array (),
'style' => array (),
'type' => array ()),
'meta' => array(),
'nav' => array(
'align' => array (),
'class' => array (),
'dir' => array (),
'lang' => array(),
'style' => array (),
'xml:lang' => array(),
),
'p' => array(
'class' => array (),
'align' => array (),
'dir' => array(),
'lang' => array(),
'style' => array (),
'xml:lang' => array()),
'pre' => array(
'style' => array(),
'width' => array ()),
'q' => array(
'cite' => array ()),
's' => array(),
//'script' => array(), // only admin or multi-site super-admin can add scripts
'span' => array (
'class' => array (),
'dir' => array (),
'align' => array (),
'lang' => array (),
'style' => array (),
'title' => array (),
'xml:lang' => array()),
'section' => array(
'align' => array (),
'class' => array (),
'dir' => array (),
'lang' => array(),
'style' => array (),
'xml:lang' => array(),
),
'strike' => array(),
'strong' => array(),
'style' => array(),
'sub' => array(),
'summary' => array(
'align' => array (),
'class' => array (),
'dir' => array (),
'lang' => array(),
'style' => array (),
'xml:lang' => array(),
),
'sup' => array(),
'table' => array(
'align' => array (),
'bgcolor' => array (),
'border' => array (),
'cellpadding' => array (),
'cellspacing' => array (),
'class' => array (),
'dir' => array(),
'id' => array(),
'rules' => array (),
'style' => array (),
'summary' => array (),
'width' => array ()),
'tbody' => array(
'align' => array (),
'char' => array (),
'charoff' => array (),
'valign' => array ()),
'td' => array(
'abbr' => array (),
'align' => array (),
'axis' => array (),
'bgcolor' => array (),
'char' => array (),
'charoff' => array (),
'class' => array (),
'colspan' => array (),
'dir' => array(),
'headers' => array (),
'height' => array (),
'nowrap' => array (),
'rowspan' => array (),
'scope' => array (),
'style' => array (),
'valign' => array (),
'width' => array ()),
'textarea' => array(
'cols' => array (),
'rows' => array (),
'disabled' => array (),
'name' => array (),
'readonly' => array ()),
'tfoot' => array(
'align' => array (),
'char' => array (),
'class' => array (),
'charoff' => array (),
'valign' => array ()),
'th' => array(
'abbr' => array (),
'align' => array (),
'axis' => array (),
'bgcolor' => array (),
'char' => array (),
'charoff' => array (),
'class' => array (),
'colspan' => array (),
'headers' => array (),
'height' => array (),
'nowrap' => array (),
'rowspan' => array (),
'scope' => array (),
'valign' => array (),
'width' => array ()),
'thead' => array(
'align' => array (),
'char' => array (),
'charoff' => array (),
'class' => array (),
'valign' => array ()),
'title' => array(),
'tr' => array(
'align' => array (),
'bgcolor' => array (),
'char' => array (),
'charoff' => array (),
'class' => array (),
'style' => array (),
'valign' => array ()),
'tt' => array(),
'u' => array(),
'ul' => array (
'class' => array (),
'style' => array (),
'type' => array ()),
'ol' => array (
'class' => array (),
'start' => array (),
'style' => array (),
'type' => array ()),
'var' => array ());
// virtually all option input from Aspen can be code, and thus must not be
// content filtered. The utf8 check is about the extent of it, although even
// that is more restrictive than the standard text widget uses.
// Note: this check also works OK for simple checkboxes/radio buttons/selections,
// so it is ok to blindly pass those options in here, too.
$noslash = trim(stripslashes($text));
if ($noslash == ' ') return '';
if ( current_user_can('unfiltered_html') ) {
return wp_check_invalid_utf8( $noslash );
} else if (current_user_can('add_users')) {
return wp_kses( $text , $aspen_allowedadmintags);
} else {
return stripslashes( wp_filter_post_kses( addslashes($text) ) ); // wp_filter_post_kses() expects slashed
}
}
// # MISC ==============================================================
function aspen_media_lib_button($fillin = '') {
?>
←
';
}
function aspen_post_count_clear() {
global $aspen_cur_post_count;
$aspen_cur_post_count = 0;
}
function aspen_post_count_bump() {
global $aspen_cur_post_count;
$aspen_cur_post_count++;
}
function aspen_post_count() {
global $aspen_cur_post_count;
return $aspen_cur_post_count;
}
function aspen_post_count_class($hidecount = false) {
global $aspen_cur_post_count;
global $aspen_sticky;
if ($aspen_sticky) // For page with posts - re-ordering sticky posts
$postclass = 'sticky ';
else
$postclass = ' ';
if ($aspen_cur_post_count == 0 || $hidecount) return $postclass;
return $postclass . 'post-' . (($aspen_cur_post_count % 2) ? 'odd' : 'even') . ' post-order-' . $aspen_cur_post_count;
}
function aspen_hide_page_title() {
if (aspen_is_checked_page_opt('pp_hide_page_title')) {
echo ' aspen-hide'; // is included in a class=
}
}
function aspen_use_inline_css($css_file) {
return aspen_getopt_checked('_inline_style') || !aspen_f_file_access_available()
|| !aspen_f_exists($css_file);
}
function aspen_allow_multisite() {
// return true if it is allowed to use on MultiSite
$restrict = (defined('ASPEN_MULTISITE_RESTRICT_OPTIONS')) ? ASPEN_MULTISITE_RESTRICT_OPTIONS : false;
return ((!is_multisite() && current_user_can('install_themes'))
|| (is_multisite() && current_user_can('manage_network_themes'))
|| !$restrict);
}
function aspen_help_link($link, $info) {
$t_dir = aspen_relative_url('');
$pp_help = ''
. '
';
echo($pp_help);
}
function aspen_html_br() {
echo '
';
}
function aspen_compact_post() {
return aspen_getopt('compact_post_formats') || aspen_is_checked_page_opt('pp_pwp_compact');
}
function aspen_get_first_post_image($content='') {
if (has_post_thumbnail()) {
$img = wp_get_attachment_image_src( get_post_thumbnail_id( ), 'medium' );
return '';
}
if ($content == '')
$content = do_shortcode(apply_filters( 'the_content', get_the_content(''))); // pick up wp 3.6 post format meta image
if (preg_match('/
]+>/i',$content, $images)) { // grab
s
$src = '';
if (preg_match('/src="([^"]*)"/', $images[0], $srcs)) {
$src = $srcs[0];
} else if (preg_match("/src='([^']*)'/", $images[0], $srcs)) {
$src = $srcs[0];
}
return '
';
} else {
return '';
}
}
function aspen_compact_link($check = '') {
if ($check == 'check' && !aspen_is_checked_post_opt('pp_post_add_link'))
return;
$link_img = aspen_relative_url('') . 'images/icons/expand.png';
?>