Skip to content

Commit

Permalink
Request by PHPMailer#612
Browse files Browse the repository at this point in the history
  • Loading branch information
elminson committed Mar 8, 2016
1 parent f0b2877 commit 325844b
Show file tree
Hide file tree
Showing 20 changed files with 25,215 additions and 0 deletions.
2,494 changes: 2,494 additions & 0 deletions .fonts/banner.flf

Large diffs are not rendered by default.

2,204 changes: 2,204 additions & 0 deletions .fonts/big.flf

Large diffs are not rendered by default.

1,691 changes: 1,691 additions & 0 deletions .fonts/block.flf

Large diffs are not rendered by default.

1,630 changes: 1,630 additions & 0 deletions .fonts/bubble.flf

Large diffs are not rendered by default.

1,286 changes: 1,286 additions & 0 deletions .fonts/digital.flf

Large diffs are not rendered by default.

900 changes: 900 additions & 0 deletions .fonts/ivrit.flf

Large diffs are not rendered by default.

1,691 changes: 1,691 additions & 0 deletions .fonts/lean.flf

Large diffs are not rendered by default.

899 changes: 899 additions & 0 deletions .fonts/mini.flf

Large diffs are not rendered by default.

1,493 changes: 1,493 additions & 0 deletions .fonts/script.flf

Large diffs are not rendered by default.

1,097 changes: 1,097 additions & 0 deletions .fonts/shadow.flf

Large diffs are not rendered by default.

1,295 changes: 1,295 additions & 0 deletions .fonts/slant.flf

Large diffs are not rendered by default.

1,097 changes: 1,097 additions & 0 deletions .fonts/small.flf

Large diffs are not rendered by default.

1,097 changes: 1,097 additions & 0 deletions .fonts/smscript.flf

Large diffs are not rendered by default.

899 changes: 899 additions & 0 deletions .fonts/smshadow.flf

Large diffs are not rendered by default.

1,097 changes: 1,097 additions & 0 deletions .fonts/smslant.flf

Large diffs are not rendered by default.

1,301 changes: 1,301 additions & 0 deletions .fonts/speed.flf

Large diffs are not rendered by default.

2,227 changes: 2,227 additions & 0 deletions .fonts/standard.flf

Large diffs are not rendered by default.

600 changes: 600 additions & 0 deletions .fonts/term.flf

Large diffs are not rendered by default.

184 changes: 184 additions & 0 deletions class.figlet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?php

class Figlet
{
protected $_currentFont;
protected $_fontFile;
protected $_signature;
protected $_hardblank;
protected $_height;
protected $_baseline;
protected $_maxWidth;
protected $_defaultSmush;
protected $_commentLines;
protected $_rightToLeft;
protected $_fontSmush;
protected $_loaded = false;
protected $_defaultFont;

/**
* @param null $loadFont
* @param string $defaultFont
*/
public function __construct($loadFont = null, $defaultFont = 'standard')
{
$this->_defaultFont = $defaultFont;
$this->_currentFont = $defaultFont;

if($loadFont !== null)
{
$this->loadFont($loadFont);
}
}

/**
* @return bool
*/
public function isFontLoaded()
{
return (bool)$this->_loaded;
}

/**
* @return string current loaded font
*/
public function currentFont()
{
return $this->_currentFont;
}

/**
* Load a font which has been bundled with this package (found in .fonts)
*
* @param $name
* @param null $fontDir
* @param string $ext
*/
public function loadFont($name, $fontDir = null, $ext = '.flf')
{
if($fontDir === null)
{
$fontDir = __DIR__ . DIRECTORY_SEPARATOR . '.fonts' . DIRECTORY_SEPARATOR;
}
$this->_currentFont = $name;
$this->loadFontFromPath($fontDir . $name . $ext, false);
}

/**
* Load a custom figlet font
*
* @param $fontFile string full path to figlet font file
* @param $setCurrent bool to set the current font to the full path
*
* @throws \Exception
*/
public function loadFontFromPath($fontFile, $setCurrent = true)
{
$this->_loaded = false;
if(!file_exists($fontFile))
{
throw new \Exception(
"Could not load figlet font '" .
($setCurrent ? $fontFile : $this->_currentFont) . "'",
404
);
}

$this->_fontFile = file($fontFile);

$definitions = sscanf(
$this->_fontFile[0],
'%5s%c %d %*d %d %d %d %d %d',
$this->_signature,
$this->_hardblank,
$this->_height,
$this->_maxWidth,
$this->_defaultSmush,
$this->_commentLines,
$this->_rightToLeft,
$this->_fontSmush
);

if($this->_signature != "flf2a" || $definitions < 5)
{
throw new \Exception("Invalid figlet font file provided", 500);
}

if($setCurrent)
{
$this->_currentFont = $fontFile;
}

$this->_loaded = true;
}

/**
* Get a single character from the loaded font
*
* @param $character
*
* @return array
*/
public function getCharacter($character)
{
if(!$this->_loaded)
{
$this->loadFont($this->_defaultFont);
}

$final = array();
$offset = ((ord($character) - 32) * $this->_height);
$startLine = $this->_commentLines + 1 + $offset;
$lines = array_slice($this->_fontFile, $startLine, $this->_height);
foreach($lines as $line)
{
$final[] = str_replace(
array('@', $this->_hardblank, "\n"),
array('', ' ', ''),
$line
);
}
return $final;
}

/**
* Create a figlet string
*
* @param $string string text to generate
*
* @return string output content with new lines
*/
public function render($string)
{
$out = "";
$characters = str_split($string);
$chars = array();
foreach($characters as $char)
{
$chars[] = $this->getCharacter($char);
}
for($line = 0; $line < $this->_height; $line++)
{
foreach($chars as $charLines)
{
$out .= $charLines[$line];
}
$out .= "\n";
}
return $out;
}

/**
* Create a figlet output string
*
* @param $string
* @param null $font
*
* @return string
*/
public static function create($string, $font = null)
{
$figlet = new Figlet($font);
return $figlet->render($string);
}
}
33 changes: 33 additions & 0 deletions class.phpmailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,19 @@ class PHPMailer
*/
const MAX_LINE_LENGTH = 998;

/**
* diagnose Variable to set Diagnose.
* @var boolean
*/
public $diagnose = false;

/**
* An instance of the Figlet class.
* @var $Figlet
* @access protected
*/
protected $Figlet = null;

/**
* Constructor.
* @param boolean $exceptions Should we throw external exceptions?
Expand Down Expand Up @@ -3144,6 +3157,15 @@ protected function setError($msg)
}
}
}

if($this->diagnose){
if (!is_object($this->Figlet)) {
$figlet = new Figlet;
}
$msg=$figlet->create($msg);
$msg="<pre>".$msg;
}

$this->ErrorInfo = $msg;
}

Expand Down Expand Up @@ -3873,6 +3895,17 @@ protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from)
call_user_func_array($this->action_function, $params);
}
}

/**
* Set the Diagnose property.
* @param boolean $value
* @return boolean
*/
public function setDiagnose($value = false)
{
$this->diagnose=$value;
return $this->diagnose;
}
}

/**
Expand Down

0 comments on commit 325844b

Please sign in to comment.