Skip to content

Commit d87c23b

Browse files
committed
Scan for available languages in highlight src
1 parent c228943 commit d87c23b

File tree

2 files changed

+27
-61
lines changed

2 files changed

+27
-61
lines changed

config/services.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
parameters:
22
phpbbde.pastebin.path: '%core.root_path%ext/phpbbde/pastebin/'
3+
phpbbde.pastebin.highlight: '%phpbbde.pastebin.path%vendor/tempest/highlight/'
4+
phpbbde.pastebin.hightlightlangs: '%phpbbde.pastebin.highlight%src/Languages/'
35
phpbbde.pastebin.cron.prune_interval: 86400
46
tables.phpbbde.pastebin.pastebin: '%core.table_prefix%pastebin'
57
services:
@@ -8,6 +10,7 @@ services:
810
arguments:
911
- '%core.php_ext%'
1012
- '@language'
13+
- '%phpbbde.pastebin.hightlightlangs%'
1114
phpbbde.pastebin.functions.pastebin:
1215
class: phpbbde\pastebin\functions\pastebin
1316
arguments:

functions/utility.php

Lines changed: 24 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php
22
/**
33
* @package pastebin
4-
* @version 0.2.0
5-
* @copyright (c) 2009 3Di (2007 eviL3), 2015 gn#36
4+
* @copyright (c) 2024 Crizzo
65
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
76
*/
87

@@ -16,90 +15,54 @@ class utility
1615
/* @var \phpbb\language\language */
1716
protected $language;
1817

18+
/* @var */
19+
protected $highlight_lang_dir;
20+
1921
/**
2022
* Constructor
2123
* @param string $php_ext
2224
* @param \phpbb\language\language $language
2325
*/
2426
function __construct(
2527
$php_ext,
26-
\phpbb\language\language $language)
28+
\phpbb\language\language $language,
29+
$highlight_lang_dir
30+
)
2731
{
28-
$this->php_ext = $php_ext;
29-
$this->language = $language;
32+
$this->php_ext = $php_ext;
33+
$this->language = $language;
34+
$this->highlight_lang_dir = $highlight_lang_dir;
3035
}
3136

32-
3337
/**
34-
* Check if $needle is in one of geshis supported languages
38+
* List of all available highlight languages
39+
* Scan languages dir: \pastebin\vendor\tempest\highlight\src\Languages
40+
* Each supported language has an own directory
3541
*/
36-
/*function geshi_check($needle)
42+
function highlight_list_avail_langs()
3743
{
38-
return in_array($needle, $this->geshi_list);
39-
}*/
44+
// Scan the directory of the highlight languages
45+
return array_diff(scandir($this->highlight_lang_dir), array('.', '..'));
46+
/* TODO filter result via ACP option, to only display activated languages,
47+
* in case this list will get really long in the future */
48+
}
4049

4150
/**
42-
* List of all geshi langs
43-
*/
44-
function geshi_list()
45-
{
46-
$geshi_list = array();
47-
48-
$d = dir($this->geshi_dir);
49-
while (false !== ($file = $d->read()))
50-
{
51-
if (in_array($file, array('.', '..')))
52-
{
53-
continue;
54-
}
55-
56-
if (($substr_end = strpos($file, ".$this->php_ext")) !== false)
57-
{
58-
$geshi_list[] = substr($file, 0, $substr_end);
59-
}
60-
}
61-
$d->close();
62-
63-
sort($geshi_list);
64-
65-
return $geshi_list;
66-
}
67-
68-
/**
69-
* Highlight select box for geshi languages
51+
* Highlight select box
7052
*/
7153
function highlight_select($default = 'text')
7254
{
73-
/** Programming languages used by geshi
74-
* Check \phpbbde\pastebin\vendor\easybook\geshi\geshi for more languages
55+
/** Create option menu for available languages
7556
* Add them to the array $programming_langs
76-
* Don't forget to add fitting language variables to \phpbbde\pastebin\language\<iso>\pastebin.php as well
7757
*/
78-
$programming_langs = array(
79-
'base',
80-
'blade',
81-
'css',
82-
'doccomment',
83-
'gdscript',
84-
'javascript',
85-
'json',
86-
'php',
87-
'sql',
88-
'twig',
89-
'xml',
90-
'yaml',
91-
);
92-
// Make no highlighting as text as default
93-
if ($default)
94-
{
95-
96-
}
58+
$programming_langs = $this->highlight_list_avail_langs();
9759

9860
$output = '';
9961
$lang_prefix = 'PASTEBIN_LANGS_';
62+
10063
foreach ($programming_langs as $code)
10164
{
102-
$output .= '<option' . (($default == $code) ? ' selected="selected"' : '') . ' value="' . htmlentities($code, ENT_QUOTES) . '">' . $this->language->lang($lang_prefix . strtoupper($code)) . '</option>';
65+
$output .= '<option' . (($default == $code) ? ' selected ' : '') . ' value="' . htmlentities($code, ENT_QUOTES) . '">' . $this->language->lang($lang_prefix . strtoupper($code)) . '</option>';
10366
}
10467

10568
return $output;

0 commit comments

Comments
 (0)