PHP Classes

File: template.php

Recommend this page to a friend!
  Classes of Viktor   Universal comment module   template.php   Download  
File: template.php
Role: Auxiliary script
Content type: text/plain
Description: Template script
Class: Universal comment module
Generic site comments system
Author: By
Last change: Fixed problem with special symbols.
Date: 16 years ago
Size: 2,713 bytes
 

Contents

Class file image Download
<?php
function getTPLComments($msgArr = array(),$id=0,$userId=1)
{
   
   
   
$form_id = $id;
       
   
$msg = '<div class="commentBox"><div id="_'.$form_id.'_comments">';
    if(
testArray($msgArr))
    foreach (
$msgArr as $com)
    {
       
$msg.= getTplROW($com);
    }
   
$msg .='
        </div>
    '
;
    if(
$userId >0)
    {
   
$msg .='
        <div>
            <form name="'
.$form_id.'_form" id="'.$form_id.'_form">
            <textarea name="msg" id="'
.$form_id.'_msg" class="commentTextArea"></textarea>
            <div id="'
.$form_id.'_submit">
            <input type="button" value="Add Comment" class="commentSubmit" onClick="_'
.$form_id.'ajaxRequest(\''.URL_TO_API.'\', $(\''.$form_id.'_form\').serialize())">
            </div>
            <div id="'
.$form_id.'_loading" style="display: none;">
                <img src="'
._URL_.'loading.gif" border="0">
            </div>
            <input type="hidden" name="id" id="'
.$form_id.'_id" value="'.$form_id.'">
            <input type="hidden" name="uid" id="'
.$form_id.'_uid" value="'.$userId.'">
            </form>
        </div>
    '
;
    }
   
$msg .='
        </div>
        '
;

   
$msg.='
   
<script type="text/javascript">

    /* ajax.Request */
function _'
.$form_id.'ajaxRequest(url,data)
    {
      var aj = new Ajax.Request(
      url, {
      method:\'post\',
      parameters: data,
      onComplete: _'
.$form_id.'getResponse
      }
     );
     $("'
.$form_id.'_submit").style.display= "none";
      $("'
.$form_id.'_loading").style.display= "block";
   }
   /* ajax.Response */
   function _'
.$form_id.'getResponse(oReq)
   {
// alert(oReq.responseText);
       '
;
   
   
   
    if(
_MESSAGES_DERECTION == 1)
          
$msg .='$("_'.$form_id.'_comments").innerHTML = oReq.responseText + $("_'.$form_id.'_comments").innerHTML ; ';
    else
       
$msg .='$("_'.$form_id.'_comments").innerHTML = $("_'.$form_id.'_comments").innerHTML + oReq.responseText; ';
      
$msg .='
        $("'
.$form_id.'_msg").value="";
       
        $("'
.$form_id.'_loading").style.display= "none";
        $("'
.$form_id.'_submit").style.display= "block";
       
       
       
   }
  </script>
 

   
   
    '
;
    return
$msg;
}



function
getTplROW($com)
{
   
$lmsg='
        <div class="commentRow">
            <table cellpadding="0" cellspacing="0" border="0" style="width: 100%">
                <tr>
                    <td class="commentMSG"><pre>'
.$com['msg'].'</pre></td>
                </tr>
                <tr>
                    <td class="commentInfo">
                        <table cellpadding="0" cellspacing="0" border="0" style="width: 100%">
                            <tr>
                                <td align="left" class="commentUser">'
.$com['username'].'</td>
                                <td align="right" class="commentDate">'
.$com['ldate'].'</td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
       
   
    '
;
    return
$lmsg;
}

?>