project_id = $project_id; $project = get_post( $project_id ); if ( !empty( $project->post_title ) ) $this->project_name = $project->post_title; } function display() { if ( isset( $_POST['new_item'] ) ) $this->add_item_to_part( $_POST['item_id'], $_POST['part_id'] ); if ( isset( $_POST['new_part'] ) ) $this->add_new_part( $_POST['new_part_name'] ); if ( isset( $_GET['move_up'] ) ) $this->move_up( $_GET['move_up'] ); if ( isset( $_GET['move_down'] ) ) $this->move_down( $_GET['move_down'] ); if ( isset( $_GET['remove'] ) ) $this->remove_item( $_GET['remove'] ); if ( isset( $_POST['append_children'] ) ) { $this->append_children( $_POST['append_parent'], $_POST['append_children'] ); } ?>
__( 'Tag', 'anthologize' ), 'category' => __( 'Category', 'anthologize' ), 'date' => __( 'Date Range', 'anthologize' ), 'post_type' => __( 'Post Type', 'anthologize' ) ); $cfilter = isset( $_COOKIE['anth-filter'] ) ? $_COOKIE['anth-filter'] : ''; ?> available_post_types(); $terms = array(); foreach ( $types as $type_id => $type_label ) { $type_object = null; $type_object->term_id = $type_id; $type_object->name = $type_label; $terms[] = $type_object; } $nulltext = __( 'All post types', 'anthologize' ); break; default : $terms = Array(); $nulltext = ' - '; break; } ?>"New Part" to get started.', 'anthologize' ), 'post-new.php?post_type=anth_part&project_id=' . $this->project_id . '&new_part=1' ) ?>
array('post', 'page', 'anth_imported_item' ), 'posts_per_page' => -1, 'orderby' => 'post_title', 'order' => 'DESC' ); $cfilter = ( isset( $_COOKIE['anth-filter'] ) ) ? $_COOKIE['anth-filter'] : false; if ( $cfilter == 'date' ) { $startdate = mysql_real_escape_string($_COOKIE['anth-startdate']); $enddate = mysql_real_escape_string($_COOKIE['anth-enddate']); $date_range_where = ''; if (strlen($startdate) > 0){ $date_range_where = " AND post_date >= '".$startdate."'"; } if (strlen($enddate) > 0){ $date_range_where .= " AND post_date <= '".$enddate."'"; } $where_func = '$where .= "'.$date_range_where.'"; return $where;'; $filter_where = create_function('$where', $where_func); add_filter('posts_where', $filter_where); } else { $cterm = ( isset( $_COOKIE['anth-term'] ) ) ? $_COOKIE['anth-term'] : false; if ( $cterm ) { if ( $cfilter ) { switch( $cfilter ) { case 'tag' : $filtertype = 'tag'; break; case 'category' : $filtertype = 'cat'; break; case 'post_type' : $filtertype = 'post_type'; break; } $args[$filtertype] = $cterm; } } } $big_posts = new WP_Query( $args ); if ( $big_posts->have_posts() ) { ?> get_results($sql); $counter = 0; foreach( $ids as $id ) { if ( in_array( $id->id, $items ) || array_key_exists( $id->id, $items ) ) // Todo: adjust so that it references parent stuff continue; echo ''; $counter++; } if ( !$counter ) echo ''; } function get_part_items( $part_id ) { $append_parent = !empty( $_GET['append_parent'] ) ? $_GET['append_parent'] : false; $items = get_post_meta( $part_id, 'items', true ); //echo "";
//print_r($items); die();
//if ( empty( $items ) )
// return;
$args = array(
'post_parent' => $part_id,
'post_type' => 'anth_library_item',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$items_query = new WP_Query( $args );
if ( $items_query->have_posts() ) {
while ( $items_query->have_posts() ) : $items_query->the_post();
$this->display_item( $append_parent );
endwhile;
}
}
function move_up( $id ) {
global $wpdb;
$post = get_post( $id );
$my_menu_order = $post->menu_order;
$little_brother = 0;
$minus = 0;
while ( !$big_brother ) {
$minus++;
// Find the big brother
$big_brother_q = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND menu_order = %d LIMIT 1", $post->post_parent, $my_menu_order-$minus );
$bb = $wpdb->get_results( $big_brother_q, ARRAY_N );
$big_brother = $bb[0][0];
}
// Downgrade the big brother
$big_brother_q = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = %d WHERE ID = %d", $my_menu_order, $big_brother ) );
// Upgrade self
$little_brother_q = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = %d WHERE ID = %d", $my_menu_order-$minus, $id ) );
return true;
}
function move_down( $id ) {
global $wpdb;
$post = get_post( $id );
$my_menu_order = $post->menu_order;
$little_brother = 0;
$plus = 0;
while ( !$little_brother ) {
$plus++;
// Find the little brother
$little_brother_q = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND menu_order = %d LIMIT 1", $post->post_parent, $my_menu_order+$plus );
$lb = $wpdb->get_results( $little_brother_q, ARRAY_N );
$little_brother = $lb[0][0];
}
// Upgrade the little brother
$little_brother_q = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = %d WHERE ID = %d", $my_menu_order, $little_brother ) );
// Downgrade self
$big_brother_q = $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = %d WHERE ID = %d", $my_menu_order+$plus, $id ) );
return true;
}
function insert_item( $project_id, $post_id, $new_post, $dest_id, $source_id, $dest_seq, $source_seq ) {
global $wpdb;
if ( !isset( $project_id ) || !isset( $post_id ) || !isset( $dest_id ) || !isset( $dest_seq ) )
return false;
if ( !$new_post ) {
if ( !isset( $source_id ) || !isset( $source_seq ) )
return false;
}
if ( true === $new_post ) {
$add_item_result = $this->add_item_to_part( $post_id, $dest_id );
if (false === $add_item_result) {
return false;
}
$post_id = $add_item_result;
// $dest_seq[$post_id] = $dest_seq['new_new_new'];
// unset($dest_seq['new_new_new']);
} else {
$post_params = Array('ID' => $post_id,
'post_parent' => $dest_id);
$update_item_result = wp_update_post($post_params);
if (0 === $update_item_result) {
return false;
}
$post_id = $update_item_result;
$this->rearrange_items( $source_seq );
}
// not really any point in checking for errors at this point
// Since the insert succeeded
// We should use more detailed Exceptions eventually
//
// All items require the destination siblings to be reordered
/* if ( !$this->rearrange_items( $dest_seq ) )
return false;*/
//$this->rearrange_items( $dest_seq );
return $post_id;
}
function rearrange_items( $seq ) {
global $wpdb;
foreach ( $seq as $item_id => $pos ) {
$q = "UPDATE $wpdb->posts SET menu_order = %d WHERE ID = %d";
$post_up_query = $wpdb->query( $wpdb->prepare( $q, $pos, $item_id ) );
}
$this->update_project_modified_date();
return true;
}
function remove_item( $id ) {
// Git ridda the post
if ( !wp_delete_post( $id ) )
return false;
$this->update_project_modified_date();
return true;
}
function append_children( $append_parent, $append_children ) {
$parent_post = get_post( $append_parent );
$pp_content = $parent_post->post_content;
if ( !$author_name = get_post_meta( $append_parent, 'author_name', true ) )
$author_name = '';
if ( !$author_name_array = get_post_meta( $append_parent, 'author_name_array', true ) )
$author_name_array = array();
foreach( $append_children as $append_child ) {
$child_post = get_post( $append_child );
$cp_title = '' . $child_post->post_title . '
';
$cp_content = $child_post->post_content;
$pp_content .= $cp_title . $cp_content . '
';
if ( $author_name != '' )
$author_name .= ', ';
$cp_author_name = get_post_meta( $append_child, 'author_name', true );
$author_name .= $cp_author_name;
$author_name_array[] = $cp_author_name;
wp_delete_post( $append_child );
}
$args = array(
'ID' => $append_parent,
'post_content' => $pp_content,
);
if ( !wp_update_post( $args ) )
return false;
update_post_meta( $append_parent, 'author_name', $author_name );
update_post_meta( $append_parent, 'author_name_array', $author_name_array );
$this->update_project_modified_date();
return true;
}
function display_item( $append_parent ) {
global $post;
/**
* Pull up some comment data to be used in the Comments (x/y) area.
* Comments themselves are fetched with AJAX as needed.
*/
// First, the original post
$anth_meta = get_post_meta( get_the_ID(), 'anthologize_meta', true );
$original_comment_count = 0;
if ( !empty( $anth_meta['original_post_id'] ) ) {
$original_post = get_post( $anth_meta['original_post_id'] );
$original_comment_count = $original_post->comment_count;
}
// Then, see how many comments are being brought along to the export
$included_comment_count = 0;
if ( !empty( $anth_meta['included_comments'] ) ) {
$included_comment_count = count( $anth_meta['included_comments'] );
}
?>