mirror of
https://github.com/dokuwiki/dokuwiki-plugin-xref.git
synced 2025-07-25 16:11:59 +00:00
integrate new Grok based xref into the syntax
This commit is contained in:
4
Grok.php
4
Grok.php
@ -26,6 +26,8 @@ class Grok
|
|||||||
*/
|
*/
|
||||||
public function getSearchUrl()
|
public function getSearchUrl()
|
||||||
{
|
{
|
||||||
|
if($this->def === '' && $this->path === '') return $this->baseUrl;
|
||||||
|
|
||||||
$url = $this->baseUrl . '/search?';
|
$url = $this->baseUrl . '/search?';
|
||||||
$param = [
|
$param = [
|
||||||
'project' => 'dokuwiki',
|
'project' => 'dokuwiki',
|
||||||
@ -60,6 +62,8 @@ class Grok
|
|||||||
*/
|
*/
|
||||||
public function getResultCount()
|
public function getResultCount()
|
||||||
{
|
{
|
||||||
|
if($this->def === '' && $this->path === '') return 0;
|
||||||
|
|
||||||
$http = new DokuHTTPClient();
|
$http = new DokuHTTPClient();
|
||||||
$http->timeout = 5;
|
$http->timeout = 5;
|
||||||
$json = $http->get($this->getAPIUrl());
|
$json = $http->get($this->getAPIUrl());
|
||||||
|
@ -42,4 +42,11 @@ class GrokTest extends DokuWikiTest
|
|||||||
$grok = new Grok($reference);
|
$grok = new Grok($reference);
|
||||||
$this->assertEquals(1, $grok->getResultCount(), $grok->getSearchUrl());
|
$this->assertEquals(1, $grok->getResultCount(), $grok->getSearchUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEmptyData()
|
||||||
|
{
|
||||||
|
$grok = new Grok('', 'https://testurl/');
|
||||||
|
$this->assertEquals('https://testurl', $grok->getSearchUrl());
|
||||||
|
$this->assertSame(0, $grok->getResultCount());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
9
conf/default.php
Normal file
9
conf/default.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Default settings for the xref plugin
|
||||||
|
*
|
||||||
|
* @author Andreas Gohr <andi@splitbrain.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
$conf['grokbaseurl'] = 'https://codesearch.dokuwiki.org';
|
||||||
|
|
@ -1,5 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$meta['web'] = array('string');
|
$meta['grokbaseurl'] = array('string');
|
||||||
$meta['dir'] = array('string');
|
|
||||||
|
|
||||||
|
@ -2,4 +2,5 @@
|
|||||||
|
|
||||||
$lang['unknown'] = 'unknown cross reference';
|
$lang['unknown'] = 'unknown cross reference';
|
||||||
$lang['view'] = 'view cross reference for %s';
|
$lang['view'] = 'view cross reference for %s';
|
||||||
|
$lang['search'] = 'search cross reference for %s';
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$lang['dir'] = 'Specify the directory where the PHPXref files of your project are located here.';
|
$lang['grokbaseurl'] = 'URL to the grok install';
|
||||||
$lang['web'] = "Specify the root URL of your PHPXref documents here.";
|
|
||||||
|
|
||||||
|
11
style.css
11
style.css
@ -1,11 +0,0 @@
|
|||||||
a.xref_plugin {
|
|
||||||
padding-left: 18px;
|
|
||||||
background: transparent url(xref.png) left top no-repeat;
|
|
||||||
}
|
|
||||||
|
|
||||||
a.xref_plugin_err {
|
|
||||||
color: __missing__ !important;
|
|
||||||
text-decoration: none !important;
|
|
||||||
border-bottom: dashed 1px __missing__ !important;
|
|
||||||
}
|
|
||||||
|
|
8
style.less
Normal file
8
style.less
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
.dokuwiki a.plugin_xref {
|
||||||
|
background-image: url(xref.svg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dokuwiki a.plugin_xref_err {
|
||||||
|
border-bottom: dashed 1px __missing__ !important;
|
||||||
|
}
|
||||||
|
|
86
syntax.php
86
syntax.php
@ -45,16 +45,12 @@ class syntax_plugin_xref extends DokuWiki_Syntax_Plugin
|
|||||||
{
|
{
|
||||||
$match = trim(substr($match, 7, -2));
|
$match = trim(substr($match, 7, -2));
|
||||||
|
|
||||||
list($link, $name) = explode('|', $match, 2);
|
list($reference, $name) = explode('|', $match, 2);
|
||||||
list($link, $anchor) = explode('#', $link, 2);
|
list($reference, $anchor) = explode('#', $reference, 2);
|
||||||
if (!$name) $name = $link;
|
if (!$name) $name = $reference;
|
||||||
if ($anchor) $anchor = "#" . $anchor;
|
if ($anchor) $reference = "#" . $anchor;
|
||||||
|
|
||||||
$first = 0;
|
return array($reference, $name);
|
||||||
if ($link[0] == '$') $first = 4;
|
|
||||||
$found = $this->find($link, $first);
|
|
||||||
|
|
||||||
return array($link, $found, $name, $anchor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
@ -63,63 +59,33 @@ class syntax_plugin_xref extends DokuWiki_Syntax_Plugin
|
|||||||
global $conf;
|
global $conf;
|
||||||
if ($format != 'xhtml') return false;
|
if ($format != 'xhtml') return false;
|
||||||
|
|
||||||
//prepare for formating
|
list($reference, $name) = $data;
|
||||||
$link['target'] = $conf['target']['extern'];
|
$grok = new \dokuwiki\plugin\xref\Grok($reference, $this->getConf('grokbaseurl'));
|
||||||
$link['style'] = '';
|
$count = $grok->getResultCount();
|
||||||
$link['pre'] = '';
|
|
||||||
$link['suf'] = '';
|
|
||||||
$link['more'] = '';
|
|
||||||
$link['class'] = 'xref_plugin';
|
|
||||||
$link['name'] = hsc($data[2]);
|
|
||||||
|
|
||||||
if (!$data[1]) {
|
$link = [
|
||||||
$link['url'] = $this->web;
|
'target' => $conf['target']['extern'],
|
||||||
|
'style' => '',
|
||||||
|
'pre' => '',
|
||||||
|
'suf' => '',
|
||||||
|
'more' => '',
|
||||||
|
'class' => 'interwiki plugin_xref',
|
||||||
|
'name' => hsc($name),
|
||||||
|
'url' => $grok->getSearchUrl(),
|
||||||
|
'title' => sprintf($this->getLang('view'), hsc($reference)),
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($count === false || $count === 0) {
|
||||||
$link['title'] = $this->getLang('unknown');
|
$link['title'] = $this->getLang('unknown');
|
||||||
$link['class'] .= ' xref_plugin_err';
|
$link['class'] .= ' plugin_xref_err';
|
||||||
} else {
|
}
|
||||||
$link['url'] = $this->web . '/' . $data[1] . hsc($data[3]);
|
|
||||||
$link['title'] = sprintf($this->getLang('view'), hsc($data[0]));
|
if ($count > 1) {
|
||||||
|
$link['title'] = sprintf($this->getLang('search'), hsc($reference));
|
||||||
}
|
}
|
||||||
|
|
||||||
$R->doc .= $R->_formatLink($link);
|
$R->doc .= $R->_formatLink($link);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Try to find the given name in the xref directory
|
|
||||||
*
|
|
||||||
* @param int $first - defines which type should be searched first for the name
|
|
||||||
*/
|
|
||||||
protected function find($name, $first = 0)
|
|
||||||
{
|
|
||||||
$paths = array(
|
|
||||||
0 => '_functions',
|
|
||||||
1 => '_classes',
|
|
||||||
2 => '_constants',
|
|
||||||
3 => '_tables',
|
|
||||||
4 => '_variables',
|
|
||||||
);
|
|
||||||
|
|
||||||
$clean = preg_replace('/[^\w\-_]+/', '', $name);
|
|
||||||
$small = strtolower($clean);
|
|
||||||
|
|
||||||
$path = $paths[$first];
|
|
||||||
unset($paths[$first]);
|
|
||||||
do {
|
|
||||||
$check = $path . '/' . $clean . '.html';
|
|
||||||
if (@file_exists($this->dir . '/' . $check)) return $check;
|
|
||||||
$check = $path . '/' . $small . '.html';
|
|
||||||
if (@file_exists($this->dir . '/' . $check)) return $check;
|
|
||||||
$path = array_shift($paths);
|
|
||||||
} while ($path);
|
|
||||||
|
|
||||||
// still here? might be a file reference
|
|
||||||
$clean = preg_replace('/\.\.+/', '.', $name);
|
|
||||||
if (@file_exists($this->dir . '/' . $clean . '.html')) {
|
|
||||||
return $clean . '.html';
|
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
1
xref.svg
Normal file
1
xref.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#a3b8cb" d="M15.5,12C18,12 20,14 20,16.5C20,17.38 19.75,18.21 19.31,18.9L22.39,22L21,23.39L17.88,20.32C17.19,20.75 16.37,21 15.5,21C13,21 11,19 11,16.5C11,14 13,12 15.5,12M15.5,14A2.5,2.5 0 0,0 13,16.5A2.5,2.5 0 0,0 15.5,19A2.5,2.5 0 0,0 18,16.5A2.5,2.5 0 0,0 15.5,14M5,3H19C20.11,3 21,3.89 21,5V13.03C20.5,12.23 19.81,11.54 19,11V5H5V19H9.5C9.81,19.75 10.26,20.42 10.81,21H5C3.89,21 3,20.11 3,19V5C3,3.89 3.89,3 5,3M7,7H17V9H7V7M7,11H12.03C11.23,11.5 10.54,12.19 10,13H7V11M7,15H9.17C9.06,15.5 9,16 9,16.5V17H7V15Z"/></svg>
|
After Width: | Height: | Size: 597 B |
Reference in New Issue
Block a user