Skip to content

Commit

Permalink
improved code
Browse files Browse the repository at this point in the history
  • Loading branch information
zqzten committed Dec 14, 2017
1 parent 607cd63 commit 8fa29cc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/util/download.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function initDownloadDir($clear) {
function saveAndReturnFile($url, $name = null) {
global $download_dir;

if (!$name) $name = uniqid();
if (is_null($name)) $name = uniqid();
$path = $download_dir.'/'.$name;

file_put_contents($path, file_get_contents($url));
Expand Down
8 changes: 1 addition & 7 deletions src/util/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ function request($url = null, $options = null) {
foreach ($options as $k => $v)
$defaults[$k] = $v;

array_filter($defaults,
function($a) {
if ($a == '' || $a == null)
return false;
else
return true;
});
array_filter($defaults, function($a) { return !empty($a); });

$ch = curl_init();
curl_setopt_array($ch, $defaults);
Expand Down
4 changes: 2 additions & 2 deletions src/wikipedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

$wf = new Workflow;

if (strpos($query, ' ') !== FALSE) {
if (strpos($query, ' ') !== false) {
$parts = explode(' ', $query);
$code = array_shift($parts);
$query = implode(' ', $parts);
Expand All @@ -31,7 +31,7 @@
->quicklookurl("$url");
}

if (count($json[1]) == 0) {
if (count($json[1]) === 0) {
$wf->result()
->title('No Suggestions')
->subtitle('No search suggestions found. Search Wikipedia.'.$code.' for '.$query)
Expand Down
6 changes: 3 additions & 3 deletions src/zhihu.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
$wf = new Workflow;

$download_dir = getenv('alfred_workflow_cache').'/zhihu';
initDownloadDir(TRUE);
initDownloadDir(true);

$response = request('https://www.zhihu.com/autocomplete?token='.urlencode($query));
$json = json_decode(mb_convert_encoding($response, 'UTF-8', 'HTML-ENTITIES'))[0];

foreach ($json as $sugg) {
if (is_array($sugg)) {
$matched = TRUE;
$matched = true;
$type = $sugg[0];
switch ($type) {
case 'topic':
Expand Down Expand Up @@ -46,7 +46,7 @@
$icon = ICON;
break;
default:
$matched = FALSE;
$matched = false;
break;
}

Expand Down

0 comments on commit 8fa29cc

Please sign in to comment.