1: <?php
2:
3: /**
4: * NUX modules
5: * @package modules
6: * @subpackage nux
7: */
8:
9: if (!defined('DEBUG_MODE')) { die(); }
10:
11: /**
12: * Build a source list for sent folders
13: * @subpackage nux/functions
14: * @param string $file_path file path
15: * @param string $delimiter csv delimiter with default ;
16: * @return array
17: */
18: if (!hm_exists('parse_csv_with_headers')) {
19: function parse_csv_with_headers($file_path, $delimiter = ';') {
20: // Open the file
21: $file = new SplFileObject($file_path);
22: // Set the file to read as CSV
23: $file->setFlags(SplFileObject::DROP_NEW_LINE);
24:
25: // Initialize an array to hold the rows
26: $rows = [];
27: $is_first_line = true;
28: $header = [];
29: // Loop through each line in the CSV file
30: while (!$file->eof()) {
31: // Get the line as a string
32: $line = $file->fgets();
33:
34: // Skip empty lines (e.g., due to trailing newlines)
35: if ($line === [null] || $line === false) {
36: continue;
37: }
38:
39: // Split the line into an array using the specified delimiter
40: $fields = explode($delimiter, $line);
41: // Process the header line
42: if ($is_first_line) {
43: $header = $fields;
44: $is_first_line = false;
45: } else {
46: // Ensure that the number of fields matches the header count
47: if (count($fields) === count($header)) {
48: // Combine the header and fields into an associative array
49: $line_data = array_combine($header, $fields);
50: foreach ($line_data as $key => $value) {
51: $line_data[$key] = convert_to_boolean($value);
52: }
53: $rows[] = $line_data;
54: }
55: }
56: }
57: return $rows;
58: }}
59:
60: if (!hm_exists('convert_to_boolean')) {
61: function convert_to_boolean($value) {
62: if (in_array($value, ['true', '1', 'yes'])) {
63: return true;
64: } elseif (in_array($value, ['false', '0', 'no'])) {
65: return false;
66: }
67: return $value;
68: }}
69:
70: /**
71: * @subpackage nux/functions
72: */
73: if (!hm_exists('oauth2_form')) {
74: function oauth2_form($details, $mod)
75: {
76: $oauth2 = new Hm_Oauth2($details['client_id'], $details['client_secret'], $details['redirect_uri']);
77: $url = $oauth2->request_authorization_url($details['auth_uri'], $details['scope'], 'nux_authorization', $details['email']);
78: $res = '<input type="hidden" name="nux_service" value="' . $mod->html_safe($details['id']) . '" />';
79: $res .= '<div class="nux_step_two_title fw-bold">' . $mod->html_safe($details['name']) . '</div><div class="mb-3">';
80: $res .= $mod->trans('This provider supports Oauth2 access to your account.');
81: $res .= $mod->trans(' This is the most secure way to access your E-mail. Click "Enable" to be redirected to the provider site to allow access.');
82: $res .= '</div><div class="mb-3"><a class="enable_auth2 btn btn-sm btn-success me-2" data-external="true" href="' . $url . '">' . $mod->trans('Enable') . '</a>';
83: $res .= '<a href="" class="reset_nux_form btn btn-sm btn-secondary">Reset</a></div>';
84: return $res;
85: }
86: }
87:
88: /**
89: * @subpackage nux/functions
90: */
91: if (!hm_exists('credentials_form')) {
92: function credentials_form($details, $mod)
93: {
94: $res = '<input type="hidden" id="nux_service" name="nux_service" value="' . $mod->html_safe($details['id']) . '" />';
95: $res .= '<input type="hidden" name="nux_name" class="nux_name" value="' . $mod->html_safe($details['name']) . '" />';
96: $res .= '<div class="nux_step_two_title"><b>' . $mod->html_safe($details['name']) . '</b></div>';
97: $res .= $mod->trans('Enter your password for this E-mail provider to complete the connection process');
98:
99: $res .= '<div class="row"><div class="col col-lg-4">';
100: // E-mail Address Field
101: $res .= '<div class="form-floating mb-3 mt-3">';
102: $res .= '<input type="email" class="form-control" id="nux_email" name="nux_email" placeholder="' . $mod->trans('E-mail Address') . '" value="' . $mod->html_safe($details['email']) . '">';
103: $res .= '<label for="nux_email">' . $mod->trans('E-mail Address') . '</label></div>';
104:
105: // E-mail Password Field
106: $res .= '<div class="form-floating mb-3">';
107: $res .= '<input type="password" class="form-control nux_password" id="nux_password" name="nux_password" placeholder="' . $mod->trans('E-Mail Password') . '">';
108: $res .= '<label for="nux_password">' . $mod->trans('E-mail Password') . '</label></div>';
109: $res .= '<div class="d-flex flex-md-row gap-3 mt-3">';
110: // Connect Button
111: $res .= '<input type="button" class="nux_submit px-5 btn btn-primary w-100 w-md-auto" value="' . $mod->trans('Connect') . '">';
112:
113: // Reset Link
114: $res .= '<a href="" class="reset_nux_form px-5 btn btn-secondary w-100 w-md-auto">Reset</a>';
115:
116: $res .= '</div></div></div>';
117:
118: return $res;
119: }
120: }
121:
122: /**
123: * @subpackage nux/functions
124: */
125: if (!hm_exists('data_source_available')) {
126: function data_source_available($mods, $types)
127: {
128: if (!is_array($types)) {
129: $types = array($types);
130: }
131: return count(array_intersect($types, $mods)) == count($types);
132: }
133: }
134: