Guest User

Untitled

a guest
May 26th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. <?PHP
  2.  
  3. class content {
  4.  
  5. var $userid;
  6. var $id;
  7. var $pid;
  8. var $cid;
  9. var $title;
  10. var $content;
  11. var $dateposted;
  12. var $votes;
  13. var $status;
  14.  
  15. // Convert category id to category name.
  16. function convertCatName($id) {
  17. $query = "select * from `category` where `id` = ".$id."";
  18. $result = mysql_query($query);
  19. $catname = mysql_fetch_object($result);
  20. return $catname->title;
  21. }
  22.  
  23. // Convert user id to username.
  24. function convertUserName($id) {
  25. $query = "select * from `user` where `id` = ".$id."";
  26. $result = mysql_query($query);
  27. $usrname = mysql_fetch_object($result);
  28. return $usrname->username;
  29. }
  30.  
  31. // Count the number of rows in a table, with modifier.
  32. function countRows($table, $field = 'none', $modify = 'none') {
  33. if($modify == 'none' || $field == 'none') {
  34. $query = "select * from `".$table."`";
  35. }
  36. else {
  37. $query = "select * from `".$table."` where `".$field."` = ".$modify."";
  38. }
  39. $count = mysql_num_rows(mysql_query($query));
  40. return $count;
  41. }
  42.  
  43. // Get category list
  44. function getCategoryList($location) {
  45. $query = "select * from `category`";
  46. $result = mysql_query($query);
  47. if($location == "Home") {
  48. $output = "<h3>Jump to category...</h3>\n";
  49. }
  50. if($location == "Menu") {
  51. $output = "<h3>Category List</h3>\r";
  52. }
  53. $output .= " <ul class=\"catlist\">\r";
  54. while ($row = mysql_fetch_object($result)) {
  55. if($location == "Home") {
  56. $output .= " <li><a href=\"viewideas.php?cat=".$row->id."\" class=\"cat\">".$row->title."</a><br />
  57. Pages: ".$this->countRows('posts', 'cid', $row->id)."</li>\r";
  58. }
  59. if($location == "Menu") {
  60. $output .= " <li><a href=\"javascript:;\" class=\"cat\" onclick=\"showCat(".$row->id.")\">".$row->title."</a><br />
  61. Pages: ".$this->countRows('posts', 'cid', $row->id)."</li>\r";
  62. }
  63. }
  64. $output .= " </ul>\r";
  65. echo $output;
  66. }
  67.  
  68.  
  69. function getData($table='posts', $field=1, $modify='=1', $limitx=3) {
  70.  
  71. if (isset($_GET['pageno'])) {
  72. $pageno = $_GET['pageno'];
  73. }
  74. else {
  75. $pageno = 1;
  76. }
  77.  
  78. $query = "SELECT count(*) FROM ".$table." WHERE ".$field." ".$modify."";
  79. $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
  80. $query_data = mysql_fetch_row($result);
  81. $numrows = $query_data[0];
  82. $rows_per_page = $limitx;
  83. $lastpage = ceil($numrows/$rows_per_page);
  84.  
  85. $pageno = (int)$pageno;
  86. if ($pageno > $lastpage) {
  87. $pageno = $lastpage;
  88. }
  89. if ($pageno < 1) {
  90. $pageno = 1;
  91. }
  92.  
  93. $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
  94.  
  95. $query2 = "SELECT * FROM ".$table." WHERE ".$field." ".$modify." $limit";
  96. $result2 = mysql_query($query2) or trigger_error("SQL", E_USER_ERROR);
  97.  
  98. while ($row = mysql_fetch_object($result2)) {
  99. echo "<div class=\"recentlist\">\n";
  100. echo "<div style=\"padding: 10px;\"><a href=\"viewideas.php?id=".$row->id."\" class=\"post\">".$row->title."</a><br />\n";
  101. echo "Posted by <a href=\"view.php?id=".$row->pid."\" rel=\"facebox\">".$this->convertUserName($row->pid)."</a> on ".$row->dateposted."<br />\n";
  102. echo "Category - <strong>".$this->convertCatName($row->cid)."</strong><br /><br />\n";
  103. echo truncate($row->content, 100)."</div>\n";
  104. echo "<div class=\"menubar\"><img src=\"images/viewpost.png\" alt=\"View Post\" /> View Idea <img src=\"images/commentpost.png\" alt=\"Comment Post\" /> Comment on Idea</div>\n";
  105. echo "</div>\n";
  106. }
  107.  
  108. echo "<div class=\"recentlist\">\n";
  109. echo "<span style=\"display: block; margin-right: 90px; float: left; width: 80px;\">\n";
  110. if ($pageno == 1) {
  111. echo " FIRST PREV ";
  112. } else {
  113. echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
  114. $prevpage = $pageno-1;
  115. echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
  116. } // if
  117. echo "</span>\n";
  118. echo "<span style=\"display: block; margin-right: 90px; float: left; width: 120px;\">\n";
  119. echo " ( Page $pageno of $lastpage ) ";
  120. echo "</span>\n";
  121. echo "<span style=\"display: block; float: left; width: 80px;\">\n";
  122. if ($pageno == $lastpage) {
  123. echo " NEXT LAST ";
  124. } else {
  125. $nextpage = $pageno+1;
  126. echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
  127. echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
  128. } // if
  129. echo "</span>\n";
  130. echo "<span style=\"display: block; clear: both;\"></span>\n";
  131. echo "</div>\n";
  132.  
  133. }
  134.  
  135.  
  136.  
  137.  
  138. }
  139.  
  140. ?>
Add Comment
Please, Sign In to add comment