Skip to content

Commit

Permalink
WPCIVIUX-144 Refactor strftime use to prevent incorrect autoloader us…
Browse files Browse the repository at this point in the history
…e in pear/log package
  • Loading branch information
agileware-fj authored and agileware-dev committed Apr 10, 2024
1 parent fb72bd0 commit e6f9026
Show file tree
Hide file tree
Showing 38 changed files with 154 additions and 1,396 deletions.
2 changes: 1 addition & 1 deletion civicrm-ux.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Plugin Name: WP CiviCRM UX
* Plugin URI: https://github.com/agileware/wp-civicrm-ux
* Description: A better user experience for integrating WordPress and CiviCRM
* Version: 1.13.1
* Version: 1.13.2
* Requires at least: 5.8
* Requires PHP: 7.4
* Author: Agileware
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"require": {
"sabre/vobject": "^4.2",
"php81_bc/strftime": "^0.7.4"
"sabre/vobject": "^4.2"
}
}
48 changes: 2 additions & 46 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions includes/class-civicrm-ux.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static public function getInstance( $plugin_file = '../civicrm-ux.php' ) {
private function __construct( $plugin_file ) {
$this->version = \get_file_data( realpath( $plugin_file ), [ 'Version' => 'Version' ], 'plugin' )['Version'];
$this->civicrm_ux = 'civicrm-ux';
self::$directory = plugin_dir_path( $plugin_file );
self::$directory = trailingslashit( plugin_dir_path( $plugin_file ) );

$this->load_dependencies();
$this->set_locale();
Expand All @@ -113,8 +113,10 @@ private function __construct( $plugin_file ) {
$this->define_rest();
$this->define_magic_tag();

if( !function_exists( 'urlparam' ) && !empty( self::$directory ) ) {
include_once( self::$directory . '/packaged/url-params/urlparams.php');
if( !empty( self::$directory ) ) {
if ( !function_exists( 'urlparam' ) ){
include_once( self::$directory . 'packaged/url-params/urlparams.php');
}
}

$this->loader->add_action( 'init', $this, 'civicrm_init' );
Expand Down Expand Up @@ -418,4 +420,11 @@ public function get_version() {
return $this->version;
}

public function strftime ( string $format, $timestamp = null, ?string $locale = null ) : string {
if ( !function_exists( 'PHP81_BC\\strftime' ) ){
include_once( self::$directory . 'packaged/PHP81_BC/strftime.php');
}

return PHP81_BC\strftime( $format, $timestamp, $locale );
}
}
4 changes: 1 addition & 3 deletions shortcodes/civicrm/api4-get.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
use function PHP81_BC\strftime;

/**
* Class Civicrm_Ux_Shortcode_CiviCRM_Api4_Get
*/
Expand Down Expand Up @@ -152,7 +150,7 @@ public function shortcode_callback( $atts = [], $content = NULL, $tag = '' ) {
$field = $fields[ $match['field'] ] ?? [];

if ( array_key_exists( 'data_type', $field ) && ( ( $field['data_type'] == 'Date' ) || ( $field['data_type'] == 'Timestamp' ) ) ) {
$output = isset( $match['format'] ) ? strftime( $match['format'], strtotime( $output ) ) : CRM_Utils_Date::customFormat( $output );
$output = isset( $match['format'] ) ? Civicrm_Ux::getInstance()->strftime( $match['format'], strtotime( $output ) ) : CRM_Utils_Date::customFormat( $output );
} elseif ( ( $field['fk_entity'] ?? NULL ) == 'File' ) {
$output = Civicrm_Ux::in_basepage( function () use ( $output ) {
return htmlentities( civicrm_api3( 'Attachment', 'getvalue', [
Expand Down
18 changes: 18 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

// autoload.php @generated by Composer

if (PHP_VERSION_ID < 50600) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, $err);
} elseif (!headers_sent()) {
echo $err;
}
}
trigger_error(
$err,
E_USER_ERROR
);
}

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitfa85ac06b7f15758458f94c1334ceeb2::getLoader();
Loading

0 comments on commit e6f9026

Please sign in to comment.