<?php// NOTE: all functions have comments preceeding the function call// explaining the overall function of the function.// The somewhat important functions have larger comments,// whereas self-explanatory or functions with less importance// will have limited comments preceeding.// numcode(row number) // --------------------// Figures out whether a number is even or odd// returns:// 1 on odd// 2 on even// --------------------// Usage:// Table alternating row specifications//function numcode($num){ if($num % 2 == 0) { return 2; } else { return 1; }}// rating functions// getRating(tutorial id)// --------------------// Returns the rating of the tutorial, identified// by tutorial id.// returns:// The rating in the form of// xx.xx/10// --------------------// Usage:// Gets the rating simply by setting the tutorial id// argument//function getRating($id){ return NULL; //return "0/10";}// numVotes(tutorial id)// --------------------// Returns the number of votes for the tutorial, identified// by tutorial id.// returns:// An integer// --------------------// Usage:// Gets the number of votes for a tutorial.//function numVotes($id){ return NULL; //return 0;}// getURL()function getURL($id){ $obj = sql_fetch_object("SELECT * FROM " . TUTORIALS_TABLE . " WHERE id='$id'"); $seoname = str_replace(" ", "_", $obj->name); $seoname = str_replace("/", "-", $seoname); $seoname = str_replace("\\", "-", $seoname); $str = TUTORIALS_SEO_DIR . $id . "/" . $seoname; return $str;}// catList([tutorial id], [category tree seperator], [drop down menu name], [selected category id])// --------------------// This function has 2 parts.// 1) tutorial id & category tree seperators are both set.// 2) drop down menu & selected category id are both set.//// -----// 1) Returns a category tree list of where the tutorial belongs// with category tree seperator seperating category levels.// e.g. Photoshop [category tree seperator] Web Graphics//// 2) Returns a select drop down menu with [selected category id]// selected and on top. The name of the select is [drop down menu name].// Each of the options' values are their respective ids.// --------------------// Usage:// Fetches either the category tree list of a tutorial or a select form of// all the categories.//function catList($id = '', $seperator = '', $select = '', $selectid = ''){ if(!$select) { $obj = sql_fetch_object("SELECT * FROM " . CATEGORIES_TABLE . " WHERE id='$id'"); if($obj->main_cat > 0) { $str = $id . "|"; $lfid = $obj->main_cat; for($i=0;$i<1;$i++) { $mobj = sql_fetch_object("SELECT * FROM " . CATEGORIES_TABLE . " WHERE id='$lfid'"); $str .= $mobj->id . "|"; if($mobj->main_cat > 0) { $i--; $lfid = $mobj->main_cat; } } $ex = explode("|", $str); $result = array_reverse($ex); for($x=1;$x<count($result);$x++) { $cobj = sql_fetch_object("SELECT * FROM " . CATEGORIES_TABLE . " WHERE id='" . $result[$x] . "'"); $string .= "<a href=\"http://www.tutorialmonkey.com/category.php?id=" . $result[$x] . "\">" . htmlspecialchars($cobj->name) . "</a>"; if($x+1 < count($result)) { $string .= $seperator; } } } else { $string = "<a href=\"http://www.tutorialmonkey.com/category.php?id=$id\">" . htmlspecialchars($obj->name) . "</a>"; } return $string; } else { $string = "<select name=\"" . $select . "\" size=\"5\">\n"; if($selectid > 0) { $sobj = sql_fetch_object("SELECT * FROM " . CATEGORIES_TABLE . " WHERE id = " . $selectid); $string .= "<option value=\"" . $sobj->id . "\" selected=\"selected\">" . $sobj->name . " (ID: $selectid)</option>\n"; $string .= "<option value=\"\">-----------------------</option>\n"; } $query = mysql_query("SELECT * FROM " . CATEGORIES_TABLE . " ORDER BY name ASC"); while($row = sql_fetch_array($query)) { if($selectid != $row['id']) { $string .= "<option value=\"" . $row['id'] . "\">" . $row['name'] . " (ID: " . $row['id'] . ")</option>\n"; } } $string .= "</select>"; return $string; }}//*********************************************************************************// listTutorials($perpage, $limit, $orderby, $sort, $catid)// =========================================// OVERVIEW:// This is the main function of the site. This parses tutorials from the database// in a simple list form.// =========================================// if $perpage is set, $limit must be bool FALSE.// if $limit is set, $perpage must be bool FALSE.//// if this function is called with conflicting arguments,// this function will PARSE an error message and return FALSE// ---------------------// if $perpage is an INTEGER greater than 0, the function// uses the result_set class to fetch tutorials and PARSES// tutorials (directly from function) 10 per page, with // a pagination navigation as well (all from class result_set)// ----------------------// if $limit is an INTEGER greater than 0, the function will// simply PARSE $limit number of tutorials ordered by $orderby.// There will only be one page, and no pagination.//// if $catid (OPTIONAL INT) is set, this function will ONLY display tutorials// for that certain category and NOT THE TUTORIALS IN THAT CATEGORY'S// SUBCATEGORIES.// =========================================// In either case ($perpage OR $limit), a text will be parsed// stating the amount of tutorials displayed using $sort;// unless $sort is a bool FALSE.//// It is worth noting that this function also starts with// <div style="padding:0px 6px 2px 6px">// as a padding to keep the tutorial list seperated from other content.//*********************************************************************************function listTutorials($perpage, $limit, $orderby, $sort='', $catid=''){ global $HTTP_GET_VARS; if( (is_numeric($perpage) && is_numeric($limit)) || (!is_numeric($perpage) && !is_numeric($limit)) ) { ?> <strong>listTutorials() error [functions.php]: <u>$limit and $perpage cannot be set together, nor can they both not be set. $limit must be numeric while $perpage is bool FALSE, or vice versa.</u></strong> <?php return false; } elseif(!isset($orderby)) { ?> <strong>listTutorials() error [functions.php]: <u>$orderby is a REQUIRED argument for listTutorials()</u></strong> <?php return false; } ?> <div style="padding:0px 6px 2px 6px"> <?php if(is_numeric($catid)) { $where = " AND catid = $catid"; } if(is_numeric($perpage)) { $query = "SELECT * FROM " . TUTORIALS_TABLE . " WHERE approved = 1" . $where ." ORDER BY " . $orderby; $result = new result_set($query, $perpage); } if(is_numeric($limit)) { $result = mysql_query("SELECT * FROM " . TUTORIALS_TABLE . " WHERE approved = 1" . $where ." ORDER BY " . $orderby . " LIMIT " . $limit); } if(isset($sort)) { ?> Displaying <?=$perpage?> results per page sorted <?=$sort?>.<br /> <?php } while($row = (is_numeric($perpage) ? $result->fetch_array() : mysql_fetch_array($result))) { $i++; $num = numcode($i); ?> <table cellspacing="0" cellpadding="3" class="tutorial<?=$num?>"> <tr> <td valign="bottom" style="text-align:left;"> <div style="width:40px; height:40px; float:left; border:1px solid #000000;"><a href="<?=getURL($row['id'])?>" style="border-bottom:0px"><?=fetchImg($row['id'], $row['thumb'], "thumb")?></div> <div style="float:left; margin-left:18px;"> <?=catList($row['catid'], " -> ")?><br /> <a href="<?=getURL($row['id'])?>" class="tuttitle"><?=htmlspecialchars(stripslashes($row['name']))?></a><font style="font-size:14px"><strong><?=getRating($row['id'])?></strong></font><br /> <em><?=ddate("M d Y", $row['date_approved'])?></em><br /> </div> </td> </tr> <tr> <td> <?=htmlspecialchars(stripslashes($row['description']))?> </td> </tr> </table> <?php } if(is_numeric($perpage)) { print "<div align='center'>" . $result->pagination($HTTP_GET_VARS) . "</div>"; } ?> </div> <?php}// fetchImg()function fetchImg($id, $name, $type = '', $extrapath = ''){ error_reporting(0); $image = IMGS_DIRECTORY . $id . "/" . $name; if(!is_file($image) && $type == "thumb") { $image = IMGS_DIRECTORY . NO_IMAGE_NAME; } list($width, $height) = getimagesize($image); if($width > 563) { $string = "<a href=\"#\" onclick=\"expand('http://www.tutorialmonkey.com/" . IMGS_DIRECTORY . $id . "/" . $name . "', '$width' , '$height'); return false;\" style='border-bottom:0px'><img src=\"http://www.tutorialmonkey.com/image.php?i=" . $image . "\" alt=\"\" border=\"0\" /></a>"; return $string; } else { $string = "<img src=\"http://www.tutorialmonkey.com/image.php?i=" . $image . "\" alt=\"\" border=\"0\" />"; return $string; }}// tut_manipulate()// manipulates the tutorial and returns the tutorial in html form.function tut_manipulate($tutorial){// get rid of slashes$tutorial = stripslashes($tutorial);// replace STEP x with XHTML$tutorial = preg_replace("/===STEP (.*?)===/", "<div class=\"tutorial\"><strong>Step $1</strong></div>", $tutorial);// replace COMPLETED with XHTML$tutorial = str_replace("===COMPLETED===", "<div class=\"tutorial\"><strong>Completed</strong></div>", $tutorial);// CODES ----------------------------------------------------// image code$tutorial = preg_replace("#\[\[\[IMG:(.*?)\]\]\]#e", "fetchImg($_GET[id], '\$1')", $tutorial);// code .. code$tutorial = preg_replace("#\[code\](.*?)\[\/code\]#sie", "'<div class=\'code\'>' . highlight_string(trim(stripslashes('$1')), true) . '</div>'", $tutorial);// php.net link$tutorial = preg_replace("#\[=\[(.*?)\]=\]#", "<a href='http://www.php.net/$1' target='_blank'>$1</a>", $tutorial);$tutorial = nl2br($tutorial);return $tutorial;}// ddate()// manipulates the date // ---// NOTE: at the moment, there is no real need for this function. However,// in the case that the server time differs from the preferred time, or if// in the future, specific date preferences are added, this function would be// extremely useful as every date format in the site uses this function as// opposed to PHP's default date();function ddate($date_format, $unix_timestamp){ $date = date($date_format, $unix_timestamp+3600); return $date;}// email()// sends an email with certain preferencesfunction email($to, $name, $from, $subject, $message, $header='', $footer=''){ if(!isset($header)) { $header = str_replace("[n]", $name, DEFAULT_MAIL_HEADER); } if(!isset($footer)) { $footer = str_replace("[n]", $name, DEFAULT_MAIL_FOOTER); } $str = $header . $message . $footer; mail($to, $subject, $str, "From: " . $from);}// getContent()//function getContent($path, $field=''){ if(sql_num_rows("SELECT * FROM " . PAGES_TABLE . " WHERE file='$path'") > 0) { $obj = sql_fetch_object("SELECT * FROM " . PAGES_TABLE . " WHERE file='$path'"); if($field == "") { $head = (!empty($obj->title) ? "<strong>" . $obj->title . "</strong><br /><br />" : ""); return $head . nl2br($obj->content); } elseif($field == "obj") { return $obj; } else { return nl2br($obj->$field); } } else { return false; }}?>