saved_notice = false;
}
/*========================================================================
*
* Admin frontend
*
*=======================================================================*/
/*========================================================================
*
* Build each item
*
*=======================================================================*/
function build_post_list_item($post_id, $post_type, $is_child, $child_query) {
if ( !isset($_GET['post']) )
$current_post_ID = -1;
else
$current_post_ID = $_GET['post']; /* Get current post ID on admin screen */
$edit_link = get_edit_post_link($post_id);
$title = get_the_title($post_id);
$title = esc_html($title);
// Limit title length
if (($this->max_trim_length>0) && ( strlen($title)>($this->max_trim_length) ) ) {
$orig_title = $title;
if ( function_exists( 'mb_substr' ) ) {
$title = mb_substr($title, 0, $this->max_trim_length);
} else {
$title = substr($title, 0, $this->max_trim_length);
}
if ($title != $orig_title) $title.='..';
}
if (rtrim($title) == '') $title = '(no title)';
$output = '
';
$output .= '
';
/*========================================================================
*
* Indent child posts
*
*=======================================================================*/
if ($is_child == 'child') {
if ($this->current_indent_level>0) {
$output .= '';
for ($i=0; $i < $this->current_indent_level; $i++) {
$output .= '–';
}
$output .= '
';
$output .= ' ';
}
}
/*========================================================================
*
* Post status
*
*=======================================================================*/
$post_status = get_post_status($post_id);
$not_published = in_array($post_status, array('draft', 'pending', 'future'));
$is_current = $current_post_ID == $post_id;
if ($not_published) $output .= '';
if ($is_current) $output .= '';
$output .= $title;
if ($is_current) $output .= '';
if ($not_published) $output .= '';
$output .= '';
/*========================================================================
*
* Search for children
*
*=======================================================================*/
$children = get_posts(array(
'post_parent' => $post_id,
'post_type' => $post_type,
'orderby' => $child_query['orderby'],
'order' => $child_query['order'],
'post_status' => $child_query['post_status'],
'posts_per_page' => -1,
));
// Dropdown for children?
$dropdown = false;
if ( (($is_child == 'parent') && ($children) && ($this->drop_down_enabled)) &&
(($this->max_list_count==0) || ($this->current_list_count < $this->max_list_count)) ) {
$this->current_drop_down_count++;
$output .= '
+
';
$dropdown = true;
}
// Output child posts recursively
if ($children) {
if ($dropdown) {
$output .= '
';
}
$this->current_indent_level++;
foreach($children as $child) {
// Count children?
if (!$dropdown)
$this->current_list_count++;
if (($this->max_list_count==0) || ($this->current_list_count <= $this->max_list_count)) {
$output .= $this->build_post_list_item($child->ID, $post_type, 'child', $child_query);
} else {
break;
}
}
$this->current_indent_level--;
if ($dropdown)
$output .= '
';
}
$output .= '
';
return $output;
} // End: function build_post_list_item
/*========================================================================
*
* Add post list to all enabled post types
*
*=======================================================================*/
function add_post_list_view() {
// Get settings
$settings = get_option( 'ampl_settings' );
$this->max_trim_length = isset($settings['max_trim']) ? $settings['max_trim'] : 0;
$this->drop_down_enabled = isset($settings['child_dropdown']) ? ($settings['child_dropdown']=="on") : false;
$this->current_drop_down_count = 0;
// Get all post types
$post_types = $this->get_all_post_types();
foreach ($post_types as $post_type) {
$post_types_setting = isset($settings['post_types'][$post_type]) ?
$settings['post_types'][$post_type] : 'off';
// If enabled
if ($post_types_setting == 'on' ) {
/*========================================================================
*
* Get display options
*
*=======================================================================*/
$this->max_list_count = isset($settings['max_limit'][$post_type]) ?
$settings['max_limit'][$post_type] : 0;
$post_orderby = isset($settings['orderby'][$post_type]) ?
$settings['orderby'][$post_type] : 'date';
$post_order = isset($settings['order'][$post_type]) ?
$settings['order'][$post_type] : 'ASC';
$post_exclude = isset($settings['exclude_status'][$post_type]) ?
$settings['exclude_status'][$post_type] : 'off';
if ($post_exclude=='on')
$post_exclude = 'publish';
else
$post_exclude = 'any';
$custom_menu_slug = $post_type;
$output = '';
if ($this->max_list_count==0) {
$max_numberposts = 999;
} else {
$max_numberposts = $this->max_list_count;
}
$args = apply_filters('AdminMenuPostList_get_posts_args', array(
'post_type' => $post_type,
'post_parent' => 0,
'numberposts' => $max_numberposts,
'orderby' => $post_orderby,
'order' => $post_order,
'post_status' => $post_exclude,
'suppress_filters' => 0
));
$child_query = apply_filters('AdminMenuPostList_child_query_args', array(
'orderby' => $post_orderby,
'order' => $post_order,
'post_status' => $post_exclude,
));
// Support bbPress topics and replies
if (in_array($post_type, array('topic', 'reply')) && class_exists('bbPress')) {
unset($args['post_parent']);
}
$posts = get_posts($args);
if ($posts) {
$output .= '';
$output .= ''
. '
' . '
' . '';
$this->current_list_count = 0;
foreach ($posts as $post) {
$this->current_indent_level = 0; // Start all parents at 0
$this->current_list_count++;
if ($this->max_list_count==0
|| $this->current_list_count <= $this->max_list_count
) {
$output .= $this->build_post_list_item(
$post->ID, $post_type, 'parent', $child_query
);
} else break;
}
$output .= '
';
$output .= '