| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong |
| 4 |
namespace Yoast\WP\SEO\Editors\Framework\Site; |
| 5 |
|
| 6 |
use Exception; |
| 7 |
use Yoast\WP\SEO\Helpers\Options_Helper; |
| 8 |
use Yoast\WP\SEO\Helpers\Product_Helper; |
| 9 |
use Yoast\WP\SEO\Helpers\Short_Link_Helper; |
| 10 |
use Yoast\WP\SEO\Introductions\Infrastructure\Wistia_Embed_Permission_Repository; |
| 11 |
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager; |
| 12 |
use Yoast\WP\SEO\Surfaces\Meta_Surface; |
| 13 |
|
| 14 |
/** |
| 15 |
* The Base_Site_Information class. |
| 16 |
*/ |
| 17 |
abstract class Base_Site_Information { |
| 18 |
|
| 19 |
/** |
| 20 |
* The short link helper. |
| 21 |
* |
| 22 |
* @var Short_Link_Helper |
| 23 |
*/ |
| 24 |
protected $short_link_helper; |
| 25 |
|
| 26 |
/** |
| 27 |
* The wistia embed permission repository. |
| 28 |
* |
| 29 |
* @var Wistia_Embed_Permission_Repository |
| 30 |
*/ |
| 31 |
protected $wistia_embed_permission_repository; |
| 32 |
|
| 33 |
/** |
| 34 |
* The meta surface. |
| 35 |
* |
| 36 |
* @var Meta_Surface |
| 37 |
*/ |
| 38 |
protected $meta; |
| 39 |
|
| 40 |
/** |
| 41 |
* The product helper. |
| 42 |
* |
| 43 |
* @var Product_Helper |
| 44 |
*/ |
| 45 |
protected $product_helper; |
| 46 |
|
| 47 |
/** |
| 48 |
* The options helper. |
| 49 |
* |
| 50 |
* @var Options_Helper |
| 51 |
*/ |
| 52 |
protected $options_helper; |
| 53 |
|
| 54 |
/** |
| 55 |
* The promotion manager. |
| 56 |
* |
| 57 |
* @var Promotion_Manager |
| 58 |
*/ |
| 59 |
protected $promotion_manager; |
| 60 |
|
| 61 |
/** |
| 62 |
* The constructor. |
| 63 |
* |
| 64 |
* @param Short_Link_Helper $short_link_helper The short link helper. |
| 65 |
* @param Wistia_Embed_Permission_Repository $wistia_embed_permission_repository The wistia embed permission |
| 66 |
* repository. |
| 67 |
* @param Meta_Surface $meta The meta surface. |
| 68 |
* @param Product_Helper $product_helper The product helper. |
| 69 |
* @param Options_Helper $options_helper The options helper. |
| 70 |
* @param Promotion_Manager $promotion_manager The promotion manager. |
| 71 |
*/ |
| 72 |
public function __construct( |
| 73 |
Short_Link_Helper $short_link_helper, |
| 74 |
Wistia_Embed_Permission_Repository $wistia_embed_permission_repository, |
| 75 |
Meta_Surface $meta, |
| 76 |
Product_Helper $product_helper, |
| 77 |
Options_Helper $options_helper, |
| 78 |
Promotion_Manager $promotion_manager |
| 79 |
) { |
| 80 |
$this->short_link_helper = $short_link_helper; |
| 81 |
$this->wistia_embed_permission_repository = $wistia_embed_permission_repository; |
| 82 |
$this->meta = $meta; |
| 83 |
$this->product_helper = $product_helper; |
| 84 |
$this->options_helper = $options_helper; |
| 85 |
$this->promotion_manager = $promotion_manager; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Returns site information that is the |
| 90 |
* |
| 91 |
* @return array<string, string|array<string, string>> |
| 92 |
* |
| 93 |
* @throws Exception If an invalid user ID is supplied to the wistia repository. |
| 94 |
*/ |
| 95 |
public function get_site_information(): array { |
| 96 |
return [ |
| 97 |
'adminUrl' => \admin_url( 'admin.php' ), |
| 98 |
'linkParams' => $this->short_link_helper->get_query_params(), |
| 99 |
'pluginUrl' => \plugins_url( '', \WPSEO_FILE ), |
| 100 |
'wistiaEmbedPermission' => $this->wistia_embed_permission_repository->get_value_for_user( \get_current_user_id() ), |
| 101 |
'site_name' => $this->meta->for_current_page()->site_name, |
| 102 |
'contentLocale' => \get_locale(), |
| 103 |
'userLocale' => \get_user_locale(), |
| 104 |
'isRtl' => \is_rtl(), |
| 105 |
'isPremium' => $this->product_helper->is_premium(), |
| 106 |
'siteIconUrl' => \get_site_icon_url(), |
| 107 |
'showSocial' => [ |
| 108 |
'facebook' => $this->options_helper->get( 'opengraph', false ), |
| 109 |
'twitter' => $this->options_helper->get( 'twitter', false ), |
| 110 |
], |
| 111 |
'sitewideSocialImage' => $this->options_helper->get( 'og_default_image' ), |
| 112 |
// phpcs:ignore Generic.ControlStructures.DisallowYodaConditions -- Bug: squizlabs/PHP_CodeSniffer#2962. |
| 113 |
'isPrivateBlog' => ( (string) \get_option( 'blog_public' ) ) === '0', |
| 114 |
'currentPromotions' => $this->promotion_manager->get_current_promotions(), |
| 115 |
]; |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Returns site information that is the |
| 120 |
* |
| 121 |
* @return array<string, string|array<string, string|array<string, string>>> |
| 122 |
* |
| 123 |
* @throws Exception If an invalid user ID is supplied to the wistia repository. |
| 124 |
*/ |
| 125 |
public function get_legacy_site_information(): array { |
| 126 |
return [ |
| 127 |
'adminUrl' => \admin_url( 'admin.php' ), |
| 128 |
'linkParams' => $this->short_link_helper->get_query_params(), |
| 129 |
'pluginUrl' => \plugins_url( '', \WPSEO_FILE ), |
| 130 |
'wistiaEmbedPermission' => $this->wistia_embed_permission_repository->get_value_for_user( \get_current_user_id() ), |
| 131 |
'sitewideSocialImage' => $this->options_helper->get( 'og_default_image' ), |
| 132 |
// phpcs:ignore Generic.ControlStructures.DisallowYodaConditions -- Bug: squizlabs/PHP_CodeSniffer#2962. |
| 133 |
'isPrivateBlog' => ( (string) \get_option( 'blog_public' ) ) === '0', |
| 134 |
'currentPromotions' => $this->promotion_manager->get_current_promotions(), |
| 135 |
'metabox' => [ |
| 136 |
'site_name' => $this->meta->for_current_page()->site_name, |
| 137 |
'contentLocale' => \get_locale(), |
| 138 |
'userLocale' => \get_user_locale(), |
| 139 |
'isRtl' => \is_rtl(), |
| 140 |
'isPremium' => $this->product_helper->is_premium(), |
| 141 |
'siteIconUrl' => \get_site_icon_url(), |
| 142 |
'showSocial' => [ |
| 143 |
'facebook' => $this->options_helper->get( 'opengraph', false ), |
| 144 |
'twitter' => $this->options_helper->get( 'twitter', false ), |
| 145 |
], |
| 146 |
], |
| 147 |
]; |
| 148 |
} |
| 149 |
} |
| 150 |
|