KillaCode

Moderators: Moderator, Global Moderator

Post Reply
Scott
Administrator
Administrator
Posts: 1651
Joined: Sun Apr 25, 2004 1:08 pm

KillaCode

Post by Scott »

KillaCode.com is something I would like to get started asap. However, rather than Rob making a purdy layout and me doing some PHP, I think its time we swapped some roles around. As you can [url=\"http://www.killacode.com\"][u]see[/u][/url], we\'re currently a little low on the layout side <_<

If anyone feels like helping out with the layout and/or the coding, let me know here or via pm. The bonus for this site is that time limit is not a major issue, but we would like the site active somepoint before the domain expires.
Tami
Administrator
Administrator
Posts: 10892
Joined: Sun Apr 25, 2004 1:05 pm

KillaCode

Post by Tami »

Nice layout Scott...did you code that all in one day?

We do have a snippet library script that was coded by a group on sourceforge however it\'s still in beta; if anyone would like to have a look at it to see what\'s what, you\'re more than welcome to, just ask.

KillaCode will have snippets, downloads, tutorials, articles, other coding reference stuff...pretty well the contents of the Code Crypt section here on the KG forum will be moved to KillaCode.
Image

[color=\"#41211C\"]It takes years to build up trust and only seconds to destroy it

[/color]
radar
Hero Member
Hero Member
Posts: 632
Joined: Thu Jun 17, 2004 12:37 am

KillaCode

Post by radar »

Dear god!

That layout OWNS.

I'll help out. Just tell me what to do.
Tami
Administrator
Administrator
Posts: 10892
Joined: Sun Apr 25, 2004 1:05 pm

KillaCode

Post by Tami »

Something professional looking utilizing the KillaNet theme which can accomodate the sub-forum areas from the Code Crypt section on the forum:

Code Crypt Support,
Basic Web Design,
Cascading Style Sheets,
(X)HTML,
Hosting Help,
javascript,
MySQL,
PHP Scripting,
Perl,
Programming Challenges,
Python,
Web Builder News & Events,
Reference,
Web Building Software

These will need to be in an easily navigable format, tutorials need to be well indexed and easy to find, the snippets section needs to be similarly indexed.

Here is the snippets script I mentioned earlier:
attachment
These are some notes that were given to me along with the script:
http://sourceforge.net/projects/php-csl/

it\'s just been rewritten to correct a bug where all "+" symbols were stripped from the output.
Nasty bug that was!
And reverse encryption code storage has been eliminated, probably due to that same bug.

You\'ll probably need to add a user account setup and submission aprovals cause I think only admins and superusers can add code right now.
Last edited by Tami on Thu May 05, 2005 12:52 am, edited 1 time in total.
Image

[color=\"#41211C\"]It takes years to build up trust and only seconds to destroy it

[/color]
Trinity
Hero Member
Hero Member
Posts: 808
Joined: Wed May 05, 2004 9:19 am

KillaCode

Post by Trinity »

This should save a lot of the coding, just the layout stuff needs to be changed over.

Fully commented database class, just needs the variables updated - totally OOP, easy to use.
[code]<?php
/*
 CodeCrypt.org
 Name: cDatabase.php
 Path: _lib/_classes/cDatabase.php
 Desc: Database Connection Class
                               Auth: Trinity
*/

class cDataBase {
 // Database Variables
 // _dbVarName
 var $_dbHost = 'localhost';
 var $_dbUser = 'codec';
 var $_dbPass = 'pr3dat0r';
 var $_dbName = 'code';
 
 // Data Storing Variables
 // _dVarName
 var $_dConnection;
 var $_dResult;
 var $_dItems = array();

 // Constructor Function (init)
 function cDataBase() {
 $this-> _dConnection = $this->dbConnect();
 }
 
 // Function to connect to the database
 function dbConnect() {
 if (mysql_connect($this-> _dbHost, $this-> _dbUser, $this-> _dbPass)) {
   $this-> _dConnection = mysql_connect($this-> _dbHost, $this-> _dbUser, $this-> _dbPass);
   mysql_select_db($this-> _dbName, $this-> _dConnection);
   return $this-> _dConnection;
 }
 else {
   return mysql_error();
 }
 }
 
 // Function to Query database, but return no data
 // Will return either "True" or a mysql_error()
 // Requires input of vaild query string
 function doQuery($sql) {
 if (!mysql_query($sql, $this-> _dConnection)) {
   return mysql_error();
 }
 return true;
 }
 
 // Function to Query database, when accessing data
 // Returns a data array or mysql_error()
 // Requires input of valid query string
 function doQueryResult($sql) {
 $this-> _dItems = "";
 if ($sql != "") {
   $this-> _dResult = mysql_query($sql, $this-> _dConnection);
   $dItem = array();
   while ($dItem = mysql_fetch_array($this-> _dResult)) {
   $this-> _dItems[] = $dItem;
   }
   return $this-> _dItems;
   mysql_free_result($this-> _dResult);
 }
 else {
   return mysql_error();
 }
 }
 
 // Function to Query database, when accessing data
 // Returns a data array or mysql_error()
 // Requires input of valid query string
 function doCountRow($sql) {
 if ($sql != "") {
   $this-> _dResult = mysql_query($sql, $this-> _dConnection);
   $dItem = mysql_fetch_row($this-> _dResult);
   $this-> _dResult = $dItem['0'];
   return $this-> _dResult;
 }
 else {
   return mysql_error();
 }
 }
 
 // Close connection to the databse
 function dbDisconnect() {
 mysql_close($this-> _dConnection);
 return true;
 }
}

?>[/code]

User class code, may be useful:
[code]<?php
/*
 CodeCrypt.org
 Name: cUsers.php
 Path: _lib/_classes/cUsers.php
 Desc: CodeCrypt Users
*/

// Make sure we have access to the databse
require_once('cDatabase.php');

class cUsers {
 
 // Constant Variabls
 var $_table = "users";
 
 // Other Variables
 var $_dbCon;
 
 // Constructor Function (init)
 function cUsers() {
 $this->_dbCon = new cDataBase();
 }
 
 /*  #######################################
 Internal Functions
 */  #######################################
 
 // Check to see if a name exists
 // Vaild $name required
 function _checkName($username) {
 $sql = "SELECT * FROM $this->_table WHERE `username`='".$username."'";
 if ($results = $this->_dbCon->doQueryResult($sql)) {
   foreach ($results as $result) {
   return true;
   }
 }
 else {
   return false;
 }
   
 }
 
 function _checkEmail($email) {
 $sql = "SELECT * FROM $this->_table WHERE `email`='".$email."'";
 if ($results = $this->_dbCon->doQueryResult($sql)) {
   foreach ($results as $result) {
   return true;
   }
 }
 else {
   return false;
 }
 }
 
 //Set the cookie variables for this session
 //$aArgs is an array of user values
 function _setCookie($aArgs) {
 $uInfo = implode("|", $aArgs);
 setcookie("ccAccount", $uInfo, time()+31536000, "/", ".codecrypt.org", "0");
 }
 
 
 /*  #######################################
 Inserting new things into the database
 */  #######################################
 function addUser($aArgs) {
 // First check to make sure these things are alright
 if ($this->_checkName($aArgs['user'])) {
   $return = "Sorry, but that nickname is already in use<br />";
   $return .= "Click <a href=\"javascript:history.back(1)\">here</a> to go back and choose another name.";
 }
 elseif ($this->_checkEmail($aArgs['email'])) {
   $return = "Sorry, but that email is already in use<br />";
   $return .= "Click <a href=\"javascript:history.back(1)\">here</a> to go back and enter another email address.";
 }
 
 else {
   $uActivate = microtime()*5451384;
   $uActivate .= $aArgs['user'];
   $uActivate = md5($uActivate);
   $mailSender = "From: ".ENTITY." <".MAIL_ADMIN.">";
   $mailMessage = "Hello ". $aArgs['user'] .",\r\n";
   $mailMessage .= "This is a message to confirm your registration with ".SITE_URL."\r\n";
   $mailMessage .= "Your account has not been activated yet. To activate your account, click the link below. Some users may need to copy the link and paste it into their browser.\r\n";
   $mailMessage .= SITE_URL."/members.php?action=activate&id=". $uActivate ."\r\n";
   $mailMessage .= "Username: ". $aArgs['user'] ."\r\n";
   $mailMessage .= "Password: ". $aArgs['pass'] ."\r\n";
   $mailMessage .= "Thankyou for registering with ". ENTITY .".\r\n";
   mail($aArgs['email'], "CodeCrypt Account Activation", $mailMessage, "$mailSender\r\n");
   $aArgs['pass'] = md5($aArgs['pass']);
   $return = "Registration succesfull. Please check your email.";
   $sql = "INSERT INTO $this->_table (`username`,`password`,`email`, `active`, `validate`, `regip`) "
   ."VALUES ('".$aArgs['user']."', '".$aArgs['pass']."','".$aArgs['email']."',0,'".$uActivate."', '".$_SERVER['REMOTE_ADDR']."')";
   $result = $this->_dbCon->doQuery($sql);
   if ($result != true) {
   echo $result;
   }
   
 }
 return $return;
 }
 
 /*  #######################################
 Authenticate / Login
 */  #######################################
 function logIn($aArgs) {
 $aArgs['pass'] = md5($aArgs['pass']);
 $sql = "SELECT * FROM $this->_table WHERE `username`='".$aArgs['user']."' LIMIT 1";
 if ($results = $this->_dbCon->doQueryResult($sql)) {
   foreach ($results as $result) {
   if ($aArgs['pass'] != $result['password']) {
     $return = "That password does not match the one we have stored";
   }
   elseif ($result['active'] == 0) {
     $return = "This account has not been activated.";
   }
   else {
     $return = "Login successful, redirecting<br />";
     $return .= "<a href=\"login.php?id=". $result['id'] ."&user=". $aArgs['user'] ."&rank=". $result['rank'] ."\">Click here if you're not redirected</a>";
     $return .= "<meta http-equiv=\"refresh\" content=\"3;URL='http://codecrypt.org/login.php?id=". $result['id'] ."&user=". $aArgs['user'] ."&rank=". $result['rank'] ."'\">";
   }
   }
 }
 else {
   $return = "Username does not exist";
 }
 return $return;
 }
 
 function logOut() {
 if (!$this->getSession()) {
   $return = "You are not logged in!";
 }
 else {
   $return = "Logging out.<br />";
   $return .= "<a href=\"logout.php\">Click here if you're not redirected</a>";
   $return .= "<meta http-equiv=\"refresh\" content=\"3;URL=logout.php\">";
 }
 return $return;
 }
 
 function getSession() {
 if (isset($_COOKIE['ccAccount'])) {
   $uInfo = explode("|", $_COOKIE['ccAccount']);
   $return['uID'] = $uInfo['0'];
   $return['Username'] = $uInfo['1'];
   $return['rank'] = $uInfo['2'];
   return $return;
 }
 else {
   return false;
 }
 }
 
 function validateUser($activate) {
 $sql = "SELECT * FROM $this->_table WHERE `validate`='".$activate."' LIMIT 1";
 if ($results = $this->_dbCon->doQueryResult($sql)) {
   foreach ($results as $result) {
   $sql = "UPDATE $this->_table SET `active` = 1, `validate`='' WHERE `id` = '". $result['id'] ."'";
   $this->_dbCon->doQuery($sql);
   $return = "Success! Your account has been activated, you may now access all your member features!";
   $return .= "<br />Click <a href=\"members.php\">here</a> to login.";
   }
 }
 else {
   $return = "Validation failed.";
   $return = "<br />Please check that the link is correct in your email.";
   $return = "<br />If you have any further problems please contact an admin.";
 }
 return $return;
 }
}

?>[/code]

And for the tutorials, this might be useful:
[code]<?php
/*
 CodeCrypt.org
 Name: cTutorials.php
 Path: _lib/_classes/cTutorials.php
 Desc: Tutorials Classes
*/

// Make sure we have access to the databse
require_once('cDatabase.php');

class cTutorials {
 
 // Constant Variabls
 var $_table = "tutorials";
 var $_tableCat = "tutorial_cat";
 
 // Other Variables
 var $_dbCon;
 
 // Constructor Function (init)
 function cTutorials() {
 $this->_dbCon = new cDataBase();
 }
 
 /*
 ########################################################################
 Internal Functions
 ########################################################################
 */
 

 /*
 ########################################################################
 Showing Data
 ########################################################################
 */
 //Show the actual Tutorial
 function showTut($id, $cat) {
 $sql = "SELECT * FROM `tutorials` WHERE `id` = '$id' AND `cat` = '$cat'";
 $results = $this->_dbCon->doQueryResult($sql);
 foreach ($results as $result) {
   print '
   <img src="images/hd_tutorial.gif" />
   <div id="news">
   ';
   print '<h1>'.$result['name'].'</h1>';
   print $result['tutorial'];
   if ($result['active'] == 0) {
   print '
   <br /><br />
   <a href="?action=acceptTut">Accept Tutorial</a>
   | <a href="?action=editTut">Edit Tutorial</a>
   | <a href="?action=declineTut">Reject Tutorial</a>
   ';
   print '</div>';
 }
 }
 
 function showCat($cat) {
 //Print the start of the table
 print'
 <img src="images/hd_tutorials.gif" />
 <table cellpadding="0" cellspacing="0" id="index" class="margin">
   <tr>
    <td class="header" colspan="3">PHP Tutorials</td>
   </tr>
 ';
 $sql = "SELECT *,DATE_FORMAT(date, '%a %D %b') AS dated FROM `tutorials` WHERE `cat` = '$cat' AND `active` = '1' ORDER BY date DESC";
 $results = $this->_dbCon->doQueryResult($sql);
 foreach ($results as $result) {
   print '
   <tr>
    <td class="frm_link" width="60%"><a href="tutorials.php?action=showTut&cat='.$cat.'&id='.$result['id'].'" class="frm_link">'.$result['name'].'</a>'.$result['desc'].'</td>
    <td class="content" width="20%"><a href="#">'.$result['author'].'</a></td>
    <td class="content" width="20%">'.$result['dated'].'</td>
   </tr>
   ';
 }
 //Close the tables
 print '</table>';
 }
 
 function showQue() {
 print'
 <img src="images/hd_tutorials.gif" />
 <table cellpadding="0" cellspacing="0" id="index" class="margin">
   <tr>
    <td class="header" colspan="3">Tutorial Submission Que</td>
   </tr>
 ';
 $sql = "SELECT *,DATE_FORMAT(date, '%a %D %b') AS dated FROM `tutorials` WHERE `active` = '0' ORDER BY date DESC";
 $results = $this->_dbCon->doQueryResult($sql);
 foreach ($results as $result) {
   print '
   <tr>
    <td class="frm_link" width="60%"><a href="tutorials.php?action=showTut&cat='.$result['cat'].'&id='.$result['id'].'" class="frm_link">'.$result['name'].'</a>'.$result['desc'].'</td>
    <td class="content" width="20%"><a href="#">'.$result['author'].'</a></td>
    <td class="content" width="20%">'.$result['dated'].'</td>
   </tr>
   ';
 }
 //Close the tables
 print '</table>';
 }
 
 function showRoot() {
 print '
 <img src="images/hd_tutorials.gif" /><br /><br />
 <table cellpadding="0" cellspacing="0" id="index" class="margin">
   <tr>
    <td class="header" colspan="2">Tutorial Catagories</td>
   </tr>
 ';
 $sql = "SELECT * FROM tutorial_cat";
 $results = $this->_dbCon->doQueryResult($sql);
 foreach ($results as $result) {
   print '
    <tr>
     <td class="frm_link" width="72%"><a href="?action=showCat&cat='.$result['id'].'" class="frm_link">'.$result['name'].'</a>'.$result['desc'].'</td>
     <td class="content" width="10%">'.$result['number'].'</td>
    </tr>
   ';
 }
 print '
   </tr>
 </table>
 ';
 }

 
 function showAdminRoot() {
 print '
 <img src="images/hd_tutorials.gif" /><br /><br />
 <table cellpadding="0" cellspacing="0" id="index" class="margin">
   <tr>
    <td class="header" colspan="3">Tutorial Catagories</td>
   </tr>
 ';
 $sql = "SELECT * FROM tutorial_cat";
 $results = $this->_dbCon->doQueryResult($sql);
 foreach ($results as $result) {
   print '
    <tr>
     <td class="frm_link" width="50%"><a href="#" class="frm_link">'.$result['name'].'</a></td>
     <td class="content" width="25%"><a href="?action=editTutCat&id='.$result['id'].'">Edit</a></td>
      <td class="content" width="25%"><a href="?action=deleteTutCat&id='.$result['id'].'">Delete</a></td>
    </tr>
   ';
 }
 print '
 </table>
 <br /><br />
 <img src="images/hd_addcat.gif" />
 <br />
 <div id="commentReply">
   <p>Please keep the description short as we have limited room in the tables that display
   the catagories.</p>
   <form method="post" action="?action=showTutCat" id="addcat">
   <span><label for="title">Title:</label><input name="title" id="title" /></span>
   <span><label for="text">Description:</label><textarea id="text" name="text" rows="13" cols="55"></textarea></span>
   <span class="submit"><input type="submit" id="submit" name="submit" value=" Add Catagory " /></span>
   </form>
 </div>
 ';
 }
 function showEditTutCat($id) {
 $sql = "SELECT * FROM tutorial_cat WHERE id=$id";
 $results = $this->_dbCon->doQueryResult($sql);
 foreach ($results as $result) {
   print '
 <img src="images/hd_editcat.gif" />
 <br />
 <div id="commentReply">
   <p>Please keep the description short as we have limited room in the tables that display
   the catagories.</p>
   <form method="post" action="?action=editTutCat&id='.$id.'" id="editcat">
   <span><label for="title">Title:</label><input name="title" id="title" value="'.$result['name'].'"/></span>
   <span><label for="text">Description:</label><textarea id="text" name="text" rows="13" cols="55">'.$result['desc'].'</textarea></span>
   <span class="submit"><input type="submit" id="submit" name="submit" value=" Update Catagory " /></span>
   </form>
 </div>
   ';
 }
 }
 function showAddTut() {
 print '
 <img src="images/hd_addtut.gif" />
 <div id="commentReply">
   <p>Please make sure that you select the right category for your news. HTML will be stripped
   and line breaks added. You can also use emoticons and BB Code.</p>
   <form method="post" action="?action=addTutorial" id="addtut">
   <span><label for="title">Title:</label><input name="title" id="title" /></span>
   <span><label for="author">Author:</label><input name="author" id="author" /></span>
   <span><label for="desc">Descriptione:</label><input name="desc" id="desc" /></span>
   <span><label for="cat">Category:</label>
   <select id="cat" name="cat" title="Category">
 ';
 $sql = "SELECT * FROM tutorial_cat";
 $results = $this->_dbCon->doQueryResult($sql);
 foreach ($results as $result) {
   print '
   <option value="'.$result['id'].'">'.$result['name'].'</option>
   ';
 }
 print '
   </select></span>
   <span><label for="text">Tutorial:</label><textarea id="text" name="text" rows="13" cols="55"></textarea></span>
   <span class="submit"><input type="submit" id="submit" name="submit" value=" Submit Tutorial " /></span>
   </form>
 </div>
   ';
 }
 /*
 ########################################################################
 Adding Data
 ########################################################################
 */
 function addTut($title, $desc, $cat, $uID, $author, $tutorial) {
 $sql = "INSERT INTO `tutorials` (`name, `desc`, `cat`, `userid`, `author`, `tutorial, `active`) VALUES ('".$title."', '".$desc."', '".$cat."', '".$uID."', '".$author."', '".$tutorial."',  '1')";
 $result = $this->_dbCon->doQuery($sql);
 if ($result != true) {
   echo $result;
 }
 $this->showCat($cat);
 }
 function submitTut($title, $desc, $cat, $uID, $author, $tutorial) {
 $sql = "INSERT INTO tutorials (`name, `desc`, `cat`, `userid`, `author`, `tutorial, `active`) VALUES ('".$title."', '".$desc."', '".$cat."', '".$uID."', '".$author."', '".$tutorial."',  '0')";
 $result = $this->_dbCon->doQuery($sql);
 if ($result != true) {
   echo $result;
 }
 $this->showCat($cat);
 }
 function addTutCat($title, $desc) {
 $sql = "INSERT INTO tutorial_cat (`name`,`desc`) VALUES ('".$title."','".$desc."')";
 $result = $this->_dbCon->doQuery($sql);
 if ($result != true) {
   echo $result;
 }
 $this->showAdminRoot();
 }
 /*
 ########################################################################
 Updating Data
 ########################################################################
 */
 function editTutCat($id, $title, $desc) {
 $sql = "UPDATE `tutorial_cat` SET `name` = '$title',`desc` = '$desc' WHERE `id` = '$id' LIMIT 1";
 $result = $this->_dbCon->doQuery($sql);
 if ($result != true) {
   echo $result;
 }
 $this->showAdminRoot();
 }
 /*
 ########################################################################
 Deleting Data
 ########################################################################
 */
 function deleteTutCat($id) {
 $sql = "DELETE FROM tutorial_cat WHERE id = $id";
 $result = $this->_dbCon->doQuery($sql);
 if ($result != true) {
   echo $result;
 }
 $this->showAdminRoot();
 }
 
}

?>[/code]

News and comments, using the db class:

[code]<?php
/*
 CodeCrypt.org
 Name: cNews.php
 Path: _lib/_classes/cNews.php
 Desc: News System Class
*/
require_once('cDatabase.php');

class cNews {
 // Database Variables
 // _nVarName
 var $_nLimit = '10';
 
 // Data Storing Variables
 // _dVarName
 var $_dCon;

 
 // Constructor Function (init)
 function cNews() {
 $this-> _dCon = new cDataBase();
 }
 
 /*
 ########################################################################
 Displaying Data
 ########################################################################
 */
 
 //Displays the news to the index page
 //$showAll is a boolean variable, either limit or no limit - 0/1
 function displayNews($showAll, $rank) {
 echo '<img src="images/hd_news.gif" />';
 if ($showAll = "0") {
   $sql =
   "SELECT id,name,message,userid,title,DATE_FORMAT(postdate, '%a %D %b @ %H:%i') AS dated " .
   "FROM news ORDER BY postdate DESC LIMIT $this->_nLimit";
 }
 else {
   $sql =
   "SELECT id,name,message,userid,title,DATE_FORMAT(postdate, '%a %D %b @ %H:%i') AS dated " .
   "FROM news ORDER BY postdate DESC";
 }
 $results = $this->_dCon->doQueryResult($sql);
 if ($rank == 3) {
   foreach ($results as $result) {
   // Count the number of comments for this news item
   $sql = 'SELECT count(*) FROM news_comments WHERE news_id='. $result['id'];
   $comment_count = $this->_dCon->doCountRow($sql);
   // Echo the information
   echo '<div id="news">';
   echo '<p class="header">'. $result['title'] .' - by <a href="members.php?acion=showProfile&id='.$result['userid'].'">'. $result['name'] .'</a></p>';
   echo $result['message'];
   echo '<p class="footer"><span class="right"><a href="?action=editNews&id='.$result['id'].'">Edit</a>'
      .' | <a href="?action=deleteNews&id='.$result['id'].'">Delete</a></span>'. $result['dated'] .' - <a href="?action=show&id='. $result['id'] .'"> Comments ('. $comment_count .')</a></p>';  
   echo '</div>';
   }
 }
 else {
   foreach ($results as $result) {
   // Count the number of comments for this news item
   $sql = 'SELECT count(*) FROM news_comments WHERE news_id='. $result['id'];
   $comment_count = $this->_dCon->doCountRow($sql);
   // Echo the information
   echo '<div id="news">';
   echo '<p class="header">'. $result['title'] .' - by <a href="members.php?acion=showProfile&id='.$result['userid'].'">'. $result['name'] .'</a></p>';
   echo $result['message'];
   echo '<p class="footer">'. $result['dated'] .' - <a href="?action=show&id='. $result['id'] .'"> Comments ('. $comment_count .')</a></p>';  
   echo '</div>';
   }
 }
 if ($showAll = "0") {
   echo '<a href=?action=showAll>View all news</a>';
 }    
 }
 
 //Display just one news item (for comments)
 //$id = the news id
 function displayOneItem($id, $rank) {
 echo '<img src="images/hd_article.gif" />';
 $sql =
   "SELECT id,name,message,userid,title,DATE_FORMAT(postdate, '%a %D %b @ %H:%i') AS dated " .
   "FROM news WHERE id=". $id;
 $results = $this->_dCon->doQueryResult($sql);
 foreach ($results as $result) {
   echo '<div id="news">';
   echo '<p class="header">'. $result['title'] .' - by <a href="members.php?acion=showProfile&id='.$result['userid'].'">'. $result['name'] .'</a></p>';
   echo $result['message'];
   echo '<p class="footer">'. $result['dated'] .'</p>';  
   echo '</div>';
 }
 echo '<img src="images/hd_comments.gif" />';
 $this->displayComments($id, $rank);
 }
 
 //Display the comments
 //$id = the news id
 function displayComments($id, $rank) {
 $sql = "SELECT id,name,news_id,message,userid,DATE_FORMAT(postdate, '%a %D %b @ %H:%i') AS dated FROM news_comments WHERE news_id=$id ORDER BY postdate ASC";
 $results = $this->_dCon->doQueryResult($sql);
 if (!$results) {
   echo '<div id="comments"><p>No one has commented on this article.</[></div>';
 }
 else {
   if ($rank <= 1) {
   foreach ($results as $result) {
     echo '<div id="comments">';
     echo '<p><a href="members.php?acion=showProfile&id='.$result['userid'].'">'. $result['name'] .'</a> says:</p>';
     echo $result['message'];
     echo '<p class="commentftr">'. $result['dated'] .'</p>';
     echo '</div>';
   }
   }
   elseif ($rank >= 2) {
   foreach ($results as $result) {
     echo '<div id="comments">';
     echo '<p><a href="members.php?acion=showProfile&id='.$result['userid'].'">'. $result['name'] .'</a> says:</p>';
     echo $result['message'];
     echo '<p class="commentftr"><span class="right"><a href="?action=deleteComment&id='.$result['id'].'&nID='.$id.'">Delete</a></span>'. $result['dated'] .'</p>';
     echo '</div>';
   }
   }
 }
 $this->displayReply($rank, $id);
 }
 function displayReply($rank, $id) {
 if ($rank >= 1) {
   echo '<img src="images/hd_addcom.gif" />';
   echo '
   <div id="commentReply">
   <p>Comments will be stripped of HTML and line breaks will be converted. Your IP will be logged
   to prevent abuse.</p>
   <form method="post" action="?action=addComment&id='.$id.'" id="comments">
     <span><label for="text">Comments:</label><textarea id="text" name="text" rows="13" cols="55"></textarea></span>
     <span class="submit"><input type="submit" id="submit" name="submit" value=" Submit Comment " /></span>
   </form>
   </div>
   ';
 }
 else {
   echo '
 <img src="images/hd_addcom.gif" />
 <div id="commentReply">
   <p class="centerText">You need to be <a href="members.php">logged in</a> to add comments.</p>
 </div>
   ';
 }
 }
 function showNewsForm() {
 print '
 <img src="images/hd_addnews.gif" />
 <div id="commentReply">
   <p>Please make sure that you select the right category for your news. HTML will be stripped
   and line breaks added. You can also use emoticons and BB Code.</p>
   <form method="post" action="index.php?action=addNews" id="comments">
   <span><label for="title">Title:</label><input name="title" id="title" /></span>
   <span><label for="text">News:</label><textarea id="text" name="text" rows="13" cols="55"></textarea></span>
   <span class="submit"><input type="submit" id="submit" name="submit" value=" Submit News " /></span>
   </form>
 </div>
 ';
 }
 
 function showEditForm($id) {
 $sql = "SELECT * FROM news WHERE id=$id";
 $results = $this->_dCon->doQueryResult($sql);
 foreach($results as $result) {
   print '
   <img src="images/hd_addnews.gif" />
   <div id="commentReply">
   <p>Please make sure that you select the right category for your news. HTML will be stripped
   and line breaks added. You can also use emoticons and BB Code.</p>
   <form method="post" action="index.php?action=editNews&id='.$id.'" id="comments">
     <input type="hidden" name="date" value="'.$result['postdate'].'">
     <span><label for="title">Title:</label><input name="title" id="title" value="'.$result['title'].'"/></span>
     <span><label for="text">News:</label><textarea id="text" name="text" rows="13" cols="55">'.$result['message'].'</textarea></span>
     <span class="submit"><input type="submit" id="submit" name="submit" value=" Submit News " /></span>
   </form>
   </div>
   ';
 }
 }
 
 /*
 ########################################################################
 Adding Data
 ########################################################################
 */
 
 //Add news to the database
 function addComment($id, $userName, $uID, $comment, $rank) {
 $sql = "INSERT INTO news_comments (`news_id`,`name`,`message`,`userid`,`postdate`) "
 ."VALUES ('".$id."','".$userName."','".$comment."','".$uID."',now())";
 $result = $this->_dCon->doQuery($sql);
 if ($result != true) {
   echo $result;
 }
 $this->displayOneItem($id, $rank);
 }
 
 function addNews($userName, $uID, $title, $message, $rank) {
 $sql = "INSERT INTO news (`name`,`userid`,`title`,`message`,`postdate`) VALUES ('".$userName."','".$uID."','".$title."', '".$message."', now())";
 $result = $this->_dCon->doQuery($sql);
 if ($result != true) {
   echo $result;
 }
 $this->displayNews(0, $rank);
 }
 
 /*
 ########################################################################
 Update Data
 ########################################################################
 */
 
 function updateNews($userName, $uID, $title, $message, $id, $date) {
 $sql = "UPDATE news SET name = '".$userName."', userid = '".$uID."', title = '".$title."', message = '".$message."', postdate = '".$date."' WHERE id=$id";
 $result = $this->_dCon->doQuery($sql);
 if ($result != true) {
   echo $result;
 }
 $this->displayNews(0, 3);
 }
 
 /*
 ########################################################################
 Delete Data
 ########################################################################
 */
 function deleteComment($id, $news_id, $rank) {
 $sql = "DELETE FROM news_comments WHERE id = $id";
 $result = $this->_dCon->doQuery($sql);
 if ($result != true) {
   echo $result;
 }
 $this->displayOneItem($news_id, $rank);
 }
 
 function deleteNews($id) {
 $sql = "DELETE FROM news WHERE id = $id";
 $result = $this->_dCon->doQuery($sql);
 if ($result != true) {
   echo $result;
 }
 $this->displayNews(0, 3);
 }
}
?>[/code]
us3rX
Hero Member
Hero Member
Posts: 1194
Joined: Thu May 06, 2004 6:11 am

KillaCode

Post by us3rX »

*wacks trin for not just attaching the files, also has nfi what that all does*

us3rX <img src=\'http://www.killanet.net/forum3/public/s ... /ph34r.gif\' class=\'bbc_emoticon\' alt=\':ph34r:\' />
[align=center]

Image

"Time is never wasted, when your wasted all the time" ~ Radio Dj/Unknown Source

"Death is the inevitable end to the suffering of the living." ~Unknown

"You were born an original. Don't die a copy" ~Murdoc Niccals

[/align]
Sp3culuM
Hero Member
Hero Member
Posts: 662
Joined: Mon May 17, 2004 2:36 pm

KillaCode

Post by Sp3culuM »

* Uses that to help with learning OOP *

Thanks Tron <img src=\'http://www.killanet.net/forum3/public/s ... igwink.gif\' class=\'bbc_emoticon\' alt=\';)\' />
Image
ner0
Hero Member
Hero Member
Posts: 982
Joined: Sat May 22, 2004 4:45 pm

KillaCode

Post by ner0 »

wow, I\'ll never complain about one-word/short posts again Trin <img src=\'http://www.killanet.net/forum3/public/s ... >/blum.gif\' class=\'bbc_emoticon\' alt=\':P\' />

if anything needs doing my door/box-flaps are always open.. but yeah the download sys, *goes off to stab it*
[color=\"green\"]'class KPIM::ProcessManager' only defines private constructors and has no friends[/color] <- :( poor class



[18:09:00] * ~Moppy stews ner0 erotically 1 times.
Scott
Administrator
Administrator
Posts: 1651
Joined: Sun Apr 25, 2004 1:08 pm

KillaCode

Post by Scott »

Would anyone be interested in doing a layout for this?
Trinity
Hero Member
Hero Member
Posts: 808
Joined: Wed May 05, 2004 9:19 am

KillaCode

Post by Trinity »

Perhaps this would be an oppurtunity for a few people to submit mock-up designs and then one is chosen?

Then, the other designs can still be added to the KillaDesign portfolio as they are still possible layouts.
Scott
Administrator
Administrator
Posts: 1651
Joined: Sun Apr 25, 2004 1:08 pm

KillaCode

Post by Scott »

Good idea. I know templates have been discussed as going on freeware, so thats also an option.
Trinity
Hero Member
Hero Member
Posts: 808
Joined: Wed May 05, 2004 9:19 am

KillaCode

Post by Trinity »

Okay, well I'll have a shot at it, perhaps radar, josh and a couple of others can as well.
Josh
Hero Member
Hero Member
Posts: 4627
Joined: Fri Jun 04, 2004 2:54 pm

KillaCode

Post by Josh »

Yes I\'d like to have a go but at the moment I\'m working on another layout for tami for another website.... That will have to come first and then I\'ll work on something for killacode <img src=\'http://www.killanet.net/forum3/public/s ... /smile.gif\' class=\'bbc_emoticon\' alt=\':)\' />
[align=center]

Image

“If you stop learning, you stop living.” ~Tami Quiring

“It's the rare man who understands the value of a single perfect rose.”

[/align]
Kobra
Sr. Member
Sr. Member
Posts: 254
Joined: Mon May 31, 2004 4:46 pm

KillaCode

Post by Kobra »

I would love to help out with this project (although I'm still working on my overdue KillaWriters project <img src=\'http://www.killanet.net/forum3/public/s ... >/blum.gif\' class=\'bbc_emoticon\' alt=\':P\' />) but I can't make a template.. I suck at templates <img src=\'http://www.killanet.net/forum3/public/s ... #>/cry.gif\' class=\'bbc_emoticon\' alt=\':(\' />
Image
radar
Hero Member
Hero Member
Posts: 632
Joined: Thu Jun 17, 2004 12:37 am

KillaCode

Post by radar »

Is that a splotch of pink I see on there? (A)

Dim the diagonal lines and red is cool.
Last edited by radar on Thu Jul 07, 2005 5:52 am, edited 1 time in total.
Post Reply

Return to “Coffee Room”