Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.65 KB | None | 0 0
  1. function archive_page($type = 'all', $year = 0, $month = 0, $day = 0) {
  2.   global $language;
  3.  
  4.   $lang = $language->language;
  5.    
  6.   // Argument validation, should be a valid node type and numeric.
  7.   $node_types = node_get_types();
  8.   if (($type != 'all' && !isset($node_types[$type])) || !is_numeric($year)
  9.       || !is_numeric($month) || $month > 12 || !is_numeric($day) || $day > 31) {
  10.     return MENU_NOT_FOUND;
  11.   }
  12.  
  13.   // Make sure all values are secure.
  14.   $day = (int) $day;
  15.   $year = (int) $year;
  16.   $month = (int) $month;
  17.   if ($month < 0 || $month > 12) {
  18.     // Ensure that we have a proper array index later.
  19.     $month = 0;
  20.   }
  21.   if (!_archive_validate_type($type)) {
  22.     $type = 'all';
  23.   }
  24.  
  25.   drupal_set_title(theme('archive_page_title', $type, $year, $month, $day));
  26.  
  27.   // Check that there're nodes we can display.
  28.   $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())) ."')")));
  29.   if (!$nodes && $type == 'all' && $year == 0 && $month == 0 && $day == 0) {
  30.     return t('No content found.');
  31.   }
  32.  
  33.   drupal_add_css(drupal_get_path('module', 'archive') .'/archive.css');
  34.   $date = _archive_date($type, $year, $month, $day);
  35.   $output = theme('archive_navigation', $type, $date);
  36.   $nodes = variable_get('default_nodes_main', 10);
  37.   $query = _archive_query($type, $date);
  38.   $result = pager_query(db_rewrite_sql(array_shift($query)), $nodes, 0, null, $query);
  39.  
  40.   $found_rows = false;
  41.   $node_date = 0;
  42.   $pushed = array();
  43.   while ($o = db_fetch_object($result)) {
  44.    
  45.     /*
  46.     This additional code will filter a node with two types of language matching with current
  47.     active language. Example: A node titled: 'Hello how are you' (english) and 'Halo apa kabar' (indonesia).
  48.     A node that have a translated node, the node with active current language will be displayed. If a node doesn't have
  49.     translated node, that node still displayed in not translated language. (sorry for my bad english)
  50.     */
  51.     if ($o->tnid == 0) {
  52.         $node = node_load($o->nid,null,true);
  53.     } else {
  54.         if (!in_array($o->tnid,$pushed)) {
  55.             if ($o->language == $lang) {
  56.                 $node = node_load($o->nid,null,true);
  57.                 array_push($pushed,$o->tnid);
  58.             } else {
  59.                 continue;
  60.             }
  61.         } else {
  62.             continue;
  63.         }
  64.        
  65.     }
  66.    
  67.     $node_created = $node->created + $date->tz;
  68. //...
  69. //...
  70. //...
  71. //...
  72. //...
  73. }
  74.  
  75. function _archive_query($type, $date) {
  76.   // Confine the display interval to only one day
  77.   if ($date->day) {
  78.     $start = gmmktime(0, 0, 0, $date->month, $date->day, $date->year);
  79.     $end   = gmmktime(0, 0, 0, $date->month, $date->day + 1, $date->year);
  80.   }
  81.   // Confine the display interval to one month
  82.   else if ($date->month) {
  83.     $start = gmmktime(0, 0, 0, $date->month, 1, $date->year);
  84.     $end   = gmmktime(0, 0, 0, $date->month + 1, 1, $date->year);
  85.   }
  86.   // Confine the display interval to one year
  87.   else if ($date->year) {
  88.     $start = gmmktime(0, 0, 0, 1, 1, $date->year);
  89.     $end   = gmmktime(0, 0, 0, 1, 1, $date->year + 1);
  90.   }
  91.   else {
  92.     $start = 0;
  93.     $end = 0;
  94.   }
  95.  
  96.   // Grab limits on node types if exist
  97.   $final_types = _archive_types_sql_string($type);
  98.  
  99.   // Allow viewing all nodes, not just nodes by year
  100.   if ($start && $end) {
  101.     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);
  102.   }
  103.   else {
  104.     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');
  105.   }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement