Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $months_str = array(
- '01' => 'янв',
- '02' => 'фев',
- '03' => 'мар',
- '04' => 'апр',
- '05' => 'май',
- '06' => 'июн',
- '07' => 'июл',
- '08' => 'авг',
- '09' => 'сен',
- '10' => 'окт',
- '11' => 'ноя',
- '12' => 'дек',
- );
- $years = $months = $nodes = array();
- $uri_year = (int)arg(1);
- $uri_year = $uri_year ? $uri_year : date('Y');
- $uri_month = (int)arg(2);
- $item_per_page = 10;
- $offset = 0;
- $count_links = 0;
- $current_uri_page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
- $current_page = $current_uri_page > 0 ? ($current_uri_page - 1)*$item_per_page : $current_uri_page;
- $month_cond = '';
- if($uri_year)
- $month_cond = ' HAVING `year` = ' . $uri_year;
- $sql = "SELECT FROM_UNIXTIME(`created`, '%Y') AS `year` FROM {node} WHERE `type` = 'news' AND `status` = 1 GROUP BY `year` ORDER BY `year`";
- $result = db_query($sql);
- while ($row = $result->fetchAssoc())
- $years[] = $row['year'];
- $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`";
- $result = db_query($sql);
- while ($row = $result->fetchAssoc())
- $months[] = $row['month'];
- if($uri_year >= 2010)
- {
- $year_cond = ' HAVING `year` = ' . $uri_year;
- $month_cond = '';
- if($uri_month >= 1 && $uri_month <= 12)
- $month_cond = ' AND `month` = ' . str_pad($uri_month, 2, 0, STR_PAD_LEFT);
- $month_cond_count = '';
- if($month_cond)
- $month_cond_count = " AND FROM_UNIXTIME(`created`, '%m') = " . str_pad($uri_month, 2, 0, STR_PAD_LEFT);
- $sql = "SELECT COUNT(*) count_nodes FROM {node} WHERE `type` = 'news' AND `status` = 1 AND FROM_UNIXTIME(`created`, '%Y') = $uri_year " . $month_cond_count;
- $result = db_query($sql);
- $count_rows = (int)$result->fetchField();
- $count_links = ceil($count_rows / $item_per_page);
- $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";
- $result = db_query($sql);
- while ($row = $result->fetchAssoc())
- $nodes[] = $row;
- $pagin_links = pagin_links($count_links);
- }
- ?>
- <?php if($years): ?>
- <ul>
- <?php foreach($years as $year): ?>
- <li><?php print l($year, 'news/' . $year); ?></li>
- <?php endforeach; ?>
- </ul><br>
- <?php if($months): ?>
- <ul>
- <?php foreach($months as $month): ?>
- <li><?php print l(strtr($month, $months_str), 'news/' . arg(1) . '/' . $month); ?></li>
- <?php endforeach; ?>
- </ul>
- <?php endif; ?>
- <?php endif; ?>
- <?php if($nodes): ?>
- <?php $i = 0; foreach($nodes as $node): $i++; ?>
- <?php print "$i) " . $node['title']; ?><br>
- <?php endforeach; ?>
- <?php endif; ?>
- <?php if($pagin_links): ?>
- <br>
- <ul class="basic_pagin">
- <?php if($current_uri_page - 1 >= 0): ?>
- <li><?php print l('<<', current_path(), array('html' => true, 'query' => array('page' => ($current_uri_page - 1 == 0 ? null : $current_uri_page - 1)))); ?></li>
- <?php else: ?>
- <li><< </li>
- <?php endif; ?>
- <?php foreach($pagin_links as $link): ?>
- <?php if($current_uri_page != $link && $link != '…'): ?>
- <li><?php print l($link, current_path(), array('html' => true, 'query' => array('page' => $link))); ?></li>
- <?php else: ?>
- <li><?php print $link; ?></li>
- <?php endif; ?>
- <?php endforeach; ?>
- <?php if($current_uri_page + 1 <= $count_links): ?>
- <li><?php print l('>>', current_path(), array('html' => true, 'query' => array('page' => $current_uri_page + 1))); ?></li>
- <?php else: ?>
- <li> >></li>
- <?php endif; ?>
- </ul>
- <?php endif; ?>
Add Comment
Please, Sign In to add comment