示例#1
0
 function array_handler($data = array(), $skipped = array(), $del = ',')
 {
     foreach ($data as $name => $value) {
         if (is_array($value) and !in_array($name, $skipped)) {
             if ($this->config->get('skip_associative', 1) and \GCore\Libs\Arr::is_assoc($value)) {
                 $value = $this->array_handler($value, $skipped, $del);
                 $data[$name] = $value;
                 continue;
             }
             $value = $this->array_handler($value, $skipped, $del);
             $data[$name] = implode($del, $value);
         }
     }
     return $data;
 }
示例#2
0
 function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     ob_start();
     eval('?>' . $config->get('template', ''));
     $body = ob_get_clean();
     $others = array();
     //get recipient
     $tos = array();
     if (strlen(trim($config->get('to', '')))) {
         $tos = explode(',', \GCore\Libs\Str::replacer(trim($config->get('to', '')), $form->data));
     }
     if (strlen(trim($config->get('dto', '')))) {
         $dtos = explode(',', trim($config->get('dto', '')));
         foreach ($dtos as $dto) {
             $d_email = explode(',', $form->data($dto));
             $tos = array_merge((array) $d_email, $tos);
         }
     }
     $ccs = array();
     if (strlen(trim($config->get('cc', '')))) {
         $ccs = explode(',', \GCore\Libs\Str::replacer(trim($config->get('cc', '')), $form->data));
     }
     if (strlen(trim($config->get('dcc', '')))) {
         $dccs = explode(',', trim($config->get('dcc', '')));
         foreach ($dccs as $dcc) {
             $d_email = explode(',', $form->data($dcc));
             $ccs = array_merge((array) $d_email, $ccs);
         }
     }
     $others['cc'] = $ccs;
     $bccs = array();
     if (strlen(trim($config->get('bcc', '')))) {
         $bccs = explode(',', \GCore\Libs\Str::replacer(trim($config->get('bcc', '')), $form->data));
     }
     if (strlen(trim($config->get('dbcc', '')))) {
         $dbccs = explode(',', trim($config->get('dbcc', '')));
         foreach ($dbccs as $dbcc) {
             $d_email = explode(',', $form->data($dbcc));
             $bccs = array_merge((array) $d_email, $bccs);
         }
     }
     $others['bcc'] = $bccs;
     //subject
     $subject = trim($config->get('subject', '')) ? \GCore\Libs\Str::replacer($config->get('subject', ''), $form->data) : $form->data($config->get('dsubject', ''));
     //from
     $others['from_name'] = trim($config->get('from_name', '')) ? \GCore\Libs\Str::replacer($config->get('from_name', ''), $form->data) : $form->data($config->get('dfrom_name'), null);
     $others['from_email'] = trim($config->get('from_email', '')) ? \GCore\Libs\Str::replacer($config->get('from_email', ''), $form->data) : $form->data($config->get('dfrom_email'), null);
     //reply to
     $others['reply_name'] = trim($config->get('reply_name', '')) ? \GCore\Libs\Str::replacer($config->get('reply_name', ''), $form->data) : $form->data($config->get('dreply_name'), null);
     $others['reply_email'] = trim($config->get('reply_email', '')) ? \GCore\Libs\Str::replacer($config->get('reply_email', ''), $form->data) : $form->data($config->get('dreply_email'), null);
     $others['type'] = $config->get('email_type', 'html');
     $form->data['ip_address'] = $_SERVER['REMOTE_ADDR'];
     if ($others['type'] == 'html') {
         if ($config->get('append_ip_address', 1)) {
             $body = $body . "<br /><br />" . "IP: {ip_address}";
         }
         $body = \GCore\Libs\Str::replacer($body, $form->data, array('replace_null' => true, 'nl2br' => true, 'repeater' => 'repeater'));
     } else {
         if ($config->get('append_ip_address', 1)) {
             $body = $body . "\n\n" . "IP: {ip_address}";
         }
         $body = \GCore\Libs\Str::replacer($body, $form->data, array('replace_null' => true, 'repeater' => 'repeater'));
     }
     //attach
     $attachments = array();
     if (strlen(trim($config->get('attach', '')))) {
         ob_start();
         $attach_fields = eval('?>' . trim($config->get('attach', '')));
         ob_end_clean();
         if (is_array($attach_fields)) {
             $attachs = array_keys($attach_fields);
             foreach ($form->files as $name => $file) {
                 if (in_array($name, $attachs)) {
                     if (\GCore\Libs\Arr::is_assoc($file)) {
                         $attachments[] = array_merge($attach_fields[$name], array('path' => $file['path']));
                     } else {
                         foreach ($file as $fi => $fv) {
                             //$attachments[] = $fv['path'];
                             $attachments[] = array_merge($attach_fields[$name], array('path' => $fv['path']));
                         }
                     }
                 }
             }
         } else {
             $attachs = explode(',', trim($config->get('attach', '')));
             foreach ($form->files as $name => $file) {
                 if (in_array($name, $attachs)) {
                     if (\GCore\Libs\Arr::is_assoc($file)) {
                         $attachments[] = $file['path'];
                     } else {
                         foreach ($file as $fi => $fv) {
                             $attachments[] = $fv['path'];
                         }
                     }
                 }
             }
         }
     }
     //load global settings
     $settings = $form::_settings();
     if (!empty($settings['mail'])) {
         if (!empty($settings['mail']['smtp']) and empty($settings['mail']['mail_method'])) {
             $settings['mail']['mail_method'] = 'smtp';
         }
         foreach ($settings['mail'] as $k => $v) {
             \GCore\Libs\Base::setConfig($k, $v);
         }
     }
     //encrypt the email
     if ($config->get('encrypt_enabled', 0) == 1 and class_exists('Crypt_GPG')) {
         $mySecretKeyId = trim($config->get('gpg_sec_key', ''));
         //Add Encryption key here
         $gpg = new Crypt_GPG();
         $gpg->addEncryptKey($mySecretKeyId);
         $body = $gpg->encrypt($body);
     }
     $sent = \GCore\Libs\Mailer::send($tos, $subject, $body, $attachments, $others);
     if ($sent) {
         $form->debug[$action_id][self::$title][] = "An email with the details below was sent successfully:";
     } else {
         $form->debug[$action_id][self::$title][] = "An email with the details below could NOT be sent:";
     }
     $form->debug[$action_id][self::$title][] = "To:" . implode(", ", $tos);
     $form->debug[$action_id][self::$title][] = "Subject:" . $subject;
     $form->debug[$action_id][self::$title][] = "From name:" . $others['from_name'];
     $form->debug[$action_id][self::$title][] = "From email:" . $others['from_email'];
     $form->debug[$action_id][self::$title][] = "CC:" . implode(", ", $ccs);
     $form->debug[$action_id][self::$title][] = "BCC:" . implode(", ", $bccs);
     $form->debug[$action_id][self::$title][] = "Reply name:" . $others['reply_name'];
     $form->debug[$action_id][self::$title][] = "Reply email:" . $others['reply_email'];
     $form->debug[$action_id][self::$title][] = "Attachments:";
     $form->debug[$action_id][self::$title][] = $attachments;
     $form->debug[$action_id][self::$title][] = "Body:\n" . $body;
 }