Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dokuwiki-plugin-piratilide
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
marek.krejpsky
dokuwiki-plugin-piratilide
Commits
fdc3fe68
Verified
Commit
fdc3fe68
authored
5 years ago
by
Andrej Ramašeuski
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parents
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
syntax.php
+177
-0
177 additions, 0 deletions
syntax.php
with
177 additions
and
0 deletions
syntax.php
0 → 100644
+
177
−
0
View file @
fdc3fe68
<?php
/**
* Pirati: Members
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author
*/
// must be run within DokuWiki
if
(
!
defined
(
'DOKU_INC'
))
die
();
if
(
!
defined
(
'DOKU_PLUGIN'
))
define
(
'DOKU_PLUGIN'
,
DOKU_INC
.
'lib/plugins/'
);
require_once
(
DOKU_PLUGIN
.
'syntax.php'
);
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class
syntax_plugin_piratimembers
extends
DokuWiki_Syntax_Plugin
{
/**
* return some info
*/
function
getInfo
(){
return
array
(
'author'
=>
'Vaclav Malek'
,
'email'
=>
'vaclav.malek@pirati.cz'
,
'date'
=>
'2012-11-02'
,
'name'
=>
'Pirati: Members'
,
'desc'
=>
'print members of group'
,
'url'
=>
'http://www.pirati.cz'
,
);
}
function
getType
(){
return
'substition'
;
}
function
getPType
(){
return
'block'
;
}
// function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
//function getAllowedTypes() { return 'substition'; }
function
getSort
(){
return
300
;
}
// 158
function
connectTo
(
$mode
)
{
$this
->
Lexer
->
addSpecialPattern
(
'<pirati>.*?</pirati>'
,
$mode
,
'plugin_piratimembers'
);
}
//function connectTo($mode) { $this->Lexer->addEntryPattern('<pirati>.*?',$mode,'plugin_piratimembers'); }
// (?=.*?</pirati>)
//function postConnect() { $this->Lexer->addExitPattern('</pirati>','plugin_piratimembers'); }
/**
* Handle the match
*/
function
handle
(
$match
,
$state
,
$pos
,
&
$handler
){
switch
(
$state
)
{
case
DOKU_LEXER_ENTER
:
return
array
(
$state
,
$match
);
case
DOKU_LEXER_SPECIAL
:
$options
=
explode
(
"
\n
"
,
$match
);
$o
=
array
();
foreach
(
$options
as
$opt
){
list
(
$key
,
$value
)
=
explode
(
':'
,
$opt
);
$o
[
trim
(
$key
)]
=
trim
(
$value
);
}
return
array
(
$state
,
$o
);
break
;
case
DOKU_LEXER_EXIT
:
return
array
(
$state
,
''
);
}
return
array
();
}
/**
* Create output
*/
function
render
(
$mode
,
&
$renderer
,
$data
)
{
$renderer
->
info
[
'cache'
]
=
false
;
if
(
$mode
==
'xhtml'
){
list
(
$state
,
$options
)
=
$data
;
switch
(
$state
)
{
case
DOKU_LEXER_ENTER
:
break
;
case
DOKU_LEXER_SPECIAL
:
// cache
$updateInterval
=
21600
;
$data
=
new
stdClass
();
$data
->
timestamp
=
0
;
$data
->
members
=
"no members"
;
$cacheFilePath
=
DOKU_INC
.
"data/tmp/piratimembers/piratimembers_"
.
urlencode
(
sha1
(
var_export
(
$options
,
true
)))
.
".cached"
;
if
(
file_exists
(
$cacheFilePath
)){
$handle
=
fopen
(
$cacheFilePath
,
"r"
);
$data
=
unserialize
(
fread
(
$handle
,
filesize
(
$cacheFilePath
)));
fclose
(
$handle
);
}
// re-cache?
if
((
time
()
-
$data
->
timestamp
)
>
$updateInterval
){
// users
$users
=
curl_init
();
curl_setopt
(
$users
,
CURLOPT_URL
,
"https://graph.pirati.cz/group/"
.
rawurlencode
(
$options
[
'group'
])
.
"/members"
);
curl_setopt
(
$users
,
CURLOPT_HEADER
,
0
);
curl_setopt
(
$users
,
CURLOPT_RETURNTRANSFER
,
true
);
$users_data
=
curl_exec
(
$users
);
if
(
$users_data
==
"no such user"
)
$renderer
->
doc
.
=
"Neznámá skupina"
;
else
{
// single
$user_data
=
array
();
$users_data
=
json_decode
(
$users_data
);
$data
->
members
=
'<ul>'
;
foreach
(
$users_data
as
$i
=>
$user
){
$user_data
[
$i
]
=
curl_init
();
curl_setopt
(
$user_data
[
$i
],
CURLOPT_URL
,
"https://graph.pirati.cz/"
.
$user
->
id
);
curl_setopt
(
$user_data
[
$i
],
CURLOPT_HEADER
,
0
);
curl_setopt
(
$user_data
[
$i
],
CURLOPT_RETURNTRANSFER
,
true
);
$usrdetail
=
json_decode
(
curl_exec
(
$user_data
[
$i
]));
if
(
empty
(
$usrdetail
->
fullname
))
$name
=
$usrdetail
->
username
;
else
$name
=
$usrdetail
->
fullname
;
if
(
isset
(
$options
[
'rank'
])){
if
(
$usrdetail
->
rank
==
$options
[
'rank'
])
$data
->
members
.
=
'<li><a href="/lide/'
.
str_replace
(
"."
,
"_"
,
$usrdetail
->
username
)
.
'">'
.
$name
.
'</a></li>'
;
}
else
$data
->
members
.
=
'<li><a href="/lide/'
.
str_replace
(
"."
,
"_"
,
$usrdetail
->
username
)
.
'">'
.
$name
.
'</a></li>'
;
}
$data
->
members
.
=
'</ul>'
;
/*
// multi
$curlm = curl_multi_init();
$user_data = array();
$users_data = json_decode($users_data);
foreach($users_data as $i=>$user){
$user_data[$i] = curl_init();
curl_setopt($user_data[$i],CURLOPT_URL,"https://graph.pirati.cz/".$user->id);
curl_setopt($user_data[$i],CURLOPT_HEADER,0);
curl_setopt($user_data[$i],CURLOPT_RETURNTRANSFER,true);
curl_multi_add_handle($curlm,$user_data[$i]);
}
$active = null;
do {
if(curl_multi_select($curlm) != -1){
while(CURLM_CALL_MULTI_PERFORM == curl_multi_exec($curlm,$active)){
}
}
} while($active);
$data->members = '<ul>';
foreach($users_data as $i=>$user){
$usrdetail = json_decode(curl_multi_getcontent($user_data[$i]));
$link = str_replace($usrdetail->username, ".", "_");
$data->members .= '<li><a href="/lide/'.$link.'">'.$usrdetail->fullname.'</a></li>';
curl_multi_remove_handle($user_data[$i]);
}
$data->members .= '</ul>';
curl_multi_close($curlm);
*/
// cache out
$data
->
timestamp
=
time
();
$handle
=
fopen
(
$cacheFilePath
,
"w"
);
fwrite
(
$handle
,
serialize
(
$data
));
fclose
(
$handle
);
// end multi
}
curl_close
(
$users
);
}
// output
$renderer
->
doc
.
=
$data
->
members
;
break
;
case
DOKU_LEXER_EXIT
:
break
;
}
return
true
;
}
return
false
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment