Guest User

Untitled

a guest
Sep 4th, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.94 KB | None | 0 0
  1. <?php
  2. $months_str = array(
  3.     '01' => 'янв',
  4.     '02' => 'фев',
  5.     '03' => 'мар',
  6.     '04' => 'апр',
  7.     '05' => 'май',
  8.     '06' => 'июн',
  9.     '07' => 'июл',
  10.     '08' => 'авг',
  11.     '09' => 'сен',
  12.     '10' => 'окт',
  13.     '11' => 'ноя',
  14.     '12' => 'дек',
  15. );
  16.  
  17. $years = $months = $nodes = array();
  18. $uri_year = (int)arg(1);
  19. $uri_year = $uri_year ? $uri_year : date('Y');
  20. $uri_month = (int)arg(2);
  21. $item_per_page = 10;
  22. $offset = 0;
  23. $count_links = 0;
  24. $current_uri_page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
  25. $current_page = $current_uri_page > 0 ? ($current_uri_page - 1)*$item_per_page : $current_uri_page;
  26.  
  27. $month_cond = '';
  28.  
  29. if($uri_year)
  30.     $month_cond = ' HAVING `year` = ' . $uri_year;
  31.  
  32. $sql = "SELECT FROM_UNIXTIME(`created`, '%Y') AS `year` FROM {node} WHERE `type` = 'news' AND `status` = 1 GROUP BY `year` ORDER BY `year`";
  33. $result = db_query($sql);
  34. while ($row = $result->fetchAssoc())
  35.     $years[] = $row['year'];
  36.  
  37. $sql = "SELECT DISTINCT FROM_UNIXTIME(`created`, '%m') AS `month`, FROM_UNIXTIME(`created`, '%Y') AS `year` FROM {node} WHERE `type` = 'news' AND `status` = 1 {$month_cond} ORDER BY `month`";
  38. $result = db_query($sql);
  39. while ($row = $result->fetchAssoc())
  40.     $months[] = $row['month'];
  41.  
  42. if($uri_year >= 2010)
  43. {
  44.     $year_cond = ' HAVING `year` = ' . $uri_year;
  45.  
  46.     $month_cond = '';
  47.     if($uri_month >= 1 && $uri_month <= 12)
  48.         $month_cond = ' AND `month` = ' . str_pad($uri_month, 2, 0, STR_PAD_LEFT);
  49.  
  50.     $month_cond_count = '';
  51.     if($month_cond)
  52.         $month_cond_count = " AND FROM_UNIXTIME(`created`, '%m') = " . str_pad($uri_month, 2, 0, STR_PAD_LEFT);
  53.  
  54.     $sql = "SELECT COUNT(*) count_nodes FROM {node} WHERE `type` = 'news' AND `status` = 1 AND FROM_UNIXTIME(`created`, '%Y') = $uri_year " . $month_cond_count;
  55.     $result = db_query($sql);
  56.     $count_rows = (int)$result->fetchField();
  57.     $count_links = ceil($count_rows / $item_per_page);
  58.  
  59.     $sql = "SELECT *, FROM_UNIXTIME(`created`, '%m') AS `month`, FROM_UNIXTIME(`created`, '%Y') AS `year` FROM {node} WHERE `type` = 'news' AND `status` = 1 {$year_cond} {$month_cond} ORDER BY created  LIMIT $current_page,$item_per_page";
  60.     $result = db_query($sql);
  61.     while ($row = $result->fetchAssoc())
  62.         $nodes[] = $row;
  63.  
  64.     $pagin_links = pagin_links($count_links);
  65. }
  66. ?>
  67.  
  68. <?php if($years): ?>
  69.     <ul>
  70.         <?php foreach($years as $year): ?>
  71.             <li><?php print l($year, 'news/' . $year); ?></li>
  72.         <?php endforeach; ?>
  73.     </ul><br>
  74.  
  75.     <?php if($months): ?>
  76.       <ul>
  77.           <?php foreach($months as $month): ?>
  78.         <li><?php print l(strtr($month, $months_str), 'news/' . arg(1) . '/' . $month); ?></li>
  79.           <?php endforeach; ?>
  80.       </ul>
  81.         <?php endif; ?>
  82. <?php endif; ?>
  83.  
  84. <?php if($nodes): ?>
  85.     <?php $i = 0; foreach($nodes as $node): $i++; ?>
  86.         <?php print "$i) " . $node['title']; ?><br>
  87.     <?php endforeach; ?>
  88. <?php endif; ?>
  89.  
  90. <?php if($pagin_links): ?>
  91.     <br>
  92.     <ul class="basic_pagin">
  93.         <?php if($current_uri_page - 1 >= 0): ?>
  94.       <li><?php print l('&lt;&lt;', current_path(), array('html' => true, 'query' => array('page' => ($current_uri_page - 1 == 0 ? null : $current_uri_page - 1)))); ?></li>
  95.         <?php else: ?>
  96.         <li>&lt;&lt; </li>
  97.         <?php endif; ?>
  98.     <?php foreach($pagin_links as $link): ?>
  99.       <?php if($current_uri_page != $link && $link != '&hellip;'): ?>
  100.         <li><?php print l($link, current_path(), array('html' => true, 'query' => array('page' => $link))); ?></li>
  101.       <?php else: ?>
  102.         <li><?php print $link; ?></li>
  103.       <?php endif; ?>
  104.     <?php endforeach; ?>
  105.       <?php if($current_uri_page + 1 <= $count_links): ?>
  106.         <li><?php print l('&gt;&gt;', current_path(), array('html' => true, 'query' => array('page' => $current_uri_page + 1))); ?></li>
  107.       <?php else: ?>
  108.         <li> &gt;&gt;</li>
  109.       <?php endif; ?>
  110.     </ul>
  111. <?php endif; ?>
Add Comment
Please, Sign In to add comment