PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.3.2
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.3.2
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / includes / Traits / TemplateTrait.php

TemplateTrait.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.3.2, at includes/Traits/TemplateTrait.php

61 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Template Trait
4 *
5 * @package Easy_Invoice
6 * @subpackage Traits
7 */
8
9 namespace EasyInvoice\Traits;
10
11 use EasyInvoice\Controllers\SettingsController;
12
13 /**
14 * TemplateTrait contains methods for template handling
15 */
16 trait TemplateTrait {
17 /**
18 * Get common template variables
19 *
20 * @return array Common template variables
21 */
22 protected function getCommonTemplateVars() {
23 $settings_controller = new SettingsController();
24 $settings = $settings_controller->getSettings();
25
26 // Ensure settings is an array and has default values
27 if (!is_array($settings)) {
28 $settings = [];
29 }
30
31 return [
32 'company' => $settings['company'] ?? '',
33 'currency_symbol' => isset($settings['currency']['symbol']) ? $settings['currency']['symbol'] : '$',
34 'currency_position' => isset($settings['currency']['position']) ? $settings['currency']['position'] : 'left',
35 ];
36 }
37
38 /**
39 * Display a template with given variables
40 *
41 * @param string $template_path Path to the template file
42 * @param array $vars Variables to extract for the template
43 * @return void
44 */
45 protected function displayTemplate($template_path, $vars = []) {
46 // Add common template variables if not already provided
47 if (!isset($vars['template_vars'])) {
48 $vars['template_vars'] = $this->getCommonTemplateVars();
49 }
50
51 // Extract variables for use in the template
52 extract($vars);
53
54 // Include the template file
55 if (file_exists($template_path)) {
56 include $template_path;
57 } else {
58 wp_die(sprintf(__('Template file not found: %s', 'easy-invoice'), $template_path));
59 }
60 }
61 }