Skip to page content or Skip to Accesskey List.

Work

Main Page Content

Php Super Widget

Rated 3.89 (Ratings: 0)

Want more?

  • More articles in Code
 

Adrian Kearns

Member info

User since: 20 Mar 2000

Articles written: 1

The Super Widget is a crawler that will can return useful info including <Meta> tags where present or read and output a selectable amount of bytes from the files it can open.

It was home built using PHP Version 4.0.2, on a win95 box running Apache 1.3.11 (Win32 Binary).

It should be fairy easy for you to add your own tweeks even if your a php beginner (like me).

Plans are also afoot to build an ASP / VB script version.

Here's the code. save it as 'super_widget.php'.

==================================

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0Transitional//EN"

"http://www.w3.org/TR/REC-html40/loose.dtd">

<html><head>

<title>Super Widget</title>

<META name="description" content="Super Widget - Version: Php 1.0">

<META name="Author" content="abk@webscape.co.nz">

<!--

This little widget is free for non commercial use.

Please don't try and sell it to make money or it will automatically crash your server.

Enjoy :)

-->

<style type="text/css"><!--

body { font-size: 100%; margin: 3em; }

h4 { font-family: verdana,helvetica,arial,sans-serif; }

p,ul,ol,li,form,input { font-size: 90%; font-family: verdana,helvetica,arial,sans-serif; }

td { background-color: #ddeeff; }

ul,ol,li { color: #ff9933; }

span { color: #999999; }

.asp { color: #0000ff; }

.css { color: #ff66cc; }

.htm { color: #cc00ff; }

.tml { color: #cc0099; }

.stm { color: #cc0033; }

.txt { color: #ff0000; }

.php { color: #0099ff; }

.meta { color: #000000; background-color: #ffeeee; }

.byte { color: #000000; background-color: #eeeeff; }

:link { color: #3366dd; text-decoration: none; }

v:link { color: #3366dd; text-decoration: none; }

a:link { color: #3366dd; text-decoration: none; }

a:visited { color: #3366dd; text-decoration: none; }

a:active { color: #3366dd; text-decoration: none; }

a:hover { color: #3366dd; }

--></style>

</head>

<body>

<h4 align="center"><b>S U P E R   W I D G E T</b></h4>

<?

if ($todo == "")

{

?>

<form action="super_widget.php" method="post">

<input type="hidden" name="todo" value="doit">

<table width="90%" border="0" align="center" cellspacing="0" cellpadding="3">

<tr><td align="right" valign="top"><p><b>Search Root: </b></p></td><td valign="top"><input type="text" name="root_arg" value="" size="20"></td></tr>

<tr><td align="right" valign="top"><p><b>Extra Info: </b></p></td><td valign="top"><select name="process">

<option value="None">None</option>

<option value="Meta Tags">Meta tags</option>

<option value="Output Bytes">Output Bytes</option>

</select></td></tr>

<tr><td align="right" valign="top"><p><b>Number of bytes to output: </b></p></td><td valign="top"><select name="my_length">

<option value="10">10</option>

<option value="50">50</option>

<option value="100">100</option>

<option value="200">200</option>

<option value="500">500</option>

<option value="1000">1000</option>

<option value="3000">3000</option>

</select></td></tr>

<tr><td align="right" valign="top"> </td><td valign="top"> <input type="submit" value="Go!"></td></tr>

</table></form>

<?

}

else

{

//================================================

//echo "<ol>";

function file_widget ($file_name)

{

global $root_arg, $process, $my_length;

$extn = substr($file_name, -3, 3);

if (($extn == "asp") or ($extn == "css") or ($extn == "htm") or ($extn == "tml") or ($extn == "stm") or ($extn == "txt") or ($extn == "php"))

{

echo "<li><span class='" . $extn . "'>" . $file_name . "</span>

";

if ($process == "None")

{

echo "</li>";

}

elseif ($process == "Meta Tags")

{

$meta_info = get_meta_tags($file_name);

foreach($meta_info as $k => $v)

{

echo "<br><span class='meta'>[ " . $k . " ][ " . $v . " ]</span></li>";

}

//$meta_info = "";

}

elseif ($process == "Output Bytes")

{

$fd = fopen( $file_name, "r" );

// Outputs the whole file

//$contents = fread ($fd, filesize ($file_name));

// length in bytes to read.

$contents = fread ($fd, ($my_length));

$contents = strtr($contents, "<", "[");

$contents = strtr($contents, ">", "]");

echo "<br><span class='byte'>" . $contents . "</span></li>

";

fclose( $fd );

}

}

else

{

echo "<li><span>" . $file_name . "</span></li>

";

}

}

//================================================

function general_widget ($dir_arg)

{

global $root_arg, $process, $my_length, $extn;

if (is_file($dir_arg) == TRUE)

{

//i am a file

}

else

{

$handle=opendir($dir_arg);

//echo $root_arg . "\<br>";

echo "<ol>

";

while ($file = readdir($handle))

{

if ($file == ".")

{

//echo "<a href='$file'><b>Root</b></a><br>

";

}

elseif ($file == "..")

{

//echo "<a href='$file'><b>Up One Level</b></a><br>

";

}

else

{

if (is_file($file) == TRUE)

{

echo file_widget ($file);

}

else

{

$woo = $dir_arg . chr(47) . $file;

echo file_widget ($woo);

echo general_widget ($woo);

}

}

}

echo "</ol>

";

closedir($handle);

}

}

//================================================

?>

<form action="super_widget.php" method="post">

<input type="hidden" name="todo" value="doit">

<table width="90%" border="0" align="center" cellspacing="0" cellpadding="3">

<tr><td align="right" valign="top"><p><b>Search Root: </b></p></td><td valign="top"><input type="text" name="root_arg" value="<? echo $root_arg; ?>" size="20"></td></tr>

<tr><td align="right" valign="top"><p><b>Extra Info: </b></p></td><td valign="top"><select name="process">

<option selected value="<? echo $process; ?>"><? echo $process; ?></option>

<option value="None">None</option>

<option value="Meta Tags">Meta Tags</option>

<option value="Output Bytes">Output Bytes</option>

</select></td></tr>

<tr><td align="right" valign="top"><p><b>Number of bytes to output: </b></p></td><td valign="top"><select name="my_length">

<option selected value="<? echo $my_length; ?>"><? echo $my_length; ?></option>

<option value="10">10</option>

<option value="50">50</option>

<option value="100">100</option>

<option value="200">200</option>

<option value="500">500</option>

<option value="1000">1000</option>

<option value="3000">3000</option>

</select></td></tr>

<tr><td align="right" valign="top"> </td><td valign="top"> <input type="submit" value="Go!"></td></tr>

</table></form>

<?

//define the root dir for the general_widget() and execute

general_widget ($root_arg);

echo "<p align='center'><b>--- Complete ---</b></p>";

//================================================

}

?>

<!-- end content -->

Super Widget - Version: Php 1.0

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.org Evolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.