From 3a0e05950740c89b608b3bf96b71fccba6fd3167 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Mon, 7 Dec 2015 00:13:06 +0000 Subject: Add help and version options --- search.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'search.php') diff --git a/search.php b/search.php index c2845f7..44c964c 100644 --- a/search.php +++ b/search.php @@ -1,5 +1,7 @@ Date: Mon, 7 Dec 2015 00:15:15 +0000 Subject: Missing ; --- search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'search.php') diff --git a/search.php b/search.php index 44c964c..f4109b1 100644 --- a/search.php +++ b/search.php @@ -1,6 +1,6 @@ Date: Mon, 7 Dec 2015 00:16:03 +0000 Subject: Missing (I am good at php yes) --- search.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'search.php') diff --git a/search.php b/search.php index f4109b1..3e89647 100644 --- a/search.php +++ b/search.php @@ -32,10 +32,10 @@ try { $args = explode(" ", $search); $page = 1; - if (args[0] == "-v" || args[0] == "--version") { + if ($args[0] == "-v" || $args[0] == "--version") { echo $version + \n; die(); - } else if (args[0] == "-h" || args[0] == "--help") { + } else if ($args[0] == "-h" || $args[0] == "--help") { echo "Usage: !blaup [query] #[page] | e.g: !blaup intense | !blaup intense marcus | " echo "!blaup intense marcus #2 (returns the second page of results)\n" die(); -- cgit v1.2.3 From 6b114bc7472907eeaadf503c60dc6b4404311f80 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Mon, 7 Dec 2015 00:17:02 +0000 Subject: More missing ;s (In my defense I don't have php locally so I can't run this until I commit it...) --- search.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'search.php') diff --git a/search.php b/search.php index 3e89647..97cd0b3 100644 --- a/search.php +++ b/search.php @@ -36,8 +36,8 @@ try { echo $version + \n; die(); } else if ($args[0] == "-h" || $args[0] == "--help") { - echo "Usage: !blaup [query] #[page] | e.g: !blaup intense | !blaup intense marcus | " - echo "!blaup intense marcus #2 (returns the second page of results)\n" + echo "Usage: !blaup [query] #[page] | e.g: !blaup intense | !blaup intense marcus | "; + echo "!blaup intense marcus #2 (returns the second page of results)\n"; die(); } -- cgit v1.2.3 From 9034127f89705ffa2b465ae256e1ea0eb9c8b933 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Mon, 7 Dec 2015 00:19:21 +0000 Subject: Quote the \n --- search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'search.php') diff --git a/search.php b/search.php index 97cd0b3..c43e3a8 100644 --- a/search.php +++ b/search.php @@ -33,7 +33,7 @@ try { $page = 1; if ($args[0] == "-v" || $args[0] == "--version") { - echo $version + \n; + echo $version + "\n"; die(); } else if ($args[0] == "-h" || $args[0] == "--help") { echo "Usage: !blaup [query] #[page] | e.g: !blaup intense | !blaup intense marcus | "; -- cgit v1.2.3 From 0bf092da0da22b7643b722e5e283013e88c83d93 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Mon, 7 Dec 2015 00:20:31 +0000 Subject: Add more text to version output --- search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'search.php') diff --git a/search.php b/search.php index c43e3a8..7f5d5a1 100644 --- a/search.php +++ b/search.php @@ -33,7 +33,7 @@ try { $page = 1; if ($args[0] == "-v" || $args[0] == "--version") { - echo $version + "\n"; + echo "blaupload-search v" . $version . "\n"; die(); } else if ($args[0] == "-h" || $args[0] == "--help") { echo "Usage: !blaup [query] #[page] | e.g: !blaup intense | !blaup intense marcus | "; -- cgit v1.2.3 From fe8493861298b1c727e2468f736e9892fb78a42e Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Mon, 7 Dec 2015 00:26:19 +0000 Subject: Make command in help output configurable --- search.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'search.php') diff --git a/search.php b/search.php index 7f5d5a1..c057423 100644 --- a/search.php +++ b/search.php @@ -36,8 +36,10 @@ try { echo "blaupload-search v" . $version . "\n"; die(); } else if ($args[0] == "-h" || $args[0] == "--help") { - echo "Usage: !blaup [query] #[page] | e.g: !blaup intense | !blaup intense marcus | "; - echo "!blaup intense marcus #2 (returns the second page of results)\n"; + echo "Usage: " . $config["command"] . " [query] #[page] | "; + echo "e.g: " . $config["command"] . " intense | "; + echo $config["command"] . " intense marcus | "; + echo $config["command"] . " intense marcus #2 (returns the second page of results)\n"; die(); } -- cgit v1.2.3 From 47cb1f271fcfe28a1e8cd4184f7820e6d7f30dd0 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Mon, 7 Dec 2015 00:30:02 +0000 Subject: Removed \! from config value to fix output --- search.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'search.php') diff --git a/search.php b/search.php index c057423..bb98c40 100644 --- a/search.php +++ b/search.php @@ -36,10 +36,10 @@ try { echo "blaupload-search v" . $version . "\n"; die(); } else if ($args[0] == "-h" || $args[0] == "--help") { - echo "Usage: " . $config["command"] . " [query] #[page] | "; - echo "e.g: " . $config["command"] . " intense | "; - echo $config["command"] . " intense marcus | "; - echo $config["command"] . " intense marcus #2 (returns the second page of results)\n"; + echo "Usage: !" . $config["command"] . " [query] #[page] | "; + echo "e.g: !" . $config["command"] . " intense | "; + echo "!" . $config["command"] . " intense marcus | "; + echo "!" . $config["command"] . " intense marcus #2 (returns the second page of results)\n"; die(); } -- cgit v1.2.3 From dcfca35dd4a41977e040e43c1dcca9ac527dac39 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Mon, 7 Dec 2015 00:31:58 +0000 Subject: Add newline to end of output --- search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'search.php') diff --git a/search.php b/search.php index bb98c40..d68beec 100644 --- a/search.php +++ b/search.php @@ -126,5 +126,5 @@ function read_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 + return $input . "\n"; // return the text entered } -- cgit v1.2.3 From 6ede577a74cee606cdde72b57e01ccc9e3295ea6 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Mon, 7 Dec 2015 00:37:50 +0000 Subject: Move newline at end of output to the correct place --- search.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'search.php') diff --git a/search.php b/search.php index d68beec..0aeb0b9 100644 --- a/search.php +++ b/search.php @@ -114,7 +114,7 @@ try { } } - echo implode(" - ", $out); + echo implode(" - ", $out) . "\n"; } catch (Exception $e) { echo $e->getMessage() . "\n";die(); @@ -126,5 +126,5 @@ function read_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 . "\n"; // return the text entered + return $input; // return the text entered } -- cgit v1.2.3 From 7bc73dd3d1b1af00fe1f88bdb8f9595d96b19fe0 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Mon, 7 Dec 2015 00:41:48 +0000 Subject: Clean up whitespace --- search.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'search.php') diff --git a/search.php b/search.php index 0aeb0b9..2c9ddb7 100644 --- a/search.php +++ b/search.php @@ -10,7 +10,7 @@ try { if (!$config = parse_ini_file("config.ini")) { throw new Exception('Could not parse ini file'); } - + // hash the password if (isset($config['password'])) { $hash = hash("sha256", $config['password']); @@ -22,7 +22,7 @@ try { curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $output = json_decode(curl_exec($curl)); curl_close($curl); - + $search = read_stdin(); if (empty($search)) { @@ -65,18 +65,18 @@ try { throw new Exception("Page `" . $page . "` is not valid"); } - + // remove the pagination from the search args $pos = array_search("#" . $page, $args); if ($pos) { $args[$pos] = null; } - + // Really slow search $results = []; foreach ($output as $upload) { $match = false; - foreach ($args as $arg) { + foreach ($args as $arg) { if (!is_null($arg) && stripos($upload->filename, $arg) === false) { $match = false; break; @@ -121,7 +121,7 @@ try { } 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. -- cgit v1.2.3 From 75872be417067e4ef1f8d128b96fc338540cda50 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Mon, 7 Dec 2015 09:05:04 +0000 Subject: switch the ifs for version and help so we use the same output method and add a couple of config checks. --- search.php | 142 +++++++++++++++++++++++++++++++------------------------------ 1 file changed, 73 insertions(+), 69 deletions(-) (limited to 'search.php') diff --git a/search.php b/search.php index 2c9ddb7..c3e2d6d 100644 --- a/search.php +++ b/search.php @@ -10,7 +10,12 @@ try { if (!$config = parse_ini_file("config.ini")) { throw new Exception('Could not parse ini file'); } - + if (!isset($config["url"])) { + throw new Exception('`url` not found in ini file'); + } + if (!isset($config["command"])) { + throw new Exception('`command` not found in ini file'); + } // hash the password if (isset($config['password'])) { $hash = hash("sha256", $config['password']); @@ -31,86 +36,85 @@ try { $args = explode(" ", $search); $page = 1; - + $out = []; if ($args[0] == "-v" || $args[0] == "--version") { - echo "blaupload-search v" . $version . "\n"; - die(); - } else if ($args[0] == "-h" || $args[0] == "--help") { - echo "Usage: !" . $config["command"] . " [query] #[page] | "; - echo "e.g: !" . $config["command"] . " intense | "; - echo "!" . $config["command"] . " intense marcus | "; - echo "!" . $config["command"] . " intense marcus #2 (returns the second page of results)\n"; - die(); - } + $out[] = "blaupload-search v" . $version; + } elseif ($args[0] == "-h" || $args[0] == "--help") { + $help = "Usage: !" . $config["command"] . " [query] #[page] | "; + $help .= "e.g: !" . $config["command"] . " intense | "; + $help .= "!" . $config["command"] . " intense marcus | "; + $help .= "!" . $config["command"] . " intense marcus #2 (returns the second page of results)"; + $out[] = $help; + } else { - // Check to see if user specified pagination - $pages = array_filter($args, function($elem) { - if (strpos($elem, "#") === 0) { - return true; - } - return false; - }); - // reset the indexes after the array filter - $pages = array_merge($pages); + // Check to see if user specified pagination + $pages = array_filter($args, function($elem) { + if (strpos($elem, "#") === 0) { + return true; + } + return false; + }); + // reset the indexes after the array filter + $pages = array_merge($pages); - if (count($pages) > 1) { - throw new Exception("Too many page choices. Enter only one `#`"); - } + if (count($pages) > 1) { + throw new Exception("Too many page choices. Enter only one `#`"); + } - if (!empty($pages)) { - // Set the page - $page = substr($pages[0], 1); - } - if (!is_int((int)$page) || $page <= 0) { - throw new Exception("Page `" . $page . "` is not valid"); - } + if (!empty($pages)) { + // Set the page + $page = substr($pages[0], 1); + } + if (!is_int((int)$page) || $page <= 0) { + throw new Exception("Page `" . $page . "` is not valid"); + } - // remove the pagination from the search args - $pos = array_search("#" . $page, $args); - if ($pos) { - $args[$pos] = null; - } + // remove the pagination from the search args + $pos = array_search("#" . $page, $args); + if ($pos) { + $args[$pos] = null; + } - // Really slow search - $results = []; - foreach ($output as $upload) { - $match = false; - foreach ($args as $arg) { - if (!is_null($arg) && stripos($upload->filename, $arg) === false) { - $match = false; - break; + // Really slow search + $results = []; + foreach ($output as $upload) { + $match = false; + foreach ($args as $arg) { + if (!is_null($arg) && stripos($upload->filename, $arg) === false) { + $match = false; + break; + } + $match = true; + } + if ($match) { + $results[] = $config["url"] . "/" . rawurlencode($upload->filename); } - $match = true; - } - if ($match) { - $results[] = $config["url"] . "/" . rawurlencode($upload->filename); } - } - // Return results - $out = []; - if (empty($results)) { - echo "No results found\n"; - } else { - $count = count($results); - $i = 0; - - $start = ($page-1)*3; - $end = $start+2; - if ($start > ($count-1)) { - throw new Exception("No results for this page"); - } - foreach($results as $result) { - if ($i < $start || $i > $end) { + // Return results + if (empty($results)) { + echo "No results found\n"; + } else { + $count = count($results); + $i = 0; + + $start = ($page-1)*3; + $end = $start+2; + if ($start > ($count-1)) { + throw new Exception("No results for this page"); + } + foreach($results as $result) { + if ($i < $start || $i > $end) { + $i++; + continue; + } + $out[] = $i+1 . ": " . $result; $i++; - continue; } - $out[] = $i+1 . ": " . $result; - $i++; - } - if ($count > 3) { - $out[] = "results (" . $count . ")"; + if ($count > 3) { + $out[] = "results (" . $count . ")"; + } } } -- cgit v1.2.3