From c7139f980ab1147d59ec66bfb5389315e04a58ab Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Tue, 16 Oct 2018 17:39:28 +0100 Subject: [PATCH] add private sites module --- _inc/client/lib/plans/constants.js | 1 + _inc/client/traffic/index.jsx | 10 + _inc/client/traffic/private.jsx | 59 ++ modules/module-headings.php | 479 +++++++------- modules/module-info.php | 7 + modules/private.php | 980 +++++++++++++++++++++++++++++ modules/private/private.php | 86 +++ 7 files changed, 1387 insertions(+), 235 deletions(-) create mode 100644 _inc/client/traffic/private.jsx create mode 100644 modules/private.php create mode 100644 modules/private/private.php diff --git a/_inc/client/lib/plans/constants.js b/_inc/client/lib/plans/constants.js index c82258dcb8e82..f3cf15bc66f45 100644 --- a/_inc/client/lib/plans/constants.js +++ b/_inc/client/lib/plans/constants.js @@ -92,6 +92,7 @@ export const FEATURE_SEO_TOOLS_JETPACK = 'seo-tools-jetpack'; export const FEATURE_WORDADS_JETPACK = 'wordads-jetpack'; export const FEATURE_GOOGLE_ANALYTICS_JETPACK = 'google-analytics-jetpack'; export const FEATURE_SEARCH_JETPACK = 'search-jetpack'; +export const FEATURE_PRIVATE_JETPACK = 'private-jetpack'; export function isMonthly( plan ) { return includes( JETPACK_MONTHLY_PLANS, plan ); diff --git a/_inc/client/traffic/index.jsx b/_inc/client/traffic/index.jsx index d36fac64c58ea..7653c3d09de44 100644 --- a/_inc/client/traffic/index.jsx +++ b/_inc/client/traffic/index.jsx @@ -15,6 +15,7 @@ import QuerySite from 'components/data/query-site'; import { SEO } from './seo'; import { GoogleAnalytics } from './google-analytics'; import { Ads } from './ads'; +import Private from './private'; import { SiteStats } from './site-stats'; import { RelatedPosts } from './related-posts'; import Search from './search'; @@ -42,6 +43,7 @@ export class Traffic extends React.Component { foundVerification = this.props.isModuleFound( 'verification-tools' ), foundSitemaps = this.props.isModuleFound( 'sitemaps' ), foundSearch = this.props.isModuleFound( 'search' ), + foundPrivateSites = this.props.isModuleFound( 'private' ), foundAnalytics = this.props.isModuleFound( 'google-analytics' ); if ( ! this.props.searchTerm && ! this.props.active ) { @@ -56,6 +58,7 @@ export class Traffic extends React.Component { ! foundVerification && ! foundSitemaps && ! foundAnalytics && + ! foundPrivateSites && ! foundSearch ) { return null; @@ -64,6 +67,13 @@ export class Traffic extends React.Component { return (
+ { + foundPrivateSites && ( + + ) + } { foundSearch && ( + +

{ __( 'Private sites can only be seen by you and users your approve.' ) }

+ + + { __( 'Make your site private' ) } + + + { module_enabled && ( + +

+ { __( 'Your site is only visible to you and users you approve.' ) } +

+
+ ) } +
+ + ); + } +} + +export default moduleSettingsForm( Private ); + diff --git a/modules/module-headings.php b/modules/module-headings.php index e688293a4b9a6..35275e5725c34 100644 --- a/modules/module-headings.php +++ b/modules/module-headings.php @@ -11,240 +11,245 @@ function jetpack_get_module_i18n( $key ) { static $modules; if ( ! isset( $modules ) ) { - $modules = array( - 'after-the-deadline' => array( + $modules = array( + 'after-the-deadline' => array( 'name' => _x( 'Spelling and Grammar', 'Module Name', 'jetpack' ), 'description' => _x( 'Check your spelling, style, and grammar', 'Module Description', 'jetpack' ), - ), - - 'carousel' => array( + ), + + 'carousel' => array( 'name' => _x( 'Carousel', 'Module Name', 'jetpack' ), 'description' => _x( 'Display images and galleries in a gorgeous, full-screen browsing experience', 'Module Description', 'jetpack' ), 'recommended description' => _x( 'Brings your photos and images to life as full-size, easily navigable galleries.', 'Jumpstart Description', 'jetpack' ), - ), - - 'comment-likes' => array( + ), + + 'comment-likes' => array( 'name' => _x( 'Comment Likes', 'Module Name', 'jetpack' ), 'description' => _x( 'Increase visitor engagement by adding a Like button to comments.', 'Module Description', 'jetpack' ), - ), - - 'comments' => array( + ), + + 'comments' => array( 'name' => _x( 'Comments', 'Module Name', 'jetpack' ), 'description' => _x( 'Let readers use WordPress.com, Twitter, Facebook, or Google+ accounts to comment', 'Module Description', 'jetpack' ), - ), - - 'contact-form' => array( + ), + + 'contact-form' => array( 'name' => _x( 'Contact Form', 'Module Name', 'jetpack' ), 'description' => _x( 'Insert a customizable contact form anywhere on your site.', 'Module Description', 'jetpack' ), 'recommended description' => _x( 'Adds a button to your post and page editors, allowing you to build simple forms to help visitors stay in touch.', 'Jumpstart Description', 'jetpack' ), - ), - - 'custom-content-types' => array( + ), + + 'custom-content-types' => array( 'name' => _x( 'Custom content types', 'Module Name', 'jetpack' ), 'description' => _x( 'Display different types of content on your site with custom content types.', 'Module Description', 'jetpack' ), - ), - - 'custom-css' => array( + ), + + 'custom-css' => array( 'name' => _x( 'Custom CSS', 'Module Name', 'jetpack' ), 'description' => _x( 'Tweak your site’s CSS without modifying your theme.', 'Module Description', 'jetpack' ), - ), - - 'enhanced-distribution' => array( + ), + + 'enhanced-distribution' => array( 'name' => _x( 'Enhanced Distribution', 'Module Name', 'jetpack' ), 'description' => _x( 'Increase reach and traffic.', 'Module Description', 'jetpack' ), - ), - - 'google-analytics' => array( + ), + + 'google-analytics' => array( 'name' => _x( 'Google Analytics', 'Module Name', 'jetpack' ), 'description' => _x( 'Set up Google Analytics without touching a line of code.', 'Module Description', 'jetpack' ), - ), - - 'gravatar-hovercards' => array( + ), + + 'gravatar-hovercards' => array( 'name' => _x( 'Gravatar Hovercards', 'Module Name', 'jetpack' ), 'description' => _x( 'Enable pop-up business cards over commenters’ Gravatars.', 'Module Description', 'jetpack' ), 'recommended description' => _x( 'Let commenters link their profiles to their Gravatar accounts, making it easy for your visitors to learn more about your community.', 'Jumpstart Description', 'jetpack' ), - ), - - 'infinite-scroll' => array( + ), + + 'infinite-scroll' => array( 'name' => _x( 'Infinite Scroll', 'Module Name', 'jetpack' ), 'description' => _x( 'Automatically load new content when a visitor scrolls', 'Module Description', 'jetpack' ), - ), - - 'json-api' => array( + ), + + 'json-api' => array( 'name' => _x( 'JSON API', 'Module Name', 'jetpack' ), 'description' => _x( 'Allow applications to securely access your content.', 'Module Description', 'jetpack' ), - ), - - 'latex' => array( + ), + + 'latex' => array( 'name' => _x( 'Beautiful Math', 'Module Name', 'jetpack' ), 'description' => _x( 'Use LaTeX markup for complex equations and other geekery.', 'Module Description', 'jetpack' ), - ), - - 'lazy-images' => array( + ), + + 'lazy-images' => array( 'name' => _x( 'Lazy Images', 'Module Name', 'jetpack' ), 'description' => _x( 'Lazy load images', 'Module Description', 'jetpack' ), 'recommended description' => _x( 'Lazy-loading images improve your site\'s speed and create a smoother viewing experience. Images will load as visitors scroll down the screen, instead of all at once.', 'Jumpstart Description', 'jetpack' ), - ), - - 'likes' => array( + ), + + 'likes' => array( 'name' => _x( 'Likes', 'Module Name', 'jetpack' ), 'description' => _x( 'Give visitors an easy way to show they appreciate your content.', 'Module Description', 'jetpack' ), - ), - - 'manage' => array( + ), + + 'manage' => array( 'name' => _x( 'Manage', 'Module Name', 'jetpack' ), 'description' => _x( 'Manage all of your sites from a centralized dashboard.', 'Module Description', 'jetpack' ), 'recommended description' => _x( 'Helps you remotely manage plugins, turn on automated updates, and more from wordpress.com.', 'Jumpstart Description', 'jetpack' ), - ), - - 'markdown' => array( + ), + + 'markdown' => array( 'name' => _x( 'Markdown', 'Module Name', 'jetpack' ), 'description' => _x( 'Write posts or pages in plain-text Markdown syntax', 'Module Description', 'jetpack' ), - ), - - 'masterbar' => array( + ), + + 'masterbar' => array( 'name' => _x( 'WordPress.com Toolbar', 'Module Name', 'jetpack' ), 'description' => _x( 'Replaces the admin bar with a useful toolbar to quickly manage your site via WordPress.com.', 'Module Description', 'jetpack' ), - ), - - 'minileven' => array( + ), + + 'minileven' => array( 'name' => _x( 'Mobile Theme', 'Module Name', 'jetpack' ), 'description' => _x( 'Enable the Jetpack Mobile theme', 'Module Description', 'jetpack' ), - ), - - 'monitor' => array( + ), + + 'monitor' => array( 'name' => _x( 'Monitor', 'Module Name', 'jetpack' ), 'description' => _x( 'Receive immediate notifications if your site goes down, 24/7.', 'Module Description', 'jetpack' ), 'recommended description' => _x( 'Receive immediate notifications if your site goes down, 24/7.', 'Jumpstart Description', 'jetpack' ), - ), - - 'notes' => array( + ), + + 'notes' => array( 'name' => _x( 'Notifications', 'Module Name', 'jetpack' ), 'description' => _x( 'Receive instant notifications of site comments and likes.', 'Module Description', 'jetpack' ), - ), - - 'photon-cdn' => array( - 'name' => _x( 'Photon CDN', 'Module Name', 'jetpack' ), + ), + + 'photon-cdn' => array( + 'name' => _x( 'Asset CDN', 'Module Name', 'jetpack' ), 'description' => _x( 'Serve static assets from our servers', 'Module Description', 'jetpack' ), - ), - - 'photon' => array( + ), + + 'photon' => array( 'name' => _x( 'Photon', 'Module Name', 'jetpack' ), 'description' => _x( 'Serve images from our servers', 'Module Description', 'jetpack' ), 'recommended description' => _x( 'Mirrors and serves your images from our free and fast image CDN, improving your site’s performance with no additional load on your servers.', 'Jumpstart Description', 'jetpack' ), - ), - - 'post-by-email' => array( + ), + + 'post-by-email' => array( 'name' => _x( 'Post by email', 'Module Name', 'jetpack' ), 'description' => _x( 'Publish posts by sending an email', 'Module Description', 'jetpack' ), - ), - - 'protect' => array( + ), + + 'private' => array( + 'name' => _x( 'Private sites', 'Module Name', 'jetpack' ), + 'description' => _x( 'Make your site only visible to you and users you approve.', 'Module Description', 'jetpack' ), + ), + + 'protect' => array( 'name' => _x( 'Protect', 'Module Name', 'jetpack' ), 'description' => _x( 'Block suspicious-looking sign in activity', 'Module Description', 'jetpack' ), - ), - - 'publicize' => array( + ), + + 'publicize' => array( 'name' => _x( 'Publicize', 'Module Name', 'jetpack' ), 'description' => _x( 'Automated social marketing.', 'Module Description', 'jetpack' ), - ), - - 'pwa' => array( + ), + + 'pwa' => array( 'name' => _x( 'Progressive Web Apps', 'Module Name', 'jetpack' ), 'description' => _x( 'Speed up and improve the reliability of your site using the latest in web technology.', 'Module Description', 'jetpack' ), - ), - - 'related-posts' => array( + ), + + 'related-posts' => array( 'name' => _x( 'Related posts', 'Module Name', 'jetpack' ), 'description' => _x( 'Increase page views by showing related content to your visitors.', 'Module Description', 'jetpack' ), 'recommended description' => _x( 'Keep visitors engaged on your blog by highlighting relevant and new content at the bottom of each published post.', 'Jumpstart Description', 'jetpack' ), - ), - - 'search' => array( + ), + + 'search' => array( 'name' => _x( 'Search', 'Module Name', 'jetpack' ), 'description' => _x( 'Enhanced search, powered by Elasticsearch', 'Module Description', 'jetpack' ), - ), - - 'seo-tools' => array( + ), + + 'seo-tools' => array( 'name' => _x( 'SEO Tools', 'Module Name', 'jetpack' ), 'description' => _x( 'Better results on search engines and social media.', 'Module Description', 'jetpack' ), - ), - - 'sharedaddy' => array( + ), + + 'sharedaddy' => array( 'name' => _x( 'Sharing', 'Module Name', 'jetpack' ), 'description' => _x( 'Allow visitors to share your content.', 'Module Description', 'jetpack' ), 'recommended description' => _x( 'Twitter, Facebook and Google+ buttons at the bottom of each post, making it easy for visitors to share your content.', 'Jumpstart Description', 'jetpack' ), - ), - - 'shortcodes' => array( + ), + + 'shortcodes' => array( 'name' => _x( 'Shortcode Embeds', 'Module Name', 'jetpack' ), 'description' => _x( 'Embed media from popular sites without any coding.', 'Module Description', 'jetpack' ), - ), - - 'shortlinks' => array( + ), + + 'shortlinks' => array( 'name' => _x( 'WP.me Shortlinks', 'Module Name', 'jetpack' ), 'description' => _x( 'Create short and simple links for all posts and pages.', 'Module Description', 'jetpack' ), - ), - - 'sitemaps' => array( + ), + + 'sitemaps' => array( 'name' => _x( 'Sitemaps', 'Module Name', 'jetpack' ), 'description' => _x( 'Make it easy for search engines to find your site.', 'Module Description', 'jetpack' ), - ), - - 'sso' => array( - 'name' => _x( 'Single Sign On', 'Module Name', 'jetpack' ), + ), + + 'sso' => array( + 'name' => _x( 'Secure Sign On', 'Module Name', 'jetpack' ), 'description' => _x( 'Allow users to log into this site using WordPress.com accounts', 'Module Description', 'jetpack' ), 'recommended description' => _x( 'Lets you log in to all your Jetpack-enabled sites with one click using your WordPress.com account.', 'Jumpstart Description', 'jetpack' ), - ), - - 'stats' => array( + ), + + 'stats' => array( 'name' => _x( 'Site Stats', 'Module Name', 'jetpack' ), 'description' => _x( 'Collect valuable traffic stats and insights.', 'Module Description', 'jetpack' ), - ), - - 'subscriptions' => array( + ), + + 'subscriptions' => array( 'name' => _x( 'Subscriptions', 'Module Name', 'jetpack' ), 'description' => _x( 'Allow users to subscribe to your posts and comments and receive notifications via email', 'Module Description', 'jetpack' ), 'recommended description' => _x( 'Give visitors two easy subscription options — while commenting, or via a separate email subscription widget you can display.', 'Jumpstart Description', 'jetpack' ), - ), - - 'tiled-gallery' => array( + ), + + 'tiled-gallery' => array( 'name' => _x( 'Tiled Galleries', 'Module Name', 'jetpack' ), 'description' => _x( 'Display image galleries in a variety of elegant arrangements.', 'Module Description', 'jetpack' ), 'recommended description' => _x( 'Display image galleries in a variety of elegant arrangements.', 'Jumpstart Description', 'jetpack' ), - ), - - 'vaultpress' => array( + ), + + 'vaultpress' => array( 'name' => _x( 'Data Backups', 'Module Name', 'jetpack' ), 'description' => _x( 'Off-site backups, security scans, and automatic fixes.', 'Module Description', 'jetpack' ), - ), - - 'verification-tools' => array( + ), + + 'verification-tools' => array( 'name' => _x( 'Site verification', 'Module Name', 'jetpack' ), 'description' => _x( 'Establish your site\'s authenticity with external services.', 'Module Description', 'jetpack' ), - ), - - 'videopress' => array( + ), + + 'videopress' => array( 'name' => _x( 'VideoPress', 'Module Name', 'jetpack' ), 'description' => _x( 'Fast, ad-free video hosting', 'Module Description', 'jetpack' ), - ), - - 'widget-visibility' => array( + ), + + 'widget-visibility' => array( 'name' => _x( 'Widget Visibility', 'Module Name', 'jetpack' ), 'description' => _x( 'Control where widgets appear on your site.', 'Module Description', 'jetpack' ), - ), - - 'widgets' => array( + ), + + 'widgets' => array( 'name' => _x( 'Extra Sidebar Widgets', 'Module Name', 'jetpack' ), 'description' => _x( 'Add images, Twitter streams, and more to your sidebar.', 'Module Description', 'jetpack' ), - ), - - 'wordads' => array( + ), + + 'wordads' => array( 'name' => _x( 'Ads', 'Module Name', 'jetpack' ), 'description' => _x( 'Earn income by allowing Jetpack to display high quality ads.', 'Module Description', 'jetpack' ), - ), + ), ); - } + } return $modules[ $key ]; } /** @@ -253,107 +258,111 @@ function jetpack_get_module_i18n( $key ) { * @param string $key Module tag as is in each module heading. * * @return string - */ + */ function jetpack_get_module_i18n_tag( $key ) { static $module_tags; - if ( ! isset( $module_tags ) ) { - $module_tags = array( - // Modules with `Other` tag: - // - modules/contact-form.php - // - modules/notes.php - 'Other' =>_x( 'Other', 'Module Tag', 'jetpack' ), - - // Modules with `Writing` tag: - // - modules/after-the-deadline.php - // - modules/custom-content-types.php - // - modules/enhanced-distribution.php - // - modules/json-api.php - // - modules/latex.php - // - modules/markdown.php - // - modules/post-by-email.php - // - modules/shortcodes.php - 'Writing' =>_x( 'Writing', 'Module Tag', 'jetpack' ), - - // Modules with `Photos and Videos` tag: - // - modules/carousel.php - // - modules/photon-cdn.php - // - modules/photon.php - // - modules/shortcodes.php - // - modules/tiled-gallery.php - // - modules/videopress.php - 'Photos and Videos' =>_x( 'Photos and Videos', 'Module Tag', 'jetpack' ), - - // Modules with `Social` tag: - // - modules/comment-likes.php - // - modules/comments.php - // - modules/gravatar-hovercards.php - // - modules/likes.php - // - modules/publicize.php - // - modules/seo-tools.php - // - modules/sharedaddy.php - // - modules/shortcodes.php - // - modules/shortlinks.php - // - modules/subscriptions.php - // - modules/widgets.php - 'Social' =>_x( 'Social', 'Module Tag', 'jetpack' ), - - // Modules with `Appearance` tag: - // - modules/custom-css.php - // - modules/gravatar-hovercards.php - // - modules/infinite-scroll.php - // - modules/lazy-images.php - // - modules/minileven.php - // - modules/photon-cdn.php - // - modules/photon.php - // - modules/seo-tools.php - // - modules/shortcodes.php - // - modules/widget-visibility.php - // - modules/widgets.php - // - modules/wordads.php - 'Appearance' =>_x( 'Appearance', 'Module Tag', 'jetpack' ), - - // Modules with `Developers` tag: - // - modules/json-api.php - // - modules/pwa.php - // - modules/sso.php - 'Developers' =>_x( 'Developers', 'Module Tag', 'jetpack' ), - - // Modules with `Recommended` tag: - // - modules/lazy-images.php - // - modules/manage.php - // - modules/minileven.php - // - modules/monitor.php - // - modules/photon-cdn.php - // - modules/photon.php - // - modules/protect.php - // - modules/publicize.php - // - modules/related-posts.php - // - modules/sharedaddy.php - // - modules/sitemaps.php - // - modules/stats.php - 'Recommended' =>_x( 'Recommended', 'Module Tag', 'jetpack' ), - - // Modules with `Centralized Management` tag: - // - modules/manage.php - 'Centralized Management' =>_x( 'Centralized Management', 'Module Tag', 'jetpack' ), - - // Modules with `General` tag: - // - modules/masterbar.php - 'General' =>_x( 'General', 'Module Tag', 'jetpack' ), - - // Modules with `Mobile` tag: - // - modules/minileven.php - 'Mobile' =>_x( 'Mobile', 'Module Tag', 'jetpack' ), - - // Modules with `Traffic` tag: - // - modules/sitemaps.php - // - modules/wordads.php - 'Traffic' =>_x( 'Traffic', 'Module Tag', 'jetpack' ), - - // Modules with `Site Stats` tag: - // - modules/stats.php - 'Site Stats' =>_x( 'Site Stats', 'Module Tag', 'jetpack' ), + if ( ! isset( $module_tags ) ) { + $module_tags = array( + // Modules with `Other` tag: + // - modules/contact-form.php + // - modules/notes.php + 'Other' =>_x( 'Other', 'Module Tag', 'jetpack' ), + + // Modules with `Writing` tag: + // - modules/after-the-deadline.php + // - modules/custom-content-types.php + // - modules/enhanced-distribution.php + // - modules/json-api.php + // - modules/latex.php + // - modules/markdown.php + // - modules/post-by-email.php + // - modules/shortcodes.php + 'Writing' =>_x( 'Writing', 'Module Tag', 'jetpack' ), + + // Modules with `Photos and Videos` tag: + // - modules/carousel.php + // - modules/photon-cdn.php + // - modules/photon.php + // - modules/shortcodes.php + // - modules/tiled-gallery.php + // - modules/videopress.php + 'Photos and Videos' =>_x( 'Photos and Videos', 'Module Tag', 'jetpack' ), + + // Modules with `Social` tag: + // - modules/comment-likes.php + // - modules/comments.php + // - modules/gravatar-hovercards.php + // - modules/likes.php + // - modules/publicize.php + // - modules/seo-tools.php + // - modules/sharedaddy.php + // - modules/shortcodes.php + // - modules/shortlinks.php + // - modules/subscriptions.php + // - modules/widgets.php + 'Social' =>_x( 'Social', 'Module Tag', 'jetpack' ), + + // Modules with `Appearance` tag: + // - modules/custom-css.php + // - modules/gravatar-hovercards.php + // - modules/infinite-scroll.php + // - modules/lazy-images.php + // - modules/minileven.php + // - modules/photon-cdn.php + // - modules/photon.php + // - modules/seo-tools.php + // - modules/shortcodes.php + // - modules/widget-visibility.php + // - modules/widgets.php + // - modules/wordads.php + 'Appearance' =>_x( 'Appearance', 'Module Tag', 'jetpack' ), + + // Modules with `Developers` tag: + // - modules/json-api.php + // - modules/pwa.php + // - modules/sso.php + 'Developers' =>_x( 'Developers', 'Module Tag', 'jetpack' ), + + // Modules with `Recommended` tag: + // - modules/lazy-images.php + // - modules/manage.php + // - modules/minileven.php + // - modules/monitor.php + // - modules/photon-cdn.php + // - modules/photon.php + // - modules/protect.php + // - modules/publicize.php + // - modules/related-posts.php + // - modules/sharedaddy.php + // - modules/sitemaps.php + // - modules/stats.php + 'Recommended' =>_x( 'Recommended', 'Module Tag', 'jetpack' ), + + // Modules with `Centralized Management` tag: + // - modules/manage.php + 'Centralized Management' =>_x( 'Centralized Management', 'Module Tag', 'jetpack' ), + + // Modules with `General` tag: + // - modules/masterbar.php + 'General' =>_x( 'General', 'Module Tag', 'jetpack' ), + + // Modules with `Mobile` tag: + // - modules/minileven.php + 'Mobile' =>_x( 'Mobile', 'Module Tag', 'jetpack' ), + + // Modules with `Private` tag: + // - modules/private.php + 'Private' =>_x( 'Private', 'Module Tag', 'jetpack' ), + + // Modules with `Traffic` tag: + // - modules/sitemaps.php + // - modules/wordads.php + 'Traffic' =>_x( 'Traffic', 'Module Tag', 'jetpack' ), + + // Modules with `Site Stats` tag: + // - modules/stats.php + 'Site Stats' =>_x( 'Site Stats', 'Module Tag', 'jetpack' ), ); - } + } return $module_tags[ $key ]; -} +} \ No newline at end of file diff --git a/modules/module-info.php b/modules/module-info.php index 08daf5c78fe41..b446bee64d6a9 100644 --- a/modules/module-info.php +++ b/modules/module-info.php @@ -699,3 +699,10 @@ function jetpack_assetcdn_more_info() { ); } add_action( 'jetpack_module_more_info_photon-cdn', 'jetpack_assetcdn_more_info' ); + +function jetpack_private() { + esc_html_e( + 'Allows private and unlaunched sites, visible only to yourself and those you invite.' + ); +} +add_action( 'jetpack_module_more_info_private', 'jetpack_private' ); diff --git a/modules/private.php b/modules/private.php new file mode 100644 index 0000000000000..216ae8e3e54cc --- /dev/null +++ b/modules/private.php @@ -0,0 +1,980 @@ + $v ) { + $this->$k = $v; + } + + $this->maybe_skip_this_blog(); + $this->last_link_was_privatized = false; + } + + function is_a8c_to_a8c( $url ) { + global $blog_id; + + // These are static so that we only preform these operations once per execution + static $a8c_p2_blog_ids = null; + static $a8c_p2_blog_domains = null; + + // populate our list of a8c p2 blog_ids + if ( null === $a8c_p2_blog_ids ) { + global $automattic_p2s; + require_once ABSPATH . '/.config/p2-list.php'; + $a8c_p2_blog_ids = array_map( 'absint', array_merge( $automattic_p2s['teams'], $automattic_p2s['projects'] ) ); + } + + // if this isn't an a8c p2 then stop here... + if ( false === in_array( $blog_id, $a8c_p2_blog_ids ) ) { + return false; + } + + // wp.me links give us the blog id encoded into the uri so there's no need + // to hit the database to find out if this link is to another a8c p2 + if ( preg_match( '@^https?://wp.me/[pam]([^-]+)-[^-]+$@i', $url, $m ) > 0 ) { + return in_array( sixtwo2dec( $m[1] ), $a8c_p2_blog_ids ); + } + + // get an array containing all the a8c p2 domain names + if ( null === $a8c_p2_blog_domains ) { + global $wpdb; + // "Use placeholders and $wpdb->prepare(); found $a8c_p2_blog_ids" -- Sometimes + // I feel like automated linting just doesn't "get" me... :) + $a8c_p2_blog_domains = $wpdb->get_col( sprintf( + 'SELECT `domain` FROM `wp_blogs` WHERE `blog_id` IN(%s) LIMIT %d', implode( ',', $a8c_p2_blog_ids ), count( $a8c_p2_blog_ids ) + ) ); + } + + // return true if this link is to a domain in our list... + return in_array( preg_replace( '/\.files\.wordpress\.com$/i','.wordpress.com', parse_url( $url, PHP_URL_HOST ) ), $a8c_p2_blog_domains ); + } + + function maybe_skip_this_blog() { + if ( !$this->skip_this_blog_links ) { + $this->skip_this_blog_domains = array(); + } + + list( $blog_name ) = explode( '.', parse_url( site_url(), PHP_URL_HOST ), 2 ); + + $this->skip_this_blog_domains = array( + "$blog_name.wordpress.com", + "$blog_name.files.wordpress.com", + parse_url( home_url(), PHP_URL_HOST ), + ); + } + + function privatize_url( $url ) { + $this->last_link_was_privatized = false; + $host = parse_url( $url, PHP_URL_HOST ); + if ( in_array( $host, $this->skip_domains ) || in_array( $host, $this->skip_this_blog_domains ) ) { + return $url; + } + + if ( $this->is_a8c_to_a8c( $url ) ) { + return $url; + } + + if ( wp_startswith( $url, '//' ) ) { + $url = http() . ":$url"; + } + + // Don't double-prefix + // This is usually a result of people copy/pasting an already privatized link + if ( $this->hide_url && wp_startswith( $url, $this->hide_url ) ) { + $url = substr( $url, strlen( $this->hide_url ) ); + } + + $this->last_link_was_privatized = true; + return $this->hide_url . $url; + } + + function privatize_link( $link ) { + if ( is_array( $link ) ) { // preg callback + $link = $link[0]; + } + + $this->last_link_was_privatized = false; + $did_rel = false; + + $dom = new DOMDocument; + $link = mb_convert_encoding( $link, 'HTML-ENTITIES', 'UTF-8' ); + // The @ is not enough to suppress errors when dealing with libxml, + // we have to tell it directly how we want to handle errors. + libxml_use_internal_errors( TRUE ); + @$dom->loadHTML( "$link" ); // suppress parser warnings + libxml_use_internal_errors( FALSE ); + $link_node = false; + foreach ( $dom->childNodes as $child ) { + if ( XML_ELEMENT_NODE === $child->nodeType && 'html' === strtolower( $child->tagName ) ) { + $link_node = $child->firstChild->firstChild; + break; + } + } + + if ( !$link_node ) { + return $link; + } + + if ( !$link_node->hasAttribute( 'href' ) ) { + return $link; + } + + $href = $link_node->getAttribute( 'href' ); + + if ( preg_match( '#^(?:\w+:)?//#', $href ) ) { + $link_node->setAttribute( 'href', $this->privatize_url( $href ) ); + } + + if ( $this->last_link_was_privatized ) { + if ( $link_node->hasAttribute( 'rel' ) ) { + $rels = preg_split( '#\s+#', $link_node->getAttribute( 'rel' ), PREG_SPLIT_NO_EMPTY ); + $rels[] = 'noreferrer'; + $rel = join( ' ', $rels ); + } else { + $rel = 'noreferrer'; + } + $link_node->setAttribute( 'rel', $rel ); + } + + $link = $dom->saveXML( $link_node ); + $link = rtrim( $link, '/>' ) . '>'; + + return $link; + } + + function privatize_links( $html ) { + return preg_replace_callback( '#]+>#i', array( $this, 'privatize_link' ), $html ); + } +} + +function privatize_blog( $wp ) { + global $pagenow, $current_user, $wpdb; + + /*if ( '-1' != get_option('blog_public') ) + return;*/ + + if ( !get_option('links_public') ) { + add_filter( 'the_content', 'privatize_links', 121 ); + add_filter( 'comment_text', 'privatize_links', 121 ); + add_filter( 'widget_text', 'privatize_links', 121 ); + add_filter( 'privatize_links', 'privatize_links', 121 ); + } + + if ( 'wp-login.php' == $pagenow ) + return; + + if ( defined( 'WP_CLI' ) && WP_CLI ) + return; + + if ( defined( 'WPCOM_JOBS' ) && WPCOM_JOBS ) + return; + + // Serve robots.txt for private blogs. + if ( is_object( $wp ) && !empty( $wp->query_vars['robots'] ) ) + return; + + // Go ahead and allow trackbacks. +// if ( is_object($wp) && !empty($wp->query_vars['tb']) ) +// return; + + if ( $current_user ) { + if ( is_super_admin() || is_private_blog_user($wpdb->blogid, $current_user) ) + return; + } + +// if ( !empty($wp->query_vars['feed']) && check_feedauth() ) +// return; + + remove_action( 'wp_head', array( 'Jetpack_Custom_CSS', 'link_tag' ), 101 ); + + if ( file_exists(TEMPLATEPATH . '/private.php' ) ) + include(TEMPLATEPATH . '/private.php' ); + else if ( file_exists(ABSPATH . 'wp-content/plugins/jetpack/modules/private/private.php' ) ) + include(ABSPATH . 'wp-content/plugins/jetpack/modules/private/private.php' ); + else + _e( 'This site is private.' ); + + exit; +} + +/** + * Does not check whether the blog is private. Accepts blog and user in various types. + * Returns true for super admins; if you don't want that, use is_really_private_blog_user. + */ +function is_private_blog_user( $blog, $user ) { + global $wpdb; + + if ( !is_object($user) ) + $user = new WP_User($user); + + if ( !$user->ID ) + return false; + + $user_id = $user->data->ID; + + if ( is_numeric($blog) ) + $blog_id = intval($blog); + elseif ( is_object($blog) ) + $blog_id = $blog->blog_id; + elseif ( is_string($blog) ) + { + $blog = get_blog_info($blog, '/', 1); + $blog_id = $blog->blog_id; + } + else + $blog_id = $wpdb->blogid; + + if ( is_really_private_blog_user( $blog_id, $user_id ) ) + return true; + + // check if the user has read permissions + $the_user = wp_clone( $user ); + $the_user->for_blog( $blog_id ); + return $the_user->has_cap( 'read' ); +} + +function is_really_private_blog_user( $blog = null, $user = null ) { + global $wpdb; + + if ( !isset( $blog ) ) + $blog_id = $wpdb->blogid; + elseif ( is_numeric($blog) ) + $blog_id = intval($blog); + elseif ( is_object($blog) ) + $blog_id = $blog->blog_id; + else { + $blog = get_blog_info($blog, '/', 1); + $blog_id = $blog->blog_id; + } + + if ( !$blog_id ) + return false; + + if ( !isset( $user ) ) + $user = wp_get_current_user(); + + if ( !is_object($user) ) + $user = new WP_User($user); + + if ( !$user->ID ) + return false; + + $user_id = $user->data->ID; + + $key = "private_blog_user_{$blog_id}_{$user_id}"; + $cache = wp_cache_get( $key, 'users' ); + if ( $cache ) + return $cache === 'y' ? true : false; + + $result = (bool) $wpdb->get_row( $wpdb->prepare( + "SELECT blog_id FROM drama_blog_access WHERE blog_id = %d AND user_id = %d", + $blog_id, $user_id ) ); + + wp_cache_set( $key, $result ? 'y' : 'n', 'users' ); + + return $result; +} + +/** + * Tests whether the current blog is private and not spam/suspended/deleted. + */ +function is_private_blog( $_blog_id = null ) { + return true; + global $blog_id; + + if ( empty( $_blog_id ) ) + $_blog_id = $blog_id; + + $blog_details = get_blog_details( $_blog_id ); + + return ( ( '-1' == $blog_details->public ) && + ( !isset( $blog_details->deleted ) || !$blog_details->deleted ) && + ( !isset( $blog_details->archived ) || !$blog_details->archived ) && + ( !isset( $blog_details->spam ) || !$blog_details->spam ) + ); +} + +function privatize_links( $content ) { // Only for href links right now, not images or such + static $hide_referrer = false; + if ( !$hide_referrer ) { + $hide_referrer = new WPCOM_NoReferrer(); + } + + $hide_referrer->maybe_skip_this_blog(); + + return $hide_referrer->privatize_links( $content ); +} + +function check_feedauth() { + global $blog_id; + + if ( isset( $_GET['feedauth'] ) ) { + $users = get_users_of_blog($blog_id); + if ( is_array($users) ) + foreach ( $users as $user ) + if ( create_feedauth( $user->user_id ) === $_GET['feedauth'] ) + return true; + $users = get_private_blog_users($blog_id); + if ( is_array($users) ) + foreach ( $users as $user_id ) + if ( create_feedauth( $user_id ) === $_GET['feedauth'] ) + return true; + } + + return false; +} + +function create_feedauth( $user_id = null, $blog_id = null ) { + if ( !isset($user_id) ) + $user_id = $GLOBALS['current_user']->ID; + if ( !isset($blog_id) ) + $blog_id = $GLOBALS['blog_id']; + return wp_hash( "feedauth_{$user_id}_{$blog_id}" ); +} + +function privatize_blog_comments( $comment ) { + privatize_blog(null); + return $comment; +} + +function private_blog_user_limit() { + return false; +} + +function privatize_blog_priv_selector() { +?> +
/> + + + + +

Want more?' ), $user_limit ); +else + _e( 'Users allowed to access site:' ); +?>

+ +blogid ); + +if ( false == $user_limit || ( true == $user_limit && count( $current_users ) < $user_limit ) ) { + echo '

' . __( 'Invite viewers to your blog' ) . '

'; +} + +if ( count( $current_users ) > 0 ) { + echo '

' . __( 'Current site members:' ) . '

'; + echo "
    "; + foreach ( $current_users as $u ) { + $user = get_userdata( $u ); + echo "
  1. $user->user_login"; + echo "   "; + wp_nonce_field( 'remove_user_' . $user->ID, '_wpnonce_remove_' . $user->ID ,false, true); + echo "
  2. "; + } + echo "
"; +} else { + ?> +

+ + + +
+

/> +

+
+ +

' . $message . '.

'; + } + } + +} + + +/** + * Hides the blog's name on the login form for private blogs. + */ +function privatize_blog_maybe_mask_blog_name() { + if ( ! is_private_blog() ) + return; + + add_filter( 'bloginfo', 'privatize_blog_mask_blog_name', 3, 2 ); +} + +/** + * Replaces the the blog's "name" value with "Protected Blog" + * + * @see privatize_blog_maybe_mask_blog_name() + */ +function privatize_blog_mask_blog_name( $value, $what ) { + if ( in_array( $what, array( 'name', 'title' ) ) ) { + $value = __( 'Protected Blog' ); + } + + return $value; +} + + +add_action( 'admin_notices', 'privatize_blog_updated_message' ); +add_action( 'parse_request', 'privatize_blog', 100 ); +add_action( 'login_init', 'privatize_blog_maybe_mask_blog_name' ); +add_filter( 'preprocess_comment', 'privatize_blog_comments' ); +add_action( 'blog_privacy_selector', 'privatize_blog_priv_selector' ); +add_filter( 'whitelist_options', 'privatize_blog_option_whitelist' ); + +// So that users can't request access to private Automattic sites. +function private_blog_accepts_invites( $blog_id = 0 ) { + if ( ! $blog_id ) { + $blog_id = get_current_blog_id(); + } + + if ( isset( $allow_private_blog_request[$blog_id] ) && $allow_private_blog_request[$blog_id] ) { + return true; + } + + /*if ( is_automattic_private( $blog_id ) ) { + return false; + }*/ + + return true; +} + +/** + * Allow logged-in, non blog users to request access to a blog from + * blog administrator. Sends notification email. + */ +function handle_private_blog_access_request() { + global $blog_id, $current_user; + + if ( ! private_blog_accepts_invites() ) { + return false; + } + + if ( !is_private_blog() || !is_user_logged_in() || !isset( $_GET['action'] ) || $_GET['action'] != 'request_access' || !isset( $_GET[ 'nonce' ] ) || !wp_verify_nonce( $_GET[ 'nonce' ], "request_access_$blog_id" ) ) + return false; + + // Generate and send the requesting email + $admin_email = apply_filters( 'wpcom_privacy_access_admin_email', get_bloginfo( 'admin_email' ) ); + $site_name = get_bloginfo( 'name' ); + $home_url = trailingslashit( get_home_url() ); + $subject = sprintf( __( "[%s] WordPress.com user '%s' requested access to your private site" ), $site_name, $current_user->user_login ); + $message = __( "Howdy," ); + $message .= "\n\n"; + // Only use the display name if they have a different one than the username + if ( $current_user->user_login != $current_user->display_name ) + $name .= "$current_user->display_name (username '$current_user->user_login')"; + else + $name .= "'$current_user->user_login'"; + + $message .= sprintf( __( "The WordPress.com user %s requested access to view your private site at %s" ), $name, $home_url ); + $message .= "\n\n"; + $message .= __( "Want to give them access to view this site? Click on this link: " ); + $message .= add_query_arg( 'user_login', $current_user->user_login, add_query_arg( 'action', 'add_user', get_home_url( $blog_id, 'wp-admin/options-reading.php' ) ) ); + $message .= "\n\n"; + $message .= sprintf( __( "If you don't want this person to be able to view %s, simply ignore this email, and they will not receive access to your private site." ), $home_url ); + $message .= "\n\n"; + $message .= sprintf( __( "To see a list of users who have access to %s, visit %s" ), $home_url, get_home_url( $blog_id, 'wp-admin/options-reading.php' ) ); + $message .= "\n\n"; + $message .= __( "Cheers," ); + $message .= "\n\n"; + $message .= __( "The WordPress.com Team" ); + wp_mail( $admin_email, $subject, $message ); + + bump_stats_extras( 'wpcom_privacy_access', 'request_access' ); + + // Redirect requester back where they came + wp_safe_redirect( get_site_url( $blog_id, '?request_access=success' ) ); + die(); +} +add_action( 'parse_request', 'handle_private_blog_access_request', 20 ); + +/** + * handle_add_private_blog_user_from_email() + * Blog admin uses one-click add user to private blog link in notification email + * + * @uses add_private_blog_user() + * @return void + */ +function handle_add_private_blog_user_from_email() { + global $pagenow; + + if ( !is_private_blog() || !isset( $_GET['action'] ) || $_GET['action'] != 'add_user' || $pagenow != 'options-reading.php' || !current_user_can( 'manage_options' ) ) + return false; + + $user_login = sanitize_user( $_GET['user_login'] ); + $user_to_add = get_user_by( 'login', $user_login ); + if ( !$user_to_add ) { + $message = 'user-not-found'; + wp_safe_redirect( add_query_arg( 'updated', $message, get_option( 'siteurl' ) . '/wp-admin/options-reading.php' ) ); + die(); + } + + $title = __( 'Privacy Settings' ); + $caution_message = __( 'You are about to give this user permission to view your private site:' ); + $ignore_message = 'ignore-request'; + $ignore_url = add_query_arg( 'updated', $ignore_message, admin_url( 'options-reading.php' ) ); + + $submit_button = __( 'Grant Access to User' ); + + // Only use the display name if they have a different one than the username + if ( $user_to_add->user_login != $user_to_add->display_name ) + $requesting_user .= esc_html( $user_to_add->display_name ) . '
' . esc_html( $user_to_add->user_login ) . ''; + else + $requesting_user .= esc_html( $user_to_add->user_login ); + + require_once( ABSPATH . 'wp-admin/admin-header.php' ); + ?> + +
+ +
+ + +

+ +

+ + + + + + +
user_email, 48 ); ?>
+ +

+ +
+ + + + + + +
+ + + + +
+ +
+
+ + prepare( + "SELECT user_id FROM drama_blog_access WHERE blog_id = %d AND user_id = %d", $blog_id, $user_id + ); + + $result = $wpdb->query( $query ); + + return false !== $result && 0 < $result; +} + +function get_private_blog_users( $blog_id, $args = array() ) { + global $wpdb; + + $query = $wpdb->prepare( "SELECT user_id FROM drama_blog_access WHERE blog_id = %d", $blog_id ); + + if ( ! empty( $args ) ) { + $defaults = array( + 'orderby' => 'added', + 'order' => 'DESC', + 'page' => 1, + 'per_page' => 20 + ); + + $args = wp_parse_args( $args, $defaults ); + + $query .= $wpdb->prepare( + " ORDER BY %s %s LIMIT %d, %d;", + $args['orderby'], + $args['order'], + intval( ( $args['page'] - 1 ) * $args['per_page'] ), + intval( $args['per_page'] ) + ); + } + + $users = $wpdb->get_col( $query ); + + return $users; +} + +function get_count_private_blog_users( $blog_id ) { + global $wpdb; + + $query = $wpdb->prepare( "SELECT COUNT(user_id) FROM drama_blog_access WHERE blog_id = %d", $blog_id ); + + return (int) $wpdb->get_var( $query ); +} + +function _add_private_blog_user( $username, $blog_id = null ) { + global $wpdb; + + $username = wp_specialchars( strtolower( $username ) ); + if ( is_email( $username ) ) { + $user = get_user_by( 'email', $username ); + $user_id = $user->ID; + } else { + $username = preg_replace( '|[^a-z0-9-]|i', '', $username ); + $user = get_user_by( 'login', $username ); + $user_id = $user->ID; + } + + if ( !$user_id ) + return new WP_Error( 'user-not-found', __( 'User not found' ) ); + + if ( isset( $blog_id ) ) + $blog_id = intval( $blog_id ); + else + $blog_id = $wpdb->blogid; + + $current_users = get_private_blog_users( $blog_id ); + $user_limit = private_blog_user_limit(); + + if ( $user_limit !== false && count( $current_users ) >= $user_limit ) + return new WP_Error( 'too-many-users', sprintf( __( 'You can only add %d users to access this site.' ), $user_limit ) ); + + if ( $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM drama_blog_access WHERE blog_id = %d AND user_id = %d", $blog_id, $user_id ) ) ) + return new WP_Error( 'already-member', __( 'User is already a member of your private site' ) ); + + do_action( 'add_private_blog_user', $user_id, $blog_id ); + + $wpdb->insert( + 'drama_blog_access', + array( + 'blog_id' => $blog_id, + 'user_id' => $user_id, + 'added' => current_time( 'mysql', true ) + ), + array( '%d', '%d', '%s' ) + ); + $key = "private_blog_user_{$blog_id}_{$user_id}"; + wp_cache_set( $key, 'y', 'users', HOUR_IN_SECONDS ); + + do_action( 'added_private_blog_user', $user_id, $blog_id ); + + bump_stats_extras( 'wpcom_privacy_access', 'access_added' ); + + return true; +} + +function add_private_blog_user( $username, $blog_id = null ) { + $added = _add_private_blog_user( $username, $blog_id ); + if ( is_wp_error( $added ) ) { + $message = urlencode( $added->get_error_code() ); + wp_safe_redirect( add_query_arg( 'updated', $message, get_admin_url( '/options-reading.php' ) ) ); + die(); + } + + // Generate and send the acceptance email + $usermeta = get_user_by( 'login', $username ); + $site_name = get_bloginfo( 'name' ); + $subject = sprintf( __( "[%s] You've been granted access to view this private site" ), $site_name ); + $message = __( 'Howdy,' ); + $message .= "\n\n"; + $message .= sprintf( __( "You've been granted access to view %s by the site owner." ), trailingslashit( get_home_url( $blog_id ) ) ); + $message .= "\n\n"; + $message .= __( 'Cheers,' ); + $message .= "\n\n"; + $message .= __( 'The WordPress.com Team' ); + + $to = $usermeta->user_email; + + if ( ! empty( $to ) && false === strpos( $to, 'deleted-account' ) ) + wp_mail( $usermeta->user_email, $subject, $message ); + + $message = 'user-added'; + wp_safe_redirect( add_query_arg( 'updated', $message, get_option( 'siteurl' ) . '/wp-admin/options-reading.php' ) ); + die(); +} + +function remove_private_blog_user( $user_id, $blog_id = null ) { + global $wpdb; + + $user_id = (int) $user_id; + + if ( !$user_id ) + return; + + if ( isset( $blog_id ) ) + $blog_id = intval( $blog_id ); + else + $blog_id = $wpdb->blogid; + + do_action( 'remove_private_blog_user', $user_id, $blog_id ); + $result = $wpdb->query( $wpdb->prepare( "DELETE FROM drama_blog_access WHERE blog_id = %d AND user_id = %d", $blog_id, $user_id ) ); + + $key = "private_blog_user_{$blog_id}_{$user_id}"; + wp_cache_set( $key, 'n', 'users', HOUR_IN_SECONDS ); + + bump_stats_extras( 'wpcom_privacy_access', 'access_removed' ); + + // Was the remove successful? + return false !== $result && 0 < $result; +} + +function catch_private_users() { + if ( ! current_user_can( 'manage_options' ) ) { + return; + } + + if ( !$_POST['add_private_user'] && !$_POST['remove_private_blog_user'] ) + return; + + if ( $_POST['remove_private_blog_user'] ) { + foreach ( $_POST['remove_private_blog_user'] as $k => $v ) { + if ( check_admin_referer( 'remove_user_' . $k, '_wpnonce_remove_' . $k) ) + remove_private_blog_user( $k ); + $message = 'user-removed'; + wp_safe_redirect( add_query_arg( 'updated', $message, get_option( 'siteurl' ) . '/wp-admin/options-reading.php' ) ); + die(); + } + } + + if ( $_POST['add_private_user'] && check_admin_referer( 'add_private_user', '_wpnonce_add_private_user' ) ) { + if ( $_POST['approved_from_moderation'] ) + bump_stats_extras( 'wpcom_privacy_access', 'request_approved' ); + + $user_login = sanitize_user( $_POST['add_private_user'] ); + add_private_blog_user( $user_login ); + } +} +add_action( 'load-options.php', 'catch_private_users' ); + +function unpublic_blog( $blog_id ) { + $data = array( ); + $data['_blog_id'] = $blog_id; + $data['_bt'] = wp_debug_backtrace_summary(); + queue_async_job( $data, 'async_unpublic_blog' ); +} + +function publicize_blog( $blog_id ) { + $data = array( ); + $data['_blog_id'] = $blog_id; + $data['_bt'] = wp_debug_backtrace_summary(); + queue_async_job( $data, 'async_publicize_blog' ); +} + +function privitize_tag_db() { + global $wpdb, $current_blog; + + $is_public = 0; + $blog_public = (int) $_POST['blog_public']; + + if ( 1 == $blog_public ) + $is_public = 1; + + if ( 1 == $current_blog->mature ) + $is_public = 0; + + if ( $is_public ) + publicize_blog( $wpdb->blogid ); + else + unpublic_blog( $wpdb->blogid ); +} +add_action( 'update_blog_public', 'privitize_tag_db' ); + +/** + * If a user of a private blog isn't allowed access it's dashboard then redirect them to the blog itself + */ +function redirect_private_users_to_blog() { + global $current_user, $current_site, $wpdb; + if ( get_option( 'blog_public' ) && $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM drama_blog_access WHERE blog_id = %d AND user_id = %d", $wpdb->blogid, $current_user->ID ) ) ) { + wp_safe_redirect( home_url() ); + exit; + } +} +add_action( 'admin_page_access_denied', 'redirect_private_users_to_blog', 1 ); + +/** + * Don't let search engines index private sites + * or sites not deemed publicly available, like deleted, archived, spam. + */ +function private_robots_txt( $output, $public ) { + if ( ! is_publicly_available() ) { + $output = "User-agent: *\n"; // Purposefully overriding current output; we only want these rules. + $output .= "Disallow: /\n"; + } + + return $output; +} +add_filter( 'robots_txt', 'private_robots_txt', 10, 2 ); + +function privatize_privacy_on_link_title( $text ) { + if ( '-1' == get_option('blog_public') ) + return __('Your site is visible only to registered members'); + + return $text; +} +add_filter('privacy_on_link_title', 'privatize_privacy_on_link_title'); + +function privatize_privacy_on_link_text( $text ) { + if ( '-1' == get_option('blog_public') ) + return __('Private'); + + return $text; +} +add_filter('privacy_on_link_text', 'privatize_privacy_on_link_text'); + +/** + * Output the meta tag that tells Pinterest not to allow users to pin + * content from this page. + * https://support.pinterest.com/entries/21063792-what-if-i-don-t-want-images-from-my-site-to-be-pinned + */ +function private_no_pinning() { + echo ''; +} +add_action( 'wp_head', 'private_no_pinning' ); + +function privatize_opml() { + if ( '-1' != get_option('blog_public') ) { + return; + } + + if ( is_super_admin() || is_private_blog_user( get_current_blog_id(), get_current_user_id() ) ) { + return; + } + + + echo wpcom_get_the_generator( '', 'comment' ); +?> + + + + +blogid, $current_user) ) { + wp_die( -1 ); + } +} +add_action( 'check_ajax_referer', 'private_blog_ajax_nonce_check', 9999, 2 ); + +add_filter( 'syntaxhighlighter_defaultsettings', function( $settings ) { + if ( is_private_blog() && ! get_option('links_public') ) { + $settings['autolinks'] = 0; + } + + return $settings; +} ); \ No newline at end of file diff --git a/modules/private/private.php b/modules/private/private.php new file mode 100644 index 0000000000000..186d464020b04 --- /dev/null +++ b/modules/private/private.php @@ -0,0 +1,86 @@ +'; + $message .= '

' . __( "This site is marked private by its owner. If you would like to view it, you’ll need permission from the site owner. Once you've created an account, log in and revisit this screen to request an invite." ) . ''; + $message .= ''; + $message .= '

' . __( "If you already have permission then log in:" ) . '

'; + $message .= '

' . __( "Log in here" ) . '

'; + $message .= ''; + + //login_header( __( 'Log in' ), $message, $errors ); + +else : //logged in, but no access to the blog + $message = '
'; + // Success message for requesting access + if ( isset( $_GET['request_access'] ) && $_GET['request_access'] == 'success' ) { + $message .= __( 'Thank you. The site owner has been notified of your request.' ); + } else { + global $current_user; + + if ( ! private_blog_accepts_invites() ) { + if ( is_automattician() && is_automattic() ) { + $access_url = add_query_arg( array( + 'user-names' => [ $current_user->user_login ], + 'blogs' => [ intval( get_current_blog_id() ) ], + 'a11n-blogs-nonce' => wpcom_create_mc_nonce( 'a11n-blogs-user-' . $current_user->user_login ), + '_wp_http_referer' => rawurlencode( site_url() . $_SERVER['REQUEST_URI'] ), + ), 'https://mc.a8c.com/automattic-blogs/index.php' ); + $message .= '' . trailingslashit( get_home_url() ) . ' is marked private. As an Automattician you can give yourself access.'; + } else { + $message .= sprintf( __( '%s is marked private by its owner.' ), '' . trailingslashit( get_home_url() ) . '' ); + } + } else { + $message .= '

' . sprintf( __( "This site is marked private by its owner. If you would like to view it, you’ll need permission from the site owner. Request an invite and we'll send your username to the site owner for their approval." ), get_home_url( null, '?action=request_access&redirect_to=' . urlencode( get_home_url() ) . '&nonce=' . wp_create_nonce( 'request_access_' . get_current_blog_id() ) ) ) . '

'; + } + } + $message .= '
'; + //login_header( __( 'Log in' ), $message, $errors ); + +endif; +?> + + + +> + + + + + + + +> + + + \ No newline at end of file