Пример #1
0
 /**
  * Tests RW_Debug::sendError()
  */
 public function testSendError()
 {
     $error = RW_Debug::sendError('Teste', 404);
     $this->assertEquals('Página não encontrada', $error);
     $error = RW_Debug::sendError('Teste', 500);
     $this->assertEquals('Erro encontrado no site', $error);
 }
Пример #2
0
 /**
  * Enviar um feedback de acordo com as configurações do arquivo .INI
  *  - O arquivo deve estar na pasta /configs
  *  - O nome do arquivo deve ser feedback.ARQUIVO.ini
  *
  * @todo colocar valores padrões para limpar o INI e previnir possiveis erros
  * @todo verificar SPAM
  * @todo colocar em uma classe separada
  *
  * @param array 	$post campos do formulário
  * @param string	$config arquivo ini com as configurações
  *
  * @uses   Zend_Config_Ini
  * @throws RW_Exception
  * @see    RW_Exception
  */
 public function sendFeedback($post, $configfile)
 {
     $configpath = realpath(APPLICATION_PATH . "/../configs/feedback.{$configfile}.ini");
     if (!file_exists($configpath)) {
         // Tenta outro diretório
         $configpath = realpath(APPLICATION_PATH . "/configs/feedback.{$configfile}.ini");
     }
     if (!file_exists($configpath)) {
         throw new Exception("Arquivo de configuração '{$configfile}' não encontrado do diretório /configs");
     }
     $config = new Zend_Config_Ini($configpath, APPLICATION_ENV);
     $config = $config->toArray();
     $opts = array();
     // arruma os destinatarios
     foreach ($config['destinatarios'] as $id => $campo) {
         $c = explode(':', $campo);
         if (count($c) == 1) {
             $config['destinatarios'][$c[0]] = null;
         } elseif (count($c) == 2) {
             $config['destinatarios'][$c[1]] = $c[0];
         }
         unset($config['destinatarios'][$id]);
     }
     // arruma os campos
     foreach ($config['campos'] as $id => $campo) {
         $c = explode(':', $campo);
         if (count($c) == 1) {
             $config['campos'][$c[0]] = $c[0];
         } elseif (count($c) == 2) {
             $config['campos'][$c[0]] = $c[1];
         }
         unset($config['campos'][$id]);
     }
     // Verifica se há variáveis no titulo
     if (strpos($config['titulo'], '$') !== false) {
         foreach ($post as $c => $v) {
             $config['titulo'] = str_replace('$' . $c, $v, $config['titulo']);
         }
     }
     // Verifica se vai usar um modelo
     if (isset($config['modelo'])) {
         $view = new Zend_View();
         $view->setScriptPath(APPLICATION_PATH . '/views/scripts');
         $html = $emailCliente = $view->partial('/_modelos/feedback/' . $config['modelo'] . '.phtml', array('valores' => $post, 'config' => $config));
         $text = $this->_extractText($html);
     } else {
         // Cria o HTML para enviar no email
         $html = '<table>';
         $text = '';
         foreach ($config['campos'] as $campo => $nome) {
             if (isset($post[$campo]) && $post[$campo] != '' || $config['mostraVazios'] == 1) {
                 $text .= "{$nome}: " . (isset($post[$campo]) ? $post[$campo] : '') . "\n";
                 $html .= '<tr>';
                 $html .= '<td align="right" valign="top"><font face="verdana" size="2">' . $nome . '</font></td>';
                 $html .= '<td></td>';
                 $html .= '<td valign="top"><font face="verdana" size="2">' . (isset($post[$campo]) ? $post[$campo] : '') . '</font></td>';
                 $html .= '</tr>';
             }
         }
         $html .= "</table>";
     }
     // Coloca a assinatura
     if (isset($text) && $text != '') {
         $text .= "\n\n";
         $text .= 'Realejo Feedback v1.0' . "\n";
         $text .= 'Este e-mail foi gerado automaticamente em ' . date("d/m/y H:m:s") . "\n";
         $text .= '(C)2010, Realejo (http://www.realejo.com.br)' . "\n";
     }
     if (isset($html) && $html != '') {
         $html .= '<p>&nbsp;</p><center>';
         $html .= '<table width=95% cellspacing=0 cellpadding=0>';
         $html .= '<tr><td align="right" colspan="2"><font face="verdana" size="1">Este e-mail foi gerado automaticamente em ' . date("d/m/y H:m:s") . '.</font></td></tr>';
         $html .= '<tr bgcolor="#6E6E6E"><td height="1" colspan="2"></td></tr>';
         $html .= '<tr>';
         $html .= '<td><font size="1" face="verdana">Realejo Feedback v1.0</font></td>';
         $html .= '<td align=right>';
         $html .= '<font size="1" face="verdana">&copy; 2010, <a href="http://www.realejo.com.br"><font color="black">Realejo</font></a></font>';
         $html .= '</td></tr>';
         $html .= '</table></center>';
     }
     if ($config['verificar'] == 1 && APPLICATION_ENV != 'production') {
         echo "<h1>Verificação do Feedback</h1>";
         echo "<p>veja abaixo as configurações e o email enviado</p>";
         echo "<h2>Configuração feedback.{$configfile}.ini</h2>";
         RW_Debug::dump($config, '$config');
         echo "<hr/>";
         RW_Debug::dump($post, '$post');
         echo "<hr/>";
         echo "<h2>HTML</h2>{$html} <hr>";
         echo "<h2>TEXTO</h2><pre>{$text}</pre><hr>";
     }
     if ($config['destinatarios_unir'] == 1) {
         // verifica se tem cópia oculta
         if (isset($config['bcc']) && $config['bcc'] != '') {
             $opts['bcc'] = $config['bcc'];
         }
         $this->SendEmail($post[$config['nome']], $post[$config['email']], null, $config['destinatarios'], $config['titulo'], array('html' => $html, 'text' => $text), $opts);
     } else {
         foreach ($config['destinatarios'] as $email => $nome) {
             $this->SendEmail($post[$config['nome']], $post[$config['email']], $nome, $email, $config['titulo'], array('html' => $html, 'text' => $text));
         }
         // verifica se tem cópia oculta
         // @todo permitir que tenha nome no bcc
         // @todo informar que recebeu os emails
         if (isset($config['bcc']) && $config['bcc'] != '') {
             $this->SendEmail($post[$config['nome']], $post[$config['email']], $config['bcc'], $config['bcc'], $config['titulo'], array('html' => $html, 'text' => $text));
         }
     }
     if ($config['verificar'] == 1 && APPLICATION_ENV != 'production') {
         die('<hr/>email enviado');
     }
 }