Computer Science Canada

Got any fav PHP scripts? ( post em here :)..duh... )

Author:  Amailer [ Tue Jun 24, 2003 12:05 am ]
Post subject:  Got any fav PHP scripts? ( post em here :)..duh... )

Guys, who ever is into PHP....got any fav scripts/functipn/clases etc? Post them over here.


Mine, its BBCODE!
well...hehe i just use it for my news, and well its nto my fav but i just made it.

code:

//BBC

//
//      $code_start_html = '<div class=\"ng_quote\"><b><i>Code:</i></b><div class=\"ng_quote_body\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; border-style: dotted; border-width: 0\" width=\"100%\" bgcolor=\"#FFFFFF\"><tr><td width=\"100%\">';
//      $code_end_html = '</td></tr></table></div></div>';
//      $info = str_replace('[code]', "$code_start_html", $info);
//      $info = str_replace('[/code]', "$code_end_html", $info);

  $preg = array(
    // Font and text manipulation ( [color] [size] [font] [align] )
    '/\[color=(.*?)(?::\w+)?\](.*?)\[\/color(?::\w+)?\]/si'   => "<span style=\"color:\\1\">\\2</span>",
    '/\[size=(.*?)(?::\w+)?\](.*?)\[\/size(?::\w+)?\]/si'     => "<span style=\"font-size:\\1\">\\2</span>",
    '/\[font=(.*?)(?::\w+)?\](.*?)\[\/font(?::\w+)?\]/si'     => "<span style=\"font-family:\\1\">\\2</span>",
    '/\[align=(.*?)(?::\w+)?\](.*?)\[\/align(?::\w+)?\]/si'   => "<div style=\"text-align:\\1\">\\2</div>",
    '/\[b(?::\w+)?\](.*?)\[\/b(?::\w+)?\]/si'                 => "<b>\\1</b>",
    '/\[i(?::\w+)?\](.*?)\[\/i(?::\w+)?\]/si'                 => "<i>\\1</i>",
    '/\[u(?::\w+)?\](.*?)\[\/u(?::\w+)?\]/si'                 => "<u>\\1</u>",
    '/\[center(?::\w+)?\](.*?)\[\/center(?::\w+)?\]/si'       => "<div style=\"text-align:center\">\\1</div>",
// '/\[code(?::\w+)?\](.*?)\[\/code(?::\w+)?\]/si'           => "<div class=\"ng_code\">\\1</div>",
    // [email]
    '/\[email(?::\w+)?\](.*?)\[\/email(?::\w+)?\]/si'         => "<a href=\"mailto:\\1\" class=\"ng_email\">\\1</a>",
    '/\[email=(.*?)(?::\w+)?\](.*?)\[\/email(?::\w+)?\]/si'   => "<a href=\"mailto:\\1\" class=\"ng_email\">\\2</a>",
    // [url]
    '/\[url(?::\w+)?\]www\.(.*?)\[\/url(?::\w+)?\]/si'        => "<a href=\"http://www.\\1\" target=\"_blank\" class=\"ng_url\">\\1</a>",
    '/\[url(?::\w+)?\](.*?)\[\/url(?::\w+)?\]/si'             => "<a href=\"\\1\" target=\"_blank\" class=\"ng_url\">\\1</a>",
    '/\[url=(.*?)(?::\w+)?\](.*?)\[\/url(?::\w+)?\]/si'       => "<a href=\"\\1\" target=\"_blank\" class=\"ng_url\">\\2</a>",
    // [img]
    '/\[img(?::\w+)?\](.*?)\[\/img(?::\w+)?\]/si'             => "<img src=\"\\1\" border=\"0\" />",
    '/\[img=(.*?)x(.*?)(?::\w+)?\](.*?)\[\/img(?::\w+)?\]/si' => "<img width=\"\\1\" height=\"\\2\" src=\"\\3\" border=\"0\" />",
    // [quote]
    '/\[quote(?::\w+)?\](.*?)\[\/quote(?::\w+)?\]/si'         => "<div class=\"ng_quote\"><b><i>Quote:</i></b><div class=\"ng_quote_body\"><table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; border-style: dotted; border-width: 1\" width=\"100%\" bgcolor=\"#FBFBFB\">
  <tr>
    <td width=\"100%\"><font size=\"2\" face=\"Courier New, Courier, mono\">\\1</font></td>
  </tr>
</table>
</div></div>",
    '/\[quote=(?:&quot;|"|\')?(.*?)["\']?(?:&quot;|"|\')?\](.*?)\[\/quote(?::\w+)?\]/si'   => "<div class=\"ng_quote\">Quote \\1:<div class=\"ng_quote_body\">\\2</div></div>",
    // [list]
    '/\[\*(?::\w+)?\]\s*([^\[]*)/si'                          => "<li class=\"ng_list_item\">\\1</li>",
    '/\[list(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/si'           => "<ul class=\"ng_list\">\\1</ul>",
    '/\[list(?::\w+)?\](.*?)\[\/list:u(?::\w+)?\]/s'          => "<ul class=\"ng_list\">\\1</ul>",
    '/\[list=1(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/si'         => "<ol class=\"ng_list\" style=\"list-style-type:decimal;\">\\1</ol>",
    '/\[list=i(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/s'          => "<ol class=\"ng_list\" style=\"list-style-type:lower-roman;\">\\1</ol>",
    '/\[list=I(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/s'          => "<ol class=\"ng_list\" style=\"list-style-type:upper-roman;\">\\1</ol>",
    '/\[list=a(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/s'          => "<ol class=\"ng_list\" style=\"list-style-type:lower-alpha;\">\\1</ol>",
    '/\[list=A(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/s'          => "<ol class=\"ng_list\" style=\"list-style-type:upper-alpha;\">\\1</ol>",
    '/\[list(?::\w+)?\](.*?)\[\/list:o(?::\w+)?\]/s'          => "<ol class=\"ng_list\" style=\"list-style-type:decimal;\">\\1</ol>",
    // the following lines clean up our output a bit
    '/<ol(.*?)>(?:.*?)<li(.*?)>/si'         => "<ol\\1><li\\2>",
    '/<ul(.*?)>(?:.*?)<li(.*?)>/si'         => "<ul\\1><li\\2>"
  );
  $info = preg_replace(array_keys($preg), array_values($preg), $info);


//END OF




HEHE useful, but the [ code.] and [/ code.] don't work Sad
I will have to fix it

This is my latest [[ for the profile ]]
ITS A BETA, not the real one... i don't code it this way for the real one, its much better the real one.

But i sitll made this.

code:

//Ok, im putting the view profile here,
//so...it kinda is part of the news though :)
function d_profile() {
global $rec, $result;
global $displays, $title;
global $name, $password, $email, $aim, $msn, $icq, $info, $id, $avatar, $websites;
global $PHP_SELF;

$displays = "<b><u><i>Profile information Of: $name</i></u><br><br>";
$title = "Profile info of: $name";

mysql_select_db("amailerforum");

$result = mysql_query("SELECT * FROM phpbb_users WHERE username='$name'");


while($rec = mysql_fetch_array($result)) {


//Now this is the important information
//the pass name email
$name = $rec['username'];
$password = $rec['user_password'];
$email = $rec['user_email'];

//this is the attitional information
$aim = $rec['user_aim'];
$msn = $rec['user_msnm'];
$icq = $rec['user_icq'];

//the web site of the user
$website = $rec['user_website'];

//this is like a user comment
$occ = $rec['user_occ'];
$intrests = $rec['user_interests'];

//ah yes, user avatar
$avatar = $rec['user_avatar'];

//the id of the user
$id = $rec['user_id'];


//So, if the Intrests are empty
//display 'None'
if($intrests == "") {
        $intrests = "None";
}


//If the Occ is empty
//display 'None'
if($occ == "") {
        $occ = "None";
}


//The thing that viewsers will have to click
//inorder to go to the users site
$webname = "Click here to visit";


//If the website is empty
//display a diffrent table with the name ''None''
if($website == "") {
        $websites = "
                </table>
          <br>
        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"56%\">
  <tr>
    <td width=\"23%\" valign=\"top\"><font face=\"Fixedsys\">Website:</font></td>
    <td width=\"77%\" valign=\"top\"><font face=\"Verdana\" size=\"2\">None</a></font></td>
  </tr>
</table>";

//else if the website is not empty
//then display the information needed
} elseif($website != "") {
$websites = "
                </table>
          <br>
        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"56%\">
  <tr>
    <td width=\"23%\" valign=\"top\"><font face=\"Fixedsys\">Website:</font></td>
    <td width=\"77%\" valign=\"top\"><font face=\"Verdana\" size=\"2\"><a href=\"$website\" target=\"_blank\">$webname</a></font></td>
  </tr>";
}


//Checking if the AIM field is blank or not
if($aim == "") {
        $aims = "
            <td width=\"23%\" valign=\"top\"><font face=\"Fixedsys\">AIM:</font></td>
    <td width=\"77%\" valign=\"top\"><font face=\"Verdana\" size=\"2\">None</a></font></td>
  </tr>
</table>";
} else {
         $aims = "<td width=\"23%\" valign=\"top\"><font face=\"Fixedsys\">AIM:</font></td>
    <td width=\"77%\" valign=\"top\"><font face=\"Verdana\" size=\"2\"><a href=\"aim:goim?screenname=$aim\">$aim</a></font></td>
  </tr>
</table>";
}

//Checkign if the MSN field is blank or not
if($msn == "") {
        $msns = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"56%\">
  <tr>
    <td width=\"23%\" valign=\"top\"><font face=\"Fixedsys\">MSN:</font></td>
    <td width=\"77%\" valign=\"top\"><font face=\"Verdana\" size=\"2\">None</a></font></td>
  </tr>
</table>";
} else {
        $msns = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"56%\">
  <tr>
    <td width=\"23%\" valign=\"top\"><font face=\"Fixedsys\">MSN:</font></td>
    <td width=\"77%\" valign=\"top\"><font face=\"Verdana\" size=\"2\"><a href=\"http://members.msn.com/$msn\" target=\"_blank\">$msn</a></font></td>
  </tr>
</table>";
}


//Checking if the ICQ field is blank or not!
if($icq == "") {
        $icqs = "
        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"56%\">
  <tr>
    <td width=\"23%\" valign=\"top\"><font face=\"Fixedsys\">ICQ:</font></td>
    <td width=\"77%\" valign=\"top\"><font face=\"Verdana\" size=\"2\">None</a></font></td>
  </tr>";

} else {
        $icqs = "
        <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"56%\">
  <tr>
    <td width=\"23%\" valign=\"top\"><font face=\"Fixedsys\">ICQ:</font></td>
    <td width=\"77%\" valign=\"top\"><font face=\"Verdana\" size=\"2\"><a href=\"$PHP_SELF?module=message&messenger=ICQ&icq=$icq&name=$name\">$icq</a></font></td>
  </tr>";
}


//After all the checks,
//we can finaly display the main thing
$displays .= "
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"56%\">
  <tr>
    <td width=\"23%\" valign=\"top\"><font face=\"Fixedsys\">Username:</font></td>
    <td width=\"77%\" valign=\"top\"><font face=\"Verdana\" size=\"2\">$name</font></td>
  </tr>
  <tr>
    <td width=\"23%\" valign=\"top\"><font face=\"Fixedsys\">Email:</font></td>
    <td width=\"77%\" valign=\"top\"><font face=\"Verdana\" size=\"2\"><a href=\"mailto:$email\">$email</a></font></td>
  </tr>
  <tr>
    <td width=\"23%\" valign=\"top\"><font face=\"Verdana\" size=\"2\">&nbsp;&nbsp;
    </font></td>
    <td width=\"77%\" valign=\"top\"><font face=\"Verdana\" size=\"2\">&nbsp;&nbsp;
    </font></td>
  </tr>
  <tr>
$aims
$msns
$icqs
$websites
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"56%\">
  <tr>
    <td width=\"23%\" valign=\"top\"><font face=\"Verdana\" size=\"2\"><font face=\"Fixedsys\">PM:</font></font></td>
    <td width=\"77%\" valign=\"top\"><font face=\"Verdana\" size=\"2\"><a href=\"http://termix-zero.ath.cx/scripts/amailers/forum/privmsg.php?mode=post&u=$id\">
Click to send a private message</a>&nbsp;</p></font></td>
  </tr>
</table>
          <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"56%\">
  <tr>
    <td width=\"23%\" valign=\"top\"><font face=\"Verdana\" size=\"2\">&nbsp;</font></td>
    <td width=\"77%\" valign=\"top\"><font face=\"Verdana\" size=\"2\">&nbsp;</font></td>
  </tr>
</table>
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"505\" height=\"41\">
  <tr>
    <td width=\"115\" valign=\"top\" height=\"41\"><font face=\"Fixedsys\">Small Info:</font></td>
    <td width=\"390\" valign=\"top\" height=\"41\"><font face=\"Verdana\" size=\"2\"><u>Interests:</u> $intrests<br><u>Occupation:</u> $occ</font></td>
  </tr>
  <tr>
    <td width=\"115\" valign=\"top\" height=\"41\"><font face=\"Fixedsys\">Avatar:</font></td>
    <td width=\"390\" valign=\"top\" height=\"41\"><font face=\"Verdana\" size=\"2\"><img border=\"0\" src=\"http://termix-zero.ath.cx/scripts/amailers/forum/images/avatars/$avatar\" width=\"64\" height=\"64\"></font></td>
  </tr>
</table>
<br>
<br>
<font face=\"Courier New\"><a href=\"javascript:history.back()\"></b>Return back</a></font>";
}


mysql_select_db("amailersite");
main_sites($displays, $title);
}


Basicaly i have connected to the phpBB forum, to get the user info. There is about...well not about there IS 2097 lines of code in my modules.php file Smile i shoved all my functions and etc in there, also my test stuff...which i did not delete, but it does nto take up much space...I KNOW its a bad way of coding but Sad hey Smile


Reason is that, i kinda am lazy to make function for everything and then use it for my future projects and etc. But im making a php NUKE NOW! wee! Good thing is i got everythign ready, i just need to put it all togeather and everything will be good. BTW as you can see the scripts on top, PHP IS EASY!

Author:  Blade [ Tue Jun 24, 2003 11:17 am ]
Post subject: 

really nice... but you should attach massive amounts of code as txt file or something... lol

Author:  Amailer [ Tue Jun 24, 2003 3:10 pm ]
Post subject: 

Yes well sorry, i got some more i want to post [[ small ones, for mysql ]]
But, i guess no one is into php here Sad

im currently going to have to put my whole forum in my sites layout, its going to take some time but oh well Neutral

Author:  Homer_simpson [ Tue Jun 24, 2003 5:03 pm ]
Post subject: 

i am interested in php projects but those things you made are addons to phpbb.. =(

Author:  Amailer [ Tue Jun 24, 2003 5:08 pm ]
Post subject: 

What things? the scripts i made? err...no...they are for my site. phpbb got its own stuff.... go to:
http://termix-zero.ath.cx/scripts/amailers/modules.php?module=news

i think is the url, click the name 'admin' you will see what the profile script does. ITS SO SIMPLE, to test it your self, creat an account on my forum, and go to:
http://termix-zero.ath.cx/scripts/amailers/modules.php?module=profile&name=YOUR FORUM NAME HERE

Smile you will see how it works...

Author:  Homer_simpson [ Tue Jun 24, 2003 5:38 pm ]
Post subject: 

lol i cant add comment to your news for some reason... and i already how to create a forum or a website with signup and everything Very Happy...
so uh... how bout a big php project? you come up with the idea we script it?

Author:  Amailer [ Tue Jun 24, 2003 5:46 pm ]
Post subject: 

Comment, err...as it says, its not ready.

Second, what kinda of project you wanna work on?
Project management one? Smile

Need tip:
Ok, should i change the forum layout to fit in my main sites layout? Or should i jsut use an iframe to put the forum on my main site?

Author:  PaddyLong [ Tue Jun 24, 2003 6:12 pm ]
Post subject: 

could make a full content management type of thing... like php nuke type of thing

Author:  Amailer [ Tue Jun 24, 2003 6:14 pm ]
Post subject: 

Those are boring, many people make it. Just don't get famous. My amailer site is PARTLY like php nuke, but its not fully compleated, since...well. lol the admin center has not been started Smile.

But if i would make a thing like phpNUKE...then i would let people change the FULL layout of the site, i mean the tables and everything, cept my copyright Smile

Author:  PaddyLong [ Tue Jun 24, 2003 8:41 pm ]
Post subject: 

of course...

like do everything as modules and then the designer can just do an include("somemodule.php") where ever in the layout they want it

the OSCommerce shopping cart is kind of like that with the side bars... each one of the things (like menu, search, feature product, etc) is its own file

but really, the things like nuke I think are mostly just for lazy or unexperienced people who are just looking for a quick thing that they can some what, but easily control

Author:  Amailer [ Tue Jun 24, 2003 8:49 pm ]
Post subject: 

They cant just include the file, if they are doing that, itneeds to have crtin stuff in it, so it can display the links and etc...

But it will be very easy to edit the layout. It would be like templates, put your templates in the templated folder. It has to have the stuff to display the links. And then once you have made your own template, the admin can choose which ever he/she wantes. Course it has to include downloads, links etc like a phpNUKE, but it should be made for programmers. Not the normal public

Author:  Amailer [ Tue Jun 24, 2003 11:28 pm ]
Post subject: 

These are some small scripts that are IMPORTANT!

code:

//Connect DB function
function db_connect() {
   global $dbhost, $dbusername, $dbuserpassword, $default_dbname;
   global $MYSQL_ERRNO, $MYSQL_ERROR;

   $link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword);
   if(!$link_id) {
      $MYSQL_ERRNO = 0;
      $MYSQL_ERROR = "Connection failed to the host $dbhost";
     
      return 0;
 
   }
   else return $link_id;
 }




$dbconnect = db_connect(); //Connect to mySQL

mysql_select_db("DBNAME"); //select a database


//Thats for selecting infromation from a table :)
        $result = mysql_query("SELECT * FROM table");
        while($rec = mysql_fetch_array($result)) {
        $variable = $rec['field'];
        }



there are a lot more, update, delete and etc Smile

Author:  Amailer [ Wed Jun 25, 2003 11:31 pm ]
Post subject: 

Well no once likes PHP [[ THATS IMPOSSIABLE ]] but im still going to keep posting some scritps, once im sure...ill make a LOGN tuorial Smile or what ever..

Now this script...Well ill just give you guys some tips and etc [[ I WANT POINTS!! Smile ]]

Ok as we all might know we all start php with.
code:

<?
and...
?>


So...once we know that...lets see our php information.
code:

<?
phpinfo();
?>


Copy and past that in a file name it: phpinfo.php
and then run it on your browser.

You will see all your PHP INFO Smile [[ er...ya.. ]]

Now some basic stuff
code:

<?
echo "Hello Compsci.ca...people";
?>


Now the echo is like print...in other languages you should know Smile
But in php there is PRINT and ECHO

code:

<?
print "Hello Compsci.ca...people";
?>


Yes well, you should know what echo is...because you WILL ...be using it in ALL you scripts at some point Smile

Now some if statements, with variables Smile
code:

<?
$variable_name = "Aaron";
$variable_message = "My name is:";

if($variable_name == "Aaron") {
  echo $variable_message . $variable_message;
} elseif($variable_name != "Aaron" AND $variable_name == "retard") {
echo "WHAT!! RETARD HAHAHAHAH!?";
} else {
echo "uh oh? what...oh..no one here...no name :( i feel sad :(";
?>


Ahh ok, hehe lil if statements Smile
Ok now, != means NOT EQUAL
and you should know what the rest means...you all are programmers here right? RIGHT!
Smile!
THIS TUTORIAL SUCKS..wait...its not 1 Smile ahh im happy good.



OK NOW...DATE/TIME/YEAR SCRIPT!!..ya..
code:

<?
//Lets display the title.
echo "<center><h1><u>Month/Day/Year/Time/</U></h1></center>";

//File name for writign the date and time.
$file = "mdyt.txt";
//get current date and time
$month = date("M, D, Y");
$day = date("d");
$year = date("Y");
$time = date("H:i:s");

//Lets just display the information
echo "<b>Month:</b> $month<br>";
echo "<b>Day:</b> $day<br>";
echo "<b>Year:</b> $year<br>";
echo "<b>Time:</b> $time<br>";
echo "<br>";

//Ok, now this is the variable for the /day/year/time.
//Its used in the fwrite part.
$mdyt = "$month $day $year $time";

//lets write them in a file.
$fp = fopen($file, "w");
fwrite($fp, $mdyt);
fclose($fp);
?>
<br>

<?
//Ok, now how about putting some examples?

//Example 1: This is a copyright example, very useful for sites.
echo "<b>Example 1: Copyright using the $ year.</b><br>";
echo "Copyright © Termix 2002 - $year. All rights researved.";

echo "<br><br>";

//Example 2: if you wan't time on your web site you can use this.
//Course you know you can change the style of the time.
//Just ajust the  $time = date("H").":".date("i").":".date("s");
echo "<b>Example 2: Using the $ time on your site.</b><br>";
echo "Current time: $time";

echo "<br><br>";

//Example 2: if you wan't time on your web site you can use this.
//Course you know you can change the style of the time.
//Just ajust the  $time = date("H").":".date("i").":".date("s");
echo "<b>Example 2: Using the $ time on your site.</b><br>";
echo "Current time: $time";


?>




Guys look at the post down....WHO on earth turns HTML ON? look what sort of things you can do when html is on Smile

Author:  Amailer [ Wed Jun 25, 2003 11:42 pm ]
Post subject: 

Guys...why did you turn HTML ON!?
err look what CAN happne with html on :

Mod Edit: Thanks for that whonderfull Demo of what not to do Twisted Evil

Author:  Dan [ Thu Jun 26, 2003 12:09 am ]
Post subject: 

well i have it on b/c i turst poleop for now, if poelop abuse it they lose it. (like the rime?).

it helps with other stuff but it is easy enfogth for now to stop any one who trys to do dum things.

Author:  Amailer [ Thu Jun 26, 2003 1:47 am ]
Post subject: 

hey i was going to take it out but...thx Smile

Anyway..

Author:  Amailer [ Thu Jun 26, 2003 9:11 pm ]
Post subject: 

Finaly! i have STARTED putting the forum [[[ of amailers ]] on the main sites layout! WOO! took some time, i had to change my whole sites code Sad sad but oh well. The links ont he forums layout are not done, so hehe Smile Ill finish them

Author:  Amailer [ Sun Jun 29, 2003 1:55 am ]
Post subject: 

Mods/Admins etc, you see when you click a forum you will see on top:
Moderators: None
and soemthign else...

Can you like make it display who the mod is for which forum...insted of only whent he mod comes on it tells us?


: