Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 49 additions & 33 deletions syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
/**
* Info Alphaindex: Displays the alphabetical index of a specified namespace.
*
* Version: 1.2
* last modified: 2006-06-14 12:00:00
* Version: 1.3
* last modified: 2019-01-06 14:00:00
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Hubert Molière <hubert.moliere@alternet.fr>
* Modified by Cyrille G. <cyrille37 at giquello.fr>
* Modified by Nicolas H. <prog@a-et-n.com>
* Modified by Jonesy <jonesy@oryma.org>
* Modified by Samuele Tognini <samuele@netsons.org>
Expand All @@ -24,11 +25,11 @@
class syntax_plugin_alphaindex extends DokuWiki_Syntax_Plugin {

function getType(){ return 'substition';}

function getAllowedTypes() { return array('baseonly', 'substition', 'formatting', 'paragraphs', 'protected'); }

function getPType() { return 'block'; }

/**
* Where to sort in?
*/
Expand All @@ -50,16 +51,16 @@ function handle($match, $state, $pos, Doku_Handler $handler){
$level = 0;
$nons = true;
$match = substr($match, 13, -2);

// split namespaces
$match = preg_split('/\|/u', $match, 2);

// split level
$ns_opt = preg_split('/\#/u', $match[0], 2);

// namespace name
$ns = $ns_opt[0];

// add @NS@ option
if(empty($ns) || $ns == '@NS@') {
$pos = strrpos($ID,':');
Expand All @@ -69,20 +70,20 @@ function handle($match, $state, $pos, Doku_Handler $handler){
$ns = '.';
}
}

// level;
if (is_numeric($ns_opt[1])) {
$level = $ns_opt[1];
}
$match = explode(" ", $match[1]);

$match = explode(' ', $match[1]);

// namespaces option
$nons = in_array('nons', $match);

// multi-columns option
$incol = in_array('incol', $match);

return array($ns, array('level' => $level, 'nons' => $nons, 'incol' => $incol));
}

Expand All @@ -101,25 +102,38 @@ function render($mode, Doku_Renderer $renderer, $data) {
$n = 'No index for <b>{{ns}}</b>';
}
}

$alpha_data = str_replace('{{ns}}', cleanID($data[0]), $alpha_data);

// Remove Section Edit Buttons
$oldmaxecl = $conf['maxseclevel'];
$conf['maxseclevel'] = 0;

$alpha_data = p_render('xhtml', p_get_instructions($alpha_data), $info);

$conf['maxseclevel'] = $oldmaxecl ;

/*
// remove toc, section edit buttons and category tags
$patterns = array('!<div class="toc">.*?(</div>\n</div>)!s',
'#<!-- SECTION \[(\d*-\d*)\] -->#e',
'!<div class="category">.*?</div>!s');
$replace = array('','','');
// Remove all comments, to remove the "Edit section" button.
// by that way, it solves too the preg_replace() "/e" modifier deprecation.
//'#<!-- SECTION \[(\d*-\d*)\] -->#e',
//'#<!-- SECTION \[(\d*-\d*)\] -->#',
//'#<!-- .* -->#m',
//'!<div class="category">.*?</div>!s'
);
$replace = array('');
$alpha_data = preg_replace($patterns, $replace, $alpha_data);
*/
$renderer->doc .= '<div id="alphaindex_content">' ;
$renderer->doc .= $ns_data;
$renderer->doc .= '<hr />';
//$renderer->doc .= $ns_data;
//$renderer->doc .= '<hr />';
$renderer->doc .= $alpha_data;
$renderer->doc .= '</div>' ;
return true;
}

return false;
}

Expand Down Expand Up @@ -161,19 +175,19 @@ function _alpha_index($myns, &$renderer) {
} else {
$titleTpl = '===== Index =====';
}

if($this->getConf('begin_letter_tpl')) {
$beginLetterTpl = $this->getConf('begin_letter_tpl');
} else {
$beginLetterTpl = '==== {{letter}} ====';
}

if($this->getConf('entry_tpl')) {
$entryTpl = $this->getConf('entry_tpl');
} else {
$entryTpl = ' * [[{{link}}|{{name}}]]';
}

if($this->getConf('end_letter_tpl')) {
$endLetterTpl = $this->getConf('end_letter_tpl');
} else {
Expand Down Expand Up @@ -202,7 +216,7 @@ function _alpha_index($myns, &$renderer) {
$pos = strrpos(utf8_decode($tmpData), ':');
if($conf['useheading']) {
$pageName = p_get_first_heading($tmpData);

if($pageName == NULL) {
if($pos != FALSE) {
$pageName = utf8_substr($tmpData, $pos+1, utf8_strlen($tmpData));
Expand All @@ -217,7 +231,7 @@ function _alpha_index($myns, &$renderer) {
} else {
$pageName = $tmpData;
}

$pageName = str_replace('_', ' ', $pageName);
}
$pageNameArticle = '';
Expand All @@ -233,7 +247,7 @@ function _alpha_index($myns, &$renderer) {
}
}
}

// Fix for useheading - Decide if the heading is used or the pagename
if($this->getConf('metadata_title')) {
$tmp = p_get_metadata($data[$cpt]['id']);
Expand All @@ -242,7 +256,7 @@ function _alpha_index($myns, &$renderer) {

// R�cup�ration de la premi�re lettre du mot et classement
$firstLetter = utf8_deaccent(utf8_strtolower(utf8_substr($pageName, 0, 1)));

if(is_numeric($firstLetter)) {
if($this->getConf('numerical_index')) {
$firstLetter = $this->getConf('numerical_index');
Expand Down Expand Up @@ -272,13 +286,15 @@ function _alpha_index($myns, &$renderer) {

// Display of results

$alphaOutput = '' ;

// alphabetical index
$alphaOutput .= $titleTpl . "\n";
$nb_data = count($alpha_data);

foreach($alpha_data as $key => $currentLetter) {
// Sorting of $currentLetter array
usort($currentLetter, create_function('$a, $b', "return strnatcasecmp(\$a['id2'], \$b['id2']);"));
usort($currentLetter, function($a, $b) {return strnatcasecmp($a['id2'], $b['id2']);});

$begin = str_replace("{{letter}}" ,utf8_strtoupper($key), $beginLetterTpl);
$alphaOutput .= $begin."\n";
Expand Down Expand Up @@ -308,7 +324,7 @@ function _alpha_index($myns, &$renderer) {
function alphaindex_search_index(&$data, $base, $file, $type, $lvl, $opts) {
$return = true;
$item = array();

if($type == 'd'){
if ($opts['level'] == $lvl) $return = false;
if ($opts['nons']) return $return;
Expand Down Expand Up @@ -338,6 +354,6 @@ function alphaindex_search_index(&$data, $base, $file, $type, $lvl, $opts) {
'type' => $type,
'level' => $lvl,
'open' => $return);

return $return;
}
}