ОсновноеRadiotalkПользовательское
Технологии вещания, софт, скрипты
7   •   Посмотреть все темы

Поможите ! Рейтинг для песен PHP (оптимизировать)

 

54
wwc @wwc
Уважаемые форумчане !

Не являясь большим докой в области РНР программирования, очень прошу помощи в подгонке, и разъяснении установки ниже приложенного кода к SAM Broadcaster 4.9.0 . Просмотрев дирректорию PHP программы, увидел, что структуры файлов расходятся координально.

Спасибо.

  1.  
  2. <?
  3. ##############################################################################
  4. # #
  5. # This script was written by Paul MacArthur: ********** #
  6. # You are allowed to use this script freely on your website, but it is not #
  7. # to be sold or distributed to any other broadcaster, website, person or #
  8. # entity. To aquire the most recent version of this script, please visit: #
  9. # #
  10. # ********** #
  11. # #
  12. # In addition, please do not remove the credits and website URL provided in #
  13. # this section. Would very much appreciate that! #
  14. # #
  15. # Suggestions, comments and feedback: webmaster@celticradio.net #
  16. # #
  17. # -------------------------------------------------------------------------- #
  18. # #
  19. # PHP SAM COOKIE RATING SCRIPT #
  20. # ---------------------------- #
  21. # #
  22. # The purpose of this script is to allow for a cookie based rating system #
  23. # that works in conjunction with the PHP template provided via the SAM #
  24. # broadcaster by Spacial Audio. It has been tested with SAM V3 and above. #
  25. # #
  26. # Listeners can rate a song once every 24 hours and only when that song is #
  27. # playing on your broadcast. Some broadcasters have chosen to only allow #
  28. # one rating per song, but we believe that giving our listeners the #
  29. # ability to rate a song multiple times over time will create a #
  30. # better broadcast by playing the songs listeners want to hear. #
  31. # #
  32. # Not only does this script provide a rating system, but it also adds #
  33. # weight to a song that is rated based on the following formula: #
  34. # #
  35. # Rating of 5 add 5 to the weight. #
  36. # Rating of 4 add 3 to the weight. #
  37. # Rating of 2.5 add 0 to the weight. #
  38. # Rating of 1 add -3 to the weight. #
  39. # Rating of 0 add -5 to the weight. #
  40. # #
  41. # Additionally, your listeners will be able to see the current rating and #
  42. # weight of the song upon a successful rating via a pop-up web page. #
  43. # #
  44. # Because of buffering issues with web radio, sometimes the song playing #
  45. # will not match what shows on your website - it could be off by 5 seconds #
  46. # or 20 seconds. Therefore, we have built in a check that prevents rating #
  47. # a song that does not match what is currently playing on your broadcast. #
  48. # #
  49. # INSTRUCTIONS: #
  50. # #
  51. # Place this script in with the other PHP template files provided by SAM. #
  52. # View the CopyCode.txt file to easily grab the code. Copy all graphic #
  53. # files to appropriate locations. #
  54. # #
  55. # Add the following javascript code to your header file (header.php): #
  56. # #
  57. # <script LANGUAGE="JavaScript" type="text/javascript"> #
  58. # #
  59. # function ratesong(rating, songid) #
  60. # { #
  61. # var ratesong; #
  62. # if (ratesong) { #
  63. # ratesong++; #
  64. # } #
  65. # else { #
  66. # ratesong=0; #
  67. # } #
  68. # ratesong = window.open("./ratesong.php?rating="+rating+"&checkid=" #
  69. # +songid, "ratesongwin", "location=no,status=no,menubar=no,scrollbars #
  70. # =no,resizeable=yes,height=305,width=290"); #
  71. # } #
  72. # </script> #
  73. # #
  74. # The following HTML snipets should be placed on the page that your #
  75. # listeners will actually rate the song. I have also provided the HTML #
  76. # code to display the current rating of a song using the include star.gif #
  77. # graphic set. #
  78. # #
  79. # RATING FORM HTML: #
  80. # #
  81. # <? $songid = $song['songid']; ?> #
  82. # <form name="rateform" > #
  83. # <select style="font-family: Verdana, Arial, Helvetica, sans-serif; #
  84. # font-size: 10px; line-height: 150%; " name = "rate" #
  85. # onchange="if ((rate.value>=0) && (rate.value<6)) {ratesong(rate.value, #
  86. # <?echo $songid; ?>); rate.disabled=true; }"> #
  87. # <option value = "9" selected>Rate this song! #
  88. # <option value = "5">Love it! #
  89. # <option value = "4">Like it #
  90. # <option value = "2.5">It's OK #
  91. # <option value = "1">Don't Like it #
  92. # <option value = "0">Dump It! #
  93. # <option value = "9">Cancel #
  94. # </select> #
  95. # </form> #
  96. # #
  97. # DISPLAY RATING HTML: #
  98. # #
  99. # <span><b>Rating:&nbsp;</b> #
  100. # <? #
  101. # if ($song['rating'] == 0) { #
  102. # $rating_image = "stars-0-0.gif"; #
  103. # } #
  104. # #
  105. # if (($song['rating'] > 0) && ($song['rating'] < 1)) { #
  106. # $rating_image = "stars-0-5.gif"; #
  107. # } #
  108. # #
  109. # if (($song['rating'] >= 1) && ($song['rating'] < 1.5)) { #
  110. # $rating_image = "stars-1-0.gif"; #
  111. # } #
  112. # #
  113. # if (($song['rating'] >= 1.5) && ($song['rating'] < 2)) { #
  114. # $rating_image = "stars-1-5.gif"; #
  115. # } #
  116. # #
  117. # if (($song['rating'] >= 2) && ($song['rating'] < 2.5)) { #
  118. # $rating_image = "stars-2-0.gif"; #
  119. # } #
  120. # #
  121. # if (($song['rating'] >= 2.5) && ($song['rating'] < 3)) { #
  122. # $rating_image = "stars-2-5.gif"; #
  123. # } #
  124. # #
  125. # if (($song['rating'] >= 3) && ($song['rating'] < 3.5)) { #
  126. # $rating_image = "stars-3-0.gif"; #
  127. # } #
  128. # #
  129. # if (($song['rating'] >= 3.5) && ($song['rating'] < 4)) { #
  130. # $rating_image = "stars-3-5.gif"; #
  131. # } #
  132. # #
  133. # if (($song['rating'] >= 4) && ($song['rating'] < 4.5)) { #
  134. # $rating_image = "stars-4-0.gif"; #
  135. # } #
  136. # #
  137. # if (($song['rating'] >= 4.5) && ($song['rating'] < 5)) { #
  138. # $rating_image = "stars-4-5.gif"; #
  139. # } #
  140. # #
  141. # if ($song['rating'] >=5 ) { #
  142. # $rating_image = "stars-5-0.gif"; #
  143. # } #
  144. # ?> #
  145. # <img src="<? echo "$rating_image"; ?>" width="64" height="12"/> #
  146. # </span> #
  147. # #
  148. # #
  149. # CHANGES TO PHP TEMPLATE: #
  150. # #
  151. # The only changes required to the PHP template system provided by #
  152. # Spacial Audio is the FUNCTIONS.PHP file located in common directory: #
  153. # #
  154. # Add the following to the definitions section: #
  155. # #
  156. # Def($song["rating"],$song["rating"]); #
  157. # Def($song["num_ratings"],$song["num_ratings"]); #
  158. # #
  159. # Included with this script are the stars.gif graphic set to display #
  160. # stars on your website and also a graphic file to display "na.gif" when #
  161. # there is no album cover available. #
  162. # #
  163. # Please note that on CelticRadio.net we use a thumbnail version(100x100) #
  164. # to display a smaller version of the album cover in the rating script. #
  165. # You may need to adjust the pop-up size of the webpage to adjust to the #
  166. # standard size you use for displaying album covers. #
  167. # #
  168. # Any questions at all on installing this script, ways to make it better #
  169. # or just to say "Hello", give me a shout at webmaster@celticradio.net. #
  170. # #
  171. # #
  172. # #
  173. # #
  174. # #
  175. ##############################################################################
  176. require("config.php");
  177. $db->open("SELECT songlist.*, historylist.listeners as listeners, historylist.requestID as requestID, historylist.date_played as starttime FROM historylist,songlist WHERE (historylist.songID = songlist.ID) AND (songlist.songtype='S') ORDER BY historylist.date_played DESC LIMIT 6");
  178. $history = $db->rows();
  179. reset($history);
  180. $db->open("SELECT songlist.*, queuelist.requestID as requestID FROM queuelist, songlist WHERE (queuelist.songID = songlist.ID) AND (songlist.songtype='S') AND (songlist.artist <> '') ORDER BY queuelist.sortID ASC LIMIT 4");
  181. $queue = $db->rows();
  182. reset($queue);
  183. list($key, $song) = each($history);
  184. $listeners = $song["listeners"];
  185. PrepareSong($song);
  186. $rating = urlencode($_GET['rating']);
  187. $checkid = urlencode($_GET['checkid']);
  188. if ($rating == 5) $weight_add = 5;
  189. if ($rating == 4) $weight_add = 3;
  190. if ($rating == 2.5) $weight_add = 0;
  191. if ($rating == 1) $weight_add = -3;
  192. if ($rating == 0) $weight_add = -5;
  193. $new_weight = $song["weight"] + $weight_add;
  194. if ($new_weight > 100) $new_weight = 100;
  195. if ($new_weight < 0) $new_weight = 1;
  196. if (($new_weight > 0) && ($new_weight < 10)) $rotation = "No Rotation";
  197. if (($new_weight > 9) && ($new_weight < 20)) $rotation = "Rare Rotation";
  198. if (($new_weight > 19) && ($new_weight < 40)) $rotation = "Light Rotation";
  199. if (($new_weight > 39) && ($new_weight < 60)) $rotation = "Medium Rotation";
  200. if (($new_weight > 59) && ($new_weight < 80)) $rotation = "Heavy Rotation";
  201. if (($new_weight > 79) && ($new_weight < 101)) $rotation = "Power Hit";
  202. if (isset($_COOKIE[$song['songID']])) {
  203. $message = "<b>ERROR:</b> Sorry, only one rating<br>per song every 24 hours!";
  204. }
  205. else {
  206. if ($song['songID'] == $checkid) {
  207. $message = "Song successfuly weighted & rated!";
  208. if ($song['num_ratings'] == 0) {
  209. $query = "update songlist set rating = $rating, num_ratings = 1, total_rating = $rating, weight = $new_weight WHERE ID = ".$song['songID']."";
  210. $result = mysql_query($query);
  211. $song['num_ratings'] = 1;
  212. $song['rating'] = $rating;
  213. $rating = 0;
  214. setcookie($song['songID'], $song['title'], time()+86400); }
  215. else {
  216. $num_ratings = $song['num_ratings'];
  217. $num_ratings = $num_ratings + 1;
  218. $total_rating = $song['total_rating'] + $rating;
  219. $new_rating = $total_rating/$num_ratings;
  220. $song['num_ratings'] = $num_ratings;
  221. $query = "update songlist set rating = $new_rating, num_ratings = $num_ratings, total_rating = $total_rating, weight = $new_weight WHERE ID = ".$song['songID']."";
  222. $result = mysql_query($query);
  223. $song['rating'] = round($new_rating, 1);
  224. $new_rating = 0;
  225. setcookie($song['songID'], $song['title'], time()+86400);
  226. }
  227. } else {
  228. $song['title'] = "N/A";
  229. $song['artist'] = "N/A";
  230. $song['rating'] = 0;
  231. $song['picture_tb'] = "";
  232. $song['num_ratings'] = 0;
  233. $message = "<b>ERROR:</b> Rating failed. Next song is loading...";
  234. }
  235. }
  236. ?>
  237. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  238. <html>
  239. <head>
  240. <title>Song Rating - <? echo $song['title']; ?></title>
  241. <link rel="stylesheet" type="text/css" href="<?echo "$styleSheet"; ?>"/>
  242. </head>
  243. <body style="background-color:#e4e8dd">
  244. <div id ='small' align='center'>
  245. <img src='songrating.gif' />
  246. <br>
  247. <b>Artist:</b>&nbsp;<? echo $song['artist']; ?><br>
  248. <b>Song:</b> <? echo $song['title']; ?><br><br>
  249. <?
  250. if ($song['rating'] == 0) {
  251. $rating_image = "stars-0-0.gif";
  252. }
  253. if (($song['rating'] > 0) && ($song['rating'] < 1)) {
  254. $rating_image = "stars-0-5.gif";
  255. }
  256. if (($song['rating'] >= 1) && ($song['rating'] < 1.5)) {
  257. $rating_image = "stars-1-0.gif";
  258. }
  259. if (($song['rating'] >= 1.5) && ($song['rating'] < 2)) {
  260. $rating_image = "stars-1-5.gif";
  261. }
  262. if (($song['rating'] >= 2) && ($song['rating'] < 2.5)) {
  263. $rating_image = "stars-2-0.gif";
  264. }
  265. if (($song['rating'] >= 2.5) && ($song['rating'] < 3)) {
  266. $rating_image = "stars-2-5.gif";
  267. }
  268. if (($song['rating'] >= 3) && ($song['rating'] < 3.5)) {
  269. $rating_image = "stars-3-0.gif";
  270. }
  271. if (($song['rating'] >= 3.5) && ($song['rating'] < 4)) {
  272. $rating_image = "stars-3-5.gif";
  273. }
  274. if (($song['rating'] >= 4) && ($song['rating'] < 4.5)) {
  275. $rating_image = "stars-4-0.gif";
  276. }
  277. if (($song['rating'] >= 4.5) && ($song['rating'] < 5)) {
  278. $rating_image = "stars-4-5.gif";
  279. }
  280. if ($song['rating'] >=5 ) {
  281. $rating_image = "stars-5-0.gif";
  282. }
  283. ?>
  284. <img src="<? if ($song['picture']) {echo $song['picture'];} else { echo "na.gif";} ?>" align="center" /><br>
  285. <img src="<? echo "$images"; ?><? echo "$rating_image"; ?>" align="center" />
  286. <br>
  287. <? if ($song['num_ratings'] == 0) {echo "Not Rated Yet";} ?><br>
  288. <b>Current Rating:</b> <? echo $song['rating']; ?>/5&nbsp;&nbsp;&nbsp;<b># of Ratings:</b> <? echo $song['num_ratings']; ?>
  289. <br>
  290. <b>Broadcast Weight:</b> <? echo $new_weight."% - ".$rotation; ?><br><br>
  291. <? echo $message; ?>
  292. </div>
  293. </body>
  294. </html>

Отредактировано wwc - 22.08.2013
0





Согласие на обработку данных на нашем сайте

Продолжая просматривать страницу, вы соглашаетесь с использованием файлов «Cookie» и с Политикой конфиденциальности «Privacy».
Наверху или внизу страницы вы можете изменить валюту и язык по умолчанию. Английская версия сайта ещё находится в доработке и доступна не полностью.