Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rb192 #197

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Rb192 #197

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions classes/class-eventorganiser-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,19 @@ static function handle_venuemap_shortcode($atts) {

$venue_slugs = explode(',',$atts['venue']);

$args = shortcode_atts( array(
'zoom' => 15, 'scrollwheel'=>'true','zoomcontrol'=>'true',
'rotatecontrol'=>'true','pancontrol'=>'true','overviewmapcontrol'=>'true',
'streetviewcontrol'=>'true','maptypecontrol'=>'true','draggable'=>'true',
'maptypeid' => 'ROADMAP',
'width' => '100%','height' => '200px','class' => '',
'tooltip'=>'false'
), $atts );

//Cast options as boolean:
$bool_options = array('tooltip','scrollwheel','zoomcontrol','rotatecontrol','pancontrol','overviewmapcontrol','streetviewcontrol','draggable','maptypecontrol');
foreach( $bool_options as $option ){
$args[$option] = ( $args[$option] == 'false' ? false : true );
// Cast options as boolean:
$boolean_keys = array_filter(eo_venue_map_defaults(), "is_bool");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how the boolean keys are treated, but I think the defaults should be an array rather than a separate function. That way the default values are obvious within the function.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, defaults are used in two separate places. I see the reasoning now...

The default values, however are different for the function/shortcode (tooltip as far as I can tell).

if (!function_exists("cast_to_boolean_if_possible")) {
function cast_to_boolean_if_possible($attribute) {
return ("false" === $attribute ? false : true);
}
}
$booleans = array_intersect_key($atts, $boolean_keys);
$booleans_cast = array_map("cast_to_boolean_if_possible", $booleans);
$non_booleans = array_diff_key($atts, $boolean_keys);
$all_atts = array_merge($booleans_cast, $non_booleans);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is defining/ using $non_booleans necessary. We could just do

$all_atts = array_merge( $atts, $booleans_cast );

And remove lines 164 & 165.


return eo_get_venue_map($venue_slugs, $args);
return eo_get_venue_map($venue_slugs, $all_atts);
}


Expand Down Expand Up @@ -421,7 +418,6 @@ static function print_script() {
));

if( !empty(self::$calendars) || !empty(self::$map) || !empty(self::$widget_calendars) ):
wp_enqueue_script( 'eo_qtip2');
wp_enqueue_script( 'eo_front');

if( !eventorganiser_get_option( 'disable_css' ) ){
Expand All @@ -430,8 +426,11 @@ static function print_script() {
}
endif;

if( !empty( self::$map ) )
if( !empty( self::$map ) ) {
wp_enqueue_script( 'eo_GoogleMap' );
} else {
wp_enqueue_script( 'eo_qtip2');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would enqueue qtip2 whenever a map isn't used. We only wanted enqueued if self::$calendars is non-empty.

}
}
}

Expand Down
2 changes: 1 addition & 1 deletion event-organiser.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,4 @@ function eventorganiser_get_option( $option = false, $default = false ){
require_once(EVENT_ORGANISER_DIR.'classes/class-eo-calendar-widget.php');
require_once(EVENT_ORGANISER_DIR.'classes/class-eo-widget-categories.php');
require_once(EVENT_ORGANISER_DIR.'classes/class-eo-widget-venues.php');
require_once(EVENT_ORGANISER_DIR.'classes/class-eventorganiser-shortcodes.php');
require_once(EVENT_ORGANISER_DIR.'classes/class-eventorganiser-shortcodes.php');
30 changes: 23 additions & 7 deletions includes/event-organiser-venue-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,19 @@ function eo_delete_venue($venue_id){
return true;
}

/**
* Defaults for the venue map
*/
function eo_venue_map_defaults() {
return array(
'zoom' => 15, 'scrollwheel' => true, 'zoomcontrol' => true, 'rotatecontrol' => true,
'pancontrol' => true, 'overviewmapcontrol' => true, 'streetviewcontrol' => true,
'maptypecontrol' => true, 'draggable' => true, 'maptypeid' => 'ROADMAP',
'width' => '100%', 'height' => '200px', 'class' => '',
'tooltip' => true, 'centerlat' => "", 'centerlng' => "", "disableautopan" => false
);
}

/**
* Returns the mark-up for a Google map of the venue (and enqueues scripts).
* Accepts an arguments array corresponding to the attributes supported by the shortcode.
Expand Down Expand Up @@ -694,16 +707,19 @@ function eo_get_venue_map($venue_slug_or_id='', $args=array()){
$venue_ids = array_map('eo_get_venue_id_by_slugorid',$venue_slug_or_id);

//Map properties
$args = shortcode_atts( array(
'zoom' => 15, 'scrollwheel'=>true, 'zoomcontrol'=>true, 'rotatecontrol'=>true,
'pancontrol'=>true, 'overviewmapcontrol'=>true, 'streetviewcontrol'=>true,
'maptypecontrol'=>true, 'draggable'=>true,'maptypeid' => 'ROADMAP',
'width' => '100%','height' => '200px','class' => '',
'tooltip' => true
), $args );
$args = shortcode_atts(eo_venue_map_defaults(), $args);

//Cast zoom as integer
$args['zoom'] = (int) $args['zoom'];

// remove center lat and lng if they are not filled both
if(is_numeric($args['centerlat']) && is_numeric($args['centerlng'])) {
$args['centerlat'] = (double) $args['centerlat'];
$args['centerlng'] = (double) $args['centerlng'];
} else {
unset($args['centerlng']);
unset($args['centerlat']);
}

//Escape attributes
$width = esc_attr($args['width']);
Expand Down
4 changes: 2 additions & 2 deletions js/admin-calendar.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/edit-event-controller.min.js

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

4 changes: 2 additions & 2 deletions js/event-manager.min.js

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

Loading