aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorkalvn <kalvnthereal@gmail.com>2018-02-01 13:16:58 +0100
committerkalvn <kalvnthereal@gmail.com>2018-02-01 13:16:58 +0100
commit50142efd1b4b826f60b1e5673dba5ccbe26e0108 (patch)
tree6cffd9e5e733e10afcfc3010dbeeb4f08bb32f62
parent499bd43c37a6ee3d13dabe8bdd0bb449ae57122a (diff)
downloadShaarli-50142efd1b4b826f60b1e5673dba5ccbe26e0108.tar.gz
Shaarli-50142efd1b4b826f60b1e5673dba5ccbe26e0108.tar.zst
Shaarli-50142efd1b4b826f60b1e5673dba5ccbe26e0108.zip
Executes daily hooks before creating columns.
-rw-r--r--index.php29
-rw-r--r--plugins/demo_plugin/demo_plugin.php12
-rw-r--r--plugins/markdown/markdown.php23
-rw-r--r--tests/plugins/PluginMarkdownTest.php28
4 files changed, 42 insertions, 50 deletions
diff --git a/index.php b/index.php
index d57789e6..ae0ce8f0 100644
--- a/index.php
+++ b/index.php
@@ -611,6 +611,20 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager)
611 $linksToDisplay[$key]['timestamp'] = $link['created']->getTimestamp(); 611 $linksToDisplay[$key]['timestamp'] = $link['created']->getTimestamp();
612 } 612 }
613 613
614 $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000');
615 $data = array(
616 'pagetitle' => $conf->get('general.title') .' - '. format_date($dayDate, false),
617 'linksToDisplay' => $linksToDisplay,
618 'day' => $dayDate->getTimestamp(),
619 'dayDate' => $dayDate,
620 'previousday' => $previousday,
621 'nextday' => $nextday,
622 );
623
624 /* Hook is called before column construction so that plugins don't have
625 to deal with columns. */
626 $pluginManager->executeHooks('render_daily', $data, array('loggedin' => isLoggedIn()));
627
614 /* We need to spread the articles on 3 columns. 628 /* We need to spread the articles on 3 columns.
615 I did not want to use a JavaScript lib like http://masonry.desandro.com/ 629 I did not want to use a JavaScript lib like http://masonry.desandro.com/
616 so I manually spread entries with a simple method: I roughly evaluate the 630 so I manually spread entries with a simple method: I roughly evaluate the
@@ -618,7 +632,7 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager)
618 */ 632 */
619 $columns = array(array(), array(), array()); // Entries to display, for each column. 633 $columns = array(array(), array(), array()); // Entries to display, for each column.
620 $fill = array(0, 0, 0); // Rough estimate of columns fill. 634 $fill = array(0, 0, 0); // Rough estimate of columns fill.
621 foreach($linksToDisplay as $key => $link) { 635 foreach($data['linksToDisplay'] as $key => $link) {
622 // Roughly estimate length of entry (by counting characters) 636 // Roughly estimate length of entry (by counting characters)
623 // Title: 30 chars = 1 line. 1 line is 30 pixels height. 637 // Title: 30 chars = 1 line. 1 line is 30 pixels height.
624 // Description: 836 characters gives roughly 342 pixel height. 638 // Description: 836 characters gives roughly 342 pixel height.
@@ -634,18 +648,7 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager)
634 $fill[$index] += $length; 648 $fill[$index] += $length;
635 } 649 }
636 650
637 $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000'); 651 $data['cols'] = $columns;
638 $data = array(
639 'pagetitle' => $conf->get('general.title') .' - '. format_date($dayDate, false),
640 'linksToDisplay' => $linksToDisplay,
641 'cols' => $columns,
642 'day' => $dayDate->getTimestamp(),
643 'dayDate' => $dayDate,
644 'previousday' => $previousday,
645 'nextday' => $nextday,
646 );
647
648 $pluginManager->executeHooks('render_daily', $data, array('loggedin' => isLoggedIn()));
649 652
650 foreach ($data as $key => $value) { 653 foreach ($data as $key => $value) {
651 $pageBuilder->assign($key, $value); 654 $pageBuilder->assign($key, $value);
diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php
index b80a2b6d..f3a63b6a 100644
--- a/plugins/demo_plugin/demo_plugin.php
+++ b/plugins/demo_plugin/demo_plugin.php
@@ -378,17 +378,13 @@ function hook_demo_plugin_render_daily($data)
378 378
379 379
380 // Manipulate columns data 380 // Manipulate columns data
381 foreach ($data['cols'] as &$value) { 381 foreach ($data['linksToDisplay'] as &$value) {
382 foreach ($value as &$value2) { 382 $value['formatedDescription'] .= ' ಠ_ಠ';
383 $value2['formatedDescription'] .= ' ಠ_ಠ';
384 }
385 } 383 }
386 384
387 // Add plugin content at the end of each link 385 // Add plugin content at the end of each link
388 foreach ($data['cols'] as &$value) { 386 foreach ($data['linksToDisplay'] as &$value) {
389 foreach ($value as &$value2) { 387 $value['link_plugin'][] = 'DEMO';
390 $value2['link_plugin'][] = 'DEMO';
391 }
392 } 388 }
393 389
394 return $data; 390 return $data;
diff --git a/plugins/markdown/markdown.php b/plugins/markdown/markdown.php
index 1531549d..6b4aabf3 100644
--- a/plugins/markdown/markdown.php
+++ b/plugins/markdown/markdown.php
@@ -70,19 +70,18 @@ function hook_markdown_render_feed($data, $conf)
70 */ 70 */
71function hook_markdown_render_daily($data, $conf) 71function hook_markdown_render_daily($data, $conf)
72{ 72{
73 //var_dump($data);die;
73 // Manipulate columns data 74 // Manipulate columns data
74 foreach ($data['cols'] as &$value) { 75 foreach ($data['linksToDisplay'] as &$value) {
75 foreach ($value as &$value2) { 76 if (!empty($value['tags']) && noMarkdownTag($value['tags'])) {
76 if (!empty($value2['tags']) && noMarkdownTag($value2['tags'])) { 77 $value = stripNoMarkdownTag($value);
77 $value2 = stripNoMarkdownTag($value2); 78 continue;
78 continue;
79 }
80 $value2['formatedDescription'] = process_markdown(
81 $value2['formatedDescription'],
82 $conf->get('security.markdown_escape', true),
83 $conf->get('security.allowed_protocols')
84 );
85 } 79 }
80 $value['formatedDescription'] = process_markdown(
81 $value['formatedDescription'],
82 $conf->get('security.markdown_escape', true),
83 $conf->get('security.allowed_protocols')
84 );
86 } 85 }
87 86
88 return $data; 87 return $data;
@@ -136,7 +135,7 @@ function hook_markdown_render_includes($data)
136 || $data['_PAGE_'] == Router::$PAGE_DAILY 135 || $data['_PAGE_'] == Router::$PAGE_DAILY
137 || $data['_PAGE_'] == Router::$PAGE_EDITLINK 136 || $data['_PAGE_'] == Router::$PAGE_EDITLINK
138 ) { 137 ) {
139 138
140 $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/markdown/markdown.css'; 139 $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/markdown/markdown.css';
141 } 140 }
142 141
diff --git a/tests/plugins/PluginMarkdownTest.php b/tests/plugins/PluginMarkdownTest.php
index 96891f1f..ddc2728d 100644
--- a/tests/plugins/PluginMarkdownTest.php
+++ b/tests/plugins/PluginMarkdownTest.php
@@ -58,20 +58,17 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
58 $markdown = '# My title' . PHP_EOL . 'Very interesting content.'; 58 $markdown = '# My title' . PHP_EOL . 'Very interesting content.';
59 $data = array( 59 $data = array(
60 // Columns data 60 // Columns data
61 'cols' => array( 61 'linksToDisplay' => array(
62 // First, second, third. 62 // nth link
63 0 => array( 63 0 => array(
64 // nth link 64 'formatedDescription' => $markdown,
65 0 => array(
66 'formatedDescription' => $markdown,
67 ),
68 ), 65 ),
69 ), 66 ),
70 ); 67 );
71 68
72 $data = hook_markdown_render_daily($data, $this->conf); 69 $data = hook_markdown_render_daily($data, $this->conf);
73 $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<h1>')); 70 $this->assertNotFalse(strpos($data['linksToDisplay'][0]['formatedDescription'], '<h1>'));
74 $this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<p>')); 71 $this->assertNotFalse(strpos($data['linksToDisplay'][0]['formatedDescription'], '<p>'));
75 } 72 }
76 73
77 /** 74 /**
@@ -148,21 +145,18 @@ class PluginMarkdownTest extends PHPUnit_Framework_TestCase
148 145
149 $data = array( 146 $data = array(
150 // Columns data 147 // Columns data
151 'cols' => array( 148 'linksToDisplay' => array(
152 // First, second, third. 149 // nth link
153 0 => array( 150 0 => array(
154 // nth link 151 'formatedDescription' => $str,
155 0 => array( 152 'tags' => NO_MD_TAG,
156 'formatedDescription' => $str, 153 'taglist' => array(),
157 'tags' => NO_MD_TAG,
158 'taglist' => array(),
159 ),
160 ), 154 ),
161 ), 155 ),
162 ); 156 );
163 157
164 $data = hook_markdown_render_daily($data, $this->conf); 158 $data = hook_markdown_render_daily($data, $this->conf);
165 $this->assertEquals($str, $data['cols'][0][0]['formatedDescription']); 159 $this->assertEquals($str, $data['linksToDisplay'][0]['formatedDescription']);
166 } 160 }
167 161
168 /** 162 /**