Completed
Branch old/BUG-7514-7935-7936-price-o... (518ae6)
by
unknown
25:14 queued 22:51
created
core/db_models/helpers/EE_Secondary_Table.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -1,17 +1,17 @@  discard block
 block discarded – undo
1 1
 <?php
2
-require_once( EE_MODELS . 'helpers/EE_Table_Base.php');
3
-class EE_Secondary_Table extends EE_Table_Base{
2
+require_once(EE_MODELS.'helpers/EE_Table_Base.php');
3
+class EE_Secondary_Table extends EE_Table_Base {
4 4
 	protected $_extra_join_conditions;
5 5
 	
6
-	function __construct($table_name, $pk_column,  $fk_column = null, $extra_join_conditions = null){
6
+	function __construct($table_name, $pk_column, $fk_column = null, $extra_join_conditions = null) {
7 7
 		$this->_fk_on_table = $fk_column;
8 8
 		$this->_extra_join_conditions = $extra_join_conditions;
9 9
 		parent::__construct($table_name, $pk_column);
10 10
 	}
11
-	function get_fk_on_table(){
11
+	function get_fk_on_table() {
12 12
 		return $this->_fk_on_table;
13 13
 	}
14
-	function _construct_finalize_set_table_to_join_with(EE_Table_Base $table){
14
+	function _construct_finalize_set_table_to_join_with(EE_Table_Base $table) {
15 15
 		$this->_table_to_join_with = $table;
16 16
 	}
17 17
 	/**
@@ -19,14 +19,14 @@  discard block
 block discarded – undo
19 19
 	 * @return string of sql like "Event.post_type = 'event'", which gets added to
20 20
 	 * the end of the join statement with the primary table
21 21
 	 */
22
-	function get_extra_join_conditions(){
22
+	function get_extra_join_conditions() {
23 23
 		return $this->_extra_join_conditions;
24 24
 	}
25 25
 	/**
26 26
 	 * 
27 27
 	 * @return EE_Primary_Table
28 28
 	 */
29
-	function get_table_to_join_with(){
29
+	function get_table_to_join_with() {
30 30
 		return $this->_table_to_join_with;
31 31
 	}
32 32
 	/**
@@ -36,15 +36,15 @@  discard block
 block discarded – undo
36 36
 	 * @param string $table allows us to set special conditions on the $table_name portion of the join query (i.e. doing a subquery)
37 37
 	 * @return string of SQL
38 38
 	 */
39
-	function get_join_sql( $primary_table_alias_with_model_chain_prefix  ){
39
+	function get_join_sql($primary_table_alias_with_model_chain_prefix) {
40 40
 		
41 41
 		$table_name = $this->get_table_name();
42
-		$secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix) . $this->get_table_alias();
42
+		$secondary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($primary_table_alias_with_model_chain_prefix).$this->get_table_alias();
43 43
 		$other_table_pk = $this->get_table_to_join_with()->get_pk_column();
44 44
 		$fk = $this->get_fk_on_table();
45 45
 		$join_sql = " LEFT JOIN $table_name AS $secondary_table_alias ON $primary_table_alias_with_model_chain_prefix.$other_table_pk = $secondary_table_alias.$fk ";
46
-		if($this->get_extra_join_conditions()){
47
-			$join_sql.="AND ".$this->get_extra_join_conditions();
46
+		if ($this->get_extra_join_conditions()) {
47
+			$join_sql .= "AND ".$this->get_extra_join_conditions();
48 48
 		}
49 49
 		return $join_sql;
50 50
 	}
@@ -58,14 +58,14 @@  discard block
 block discarded – undo
58 58
 	 * This is useful if the secondary table is already included in the SQL, but the primary table is not yet.
59 59
 	 * @return string
60 60
 	 */
61
-	function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix){
62
-		$primary_table_name =$this->get_table_to_join_with()->get_table_name();
63
-		$primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias();
64
-		$primary_table_pk = $this->get_table_to_join_with()->get_pk_column();//$this->get_pk_column();
61
+	function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix) {
62
+		$primary_table_name = $this->get_table_to_join_with()->get_table_name();
63
+		$primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix).$this->get_table_to_join_with()->get_table_alias();
64
+		$primary_table_pk = $this->get_table_to_join_with()->get_pk_column(); //$this->get_pk_column();
65 65
 		$fk = $this->get_fk_on_table();
66 66
 		$join_sql = " LEFT JOIN $primary_table_name AS $primary_table_alias ON $primary_table_alias.$primary_table_pk = $secondary_table_alias_with_model_chain_prefix.$fk ";
67
-		if($this->get_extra_join_conditions()){
68
-			$join_sql.="AND ".$this->get_extra_join_conditions();
67
+		if ($this->get_extra_join_conditions()) {
68
+			$join_sql .= "AND ".$this->get_extra_join_conditions();
69 69
 		}
70 70
 		return $join_sql;
71 71
 	}
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	public function get_select_join_limit_join($limit) {
79 79
 		//first get the select
80 80
 		$select = $this->get_select_join_limit($limit);
81
-		$join_sql = $this->get_join_sql( $select );
81
+		$join_sql = $this->get_join_sql($select);
82 82
 		return $join_sql;
83 83
 	}
84 84
 
@@ -87,12 +87,12 @@  discard block
 block discarded – undo
87 87
 	function get_fully_qualified_fk_column() {
88 88
 		$table_alias = $this->get_table_alias();
89 89
 		$fk = $this->get_fk_on_table();
90
-		return $table_alias . '.' . $fk;
90
+		return $table_alias.'.'.$fk;
91 91
 	}
92 92
 
93 93
 	function get_fully_qualified_pk_on_fk_table() {
94 94
 		$table_alias = $this->get_table_to_join_with()->get_table_alias();
95 95
 		$pk = $this->get_table_to_join_with()->get_pk_column();
96
-		return $table_alias . '.' . $pk;
96
+		return $table_alias.'.'.$pk;
97 97
 	}
98 98
 }
99 99
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Table_Base.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * Base class for defining the tables that comprise models. This is used to store information
5 5
  * about the table\s alias, private key, etc.
6 6
  */
7
-abstract class EE_Table_Base{
7
+abstract class EE_Table_Base {
8 8
 	var $_table_name;
9 9
 	var $_table_alias;
10 10
 	/**
@@ -13,21 +13,21 @@  discard block
 block discarded – undo
13 13
 	 */
14 14
 	protected $_pk_column;
15 15
 	
16
-	function __construct($table_name, $pk_column){
16
+	function __construct($table_name, $pk_column) {
17 17
 		global $wpdb;
18
-		$this->_table_name = $wpdb->prefix . $table_name;
18
+		$this->_table_name = $wpdb->prefix.$table_name;
19 19
 		$this->_pk_column = $pk_column;
20 20
 	}
21 21
 	
22
-	function _construct_finalize_with_alias($table_alias){
22
+	function _construct_finalize_with_alias($table_alias) {
23 23
 		$this->_table_alias = $table_alias;
24 24
 	}
25 25
 	
26
-	function get_table_name(){
26
+	function get_table_name() {
27 27
 		return $this->_table_name;
28 28
 	}
29
-	function get_table_alias(){
30
-		if( ! $this->_table_alias){
29
+	function get_table_alias() {
30
+		if ( ! $this->_table_alias) {
31 31
 			throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
32 32
 		}
33 33
 		return $this->_table_alias;
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	 * 
38 38
 	 * @return string name of column of PK
39 39
 	 */
40
-	function get_pk_column(){
40
+	function get_pk_column() {
41 41
 		return $this->_pk_column;
42 42
 	}
43 43
 	
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
 	 * returns a string with the table alias, a period, and the private key's column.
48 48
 	 * @return string
49 49
 	 */
50
-	function get_fully_qualified_pk_column(){
51
-		$sql =  $this->get_table_alias().".".$this->get_pk_column();
50
+	function get_fully_qualified_pk_column() {
51
+		$sql = $this->get_table_alias().".".$this->get_pk_column();
52 52
 		return $sql;
53 53
 	}
54 54
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 * returns the special sql for a inner select with a limit.
58 58
 	 * @return string    SQL select
59 59
 	 */
60
-	public function get_select_join_limit( $limit ) {
61
-		$limit = is_array( $limit ) ? 'LIMIT ' . implode(',', array_map( 'intval', $limit ) ) : 'LIMIT ' . (int) $limit;
62
-		$SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
60
+	public function get_select_join_limit($limit) {
61
+		$limit = is_array($limit) ? 'LIMIT '.implode(',', array_map('intval', $limit)) : 'LIMIT '.(int) $limit;
62
+		$SQL = SP.'(SELECT * FROM '.$this->_table_name.SP.$limit.') AS '.$this->_table_alias;
63 63
 		return $SQL;
64 64
 	}
65 65
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Credit_Card_Input.input.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -7,16 +7,16 @@
 block discarded – undo
7 7
  * @subpackage
8 8
  * @author				Mike Nelson
9 9
  */
10
-class EE_Credit_Card_Input extends EE_Form_Input_Base{
10
+class EE_Credit_Card_Input extends EE_Form_Input_Base {
11 11
 
12 12
 	/**
13 13
 	 * @param array $input_settings
14 14
 	 */
15
-	function __construct($input_settings = array()){
15
+	function __construct($input_settings = array()) {
16 16
 		$input_settings['required'] = TRUE;
17 17
 		$this->_set_display_strategy(new EE_Text_Input_Display_Strategy());
18 18
 		$this->_set_normalization_strategy(new EE_Text_Normalization());
19
-		$this->_add_validation_strategy(new EE_Credit_Card_Validation_Strategy( isset( $input_settings[ 'validation_error_message' ] ) ? $input_settings[ 'validation_error_message' ] : NULL ));
19
+		$this->_add_validation_strategy(new EE_Credit_Card_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : NULL));
20 20
 		$this->set_sensitive_data_removal_strategy(new EE_Credit_Card_Sensitive_Data_Removal());
21 21
 		parent::__construct($input_settings);
22 22
 	}
Please login to merge, or discard this patch.
strategies/validation/EE_Text_Validation_Strategy.strategy.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
  * @subpackage	Expression package is undefined on line 19, column 19 in Templates/Scripting/PHPClass.php.
7 7
  * @author				Mike Nelson
8 8
  */
9
-class EE_Text_Validation_Strategy extends EE_Validation_Strategy_Base{
9
+class EE_Text_Validation_Strategy extends EE_Validation_Strategy_Base {
10 10
 
11 11
 	/**
12 12
 	 * @param $normalized_value
Please login to merge, or discard this patch.
core/libraries/messages/EE_messenger.lib.php 2 patches
Spacing   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!defined('EVENT_ESPRESSO_VERSION') )
2
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
3 3
 	exit('NO direct script access allowed');
4 4
 
5 5
 /**
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 	 * @return void
290 290
 	 */
291 291
 	public function enqueue_scripts_styles() {
292
-		do_action( 'AHEE__EE_messenger__enqueue_scripts_styles');
292
+		do_action('AHEE__EE_messenger__enqueue_scripts_styles');
293 293
 	}
294 294
 
295 295
 
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 
326 326
 		$this->_supports_labels->template_variation_description = __('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.');
327 327
 
328
-		$this->_supports_labels = apply_filters( 'FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this );
328
+		$this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this);
329 329
 	}
330 330
 
331 331
 
@@ -340,10 +340,10 @@  discard block
 block discarded – undo
340 340
 	 * @return stdClass
341 341
 	 */
342 342
 	public function get_supports_labels() {
343
-		if ( empty( $this->_supports_labels->template_pack ) || empty( $this->_supports_labels->template_variation) ) {
343
+		if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) {
344 344
 			$this->_set_supports_labels_defaults();
345 345
 		}
346
-		return apply_filters( 'FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this );
346
+		return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this);
347 347
 	}
348 348
 
349 349
 
@@ -363,10 +363,10 @@  discard block
 block discarded – undo
363 363
 	 *
364 364
 	 * @return string                    path or url for the requested variation.
365 365
 	 */
366
-	public function get_variation( EE_Messages_Template_Pack $pack, $message_type_name, $url = FALSE, $type = 'main', $variation = 'default', $skip_filters = FALSE ) {
366
+	public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = FALSE, $type = 'main', $variation = 'default', $skip_filters = FALSE) {
367 367
 		$this->_tmp_pack = $pack;
368
-		$variation_path = apply_filters( 'EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters );
369
-		$variation_path = empty( $variation_path ) ? $this->_tmp_pack->get_variation( $this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters ) : $variation_path;
368
+		$variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters);
369
+		$variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;
370 370
 		return $variation_path;
371 371
 
372 372
 	}
@@ -384,13 +384,13 @@  discard block
 block discarded – undo
384 384
 	 * @return array
385 385
 	 */
386 386
 	public function get_default_message_types() {
387
-		$class = get_class( $this );
387
+		$class = get_class($this);
388 388
 
389 389
 		//messenger specific filter
390
-		$default_types = apply_filters( 'FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this );
390
+		$default_types = apply_filters('FHEE__'.$class.'__get_default_message_types__default_types', $this->_default_message_types, $this);
391 391
 
392 392
 		//all messengers filter
393
-		$default_types = apply_filters( 'FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this );
393
+		$default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this);
394 394
 		return $default_types;
395 395
 	}
396 396
 
@@ -405,14 +405,14 @@  discard block
 block discarded – undo
405 405
 	 * @return array
406 406
 	 */
407 407
 	public function get_valid_message_types() {
408
-		$class = get_class( $this );
408
+		$class = get_class($this);
409 409
 
410 410
 		//messenger specific filter
411 411
 		//messenger specific filter
412
-		$valid_types = apply_filters( 'FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this );
412
+		$valid_types = apply_filters('FHEE__'.$class.'__get_valid_message_types__valid_types', $this->_valid_message_types, $this);
413 413
 
414 414
 		//all messengers filter
415
-		$valid_types = apply_filters( 'FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this );
415
+		$valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this);
416 416
 		return $valid_types;
417 417
 	}
418 418
 
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 	 * @access public
427 427
 	 * @param array $new_config Whatever is put in here will reset the _validator_config property
428 428
 	 */
429
-	public function set_validator_config( $new_config ) {
429
+	public function set_validator_config($new_config) {
430 430
 		$this->_validator_config = $new_config;
431 431
 	}
432 432
 
@@ -442,8 +442,8 @@  discard block
 block discarded – undo
442 442
 	public function get_validator_config() {
443 443
 		$class = get_class($this);
444 444
 
445
-		$config = apply_filters( 'FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this );
446
-		$config = apply_filters( 'FHEE__EE_messenger__get_validator_config', $config, $this );
445
+		$config = apply_filters('FHEE__'.$class.'__get_validator_config', $this->_validator_config, $this);
446
+		$config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this);
447 447
 		return $config;
448 448
 	}
449 449
 
@@ -460,8 +460,8 @@  discard block
 block discarded – undo
460 460
 	 * @access public
461 461
 	 * @return string content for page
462 462
 	 */
463
-	public function get_messenger_admin_page_content( $page, $action = null, $extra = array(), $message_types = array() ) {
464
-		return $this->_get_admin_page_content( $page, $action, $extra, $message_types );
463
+	public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array()) {
464
+		return $this->_get_admin_page_content($page, $action, $extra, $message_types);
465 465
 	}
466 466
 
467 467
 
@@ -470,76 +470,76 @@  discard block
 block discarded – undo
470 470
 
471 471
 
472 472
 
473
-	protected function _get_admin_content_events_edit( $message_types, $extra ) {
473
+	protected function _get_admin_content_events_edit($message_types, $extra) {
474 474
 		//defaults
475 475
 		$template_args = array();
476 476
 		$custom_templates = array();
477 477
 		$selector_rows = '';
478 478
 
479 479
 		//we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.
480
-		$event_id = isset( $extra['event'] ) ? $extra['event'] : NULL;
480
+		$event_id = isset($extra['event']) ? $extra['event'] : NULL;
481 481
 
482
-		$template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
483
-		$template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';
482
+		$template_wrapper_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_wrapper.template.php';
483
+		$template_row_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_row.template.php';
484 484
 
485 485
 		//array of template objects for global and custom (non-trashed) (but remember just for this messenger!)
486
-		$global_templates = EEM_Message_Template_Group::instance()->get_all( array( array('MTP_messenger' => $this->name, 'MTP_is_global' => TRUE, 'MTP_is_active' => TRUE ) ) );
487
-		$templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event( $event_id, array( 'MTP_messenger' => $this->name, 'MTP_is_active' => TRUE ) );
488
-		$templates_for_event = !empty( $templates_for_event ) ? $templates_for_event : array();
486
+		$global_templates = EEM_Message_Template_Group::instance()->get_all(array(array('MTP_messenger' => $this->name, 'MTP_is_global' => TRUE, 'MTP_is_active' => TRUE)));
487
+		$templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event($event_id, array('MTP_messenger' => $this->name, 'MTP_is_active' => TRUE));
488
+		$templates_for_event = ! empty($templates_for_event) ? $templates_for_event : array();
489 489
 
490 490
 		//so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)
491
-		foreach ( $global_templates as $mtpgID => $mtpg ) {
491
+		foreach ($global_templates as $mtpgID => $mtpg) {
492 492
 			//verify this message type is supposed to show on this page
493 493
 			$mtp_obj = $mtpg->message_type_obj();
494
-			if ( ! $mtp_obj instanceof EE_message_type ) {
494
+			if ( ! $mtp_obj instanceof EE_message_type) {
495 495
 				continue;
496 496
 			}
497 497
 			$mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
498
-			if ( ! in_array( 'events_edit', $mtp_obj->admin_registered_pages ) )
498
+			if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages))
499 499
 				continue;
500 500
 			$stargs = array();
501 501
 			$default_value = '';
502 502
 			$select_values = array();
503 503
 			$select_values[$mtpgID] = __('Global', 'event_espresso');
504
-			$default_value = array_key_exists( $mtpgID, $templates_for_event ) && ! $mtpg->get('MTP_is_override' ) ? $mtpgID : NULL;
504
+			$default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : NULL;
505 505
 
506 506
 			//if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.
507 507
 
508
-			if ( ! $mtpg->get('MTP_is_override' ) ) {
508
+			if ( ! $mtpg->get('MTP_is_override')) {
509 509
 				//any custom templates for this message type?
510
-				$custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt( $this->name, $mtpg->message_type() );
510
+				$custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());
511 511
 
512
-				foreach( $custom_templates as $cmtpgID => $cmtpg ) {
512
+				foreach ($custom_templates as $cmtpgID => $cmtpg) {
513 513
 					$select_values[$cmtpgID] = $cmtpg->name();
514
-					$default_value = array_key_exists( $cmtpgID, $templates_for_event ) ? $cmtpgID : $default_value;
514
+					$default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;
515 515
 				}
516 516
 			}
517 517
 
518 518
 			//if there is no $default_value then we set it as the global
519
-			$default_value = empty( $default_value ) ? $mtpgID : $default_value;
519
+			$default_value = empty($default_value) ? $mtpgID : $default_value;
520 520
 
521
-			$edit_url = EEH_URL::add_query_args_and_nonce( array('page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value), admin_url('admin.php') );
522
-			$create_url = EEH_URL::add_query_args_and_nonce( array('page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value ) );
521
+			$edit_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'edit_message_template', 'id' => $default_value), admin_url('admin.php'));
522
+			$create_url = EEH_URL::add_query_args_and_nonce(array('page' => 'espresso_messages', 'action' => 'add_new_message_template', 'GRP_ID' => $default_value));
523 523
 
524
-			$st_args['mt_name'] = ucwords( $mtp_obj->label['singular'] );
524
+			$st_args['mt_name'] = ucwords($mtp_obj->label['singular']);
525 525
 			$st_args['mt_slug'] = $mtpg->message_type();
526 526
 			$st_args['messenger_slug'] = $this->name;
527
-			$st_args['selector'] = EEH_Form_Fields::select_input( 'event_message_templates_relation[' . $mtpgID . ']', $select_values, $default_value, 'data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '"', 'message-template-selector' );
527
+			$st_args['selector'] = EEH_Form_Fields::select_input('event_message_templates_relation['.$mtpgID.']', $select_values, $default_value, 'data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'"', 'message-template-selector');
528 528
 
529 529
 			//note that  message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).
530
-			$st_args['create_button'] =  $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="' . $this->name . '" data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $create_url . '" class="button button-small create-mtpg-button">' . __('Create New Custom', 'event_espresso') . '</a>';
531
-			$st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can( 'ee_edit_messages', 'espresso_messsages_add_new_message_template' ) ? $st_args['create_button'] : '';
532
-			$st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can( 'ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID ) ?  '<a data-messagetype="' . $mtpg->message_type() . '" data-grpid="' . $default_value . '" target="_blank" href="' . $edit_url . '" class="button button-small edit-mtpg-button">' . __('Edit', 'event_espresso') . '</a>' : '';
533
-			$selector_rows .= EEH_Template::display_template( $template_row_path, $st_args, TRUE );
530
+			$st_args['create_button'] = $mtpg->get('MTP_is_override') ? '' : '<a data-messenger="'.$this->name.'" data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$create_url.'" class="button button-small create-mtpg-button">'.__('Create New Custom', 'event_espresso').'</a>';
531
+			$st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'espresso_messsages_add_new_message_template') ? $st_args['create_button'] : '';
532
+			$st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_message', 'espresso_messages_edit_message_template', $mtpgID) ? '<a data-messagetype="'.$mtpg->message_type().'" data-grpid="'.$default_value.'" target="_blank" href="'.$edit_url.'" class="button button-small edit-mtpg-button">'.__('Edit', 'event_espresso').'</a>' : '';
533
+			$selector_rows .= EEH_Template::display_template($template_row_path, $st_args, TRUE);
534 534
 		}
535 535
 
536 536
 		//if no selectors present then get out.
537
-		if ( empty( $selector_rows ) ) {
537
+		if (empty($selector_rows)) {
538 538
 			return '';
539 539
 		}
540 540
 
541 541
 		$template_args['selector_rows'] = $selector_rows;
542
-		return EEH_Template::display_template( $template_wrapper_path, $template_args, TRUE );
542
+		return EEH_Template::display_template($template_wrapper_path, $template_args, TRUE);
543 543
 	}
544 544
 
545 545
 
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
 	 * @return array $this->_template_fields
555 555
 	 */
556 556
 	public function get_template_fields() {
557
-		$template_fields = apply_filters( 'FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this );
558
-		$template_fields = apply_filters( 'FHEE__EE_messenger__get_template_fields', $template_fields, $this );
557
+		$template_fields = apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this);
558
+		$template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this);
559 559
 		return $template_fields;
560 560
 	}
561 561
 
@@ -568,9 +568,9 @@  discard block
 block discarded – undo
568 568
 	 * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger
569 569
 	 */
570 570
 	protected function _set_template_value($item, $value) {
571
-		if ( array_key_exists($item, $this->_template_fields) ) {
572
-			$prop = '_' . $item;
573
-			$this->$prop= $value;
571
+		if (array_key_exists($item, $this->_template_fields)) {
572
+			$prop = '_'.$item;
573
+			$this->$prop = $value;
574 574
 		}
575 575
 	}
576 576
 
@@ -580,8 +580,8 @@  discard block
 block discarded – undo
580 580
 	 * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.
581 581
 	 * @return bool | WP_Error
582 582
 	 */
583
-	public function send_message( $message, EE_message_type $message_type ) {
584
-		$this->_validate_and_setup( $message );
583
+	public function send_message($message, EE_message_type $message_type) {
584
+		$this->_validate_and_setup($message);
585 585
 		$this->_incoming_message_type = $message_type;
586 586
 		return $this->_send_message();
587 587
 	}
@@ -595,26 +595,26 @@  discard block
 block discarded – undo
595 595
 	 * @param  bool   $send    true we will actually use the _send method (for test sends). FALSE we just return preview
596 596
 	 * @return string          return the message html content
597 597
 	 */
598
-	public function get_preview( $message, EE_message_type $message_type, $send = FALSE ) {
599
-		$this->_validate_and_setup( $message );
598
+	public function get_preview($message, EE_message_type $message_type, $send = FALSE) {
599
+		$this->_validate_and_setup($message);
600 600
 
601 601
 		$this->_incoming_message_type = $message_type;
602 602
 
603
-		if ( $send ) {
603
+		if ($send) {
604 604
 			//are we overriding any existing template fields?
605 605
 			$settings = $this->get_existing_test_settings();
606
-			if ( !empty( $settings ) ) {
607
-				foreach( $settings as $field => $value ) {
608
-					$this->_set_template_value( $field, $value );
606
+			if ( ! empty($settings)) {
607
+				foreach ($settings as $field => $value) {
608
+					$this->_set_template_value($field, $value);
609 609
 				}
610 610
 			}
611 611
 		}
612 612
 
613 613
 		//enqueue preview js so that any links/buttons on the page are disabled.
614
-		if ( ! $send ) {
614
+		if ( ! $send) {
615 615
 			//the below may seem liks duplication.  However, typically if a messenger enqueues scripts/styles, it deregisters all existing wp scripts and styles first.  So the second hook ensures our previewer still gets setup.
616
-			add_action( 'wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10 );
617
-			add_action( 'AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10 );
616
+			add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10);
617
+			add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10);
618 618
 		}
619 619
 
620 620
 		return $send ? $this->_send_message() : $this->_preview();
@@ -631,12 +631,12 @@  discard block
 block discarded – undo
631 631
 	 * @return void
632 632
 	 */
633 633
 	public function add_preview_script() {
634
-		wp_register_script( 'ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true );
634
+		wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
635 635
 
636 636
 		//error message
637 637
 		EE_Registry::$i18n_js_strings['links_disabled'] = __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso');
638
-		wp_localize_script( 'ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings );
639
-		wp_enqueue_script( 'ee-messages-preview-js' );
638
+		wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings);
639
+		wp_enqueue_script('ee-messages-preview-js');
640 640
 	}
641 641
 
642 642
 
@@ -647,23 +647,23 @@  discard block
 block discarded – undo
647 647
 	 * @param  object $message message object
648 648
 	 * @return void
649 649
 	 */
650
-	protected function _validate_and_setup( $message ) {
651
-		if ( !is_object( $message ) )
652
-			throw new EE_Error( __('Incoming "$message" must be an object', 'event_espresso' ) );
650
+	protected function _validate_and_setup($message) {
651
+		if ( ! is_object($message))
652
+			throw new EE_Error(__('Incoming "$message" must be an object', 'event_espresso'));
653 653
 
654 654
 		//verify we have the required template pack value on the $message object.
655
-		if ( empty( $message->template_pack ) || ! $message->template_pack instanceof EE_Messages_Template_Pack ) {
656
-			throw new EE_Error( __('Incoming $message object must have a EE_Messages_Template_Pack object assigned to the template_pack property', 'event_espresso' ) );
655
+		if (empty($message->template_pack) || ! $message->template_pack instanceof EE_Messages_Template_Pack) {
656
+			throw new EE_Error(__('Incoming $message object must have a EE_Messages_Template_Pack object assigned to the template_pack property', 'event_espresso'));
657 657
 		}
658 658
 
659 659
 		$this->_tmp_pack = $message->template_pack;
660 660
 
661
-		$this->_variation = !empty ( $message->variation ) ? $message->variation : 'default';
661
+		$this->_variation = ! empty ($message->variation) ? $message->variation : 'default';
662 662
 
663 663
 		$template_fields = $this->get_template_fields();
664 664
 
665
-		foreach ( $template_fields as $template => $value ) {
666
-			if ( $template !== 'extra' )
665
+		foreach ($template_fields as $template => $value) {
666
+			if ($template !== 'extra')
667 667
 				$this->_set_template_value($template, $message->$template);
668 668
 		}
669 669
 	}
@@ -679,21 +679,21 @@  discard block
 block discarded – undo
679 679
 	 * @param  bool 	$preview if true we use the preview wrapper otherwise we use main wrapper.
680 680
 	 * @return string
681 681
 	 */
682
-	protected function _get_main_template( $preview = FALSE ) {
682
+	protected function _get_main_template($preview = FALSE) {
683 683
 		$type = $preview ? 'preview' : 'main';
684 684
 
685 685
 		//first get inline css (will be empty if the messenger doesn't use it)
686
-		$this->_template_args['inline_style'] = file_get_contents( $this->get_variation( $this->_tmp_pack, $this->_incoming_message_type->name, FALSE, $type, $this->_variation ), TRUE );
686
+		$this->_template_args['inline_style'] = file_get_contents($this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, FALSE, $type, $this->_variation), TRUE);
687 687
 
688
-		$wrapper_template = $this->_tmp_pack->get_wrapper( $this->name, $type );
688
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);
689 689
 
690 690
 		//check file exists and is readable
691
-		if ( !is_readable( $wrapper_template ) )
692
-			throw new EE_Error( sprintf( __('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso' ), ucwords($this->label['singular']) , $wrapper_template ) );
691
+		if ( ! is_readable($wrapper_template))
692
+			throw new EE_Error(sprintf(__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template));
693 693
 
694 694
 		//require template helper
695
-		EE_Registry::instance()->load_helper( 'Template' );
696
-		return EEH_Template::display_template( $wrapper_template, $this->_template_args, TRUE );
695
+		EE_Registry::instance()->load_helper('Template');
696
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, TRUE);
697 697
 	}
698 698
 
699 699
 
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
 	 */
730 730
 	public function get_existing_test_settings() {
731 731
 		$settings = EEH_MSG_Template::get_active_messengers_in_db();
732
-		return isset( $settings[$this->name]['test_settings'] ) ? $settings[$this->name]['test_settings'] : array();
732
+		return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array();
733 733
 	}
734 734
 
735 735
 
@@ -740,10 +740,10 @@  discard block
 block discarded – undo
740 740
 	 * @access public
741 741
 	 * @return bool 	success/fail
742 742
 	 */
743
-	public function set_existing_test_settings( $settings ) {
743
+	public function set_existing_test_settings($settings) {
744 744
 		$existing = EEH_MSG_Template::get_active_messengers_in_db();
745 745
 		$existing[$this->name]['test_settings'] = $settings;
746
-		return EEH_MSG_Template::update_active_messengers_in_db( $existing );
746
+		return EEH_MSG_Template::update_active_messengers_in_db($existing);
747 747
 	}
748 748
 
749 749
 
@@ -756,21 +756,21 @@  discard block
 block discarded – undo
756 756
 	 * @param string $field The field to retrieve the label for
757 757
 	 * @return string        	  The label
758 758
 	 */
759
-	public function get_field_label( $field ) {
759
+	public function get_field_label($field) {
760 760
 		//first let's see if the field requests is in the top level array.
761
-		if ( isset( $this->_template_fields[$field] ) && !empty( $this->_template_fields[$field]['label'] ) )
761
+		if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label']))
762 762
 			return $this->_template[$field]['label'];
763 763
 
764 764
 		//nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
765
-		if ( isset( $this->_template_fields['extra'] ) && !empty( $this->_template_fields['extra'][$field] ) && !empty( $this->_template_fields['extra'][$field]['main']['label'] )  )
765
+		if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label']))
766 766
 			return $this->_template_fields['extra'][$field]['main']['label'];
767 767
 
768 768
 		//now it's possible this field may just be existing in any of the extra array items.
769
-		if ( !empty( $this->_template_fields['extra'] ) && is_array( $this->_template_fields['extra'] ) ) {
770
-			foreach ( $this->_template_fields['extra'] as $main_field => $subfields ) {
771
-				if ( !is_array( $subfields ) )
769
+		if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) {
770
+			foreach ($this->_template_fields['extra'] as $main_field => $subfields) {
771
+				if ( ! is_array($subfields))
772 772
 					continue;
773
-				if ( isset( $subfields[$field] ) && !empty( $subfields[$field]['label'] ) )
773
+				if (isset($subfields[$field]) && ! empty($subfields[$field]['label']))
774 774
 					return $subfields[$field]['label'];
775 775
 			}
776 776
 		}
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
 	 *
792 792
 	 * @return void
793 793
 	 */
794
-	public function do_secondary_messenger_hooks( $sending_messenger_name ) {
794
+	public function do_secondary_messenger_hooks($sending_messenger_name) {
795 795
 		return;
796 796
 	}
797 797
 
Please login to merge, or discard this patch.
Braces   +26 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,6 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!defined('EVENT_ESPRESSO_VERSION') )
2
+if (!defined('EVENT_ESPRESSO_VERSION') ) {
3 3
 	exit('NO direct script access allowed');
4
+}
4 5
 
5 6
 /**
6 7
  * Event Espresso
@@ -495,8 +496,9 @@  discard block
 block discarded – undo
495 496
 				continue;
496 497
 			}
497 498
 			$mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;
498
-			if ( ! in_array( 'events_edit', $mtp_obj->admin_registered_pages ) )
499
-				continue;
499
+			if ( ! in_array( 'events_edit', $mtp_obj->admin_registered_pages ) ) {
500
+							continue;
501
+			}
500 502
 			$stargs = array();
501 503
 			$default_value = '';
502 504
 			$select_values = array();
@@ -648,8 +650,9 @@  discard block
 block discarded – undo
648 650
 	 * @return void
649 651
 	 */
650 652
 	protected function _validate_and_setup( $message ) {
651
-		if ( !is_object( $message ) )
652
-			throw new EE_Error( __('Incoming "$message" must be an object', 'event_espresso' ) );
653
+		if ( !is_object( $message ) ) {
654
+					throw new EE_Error( __('Incoming "$message" must be an object', 'event_espresso' ) );
655
+		}
653 656
 
654 657
 		//verify we have the required template pack value on the $message object.
655 658
 		if ( empty( $message->template_pack ) || ! $message->template_pack instanceof EE_Messages_Template_Pack ) {
@@ -663,8 +666,9 @@  discard block
 block discarded – undo
663 666
 		$template_fields = $this->get_template_fields();
664 667
 
665 668
 		foreach ( $template_fields as $template => $value ) {
666
-			if ( $template !== 'extra' )
667
-				$this->_set_template_value($template, $message->$template);
669
+			if ( $template !== 'extra' ) {
670
+							$this->_set_template_value($template, $message->$template);
671
+			}
668 672
 		}
669 673
 	}
670 674
 
@@ -688,8 +692,9 @@  discard block
 block discarded – undo
688 692
 		$wrapper_template = $this->_tmp_pack->get_wrapper( $this->name, $type );
689 693
 
690 694
 		//check file exists and is readable
691
-		if ( !is_readable( $wrapper_template ) )
692
-			throw new EE_Error( sprintf( __('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso' ), ucwords($this->label['singular']) , $wrapper_template ) );
695
+		if ( !is_readable( $wrapper_template ) ) {
696
+					throw new EE_Error( sprintf( __('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso' ), ucwords($this->label['singular']) , $wrapper_template ) );
697
+		}
693 698
 
694 699
 		//require template helper
695 700
 		EE_Registry::instance()->load_helper( 'Template' );
@@ -758,20 +763,24 @@  discard block
 block discarded – undo
758 763
 	 */
759 764
 	public function get_field_label( $field ) {
760 765
 		//first let's see if the field requests is in the top level array.
761
-		if ( isset( $this->_template_fields[$field] ) && !empty( $this->_template_fields[$field]['label'] ) )
762
-			return $this->_template[$field]['label'];
766
+		if ( isset( $this->_template_fields[$field] ) && !empty( $this->_template_fields[$field]['label'] ) ) {
767
+					return $this->_template[$field]['label'];
768
+		}
763 769
 
764 770
 		//nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.
765
-		if ( isset( $this->_template_fields['extra'] ) && !empty( $this->_template_fields['extra'][$field] ) && !empty( $this->_template_fields['extra'][$field]['main']['label'] )  )
766
-			return $this->_template_fields['extra'][$field]['main']['label'];
771
+		if ( isset( $this->_template_fields['extra'] ) && !empty( $this->_template_fields['extra'][$field] ) && !empty( $this->_template_fields['extra'][$field]['main']['label'] )  ) {
772
+					return $this->_template_fields['extra'][$field]['main']['label'];
773
+		}
767 774
 
768 775
 		//now it's possible this field may just be existing in any of the extra array items.
769 776
 		if ( !empty( $this->_template_fields['extra'] ) && is_array( $this->_template_fields['extra'] ) ) {
770 777
 			foreach ( $this->_template_fields['extra'] as $main_field => $subfields ) {
771
-				if ( !is_array( $subfields ) )
772
-					continue;
773
-				if ( isset( $subfields[$field] ) && !empty( $subfields[$field]['label'] ) )
774
-					return $subfields[$field]['label'];
778
+				if ( !is_array( $subfields ) ) {
779
+									continue;
780
+				}
781
+				if ( isset( $subfields[$field] ) && !empty( $subfields[$field]['label'] ) ) {
782
+									return $subfields[$field]['label'];
783
+				}
775 784
 			}
776 785
 		}
777 786
 
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Email_messenger.class.php 2 patches
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (!defined('EVENT_ESPRESSO_VERSION') )
3
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
4 4
 	exit('NO direct script access allowed');
5 5
 
6 6
 /**
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 /**
30 30
  * This sets up the email messenger for the EE_messages (notifications) subsystem in EE.
31 31
  */
32
-class EE_Email_messenger extends EE_messenger  {
32
+class EE_Email_messenger extends EE_messenger {
33 33
 
34 34
 	/**
35 35
 	 * The following are the properties that email requires for the message going out.
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	protected function _set_valid_shortcodes() {
76 76
 		//remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the message type.
77 77
 		$this->_valid_shortcodes = array(
78
-			'to' => array('email','event_author', 'primary_registration_details', 'recipient_details'),
78
+			'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
79 79
 			'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details')
80 80
 			);
81 81
 	}
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 				'shortcodes' => array('organization', 'primary_registration_details', 'event_author', 'primary_registration_details', 'recipient_details')
110 110
 				),
111 111
 			'content' => array(
112
-				'shortcodes' => array('event_list','attendee_list', 'ticket_list', 'organization', 'primary_registration_details', 'primary_registration_list', 'event_author', 'recipient_details', 'recipient_list', 'transaction', 'messenger')
112
+				'shortcodes' => array('event_list', 'attendee_list', 'ticket_list', 'organization', 'primary_registration_details', 'primary_registration_list', 'event_author', 'recipient_details', 'recipient_list', 'transaction', 'messenger')
113 113
 				),
114 114
 			'attendee_list' => array(
115 115
 				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 				'required' => array('[EVENT_LIST]')
121 121
 				),
122 122
 			'ticket_list' => array(
123
-				'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list','primary_registration_details', 'recipient_details'),
123
+				'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'primary_registration_details', 'recipient_details'),
124 124
 				'required' => array('[TICKET_LIST]')
125 125
 				),
126 126
 			'datetime_list' => array(
@@ -139,21 +139,21 @@  discard block
 block discarded – undo
139 139
 	 *
140 140
 	 * @since 4.5.0
141 141
 	 */
142
-	public function do_secondary_messenger_hooks( $sending_messenger_name ) {
143
-		if ( $sending_messenger_name = 'html' ) {
144
-			add_filter( 'FHEE__EE_Messages_Template_Pack__get_variation', array( $this, 'add_email_css' ), 10, 8 );
142
+	public function do_secondary_messenger_hooks($sending_messenger_name) {
143
+		if ($sending_messenger_name = 'html') {
144
+			add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
145 145
 		}
146 146
 	}
147 147
 
148 148
 
149 149
 
150 150
 
151
-	public function add_email_css( $variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url, EE_Messages_Template_Pack $template_pack ) {
151
+	public function add_email_css($variation_path, $messenger, $message_type, $type, $variation, $file_extension, $url, EE_Messages_Template_Pack $template_pack) {
152 152
 		//prevent recursion on this callback.
153
-		remove_filter( 'FHEE__EE_Messages_Template_Pack__get_variation', array( $this, 'add_email_css' ), 10 );
154
-		$variation = $this->get_variation( $template_pack, $message_type, $url, 'main', $variation, FALSE  );
153
+		remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
154
+		$variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, FALSE);
155 155
 
156
-		add_filter( 'FHEE__EE_Messages_Template_Pack__get_variation', array( $this, 'add_email_css' ), 10, 8 );
156
+		add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
157 157
 		return $variation;
158 158
 	}
159 159
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 				'required' => FALSE,
186 186
 				'validation' => FALSE,
187 187
 				'format' => '%s',
188
-				'value' => sprintf( __('Test email sent from %s', 'event_espresso'), get_bloginfo('name') ),
188
+				'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
189 189
 				'default'=> '',
190 190
 				'css_class' => ''
191 191
 				)
@@ -347,8 +347,8 @@  discard block
 block discarded – undo
347 347
 	 */
348 348
 	protected function _send_message() {
349 349
 		return wp_mail(
350
-			html_entity_decode( $this->_to, ENT_QUOTES, "UTF-8" ),
351
-			stripslashes( html_entity_decode( $this->_subject, ENT_QUOTES, "UTF-8" )),
350
+			html_entity_decode($this->_to, ENT_QUOTES, "UTF-8"),
351
+			stripslashes(html_entity_decode($this->_subject, ENT_QUOTES, "UTF-8")),
352 352
 			$this->_body(),
353 353
 			$this->_headers()
354 354
 		);
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 	 * @return string html body of the message content and the related css.
363 363
 	 */
364 364
 	protected function _preview() {
365
-		return $this->_body( TRUE );
365
+		return $this->_body(TRUE);
366 366
 	}
367 367
 
368 368
 
@@ -376,17 +376,17 @@  discard block
 block discarded – undo
376 376
 	 * @return string formatted header for email
377 377
 	 */
378 378
 	protected function _headers() {
379
-		$from = stripslashes_deep( html_entity_decode($this->_from,  ENT_QUOTES,"UTF-8" ) );
379
+		$from = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8"));
380 380
 		$headers = array(
381 381
 			'MIME-Version: 1.0',
382
-			'From:' . $from,
383
-			'Reply-To:' . $from,
382
+			'From:'.$from,
383
+			'Reply-To:'.$from,
384 384
 			'Content-Type:text/html; charset=utf-8'
385 385
 			);
386 386
 
387 387
 		//but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the header.
388
-		add_filter( 'wp_mail_from',  array( $this, 'set_from_address' ), 100 );
389
-		add_filter( 'wp_mail_from_name', array( $this, 'set_from_name' ), 100 );
388
+		add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
389
+		add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
390 390
 		return $headers;
391 391
 	}
392 392
 
@@ -403,19 +403,19 @@  discard block
 block discarded – undo
403 403
 	 * @return array
404 404
 	 */
405 405
 	private function _parse_from() {
406
-		if ( strpos( $this->_from, '<' ) !== false ) {
407
-			$from_name = substr( $this->_from, 0, strpos( $this->_from, '<' ) - 1 );
408
-			$from_name = str_replace( '"', '', $from_name );
409
-			$from_name = trim( $from_name );
410
-
411
-			$from_email = substr( $this->_from, strpos( $this->_from, '<' ) + 1 );
412
-			$from_email = str_replace( '>', '', $from_email );
413
-			$from_email = trim( $from_email );
406
+		if (strpos($this->_from, '<') !== false) {
407
+			$from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
408
+			$from_name = str_replace('"', '', $from_name);
409
+			$from_name = trim($from_name);
410
+
411
+			$from_email = substr($this->_from, strpos($this->_from, '<') + 1);
412
+			$from_email = str_replace('>', '', $from_email);
413
+			$from_email = trim($from_email);
414 414
 		} else {
415 415
 			$from_name = '';
416
-			$from_email = trim( $this->_from );
416
+			$from_email = trim($this->_from);
417 417
 		}
418
-		return array( $from_name, $from_email );
418
+		return array($from_name, $from_email);
419 419
 	}
420 420
 
421 421
 
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 	 *
429 429
 	 * @param string $from_email What the original from_email is.
430 430
 	 */
431
-	public function set_from_address( $from_email ) {
431
+	public function set_from_address($from_email) {
432 432
 		$parsed_from = $this->_parse_from();
433 433
 		return $parsed_from[1];
434 434
 	}
@@ -443,13 +443,13 @@  discard block
 block discarded – undo
443 443
 	 *
444 444
 	 * @param string $from_name The original from_name.
445 445
 	 */
446
-	public function set_from_name( $from_name ) {
446
+	public function set_from_name($from_name) {
447 447
 		$parsed_from = $this->_parse_from();
448
-		if ( is_array( $parsed_from) && ! empty( $parsed_from[0] ) ) {
449
-			$from_name =  $parsed_from[0];
448
+		if (is_array($parsed_from) && ! empty($parsed_from[0])) {
449
+			$from_name = $parsed_from[0];
450 450
 		}
451 451
 
452
-		return stripslashes_deep( html_entity_decode($from_name,  ENT_QUOTES,"UTF-8" ) );
452
+		return stripslashes_deep(html_entity_decode($from_name, ENT_QUOTES, "UTF-8"));
453 453
 	}
454 454
 
455 455
 
@@ -460,26 +460,26 @@  discard block
 block discarded – undo
460 460
 	 * @param bool $preview will etermine whether this is preview template or not.
461 461
 	 * @return string formatted body for email.
462 462
 	 */
463
-	protected function _body( $preview = FALSE ) {
463
+	protected function _body($preview = FALSE) {
464 464
 		//setup template args!
465 465
 		$this->_template_args = array(
466 466
 			'subject' => $this->_subject,
467 467
 			'from' => $this->_from,
468
-			'main_body' => wpautop(stripslashes_deep( html_entity_decode($this->_content,  ENT_QUOTES,"UTF-8" ) ))
468
+			'main_body' => wpautop(stripslashes_deep(html_entity_decode($this->_content, ENT_QUOTES, "UTF-8")))
469 469
 			);
470
-		$body =  $this->_get_main_template( $preview );
470
+		$body = $this->_get_main_template($preview);
471 471
 
472 472
 		//now if this isn't a preview, let's setup the body so it has inline styles
473
-		if ( !$preview ) {
474
-			require_once EE_LIBRARIES . 'messages/messenger/assets/email/CssToInlineStyles.php';
475
-			$CSS = new CssToInlineStyles( $body );
473
+		if ( ! $preview) {
474
+			require_once EE_LIBRARIES.'messages/messenger/assets/email/CssToInlineStyles.php';
475
+			$CSS = new CssToInlineStyles($body);
476 476
 			$CSS->setUseInlineStylesBlock();
477
-			$body = ltrim( $CSS->convert(), ">\n" ); //for some reason the library has a bracket and new line at the beginning.  This takes care of that.
478
-		} else if ( $preview && defined('DOING_AJAX' ) ) {
479
-			require_once EE_LIBRARIES . 'messages/messenger/assets/email/CssToInlineStyles.php';
480
-			$style = file_get_contents( $this->get_variation( $this->_tmp_pack,  $this->_incoming_message_type->name, FALSE, 'main', $this->_variation ) );
481
-			$CSS = new CssToInlineStyles( utf8_decode($body), $style );
482
-			$body = ltrim( $CSS->convert(), ">\n" );
477
+			$body = ltrim($CSS->convert(), ">\n"); //for some reason the library has a bracket and new line at the beginning.  This takes care of that.
478
+		} else if ($preview && defined('DOING_AJAX')) {
479
+			require_once EE_LIBRARIES.'messages/messenger/assets/email/CssToInlineStyles.php';
480
+			$style = file_get_contents($this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, FALSE, 'main', $this->_variation));
481
+			$CSS = new CssToInlineStyles(utf8_decode($body), $style);
482
+			$body = ltrim($CSS->convert(), ">\n");
483 483
 
484 484
 			//let's attempt to fix width's for ajax preview
485 485
 			/*$i_width = '/width:[ 0-9%]+;|width:[ 0-9px]+;/';
@@ -502,8 +502,8 @@  discard block
 block discarded – undo
502 502
 	public function get_existing_test_settings() {
503 503
 		$settings = parent::get_existing_test_settings();
504 504
 		//override subject if present because we always want it to be fresh.
505
-		if ( is_array( $settings ) && ! empty( $settings['subject'] ) ) {
506
-			$settings['subject'] = sprintf( __('Test email sent from %s', 'event_espresso'), get_bloginfo('name') );
505
+		if (is_array($settings) && ! empty($settings['subject'])) {
506
+			$settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
507 507
 		}
508 508
 		return $settings;
509 509
 	}
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,7 @@
 block discarded – undo
1 1
 <?php
2
-if (!defined('EVENT_ESPRESSO_VERSION') )
2
+if (!defined('EVENT_ESPRESSO_VERSION') ) {
3 3
 	exit('NO direct script access allowed');
4
+}
4 5
 
5 6
 /**
6 7
  * Event Espresso
Please login to merge, or discard this patch.
core/libraries/messages/messenger/assets/email/CssToInlineStyles.php 3 patches
Indentation   +708 added lines, -708 removed lines patch added patch discarded remove patch
@@ -11,712 +11,712 @@
 block discarded – undo
11 11
  */
12 12
 class CssToInlineStyles
13 13
 {
14
-    /**
15
-     * The CSS to use
16
-     *
17
-     * @var	string
18
-     */
19
-    private $css;
20
-
21
-    /**
22
-     * The processed CSS rules
23
-     *
24
-     * @var	array
25
-     */
26
-    private $cssRules;
27
-
28
-    /**
29
-     * Should the generated HTML be cleaned
30
-     *
31
-     * @var	bool
32
-     */
33
-    private $cleanup = false;
34
-
35
-    /**
36
-     * The encoding to use.
37
-     *
38
-     * @var	string
39
-     */
40
-    private $encoding = 'UTF-8';
41
-
42
-    /**
43
-     * The HTML to process
44
-     *
45
-     * @var	string
46
-     */
47
-    private $html;
48
-
49
-    /**
50
-     * Use inline-styles block as CSS
51
-     *
52
-     * @var	bool
53
-     */
54
-    private $useInlineStylesBlock = false;
55
-
56
-    /**
57
-     * Strip original style tags
58
-     *
59
-     * @var bool
60
-     */
61
-    private $stripOriginalStyleTags = false;
62
-
63
-    /**
64
-     * Exclude the media queries from the inlined styles
65
-     *
66
-     * @var bool
67
-     */
68
-    private $excludeMediaQueries = false;
69
-
70
-    /**
71
-     * Creates an instance, you could set the HTML and CSS here, or load it
72
-     * later.
73
-     *
74
-     * @return void
75
-     * @param  string[optional] $html The HTML to process.
76
-     * @param  string[optional] $css  The CSS to use.
77
-     */
78
-    public function __construct($html = null, $css = null)
79
-    {
80
-        if($html !== null) $this->setHTML($html);
81
-        if($css !== null) $this->setCSS($css);
82
-    }
83
-
84
-    /**
85
-     * Convert a CSS-selector into an xPath-query
86
-     *
87
-     * @return string
88
-     * @param  string $selector The CSS-selector.
89
-     */
90
-    private function buildXPathQuery($selector)
91
-    {
92
-        // redefine
93
-        $selector = (string) $selector;
94
-
95
-        // the CSS selector
96
-        $cssSelector = array(
97
-            // E F, Matches any F element that is a descendant of an E element
98
-            '/(\w)\s+([\w\*])/',
99
-            // E > F, Matches any F element that is a child of an element E
100
-            '/(\w)\s*>\s*([\w\*])/',
101
-            // E:first-child, Matches element E when E is the first child of its parent
102
-            '/(\w):first-child/',
103
-            // E + F, Matches any F element immediately preceded by an element
104
-            '/(\w)\s*\+\s*(\w)/',
105
-            // E[foo], Matches any E element with the "foo" attribute set (whatever the value)
106
-            '/(\w)\[([\w\-]+)]/',
107
-            // E[foo="warning"], Matches any E element whose "foo" attribute value is exactly equal to "warning"
108
-            '/(\w)\[([\w\-]+)\=\"(.*)\"]/',
109
-            // div.warning, HTML only. The same as DIV[class~="warning"]
110
-            '/(\w+|\*)+\.([\w\-]+)+/',
111
-            // .warning, HTML only. The same as *[class~="warning"]
112
-            '/\.([\w\-]+)/',
113
-            // E#myid, Matches any E element with id-attribute equal to "myid"
114
-            '/(\w+)+\#([\w\-]+)/',
115
-            // #myid, Matches any element with id-attribute equal to "myid"
116
-            '/\#([\w\-]+)/'
117
-        );
118
-
119
-        // the xPath-equivalent
120
-        $xPathQuery = array(
121
-            // E F, Matches any F element that is a descendant of an E element
122
-            '\1//\2',
123
-            // E > F, Matches any F element that is a child of an element E
124
-            '\1/\2',
125
-            // E:first-child, Matches element E when E is the first child of its parent
126
-            '*[1]/self::\1',
127
-            // E + F, Matches any F element immediately preceded by an element
128
-            '\1/following-sibling::*[1]/self::\2',
129
-            // E[foo], Matches any E element with the "foo" attribute set (whatever the value)
130
-            '\1 [ @\2 ]',
131
-            // E[foo="warning"], Matches any E element whose "foo" attribute value is exactly equal to "warning"
132
-            '\1[ contains( concat( " ", @\2, " " ), concat( " ", "\3", " " ) ) ]',
133
-            // div.warning, HTML only. The same as DIV[class~="warning"]
134
-            '\1[ contains( concat( " ", @class, " " ), concat( " ", "\2", " " ) ) ]',
135
-            // .warning, HTML only. The same as *[class~="warning"]
136
-            '*[ contains( concat( " ", @class, " " ), concat( " ", "\1", " " ) ) ]',
137
-            // E#myid, Matches any E element with id-attribute equal to "myid"
138
-            '\1[ @id = "\2" ]',
139
-            // #myid, Matches any element with id-attribute equal to "myid"
140
-            '*[ @id = "\1" ]'
141
-        );
142
-
143
-        // return
144
-        $xPath = (string) '//' . preg_replace($cssSelector, $xPathQuery, $selector);
145
-
146
-        return str_replace('] *', ']//*', $xPath);
147
-    }
148
-
149
-    /**
150
-     * Calculate the specifity for the CSS-selector
151
-     *
152
-     * @return int
153
-     * @param  string $selector The selector to calculate the specifity for.
154
-     */
155
-    private function calculateCSSSpecifity($selector)
156
-    {
157
-        // cleanup selector
158
-        $selector = str_replace(array('>', '+'), array(' > ', ' + '), $selector);
159
-
160
-        // init var
161
-        $specifity = 0;
162
-
163
-        // split the selector into chunks based on spaces
164
-        $chunks = explode(' ', $selector);
165
-
166
-        // loop chunks
167
-        foreach ($chunks as $chunk) {
168
-            // an ID is important, so give it a high specifity
169
-            if(strstr($chunk, '#') !== false) $specifity += 100;
170
-
171
-            // classes are more important than a tag, but less important then an ID
172
-            elseif(strstr($chunk, '.')) $specifity += 10;
173
-
174
-            // anything else isn't that important
175
-            else $specifity += 1;
176
-        }
177
-
178
-        // return
179
-        return $specifity;
180
-    }
181
-
182
-
183
-    /**
184
-     * Cleanup the generated HTML
185
-     *
186
-     * @return string
187
-     * @param  string $html The HTML to cleanup.
188
-     */
189
-    private function cleanupHTML($html)
190
-    {
191
-        // remove classes
192
-        $html = preg_replace('/(\s)+class="(.*)"(\s)+/U', ' ', $html);
193
-
194
-        // remove IDs
195
-        $html = preg_replace('/(\s)+id="(.*)"(\s)+/U', ' ', $html);
196
-
197
-        // return
198
-        return $html;
199
-    }
200
-
201
-
202
-    /**
203
-     * Converts the loaded HTML into an HTML-string with inline styles based on the loaded CSS
204
-     *
205
-     * @return string
206
-     * @param  bool[optional] $outputXHTML Should we output valid XHTML?
207
-     */
208
-    public function convert($outputXHTML = false)
209
-    {
210
-        // redefine
211
-        $outputXHTML = (bool) $outputXHTML;
212
-
213
-        // validate
214
-        if($this->html == null) throw new Exception('No HTML provided.');
215
-
216
-        // should we use inline style-block
217
-        if ($this->useInlineStylesBlock) {
218
-            // init var
219
-            $matches = array();
220
-
221
-            // match the style blocks
222
-            preg_match_all('|<style(.*)>(.*)</style>|isU', $this->html, $matches);
223
-
224
-            // any style-blocks found?
225
-            if (!empty($matches[2])) {
226
-                // add
227
-                foreach($matches[2] as $match) $this->css .= trim($match) ."\n";
228
-            }
229
-        }
230
-
231
-        // process css
232
-        $this->processCSS();
233
-
234
-        // create new DOMDocument
235
-        $document = new DOMDocument('1.0', $this->getEncoding());
236
-
237
-        // set error level
238
-        libxml_use_internal_errors(true);
239
-
240
-        // load HTML
241
-        $document->loadHTML($this->html);
242
-
243
-        // create new XPath
244
-        $xPath = new DOMXPath($document);
245
-
246
-        // any rules?
247
-        if (!empty($this->cssRules)) {
248
-            // loop rules
249
-            foreach ($this->cssRules as $rule) {
250
-                // init var
251
-                $query = $this->buildXPathQuery($rule['selector']);
252
-
253
-                // validate query
254
-                if($query === false) continue;
255
-
256
-                // search elements
257
-                $elements = $xPath->query($query);
258
-
259
-                // validate elements
260
-                if($elements === false) continue;
261
-
262
-                // loop found elements
263
-                foreach ($elements as $element) {
264
-                    // no styles stored?
265
-                    if ($element->attributes->getNamedItem(
266
-                        'data-css-to-inline-styles-original-styles'
267
-                    ) == null) {
268
-                        // init var
269
-                        $originalStyle = '';
270
-                        if ($element->attributes->getNamedItem('style') !== null) {
271
-                            $originalStyle = $element->attributes->getNamedItem('style')->value;
272
-                        }
273
-
274
-                        // store original styles
275
-                        $element->setAttribute(
276
-                            'data-css-to-inline-styles-original-styles',
277
-                            $originalStyle
278
-                        );
279
-
280
-                        // clear the styles
281
-                        $element->setAttribute('style', '');
282
-                    }
283
-
284
-                    // init var
285
-                    $properties = array();
286
-
287
-                    // get current styles
288
-                    $stylesAttribute = $element->attributes->getNamedItem('style');
289
-
290
-                    // any styles defined before?
291
-                    if ($stylesAttribute !== null) {
292
-                        // get value for the styles attribute
293
-                        $definedStyles = (string) $stylesAttribute->value;
294
-
295
-                        // split into properties
296
-                        $definedProperties = (array) explode(';', $definedStyles);
297
-
298
-                        // loop properties
299
-                        foreach ($definedProperties as $property) {
300
-                            // validate property
301
-                            if($property == '') continue;
302
-
303
-                            // split into chunks
304
-                            $chunks = (array) explode(':', trim($property), 2);
305
-
306
-                            // validate
307
-                            if(!isset($chunks[1])) continue;
308
-
309
-                            // loop chunks
310
-                            $properties[$chunks[0]] = trim($chunks[1]);
311
-                        }
312
-                    }
313
-
314
-                    // add new properties into the list
315
-                    foreach ($rule['properties'] as $key => $value) {
316
-                        $properties[$key] = $value;
317
-                    }
318
-
319
-                    // build string
320
-                    $propertyChunks = array();
321
-
322
-                    // build chunks
323
-                    foreach ($properties as $key => $values) {
324
-                        foreach ((array) $values as $value) {
325
-                            $propertyChunks[] = $key . ': ' . $value . ';';
326
-                        }
327
-                    }
328
-
329
-                    // build properties string
330
-                    $propertiesString = implode(' ', $propertyChunks);
331
-
332
-                    // set attribute
333
-                    if ($propertiesString != '') {
334
-                        $element->setAttribute('style', $propertiesString);
335
-                    }
336
-                }
337
-            }
338
-
339
-            // reapply original styles
340
-            $query = $this->buildXPathQuery(
341
-                '*[@data-css-to-inline-styles-original-styles]'
342
-            );
343
-
344
-            // validate query
345
-            if($query === false) return;
346
-
347
-            // search elements
348
-            $elements = $xPath->query($query);
349
-
350
-            // loop found elements
351
-            foreach ($elements as $element) {
352
-                // get the original styles
353
-                $originalStyle = $element->attributes->getNamedItem(
354
-                    'data-css-to-inline-styles-original-styles'
355
-                )->value;
356
-
357
-                if ($originalStyle != '') {
358
-                    $originalProperties = array();
359
-                    $originalStyles = (array) explode(';', $originalStyle);
360
-
361
-                    foreach ($originalStyles as $property) {
362
-                        // validate property
363
-                        if($property == '') continue;
364
-
365
-                        // split into chunks
366
-                        $chunks = (array) explode(':', trim($property), 2);
367
-
368
-                        // validate
369
-                        if(!isset($chunks[1])) continue;
370
-
371
-                        // loop chunks
372
-                        $originalProperties[$chunks[0]] = trim($chunks[1]);
373
-                    }
374
-
375
-                    // get current styles
376
-                    $stylesAttribute = $element->attributes->getNamedItem('style');
377
-                    $properties = array();
378
-
379
-                    // any styles defined before?
380
-                    if ($stylesAttribute !== null) {
381
-                        // get value for the styles attribute
382
-                        $definedStyles = (string) $stylesAttribute->value;
383
-
384
-                        // split into properties
385
-                        $definedProperties = (array) explode(';', $definedStyles);
386
-
387
-                        // loop properties
388
-                        foreach ($definedProperties as $property) {
389
-                            // validate property
390
-                            if($property == '') continue;
391
-
392
-                            // split into chunks
393
-                            $chunks = (array) explode(':', trim($property), 2);
394
-
395
-                            // validate
396
-                            if(!isset($chunks[1])) continue;
397
-
398
-                            // loop chunks
399
-                            $properties[$chunks[0]] = trim($chunks[1]);
400
-                        }
401
-                    }
402
-
403
-                    // add new properties into the list
404
-                    foreach ($originalProperties as $key => $value) {
405
-                        $properties[$key] = $value;
406
-                    }
407
-
408
-                    // build string
409
-                    $propertyChunks = array();
410
-
411
-                    // build chunks
412
-                    foreach ($properties as $key => $values) {
413
-                        foreach ((array) $values as $value) {
414
-                            $propertyChunks[] = $key . ': ' . $value . ';';
415
-                        }
416
-                    }
417
-
418
-                    // build properties string
419
-                    $propertiesString = implode(' ', $propertyChunks);
420
-
421
-                    // set attribute
422
-                    if($propertiesString != '') $element->setAttribute(
423
-                        'style', $propertiesString
424
-                    );
425
-                }
426
-
427
-                // remove placeholder
428
-                $element->removeAttribute(
429
-                    'data-css-to-inline-styles-original-styles'
430
-                );
431
-            }
432
-        }
433
-
434
-        // should we output XHTML?
435
-        if ($outputXHTML) {
436
-            // set formating
437
-            $document->formatOutput = true;
438
-
439
-            // get the HTML as XML
440
-            $html = $document->saveXML(null, LIBXML_NOEMPTYTAG);
441
-
442
-            // get start of the XML-declaration
443
-            $startPosition = strpos($html, '<?xml');
444
-
445
-            // valid start position?
446
-            if ($startPosition !== false) {
447
-                // get end of the xml-declaration
448
-                $endPosition = strpos($html, '?>', $startPosition);
449
-
450
-                // remove the XML-header
451
-                $html = ltrim(substr($html, $endPosition + 1));
452
-            }
453
-        }
454
-
455
-        // just regular HTML 4.01 as it should be used in newsletters
456
-        else {
457
-            // get the HTML
458
-            $html = $document->saveHTML();
459
-        }
460
-
461
-        // cleanup the HTML if we need to
462
-        if($this->cleanup) $html = $this->cleanupHTML($html);
463
-
464
-        // strip original style tags if we need to
465
-        if ($this->stripOriginalStyleTags) {
466
-            $html = $this->stripOriginalStyleTags($html);
467
-        }
468
-
469
-        // return
470
-        return $html;
471
-    }
472
-
473
-
474
-    /**
475
-     * Get the encoding to use
476
-     *
477
-     * @return string
478
-     */
479
-    private function getEncoding()
480
-    {
481
-        return $this->encoding;
482
-    }
483
-
484
-
485
-    /**
486
-     * Process the loaded CSS
487
-     *
488
-     * @return void
489
-     */
490
-    private function processCSS()
491
-    {
492
-        // init vars
493
-        $css = (string) $this->css;
494
-
495
-        // remove newlines
496
-        $css = str_replace(array("\r", "\n"), '', $css);
497
-
498
-        // replace double quotes by single quotes
499
-        $css = str_replace('"', '\'', $css);
500
-
501
-        // remove comments
502
-        $css = preg_replace('|/\*.*?\*/|', '', $css);
503
-
504
-        // remove spaces
505
-        $css = preg_replace('/\s\s+/', ' ', $css);
506
-
507
-        if ($this->excludeMediaQueries) {
508
-            $css = preg_replace('/@media [^{]*{([^{}]|{[^{}]*})*}/', '', $css);
509
-        }
510
-
511
-        // rules are splitted by }
512
-        $rules = (array) explode('}', $css);
513
-
514
-        // init var
515
-        $i = 1;
516
-
517
-        // loop rules
518
-        foreach ($rules as $rule) {
519
-            // split into chunks
520
-            $chunks = explode('{', $rule);
521
-
522
-            // invalid rule?
523
-            if(!isset($chunks[1])) continue;
524
-
525
-            // set the selectors
526
-            $selectors = trim($chunks[0]);
527
-
528
-            // get cssProperties
529
-            $cssProperties = trim($chunks[1]);
530
-
531
-            // split multiple selectors
532
-            $selectors = (array) explode(',', $selectors);
533
-
534
-            // loop selectors
535
-            foreach ($selectors as $selector) {
536
-                // cleanup
537
-                $selector = trim($selector);
538
-
539
-                // build an array for each selector
540
-                $ruleSet = array();
541
-
542
-                // store selector
543
-                $ruleSet['selector'] = $selector;
544
-
545
-                // process the properties
546
-                $ruleSet['properties'] = $this->processCSSProperties(
547
-                    $cssProperties
548
-                );
549
-
550
-                // calculate specifity
551
-                $ruleSet['specifity'] = $this->calculateCSSSpecifity(
552
-                    $selector
553
-                ) + $i;
554
-
555
-                // add into global rules
556
-                $this->cssRules[] = $ruleSet;
557
-            }
558
-
559
-            // increment
560
-            $i++;
561
-        }
562
-
563
-        // sort based on specifity
564
-        if (!empty($this->cssRules)) {
565
-            usort($this->cssRules, array(__CLASS__, 'sortOnSpecifity'));
566
-        }
567
-    }
568
-
569
-    /**
570
-     * Process the CSS-properties
571
-     *
572
-     * @return array
573
-     * @param  string $propertyString The CSS-properties.
574
-     */
575
-    private function processCSSProperties($propertyString)
576
-    {
577
-        // split into chunks
578
-        $properties = (array) explode(';', $propertyString);
579
-
580
-        // init var
581
-        $pairs = array();
582
-
583
-        // loop properties
584
-        foreach ($properties as $property) {
585
-            // split into chunks
586
-            $chunks = (array) explode(':', $property, 2);
587
-
588
-            // validate
589
-            if(!isset($chunks[1])) continue;
590
-
591
-            // cleanup
592
-            $chunks[0] = trim($chunks[0]);
593
-            $chunks[1] = trim($chunks[1]);
594
-
595
-            // add to pairs array
596
-            if(!isset($pairs[$chunks[0]]) ||
597
-               !in_array($chunks[1], $pairs[$chunks[0]])) {
598
-                $pairs[$chunks[0]][] = $chunks[1];
599
-            }
600
-        }
601
-
602
-        // sort the pairs
603
-        ksort($pairs);
604
-
605
-        // return
606
-        return $pairs;
607
-    }
608
-
609
-    /**
610
-     * Should the IDs and classes be removed?
611
-     *
612
-     * @return void
613
-     * @param  bool[optional] $on Should we enable cleanup?
614
-     */
615
-    public function setCleanup($on = true)
616
-    {
617
-        $this->cleanup = (bool) $on;
618
-    }
619
-
620
-    /**
621
-     * Set CSS to use
622
-     *
623
-     * @return void
624
-     * @param  string $css The CSS to use.
625
-     */
626
-    public function setCSS($css)
627
-    {
628
-        $this->css = (string) $css;
629
-    }
630
-
631
-    /**
632
-     * Set the encoding to use with the DOMDocument
633
-     *
634
-     * @return void
635
-     * @param  string $encoding The encoding to use.
636
-     */
637
-    public function setEncoding($encoding)
638
-    {
639
-        $this->encoding = (string) $encoding;
640
-    }
641
-
642
-    /**
643
-     * Set HTML to process
644
-     *
645
-     * @return void
646
-     * @param  string $html The HTML to process.
647
-     */
648
-    public function setHTML($html)
649
-    {
650
-        $this->html = (string) $html;
651
-    }
652
-
653
-    /**
654
-     * Set use of inline styles block
655
-     * If this is enabled the class will use the style-block in the HTML.
656
-     *
657
-     * @return void
658
-     * @param  bool[optional] $on Should we process inline styles?
659
-     */
660
-    public function setUseInlineStylesBlock($on = true)
661
-    {
662
-        $this->useInlineStylesBlock = (bool) $on;
663
-    }
664
-
665
-    /**
666
-     * Set strip original style tags
667
-     * If this is enabled the class will remove all style tags in the HTML.
668
-     *
669
-     * @return void
670
-     * @param  bool[optional] $on Should we process inline styles?
671
-     */
672
-    public function setStripOriginalStyleTags($on = true)
673
-    {
674
-        $this->stripOriginalStyleTags = (bool) $on;
675
-    }
676
-
677
-    /**
678
-     * Set exclude media queries
679
-     *
680
-     * If this is enabled the media queries will be removed before inlining the rules
681
-     *
682
-     * @return void
683
-     * @param bool[optional] $on
684
-     */
685
-    public function setExcludeMediaQueries($on = true)
686
-    {
687
-        $this->excludeMediaQueries = (bool) $on;
688
-    }
689
-
690
-    /**
691
-     * Strip style tags into the generated HTML
692
-     *
693
-     * @return string
694
-     * @param  string $html The HTML to strip style tags.
695
-     */
696
-    private function stripOriginalStyleTags($html)
697
-    {
698
-        return preg_replace('|<style(.*)>(.*)</style>|isU', '', $html);
699
-    }
700
-
701
-    /**
702
-     * Sort an array on the specifity element
703
-     *
704
-     * @return int
705
-     * @param  array $e1 The first element.
706
-     * @param  array $e2 The second element.
707
-     */
708
-    private static function sortOnSpecifity($e1, $e2)
709
-    {
710
-        // validate
711
-        if(!isset($e1['specifity']) || !isset($e2['specifity'])) return 0;
712
-
713
-        // lower
714
-        if($e1['specifity'] < $e2['specifity']) return -1;
715
-
716
-        // higher
717
-        if($e1['specifity'] > $e2['specifity']) return 1;
718
-
719
-        // fallback
720
-        return 0;
721
-    }
14
+	/**
15
+	 * The CSS to use
16
+	 *
17
+	 * @var	string
18
+	 */
19
+	private $css;
20
+
21
+	/**
22
+	 * The processed CSS rules
23
+	 *
24
+	 * @var	array
25
+	 */
26
+	private $cssRules;
27
+
28
+	/**
29
+	 * Should the generated HTML be cleaned
30
+	 *
31
+	 * @var	bool
32
+	 */
33
+	private $cleanup = false;
34
+
35
+	/**
36
+	 * The encoding to use.
37
+	 *
38
+	 * @var	string
39
+	 */
40
+	private $encoding = 'UTF-8';
41
+
42
+	/**
43
+	 * The HTML to process
44
+	 *
45
+	 * @var	string
46
+	 */
47
+	private $html;
48
+
49
+	/**
50
+	 * Use inline-styles block as CSS
51
+	 *
52
+	 * @var	bool
53
+	 */
54
+	private $useInlineStylesBlock = false;
55
+
56
+	/**
57
+	 * Strip original style tags
58
+	 *
59
+	 * @var bool
60
+	 */
61
+	private $stripOriginalStyleTags = false;
62
+
63
+	/**
64
+	 * Exclude the media queries from the inlined styles
65
+	 *
66
+	 * @var bool
67
+	 */
68
+	private $excludeMediaQueries = false;
69
+
70
+	/**
71
+	 * Creates an instance, you could set the HTML and CSS here, or load it
72
+	 * later.
73
+	 *
74
+	 * @return void
75
+	 * @param  string[optional] $html The HTML to process.
76
+	 * @param  string[optional] $css  The CSS to use.
77
+	 */
78
+	public function __construct($html = null, $css = null)
79
+	{
80
+		if($html !== null) $this->setHTML($html);
81
+		if($css !== null) $this->setCSS($css);
82
+	}
83
+
84
+	/**
85
+	 * Convert a CSS-selector into an xPath-query
86
+	 *
87
+	 * @return string
88
+	 * @param  string $selector The CSS-selector.
89
+	 */
90
+	private function buildXPathQuery($selector)
91
+	{
92
+		// redefine
93
+		$selector = (string) $selector;
94
+
95
+		// the CSS selector
96
+		$cssSelector = array(
97
+			// E F, Matches any F element that is a descendant of an E element
98
+			'/(\w)\s+([\w\*])/',
99
+			// E > F, Matches any F element that is a child of an element E
100
+			'/(\w)\s*>\s*([\w\*])/',
101
+			// E:first-child, Matches element E when E is the first child of its parent
102
+			'/(\w):first-child/',
103
+			// E + F, Matches any F element immediately preceded by an element
104
+			'/(\w)\s*\+\s*(\w)/',
105
+			// E[foo], Matches any E element with the "foo" attribute set (whatever the value)
106
+			'/(\w)\[([\w\-]+)]/',
107
+			// E[foo="warning"], Matches any E element whose "foo" attribute value is exactly equal to "warning"
108
+			'/(\w)\[([\w\-]+)\=\"(.*)\"]/',
109
+			// div.warning, HTML only. The same as DIV[class~="warning"]
110
+			'/(\w+|\*)+\.([\w\-]+)+/',
111
+			// .warning, HTML only. The same as *[class~="warning"]
112
+			'/\.([\w\-]+)/',
113
+			// E#myid, Matches any E element with id-attribute equal to "myid"
114
+			'/(\w+)+\#([\w\-]+)/',
115
+			// #myid, Matches any element with id-attribute equal to "myid"
116
+			'/\#([\w\-]+)/'
117
+		);
118
+
119
+		// the xPath-equivalent
120
+		$xPathQuery = array(
121
+			// E F, Matches any F element that is a descendant of an E element
122
+			'\1//\2',
123
+			// E > F, Matches any F element that is a child of an element E
124
+			'\1/\2',
125
+			// E:first-child, Matches element E when E is the first child of its parent
126
+			'*[1]/self::\1',
127
+			// E + F, Matches any F element immediately preceded by an element
128
+			'\1/following-sibling::*[1]/self::\2',
129
+			// E[foo], Matches any E element with the "foo" attribute set (whatever the value)
130
+			'\1 [ @\2 ]',
131
+			// E[foo="warning"], Matches any E element whose "foo" attribute value is exactly equal to "warning"
132
+			'\1[ contains( concat( " ", @\2, " " ), concat( " ", "\3", " " ) ) ]',
133
+			// div.warning, HTML only. The same as DIV[class~="warning"]
134
+			'\1[ contains( concat( " ", @class, " " ), concat( " ", "\2", " " ) ) ]',
135
+			// .warning, HTML only. The same as *[class~="warning"]
136
+			'*[ contains( concat( " ", @class, " " ), concat( " ", "\1", " " ) ) ]',
137
+			// E#myid, Matches any E element with id-attribute equal to "myid"
138
+			'\1[ @id = "\2" ]',
139
+			// #myid, Matches any element with id-attribute equal to "myid"
140
+			'*[ @id = "\1" ]'
141
+		);
142
+
143
+		// return
144
+		$xPath = (string) '//' . preg_replace($cssSelector, $xPathQuery, $selector);
145
+
146
+		return str_replace('] *', ']//*', $xPath);
147
+	}
148
+
149
+	/**
150
+	 * Calculate the specifity for the CSS-selector
151
+	 *
152
+	 * @return int
153
+	 * @param  string $selector The selector to calculate the specifity for.
154
+	 */
155
+	private function calculateCSSSpecifity($selector)
156
+	{
157
+		// cleanup selector
158
+		$selector = str_replace(array('>', '+'), array(' > ', ' + '), $selector);
159
+
160
+		// init var
161
+		$specifity = 0;
162
+
163
+		// split the selector into chunks based on spaces
164
+		$chunks = explode(' ', $selector);
165
+
166
+		// loop chunks
167
+		foreach ($chunks as $chunk) {
168
+			// an ID is important, so give it a high specifity
169
+			if(strstr($chunk, '#') !== false) $specifity += 100;
170
+
171
+			// classes are more important than a tag, but less important then an ID
172
+			elseif(strstr($chunk, '.')) $specifity += 10;
173
+
174
+			// anything else isn't that important
175
+			else $specifity += 1;
176
+		}
177
+
178
+		// return
179
+		return $specifity;
180
+	}
181
+
182
+
183
+	/**
184
+	 * Cleanup the generated HTML
185
+	 *
186
+	 * @return string
187
+	 * @param  string $html The HTML to cleanup.
188
+	 */
189
+	private function cleanupHTML($html)
190
+	{
191
+		// remove classes
192
+		$html = preg_replace('/(\s)+class="(.*)"(\s)+/U', ' ', $html);
193
+
194
+		// remove IDs
195
+		$html = preg_replace('/(\s)+id="(.*)"(\s)+/U', ' ', $html);
196
+
197
+		// return
198
+		return $html;
199
+	}
200
+
201
+
202
+	/**
203
+	 * Converts the loaded HTML into an HTML-string with inline styles based on the loaded CSS
204
+	 *
205
+	 * @return string
206
+	 * @param  bool[optional] $outputXHTML Should we output valid XHTML?
207
+	 */
208
+	public function convert($outputXHTML = false)
209
+	{
210
+		// redefine
211
+		$outputXHTML = (bool) $outputXHTML;
212
+
213
+		// validate
214
+		if($this->html == null) throw new Exception('No HTML provided.');
215
+
216
+		// should we use inline style-block
217
+		if ($this->useInlineStylesBlock) {
218
+			// init var
219
+			$matches = array();
220
+
221
+			// match the style blocks
222
+			preg_match_all('|<style(.*)>(.*)</style>|isU', $this->html, $matches);
223
+
224
+			// any style-blocks found?
225
+			if (!empty($matches[2])) {
226
+				// add
227
+				foreach($matches[2] as $match) $this->css .= trim($match) ."\n";
228
+			}
229
+		}
230
+
231
+		// process css
232
+		$this->processCSS();
233
+
234
+		// create new DOMDocument
235
+		$document = new DOMDocument('1.0', $this->getEncoding());
236
+
237
+		// set error level
238
+		libxml_use_internal_errors(true);
239
+
240
+		// load HTML
241
+		$document->loadHTML($this->html);
242
+
243
+		// create new XPath
244
+		$xPath = new DOMXPath($document);
245
+
246
+		// any rules?
247
+		if (!empty($this->cssRules)) {
248
+			// loop rules
249
+			foreach ($this->cssRules as $rule) {
250
+				// init var
251
+				$query = $this->buildXPathQuery($rule['selector']);
252
+
253
+				// validate query
254
+				if($query === false) continue;
255
+
256
+				// search elements
257
+				$elements = $xPath->query($query);
258
+
259
+				// validate elements
260
+				if($elements === false) continue;
261
+
262
+				// loop found elements
263
+				foreach ($elements as $element) {
264
+					// no styles stored?
265
+					if ($element->attributes->getNamedItem(
266
+						'data-css-to-inline-styles-original-styles'
267
+					) == null) {
268
+						// init var
269
+						$originalStyle = '';
270
+						if ($element->attributes->getNamedItem('style') !== null) {
271
+							$originalStyle = $element->attributes->getNamedItem('style')->value;
272
+						}
273
+
274
+						// store original styles
275
+						$element->setAttribute(
276
+							'data-css-to-inline-styles-original-styles',
277
+							$originalStyle
278
+						);
279
+
280
+						// clear the styles
281
+						$element->setAttribute('style', '');
282
+					}
283
+
284
+					// init var
285
+					$properties = array();
286
+
287
+					// get current styles
288
+					$stylesAttribute = $element->attributes->getNamedItem('style');
289
+
290
+					// any styles defined before?
291
+					if ($stylesAttribute !== null) {
292
+						// get value for the styles attribute
293
+						$definedStyles = (string) $stylesAttribute->value;
294
+
295
+						// split into properties
296
+						$definedProperties = (array) explode(';', $definedStyles);
297
+
298
+						// loop properties
299
+						foreach ($definedProperties as $property) {
300
+							// validate property
301
+							if($property == '') continue;
302
+
303
+							// split into chunks
304
+							$chunks = (array) explode(':', trim($property), 2);
305
+
306
+							// validate
307
+							if(!isset($chunks[1])) continue;
308
+
309
+							// loop chunks
310
+							$properties[$chunks[0]] = trim($chunks[1]);
311
+						}
312
+					}
313
+
314
+					// add new properties into the list
315
+					foreach ($rule['properties'] as $key => $value) {
316
+						$properties[$key] = $value;
317
+					}
318
+
319
+					// build string
320
+					$propertyChunks = array();
321
+
322
+					// build chunks
323
+					foreach ($properties as $key => $values) {
324
+						foreach ((array) $values as $value) {
325
+							$propertyChunks[] = $key . ': ' . $value . ';';
326
+						}
327
+					}
328
+
329
+					// build properties string
330
+					$propertiesString = implode(' ', $propertyChunks);
331
+
332
+					// set attribute
333
+					if ($propertiesString != '') {
334
+						$element->setAttribute('style', $propertiesString);
335
+					}
336
+				}
337
+			}
338
+
339
+			// reapply original styles
340
+			$query = $this->buildXPathQuery(
341
+				'*[@data-css-to-inline-styles-original-styles]'
342
+			);
343
+
344
+			// validate query
345
+			if($query === false) return;
346
+
347
+			// search elements
348
+			$elements = $xPath->query($query);
349
+
350
+			// loop found elements
351
+			foreach ($elements as $element) {
352
+				// get the original styles
353
+				$originalStyle = $element->attributes->getNamedItem(
354
+					'data-css-to-inline-styles-original-styles'
355
+				)->value;
356
+
357
+				if ($originalStyle != '') {
358
+					$originalProperties = array();
359
+					$originalStyles = (array) explode(';', $originalStyle);
360
+
361
+					foreach ($originalStyles as $property) {
362
+						// validate property
363
+						if($property == '') continue;
364
+
365
+						// split into chunks
366
+						$chunks = (array) explode(':', trim($property), 2);
367
+
368
+						// validate
369
+						if(!isset($chunks[1])) continue;
370
+
371
+						// loop chunks
372
+						$originalProperties[$chunks[0]] = trim($chunks[1]);
373
+					}
374
+
375
+					// get current styles
376
+					$stylesAttribute = $element->attributes->getNamedItem('style');
377
+					$properties = array();
378
+
379
+					// any styles defined before?
380
+					if ($stylesAttribute !== null) {
381
+						// get value for the styles attribute
382
+						$definedStyles = (string) $stylesAttribute->value;
383
+
384
+						// split into properties
385
+						$definedProperties = (array) explode(';', $definedStyles);
386
+
387
+						// loop properties
388
+						foreach ($definedProperties as $property) {
389
+							// validate property
390
+							if($property == '') continue;
391
+
392
+							// split into chunks
393
+							$chunks = (array) explode(':', trim($property), 2);
394
+
395
+							// validate
396
+							if(!isset($chunks[1])) continue;
397
+
398
+							// loop chunks
399
+							$properties[$chunks[0]] = trim($chunks[1]);
400
+						}
401
+					}
402
+
403
+					// add new properties into the list
404
+					foreach ($originalProperties as $key => $value) {
405
+						$properties[$key] = $value;
406
+					}
407
+
408
+					// build string
409
+					$propertyChunks = array();
410
+
411
+					// build chunks
412
+					foreach ($properties as $key => $values) {
413
+						foreach ((array) $values as $value) {
414
+							$propertyChunks[] = $key . ': ' . $value . ';';
415
+						}
416
+					}
417
+
418
+					// build properties string
419
+					$propertiesString = implode(' ', $propertyChunks);
420
+
421
+					// set attribute
422
+					if($propertiesString != '') $element->setAttribute(
423
+						'style', $propertiesString
424
+					);
425
+				}
426
+
427
+				// remove placeholder
428
+				$element->removeAttribute(
429
+					'data-css-to-inline-styles-original-styles'
430
+				);
431
+			}
432
+		}
433
+
434
+		// should we output XHTML?
435
+		if ($outputXHTML) {
436
+			// set formating
437
+			$document->formatOutput = true;
438
+
439
+			// get the HTML as XML
440
+			$html = $document->saveXML(null, LIBXML_NOEMPTYTAG);
441
+
442
+			// get start of the XML-declaration
443
+			$startPosition = strpos($html, '<?xml');
444
+
445
+			// valid start position?
446
+			if ($startPosition !== false) {
447
+				// get end of the xml-declaration
448
+				$endPosition = strpos($html, '?>', $startPosition);
449
+
450
+				// remove the XML-header
451
+				$html = ltrim(substr($html, $endPosition + 1));
452
+			}
453
+		}
454
+
455
+		// just regular HTML 4.01 as it should be used in newsletters
456
+		else {
457
+			// get the HTML
458
+			$html = $document->saveHTML();
459
+		}
460
+
461
+		// cleanup the HTML if we need to
462
+		if($this->cleanup) $html = $this->cleanupHTML($html);
463
+
464
+		// strip original style tags if we need to
465
+		if ($this->stripOriginalStyleTags) {
466
+			$html = $this->stripOriginalStyleTags($html);
467
+		}
468
+
469
+		// return
470
+		return $html;
471
+	}
472
+
473
+
474
+	/**
475
+	 * Get the encoding to use
476
+	 *
477
+	 * @return string
478
+	 */
479
+	private function getEncoding()
480
+	{
481
+		return $this->encoding;
482
+	}
483
+
484
+
485
+	/**
486
+	 * Process the loaded CSS
487
+	 *
488
+	 * @return void
489
+	 */
490
+	private function processCSS()
491
+	{
492
+		// init vars
493
+		$css = (string) $this->css;
494
+
495
+		// remove newlines
496
+		$css = str_replace(array("\r", "\n"), '', $css);
497
+
498
+		// replace double quotes by single quotes
499
+		$css = str_replace('"', '\'', $css);
500
+
501
+		// remove comments
502
+		$css = preg_replace('|/\*.*?\*/|', '', $css);
503
+
504
+		// remove spaces
505
+		$css = preg_replace('/\s\s+/', ' ', $css);
506
+
507
+		if ($this->excludeMediaQueries) {
508
+			$css = preg_replace('/@media [^{]*{([^{}]|{[^{}]*})*}/', '', $css);
509
+		}
510
+
511
+		// rules are splitted by }
512
+		$rules = (array) explode('}', $css);
513
+
514
+		// init var
515
+		$i = 1;
516
+
517
+		// loop rules
518
+		foreach ($rules as $rule) {
519
+			// split into chunks
520
+			$chunks = explode('{', $rule);
521
+
522
+			// invalid rule?
523
+			if(!isset($chunks[1])) continue;
524
+
525
+			// set the selectors
526
+			$selectors = trim($chunks[0]);
527
+
528
+			// get cssProperties
529
+			$cssProperties = trim($chunks[1]);
530
+
531
+			// split multiple selectors
532
+			$selectors = (array) explode(',', $selectors);
533
+
534
+			// loop selectors
535
+			foreach ($selectors as $selector) {
536
+				// cleanup
537
+				$selector = trim($selector);
538
+
539
+				// build an array for each selector
540
+				$ruleSet = array();
541
+
542
+				// store selector
543
+				$ruleSet['selector'] = $selector;
544
+
545
+				// process the properties
546
+				$ruleSet['properties'] = $this->processCSSProperties(
547
+					$cssProperties
548
+				);
549
+
550
+				// calculate specifity
551
+				$ruleSet['specifity'] = $this->calculateCSSSpecifity(
552
+					$selector
553
+				) + $i;
554
+
555
+				// add into global rules
556
+				$this->cssRules[] = $ruleSet;
557
+			}
558
+
559
+			// increment
560
+			$i++;
561
+		}
562
+
563
+		// sort based on specifity
564
+		if (!empty($this->cssRules)) {
565
+			usort($this->cssRules, array(__CLASS__, 'sortOnSpecifity'));
566
+		}
567
+	}
568
+
569
+	/**
570
+	 * Process the CSS-properties
571
+	 *
572
+	 * @return array
573
+	 * @param  string $propertyString The CSS-properties.
574
+	 */
575
+	private function processCSSProperties($propertyString)
576
+	{
577
+		// split into chunks
578
+		$properties = (array) explode(';', $propertyString);
579
+
580
+		// init var
581
+		$pairs = array();
582
+
583
+		// loop properties
584
+		foreach ($properties as $property) {
585
+			// split into chunks
586
+			$chunks = (array) explode(':', $property, 2);
587
+
588
+			// validate
589
+			if(!isset($chunks[1])) continue;
590
+
591
+			// cleanup
592
+			$chunks[0] = trim($chunks[0]);
593
+			$chunks[1] = trim($chunks[1]);
594
+
595
+			// add to pairs array
596
+			if(!isset($pairs[$chunks[0]]) ||
597
+			   !in_array($chunks[1], $pairs[$chunks[0]])) {
598
+				$pairs[$chunks[0]][] = $chunks[1];
599
+			}
600
+		}
601
+
602
+		// sort the pairs
603
+		ksort($pairs);
604
+
605
+		// return
606
+		return $pairs;
607
+	}
608
+
609
+	/**
610
+	 * Should the IDs and classes be removed?
611
+	 *
612
+	 * @return void
613
+	 * @param  bool[optional] $on Should we enable cleanup?
614
+	 */
615
+	public function setCleanup($on = true)
616
+	{
617
+		$this->cleanup = (bool) $on;
618
+	}
619
+
620
+	/**
621
+	 * Set CSS to use
622
+	 *
623
+	 * @return void
624
+	 * @param  string $css The CSS to use.
625
+	 */
626
+	public function setCSS($css)
627
+	{
628
+		$this->css = (string) $css;
629
+	}
630
+
631
+	/**
632
+	 * Set the encoding to use with the DOMDocument
633
+	 *
634
+	 * @return void
635
+	 * @param  string $encoding The encoding to use.
636
+	 */
637
+	public function setEncoding($encoding)
638
+	{
639
+		$this->encoding = (string) $encoding;
640
+	}
641
+
642
+	/**
643
+	 * Set HTML to process
644
+	 *
645
+	 * @return void
646
+	 * @param  string $html The HTML to process.
647
+	 */
648
+	public function setHTML($html)
649
+	{
650
+		$this->html = (string) $html;
651
+	}
652
+
653
+	/**
654
+	 * Set use of inline styles block
655
+	 * If this is enabled the class will use the style-block in the HTML.
656
+	 *
657
+	 * @return void
658
+	 * @param  bool[optional] $on Should we process inline styles?
659
+	 */
660
+	public function setUseInlineStylesBlock($on = true)
661
+	{
662
+		$this->useInlineStylesBlock = (bool) $on;
663
+	}
664
+
665
+	/**
666
+	 * Set strip original style tags
667
+	 * If this is enabled the class will remove all style tags in the HTML.
668
+	 *
669
+	 * @return void
670
+	 * @param  bool[optional] $on Should we process inline styles?
671
+	 */
672
+	public function setStripOriginalStyleTags($on = true)
673
+	{
674
+		$this->stripOriginalStyleTags = (bool) $on;
675
+	}
676
+
677
+	/**
678
+	 * Set exclude media queries
679
+	 *
680
+	 * If this is enabled the media queries will be removed before inlining the rules
681
+	 *
682
+	 * @return void
683
+	 * @param bool[optional] $on
684
+	 */
685
+	public function setExcludeMediaQueries($on = true)
686
+	{
687
+		$this->excludeMediaQueries = (bool) $on;
688
+	}
689
+
690
+	/**
691
+	 * Strip style tags into the generated HTML
692
+	 *
693
+	 * @return string
694
+	 * @param  string $html The HTML to strip style tags.
695
+	 */
696
+	private function stripOriginalStyleTags($html)
697
+	{
698
+		return preg_replace('|<style(.*)>(.*)</style>|isU', '', $html);
699
+	}
700
+
701
+	/**
702
+	 * Sort an array on the specifity element
703
+	 *
704
+	 * @return int
705
+	 * @param  array $e1 The first element.
706
+	 * @param  array $e2 The second element.
707
+	 */
708
+	private static function sortOnSpecifity($e1, $e2)
709
+	{
710
+		// validate
711
+		if(!isset($e1['specifity']) || !isset($e2['specifity'])) return 0;
712
+
713
+		// lower
714
+		if($e1['specifity'] < $e2['specifity']) return -1;
715
+
716
+		// higher
717
+		if($e1['specifity'] > $e2['specifity']) return 1;
718
+
719
+		// fallback
720
+		return 0;
721
+	}
722 722
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
      */
78 78
     public function __construct($html = null, $css = null)
79 79
     {
80
-        if($html !== null) $this->setHTML($html);
81
-        if($css !== null) $this->setCSS($css);
80
+        if ($html !== null) $this->setHTML($html);
81
+        if ($css !== null) $this->setCSS($css);
82 82
     }
83 83
 
84 84
     /**
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
         );
142 142
 
143 143
         // return
144
-        $xPath = (string) '//' . preg_replace($cssSelector, $xPathQuery, $selector);
144
+        $xPath = (string) '//'.preg_replace($cssSelector, $xPathQuery, $selector);
145 145
 
146 146
         return str_replace('] *', ']//*', $xPath);
147 147
     }
@@ -166,10 +166,10 @@  discard block
 block discarded – undo
166 166
         // loop chunks
167 167
         foreach ($chunks as $chunk) {
168 168
             // an ID is important, so give it a high specifity
169
-            if(strstr($chunk, '#') !== false) $specifity += 100;
169
+            if (strstr($chunk, '#') !== false) $specifity += 100;
170 170
 
171 171
             // classes are more important than a tag, but less important then an ID
172
-            elseif(strstr($chunk, '.')) $specifity += 10;
172
+            elseif (strstr($chunk, '.')) $specifity += 10;
173 173
 
174 174
             // anything else isn't that important
175 175
             else $specifity += 1;
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
         $outputXHTML = (bool) $outputXHTML;
212 212
 
213 213
         // validate
214
-        if($this->html == null) throw new Exception('No HTML provided.');
214
+        if ($this->html == null) throw new Exception('No HTML provided.');
215 215
 
216 216
         // should we use inline style-block
217 217
         if ($this->useInlineStylesBlock) {
@@ -222,9 +222,9 @@  discard block
 block discarded – undo
222 222
             preg_match_all('|<style(.*)>(.*)</style>|isU', $this->html, $matches);
223 223
 
224 224
             // any style-blocks found?
225
-            if (!empty($matches[2])) {
225
+            if ( ! empty($matches[2])) {
226 226
                 // add
227
-                foreach($matches[2] as $match) $this->css .= trim($match) ."\n";
227
+                foreach ($matches[2] as $match) $this->css .= trim($match)."\n";
228 228
             }
229 229
         }
230 230
 
@@ -244,20 +244,20 @@  discard block
 block discarded – undo
244 244
         $xPath = new DOMXPath($document);
245 245
 
246 246
         // any rules?
247
-        if (!empty($this->cssRules)) {
247
+        if ( ! empty($this->cssRules)) {
248 248
             // loop rules
249 249
             foreach ($this->cssRules as $rule) {
250 250
                 // init var
251 251
                 $query = $this->buildXPathQuery($rule['selector']);
252 252
 
253 253
                 // validate query
254
-                if($query === false) continue;
254
+                if ($query === false) continue;
255 255
 
256 256
                 // search elements
257 257
                 $elements = $xPath->query($query);
258 258
 
259 259
                 // validate elements
260
-                if($elements === false) continue;
260
+                if ($elements === false) continue;
261 261
 
262 262
                 // loop found elements
263 263
                 foreach ($elements as $element) {
@@ -298,13 +298,13 @@  discard block
 block discarded – undo
298 298
                         // loop properties
299 299
                         foreach ($definedProperties as $property) {
300 300
                             // validate property
301
-                            if($property == '') continue;
301
+                            if ($property == '') continue;
302 302
 
303 303
                             // split into chunks
304 304
                             $chunks = (array) explode(':', trim($property), 2);
305 305
 
306 306
                             // validate
307
-                            if(!isset($chunks[1])) continue;
307
+                            if ( ! isset($chunks[1])) continue;
308 308
 
309 309
                             // loop chunks
310 310
                             $properties[$chunks[0]] = trim($chunks[1]);
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
                     // build chunks
323 323
                     foreach ($properties as $key => $values) {
324 324
                         foreach ((array) $values as $value) {
325
-                            $propertyChunks[] = $key . ': ' . $value . ';';
325
+                            $propertyChunks[] = $key.': '.$value.';';
326 326
                         }
327 327
                     }
328 328
 
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
             );
343 343
 
344 344
             // validate query
345
-            if($query === false) return;
345
+            if ($query === false) return;
346 346
 
347 347
             // search elements
348 348
             $elements = $xPath->query($query);
@@ -360,13 +360,13 @@  discard block
 block discarded – undo
360 360
 
361 361
                     foreach ($originalStyles as $property) {
362 362
                         // validate property
363
-                        if($property == '') continue;
363
+                        if ($property == '') continue;
364 364
 
365 365
                         // split into chunks
366 366
                         $chunks = (array) explode(':', trim($property), 2);
367 367
 
368 368
                         // validate
369
-                        if(!isset($chunks[1])) continue;
369
+                        if ( ! isset($chunks[1])) continue;
370 370
 
371 371
                         // loop chunks
372 372
                         $originalProperties[$chunks[0]] = trim($chunks[1]);
@@ -387,13 +387,13 @@  discard block
 block discarded – undo
387 387
                         // loop properties
388 388
                         foreach ($definedProperties as $property) {
389 389
                             // validate property
390
-                            if($property == '') continue;
390
+                            if ($property == '') continue;
391 391
 
392 392
                             // split into chunks
393 393
                             $chunks = (array) explode(':', trim($property), 2);
394 394
 
395 395
                             // validate
396
-                            if(!isset($chunks[1])) continue;
396
+                            if ( ! isset($chunks[1])) continue;
397 397
 
398 398
                             // loop chunks
399 399
                             $properties[$chunks[0]] = trim($chunks[1]);
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
                     // build chunks
412 412
                     foreach ($properties as $key => $values) {
413 413
                         foreach ((array) $values as $value) {
414
-                            $propertyChunks[] = $key . ': ' . $value . ';';
414
+                            $propertyChunks[] = $key.': '.$value.';';
415 415
                         }
416 416
                     }
417 417
 
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
                     $propertiesString = implode(' ', $propertyChunks);
420 420
 
421 421
                     // set attribute
422
-                    if($propertiesString != '') $element->setAttribute(
422
+                    if ($propertiesString != '') $element->setAttribute(
423 423
                         'style', $propertiesString
424 424
                     );
425 425
                 }
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
         }
460 460
 
461 461
         // cleanup the HTML if we need to
462
-        if($this->cleanup) $html = $this->cleanupHTML($html);
462
+        if ($this->cleanup) $html = $this->cleanupHTML($html);
463 463
 
464 464
         // strip original style tags if we need to
465 465
         if ($this->stripOriginalStyleTags) {
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
             $chunks = explode('{', $rule);
521 521
 
522 522
             // invalid rule?
523
-            if(!isset($chunks[1])) continue;
523
+            if ( ! isset($chunks[1])) continue;
524 524
 
525 525
             // set the selectors
526 526
             $selectors = trim($chunks[0]);
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
         }
562 562
 
563 563
         // sort based on specifity
564
-        if (!empty($this->cssRules)) {
564
+        if ( ! empty($this->cssRules)) {
565 565
             usort($this->cssRules, array(__CLASS__, 'sortOnSpecifity'));
566 566
         }
567 567
     }
@@ -586,15 +586,15 @@  discard block
 block discarded – undo
586 586
             $chunks = (array) explode(':', $property, 2);
587 587
 
588 588
             // validate
589
-            if(!isset($chunks[1])) continue;
589
+            if ( ! isset($chunks[1])) continue;
590 590
 
591 591
             // cleanup
592 592
             $chunks[0] = trim($chunks[0]);
593 593
             $chunks[1] = trim($chunks[1]);
594 594
 
595 595
             // add to pairs array
596
-            if(!isset($pairs[$chunks[0]]) ||
597
-               !in_array($chunks[1], $pairs[$chunks[0]])) {
596
+            if ( ! isset($pairs[$chunks[0]]) ||
597
+               ! in_array($chunks[1], $pairs[$chunks[0]])) {
598 598
                 $pairs[$chunks[0]][] = $chunks[1];
599 599
             }
600 600
         }
@@ -708,13 +708,13 @@  discard block
 block discarded – undo
708 708
     private static function sortOnSpecifity($e1, $e2)
709 709
     {
710 710
         // validate
711
-        if(!isset($e1['specifity']) || !isset($e2['specifity'])) return 0;
711
+        if ( ! isset($e1['specifity']) || ! isset($e2['specifity'])) return 0;
712 712
 
713 713
         // lower
714
-        if($e1['specifity'] < $e2['specifity']) return -1;
714
+        if ($e1['specifity'] < $e2['specifity']) return -1;
715 715
 
716 716
         // higher
717
-        if($e1['specifity'] > $e2['specifity']) return 1;
717
+        if ($e1['specifity'] > $e2['specifity']) return 1;
718 718
 
719 719
         // fallback
720 720
         return 0;
Please login to merge, or discard this patch.
Braces   +69 added lines, -23 removed lines patch added patch discarded remove patch
@@ -77,8 +77,12 @@  discard block
 block discarded – undo
77 77
      */
78 78
     public function __construct($html = null, $css = null)
79 79
     {
80
-        if($html !== null) $this->setHTML($html);
81
-        if($css !== null) $this->setCSS($css);
80
+        if($html !== null) {
81
+        	$this->setHTML($html);
82
+        }
83
+        if($css !== null) {
84
+        	$this->setCSS($css);
85
+        }
82 86
     }
83 87
 
84 88
     /**
@@ -166,13 +170,19 @@  discard block
 block discarded – undo
166 170
         // loop chunks
167 171
         foreach ($chunks as $chunk) {
168 172
             // an ID is important, so give it a high specifity
169
-            if(strstr($chunk, '#') !== false) $specifity += 100;
173
+            if(strstr($chunk, '#') !== false) {
174
+            	$specifity += 100;
175
+            }
170 176
 
171 177
             // classes are more important than a tag, but less important then an ID
172
-            elseif(strstr($chunk, '.')) $specifity += 10;
178
+            elseif(strstr($chunk, '.')) {
179
+            	$specifity += 10;
180
+            }
173 181
 
174 182
             // anything else isn't that important
175
-            else $specifity += 1;
183
+            else {
184
+            	$specifity += 1;
185
+            }
176 186
         }
177 187
 
178 188
         // return
@@ -211,7 +221,9 @@  discard block
 block discarded – undo
211 221
         $outputXHTML = (bool) $outputXHTML;
212 222
 
213 223
         // validate
214
-        if($this->html == null) throw new Exception('No HTML provided.');
224
+        if($this->html == null) {
225
+        	throw new Exception('No HTML provided.');
226
+        }
215 227
 
216 228
         // should we use inline style-block
217 229
         if ($this->useInlineStylesBlock) {
@@ -224,7 +236,9 @@  discard block
 block discarded – undo
224 236
             // any style-blocks found?
225 237
             if (!empty($matches[2])) {
226 238
                 // add
227
-                foreach($matches[2] as $match) $this->css .= trim($match) ."\n";
239
+                foreach($matches[2] as $match) {
240
+                	$this->css .= trim($match) ."\n";
241
+                }
228 242
             }
229 243
         }
230 244
 
@@ -251,13 +265,17 @@  discard block
 block discarded – undo
251 265
                 $query = $this->buildXPathQuery($rule['selector']);
252 266
 
253 267
                 // validate query
254
-                if($query === false) continue;
268
+                if($query === false) {
269
+                	continue;
270
+                }
255 271
 
256 272
                 // search elements
257 273
                 $elements = $xPath->query($query);
258 274
 
259 275
                 // validate elements
260
-                if($elements === false) continue;
276
+                if($elements === false) {
277
+                	continue;
278
+                }
261 279
 
262 280
                 // loop found elements
263 281
                 foreach ($elements as $element) {
@@ -298,13 +316,17 @@  discard block
 block discarded – undo
298 316
                         // loop properties
299 317
                         foreach ($definedProperties as $property) {
300 318
                             // validate property
301
-                            if($property == '') continue;
319
+                            if($property == '') {
320
+                            	continue;
321
+                            }
302 322
 
303 323
                             // split into chunks
304 324
                             $chunks = (array) explode(':', trim($property), 2);
305 325
 
306 326
                             // validate
307
-                            if(!isset($chunks[1])) continue;
327
+                            if(!isset($chunks[1])) {
328
+                            	continue;
329
+                            }
308 330
 
309 331
                             // loop chunks
310 332
                             $properties[$chunks[0]] = trim($chunks[1]);
@@ -342,7 +364,9 @@  discard block
 block discarded – undo
342 364
             );
343 365
 
344 366
             // validate query
345
-            if($query === false) return;
367
+            if($query === false) {
368
+            	return;
369
+            }
346 370
 
347 371
             // search elements
348 372
             $elements = $xPath->query($query);
@@ -360,13 +384,17 @@  discard block
 block discarded – undo
360 384
 
361 385
                     foreach ($originalStyles as $property) {
362 386
                         // validate property
363
-                        if($property == '') continue;
387
+                        if($property == '') {
388
+                        	continue;
389
+                        }
364 390
 
365 391
                         // split into chunks
366 392
                         $chunks = (array) explode(':', trim($property), 2);
367 393
 
368 394
                         // validate
369
-                        if(!isset($chunks[1])) continue;
395
+                        if(!isset($chunks[1])) {
396
+                        	continue;
397
+                        }
370 398
 
371 399
                         // loop chunks
372 400
                         $originalProperties[$chunks[0]] = trim($chunks[1]);
@@ -387,13 +415,17 @@  discard block
 block discarded – undo
387 415
                         // loop properties
388 416
                         foreach ($definedProperties as $property) {
389 417
                             // validate property
390
-                            if($property == '') continue;
418
+                            if($property == '') {
419
+                            	continue;
420
+                            }
391 421
 
392 422
                             // split into chunks
393 423
                             $chunks = (array) explode(':', trim($property), 2);
394 424
 
395 425
                             // validate
396
-                            if(!isset($chunks[1])) continue;
426
+                            if(!isset($chunks[1])) {
427
+                            	continue;
428
+                            }
397 429
 
398 430
                             // loop chunks
399 431
                             $properties[$chunks[0]] = trim($chunks[1]);
@@ -419,9 +451,11 @@  discard block
 block discarded – undo
419 451
                     $propertiesString = implode(' ', $propertyChunks);
420 452
 
421 453
                     // set attribute
422
-                    if($propertiesString != '') $element->setAttribute(
454
+                    if($propertiesString != '') {
455
+                    	$element->setAttribute(
423 456
                         'style', $propertiesString
424 457
                     );
458
+                    }
425 459
                 }
426 460
 
427 461
                 // remove placeholder
@@ -459,7 +493,9 @@  discard block
 block discarded – undo
459 493
         }
460 494
 
461 495
         // cleanup the HTML if we need to
462
-        if($this->cleanup) $html = $this->cleanupHTML($html);
496
+        if($this->cleanup) {
497
+        	$html = $this->cleanupHTML($html);
498
+        }
463 499
 
464 500
         // strip original style tags if we need to
465 501
         if ($this->stripOriginalStyleTags) {
@@ -520,7 +556,9 @@  discard block
 block discarded – undo
520 556
             $chunks = explode('{', $rule);
521 557
 
522 558
             // invalid rule?
523
-            if(!isset($chunks[1])) continue;
559
+            if(!isset($chunks[1])) {
560
+            	continue;
561
+            }
524 562
 
525 563
             // set the selectors
526 564
             $selectors = trim($chunks[0]);
@@ -586,7 +624,9 @@  discard block
 block discarded – undo
586 624
             $chunks = (array) explode(':', $property, 2);
587 625
 
588 626
             // validate
589
-            if(!isset($chunks[1])) continue;
627
+            if(!isset($chunks[1])) {
628
+            	continue;
629
+            }
590 630
 
591 631
             // cleanup
592 632
             $chunks[0] = trim($chunks[0]);
@@ -708,13 +748,19 @@  discard block
 block discarded – undo
708 748
     private static function sortOnSpecifity($e1, $e2)
709 749
     {
710 750
         // validate
711
-        if(!isset($e1['specifity']) || !isset($e2['specifity'])) return 0;
751
+        if(!isset($e1['specifity']) || !isset($e2['specifity'])) {
752
+        	return 0;
753
+        }
712 754
 
713 755
         // lower
714
-        if($e1['specifity'] < $e2['specifity']) return -1;
756
+        if($e1['specifity'] < $e2['specifity']) {
757
+        	return -1;
758
+        }
715 759
 
716 760
         // higher
717
-        if($e1['specifity'] > $e2['specifity']) return 1;
761
+        if($e1['specifity'] > $e2['specifity']) {
762
+        	return 1;
763
+        }
718 764
 
719 765
         // fallback
720 766
         return 0;
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_PMT_Base.lib.php 2 patches
Spacing   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  * @since 				$VID:$
15 15
  *
16 16
  */
17
-abstract class EE_PMT_Base{
17
+abstract class EE_PMT_Base {
18 18
 
19 19
 	const onsite = 'on-site';
20 20
 	const offsite = 'off-site';
@@ -90,27 +90,27 @@  discard block
 block discarded – undo
90 90
 	 * @return EE_PMT_Base
91 91
 	 */
92 92
 	function __construct($pm_instance = NULL) {
93
-		if ( $pm_instance instanceof EE_Payment_Method ){
93
+		if ($pm_instance instanceof EE_Payment_Method) {
94 94
 			$this->set_instance($pm_instance);
95 95
 		}
96 96
 		$this->_set_file_folder();
97 97
 		$this->_set_file_url();
98
-		if($this->_gateway){
99
-			$this->_gateway->set_payment_model( EEM_Payment::instance() );
100
-			$this->_gateway->set_payment_log( EEM_Change_Log::instance() );
101
-			EE_Registry::instance()->load_helper( 'Template' );
102
-			$this->_gateway->set_template_helper( new EEH_Template() );
103
-			EE_Registry::instance()->load_helper( 'Line_Item' );
104
-			$this->_gateway->set_line_item_helper( new EEH_Line_Item() );
105
-			EE_Registry::instance()->load_helper( 'Money' );
106
-			$this->_gateway->set_money_helper( new EEH_Money() );
98
+		if ($this->_gateway) {
99
+			$this->_gateway->set_payment_model(EEM_Payment::instance());
100
+			$this->_gateway->set_payment_log(EEM_Change_Log::instance());
101
+			EE_Registry::instance()->load_helper('Template');
102
+			$this->_gateway->set_template_helper(new EEH_Template());
103
+			EE_Registry::instance()->load_helper('Line_Item');
104
+			$this->_gateway->set_line_item_helper(new EEH_Line_Item());
105
+			EE_Registry::instance()->load_helper('Money');
106
+			$this->_gateway->set_money_helper(new EEH_Money());
107 107
 		}
108
-		if( ! $this->_pretty_name){
108
+		if ( ! $this->_pretty_name) {
109 109
 			throw new EE_Error(sprintf(__("You must set the pretty name for the Payment Method Type in the constructor (_pretty_name), and please make it internationalized", "event_espresso")));
110 110
 		}
111 111
 		//if the child didn't specify a default button, use the credit card one
112
-		if( $this->_default_button_url === NULL){
113
-			$this->_default_button_url = EE_PLUGIN_DIR_URL . 'payment_methods' . DS . 'pay-by-credit-card.png';
112
+		if ($this->_default_button_url === NULL) {
113
+			$this->_default_button_url = EE_PLUGIN_DIR_URL.'payment_methods'.DS.'pay-by-credit-card.png';
114 114
 		}
115 115
 	}
116 116
 
@@ -119,10 +119,10 @@  discard block
 block discarded – undo
119 119
 	/**
120 120
 	 * sets the file_folder property
121 121
 	 */
122
-	protected function _set_file_folder(){
122
+	protected function _set_file_folder() {
123 123
 		$reflector = new ReflectionClass(get_class($this));
124 124
 		$fn = $reflector->getFileName();
125
-		$this->_file_folder =  dirname($fn).DS;
125
+		$this->_file_folder = dirname($fn).DS;
126 126
 	}
127 127
 
128 128
 
@@ -130,10 +130,10 @@  discard block
 block discarded – undo
130 130
 	/**
131 131
 	 * sets the file URL with a trailing slash for this PMT
132 132
 	 */
133
-	protected function _set_file_url(){
134
-		$plugins_dir_fixed = str_replace('\\',DS,WP_PLUGIN_DIR);
135
-		$file_folder_fixed = str_replace('\\',DS,$this->file_folder());
136
-		$file_path = str_replace($plugins_dir_fixed,WP_PLUGIN_URL,$file_folder_fixed);
133
+	protected function _set_file_url() {
134
+		$plugins_dir_fixed = str_replace('\\', DS, WP_PLUGIN_DIR);
135
+		$file_folder_fixed = str_replace('\\', DS, $this->file_folder());
136
+		$file_path = str_replace($plugins_dir_fixed, WP_PLUGIN_URL, $file_folder_fixed);
137 137
 		$this->_file_url = $file_path;
138 138
 	}
139 139
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 * Gets the default description on all payment methods of this type
142 142
 	 * @return string
143 143
 	 */
144
-	public function default_description(){
144
+	public function default_description() {
145 145
 		return $this->_default_description;
146 146
 	}
147 147
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 * Returns the folder containing the PMT child class, with a trailing slash
152 152
 	 * @return string
153 153
 	 */
154
-	public function file_folder(){
154
+	public function file_folder() {
155 155
 		return $this->_file_folder;
156 156
 	}
157 157
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	/**
161 161
 	 * @return string
162 162
 	 */
163
-	public function file_url(){
163
+	public function file_url() {
164 164
 		return $this->_file_url;
165 165
 	}
166 166
 
@@ -171,14 +171,14 @@  discard block
 block discarded – undo
171 171
 	 * Its important teh payment method instance is set before
172 172
 	 * @param EE_Payment_Method $payment_method_instance
173 173
 	 */
174
-	function set_instance($payment_method_instance){
174
+	function set_instance($payment_method_instance) {
175 175
 		$this->_pm_instance = $payment_method_instance;
176 176
 		//if they have already requested the settings form, make sure its
177 177
 		//data matches this model object
178
-		if($this->_settings_form){
178
+		if ($this->_settings_form) {
179 179
 			$this->settings_form()->populate_model_obj($payment_method_instance);
180 180
 		}
181
-		if($this->_gateway && $this->_gateway instanceof EE_Gateway){
181
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
182 182
 			$this->_gateway->set_settings($payment_method_instance->settings_array());
183 183
 		}
184 184
 	}
@@ -189,14 +189,14 @@  discard block
 block discarded – undo
189 189
 	 * Gets teh form for displaying to admins where they setup the payment method
190 190
 	 * @return EE_Payment_Method_Form
191 191
 	 */
192
-	function settings_form(){
193
-		if( ! $this->_settings_form){
192
+	function settings_form() {
193
+		if ( ! $this->_settings_form) {
194 194
 			$this->_settings_form = $this->generate_new_settings_form();
195
-			$this->_settings_form->set_payment_method_type( $this );
196
-			$this->_settings_form->_construct_finalize(NULL, NULL );
195
+			$this->_settings_form->set_payment_method_type($this);
196
+			$this->_settings_form->_construct_finalize(NULL, NULL);
197 197
 			//if we have already assigned a model object to this pmt, make
198 198
 			//sure its reflected in teh form we just generated
199
-			if($this->_pm_instance){
199
+			if ($this->_pm_instance) {
200 200
 				$this->_settings_form->populate_model_obj($this->_pm_instance);
201 201
 			}
202 202
 		}
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 	 * this payment method type's settings form later in the request
223 223
 	 * @param EE_Payment_Method_Form $form
224 224
 	 */
225
-	public function set_settings_form($form){
225
+	public function set_settings_form($form) {
226 226
 		$this->_settings_form = $form;
227 227
 	}
228 228
 
@@ -235,18 +235,18 @@  discard block
 block discarded – undo
235 235
 	 * @param \EE_Transaction $transaction
236 236
 	 * @return \EE_Billing_Attendee_Info_Form|\EE_Billing_Info_Form
237 237
 	 */
238
-	public function billing_form( EE_Transaction $transaction = NULL ){
238
+	public function billing_form(EE_Transaction $transaction = NULL) {
239 239
 		// has billing form already been regenerated ? or overwrite cache?
240
-		if( ! $this->_billing_form || ! $this->_cache_billing_form ){
241
-			$this->_billing_form = $this->generate_new_billing_form( $transaction );
240
+		if ( ! $this->_billing_form || ! $this->_cache_billing_form) {
241
+			$this->_billing_form = $this->generate_new_billing_form($transaction);
242 242
 		}
243 243
 		//if we know who the attendee is, and this is a billing form
244 244
 		//that uses attendee info, populate it
245
-		if( $this->_billing_form instanceof EE_Billing_Attendee_Info_Form &&
245
+		if ($this->_billing_form instanceof EE_Billing_Attendee_Info_Form &&
246 246
 				$transaction instanceof EE_Transaction &&
247 247
 				$transaction->primary_registration() instanceof EE_Registration &&
248
-				$transaction->primary_registration()->attendee() instanceof EE_Attendee ){
249
-			$this->_billing_form->populate_from_attendee( $transaction->primary_registration()->attendee() );
248
+				$transaction->primary_registration()->attendee() instanceof EE_Attendee) {
249
+			$this->_billing_form->populate_from_attendee($transaction->primary_registration()->attendee());
250 250
 		}
251 251
 		return $this->_billing_form;
252 252
 	}
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 	 * @param \EE_Transaction $transaction
258 258
 	 * @return \EE_Billing_Info_Form
259 259
 	 */
260
-	abstract function generate_new_billing_form( EE_Transaction $transaction = NULL );
260
+	abstract function generate_new_billing_form(EE_Transaction $transaction = NULL);
261 261
 
262 262
 
263 263
 
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 	 * @param \EE_Billing_Info_Form $billing_form
269 269
 	 * @return \EE_Billing_Info_Form
270 270
 	 */
271
-	public function apply_billing_form_debug_settings( EE_Billing_Info_Form $billing_form ) {
271
+	public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) {
272 272
 		return $billing_form;
273 273
 	}
274 274
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 	 * if you have form
280 280
 	 * @param EE_Payment_Method $form
281 281
 	 */
282
-	public function set_billing_form($form){
282
+	public function set_billing_form($form) {
283 283
 		$this->_billing_form = $form;
284 284
 	}
285 285
 
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 	 * Returns whether or not this payment method requires HTTPS to be used
290 290
 	 * @return boolean
291 291
 	 */
292
-	function requires_https(){
292
+	function requires_https() {
293 293
 		return $this->_requires_https;
294 294
 	}
295 295
 
@@ -307,9 +307,9 @@  discard block
 block discarded – undo
307 307
 	 * @return \EE_Base_Class|\EE_Payment|null
308 308
 	 * @throws EE_Error
309 309
 	 */
310
-	function process_payment( EE_Transaction $transaction, $amount = NULL, $billing_info = NULL, $return_url = NULL,$fail_url = NULL, $method = 'CART', $by_admin = FALSE ){
310
+	function process_payment(EE_Transaction $transaction, $amount = NULL, $billing_info = NULL, $return_url = NULL, $fail_url = NULL, $method = 'CART', $by_admin = FALSE) {
311 311
 		// @todo: add surcharge for the payment method, if any
312
-		if ( $this->_gateway ) {
312
+		if ($this->_gateway) {
313 313
 			//there is a gateway, so we're going to make a payment object
314 314
 			//but wait! do they already have a payment in progress that we thought was failed?
315 315
 			$duplicate_properties = array(
@@ -320,15 +320,15 @@  discard block
 block discarded – undo
320 320
 				'PMD_ID' => $this->_pm_instance->ID(),
321 321
 				'PAY_gateway_response'=>NULL,
322 322
 			);
323
-			$payment = EEM_Payment::instance()->get_one( array( $duplicate_properties ));
323
+			$payment = EEM_Payment::instance()->get_one(array($duplicate_properties));
324 324
 			//if we didn't already have a payment in progress for the same thing,
325 325
 			//then we actually want to make a new payment
326
-			if ( ! $payment instanceof EE_Payment ){
326
+			if ( ! $payment instanceof EE_Payment) {
327 327
 				$payment = EE_Payment::new_instance(
328 328
 					array_merge(
329 329
 						$duplicate_properties,
330 330
 						array(
331
-							'PAY_timestamp' => current_time( 'mysql' ),
331
+							'PAY_timestamp' => current_time('mysql'),
332 332
 							'PAY_txn_id_chq_nmbr' => NULL,
333 333
 							'PAY_po_number' => NULL,
334 334
 							'PAY_extra_accntng' => NULL,
@@ -339,10 +339,10 @@  discard block
 block discarded – undo
339 339
 			}
340 340
 			//make sure the payment has been saved to show we started it, and so it has an ID should the gateway try to log it
341 341
 			$payment->save();
342
-			$billing_values = $this->_get_billing_values_from_form( $billing_info );
342
+			$billing_values = $this->_get_billing_values_from_form($billing_info);
343 343
 
344 344
 			//  Offsite Gateway
345
-			if( $this->_gateway instanceof EE_Offsite_Gateway ){
345
+			if ($this->_gateway instanceof EE_Offsite_Gateway) {
346 346
 
347 347
 				$payment = $this->_gateway->set_redirection_info(
348 348
 					$payment,
@@ -358,17 +358,17 @@  discard block
 block discarded – undo
358 358
 				);
359 359
 
360 360
 			//  Onsite Gateway
361
-			} elseif ( $this->_gateway instanceof EE_Onsite_Gateway ) {
361
+			} elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
362 362
 
363
-				$payment = $this->_gateway->do_direct_payment($payment,$billing_values);
363
+				$payment = $this->_gateway->do_direct_payment($payment, $billing_values);
364 364
 				$payment->save();
365 365
 
366 366
 			} else {
367 367
 				throw new EE_Error(
368 368
 					sprintf(
369
-						__('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or NULL (to indicate NO gateway)', 'event_espresso' ),
369
+						__('Gateway for payment method type "%s" is "%s", not a subclass of either EE_Offsite_Gateway or EE_Onsite_Gateway, or NULL (to indicate NO gateway)', 'event_espresso'),
370 370
 						get_class($this),
371
-						gettype( $this->_gateway )
371
+						gettype($this->_gateway)
372 372
 					)
373 373
 				);
374 374
 			}
@@ -380,8 +380,8 @@  discard block
 block discarded – undo
380 380
 		}
381 381
 
382 382
 		// if there is billing info, clean it and save it now
383
-		if( $billing_info instanceof EE_Billing_Attendee_Info_Form ){
384
-			$this->_save_billing_info_to_attendee( $billing_info, $transaction );
383
+		if ($billing_info instanceof EE_Billing_Attendee_Info_Form) {
384
+			$this->_save_billing_info_to_attendee($billing_info, $transaction);
385 385
 		}
386 386
 
387 387
 		return $payment;
@@ -394,10 +394,10 @@  discard block
 block discarded – undo
394 394
 	 * @param EE_Billing_Info_Form $billing_form
395 395
 	 * @return array
396 396
 	 */
397
-	protected function _get_billing_values_from_form( $billing_form ){
398
-		if($billing_form instanceof EE_Form_Section_Proper ){
397
+	protected function _get_billing_values_from_form($billing_form) {
398
+		if ($billing_form instanceof EE_Form_Section_Proper) {
399 399
 			return $billing_form->input_pretty_values();
400
-		}else{
400
+		} else {
401 401
 			return NULL;
402 402
 		}
403 403
 	}
@@ -411,13 +411,13 @@  discard block
 block discarded – undo
411 411
 	 * @return EE_Payment
412 412
 	 * @throws EE_Error
413 413
 	 */
414
-	public function handle_ipn($req_data,$transaction){
414
+	public function handle_ipn($req_data, $transaction) {
415 415
 		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
416
-		if( ! $this->_gateway instanceof EE_Offsite_Gateway){
417
-			throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r( $this->_gateway, TRUE )));
416
+		if ( ! $this->_gateway instanceof EE_Offsite_Gateway) {
417
+			throw new EE_Error(sprintf(__("Could not handle IPN because '%s' is not an offsite gateway", "event_espresso"), print_r($this->_gateway, TRUE)));
418 418
 
419 419
 		}
420
-		$payment = $this->_gateway->handle_payment_update( $req_data, $transaction );
420
+		$payment = $this->_gateway->handle_payment_update($req_data, $transaction);
421 421
 		return $payment;
422 422
 	}
423 423
 
@@ -430,22 +430,22 @@  discard block
 block discarded – undo
430 430
 	 * @param EE_Transaction $transaction
431 431
 	 * @return boolean success
432 432
 	 */
433
-	protected function _save_billing_info_to_attendee($billing_form, $transaction){
434
-		if( ! $transaction || ! $transaction instanceof EE_Transaction){
433
+	protected function _save_billing_info_to_attendee($billing_form, $transaction) {
434
+		if ( ! $transaction || ! $transaction instanceof EE_Transaction) {
435 435
 			EE_Error::add_error(__("Cannot save billing info because no transaction was specified", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
436 436
 			return false;
437 437
 		}
438 438
 		$primary_reg = $transaction->primary_registration();
439
-		if( ! $primary_reg ){
439
+		if ( ! $primary_reg) {
440 440
 			EE_Error::add_error(__("Cannot save billing info because the transaction has no primary registration", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
441 441
 			return false;
442 442
 		}
443 443
 		$attendee = $primary_reg->attendee();
444
-		if( ! $attendee ){
444
+		if ( ! $attendee) {
445 445
 			EE_Error::add_error(__("Cannot save billing info because the transaction's primary registration has no attendee!", "event_espresso"), __FILE__, __FUNCTION__, __LINE__);
446 446
 			return false;
447 447
 		}
448
-		return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method() );
448
+		return $attendee->save_and_clean_billing_info_for_payment_method($billing_form, $transaction->payment_method());
449 449
 
450 450
 	}
451 451
 
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 	 * @param array $req_data
459 459
 	 * @return EE_Payment
460 460
 	 */
461
-	protected function find_payment_for_ipn( EE_Transaction $transaction, $req_data = array() ){
461
+	protected function find_payment_for_ipn(EE_Transaction $transaction, $req_data = array()) {
462 462
 		return $transaction->last_payment();
463 463
 	}
464 464
 
@@ -475,8 +475,8 @@  discard block
 block discarded – undo
475 475
 	 * and identifies the IPN as being for this payment method (not just fo ra payment method of this type)
476 476
 	 * @throws EE_Error
477 477
 	 */
478
-	public function handle_unclaimed_ipn( $req_data = array() ){
479
-		throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this) ));
478
+	public function handle_unclaimed_ipn($req_data = array()) {
479
+		throw new EE_Error(sprintf(__("Payment Method '%s' cannot handle unclaimed IPNs", "event_espresso"), get_class($this)));
480 480
 	}
481 481
 
482 482
 
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 	 * @param EE_Transaction $transaction
493 493
 	 * @return EE_Payment
494 494
 	 */
495
-	public function finalize_payment_for($transaction){
495
+	public function finalize_payment_for($transaction) {
496 496
 		return $transaction->last_payment();
497 497
 	}
498 498
 
@@ -502,10 +502,10 @@  discard block
 block discarded – undo
502 502
 	 * Whether or not this payment method's gateway supports sending refund requests
503 503
 	 * @return boolean
504 504
 	 */
505
-	public function supports_sending_refunds(){
506
-		if($this->_gateway && $this->_gateway instanceof EE_Gateway){
505
+	public function supports_sending_refunds() {
506
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
507 507
 			return $this->_gateway->supports_sending_refunds();
508
-		}else{
508
+		} else {
509 509
 			return false;
510 510
 		}
511 511
 	}
@@ -519,11 +519,11 @@  discard block
 block discarded – undo
519 519
 	 * @throws EE_Error
520 520
 	 * @return EE_Payment
521 521
 	 */
522
-	public function process_refund($payment, $refund_info = array()){
523
-		if($this->_gateway && $this->_gateway instanceof EE_Gateway){
524
-			return $this->_gateway->do_direct_refund( $payment, $refund_info );
525
-		}else{
526
-			throw new EE_Error(sprintf(__("Payment Method Type '%s' does not support sending refund requests", "event_espresso"),get_class($this)));
522
+	public function process_refund($payment, $refund_info = array()) {
523
+		if ($this->_gateway && $this->_gateway instanceof EE_Gateway) {
524
+			return $this->_gateway->do_direct_refund($payment, $refund_info);
525
+		} else {
526
+			throw new EE_Error(sprintf(__("Payment Method Type '%s' does not support sending refund requests", "event_espresso"), get_class($this)));
527 527
 		}
528 528
 	}
529 529
 
@@ -535,15 +535,15 @@  discard block
 block discarded – undo
535 535
 	 * @return string
536 536
 	 * @throws EE_Error
537 537
 	 */
538
-	public function payment_occurs(){
539
-		if( ! $this->_gateway){
538
+	public function payment_occurs() {
539
+		if ( ! $this->_gateway) {
540 540
 			return EE_PMT_Base::offline;
541
-		}elseif($this->_gateway instanceof EE_Onsite_Gateway){
541
+		}elseif ($this->_gateway instanceof EE_Onsite_Gateway) {
542 542
 			return EE_PMT_Base::onsite;
543
-		}elseif($this->_gateway instanceof EE_Offsite_Gateway){
543
+		}elseif ($this->_gateway instanceof EE_Offsite_Gateway) {
544 544
 			return EE_PMT_Base::offsite;
545
-		}else{
546
-			throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"),get_class($this)));
545
+		} else {
546
+			throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"), get_class($this)));
547 547
 		}
548 548
 	}
549 549
 
@@ -556,9 +556,9 @@  discard block
 block discarded – undo
556 556
 	 * @param EE_Payment $payment
557 557
 	 * @return string
558 558
 	 */
559
-	public function payment_overview_content(EE_Payment $payment){
559
+	public function payment_overview_content(EE_Payment $payment) {
560 560
 		EE_Registry::instance()->load_helper('Template');
561
-		return EEH_Template::display_template(EE_LIBRARIES.'payment_methods'.DS.'templates'.DS.'payment_details_content.template.php', array('payment_method'=>$this->_pm_instance,'payment'=>$payment) , true);
561
+		return EEH_Template::display_template(EE_LIBRARIES.'payment_methods'.DS.'templates'.DS.'payment_details_content.template.php', array('payment_method'=>$this->_pm_instance, 'payment'=>$payment), true);
562 562
 	}
563 563
 
564 564
 
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
 	/**
567 567
 	 * @return array exactly like EE_Admin_Page _page_config's 'help_tabs' attribute. @see EE_Admin_Page::_set_page_config()
568 568
 	 */
569
-	public function help_tabs_config(){
569
+	public function help_tabs_config() {
570 570
 		return array();
571 571
 	}
572 572
 
@@ -577,9 +577,9 @@  discard block
 block discarded – undo
577 577
 	 * the payment method's table's PMT_type column)
578 578
 	 * @return string
579 579
 	 */
580
-	public function system_name(){
580
+	public function system_name() {
581 581
 		$classname = get_class($this);
582
-		return str_replace("EE_PMT_",'',$classname);
582
+		return str_replace("EE_PMT_", '', $classname);
583 583
 	}
584 584
 
585 585
 
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 	 * A pretty i18n version of the PMT name
589 589
 	 * @return string
590 590
 	 */
591
-	public function pretty_name(){
591
+	public function pretty_name() {
592 592
 		return $this->_pretty_name;
593 593
 	}
594 594
 
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 	 * Gets the default absolute URL to the payment method type's button
599 599
 	 * @return string
600 600
 	 */
601
-	public function default_button_url(){
601
+	public function default_button_url() {
602 602
 		return $this->_default_button_url;
603 603
 	}
604 604
 
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
 	 * Gets the gateway used by this payment method (if any)
609 609
 	 * @return EE_Gateway
610 610
 	 */
611
-	public function get_gateway(){
611
+	public function get_gateway() {
612 612
 		return $this->_gateway;
613 613
 	}
614 614
 
@@ -617,9 +617,9 @@  discard block
 block discarded – undo
617 617
 	/**
618 618
 	 * @return string html for the link to a help tab
619 619
 	 */
620
-	public function get_help_tab_link(){
621
-		EE_Registry::instance()->load_helper( 'Template' );
622
-		return EEH_Template::get_help_tab_link( $this->get_help_tab_name() );
620
+	public function get_help_tab_link() {
621
+		EE_Registry::instance()->load_helper('Template');
622
+		return EEH_Template::get_help_tab_link($this->get_help_tab_name());
623 623
 	}
624 624
 
625 625
 
@@ -628,8 +628,8 @@  discard block
 block discarded – undo
628 628
 	 * Returns the name of the help tab for this PMT
629 629
 	 * @return string
630 630
 	 */
631
-	public function get_help_tab_name(){
632
-		return 'ee_' . strtolower( $this->system_name() ) . '_help_tab';
631
+	public function get_help_tab_name() {
632
+		return 'ee_'.strtolower($this->system_name()).'_help_tab';
633 633
 	}
634 634
 
635 635
 	/**
@@ -637,8 +637,8 @@  discard block
 block discarded – undo
637 637
 	 * this PMT by an admin
638 638
 	 * @return string
639 639
 	 */
640
-	public function cap_name(){
641
-		return 'ee_payment_method_' . strtolower( $this->system_name() );
640
+	public function cap_name() {
641
+		return 'ee_payment_method_'.strtolower($this->system_name());
642 642
 	}
643 643
 
644 644
 	/**
@@ -650,9 +650,9 @@  discard block
 block discarded – undo
650 650
 	 * @param EE_Payment $payment
651 651
 	 * @return void
652 652
 	 */
653
-	public function update_txn_based_on_payment( $payment ){
654
-		if( $this->_gateway instanceof EE_Gateway ){
655
-			$this->_gateway->update_txn_based_on_payment( $payment );
653
+	public function update_txn_based_on_payment($payment) {
654
+		if ($this->_gateway instanceof EE_Gateway) {
655
+			$this->_gateway->update_txn_based_on_payment($payment);
656 656
 		}
657 657
 	}
658 658
 
Please login to merge, or discard this patch.
Braces   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 	protected function _get_billing_values_from_form( $billing_form ){
398 398
 		if($billing_form instanceof EE_Form_Section_Proper ){
399 399
 			return $billing_form->input_pretty_values();
400
-		}else{
400
+		} else{
401 401
 			return NULL;
402 402
 		}
403 403
 	}
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
 	public function supports_sending_refunds(){
506 506
 		if($this->_gateway && $this->_gateway instanceof EE_Gateway){
507 507
 			return $this->_gateway->supports_sending_refunds();
508
-		}else{
508
+		} else{
509 509
 			return false;
510 510
 		}
511 511
 	}
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 	public function process_refund($payment, $refund_info = array()){
523 523
 		if($this->_gateway && $this->_gateway instanceof EE_Gateway){
524 524
 			return $this->_gateway->do_direct_refund( $payment, $refund_info );
525
-		}else{
525
+		} else{
526 526
 			throw new EE_Error(sprintf(__("Payment Method Type '%s' does not support sending refund requests", "event_espresso"),get_class($this)));
527 527
 		}
528 528
 	}
@@ -538,11 +538,11 @@  discard block
 block discarded – undo
538 538
 	public function payment_occurs(){
539 539
 		if( ! $this->_gateway){
540 540
 			return EE_PMT_Base::offline;
541
-		}elseif($this->_gateway instanceof EE_Onsite_Gateway){
541
+		} elseif($this->_gateway instanceof EE_Onsite_Gateway){
542 542
 			return EE_PMT_Base::onsite;
543
-		}elseif($this->_gateway instanceof EE_Offsite_Gateway){
543
+		} elseif($this->_gateway instanceof EE_Offsite_Gateway){
544 544
 			return EE_PMT_Base::offsite;
545
-		}else{
545
+		} else{
546 546
 			throw new EE_Error(sprintf(__("Payment method type '%s's gateway isn't an instance of EE_Onsite_Gateway, EE_Offsite_Gateway, or null. It must be one of those", "event_espresso"),get_class($this)));
547 547
 		}
548 548
 	}
Please login to merge, or discard this patch.
libraries/shortcodes/EE_Primary_Registration_Details_Shortcodes.lib.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (!defined('EVENT_ESPRESSO_VERSION') )
3
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
4 4
 	exit('NO direct script access allowed');
5 5
 
6 6
 /**
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 			'[PRIMARY_REGISTRANT_ADDRESS2]' => __('Whatever was in the address 2 field for the primary registrant for the transaction.', 'event_espresso'),
46 46
 			'[PRIMARY_REGISTRANT_CITY]' => __('The city for the primary registrant for the transaction.', 'event_espresso'),
47 47
 			'[PRIMARY_REGISTRANT_ZIP_PC]' => __('The ZIP (or Postal) Code for the primary registrant for the transaction.', 'event_espresso'),
48
-			'[PRIMARY_REGISTRANT_ADDRESS_STATE]' => __('The state/province for the primary registrant for the transaction.', 'event_espresso' ),
48
+			'[PRIMARY_REGISTRANT_ADDRESS_STATE]' => __('The state/province for the primary registrant for the transaction.', 'event_espresso'),
49 49
 			'[PRIMARY_REGISTRANT_COUNTRY]' => __('The country for the primary registrant for the transaction.', 'event_espresso'),
50 50
 			'[PRIMARY_REGISTRANT_REGISTRATION_DATE]' => __('The date the registration occured for the primary registration.', 'event_espresso'),
51 51
 			'[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]' => __('Generates a link for the given registration to edit this registration details on the frontend.', 'event_espresso')
@@ -54,21 +54,21 @@  discard block
 block discarded – undo
54 54
 
55 55
 
56 56
 
57
-	protected function _parser( $shortcode ) {
57
+	protected function _parser($shortcode) {
58 58
 		//make sure we end up with a copy of the EE_Messages_Addressee object
59 59
 		$primary_registration = $this->_data instanceof EE_Messages_Addressee ? $this->_data : NULL;
60
-		$primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && is_array($this->_data) && isset( $this->_data['data'] ) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data'] : $primary_registration;
61
-		$primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && !empty( $this->_extra_data['data'] ) && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data'] : $primary_registration;
60
+		$primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && is_array($this->_data) && isset($this->_data['data']) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data'] : $primary_registration;
61
+		$primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data'] : $primary_registration;
62 62
 
63
-		if ( ! $primary_registration instanceof EE_Messages_Addressee )
63
+		if ( ! $primary_registration instanceof EE_Messages_Addressee)
64 64
 			return '';
65 65
 
66 66
 		$attendee = $primary_registration->primary_att_obj;
67 67
 
68
-		if ( ! $attendee instanceof EE_Attendee )
68
+		if ( ! $attendee instanceof EE_Attendee)
69 69
 			return '';
70 70
 
71
-		switch ( $shortcode ) {
71
+		switch ($shortcode) {
72 72
 			case '[PRIMARY_REGISTRANT_FNAME]' :
73 73
 				return $attendee->fname();
74 74
 				break;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 				break;
83 83
 
84 84
 			case '[PRIMARY_REGISTRANT_REGISTRATION_CODE]' :
85
-				if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration )
85
+				if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration)
86 86
 					return '';
87 87
 				return $primary_registration->primary_reg_obj->reg_code();
88 88
 				break;
@@ -118,13 +118,13 @@  discard block
 block discarded – undo
118 118
 				break;
119 119
 
120 120
 			case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]' :
121
-				if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration )
121
+				if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration)
122 122
 					return '';
123
-				return date_i18n( get_option( 'date_format'), strtotime( $primary_registration->primary_reg_obj->date() ) );
123
+				return date_i18n(get_option('date_format'), strtotime($primary_registration->primary_reg_obj->date()));
124 124
 				break;
125 125
 
126 126
 			case '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]' :
127
-				if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration )
127
+				if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration)
128 128
 					return '';
129 129
 				return $primary_registration->primary_reg_obj->edit_attendee_information_url();
130 130
 				break;
Please login to merge, or discard this patch.
Braces   +17 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (!defined('EVENT_ESPRESSO_VERSION') )
3
+if (!defined('EVENT_ESPRESSO_VERSION') ) {
4 4
 	exit('NO direct script access allowed');
5
+}
5 6
 
6 7
 /**
7 8
  * Event Espresso
@@ -60,13 +61,15 @@  discard block
 block discarded – undo
60 61
 		$primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && is_array($this->_data) && isset( $this->_data['data'] ) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data'] : $primary_registration;
61 62
 		$primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && !empty( $this->_extra_data['data'] ) && $this->_extra_data['data'] instanceof EE_Messages_Addressee ? $this->_extra_data['data'] : $primary_registration;
62 63
 
63
-		if ( ! $primary_registration instanceof EE_Messages_Addressee )
64
-			return '';
64
+		if ( ! $primary_registration instanceof EE_Messages_Addressee ) {
65
+					return '';
66
+		}
65 67
 
66 68
 		$attendee = $primary_registration->primary_att_obj;
67 69
 
68
-		if ( ! $attendee instanceof EE_Attendee )
69
-			return '';
70
+		if ( ! $attendee instanceof EE_Attendee ) {
71
+					return '';
72
+		}
70 73
 
71 74
 		switch ( $shortcode ) {
72 75
 			case '[PRIMARY_REGISTRANT_FNAME]' :
@@ -82,8 +85,9 @@  discard block
 block discarded – undo
82 85
 				break;
83 86
 
84 87
 			case '[PRIMARY_REGISTRANT_REGISTRATION_CODE]' :
85
-				if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration )
86
-					return '';
88
+				if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration ) {
89
+									return '';
90
+				}
87 91
 				return $primary_registration->primary_reg_obj->reg_code();
88 92
 				break;
89 93
 
@@ -118,14 +122,16 @@  discard block
 block discarded – undo
118 122
 				break;
119 123
 
120 124
 			case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]' :
121
-				if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration )
122
-					return '';
125
+				if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration ) {
126
+									return '';
127
+				}
123 128
 				return date_i18n( get_option( 'date_format'), strtotime( $primary_registration->primary_reg_obj->date() ) );
124 129
 				break;
125 130
 
126 131
 			case '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]' :
127
-				if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration )
128
-					return '';
132
+				if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration ) {
133
+									return '';
134
+				}
129 135
 				return $primary_registration->primary_reg_obj->edit_attendee_information_url();
130 136
 				break;
131 137
 
Please login to merge, or discard this patch.