First
This commit is contained in:
parent
5456377286
commit
6360ff0ea5
@ -1,2 +1,5 @@
|
||||
# tiledblog
|
||||
|
||||
DokuWiki Extensions : https://www.dokuwiki.org/plugin:tiledblog
|
||||
|
||||
A blog summary in the form of thumbnails.
|
||||
|
50
ajax.php
Normal file
50
ajax.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @license http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
|
||||
* @author Francois Merciol <dokuplugin@merciol.fr>
|
||||
*
|
||||
* TiledBlog Plugin: manage clear action action
|
||||
*/
|
||||
if (!defined ('DOKU_INC'))
|
||||
define ('DOKU_INC', realpath (dirname (__FILE__).'/../../../').'/');
|
||||
require_once (DOKU_INC.'inc/init.php');
|
||||
require_once (DOKU_INC.'inc/common.php');
|
||||
require_once (DOKU_INC.'inc/auth.php');
|
||||
{
|
||||
global $INFO;
|
||||
if (isset ($_SERVER['REMOTE_USER']))
|
||||
$INFO['userinfo'] = $auth->getUserData ($auth->cleanUser ($_SERVER['REMOTE_USER']));
|
||||
$tiledblogPug =& plugin_load ('syntax', 'tiledblog');
|
||||
if (!$tiledblogPug->isAdmin ())
|
||||
die ();
|
||||
|
||||
global $conf;
|
||||
$savedir = ((!$conf['savedir'] || strpos ($conf['savedir'], '.') === 0) ? DOKU_INC : "").$conf['savedir']."/";
|
||||
$cacheDir = $savedir."cache/tiledblog/";
|
||||
switch ($_REQUEST ['tiledblog']['action']) {
|
||||
case 'clear':
|
||||
$baseName = $cacheDir.md5 ($_REQUEST ['tiledblog']['ns']);
|
||||
@unlink ($baseName."-tile.cache");
|
||||
@unlink ($baseName."-sample.cache");
|
||||
break;
|
||||
|
||||
case 'clearAll':
|
||||
$exclude = ".|..";
|
||||
$exclude_array = explode("|", $exclude);
|
||||
$pathDir = rtrim ($cacheDir, "/") . "/";
|
||||
if (!is_dir($pathDir))
|
||||
break;
|
||||
$pathDirObj = opendir ($pathDir);
|
||||
while (false !== ($file = readdir ($pathDirObj))) {
|
||||
if (in_array (strtolower ($file), $exclude_array))
|
||||
continue;
|
||||
$pathFile = $pathDir.$file;
|
||||
if (!is_file ($pathFile))
|
||||
continue;
|
||||
if (eregi ('.*-tile\.cache$', $file, $b) ||
|
||||
eregi ('.*-sample\.cache$', $file, $b))
|
||||
@unlink ($pathFile);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
9
conf/default.php
Normal file
9
conf/default.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* Options for the Blog Plugin
|
||||
*/
|
||||
$conf['formPosition'] = 'top'; // position of new entry form
|
||||
$conf['iconSize'] = 100; // the icon size
|
||||
$conf['adminGroup'] = 'admin'; // who can clear the cache
|
||||
$conf['sampleDelai'] = 2*60*60; // delai to change sample
|
||||
?>
|
14
conf/metadata.php
Normal file
14
conf/metadata.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* @license http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
|
||||
* @author Francois Merciol <dokuplugin@merciol.fr>
|
||||
*
|
||||
* Metadata for configuration manager plugin
|
||||
* Additions for the tiledBlog plugin
|
||||
*/
|
||||
$meta['formPosition'] = array('multichoice',
|
||||
'_choices' => array ('top', 'bottom', 'none'));
|
||||
$meta['iconSize'] = array('numeric');
|
||||
$meta['adminGroup'] = array('string');
|
||||
$meta['sampleDelai'] = array('numeric');
|
||||
?>
|
11
lang/en/lang.php
Normal file
11
lang/en/lang.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @license http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
|
||||
* @author Francois Merciol <dokuplugin@merciol.fr>
|
||||
*
|
||||
* English language file
|
||||
*/
|
||||
|
||||
// commands
|
||||
$lang['clear'] = 'Clear cache';
|
||||
$lang['clearAll'] = 'Clear all cache';
|
14
lang/en/settings.php
Normal file
14
lang/en/settings.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* @license http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
|
||||
* @author Francois Merciol <dokuplugin@merciol.fr>
|
||||
*
|
||||
* English language file
|
||||
*/
|
||||
|
||||
// for the configuration tiledblog plugin
|
||||
$lang['formPosition'] = 'position of the new entry form';
|
||||
$lang['iconSize'] = 'tile icon size';
|
||||
$lang['adminGroup'] = 'who can clear the cache';
|
||||
$lang['sampleDelai'] = 'cache time delay for sample (sec)';
|
||||
?>
|
11
lang/fr/lang.php
Normal file
11
lang/fr/lang.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @license http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
|
||||
* @author Francois Merciol <dokuplugin@merciol.fr>
|
||||
*
|
||||
* French language file
|
||||
*/
|
||||
|
||||
// commands
|
||||
$lang['clear'] = 'Effacer le cache';
|
||||
$lang['clearAll'] = 'Effacer tout les caches';
|
14
lang/fr/settings.php
Normal file
14
lang/fr/settings.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* @license http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
|
||||
* @author Francois Merciol <dokuplugin@merciol.fr>
|
||||
*
|
||||
* French language file
|
||||
*/
|
||||
|
||||
// for the configuration tiledblog plugin
|
||||
$lang['formPosition'] = 'position du formulaire du nouveau billet';
|
||||
$lang['iconSize'] = 'taille de l\'icon de tuile';
|
||||
$lang['adminGroup'] = 'qui peut effacer le cache';
|
||||
$lang['sampleDelai'] = 'temps de cache pour l\'exemple (en secondes)';
|
||||
?>
|
7
plugin.info.txt
Normal file
7
plugin.info.txt
Normal file
@ -0,0 +1,7 @@
|
||||
base tiledblog
|
||||
author Francois Merciol
|
||||
email dokuplugin@merciol.fr
|
||||
date 2020-07-20
|
||||
name tiledblog Plugin
|
||||
desc Tile an existing blog
|
||||
url http://www.dokuwiki.org/plugin:tiledblog
|
22
script.js
Normal file
22
script.js
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* @license http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
|
||||
* @author Francois Merciol <dokuplugin@merciol.fr>
|
||||
*
|
||||
* Javascript functionality for the tiledblog plugin
|
||||
*/
|
||||
|
||||
// ========================================
|
||||
// Ajax function
|
||||
// ========================================
|
||||
/* performe ajax request */
|
||||
function tiledblogAjax (action, ns) {
|
||||
jQuery.ajax ({
|
||||
type: "POST",
|
||||
url: DOKU_BASE+"lib/plugins/tiledblog/ajax.php",
|
||||
cache: false,
|
||||
async: true,
|
||||
data: "tiledblog[action]="+action+"&tiledblog[ns]="+ns,
|
||||
});
|
||||
}
|
||||
|
||||
// ========================================
|
48
style.css
Normal file
48
style.css
Normal file
@ -0,0 +1,48 @@
|
||||
div.tiledblog {
|
||||
background: #E8E8E8;
|
||||
display: block;
|
||||
padding: 0.5em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div.tileblog {
|
||||
background: #FFF;
|
||||
display: inline-block;
|
||||
padding: 0.5em;
|
||||
margin: 0.5em;
|
||||
width: 10em;
|
||||
min-height: 15em;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
div.tileblog a {
|
||||
display: block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
div.tileblog p.title {
|
||||
margin-bottom: 0 ! important;
|
||||
margin: 0 ! important;
|
||||
text-align: center;
|
||||
font-size: 100%;
|
||||
}
|
||||
|
||||
div.tileblog p.date {
|
||||
margin-bottom: 0 ! important;
|
||||
margin-left: 0 ! important;
|
||||
text-align: center;
|
||||
color: gray;
|
||||
font-size: 60%;
|
||||
}
|
||||
|
||||
div.tileblog div.image {
|
||||
margin-bottom: 0 ! important;
|
||||
margin-left: 0 ! important;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div.tileblog img {
|
||||
max-height: 9em;
|
||||
max-width: 9em;
|
||||
}
|
184
syntax.php
Normal file
184
syntax.php
Normal file
@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* @license http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
|
||||
* @author Francois <dokuplugin@merciol.fr>
|
||||
*
|
||||
* Plugin tiledblog: display blog in tile
|
||||
*/
|
||||
|
||||
if (!defined ('DOKU_INC'))
|
||||
die ();
|
||||
if (!defined ('DOKU_PLUGIN'))
|
||||
define ('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
|
||||
require_once (DOKU_PLUGIN.'syntax.php');
|
||||
|
||||
class syntax_plugin_tiledblog extends DokuWiki_Syntax_Plugin {
|
||||
|
||||
// ============================================================
|
||||
function getInfo () {
|
||||
return confToHash (dirname (__FILE__).'/INFO.txt');
|
||||
}
|
||||
function getType () { return 'substition'; }
|
||||
function getPType () { return 'block'; }
|
||||
function getSort () { return 299; }
|
||||
function connectTo ($mode) {
|
||||
$this->Lexer->addSpecialPattern ('\{\{tiledBlog.*?\}\}', $mode, 'plugin_tiledblog');
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
function handle ($match, $state, $pos, Doku_Handler $handler) {
|
||||
switch ($state) {
|
||||
case DOKU_LEXER_SPECIAL :
|
||||
return trim (substr ($match, 11, -2)); // "{{tiledBlog" => 11 "}}" => 2
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
function render ($mode, Doku_Renderer $renderer, $indata) {
|
||||
if ($mode != 'xhtml')
|
||||
return false;
|
||||
$data = " ".$indata." ";
|
||||
if (preg_match_all ("#(\"[^\"]*\")* help (\"[^\"]*\")*#", strtolower ($data), $dumy) > 0) {
|
||||
$this->help ($renderer);
|
||||
return true;
|
||||
}
|
||||
global $ID;
|
||||
$ns = getNS ($ID);
|
||||
// namespace
|
||||
if (preg_match_all ("#^ >([^ ]*) .*#", strtolower ($data), $dumy) > 0) {
|
||||
$ns = $dumy[1][0];
|
||||
if (($ns == '*') || ($ns == ':'))
|
||||
$ns = '';
|
||||
elseif ($ns == '.')
|
||||
$ns = getNS ($ID);
|
||||
else
|
||||
$ns = cleanID ($ns);
|
||||
}
|
||||
global $conf;
|
||||
$savedir = ((!$conf['savedir'] || strpos ($conf['savedir'], '.') === 0) ? DOKU_INC : "").$conf['savedir']."/";
|
||||
$cacheDir = $savedir."cache/tiledblog/";
|
||||
if (!is_dir ($cacheDir)) {
|
||||
@mkdir ($cacheDir);
|
||||
@chmod ($cacheDir, 0775);
|
||||
}
|
||||
$renderer->info ['cache'] = FALSE;
|
||||
if (preg_match_all ("#(\"[^\"]*\")* sample (\"[^\"]*\")*#", strtolower ($data), $dumy) > 0) {
|
||||
$this->sample ($renderer, $ns, $cacheDir);
|
||||
return true;
|
||||
}
|
||||
$this->tile ($renderer, $ns, $cacheDir);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
function sample (Doku_Renderer $renderer, $ns, $cacheDir) {
|
||||
$filename = $cacheDir.md5($ns)."-sample.cache";
|
||||
if (file_exists ($filename) &&
|
||||
(time () - filemtime ($filename) < $this->getConf ('sampleDelai'))) {
|
||||
$renderer->doc .= file_get_contents ($filename);
|
||||
return;
|
||||
}
|
||||
if ($helperPlugin =& plugin_load ('helper', 'blog')) {
|
||||
$entries = $helperPlugin->getBlog ($ns);
|
||||
$width = $this->getConf ('iconSize');
|
||||
$keys = array_keys ($entries);
|
||||
$rand = array_rand ($keys);
|
||||
$text = $this->getEntry ($entries [$keys [$rand]], $width);
|
||||
$renderer->doc .= $text.NL;
|
||||
file_put_contents ($filename, $text);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
function tile (Doku_Renderer $renderer, $ns, $cacheDir) {
|
||||
$formPos = $this->getConf ('formPosition');
|
||||
$blogPlugin =& plugin_load ('syntax', 'blog_blog');
|
||||
$createPerm = (auth_quickaclcheck ($ns.':*') >= AUTH_CREATE);
|
||||
if ($formPos == 'top')
|
||||
$this->displayForm ($renderer, $blogPlugin, $ns, $createPerm);
|
||||
|
||||
$filename = $cacheDir.md5($ns)."-tile.cache";
|
||||
if (file_exists ($filename) &&
|
||||
(time () - filemtime ($filename) < $this->getConf ('sampleDelai'))) {
|
||||
$renderer->doc .= file_get_contents ($filename);
|
||||
} else {
|
||||
if ($helperPlugin =& plugin_load ('helper', 'blog'))
|
||||
$entries = $helperPlugin->getBlog ($ns);
|
||||
$text = '
|
||||
<div class="tiledblog">';
|
||||
$width = $this->getConf ('iconSize');
|
||||
foreach ($entries as $entry)
|
||||
$text .= $this->getEntry ($entry, $width);
|
||||
$text .= '
|
||||
</div>';
|
||||
$renderer->doc .= $text.NL;
|
||||
file_put_contents ($filename, $text);
|
||||
}
|
||||
|
||||
if ($formPos == 'bottom')
|
||||
$this->displayForm ($renderer, $blogPlugin, $ns, $createPerm);
|
||||
}
|
||||
|
||||
|
||||
// ============================================================
|
||||
function displayForm (Doku_Renderer $renderer, syntax_plugin_blog_blog $blogPlugin, $ns, $createPerm) {
|
||||
if ($createPerm)
|
||||
$renderer->doc .= $blogPlugin->_newEntryForm ($ns, "");
|
||||
global $INFO;
|
||||
if (! $this->isAdmin ())
|
||||
return;
|
||||
$renderer->doc .= '<div><form>';
|
||||
foreach (array ('clear', 'clearAll') as $action)
|
||||
$renderer->doc .= '<input value="'.$this->getLang ($action).'" onclick="javascript:tiledblogAjax (\''.$action.'\', \''.$ns.'\')" type="button">';
|
||||
$renderer->doc .= '</form></div>';
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
function isAdmin () {
|
||||
global $INFO;
|
||||
return
|
||||
isset ($INFO ['userinfo']) &&
|
||||
isset ($INFO ['userinfo']['grps']) &&
|
||||
in_array (trim ($this->getConf ('adminGroup')), $INFO ['userinfo']['grps']);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
function getEntry ($entry, $width) {
|
||||
if (auth_quickaclcheck($entry['id']) < AUTH_READ)
|
||||
return;
|
||||
$id = $entry['id'];
|
||||
$file = wikiFN ($entry['id']);
|
||||
if (!@file_exists($file))
|
||||
return '';
|
||||
$title = $entry['title'];
|
||||
$meta = p_get_metadata ($id);
|
||||
$img = $meta['relation']['firstimage'];
|
||||
$date = dformat ($meta['date']['created']);
|
||||
global $_REQUEST;
|
||||
return '
|
||||
<div class="tileblog">
|
||||
<a href="'.wl ($id).'">
|
||||
<div class="image">
|
||||
<img src="'.ml ($img, array ('cache'=>$_REQUEST['cache'], 'w'=>$width)).'" width="'.$width.'"/>
|
||||
</div>
|
||||
<p class="title">'.$title.'</p>
|
||||
<p class="date">'.$date.'</p>
|
||||
</a>
|
||||
</div>';
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
function help (Doku_Renderer $renderer) {
|
||||
$url = "http://admin.parlenet.org/plugins/tiledblog/";
|
||||
$renderer->doc .=
|
||||
' <h1>Help TiledBlog V2.0</h1>'.NL.
|
||||
' <ul>'.NL.
|
||||
' <li><b>{{tiledBlog></b>namespace [help] <b>}}</b></li>'.NL.
|
||||
' </ul>'.NL.
|
||||
' <p><a class="urlextern" rel="nofollow" title="'.$url.'" href="'.$url.'">'.$url.'</a></p>'.NL;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
} // syntax_plugin_tiledblog
|
||||
?>
|
Loading…
Reference in New Issue
Block a user