minimum_cap = $this->minimum_cap(); add_action( 'admin_init', array( $this, 'init' ) ); add_action( 'admin_menu', array( $this, 'dashboard_hooks' ), 990 ); require( dirname( __FILE__ ) . '/class-ajax-handlers.php' ); $ajax_handlers = new Anthologize_Ajax_Handlers(); add_action( 'admin_menu', array( $this, 'load_template' ), 999 ); if ( is_multisite() ) { add_action( 'wpmu_options', array( $this, 'ms_settings' ) ); add_action( 'update_wpmu_options', array( $this, 'save_ms_settings' ) ); } } function init() { foreach ( array( 'anth_project', 'anth_part', 'anth_library_item', 'anth_imported_item' ) as $type ) { add_meta_box('anthologize', __( 'Anthologize', 'anthologize' ), array( $this,'item_meta_box' ), $type, 'side', 'high'); add_meta_box('anthologize-save', __( 'Save', 'anthologize' ), array( $this,'meta_save_box' ), $type, 'side', 'high'); remove_meta_box( 'submitdiv' , $type , 'normal' ); } add_action( 'save_post',array( $this, 'item_meta_save' ) ); do_action( 'anthologize_admin_init' ); } /** * Loads the minimum user capability for displaying the Anthologize menus * * When running Multisite, this function first checks to see whether the super admin has * allowed per-blog settings. * * For now, Anthologize pages are all-or-nothing. In the future, finer-grained access is * planned. In the meantime, feel free to filter this value in your own plugin. * * @package Anthologize * @since 0.6 */ function minimum_cap() { // If the super admin hasn't set a default, it'll fall back to manage_options, i.e. Administrators-only // Get the default cap if ( is_multisite() ) { $site_settings = get_site_option( 'anth_site_settings' ); $default_cap = ! empty( $site_settings['minimum_cap'] ) ? $site_settings['minimum_cap'] : 'manage_options'; } else { $default_cap = 'manage_options'; } // Then use the default to set the minimum cap for this blog if ( ! is_multisite() || empty( $site_settings['forbid_per_blog_caps'] ) ) { $blog_settings = get_option( 'anth_settings' ); $cap = ! empty( $blog_settings['minimum_cap'] ) ? $blog_settings['minimum_cap'] : $default_cap; } else { $cap = $default_cap; } return apply_filters( 'anth_minimum_cap', $cap ); } /** * Adds Anthologize's plugin pages to the Dashboard * * Uses a somewhat hackish method, borrowed from BuddyPress, to get things in a nice order * * @todo this is rude and we shouldn't do it * * @package Anthologize * @since 0.3 */ function dashboard_hooks() { global $menu; // The default location of the Anthologize menu item. Anthologize needs an empty // space before and after it in order to display, so it might have to poke around // a bit to find room for itself $default_index = apply_filters( 'anth_default_menu_position', 55 ); while ( ! empty( $menu[ $default_index - 1 ] ) || ! empty( $menu[ $default_index ] ) || ! empty( $menu[ $default_index + 1 ] ) ) { $default_index++; } $separator = array( 0 => '', 1 => 'read', 2 => 'separator-anthologize', 3 => '', 4 => 'wp-menu-separator' ); $menu[ $default_index - 1 ] = $separator; $menu[ $default_index + 1 ] = $separator; $plugin_pages = array(); // Adds the top-level Anthologize Dashboard menu button $this->add_admin_menu_page( array( 'menu_title' => __( 'Anthologize', 'anthologize' ), 'page_title' => __( 'Anthologize', 'anthologize' ), 'access_level' => $this->minimum_cap, 'file' => 'anthologize', 'function' => array( $this, 'display' ), 'position' => $default_index ) ); // Creates the submenu items $plugin_pages[] = add_submenu_page( 'anthologize', __( 'My Projects', 'anthologize' ), __( 'My Projects', 'anthologize' ), $this->minimum_cap, 'anthologize', array ( $this, 'display' ) ); $plugin_pages[] = add_submenu_page( 'anthologize', __( 'New Project', 'anthologize' ), __( 'New Project', 'anthologize' ), $this->minimum_cap, 'anthologize_new_project', array( $this, 'load_admin_panel_new_project' ) ); $plugin_pages[] = add_submenu_page( 'anthologize', __( 'Export Project', 'anthologize' ), __( 'Export Project', 'anthologize' ), $this->minimum_cap, 'anthologize_export_project', array( $this, 'load_admin_panel_export_project' ) ); $plugin_pages[] = add_submenu_page( 'anthologize', __( 'Import Content', 'anthologize' ), __( 'Import Content', 'anthologize' ), $this->minimum_cap, 'anthologize_import_content', array( $this, 'load_admin_panel_import_content' ) ); $plugin_pages[] = add_submenu_page( 'anthologize', __( 'Settings', 'anthologize' ), __( 'Settings', 'anthologize' ), 'manage_options', 'anthologize_settings', array( $this, 'load_admin_panel_settings' ) ); $plugin_pages[] = add_submenu_page( 'anthologize', __( 'About Anthologize', 'anthologize' ), __( 'About', 'anthologize' ), $this->minimum_cap, 'anthologize_about', array( $this, 'load_admin_panel_about' ) ); foreach ( $plugin_pages as $plugin_page ) { add_action( "admin_print_styles-$plugin_page", array( $this, 'load_styles' ) ); add_action( "admin_print_scripts-$plugin_page", array( $this, 'load_scripts' ) ); } } // Borrowed, with much love, from BuddyPress. Allows us to put Anthologize way up top. function add_admin_menu_page( $args = '' ) { global $menu, $admin_page_hooks, $_registered_pages; $defaults = array( 'page_title' => '', 'menu_title' => '', 'access_level' => 2, 'file' => false, 'function' => false, 'icon_url' => false, 'position' => 100 ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); $file = plugin_basename( $file ); $admin_page_hooks[$file] = sanitize_title( $menu_title ); $hookname = get_plugin_page_hookname( $file, '' ); if (!empty ( $function ) && !empty ( $hookname )) add_action( $hookname, $function ); if ( empty($icon_url) ) $icon_url = 'images/generic.png'; elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') ) $icon_url = 'https://' . substr($icon_url, 7); do { $position++; } while ( !empty( $menu[$position] ) ); $menu[$position] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url ); unset( $menu[$position][5] ); $_registered_pages[$hookname] = true; return $hookname; } /** * Load the New Project admin panel * * @since 0.7 */ function load_admin_panel_new_project() { require( anthologize()->includes_dir . 'class-new-project.php' ); $this->panels['new_project'] = Anthologize_New_Project::init(); $this->panels['new_project']->display(); } /** * Load the Export Project admin panel * * @since 0.7 */ function load_admin_panel_export_project() { require( anthologize()->includes_dir . 'class-export-panel.php' ); $this->panels['export_project'] = Anthologize_Export_Panel::init(); } /** * Load the Import Content admin panel * * @since 0.7 */ function load_admin_panel_import_content() { require( anthologize()->includes_dir . 'class-import-feeds.php' ); $this->panels['import_content'] = Anthologize_Import_Feeds_Panel::init(); } /** * Load the Import Content admin panel * * @since 0.7 */ function load_admin_panel_settings() { require( anthologize()->includes_dir . 'class-settings.php' ); $this->panels['settings'] = Anthologize_Settings::init(); } /** * Load the About Anthologize admin panel * * @since 0.7 */ function load_admin_panel_about() { require( anthologize()->includes_dir . 'class-about.php' ); $this->panels['about'] = Anthologize_About::init(); } /** * Loads Anthologize's JS * * This needs a massive amount of cleanup * * @package Anthologize * @since 0.3 */ function load_scripts() { wp_enqueue_script( 'anthologize-js', plugins_url() . '/anthologize/js/project-organizer.js' ); wp_enqueue_script( 'jquery'); wp_enqueue_script( 'jquery-ui-core'); wp_enqueue_script( 'jquery-ui-sortable'); wp_enqueue_script( 'jquery-ui-draggable'); wp_enqueue_script( 'jquery-ui-datepicker', plugins_url() . '/anthologize/js/jquery-ui-datepicker.js'); wp_enqueue_script( 'jquery-cookie', plugins_url() . '/anthologize/js/jquery-cookie.js' ); wp_enqueue_script( 'blockUI-js', plugins_url() . '/anthologize/js/jquery.blockUI.js' ); wp_enqueue_script( 'anthologize_admin-js', plugins_url() . '/anthologize/js/anthologize_admin.js' ); wp_enqueue_script( 'anthologize-sortlist-js', plugins_url() . '/anthologize/js/anthologize-sortlist.js' ); wp_localize_script( 'anthologize-sortlist-js', 'anth_strings', array( 'append' => __( 'Append', 'anthologize' ), 'cancel' => __( 'Cancel', 'anthologize' ), 'commenter' => __( 'Commenter', 'anthologize' ), 'comment_content' => __( 'Comment Content', 'anthologize' ), 'comments' => __( 'Comments', 'anthologize' ), 'comments_explain' => __( 'Check the comments from the original post that you would like to include in your project.', 'anthologize' ), 'done' => __( 'Done', 'anthologize' ), 'edit' => __( 'Edit', 'anthologize' ), 'less' => __( 'less', 'anthologize' ), 'more' => __( 'more', 'anthologize' ), 'no_comments' => __( 'This post has no comments associated with it.', 'anthologize' ), 'preview' => __( 'Preview', 'anthologize' ), 'posted' => __( 'Posted', 'anthologize' ), 'remove' => __( 'Remove', 'anthologize' ), 'save' => __( 'Save', 'anthologize' ), 'select_all' => __( 'Select all', 'anthologize' ), 'select_none' => __( 'Select none', 'anthologize' ), ) ); } /** * Loads Anthologize's styles * * This should be optimized to load CSS only on Anthologize pages * * @package Anthologize * @since 0.3 */ function load_styles() { wp_enqueue_style( 'anthologize-css', plugins_url() . '/anthologize/css/project-organizer.css' ); wp_enqueue_style( 'jquery-ui-datepicker-css', plugins_url() . '/anthologize/css/jquery-ui-1.7.3.custom.css'); } /** * Loads the project organizer when an 'edit' parameter is passed with the url * * @package Anthologize * @since 0.3 * * @param int $project_id The id for the project being loaded */ function load_project_organizer( $project_id ) { require_once( dirname( __FILE__ ) . '/class-project-organizer.php' ); $project_organizer = new Anthologize_Project_Organizer( $project_id ); $project_organizer->display(); } /** * Displays error markup when a project is not found by the supplied ID * * @package Anthologize * @since 0.3 */ function display_no_project_id_message() { ?>

includes_dir . 'class-export-panel.php' ); Anthologize_Export_Panel::save_session(); $type = $_SESSION['filetype']; if ( !is_array( $anthologize_formats[$type] ) ) return; $project_id = $_SESSION['project_id']; load_template( $anthologize_formats[$type]['loader-path'] ); return false; } /** * Gets the parts associated with a project * * @package Anthologize * @since 0.3 * * @param int $project_id The id for the project being loaded * @return array $parts The project's parts */ function get_project_parts( $project_id = null ) { global $post; if ( ! $project_id ) { $project_id = $post->ID; } $args = array( 'post_parent' => $project_id, 'post_type' => 'anth_part', 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC' ); $parts_query = new WP_Query( $args ); if ( $parts = $parts_query->posts ) { return $parts; } else { return false; } } /** * Gets the items associated with a project * * @package Anthologize * @since 0.3 * * @param int $project_id The id for the project being loaded * @return array $items The project's items */ function get_project_items($project_id = null) { global $post; if ( ! $project_id ) { $project_id = $post->ID; } $parts = $this->get_project_parts($project_id); $items = array(); if ( $parts ) { foreach ($parts as $part) { $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 ); // May need optimization if ( $child_posts = $items_query->posts ) { foreach( $child_posts as $child_post ) { $items[] = $child_post; } } } } return $items; } /** * Displays the markup for the main admin panel * * @package Anthologize * @since 0.3 */ function display() { if ( isset( $_GET['project_id'] ) ) $project = get_post( $_GET['project_id'] ); if ( isset( $_GET['action'] ) ) { if ( $_GET['action'] == 'delete' && $project ) { wp_delete_post($project->ID); } if ( $_GET['action'] == 'edit' && $project ) { $this->load_project_organizer( $_GET['project_id'] ); } } if ( ! isset( $_GET['action'] ) || $_GET['action'] == 'list-projects' || ( $_GET['action'] == 'edit' && !$project ) || ( $_GET['action'] == 'delete') ) { ?>

display_no_project_id_message(); } $this->do_project_query(); if ( have_posts() ) { ?>

' . __('Project Details', 'anthologize') . ''; $controlActions[] = ''.__('Manage Parts', 'anthologize') . ''; $controlActions[] = ''.__('Delete Project', 'anthologize') . ''; ?>
get_project_parts(); echo (is_array($parts) ? count($parts) : '0'); ?> get_project_items(); echo count($items); ?> post_date ) ) ?>

'anth_project' ); // Anyone less than an Editor should only see their own posts if ( ! current_user_can( 'edit_others_posts' ) ) { $args['author'] = $current_user->ID; } // Do that thang query_posts( $args ); } function meta_save_box( $post_id ) { ?>
user_can_edit() ) { return $post_id; } if ( empty( $_POST['anthologize_meta'] ) || ! $new_data = $_POST['anthologize_meta'] ) { $new_data = array(); } if ( ! $anthologize_meta = get_post_meta( $post_id, 'anthologize_meta', true ) ) { $anthologize_meta = array(); } foreach ( $new_data as $key => $value ) { $anthologize_meta[ $key ] = maybe_unserialize( $value ); } update_post_meta( $post_id, 'anthologize_meta', $anthologize_meta ); update_post_meta( $post_id, 'author_name', $new_data['author_name'] ); // We need to filter the redirect location when Anthologize items are saved add_filter( 'redirect_post_location', array( $this, 'item_meta_redirect' ) ); return $post_id; } /** * Provides a redirect location for after a post is saved * * @package Anthologize * @since 0.3 * * @param str $location * @retur str $location */ function item_meta_redirect($location) { if ( isset( $_POST['post_parent'] ) ) { $post_parent_id = $_POST['post_parent']; } else { $post = get_post( $_POST['ID'] ); $post_parent_id = $post->post_parent; } $post_parent = get_post( $post_parent_id ); if ( isset( $_POST['new_part'] ) ) $arg = $_POST['parent_id']; else $arg = $post_parent->post_parent; $location = add_query_arg( array( 'page' => 'anthologize', 'action' => 'edit', 'project_id' => $arg ), admin_url( 'admin.php' ) ); if ( isset( $_POST['return_to_project'] ) ) { $location = add_query_arg( array( 'page' => 'anthologize', 'action' => 'edit', 'project_id' => $_POST['return_to_project'] ), admin_url( 'admin.php' ) ); } return $location; } /** * item_meta_box * * Displays form for editing item metadata associated with * Anthologize. Includes hidden fields for post_parent and * menu_order because WP sets those values to 0 if those * fields are not present on the form. **/ function item_meta_box() { global $post; $meta = get_post_meta( $post->ID, 'anthologize_meta', true ); $imported_item_meta = get_post_meta( $post->ID, 'imported_item_meta', true ); $author_name = get_post_meta( $post->ID, 'author_name', true ); ?>

$value ) : ?> ' . $value . ''; break; case 'link': $dt = __( 'Source URL:', 'anthologize' ); $dd = '' . $value . ''; break; /*case 'authors': $dt = __( 'Author:', 'anthologize' ); $ddv = $value[0]; $dd = $ddv->name; break; todo: fixme */ case 'created_date': $dt = __( 'Date created:', 'anthologize' ); $dd = $value; break; default: continue; break; } ?>
ID; } if ( $post_id ) { $post = get_post( $post_id ); } // Is the user the author of the post in question? if ( $user_id == $post->post_author ) { $user_can_edit = true; } } return apply_filters( 'anth_user_can_edit', $user_can_edit, $post_id, $user_id ); } /** * Adds Anthologize settings to the ms-options.php panel of an MS dashboard * * @package Anthologize * @since 0.6 */ function ms_settings() { $site_settings = get_site_option( 'anth_site_settings' ); $minimum_cap = ! empty( $site_settings['minimum_cap'] ) ? $site_settings['minimum_cap'] : 'manage_options'; ?>

$forbid_per_blog_caps, 'minimum_cap' => $minimum_cap ); update_site_option( 'anth_site_settings', $anth_site_settings ); } } endif;