Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function archive_page($type = 'all', $year = 0, $month = 0, $day = 0) {
- global $language;
- $lang = $language->language;
- // Argument validation, should be a valid node type and numeric.
- $node_types = node_get_types();
- if (($type != 'all' && !isset($node_types[$type])) || !is_numeric($year)
- || !is_numeric($month) || $month > 12 || !is_numeric($day) || $day > 31) {
- return MENU_NOT_FOUND;
- }
- // Make sure all values are secure.
- $day = (int) $day;
- $year = (int) $year;
- $month = (int) $month;
- if ($month < 0 || $month > 12) {
- // Ensure that we have a proper array index later.
- $month = 0;
- }
- if (!_archive_validate_type($type)) {
- $type = 'all';
- }
- drupal_set_title(theme('archive_page_title', $type, $year, $month, $day));
- // Check that there're nodes we can display.
- $nodes = db_result(db_query(db_rewrite_sql("SELECT COUNT(1) FROM {node} n WHERE n.status = 1 AND n.type IN ('". implode("', '", variable_get('archive_type_filters', array())) ."')")));
- if (!$nodes && $type == 'all' && $year == 0 && $month == 0 && $day == 0) {
- return t('No content found.');
- }
- drupal_add_css(drupal_get_path('module', 'archive') .'/archive.css');
- $date = _archive_date($type, $year, $month, $day);
- $output = theme('archive_navigation', $type, $date);
- $nodes = variable_get('default_nodes_main', 10);
- $query = _archive_query($type, $date);
- $result = pager_query(db_rewrite_sql(array_shift($query)), $nodes, 0, null, $query);
- $found_rows = false;
- $node_date = 0;
- $pushed = array();
- while ($o = db_fetch_object($result)) {
- /*
- This additional code will filter a node with two types of language matching with current
- active language. Example: A node titled: 'Hello how are you' (english) and 'Halo apa kabar' (indonesia).
- A node that have a translated node, the node with active current language will be displayed. If a node doesn't have
- translated node, that node still displayed in not translated language. (sorry for my bad english)
- */
- if ($o->tnid == 0) {
- $node = node_load($o->nid,null,true);
- } else {
- if (!in_array($o->tnid,$pushed)) {
- if ($o->language == $lang) {
- $node = node_load($o->nid,null,true);
- array_push($pushed,$o->tnid);
- } else {
- continue;
- }
- } else {
- continue;
- }
- }
- $node_created = $node->created + $date->tz;
- //...
- //...
- //...
- //...
- //...
- }
- function _archive_query($type, $date) {
- // Confine the display interval to only one day
- if ($date->day) {
- $start = gmmktime(0, 0, 0, $date->month, $date->day, $date->year);
- $end = gmmktime(0, 0, 0, $date->month, $date->day + 1, $date->year);
- }
- // Confine the display interval to one month
- else if ($date->month) {
- $start = gmmktime(0, 0, 0, $date->month, 1, $date->year);
- $end = gmmktime(0, 0, 0, $date->month + 1, 1, $date->year);
- }
- // Confine the display interval to one year
- else if ($date->year) {
- $start = gmmktime(0, 0, 0, 1, 1, $date->year);
- $end = gmmktime(0, 0, 0, 1, 1, $date->year + 1);
- }
- else {
- $start = 0;
- $end = 0;
- }
- // Grab limits on node types if exist
- $final_types = _archive_types_sql_string($type);
- // Allow viewing all nodes, not just nodes by year
- if ($start && $end) {
- return array('SELECT DISTINCT n.nid, n.tnid, n.language, n.type FROM {node} n WHERE n.status = 1 '. $final_types .'AND n.created >= %d AND n.created < %d ORDER BY n.created DESC', $start - $date->tz, $end - $date->tz);
- }
- else {
- return array('SELECT DISTINCT n.nid, n.tnid, n.language, n.type FROM {node} n WHERE n.status = 1 '. $final_types .'ORDER BY n.created DESC');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement