PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/functions_browse.php

https://github.com/aravindc/pixelpost
PHP | 157 lines | 127 code | 25 blank | 5 comment | 20 complexity | 8a9d44e45615c97d1c882be37ef503ad MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. // SVN file version:
  3. // $Id$
  4. if(isset($_GET['x']) && $_GET['x'] == "browse")
  5. {
  6. $thumb_output = "";
  7. $where = "";
  8. $headline_selection = ($language_abr == $default_language_abr) ? 'headline' : 'alt_headline';
  9. $display_order = ($cfgrow['display_order']=='default') ? 'DESC' : 'ASC';
  10. if(isset($_GET['category']))
  11. {
  12. $pp_cat = addslashes($_GET['category']);
  13. }
  14. else
  15. {
  16. $pp_cat = 0;
  17. }
  18. if(is_numeric($pp_cat) && $pp_cat != "")
  19. {
  20. // Modified from Mark Lewin's hack for multiple categories
  21. $query = mysql_query(
  22. "SELECT 1,t2.id,{$headline_selection},image,datetime FROM {$pixelpost_db_prefix}catassoc as t1
  23. INNER JOIN {$pixelpost_db_prefix}pixelpost t2 on t2.id = t1.image_id
  24. WHERE t1.cat_id = '".$pp_cat."' AND (datetime<='$cdate')
  25. ORDER BY ".$cfgrow['display_sort_by']." ".$display_order
  26. );
  27. $lookingfor = 1;
  28. }
  29. elseif(isset($_GET['archivedate']) && eregi("^[0-9]{4}-[0-9]{2}$", $_GET['archivedate']))
  30. {
  31. $where = "AND (DATE_FORMAT(datetime, '%Y-%m')='".$_GET['archivedate']."')"; //DATE_FORMAT(foo, '%Y-%m-%d')
  32. $query = mysql_query("SELECT 1,id,{$headline_selection},image, datetime FROM ".$pixelpost_db_prefix."pixelpost WHERE (datetime<='$cdate') $where ORDER BY ".$cfgrow['display_sort_by']." ".$display_order);
  33. $lookingfor = 1;
  34. }
  35. elseif(isset($_POST['category']))
  36. {
  37. $lookingfor = 0;
  38. $where = "(";
  39. foreach( $_POST['category'] as $cat)
  40. {
  41. $cat = clean($cat);
  42. $where .= "t1.cat_id='$cat' OR ";
  43. $lookingfor++;
  44. }
  45. $where .= " 0)";
  46. $querystr = "SELECT COUNT(t1.id), t2.id,{$headline_selection},image,datetime
  47. FROM {$pixelpost_db_prefix}catassoc AS t1
  48. INNER JOIN {$pixelpost_db_prefix}pixelpost t2 ON t2.id = t1.image_id
  49. WHERE (datetime<='$cdate') AND
  50. $where
  51. GROUP BY t2.id
  52. ORDER BY ".$cfgrow['display_sort_by']." ".$display_order;
  53. $query = mysql_query($querystr);
  54. }
  55. elseif(isset($_GET['tag']) && eregi("[a-zA-Z 0-9_]+",$_GET['tag']))
  56. {
  57. $lookingfor = 1;
  58. $default_language_abr = strtolower($PP_supp_lang[$cfgrow['langfile']][0]);
  59. if ($language_abr == $default_language_abr)
  60. {
  61. $tag_selection = "AND (t2.tag = '" . addslashes($_GET['tag']) . "')";
  62. }
  63. else
  64. {
  65. $tag_selection = "AND (t2.alt_tag = '" . addslashes($_GET['tag']) . "')";
  66. }
  67. $querystr = "SELECT 1, t1.id,t1.{$headline_selection},t1.image, t1.datetime
  68. FROM {$pixelpost_db_prefix}pixelpost AS t1, {$pixelpost_db_prefix}tags AS t2
  69. WHERE (t1.datetime<='$cdate')
  70. $where
  71. AND (t1.id = t2.img_id)
  72. $tag_selection
  73. GROUP BY t1.id
  74. ORDER BY t1.".$cfgrow['display_sort_by']." ".$display_order;
  75. $query = mysql_query($querystr);
  76. }
  77. else
  78. {
  79. $lookingfor = 1;
  80. $query = mysql_query("SELECT 1,id,{$headline_selection},image,datetime FROM ".$pixelpost_db_prefix."pixelpost WHERE (datetime<='$cdate') ORDER BY ".$cfgrow['display_sort_by']." ".$display_order);
  81. }
  82. while(list($count,$id,$title,$name,$datetime) = mysql_fetch_row($query))
  83. {
  84. if( $count != $lookingfor) continue; // Major hack for the browse filters.
  85. $title = pullout($title);
  86. $title = htmlspecialchars($title,ENT_QUOTES);
  87. $thumbnail = ltrim($cfgrow['thumbnailpath'], "./")."thumb_".$name;
  88. $thumbnail_extra = getimagesize($thumbnail);
  89. $local_width = $thumbnail_extra['0'];
  90. $local_height = $thumbnail_extra['1'];
  91. $thumb_output .= "<a href=\"$showprefix$id\"><img src=\"$thumbnail\" alt=\"$title\" title=\"$title\" width=\"$local_width\" height=\"$local_height\" class=\"thumbnails\" /></a>";
  92. }
  93. $tpl = ereg_replace("<THUMBNAILS>",$thumb_output,$tpl);
  94. }
  95. // build browse menu
  96. $browse_select = "<select name='browse' onchange='self.location.href=this.options[this.selectedIndex].value;'><option value=''>$lang_browse_select_category</option><option value='index.php?x=browse&amp;category='>$lang_browse_all</option>";
  97. $query = mysql_query("SELECT * FROM ".$pixelpost_db_prefix."categories ORDER BY name");
  98. while(list($id,$name, $alt_name) = mysql_fetch_row($query))
  99. {
  100. if ($language_abr == $default_language_abr)
  101. {
  102. $name = pullout($name);
  103. }
  104. else
  105. {
  106. $name = pullout($alt_name);
  107. }
  108. $browse_select .= "<option value='index.php?x=browse&amp;category=$id'>$name</option>";
  109. }
  110. $browse_select .= "</select>";
  111. $tpl = ereg_replace("<BROWSE_CATEGORIES>",$browse_select,$tpl);
  112. $browse_order_by = ($language_abr == $default_language_abr) ? 'name' : 'alt_name';
  113. // build browse checkboxes
  114. $checkboxes = "<form method='post' action='index.php?x=browse'>";
  115. $query = mysql_query("SELECT * FROM ".$pixelpost_db_prefix."categories ORDER BY ".$browse_order_by);
  116. while(list($id,$name,$alt_name) = mysql_fetch_row($query))
  117. {
  118. if ($language_abr == $default_language_abr)
  119. {
  120. $name = pullout($name);
  121. }
  122. else
  123. {
  124. $name = pullout($alt_name);
  125. }
  126. $checkbox_checked = "";
  127. if(isset($category)&&is_array($category)&& in_array($id,$category)) $checkbox_checked = "checked";
  128. $checkboxes .= "<input type='checkbox' name='category[]' value='$id' $checkbox_checked />$name&nbsp;&nbsp;&nbsp;\n";
  129. }
  130. $checkboxes .= "<input type='submit' value='Filter' /></form>";
  131. $tpl = ereg_replace("<BROWSE_CHECKBOXLIST>",$checkboxes,$tpl);
  132. ?>