/** * Check to see if the post is currently being edited by another user. * * This is a verbatim copy of wp_check_post_lock(), which is only available * in the admin * * @since 1.2.8 * * @param int $post_id ID of the post to check for editing * @return bool|int False: not locked or locked by current user. Int: user ID of user with lock. */ function bp_docs_check_post_lock($post_id) { if (!($post = get_post($post_id))) { return false; } if (!($lock = get_post_meta($post->ID, '_bp_docs_last_pinged', true))) { return false; } $lock = explode(':', $lock); $time = $lock[0]; $user = isset($lock[1]) ? $lock[1] : get_post_meta($post->ID, '_edit_last', true); $heartbeat_interval = bp_docs_heartbeat_pulse(); // Bail out of the lock if four pings have been missed (one minute, by default) $time_window = apply_filters('bp_docs_post_lock_interval', $heartbeat_interval * 4); if ($time && $time > time() - $time_window && $user != get_current_user_id()) { return $user; } return false; }
/** * Loads JavaScript * * @package BuddyPress Docs * @since 1.0-beta */ function enqueue_scripts() { wp_register_script('bp-docs-js', plugins_url(BP_DOCS_PLUGIN_SLUG . '/includes/js/bp-docs.js'), array('jquery')); // This is for edit/create scripts if (bp_docs_is_doc_edit() || bp_docs_is_doc_create() || !empty($this->query->current_view) && ('edit' == $this->query->current_view || 'create' == $this->query->current_view)) { require_once ABSPATH . '/wp-admin/includes/post.php'; wp_enqueue_script('common'); wp_enqueue_script('jquery-color'); wp_enqueue_script('editor'); wp_enqueue_script('utils'); wp_register_script('bp-docs-idle-js', plugins_url(BP_DOCS_PLUGIN_SLUG . '/includes/js/idle.js'), array('jquery', 'bp-docs-js')); wp_enqueue_script('bp-docs-idle-js'); wp_register_script('jquery-colorbox', plugins_url(BP_DOCS_PLUGIN_SLUG . '/lib/js/colorbox/jquery.colorbox-min.js'), array('jquery')); wp_enqueue_script('jquery-colorbox'); // Edit mode requires bp-docs-js to be dependent on TinyMCE, so we must // reregister bp-docs-js with the correct dependencies wp_deregister_script('bp-docs-js'); wp_register_script('bp-docs-js', plugins_url(BP_DOCS_PLUGIN_SLUG . '/includes/js/bp-docs.js'), array('jquery', 'editor', 'heartbeat')); wp_register_script('word-counter', site_url() . '/wp-admin/js/word-count.js', array('jquery')); wp_enqueue_script('bp-docs-edit-validation', plugins_url(BP_DOCS_PLUGIN_SLUG . '/includes/js/edit-validation.js'), array('jquery', 'bp-docs-js')); } // Only load our JS on the right sorts of pages. Generous to account for // different item types if (in_array(bp_docs_get_docs_slug(), $this->slugstocheck) || bp_docs_is_single_doc() || bp_docs_is_global_directory() || bp_docs_is_mygroups_directory() || bp_docs_is_doc_create()) { wp_enqueue_script('bp-docs-js'); wp_enqueue_script('comment-reply'); $strings = array('upload_title' => __('Upload File', 'bp-docs'), 'upload_button' => __('OK', 'bp-docs'), 'still_working' => __('Still working?', 'bp-docs'), 'and_x_more' => __('and %d more', 'bp-docs'), 'failed_submission' => !empty(buddypress()->bp_docs->submitted_data) ? 1 : 0); if (bp_docs_is_doc_edit()) { $strings['pulse'] = bp_docs_heartbeat_pulse(); } wp_localize_script('bp-docs-js', 'bp_docs', $strings); } }