]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Executes daily hooks before creating columns. 1074/head
authorkalvn <kalvnthereal@gmail.com>
Thu, 1 Feb 2018 12:16:58 +0000 (13:16 +0100)
committerkalvn <kalvnthereal@gmail.com>
Thu, 1 Feb 2018 12:16:58 +0000 (13:16 +0100)
index.php
plugins/demo_plugin/demo_plugin.php
plugins/markdown/markdown.php
tests/plugins/PluginMarkdownTest.php

index d57789e656749c248fbffe1e60a862b0aad4fbe6..ae0ce8f0e738fa6204b12fbfca3b1ef99b403391 100644 (file)
--- a/index.php
+++ b/index.php
@@ -611,6 +611,20 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager)
         $linksToDisplay[$key]['timestamp'] =  $link['created']->getTimestamp();
     }
 
+    $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000');
+    $data = array(
+        'pagetitle' => $conf->get('general.title') .' - '. format_date($dayDate, false),
+        'linksToDisplay' => $linksToDisplay,
+        'day' => $dayDate->getTimestamp(),
+        'dayDate' => $dayDate,
+        'previousday' => $previousday,
+        'nextday' => $nextday,
+    );
+
+    /* Hook is called before column construction so that plugins don't have
+       to deal with columns. */
+    $pluginManager->executeHooks('render_daily', $data, array('loggedin' => isLoggedIn()));
+
     /* We need to spread the articles on 3 columns.
        I did not want to use a JavaScript lib like http://masonry.desandro.com/
        so I manually spread entries with a simple method: I roughly evaluate the
@@ -618,7 +632,7 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager)
     */
     $columns = array(array(), array(), array()); // Entries to display, for each column.
     $fill = array(0, 0, 0);  // Rough estimate of columns fill.
-    foreach($linksToDisplay as $key => $link) {
+    foreach($data['linksToDisplay'] as $key => $link) {
         // Roughly estimate length of entry (by counting characters)
         // Title: 30 chars = 1 line. 1 line is 30 pixels height.
         // Description: 836 characters gives roughly 342 pixel height.
@@ -634,18 +648,7 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager)
         $fill[$index] += $length;
     }
 
-    $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000');
-    $data = array(
-        'pagetitle' => $conf->get('general.title') .' - '. format_date($dayDate, false),
-        'linksToDisplay' => $linksToDisplay,
-        'cols' => $columns,
-        'day' => $dayDate->getTimestamp(),
-        'dayDate' => $dayDate,
-        'previousday' => $previousday,
-        'nextday' => $nextday,
-    );
-
-    $pluginManager->executeHooks('render_daily', $data, array('loggedin' => isLoggedIn()));
+    $data['cols'] = $columns;
 
     foreach ($data as $key => $value) {
         $pageBuilder->assign($key, $value);
index b80a2b6d5175bfb57d8dcf9774c4336357807c5b..f3a63b6aeb26a9a003271f981e16ac32761623d6 100644 (file)
@@ -378,17 +378,13 @@ function hook_demo_plugin_render_daily($data)
 
 
     // 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;
index 1531549d8f613e594b6fd36259e3e825932ea43e..6b4aabf3ae8ad6798ab40bb12ba8b499c7b13609 100644 (file)
@@ -70,19 +70,18 @@ function hook_markdown_render_feed($data, $conf)
  */
 function hook_markdown_render_daily($data, $conf)
 {
+    //var_dump($data);die;
     // Manipulate columns data
-    foreach ($data['cols'] as &$value) {
-        foreach ($value as &$value2) {
-            if (!empty($value2['tags']) && noMarkdownTag($value2['tags'])) {
-                $value2 = stripNoMarkdownTag($value2);
-                continue;
-            }
-            $value2['formatedDescription'] = process_markdown(
-                $value2['formatedDescription'],
-                $conf->get('security.markdown_escape', true),
-                $conf->get('security.allowed_protocols')
-            );
+    foreach ($data['linksToDisplay'] as &$value) {
+        if (!empty($value['tags']) && noMarkdownTag($value['tags'])) {
+            $value = stripNoMarkdownTag($value);
+            continue;
         }
+        $value['formatedDescription'] = process_markdown(
+            $value['formatedDescription'],
+            $conf->get('security.markdown_escape', true),
+            $conf->get('security.allowed_protocols')
+        );
     }
 
     return $data;
@@ -136,7 +135,7 @@ function hook_markdown_render_includes($data)
         || $data['_PAGE_'] == Router::$PAGE_DAILY
         || $data['_PAGE_'] == Router::$PAGE_EDITLINK
     ) {
-        
+
         $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/markdown/markdown.css';
     }
 
index 96891f1f39788b96faaf27f2a9a9a07609c3ab68..ddc2728d3ae22542f82dd9bd158de7a1bab73ec0 100644 (file)
@@ -58,20 +58,17 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
         $markdown = '# My title' . PHP_EOL . 'Very interesting content.';
         $data = array(
             // Columns data
-            'cols' => array(
-                // First, second, third.
+            'linksToDisplay' => array(
+                // nth link
                 0 => array(
-                    // nth link
-                    0 => array(
-                        'formatedDescription' => $markdown,
-                    ),
+                    'formatedDescription' => $markdown,
                 ),
             ),
         );
 
         $data = hook_markdown_render_daily($data, $this->conf);
-        $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<h1>'));
-        $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<p>'));
+        $this->assertNotFalse(strpos($data['linksToDisplay'][0]['formatedDescription'], '<h1>'));
+        $this->assertNotFalse(strpos($data['linksToDisplay'][0]['formatedDescription'], '<p>'));
     }
 
     /**
@@ -148,21 +145,18 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
 
         $data = array(
             // Columns data
-            'cols' => array(
-                // First, second, third.
+            'linksToDisplay' => array(
+                // nth link
                 0 => array(
-                    // nth link
-                    0 => array(
-                        'formatedDescription' => $str,
-                        'tags' => NO_MD_TAG,
-                        'taglist' => array(),
-                    ),
+                    'formatedDescription' => $str,
+                    'tags' => NO_MD_TAG,
+                    'taglist' => array(),
                 ),
             ),
         );
 
         $data = hook_markdown_render_daily($data, $this->conf);
-        $this->assertEquals($str, $data['cols'][0][0]['formatedDescription']);
+        $this->assertEquals($str, $data['linksToDisplay'][0]['formatedDescription']);
     }
 
     /**