@@ -27,11 +27,37 @@ class Email_Template_Renderer {
2727 */
2828 const EMAIL_ASSETS_BASE_URL = 'https://storage.googleapis.com/pue-email-assets-dev/ ' ;
2929
30+ /**
31+ * Asset paths mapping.
32+ *
33+ * Maps asset filenames to their versioned folder paths.
34+ * Format: 'asset-filename.png' => 'version/template-name'
35+ *
36+ * @since n.e.x.t
37+ * @var array
38+ */
39+ const EMAIL_ASSET_PATHS = array (
40+ // email-report assets (1.168.0).
41+ 'site-kit-logo.png ' => '1.168.0/email-report ' ,
42+ 'shooting-stars-graphic.png ' => '1.168.0/email-report ' ,
43+ 'icon-conversions.png ' => '1.168.0/email-report ' ,
44+ 'icon-growth.png ' => '1.168.0/email-report ' ,
45+ 'icon-link-arrow.png ' => '1.168.0/email-report ' ,
46+ 'icon-search.png ' => '1.168.0/email-report ' ,
47+ 'icon-views.png ' => '1.168.0/email-report ' ,
48+ 'icon-visitors.png ' => '1.168.0/email-report ' ,
49+ 'conversions-timeline-green.png ' => '1.168.0/email-report ' ,
50+ 'conversions-timeline-red.png ' => '1.168.0/email-report ' ,
51+ 'notification-icon-star.png ' => '1.168.0/email-report ' ,
52+ // invitation-email assets (1.172.0).
53+ 'invitation-envelope-graphic.png ' => '1.172.0/invitation-email ' ,
54+ );
55+
3056 /**
3157 * The sections map instance.
3258 *
3359 * @since 1.168.0
34- * @var Sections_Map
60+ * @var Sections_Map|null
3561 */
3662 protected $ sections_map ;
3763
@@ -57,24 +83,32 @@ class Email_Template_Renderer {
5783 * Constructor.
5884 *
5985 * @since 1.168.0
86+ * @since n.e.x.t Sections map is now optional for templates that don't use sections.
6087 *
61- * @param Sections_Map $sections_map The sections map instance.
88+ * @param Sections_Map|null $sections_map The sections map instance, or null for simple templates .
6289 */
63- public function __construct ( Sections_Map $ sections_map ) {
90+ public function __construct ( Sections_Map $ sections_map = null ) {
6491 $ this ->sections_map = $ sections_map ;
6592 $ this ->templates_dir = realpath ( __DIR__ . '/templates ' );
6693 }
6794
6895 /**
6996 * Gets the full URL for an email asset.
7097 *
98+ * Constructs a URL following the folder structure:
99+ * {base_url}/{version}/{template-name}/{asset-filename}
100+ *
71101 * @since 1.168.0
102+ * @since n.e.x.t Updated to use asset-specific path mapping.
72103 *
73104 * @param string $asset_name The asset filename (e.g., 'icon-conversions.png').
74105 * @return string The full URL to the asset.
75106 */
76107 public function get_email_asset_url ( $ asset_name ) {
77- return self ::EMAIL_ASSETS_BASE_URL . ltrim ( $ asset_name , '/ ' );
108+ $ asset_name = ltrim ( $ asset_name , '/ ' );
109+ $ asset_path = self ::EMAIL_ASSET_PATHS [ $ asset_name ] ?? '1.168.0/email-report ' ;
110+
111+ return self ::EMAIL_ASSETS_BASE_URL . $ asset_path . '/ ' . $ asset_name ;
78112 }
79113
80114 /**
@@ -92,7 +126,7 @@ public function render( $template_name, $data ) {
92126 return '' ;
93127 }
94128
95- $ sections = $ this ->sections_map -> get_sections ();
129+ $ sections = $ this ->sections_map ? $ this -> sections_map -> get_sections () : array ();
96130
97131 $ shared_parts_dir = $ this ->templates_dir . '/parts ' ;
98132 $ template_parts_dir = $ this ->templates_dir . '/ ' . $ template_name . '/parts ' ;
@@ -171,13 +205,20 @@ protected function render_part_file( $file, $vars = array() ) {
171205 * Plain_Text_Formatter for formatting.
172206 *
173207 * @since 1.170.0
208+ * @since n.e.x.t Added support for invitation-email template.
174209 *
175- * @param string $template_name The template name (unused for plain text, kept for API consistency with render()) .
210+ * @param string $template_name The template name.
176211 * @param array $data The data to render (metadata like subject, preheader, etc.).
177212 * @return string The rendered plain text.
178213 */
179214 public function render_text ( $ template_name , $ data ) {
180- $ sections = $ this ->sections_map ->get_sections ();
215+ // Handle invitation email separately.
216+ if ( 'invitation-email ' === $ template_name ) {
217+ return Plain_Text_Formatter::format_invitation_email ( $ data );
218+ }
219+
220+ // Handle email-report template with sections.
221+ $ sections = $ this ->sections_map ? $ this ->sections_map ->get_sections () : array ();
181222
182223 $ output = Plain_Text_Formatter::format_header (
183224 $ data ['site ' ]['domain ' ] ?? '' ,
0 commit comments