[PHP] mIRC Identifier Library : mIRC.lib.php

By ProIcons on Nov 18, 2012

[size=20]mIRC Identifier Library - Still Beta.[/size]
This library contains the most of usable [out of mIRC and IRC Connection] identifiers.
All the Identifiers has the same Syntax with mIRC's Syntax.

Functions $ord,$pos,$time,$date,$count,$file,$sha1 Have been replaced with
m+function_name.
Example mord(); , mpos().. and etc... Because they were already predeclared from PHP itself

Also you have the Option to use some of the function that don't need arguments, as variables.
you have to DEFINE before include, "mIRC_FUNC_TO_VARS" .

an example usage of this system.

<?php
define("mIRC_FUNC_TO_VARS","1");
include("mIRC.lib.php");
echo $time();
?>

With Result:

12:58:45

There were some functions i did Get Ready from Other Users such as:

scanFileNameRecursivly That is Used for $findfile, and $finddir
Refered From http://www.php.net/manual/en/function.scandir.php#108229

matchtok That is used for $matchtok
Refered by ^Neptune from http://www.hawkee.com/snippet/6998/ [With Delimeter Modification]

gettok That is used for $gettok
Refered By sunslayer From http://www.hawkee.com/snippet/6998/#comment_64071

Also disk(); Function Fully working on Windows, but in *nix Systems is working only Free and Total Space.

They way to retrieve .props from the function constructed with Objects.
Example: $disk(C:).size to disk("C:\")->size;

Also on file(); Function .attr working only for Windows Systems.
shortfn(); and longfn(); working aswell only on windows systems

Functions: disk(); file(); shortfn(); longfn(); uptime(); Are Working with Com Objects.
uptime() is also working on *nix Machines.

For ip() function there is a $self option.
if option set to 1 function return's Server name. if not returns Client's name.

For os() function there is a $client option.
if option not set , returns server's os else returns client's os

There have been made aswell some tweaks to duration() function.
Instead of returning wks,hrs and etc.. is retuning Weeks Hours etc...
Example

echo duration(100000000);
//echo $duration(100000000)

3 Years 1 Month 4 Weeks 1 Day 9 Hours 46 Minutes 40 Seconds
165wks 2days 9hrs 46mins 40secs

But there is an option duration($number,$old);
if $old is set, the duration returns the default value of mIRC's duration.

Description about: readini(), ini() : http://www.hawkee.com/snippet/9717/

Function List:

    function asc($chr)
    function islower($text)
    function isupper($text)
    function left($text,$p)
    function right($text,$p)
    function len($text)
    function longip($text)
    function lower($text)
    function upper($text)
    function mid($text,$s,$n)
    function cr()
    function crlf()
    function ip($self=0)
    function serverip()
    function version()
    function os($client=0)
    function mord($text)
    function mpos($text,$s,$o = NULL)
    function mtime($data=NULL)
    function mdate($data=NULL)
    function mcount()
    function qt($text)
    function noqt($text)
    function replace()
    function replacex()
    function remove()
    function str($text,$l)
    function ctime($text=NULL)
    function day()
    function daylight()
    function gmt()
    function timezone()
    function asctime($n,$format=NULL)
    function int($data)
    function duration($text,$old=NULL)
    function bytes($n,$options)
    function ini($file,$n,$n2 = NULL)
    function readini($file,$section,$value)
    function read($file,$p,$m=NULL,$n=NULL)
    function base($num,$in,$out)
    function nofile($file)
    function nopath($file)
    function lines($file)
    function isdir($file)
    function isfile($file)
    function findfile($path,$name,$n)
    function uptime()
    function finddir($path,$name,$n)
    function exists($file)
    function shortfn($files)
    function longfn($files)
    function mfile($file)
    function disk($disk)
    function lasttok($string, $c)
    function firsttok($string, $c)
    function numtok($string, $c)
    function sorttok($string, $opt, $c)
    function addtok($string, $add, $c)
    function remtok($string, $del, $n, $c)
    function matchtok($text, $search, $returnmatch=1,$c=32)
    function deltok($string, $n, $c)
    function istok($string, $word, $c)
    function puttok($string, $word, $n, $c)
    function randtok($string, $c)
    function instok($string, $word, $n, $c)
    function findtok($string,$word,$n,$c)
    function reptok($string,$del,$add,$n,$c=NULL)
    function wildtok($string,$text,$n,$c)
    function msha1($input)
    function port()
    function url()
    function gettok($string,$n,$c)
    function crc($file)

[size=23]Update #1[/size]
-Fixed issues that the $time,$ctime and general all the non-static variables were staying static in the execution of script.
-Feature: now all functions can be used with mIRC style dollar symbol.$.
But Still functions with no parameters needs the opening and closing brackets (). except from: $cr,$crlf,$os,$osclient,$version,$serverip,$ip,$ipclient,$day,$url,$port,$timezone

Also in the default , predeclared functions of php that were the same with mIRC added the $ symbol. $chr() $floor() and so on...

Also new Function Added: $strip

Function can be used with $ symbol:

$asc
$islower
$isupper
$left
$right
$len
$longip
$lower
$upper
$mid
$version
$ord
$pos
$time
$date
$count
$qt
$noqt
$replace
$replacex
$remove
$str
$ctime
$asctime
$int
$duration
$bytes
$ini
$readini
$read
$base
$nofile
$nopath
$lines
$isdir
$isfile
$findfile
$uptime
$finddir
$exists
$shortfn
$longfn
$file
$disk
$lasttok
$firsttok
$numtok
$sorttok
$addtok
$remtok
$matchtok
$deltok
$istok
$puttok
$randtok
$instok
$findtok
$reptok
$wildtok
$sha1
$gettok
$crc
$chr
$floor
$ceil
$cos
$acos
$sqrt
$sin
$asin
$round
$rand
$abs
$tan
$atan
$md5
$null
<?php
/***************************************/
/*     mIRC Library Experimental v1     /
/*   Coded By Nikolas.M aka ProIcons    /
/***************************************/
    if (defined("mIRC_FUNC_TO_VARS")) {
        global $cr,$crlf,$os,$osclient,$version,$serverip,$ip,$ipclient,$url,$port,$timezone;
        $cr=cr();$crlf=crlf();$os=os();$osclient=os(1);$version=version();$serverip=serverip();$ip=ip();$ipclient=ip(1);$day=day();$daylight=daylight();$gmt=gmt();$url=url();$port=port();$timezone=timezone();
    }
    $asc='asc';$islower='islower';$isupper='isupper';$left='left';$right='right';$len='len';$longip='longip';$lower='lower';$upper='upper';$mid='mid';$version='version';$ord='mord';$pos='mpos';$time='mtime';$date='mdate';$count='mcount';$qt='qt';$noqt='noqt';$replace='replace';$replacex='replacex';$remove='remove';$str='str';$ctime='ctime';$asctime='asctime';$int='int';$duration='duration';$bytes='bytes';$ini='ini';$readini='readini';$read='read';$base='base';$nofile='nofile';$nopath='nopath';$lines='lines';$isdir='isdir';$isfile='isfile';$findfile='findfile';$uptime='uptime';$finddir='finddir';$exists='exists';$shortfn='shortfn';$longfn='longfn';$file='mfile';$disk='disk';$lasttok='lasttok';$firsttok='firsttok';$numtok='numtok';$sorttok='sorttok';$addtok='addtok';$remtok='remtok';$matchtok='matchtok';$deltok='deltok';$istok='istok';$puttok='puttok';$randtok='randtok';$instok='instok';$findtok='findtok';$reptok='reptok';$wildtok='wildtok';$sha1='msha1';$gettok='gettok';$crc='crc';
    //Built in PHP Functions
    $chr='chr';$floor='floor';$ceil='ceil';$cos='cos';$acos='acos';$sqrt='sqrt';$sin='sin';$asin='asin';$round='round';$rand='rand';$abs='abs';$tan='tan';$atan='atan';$md5='md5';$null=NULL;

    function strip($text) { return trim($text); }
    function asc($chr) { return ord($chr); }
    function islower($text) {
        if ($text === strtolower($text)) { return true; }
        else { return false; }
    }
    function isupper($text) {
        if ($text == strtoupper($text)) { return true; }
        else {return false; }
    }
    function left($text,$p) { if ($p!=0) return mid($text,1,$p); }
    function right($text,$p) { return mid($text,len($text) - ($p-1),len($text)); }
    function len($text) { return strlen($text); }
    function longip($text) { return ip2long($text); }
    function lower($text) { return strtolower($text); }
    function upper($text) { return strtoupper($text); }
    function mid($text,$s,$n) { return substr($text,($s-1),$n); }
    function cr() { return chr(13); }
    function crlf() { return chr(13); }

    function ip($self=0) { 
        if ($self=0) {return $_SERVER_ADDR['REMOTE_ADDR'];}
        else {return $_SERVER_ADDR['SERVER_ADDR'];}

    }
    function serverip() { return $_SERVER_ADDR['SERVER_ADDR'];}
    function version() { return phpversion(); }
    function os($client=0) {
        if ($client=0) {return php_uname('s');}
        else {
            $OSList = array
            (
                    'Windows 3.11' => 'Win16',
                    'Windows 95' => '(Windows 95)|(Win95)|(Windows_95)',
                    'Windows 98' => '(Windows 98)|(Win98)',
                    'Windows 2000' => '(Windows NT 5.0)|(Windows 2000)',
                    'Windows XP' => '(Windows NT 5.1)|(Windows XP)',
                    'Windows Server 2003' => '(Windows NT 5.2)',
                    'Windows Vista' => '(Windows NT 6.0)',
                    'Windows 7' => '(Windows NT 7.0)',
                    'Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
                    'Windows ME' => 'Windows ME',
                    'Open BSD' => 'OpenBSD',
                    'Sun OS' => 'SunOS',
                    'Linux' => '(Linux)|(X11)',
                    'Mac OS' => '(Mac_PowerPC)|(Macintosh)',
                    'QNX' => 'QNX',
                    'BeOS' => 'BeOS',
                    'OS/2' => 'OS/2',
                    'Search Bot'=>'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)'
            );

            foreach($OSList as $CurrOS=>$Match){
                    if (eregi($Match, $_SERVER['HTTP_USER_AGENT'])){break;}
            }
            return $CurrOS;
        }
    }
    function mord($text) {
        if (is_numeric($text)) { switch($text) { case 1:return "1st";break; case 2:return "2nd";break; case 3:return "3rd";break; default:return $text."th";break; } }
    }
    function mpos($text,$s,$o = NULL) {
        $c=0;
        for ($i=1;$i<=strlen($text);$i++) {
            if ($s==mid($text,$i,1)) {
                if ($o==NULL && $o<>0) { return $i; }
                $c++;
                if ($c==$o) { return $i; }
            }
        }
        if ($o == 0) { return $i; }
    }
    function mtime($data=NULL) {
        $data=replacex($data,"yyyy","Y","yy","y","mmmm","F","mmm","M","mm","m","m","n","d","j","dd","d","ddd","D","dddd","l","hh","h","h","g","HH","H","H","G","nn","i","n","i","ss","s","tt","a","t","a","TT","A","zz","O","zzz","O e");
        if ($data == NULL) {
            return date("H:i:s");
        }
        return date($data);
    }
    function mdate($data=NULL) {
        $data=replacex($data,"yyyy","Y","yy","y","mmmm","F","mmm","M","mm","m","m","n","d","j","dd","d","ddd","D","dddd","l","hh","h","h","g","HH","H","H","G","nn","i","n","i","ss","s","tt","a","t","a","TT","A","zz","O","zzz","O e");
        if ($data == NULL) {
            return date("d/m/Y");
        }
        return date($data);
    }
    function mcount() { 
        $args=func_num_args();
        $arglist = func_get_args();
        $text=$arglist[0];
        for ($i =1;$i<=($args-1);$i+=2) {
            $num+=substr_count($text, $arglist[$i]);
        }
        return $num;
    }
    function qt($text) {
        if (left($text,1) != "\"") { $text="\"".$text; }
        if (right($text,1) != "\"") { $text=$text."\""; }
        return $text;
    }
    function noqt($text) {
        if (left($text,1) == "\"") { $text=mid($text,2,(len($text) -1)); }
        if (right($text,1) == "\"") { $text=mid($text,1,(len($text) -1)); }
        return $text;
    }
    function replace() {
        $args=func_num_args();
        $arglist = func_get_args();
        $text=$arglist[0];
        if ((($args-1) % 2) == 0) {
            for ($i =1;$i<=($args-1);$i+=2) {
                $text=str_replace($arglist[$i],$arglist[$i+1],$text);
            }
        }
        return $text;
    }
    function replacex() {
        $args=func_num_args();
        $arglist = func_get_args();
        $text=$arglist[0];
        if ((($args-1) % 2) == 0) {
            for ($i=($args-1);$i>=1;$i-=2) {
                $text=str_replace($arglist[$i-1],$arglist[$i],$text);
            }
        }
        return $text;
    }
    function remove() {
        $args=func_num_args();
        $arglist = func_get_args();
        $text=$arglist[0];
        if ((($args-1) > 0)) {
            for ($i =1;$i<=($args-1);$i++) {
                $text=replace($text,$arglist[$i],"");
            }
        }
        return $text;
    }
    function str($text,$l) {
        for ($i=1;$i<=($l-1);$i++) {
            $text=$text.$text;
        }
        return $text;
    }

    function ctime($text=NULL) {
        return mktime($text);
    }
    function day() {
        return date("l");
    }
    function daylight() {
        return date("I");
    }
    function gmt() {
        return gmmktime();
    }

    function timezone() { return date("Z"); }
    function asctime($n,$format=NULL) {
        function parse_time($data) {
            $data=replacex($data,"yyyy","Y","yy","y","mmmm","F","mmm","M","mm","m","m","n","d","j","dd","d","ddd","D","dddd","l","hh","h","h","g","HH","H","H","G","nn","i","n","i","ss","s","tt","a","t","a","TT","A","zz","O","zzz","O e");
            return $data;
        }
        if ($format != NULL) {
            return date(parse_time($format),$n);
        }
        else {
            if (is_numeric($n)) {
                return date("D M d H:i:s Y",$n);
            }
            else { return date(parse_time($n)); }
        }
    }
    function int($data) { return (int)$data; }
    function duration($text,$old=NULL) {
        switch (date("L")) {
            case 1:
                $days=366;
                break;
            case 0:
                $days=365;
                break;
        }
        if ($text/(60*60*24*$days) >= 1) {
            $years=int($text/(60*60*24*$days));
            if($old==1){if($years>1){$s="yrs";}else{$s="yr";}$years=$years."$s";}
            elseif($old==NULL){if($years>1){$s="Years";}else{$s="Year";}$years=$years." $s";}
            $text=$text%(60*60*24*$days*$years);
        }
        if ($text/(60*60*24*30) >= 1) {
            $months=int($text/(60*60*24*31));
            if($old==1){if($months>1){$s="mnts";}else{$s="mnt";}$months=$months."$s";}
            elseif($old==NULL){if($months>1){$s="Months";}else{$s="Month";}$months=$months." $s";}
            $text=$text%(60*60*24*30*$months);
        }
        if ($text/(60*60*24*7) >= 1) {
            $weeks=int($text/(60*60*24*7));
            if($old==1){if($weeks>1){$s="wks";}else{$s="wk";}$weeks=$weeks."$s";}
            elseif($old==NULL){if($weeks>1){$s="Weeks";}else{$s="Week";}$weeks=$weeks." $s";}
            $text=$text%(60*60*24*7);
        }
        if ($text/(60*60*24) >= 1) {
            $day=int($text/(60*60*24));
            if($old==1){if($day>1){$s="days";}else{$s="day";}$day=$day."$s";}
            elseif($old==NULL){if($day>1){$s="Days";}else{$s="Day";}$day=$day." $s";}
            $text=$text%(60*60*24);
        }
        if ($text/(60*60) >= 1) {
            $hours=int($text/(60*60));
            if($old==1){if($hours>1){$s="hrs";}else{$s="hr";}$hours=$hours."$s";}
            elseif($old==NULL){if($hours>1){$s="Hours";}else{$s="Hour";}$hours=$hours." $s";}
            $text=$text%(60*60);
        }
        if ($text/60 >= 1) {
            $mins=int($text/60);
            if($old==1){if($mins>1){$s="mins";}else{$s="min";}$mins=$mins."$s";}
            elseif($old==NULL){if($mins>1){$s="Minutes";}else{$s="Minute";}$mins=$mins." $s";}
            $text=$text%(60);
        }
        if ($text > 0) {
            $secs=$text;
            if($old==1){if($secs>1){$s="secs";}else{$s="sec";}$secs=$secs."$s";}
            elseif($old==NULL){if($secs>1){$s="Seconds";}else{$s="Second";}$secs=$secs." $s";}
        }
        return "$years $months $weeks $day $hours $mins $secs";
    }
    function bytes($n,$options) {
        $size=$n;
        switch ($options) {
            case "k":$c=1;$t="KB";break;
            case "m":$c=2;$t="MB";break;
            case "g":$c=3;$t="GB";break;
            case "t";$c=4;$t="TB";break;
        }
        for ($i=1;$i<=$c;$i++) { $size=$size/1024; }
        return round($size,2).$t;
    }

    function ini($file,$n,$n2 = NULL){
        $counter2=0;$counter=0;
        $handle = @fopen($file, "r"); 
        $contents = @fread($handle, filesize($file));
        if (!$handle || !$contents) return false; 
        $contents = split("\n", trim($contents)); 
        foreach ($contents as $k => $v) {
            if ((substr(trim($v), 0, 1) != ";") && (substr(trim($v), 0, 1) != "#")) {
                if (substr(trim($v), 0, 1) == "[") {
                    $counter++;
                    $head=substr(trim($v), 1, -1);
                    if (is_numeric($n) && !$n2) {
                        if ($counter == $n && $n != 0) {
                            return $head; 
                        }
                    }
                    else {
                        if ($head == $n && ($n2 == NULL && $n2<>0)) {
                            return $counter;
                        }
                    }
                } 
                elseif ((trim($v) <> "") and (substr($v, 0, 1) <> "#") and ($head == $n)) {
                    if ($n2 >= 0 && !is_numeric($n)) {
                        $counter2++;
                        $tmp = explode("=", $v);
                        if ($counter2 == $n2) {
                            return $tmp[0];
                        }
                    }
                }
            }
        }
        if ($n2<=0 && !is_numeric($n)) { return $counter2; }
        if ($n == 0 && !$n2) {
            return $counter;
        }
    }
    function readini($file,$section,$value) {
        $counter;
        $head;
        $handle = @fopen($file, "r"); 
        $contents = @fread($handle, filesize($file)); 
        if (!$handle || !$contents) return false;
        $contents = split("\n", trim($contents)); 
        foreach ($contents as $k => $v) {
            if ((substr(trim($v), 0, 1) != ";") && (substr(trim($v), 0, 1) != "#")) {
                if (substr(trim($v), 0, 1) == "[") {
                    $counter++;
                    $head=substr(trim($v), 1, -1);
                } 
                elseif ((trim($v) <> "") and (substr($v, 0, 1) <> "#")) { 
                    $tmp = explode("=", $v);
                    if ($value==trim($tmp[0]) && $section == $head) {
                        return trim($tmp[1]);
                    }
                } 
            }
        }
        @fclose($handle); 
    }

    function read($file,$p,$m=NULL,$n=NULL) {
        //$handle=file_get_contents($file);
        //$contents = split("\n", trim($handle));
        $handle = @fopen($file, "r");
        $m=left($m,1).replace(mid($m,2,len($m)-2),"*",").*?(").right($m,1);
        if (left($m,1) == "*") { 
            $m=".*?(".mid($m,2,len($m-1));
        }
        else {
            $m=".*?(".$m;
        }
        if (right($m,1) == "*") {
            $m=mid($m,1,len($m)-1).").*?";
        }
        else {
            $m=$m.").*?";
        }
        $k=0;
        while(!@feof($handle)){
            $k++;
            $v = @fgets($handle);
            if (lower($p) == "w") {
                if (preg_match_all("/".$m."/is",$v,$matches)) {
                    if ($n == NULL) { $n=0; }
                    if ($k == ($n)) {
                        return $v;
                        exit();
                    }
                }
            }
            elseif (lower($p) == "s") {
                if (preg_match($m,$handle,$matches)) {
                    if ($n == NULL) { $n=0; }
                    return $v;
                }
            }
            elseif (($p-1) == $k) { return $v; }
        }
        @fclose($handle);
        /*foreach ($contents as $k => $v) {
            if (lower($p) == "w") {
                if (preg_match_all("/".$m."/is",$v,$matches)) {
                    if ($n == NULL) { $n=0; }
                    if ($k == ($n-1)) {
                        return $v;
                        exit();
                    }
                }
            }
            elseif (lower($p) == "s") {
                if (preg_match($m,$handle,$matches)) {
                    if ($n == NULL) { $n=0; }
                    return $v;
                }
            }
            elseif (($p-1) == $k) { return $v; }
        }*/
    }
    function base($num,$in,$out) {
        return base_convert($num,$in,$out);
    }
    function nofile($file) {
        $file = @pathinfo($file);
        return $file['dirname'];

    }
    function nopath($file) {
        $file = @pathinfo($file);
        return $file['basename'];
    }
    function lines($file) {
        $linecount = 0;
        $handle = fopen($file, "r");
        while(!feof($handle)){
          $line = fgets($handle);
          $linecount++;
        }
        fclose($handle);
        return $linecount;
    }
    function isdir($file) { return is_dir($file); }
    function isfile($file) { return is_file($file); }
    //Refered From http://www.php.net/manual/en/function.scandir.php#108229
    function scanFileNameRecursivly($path = '', &$name = array() )
    {
      $path = $path == ''? dirname(__FILE__) : $path;
      $lists = @scandir($path);

      if(!empty($lists))
      {
          foreach($lists as $f)
          {

          if(is_dir($path.DIRECTORY_SEPARATOR.$f) && $f != ".." && $f != ".")
          {
              scanFileNameRecursivly($path.DIRECTORY_SEPARATOR.$f, &$name);
          }
          else
          {
              $name[] = $path.DIRECTORY_SEPARATOR.$f;
          }
          }
      }
      return $name;
    }

    function findfile($path,$name,$n) {
        $files=scanFileNameRecursivly($path);
        $m=$name;
        if (strpos($m,"*")) { $mode='wild'; }
        else { $mode='plain'; }
        if ($mode == 'wild') {
            $m=left($m,1).replace(mid($m,2,len($m)-2),"*",").*?(").right($m,1);
            if (left($m,1) == "*") { 
                $m=".*?(".mid($m,2,len($m-1));
            }
            else {
                $m=".*?(".$m;
            }
            if (right($m,1) == "*") {
                $m=mid($m,1,len($m)-1).".*?).*?";
            }
            else {
                $m=$m.").*?";
            }
            foreach ($files as $k => $v) {
                if (isfile($v)) {
                    if (preg_match_all("/".$m."/is",$v,$matches)) {
                        $z++;
                        if ($z == $n) {
                            return $v;
                            exit();
                        }
                    }
                }
            }
            if ($n==0) { return $z; }
        }
        else { 
            foreach ($files as $k => $v) {
                if (isfile($v)) {
                    if (trim(basename($v)) == $m) {
                        $z++;
                        if ($z==$n) {
                            return $v;
                            exit();
                        }
                    }
                }
            }
            if ($n==0) { return $z; }
        }
    }
    function uptime() {
        if (class_exists("COM")) {
            $wmi = new COM("winmgmts://localhost/root/CIMV2");
            $uptime = 0;
            $systems = $wmi->InstancesOf("Win32_PerfRawData_PerfOS_System");
            foreach ($systems as $system) {
                $PerfTimeStamp = $system->Timestamp_Object ;
                $PerfTimeFreq = $system->Frequency_Object ;
                $Counter = $system->SystemUpTime ;
                $UptimeInSec = ($PerfTimeStamp - $Counter)/$PerfTimeFreq ;
                $uptime = max($uptime, $UptimeInSec);

            }
            return round($uptime*1000);
        }
        else {
            if (ini_get('disable_functions')) {
                $disabled_funcs=array_map('trim',explode(',',ini_get('disable_functions')));
            }
            if (in_array('shell_exec',$disabled_funcs) && in_array('exec',$disabled_funcs)) {
                $uptime_text=file_get_contents("/proc/uptime");
                $uptime=substr($uptime_text,0,strpos($uptime_text," "))*1000;
                return $uptime;
            }
            else {
                if (in_array('shell_exec',$disabled_funcs) && (!in_array('exec',$disabled_funcs))) {
                    $uptime=exec("awk '{print $1*1000}' /proc/uptime");
                    return $uptime;
                }
                if (in_array('exec',$disabled_funcs) && !in_array('shell_exec',$disabled_funcs)) {
                    $uptime=shell_exec("awk '{print $1*1000}' /proc/uptime");
                    return $uptime;
                }
            }
        }
    }
    function finddir($path,$name,$n) {
        $files=scanFileNameRecursivly($path);
        $m=$name;
        if (strpos($m,"*")) { $mode='wild'; }
        else { $mode='plain'; }
        if ($mode == 'wild') {
            $m=left($m,1).replace(mid($m,2,len($m)-2),"*",").*?(").right($m,1);
            if (left($m,1) == "*") { 
                $m=".*?(".mid($m,2,len($m-1));
            }
            else {
                $m=".*?(".$m;
            }
            if (right($m,1) == "*") {
                $m=mid($m,1,len($m)-1).".*?).*?";
            }
            else {
                $m=$m.").*?";
            }
            foreach ($files as $k => $v) {
                $path=pathinfo($v);
                $v=$path['dirname'];
                if (isdir($v)) {
                    if (preg_match_all("/".$m."/is",$v,$matches)) {
                        if (!$found[$v]) {
                            $z++;
                            $found[$v]=1;
                            if ($z == $n) {

                                return $v;
                                exit();
                            }
                        }
                    }
                }
            }
            if ($n==0) { return $z; }
        }
        else { 
            foreach ($files as $k => $v) {
                $path=pathinfo($v);
                $v=$path['dirname'];
                if (isdir($v)) {
                    if (trim(basename($v)) == $m) {
                        if (!$found[$v]) {
                            $z++;
                            $found[$v]=1;
                            if ($z==$n) {
                                return $v;
                                exit();
                            }
                        }
                    }
                }
            }
            if ($n==0) { return $z; }
        }
    }
    function exists($file) { return file_exists($file); }
    function shortfn($files) {
        $obj=new COM("Scripting.FileSystemObject");
        if (isfile($files)) {
            $file = $obj->GetFile($files);
        }
        elseif (isdir($files)) {
            $file = $obj->GetFolder($files);
        }
        return $file->ShortPath;
    }
    function longfn($files) {
        $obj=new COM("Scripting.FileSystemObject");
        $obj2=new COM("Shell.Application");
        if (isfile($files)) {
            $file = $obj->GetFile($files);
            $fileparent=$file->ParentFolder;
            $foj = $obj2->Namespace($fileparent->Path);
            $foi = $foj->ParseName($file->Name);
        }
        elseif (isdir($files)) {
            $file = $obj->GetFolder($files);
            $fileparent=$file->ParentFolder;
            $foj = $obj2->Namespace($fileparent->Path);
            $foi = $foj->ParseName($file->Name);
        }
        return $foi->Path;
    }
    function mfile($file) {
        $hfile=stat($file);
        $mfile = array();
        $mfile['atime']=$hfile['atime'];
        $mfile['ctime']=$hfile['ctime'];
        $mfile['mtime']=$hfile['mtime'];
        $mfile['size']=$hfile['size'];
        $obj=new COM("Scripting.FileSystemObject");
        $file = $obj->GetFile($file);
        $attr=$file->Attributes;
        if ($attr == 0) {
            $flag="x";
        }
        if ($attr >= 2048) {
            $flag.="c";
            $attr-=2048;
        }
        if ($attr >= 64) {
            $flag.="";
            $attr-=64;
        }
        if ($attr >= 32) {
            $flag.="a";
            $attr-=32;
        }
        if ($attr >= 16) {
            $flag.="d";
            $attr-=16;
        }
        if ($attr >= 8) {
            $flag.="";
            $attr-=8;
        }
        if ($attr >= 4) {
            $flag.="s";
            $attr-=4;
        }
        if ($attr >= 2) {
            $flag.="h";
            $attr-=2;
        }
        if ($attr >= 1) {
            $flag.="r";
            $attr-=1;
        }
        $mfile['attr']=$flag;
        $mfile['longfn']=longfn($file);
        $mfile['shortfn']=shortfn($file);
        return (object)$mfile;
    }
    function disk($disk) {
        if (class_exists("COM")) {
            $obj=new COM("Scripting.FileSystemObject");
            $disk=@$obj->GetDrive($disk);
            switch ($disk->DriveType) {
                case 0:$dt="Unknown";break;
                case 1:$dt="Removable";break;
                case 2:$dt="Fixed";break;
                case 3:$dt="Network";break;
                case 4:$dt="CD-ROM";break;
                case 5:$dt="RAM Disk";break; 
            }

            $dsk["type"]=$dt;
            $dsk["label"]=$disk->VolumeName;
            $dsk["path"]=$disk->Path;
            $dsk['unc']=$disk->ShareName;
            $dsk['free']=$disk->FreeSpace;
            $dsk['total']=$disk->TotalSize;
            return (object)$dsk;
        }
        else {
            $dsk['free']=disk_free_space($disk);
            $dsk['total']=disk_total_space($disk);
            //$mount=exec("mount|grep ^'/dev'");
        }
    }
    function lasttok($string, $c) {
        $last = explode(chr($c), $string);return $end($last);
    }
    function firsttok($string, $c) {
        $explode = explode(chr($c), $string);return $explode[0];
    }
    function numtok($string, $c) {
        $numa = explode(chr($c), $string);
        return count($numa);
    }
    function sorttok($string, $opt, $c) {
        $text = explode(chr($c), $string);
        if ($f == "r") {
            sort($text, SORT_REGULAR);
            return implode(chr($c), $text);
        }
        if ($f == "n") {
            sort($text, SORT_NUMERIC);
            return implode(chr($c), $text);
        }
    }
    function addtok($string, $add, $c) {
        $text = explode(chr($c), $string);
        foreach ($text as $v) {
            if ($v == $add) {
                $exists = 1;
                break;
            }
        }
        if ($exists) {return implode(chr($c), $text);}
        else {
            $count = count($text)+1;
            $text[$count]=$add;
            return implode(chr($c), $text);
        }
    }
    function remtok($string, $del, $n, $c) {
        $text=explode(chr($c),$string);
        $keys=array_keys($text, $del);
        if ($n>0) {$n--;if (count($keys)>$n) {unset($text[$keys[$n]]);}}
        else {
            foreach ($keys as $key) {unset($text[$key]);}
        }
        return implode(chr($c), $text);
    }
    //Refered by ^Neptune http://www.hawkee.com/snippet/6998/ [With Delimeter Modification]
    function matchtok($text, $search, $returnmatch=1,$c=32) {
        $i = 0;
        $token = strtok($text, chr($c));
        do {
            if(strpos($token, $search) !== FALSE) {
                $i++;
                if($i == $returnmatch) {
                    return $token;
                }
            }
        } 
        while(($token = strtok(chr($c))) !== FALSE);
        return $i;
    }
    function deltok($string, $n, $c) {
        $text = explode(chr($c), $string);unset($text[$n-1]);return implode(chr($c), $text);
    }
    function istok($string, $word, $c) {
        $text = explode(chr($c), $string);foreach ($text as $v) {if ($v == $word) {$exists=1;break;}}if ($exists) {return true;}else {return false;}
    }
    function puttok($string, $word, $n, $c) {
        $text = explode(chr($c), $string);$count=$n-1;return implode(chr($c),array_replace($text, array($count => $word)));
    }
    function randtok($string, $c) {
        return gettok($string,rand(1,numtok($string,$c)),$c);
    }
    function instok($string, $word, $n, $c) {
        $text = explode(chr($c), $string);$start=array_slice($text, 0, $n-1);$end=array_slice($text,$n-1);
        $start[count($start)+1] = $k;$result=array_merge($start, $end);
        return implode(chr($c), $result);
    }
    function findtok($string,$word,$n,$c) {
        $text=explode(chr($c),$string);
        $count=1;
        foreach ($text as $k => $v) {if ($v==$word){ $find[$count]=$k;$count++; }}
        if ($n!=0&&$n<=$count-1){return $find[$n]+1;}
        elseif ($n==0){return $count-1;}
    }
    function reptok($string,$del,$add,$n,$c=NULL) {
        if ($c == NULL) { $c=$n;$n=1; }
        $text=explode(chr($c),$string);
        $count=1;
        foreach ($text as $k => $v) {
            if ($v==$del){
                if($count==$n||$n==0){$text[$k]=$add;}
                $count++;
            }
        }
        return implode(chr($c),$text);
    }
    function wildtok($string,$text,$n,$c) {
        $m=$text;
        $m=left($m,1).replace(mid($m,2,len($m)-2),"*",").*?(").right($m,1);
        if (left($m,1) == "*") { 
            $m=".*?(".mid($m,2,len($m-1));
        }
        else {
            $m="(".$m;
        }
        if (right($m,1) == "*") {
            $m=mid($m,1,len($m)-1).".*?).*?";
        }
        else {
            $m=$m.")";
        }
        $text=explode(chr($c),$string);
        $count=1;
        foreach ($text as $k => $v) {
            if (preg_match("/".$m."/is",$v)) { 
                if ($n==$count&&$n!=0) { return $v; }
                $count++;
            }
        }
        if ($n==0) { return $count-1; }
    }
    function msha1($input) {
        if (isfile($input)) {
            $input=file_get_contents($input);
        }
        return sha1($input);
    }
    function port() {
        return $_SERVER['REMOTE_PORT'];
    }
    function url() {
        $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
        $sp = strtolower($_SERVER["SERVER_PROTOCOL"]);
        $protocol = substr($sp, 0, strpos($sp, "/")) . $s;
        $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
        return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI'];
    }
    //Refered From: sunslayer http://www.hawkee.com/snippet/6998/#comment_64071
    function gettok($string,$n,$c) {
        $num=numtok($string,$c);
        if(is_numeric($c)) $c=chr($c);
        $tok=explode($c,$string);
        if($n==0) return count($tok);
        elseif($n<0) {
            $tok=array_reverse($tok);
            return $tok[lasttok($n+1,45)];
        }
        elseif(preg_match("/(\d+)-(\d+)?/",$n,$range)) {
            $start=$range[1]-1;
            if (!$range[2]) $end=$num;
            else $end=$range[2];
            for (;$start<$end;$start++,$text.=$tok[$start-1].$c);
                return $text;
            }
        else return $tok[$n-1];
    }   
    function crc($file) {
        if (isfile($file)) {
            $string=file_get_contents($file);
        }
        else { $string=$file; }
        return crc32($string);
    }
?>

Comments

Sign in to comment.
Typo   -  Dec 18, 2013

This is pretty cool. I would never use something like this but I like that you took the time to try and do it :) .

ProIcons  -  Jan 21, 2014

For some people using gettok is easier than explode, also mIRC provides BultIN functions for many things. I've recreated these functions in PHP Language in order to help people to NOT RE-INVENT the Wheel. Now some of you may find it useless and its ok from me, I've never used it either in any of my web projects... though many other people find this very usefull. I mean there are bultin functions to interact with ini files, There are functions for each Token Procedure. Gettok Sorttok Wildtok Numtok Istok Instok addtok deltok remtok randtok findtok puttok matchtok firsttok lasttok , There are also the find functions, finddir and findfile
easy read function... any many others

Sign in to comment

ProIcons   -  Nov 22, 2012

I'm not familiar with PITC. Can u provide me more information about it?

 Respond  
TMFKSOFT   -  Nov 22, 2012

ProIcons, You should have a go at converting mIRC scripts to PITC so I can intergrate an MSL Interpeter into my IRC Client XD

 Respond  
ProIcons   -  Nov 19, 2012

Description Also Updated. All Functions are now accessible through $ Symbol like mIRC Style.
Be aware. They Opening and Closing Brackets () are required. Otherwise it will return the function name.

 Respond  
Hawkee   -  Nov 19, 2012

There you go.

 Respond  
ProIcons   -  Nov 19, 2012

Updated. Now Vars are $var(); style.

 Respond  
sean   -  Nov 18, 2012

Yup @Hawkee is right. You'll want to make use of variable functions to pull this off correctly :)

 Respond  
Hawkee   -  Nov 18, 2012

Once you include this file $time will be set to the time that you included the file, but it will not change. So if you check it 5 minutes later it'll still reflect the original time.

 Respond  
ProIcons   -  Nov 18, 2012

Oh if i got it right, it should be fine now..

Edit:
i Made a test

echo $time." ".mtime()." ".date("H:i:s");

Before the fix, so the first value was 3 seconds behind. Now it should be fine.. if that was what you meant.

 Respond  
Hawkee   -  Nov 18, 2012

Wouldn't $time remain static upon loading the library?

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.