示例#1
0
/**
 * Is Participad installed correctly?
 */
function participad_is_installed_correctly()
{
    $is_installed_correctly = true;
    $api_endpoint = participad_api_endpoint();
    $api_key = participad_api_key();
    if (!$api_endpoint || !$api_key) {
        $is_installed_correctly = false;
    }
    if (!method_exists(participad_client(), 'is_connected') || !participad_client()->is_connected()) {
        $is_installed_correctly = false;
    }
    return $is_installed_correctly;
}
 /**
  * Given a WP user ID, create a new EP user
  *
  * @param int $wp_user_id
  * @return string $ep_user_id
  */
 public static function create_ep_user($wp_user_id)
 {
     $ep_user_id = '';
     // Use display_name for the WP user
     $wp_user = new WP_User($wp_user_id);
     if (is_a($wp_user, 'WP_User')) {
         try {
             $ep_user = participad_client()->createAuthorIfNotExistsFor($wp_user->ID, $wp_user->display_name);
             $ep_user_id = $ep_user->authorID;
             update_user_meta($wp_user_id, 'ep_user_id', $ep_user_id);
             return $ep_user_id;
         } catch (Exception $e) {
             return new WP_Error('create_ep_user', __('Could not create the Etherpad Lite user.', 'participad'));
         }
     }
 }
 public static function set_ep_post_content($ep_post_id, $post_content)
 {
     try {
         $content = participad_client()->setText($ep_post_id, $post_content);
         return $content->message;
     } catch (Exception $e) {
         return new WP_Error('get_ep_post_last_edited', __('Could not get the last edited date of this Etherpad Lite post', 'participad'));
     }
 }
示例#4
0
 /**
  * On WP post save, look to see whether there's a corresponding EP post,
  * and if found, sync the EP content into the WP post
  *
  * Note that this will overwrite local modifications.
  * @todo Refactor to use the correct sync mechanism
  */
 public function sync_etherpad_content_to_wp($postdata)
 {
     try {
         // We have to concatenaty the getText source
         // differently depending on whether this is a new or
         // existing post
         if (isset($_POST['participad_dummy_post_ID'])) {
             $post_id = (int) $_POST['participad_dummy_post_ID'];
             $ep_post_id = get_post_meta($post_id, 'ep_post_group_id', true) . '$' . get_post_meta($post_id, 'ep_post_id', true);
         } else {
             $ep_post_id = $this->current_post->ep_post_id_concat;
         }
         $text = participad_client()->getHTML($ep_post_id);
         $postdata['post_content'] = $text->html;
     } catch (Exception $e) {
     }
     return $postdata;
 }