Forum Thread
  Posts  
Function code list - PHP fun! (Forums : Coding & Scripting : Function code list - PHP fun!) Locked
Thread Options 1 2
Jul 20 2003 Anchor

I decided to post this for some php fun, plus if 40oz see's this then it should give him insentive to get PHPing :P

Any errors or suggestions are welcome.

<?PHP

/*
+=================================================+
| Wuggawoo version 1.5
| Created by Aaron Lote
| Address: http://www.wuggawoo.co.uk/
| Email: azz0r@wuggawoo.co.uk
| > Function List
+=================================================+
*/



/*Make's sure the page isnt cached; useful for sql driven pages - called in every page header*/
function disable_cache($update_date='')
{header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");}



/*Used to convert date fields into actual dates - called in user profile*/
function datetimeformat($format, $datetimestr)
{list($date, $time2) = explode(" ", $datetimestr);
list($year, $month, $day) = explode("-", $date);
list($hour, $minute, $second) = explode(":", $time2);
return date($format, mktime($hour, $minute, $second, $month, $day, $year));}



/*Defines the $time variable as the unix timestamped time - called in every page header*/
$time = time();



/*Figures out the diffrence between the variable and the current time, based on unix timestamp - called in various places*/
function TimeDiffo($time)
{$time=time()-$time;

$weeks=$time/604800;
$days=($time%604800)/86400;
$hours=(($time%604800)%86400)/3600;
$minutes=((($time%604800)%86400)%3600)/60;
$seconds=(((($time%604800)%86400)%3600)%60);

if(round($days)) $timestring.=round($days)."d ";
if(round($hours)) $timestring.=round($hours)."h ";
if(round($minutes)) $timestring.=round($minutes)."m";
if(!round($minutes)&&!round($hours)&&!round($days)) $timestring.=" ".round($seconds)."s";
return $timestring;}



/*Collects smilies from the DB and replaces sections in the variable where match is found - called on most pages with dynamic text*/
function smileys($smile)
{$query = mysql_query("SELECT * FROM unz_smilies");
while($smily = mysql_fetch_object($query))
{$smile = str_replace("$smily->replace", "<img src='images/smilies/$smily->link' alt='$smily->alt'>",$smile);}
return $smile;}



/*Collects the categories from the DB and turns them into a drop down box - called in most pages*/
function Category_Drop()
{echo "<select name='cid'>";
$query = mysql_query("SELECT cid, name FROM unz_category ORDER BY cid DESC");
while($category = mysql_fetch_object($query))
{echo "<option value='$category->cid' class='ip1'>$category->name</option>";}
echo "</select>";}



/*Collects the birthday from the DB and then selects then date in the option box, if they match then the date/month/year is preselected - called in edit profile page*/
function Category_DropChosen($day)
{echo "<select name='cid'>";
$query = mysql_query("SELECT cid, name FROM unz_category ORDER BY cid DESC");
while($category = mysql_fetch_object($query))
if($day == $category->cid)
{echo "<option value='$category->cid' class='ip1' selected>$category->name</option>";}
else
{echo "<option value='$category->cid' class='ip1'>$category->name</option>";}
echo "</select>";}



/*Cleans data made by user of possibly evil codes - called in all pages with user text*/
function safeHTML($comment)
{$comment = stripslashes($comment);
$comment = strip_tags($comment, '<   b><  i><  u><   a>');
$comment = ereg_replace ("<a[^>]+href *= *([^ ]+)[^>]*>", "<a href=1>", $comment);
$comment = ereg_replace ("<([b|i|u])[^>]*>", "<1>", $comment);
$comment = preg_replace ("/([^s]{45,})/e", "''.wordwrap('1', 45, ' ', 1).''", $comment);
$comment = preg_replace('/<!--.+?-->/','',$comment);
$comment = str_replace("<", "<", $comment);
$comment = str_replace(">", ">", $comment);
$comment = addslashes($comment);
return $comment;}



/*Error table - called if theres an error*/
function error_box($error, $forward=""))
{echo "<table width='100%' cellspacing='1' cellpadding='4' class='bg6' style='margin-top : 7px;'><tr><td class='bg3'>
&lt;font class=&#039;newstitle&#039;&gt;Error&lt;/font&gt;</br>
&lt;font class=&#039;newstext&#039;&gt;$error&lt;/font&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;;
if(!$forward)
{NULL}
else
{echo &quot;&lt;script&gt;function redirect() { window.location.replace(&#039;javascript:history.go(-1)&#039;); }
setTimeout(&#039;redirect();&#039;, 2000);&lt;/script&gt;&quot;;}}



/*Success table - called if theres a successful insertion*/
function success_box($success, $forward)
{echo&quot;&lt;table width=&#039;100%&#039; cellspacing=&#039;1&#039; cellpadding=&#039;4&#039; class=&#039;bg6&#039; style=&#039;margin-top : 7px;&#039;&gt;&lt;tr&gt;&lt;td class=&#039;bg3&#039;&gt;
&lt;font class=&#039;newstitle&#039;&gt;Success&lt;/font&gt;</br>&lt;font class=&#039;newstext&#039;&gt;$success&lt;/font&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;script&gt;function redirect() { window.location.replace(&#039;$forward&#039;); }
setTimeout(&#039;redirect();&#039;, 1000);&lt;/script&gt;&quot;;}



/*Collects the birthday from the DB and then selects then date in the option box, if they match then the date/month/year is preselected - called in edit profile page*/
function day_dropdown($day)
{print &#039;&lt;select name=&#039;date&#039;&gt;&lt;option class=&#039;ip1&#039; value=&#039;&#039;&gt;Day&lt;/option&gt;&#039;;
$count = 00;
while ($count &lt; 31)
{if ($count == $day)
{$out .= &quot;&lt;option name=&#039;$day&#039; class=&#039;ip1&#039; selected&gt;$day&lt;/option&gt;&quot;;}
else
{$out .= &quot;&lt;option class=&#039;ip1&#039; name=&#039;$count&#039;&gt;$count&lt;/option&gt;&quot;;}
$count++;}
$out .= &#039;&lt;/select&gt;&#039;;
return $out;}
/*Collects the birthday from the DB and then selects then date in the option box, if they match then the date/month/year is preselected - called in edit profile page*/
function month_dropdown($month)
{print &#039;&lt;select name=&#039;month&#039;&gt;&lt;option class=&#039;ip1&#039; value=&#039;&#039;&gt;Month&lt;/option&gt;&#039;;
$count = 00;
while ($count &lt; 12)
{if ($count == $month)
{$out .= &quot;&lt;option name=&#039;$month&#039; class=&#039;ip1&#039; selected&gt;$month&lt;/option&gt;&quot;;}
else
{$out .= &quot;&lt;option  class=&#039;ip1&#039;  name=&#039;$count&#039;&gt;$count&lt;/option&gt;&quot;;}
$count++;}
$out .= &#039;&lt;/select&gt;&#039;;
return $out;}
/*Collects the birthday from the DB and then selects then date in the option box, if they match then the date/month/year is preselected - called in edit profile page*/
function year_dropdown($year)
{print &#039;&lt;select name=&#039;year&#039;&gt;&lt;option class=&#039;ip1&#039; value=&#039;&#039;&gt;Year&lt;/option&gt;&#039;;
$count = 1959;
$thisyear = date(&quot;Y&quot;);
while ($count &lt; $thisyear)
{if ($count == $year)
{$out .= &quot;&lt;option name=&#039;$year&#039; class=&#039;ip1&#039; selected&gt;$year&lt;/option&gt;&quot;;}
else
{$out .= &quot;&lt;option class=&#039;ip1&#039; name=&#039;$count&#039;&gt;$count&lt;/option&gt;&quot;;}
$count++;}
$out .= &#039;&lt;/select&gt;&#039;;
return $out;}



/*Beta random password generator, doesnt work yet - called when user signs-up*/
function password()
{$chars = &quot;abcdefghjklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ023456789&quot;;
for($i = 0; $i &lt; $length; $i++)
{$x = rand(0, strlen($chars) -1);
$password .= $chars{$x};}
return $password;}



/*Checks data for BB code - called quite abit, anything with possible BB code*/

function InsertBBCode($unznews){
$bbcodes_open  = array(&quot;[move]&quot;,&quot;[sub]&quot;,&quot;[tt]&quot;,&quot;[sup]&quot;,&quot;<s>&quot;,&quot;[  b]&quot;,&quot;[  i]&quot;,&quot;[ u]&quot;,&quot;[  quote]&quot;,&quot;[  code]&quot;);
$bbcodes_close = array(&quot;[/move]&quot;,&quot;[/sub]&quot;,&quot;[/tt]&quot;,&quot;[/sup]&quot;,&quot;</s>&quot;,&quot;[/b]&quot;,&quot;[/i]&quot;,&quot;[/u]&quot;,&quot;[  /quote]&quot;,&quot;[  /code]&quot;);

for($i = 0; $i &lt; 10; $i++ )
{$bbcode_open = $bbcodes_open[$i];
$bbcode_close = $bbcodes_close[$i];

$open_cnt = substr_count( $unznews, $bbcode_open );
$close_cnt = substr_count( $unznews, $bbcode_close );
$div = abs( $open_cnt - $close_cnt );

if ( $open_cnt &gt; $close_cnt)
{for ($i = 0; $i &lt; $div; $i++)
$unznews .= $bbcode_close;}

if ( $open_cnt &lt; $close_cnt )
{for ($i = 0; $i &lt; $div; $i++)
$unznews = $bbcode_open.$unznews;}}

$unznews = str_replace(&quot;[sub]&quot;, &quot;&lt;sub&gt;&quot;, $unznews);
$unznews = str_replace(&quot;[/sub]&quot;, &quot;&lt;/sub&gt;&quot;, $unznews);
$unznews = str_replace(&quot;[tt]&quot;, &quot;&lt;tt&gt;&quot;, $unznews);
$unznews = str_replace(&quot;[/tt]&quot;, &quot;&lt;/tt&gt;&quot;, $unznews);
$unznews = str_replace(&quot;[sup]&quot;, &quot;&lt;sup&gt;&quot;, $unznews);
$unznews = str_replace(&quot;[/sup]&quot;, &quot;&lt;/sup&gt;&quot;, $unznews);
$unznews = str_replace(&quot;<s>&quot;, &quot;&lt;s&gt;&quot;, $unznews);
$unznews = str_replace(&quot;</s>&quot;, &quot;&lt;/s&gt;&quot;, $unznews);
$unznews = str_replace(&quot;<strong>&quot;, &quot;<b>&quot;, $unznews);
$unznews = str_replace(&quot;</strong>&quot;, &quot;</b>&quot;, $unznews);
$unznews = str_replace(&quot;<em>&quot;, &quot;<i>&quot;, $unznews);
$unznews = str_replace(&quot;</em>&quot;, &quot;</i>&quot;, $unznews);
$unznews = str_replace(&quot;<u>&quot;, &quot;<u>&quot;, $unznews);
$unznews = str_replace(&quot;</u>&quot;, &quot;</u>&quot;, $unznews);
$unznews = str_replace(&quot;[  quote]&quot;, &quot;&lt;table width=&#039;50%&#039; cellspacing=&#039;1&#039; cellpadding=&#039;4&#039; class=&#039;bg6&#039; style=&#039;margin-top : 7px;&#039;&gt;&lt;tr&gt;&lt;td class=&#039;bg3&#039;&gt;&lt;font class=&#039;newstitle&#039;&gt;Quote&lt;/font&gt;</br>&lt;div class=&#039;news&#039;&gt;&quot;, $unznews);
$unznews = str_replace(&quot;[  /quote]&quot;, &quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;, $unznews);
$unznews = str_replace(&quot;[  code]&quot;,&quot;<blockquote>&lt;span class=&quot;12px&quot;&gt;code:&lt;/span&gt;&lt;hr&gt;&lt;pre&gt;&quot;,$unznews);
$unznews = str_replace(&quot;[  /code]&quot;,&quot;&lt;/pre&gt;&lt;hr&gt;</blockquote>&quot;,$unznews);
$unznews = str_replace(&quot;<li>&quot;, &quot;&lt;li&gt;&quot;, $unznews); </li>$unznews = str_replace(&quot;[hr]&quot;, &quot;&lt;hr&gt;&quot;, $unznews);
$unznews = eregi_replace(&quot;<span style="color:"[^[">*)]([^[]*)</span>&quot;,&quot;&lt;font color=&quot;1&quot;&gt;2&lt;/font&gt;&quot;,$unznews);
$unznews = eregi_replace(&quot;[size=([^[]*)]([^[]*)[/size]&quot;,&quot;&lt;font size=&quot;1&quot;&gt;2&lt;/font&gt;&quot;,$unznews);
$unznews = eregi_replace(&quot;[font=([^[]*)]([^[]*)[/font]&quot;,&quot;&lt;font face=&quot;1&quot;&gt;2&lt;/font&gt;&quot;,$unznews);
$unznews = eregi_replace(&quot;[<a href="http://([^[" target="_blank" rel="nofollow">*)]IMAGE</a>]&quot;,&quot;&lt;img src=&quot;1&quot;&gt;&quot;,$unznews);
$unznews = eregi_replace(&quot;[align=([^[]*)]([^[]*)[/align]&quot;,&quot;&lt;p align=&quot;1&quot;&gt;2&lt;/p&gt;&quot;,$unznews);
$unznews = eregi_replace(&quot;<a href="mailto:([^[]*)">([^[]*)</a>&quot;, &quot;&lt;a href=&quot;mailto:1&quot;&gt;1&lt;/a&gt;&quot;,$unznews);
$unznews = eregi_replace(&quot;[email=([^[]*)]([^[]*)[/email]&quot;, &quot;&lt;a href=&quot;mailto:1&quot;&gt;2&lt;/a&gt;&quot;,$unznews);
$unznews = eregi_replace(&quot;(^|[&gt;[:space:]n])([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])([&lt;[:space:]n]|$)&quot;,&quot;1&lt;a href=&quot;2://34&quot; target=&quot;_blank&quot;&gt;2://34&lt;/a&gt;&quot;, $unznews);
$unznews = preg_replace(&quot;/([n &gt;(])www((.[w-_]+)+(:[d]+)?((/[w-_%]+(.[w-_%]+)*)|(/[~]?[w-_%]*))*(/?(?[&;=w+%]+)*)?(#[w-_]*)?)/&quot;, &quot;1&lt;a href=&quot;http://www2&quot;&gt;www2&lt;/a&gt;&quot;, $unznews);
$unznews = eregi_replace(&quot;www.([^[]*)&quot;, &quot;&lt;a href=&quot;http://www.1&quot; target=_blank&gt;1&lt;/a&gt;&quot;,$unznews);
$unznews = eregi_replace(&quot;([^[]*)&quot;,&quot;&lt;a href=&quot;1&quot; target=_blank&gt;1&lt;/a&gt;&quot;,$unznews);
$unznews = eregi_replace(&quot;<a href="http://([^[" target="_blank" rel="nofollow">*)]([^[]*)</a>&quot;,&quot;&lt;a href=&quot;1&quot; target=_blank&gt;2&lt;/a&gt;&quot;,$unznews);
return $unznews;}



/*Beta size calculator - Will be used on avatar checking*/
function calc_size ( $size )
{if ( $size &lt; 1000 )
return $size + &#039; Bytes&#039;;
if ( $size &lt; 1000000 )
return number_format(($size/1024), 2, &#039;.&#039;, &#039;&#039;).&#039; kB&#039;;
if ( $size &lt; 1000000000 )
return number_format($size/(1024*1024), 2, &#039;.&#039;, &#039;&#039;).&#039; MB&#039;;
if ( $size &lt; 1000000000000 )
return number_format($size/(1024*1024*1024), 2, &#039;.&#039;, &#039;&#039;).&#039; GB&#039;;}

?&gt;

- Edited By azz0r On Sun 20th, Jul 2003 @ 1:36:56pm

--

Why wont it save me?

Teh_Wolf
Teh_Wolf Carnager Of Pixels
Jul 20 2003 Anchor

Just to show azz0r some clean code:

&lt;?php
#------------------------------------------------------------#
# Core CMS v00001                                            #
# Copyright 2003 by Core PHP                                 #
#------------------------------------------------------------#

# INIT CORE CMS ------------------------------------ #
session_start ();

list($usec, $sec) = explode(&#039; &#039;, microtime());
$head[&#039;time_start&#039;] = ((float)$usec + (float)$sec);

# Load required files:
require(&#039;./settings/main.php&#039;);
require(&#039;./functions.php&#039;);
require(&#039;./classes/mysql.php&#039;);

# Set head vals:
$head[&#039;body&#039;] = &#039;&#039;;
$head[&#039;time&#039;] = time();
$head[&#039;active&#039;] = false;
$head[&#039;delsql&#039;] = &#039;&#039;;
$head[&#039;found&#039;] = false;
$head[&#039;lang&#039;] = &#039;en&#039;;
$head[&#039;theme&#039;] = &#039;default&#039;;
$head[&#039;page&#039;] = $_GET[&#039;p&#039;];
$head[&#039;title&#039;] = $set[&#039;sitename&#039;];
$head[&#039;location&#039;] = &#039;&#039;;

# Make sure we have a page to go to:
if (!$head[&#039;page&#039;]){
header(&#039;Location: &#039; . $set[&#039;defpage&#039;]);
exit;
}

# Add site name to location bar:
$head[&#039;location&#039;][] = array($set[&#039;sitename&#039;], &#039;./index.php&#039;);

# Start Database:
$database = new db; $database-&gt;open();

# Cache main templates:
$mtpl = load_temp(array(
&#039;main_user_color&#039;,
&#039;main_user_plain&#039;,
&#039;main&#039;,
));

# MANAGE SESSIONS ---------------------------------- #

# Check to see if there is a session to wrok with:
if (isset($_SESSION[&#039;username&#039;]) and isset($_SESSION[&#039;password&#039;]) and isset($_SESSION[&#039;userid&#039;])) {
$_SESSION[&#039;username&#039;] = addslashes($_SESSION[&#039;username&#039;]);

$userinf = $database-&gt;query(&quot;SELECT * FROM $set[sqlpref]users WHERE id = &#039;&quot; . $_SESSION[&#039;userid&#039;] . &quot;&#039; LIMIT 1&quot;);

$userinf = $database-&gt;fetch_array($userinf);
$userinf[&#039;password&#039;] = stripslashes($userinf[&#039;password&#039;]);
$_SESSION[&#039;password&#039;] = stripslashes($_SESSION[&#039;password&#039;]);

if($_SESSION[&#039;password&#039;] == $userinf[&#039;password&#039;]) {
$head[&#039;active&#039;] = true;
$head[&#039;username&#039;] = $userinf[&#039;name&#039;];
$head[&#039;id&#039;] = $userinf[&#039;id&#039;];
$head[&#039;ip&#039;] = $_SERVER[&#039;REMOTE_ADDR&#039;];
$head[&#039;level&#039;] = $_SESSION[&#039;userlevel&#039;];
}
}

$_SESSION[&#039;username&#039;] = stripslashes($_SESSION[&#039;username&#039;]);

if (!$head[&#039;active&#039;]) {
$head[&#039;username&#039;] = $set[&#039;guestname&#039;];
$head[&#039;id&#039;] = 0;
$head[&#039;ip&#039;] = $_SERVER[&#039;REMOTE_ADDR&#039;];
$head[&#039;level&#039;] = 0;
}

# Find users online entries that need deleting:
$res = $database-&gt;query(&quot;SELECT id, ip, time FROM $set[sqlpref]usersonline&quot;);
while ($user = $database-&gt;fetch_array($res)) {
if ($user[&#039;ip&#039;] &lt;&gt; $_SERVER[&#039;REMOTE_ADDR&#039;]) {
if ($head[&#039;time&#039;] - $user[&#039;time&#039;] &gt; $set[&#039;seslen&#039;]) {
if (!$head[&#039;delsql&#039;]) {
$head[&#039;delsql&#039;] .= &quot;DELETE FROM $set[sqlpref]usersonline WHERE ip=&#039;$user[ip]&#039; &quot;;
} else {
$head[&#039;delsql&#039;] .= &#039;OR ip=&#039;&#039; . $user[&#039;ip&#039;] . &#039;&#039; &#039;;
}
}
} else {
if (!$head[&#039;found&#039;]) {
$head[&#039;found&#039;] = true;
$database-&gt;query(&quot;UPDATE $set[sqlpref]usersonline SET time=&#039;$head[time]&#039; WHERE ip=&#039;$_SERVER[REMOTE_ADDR]&#039; LIMIT 1&quot;);
}
}
}

if (!$head[&#039;found&#039;]) {
$database-&gt;query(&quot;INSERT INTO $set[sqlpref]usersonline VALUES (&#039;$head[userid]&#039;, &#039;$head[username]&#039;, &#039;$_SERVER[REMOTE_ADDR]&#039;, &#039;$head[time]&#039;, &#039;&#039;, &#039;&#039;)&quot;);
}

# Chack to see if there where any to dalete and delete them:
if ($head[&#039;delsql&#039;]) {
$database-&gt;query($head[&#039;delsql&#039;]);
}

# CAPTURE ------------------------------------------ #
# Start output capturing:
ob_start();

# PAGE --------------------------------------------- #
#print $set[&#039;defpage&#039;] . &#039; - &#039; . $_SERVER[&#039;REQUEST_URI&#039;];
# Make sure we can open the requested page:
if (file_exists(&quot;./langs/$head[lang]_$head[page].php&quot;) and file_exists(&quot;./settings/$head[page].php&quot;) and file_exists(&quot;./pages/$head[page].php&quot;)) {
require(&quot;./langs/$head[lang]_$head[page].php&quot;);
require(&quot;./settings/$head[page].php&quot;);
require(&quot;./pages/$head[page].php&quot;);
} else {
header(&#039;Location: &#039; . $set[&#039;404page&#039;]);
}

# PAGE BLOCKS -------------------------------------- #

# Load block templates:
$btpl = array();
$blocks = $database-&gt;query(&quot;SELECT * FROM $set[sqlpref]plugin_tags&quot;);
while ($row = $database-&gt;fetch_array($blocks)) {
$btpl[&quot;block_$row[id]&quot;] = load_temp(array(&quot;block_$row[id]&quot;));
}

$blocks = $database-&gt;query(&quot;SELECT t.*, i.* FROM $set[sqlpref]plugin_tags t LEFT JOIN $set[sqlpref]plugin_items i ON (i.pid=t.id) WHERE i.pos&lt;&gt;0 ORDER BY i.pos ASC&quot;);
while ($row = $database-&gt;fetch_array($blocks)) {
eval(&quot;$row[title] = &quot;&quot; . addslashes($row[&#039;title&#039;]) . &quot;&quot;;&quot;);
eval(&quot;$row[data] = &quot;&quot; . addslashes($row[&#039;data&#039;]) . &quot;&quot;;&quot;);
eval(&quot;$block[$row[id]] .= &quot;&quot; . $btpl[&quot;block_$row[id]&quot;] . &quot;&quot;;&quot;);
}

# END CAPTURE -------------------------------------- #

# Save output and stop capturing:
$head[&#039;body&#039;] = ob_get_contents();
ob_end_clean();

# FINALIZE ----------------------------------------- #

# Make the location selector:
$location = &#039;&#039;; $i = 1;
if ($set[&#039;defpage&#039;] &lt;&gt; &#039;.&#039; . $_SERVER[&#039;REQUEST_URI&#039;]) {
foreach ($head[&#039;location&#039;] as $k) {
if ($i &lt;&gt; count($head[&#039;location&#039;])) {
$location .= &quot;&lt;a href=&quot;$k[1]&quot;&gt;$k[0]&lt;/a&gt; &gt; &quot;;
} else {
$location .= &quot;<b>$k[0]</b>&quot;;
$head[&#039;pagetitle&#039;] = $k[0];
}
$i++;
}
} else {
$location .= &#039;<b>&#039; . $head[&#039;location&#039;][0][0] . &#039;</b>&#039;;
$head[&#039;pagetitle&#039;] = $head[&#039;location&#039;][1][0];
}
$head[&#039;location&#039;] = $location;
unset($location);

# Update users online:
$database-&gt;query(&quot;UPDATE $set[sqlpref]usersonline SET ls_title=&#039;$head[pagetitle]&#039;, ls_url=&#039;.$_SERVER[REQUEST_URI]&#039; WHERE ip=&#039;$_SERVER[REMOTE_ADDR]&#039; LIMIT 1&quot;);

list($usec, $sec) = explode(&#039; &#039;, microtime());
$head[&#039;time_end&#039;] = ((float)$usec + (float)$sec);
$head[&#039;time_end&#039;] = number_format(($head[&#039;time_end&#039;] - $head[&#039;time_start&#039;]), 5, &#039;.&#039;, &#039;&#039;);
$head[&#039;count_sql&#039;] = $database-&gt;querycount;

# Eval main template:
eval(&quot;$output = &quot;&quot; . $mtpl[&#039;main&#039;] . &quot;&quot;;&quot;);

print stripslashes($output);

# -------------------------------------------------- #
?&gt;

- Edited By The_Wolf On Sun 20th, Jul 2003 @ 7:32:27am

--

“I hereby state my opinion that the notion of a [expletive deleted] is a basic superstition, that there is no evidence for the existence of any [expletive deleted].”

Jul 20 2003 Anchor

Ok fix0red my function list...heres my...start-up

&lt;?

$query_setting = mysql_query(&quot;SELECT * FROM unz_settings&quot;);
$setting = mysql_fetch_object($query_setting);

$site_properties[&#039;site&#039;] = $setting-&gt;site;
$site_properties[&#039;commenting&#039;] = $setting-&gt;commenting;
$site_properties[&#039;guest_comment&#039;] = $setting-&gt;guest_comment;
$site_properties[&#039;sign_up&#039;] = $setting-&gt;sign_up;
$site_properties[&#039;per_page&#039;] = $setting-&gt;per_page;
$site_properties[&#039;guest_vote&#039;] = $setting-&gt;guest_vote;
$site_properties[&#039;chatter_pp&#039;] = $setting-&gt;chatter_pp;
$site_properties[&#039;guest_chatter&#039;] = $setting-&gt;guest_chatter;

if($site_properties[&#039;site&#039;] == &#039;off&#039;)
{include(&quot;pages/misc/site_off.php&quot;);
exit();}

else

{if(isset($_COOKIE[&#039;username&#039;]) && isset($_COOKIE[&#039;password&#039;]))
{$sql = &quot;SELECT uid,username,password,status FROM unz_users WHERE username = &#039;&quot; . $_COOKIE[&#039;username&#039;] . &quot;&#039; AND password = &#039;&quot; . $_COOKIE[&#039;password&#039;] . &quot;&#039;&quot;;
$query = mysql_query($sql);
$auth = mysql_fetch_object($query);

$user_properties[&#039;username&#039;] = $auth-&gt;username;
$user_properties[&#039;status&#039;] = $auth-&gt;status;
$user_properties[&#039;uid&#039;] = $auth-&gt;uid;}}



if(!$_COOKIE[&#039;visited&#039;])
{if(!$user_properties[&#039;uid&#039;])
{setcookie (&quot;visited&quot;, &quot;visited&quot;, time()+60*60*24*30,&#039;/&#039;,&#039;.wuggawoo.co.uk&#039;, 0);
mysql_query(&quot;INSERT INTO unz_stats (uid,status,host,ip,browser,time,referer,qstring) VALUES (&#039;2&#039;,&#039;unique&#039;,&#039;$host&#039;,&#039;$ip&#039;,&#039;$browser&#039;,
&#039;$time&#039;,&#039;$referer&#039;,&#039;$qstring&#039;)&quot;);}
else
{mysql_query(&quot;INSERT INTO unz_stats (uid,status,host,ip,browser,time,referer,qstring) VALUES (&#039;&quot;.$user_properties[&#039;uid&#039;].&quot;&#039;,&#039;unique&#039;,&#039;$host&#039;,&#039;$ip&#039;,&#039;$browser&#039;, &#039;$time&#039;,&#039;$referer&#039;,&#039;$qstring&#039;)&quot;);}}

else

{if(!$user_properties[&#039;uid&#039;])
{mysql_query(&quot;INSERT INTO unz_stats (uid,status,host,ip,qstring) VALUES (&#039;2&#039;,&#039;pageview&#039;,&#039;$host&#039;,&#039;$ip&#039;,&#039;$qstring&#039;
)&quot;);}
else
{mysql_query(&quot;INSERT INTO unz_stats (uid,status,host,ip,qstring) VALUES (&#039;&quot;.$user_properties[&#039;uid&#039;].&quot;&#039;,&#039;pageview&#039;,&#039;$host&#039;,&#039;$ip&#039;,&#039;$qstring&#039;)&quot;);}}

?&gt;

--

Why wont it save me?

Teh_Wolf
Teh_Wolf Carnager Of Pixels
Jul 20 2003 Anchor

Look at the clean!

Ccms.corephp.org

--

“I hereby state my opinion that the notion of a [expletive deleted] is a basic superstition, that there is no evidence for the existence of any [expletive deleted].”

Jul 20 2003 Anchor

Looks like ass to me :P

--

Why wont it save me?

Jul 20 2003 Anchor

:o so confusing! Which one of you is right? ARGH!

Jul 20 2003 Anchor

me obviously.

although most PHP sites will favour wolfs bracketing style; btw no1's code is wrong, and no-ones is right.

--

Why wont it save me?

Teh_Wolf
Teh_Wolf Carnager Of Pixels
Jul 21 2003 Anchor

Thats correct, mine just happens to be easy to read...

--

“I hereby state my opinion that the notion of a [expletive deleted] is a basic superstition, that there is no evidence for the existence of any [expletive deleted].”

Jul 21 2003 Anchor

O_o

BigBird
BigBird Mod DB Pilot
Jul 22 2003 Anchor

O_o

/me continues writing Domination code

--

BigBird

Mod DB Guy
Play Something Different

PsychoFarmer
PsychoFarmer modDB King
Jul 22 2003 Anchor

erm, i cant actually play the game though... just displays member info, including a non bleeped password

and azzy, i like your commenting... makes it easy to change things if a certain feature is borked

- Edited By PsychoFarmer On Mon 21st, Jul 2003 @ 9:24:34pm

--

___________________________
Today seems like a good day to burn a bridge or two
I am the freakiest man in the world!!!!
I beg to differ, on the contrary, I agree with every word that you say

User Posted Image

BigBird
BigBird Mod DB Pilot
Jul 22 2003 Anchor

yeh yeh the game is still very much so in development...

and ofcourse it's unbleeped... :P (i dun have a reason for havin it unbleeped but there ya go...)

--

BigBird

Mod DB Guy
Play Something Different

Jul 22 2003 Anchor

Indeed PF, I really cant understand Wolfs code usually cos its like bracketing hell.

--

Why wont it save me?

INtense!
INtense! End Boss
Jul 22 2003 Anchor

Core CMS is neat, very neat but you are making code to be publically released, azz0r and myself are not planning that, so we have a little extra freedom.

I would show off my new forum code, but it still is a while off and messy ;)

--

Scott Reismanis
DBolical | @scottreismanis

BigBird
BigBird Mod DB Pilot
Jul 22 2003 Anchor

don't talk to me about messy...
hehe last time i showed you some code i had written INtense! your shot me down.. said it works but was like php v1 n00b style coding hehe (well they weren't your words but that was what was emplied :P)

but yeh my code is generally neat cos i'm from a vb back ground and vb helps to be structured... and my code is getting more and more complex on a weekly basis...

--

BigBird

Mod DB Guy
Play Something Different

Jul 27 2003 Anchor

Wuggawoo.co.uk > to see this in action

view wrote: <?php

if(!$uid)
{$error = "You didnt input a user ID.";
error_box($error, $forward);}

else

{$query = mysql_query("SELECT * FROM unz_users WHERE uid='$uid'");
$num_rows = mysql_num_rows($query);

if($num_rows > 0)

{$user = mysql_fetch_object($query);
mysql_query("UPDATE unz_users SET views = views + 1 WHERE uid = '$uid'");

if($user->uid == $user_properties['uid'] || $user_properties['status'] == admin)
{$edit = "<font class='newsunder'>: <a href='?section=edit_account'>Edit account</a></font>";}

echo "<table width='100%' cellspacing='1' cellpadding='4' class='bg6' style='margin-top : 7px;'>
<tr align='left' valign='top'>
<td class='bg1'><font class='newstitle'>Viewing $user->username $edit</font>";

echo "<table width='100%' cellspacing='1' cellpadding='4' class='bg6' style='margin-top : 7px;'>
<tr align='left' valign='top'>
<td class='bg3'><font class='newstitle'>Vital statistics</font>

<font class='newstext'>User ID : $user->uid</font>

<font class='newstext'>Registered : ".date('jS F y', $user->regdate)."</font>

<font class='newstext'>Last login : ".date('jS F y', $user->last_login)." (";

echo TimeDiffo($user->last_login);
echo " ago)</font>

<font class='newstext'>Host address : $user->host</font></td></tr></table>";


/*User defined data box start*/
if($user->email && !$user->email_hide)
{$email = "<font class='newstext'>Email Address : <a href='mailto:$user->email' subject='Emailed from wuggawoo.co.uk'>$user->email</a></font>
";}

if($user->site)
{$site = "<font class='newstext'>Website : <a href='$user->site' target='_blank'>$user->site</a></font>
";}

if($user->msn && !$user->msn_hide)
{$msn = "<font class='newstext'>MSN address : $user->msn</font>
";}

if($user->sex == 'M')
{$sex = "<a href='http://www.bullz-eye.com/'>Male</a>";}
elseif ($user->sex == 'F')
{$sex = "<a href='http://www.ivillage.com/'>Female</a>";}
else{$sex = "Not available";}

echo "<table width='100%' cellspacing='1' cellpadding='4' class='bg6' style='margin-top : 7px;'>
<tr align='left' valign='top'>
<td class='bg3'><font class='newstitle'>User defined data</font>

$email
$site
$msn
<font class='newstext'>Gender : $sex</font>

<font class='newstext'>Birthday : ".datetimeformat('jS F Y', $user->bday)."</font></td></tr></table>";


/*Contribution box start*/
$query_comment = mysql_query("SELECT uid FROM unz_comments WHERE uid= '$uid'");
$query_chatter = mysql_query("SELECT uid FROM unz_chatterbox WHERE uid = '$uid'");
$comment_count = mysql_num_rows($query_comment);
$chatter_count = mysql_num_rows($query_chatter);

echo "<table width='100%' cellspacing='1' cellpadding='4' class='bg6' style='margin-top : 7px;'>
<tr align='left' valign='top'>
<td class='bg3'>
<font class='newstitle'>Site contribution</font>

<font class='newstext'>News Comment : $comment_count</font>

<font class='newstext'>ChatterBox entries : $chatter_count</font>

<font class='newstext'>Logins / Logouts : $user->login / $user->logout</font></td></tr></table>";


/*Tag wall meter start*/
if($user->tag !="")
{$user->tag = nl2br($user->tag);
$user->tag = smileys($user->tag);
$user->tag = InsertBBCode($user->tag);
echo "<table width='100%' cellspacing='1' cellpadding='4' class='bg6' style='margin-top : 7px;'>
<tr align='left' valign='top'>
<td class='bg3'>
<font class='newstitle'>FreeSpeech box</font>

<font class='newstext'>$user->tag</font></td></tr></table>"
;;}


/*Respect meter start*/
if ($user->respect_total == NULL || $user->people_voted == NULL)
{$respect = 0;
$user->respect_total = 0;
$user->people_voted = 0;}

else

{$respect = $user->respect_total / $user->people_voted;
$respect = substr($respect, 0, strrpos($respect, '.') + 2);}

echo "<table width='100%' cellspacing='1' cellpadding='4' class='bg6' style='margin-top : 7px;'>
<tr align='left' valign='top'>
<td class='bg3'>
<font class='newstitle'>Respect vote</font>

<font class='newstext'>$respect out of 5</font>
<font class='newstext'>Total ($user->respect_total) / Total people voted ($user->people_voted)</font>

<font class='newstext'><a href='?section=voting_user&uid=$uid&vote=1' target='_self' class='navbar'>1</a>
<a href='?section=voting_user&uid=$uid&vote=2' target='_self' class='navbar'>2</a>
<a href='?section=voting_user&uid=$uid&vote=3' target='_self' class='navbar'>3</a>
<a href='?section=voting_user&uid=$uid&vote=4' target='_self' class='navbar'>4</a>
<a href='?section=voting_user&uid=$uid&vote=5' target='_self' class='navbar'>5</a>
</font></td></tr></table>"
;;

echo "</td></tr></table>";}

else

{$forward = "";
$error = "No such user exists.";
$forward = "yep";
error_box($error, $forward);}}

?>


My favourite page, not to complex :)

- Edited By azz0r On Sun 27th, Jul 2003 @ 3:52:58pm

--

Why wont it save me?

Jul 27 2003 Anchor

BigBird wrote: don't talk to me about messy...
hehe last time i showed you some code i had written INtense! your shot me down.. said it works but was like php v1 n00b style coding hehe (well they weren't your words but that was what was emplied :P)

but yeh my code is generally neat cos i'm from a vb back ground and vb helps to be structured... and my code is getting more and more complex on a weekly basis...


PHP v1 n00b style? Haha! Birdeh that sucks but it's funny. Where would you guys recommend me to look to get good assistance on PHP? I want to teach myself.

Jul 27 2003 Anchor

Try Php.net

--

Give me ambiguity or give me... something else.

Dominant Species scope.creep User Posted Image

PsychoFarmer
PsychoFarmer modDB King
Jul 27 2003 Anchor

i tried php.net, and it was helpful for about 10 mins before it went WAY over my head...

that, plus the fact that i dont have a place to view php on, atm...

--

___________________________
Today seems like a good day to burn a bridge or two
I am the freakiest man in the world!!!!
I beg to differ, on the contrary, I agree with every word that you say

User Posted Image

Jul 28 2003 Anchor

Notepad? Internet Explorer?

Jul 28 2003 Anchor

View? Do you mean that you don't have a php IDE app to help you code, or you don't have a php-capable web server to host your stuff? Or perhaps something even more cryptic?

Google to the rescue! Don't have it? Find it and download it. Or try Download.com or even Tucows.com .

--

Give me ambiguity or give me... something else.

Dominant Species scope.creep User Posted Image

Mar 4 2004 Anchor

heres my startup.php

&lt;?

list($var_null, $var_section, $var_id, $var_page, $var_extra, $var_extra1) = explode(&#039;/&#039;, $_SERVER[&#039;PATH_INFO&#039;]);//smart clean urls

if(isset($_COOKIE[&#039;username&#039;]) && isset($_COOKIE[&#039;password&#039;]))
{$auth = mysql_fetch_object(mysql_query(&quot;SELECT uid, username, password, status, warn, timezone, avatoo, sigoo FROM $UserDB.unz_users WHERE username = &#039;&quot;.$_COOKIE[&#039;username&#039;].&quot;&#039; AND password = &#039;&quot;.$_COOKIE[&#039;password&#039;].&quot;&#039;&quot;)) or die(mysql_error());

if($auth-&gt;status == &#039;0&#039; || $auth-&gt;warn &gt; 2)//IF USERS BANNED...
{$user_properties[&#039;banned&#039;] = &#039;0&#039;;}

else

{$user_properties[&#039;banned&#039;] = 1;}
$user_properties[&#039;status_id&#039;] = $auth-&gt;status;
$user_properties[&#039;username&#039;] = $auth-&gt;username; //SET USER VARIABLES
$user_properties[&#039;uid&#039;] = $auth-&gt;uid;
$user_properties[&#039;avatoo&#039;] = $auth-&gt;avatoo;
$user_properties[&#039;sigoo&#039;] = $auth-&gt;sigoo;
$user_properties[&#039;timezone&#039;] = $auth-&gt;timezone;}


//FORUM SETTINGS
$settings = mysql_fetch_object(mysql_query(&quot;SELECT * FROM $forumzDB.forumz_settings&quot;)) or die(mysql_error());

$forum_properties[&#039;status&#039;] = $settings-&gt;status; //1 for on, 0 for off

if($forum_properties[&#039;status&#039;] == &#039;0&#039; && $user_properties[&#039;status_id&#039;] &lt;= 1) //IF FORUM IS OFF, AND USER IS NOT A STAFFER OR ADMIN
{$reason = &quot;$settings-&gt;reason&quot;; require_once(&quot;pages/html/site_off.html&quot;); exit();}//THEN DISPLAY SITEOFF.PHP

else

{$forum_properties[&#039;reason&#039;] = $settings-&gt;reason;}
$forum_properties[&#039;site_name&#039;] = $settings-&gt;site_name; //site name used in title and header
$forum_properties[&#039;cookieURL&#039;] = $settings-&gt;cookieURL; //cookie URL
$forum_properties[&#039;adminemail&#039;] = $settings-&gt;admin_email; //admin email address
$forum_properties[&#039;sign_up&#039;] = $settings-&gt;sign_up; //1 for signing up
$forum_properties[&#039;scar&#039;] = $settings-&gt;scar; // 1 to leave edit marks
$forum_properties[&#039;guests&#039;] = $settings-&gt;guests;// 1 to let guests post
$forum_properties[&#039;attachments&#039;] = $settings-&gt;attachments;// 1 to allow attachment posting
$forum_properties[&#039;attachments_guest&#039;] = $settings-&gt;attachments_guest;// 1 to let guests see attachments
$forum_properties[&#039;user_titles&#039;] = $settings-&gt;user_titles;// 1 to have user titles
$forum_properties[&#039;custom_titles&#039;] = $settings-&gt;custom_titles;// 1 to let users edit there title
$forum_properties[&#039;ot&#039;] = $settings-&gt;ot; //in seconds
$forum_properties[&#039;df&#039;] = $settings-&gt;df; //deleted forum ID
$forum_properties[&#039;dt&#039;] = $settings-&gt;dt; //deleted thread ID
$forum_properties[&#039;version&#039;] = &quot;2.40&quot;; // forumz version
$forum_properties[&#039;forumzURL&#039;] = $settings-&gt;forumzURL;//images + attachments url
$forum_properties[&#039;base_url&#039;] = &quot;&quot;.$forum_properties[&#039;forumzURL&#039;].&quot;/index&quot;;//base url
//ARRAY
$setting_array = array(
array(&#039;smilies&#039;),// 1 for smilies
array(&#039;swears&#039;),//1 for swearbot
array(&#039;memberslist_pp&#039;),//members per page on memberlist
array(&#039;active_pp&#039;),//threads per active topics
array(&#039;thread_pp&#039;),//posts per thread page
array(&#039;forum_pp&#039;),//threads per forum page
array(&#039;newposts_pp&#039;),//threads per forum page
array(&#039;pm_pp&#039;));//messages per pm page

foreach($setting_array as $subarray)
{list($set) = $subarray;
if(!$_COOKIE[&quot;$set&quot;])
{$forum_properties[&quot;$set&quot;] = $settings-&gt;$set;}//set the forum properties using the DB
else
{$forum_properties[&quot;$set&quot;] = $_COOKIE[&quot;$set&quot;];}}//set the forum properties using the cookie


if(!$user_properties[&#039;uid&#039;])//IF USER IS A GUEST THEN ADD TO STATS, ELSE ADD TO USER LIST AND STORE IP+HOST
{mysql_query(&quot;UPDATE $forumzDB.unz_stats SET guest = guest + 1 WHERE stid = 1&quot;) or die(mysql_error());}
else
{mysql_query(&quot;UPDATE $forumzDB.unz_stats SET user = user + 1 WHERE stid = 1&quot;) or die(mysql_error());
hostIP($user_properties[&#039;uid&#039;]);}




//CHECK TO SEE IF THE USER IS A UNIQUE OR A REVISIT AND RECORD
if($_COOKIE[&#039;visited&#039;] == 1)
{mysql_query(&quot;UPDATE $forumzDB.unz_stats SET pageview = pageview + 1 WHERE stid = 1&quot;) or die(mysql_error());}
else
{mysql_query(&quot;UPDATE $forumzDB.unz_stats SET `unique` = `unique` + 1 WHERE stid = 1&quot;);
setcookie (&quot;visited&quot;, &quot;1&quot;, time()+60*60*24*30,&#039;/&#039;,&quot;&quot;.$forum_properties[&#039;cookieURL&#039;].&quot;&quot;, 0);}




//SET THEME DEPENEDENT ON VARIABLE IN LINK - thx nicholas
if($submitted == true)
{setcookie (&quot;theme&quot;, &quot;$tc&quot;, time()+60*60*24*30,&#039;/&#039;,&quot;&quot;.$forum_properties[&#039;cookieURL&#039;].&quot;&quot;, 0);
header(&quot;Location: $HTTP_REFERER&quot;);}

if(!$_COOKIE[&#039;theme&#039;])
{setcookie (&quot;theme&quot;, &quot;default&quot;, time()+60*60*24*30,&#039;/&#039;,&quot;&quot;.$forum_properties[&#039;cookieURL&#039;].&quot;&quot;, 0);
header(&quot;Location: ?section=index&quot;);}

if(!$_COOKIE[&#039;username&#039;])
{$user_properties[&#039;banned&#039;] = 1;}//if were a guest we arent banned

if($_COOKIE[&#039;last_visit&#039;])

{if($user_properties[&#039;status_id&#039;] &gt; 1)

{$count = mysql_num_rows(mysql_query(&quot;SELECT time FROM $forumzDB.forumz_posts WHERE time &gt; &quot;.$_COOKIE[&#039;last_visit&#039;].&quot;&quot;));}

else

{$count = mysql_num_rows(mysql_query(&quot;SELECT p.time, p.pid, f.type, f.fid FROM $forumzDB.forumz_posts p LEFT
JOIN $forumzDB.forumz_forums f ON (p.fid = f.fid) WHERE ((p.time &gt; &quot;.$_COOKIE[&#039;last_visit&#039;].&quot;)
&& (f.type = &#039;anon&#039; OR f.type = &#039;publ&#039;))&quot;));}

if($count &gt; 0)
{$nposts =  &quot;&lt;a href=\&quot;index/new_posts/&quot;.$_COOKIE[&#039;last_visit&#039;].&quot;\&quot;&gt;New Posts ($count)&lt;/a&gt; : &quot;;}}

else

{last_visit($section);}

$theme = $_COOKIE[&#039;theme&#039;];//$theme is now our oyster
usersonline($user_properties[&#039;uid&#039;]);//Puts the user online
disable_cache();//Clears old data
last_visit($var_section);

?&gt;

--

Why wont it save me?

Mar 4 2004 Anchor

azz0r how is Wuggawoo coming along? I haven't been there in awhile and we don't talk on MSN anymore. :(

Mar 9 2004 Anchor

Why dont you go see :P its not nearly as active really. I dont use msn much anymore either :o

--

Why wont it save me?

Mar 9 2004 Anchor

Then what do you do? You should post some more with me, let's show the nubs how we do it around here.

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.