Initial commit: Atomaste website

This commit is contained in:
2025-12-10 12:17:30 -05:00
commit 0b9e5d1605
19260 changed files with 5206382 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
<?php
namespace AIOSEO\Plugin\Common\Integrations;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class to integrate with the bbPress plugin.
*
* @since 4.8.1
*/
class BbPress {
/**
* Returns whether the current page is a bbPress component page.
*
* @since 4.8.1
*
* @return bool Whether the current page is a bbPress component page.
*/
public static function isComponentPage() {
return ! empty( aioseo()->standalone->bbPress->component->templateType );
}
}

View File

@@ -0,0 +1,177 @@
<?php
namespace AIOSEO\Plugin\Common\Integrations;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class to integrate with the BuddyPress plugin.
*
* @since 4.7.6
*/
class BuddyPress {
/**
* Call the callback given by the first parameter.
*
* @since 4.7.6
*
* @param callable $callback The function to be called.
* @param mixed ...$args Zero or more parameters to be passed to the function
* @return mixed|null The function result or null if the function is not callable.
*/
public static function callFunc( $callback, ...$args ) {
if ( is_callable( $callback ) ) {
return call_user_func( $callback, ...$args );
}
return null;
}
/**
* Returns the BuddyPress email custom post type slug.
*
* @since 4.7.6
*
* @return string The BuddyPress email custom post type slug if found or an empty string.
*/
public static function getEmailCptSlug() {
$slug = '';
if ( aioseo()->helpers->isPluginActive( 'buddypress' ) ) {
$slug = self::callFunc( 'bp_get_email_post_type' );
}
return is_scalar( $slug ) ? strval( $slug ) : '';
}
/**
* Retrieves the BuddyPress component archive page permalink.
*
* @since 4.7.6
*
* @param string $component The BuddyPress component.
* @return string The component archive page permalink.
*/
public static function getComponentArchiveUrl( $component ) {
switch ( $component ) {
case 'activity':
$output = self::callFunc( 'bp_get_activity_directory_permalink' );
break;
case 'member':
$output = self::callFunc( 'bp_get_members_directory_permalink' );
break;
case 'group':
$output = self::callFunc( 'bp_get_groups_directory_url' );
break;
default:
$output = '';
}
return is_scalar( $output ) ? strval( $output ) : '';
}
/**
* Returns the BuddyPress component single page permalink.
*
* @since 4.7.6
*
* @param string $component The BuddyPress component.
* @param mixed $id The component ID.
* @return string The component single page permalink.
*/
public static function getComponentSingleUrl( $component, $id ) {
switch ( $component ) {
case 'activity':
$output = self::callFunc( 'bp_activity_get_permalink', $id );
break;
case 'group':
$output = self::callFunc( 'bp_get_group_url', $id );
break;
case 'member':
$output = self::callFunc( 'bp_core_get_userlink', $id, false, true );
break;
default:
$output = '';
}
return is_scalar( $output ) ? strval( $output ) : '';
}
/**
* Returns the BuddyPress component edit link.
*
* @since 4.7.6
*
* @param string $component The BuddyPress component.
* @param mixed $id The component ID.
* @return string The component edit link.
*/
public static function getComponentEditUrl( $component, $id ) {
switch ( $component ) {
case 'activity':
$output = add_query_arg( [
'page' => 'bp-activity',
'aid' => $id,
'action' => 'edit'
], self::callFunc( 'bp_get_admin_url', 'admin.php' ) );
break;
case 'group':
$output = add_query_arg( [
'page' => 'bp-groups',
'gid' => $id,
'action' => 'edit'
], self::callFunc( 'bp_get_admin_url', 'admin.php' ) );
break;
case 'member':
$output = get_edit_user_link( $id );
break;
default:
$output = '';
}
return is_scalar( $output ) ? strval( $output ) : '';
}
/**
* Returns whether the BuddyPress component is active or not.
*
* @since 4.7.6
*
* @param string $component The BuddyPress component.
* @return bool Whether the BuddyPress component is active.
*/
public static function isComponentActive( $component ) {
static $active = [];
if ( isset( $active[ $component ] ) ) {
return $active[ $component ];
}
switch ( $component ) {
case 'activity':
$active[ $component ] = self::callFunc( 'bp_is_active', 'activity' );
break;
case 'group':
$active[ $component ] = self::callFunc( 'bp_is_active', 'groups' );
break;
case 'member':
$active[ $component ] = self::callFunc( 'bp_is_active', 'members' );
break;
default:
$active[ $component ] = false;
}
return $active[ $component ];
}
/**
* Returns whether the current page is a BuddyPress component page.
*
* @since 4.7.6
*
* @return bool Whether the current page is a BuddyPress component page.
*/
public static function isComponentPage() {
return ! empty( aioseo()->standalone->buddyPress->component->templateType );
}
}

View File

@@ -0,0 +1,224 @@
<?php
namespace AIOSEO\Plugin\Common\Integrations;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class to integrate with the Semrush API.
*
* @since 4.0.16
*/
class Semrush {
/**
* The Oauth2 URL.
*
* @since 4.0.16
*
* @var string
*/
public static $url = 'https://oauth.semrush.com/oauth2/access_token';
/**
* The client ID for the Oauth2 integration.
*
* @since 4.0.16
*
* @var string
*/
public static $clientId = 'aioseo';
/**
* The client secret for the Oauth2 integration.
*
* @since 4.0.16
*
* @var string
*/
public static $clientSecret = 'sdDUjYt6umO7sKM7mp4OrN8yeePTOQBy';
/**
* Static method to authenticate the user.
*
* @since 4.0.16
*
* @param string $authorizationCode The authorization code for the Oauth2 authentication.
* @return bool Whether the user is succesfully authenticated.
*/
public static function authenticate( $authorizationCode ) {
$time = time();
$response = wp_remote_post( self::$url, [
'headers' => [ 'Content-Type' => 'application/json' ],
'body' => wp_json_encode( [
'client_id' => self::$clientId,
'client_secret' => self::$clientSecret,
'grant_type' => 'authorization_code',
'code' => $authorizationCode,
'redirect_uri' => 'https://oauth.semrush.com/oauth2/aioseo/success'
] )
] );
$responseCode = wp_remote_retrieve_response_code( $response );
if ( 200 === $responseCode ) {
$tokens = json_decode( wp_remote_retrieve_body( $response ) );
return self::saveTokens( $tokens, $time );
}
return false;
}
/**
* Static method to refresh the tokens once expired.
*
* @since 4.0.16
*
* @return bool Whether the tokens were successfully renewed.
*/
public static function refreshTokens() {
$refreshToken = aioseo()->internalOptions->integrations->semrush->refreshToken;
if ( empty( $refreshToken ) ) {
self::reset();
return false;
}
$time = time();
$response = wp_remote_post( self::$url, [
'headers' => [ 'Content-Type' => 'application/json' ],
'body' => wp_json_encode( [
'client_id' => self::$clientId,
'client_secret' => self::$clientSecret,
'grant_type' => 'refresh_token',
'refresh_token' => $refreshToken
] )
] );
$responseCode = wp_remote_retrieve_response_code( $response );
if ( 200 === $responseCode ) {
$tokens = json_decode( wp_remote_retrieve_body( $response ) );
return self::saveTokens( $tokens, $time );
}
return false;
}
/**
* Clears out the internal options to reset the tokens.
*
* @since 4.1.5
*
* @return void
*/
private static function reset() {
aioseo()->internalOptions->integrations->semrush->accessToken = '';
aioseo()->internalOptions->integrations->semrush->tokenType = '';
aioseo()->internalOptions->integrations->semrush->expires = '';
aioseo()->internalOptions->integrations->semrush->refreshToken = '';
}
/**
* Checks if the token has expired
*
* @since 4.0.16
*
* @return boolean Whether or not the token has expired.
*/
public static function hasExpired() {
$tokens = self::getTokens();
return time() >= $tokens['expires'];
}
/**
* Returns the tokens.
*
* @since 4.0.16
*
* @return array An array of token data.
*/
public static function getTokens() {
return aioseo()->internalOptions->integrations->semrush->all();
}
/**
* Saves the token options.
*
* @since 4.0.16
*
* @param Object $tokens The tokens object.
* @param string $time The time set before the request was made.
* @return bool Whether the response was valid and successfully saved.
*/
public static function saveTokens( $tokens, $time ) {
$expectedProps = [
'access_token',
'token_type',
'expires_in',
'refresh_token'
];
// If the oAuth response does not include all expected properties, drop it.
foreach ( $expectedProps as $prop ) {
if ( empty( $tokens->$prop ) ) {
return false;
}
}
// Save the options.
aioseo()->internalOptions->integrations->semrush->accessToken = $tokens->access_token;
aioseo()->internalOptions->integrations->semrush->tokenType = $tokens->token_type;
aioseo()->internalOptions->integrations->semrush->expires = $time + $tokens->expires_in;
aioseo()->internalOptions->integrations->semrush->refreshToken = $tokens->refresh_token;
return true;
}
/**
* API call to get keyphrases from semrush.
*
* @since 4.0.16
*
* @param string $keyphrase A primary keyphrase.
* @param string $database A country database.
* @return object|bool The response object or false if the tokens could not be refreshed.
*/
public static function getKeyphrases( $keyphrase, $database ) {
if ( self::hasExpired() ) {
$success = self::refreshTokens();
if ( ! $success ) {
return false;
}
}
$transientKey = 'semrush_keyphrases_' . $keyphrase . '_' . $database;
$results = aioseo()->core->cache->get( $transientKey );
if ( null !== $results ) {
return $results;
}
$params = [
'phrase' => $keyphrase,
'export_columns' => 'Ph,Nq,Td',
'database' => strtolower( $database ),
'display_limit' => 10,
'display_offset' => 0,
'display_sort' => 'nq_desc',
'display_filter' => '%2B|Nq|Lt|1000',
'access_token' => aioseo()->internalOptions->integrations->semrush->accessToken
];
$url = 'https://oauth.semrush.com/api/v1/keywords/phrase_fullsearch?' . http_build_query( $params );
$response = wp_remote_get( $url );
$body = json_decode( wp_remote_retrieve_body( $response ) );
aioseo()->core->cache->update( $transientKey, $body );
return $body;
}
}

View File

@@ -0,0 +1,122 @@
<?php
namespace AIOSEO\Plugin\Common\Integrations;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Route class for the API.
*
* @since 4.3.8
*/
class WpCode {
/**
* Load the WPCode snippets for our desired username or return an empty array if not available.
*
* @since 4.3.8
*
* @return array The snippets.
*/
public static function loadWpCodeSnippets() {
$snippets = self::getPlaceholderSnippets();
if ( function_exists( 'wpcode_get_library_snippets_by_username' ) ) {
$snippets = wpcode_get_library_snippets_by_username( 'aioseo' );
}
return $snippets;
}
/**
* Checks if the plugin is installed, either the lite or premium version.
*
* @since 4.3.8
*
* @return bool True if the plugin is installed.
*/
public static function isPluginInstalled() {
return self::isProInstalled() || self::isLiteInstalled();
}
/**
* Is the pro plugin installed.
*
* @since 4.3.8
*
* @return bool True if the pro plugin is installed.
*/
public static function isProInstalled() {
$installedPlugins = array_keys( get_plugins() );
return in_array( 'wpcode-premium/wpcode.php', $installedPlugins, true );
}
/**
* Is the lite plugin installed.
*
* @since 4.3.8
*
* @return bool True if the lite plugin is installed.
*/
public static function isLiteInstalled() {
$installedPlugins = array_keys( get_plugins() );
return in_array( 'insert-headers-and-footers/ihaf.php', $installedPlugins, true );
}
/**
* Basic check if the plugin is active by looking for the main function.
*
* @since 4.3.8
*
* @return bool True if the plugin is active.
*/
public static function isPluginActive() {
return function_exists( 'wpcode' );
}
/**
* Checks if the plugin is active but needs to be updated by checking if the function to load the
* library snippets by username exists.
*
* @since 4.3.8
*
* @return bool True if the plugin is active but needs to be updated.
*/
public static function pluginNeedsUpdate() {
return self::isPluginActive() && ! function_exists( 'wpcode_get_library_snippets_by_username' );
}
/**
* Get placeholder snippets if the WPCode snippets are not available.
*
* @since 4.3.8
*
* @return array The placeholder snippets.
*/
private static function getPlaceholderSnippets() {
$snippetTitles = [
'Disable autogenerated shipping details schema for WooCommerce',
'Disable SEO Preview feature',
'Disable Shortcode Parsing in All in One SEO',
'Enable WooCommerce Product Attributes in Search Appearance',
'Fix LearnPress conflict that hides AIOSEO tabs on settings pages',
'Limit Meta Description to 160 characters',
'Limit SEO Title to 60 characters',
'Noindex Product Search Pages',
'Noindex Products under a Product Category',
];
$placeholderSnippets = [];
foreach ( $snippetTitles as $snippetTitle ) {
// Add placeholder install link so we show a button.
$placeholderSnippets[] = [
'title' => $snippetTitle,
'install' => 'https://library.wpcode.com/'
];
}
return $placeholderSnippets;
}
}