Login   Register  
PHP Classes
elePHPant
Icontem

File: coco.html.php4

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Matthias Richter  >  phpMyCoCo  >  coco.html.php4  >  Download  
File: coco.html.php4
Role: ???
Content type: text/plain
Description: html rendering class
Class: phpMyCoCo
Author: By
Last change:
Date: 2001-03-11 13:43
Size: 15,218 bytes
 

Contents

Class file image Download
<?php

// this class *requires* conf.vars.php

class cocoHTML
{
  function showErrorMessage($error)
  {
    if(!empty($error))
    {
      echo "<div class=\"error\"><p>$error</p></div>\n<br>";
    }
  }

  function showPageDescInput($cocodb,$pgid)
  {
    global $COCO_CONF_VARS;
    global $COCO_STRINGS;
    global $HTTP_POST_VARS;
    // Check if there is a description in the db
    if(!isset($HTTP_POST_VARS[description]))
    {
      $query = "SELECT description FROM $COCO_CONF_VARS[TBCOUNTER]";
      $query.= " WHERE id='$pgid';";
      $answer = $cocodb -> db_query($query);
      if($result = $cocodb -> db_fetch_array($answer))
      {
        $description = $result[description];
      }
    }
?>
<h1><?php echo $COCO_STRINGS[DESC_INPUT_TITLE]; ?></h1>
<form action="<?php echo $COCO_CONF_VARS[COMMENT];
  ?>?action=addesc&pgid=<?php echo $pgid; ?>" method="post">
<table>
<tr>
  <td><p><?php echo $COCO_STRINGS[DESC_PWPLEASE]; ?></p></td>
  <td><input type="password" name="password" value="<?php 
    echo $HTTP_POST_VARS[password];
  ?>"></td>
</tr>
<tr>
  <td valign="top"><p><?php echo $COCO_STRINGS[DESC_TEXT]; ?></p></td>
  <td><textarea name="description" rows=15 cols=50><?php 
  if (isset($description) && !empty($description))
  {
    echo $description;
  } else {
    echo $HTTP_POST_VARS[description];
  }
  ?></textarea></td>
</tr>
<tr>
  <td></td>
  <td><input type="submit" value="<?php 
    echo $COCO_STRINGS[DESC_SUBMIT_BUTTON];
  ?>"></td>
</tr>
</table>
</form>
<?php
  }

  function showPageDescription($cocodb,$pgid)
  {
    global $COCO_STRINGS;
    global $COCO_CONF_VARS;
    $query = "SELECT description,name FROM $COCO_CONF_VARS[TBCOUNTER]";
    $query.= " WHERE id='$pgid';";
    $answer = $cocodb -> db_query($query);
    $result = $cocodb -> db_fetch_array($answer);
    $description = $result[description];
    $this -> pageref = $name = $result[name];
    $refp = $COCO_STRINGS[REFP];
    if(empty($description))
    {
      $description = $COCO_STRINGS[MAGIC_NODESCRIPTION];
      $desctext = $COCO_STRINGS[MAGIC_E_DESCRIPTION]; 
      $description = ereg_replace("<--DESCRIPTION-->",
        "<a href=\"$COCO_CONF_VARS[COMMENT]?action=addesc&" . 
	"pgid=$pgid\">$desctext</a>",$description);
      $description = ereg_replace("<--REFP-->",
        "<a href=\"$name\">$refp</a>",$description);
      $description = "<div class=\"commenttext\">" . $description . "</div>";
    } else {
     $desc0 = $COCO_STRINGS[DESCRIPTION];
      $desc0 = ereg_replace("<--REFP-->",
        "<a href=\"$name\">$refp</a>",$desc0);
     $desc1 = $COCO_STRINGS[MAGIC_DESCRIPTION];
     $desctext = $COCO_STRINGS[MAGIC_E_CHANGE];
     $desc1 = ereg_replace("<--CHANGE-->",
        "<a href=\"$COCO_CONF_VARS[COMMENT]?action=addesc&" . 
	"pgid=$pgid\">$desctext</a>",$desc1);
    $description = nl2br($description);
    $description = "<div class=\"deschead\">" . $desc0 . 
      "</div>\n<div class=\"commenttext\">" . $description . 
      "</div>\n<div class=\"descfoot\">" . $desc1 . "</div>";
    }
    echo "$description\n<br>";
  }
  
  function showInclude
    ($pageid, $numbercomments, $hits, $author, $date, $title, $email, $url)
  {
    global $COCO_CONF_VARS;
    global $COCO_STRINGS;

    $author = rawurldecode($author);
    $title = rawurldecode($title);
    $email = rawurldecode($email);

    $views = $COCO_STRINGS[MAGIC_VIEWS];
    $comments = $COCO_STRINGS[MAGIC_COMMENTS];
    $lastcomment = $COCO_STRINGS[MAGIC_LAST_COMMENT];
    $read = $COCO_STRINGS[MAGIC_READ];
    $write = $COCO_STRINGS[MAGIC_WRITE];

    // Open Links in blank window?
    if($COCO_CONF_VARS[TARGETBLANK]=="yes")
      { $target="target=_blank";} else { $target=""; }
    // Automagically insert variables into the output-text
    $views = ereg_replace("<--HITS-->","$hits", $views);
    $comments = ereg_replace("<--COMMENTS-->","$numbercomments",$comments);
    $comments = ereg_replace 
      ( "<--READ-->",
        "<a $target href=\"$COCO_CONF_VARS[COMMENT]?action=read&pgid=$pageid\">$read</a>",
	$comments);
    $comments = ereg_replace 
      ("<--WRITE-->",
      "<a $target href=\"$COCO_CONF_VARS[COMMENT]?action=write&pgid=$pageid\">$write</a>",
      $comments);
    if($numbercomments>0)
    {
      $lastcomment = ereg_replace("<--TITLE-->","$title",$lastcomment);
      $lastcomment = ereg_replace("<--AUTHOR-->", 
        "<a href='mailto:$email'>$author</a>", $lastcomment);
      $lastcomment = ereg_replace("<--DATE-->","$date",$lastcomment);
    } else {
      $lastcomment = "";
    }
    
    $homelink = $COCO_STRINGS[HOMELINK];
    // Output ...
    echo "<div class=\"footer\">" .$views . $comments . "\n<br>" 
    . $lastcomment . $homelink ."</div>\n";
  }

  function showCommentInput($pageid,$parentid)
  {
  global $HTTP_SERVER_VARS;
  global $HTTP_POST_VARS;
  global $COCO_CONF_VARS;
  global $COCO_STRINGS;
  if(empty($parentid))
    {$parentid=0;}
?>
<form action="<?php echo $COCO_CONF_VARS[COMMENT]; 
  ?>?pgid=<?php echo $pageid; ?>&action=input&paid=<?php echo $parentid; ?>" 
  method="post">
<table border=0 cellpadding=0 cellspacing=0>
  <tr>
    <td><p class="input"><?php echo $COCO_STRINGS[NAME]; ?></p></td>
    <td><input type="text" name="name" 
      value="<?php echo $HTTP_POST_VARS[name]?>"></td>
  </tr>
  <tr>
    <td><p class="input"><?php echo $COCO_STRINGS[EMAIL]; ?></p></td>
    <td><input type="text" name="email" 
      value="<?php echo $HTTP_POST_VARS[email]?>"></td>
  </tr>
  <tr>
    <td><p class="input"><?php echo $COCO_STRINGS[URL]; ?></p></td>
    <td><input type="text" name="url" 
      value="<?php echo $HTTP_POST_VARS[url]?>"></td>
  </tr>
  <tr>
    <td><p class="input"><?php echo $COCO_STRINGS[TITLE]; ?></p></td>
    <td><input type="text" name="title" 
      value="<?php echo $HTTP_POST_VARS[title]?>"></td>
  </tr>
  <tr>
    <td align="right"><input type="checkbox" name="replies"></td>
    <td><p class="input">&nbsp;<?php echo $COCO_STRINGS[REPLIES]; ?></p></td>
  </tr>
  <tr>
    <td valign="top"><p class="input"><?php echo $COCO_STRINGS[TEXT]; ?></p></td>
    <td><textarea name="text" cols="50" rows="15" wrap=virtual><?php 
       echo $HTTP_POST_VARS[text];
    ?></textarea></td>
  </tr>
  <tr>
    <td></td>
    <td><input type="submit" 
      value="<?php echo $COCO_STRINGS[INPUT]?>"></td>
  </tr>
</table>
</form>
<?php
  }
  
  // Show only one comment $paid
  function showComment
    ($cocodb, $id)
  {
    global $COCO_CONF_VARS;
    // Show all comments with pageid=$pageid and parentid=0
    // ordered by time
    $query = "SELECT c.id,name,title,email,url,text,replies,a.lasttime ";
    $query.= "as time FROM $COCO_CONF_VARS[TBCOMMENT] as c,";
    $query.= " $COCO_CONF_VARS[TBACCESS] as a WHERE ";
    $query .= "acid=a.id AND c.id=$id;";
    $answer = $cocodb -> db_query($query);
    if($result = $cocodb -> db_fetch_array($answer))
    {
      $this -> beginTopComment();
      $this -> printOneComment
        ( $result[id], 
	  rawurldecode($result[name]), 
	  rawurldecode($result[title]),
	  rawurldecode($result[email]), 
	  rawurldecode($result[url]), 
	  rawurldecode($result[text]), 
	  $result[replies], $result[time], $pageid);
      $this -> endTopComment();
    }
  }
  
  // Show the comments for pageid (threaded)
  function showComments
    ($cocodb, $pageid)
  {
    global $COCO_CONF_VARS;
    global $COCO_STRINGS;
    // Show all comments with pageid=$pageid and parentid=0
    // ordered by time
    $query = "SELECT c.id,name,title,email,url,text,replies,a.lasttime ";
    $query.= "as time FROM $COCO_CONF_VARS[TBCOMMENT] as c,";
    $query.= " $COCO_CONF_VARS[TBACCESS] as a WHERE paid=0 AND ";
    $query .= "acid=a.id AND pgid=$pageid ORDER BY acid ";
    if($COCO_CONF_VARS[ORDER_T_COMMENTS]=="LATEST") 
    {
      $query .= "DESC;";
    } else{
      $query .= "ASC;";
    }
    $answer = $cocodb -> db_query($query);
    echo "<h1>$COCO_STRINGS[COM_PAGE_TITLE]</h1>";
    while($result = $cocodb -> db_fetch_array($answer))
    {
      $this -> beginTopComment();
      $this -> printComment
        ( $result[id], 
	  rawurldecode($result[name]), 
	  rawurldecode($result[title]),
	  rawurldecode($result[email]), 
	  rawurldecode($result[url]), 
	  rawurldecode($result[text]), 
	  $result[replies], $result[time], $pageid);
      $this -> showChildren($cocodb,$result[id],$pageid);
      $this -> endTopComment();
    }
  }
  
  function showChildren 
    ($cocodb,$commentid,$pageid)
  {
    global $COCO_CONF_VARS;
    // Show all comments with pageid=$pageid and
    // parentid=$commentid ordered by time
    $query = "SELECT c.id,name,title,email,url,text,replies,a.lasttime ";
    $query.= "as time FROM $COCO_CONF_VARS[TBCOMMENT] as c,";
    $query.= " $COCO_CONF_VARS[TBACCESS] as a WHERE paid=$commentid AND ";
    $query .= "acid=a.id ORDER BY acid ";
    if($COCO_CONF_VARS[ORDER_S_COMMENTS]=="FIRST") 
    {
      $query .= "ASC;";
    } else{
      $query .= "DESC;";
    }
    $answer = $cocodb -> db_query($query);

    if($result = $cocodb -> db_fetch_array($answer))
    {
      // recusively show children...
      do 
      {
        $this -> beginSubComment();
	$this -> printComment
          ( $result[id], 
	  rawurldecode($result[name]), 
	  rawurldecode($result[title]),
	  rawurldecode($result[email]), 
	  rawurldecode($result[url]), 
	  rawurldecode($result[text]), 
	  $result[replies], $result[time], $pageid);
        $this -> showChildren($cocodb,$result[id], $pageid);
	$this -> endSubComment();
      } while($result = $cocodb -> db_fetch_array($answer));
    } else {
      // unless there is nothing to show
    }
  }

  function printOneComment
    ($id,$name,$title,$email,$url,$text,$replies,$time,$pageid)
  {
    global $COCO_STRINGS;
    global $COCO_CONF_VARS;

    $titlestring = $COCO_STRINGS[MAGIC_AC_FOOT];
    $headstring = $COCO_STRINGS[MAGIC_AC_HEAD];
    $date = date("$COCO_CONF_VARS[TIMESTRING]",$time);
    $name .= " [ <a href=\"mailto:$email\">email</a> ";
    if(empty($url))
    {
      $name .= "]";
    } else {
      $name .= "| <a href=\"http://$url\">homepage</a> ]";
    }
    $titlestring = ereg_replace("<--AUTHOR-->", "$name", $titlestring);
    $titlestring = ereg_replace("<--DATE-->","$date",$titlestring);
    $headstring = ereg_replace("<--TITLE-->",
      "&quot;$title&quot;", $headstring);
    $text = nl2br($text);

    echo "<div class=\"commenttitle\">$headstring</div>\n";
    echo "<div class=\"commenttext\">$text</div>\n";
    echo "<div class=\"commentfoot\">$titlestring</div>\n<br>";
  }
  
  function printComment
    ($id,$name,$title,$email,$url,$text,$replies,$time,$pageid)
  {
    global $COCO_STRINGS;
    global $COCO_CONF_VARS;

    $titlestring = $COCO_STRINGS[MAGIC_C_TITLE];
    $date = date("$COCO_CONF_VARS[TIMESTRING]",$time);
    $name .= " [ <a href=\"mailto:$email\">email</a> ";
    if(empty($url))
    {
      $name .= "]";
    } else {
      $name .= "| <a href=\"http://$url\">homepage</a> ]";
    }
    $titlestring = ereg_replace("<--AUTHOR-->", "$name", $titlestring);
    $titlestring = ereg_replace("<--DATE-->","$date",$titlestring);
    $titlestring = ereg_replace("<--TITLE-->",
      "&quot;$title&quot;", $titlestring);
    $text = nl2br($text);
    $footstring = $COCO_STRINGS[MAGIC_C_FOOT];
    $footstring = ereg_replace("<--ADD-->",
    "<a href=\"$COCO_CONF_VARS[COMMENT]?action=write&paid="
    . "$id&pgid=$pageid\">$COCO_STRINGS[MAGIC_ADD]</a>",
    $footstring);
    $footstring = ereg_replace("<--EDIT-->",
    "<a href=\"$COCO_CONF_VARS[COMMENT]?action=edit&cid=$id"
    . "&pgid=$pageid\">$COCO_STRINGS[MAGIC_EDIT]</a>",
    $footstring);

    echo "<div class=\"commenttitle\">$titlestring</div>\n";
    echo "<div class=\"commenttext\">$text</div>\n";
    echo "<div class=\"commentfoot\">$footstring</div>\n<br>";
  }

  function showEditCommentForm($cocodb,$cid,$pgid)
  {
    global $COCO_CONF_VARS;
    global $COCO_STRINGS;
    global $HTTP_POST_VARS;
    // get comment
    // password has already been checked in comment.php, so
    // if there is a password we consider it to be correct
    if(!isset($HTTP_POST_VARS[password]))
    {
      $query = "SELECT name,title,email,url,text FROM ";
      $query.= "$COCO_CONF_VARS[TBCOMMENT] WHERE id=$cid;";
      $answer = $cocodb -> db_query($query);
      if($result = $cocodb -> db_fetch_array($answer))
      {
        $name = rawurldecode($result[name]);
	$title = rawurldecode($result[title]);
	$email = rawurldecode($result[email]);
	$url = rawurldecode($result[url]);
	$text = rawurldecode($result[text]);
      }
    } else {
      $name = $HTTP_POST_VARS[name];
      $title = $HTTP_POST_VARS[title];
      $email = $HTTP_POST_VARS[email];
      $url = $HTTP_POST_VARS[url];
      $text = $HTTP_POST_VARS[text];
    }
?>
<h1><?php echo $COCO_STRINGS[EDIT_COMMENT]; ?></h1>
<form action="<?php echo $COCO_CONF_VARS[COMMENT]; 
  ?>?pgid=<?php echo $pgid; ?>&action=edit&cid=<?php echo $cid; ?>" 
  method="post">
<table border=0 cellpadding=0 cellspacing=0>
  <tr>
    <td><p class="input"><?php echo $COCO_STRINGS[E_NAME]; ?></p></td>
    <td><input type="text" name="name" 
      value="<?php echo $name; ?>"></td>
  </tr>
  <tr>
    <td><p class="input"><?php echo $COCO_STRINGS[E_EMAIL]; ?></p></td>
    <td><input type="text" name="email" 
      value="<?php echo $email; ?>"></td>
  </tr>
  <tr>
    <td><p class="input"><?php echo $COCO_STRINGS[E_URL]; ?></p></td>
    <td><input type="text" name="url" 
      value="<?php echo $url;?>"></td>
  </tr>
  <tr>
    <td><p class="input"><?php echo $COCO_STRINGS[E_TITLE]; ?></p></td>
    <td><input type="text" name="title" 
      value="<?php echo $title;?>"></td>
  </tr>
  <tr>
    <td valign="top"><p class="input"><?php echo $COCO_STRINGS[E_TEXT]; ?></p></td>
    <td><textarea name="text" cols="50" rows="15" wrap=virtual><?php 
       echo $text;
    ?></textarea></td>
  </tr>
  <tr>
    <td><p><?php echo $COCO_STRINGS[DESC_PWPLEASE]; ?></p></td>
    <td><input type="password" name="password" value="<?php 
      echo $HTTP_POST_VARS[password];
    ?>"></td>
  </tr>
  <tr>
    <td align="right"><input type="checkbox" name="drop"></td>
    <td><p><?php echo $COCO_STRINGS[DROP_COMMENT]; ?></p></td>
  </tr>
  <tr>
    <td></td>
    <td><input type="submit" 
      value="<?php echo $COCO_STRINGS[E_INPUT]?>"></td>
  </tr>
</table>
</form>
<?php
  }

  function beginTopComment()
  {
//    echo "<table><tr><td width=\"10\">&nbsp;</td><td>";
  }
  function endTopComment(){
//    echo "</td></tr></table>";
  }
  function beginSubComment()
  {
//    echo "<table><tr><td width=\"10\">&nbsp;</td><td>";
    echo "<blockquote>";
  }
  function endSubComment()
  {
//    echo "</td></tr></table>";
    echo "</blockquote>";
  }
}
?>