diff options
-rw-r--r-- | index.php | 29 | ||||
-rw-r--r-- | plugins/demo_plugin/demo_plugin.php | 12 | ||||
-rw-r--r-- | plugins/markdown/markdown.php | 23 | ||||
-rw-r--r-- | tests/plugins/PluginMarkdownTest.php | 28 |
4 files changed, 42 insertions, 50 deletions
@@ -616,6 +616,20 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager) | |||
616 | $linksToDisplay[$key]['timestamp'] = $link['created']->getTimestamp(); | 616 | $linksToDisplay[$key]['timestamp'] = $link['created']->getTimestamp(); |
617 | } | 617 | } |
618 | 618 | ||
619 | $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000'); | ||
620 | $data = array( | ||
621 | 'pagetitle' => $conf->get('general.title') .' - '. format_date($dayDate, false), | ||
622 | 'linksToDisplay' => $linksToDisplay, | ||
623 | 'day' => $dayDate->getTimestamp(), | ||
624 | 'dayDate' => $dayDate, | ||
625 | 'previousday' => $previousday, | ||
626 | 'nextday' => $nextday, | ||
627 | ); | ||
628 | |||
629 | /* Hook is called before column construction so that plugins don't have | ||
630 | to deal with columns. */ | ||
631 | $pluginManager->executeHooks('render_daily', $data, array('loggedin' => isLoggedIn())); | ||
632 | |||
619 | /* We need to spread the articles on 3 columns. | 633 | /* We need to spread the articles on 3 columns. |
620 | I did not want to use a JavaScript lib like http://masonry.desandro.com/ | 634 | I did not want to use a JavaScript lib like http://masonry.desandro.com/ |
621 | so I manually spread entries with a simple method: I roughly evaluate the | 635 | so I manually spread entries with a simple method: I roughly evaluate the |
@@ -623,7 +637,7 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager) | |||
623 | */ | 637 | */ |
624 | $columns = array(array(), array(), array()); // Entries to display, for each column. | 638 | $columns = array(array(), array(), array()); // Entries to display, for each column. |
625 | $fill = array(0, 0, 0); // Rough estimate of columns fill. | 639 | $fill = array(0, 0, 0); // Rough estimate of columns fill. |
626 | foreach($linksToDisplay as $key => $link) { | 640 | foreach($data['linksToDisplay'] as $key => $link) { |
627 | // Roughly estimate length of entry (by counting characters) | 641 | // Roughly estimate length of entry (by counting characters) |
628 | // Title: 30 chars = 1 line. 1 line is 30 pixels height. | 642 | // Title: 30 chars = 1 line. 1 line is 30 pixels height. |
629 | // Description: 836 characters gives roughly 342 pixel height. | 643 | // Description: 836 characters gives roughly 342 pixel height. |
@@ -639,18 +653,7 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager) | |||
639 | $fill[$index] += $length; | 653 | $fill[$index] += $length; |
640 | } | 654 | } |
641 | 655 | ||
642 | $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000'); | 656 | $data['cols'] = $columns; |
643 | $data = array( | ||
644 | 'pagetitle' => $conf->get('general.title') .' - '. format_date($dayDate, false), | ||
645 | 'linksToDisplay' => $linksToDisplay, | ||
646 | 'cols' => $columns, | ||
647 | 'day' => $dayDate->getTimestamp(), | ||
648 | 'dayDate' => $dayDate, | ||
649 | 'previousday' => $previousday, | ||
650 | 'nextday' => $nextday, | ||
651 | ); | ||
652 | |||
653 | $pluginManager->executeHooks('render_daily', $data, array('loggedin' => isLoggedIn())); | ||
654 | 657 | ||
655 | foreach ($data as $key => $value) { | 658 | foreach ($data as $key => $value) { |
656 | $pageBuilder->assign($key, $value); | 659 | $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 | */ |
71 | function hook_markdown_render_daily($data, $conf) | 71 | function 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 | /** |