OK folks, It seems I did it!
It's not very universal solution because I need it just for Board3 Portal mini calendar block. But it (almost) works and that's important for now! There is a minor issue I'm not quite sure how to fix it or what's the problem. The search returns not only the posts from selected date, but also some posts before/after the selected day
Let's say, I select 13.Dec.2008 (it returns 1229130000). The date range for search is set as follow...
1229040000 - 12.12.2008 00:00:00
1229212800 - 14.12.2008 00:00:00
However, the search returns not only posts from 13.12.2008 (as expected) but also some posts started on 12.12. and 14.12. See this example...
http://ricohforum.com/phpbb/search.php? ... 1229130000
Here is what I did...
In
search.php look for this row:
Code: Select all
$search_id = request_var('search_id', '');
and insert this after it:
Code: Select all
$search_date = request_var('date', 0);
then search this:
Code: Select all
case 'newposts':
$l_search_title = $user->lang['SEARCH_NEW'];
// force sorting
$show_results = (request_var('sr', 'topics') == 'posts') ? 'posts' : 'topics';
$sort_key = 't';
$sort_dir = 'd';
$sort_by_sql['t'] = ($show_results == 'posts') ? 'p.post_time' : 't.topic_last_post_time';
$sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC');
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
$s_sort_key = $s_sort_dir = $u_sort_param = $s_limit_days = '';
if ($show_results == 'posts')
{
$sql = 'SELECT p.post_id
FROM ' . POSTS_TABLE . ' p
WHERE p.post_time > ' . $user->data['user_lastvisit'] . "
$m_approve_fid_sql
" . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . "
$sql_sort";
$field = 'post_id';
}
else
{
$sql = 'SELECT t.topic_id
FROM ' . TOPICS_TABLE . ' t
WHERE t.topic_last_post_time > ' . $user->data['user_lastvisit'] . '
AND t.topic_moved_id = 0
' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . "
$sql_sort";
$field = 'topic_id';
}
break;
and insert this after it:
Code: Select all
case 'datesearch':
$l_search_title = $user->lang['SEARCH_DATE'];
// force sorting
$show_results = (request_var('sr', 'topics') == 'posts') ? 'posts' : 'topics';
$sort_key = 't';
$sort_dir = 'd';
$sort_by_sql['t'] = ($show_results == 'posts') ? 'p.post_time' : 't.topic_last_post_time';
$sql_sort = 'ORDER BY ' . $sort_by_sql[$sort_key] . (($sort_dir == 'a') ? ' ASC' : ' DESC');
gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
$s_sort_key = $s_sort_dir = $u_sort_param = $s_limit_days = '';
// set day before (23:59:59) the selected day
// if your board time zone is different than UTC 0, you need to add/subtract the amount of secs based of your time zone settings
// for example, my board is UTC+1 then I need to subtract 3600 secs to get the time in UTC 0.
// if your board is UTC-2, you should add 3600*2
$daybefore = ($search_date - (3600-1));
// set day after the selected day
$dayafter = ($search_date + (86400-3600));
if ($show_results == 'posts')
{
$sql = 'SELECT p.post_id
FROM ' . POSTS_TABLE . ' p
WHERE p.post_time > ' . $daybefore . '
AND p.post_time < ' . $dayafter . "
$m_approve_fid_sql
" . ((sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '') . "
$sql_sort";
$field = 'post_id';
}
else
{
$sql = 'SELECT t.topic_id
FROM ' . TOPICS_TABLE . ' t
WHERE t.topic_time > ' . $daybefore . '
AND t.topic_time < ' . $dayafter . '
AND t.topic_moved_id = 0
' . str_replace(array('p.', 'post_'), array('t.', 'topic_'), $m_approve_fid_sql) . '
' . ((sizeof($ex_fid_ary)) ? 'AND ' . $db->sql_in_set('t.forum_id', $ex_fid_ary, true) : '') . "
$sql_sort";
$field = 'topic_id';
}
break;
Now in
functions.php search for:
Code: Select all
'U_SEARCH_NEW' => append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=newposts'),
and add this after it:
Code: Select all
'U_SEARCH_DATE' => append_sid("{$phpbb_root_path}search.$phpEx", 'search_id=datesearch'),
and finally, in Board3 Portal
mini_calc.php search for this:
Code: Select all
$mini_cal_day_link = '<a href="' . append_sid($phpbb_root_path . "search.$phpEx?search_id=unanswered&st=" . $nix_mini_cal_today) . '" class="' . MINI_CAL_DAY_LINK_CLASS . '" style="color: ' . $portal_config['portal_minicalendar_day_link_color'] . ';">' . ( $mini_cal_day ) . '</a>';
and replace it with this line:
Code: Select all
$mini_cal_day_link = '<a href="' . append_sid($phpbb_root_path . "search.$phpEx?search_id=datesearch&date=" . $nix_mini_cal_today) . '" class="' . MINI_CAL_DAY_LINK_CLASS . '" style="color: ' . $portal_config['portal_minicalendar_day_link_color'] . ';">' . ( $mini_cal_day ) . '</a>';
Any idea what to do to force search to return only the posts from selected date? Thank you in advance!
EDIT: corrected script to get the proper UNIX date/time range.