diff --git a/README.md b/README.md index b9276c3..87be83a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # tiledblog +DokuWiki Extensions : https://www.dokuwiki.org/plugin:tiledblog + +A blog summary in the form of thumbnails. diff --git a/ajax.php b/ajax.php new file mode 100644 index 0000000..40b4dff --- /dev/null +++ b/ajax.php @@ -0,0 +1,50 @@ + + * + * 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; + } +} diff --git a/conf/default.php b/conf/default.php new file mode 100644 index 0000000..66254bb --- /dev/null +++ b/conf/default.php @@ -0,0 +1,9 @@ + diff --git a/conf/metadata.php b/conf/metadata.php new file mode 100644 index 0000000..5b28f68 --- /dev/null +++ b/conf/metadata.php @@ -0,0 +1,14 @@ + + * + * 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'); +?> diff --git a/lang/en/lang.php b/lang/en/lang.php new file mode 100644 index 0000000..95881dc --- /dev/null +++ b/lang/en/lang.php @@ -0,0 +1,11 @@ + + * + * English language file + */ + +// commands +$lang['clear'] = 'Clear cache'; +$lang['clearAll'] = 'Clear all cache'; diff --git a/lang/en/settings.php b/lang/en/settings.php new file mode 100644 index 0000000..aef74fd --- /dev/null +++ b/lang/en/settings.php @@ -0,0 +1,14 @@ + + * + * 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)'; +?> diff --git a/lang/fr/lang.php b/lang/fr/lang.php new file mode 100644 index 0000000..da33787 --- /dev/null +++ b/lang/fr/lang.php @@ -0,0 +1,11 @@ + + * + * French language file + */ + +// commands +$lang['clear'] = 'Effacer le cache'; +$lang['clearAll'] = 'Effacer tout les caches'; diff --git a/lang/fr/settings.php b/lang/fr/settings.php new file mode 100644 index 0000000..6334a27 --- /dev/null +++ b/lang/fr/settings.php @@ -0,0 +1,14 @@ + + * + * 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)'; +?> diff --git a/plugin.info.txt b/plugin.info.txt new file mode 100644 index 0000000..a246bfb --- /dev/null +++ b/plugin.info.txt @@ -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 diff --git a/script.js b/script.js new file mode 100644 index 0000000..aa49cba --- /dev/null +++ b/script.js @@ -0,0 +1,22 @@ +/** + * @license http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html + * @author Francois Merciol + * + * 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, + }); +} + +// ======================================== diff --git a/style.css b/style.css new file mode 100644 index 0000000..9d30602 --- /dev/null +++ b/style.css @@ -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; +} diff --git a/syntax.php b/syntax.php new file mode 100644 index 0000000..215a006 --- /dev/null +++ b/syntax.php @@ -0,0 +1,184 @@ + + * + * 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 = ' +
'; + $width = $this->getConf ('iconSize'); + foreach ($entries as $entry) + $text .= $this->getEntry ($entry, $width); + $text .= ' +
'; + $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 .= '
'; + foreach (array ('clear', 'clearAll') as $action) + $renderer->doc .= ''; + $renderer->doc .= '
'; + } + + // ============================================================ + 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 ' +
+ +
+ +
+

'.$title.'

+

'.$date.'

+
+
'; + } + + // ============================================================ + function help (Doku_Renderer $renderer) { + $url = "http://admin.parlenet.org/plugins/tiledblog/"; + $renderer->doc .= + '

Help TiledBlog V2.0

'.NL. + ' '.NL. + '

'.$url.'

'.NL; + } + + // ============================================================ +} // syntax_plugin_tiledblog +?>