public function init(array $options = []) { $this->default = array_merge($this->default, Configure::read('auth.' . $this->config)); $this->default = Hash::merge($this->default, $options); $table = '\\App\\Model\\Table\\' . $this->default['model'] . 'Table'; $this->model = new $table(); $this->keyName = $this->default['keyName']; }
/** * * Adiciona um helper * * @param string|array $class */ public function addHerper($class) { $default = ['nome' => '', 'class' => '']; if (!is_array($class)) { $class = ['nome' => $class, 'class' => '']; } $class = \Core\Hash::merge($default, $class); $class['nome'] = Inflector::camelize(Inflector::underscore($class['nome'])); $class['class'] = Inflector::camelize(Inflector::underscore(str_replace('Helper', '', $class['class']))) . 'Helper'; self::$_helpers[$class['nome']] = $class; }
/** * * função que converte a data passada * * @param string $data * @param string $separador * @param string $include * @return string */ public function money($str, $options = [], $float = false) { if (trim($str) != '') { if (stripos($str, ',') !== false) { $str = str_replace('R$', '', $str); $str = str_replace('.', '', $str); $return = (double) str_replace(',', '.', $str); } else { if (!$float) { $defautl = ['prefix' => 'R$ ']; $options = \Core\Hash::merge($defautl, $options); $return = (string) $options['prefix'] . number_format($str, 2, ',', '.'); } else { $return = (double) $str; } } return $return; } return null; }
/** * * Cria um botão * * @param string $name * @param array $options * @return string */ public function button($name, $options = []) { $default = ['form' => $this->id, 'id' => $this->getId($name, 'Button'), 'type' => 'submit', 'class' => '']; $options = \Core\Hash::merge($default, $options); return $this->html->tags('button', $options, true, $name); }
/** * * Inicia a criação do formulario * * @param string $url * @param array $options * @return string */ public function init($options = []) { $this->options = \Core\Hash::merge($this->options, $options); }
/** * * Cria um link * * @param string $label * @param string $url * @param array $options * @return string */ public function link($label, $url, $options = []) { if (is_array($url)) { $defautl = ['action' => $this->request->action, 'controller' => $this->request->controller, 'path' => $this->request->path]; $url = array_merge($defautl, $url); } $default = ['href' => $this->url($url)]; if (isset($options['icon']) and $options['icon'] !== false) { $label = $this->icon($options['icon']) . $label; unset($options['icon']); } return $this->tags('a', \Core\Hash::merge($default, $options), true, $label); }
/** * * função que faz um pre tratamento no banco de dados. * * @param array $dados * @param string $coluna * @return array */ private function setData($dados, $coluna) { $newDados = []; $coluns = $this->schema()->columns(); if (count($coluns) > 0) { foreach ($coluns as $key => $value) { if (array_key_exists($key, $dados)) { $newDados[$key] = $dados[$key]; } if ($key === $coluna) { $newDados[$key] = date('Y-m-d H:i:s'); } } } $dados = \Core\Hash::merge($dados, $newDados); $this->data = $dados; return $newDados; }
public function hasMany($class, array $options = []) { if (!empty($this->contain[$class])) { $defautl = ['className' => '', 'foreignKey' => '', 'from' => '*', 'where' => [], 'order' => [], 'group' => []]; $options = \Core\Hash::merge($defautl, $options); if (empty($options['className'])) { $options['className'] = $class; } $table = $this->loadModel($options['className']); $table->where($table->primary_key, $this->{$options['foreignKey']}); if (is_array($this->contain[$class])) { $extra = $this->contain[$class]; if (!empty($extra['contain'])) { $table->contain($extra['contain']); unset($extra['contain']); } //debug($extra); //exit; $options = \Core\Hash::merge($options, $extra); } $this->{$class} = $table->all($options); unset($this->contain[$class]); return $this; } }
/** * Le dados que estão na sessão * * @param string $key * @param mixed $default * @return mixed */ public function delete($key) { $key = trim($key, '.'); $_SESSION = Hash::insert($_SESSION, $key, null); return true; }
public function setQuery($dados) { $dados = (array) $dados; //$this->query = Hash::merge($this->query, json_decode(json_encode($dados), true)); $this->query = Hash::merge($this->query, $dados); $_GET = Hash::merge($_GET, $this->query); }
public function processa(array $options = []) { $defautl = ['where' => [], 'order' => [], 'group' => [], 'from' => []]; $options = \Core\Hash::merge($defautl, $options); if (!empty($options['where'])) { foreach ($options['where'] as $key => $value) { switch (count($value)) { case 4: $this->where($value[0], $value[1], $value[2], $value[3]); break; case 3: $this->where($value[0], $value[1], $value[2]); break; default: $this->where($value[0], $value[1]); break; } } } if (!empty($options['order'])) { foreach ($options['order'] as $key => $value) { switch (count($value)) { case 2: $this->order($value[0], $value[1]); break; default: $this->order($value[0]); break; } } } if (!empty($options['group'])) { foreach ($options['group'] as $key => $value) { switch (count($value)) { case 2: $this->group($value[0], $value[1]); break; default: $this->group($value[0]); break; } } } if (!empty($options['from'])) { if (!is_array($options['from'])) { $options['from'] = explode(', ', $options['from']); } $this->from($options['from']); } return $this; }
public function send($options, $type = 'default') { Configure::load('mail'); $config = Configure::read('mail'); if (!empty(Configure::read('Parametros.Email'))) { $config = array_merge($config, Configure::read('Parametros.Email')); } $config = $config[$type]; $mail = new PHPMailer((bool) Configure::read('app.debug')); $mail->SMTPDebug = (int) $config['Debug']; $mail->isSMTP(); $mail->Host = $config['Host']; $mail->SMTPAuth = (bool) $config['Auth']; $mail->Username = $config['Username']; $mail->Password = $config['Password']; $mail->SMTPAutoTLS = false; if ($config['AutoTls'] > 0) { $mail->SMTPSecure = $config['Secure']; $mail->SMTPAutoTLS = true; } $mail->Port = (int) $config['Port']; $mail->CharSet = $config['Charset']; //$mail->isSMTP(); // Set mailer to use SMTP //$mail->Host = 'smtp.appettosa.com.br'; // Specify main and backup server //$mail->SMTPAuth = true; // Enable SMTP authentication //$mail->Port = 587; //$mail->Username = '******'; // SMTP username //$mail->Password = '******'; // SMTP password //$mail->From = ('*****@*****.**'); //$mail->FromName = $_POST['nome']; $default = ['from' => ['mail' => '', 'title' => ''], 'add' => [], 'replyto' => [], 'cc' => [], 'bcc' => [], 'file' => [], 'html' => true, 'title' => '', 'data' => [], 'alt' => '', 'layout' => 'default', 'view' => 'default']; $options = Hash::merge($default, $options); $options['add'] = Hash::merge([-1 => [$options['from']['mail'] => $options['from']['title']]], $options['add']); $mail->setFrom($config['Username'], $config['Name']); if (count($options['add'])) { foreach ($options['add'] as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $mail->addAddress($k, $v); } } else { $mail->addAddress($value); } } } if (count($options['replyto'])) { foreach ($options['replyto'] as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $mail->addReplyTo($k, $v); } } else { $mail->addReplyTo($value); } } } if (count($options['cc'])) { foreach ($options['cc'] as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $mail->addCC($k, $v); } } else { $mail->addCC($value); } } } if (count($options['bcc'])) { foreach ($options['bcc'] as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $mail->addBCC($k, $v); } } else { $mail->addBCC($value); } } } if (count($options['file'])) { foreach ($options['file'] as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $mail->addAttachment($k, $v); } } else { $mail->addAttachment($value); } } } $mail->isHTML($options['html']); $this->data = $options['data']; //debug($this->data); $this->data['title'] = $options['title']; $this->loads(); $this->render($options['view']); $options['body'] = $this->renderlayout($options['layout']); $mail->Subject = $options['title']; $mail->Body = $options['body']; $mail->AltBody = $options['alt']; try { if (!$mail->send()) { return false; } else { return true; } } catch (\Exception $exception) { $this->error = $exception; $ex = new \Core\MyException(); $ex->show_exception($exception); return false; } }
public function inputStatic($value = '', $label = '', $options = []) { $default = ['class' => 'form-group']; $options = \Core\Hash::merge($default, $options); return $this->html->tags('div', $options, true, '<label class="control-label">' . $label . '</label><div class="col-xs-12"><p class="form-control-static">' . $value . '</p></div>'); }
/** * Prepare a message for sending. * @throws Exception * @return boolean */ public function preSend() { try { $this->error_count = 0; // Reset errors $this->mailHeader = ''; // Dequeue recipient and Reply-To addresses with IDN foreach (\Core\Hash::merge($this->RecipientsQueue, $this->ReplyToQueue) as $params) { $params[1] = $this->punyencodeAddress($params[1]); call_user_func_array([$this, 'addAnAddress'], $params); } if (count($this->to) + count($this->cc) + count($this->bcc) < 1) { throw new \Exception($this->lang('provide_address'), self::STOP_CRITICAL); } // Validate From, Sender, and ConfirmReadingTo addresses foreach (['From', 'Sender', 'ConfirmReadingTo'] as $address_kind) { $this->{$address_kind} = trim($this->{$address_kind}); if (empty($this->{$address_kind})) { continue; } $this->{$address_kind} = $this->punyencodeAddress($this->{$address_kind}); if (!$this->validateAddress($this->{$address_kind})) { $error_message = $this->lang('invalid_address') . ' (punyEncode) ' . $this->{$address_kind}; $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { throw new \Exception($error_message); } return false; } } // Set whether the message is multipart/alternative if ($this->alternativeExists()) { $this->ContentType = 'multipart/alternative'; } $this->setMessageType(); // Refuse to send an empty message unless we are specifically allowing it if (!$this->AllowEmpty and empty($this->Body)) { throw new \Exception($this->lang('empty_message'), self::STOP_CRITICAL); } // Create body before headers in case body makes changes to headers (e.g. altering transfer encoding) $this->MIMEHeader = ''; $this->MIMEBody = $this->createBody(); // createBody may have added some headers, so retain them $tempheaders = $this->MIMEHeader; $this->MIMEHeader = $this->createHeader(); $this->MIMEHeader .= $tempheaders; // To capture the complete message when using mail(), create // an extra header list which createHeader() doesn't fold in if ($this->Mailer == 'mail') { if (count($this->to) > 0) { $this->mailHeader .= $this->addrAppend('To', $this->to); } else { $this->mailHeader .= $this->headerLine('To', 'undisclosed-recipients:;'); } $this->mailHeader .= $this->headerLine('Subject', $this->encodeHeader($this->secureHeader(trim($this->Subject)))); } // Sign with DKIM if enabled if (!empty($this->DKIM_domain) && !empty($this->DKIM_private) && !empty($this->DKIM_selector) && file_exists($this->DKIM_private)) { $header_dkim = $this->DKIM_Add($this->MIMEHeader . $this->mailHeader, $this->encodeHeader($this->secureHeader($this->Subject)), $this->MIMEBody); $this->MIMEHeader = rtrim($this->MIMEHeader, "\r\n ") . self::CRLF . str_replace("\r\n", "\n", $header_dkim) . self::CRLF; } return true; } catch (\Exception $exception) { $this->setError($exception->getMessage()); if ($this->exceptions) { throw $exception; } $ex = new \Core\MyException(); $ex->show_exception($exception); return false; } }
public function init(array $config = []) { $this->default = \Core\Hash::merge($this->default, $config); }