Newsletter - Version 7.5.8

Version Description

  • Added filter on newsletter message before online view
  • Added excerpt lenght in character (useful for Chinese) on posts block
  • Improved the excerpt extraction
  • Add link on excerpt on posts block
Download this release

Release Info

Developer satollo
Plugin Icon 128x128 Newsletter
Version 7.5.8
Comparing to
See all releases

Code changes from version 7.5.7 to 7.5.8

emails/blocks/posts/block.php CHANGED
@@ -37,6 +37,7 @@ $defaults = array(
37
  'block_padding_bottom' => 15,
38
  'block_background' => '',
39
  'excerpt_length' => 30,
 
40
  'post_offset' => 0,
41
  'automated_include' => 'new',
42
  'inline_edits' => [],
@@ -119,6 +120,8 @@ remove_all_filters('excerpt_more');
119
  $image_placeholder_url = plugins_url('newsletter') . '/emails/blocks/posts/images/blank-240x160.png';
120
 
121
  $excerpt_length = $options['excerpt_length'];
 
 
122
 
123
  $show_image = !empty($options['show_image']);
124
  $show_date = !empty($options['show_date']);
37
  'block_padding_bottom' => 15,
38
  'block_background' => '',
39
  'excerpt_length' => 30,
40
+ 'excerpt_length_type' => '',
41
  'post_offset' => 0,
42
  'automated_include' => 'new',
43
  'inline_edits' => [],
120
  $image_placeholder_url = plugins_url('newsletter') . '/emails/blocks/posts/images/blank-240x160.png';
121
 
122
  $excerpt_length = $options['excerpt_length'];
123
+ $excerpt_length_in_chars = $options['excerpt_length_type'] == 'chars';
124
+
125
 
126
  $show_image = !empty($options['show_image']);
127
  $show_date = !empty($options['show_date']);
emails/blocks/posts/layout-big-image.php CHANGED
@@ -1,126 +1,132 @@
1
- <?php
2
- $size = ['width' => 600, 'height' => 0];
3
- $content_width = 600 - $options['block_padding_left'] - $options['block_padding_right'];
4
- $title_style = TNP_Composer::get_title_style($options, 'title', $composer);
5
- $text_style = TNP_Composer::get_style($options, '', $composer, 'text');
6
- ?>
7
- <style>
8
- .title {
9
- <?php echo $title_style->echo_css() ?>
10
- line-height: normal!important;
11
- padding: 0 0 5px 0;
12
- }
13
-
14
- .excerpt {
15
- <?php echo $text_style->echo_css() ?>
16
- line-height: 1.5em!important;
17
- padding: 10px 0 15px 0;
18
- }
19
-
20
- .meta {
21
- <?php echo $text_style->echo_css(0.9) ?>
22
- line-height: normal!important;
23
- padding: 0 0 5px 0;
24
- font-style: italic;
25
- }
26
- </style>
27
-
28
-
29
- <?php foreach ($posts as $post) { ?>
30
-
31
- <?php
32
- $url = tnp_post_permalink($post);
33
- $button_options['button_url'] = $url;
34
-
35
- $media = null;
36
- if ($show_image) {
37
- $media = tnp_composer_block_posts_get_media($post, $size);
38
-
39
- if ($media) {
40
- $media->set_width($content_width);
41
- $media->link = $url;
42
- }
43
- }
44
-
45
-
46
- $meta = [];
47
-
48
- if ($show_date) {
49
- $meta[] = tnp_post_date($post);
50
- }
51
-
52
- if ($show_author) {
53
- $author_object = get_user_by('id', $post->post_author);
54
- if ($author_object) {
55
- $meta[] = $author_object->display_name;
56
- }
57
- }
58
- ?>
59
-
60
- <?php if ($media) { ?>
61
- <table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-bottom: 20px">
62
- <tr>
63
- <td align="center">
64
- <?php echo TNP_Composer::image($media) ?>
65
- </td>
66
- </tr>
67
- </table>
68
- <?php } ?>
69
-
70
- <table width="100%" cellpadding="0" cellspacing="0" border="0" class="responsive" style="margin: 0;">
71
- <tr>
72
- <td>
73
-
74
- <table border="0" cellspacing="0" cellpadding="0" width="100%">
75
-
76
-
77
- <tr>
78
- <td align="<?php echo $align_left ?>" inline-class="title" class="tnpc-row-edit tnpc-inline-editable"
79
- data-type="title" data-id="<?php echo $post->ID ?>" dir="<?php echo $dir ?>">
80
- <?php
81
- echo TNP_Composer::is_post_field_edited_inline($options['inline_edits'], 'title', $post->ID) ?
82
- TNP_Composer::get_edited_inline_post_field($options['inline_edits'], 'title', $post->ID) :
83
- tnp_post_title($post)
84
- ?>
85
- </td>
86
- </tr>
87
-
88
- <?php if ($meta) { ?>
89
- <tr>
90
- <td align="<?php echo $align_left ?>" inline-class="meta">
91
- <?php echo esc_html(implode(' - ', $meta)) ?>
92
- </td>
93
- </tr>
94
- <?php } ?>
95
-
96
- <?php if ($excerpt_length) { ?>
97
- <tr>
98
- <td align="<?php echo $align_left ?>" inline-class="excerpt" class="tnpc-row-edit tnpc-inline-editable" data-type="text" data-id="<?php echo $post->ID ?>" dir="<?php echo $dir ?>">
99
- <?php
100
- echo TNP_Composer::is_post_field_edited_inline($options['inline_edits'], 'text', $post->ID) ?
101
- TNP_Composer::get_edited_inline_post_field($options['inline_edits'], 'text', $post->ID) :
102
- tnp_post_excerpt($post, $excerpt_length)
103
- ?>
104
- </td>
105
- </tr>
106
- <?php } ?>
107
-
108
- <?php if ($show_read_more_button) { ?>
109
- <tr>
110
- <td align="<?php echo $align_left ?>" inline-class="button">
111
- <?php echo TNP_Composer::button($button_options) ?>
112
- </td>
113
- </tr>
114
- <?php } ?>
115
- <tr>
116
- <td style="padding: 10px">&nbsp;</td>
117
- </tr>
118
- </table>
119
-
120
- </td>
121
- </tr>
122
- </table>
123
-
124
- <?php } ?>
125
-
126
-
 
 
 
 
 
 
1
+ <?php
2
+ $size = ['width' => 600, 'height' => 0];
3
+ $content_width = 600 - $options['block_padding_left'] - $options['block_padding_right'];
4
+ $title_style = TNP_Composer::get_title_style($options, 'title', $composer);
5
+ $text_style = TNP_Composer::get_style($options, '', $composer, 'text');
6
+ ?>
7
+ <style>
8
+ .title {
9
+ <?php echo $title_style->echo_css() ?>
10
+ line-height: normal!important;
11
+ padding: 0 0 5px 0;
12
+ }
13
+
14
+ .excerpt-td {
15
+ padding: 10px 0 15px 0;
16
+ }
17
+
18
+ .excerpt {
19
+ <?php echo $text_style->echo_css() ?>
20
+ line-height: 1.5em!important;
21
+ text-decoration: none;
22
+ }
23
+
24
+ .meta {
25
+ <?php echo $text_style->echo_css(0.9) ?>
26
+ line-height: normal!important;
27
+ padding: 0 0 5px 0;
28
+ font-style: italic;
29
+ }
30
+ </style>
31
+
32
+
33
+ <?php foreach ($posts as $post) { ?>
34
+
35
+ <?php
36
+ $url = tnp_post_permalink($post);
37
+ $button_options['button_url'] = $url;
38
+
39
+ $media = null;
40
+ if ($show_image) {
41
+ $media = tnp_composer_block_posts_get_media($post, $size);
42
+
43
+ if ($media) {
44
+ $media->set_width($content_width);
45
+ $media->link = $url;
46
+ }
47
+ }
48
+
49
+
50
+ $meta = [];
51
+
52
+ if ($show_date) {
53
+ $meta[] = tnp_post_date($post);
54
+ }
55
+
56
+ if ($show_author) {
57
+ $author_object = get_user_by('id', $post->post_author);
58
+ if ($author_object) {
59
+ $meta[] = $author_object->display_name;
60
+ }
61
+ }
62
+ ?>
63
+
64
+ <?php if ($media) { ?>
65
+ <table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-bottom: 20px">
66
+ <tr>
67
+ <td align="center">
68
+ <?php echo TNP_Composer::image($media) ?>
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ <?php } ?>
73
+
74
+ <table width="100%" cellpadding="0" cellspacing="0" border="0" class="responsive" style="margin: 0;">
75
+ <tr>
76
+ <td>
77
+
78
+ <table border="0" cellspacing="0" cellpadding="0" width="100%">
79
+
80
+
81
+ <tr>
82
+ <td align="<?php echo $align_left ?>" inline-class="title" class="tnpc-row-edit tnpc-inline-editable"
83
+ data-type="title" data-id="<?php echo $post->ID ?>" dir="<?php echo $dir ?>">
84
+ <?php
85
+ echo TNP_Composer::is_post_field_edited_inline($options['inline_edits'], 'title', $post->ID) ?
86
+ TNP_Composer::get_edited_inline_post_field($options['inline_edits'], 'title', $post->ID) :
87
+ tnp_post_title($post)
88
+ ?>
89
+ </td>
90
+ </tr>
91
+
92
+ <?php if ($meta) { ?>
93
+ <tr>
94
+ <td align="<?php echo $align_left ?>" inline-class="meta">
95
+ <?php echo esc_html(implode(' - ', $meta)) ?>
96
+ </td>
97
+ </tr>
98
+ <?php } ?>
99
+
100
+ <?php if ($excerpt_length) { ?>
101
+ <tr>
102
+ <td align="<?php echo $align_left ?>" inline-class="excerpt-td" dir="<?php echo $dir ?>">
103
+ <a href="<?php $url ?>" data-id="<?php echo $post->ID ?>" inline-class="excerpt" class="tnpc-row-edit tnpc-inline-editable" data-type="text">
104
+ <?php
105
+ echo TNP_Composer::is_post_field_edited_inline($options['inline_edits'], 'text', $post->ID) ?
106
+ TNP_Composer::get_edited_inline_post_field($options['inline_edits'], 'text', $post->ID) :
107
+ tnp_post_excerpt($post, $excerpt_length, $excerpt_length_in_chars)
108
+ ?>
109
+ </a>
110
+ </td>
111
+ </tr>
112
+ <?php } ?>
113
+
114
+ <?php if ($show_read_more_button) { ?>
115
+ <tr>
116
+ <td align="<?php echo $align_left ?>" inline-class="button">
117
+ <?php echo TNP_Composer::button($button_options) ?>
118
+ </td>
119
+ </tr>
120
+ <?php } ?>
121
+ <tr>
122
+ <td style="padding: 10px">&nbsp;</td>
123
+ </tr>
124
+ </table>
125
+
126
+ </td>
127
+ </tr>
128
+ </table>
129
+
130
+ <?php } ?>
131
+
132
+
emails/blocks/posts/layout-one-2.php CHANGED
@@ -1,138 +1,138 @@
1
- <?php
2
- $size = ['width' => 600, 'height' => 0];
3
- $total_width = 600 - $options['block_padding_left'] - $options['block_padding_right'];
4
- $column_width = $total_width / 2 - 10;
5
-
6
- $title_style = TNP_Composer::get_style($options, 'title', $composer, 'title');
7
- $text_style = TNP_Composer::get_style($options, '', $composer, 'text');
8
- ?>
9
- <style>
10
- .title {
11
- <?php $title_style->echo_css() ?>
12
- line-height: normal;
13
- padding: 0 0 10px 0;
14
- }
15
-
16
- .excerpt {
17
- <?php $text_style->echo_css() ?>
18
- line-height: 1.5em;
19
- padding: 0 0 15px 0;
20
- text-decoration: none;
21
- }
22
-
23
- .meta {
24
- font-family: <?php echo $text_style->font_family ?>;
25
- color: <?php echo $text_style->font_color ?>;
26
- font-size: <?php echo round($text_style->font_size * 0.9) ?>px;
27
- font-weight: <?php echo $text_style->font_weight ?>;
28
- padding: 0 0 5px 0;
29
- line-height: normal !important;
30
- font-style: italic;
31
- }
32
- .button {
33
- padding: 15px 0;
34
- }
35
- </style>
36
-
37
-
38
- <table border="0" cellpadding="0" cellspacing="0" width="100%" class="responsive">
39
-
40
- <?php foreach ($posts as $post) { ?>
41
- <?php
42
- $url = tnp_post_permalink($post);
43
-
44
- $media = null;
45
- if ($show_image) {
46
- $media = tnp_composer_block_posts_get_media($post, $size);
47
- if ($media) {
48
- $media->link = $url;
49
- $media->set_width($column_width);
50
- }
51
- }
52
-
53
- $meta = [];
54
-
55
- if ($show_date) {
56
- $meta[] = tnp_post_date($post);
57
- }
58
-
59
- if ($show_author) {
60
- $author_object = get_user_by('id', $post->post_author);
61
- if ($author_object) {
62
- $meta[] = $author_object->display_name;
63
- }
64
- }
65
-
66
- $button_options['button_url'] = $url;
67
- $button_options['button_align'] = 'left';
68
- ?>
69
-
70
- <tr>
71
- <td align="<?php echo $align_left ?>" inline-class="title" class="tnpc-row-edit tnpc-inline-editable" data-type="title" data-id="<?php echo $post->ID ?>" dir="<?php echo $dir ?>">
72
- <?php
73
- echo TNP_Composer::is_post_field_edited_inline($options['inline_edits'], 'title', $post->ID) ?
74
- TNP_Composer::get_edited_inline_post_field($options['inline_edits'], 'title', $post->ID) :
75
- tnp_post_title($post)
76
- ?>
77
- </td>
78
- </tr>
79
-
80
- <tr>
81
-
82
- <td valign="top" style="padding: 20px 0 25px 0;">
83
-
84
- <?php if ($media) { ?>
85
- <table width="<?php echo $column_width ?>" cellpadding="0" cellspacing="0" border="0" align="left" style="margin: 0;" class="responsive">
86
- <tr>
87
- <td class="pb-1">
88
- <?php echo TNP_Composer::image($media, ['class' => 'fluid']) ?>
89
- </td>
90
- </tr>
91
- </table>
92
- <?php } ?>
93
-
94
- <table width="<?php echo $media ? $column_width : '100%' ?>" cellpadding="0" cellspacing="0" border="0" style="margin: 0;" class="responsive" align="right">
95
- <tr>
96
- <td>
97
- <table border="0" cellspacing="0" cellpadding="0" width="100%" style="margin: 0;">
98
- <?php if ($meta) { ?>
99
- <tr>
100
- <td inline-class="meta" dir="<?php echo $dir ?>" align="<?php echo $align_left ?>">
101
- <?php echo esc_html(implode(' - ', $meta)) ?>
102
- </td>
103
- </tr>
104
- <?php } ?>
105
-
106
- <?php if ($excerpt_length) { ?>
107
- <tr>
108
- <td align="<?php echo $align_left ?>" dir="<?php echo $dir ?>">
109
- <a href="<?php $url ?>" data-id="<?php echo $post->ID ?>" inline-class="excerpt" class="tnpc-row-edit tnpc-inline-editable" data-type="text">
110
- <?php
111
- echo TNP_Composer::is_post_field_edited_inline($options['inline_edits'], 'text', $post->ID) ?
112
- TNP_Composer::get_edited_inline_post_field($options['inline_edits'], 'text', $post->ID) :
113
- tnp_post_excerpt($post, $excerpt_length)
114
- ?>
115
- </a>
116
- </td>
117
- </tr>
118
- <?php } ?>
119
-
120
- <?php if ($show_read_more_button) { ?>
121
- <tr>
122
- <td align="<?php echo $align_left ?>" inline-class="button">
123
- <?php echo TNP_Composer::button($button_options) ?>
124
- </td>
125
- </tr>
126
- <?php } ?>
127
- </table>
128
-
129
- </td>
130
- </tr>
131
- </table>
132
-
133
- </td>
134
- </tr>
135
-
136
- <?php } ?>
137
-
138
- </table>
1
+ <?php
2
+ $size = ['width' => 600, 'height' => 0];
3
+ $total_width = 600 - $options['block_padding_left'] - $options['block_padding_right'];
4
+ $column_width = $total_width / 2 - 10;
5
+
6
+ $title_style = TNP_Composer::get_style($options, 'title', $composer, 'title');
7
+ $text_style = TNP_Composer::get_style($options, '', $composer, 'text');
8
+ ?>
9
+ <style>
10
+ .title {
11
+ <?php $title_style->echo_css() ?>
12
+ line-height: normal;
13
+ padding: 0 0 10px 0;
14
+ }
15
+
16
+ .excerpt {
17
+ <?php $text_style->echo_css() ?>
18
+ line-height: 1.5em;
19
+ padding: 0 0 15px 0;
20
+ text-decoration: none;
21
+ }
22
+
23
+ .meta {
24
+ font-family: <?php echo $text_style->font_family ?>;
25
+ color: <?php echo $text_style->font_color ?>;
26
+ font-size: <?php echo round($text_style->font_size * 0.9) ?>px;
27
+ font-weight: <?php echo $text_style->font_weight ?>;
28
+ padding: 0 0 5px 0;
29
+ line-height: normal !important;
30
+ font-style: italic;
31
+ }
32
+ .button {
33
+ padding: 15px 0;
34
+ }
35
+ </style>
36
+
37
+
38
+ <table border="0" cellpadding="0" cellspacing="0" width="100%" class="responsive">
39
+
40
+ <?php foreach ($posts as $post) { ?>
41
+ <?php
42
+ $url = tnp_post_permalink($post);
43
+
44
+ $media = null;
45
+ if ($show_image) {
46
+ $media = tnp_composer_block_posts_get_media($post, $size);
47
+ if ($media) {
48
+ $media->link = $url;
49
+ $media->set_width($column_width);
50
+ }
51
+ }
52
+
53
+ $meta = [];
54
+
55
+ if ($show_date) {
56
+ $meta[] = tnp_post_date($post);
57
+ }
58
+
59
+ if ($show_author) {
60
+ $author_object = get_user_by('id', $post->post_author);
61
+ if ($author_object) {
62
+ $meta[] = $author_object->display_name;
63
+ }
64
+ }
65
+
66
+ $button_options['button_url'] = $url;
67
+ $button_options['button_align'] = 'left';
68
+ ?>
69
+
70
+ <tr>
71
+ <td align="<?php echo $align_left ?>" inline-class="title" class="tnpc-row-edit tnpc-inline-editable" data-type="title" data-id="<?php echo $post->ID ?>" dir="<?php echo $dir ?>">
72
+ <?php
73
+ echo TNP_Composer::is_post_field_edited_inline($options['inline_edits'], 'title', $post->ID) ?
74
+ TNP_Composer::get_edited_inline_post_field($options['inline_edits'], 'title', $post->ID) :
75
+ tnp_post_title($post)
76
+ ?>
77
+ </td>
78
+ </tr>
79
+
80
+ <tr>
81
+
82
+ <td valign="top" style="padding: 20px 0 25px 0;">
83
+
84
+ <?php if ($media) { ?>
85
+ <table width="<?php echo $column_width ?>" cellpadding="0" cellspacing="0" border="0" align="left" style="margin: 0;" class="responsive">
86
+ <tr>
87
+ <td class="pb-1">
88
+ <?php echo TNP_Composer::image($media, ['class' => 'fluid']) ?>
89
+ </td>
90
+ </tr>
91
+ </table>
92
+ <?php } ?>
93
+
94
+ <table width="<?php echo $media ? $column_width : '100%' ?>" cellpadding="0" cellspacing="0" border="0" style="margin: 0;" class="responsive" align="right">
95
+ <tr>
96
+ <td>
97
+ <table border="0" cellspacing="0" cellpadding="0" width="100%" style="margin: 0;">
98
+ <?php if ($meta) { ?>
99
+ <tr>
100
+ <td inline-class="meta" dir="<?php echo $dir ?>" align="<?php echo $align_left ?>">
101
+ <?php echo esc_html(implode(' - ', $meta)) ?>
102
+ </td>
103
+ </tr>
104
+ <?php } ?>
105
+
106
+ <?php if ($excerpt_length) { ?>
107
+ <tr>
108
+ <td align="<?php echo $align_left ?>" dir="<?php echo $dir ?>">
109
+ <a href="<?php $url ?>" data-id="<?php echo $post->ID ?>" inline-class="excerpt" class="tnpc-row-edit tnpc-inline-editable" data-type="text">
110
+ <?php
111
+ echo TNP_Composer::is_post_field_edited_inline($options['inline_edits'], 'text', $post->ID) ?
112
+ TNP_Composer::get_edited_inline_post_field($options['inline_edits'], 'text', $post->ID) :
113
+ tnp_post_excerpt($post, $excerpt_length, $excerpt_length_in_chars)
114
+ ?>
115
+ </a>
116
+ </td>
117
+ </tr>
118
+ <?php } ?>
119
+
120
+ <?php if ($show_read_more_button) { ?>
121
+ <tr>
122
+ <td align="<?php echo $align_left ?>" inline-class="button">
123
+ <?php echo TNP_Composer::button($button_options) ?>
124
+ </td>
125
+ </tr>
126
+ <?php } ?>
127
+ </table>
128
+
129
+ </td>
130
+ </tr>
131
+ </table>
132
+
133
+ </td>
134
+ </tr>
135
+
136
+ <?php } ?>
137
+
138
+ </table>
emails/blocks/posts/layout-one.php CHANGED
@@ -113,7 +113,7 @@ $text_style = TNP_Composer::get_style($options, '', $composer, 'text');
113
  <?php
114
  echo TNP_Composer::is_post_field_edited_inline($options['inline_edits'], 'text', $post->ID) ?
115
  TNP_Composer::get_edited_inline_post_field($options['inline_edits'], 'text', $post->ID) :
116
- tnp_post_excerpt($post, $excerpt_length)
117
  ?>
118
  </a>
119
  </td>
113
  <?php
114
  echo TNP_Composer::is_post_field_edited_inline($options['inline_edits'], 'text', $post->ID) ?
115
  TNP_Composer::get_edited_inline_post_field($options['inline_edits'], 'text', $post->ID) :
116
+ tnp_post_excerpt($post, $excerpt_length, $excerpt_length_in_chars)
117
  ?>
118
  </a>
119
  </td>
emails/blocks/posts/layout-two.php CHANGED
@@ -115,7 +115,7 @@ $items = [];
115
  <?php
116
  echo TNP_Composer::is_post_field_edited_inline($options['inline_edits'], 'text', $p->ID) ?
117
  TNP_Composer::get_edited_inline_post_field($options['inline_edits'], 'text', $p->ID) :
118
- tnp_post_excerpt($p, $excerpt_length)
119
  ?>
120
  </a>
121
  </td>
115
  <?php
116
  echo TNP_Composer::is_post_field_edited_inline($options['inline_edits'], 'text', $p->ID) ?
117
  TNP_Composer::get_edited_inline_post_field($options['inline_edits'], 'text', $p->ID) :
118
+ tnp_post_excerpt($p, $excerpt_length, $excerpt_length_in_chars)
119
  ?>
120
  </a>
121
  </td>
emails/blocks/posts/options.php CHANGED
@@ -14,40 +14,40 @@ if (class_exists('NewsletterExtensions')) {
14
 
15
  <?php if ($context['type'] == 'automated') { ?>
16
 
17
- <div class="tnp-field-box">
18
- <p>
19
- <strong>AUTOMATED</strong><br>
20
- While composing all posts are shown while on sending posts are extrated following the rules below.
21
- <a href="https://www.thenewsletterplugin.com/documentation/addons/extended-features/automated-extension/#regeneration" target="_blank">Read more</a>.
22
- </p>
23
- <?php $fields->select('automated_disabled', '', ['' => 'Use the last newsletter date and...', '1' => 'Do not consider the last newsletter']) ?>
24
 
25
- <div class="tnp-field-row">
26
- <div class="tnp-field-col-2">
27
- <?php
28
- $fields->select('automated_include', __('If there are new posts', 'newsletter'),
29
- [
30
- 'new' => __('Include only new posts', 'newsletter'),
31
- 'max' => __('Include specified max posts', 'newsletter')
32
- ],
33
- ['description' => '', 'class' => 'tnp-small'])
34
- ?>
35
- </div>
36
- <div class="tnp-field-col-2">
37
- <?php
38
- $fields->select('automated', __('If there are not new posts', 'newsletter'),
39
- [
40
- '' => 'Show the message below',
41
- '1' => 'Do not send the newsletter',
42
- '2' => 'Remove this block'
43
- ],
44
- ['description' => '', 'class' => 'tnp-small'])
45
- ?>
46
- <?php $fields->text('automated_no_contents', null, ['placeholder' => 'No new posts message']) ?>
 
47
  </div>
 
48
  </div>
49
- <div style="clear: both"></div>
50
- </div>
51
  <?php } ?>
52
 
53
 
@@ -87,10 +87,13 @@ $fields->select('layout', __('Layout', 'newsletter'),
87
  </div>
88
 
89
  <div class="tnp-field-row">
90
- <div class="tnp-field-col-2">
91
- <?php $fields->number('excerpt_length', __('Excerpt words', 'newsletter'), array('min' => 0)); ?>
92
  </div>
93
- <div class="tnp-field-col-2">
 
 
 
94
  <?php $fields->yesno('show_read_more_button', 'Show read more button') ?>
95
  </div>
96
  <div style="clear: both"></div>
14
 
15
  <?php if ($context['type'] == 'automated') { ?>
16
 
17
+ <div class="tnp-field-box">
18
+ <p>
19
+ <strong>AUTOMATED</strong><br>
20
+ While composing all posts are shown while on sending posts are extrated following the rules below.
21
+ <a href="https://www.thenewsletterplugin.com/documentation/addons/extended-features/automated-extension/#regeneration" target="_blank">Read more</a>.
22
+ </p>
23
+ <?php $fields->select('automated_disabled', '', ['' => 'Use the last newsletter date and...', '1' => 'Do not consider the last newsletter']) ?>
24
 
25
+ <div class="tnp-field-row">
26
+ <div class="tnp-field-col-2">
27
+ <?php
28
+ $fields->select('automated_include', __('If there are new posts', 'newsletter'),
29
+ [
30
+ 'new' => __('Include only new posts', 'newsletter'),
31
+ 'max' => __('Include specified max posts', 'newsletter')
32
+ ],
33
+ ['description' => '', 'class' => 'tnp-small'])
34
+ ?>
35
+ </div>
36
+ <div class="tnp-field-col-2">
37
+ <?php
38
+ $fields->select('automated', __('If there are not new posts', 'newsletter'),
39
+ [
40
+ '' => 'Show the message below',
41
+ '1' => 'Do not send the newsletter',
42
+ '2' => 'Remove this block'
43
+ ],
44
+ ['description' => '', 'class' => 'tnp-small'])
45
+ ?>
46
+ <?php $fields->text('automated_no_contents', null, ['placeholder' => 'No new posts message']) ?>
47
+ </div>
48
  </div>
49
+ <div style="clear: both"></div>
50
  </div>
 
 
51
  <?php } ?>
52
 
53
 
87
  </div>
88
 
89
  <div class="tnp-field-row">
90
+ <div class="tnp-field-col-3">
91
+ <?php $fields->number('excerpt_length', __('Excerpt length', 'newsletter'), array('min' => 0)); ?>
92
  </div>
93
+ <div class="tnp-field-col-3">
94
+ <?php $fields->select('excerpt_length_type', 'Count', ['' => __('Words', 'newsletter'), 'chars' => __('Chars', 'newsletter')]); ?>
95
+ </div>
96
+ <div class="tnp-field-col-3">
97
  <?php $fields->yesno('show_read_more_button', 'Show read more button') ?>
98
  </div>
99
  <div style="clear: both"></div>
emails/emails.php CHANGED
@@ -781,7 +781,7 @@ class NewsletterEmails extends NewsletterModule {
781
  header('X-Robots-Tag: noindex,nofollow,noarchive');
782
  header('Cache-Control: no-cache,no-store,private');
783
 
784
- echo $this->replace($email->message, $user, $email);
785
 
786
  die();
787
  break;
781
  header('X-Robots-Tag: noindex,nofollow,noarchive');
782
  header('Cache-Control: no-cache,no-store,private');
783
 
784
+ echo apply_filters('newsletter_view_message', $this->replace($email->message, $user, $email));
785
 
786
  die();
787
  break;
includes/helper.php CHANGED
@@ -1,415 +1,430 @@
1
- <?php
2
-
3
- defined('ABSPATH') || exit;
4
-
5
- function tnp_post_thumbnail_src($post, $size = 'thumbnail', $alternative = '') {
6
- if (is_object($post)) {
7
- $post = $post->ID;
8
- }
9
-
10
- // Find a media id to be used as featured image
11
- $media_id = get_post_thumbnail_id($post);
12
- if (empty($media_id)) {
13
- $attachments = get_children(array('numberpost' => 1, 'post_parent' => $post, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order'));
14
- if (!empty($attachments)) {
15
- foreach ($attachments as $id => &$attachment) {
16
- $media_id = $id;
17
- break;
18
- }
19
- }
20
- }
21
-
22
- if (!$media_id) {
23
- return $alternative;
24
- }
25
-
26
- if (!defined('NEWSLETTER_MEDIA_RESIZE') || NEWSLETTER_MEDIA_RESIZE) {
27
- if (is_array($size)) {
28
- $src = tnp_media_resize($media_id, $size);
29
- if (is_wp_error($src)) {
30
- Newsletter::instance()->logger->error($src);
31
- return $alternative;
32
- } else {
33
- return $src;
34
- }
35
- }
36
- }
37
-
38
- $media = wp_get_attachment_image_src($media_id, $size);
39
- if (strpos($media[0], 'http') !== 0) {
40
- $media[0] = 'http:' . $media[0];
41
- }
42
- return $media[0];
43
- }
44
-
45
- /**
46
- * @param WP_Post $post
47
- * @param int $length
48
- *
49
- * @return string
50
- */
51
- function tnp_post_excerpt($post, $length = 30, $characters = false) {
52
- if (!$length) return '';
53
-
54
- $excerpt = get_the_excerpt($post->ID);
55
- $excerpt = tnp_delete_all_shordcodes_tags($excerpt);
56
- $excerpt = trim($excerpt);
57
- $excerpt = str_replace('&nbsp;', '', $excerpt);
58
-
59
- if ($characters) {
60
- if (strlen($excerpt) > $length) {
61
- $excerpt = substr($excerpt, 0, $length);
62
- $i = strrpos($excerpt, ' ');
63
- if ($i) {
64
- $excerpt = substr($excerpt, 0, $i);
65
- $excerpt .= '&hellip;';
66
- }
67
- }
68
- } else {
69
- $excerpt = wp_trim_words($excerpt, $length);
70
- }
71
-
72
- return $excerpt;
73
- }
74
-
75
- function tnp_delete_all_shordcodes_tags($post_content = '') {
76
- //Delete open tags
77
- $post_content = preg_replace("/\[[a-zA-Z0-9_-]*?(\s.*?)?\]/", '', $post_content);
78
- //Delete close tags
79
- $post_content = preg_replace("/\[\/[a-zA-Z0-9_-]*?\]/", '', $post_content);
80
-
81
- return $post_content;
82
- }
83
-
84
- function tnp_post_permalink($post) {
85
- return get_permalink($post->ID);
86
- }
87
-
88
- function tnp_post_content($post) {
89
- return $post->post_content;
90
- }
91
-
92
- function tnp_post_title($post) {
93
- //return $post->post_title;
94
- return get_the_title($post);
95
- }
96
-
97
- function tnp_post_date($post, $format = null) {
98
- return get_the_date( $format, $post );
99
- }
100
-
101
- /**
102
- * Tries to create a resized version of a media uploaded to the media library.
103
- * Returns an empty string if the media does not exists or generally if the attached file
104
- * cannot be found. If the resize fails for whatever reason, fall backs to the
105
- * standard image source returned by WP which is usually not exactly the
106
- * requested size.
107
- *
108
- * @param int $media_id
109
- * @param array $size
110
- * @return string
111
- */
112
- function tnp_media_resize($media_id, $size) {
113
- if (empty($media_id)) {
114
- return '';
115
- }
116
-
117
- $relative_file = get_post_meta($media_id, '_wp_attached_file', true);
118
- if (empty($relative_file)) {
119
- return '';
120
- }
121
-
122
- $width = $size[0];
123
- $height = $size[1];
124
- $crop = false;
125
- if (isset($size[2])) {
126
- $crop = (boolean) $size[2];
127
- }
128
-
129
- $uploads = wp_upload_dir();
130
-
131
- // Based on _wp_relative_upload_path() function for blog which store the
132
- // full patch of media files
133
- if (0 === strpos($relative_file, $uploads['basedir'])) {
134
- $relative_file = str_replace($uploads['basedir'], '', $relative_file);
135
- $relative_file = ltrim($relative_file, '/');
136
- }
137
-
138
- $absolute_file = $uploads['basedir'] . '/' . $relative_file;
139
- // Relative and absolute name of the thumbnail.
140
- $pathinfo = pathinfo($relative_file);
141
-
142
- // We don't know why, but on some systems files with non-ascii characters loose the file name (grrr...)
143
- if (empty($pathinfo['filename'])) {
144
- $src = wp_get_attachment_image_src($media_id, 'full');
145
- return $src[0];
146
- }
147
-
148
- $relative_thumb = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '-' . $width . 'x' .
149
- $height . ($crop ? '-c' : '') . '.' . $pathinfo['extension'];
150
- $absolute_thumb = $uploads['basedir'] . '/newsletter/thumbnails/' . $relative_thumb;
151
-
152
- // Thumbnail generation if needed.
153
- if (!file_exists($absolute_thumb) || filemtime($absolute_thumb) < filemtime($absolute_file)) {
154
- $r = wp_mkdir_p($uploads['basedir'] . '/newsletter/thumbnails/' . $pathinfo['dirname']);
155
-
156
- if (!$r) {
157
- $src = wp_get_attachment_image_src($media_id, 'full');
158
- return $src[0];
159
- }
160
-
161
- $editor = wp_get_image_editor($absolute_file);
162
- if (is_wp_error($editor)) {
163
- $src = wp_get_attachment_image_src($media_id, 'full');
164
- return $src[0];
165
- //return $editor;
166
- //return $uploads['baseurl'] . '/' . $relative_file;
167
- }
168
-
169
- $original_size = $editor->get_size();
170
- if ($width > $original_size['width'] || $height > $original_size['height']) {
171
- $src = wp_get_attachment_image_src($media_id, 'full');
172
- return $src[0];
173
- }
174
-
175
- $editor->set_quality(80);
176
- $resized = $editor->resize($width, $height, $crop);
177
-
178
- if (is_wp_error($resized)) {
179
- $src = wp_get_attachment_image_src($media_id, 'full');
180
- return $src[0];
181
- }
182
-
183
- $saved = $editor->save($absolute_thumb);
184
- if (is_wp_error($saved)) {
185
- $src = wp_get_attachment_image_src($media_id, 'full');
186
- return $src[0];
187
- //return $saved;
188
- //return $uploads['baseurl'] . '/' . $relative_file;
189
- }
190
- }
191
-
192
- return $uploads['baseurl'] . '/newsletter/thumbnails/' . $relative_thumb;
193
- }
194
-
195
- function _tnp_get_default_media($media_id, $size) {
196
-
197
- $src = wp_get_attachment_image_src($media_id, $size);
198
- if (!$src) {
199
- return null;
200
- }
201
- $media = new TNP_Media();
202
- $media->id = $media_id;
203
- $media->url = $src[0];
204
- $media->width = $src[1];
205
- $media->height = $src[2];
206
- return $media;
207
- }
208
-
209
- function tnp_get_media($media_id, $size) {
210
- $src = wp_get_attachment_image_src($media_id, $size);
211
- if (!$src) {
212
- return null;
213
- }
214
- $media = new TNP_Media();
215
- $media->id = $media_id;
216
- $media->url = $src[0];
217
- $media->width = $src[1];
218
- $media->height = $src[2];
219
- return $media;
220
- }
221
-
222
- /**
223
- * Create a resized version of the media stored in the WP media library.
224
- *
225
- * @param int $media_id
226
- * @param array $size
227
- * @return TNP_Media
228
- */
229
- function tnp_resize($media_id, $size) {
230
- if (empty($media_id)) {
231
- return null;
232
- }
233
-
234
- $relative_file = get_post_meta($media_id, '_wp_attached_file', true);
235
-
236
- if (empty($relative_file)) {
237
- return null;
238
- }
239
-
240
- $uploads = wp_upload_dir();
241
-
242
- // Based on _wp_relative_upload_path() function for blog which store the
243
- // full path of media files
244
- if (0 === strpos($relative_file, $uploads['basedir'])) {
245
- $relative_file = str_replace($uploads['basedir'], '', $relative_file);
246
- $relative_file = ltrim($relative_file, '/');
247
- }
248
-
249
- $width = $size[0];
250
- $height = $size[1];
251
- $crop = false;
252
- if (isset($size[2])) {
253
- $crop = (boolean) $size[2];
254
- }
255
-
256
- $absolute_file = $uploads['basedir'] . '/' . $relative_file;
257
-
258
- if (substr($relative_file, -4) === '.gif') {
259
- $editor = wp_get_image_editor($absolute_file);
260
- if (is_wp_error($editor)) {
261
- return _tnp_get_default_media($media_id, $size);
262
- }
263
- $new_size = $editor->get_size();
264
- $media = new TNP_Media();
265
- $media->id = $media_id;
266
- $media->width = $new_size['width'];
267
- $media->height = $new_size['height'];
268
- if ($media->width > $width) {
269
- $media->set_width($width);
270
- }
271
- $media->url = $uploads['baseurl'] . '/' . $relative_file;
272
- return $media;
273
- }
274
-
275
- // Relative and absolute name of the thumbnail.
276
- $pathinfo = pathinfo($relative_file);
277
-
278
- // We don't know why, but on some systems files with non-ascii characters loose the file name (grrr...)
279
- if (empty($pathinfo['filename'])) {
280
- return _tnp_get_default_media($media_id, $size);
281
- }
282
-
283
- $relative_thumb = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '-' . $width . 'x' . $height . ($crop ? '-c' : '') . '.' . $pathinfo['extension'];
284
- $absolute_thumb = $uploads['basedir'] . '/newsletter/thumbnails/' . $relative_thumb;
285
-
286
- // Thumbnail generation if needed.
287
- if (!file_exists($absolute_thumb) || filemtime($absolute_thumb) < filemtime($absolute_file)) {
288
- $r = wp_mkdir_p($uploads['basedir'] . '/newsletter/thumbnails/' . $pathinfo['dirname']);
289
-
290
- if (!$r) {
291
- Newsletter::instance()->logger->error('Unable to create dir ' . $uploads['basedir'] . '/newsletter/thumbnails/' . $pathinfo['dirname']);
292
- return _tnp_get_default_media($media_id, $size);
293
- }
294
-
295
- $editor = wp_get_image_editor($absolute_file);
296
- if (is_wp_error($editor)) {
297
- Newsletter::instance()->logger->error($editor);
298
- Newsletter::instance()->logger->error('File: ' . $absolute_file);
299
- return _tnp_get_default_media($media_id, $size);
300
- }
301
-
302
- $original_size = $editor->get_size();
303
- if ($width > $original_size['width'] && ($height > $original_size['height'] || $height == 0)) {
304
- Newsletter::instance()->logger->error('Requested size larger than the original one');
305
- return _tnp_get_default_media($media_id, $size);
306
- }
307
-
308
- if ($height > $original_size['height'] && ($width > $original_size['width'] || $width == 0)) {
309
- Newsletter::instance()->logger->error('Requested size larger than the original one');
310
- return _tnp_get_default_media($media_id, $size);
311
- }
312
-
313
- $editor->set_quality(85);
314
- $resized = $editor->resize($width, $height, $crop);
315
-
316
- if (is_wp_error($resized)) {
317
- Newsletter::instance()->logger->error($resized);
318
- Newsletter::instance()->logger->error('File: ' . $absolute_file);
319
- return _tnp_get_default_media($media_id, $size);
320
- }
321
-
322
- $saved = $editor->save($absolute_thumb);
323
- if (is_wp_error($saved)) {
324
- Newsletter::instance()->logger->error($saved);
325
- return _tnp_get_default_media($media_id, $size);
326
- }
327
- $new_size = $editor->get_size();
328
-
329
- $media = new TNP_Media();
330
- $media->width = $new_size['width'];
331
- $media->height = $new_size['height'];
332
- $media->url = $uploads['baseurl'] . '/newsletter/thumbnails/' . $relative_thumb;
333
- } else {
334
- $media = new TNP_Media();
335
- $new_size = getimagesize($absolute_thumb);
336
- $media->width = $new_size[0];
337
- $media->height = $new_size[1];
338
- $media->url = $uploads['baseurl'] . '/newsletter/thumbnails/' . $relative_thumb;
339
- }
340
-
341
- return $media;
342
- }
343
-
344
- function tnp_resize_2x($media_id, $size) {
345
- $size[0] = $size[0] * 2;
346
- $size[1] = $size[1] * 2;
347
- $media = tnp_resize($media_id, $size);
348
- if (!$media)
349
- return $media;
350
- $media->set_width($size[0] / 2);
351
- return $media;
352
- }
353
-
354
- /**
355
- * @param TNP_Media[] $images
356
- *
357
- * @return int
358
- */
359
- function tnp_get_max_height_of($images) {
360
- $max_height = 0;
361
- foreach ($images as $image) {
362
- $max_height = $image->height > $max_height ? $image->height : $max_height;
363
- }
364
-
365
- return $max_height;
366
- }
367
-
368
- /**
369
- * @param WP_Post[] $product_list
370
- * @param array $size
371
- *
372
- * @return TNP_Media[]
373
- */
374
- function tnp_resize_product_list_featured_image($product_list, $size) {
375
- $images = [];
376
- foreach ($product_list as $p) {
377
- $images[$p->ID] = tnp_resize_2x(TNP_Composer::get_post_thumbnail_id($p->ID), $size);
378
- }
379
-
380
- return $images;
381
- }
382
-
383
- /**
384
- * Get media for "posts" composer block
385
- *
386
- * @param WP_Post post
387
- * @param array $size
388
- * @param string $default_image_url
389
- *
390
- * @return TNP_Media
391
- */
392
- function tnp_composer_block_posts_get_media($post, $size, $default_image_url = null) {
393
- $post_thumbnail_id = TNP_Composer::get_post_thumbnail_id($post);
394
-
395
- $media = null;
396
-
397
- if (!empty($post_thumbnail_id)) {
398
- $media = tnp_resize($post_thumbnail_id, array_values($size));
399
- } else if ($default_image_url) {
400
- Newsletter::instance()->logger->error('Thumbnail id not found');
401
- $media = new TNP_Media();
402
- $media->url = $default_image_url;
403
- $media->width = $size['width'];
404
- $media->height = $size['height'];
405
- }
406
- return $media;
407
- }
408
-
409
- function tnp_outlook_wrapper_open($width = 600) {
410
- return NewsletterEmails::get_outlook_wrapper_open($width);
411
- }
412
-
413
- function tnp_outlook_wrapper_close() {
414
- return NewsletterEmails::get_outlook_wrapper_close();
415
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ defined('ABSPATH') || exit;
4
+
5
+ function tnp_post_thumbnail_src($post, $size = 'thumbnail', $alternative = '') {
6
+ if (is_object($post)) {
7
+ $post = $post->ID;
8
+ }
9
+
10
+ // Find a media id to be used as featured image
11
+ $media_id = get_post_thumbnail_id($post);
12
+ if (empty($media_id)) {
13
+ $attachments = get_children(array('numberpost' => 1, 'post_parent' => $post, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order'));
14
+ if (!empty($attachments)) {
15
+ foreach ($attachments as $id => &$attachment) {
16
+ $media_id = $id;
17
+ break;
18
+ }
19
+ }
20
+ }
21
+
22
+ if (!$media_id) {
23
+ return $alternative;
24
+ }
25
+
26
+ if (!defined('NEWSLETTER_MEDIA_RESIZE') || NEWSLETTER_MEDIA_RESIZE) {
27
+ if (is_array($size)) {
28
+ $src = tnp_media_resize($media_id, $size);
29
+ if (is_wp_error($src)) {
30
+ Newsletter::instance()->logger->error($src);
31
+ return $alternative;
32
+ } else {
33
+ return $src;
34
+ }
35
+ }
36
+ }
37
+
38
+ $media = wp_get_attachment_image_src($media_id, $size);
39
+ if (strpos($media[0], 'http') !== 0) {
40
+ $media[0] = 'http:' . $media[0];
41
+ }
42
+ return $media[0];
43
+ }
44
+
45
+ $tnp_excerpt_length = 0;
46
+ function tnp_excerpt_length($length) {
47
+ global $tnp_excerpt_length;
48
+ return $tnp_excerpt_length;
49
+ }
50
+
51
+ /**
52
+ * @param WP_Post $post
53
+ * @param int $length
54
+ *
55
+ * @return string
56
+ */
57
+ function tnp_post_excerpt($post, $length = 30, $characters = false) {
58
+ global $tnp_excerpt_length;
59
+
60
+ if (!$length) return '';
61
+
62
+ $tnp_excerpt_length = (int)($length*1.5);
63
+
64
+ add_filter('excerpt_length', 'tnp_excerpt_length', PHP_INT_MAX);
65
+
66
+ $excerpt = get_the_excerpt($post->ID);
67
+
68
+ remove_filter('excerpt_length', 'tnp_excerpt_length', PHP_INT_MAX);
69
+
70
+ $excerpt = tnp_delete_all_shordcodes_tags($excerpt);
71
+ $excerpt = trim($excerpt);
72
+ $excerpt = str_replace('&nbsp;', '', $excerpt);
73
+
74
+ if ($characters) {
75
+ if (mb_strlen($excerpt) > $length) {
76
+ $excerpt = mb_substr($excerpt, 0, $length);
77
+ $i = mb_strrpos($excerpt, ' ');
78
+ if ($i) {
79
+ $excerpt = mb_substr($excerpt, 0, $i);
80
+ $excerpt .= '&hellip;';
81
+ }
82
+ }
83
+ } else {
84
+ $excerpt = wp_trim_words($excerpt, $length);
85
+ }
86
+
87
+ return $excerpt;
88
+ }
89
+
90
+ function tnp_delete_all_shordcodes_tags($post_content = '') {
91
+ //Delete open tags
92
+ $post_content = preg_replace("/\[[a-zA-Z0-9_-]*?(\s.*?)?\]/", '', $post_content);
93
+ //Delete close tags
94
+ $post_content = preg_replace("/\[\/[a-zA-Z0-9_-]*?\]/", '', $post_content);
95
+
96
+ return $post_content;
97
+ }
98
+
99
+ function tnp_post_permalink($post) {
100
+ return get_permalink($post->ID);
101
+ }
102
+
103
+ function tnp_post_content($post) {
104
+ return $post->post_content;
105
+ }
106
+
107
+ function tnp_post_title($post) {
108
+ //return $post->post_title;
109
+ return get_the_title($post);
110
+ }
111
+
112
+ function tnp_post_date($post, $format = null) {
113
+ return get_the_date( $format, $post );
114
+ }
115
+
116
+ /**
117
+ * Tries to create a resized version of a media uploaded to the media library.
118
+ * Returns an empty string if the media does not exists or generally if the attached file
119
+ * cannot be found. If the resize fails for whatever reason, fall backs to the
120
+ * standard image source returned by WP which is usually not exactly the
121
+ * requested size.
122
+ *
123
+ * @param int $media_id
124
+ * @param array $size
125
+ * @return string
126
+ */
127
+ function tnp_media_resize($media_id, $size) {
128
+ if (empty($media_id)) {
129
+ return '';
130
+ }
131
+
132
+ $relative_file = get_post_meta($media_id, '_wp_attached_file', true);
133
+ if (empty($relative_file)) {
134
+ return '';
135
+ }
136
+
137
+ $width = $size[0];
138
+ $height = $size[1];
139
+ $crop = false;
140
+ if (isset($size[2])) {
141
+ $crop = (boolean) $size[2];
142
+ }
143
+
144
+ $uploads = wp_upload_dir();
145
+
146
+ // Based on _wp_relative_upload_path() function for blog which store the
147
+ // full patch of media files
148
+ if (0 === strpos($relative_file, $uploads['basedir'])) {
149
+ $relative_file = str_replace($uploads['basedir'], '', $relative_file);
150
+ $relative_file = ltrim($relative_file, '/');
151
+ }
152
+
153
+ $absolute_file = $uploads['basedir'] . '/' . $relative_file;
154
+ // Relative and absolute name of the thumbnail.
155
+ $pathinfo = pathinfo($relative_file);
156
+
157
+ // We don't know why, but on some systems files with non-ascii characters loose the file name (grrr...)
158
+ if (empty($pathinfo['filename'])) {
159
+ $src = wp_get_attachment_image_src($media_id, 'full');
160
+ return $src[0];
161
+ }
162
+
163
+ $relative_thumb = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '-' . $width . 'x' .
164
+ $height . ($crop ? '-c' : '') . '.' . $pathinfo['extension'];
165
+ $absolute_thumb = $uploads['basedir'] . '/newsletter/thumbnails/' . $relative_thumb;
166
+
167
+ // Thumbnail generation if needed.
168
+ if (!file_exists($absolute_thumb) || filemtime($absolute_thumb) < filemtime($absolute_file)) {
169
+ $r = wp_mkdir_p($uploads['basedir'] . '/newsletter/thumbnails/' . $pathinfo['dirname']);
170
+
171
+ if (!$r) {
172
+ $src = wp_get_attachment_image_src($media_id, 'full');
173
+ return $src[0];
174
+ }
175
+
176
+ $editor = wp_get_image_editor($absolute_file);
177
+ if (is_wp_error($editor)) {
178
+ $src = wp_get_attachment_image_src($media_id, 'full');
179
+ return $src[0];
180
+ //return $editor;
181
+ //return $uploads['baseurl'] . '/' . $relative_file;
182
+ }
183
+
184
+ $original_size = $editor->get_size();
185
+ if ($width > $original_size['width'] || $height > $original_size['height']) {
186
+ $src = wp_get_attachment_image_src($media_id, 'full');
187
+ return $src[0];
188
+ }
189
+
190
+ $editor->set_quality(80);
191
+ $resized = $editor->resize($width, $height, $crop);
192
+
193
+ if (is_wp_error($resized)) {
194
+ $src = wp_get_attachment_image_src($media_id, 'full');
195
+ return $src[0];
196
+ }
197
+
198
+ $saved = $editor->save($absolute_thumb);
199
+ if (is_wp_error($saved)) {
200
+ $src = wp_get_attachment_image_src($media_id, 'full');
201
+ return $src[0];
202
+ //return $saved;
203
+ //return $uploads['baseurl'] . '/' . $relative_file;
204
+ }
205
+ }
206
+
207
+ return $uploads['baseurl'] . '/newsletter/thumbnails/' . $relative_thumb;
208
+ }
209
+
210
+ function _tnp_get_default_media($media_id, $size) {
211
+
212
+ $src = wp_get_attachment_image_src($media_id, $size);
213
+ if (!$src) {
214
+ return null;
215
+ }
216
+ $media = new TNP_Media();
217
+ $media->id = $media_id;
218
+ $media->url = $src[0];
219
+ $media->width = $src[1];
220
+ $media->height = $src[2];
221
+ return $media;
222
+ }
223
+
224
+ function tnp_get_media($media_id, $size) {
225
+ $src = wp_get_attachment_image_src($media_id, $size);
226
+ if (!$src) {
227
+ return null;
228
+ }
229
+ $media = new TNP_Media();
230
+ $media->id = $media_id;
231
+ $media->url = $src[0];
232
+ $media->width = $src[1];
233
+ $media->height = $src[2];
234
+ return $media;
235
+ }
236
+
237
+ /**
238
+ * Create a resized version of the media stored in the WP media library.
239
+ *
240
+ * @param int $media_id
241
+ * @param array $size
242
+ * @return TNP_Media
243
+ */
244
+ function tnp_resize($media_id, $size) {
245
+ if (empty($media_id)) {
246
+ return null;
247
+ }
248
+
249
+ $relative_file = get_post_meta($media_id, '_wp_attached_file', true);
250
+
251
+ if (empty($relative_file)) {
252
+ return null;
253
+ }
254
+
255
+ $uploads = wp_upload_dir();
256
+
257
+ // Based on _wp_relative_upload_path() function for blog which store the
258
+ // full path of media files
259
+ if (0 === strpos($relative_file, $uploads['basedir'])) {
260
+ $relative_file = str_replace($uploads['basedir'], '', $relative_file);
261
+ $relative_file = ltrim($relative_file, '/');
262
+ }
263
+
264
+ $width = $size[0];
265
+ $height = $size[1];
266
+ $crop = false;
267
+ if (isset($size[2])) {
268
+ $crop = (boolean) $size[2];
269
+ }
270
+
271
+ $absolute_file = $uploads['basedir'] . '/' . $relative_file;
272
+
273
+ if (substr($relative_file, -4) === '.gif') {
274
+ $editor = wp_get_image_editor($absolute_file);
275
+ if (is_wp_error($editor)) {
276
+ return _tnp_get_default_media($media_id, $size);
277
+ }
278
+ $new_size = $editor->get_size();
279
+ $media = new TNP_Media();
280
+ $media->id = $media_id;
281
+ $media->width = $new_size['width'];
282
+ $media->height = $new_size['height'];
283
+ if ($media->width > $width) {
284
+ $media->set_width($width);
285
+ }
286
+ $media->url = $uploads['baseurl'] . '/' . $relative_file;
287
+ return $media;
288
+ }
289
+
290
+ // Relative and absolute name of the thumbnail.
291
+ $pathinfo = pathinfo($relative_file);
292
+
293
+ // We don't know why, but on some systems files with non-ascii characters loose the file name (grrr...)
294
+ if (empty($pathinfo['filename'])) {
295
+ return _tnp_get_default_media($media_id, $size);
296
+ }
297
+
298
+ $relative_thumb = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '-' . $width . 'x' . $height . ($crop ? '-c' : '') . '.' . $pathinfo['extension'];
299
+ $absolute_thumb = $uploads['basedir'] . '/newsletter/thumbnails/' . $relative_thumb;
300
+
301
+ // Thumbnail generation if needed.
302
+ if (!file_exists($absolute_thumb) || filemtime($absolute_thumb) < filemtime($absolute_file)) {
303
+ $r = wp_mkdir_p($uploads['basedir'] . '/newsletter/thumbnails/' . $pathinfo['dirname']);
304
+
305
+ if (!$r) {
306
+ Newsletter::instance()->logger->error('Unable to create dir ' . $uploads['basedir'] . '/newsletter/thumbnails/' . $pathinfo['dirname']);
307
+ return _tnp_get_default_media($media_id, $size);
308
+ }
309
+
310
+ $editor = wp_get_image_editor($absolute_file);
311
+ if (is_wp_error($editor)) {
312
+ Newsletter::instance()->logger->error($editor);
313
+ Newsletter::instance()->logger->error('File: ' . $absolute_file);
314
+ return _tnp_get_default_media($media_id, $size);
315
+ }
316
+
317
+ $original_size = $editor->get_size();
318
+ if ($width > $original_size['width'] && ($height > $original_size['height'] || $height == 0)) {
319
+ Newsletter::instance()->logger->error('Requested size larger than the original one');
320
+ return _tnp_get_default_media($media_id, $size);
321
+ }
322
+
323
+ if ($height > $original_size['height'] && ($width > $original_size['width'] || $width == 0)) {
324
+ Newsletter::instance()->logger->error('Requested size larger than the original one');
325
+ return _tnp_get_default_media($media_id, $size);
326
+ }
327
+
328
+ $editor->set_quality(85);
329
+ $resized = $editor->resize($width, $height, $crop);
330
+
331
+ if (is_wp_error($resized)) {
332
+ Newsletter::instance()->logger->error($resized);
333
+ Newsletter::instance()->logger->error('File: ' . $absolute_file);
334
+ return _tnp_get_default_media($media_id, $size);
335
+ }
336
+
337
+ $saved = $editor->save($absolute_thumb);
338
+ if (is_wp_error($saved)) {
339
+ Newsletter::instance()->logger->error($saved);
340
+ return _tnp_get_default_media($media_id, $size);
341
+ }
342
+ $new_size = $editor->get_size();
343
+
344
+ $media = new TNP_Media();
345
+ $media->width = $new_size['width'];
346
+ $media->height = $new_size['height'];
347
+ $media->url = $uploads['baseurl'] . '/newsletter/thumbnails/' . $relative_thumb;
348
+ } else {
349
+ $media = new TNP_Media();
350
+ $new_size = getimagesize($absolute_thumb);
351
+ $media->width = $new_size[0];
352
+ $media->height = $new_size[1];
353
+ $media->url = $uploads['baseurl'] . '/newsletter/thumbnails/' . $relative_thumb;
354
+ }
355
+
356
+ return $media;
357
+ }
358
+
359
+ function tnp_resize_2x($media_id, $size) {
360
+ $size[0] = $size[0] * 2;
361
+ $size[1] = $size[1] * 2;
362
+ $media = tnp_resize($media_id, $size);
363
+ if (!$media)
364
+ return $media;
365
+ $media->set_width($size[0] / 2);
366
+ return $media;
367
+ }
368
+
369
+ /**
370
+ * @param TNP_Media[] $images
371
+ *
372
+ * @return int
373
+ */
374
+ function tnp_get_max_height_of($images) {
375
+ $max_height = 0;
376
+ foreach ($images as $image) {
377
+ $max_height = $image->height > $max_height ? $image->height : $max_height;
378
+ }
379
+
380
+ return $max_height;
381
+ }
382
+
383
+ /**
384
+ * @param WP_Post[] $product_list
385
+ * @param array $size
386
+ *
387
+ * @return TNP_Media[]
388
+ */
389
+ function tnp_resize_product_list_featured_image($product_list, $size) {
390
+ $images = [];
391
+ foreach ($product_list as $p) {
392
+ $images[$p->ID] = tnp_resize_2x(TNP_Composer::get_post_thumbnail_id($p->ID), $size);
393
+ }
394
+
395
+ return $images;
396
+ }
397
+
398
+ /**
399
+ * Get media for "posts" composer block
400
+ *
401
+ * @param WP_Post post
402
+ * @param array $size
403
+ * @param string $default_image_url
404
+ *
405
+ * @return TNP_Media
406
+ */
407
+ function tnp_composer_block_posts_get_media($post, $size, $default_image_url = null) {
408
+ $post_thumbnail_id = TNP_Composer::get_post_thumbnail_id($post);
409
+
410
+ $media = null;
411
+
412
+ if (!empty($post_thumbnail_id)) {
413
+ $media = tnp_resize($post_thumbnail_id, array_values($size));
414
+ } else if ($default_image_url) {
415
+ Newsletter::instance()->logger->error('Thumbnail id not found');
416
+ $media = new TNP_Media();
417
+ $media->url = $default_image_url;
418
+ $media->width = $size['width'];
419
+ $media->height = $size['height'];
420
+ }
421
+ return $media;
422
+ }
423
+
424
+ function tnp_outlook_wrapper_open($width = 600) {
425
+ return NewsletterEmails::get_outlook_wrapper_open($width);
426
+ }
427
+
428
+ function tnp_outlook_wrapper_close() {
429
+ return NewsletterEmails::get_outlook_wrapper_close();
430
+ }
plugin.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin Name: Newsletter
5
  Plugin URI: https://www.thenewsletterplugin.com/plugins/newsletter
6
  Description: Newsletter is a cool plugin to create your own subscriber list, to send newsletters, to build your business. <strong>Before update give a look to <a href="https://www.thenewsletterplugin.com/category/release">this page</a> to know what's changed.</strong>
7
- Version: 7.5.7
8
  Author: Stefano Lissa & The Newsletter Team
9
  Author URI: https://www.thenewsletterplugin.com
10
  Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
@@ -37,7 +37,7 @@ if (version_compare(phpversion(), '5.6', '<')) {
37
  return;
38
  }
39
 
40
- define('NEWSLETTER_VERSION', '7.5.7');
41
 
42
  global $newsletter, $wpdb;
43
 
4
  Plugin Name: Newsletter
5
  Plugin URI: https://www.thenewsletterplugin.com/plugins/newsletter
6
  Description: Newsletter is a cool plugin to create your own subscriber list, to send newsletters, to build your business. <strong>Before update give a look to <a href="https://www.thenewsletterplugin.com/category/release">this page</a> to know what's changed.</strong>
7
+ Version: 7.5.8
8
  Author: Stefano Lissa & The Newsletter Team
9
  Author URI: https://www.thenewsletterplugin.com
10
  Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
37
  return;
38
  }
39
 
40
+ define('NEWSLETTER_VERSION', '7.5.8');
41
 
42
  global $newsletter, $wpdb;
43
 
readme.txt CHANGED
@@ -1,7 +1,7 @@
1
  === Newsletter - Send awesome emails from WordPress ===
2
  Tags: newsletter, email marketing, welcome email, signup forms, lead generation, marketing automation
3
  Tested up to: 6.1.1
4
- Stable tag: 7.5.7
5
  Contributors: satollo,webagile,michael-travan
6
  License: GPLv2 or later
7
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -126,6 +126,13 @@ Thank you, The Newsletter Team
126
 
127
  == Changelog ==
128
 
 
 
 
 
 
 
 
129
  = 7.5.7 =
130
 
131
  * Check on ctype_space function (there are installation without it)
1
  === Newsletter - Send awesome emails from WordPress ===
2
  Tags: newsletter, email marketing, welcome email, signup forms, lead generation, marketing automation
3
  Tested up to: 6.1.1
4
+ Stable tag: 7.5.8
5
  Contributors: satollo,webagile,michael-travan
6
  License: GPLv2 or later
7
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
126
 
127
  == Changelog ==
128
 
129
+ = 7.5.8 =
130
+
131
+ * Added filter on newsletter message before online view
132
+ * Added excerpt lenght in character (useful for Chinese) on posts block
133
+ * Improved the excerpt extraction
134
+ * Add link on excerpt on posts block
135
+
136
  = 7.5.7 =
137
 
138
  * Check on ctype_space function (there are installation without it)