* * Copyright 2008-2011 Crowd Favorite, Ltd. All rights reserved. * Released under the GPL license * http://www.opensource.org/licenses/gpl-license.php */ /** * Saves an event in post meta to be used when outputting an audit log. * * @param int $post_id ID of the post that the event occurred for * @param int $actor_id ID of the user that created the event * @param int $event_id ID of the event corresponding to an events array. See $event_array in function annowf_audit_log * @param array $data Any data associated with the event. * @return bool True if the event was saved, false otherwise */ function annowf_save_audit_item($post_id, $actor_id, $event_id, $data = array()) { $num_items = get_post_meta($post_id, '_anno_audit_count', true); if (empty($num_items)) { $num_items = 0; } $audit_item = array( 'actor' => $actor_id, 'event' => $event_id, 'time' => time(), 'data' => $data, ); if (update_post_meta($post_id, '_anno_audit_item_'.($num_items + 1), $audit_item)) { update_post_meta($post_id, '_anno_audit_count', $num_items + 1); return true; } return false; } /** * Displays an audit log of events for a given post. * * @param int $post_id The ID of the post to display the log for. * @return void */ function annowf_audit_log($post) { $post_id = $post->ID; $html = ''; $num_items = get_post_meta($post_id, '_anno_audit_count', true); $items = array(); for ($i = 1; $i <= $num_items; $i++) { $items[] = get_post_meta($post_id, '_anno_audit_item_'.$i, true); } if (empty($items)) { return $html; } // Indices start at 1 to prevent empty() check failures $event_array = array( 0 => '', 1 => _x('Created a revision', 'article audit event', 'anno'), 2 => _x('Transitioned post state from %s to %s', 'article audit event', 'anno'), 3 => _x('Added a reviewer comment', 'article audit event', 'anno'), 4 => _x('Added a review of %s', 'article audit event', 'anno'), 5 => _x('Added an internal comment', 'article audit event', 'anno'), 6 => _x('Added %s as a co-author', 'article audit event', 'anno'), 7 => _x('Removed %s as a co-author', 'article audit event', 'anno'), 8 => _x('Added %s as a reviewer', 'article audit event', 'anno'), 9 => _x('Removed %s as a reviewer', 'article audit event', 'anno'), ); echo ''; } /** * Hooks into cf-revision-manager plugin. Defines post meta to be saved with revisions. */ function annowf_registered_post_meta_items() { if (function_exists('cfr_register_metadata')) { $workflow_meta_keys = array( '_anno_acknowledgements', '_anno_funding', '_anno_subtitle', '_anno_appendices', '_anno_doi', '_anno_author_snapshot', '_anno_references', ); foreach ($workflow_meta_keys as $meta_key) { cfr_register_metadata($meta_key); add_filter('cfrm_compare_header_'.$meta_key, 'annowf_meta_compare_display', 10, 2); } add_filter('cfrm_selector', 'annowf_cfrm_selector'); } } add_action('init', 'annowf_registered_post_meta_items'); add_filter('cfrm_compare_header', '__return_false'); function annowf_cfrm_selector($selector) { return '[name^="anno_"]:not([name^="anno_snapshot"], [name^="anno_appendix"])'; } function annowf_meta_compare_display($html, $key) { $html = ''; $html = ucwords(str_replace('_', ' ', substr($key, 6))); return $html; } /** * Styling for post-meta in revisions */ function annowf_revisions_css() { ?>