From ba0fd80732acbff0fcda57a0b31e4edfaa337001 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 1 Dec 2016 11:38:21 +0100 Subject: [PATCH] Improve theme dependent plugin placeholders: - buttons_toolbar: now expect links represented by an array instead of HTML content - fields_toolbar: now expect a form represented by an array instead of HTML content - action_plugin: now expect links represented by an array instead of HTML content Default templates updated accordingly mprove theme dependent plugin placeholders: --- plugins/addlink_toolbar/addlink_toolbar.css | 4 - plugins/addlink_toolbar/addlink_toolbar.html | 6 -- plugins/addlink_toolbar/addlink_toolbar.php | 22 +++++- plugins/demo_plugin/custom_demo.css | 4 - plugins/demo_plugin/demo_plugin.php | 82 ++++++++++++++++++-- plugins/playvideos/playvideos.html | 1 - plugins/playvideos/playvideos.php | 10 ++- tpl/linklist.html | 12 ++- tpl/linklist.paging.html | 9 ++- tpl/page.header.html | 7 +- 10 files changed, 130 insertions(+), 27 deletions(-) delete mode 100644 plugins/addlink_toolbar/addlink_toolbar.css delete mode 100644 plugins/addlink_toolbar/addlink_toolbar.html delete mode 100644 plugins/playvideos/playvideos.html diff --git a/plugins/addlink_toolbar/addlink_toolbar.css b/plugins/addlink_toolbar/addlink_toolbar.css deleted file mode 100644 index b6a612f0..00000000 --- a/plugins/addlink_toolbar/addlink_toolbar.css +++ /dev/null @@ -1,4 +0,0 @@ -#addlink_toolbar { - display: inline; - margin: 0 0 0 25px; -} \ No newline at end of file diff --git a/plugins/addlink_toolbar/addlink_toolbar.html b/plugins/addlink_toolbar/addlink_toolbar.html deleted file mode 100644 index f38c41a0..00000000 --- a/plugins/addlink_toolbar/addlink_toolbar.html +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file diff --git a/plugins/addlink_toolbar/addlink_toolbar.php b/plugins/addlink_toolbar/addlink_toolbar.php index cfd74207..bf8a198a 100644 --- a/plugins/addlink_toolbar/addlink_toolbar.php +++ b/plugins/addlink_toolbar/addlink_toolbar.php @@ -15,7 +15,27 @@ function hook_addlink_toolbar_render_header($data) { if ($data['_PAGE_'] == Router::$PAGE_LINKLIST && $data['_LOGGEDIN_'] === true) { - $data['fields_toolbar'][] = file_get_contents(PluginManager::$PLUGINS_PATH . '/addlink_toolbar/addlink_toolbar.html'); + $form = array( + 'attr' => array( + 'method' => 'GET', + 'action' => '', + 'name' => 'addform', + 'class' => 'addform', + ), + 'inputs' => array( + array( + 'type' => 'text', + 'name' => 'post', + 'placeholder' => 'URI', + ), + array( + 'type' => 'submit', + 'value' => 'Add link', + 'class' => 'bigbutton', + ), + ), + ); + $data['fields_toolbar'][] = $form; } return $data; diff --git a/plugins/demo_plugin/custom_demo.css b/plugins/demo_plugin/custom_demo.css index af5e8bf9..95019e28 100644 --- a/plugins/demo_plugin/custom_demo.css +++ b/plugins/demo_plugin/custom_demo.css @@ -2,10 +2,6 @@ color: red; } -.upper_plugin_demo { - float: left; -} - #demo_marquee { background: darkmagenta; color: white; diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index 7335c9d4..8fdbf663 100644 --- a/plugins/demo_plugin/demo_plugin.php +++ b/plugins/demo_plugin/demo_plugin.php @@ -50,15 +50,68 @@ function hook_demo_plugin_render_header($data) // If loggedin if ($data['_LOGGEDIN_'] === true) { - // Buttons in toolbar - $data['buttons_toolbar'][] = '
  • DEMO_buttons_toolbar
  • '; + /* + * Links in toolbar: + * A link is an array of its attributes (key="value"), + * and a mandatory `html` key, which contains its value. + */ + $button = array( + 'attr' => array ( + 'href' => '#', + 'class' => 'mybutton', + 'title' => 'hover me', + ), + 'html' => 'DEMO buttons toolbar', + ); + $data['buttons_toolbar'][] = $button; } - // Fields in toolbar - $data['fields_toolbar'][] = 'DEMO_fields_toolbar'; + /* + * Add additional input fields in the tools. + * A field is an array containing: + * [ + * 'form-attribute-1' => 'form attribute 1 value', + * 'form-attribute-2' => 'form attribute 2 value', + * 'inputs' => [ + * [ + * 'input-1-attribute-1 => 'input 1 attribute 1 value', + * 'input-1-attribute-2 => 'input 1 attribute 2 value', + * ], + * [ + * 'input-2-attribute-1 => 'input 2 attribute 1 value', + * ], + * ], + * ] + * This example renders as: + *
    + * + * + *
    + */ + $form = array( + 'attr' => array( + 'method' => 'GET', + 'action' => '?', + 'class' => 'addform', + ), + 'inputs' => array( + array( + 'type' => 'text', + 'name' => 'demo', + 'placeholder' => 'demo', + ) + ) + ); + $data['fields_toolbar'][] = $form; } // Another button always displayed - $data['buttons_toolbar'][] = '
  • DEMO
  • '; + $button = array( + 'attr' => array( + 'href' => '#', + ), + 'html' => 'Demo', + ); + $data['buttons_toolbar'][] = $button; return $data; } @@ -143,8 +196,19 @@ function hook_demo_plugin_render_footer($data) */ function hook_demo_plugin_render_linklist($data) { - // action_plugin - $data['action_plugin'][] = '
    ←
    '; + /* + * Action links (action_plugin): + * A link is an array of its attributes (key="value"), + * and a mandatory `html` key, which contains its value. + * It's also recommended to add key 'on' or 'off' for theme rendering. + */ + $action = array( + 'attr' => array( + 'href' => '?up', + 'title' => 'Uppercase!', + ), + 'html' => '←', + ); if (isset($_GET['up'])) { // Manipulate link data @@ -152,7 +216,11 @@ function hook_demo_plugin_render_linklist($data) $value['description'] = strtoupper($value['description']); $value['title'] = strtoupper($value['title']); } + $action['on'] = true; + } else { + $action['off'] = true; } + $data['action_plugin'][] = $action; // link_plugin (for each link) foreach ($data['links'] as &$value) { diff --git a/plugins/playvideos/playvideos.html b/plugins/playvideos/playvideos.html deleted file mode 100644 index fda3d54f..00000000 --- a/plugins/playvideos/playvideos.html +++ /dev/null @@ -1 +0,0 @@ -► Play Videos \ No newline at end of file diff --git a/plugins/playvideos/playvideos.php b/plugins/playvideos/playvideos.php index 7645b778..64484504 100644 --- a/plugins/playvideos/playvideos.php +++ b/plugins/playvideos/playvideos.php @@ -16,7 +16,15 @@ function hook_playvideos_render_header($data) { if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) { - $data['buttons_toolbar'][] = file_get_contents(PluginManager::$PLUGINS_PATH . '/playvideos/playvideos.html'); + $playvideo = array( + 'attr' => array( + 'href' => '#', + 'title' => 'Video player', + 'id' => 'playvideos', + ), + 'html' => '► Play Videos' + ); + $data['buttons_toolbar'][] = $playvideo; } return $data; diff --git a/tpl/linklist.html b/tpl/linklist.html index ddfd729a..3fe86deb 100644 --- a/tpl/linklist.html +++ b/tpl/linklist.html @@ -28,7 +28,17 @@ {loop="$plugins_header.fields_toolbar"} - {$value} +
    + {loop="$value.inputs"} + + {/loop} +
    {/loop} diff --git a/tpl/linklist.paging.html b/tpl/linklist.paging.html index e91c8f86..86019c01 100644 --- a/tpl/linklist.paging.html +++ b/tpl/linklist.paging.html @@ -13,7 +13,14 @@ {/if} {loop="$action_plugin"} - {$value} + {/loop}
    Links per page: 20 50 100 diff --git a/tpl/page.header.html b/tpl/page.header.html index eac2ed4a..cce61ec4 100644 --- a/tpl/page.header.html +++ b/tpl/page.header.html @@ -35,7 +35,12 @@
  • Picture wall
  • Daily
  • {loop="$plugins_header.buttons_toolbar"} - {$value} +
  • + {$value.html} +
  • {/loop} {/if} -- 2.41.0