blob: 99a628f7235ea705c925bdd0085735ee2e26de3b (
plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
|
<?php
/*THE SOURCE - A source for help with anything.*/
//Orginal Author: Phil Burton <philbeansburton@gmail.com>
// Version History
// 0.0.1 Created blasource.php
// 0.0.2 Added -l option for listing for sources.
$version = "BlaSource Version: 0.0.2";
// get the input
$stdin = read_stdin();
$stdin = explode(" ", $stdin);
$out = "";
$token = "";
for ($i=0 ; $i<sizeof($stdin); $i++)
{
switch ($stdin[$i])
{
case "-l":
if(!isset($stdin[$i+1]))
{
$n = 1;
}
else
{
$n=$stdin[$i+1];
$i++;
}
$X = ($n*5)-5;
for($j=0;$j<5;$j++)
{
$bla = $j+$X;
$temp = exec("grep -n \"\" blasource.txt | head -n" . $bla . " | tail -n1") . " ";
$out .= $temp;
}
break;
case "-new":
$name = $stdin[$i+1];
$link = $stdin[$i+2];
$file_handle = fopen("blasource.txt", "rb");
exec ("echo $name $link >> blasource.txt");
$out = $name . ": " . $link . " added.";
$i = sizeof($stdin);
break;
case "-v":
$out = $version;
$i = sizeof($stdin);
break;
case "-h":
$out = "-h for help, -v for version, -new <some-string-like-this> <someurl.html> e.g. !source -new gentoo-portage someurl.html. To view source:just enter a token <like-this-one> or <like this one> e.g. !source gentoo-portage or !source gentoo portage";
$i = sizeof($stdin);
break;
default:
for($j=$i;$j<sizeof($stdin);$j++)
{
$token .= $stdin[$j] . "-";
$i++;
}
$token = substr($token, 0, -1);
$file_handle = fopen("blasource.txt", "rb");
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$parts = explode(" ",$line_of_text);
if(sizeof($parts)>1)
{
if($parts[0] == $token)
{
$out = $parts[0] . ": " . $parts[1];
break;
}
$out = "No Source Found!";
}
}
fclose($file_handle);
break;
}
}
echo $out . "\n";
function read_stdin()
{
$fr=fopen("php://stdin","r"); // open our file pointer to read from stdin
$input = fgets($fr,128); // read a maximum of 128 characters
$input = rtrim($input); // trim any trailing spaces.
fclose ($fr); // close the file handle
return $input; // return the text entered
}
?>
|