/** * The HTML image tag for the avatar from WP or Twitter based on user configuration. * * @static * * @param string $from The source of the avatar, can be "twitter" or "native". * @return string HTML image tag. */ public static function get_avatar_img_tag($from) { if (null === $from) { return; } global $user; $avatar_img_tag = get_avatar($user->ID, 30); if ($from === 'twitter' && LivePress_Administration::twitter_avatar_url()) { $avatar_img_tag = self::avatar_img_tag(LivePress_Administration::twitter_avatar_url()); } return $avatar_img_tag; }
/** * 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'); } }
/** * Install/upgrade required tables * * @todo Remove this. The new table(s) functionality has already been removed. * * @static */ static function install_or_upgrade() { $options = get_option(self::$options_name); if (get_option(self::$options_name . '_version') != LP_PLUGIN_VERSION) { Collaboration::install(); $postUpdater = new LivePress_Administration(); $postUpdater->merge_default_values(); update_option(self::$options_name . '_version', LP_PLUGIN_VERSION); } }
/** * Save the user settings. * * @author tddewey * * @param $user_id integer user ID being updated. * * @return integer returns the $user_id regardless of success or failure. */ function save_fields($user_id) { // Check permissions and nonce. if (!current_user_can('edit_user', $user_id) && wp_verify_nonce($_POST['_wpnonce'])) { return $user_id; } $old_lp_twitter = get_user_meta($user_id, 'lp_twitter', true); // returns empty string if not set, perfect $lp_twitter = isset($_POST['lp_twitter']) ? sanitize_text_field($_POST['lp_twitter']) : ''; $lp_user_password = isset($_POST['lp_user_password']) ? sanitize_text_field($_POST['lp_user_password']) : ''; if ($old_lp_twitter != $lp_twitter || '' !== $lp_user_password) { $user = get_userdata($user_id); $options = get_option(LivePress_Administration::$options_name); $livepress_com = new LivePress_Communication($options['api_key']); $error_message = ''; try { $return_code = $livepress_com->manage_remote_post_from_twitter($lp_twitter, $user->user_login); } catch (LivePress_Communication_Exception $e) { $return_code = $e->get_code(); $error_message = $e->getMessage(); } /* User not found at livepress, or password invalid, or WordPress password entered */ if ($return_code == 403 || '' !== $lp_user_password) { $la = new LivePress_Administration(); $error_message = $livepress_com->get_last_error_message(); if (!$la->enable_remote_post($user_id, $lp_user_password)) { $this->add_error('Error from the LivePress service: ', $error_message); } else { $error_message = ''; try { $return_code = $livepress_com->manage_remote_post_from_twitter($lp_twitter, $user->user_login); } catch (LivePress_Communication_Exception $e) { $return_code = $e->get_code(); $error_message = $e->getMessage(); } } } if ($return_code != 200 && $return_code != 'OK.') { if (strlen($error_message) > 0) { $this->add_error('Problem with setting twitter user: '******'Problem with setting twitter user: error #' . $return_code); // Show error code if no msg } } else { // No error if (empty($lp_twitter)) { // None left, delete meta delete_user_meta($user_id, 'lp_twitter'); } else { // Update meta with current lp_twitter update_user_meta($user_id, 'lp_twitter', $lp_twitter); } } } $old_lp_phone_number = get_user_meta($user_id, 'lp_phone_number', true); // returns empty string if not set, perfect $lp_phone_number = isset($_POST['lp_phone_number']) ? sanitize_text_field($_POST['lp_phone_number']) : ''; if ($old_lp_phone_number != $lp_phone_number) { $user = get_userdata($user_id); $options = get_option(LivePress_Administration::$options_name); $livepress_com = new LivePress_Communication($options['api_key']); $error_message = ''; try { $return_code = $livepress_com->set_phone_number($lp_phone_number, $user->user_login); } catch (LivePress_Communication_Exception $e) { $return_code = $e->get_code(); $error_message = $e->getMessage(); } if ($return_code == 403) { /* User not found at livepress, or password invalid */ $la = new LivePress_Administration(); $error_message = $livepress_com->get_last_error_message(); if (!$la->enable_remote_post($user_id, $lp_user_password)) { $this->add_error('Error from the LivePress service: ', $error_message); } else { $error_message = ''; try { $return_code = $livepress_com->set_phone_number($lp_phone_number, $user->user_login); } catch (LivePress_Communication_Exception $e) { $return_code = $e->get_code(); $error_message = $e->getMessage(); } } } if ($return_code != 200 && $return_code != 'OK.') { if (strlen($error_message) > 0) { $this->add_error('Problem with setting phone number: ' . $error_message); // Show existing error } else { $this->add_error('Problem with setting phone number: error #' . $return_code); // Show error code if no msg } } else { // No error if (empty($lp_phone_number)) { // None left, delete meta delete_user_meta($user_id, 'lp_phone_number'); } else { // Update meta with current lp_phone_number update_user_meta($user_id, 'lp_phone_number', $lp_phone_number); } } } return $user_id; }
private function avatar_html($author) { return ''; // come back later $lp_authors = LivePress_Administration::lp_get_authors(); error_log('lp_authors - ' . implode(' - ', $lp_authors['names'][0])); error_log('author - ' . $author); $output = ''; return '<div class="live-update-authors"><span class="live-update-author live-update-author-superadmin"><span class="lp-authorID">1</span><span class="live-author-gravatar"><a href="http://ms.bearne.ca/blog/author/superadmin/" target="_blank"><img alt="" src="http://0.gravatar.com/avatar/6eca4708c14b4aae041335e251dd3b12?s=96&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&r=G" class="avatar avatar-96 photo" height="96" width="96" /></a></span><span class="live-author-name"><a href="http://ms.bearne.ca/blog/author/superadmin/" target="_blank">superAdmin</a></span></span></div>'; }