PageRenderTime 36ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/strawberry/1.1.2/plugins/prev-next-links.php

http://goodgirl.googlecode.com/
PHP | 66 lines | 42 code | 15 blank | 9 comment | 4 complexity | d2f72125a6f559077cb4e976eb9ce210 MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: Prev-next-links
  4. Plugin URI: http://english.cutenews.ru/forum
  5. Description: ?????? ?? ?????????? ? ????????? ???? ? ?????? ???????.
  6. Version: 1.1
  7. Application: Strawberry
  8. Author: FI-DD
  9. Author URI: http://english.cutenews.ru/forum/profile.php?mode=viewprofile&u=2
  10. */
  11. add_action('head', 'prev_next');
  12. function prev_next(){
  13. global $sql, $cache, $post, $prev_next_links;
  14. if ($post){
  15. if (!$prev_next_links = $cache->unserialize('prev-next-links', $post['id'])){
  16. $prev_next_links['prev'] = $sql->select(array(
  17. 'table' => 'news',
  18. 'where' => array('id < '.$post['id']),
  19. 'orderby' => array('date', 'DESC'),
  20. 'limit' => array(0, 1)
  21. ));
  22. $prev_next_links['next'] = $sql->select(array(
  23. 'table' => 'news',
  24. 'where' => array('id > '.$post['id']),
  25. 'orderby' => array('date', 'ASC'),
  26. 'limit' => array(0, 1)
  27. ));
  28. $prev_next_links = $cache->serialize($prev_next_links);
  29. }
  30. } else {
  31. $prev_next_links = array();
  32. }
  33. return $tpl;
  34. }
  35. add_filter('news-show-generic', 'prev_next_generic');
  36. function prev_next_generic($tpl){
  37. global $prev_next_links;
  38. if ($prev_next_links){
  39. $tpl['prev-next']['prev']['link'] = cute_get_link($prev_next_links['prev'][0]);
  40. $tpl['prev-next']['prev']['title'] = $prev_next_links['prev'][0]['title'];
  41. $tpl['prev-next']['next']['link'] = cute_get_link($prev_next_links['next'][0]);
  42. $tpl['prev-next']['next']['title'] = $prev_next_links['next'][0]['title'];
  43. }
  44. return $tpl;
  45. }
  46. add_filter('template-full', 'template_prev_next');
  47. function template_prev_next($template){
  48. $template['prev-next'] = t('?????????? ?????? ?? ?????????? ? ????????? ???????: $tpl[\'post\'][\'prev-next\'][\'prev\'][\'link\'] ? $tpl[\'post\'][\'prev-next\'][\'next\'][\'link\']. ? ????? ?????????: $tpl[\'post\'][\'prev-next\'][\'prev\'][\'title\'] ? $tpl[\'post\'][\'prev-next\'][\'next\'][\'title\']');
  49. return $template;
  50. }
  51. ?>