Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,143 @@
<?php
namespace bizpanda\includes\gates\google;
use bizpanda\includes\gates\exceptions\GateBridgeException;
use bizpanda\includes\gates\OAuthGateBridge;
/**
* The class to proxy the request to the Google API.
*/
class GoogleBridge extends OAuthGateBridge {
/**
* Returns an URL to authorize and grant permissions.
* @param array $stateArgs An extra data to add into the state argument. They will be passed back on callback.
* @return string An URL to authorize.
*/
public function getAuthorizeURL( $stateArgs = [] ) {
$endpointUrl = 'https://accounts.google.com/o/oauth2/v2/auth';
$args = [
'scope' => $this->permissions,
'access_type' => 'online',
'include_granted_scopes' => 'true',
'response_type' => 'code',
'redirect_uri' => $this->callbackUrl,
'client_id' => $this->clientId,
'display' => 'popup',
'state' => $this->buildStateParam( $stateArgs )
];
return $endpointUrl . '?' . http_build_query( $args );
}
/**
* Gets the access token using the code received on the authorization step.
* @param $code Code received on the authorization step.
* @return mixed[]
* @throws GateBridgeException
*/
function getAccessToken( $code ) {
$endpointUrl = 'https://oauth2.googleapis.com/token';
$requestData = [
'code' => $code,
'grant_type' => 'authorization_code',
'redirect_uri' => $this->callbackUrl,
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret
];
$json = $this->requestJson($endpointUrl, 'POST', [
'data' => $requestData
]);
if ( !isset( $json['access_token'] ) ) {
throw $this->createException( GateBridgeException::UNEXPECTED_RESPONSE, 'The parameter [access_token] is not set.' );
}
return [
'accessToken' => $json['access_token']
];
}
/**
* Gets user info.
*/
function getUserInfo() {
$endpointUrl = 'https://www.googleapis.com/oauth2/v2/userinfo';
$url = $endpointUrl . '?access_token=' . $this->accessToken;
return $this->requestJson($url, 'GET');
}
/**
* Subscribes to YouTube channel.
* @param $channelId string A channel to subscribe to.
* @return string
* @throws GateBridgeException
*/
function subscribeToYoutube( $channelId ) {
$endpointUrl = 'https://www.googleapis.com/youtube/v3/subscriptions';
$url = $endpointUrl . '?access_token=' . $this->accessToken . '&part=snippet';
$data = json_encode([
'snippet' => [
'resourceId' => [
'kind' => 'youtube#channel',
'channelId' => $channelId
]
]
]);
$headers = [
'Content-Type' => 'application/json'
];
return $this->requestJson($url, 'POST', [
'data' => $data,
'headers' => $headers
]);
}
/**
* Makes a request to Google API.
* @param $url
* @param $method
* @param array $options
* @return string
* @throws GateBridgeException
*/
function requestJson($url, $method, $options = [] ) {
$options['expectJson'] = true;
$json = $this->http( $url, $method, $options );
return $this->throwExceptionOnErrors( $json );
}
/**
* Throws an exception if the response contains errors.
* @param $json
* @return mixed[] Returns response data back.
* @throws GateBridgeException
*/
function throwExceptionOnErrors( $json ) {
if ( isset( $json['error'] ) && isset( $json['error_description'] ) ) {
if ( 'invalid_client' === $json['error'] ) {
throw $this->createException( GateBridgeException::NOT_AUTHENTICATED, 'Please make sure that Google Client ID and Client Secret are set correctly.' );
}
throw $this->createException( GateBridgeException::ERROR_RESPONSE, $json['error_description']);
} else if ( isset( $json['error'] ) && isset( $json['error']['message'] ) ) {
throw $this->createException( GateBridgeException::ERROR_RESPONSE, $json['error']['message']);
}
return $json;
}
}

View File

@@ -0,0 +1,135 @@
<?php
namespace bizpanda\includes\gates\google;
use bizpanda\includes\gates\Gate;
use bizpanda\includes\gates\exceptions\GateException;
use bizpanda\includes\gates\OAuthGate;
use Yii;
/**
* The class to proxy the request to the Google API.
*/
class GoogleGate extends OAuthGate {
/**
* GoogleGate constructor.
* @param null $session
* @param null $config
* @param null $request
*/
public function __construct($session = null, $config = null, $request = null)
{
parent::__construct($session, $config, $request);
$this->name = 'google';
$this->allowedRequestTypes = array_merge(
$this->allowedRequestTypes,
['subscribe_to_youtube']
);
$this->allowedPermissionScopes = ['userinfo', 'youtube'];
}
/**
* @inheritDoc
*/
public function createBridge( $authorized = false ) {
$config = $this->getOptionsForBridge( $authorized );
return new GoogleBridge( $config );
}
/**
* @inheritDoc
*/
public function getOptionsForBridge( $authorized = false ) {
$options = $this->config->get( $this->name );
if ( !isset( $options['clientId'] ) || !isset( $options['clientSecret'] ) ) {
throw GateException::create(GateException::APP_NOT_CONFIGURED, 'Client Id or Client Secret are not set.' );
}
$options['permissions'] = $this->getGooglePermissions( $this->permissionScopes );
if ( $authorized ) {
$options['accessToken'] = $this->getVisitorValue($this->name . '_access_token', null );
if ( empty( $options['accessToken'] ) ) {
throw GateException::create(GateException::AUTH_FLOW_BROKEN, 'The access token is not set.' );
}
}
return $options;
}
/**
* Converts app scopes to the google scopes.
* @param array $scopes
* @return string
*/
public function getGooglePermissions( $scopes = [] ) {
$googleScopes = [];
foreach( $scopes as $scope ) {
if ( 'userinfo' === $scope ) {
$googleScopes[] = 'https://www.googleapis.com/auth/userinfo.profile';
$googleScopes[] = 'https://www.googleapis.com/auth/userinfo.email';
} else if ( 'youtube' === $scope ) {
$googleScopes[] = 'https://www.googleapis.com/auth/youtube';
}
}
return implode(' ', $googleScopes);
}
/**
* Returns user profile info.
* @return mixed
*/
public function doGetUserInfo() {
$bridge = $this->createBridge( true );
$result = $bridge->getUserInfo();
$identity = [
'source' => 'google',
'email' => isset( $result['email'] ) ? $result['email'] : false,
'displayName' => isset( $result['name'] ) ? $result['name'] : false,
'name' => isset( $result['given_name'] ) ? $result['given_name'] : false,
'family' => isset( $result['family_name'] ) ? $result['family_name'] : false,
'social' => true,
'googleId' => isset( $result['id'] ) ? $result['id'] : false,
'googleUrl' => false,
'image' => isset( $result['picture'] ) ? $result['picture'] : false
];
return $this->prepareResult([
'identity' => $identity,
]);
}
/**
* Performs subscription to YouTube channel.
* @throws GateException
*/
public function doSubscribeToYouTube() {
$channelId = $this->getRequestParam('channelId');
if ( empty( $channelId ) ) throw new GateException('Invalid request [channelId].');
$bridge = $this->createBridge( true );
$result = $bridge->subscribeToYoutube( $channelId );
return $this->prepareResult([
'response' => $result,
]);
}
}

File diff suppressed because one or more lines are too long