update
This commit is contained in:
77
api.php
77
api.php
@@ -9,6 +9,12 @@ function __autoload_my_classes( $classname )
|
||||
|
||||
if ( file_exists( $f ) )
|
||||
require_once( $f );
|
||||
else
|
||||
{
|
||||
$f = 'autoload/' . implode( '/', $q ) . '/' . $c . '.php';
|
||||
if ( file_exists( $f ) )
|
||||
require_once( $f );
|
||||
}
|
||||
}
|
||||
|
||||
spl_autoload_register( '__autoload_my_classes' );
|
||||
@@ -19,19 +25,62 @@ require_once 'libraries/medoo/medoo.php';
|
||||
require_once 'libraries/phpmailer/class.phpmailer.php';
|
||||
require_once 'libraries/phpmailer/class.smtp.php';
|
||||
|
||||
session_start();
|
||||
// Detect API request (stateless, no session)
|
||||
$isApiRequest = isset( $_GET['endpoint'] );
|
||||
|
||||
if ( !isset( $_SESSION[ 'check' ] ) )
|
||||
if ( !$isApiRequest )
|
||||
{
|
||||
session_regenerate_id();
|
||||
$_SESSION[ 'check' ] = true;
|
||||
$_SESSION[ 'ip' ] = $_SERVER[ 'REMOTE_ADDR' ];
|
||||
session_start();
|
||||
|
||||
if ( !isset( $_SESSION[ 'check' ] ) )
|
||||
{
|
||||
session_regenerate_id();
|
||||
$_SESSION[ 'check' ] = true;
|
||||
$_SESSION[ 'ip' ] = $_SERVER[ 'REMOTE_ADDR' ];
|
||||
}
|
||||
|
||||
if ( $_SESSION[ 'ip' ] !== $_SERVER[ 'REMOTE_ADDR' ] )
|
||||
{
|
||||
session_destroy();
|
||||
header( 'Location: /' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $_SESSION[ 'ip' ] !== $_SERVER[ 'REMOTE_ADDR' ] )
|
||||
// --- API routing (ordersPRO) ---
|
||||
if ( $isApiRequest )
|
||||
{
|
||||
session_destroy();
|
||||
header( 'Location: /' );
|
||||
if ( !headers_sent() )
|
||||
header( 'Content-Type: application/json; charset=utf-8' );
|
||||
|
||||
try
|
||||
{
|
||||
$mdb = new medoo( [
|
||||
'database_type' => 'mysql',
|
||||
'database_name' => $database[ 'name' ],
|
||||
'server' => $database[ 'host' ],
|
||||
'username' => $database[ 'user' ],
|
||||
'password' => $database[ 'password' ],
|
||||
'charset' => 'utf8'
|
||||
] );
|
||||
|
||||
$settingsRepo = new \Domain\Settings\SettingsRepository( $mdb );
|
||||
$router = new \api\ApiRouter( $mdb, $settingsRepo );
|
||||
$router->handle();
|
||||
}
|
||||
catch ( \Throwable $e )
|
||||
{
|
||||
if ( !headers_sent() )
|
||||
header( 'Content-Type: application/json; charset=utf-8' );
|
||||
|
||||
http_response_code( 500 );
|
||||
echo json_encode( [
|
||||
'status' => 'error',
|
||||
'code' => 'INTERNAL_ERROR',
|
||||
'message' => 'Internal server error'
|
||||
], JSON_UNESCAPED_UNICODE );
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -44,16 +93,18 @@ $mdb = new medoo( [
|
||||
'charset' => 'utf8'
|
||||
] );
|
||||
|
||||
$settings = \front\factory\Settings::settings_details();
|
||||
$settingsRepo = new \Domain\Settings\SettingsRepository( $mdb );
|
||||
$settings = $settingsRepo->allSettings();
|
||||
|
||||
if ( \S::get( 'ekomi_csv' ) )
|
||||
// --- Ekomi CSV export ---
|
||||
if ( \Shared\Helpers\Helpers::get( 'ekomi_csv' ) )
|
||||
{
|
||||
$csv_array = [ [ 'ORDER_ID', 'MAIL', 'FIRST_NAME', 'LAST_NAME', 'PRODUCT_ID', 'PRODUCT_NAME' ] ];
|
||||
|
||||
$orders_id = $mdb -> select( 'pp_shop_order_statuses', 'order_id', [ 'AND' => [ 'status_id' => 6, 'date[~]' => date( 'Y-m-d', strtotime( '-1 day', time() ) ) ] ] );
|
||||
$orders_id = array_unique( $orders_id );
|
||||
|
||||
if ( \S::is_array_fix( $orders_id ) )
|
||||
if ( \Shared\Helpers\Helpers::is_array_fix( $orders_id ) )
|
||||
{
|
||||
foreach ( $orders_id as $order_id )
|
||||
{
|
||||
@@ -61,7 +112,7 @@ if ( \S::get( 'ekomi_csv' ) )
|
||||
if ( $order )
|
||||
{
|
||||
$products = $mdb -> select( 'pp_shop_order_products', '*', [ 'order_id' => $order['id'] ] );
|
||||
if ( \S::is_array_fix( $products ) ) foreach ( $products as $product )
|
||||
if ( \Shared\Helpers\Helpers::is_array_fix( $products ) ) foreach ( $products as $product )
|
||||
{
|
||||
$csv_array[] = [ $order['id'], $order['client_email'], $order['client_name'], $order['client_surname'], $product['product_id'], $product['name'] ];
|
||||
}
|
||||
@@ -78,4 +129,4 @@ if ( \S::get( 'ekomi_csv' ) )
|
||||
|
||||
fclose( $fp );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user