Commit 49fc2e71 authored by nyloth's avatar nyloth

[MOD] articles: change list_articles() API to handle $date_min and $date_max...

[MOD] articles: change list_articles() API to handle $date_min and $date_max params, in order to get articles between two dates (timestamps)
parent acd6814b
......@@ -30,7 +30,7 @@ function smarty_function_article($params, &$smarty)
} else {
$skip = array();
}
$list_articles = $tikilib->list_articles(0, $max, 'publishDate_desc', '', '', '', '', '', 1);
$list_articles = $tikilib->list_articles(0, $max, 'publishDate_desc', '', '', '', '', '', '', 1);
$x = "";
......
......@@ -2734,7 +2734,7 @@ class TikiLib extends TikiDB {
}
/*shared*/
function list_articles($offset = 0, $maxRecords = -1, $sort_mode = 'publishDate_desc', $find = '', $date = '', $user=false, $type = '', $topicId = '', $visible_only = 'y', $topic='', $categId='',$creator='',$group='', $lang='') {
function list_articles($offset = 0, $maxRecords = -1, $sort_mode = 'publishDate_desc', $find = '', $date_min = 0, $date_max = 0, $user=false, $type = '', $topicId = '', $visible_only = 'y', $topic='', $categId='',$creator='',$group='', $lang='') {
global $userlib, $user;
......@@ -2820,22 +2820,15 @@ class TikiLib extends TikiDB {
if ($add <> "") { $mid .= " ( ".$add." ) "; }
}
if (($visible_only) && ($visible_only <> 'n')) {
if ($date !== false){ // looking for articles on a specific date (or today)
if ($date === ""){ // show articles published today
$date = $this->now;
}
$bindvars[]=(int) $date;
$bindvars[]=(int) $this->now;
$condition = "(`tiki_articles`.`publishDate`<? or `tiki_article_types`.`show_pre_publ`='y') and (`tiki_articles`.`expireDate`>? or `tiki_article_types`.`show_post_expire`='y')";
}else{ // looking for all articles not expired
$condition = "(`tiki_articles`.`expireDate`>? or `tiki_article_types`.`show_post_expire`='y')";
$bindvars[] = $this->now;
}
if ($mid) {
$mid .= " and $condition";
} else {
$mid .= " where $condition";
}
if ( $date_max <= 0 ) {
// show articles published today
$date_max = $this->now;
}
$bindvars[] = (int)$date_min;
$bindvars[] = (int)$date_max;
$bindvars[] = (int)$this->now;
$condition = "`tiki_articles`.`publishDate`>=? and (`tiki_articles`.`publishDate`<=? or `tiki_article_types`.`show_pre_publ`='y') and (`tiki_articles`.`expireDate`>? or `tiki_article_types`.`show_post_expire`='y')";
$mid .= ( $mid ? ' and ' : ' where ' ) . $condition;
}
if (!empty($lang)) {
$condition = '`tiki_articles`.`lang`=?';
......
......@@ -104,7 +104,7 @@ function wikiplugin_articles($data,$params) {
include_once("lib/commentslib.php");
$commentslib = new Comments($dbTiki);
$listpages = $tikilib->list_articles($start, $max, 'publishDate_desc', '', $tikilib->now, 'admin', $type, $topicId, 'y', $topic, $categId, '', '', $lang);
$listpages = $tikilib->list_articles($start, $max, 'publishDate_desc', '', 0, $tikilib->now, 'admin', $type, $topicId, 'y', $topic, $categId, '', '', $lang);
if ($prefs['feature_multilingual'] == 'y') {
global $multilinguallib;
include_once("lib/multilingual/multilinguallib.php");
......
......@@ -44,7 +44,7 @@ if (isset($module_params['categId'])) {
$categId = '';
}
$ranking = $tikilib->list_articles($start, $module_rows, 'publishDate_desc', '', '', $user, $type, $topicId, 'y', $topic, $categId, '', '', $lang);
$ranking = $tikilib->list_articles($start, $module_rows, 'publishDate_desc', '', '', '', $user, $type, $topicId, 'y', $topic, $categId, '', '', $lang);
$smarty->assign('modArticles', $ranking["data"]);
......
......@@ -31,7 +31,7 @@ if (isset($module_params['showDate']) && $module_params['showDate'] == 'y') {
$smarty->assign('showDate','y');
}
$ranking = $tikilib->list_articles(0,$module_rows,'publishDate_desc', '', date("U"), '', $mod_type, $mod_topicId, 'y', $mod_topic, $categId, '', '', $l);
$ranking = $tikilib->list_articles(0,$module_rows,'publishDate_desc', '', '', date("U"), '', $mod_type, $mod_topicId, 'y', $mod_topic, $categId, '', '', $l);
if (isset($module_params['showHeading']) && $module_params['showHeading'] != 'n') {
if ($module_params['showHeading'] == 'y')
$module_params['showHeading'] = -1;
......
......@@ -9,7 +9,7 @@ if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
if (!isset($prefs['maxArticles']))
$prefs['maxArticles'] = 0;
$ranking = $tikilib->list_articles($prefs['maxArticles'], $module_rows, 'publishDate_desc', '', '', $user);
$ranking = $tikilib->list_articles($prefs['maxArticles'], $module_rows, 'publishDate_desc', '', '', '', $user);
$smarty->assign('modOldArticles', $ranking["data"]);
?>
......@@ -6,7 +6,7 @@ if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
exit;
}
$ranking = $tikilib->list_articles(0, $module_rows, 'nbreads_desc', '', '', $user);
$ranking = $tikilib->list_articles(0, $module_rows, 'nbreads_desc', '', '', '', $user);
$smarty->assign('modTopArticles', $ranking["data"]);
$smarty->assign('nonums', isset($module_params["nonums"]) ? $module_params["nonums"] : 'n');
......
......@@ -439,7 +439,7 @@ $trackers = $trklib->list_trackers(0, -1, 'name_asc', $find_objects);
$smarty->assign_by_ref('trackers', $trackers["data"]);
$articles = $tikilib->list_articles(0, -1, 'title_asc', $find_objects, '', $user, '', '', 'n');
$articles = $tikilib->list_articles(0, -1, 'title_asc', $find_objects, '', '', $user, '', '', 'n');
$smarty->assign_by_ref('articles', $articles["data"]);
$directories = $dirlib->dir_list_all_categories(0, -1, 'name_asc', $find_objects);
......
......@@ -69,7 +69,7 @@ if ($output["data"]=="EMPTY") {
$tmp = $prefs['desc_rss_'.$feed];
if ($desc<>'') $desc = $tmp;
$changes = $tikilib -> list_articles(0, $prefs['max_rss_articles'], $dateId.'_desc', '', $tikilib->now, $user, '', $topic, 'y', '', '', '', '', $articleLang);
$changes = $tikilib -> list_articles(0, $prefs['max_rss_articles'], $dateId.'_desc', '', 0, $tikilib->now, $user, '', $topic, 'y', '', '', '', '', $articleLang);
$tmp = array();
foreach ($changes["data"] as $data) {
$data["$descId"] = $tikilib->parse_data($data["$descId"]);
......
......@@ -73,7 +73,7 @@ if ($output["data"]=="EMPTY") {
$titleId = "title";
$readrepl = "tiki-view_blog_post.php?$id=%s&postId=%s";
$changes = $bloglib -> list_blog_posts($_REQUEST["$id"], 0, $prefs['max_rss_blog'], $dateId.'_desc', '', $tikilib->now);
$changes = $bloglib -> list_blog_posts($_REQUEST["$id"], 0, $prefs['max_rss_blog'], $dateId.'_desc', '', '', $tikilib->now);
$tmp = array();
foreach ($changes["data"] as $data) {
$data["$descId"] = $tikilib->parse_data($data["$descId"]);
......
......@@ -82,7 +82,7 @@ else if ($_REQUEST['id']) {
$type = "article";
$objId = $_REQUEST['id'];
$langpage = $info['lang'];
$articles = $tikilib->list_articles(0, -1, 'title_asc', '', '', $user);
$articles = $tikilib->list_articles(0, -1, 'title_asc', '', '', '', $user);
$smarty->assign_by_ref('articles', $articles["data"]);
}
}
......
......@@ -76,17 +76,17 @@ if (!empty($_REQUEST['maxRecords'])) {
$smarty->assign_by_ref('maxRecords', $maxRecords);
if( ($tiki_p_admin == 'y') || ($tiki_p_admin_cms == 'y') ) {
$pdate = '';
$date_max = '';
} elseif(isset($_SESSION["thedate"])) {
if($_SESSION["thedate"]<$tikilib->now) {
// If the session is older then set it to today
// so you can list articles
$pdate = $tikilib->now;
$date_max = $tikilib->now;
} else {
$pdate = $_SESSION["thedate"];
$date_max = $_SESSION["thedate"];
}
} else {
$pdate = $tikilib->now;
$date_max = $tikilib->now;
}
if (isset($_REQUEST["find"])) {
......@@ -122,7 +122,7 @@ $visible_only='y';
if( ($tiki_p_admin == 'y') || ($tiki_p_admin_cms == 'y') ) { $visible_only="n"; }
// Get a list of last changes to the Wiki database
$listpages = $tikilib->list_articles($offset, $maxRecords, $sort_mode, $find, $pdate, $user, $_REQUEST["type"], $_REQUEST["topic"], $visible_only, '', $_REQUEST["categId"], '', '', $_REQUEST['lang']);
$listpages = $tikilib->list_articles($offset, $maxRecords, $sort_mode, $find, 0, $date_max, $user, $_REQUEST["type"], $_REQUEST["topic"], $visible_only, '', $_REQUEST["categId"], '', '', $_REQUEST['lang']);
// If there're more records then assign next_offset
$smarty->assign_by_ref('cant', $listpages['cant']);
......
......@@ -252,7 +252,7 @@ $smarty->assign('form_sendstructures', $form_sendstructures);
$smarty->assign('form_sendarticles', $form_sendarticles);
$pages = $tikilib->list_pageNames(0, -1, 'pageName_asc', $find);
$articles = $tikilib->list_articles(0, -1, 'publishDate_desc', $find, $tikilib->now, $user);
$articles = $tikilib->list_articles(0, -1, 'publishDate_desc', $find, 0, $tikilib->now, $user);
$smarty->assign_by_ref('pages', $pages["data"]);
$smarty->assign_by_ref('articles', $articles["data"]);
......
......@@ -131,7 +131,7 @@ case 'quiz':
break;
case 'article':
$objects = $tikilib->list_articles(0, -1, 'title_asc', $find_objects, '', $user);
$objects = $tikilib->list_articles(0, -1, 'title_asc', $find_objects, '', '', '', $user);
$smarty->assign_by_ref('objects', $objects["data"]);
$objects = $objects['data'];
......
......@@ -79,18 +79,23 @@ if (!isset($_REQUEST["offset"])) {
$smarty->assign_by_ref('offset', $offset);
if (isset($_SESSION["thedate"])) {
if ( isset($_REQUEST['date_min']) || isset($_REQUEST['date_max']) ) {
$date_min = isset($_REQUEST['date_min']) ? $_REQUEST['date_min'] : 0;
$date_max = isset($_REQUEST['date_max']) ? $_REQUEST['date_max'] : $tikilib->now;
} elseif (isset($_SESSION["thedate"])) {
$date_min = 0;
if ($_SESSION["thedate"] < $tikilib->now) {
$pdate = $_SESSION["thedate"];
$date_max = $_SESSION["thedate"];
} else {
if ($tiki_p_admin == 'y' || $tiki_p_admin_cms == 'y') {
$pdate = $_SESSION["thedate"];
$date_max = $_SESSION["thedate"];
} else {
$pdate = $tikilib->now;
$date_max = $tikilib->now;
}
}
} else {
$pdate = $tikilib->now;
$date_min = 0;
$date_max = $tikilib->now;
}
if (isset($_REQUEST["find"])) {
......@@ -131,7 +136,7 @@ if (!isset($_REQUEST['lang'])) {
}
// Get a list of last changes to the Wiki database
$listpages = $tikilib->list_articles($offset, $prefs['maxArticles'], $sort_mode, $find, $pdate, $user, $type, $topic, 'y', $topicName, $categId, '', '', $_REQUEST['lang']);
$listpages = $tikilib->list_articles($offset, $prefs['maxArticles'], $sort_mode, $find, $date_min, $date_max, $user, $type, $topic, 'y', $topicName, $categId, '', '', $_REQUEST['lang']);
if ($prefs['feature_multilingual'] == 'y') {
include_once("lib/multilingual/multilinguallib.php");
$listpages['data'] = $multilinguallib->selectLangList('article', $listpages['data']);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment