Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14012852
D14102.id34087.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D14102.id34087.diff
View Options
diff --git a/externals/pear-figlet/Text/Figlet.php b/externals/pear-figlet/Text/Figlet.php
--- a/externals/pear-figlet/Text/Figlet.php
+++ b/externals/pear-figlet/Text/Figlet.php
@@ -15,7 +15,6 @@
* @version CVS: $Id$
* @link http://pear.php.net/package/Text_Figlet
*/
-require_once 'PEAR.php';
/**
* ASCII art text creation
@@ -113,22 +112,9 @@
{
$this->font = array();
if (!file_exists($filename)) {
- //if it does not exist, try the Text_Figlet data directory
- 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
- . '" cannot be found', 1);
- }
+ return self::raiseError('Figlet font file "'
+ . $filename
+ . '" cannot be found', 1);
}
$this->font_comment = '';
@@ -139,7 +125,7 @@
$compressed = true;
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.',
3);
}
@@ -148,14 +134,14 @@
}
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) {
/* ZIPed font */
if (fread($fp, 2) == 'PK') {
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.',
5);
}
@@ -163,14 +149,14 @@
fclose($fp);
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));
zip_close($fp);
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;
@@ -193,7 +179,7 @@
$header = explode(' ', fgets($fp, 2048));
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,,,
@@ -381,9 +367,9 @@
$str = strtr(implode("\n", $out), $trans);
if ($inhtml) {
- return '<nobr>'.
- nl2br(str_replace(' ', ' ', htmlspecialchars($str))).
- '</nobr>';
+ self::raiseError(
+ 'Do not use the HTML escaping provided by this class in '.
+ 'a Phabricator context.');
}
return $str;
@@ -506,5 +492,9 @@
return true;
}
+
+
+ private static function raiseError($message, $code = 1) {
+ throw new Exception($message);
+ }
}
-?>
diff --git a/src/infrastructure/markup/interpreter/PhabricatorRemarkupFigletBlockInterpreter.php b/src/infrastructure/markup/interpreter/PhabricatorRemarkupFigletBlockInterpreter.php
--- a/src/infrastructure/markup/interpreter/PhabricatorRemarkupFigletBlockInterpreter.php
+++ b/src/infrastructure/markup/interpreter/PhabricatorRemarkupFigletBlockInterpreter.php
@@ -7,33 +7,28 @@
return 'figlet';
}
+ /**
+ * @phutil-external-symbol class Text_Figlet
+ */
public function markupContent($content, array $argv) {
- if (!Filesystem::binaryExists('figlet')) {
- return $this->markupError(
- pht(
- 'Unable to locate the `%s` binary. Install figlet.',
- 'figlet'));
- }
+ $map = self::getFigletMap();
- $font = idx($argv, 'font', 'standard');
- $safe_font = preg_replace('/[^0-9a-zA-Z-_.]/', '', $font);
- $future = id(new ExecFuture('figlet -f %s', $safe_font))
- ->setTimeout(15)
- ->write(trim($content, "\n"));
+ $font = idx($argv, 'font');
+ $font = phutil_utf8_strtolower($font);
+ if (empty($map[$font])) {
+ $font = 'standard';
+ }
- list($err, $stdout, $stderr) = $future->resolve();
+ $root = dirname(phutil_get_library_root('phabricator'));
+ require_once $root.'/externals/pear-figlet/Text/Figlet.php';
- if ($err) {
- return $this->markupError(
- pht(
- 'Execution of `%s` failed: %s',
- 'figlet',
- $stderr));
- }
+ $figlet = new Text_Figlet();
+ $figlet->loadFont($map[$font]);
+ $result = $figlet->lineEcho($content);
if ($this->getEngine()->isTextMode()) {
- return $stdout;
+ return $result;
}
return phutil_tag(
@@ -41,7 +36,30 @@
array(
'class' => 'PhabricatorMonospaced remarkup-figlet',
),
- $stdout);
+ $result);
+ }
+
+ private static function getFigletMap() {
+ $root = dirname(phutil_get_library_root('phabricator'));
+
+ $dirs = array(
+ $root.'/externals/figlet/fonts/',
+ $root.'/externals/pear-figlet/fonts/',
+ $root.'/resources/figlet/custom/',
+ );
+
+ $map = array();
+ foreach ($dirs as $dir) {
+ foreach (Filesystem::listDirectory($dir, false) as $file) {
+ if (preg_match('/\.flf\z/', $file)) {
+ $name = phutil_utf8_strtolower($file);
+ $name = preg_replace('/\.flf\z/', '', $name);
+ $map[$name] = $dir.$file;
+ }
+ }
+ }
+
+ return $map;
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 2, 8:21 PM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6731505
Default Alt Text
D14102.id34087.diff (6 KB)
Attached To
Mode
D14102: Use PEAR Text_Figlet to render figlet fonts
Attached
Detach File
Event Timeline
Log In to Comment