Skip to content

Commit

Permalink
Added examples folder and fixed a few issues in phpLive
Browse files Browse the repository at this point in the history
  • Loading branch information
Wild1145 committed Aug 15, 2012
1 parent 314afc2 commit 02272c9
Show file tree
Hide file tree
Showing 30 changed files with 487 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/nbproject/private/
8 changes: 8 additions & 0 deletions examples/construct/each.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
require_once '../../phpLive.php';
$live->list = array(1,2,3,4,5);
echo $live->each(function($k, $v){
return "$v<br />";
})->implode("");
echo "<hr />";
echo $live->highlight("each.php", HIGHLIGHT_PHP, INPUT_FILE);
12 changes: 12 additions & 0 deletions examples/construct/ifelse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
require_once '../../phpLive.php';
$age = mt_rand(0, 3);
echo $live->ifelse($age == 0, function() use ($age){
return "if statement fired! (\$age = $age)";
}, $age == 1, function() use ($age){
return "ifelse statement fired! (\$age = $age)";
}, function() use ($age){
return "else fired! (\$age = $age)";
});
echo "<hr />";
echo $live->highlight("ifelse.php", HIGHLIGHT_PHP, INPUT_FILE);
13 changes: 13 additions & 0 deletions examples/construct/in.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
require_once '../../phpLive.php';
$num = mt_rand(0, 10);

echo "List: 1, 3, 5, 6<br />";

if($live->in($num, 1, 3, 5, 6)){
echo "$num is in the list";
}else{
echo "$num is not in the list";
}
echo "<hr />";
echo $live->highlight("in.php", HIGHLIGHT_PHP, INPUT_FILE);
11 changes: 11 additions & 0 deletions examples/construct/loop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
require_once '../../phpLive.php';
echo "<p>The following will loop 10 times.</p>";

$live->loop(function(){
static $i = 0;
echo "This is : $i<br />";
$i++;
}, 10);
echo "<hr />";
echo $live->highlight("loop.php", HIGHLIGHT_PHP, INPUT_FILE);
14 changes: 14 additions & 0 deletions examples/construct/loop2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
require_once '../../phpLive.php';
echo "type 'exit' to quit.\n";
$live->loop(function() use($live){
$equation = $live->strOut("type a math equation")->strIn()->toString();
if(strtolower($equation) == "exit"){
return true; // End the while loop
}
echo $equation." = ";
eval("echo number_format($equation, 2);");
echo "\n";
});
echo "<hr />";
echo $live->highlight("listen.php", HIGHLIGHT_PHP, INPUT_FILE);
19 changes: 19 additions & 0 deletions examples/datetime/date-add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<form action="" method="post">
<p>
Add: <input type="text" name="date" value="1 day" /> from now.
</p>
<p>
<input type="submit" value="Go!" />
</p>
</form><?php
if(isset($_POST["date"]))
$range = $_POST["date"];
else
$range = "1 day";
require_once "../../phpLive.php";
echo $live->dateAdd(time(), $range);
?>
<p>&nbsp;</p>
<?php
echo "<hr />";
echo $live->highlight("date-add.php", HIGHLIGHT_PHP, INPUT_FILE);
19 changes: 19 additions & 0 deletions examples/datetime/date-sub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<form action="" method="post">
<p>
Subtract: <input type="text" name="date" value="1 day" /> from now.
</p>
<p>
<input type="submit" value="Go!" />
</p>
</form><?php
if(isset($_POST["date"]))
$range = $_POST["date"];
else
$range = "1 day";
require_once "../../phpLive.php";
echo $live->dateSub(time(), $range);
?>
<p>&nbsp;</p>
<?php
echo "<hr />";
echo $live->highlight("date-sub.php", HIGHLIGHT_PHP, INPUT_FILE);
16 changes: 16 additions & 0 deletions examples/datetime/datediff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<form action="" method="post">
<p>
Date 1: <input type="text" name="date1" value="<?php echo date("Y-m-d H:i:s"); ?>" /><br />
Date 2: <input type="text" name="date2" value="<?php echo date("Y-m-d H:i:s"); ?>" />
</p>
<p>
<input type="submit" value="Go!" />
</p>
</form><?php
require_once "../../phpLive.php";
echo $live->datediff($_POST["date1"], $_POST["date2"]);
?>
<p>&nbsp;</p>
<?php
echo "<hr />";
echo $live->highlight("datediff.php", HIGHLIGHT_PHP, INPUT_FILE);
20 changes: 20 additions & 0 deletions examples/misc/empties.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
require_once '../../phpLive.php';
echo <<<OPT
<form action="" method="post">
<p>First:<br /><input type="text" name="first" /></p>
<p>Last:<br /><input type="text" name="last" /></p>
<p>Email:<br /><input type="text" name="email" /></p>
<p><input type="submit" value="Test for empties!" /></p>
</form>
OPT;
if($live->post()){
if($live->empties($_POST["first"], $_POST["last"], $_POST["email"])){
echo "The following were empty:<br />";
print_r($live->list);
}else{
echo "There are no empty values!";
}
}
echo "<hr />";
echo $live->highlight("empties.php", HIGHLIGHT_PHP, INPUT_FILE);
27 changes: 27 additions & 0 deletions examples/misc/extend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
require_once '../../phpLive.php';
echo <<<FORM
<form method="post">
Which animal do you prefer?<br />
<input type="radio" name="animal" value="dog" /> Dog<br />
<input type="radio" name="animal" value="cat" /> Cat<br />
<input type="submit" value="What Sound?" />
</form>
FORM;

/**
* phpLive::favoriteAnimal()
* phpLive::animalNoise()
*
* The two methods can be found in extensions/example.php
*/

if($live->post()){
echo <<<ANIMAL
{$live->post("animal")->favoriteAnimal()}
{$live->animalNoise()}
ANIMAL;
}

echo "<hr />";
echo $live->highlight("extend.php", HIGHLIGHT_PHP, INPUT_FILE);
13 changes: 13 additions & 0 deletions examples/misc/highlight.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
require_once "../../phpLive.php";
echo "<h3>Html File</h3>";
echo "<pre>".$live->highlight("test_html.html", HIGHLIGHT_HTML, INPUT_FILE)->tabToSp()."</pre>";
echo "<hr />";
echo "<h3>Xml File</h3>";
echo "<pre>".$live->highlight("test_xml.xml", HIGHLIGHT_HTML, INPUT_FILE)->tabToSp()."</pre>";
echo "<hr />";
echo "<h3>CSS File</h3>";
echo "<pre>".$live->highlight("test_css.css", HIGHLIGHT_CSS, INPUT_FILE)->tabToSp()."</pre>";

echo "<hr />";
echo $live->highlight("highlight.php", HIGHLIGHT_PHP, INPUT_FILE);
8 changes: 8 additions & 0 deletions examples/misc/inet-aton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
require_once "../../phpLive.php";
echo $live->inetAToN("10.0.5.9");
echo "<br />";
echo $live->inetNToA(167773449);
echo "<hr />";

echo $live->highlight("inet-aton.php", HIGHLIGHT_PHP, INPUT_FILE);
8 changes: 8 additions & 0 deletions examples/misc/random.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
require_once '../../phpLive.php';
echo "<p style='color: red;'>The below output is html from a random page (see code at the bottom of this page)</p>";
echo "<hr />";
echo htmlentities($live->random("http://php.net", "http://phplive.org", "http://phpsnips.com")->getHttp());

echo "<hr />";
echo $live->highlight("random.php", HIGHLIGHT_PHP, INPUT_FILE);
48 changes: 48 additions & 0 deletions examples/misc/test_css.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
body{
font-size: 12px;
color: #ffffff;
background-color: #000000;
background-image: url("/images/test.png");
}

#testID{color: green;}
/*
.display{
display: block;
}
*/
.display-none{
display: none;
}

a.link{
color: red;
text-decoration: none;
}

a.link:hover{
text-decoration: underline;
}

.pa{
color: red;
}
a{
color: #ff0000;
}

*{
font-size: 12px;
}

div>a{
padding: 10px;
}

[lang=en]{
color: red;
}

p:lang(it){
color: blue;
}
35 changes: 35 additions & 0 deletions examples/misc/test_html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>HTML Highlight Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
body{
background-color: #ffffff;
font-size: 20px;
color: red;
}
h1, h2{
border-bottom: solid 1px #aaaaaa;
}
</style>
</head>
<body>
<!--
<p>Sed vitae tristique ipsum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Mauris sit amet arcu eu turpis sollicitudin vestibulum. In hac habitasse platea dictumst. Ut pulvinar blandit mi, non condimentum sem tincidunt ut. Mauris auctor risus sed nisl consectetur pulvinar. Praesent vel risus sit amet tellus bibendum pretium eget at orci. Cras pharetra nisl nec leo laoreet in auctor eros rutrum. Donec ultricies justo et est tristique aliquam. Sed in odio ut dui ullamcorper dignissim ut egestas felis.</p>
-->
<style type="text/css">
p > a{
background-color: #000000;
color: #ffffff;
font-size: 20px;
color: red;
}
</style>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sollicitudin aliquet nulla eget pulvinar. Ut a nisl vel est convallis feugiat a vel justo. Donec vel justo in tellus adipiscing facilisis. Donec lacus urna, cursus eget mattis ut, rhoncus vel orci. Morbi felis diam, lobortis id dictum convallis, congue et erat. Curabitur a hendrerit elit. Sed quis neque lorem. Pellentesque volutpat eros at sapien pretium sed aliquet orci varius. Suspendisse arcu enim, mattis a eleifend quis, imperdiet vel felis. Morbi lacinia elementum egestas. Sed fringilla libero a leo lacinia non egestas ante pellentesque. In ullamcorper varius tempor.</p>
<p>Sed vitae tristique ipsum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Mauris sit amet arcu eu turpis sollicitudin vestibulum. In hac habitasse platea dictumst. Ut pulvinar blandit mi, non condimentum sem tincidunt ut. Mauris auctor risus sed nisl consectetur pulvinar. Praesent vel risus sit amet tellus bibendum pretium eget at orci. Cras pharetra nisl nec leo laoreet in auctor eros rutrum. Donec ultricies justo et est tristique aliquam. Sed in odio ut dui ullamcorper dignissim ut egestas felis.</p>
<p>Quisque sit amet diam justo, nec sagittis elit. Sed eu nibh a ante vehicula mollis. Pellentesque eu ligula eget nunc euismod placerat sit amet eu velit. Fusce laoreet, risus non ullamcorper mollis, mi enim congue ipsum, consectetur pellentesque augue erat a nisl. Morbi a purus ut lectus ornare posuere. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam varius, sem sed sollicitudin condimentum, tortor erat cursus elit, vitae ornare sem ante id justo. Praesent at tortor leo, ac tempus tellus. Quisque vitae sem neque. Suspendisse vitae erat ligula. Sed eu mauris id dui feugiat faucibus nec ac eros. Nam sollicitudin, ante condimentum pellentesque commodo, neque risus congue quam, sed sodales erat diam ac nulla. Ut mattis magna enim. Quisque tincidunt nisi at sapien scelerisque pretium. Aliquam feugiat interdum dolor sed ullamcorper.</p>
<p>Nulla vehicula tristique nulla, ac tincidunt nunc condimentum quis. Fusce nunc arcu, tincidunt et tempus et, volutpat et nunc. Nunc iaculis eros eget risus egestas interdum consectetur ipsum interdum. Donec sit amet nunc vitae turpis condimentum scelerisque. Suspendisse potenti. Suspendisse potenti. Sed ante quam, consequat a mattis ac, dictum eu dolor. Donec elit neque, aliquam vel blandit vel, cursus non velit. Praesent tortor nunc, viverra in luctus tempus, tincidunt in nulla. Etiam consectetur risus sit amet felis porta lobortis ac blandit lacus. Vestibulum iaculis laoreet vulputate.</p>
<p>Aliquam venenatis, odio a convallis egestas, odio enim semper tortor, eget lacinia nunc lectus quis elit. Etiam interdum nulla et risus scelerisque ut vehicula magna semper. Mauris urna massa, tempus eu ultrices vel, venenatis at lectus. Pellentesque auctor interdum lorem, hendrerit malesuada sapien ultricies eget. Sed mattis, leo sit amet iaculis rutrum, quam nunc fringilla est, id rhoncus odio tortor eget mauris. Suspendisse malesuada accumsan laoreet. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vestibulum adipiscing lacus vel enim pretium adipiscing ultrices erat blandit. In porttitor nulla ut eros pellentesque malesuada. Aliquam aliquet lacinia scelerisque. Nullam fringilla volutpat sem.</p>
</body>
</html>
17 changes: 17 additions & 0 deletions examples/misc/test_xml.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<!--
People who are 25 years old
-->
<names age="25">
<name>Ryan</name>
<name>Bill</name>
<name>Bob</name>
</names>
<!-- People who are 45 years old -->
<names age="45">
<name>Roy</name>
<name>Jill</name>
<name>Jimmy</name>
</names>
</root>
29 changes: 29 additions & 0 deletions examples/misc/zip.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
require_once '../../phpLive.php';
$download = (bool)$live->get("d")->toString();
if($download){
/**
* Array key is the location on the server
* Array value is the location in the zip
*
* If an array key is not given it will save in the root of the zip and look
* for it with the given server location. If the file is not found it will be
* added as a directory in the zip.
*/
$files = array(
/**
* creates a folder ".." and a "construct" folder in it and puts "each.php" there
* add a value to this to save it with a better path name
*/
"../construct/each.php",
"inet-aton.php",
"folder A",
"random.php" => "folder A/random.php"
);
$live->zip($files)->download(PHP_TMPFILE, "download.zip");
exit;
}else{
echo "<p><a href='?d=1'>Download Zip File</a></p>";
echo "<hr />";
echo $live->highlight("zip.php", HIGHLIGHT_PHP, INPUT_FILE);
}
Binary file added examples/misc/ziped_files.zip
Binary file not shown.
5 changes: 5 additions & 0 deletions examples/regex/regCount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
require_once "../../phpLive.php";
echo $live->read("../../phpLive.php")->regCount("public function");
echo "<hr />";
echo $live->highlight("regCount.php", HIGHLIGHT_PHP, INPUT_FILE);
30 changes: 30 additions & 0 deletions examples/strings/blank.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<style type="text/css">
p.good{color:green;font-weight:bold;}
p.bad{color:red;font-weight:bold;}
</style><?php
require_once "../../phpLive.php";
if($live->get()){
if($live->get("name")->blank()){
echo "<p class='bad'>Name is blank!</p>";
}else{
echo "<p class='good'>Name is not blank!</p>";
}
}
echo <<<FORM
<form action="" method="get">
<table>
<tr><td>Name:</td><td><textarea type="text" name="name">{$live->get("name")}</textarea></td></tr>
<tr><td><input type="submit" value="Is Empty?"></td></tr>
</table>
</form>
FORM;
?>
<p>
<b>Note:</b> $live->blank() is <u>NOT</u> the same as empty(). A space is not considered an empty string when using empty().<br />
<b>Note:</b> Using $live->blank() a space is considered an empty string, so are tabs, newlines and carriage returns.<br />
<b>Note:</b> Use $live->blanks() to check for a list of empty strings.
</p>
<hr />
<?php
echo $live->highlight("blank.php", HIGHLIGHT_PHP, INPUT_FILE);
?>
Loading

0 comments on commit 02272c9

Please sign in to comment.