Skip to content

Instantly share code, notes, and snippets.

@ArthurHoaro
Last active September 2, 2017 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArthurHoaro/5d0323f758ab2401ef444a53f54e9a07 to your computer and use it in GitHub Desktop.
Save ArthurHoaro/5d0323f758ab2401ef444a53f54e9a07 to your computer and use it in GitHub Desktop.
Shaarli template cache generator
<?php
/**
* Shaarli template cache generator
*
* This script is used to generate Shaarli's RainTPL cache files for translations.
* See http://shaarli.readthedocs.io/en/master/Translations/
*
* Usage:
* 1. Remove all PHP files in <shaarli's directory>/tmp/
* 2. Put this file in your Shaarli root directory
* 3. run it in command line or visit http://<your_shaarli>/generate_templates.php
* 4. Then you can import translation strings in Poedit.
*/
require_once __DIR__ .'/vendor/autoload.php';
require_once __DIR__ .'/inc/rain.tpl.class.php';
require_once __DIR__ .'/application/Utils.php';
use \Shaarli\Config\ConfigManager;
use \Shaarli\Languages;
$conf = new ConfigManager();
new Languages(setlocale(LC_MESSAGES, 0), $conf);
RainTPL::$tpl_dir = $conf->get('resource.raintpl_tpl').'/'.$conf->get('resource.theme').'/'; // template directory
RainTPL::$cache_dir = $conf->get('resource.raintpl_tmp'); // cache directory
$templates = array_map(
function($input) {
return substr(basename($input), 0, strpos(basename($input), '.html'));
},
glob(__DIR__ .'/'. $conf->get('resource.raintpl_tpl').'/'.$conf->get('resource.theme').'/*.html')
);
$tpl = new RainTPL();
foreach ($templates as $template) {
@$tpl->draw($template, true);
}
// dummy functions to avoid fatal errors
function isLoggedIn() {}
function ban_canLogin() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment