Merge pull request #1074 from kalvn/feature/dailymarkdown

Executes daily hooks before creating columns.
This commit is contained in:
ArthurHoaro 2018-02-02 19:23:26 +01:00 committed by GitHub
commit a381c373b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 50 deletions

View file

@ -616,6 +616,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
@ -623,7 +637,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.
@ -639,18 +653,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);

View 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;

View 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';
}

View 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']);
}
/**