]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Improve theme dependent plugin placeholders: 679/head
authorArthurHoaro <arthur@hoa.ro>
Thu, 1 Dec 2016 10:38:21 +0000 (11:38 +0100)
committerArthurHoaro <arthur@hoa.ro>
Thu, 1 Dec 2016 10:38:21 +0000 (11:38 +0100)
  - 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 [deleted file]
plugins/addlink_toolbar/addlink_toolbar.html [deleted file]
plugins/addlink_toolbar/addlink_toolbar.php
plugins/demo_plugin/custom_demo.css
plugins/demo_plugin/demo_plugin.php
plugins/playvideos/playvideos.html [deleted file]
plugins/playvideos/playvideos.php
tpl/linklist.html
tpl/linklist.paging.html
tpl/page.header.html

diff --git a/plugins/addlink_toolbar/addlink_toolbar.css b/plugins/addlink_toolbar/addlink_toolbar.css
deleted file mode 100644 (file)
index b6a612f..0000000
+++ /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 (file)
index f38c41a..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<div id="addlink_toolbar">
-    <form method="GET" action="" name="addform" class="addform">
-        <input type="text" name="post" placeholder="URI">
-        <input type="submit" value="Add link" class="bigbutton">
-    </form>
-</div>
\ No newline at end of file
index cfd74207b031e51eb27ccecb83dc6e0bfd679388..bf8a198a4ed41a44c86320c71117a525f085df7e 100644 (file)
 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;
index af5e8bf95e7f83e520d3b36df3f0d8fe3f0b3d50..95019e28b8ed9bad6cb280b916b4e262df31e9d9 100644 (file)
@@ -2,10 +2,6 @@
     color: red;
 }
 
-.upper_plugin_demo {
-    float: left;
-}
-
 #demo_marquee {
        background: darkmagenta;
        color: white;
index 7335c9d4665a0429549d7fd3977ca961f81e58fa..8fdbf66383c144226770cc03334701801e7f5da8 100644 (file)
@@ -50,15 +50,68 @@ function hook_demo_plugin_render_header($data)
 
         // If loggedin
         if ($data['_LOGGEDIN_'] === true) {
-            // Buttons in toolbar
-            $data['buttons_toolbar'][] = '<li><a href="#">DEMO_buttons_toolbar</a></li>';
+            /*
+             * 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 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' => '?',
+                'class' => 'addform',
+            ),
+            'inputs' => array(
+                array(
+                    'type' => 'text',
+                    'name' => 'demo',
+                    'placeholder' => 'demo',
+                )
+            )
+        );
+        $data['fields_toolbar'][] = $form;
     }
     // Another button always displayed
-    $data['buttons_toolbar'][] = '<li><a href="#">DEMO</a></li>';
+    $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'][] = '<div class="upper_plugin_demo"><a href="?up" title="Uppercase!">←</a></div>';
+    /*
+     * 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 (file)
index fda3d54..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<a href="#" id="playvideos">► Play Videos</a>
\ No newline at end of file
index 7645b778b9c1c2f7768be95658c6cc6ae84d598b..644845049ff6599407fc43f9c5d99a9c0d4efd81 100644 (file)
 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;
index ddfd729ac9500dd3a534e8a3927af8243f38a329..3fe86deba1af17b85e378f513bddb45200090907 100644 (file)
             <input type="submit" value="Search" class="bigbutton">
         </form>
         {loop="$plugins_header.fields_toolbar"}
-            {$value}
+            <form
+                {loop="$value.attr"}
+                    {$key}="{$value}"
+                {/loop}>
+                {loop="$value.inputs"}
+                    <input
+                    {loop="$value"}
+                        {$key}="{$value}"
+                    {/loop}>
+                {/loop}
+            </form>
         {/loop}
     </div>
 </div>
index e91c8f86b66bbcc88f74ea318013c67656f513ef..86019c01ee2a5cb4ddd2a9f8b50b59c694b00e2c 100644 (file)
     </div>
 {/if}
     {loop="$action_plugin"}
-        {$value}
+      <div class="paging_privatelinks">
+        <a
+          {loop="$value.attr"}
+            {$key}="{$value}"
+          {/loop}>
+          {$value.html}
+        </a>
+      </div>
     {/loop}
     <div class="paging_linksperpage">
         Links per page: <a href="?linksperpage=20">20</a> <a href="?linksperpage=50">50</a> <a href="?linksperpage=100">100</a>
index eac2ed4aa5acc20ad55d626f0030d1cf85897038..cce61ec464b8e54c8e1897a986634b5044237b7d 100644 (file)
     <li><a href="?do=picwall{$searchcrits}">Picture wall</a></li>
     <li><a href="?do=daily">Daily</a></li>
     {loop="$plugins_header.buttons_toolbar"}
-        {$value}
+        <li><a
+            {loop="$value.attr"}
+                {$key}="{$value}"
+            {/loop}>
+            {$value.html}
+        </a></li>
     {/loop}
 {/if}
   </ul>