Skip to Content
It is currently October 23rd, 2019, 11:40 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: September 20th, 2019, 4:52 pm 
Offline
Senior User
Senior User

Joined: July 23rd, 2007, 2:22 am
Posts: 117
I would like the ability for someone to enter a comment about a song directly on the song's record when it's playing, and save that comment in the samdb (or separate) database. Next time the song plays, I want whoever is listening to it to be able to see the comments and have the option to add his or her own comment to the same track.

I tried using a PHP/MySQL comment form I found on the Internet and it does work, but it contained too much javascript and features like smilies and the ability to upload images in the comment and collapsible menus, which I do not need. I need a simple form that asks for user's name or alias, the comment, and captcha for spam protection.

Is such a thing possible? Does anyone know where I can find such a script?

Thanks!
Dan

_________________
Park Magic Radio
http://parkmagicradio.ca


Last edited by DJ Cassio on September 21st, 2019, 11:00 am, edited 1 time in total.
Moved to Web Features


Top
 Profile  
Reply with quote  
PostPosted: September 21st, 2019, 10:58 am 
Offline
SVS Member
SVS Member

Joined: May 8th, 2004, 9:00 am
Posts: 10449
Location: Denver, CO
Yes it is possible, I have that feature on my website. My site is AJAX based so, my script would not work you. However I will share so you will have some idea how to do it.

I created a table in SAMDB called song_comments

Song comments appear and are entered on the Now Playing page:
Code:
  //Get Song Comments
  $comments_rows = mysqli_query( $samDB, "Select comments, username, create_date from song_comments WHERE deleted_flag=0 and songid in ( " . $now_playing["song_id"] . " ) order by id desc" );

<!-- Song Comments -->   
            <tr>      
              <td><hr/></td>
            </tr> 
            <tr>
              <td>
              <div id="comments">   
                <div style="display:inline"><b>Song Comments:</b></div>
                     <ul>
                    <?php
                          $c=0;
                    $nameArray = Array();
                         while ( $row = mysqli_fetch_assoc( $comments_rows ) ) {?>
                          <li><?php echo( date( $configuration->date_time_format, strtotime( $row["create_date"] ) ) );
                                 echo " - <b>";
                                 echo( $row["username"] ); 
                                 echo "</b> wrote ";
                                 echo "<i>\"";
                                 echo( stripslashes(str_replace("&amp;quot;", "'",$row['comments'])));
                                 echo "</i> \""?>        
                             </li>
                    <?php
                    $nameArray[] = $row["username"];
                    $c++; } ?>
                      </ul>
                      <? if($c == 0 ) { ?>
                        No song comments posted yet
                      <?php } ?>
                  <br/>
                  <b>
                    <font color="green" size=1>
                      Comments are the opinions of the users/listeners who post them and do not represent the views or opinions of 5280 Light Jazz.
                      <br/>                 
                    </font>
                  </b>
               <?php if ((sizeof($nameArray) == 0 || !in_array($username, $nameArray)) && $is_registered) { 
                  ?>
                  <div style="display:inline"><b>Enter Song Comments:</b></div>
                <div id="expander9" style="display:inline">
                  <a href="javascript:expandBlock(9);" title="Expand this block">[+]</a>
                </div>
                <div id="item9" style="display:none">
                 <form name="theSongForm" action="#" method="post">
                          <textarea id="comment" cols="30" rows="8"></textarea>
                             <br>
                             <font face="Verdana, Arial, Helvetica" size="1">
                            Maximum comment is 200 characters
                             </font>
                             <br>
                             <input type='hidden' id='song_id' value="<?php echo $now_playing["song_id"];?>">
                             <INPUT TYPE="button" Value="Submit Comments" onClick="javascript:doComment(document.getElementById('comment').value, document.getElementById('song_id').value);">
                             &nbsp;&nbsp;&nbsp;<input type="button" Onclick="javascript:alert('Comment length:\n' + document.theSongForm.comment.value.length + ' character(s)');" value="Check length">
                        </form>
              </div>
               <?php }?>
             </div>
              </td>
            </tr>
            <tr>      
              <td><hr/></td>
            </tr>
<!-- End Song Comments -->   


This script processes the input for song comments and is called comments.php
Code:

<?php

  
// ANY EDITS BELOW THIS LINE ARE AT YOUR OWN RISK.  GOOD LUCK.

  // stop hackers from accessing included or required files
  define( "IN_5280Jazz", true );

  // do the setup
  require_once( "include/setup.php" );

  // build the page
  if ( !$is_registered )
  {
    exit();
  }

  $comments = $_POST["comments"];
  $the_id   = $_POST["id"];
  $mode = $_POST["mode"];

  if (isset($comments)) {

   $comments = mysqli_real_escape_string( $samDB, $comments);


     if (strlen($comments) <= 0) {
       $mode = "error";
       $error_message = "No comment!";
     }
     if (strlen($comments) > 200) {
       $mode = "error";
       $error_message = "Comment too large!";
     }}
//Duplicate check          
$comment_row = mysqli_query( $samDB,  "Select comments from song_comments WHERE userid = ( " . $user->data['user_id'] . " ) and songid = ".$the_id." " );
$dup_check = mysqli_fetch_assoc( $comment_row );
if ( $dup_check['comments'] == "" ) {
 if(( $mode == "add" ) && (isset( $comments )) ) {
   $insertTime = time();
   mysqli_query( $samDB,  "INSERT into song_comments (comments, create_date, username, songid, userid) VALUES ('$comments', '" . date("Y-m-d H:i:s", $insertTime) . "', '$username', '$the_id', " . $user->data['user_id'] . ")" );
     } 

}
//Get Comments
  $comments_rows = mysqli_query( $samDB,  "Select comments, username, create_date from song_comments WHERE deleted_flag=0 and songid = ".$the_id." order by id desc" );

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Song Comments</title>
    <meta charset="utf-8"/>
  </head>
  <body>
                <div style="display:inline"><b>Song Comments:</b></div>
                     <ul>
                    <?php 
                          $c=0;
                          $nameArray = array();
                         while ( $row = mysqli_fetch_assoc( $comments_rows ) ) {?>
                          <li><?php echo( date( $configuration->date_time_format, strtotime( $row["create_date"] ) ) );
                                  echo " - <b>";
                                  echo( $row["username"] );  
                                  echo "</b> wrote ";
                                  echo "<i>\"";
                                  echo stripslashes($row['comments']); 
                                  echo "</i> \""?>          
                              </li>
                    <?php 
                    $nameArray[] = $row["username"];
                    $c++; } ?>
                      </ul>
                      <? if($c == 0 ) { ?>
                        No song comments posted yet
                      <?php } ?>
                  <br/>
                  <b>
                    <font color="green" size=1>
                      Comments are the opinions of the users/listeners who post them and do not represent the views or opinions of 5280 Light Jazz.
                      <br/>                  
                    </font>
                  </b>
               <?php if (sizeof($nameArray) == 0 || !in_array($username, $nameArray)) {  
                   ?>
                   <div style="display:inline"><b>Enter Comments:</b></div>
                <div id="expander9" style="display:inline">
                  <a href="javascript:expandBlock(9);" title="Expand this block">[+]</a>
                </div>
                <div id="item9" style="display:none">                  
                  <form name="theForm" action="#" method="post">
                                <textarea id="comments" cols="50" rows="5"></textarea>
                                    <br>
                                    <font face="Verdana, Arial, Helvetica" size="1">
                                  Maximum comment is 200 characters
                                    </font>
                                    <br>
                                    <input type='hidden' id='mode' value="add">
                                    <input type='hidden' id='song_id' value="<?php echo $now_playing["song_id"];?>">
                                    <INPUT TYPE="button" Value="Submit Comment" onClick="javascript:doComment(document.getElementById('mode').value, document.getElementById('comments').value, document.getElementById('song_id').value);">
                                    &nbsp;&nbsp;&nbsp;<input type="button" Onclick="javascript:alert('Comment length:\n' + document.theForm.comments.value.length + ' character(s)');" value="Check length">
                              </form>
              </div>
               <?php }?>
       
      
</body>
</html>
<?php require_once( "include/teardown.php" ); ?>


This is the AJAX code:
Code:
function doComment( comment, song_id )
{
   var mode = 'add';
  new Ajax.Request('comments.php',
  {
    method:'post',
    parameters: {fhr_time: getFHRTime(), mode: mode, comments: comment, id: song_id},
    onSuccess: function(transport)
    {
      var response = transport.responseText || "no response";

      new Effect.Fade( "comments",
      { afterFinish: function ()
        {
          document.getElementById( "comments" ).innerHTML = response;
          new Effect.Appear( "comments" );
        }
      });
    }
  });
}

_________________
- Rob Oyler, SVS
Image


Top
 Profile  
Reply with quote  
PostPosted: September 25th, 2019, 11:21 am 
Offline
Senior User
Senior User

Joined: July 23rd, 2007, 2:22 am
Posts: 117
This is very intriguing! Thank you for posting your code. I'll see what I can do with it and report back if I have any questions.

_________________
Park Magic Radio
http://parkmagicradio.ca


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group