Skip to content

Commit

Permalink
Apply WordPress coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
agileware-justin committed Sep 14, 2021
1 parent 648074e commit a7d4e70
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 49 deletions.
72 changes: 51 additions & 21 deletions admin/partials/civicrm-ux-admin-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ function civicrm_ux_settings_page() {
];
$url = add_query_arg(
$url_param,
get_rest_url( null,
get_rest_url( NULL,
'/' . Civicrm_Ux_Shortcode_Event_ICal_Feed::API_NAMESPACE . '/' . Civicrm_Ux_Shortcode_Event_ICal_Feed::INTERNAL_ENDPOINT ) );
$opt = Civicrm_Ux::getInstance()->get_store()->get_option( 'civicrm_summary_options' );
$opt_c = Civicrm_Ux::getInstance()->get_store()->get_option( 'civicrm_contribution_ux' );
$opt = Civicrm_Ux::getInstance()
->get_store()
->get_option( 'civicrm_summary_options' );
$opt_c = Civicrm_Ux::getInstance()
->get_store()
->get_option( 'civicrm_contribution_ux' );
?>
<div class="wrap">
<h1>CiviCRM UX</h1>
Expand All @@ -31,57 +35,83 @@ function civicrm_ux_settings_page() {
<h2>iCal Feed</h2>
<table>
<tr>
<th scope="row"><label for="ical-hash-field">Hash</label></th>
<th scope="row"><label
for="ical-hash-field">Hash</label></th>
<td><input id="ical-hash-field" type="text"
name=<?php echo '"' . Civicrm_Ux_Shortcode_Event_ICal_Feed::HASH_OPTION . '"' ?> size="40"
value="<?php echo esc_attr( get_option( Civicrm_Ux_Shortcode_Event_ICal_Feed::HASH_OPTION ) ); ?>"/>
<!-- TODO fix button -->
<button id="generate-ical-hash" type="button">GENERATE</button>
<button id="generate-ical-hash" type="button">
GENERATE
</button>
</td>
</tr>
<tr>
<th scope="row"><span>The internal feed url is: </span></th>
<td><a id="ical-internal-url" href="<?php echo $url ?>"><?php echo $url ?></a></td>
<th scope="row"><span>The internal feed url is: </span>
</th>
<td><a id="ical-internal-url"
href="<?php echo $url ?>"><?php echo $url ?></a>
</td>
</tr>
</table>
<h2>Membership Summary</h2>
<table>
<tr valign="top">
<th scope="row"><label for="civicrm_summary_show_renewal_date">The number of days to show the
<th scope="row"><label
for="civicrm_summary_show_renewal_date">The
number of days to show the
renewal notice and URL</label></th>
<td><input type="number" min="0" step="1" id="civicrm_summary_show_renewal_date"
<td><input type="number" min="0" step="1"
id="civicrm_summary_show_renewal_date"
name="civicrm_summary_options[civicrm_summary_show_renewal_date]"
value="<?php echo $opt['civicrm_summary_show_renewal_date']; ?>"/></td>
value="<?php echo $opt['civicrm_summary_show_renewal_date']; ?>"/>
</td>
</tr>
<tr valign="top">
<th scope="row"><label style="float:left;" for="civicrm_summary_membership_join_URL">URL for the
<th scope="row"><label style="float:left;"
for="civicrm_summary_membership_join_URL">URL
for the
membership join page</label></th>
<td><input type="text" id="civicrm_summary_membership_join_URL"
<td><input type="text"
id="civicrm_summary_membership_join_URL"
name="civicrm_summary_options[civicrm_summary_membership_join_URL]"
value="<?php echo $opt['civicrm_summary_membership_join_URL']; ?>"/></td>
value="<?php echo $opt['civicrm_summary_membership_join_URL']; ?>"/>
</td>
</tr>
<tr valign="top">
<th scope="row"><label style="float:left;" for="civicrm_summary_membership_renew_URL">URL for
<th scope="row"><label style="float:left;"
for="civicrm_summary_membership_renew_URL">URL
for
the membership renewal page</label></th>
<td><input type="text" id="civicrm_summary_membership_renew_URL"
<td><input type="text"
id="civicrm_summary_membership_renew_URL"
name="civicrm_summary_options[civicrm_summary_membership_renew_URL]"
value="<?php echo $opt['civicrm_summary_membership_renew_URL']; ?>"/></td>
value="<?php echo $opt['civicrm_summary_membership_renew_URL']; ?>"/>
</td>
</tr>
</table>
<h2>Contribution Page Tweaks</h2>
<table>
<tr vlign="top">
<td colspan="2"><label><input type="checkbox" name="civicrm_contribution_ux[is_recur_default]"<?php if ($opt_c['is_recur_default']) echo ' checked="checked"'; ?>>Set contributions as recurring by default</label></td>
<td colspan="2"><label><input type="checkbox"
name="civicrm_contribution_ux[is_recur_default]"<?php if ( $opt_c['is_recur_default'] ) {
echo ' checked="checked"';
} ?>>Set contributions as recurring by
default</label></td>
</tr>
<tr vlign="top">
<td colspan="2"><label><input type="checkbox" name="civicrm_contribution_ux[is_autorenew_default]"<?php if ($opt_c['is_autorenew_default']) echo ' checked="checked"'; ?>>Set memberships as autorenewal by default</label></td>
<td colspan="2"><label><input type="checkbox"
name="civicrm_contribution_ux[is_autorenew_default]"<?php if ( $opt_c['is_autorenew_default'] ) {
echo ' checked="checked"';
} ?>>Set memberships as autorenewal by
default</label></td>
</tr>
</table>
</div>
<?php submit_button(); ?>
<?php /** The documentation in this file is outdated <div>
<a href="<?php echo plugin_dir_url(__FILE__) . 'civicrm-ux-guide.html'; ?>" target="_blank">CiviCRM UX guide</a>
</div> /**/ ?>
<?php /** The documentation in this file is outdated <div>
* <a href="<?php echo plugin_dir_url(__FILE__) . 'civicrm-ux-guide.html'; ?>" target="_blank">CiviCRM UX guide</a>
* </div> /**/ ?>
</form>
</div>
<?php }
15 changes: 9 additions & 6 deletions includes/class-civicrm-ux-option-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
* Class Civicrm_Ux_Option_Store
*/
class Civicrm_Ux_Option_Store {

/**
* array[option name]
* ['instance']
* ['default']
*
* @var array
*/
protected $options;
Expand All @@ -18,16 +20,16 @@ public function __construct() {
$this->options = [];

// For membership
$this->register_option( 'civicrm_summary_options', null, [
$this->register_option( 'civicrm_summary_options', NULL, [
'civicrm_summary_show_renewal_date' => '30',
'civicrm_summary_membership_join_URL' => '/join/',
'civicrm_summary_membership_renew_URL' => '/renew/'
'civicrm_summary_membership_renew_URL' => '/renew/',
] );

// For contributions
$this->register_option( 'civicrm_contribution_ux', null, [
'is_recur_default' => FALSE,
'is_autorenew_default' => FALSE
$this->register_option( 'civicrm_contribution_ux', NULL, [
'is_recur_default' => FALSE,
'is_autorenew_default' => FALSE,
] );
}

Expand All @@ -39,7 +41,7 @@ public function register_option( $name, $instance, $default = '' ) {

$this->options[ $name ] = [
'instance' => $instance,
'default' => $default
'default' => $default,
];
}

Expand All @@ -58,4 +60,5 @@ public function delete_option( $name ) {
public function get_options() {
return $this->options;
}

}
49 changes: 27 additions & 22 deletions public/class-civicrm-ux-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,55 +97,60 @@ public function enqueue_scripts() {
* class.
*/

wp_enqueue_script( $this->civicrm_ux, plugin_dir_url( __FILE__ ) . 'js/civicrm-ux-public.js', [ 'jquery' ], $this->version, false );
wp_enqueue_script( $this->civicrm_ux, plugin_dir_url( __FILE__ ) . 'js/civicrm-ux-public.js', [ 'jquery' ], $this->version, FALSE );

$opt = Civicrm_Ux::getInstance()->get_store()->get_option( 'civicrm_contribution_ux' );
$opt = Civicrm_Ux::getInstance()
->get_store()
->get_option( 'civicrm_contribution_ux' );

$options_map = [
'is_recur_default' => !! $opt['is_recur_default'],
'is_autorenew_default' => !! $opt['is_autorenew_default'],
'is_recur_default' => ! ! $opt['is_recur_default'],
'is_autorenew_default' => ! ! $opt['is_autorenew_default'],
];

wp_add_inline_script($this->civicrm_ux, 'window.wp = window.wp || ({}); window.wp.CiviCRM_UX = (' . json_encode($options_map) . ')', 'before');
wp_add_inline_script( $this->civicrm_ux, 'window.wp = window.wp || ({}); window.wp.CiviCRM_UX = (' . json_encode( $options_map ) . ')', 'before' );

}

/**
* Use the title as set for WordPress in the Avada page titlebar.
*
* @since 1.1.6
*/
public function avada_page_title_bar_contents($parts) {
/**
* Use the title as set for WordPress in the Avada page titlebar.
*
* @since 1.1.6
*/
public function avada_page_title_bar_contents( $parts ) {
[ $title, $subtitle, $secondary_content ] = $parts;

return [ get_the_title(), $subtitle, $secondary_content ];
}

/**
* Override the timezone of Event Organiser event date/times to that of the linked event.
* Override the timezone of Event Organiser event date/times to that of the
* linked event.
*
* @since 1.2.0
*/
function event_organiser_timezone_filter ( $formatted, \DateTime $date, $format, $post_id, $occurrence_id ) {
$civi_id = reset(civicrm_eo()->db->get_civi_event_ids_by_eo_event_id($post_id));
function event_organiser_timezone_filter( $formatted, \DateTime $date, $format, $post_id, $occurrence_id ) {
$civi_id = reset( civicrm_eo()->db->get_civi_event_ids_by_eo_event_id( $post_id ) );

try {
$civi_event = $civi_id ? (\Civi\Api4\Event::get(FALSE)
->addSelect('id', 'event_tz')
->addWhere('id', '=', $civi_id)
->execute())[0] : NULL;
$civi_event = $civi_id ? ( \Civi\Api4\Event::get( FALSE )
->addSelect( 'id', 'event_tz' )
->addWhere( 'id', '=', $civi_id )
->execute() )[0] : NULL;

if(!empty($civi_event['event_tz'])) {
if ( ! empty( $civi_event['event_tz'] ) ) {
$timezone = new \DateTimeZone( $civi_event['event_tz'] );

$date->setTimeZone( $timezone );

return eo_format_datetime($date, $format);
return eo_format_datetime( $date, $format );
}
} catch( \API_Exception $e ) {
\Civi::log()->error("Could not set timezone for event {$post_id}: {$e->getMessage()}");
} catch ( \API_Exception $e ) {
\Civi::log()
->error( "Could not set timezone for event {$post_id}: {$e->getMessage()}" );
}

return $formatted;
}

}

0 comments on commit a7d4e70

Please sign in to comment.