PHP Classes

File: coco.main.php4

Recommend this page to a friend!
  Classes of Matthias Richter   phpMyCoCo   coco.main.php4   Download  
File: coco.main.php4
Role: ???
Content type: text/plain
Description: main phpmycoco-class
Class: phpMyCoCo
Author: By
Last change:
Date: 23 years ago
Size: 5,797 bytes
 

Contents

Class file image Download
<?php if(!include("$COCOPATH/conf.vars.php4")) {echo "Cannot include conf.vars !\n";} if(!include("$COCOPATH/coco.db.php4")) {echo "Cannot include coco.db !\n";} if(!include("$COCOPATH/coco.log.php4")) {echo "Cannot include coco.log !\n";} if(!include("$COCOPATH/coco.commenter.php4")) {echo "Cannot include coco.commenter !\n";} if(!include("$COCOPATH/coco.html.php4")) {echo "Cannot include coco.html !\n";} if(isSet($HTTP_SERVER_VARS[QUERY_STRING]) && !empty($HTTP_SERVER_VARS[QUERY_STRING])) { if(!include("$COCOPATH/coco.queryparse.php4")) {echo "Cannot include coco.queryparse !\n";} } if($COCO_CONF_VARS[REQUIREEMAIL]=="yes") { if(!include("$COCOPATH/email_validation.php")) {echo "Cannot include email_validation !\n";} } ?> <? class phpMyCoCo { // This class does *not* have a constructor for the fact // that extending classes having constructors is not quite // what you want to puzzle out. It explicitely uses an // init()-Method instead. // Set up a Connection to our Database function init() { global $HTTP_SERVER_VARS; // CREATE new Database Link, Logger, Counter, Commenter, HTML-Writer $this -> cocodb = new cocoDB; $this -> cocolog = new cocoLOG; $this -> cococommenter = new cocoCOMMENTER; $this -> cocohtml = new cocoHTML; // CONNECT to Database, then set some variables and log access $this -> cocodb -> db_connect(); $this -> setVars(); $this -> hits = $this -> cocolog -> addLogEntry ($this->cocodb, $this->pageid, $this->hits); if(isSet($HTTP_SERVER_VARS[QUERY_STRING]) && !empty($HTTP_SERVER_VARS[QUERY_STRING])) { $this -> cocoquery = new cocoQUERYPARSER; $this -> httpgetvars = $this -> cocoquery -> parseQueryString(); } } // * sets pagename,pageid, hits and comments // * adds page to database if page had not seen before function setVars() { global $HTTP_SERVER_VARS; global $COCO_CONF_VARS; $this -> pagename = $HTTP_SERVER_VARS[SCRIPT_URI]; // check if page is already registered $query = "SELECT id,hits,comments"; $query.= " FROM $COCO_CONF_VARS[TBCOUNTER] "; $query.= "WHERE name='$this->pagename';"; $answer = $this -> cocodb -> db_query ($query); if($result = $this -> cocodb -> db_fetch_array($answer)) { // page is here. Set Variables. $this -> pageid = $result[id]; $this -> hits = $result[hits]; $this -> comments = $result[comments]; $this -> description = $result[description]; } else { // page is viewed for the first time. Add it. $this -> hits = 1; $this -> comments = 0; $query = "INSERT INTO $COCO_CONF_VARS[TBCOUNTER] (id,name,hits,comments) "; $query.= "VALUES('','$this->pagename',1,0);"; $this -> cocodb -> db_query ($query); $this -> pageid = $this -> cocodb -> db_insert_id(); } } // We do encapsulate the call of the HTML-Rendering // Function to make the include-file small and easy to // understand. function includePageComments() { global $COCO_CONF_VARS; $lc = $this -> cococommenter -> lastcomment ($this -> cocodb, $this -> pageid, "page", $this -> comments); $datestring = date("$COCO_CONF_VARS[TIMESTRING]",$lc[ctime]); $this -> cocohtml -> showInclude ( $this -> pageid, $this -> comments, $this -> hits, $lc[cname], $datestring, $lc[ctitle], $lc[cemail], $lc[curl] ); } // Adding a page description for $pgid function insertDescription($cocodb,$pgid,$description) { global $COCO_CONF_VARS; $query = "UPDATE $COCO_CONF_VARS[TBCOUNTER] set description="; $query.= "'$description' WHERE id=$pgid;"; if($cocodb -> db_query($query)) { return true;} else { return false; } } function dropComment($cocodb,$cid,$pgid) { global $HTTP_POST_VARS; global $COCO_CONF_VARS; global $COCO_STRINGS; $query = "SELECT count(pgid) FROM $COCO_CONF_VARS[TBCOMMENT] "; $query.= "WHERE paid='$cid' GROUP BY pgid;"; $answer = $cocodb -> db_query($query); if($result = $cocodb -> db_fetch_array($answer)) { // There are children, so we cannot simply drop the article $text = ereg_replace("<--DATE-->","$date", $COCO_STRINGS[MAGIC_REMOVED]); $query = "UPDATE $COCO_CONF_VARS[TBCOMMENT] SET text='$text', "; $query.= "name='', email='', url='', title='', replies='no' "; $query.= "WHERE id='$cid';"; if($cocodb -> db_query($query)) { return true; } } else { $query = "DELETE FROM $COCO_CONF_VARS[TBCOMMENT] "; $query.= "WHERE id='$cid';"; if($cocodb -> db_query($query)) { $query = "UPDATE $COCO_CONF_VARS[TBCOUNTER] SET"; $query.= " comments=comments-1 WHERE id='$pgid';"; if($cocodb -> db_query($query)) { return true; } } } } function updateComment($cocodb,$cid,$pgid) { global $HTTP_POST_VARS; global $COCO_CONF_VARS; global $COCO_STRINGS; $text = $HTTP_POST_VARS[text]; $date = date("$COCO_CONF_VARS[TIMESTRING]",time()); $append = ereg_replace("<--DATE-->","$date", $COCO_STRINGS[MAGIC_C_MODIFIED]); $text .= $append; $query = "UPDATE $COCO_CONF_VARS[TBCOMMENT] SET "; $query.= "name='$HTTP_POST_VARS[name]', "; $query.= "email='$HTTP_POST_VARS[email]', "; $query.= "url='$HTTP_POST_VARS[url]', "; $query.= "title='$HTTP_POST_VARS[title]', "; $query.= "text='$text' WHERE id=$cid;"; if($cocodb -> db_query($query)) { return true; } } } ?>