Completed
Branch FET-7988-evertec-needs (20e248)
by
unknown
1119:58 queued 1106:57
created
templates/thank-you-page-registration-details.template.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -5,61 +5,61 @@  discard block
 block discarded – undo
5 5
 /** @type string $SPCO_attendee_information_url */
6 6
 ?>
7 7
 <h3 class="ee-registration-details-h3"><?php _e('Registration Details', 'event_espresso'); ?></h3>
8
-<?php  do_action( 'AHEE__thank_you_page_registration_details_template__after_heading' ); ?>
8
+<?php  do_action('AHEE__thank_you_page_registration_details_template__after_heading'); ?>
9 9
 
10 10
 <div class="ee-registration-details-dv">
11 11
 <?php
12 12
 $reg_cntr = 0;
13 13
 $event_name = '';
14 14
 
15
-foreach ( $transaction->registrations() as $registration ) {
16
-	if ( $registration instanceof EE_Registration ) {
15
+foreach ($transaction->registrations() as $registration) {
16
+	if ($registration instanceof EE_Registration) {
17 17
 		$reg_cntr++;
18
-		if ( $event_name != $registration->event_name() ) {
18
+		if ($event_name != $registration->event_name()) {
19 19
 			$event_name = $registration->event_name();
20 20
 	?>
21 21
 	<h5>
22
-		<span class="smaller-text grey-text"><?php _e('for','event_espresso');?>: </span> <?php echo htmlentities( $registration->event_name(), ENT_QUOTES, 'UTF-8' );?>
22
+		<span class="smaller-text grey-text"><?php _e('for', 'event_espresso'); ?>: </span> <?php echo htmlentities($registration->event_name(), ENT_QUOTES, 'UTF-8'); ?>
23 23
 	</h5>
24 24
 	<table class='ee-table ee-registrations-list'>
25 25
 		<thead>
26 26
 			<tr>
27 27
 				<th width="40%">
28
-					<?php _e("Registrant Name",'event_espresso')?>
28
+					<?php _e("Registrant Name", 'event_espresso')?>
29 29
 				</th>
30 30
 				<th width="25%" class="jst-left">
31
-					<?php _e("REG Code",'event_espresso');?>
31
+					<?php _e("REG Code", 'event_espresso'); ?>
32 32
 				</th>
33 33
 				<th width="35%" class="jst-left">
34
-					<?php _e("REG Status",'event_espresso');?>
34
+					<?php _e("REG Status", 'event_espresso'); ?>
35 35
 				</th>
36 36
 			</tr>
37 37
 		</thead>
38 38
 		<tbody>
39 39
 	<?php } ?>
40
-	<?php if ( $is_primary || ( ! $is_primary && $reg_url_link == $registration->reg_url_link() )) { ?>
40
+	<?php if ($is_primary || ( ! $is_primary && $reg_url_link == $registration->reg_url_link())) { ?>
41 41
 			<tr>
42 42
 				<td width="40%">
43 43
 				<?php
44
-					if ( $registration->attendee() instanceof EE_Attendee ) {
45
-						echo $registration->attendee()->full_name( TRUE );
44
+					if ($registration->attendee() instanceof EE_Attendee) {
45
+						echo $registration->attendee()->full_name(TRUE);
46 46
 					}
47 47
 				?>
48 48
 					<p class="tiny-text" style="margin: .75em 0 0;">
49
-						<a class="ee-icon-only-lnk" href="<?php echo $registration->edit_attendee_information_url();?>" title="<?php esc_attr_e('Click here to edit Attendee Information', 'event_espresso');?>"><span class="ee-icon ee-icon-user-edit"></span><?php _e('edit info', 'event_espresso');?></a>
50
-						<a class="ee-resend-reg-confirmation-email ee-icon-only-lnk" href="<?php echo add_query_arg( array( 'token'=>$registration->reg_url_link(), 'resend_reg_confirmation' => 'true' ), EE_Registry::instance()->CFG->core->thank_you_page_url() );?>" title="<?php esc_attr_e('Click here to resend the Registration Confirmation email', 'event_espresso');?>" rel="<?php echo $registration->reg_url_link();?>"><span class="dashicons dashicons-email-alt"></span><?php _e('resend email', 'event_espresso');?></a>
49
+						<a class="ee-icon-only-lnk" href="<?php echo $registration->edit_attendee_information_url(); ?>" title="<?php esc_attr_e('Click here to edit Attendee Information', 'event_espresso'); ?>"><span class="ee-icon ee-icon-user-edit"></span><?php _e('edit info', 'event_espresso'); ?></a>
50
+						<a class="ee-resend-reg-confirmation-email ee-icon-only-lnk" href="<?php echo add_query_arg(array('token'=>$registration->reg_url_link(), 'resend_reg_confirmation' => 'true'), EE_Registry::instance()->CFG->core->thank_you_page_url()); ?>" title="<?php esc_attr_e('Click here to resend the Registration Confirmation email', 'event_espresso'); ?>" rel="<?php echo $registration->reg_url_link(); ?>"><span class="dashicons dashicons-email-alt"></span><?php _e('resend email', 'event_espresso'); ?></a>
51 51
 					</p>
52 52
 				</td>
53 53
 				<td width="25%" class="jst-left">
54 54
 					<?php $registration->e('REG_code') ?>
55 55
 				</td>
56 56
 				<td width="35%" class="jst-left">
57
-					<?php $registration->e_pretty_status( TRUE )?>
57
+					<?php $registration->e_pretty_status(TRUE)?>
58 58
 				</td>
59 59
 			</tr>
60
-            <?php  do_action( 'AHEE__thank_you_page_registration_details_template__after_registration_table_row', $registration ); ?>
60
+            <?php  do_action('AHEE__thank_you_page_registration_details_template__after_registration_table_row', $registration); ?>
61 61
         <?php } ?>
62
-        <?php if (( $event_name != $registration->event_name() && $event_name != '' ) || $reg_cntr >= count( $transaction->registrations() )) {  ?>
62
+        <?php if (($event_name != $registration->event_name() && $event_name != '') || $reg_cntr >= count($transaction->registrations())) {  ?>
63 63
 		</tbody>
64 64
 	</table>
65 65
 	<?php
@@ -67,13 +67,13 @@  discard block
 block discarded – undo
67 67
 	}
68 68
 }
69 69
 ?>
70
-<?php if ( $is_primary && $SPCO_attendee_information_url ) { ?>
70
+<?php if ($is_primary && $SPCO_attendee_information_url) { ?>
71 71
 	<p class="small-text jst-rght">
72 72
 		<a href='<?php echo $SPCO_attendee_information_url?>'><?php _e("Click here to edit All Attendee Information", 'event_espresso'); ?></a>
73 73
 	</p>
74 74
 <?php } ?>
75 75
 
76
-    <?php  do_action( 'AHEE__thank_you_page_registration_details_template__after_registration_details' ); ?>
76
+    <?php  do_action('AHEE__thank_you_page_registration_details_template__after_registration_details'); ?>
77 77
 
78 78
 </div>
79 79
 <!-- end of .registration-details -->
Please login to merge, or discard this patch.
admin_pages/registrations/templates/reg_admin_details_header.template.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 	
2
-		<h3 id="reg-admin-reg-details-reg-nmbr-hdr"><?php echo __( 'Registration # ', 'event_espresso' ) . $reg_nmbr['value'];?></h3>
3
-		<h2 id="reg-admin-reg-details-reg-date-hdr"><?php echo $reg_datetime['value'];?></h2>
2
+		<h3 id="reg-admin-reg-details-reg-nmbr-hdr"><?php echo __('Registration # ', 'event_espresso').$reg_nmbr['value']; ?></h3>
3
+		<h2 id="reg-admin-reg-details-reg-date-hdr"><?php echo $reg_datetime['value']; ?></h2>
4 4
 		<h2 id="reg-admin-reg-details-reg-status-hdr">
5
-			<?php echo __( 'Registration Status : ', 'event_espresso' );?>
6
-			<span class="<?php echo $reg_status['class'];?>"><?php echo $reg_status['value'];?></span>
5
+			<?php echo __('Registration Status : ', 'event_espresso'); ?>
6
+			<span class="<?php echo $reg_status['class']; ?>"><?php echo $reg_status['value']; ?></span>
7 7
 		</h2>
8 8
 		<h3>
9 9
 			<?php _e('Change status to: ', 'event_espresso'); ?>
10 10
 			<span id="reg-admin-approve-decline-reg-status-spn">
11
-				<?php echo $approve_decline_reg_status_buttons;?>
11
+				<?php echo $approve_decline_reg_status_buttons; ?>
12 12
 			</span>
13 13
 		</h3>
14
-		<?php if ( $registration->group_size() > 1 ) : ?>
15
-			<a id="scroll-to-other-attendees" class="scroll-to" href="#other-attendees"><?php echo __( 'Scroll to Other Registrations in the Same Transaction', 'event_espresso' );?></a>
14
+		<?php if ($registration->group_size() > 1) : ?>
15
+			<a id="scroll-to-other-attendees" class="scroll-to" href="#other-attendees"><?php echo __('Scroll to Other Registrations in the Same Transaction', 'event_espresso'); ?></a>
16 16
 		<?php endif; ?>
17 17
 		
18 18
 
Please login to merge, or discard this patch.
templates/reg_admin_details_main_meta_box_reg_details.template.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -4,44 +4,44 @@  discard block
 block discarded – undo
4 4
 	<?php echo $resend_registration_button; ?>
5 5
 	<br/>
6 6
 
7
-	<h4 class="admin-primary-mbox-h4 hdr-has-icon"><span class="dashicons dashicons-clipboard"></span><?php _e( 'Registration Items', 'event_espresso' );?></h4>
7
+	<h4 class="admin-primary-mbox-h4 hdr-has-icon"><span class="dashicons dashicons-clipboard"></span><?php _e('Registration Items', 'event_espresso'); ?></h4>
8 8
 
9 9
 	<div class="admin-primary-mbox-tbl-wrap">
10 10
 		<table class="admin-primary-mbox-tbl">
11 11
 			<thead>
12 12
 				<tr>
13
-					<th class="jst-left"><?php _e( 'Line Item ID', 'event_espresso' );?></th>
14
-					<th class="jst-left"><?php _e( 'Event Name', 'event_espresso' );?></th>
15
-					<th class="jst-left"><?php _e( 'Event Date', 'event_espresso' );?></th>
16
-					<th class="jst-left"><?php _e( 'Ticket Option', 'event_espresso' );?></th>
17
-					<th class="jst-cntr"><?php _e( 'Price', 'event_espresso' );?></th>
18
-					<th class="jst-cntr"><?php _e( 'Qty', 'event_espresso' );?></th>
19
-					<th class="jst-cntr"><?php _e( 'Line Total', 'event_espresso' );?></th>
13
+					<th class="jst-left"><?php _e('Line Item ID', 'event_espresso'); ?></th>
14
+					<th class="jst-left"><?php _e('Event Name', 'event_espresso'); ?></th>
15
+					<th class="jst-left"><?php _e('Event Date', 'event_espresso'); ?></th>
16
+					<th class="jst-left"><?php _e('Ticket Option', 'event_espresso'); ?></th>
17
+					<th class="jst-cntr"><?php _e('Price', 'event_espresso'); ?></th>
18
+					<th class="jst-cntr"><?php _e('Qty', 'event_espresso'); ?></th>
19
+					<th class="jst-cntr"><?php _e('Line Total', 'event_espresso'); ?></th>
20 20
 				</tr>
21 21
 			</thead>
22 22
 			<tbody>
23
-		<?php foreach ( $line_items as $item ) :
23
+		<?php foreach ($line_items as $item) :
24 24
 ?>
25 25
 			<tr>
26
-				<td class="jst-left"><?php echo $item->get('LIN_code');?></td>
27
-				<td class="jst-left"><?php echo $item->ticket_event_name();?></td>
28
-				<td class="jst-left"><?php echo $item->ticket_datetime_start('Y-m-d','h:i a'); ?></td>
29
-				<td class="jst-left"><?php echo $item->get('LIN_name');?></td>
30
-				<td class="jst-rght"><?php echo EEH_Template::format_currency( $item->get('LIN_unit_price') );?></td>
31
-				<td class="jst-rght"><?php echo $item->get('LIN_quantity');?></td>
32
-				<td class="jst-rght"><?php echo EEH_Template::format_currency($item->get('LIN_total'));?></td>
26
+				<td class="jst-left"><?php echo $item->get('LIN_code'); ?></td>
27
+				<td class="jst-left"><?php echo $item->ticket_event_name(); ?></td>
28
+				<td class="jst-left"><?php echo $item->ticket_datetime_start('Y-m-d', 'h:i a'); ?></td>
29
+				<td class="jst-left"><?php echo $item->get('LIN_name'); ?></td>
30
+				<td class="jst-rght"><?php echo EEH_Template::format_currency($item->get('LIN_unit_price')); ?></td>
31
+				<td class="jst-rght"><?php echo $item->get('LIN_quantity'); ?></td>
32
+				<td class="jst-rght"><?php echo EEH_Template::format_currency($item->get('LIN_total')); ?></td>
33 33
 			</tr>
34 34
 		<?php endforeach; // $items?>
35
-		<?php if ( $taxes ) : ?>
36
-			<?php foreach ( $taxes as $tax ) : ?>
35
+		<?php if ($taxes) : ?>
36
+			<?php foreach ($taxes as $tax) : ?>
37 37
 				<tr>
38
-					<th class=" jst-rght" colspan="6"><?php echo $tax->get('LIN_name');?> (<?php echo $tax->get_pretty('LIN_percent'); ?>%)</th>
39
-					<th class=" jst-rght"><?php echo EEH_Template::format_currency( $tax->get('LIN_total'));?></th>
38
+					<th class=" jst-rght" colspan="6"><?php echo $tax->get('LIN_name'); ?> (<?php echo $tax->get_pretty('LIN_percent'); ?>%)</th>
39
+					<th class=" jst-rght"><?php echo EEH_Template::format_currency($tax->get('LIN_total')); ?></th>
40 40
 				</tr>
41 41
 			<?php endforeach; // $taxes?>
42 42
 		<?php endif; // $taxes?>
43 43
 				<tr class="admin-primary-mbox-total-tr">
44
-					<th class=" jst-rght" colspan="6"><?php _e( 'Grand Total', 'event_espresso' );?></th>
44
+					<th class=" jst-rght" colspan="6"><?php _e('Grand Total', 'event_espresso'); ?></th>
45 45
 					<th class=" jst-rght"><?php echo $grand_total; ?></th>
46 46
 				</tr>
47 47
 			</tbody>
@@ -49,28 +49,28 @@  discard block
 block discarded – undo
49 49
 	</div>
50 50
 
51 51
 	<?php
52
-	if ( WP_DEBUG ) {
53
-		$delivered_messages = get_option( 'EED_Messages__maybe_registration', array() );
54
-		if ( isset( $delivered_messages[ $REG_ID ] )) {
52
+	if (WP_DEBUG) {
53
+		$delivered_messages = get_option('EED_Messages__maybe_registration', array());
54
+		if (isset($delivered_messages[$REG_ID])) {
55 55
 	?>
56
-	<h4 class="admin-primary-mbox-h4 hdr-has-icon"><span class="dashicons dashicons-email-alt"></span><?php _e( 'Messages Sent to Registrant', 'event_espresso' );?></h4>
56
+	<h4 class="admin-primary-mbox-h4 hdr-has-icon"><span class="dashicons dashicons-email-alt"></span><?php _e('Messages Sent to Registrant', 'event_espresso'); ?></h4>
57 57
 
58 58
 	<div class="admin-primary-mbox-tbl-wrap">
59 59
 		<table class="admin-primary-mbox-tbl">
60 60
 			<thead>
61 61
 				<tr>
62
-					<th class="jst-left"><?php _e( 'Date & Time', 'event_espresso' );?></th>
63
-					<th class="jst-left"><?php _e( 'Message Type', 'event_espresso' );?></th>
64
-					<th class="jst-left"><?php _e( 'REG Status Upon Sending', 'event_espresso' );?></th>
62
+					<th class="jst-left"><?php _e('Date & Time', 'event_espresso'); ?></th>
63
+					<th class="jst-left"><?php _e('Message Type', 'event_espresso'); ?></th>
64
+					<th class="jst-left"><?php _e('REG Status Upon Sending', 'event_espresso'); ?></th>
65 65
 				</tr>
66 66
 			</thead>
67 67
 			<tbody>
68
-				<?php foreach ( $delivered_messages[ $REG_ID ] as $timestamp => $delivered_message ) :
68
+				<?php foreach ($delivered_messages[$REG_ID] as $timestamp => $delivered_message) :
69 69
 					?>
70 70
 					<tr>
71
-						<td class="jst-left"><?php echo gmdate( get_option('date_format') . ' ' . get_option('time_format'), ( $timestamp + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) );?></td>
72
-						<td class="jst-left"><?php echo isset( $delivered_message['message_type'] ) ? $delivered_message['message_type'] : '';?></td>
73
-						<td class="jst-left"><?php echo isset( $delivered_message['reg_status'] ) ? $delivered_message['reg_status'] : '';?></td>
71
+						<td class="jst-left"><?php echo gmdate(get_option('date_format').' '.get_option('time_format'), ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td>
72
+						<td class="jst-left"><?php echo isset($delivered_message['message_type']) ? $delivered_message['message_type'] : ''; ?></td>
73
+						<td class="jst-left"><?php echo isset($delivered_message['reg_status']) ? $delivered_message['reg_status'] : ''; ?></td>
74 74
 					</tr>
75 75
 				<?php endforeach; // $delivered_messages?>
76 76
 			</tbody>
@@ -82,27 +82,27 @@  discard block
 block discarded – undo
82 82
 	?>
83 83
 
84 84
 	<a id="display-additional-registration-session-info" class="display-the-hidden smaller-text" rel="additional-registration-session-info">
85
-		<span class="dashicons dashicons-plus-alt"></span><?php _e( 'view additional registration session details', 'event_espresso' );?>
85
+		<span class="dashicons dashicons-plus-alt"></span><?php _e('view additional registration session details', 'event_espresso'); ?>
86 86
 	</a>
87 87
 
88 88
 	<div id="additional-registration-session-info-dv" class="hidden">
89 89
 
90 90
 		<a id="hide-additional-registration-session-info" class="hide-the-displayed hidden smaller-text" rel="additional-registration-session-info">
91
-			<span class="dashicons dashicons-dismiss"></span><?php _e( 'hide additional registration session details', 'event_espresso' );?>
91
+			<span class="dashicons dashicons-dismiss"></span><?php _e('hide additional registration session details', 'event_espresso'); ?>
92 92
 		</a>
93 93
 	<br class="clear"/>
94 94
 
95
-		<h4 class="admin-primary-mbox-h4"><?php _e( 'Registration Session Details', 'event_espresso' );?></h4>
95
+		<h4 class="admin-primary-mbox-h4"><?php _e('Registration Session Details', 'event_espresso'); ?></h4>
96 96
 
97 97
 		<table id="admin-primary-mbox-reg-extra-session-info-tbl" class="form-table skinny-rows">
98 98
 			<tbody>
99
-			<?php foreach ( $reg_details as $key => $reg_detail ) : ?>
99
+			<?php foreach ($reg_details as $key => $reg_detail) : ?>
100 100
 				<tr>
101 101
 					<th>
102
-						<label for="<?php echo $key;?>"><?php echo $reg_detail['label'];?></label>
102
+						<label for="<?php echo $key; ?>"><?php echo $reg_detail['label']; ?></label>
103 103
 					</th>
104 104
 					<td>
105
-						<?php echo $reg_detail['value'];?>
105
+						<?php echo $reg_detail['value']; ?>
106 106
 					</td>
107 107
 				</tr>
108 108
 			<?php endforeach; // $reg_details?>
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.
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.
admin/extend/events/templates/event_type_metabox_contents.template.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -4,9 +4,9 @@
 block discarded – undo
4 4
 	</ul>
5 5
 	<div id="espresso_event_type-all" class="tabs-panel">
6 6
 		<?php
7
-        $name = 'tax_input[espresso_event_type]';
8
-        echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
9
-        ?>
7
+		$name = 'tax_input[espresso_event_type]';
8
+		echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
9
+		?>
10 10
 		<ul id="espresso_event_typechecklist" data-wp-lists="list:espresso_event_type" class="categorychecklist form-no-clear">
11 11
 			<?php echo $radio_list; ?>
12 12
 		</ul>
Please login to merge, or discard this patch.