Changeset View
Changeset View
Standalone View
Standalone View
externals/pear-figlet/Text/Figlet.php
| Show All 9 Lines | |||||
| * @category Text | * @category Text | ||||
| * @package Text_Figlet | * @package Text_Figlet | ||||
| * @author Evgeny Stepanischev <imbolk@gmail.com> | * @author Evgeny Stepanischev <imbolk@gmail.com> | ||||
| * @author Christian Weiske <cweiske@php.net> | * @author Christian Weiske <cweiske@php.net> | ||||
| * @license http://www.php.net/license PHP License | * @license http://www.php.net/license PHP License | ||||
| * @version CVS: $Id$ | * @version CVS: $Id$ | ||||
| * @link http://pear.php.net/package/Text_Figlet | * @link http://pear.php.net/package/Text_Figlet | ||||
| */ | */ | ||||
| require_once 'PEAR.php'; | |||||
| /** | /** | ||||
| * ASCII art text creation | * ASCII art text creation | ||||
| * | * | ||||
| * Project home page (Russian): http://bolknote.ru/files/figlet/ | * Project home page (Russian): http://bolknote.ru/files/figlet/ | ||||
| * | * | ||||
| * PHP Version 4 | * PHP Version 4 | ||||
| * | * | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | class Text_Figlet | ||||
| * | * | ||||
| * @access public | * @access public | ||||
| * @return mixed PEAR_Error or true for success | * @return mixed PEAR_Error or true for success | ||||
| */ | */ | ||||
| function loadFont($filename, $loadgerman = true) | function loadFont($filename, $loadgerman = true) | ||||
| { | { | ||||
| $this->font = array(); | $this->font = array(); | ||||
| if (!file_exists($filename)) { | if (!file_exists($filename)) { | ||||
| //if it does not exist, try the Text_Figlet data directory | return self::raiseError('Figlet font file "' | ||||
| include_once 'PEAR/Config.php'; | |||||
| $config = PEAR_Config::singleton(); | |||||
| $fontdir = $config->get('data_dir') . '/Text_Figlet/fonts/'; | |||||
| //only for filenames without path separators | |||||
| if (strpos($filename, '/') === false | |||||
| && file_exists($fontdir . $filename) | |||||
| ) { | |||||
| $filename = $fontdir . $filename; | |||||
| } else { | |||||
| return PEAR::raiseError('Figlet font file "' | |||||
| . $filename | . $filename | ||||
| . '" cannot be found', 1); | . '" cannot be found', 1); | ||||
| } | } | ||||
| } | |||||
| $this->font_comment = ''; | $this->font_comment = ''; | ||||
| // If Gzip compressed font | // If Gzip compressed font | ||||
| if (substr($filename, -3, 3) == '.gz') { | if (substr($filename, -3, 3) == '.gz') { | ||||
| $filename = 'compress.zlib://' . $filename; | $filename = 'compress.zlib://' . $filename; | ||||
| $compressed = true; | $compressed = true; | ||||
| if (!function_exists('gzcompress')) { | if (!function_exists('gzcompress')) { | ||||
| return PEAR::raiseError('Cannot load gzip compressed fonts since' | return self::raiseError('Cannot load gzip compressed fonts since' | ||||
| . ' gzcompress() is not available.', | . ' gzcompress() is not available.', | ||||
| 3); | 3); | ||||
| } | } | ||||
| } else { | } else { | ||||
| $compressed = false; | $compressed = false; | ||||
| } | } | ||||
| if (!($fp = fopen($filename, 'rb'))) { | if (!($fp = fopen($filename, 'rb'))) { | ||||
| return PEAR::raiseError('Cannot open figlet font file ' . $filename, 2); | return self::raiseError('Cannot open figlet font file ' . $filename, 2); | ||||
| } | } | ||||
| if (!$compressed) { | if (!$compressed) { | ||||
| /* ZIPed font */ | /* ZIPed font */ | ||||
| if (fread($fp, 2) == 'PK') { | if (fread($fp, 2) == 'PK') { | ||||
| if (!function_exists('zip_open')) { | if (!function_exists('zip_open')) { | ||||
| return PEAR::raiseError('Cannot load ZIP compressed fonts since' | return self::raiseError('Cannot load ZIP compressed fonts since' | ||||
| . ' ZIP PHP extension is not available.', | . ' ZIP PHP extension is not available.', | ||||
| 5); | 5); | ||||
| } | } | ||||
| fclose($fp); | fclose($fp); | ||||
| if (!($fp = zip_open($filename))) { | if (!($fp = zip_open($filename))) { | ||||
| return PEAR::raiseError('Cannot open figlet font file ' . $filename, 2); | return self::raiseError('Cannot open figlet font file ' . $filename, 2); | ||||
| } | } | ||||
| $name = zip_entry_name(zip_read($fp)); | $name = zip_entry_name(zip_read($fp)); | ||||
| zip_close($fp); | zip_close($fp); | ||||
| if (!($fp = fopen('zip://' . realpath($filename) . '#' . $name, 'rb'))) { | if (!($fp = fopen('zip://' . realpath($filename) . '#' . $name, 'rb'))) { | ||||
| return PEAR::raiseError('Cannot open figlet font file ' . $filename, 2); | return self::raiseError('Cannot open figlet font file ' . $filename, 2); | ||||
| } | } | ||||
| $compressed = true; | $compressed = true; | ||||
| } else { | } else { | ||||
| flock($fp, LOCK_SH); | flock($fp, LOCK_SH); | ||||
| rewind($fp); | rewind($fp); | ||||
| } | } | ||||
| } | } | ||||
| // flf2a$ 6 5 20 15 3 0 143 229 | // flf2a$ 6 5 20 15 3 0 143 229 | ||||
| // | | | | | | | | | | | // | | | | | | | | | | | ||||
| // / / | | | | | | | \ | // / / | | | | | | | \ | ||||
| // Signature / / | | | | | \ Codetag_Count | // Signature / / | | | | | \ Codetag_Count | ||||
| // Hardblank / / | | | \ Full_Layout | // Hardblank / / | | | \ Full_Layout | ||||
| // Height / | | \ Print_Direction | // Height / | | \ Print_Direction | ||||
| // Baseline / \ Comment_Lines | // Baseline / \ Comment_Lines | ||||
| // Max_Length Old_Layout | // Max_Length Old_Layout | ||||
| $header = explode(' ', fgets($fp, 2048)); | $header = explode(' ', fgets($fp, 2048)); | ||||
| if (substr($header[0], 0, 5) <> 'flf2a') { | if (substr($header[0], 0, 5) <> 'flf2a') { | ||||
| return PEAR::raiseError('Unknown FIGlet font format.', 4); | return self::raiseError('Unknown FIGlet font format.', 4); | ||||
| } | } | ||||
| @list ($this->hardblank, $this->height,,, | @list ($this->hardblank, $this->height,,, | ||||
| $this->oldlayout, $cmt_count, $this->rtol) = $header; | $this->oldlayout, $cmt_count, $this->rtol) = $header; | ||||
| $this->hardblank = substr($this->hardblank, -1, 1); | $this->hardblank = substr($this->hardblank, -1, 1); | ||||
| for ($i = 0; $i < $cmt_count; $i++) { | for ($i = 0; $i < $cmt_count; $i++) { | ||||
| ▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | function lineEcho($str, $inhtml = false) | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| $trans = array("\0" => '', $this->hardblank => ' '); | $trans = array("\0" => '', $this->hardblank => ' '); | ||||
| $str = strtr(implode("\n", $out), $trans); | $str = strtr(implode("\n", $out), $trans); | ||||
| if ($inhtml) { | if ($inhtml) { | ||||
| return '<nobr>'. | self::raiseError( | ||||
| nl2br(str_replace(' ', ' ', htmlspecialchars($str))). | 'Do not use the HTML escaping provided by this class in '. | ||||
| '</nobr>'; | 'a Phabricator context.'); | ||||
| } | } | ||||
| return $str; | return $str; | ||||
| } | } | ||||
| /** | /** | ||||
| ▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | class Text_Figlet | ||||
| function _skip(&$fp) | function _skip(&$fp) | ||||
| { | { | ||||
| for ($i = 0; $i<$this->height && !feof($fp); $i++) { | for ($i = 0; $i<$this->height && !feof($fp); $i++) { | ||||
| fgets($fp, 2048); | fgets($fp, 2048); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| private static function raiseError($message, $code = 1) { | |||||
| throw new Exception($message); | |||||
| } | |||||
| } | } | ||||
| ?> | |||||