Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove "Edit section" button #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
76 changes: 41 additions & 35 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 <[email protected]>
* Modified by Cyrille G. <cyrille37 at giquello.fr>
* Modified by Nicolas H. <[email protected]>
* Modified by Jonesy <[email protected]>
* Modified by Samuele Tognini <[email protected]>
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,28 @@ 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;
$oldmaxtoc = $conf['maxtoclevel'];
$conf['maxtoclevel'] = 0 ;

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

// 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('','','');
$alpha_data = preg_replace($patterns, $replace, $alpha_data);
$conf['maxseclevel'] = $oldmaxecl ;
$conf['maxtoclevel'] = $oldmaxtoc ;

$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 +165,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 +206,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 +221,7 @@ function _alpha_index($myns, &$renderer) {
} else {
$pageName = $tmpData;
}

$pageName = str_replace('_', ' ', $pageName);
}
$pageNameArticle = '';
Expand All @@ -233,7 +237,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 +246,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,10 +276,12 @@ 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']);"));
Expand Down Expand Up @@ -308,7 +314,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 +344,6 @@ function alphaindex_search_index(&$data, $base, $file, $type, $lvl, $opts) {
'type' => $type,
'level' => $lvl,
'open' => $return);

return $return;
}
}