forked from petenelson/bacon-ipsum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gga-bacon-ipsum-form.php
82 lines (60 loc) · 2.18 KB
/
gga-bacon-ipsum-form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*
Plugin Name: Bacon Ipsum - Generator Form
Description: Generates the input form for generating meaty bacon ipsum
Plugin URI: https://github.com/petenelson/bacon-ipsum
Version: 2.1.4
Author: Pete Nelson (@GunGeekATX)
Author URI: http://petenelson.com
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
add_shortcode('gga-bacon-ipsum-form', 'gga_bacon_ipsum_form');
function gga_bacon_ipsum_form($atts) {
$output = '';
$form = '
<p>Does your lorem ipsum text long for something a little meatier? Give our generator a try… it’s tasty!</p>
<form id="make-it-meaty" action="' . site_url('/') . '" method="get">
<table>
<tbody>
<tr>
<td>Paragraphs:</td>
<td><input style="width: 40px;" type="text" name="paras" value="5" maxlength="2" /></td>
</tr>
<tr>
<td>Type:</td>
<td><input id="all-meat" type="radio" name="type" value="all-meat" checked="checked" /><label for="all-meat">All Meat</label> <input id="meat-and-filler" type="radio" name="type" value="meat-and-filler" /><label for="meat-and-filler">Meat and Filler</label></td>
</tr>
<tr>
<td></td>
<td><input id="start-with-lorem" type="checkbox" name="start-with-lorem" value="1" checked="checked" /> <label for="start-with-lorem">Start with \'Bacon ipsum dolor sit amet...\'</label></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Give me bacon" /></td>
</tr>
</tbody>
</table>
</form>
';
if (isset($_REQUEST["type"])) {
require_once 'gga-BaconIpsumGenerator.php';
$generator = new BaconIpsumGenerator();
$number_of_paragraphs = 5;
if (isset($_REQUEST["paras"]))
$number_of_paragraphs = intval($_REQUEST["paras"]);
$output = '';
if ($number_of_paragraphs < 1)
$number_of_paragraphs = 1;
if ($number_of_paragraphs > 100)
$number_of_paragraphs = 100;
$paragraphs = $generator->Make_Some_Meaty_Filler(
$_REQUEST["type"],
$number_of_paragraphs,
isset($_REQUEST["start-with-lorem"]) && $_REQUEST["start-with-lorem"] == "1");
$output = '<div>';
foreach($paragraphs as $paragraph)
$output .= '<p>' . $paragraph . '</p>';
$output .= '</div>';
}
return $output . $form;
}