| 1 |
<?php |
| 2 |
/** |
| 3 |
* DataBeam integration |
| 4 |
* |
| 5 |
* Handles all DataBeam integration and queries. |
| 6 |
* |
| 7 |
* @package Features |
| 8 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 9 |
* @since 1.0.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace POSessions\Plugin\Integration; |
| 13 |
|
| 14 |
use POSessions\System\Option; |
| 15 |
use POSessions\System\Role; |
| 16 |
use POSessions\Plugin\Core; |
| 17 |
|
| 18 |
/** |
| 19 |
* Define the DataBeam integration. |
| 20 |
* |
| 21 |
* Handles all DataBeam integration and queries. |
| 22 |
* |
| 23 |
* @package Features |
| 24 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 25 |
* @since 1.2.0 |
| 26 |
*/ |
| 27 |
class Databeam { |
| 28 |
|
| 29 |
/** |
| 30 |
* Init the class. |
| 31 |
* |
| 32 |
* @since 1.0.0 |
| 33 |
*/ |
| 34 |
public static function init() { |
| 35 |
add_filter( 'databeam_source_register', [ static::class, 'register_kpi' ] ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Register Sessions kpis endpoints for DataBeam. |
| 40 |
* |
| 41 |
* @param array $integrations The already registered integrations. |
| 42 |
* @return array The new integrations. |
| 43 |
* @since 1.0.0 |
| 44 |
*/ |
| 45 |
public static function register_kpi( $integrations ) { |
| 46 |
$integrations[ POSE_SLUG . '::kpi' ] = [ |
| 47 |
'name' => POSE_PRODUCT_NAME, |
| 48 |
'version' => POSE_VERSION, |
| 49 |
'subname' => __( 'KPIs', 'sessions' ), |
| 50 |
'description' => __( 'Allows to integrate, as a DataBeam source, all KPIs related to users\' sessions.', 'sessions' ), |
| 51 |
'instruction' => __( 'Just add this and use it as source in your favorite visualizers and publishers.', 'sessions' ), |
| 52 |
'note' => __( 'In multisite environments, this source is available for all network sites.', 'sessions' ), |
| 53 |
'legal' => |
| 54 |
[ |
| 55 |
'author' => 'Pierre Lannoy', |
| 56 |
'url' => 'https://github.com/Pierre-Lannoy', |
| 57 |
'license' => 'gpl3', |
| 58 |
], |
| 59 |
'icon' => |
| 60 |
[ |
| 61 |
'static' => [ |
| 62 |
'class' => '\POSessions\Plugin\Core', |
| 63 |
'method' => 'get_base64_logo', |
| 64 |
], |
| 65 |
], |
| 66 |
'type' => 'collection::kpi', |
| 67 |
'restrictions' => [ 'only_network' ], |
| 68 |
'ttl' => '0-3600:300', |
| 69 |
'caching' => [ 'locale' ], |
| 70 |
'data_call' => |
| 71 |
[ |
| 72 |
'static' => [ |
| 73 |
'class' => '\POSessions\Plugin\Feature\Analytics', |
| 74 |
'method' => 'get_status_kpi_collection', |
| 75 |
], |
| 76 |
], |
| 77 |
'data_args' => [], |
| 78 |
]; |
| 79 |
return $integrations; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Returns a base64 svg resource for the banner. |
| 84 |
* |
| 85 |
* @return string The svg resource as a base64. |
| 86 |
* @since 1.0.0 |
| 87 |
*/ |
| 88 |
public static function get_base64_banner() { |
| 89 |
$filename = __DIR__ . '/banner.svg'; |
| 90 |
if ( file_exists( $filename ) ) { |
| 91 |
// phpcs:ignore |
| 92 |
$content = @file_get_contents( $filename ); |
| 93 |
} else { |
| 94 |
$content = ''; |
| 95 |
} |
| 96 |
if ( $content ) { |
| 97 |
// phpcs:ignore |
| 98 |
return 'data:image/svg+xml;base64,' . base64_encode( $content ); |
| 99 |
} |
| 100 |
return ''; |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Register server infos endpoints for DataBeam. |
| 105 |
* |
| 106 |
* @param array $integrations The already registered integrations. |
| 107 |
* @return array The new integrations. |
| 108 |
* @since 1.0.0 |
| 109 |
*/ |
| 110 |
public static function register_info( $integrations ) { |
| 111 |
return $integrations; |
| 112 |
} |
| 113 |
|
| 114 |
} |
| 115 |
|