Executes daily hooks before creating columns.
This commit is contained in:
parent
499bd43c37
commit
50142efd1b
4 changed files with 42 additions and 50 deletions
29
index.php
29
index.php
|
@ -611,6 +611,20 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager)
|
||||||
$linksToDisplay[$key]['timestamp'] = $link['created']->getTimestamp();
|
$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.
|
/* We need to spread the articles on 3 columns.
|
||||||
I did not want to use a JavaScript lib like http://masonry.desandro.com/
|
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
|
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.
|
$columns = array(array(), array(), array()); // Entries to display, for each column.
|
||||||
$fill = array(0, 0, 0); // Rough estimate of columns fill.
|
$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)
|
// Roughly estimate length of entry (by counting characters)
|
||||||
// Title: 30 chars = 1 line. 1 line is 30 pixels height.
|
// Title: 30 chars = 1 line. 1 line is 30 pixels height.
|
||||||
// Description: 836 characters gives roughly 342 pixel height.
|
// Description: 836 characters gives roughly 342 pixel height.
|
||||||
|
@ -634,18 +648,7 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager)
|
||||||
$fill[$index] += $length;
|
$fill[$index] += $length;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000');
|
$data['cols'] = $columns;
|
||||||
$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()));
|
|
||||||
|
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
$pageBuilder->assign($key, $value);
|
$pageBuilder->assign($key, $value);
|
||||||
|
|
|
@ -378,17 +378,13 @@ function hook_demo_plugin_render_daily($data)
|
||||||
|
|
||||||
|
|
||||||
// Manipulate columns data
|
// Manipulate columns data
|
||||||
foreach ($data['cols'] as &$value) {
|
foreach ($data['linksToDisplay'] as &$value) {
|
||||||
foreach ($value as &$value2) {
|
$value['formatedDescription'] .= ' ಠ_ಠ';
|
||||||
$value2['formatedDescription'] .= ' ಠ_ಠ';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add plugin content at the end of each link
|
// Add plugin content at the end of each link
|
||||||
foreach ($data['cols'] as &$value) {
|
foreach ($data['linksToDisplay'] as &$value) {
|
||||||
foreach ($value as &$value2) {
|
$value['link_plugin'][] = 'DEMO';
|
||||||
$value2['link_plugin'][] = 'DEMO';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
|
|
@ -70,20 +70,19 @@ function hook_markdown_render_feed($data, $conf)
|
||||||
*/
|
*/
|
||||||
function hook_markdown_render_daily($data, $conf)
|
function hook_markdown_render_daily($data, $conf)
|
||||||
{
|
{
|
||||||
|
//var_dump($data);die;
|
||||||
// Manipulate columns data
|
// Manipulate columns data
|
||||||
foreach ($data['cols'] as &$value) {
|
foreach ($data['linksToDisplay'] as &$value) {
|
||||||
foreach ($value as &$value2) {
|
if (!empty($value['tags']) && noMarkdownTag($value['tags'])) {
|
||||||
if (!empty($value2['tags']) && noMarkdownTag($value2['tags'])) {
|
$value = stripNoMarkdownTag($value);
|
||||||
$value2 = stripNoMarkdownTag($value2);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$value2['formatedDescription'] = process_markdown(
|
$value['formatedDescription'] = process_markdown(
|
||||||
$value2['formatedDescription'],
|
$value['formatedDescription'],
|
||||||
$conf->get('security.markdown_escape', true),
|
$conf->get('security.markdown_escape', true),
|
||||||
$conf->get('security.allowed_protocols')
|
$conf->get('security.allowed_protocols')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,20 +58,17 @@ public function testMarkdownDaily()
|
||||||
$markdown = '# My title' . PHP_EOL . 'Very interesting content.';
|
$markdown = '# My title' . PHP_EOL . 'Very interesting content.';
|
||||||
$data = array(
|
$data = array(
|
||||||
// Columns data
|
// Columns data
|
||||||
'cols' => array(
|
'linksToDisplay' => array(
|
||||||
// First, second, third.
|
|
||||||
0 => array(
|
|
||||||
// nth link
|
// nth link
|
||||||
0 => array(
|
0 => array(
|
||||||
'formatedDescription' => $markdown,
|
'formatedDescription' => $markdown,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$data = hook_markdown_render_daily($data, $this->conf);
|
$data = hook_markdown_render_daily($data, $this->conf);
|
||||||
$this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<h1>'));
|
$this->assertNotFalse(strpos($data['linksToDisplay'][0]['formatedDescription'], '<h1>'));
|
||||||
$this->assertNotFalse(strpos($data['cols'][0][0]['formatedDescription'], '<p>'));
|
$this->assertNotFalse(strpos($data['linksToDisplay'][0]['formatedDescription'], '<p>'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,9 +145,7 @@ public function testNoMarkdownTag()
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
// Columns data
|
// Columns data
|
||||||
'cols' => array(
|
'linksToDisplay' => array(
|
||||||
// First, second, third.
|
|
||||||
0 => array(
|
|
||||||
// nth link
|
// nth link
|
||||||
0 => array(
|
0 => array(
|
||||||
'formatedDescription' => $str,
|
'formatedDescription' => $str,
|
||||||
|
@ -158,11 +153,10 @@ public function testNoMarkdownTag()
|
||||||
'taglist' => array(),
|
'taglist' => array(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$data = hook_markdown_render_daily($data, $this->conf);
|
$data = hook_markdown_render_daily($data, $this->conf);
|
||||||
$this->assertEquals($str, $data['cols'][0][0]['formatedDescription']);
|
$this->assertEquals($str, $data['linksToDisplay'][0]['formatedDescription']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue