/** * Called by livepress webservice to create a new live post. * * @param array $args { * An array of arguments. * @param int $blog_id Id of blog to to add post to. * @param string $username Username for action. * @param string $password Livepress generated user access key. * @param array $content_struct Initial post content. * @return Object Post object or false on error. * } */ function livepress_new_live_post($args) { global $wp_xmlrpc_server, $wpdb; $wp_xmlrpc_server->escape($args); $blog_id = (int) $args[0]; $username = $args[1]; $password = $args[2]; $content_struct = $args[3]; // Verify user is authorized if (!($user = _livepress_authenticate($username, $password))) { return false; } // Verify user can edit posts if (!user_can($user, 'edit_posts')) { return false; } unset($content_struct['ID']); $defaults = array('post_status' => 'publish', 'post_type' => 'post', 'post_author' => $user->ID, 'post_title' => $content_struct['title']); $post_data = wp_parse_args($content_struct, $defaults); // Insert the new post $post_id = wp_insert_post($post_data, true); if (is_wp_error($post_id)) { return false; } if (!$post_id) { return false; } $post = get_post($post_id); if (!$post) { return false; } // Set the post live status to live $blogging_tools = new LivePress_Blogging_Tools(); $blogging_tools->set_post_live_status($post_id, true); return $post; }
/** * Enqueue scripts and styles. * * @param string $hook Hook suffix for the current screen. */ function add_css_and_js_on_header($hook = null) { if (is_home()) { return; } if ($hook != null && $hook != 'post-new.php' && $hook != 'post.php' && $hook != 'settings_page_livepress-settings') { return; } wp_register_style('livepress_main_sheets', LP_PLUGIN_URL . 'css/livepress.css'); wp_enqueue_style('livepress_main_sheets'); global $post; if (isset($post) && !is_admin()) { $blogging_tools = new LivePress_Blogging_Tools(); $is_live = $blogging_tools->get_post_live_status($post->ID); if (!$is_live) { return; } } // On the profile page in VIP, load the profile script - handles showing password field if ('profile.php' == $hook && defined('WPCOM_IS_VIP_ENV') && false !== WPCOM_IS_VIP_ENV) { if ($this->livepress_config->script_debug()) { wp_enqueue_script('livepress-profile', LP_PLUGIN_URL . 'js/livepress-profile.full.js', array('jquery')); } else { wp_enqueue_script('livepress-profile', LP_PLUGIN_URL . 'js/livepress-profile.min.js', array('jquery')); } } wp_enqueue_style('wp-mediaelement'); wp_enqueue_script('wp-mediaelement'); wp_register_style('wordpress_override', LP_PLUGIN_URL . 'css/livepress_wordpress_override.css'); wp_enqueue_style('wordpress_override'); wp_register_style('livepress_ui', LP_PLUGIN_URL . 'css/ui.css', array(), false, 'screen'); // FIXME: temporary import of this script. It must be sent by Oortle // on the next versions $static_host = $this->livepress_config->static_host(); if ($this->livepress_config->script_debug()) { $mode = 'full'; } else { $mode = 'min'; } if (is_page() || is_single() || is_home()) { wp_enqueue_script('livepress-plugin-loader', LP_PLUGIN_URL . 'js/plugin_loader_release.' . $mode . '.js', array('jquery'), LP_PLUGIN_VERSION); $lp_client_settings = array('no_google_acct' => esc_html__('Error: [USERNAME] isn\'t a valid Google Talk account', 'livepress'), 'no_acct_in_jabber' => esc_html__('Error: [USERNAME] wasn\'t found in jabber client bot roster', 'livepress'), 'username_not_auth' => esc_html__('[USERNAME] has been authorized', 'livepress'), 'username_authorized' => esc_html__('[USERNAME] has been authorized', 'livepress'), 'livepress_err_retry' => esc_html__('LivePress! error. Try again in a few minutes', 'livepress'), 'auth_request_sent' => esc_html__('Authorization request sent to [USERNAME]', 'livepress'), 'new_updates' => esc_html__('new updates', 'livepress'), 'refresh' => esc_html__('Refresh', 'livepress'), 'to_see' => esc_html__('to see', 'livepress'), 'them' => esc_html__('them', 'livepress'), 'refresh_page' => esc_html__('Refresh page', 'livepress'), 'updated_just_now' => esc_html__('updated just now', 'livepress'), 'uptated_amin_ago' => esc_html__('updated 1 minute ago', 'livepress'), 'updated' => esc_html__('updated', 'livepress'), 'minutes_ago' => esc_html__('minutes ago', 'livepress'), 'no_recent_updates' => esc_html__('no recent updates', 'livepress'), 'sending_error' => esc_html__('Sending error.', 'livepress'), 'sending' => esc_html__('Sending', 'livepress'), 'unknown_error' => esc_html__('Unknown error.', 'livepress'), 'comment_status' => esc_html__('Comment Status', 'livepress'), 'copy_permalink' => esc_html__('Ctrl / Cmd C to copy', 'livepress'), 'filter_by_tag' => esc_html__('Filter by Tag:', 'livepress'), 'by' => esc_html__('by', 'livepress')); $options = $this->options; if (array_key_exists('show', $options) && null !== $options['show']) { $lp_client_settings['show'] = $options['show']; } wp_localize_script('livepress-plugin-loader', 'lp_client_strings', $lp_client_settings); wp_enqueue_style('livepress_ui'); wp_enqueue_script('jquery-effects-core'); wp_enqueue_script('jquery-effects-bounce'); } elseif (is_admin()) { // Add select2 for live tags wp_enqueue_style('select2', LP_PLUGIN_URL . 'css/select2.css', array(), LP_PLUGIN_VERSION); wp_register_style('lp_admin', LP_PLUGIN_URL . 'css/post_edit.css'); wp_enqueue_style('lp_admin'); wp_enqueue_style('lp_admin_font', LP_PLUGIN_URL . 'fonts/livepress-admin/style.css'); wp_enqueue_script('lp-admin', LP_PLUGIN_URL . 'js/admin/livepress-admin.' . $mode . '.js', array('jquery'), LP_PLUGIN_VERSION); $livepress_authors = LivePress_Administration::lp_get_authors(); $lp_strings = array('unexpected' => esc_html__('Unexpected result from the LivePress server. Please contact LivePress support at support@livepress.com for help.', 'livepress'), 'connection_problem' => esc_html__('Connection problem... Try Again...', 'livepress'), 'authenticated' => esc_html__('Authenticated', 'livepress'), 'sending' => esc_html__('Sending', 'livepress'), 'check' => esc_html__('Check', 'livepress'), 'remove' => esc_html__('Remove', 'livepress'), 'key_not_valid' => esc_html__('Key not valid', 'livepress'), 'sending_twitter' => esc_html__('Sending out alerts on Twitter account', 'livepress'), 'failed_to_check' => esc_html__('Failed to check status.', 'livepress'), 'checking_auth' => esc_html__('Checking authorization status', 'livepress'), 'status_not_avail' => esc_html__('Status isn\'t available yet.', 'livepress'), 'internal_error' => esc_html__('Internal server error.', 'livepress'), 'noconnect_twitter' => esc_html__('Can\'t connect to Twitter.', 'livepress'), 'noconnect_livepress' => esc_html__('Can\'t connect to livepress service.', 'livepress'), 'failed_unknown' => esc_html__('Failed for an unknown reason.', 'livepress'), 'return_code' => esc_html__('return code', 'livepress'), 'new_twitter_window' => esc_html__('A new window should be open to Twitter.com awaiting your login.', 'livepress'), 'twitter_unauthorized' => esc_html__('Twitter access unauthorized.', 'livepress'), 'start_live' => esc_html__('Start live blogging', 'livepress'), 'stop_live' => esc_html__('Stop live blogging', 'livepress'), 'readers_online' => esc_html__('readers online', 'livepress'), 'lp_updates_posted' => esc_html__('live updates posted', 'livepress'), 'comments' => esc_html__('comments', 'livepress'), 'click_to_toggle' => esc_html__('Click to toggle', 'livepress'), 'real_time_editor' => esc_html__('Live Blogging Real-Time Editor', 'livepress'), 'off' => esc_html__('off', 'livepress'), 'on' => esc_html__('on', 'livepress'), 'private_chat' => esc_html__('Private chat', 'livepress'), 'persons_online' => esc_html__('Person Online', 'livepress'), 'people_online' => esc_html__('People Online', 'livepress'), 'comment' => esc_html__('Comment', 'livepress'), 'include_timestamp' => esc_html__('include timestamp', 'livepress'), 'live_update_tags' => esc_html__('Live tags:', 'livepress'), 'lp_authors' => $livepress_authors['names'], 'lp_gravatars' => $livepress_authors['gravatars'], 'lp_avatar_links' => $livepress_authors['links'], 'live_tags_select_placeholder' => esc_html__('Live update tag(s)', 'livepress'), 'live_update_header' => esc_html__('Live update header', 'livepress'), 'live_update_byline' => esc_html__('Author(s):', 'livepress'), 'delete_perm' => esc_html__('Delete Permanently', 'livepress'), 'ctrl_enter' => esc_html__('Ctrl+Enter', 'livepress'), 'cancel' => esc_html__('Cancel', 'livepress'), 'save' => esc_html__('Save', 'livepress'), 'draft' => esc_html__('Save as draft', 'livepress'), 'push_update' => esc_html__('Push Update', 'livepress'), 'add_update' => esc_html__('Publish Draft', 'livepress'), 'confirm_delete' => esc_html__('Are you sure you want to delete this update? This action cannot be undone.', 'livepress'), 'updates' => esc_html__('Updates', 'livepress'), 'discard_unsaved' => esc_html__('You have unsaved editors open. Discard them?', 'livepress'), 'loading_content' => esc_html__('Loading content', 'livepress'), 'double_added' => esc_html__('Double added updates. Not supported now.', 'livepress'), 'confirm_switch' => esc_html__('Are you sure you want to switch to Not Live?', 'livepress'), 'scroll' => esc_html__('Scroll to Comment', 'livepress'), 'update_published' => esc_html__('Update was published live to users.', 'livepress'), 'published_not_live' => esc_html__('Update was published NOT live.', 'livepress'), 'cant_get_update' => esc_html__('Can\'t get update status from LivePress.', 'livepress'), 'wrong_ajax_nonce' => esc_html__('Wrong AJAX nonce.', 'livepress'), 'cant_get_blog_update' => esc_html__('Can\'t get upate status from blog server.', 'livepress'), 'sending_alerts' => esc_html__('Sending out alerts on Twitter account:', 'livepress'), 'tools_link_text' => esc_html__('Live Blogging Tools', 'livepress'), 'submit' => esc_html__('submit', 'livepress'), 'live_press' => esc_html__('Live Press', 'livepress'), 'live_chat' => esc_html__('Live Chat', 'livepress'), 'warning' => esc_html__('Warning', 'livepress'), 'connection_lost' => esc_html__('Will try to reconnect in some time.', 'livepress'), 'connect_again' => esc_html__('Please try to reconnect later.', 'livepress'), 'connection_just_lost' => esc_html__('The connection to the server has been lost.', 'livepress'), 'sync_lost' => esc_html__('Syncronization of live editor seems to be lost. Try to enable/disable live editor or reload page.', 'livepress'), 'collabst_sync_lost' => esc_html__('Collaboration state may be out of sync. Try to reload page.', 'livepress'), 'collab_sync_lost' => esc_html__('Collaboration may be out of sync. Try to reload page.', 'livepress'), 'post_link' => esc_html__('Copy the commenter name and full text into the post text box', 'livepress'), 'send_to_editor' => esc_html__('Send to editor', 'livepress'), 'approve_comment' => esc_html__('Approve this comment', 'livepress'), 'approve' => esc_html__('Approve', 'livepress'), 'unapprove_comment' => esc_html__('Unapprove this comment', 'livepress'), 'unapprove' => esc_html__('Unapprove', 'livepress'), 'mark_as_spam' => esc_html__('Mark this comment as spam', 'livepress'), 'spam' => esc_html__('Spam', 'livepress'), 'move_comment_trash' => esc_html__('Move this comment to the trash', 'livepress'), 'trash' => esc_html__('Trash', 'livepress'), 'save_and_refresh' => esc_html__('Save and Refresh', 'livepress'), 'publish_and_refresh' => esc_html__('Publish and Refresh', 'livepress'), 'click_pause_tweets' => esc_html__('Click to pause the tweets so you can decide when to display them', 'livepress'), 'click_copy_tweets' => esc_html__('Click to copy tweets into the post editor.', 'livepress'), 'copy_tweets' => esc_html__('Copy the tweet into the post editing area', 'livepress'), 'remove_term' => esc_html__('Remove this term', 'livepress'), 'remove_account' => esc_html__('Remove this account', 'livepress'), 'remove_lower' => esc_html__('remove', 'livepress'), 'remove_author' => esc_html__('Remote Author', 'livepress'), 'remove_authors' => esc_html__('Remote Authors', 'livepress'), 'account_not_found' => esc_html__('Account not found', 'livepress'), 'connecting' => esc_html__('Connecting', 'livepress'), 'offline' => esc_html__('offline', 'livepress'), 'connected' => esc_html__('connected', 'livepress'), 'user_pass_invalid' => esc_html__('username/password invalid', 'livepress'), 'wrong_account_name' => esc_html__('Wrong account name supplied', 'livepress'), 'problem_connecting' => esc_html__('Problem connecting to the blog server.', 'livepress'), 'test_msg_sent' => esc_html__('Test message sent', 'livepress'), 'test_msg_failure' => esc_html__('Failure sending test message', 'livepress'), 'send_again' => esc_html__('Send test message again', 'livepress'), 'live_post_header' => esc_html__('Pinned Live Post Header', 'livepress'), 'visual_text_editor' => esc_html__('Visual', 'livepress'), 'text_editor' => esc_html__('Text', 'livepress')); wp_localize_script('lp-admin', 'lp_strings', $lp_strings); wp_enqueue_script('dashboard-dyn', LP_PLUGIN_URL . 'js/dashboard-dyn.' . $mode . '.js', array('jquery', 'lp-admin'), LP_PLUGIN_VERSION); } $lan = explode('_', get_locale()); if ('en' !== $lan[0]) { $timeago_lan = $lan[0]; switch (strtolower(get_locale())) { case 'pt_br': $timeago_lan = 'pt-br'; break; case 'zh_cn': $timeago_lan = 'zh-CN'; break; case 'zh_tw': $timeago_lan = 'zh-TW'; break; } wp_enqueue_script('jquery.timeago.' . $lan[0], LP_PLUGIN_URL . "js/locales/jquery.timeago.{$timeago_lan}.js", array('jquery.timeago')); $select2_lan = $lan[0]; switch (strtolower(get_locale())) { case 'pt_br': $select2_lan = 'pt-BR'; break; case 'pt_pt': $select2_lan = 'pt-PT'; break; case 'ug_cn': $select2_lan = 'ug-CN'; break; case 'zh_cn': $select2_lan = 'zh-CN'; break; case 'zh_tw': $select2_lan = 'zh-TW'; break; } wp_enqueue_script('select2_locale.' . $lan[0], LP_PLUGIN_URL . "js/locales/select2_locale_{$select2_lan}.js", array('lp-admin')); } $current_theme = str_replace(' ', '-', strtolower(wp_get_theme()->Name)); if (file_exists(LP_PLUGIN_PATH . 'css/themes/' . $current_theme . '.css')) { wp_register_style('livepress_theme_hacks', LP_PLUGIN_URL . 'css/themes/' . $current_theme . '.css'); wp_enqueue_style('livepress_theme_hacks'); } }
add_action('init', 'LivePress_XMLRPC::initialize'); } add_action('init', 'LivePress_Themes_Helper::instance'); // Custom Feeds (PuSH) add_action('wp', 'LivePress_Feed::initialize'); // Admin menu add_action('admin_menu', 'LivePress_Administration::initialize'); // Ajax response on server-side add_action('wp_ajax_lp_api_key_validate', 'LivePress_Administration::api_key_validate'); add_action('wp_ajax_lp_post_to_twitter', 'LivePress_Administration::post_to_twitter_ajaxed'); add_action('wp_ajax_lp_check_oauth_authorization_status', 'LivePress_Administration::check_oauth_authorization_status'); add_action('wp_ajax_lp_collaboration_comments_number', 'Collaboration::comments_number'); add_action('wp_ajax_lp_collaboration_get_live_edition_data', 'Collaboration::get_live_edition_data_ajax'); add_action('wp_ajax_lp_im_integration', 'LivePress_IM_Integration::initialize'); // Live Blogging Tools $blogging_tools = new LivePress_Blogging_Tools(); $blogging_tools->setup_tabs(); add_action('wp_ajax_lp_get_blogging_tools', array($blogging_tools, 'ajax_render_tabs')); add_action('wp_ajax_lp_update-live-notes', array($blogging_tools, 'update_author_notes')); add_action('wp_ajax_lp_update-live-comments', array($blogging_tools, 'update_live_comments')); add_action('wp_ajax_lp_update-live-status', array($blogging_tools, 'toggle_live_status')); add_action('manage_posts_custom_column', array($blogging_tools, 'display_posts_livestatus'), 10, 2); /** * Add custom column to post list. * * @param array $columns Array of columns * @param string $post_type Post type. * @return array Filtered array of columns. */ function add_livepress_status_column($columns, $post_type) {
/** * Extend a user's profile with some user-specific options. * * @author tddewey * * @param $user object WP User object for the user being edited */ function user_fields($user) { // Hide form based on permission to edit this profile or edited user to publish posts if (!current_user_can('edit_user', $user->ID) && user_can($user, 'publish_posts')) { return; } $lp_twitter = get_user_meta($user->ID, 'lp_twitter', true); // returns empty string if not set, perfect $lp_phone_number = get_user_meta($user->ID, 'lp_phone_number', true); // returns empty string if not set, perfect $lp_options = get_option('livepress'); // Only display this form if atremote twitter or remote SMS is allowed by an admin. if (isset($lp_options['allow_remote_twitter']) && $lp_options['allow_remote_twitter'] == 'allow' || isset($lp_options['allow_sms']) && $lp_options['allow_sms'] == 'allow') { ?> <h3>LivePress</h3> <table class="form-table"> <?php if (isset($lp_options['allow_remote_twitter']) && $lp_options['allow_remote_twitter'] == 'allow') { ?> <?php // Use actual password for VIP if (defined('WPCOM_IS_VIP_ENV') && true === WPCOM_IS_VIP_ENV) { ?> <tr> <th><label for="lp_user_password"><?php esc_html_e('WordPress password', 'livepress'); ?> </label></th> <td> <?php $blogging_tools = new LivePress_Blogging_Tools(); if ($blogging_tools->get_have_user_pass($user->ID)) { ?> <div class="password_already_saved">Password already saved. <a class="reset_lp_user_password"><?php esc_html_e('Reset password', 'livepress'); ?> </a></div> <div class="hidden_lp_user_password hidden"> <?php } else { ?> <div> <?php } ?> <input type="password" name="lp_user_password" id="lp_user_password" value="" class="regular-text" /> <table class="description"> <tr> <td><?php esc_html_e('Please enter your WordPress password to enable remote publishing', 'livepress'); ?> </td> </tr> </table> </td> </tr> <?php } ?> <tr> <th><label for="lp_twitter"><?php esc_html_e('Publish from Twitter', 'livepress'); ?> </label></th> <td class="input-prepend"> <span class="add-on">@</span><input type="text" name="lp_twitter" id="lp_twitter" value="<?php echo esc_attr($lp_twitter); ?> " class="regular-text" /> <table class="description"> <tr> <td><code>#lpon</code></td> <td><?php esc_html_e('Tweet this with a blog title to start publishing from Twitter', 'livepress'); ?> </td> </tr> <tr> <td></td> <td><?php esc_html_e('All tweets in between are live published to one post', 'livepress'); ?> </td> </tr> <tr> <td><code>#lpoff</code></td> <td><?php esc_html_e('Tweet this on your last update to stop', 'livepress'); ?> </td> </tr> </table> </td> </tr> <?php } if (isset($lp_options['allow_sms']) && $lp_options['allow_sms'] == 'allow') { ?> <tr> <th><label for="lp_phone_number"><?php esc_html_e('Your Mobile Phone Number, to publish from SMS', 'livepress'); ?> </label></th> <td class="input-prepend"> <input type="text" name="lp_phone_number" id="lp_phone_number" value="<?php echo esc_attr($lp_phone_number); ?> " class="regular-text" /> <table class="description"> <tr> <td colspan="2"><?php esc_html_e('Text commands from your phone to LivePress at: ', 'livepress'); ?> <a href="sms:14157020916">1-415-702-0916</a></td> </tr> <tr> <td><code>#new post title</code></td> <td><?php esc_html_e('Create a new live blog post with title "post title"', 'livepress'); ?> </td> </tr> <tr> <td><code>#list</code></td> <td><?php esc_html_e('List recent live blog posts', 'livepress'); ?> </td> </tr> <tr> <td colspan="2"><?php echo wp_kses_post(__('...and much more, for a complete list text <code>#help</code> to', 'livepress')); ?> <a href="sms:14157020916">1-415-702-0916</a></td> </tr> </table> </td> </tr> <?php } ?> </table> <?php } }
/** * Upgrade live status system. * * @static */ static function plugin_install() { $blogging_tools = new LivePress_Blogging_Tools(); $blogging_tools->upgrade_live_status_system(); // set default value of sharingUI if not set $livepress = get_option(self::$options_name); if (!array_key_exists('sharing_ui', $livepress)) { $livepress['sharing_ui'] = 'display'; update_option(self::$options_name, $livepress); } if (!array_key_exists('show', $livepress)) { $livepress['show'] = array('AUTHOR', 'TIME', 'HEADER'); update_option(self::$options_name, $livepress); } }
/** * Upgrade live status system. * * @static */ static function plugin_install() { $blogging_tools = new LivePress_Blogging_Tools(); $blogging_tools->upgrade_live_status_system(); }
/** * Called by livepress webservice to create a new live post. * Uses livepress_new_post() * * @param array $args { * An array of arguments. * @param int $blog_id Id of blog to to add post to. * @param string $username Username for action. * @param string $password Livepress generated user access key. * @param array $content_struct Initial post content. * @return Object Post object or false on error. * } */ function livepress_new_live_post($args) { $post = livepress_create_new_post($args); // If there was an error, return the error, else move along if (!is_a($post, 'WP_Post')) { return $post; } // Set the post live status to live $blogging_tools = new LivePress_Blogging_Tools(); $blogging_tools->set_post_live_status($post->ID, true); return $post; }