PageRenderTime 82ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/classes/tag.php

https://github.com/mivaul/fotbalfan
PHP | 216 lines | 175 code | 41 blank | 0 comment | 25 complexity | 286535cf8a9674437ad0acac40f21c59 MD5 | raw file
  1. <?php
  2. class Tag{
  3. public function addTag($tag,$obj,$id_obj){
  4. include_once "classes/config.php";
  5. global $TABLES,$FIELDS,$conn;
  6. $query = "SELECT `" . $FIELDS['tags']['id'] . "` FROM `" . $TABLES['tags'] . "` WHERE `" . $FIELDS['tags']['tag'] . "` = '" . $tag . "' AND `" . $FIELDS['tags']['id_obj'] . "` = '" . $id_obj . "' AND `" . $FIELDS['tags']['obj'] . "` = '" . $obj . "' LIMIT 1;";
  7. $result = $conn->query($query);
  8. if($result->num_rows){
  9. $row = $result->fetch_row(); $id = $row[0];
  10. unset($query,$result,$row);
  11. $query = "UPDATE `" . $TABLES['tags'] . "` SET `" . $FIELDS['tags']['hits'] . "` = `" . $FIELDS['tags']['hits'] . "`+1 WHERE `" . $FIELDS['tags']['id'] . "` = '" . $id . "' LIMIT 1 ;";
  12. unset($id);
  13. $conn->query($query);
  14. unset($query);
  15. $query = "UPDATE `" . $TABLES['allTags'] . "` SET `" . $FIELDS['allTags']['hits'] . "` = `" . $FIELDS['allTags']['hits'] . "`+1 WHERE `" . $FIELDS['allTags']['tag'] . "` = '" . $tag . "' LIMIT 1 ;";
  16. $conn->query($query);
  17. unset($query);
  18. }
  19. else{
  20. unset($query,$result);
  21. $query = "INSERT INTO `" . $TABLES['tags'] . "` (`" . $FIELDS['tags']['id'] . "`,`" . $FIELDS['tags']['tag'] . "`,`" . $FIELDS['tags']['obj'] . "`,`" . $FIELDS['tags']['id_obj'] . "`) VALUES (NULL,'" . $tag . "','" . $obj . "','" . $id_obj . "');";
  22. $conn->query($query);
  23. unset($query);
  24. $query = "INSERT INTO `" . $TABLES['allTags'] . "` (`" . $FIELDS['allTags']['tag'] . "`) VALUES ('" . $tag . "');";
  25. $conn->query($query);
  26. }
  27. return 1;
  28. }
  29. public function addViewTag($tag,$id_user,$obj){
  30. include_once "classes/config.php";
  31. global $TABLES,$FIELDS,$conn;
  32. $query = "SELECT `" . $FIELDS['userTags']['id'] . "` FROM `" . $TABLES['userTags'] . "` WHERE `" . $FIELDS['userTags']['tag'] . "` = '" . $tag . "' AND `" . $FIELDS['userTags']['obj'] . "` = '" . $obj . "' AND `" . $FIELDS['userTags']['user'] . "` = '" . $id_user . "' LIMIT 1;";
  33. $result = $conn->query($query);
  34. if($result->num_rows){
  35. $row = $result->fetch_row(); $id = $row[0];
  36. unset($query,$result);
  37. $query = "UPDATE `" . $TABLES['userTags'] . "` SET `" . $FIELDS['userTags']['hits'] . "` = `" . $FIELDS['userTags']['hits'] . "`+1 WHERE `" . $FIELDS['userTags']['id'] . "` = '" . $id . "' LIMIT 1 ;";
  38. $conn->query($query);
  39. }
  40. else{
  41. unset($query,$result);
  42. $query = "INSERT INTO `" . $TABLES['userTags'] . "` (`" . $FIELDS['userTags']['id'] . "`,`" . $FIELDS['userTags']['tag'] . "`,`" . $FIELDS['userTags']['obj'] . "`,`" . $FIELDS['userTags']['user'] . "`) VALUES (NULL,'" . $tag . "','" . $obj . "','" . $id_user . "');";
  43. $conn->query($query);
  44. }
  45. return 1;
  46. }
  47. public function addSearchTag($tag){
  48. include_once "classes/config.php";
  49. global $FIELDS,$TABLES,$conn;
  50. $query = "SELECT `" . $FIELDS['allTags']['hits'] . "` FROM `" . $TABLES['allTags'] . "` WHERE `" . $FIELDS['allTags']['tag'] . "` = '" . $tag . "' LIMIT 1;";
  51. $result = $conn->query($query);
  52. if($result->num_rows){
  53. unset($query);
  54. $query = "UPDATE `" . $TABLES['allTags'] . "` SET `" . $FIELDS['allTags']['hits'] . "` = `" . $FIELDS['allTags']['hits'] . "`+1 WHERE `" . $FIELDS['allTags']['tag'] . "` = '" . $tag . "' LIMIT 1;";
  55. $conn->query($query);
  56. }
  57. else{
  58. $query = "INSERT INTO `" . $TABLES['allTags'] . "` (`" . $FIELDS['allTags']['tag'] . "`) VALUES ('" . $tag . "');";
  59. $conn->query($query);
  60. }
  61. return 1;
  62. }
  63. public function primeleTaguri($obj,$id_obj){
  64. include_once "classes/config.php";
  65. global $FIELDS,$TABLES,$conn;
  66. $return = array();
  67. $query = "SELECT `" . $FIELDS['tags']['tag'] . "` FROM `" . $TABLES['tags'] . "` WHERE `" . $FIELDS['tags']['obj'] . "` = '" . $obj . "' AND `" . $FIELDS['tags']['id_obj'] . "` = '" . $id_obj . "' ORDER BY `" . $FIELDS['tags']['hits'] . "` DESC LIMIT 5;";
  68. $result = $conn->query($query);
  69. if($result->num_rows){
  70. while($row = $result->fetch_row())
  71. $return[count($return)] = $row[0];
  72. }
  73. unset($query,$result,$row);
  74. return $return;
  75. }
  76. }
  77. class SearchByTag{
  78. function __construct($tag,$pg = 1,$unde = NULL){
  79. if(is_null($unde)){
  80. $nrStiri = self::searchByTagGetNr($tag,"stiri");
  81. $nrFoto = self::searchByTagGetNr($tag,"foto");
  82. if($nrStiri)
  83. echo '<a href="stiri.php?tag=' . $tag . '">' . $nrStiri . ' rezultate</a> in stiri<br />' . "\n";
  84. if($nrFoto)
  85. echo '<a href="foto.php?tag=' . $tag . '">' . $nrFoto . ' rezultate</a> in foto<br />' . "\n";
  86. }
  87. else{
  88. if($unde == "stiri"){
  89. include_once "classes/stiri.php";
  90. $limitaInf = ( $pg - 1 ) * 5;
  91. Stiri::showNewsByTag($tag,"ASC",$limitaInf,false);
  92. }
  93. elseif($unde == "foto"){
  94. include_once "classes/foto.php";
  95. $limitaInf = ( $pg - 1 ) * 30;
  96. Foto::showFotosByTag($tag,$limitaInf,false);
  97. }
  98. else
  99. echo 'Nu exista pagina pe care o cautati!';
  100. }
  101. }
  102. public function searchByTagGetNr($tag,$unde){
  103. include_once "classes/config.php";
  104. global $FIELDS,$TABLES,$conn;
  105. $query = "SELECT `" . $FIELDS['tags']['id'] . "` FROM `" . $TABLES['tags'] . "` WHERE `" . $FIELDS['tags']['tag'] . "` = '" . $tag . "' AND `" . $FIELDS['tags']['obj'] . "` = '" . $unde . "'";
  106. $result = $conn->query($query);
  107. return $result->num_rows;
  108. }
  109. }
  110. class TagCloud{
  111. function __construct($where = NULL,$nr = NULL){
  112. include_once "classes/config.php";
  113. global $FIELDS,$TABLES,$conn;
  114. (string)$unde = "";
  115. if(isset($where)){
  116. if($where == "stiri")
  117. $unde = "stiri.php?";
  118. elseif($where == "foto")
  119. $unde = "foto.php?";
  120. else
  121. $unde = "facilities.php?ce=cauta-dupa-tag&amp;";
  122. }
  123. else
  124. $unde = "facilities.php?ce=cauta-dupa-tag&amp;";
  125. (string)$limit = " LIMIT 15";
  126. if(!is_null($nr))
  127. $limit = "";
  128. $query = "SELECT * FROM `" . $TABLES['allTags'] . "` ORDER BY `" . $FIELDS['allTags']['hits'] . "` DESC" . $limit . ";";
  129. $result = $conn->query($query);
  130. (int)$i = (int)$best = 0; (int)$max = 30;
  131. $class = 0;
  132. while($row = $result->fetch_row()){
  133. if($i == 0)
  134. $best = $row[1];
  135. $class = self::aprox( $row[1] / $best * $max);
  136. if($class < 7)
  137. $class = 7;
  138. echo '<a href="' . $unde . 'tag=' . str_replace(" ","+",$row[0]) . '" class="tagSize' . $class . '">' . $row[0] . '</a>' . "\n";
  139. $i++;
  140. }
  141. }
  142. private function aprox($numar){
  143. (string)$numar; $part = array();
  144. $part = explode(".",$numar);
  145. $part1 = @$part[1];
  146. if((int)$part1[0] < 5)
  147. return (int)$part[0];
  148. else
  149. return ((int)$part[0] + 1);
  150. }
  151. public function afiseazaTaguri($id_obj,$obj,$limit){
  152. include_once "classes/config.php";
  153. global $TABLES,$FIELDS,$conn;
  154. (string)$unde = "";
  155. if($obj == "stiri")
  156. $unde = "stiri.php?";
  157. elseif($obj == "foto")
  158. $unde = "foto.php?";
  159. else
  160. $unde = "facilities.php?ce=cauta-dupa-tag&amp;";
  161. $query = "SELECT `" . $FIELDS['tags']['tag'] . "`,`" . $FIELDS['tags']['hits'] . "` FROM `" . $TABLES['tags'] . "` WHERE `" . $FIELDS['tags']['id_obj'] . "` = '" . $id_obj . "' AND `" . $FIELDS['tags']['obj'] . "` = '" . $obj . "' ORDER BY `" . $FIELDS['tags']['hits'] . "` DESC LIMIT " . $limit . ";";
  162. $result = $conn->query($query);
  163. (int)$i = 0;
  164. $max = 30;
  165. while($row = $result->fetch_row()){
  166. if($i == 0)
  167. $best = $row[1];
  168. $class = self::aprox( $row[1] / $best * $max);
  169. if($class < 7)
  170. $class = 7;
  171. echo '<a href="' . $unde . 'tag=' . str_replace(" ","+",$row[0]) . '&amp;unde=' . $obj . '" class="tagSize' . $class . '">' . $row[0] . '</a>' . "\n"; $i++;
  172. }
  173. }
  174. }
  175. ?>