/**
* Demo Plugin.
*
- * This plugin try to cover Shaarli's plugin API entirely.
- * Can be used by plugin developper to make their own.
+ * This plugin tries to completely cover Shaarli's plugin API.
+ * Can be used by plugin developers to make their own plugin.
*/
/*
*/
use Shaarli\Config\ConfigManager;
+use Shaarli\Plugin\PluginManager;
+use Shaarli\Render\TemplatePage;
/**
* In the footer hook, there is a working example of a translation extension for Shaarli.
/**
* Hook render_header.
- * Executed on every page redering.
+ * Executed on every page render.
*
* Template placeholders:
* - buttons_toolbar
function hook_demo_plugin_render_header($data)
{
// Only execute when linklist is rendered.
- if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) {
-
+ if ($data['_PAGE_'] == TemplatePage::LINKLIST) {
// If loggedin
if ($data['_LOGGEDIN_'] === true) {
/*
* ],
* ]
* This example renders as:
- * <form form-attribute-1="form attribute 1 value" form-attribute-2="form attribute 2 value">
- * <input input-1-attribute-1="input 1 attribute 1 value" input-1-attribute-2="input 1 attribute 2 value">
- * <input input-2-attribute-1="input 2 attribute 1 value">
- * </form>
+ * <form form-attribute-1="form attribute 1 value" form-attribute-2="form attribute 2 value">
+ * <input input-1-attribute-1="input 1 attribute 1 value" input-1-attribute-2="input 1 attribute 2 value">
+ * <input input-2-attribute-1="input 2 attribute 1 value">
+ * </form>
*/
$form = array(
'attr' => array(
'method' => 'GET',
- 'action' => '?',
+ 'action' => $data['_BASE_PATH_'] . '/',
'class' => 'addform',
),
'inputs' => array(
/**
* Hook render_includes.
- * Executed on every page redering.
+ * Executed on every page render.
*
* Template placeholders:
* - css_files
/**
* Hook render_footer.
- * Executed on every page redering.
+ * Executed on every page render.
*
* Template placeholders:
* - text
*/
function hook_demo_plugin_render_footer($data)
{
- // footer text
+ // Footer text
$data['text'][] = '<br>'. demo_plugin_t('Shaarli is now enhanced by the awesome demo_plugin.');
// Free elements at the end of the page.
// Load HTML into a string
$html = file_get_contents(PluginManager::$PLUGINS_PATH .'/demo_plugin/field.html');
- // replace value in HTML if it exists in $data
+ // Replace value in HTML if it exists in $data
if (!empty($data['link']['stuff'])) {
$html = sprintf($html, $data['link']['stuff']);
} else {
*/
function hook_demo_plugin_render_picwall($data)
{
- // plugin_start_zone
$data['plugin_start_zone'][] = '<center>BEFORE</center>';
- // plugin_end_zone
$data['plugin_end_zone'][] = '<center>AFTER</center>';
return $data;
*/
function hook_demo_plugin_render_tagcloud($data)
{
- // plugin_start_zone
$data['plugin_start_zone'][] = '<center>BEFORE</center>';
- // plugin_end_zone
$data['plugin_end_zone'][] = '<center>AFTER</center>';
return $data;
*/
function hook_demo_plugin_render_daily($data)
{
- // plugin_start_zone
$data['plugin_start_zone'][] = '<center>BEFORE</center>';
- // plugin_end_zone
$data['plugin_end_zone'][] = '<center>AFTER</center>';
// Manipulate columns data
- foreach ($data['cols'] as &$value) {
- foreach ($value as &$value2) {
- $value2['formatedDescription'] .= ' ಠ_ಠ';
- }
+ foreach ($data['linksToDisplay'] as &$value) {
+ $value['formatedDescription'] .= ' ಠ_ಠ';
}
// Add plugin content at the end of each link
- foreach ($data['cols'] as &$value) {
- foreach ($value as &$value2) {
- $value2['link_plugin'][] = 'DEMO';
- }
+ foreach ($data['linksToDisplay'] as &$value) {
+ $value['link_plugin'][] = 'DEMO';
}
return $data;
function hook_demo_plugin_render_feed($data)
{
foreach ($data['links'] as &$link) {
- if ($data['_PAGE_'] == Router::$PAGE_FEED_ATOM) {
+ if ($data['_PAGE_'] == TemplatePage::FEED_ATOM) {
$link['description'] .= ' - ATOM Feed' ;
- }
- elseif ($data['_PAGE_'] == Router::$PAGE_FEED_RSS) {
+ } elseif ($data['_PAGE_'] == TemplatePage::FEED_RSS) {
$link['description'] .= ' - RSS Feed';
}
}
return $data;
}
+/**
+ * When plugin parameters are saved.
+ *
+ * @param array $data $_POST array
+ *
+ * @return array Updated $_POST array
+ */
+function hook_demo_plugin_save_plugin_parameters($data)
+{
+ // Here we edit the provided value.
+ // This hook can also be used to generate config files, etc.
+ if (! empty($data['DEMO_PLUGIN_PARAMETER']) && ! endsWith($data['DEMO_PLUGIN_PARAMETER'], '_SUFFIX')) {
+ $data['DEMO_PLUGIN_PARAMETER'] .= '_SUFFIX';
+ }
+
+ return $data;
+}
+
/**
* This function is never called, but contains translation calls for GNU gettext extraction.
*/
{
// meta
t('A demo plugin covering all use cases for template designers and plugin developers.');
+ t('This is a parameter dedicated to the demo plugin. It\'ll be suffixed.');
+ t('Other demo parameter');
}