Exemplo n.º 1
0
 public function getTranslation($query)
 {
     $workflows = new Workflows();
     $api = $this->url . urlencode($query);
     $res = $workflows->request($api);
     $res = json_decode($res);
     if ($res->errorCode == 0) {
         $workflows->result($query, $res->translation[0], $res->translation[0], $query, "translate.png");
         if (isset($res->basic)) {
             $explains = $res->basic->explains;
             foreach ($explains as $key => $value) {
                 $workflows->result($key, $value, $value, $query, "translate.png");
             }
         }
         if (isset($res->web)) {
             $web = $res->web;
             foreach ($web as $key => $item) {
                 $workflows->result($key, implode(",", $item->value), implode(",", $item->value), $item->key, "translate.png");
             }
         }
     } else {
         $workflows->result('', '', '没查到呀', '没找到对应的翻译', 'translate.png', false);
     }
     echo $workflows->toxml();
 }
Exemplo n.º 2
0
function search_query($kw)
{
    $wf = new Workflows();
    $url = 'http://www.bilibili.tv/search?keyword=' . urlencode($kw) . '&orderby=&formsubmit=';
    $content = $wf->request($url, array(CURLOPT_ENCODING => 1));
    $doc = phpQuery::newDocumentHTML($content);
    $list = $doc->find('li.l');
    $i = 0;
    foreach ($list as $item) {
        $link = pq($item)->children('a:first')->attr('href');
        if (strpos($link, 'http') !== 0) {
            $link = 'http://www.bilibili.tv' . $link;
        }
        $info = pq($item)->find('div.info > i');
        $author = pq($item)->find('a.upper:first')->text();
        $view = $info->eq(0)->text();
        $comment = $info->eq(1)->text();
        $bullet = $info->eq(2)->text();
        $save = $info->eq(3)->text();
        $date = $info->eq(4)->text();
        $subtitle = 'UP主:' . $author . ' 播放:' . $view . ' 评论:' . $comment . ' 弹幕:' . $bullet . ' 收藏:' . $save . ' 日期:' . $date;
        $wf->result($i, $link, pq($item)->find('div.t:first')->text(), $subtitle, 'icon.png', 'yes');
        $i++;
    }
    if (count($wf->results()) == 0) {
        $wf->result('0', $url, '在bilibili.tv中搜索', $kw, 'icon.png', 'yes');
    }
    return $wf->toxml();
}
 /**
  * Present the Zhihu Daily.
  */
 public function show()
 {
     $webcode = json_decode(file_get_contents('http://news.at.zhihu.com/api/1.2/news/latest'), 1);
     $workflow = new Workflows();
     for ($i = 0; $i < count($webcode['news']); $i++) {
         $workflow->result($i, $webcode['news'][$i]['share_url'], $webcode['news'][$i]['title'], null, $this->getNewsIconFilePath($webcode['news'][$i]['thumbnail'], null));
     }
     echo $workflow->toxml();
 }
Exemplo n.º 4
0
 /**
  * Show News.
  *
  * @return boolean|null
  */
 public function show()
 {
     $options = $this->getOptions();
     $this->log($options);
     if (empty($options)) {
         return false;
     }
     $url = $method = null;
     extract($options);
     if (!isset($url) or !isset($method)) {
         return false;
     }
     $context = stream_context_create(array('http' => array('method' => "GET", 'timeout' => 10)));
     $this->htmlDom = file_get_html($url, 0, $context);
     if ($this->htmlDom) {
         call_user_func_array(array($this, $method), array());
     }
     if (count($this->workflow->results()) == 0) {
         $this->workflow->result($method, $url, static::NEWS_NOT_FOUND_TITLE, static::NEWS_NOT_FOUND_CONTENT, static::NEWS_ICON_DEFAULT);
     }
     echo $this->workflow->toxml();
 }
Exemplo n.º 5
0
 function getTranslations($input)
 {
     $w = new Workflows("psistorm.alfed.leo");
     $leo = new LeoParser();
     $cleanedInput = clean_utf8($input);
     $url = "http://dict.leo.org/" . $this->translationCode . "/?lang=en&searchLoc=0&search=" . urlencode($cleanedInput);
     $str = $w->request($url);
     $options = $leo->get($str);
     if ($options != array()) {
         foreach ($options as $option) {
             $w->result(time(), "{" . $this->translationCode . "}" . $option->translatedWord, $option->translatedWord, $option->originalWord, $option->languageCode . ".png", "yes", $option->originalWord);
         }
     }
     return $w->toxml();
 }
Exemplo n.º 6
0
 public function getResults($query)
 {
     $wf = new Workflows("jwm.alfed.jisho");
     $query = trim($query);
     // Limit requests to > 2 characters
     if (strlen($query) < 3) {
         echo $wf->toxml();
     }
     // Check cache first
     if ($this->isCached($query)) {
         $html_data = $this->getCachedResults($query);
     } else {
         // Scrape HTML from jisho.org
         $html_data = $wf->request("http://beta.jisho.org/search/" . rawurlencode($query));
         // Cache results
         $this->cacheResults(trim($query), $html_data);
     }
     // Parse HTML
     $search_results = $this->scrape($html_data);
     // Feed results to Alfred
     if (!empty($search_results)) {
         foreach ($search_results as $result) {
             $definition = '';
             foreach ($result['en'] as $word) {
                 $definition .= $word . '・';
             }
             $definition = preg_replace('/[^,.\\s;a-zA-Z0-9_-]|[,.;]$/s', '', $definition);
             $type = $result['type'] ? '[' . $result['type'] . '] ' : '';
             $definition = $type . str_replace('.', '; ', $definition);
             $icon = $this->getIcon($result['type']);
             $wf->result(time(), $result['url'] . ',' . $result['ja'], $result['ja'], $definition, $icon, "yes");
         }
     }
     // Return results to Alfred as XML
     echo $wf->toxml();
 }
 public function getMeans($query)
 {
     $workflows = new Workflows();
     $api = $this->url . $query;
     $res = $workflows->request($api);
     $res = json_decode($res);
     if ($res->status === 1) {
         $means = $res->message[0]->means;
         foreach ($means as $key => $mean) {
             $i = implode(',', $mean->means);
             $workflows->result($key, '', $mean->part . $i, '', '');
         }
     } else {
         $workflows->result('', '', '查不到\'' . $query . '\'', '没查到要找的单词', '');
     }
     echo $workflows->toxml();
 }
Exemplo n.º 8
0
 public function getWeather($query)
 {
     $workflows = new Workflows();
     $api = $this->url . $query;
     $res = $workflows->request($api);
     $res = json_decode($res);
     if ($res->error === 0) {
         $forecast = $res->results[0]->weather_data;
         foreach ($forecast as $key => $value) {
             $date = mb_substr($value->date, 0, 6);
             $workflows->result($key, $query, $date . "      " . $value->weather, $value->wind . ", 温度:" . $value->temperature, $value->weather . ".png");
         }
     } else {
         $workflows->result('', '', '没查到呀', '没找到你所查询城市的天气', 'unknown.png');
     }
     echo $workflows->toxml();
 }
Exemplo n.º 9
0
 function getTranslations($input)
 {
     $w = new Workflows("psistorm.alfed.leo");
     $leo = new LeoParser();
     $cleanedInput = clean_utf8($input);
     $url = "http://dict.leo.org/dictQuery/m-vocab/" . $this->translationCode . "/query.xml?tolerMode=nof&lp=" . $this->translationCode . "&lang=de&rmWords=off&directN=0&rmSearch=on&search=" . urlencode($cleanedInput) . "&searchLoc=0&resultOrder=basic&multiwordShowSingle=on&sectLenMax=16";
     $str = $w->request($url, array(CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 5));
     if (!empty($str)) {
         $options = $leo->get($str);
         if ($options != array()) {
             foreach ($options as $option) {
                 $argument = "{" . $this->translationCode . "}{" . $option->originalWord . "}{" . $option->translatedWord . "}";
                 $w->result(time(), $argument, $option->translatedWord, $option->originalWord, $option->languageCode . ".png", "yes", $option->originalWord);
             }
         }
     } else {
         $w->result(time(), "", "Timeout occurred.", $option->originalWord, "icon.png", "no");
     }
     return $w->toxml();
 }
function huittracks_helper($query)
{
    $wf = new Workflows();
    $q = trim(strtolower($query));
    $args = explode(' ', $q);
    if ($args[0] == '') {
        // if no arguments
        $wf->result('alfred8tracksworkflow.keyword', '', 'Search mixes on 8tracks by keyword', "Search mixes including the keyword '...'", 'icon.png', 'no', 'k ');
        $wf->result('alfred8tracksworkflow.popular', '', 'Most popular mixes on 8tracks', 'explore the most popular mixes', 'icon.png', 'no', 'mostpopular');
        $wf->result('alfred8tracksworkflow.trending', '', 'Most trending mixes on 8tracks', 'explore the most trending mixes', 'icon.png', 'no', 'mosttrending');
        $wf->result('alfred8tracksworkflow.newest', '', 'Most recent mixes on 8tracks', 'explore the newest mixes', 'icon.png', 'no', 'mostrecent');
        return $wf->toxml();
    } elseif ($args[0] == 'mostpopular') {
        return most_popular_mixes();
    } elseif ($args[0] == 'mosttrending') {
        return most_trending_mixes();
    } elseif ($args[0] == 'mostrecent') {
        return most_recent_mixes();
    } elseif ($args[0] == 'k' && sizeof($args) > 1 && $args[1] != "") {
        array_shift($args);
        return search_mixes_keyword($args);
    }
}
Exemplo n.º 11
0
<?php

require 'workflow.php';
require 'functions.php';
require 'GoogleMapClient.php';
isset($argv[1]) && ($query = trim($argv[1]));
$workflow = new Workflows();
$google_map_api_key = $workflow->read(GoogleMapClient::APIKEY);
$client = new GoogleMapClient($google_map_api_key);
try {
    if (is_geo($query)) {
        $params['latlng'] = $query;
    } else {
        $params['address'] = $query;
    }
    $result = $client->geocode($params);
    if ($result['status'] != 'OK') {
        $workflow->result('alfredworkflow_404', $result['status'], $result['status'], 'No response, try again!', 'icon/google.png');
    } else {
        foreach ($result['results'] as $address) {
            $address_location = $address['geometry']['location'];
            $latlng = $address_location['lat'] . ',' . $address_location['lng'];
            $workflow->result($address['place_id'], $latlng, $address['formatted_address'], $query, 'icon/google.png');
        }
    }
} catch (Exception $e) {
    $workflow->result('alfredworkflow_500', 'Please make sure your internet works well.', 'No response, try again!', 'Please make sure your internet works well.', 'icon/google.png');
}
print $workflow->toxml();
Exemplo n.º 12
0
<?php

require_once 'workflows.php';
$w = new Workflows();
$fp = fopen('insertTags.csv', 'r');
$results = array();
$i = 0;
while (!feof($fp)) {
    $row = fgetcsv($fp, 0, ';');
    $temp = array('uid' => $i, 'arg' => $row[0], 'title' => $row[0], 'subtitle' => $row[1], 'icon' => 'icon.png', 'valid' => 'yes', 'autocomplete' => 'autocomplete');
    array_push($results, $temp);
    $i++;
}
fclose($fp);
if (!empty($in)) {
    foreach ($results as $key => $value) {
        if (strpos(strtolower($value['title']), strtolower($in)) === false && strpos(strtolower($value['subtitle']), strtolower($in)) === false) {
            unset($results[$key]);
        }
    }
}
echo $w->toxml($results);
Exemplo n.º 13
0
function output($dir, $list)
{
    $wf = new Workflows();
    $parent = dirname($dir);
    if ($dir != '/') {
        $icon_name = $parent == '/' ? 'HomeFolderIcon.icns' : 'BackwardArrowIcon.icns';
        $wf->result(0, $parent . ($parent == '/' ? '' : '/'), ".. ({$parent})", "Goto parent directory", $GLOBALS["icon_path"] . $icon_name);
    }
    foreach ($list as $index => $entry) {
        $info = pathinfo($entry['name']);
        $path = (substr($dir, -1) == '/' ? $dir : "{$dir}/") . $entry["name"];
        // TODO: need to optimize performance in loop
        if ($entry["flag"] == 'd') {
            $path = "{$path}/";
            $icon = $GLOBALS["icon_path"] . (getCachedItem($path) ? 'DropFolderIcon.icns' : 'GenericFolderIcon.icns');
        } else {
            $icon = array_key_exists('extension', $info) ? "filetype:." . $info['extension'] : $GLOBALS["icon_path"] . 'GenericDocumentIcon.icns';
        }
        $wf->result($index + 1, $path, $entry["name"], ($entry["flag"] == '-' ? get_filesize($entry["size"]) . '. ' : '') . "Last modified: " . $entry["lastmodifieddate"], $icon, $entry["flag"] == '-');
    }
    echo $wf->toxml();
}
Exemplo n.º 14
0
        $data = substr($data, strrpos($data, "X-GitHub-Request-Id"));
        // clean string
        preg_match("/([\\[{])/", $data, $matches, PREG_OFFSET_CAPTURE);
        $start = $matches[0][1];
        $end = max(strrpos($data, "}"), strrpos($data, "]")) + 1;
        $data = substr($data, $start, $end - $start);
        $repos = json_decode($data);
    } else {
        $data = $w->request($url);
        $repos = json_decode($data);
    }
    if (isset($repos->message)) {
        $w->result($repos->message, $repos->message, 'Github Limit', $repos->message, $icon, 'no');
    } else {
        foreach ($repos as $repo) {
            // repos
            if (isset($repo->full_name) && (!strlen($query) || strpos(strtolower($repo->full_name), strtolower($query)) !== false)) {
                $w->result('git-' . $repo->full_name, $repo->html_url, $repo->name, $repo->description, $icon, 'yes');
            } else {
                if (!strlen($query) || strpos(strtolower($repo->description), strtolower($query)) !== false) {
                    $w->result('git-' . $repo->id, $repo->html_url, $repo->description, $repo->html_url, $icon, 'yes');
                }
            }
        }
        if (count($w->results()) == 0) {
            $w->result('git', null, 'No Repository found', 'No Repository found that match your query', $icon, 'no');
        }
    }
}
echo $w->toxml();
/**
 * Description :
 * Show the mixes 
 */
function showMix($url)
{
    // create a temporary directory for storing mix covers
    if (!file_exists(DIR_COVERS)) {
        mkdir(DIR_COVERS, 0777, true);
    }
    deleteAllFiles();
    $wf = new Workflows();
    $options = unserialize(OPTIONS);
    $json = $wf->request($url, $options);
    $data = json_decode($json, true);
    $mixes = $data['mix_set']['mixes'];
    $count = 1;
    foreach ($mixes as $mix) {
        // get mix info
        $mix_id = $mix['id'];
        $mix_name = $mix['name'];
        $url = "http://8tracks.com" . $mix['path'];
        $plays_count = $mix['plays_count'];
        $likes_count = $mix['likes_count'];
        $tracks_count = $mix['tracks_count'];
        $duration = $mix['duration'];
        $cover_url = $mix['cover_urls']['sq56'];
        // get mix cover from url
        $image_data = file_get_contents($cover_url);
        $image_name = $mix_id . '.png';
        file_put_contents(DIR_COVERS . '/' . $image_name, $image_data);
        // put image into temporary directory
        $wf->result('alfred8tracksworkflow.' . $count . '.' . time(), $url, trim($mix_name), '[' . number_format($plays_count) . ' plays] ' . '[' . number_format($likes_count) . ' likes] ' . '[' . $tracks_count . ' tracks] (' . gmdate("H:i:s", $duration) . ')', DIR_COVERS . '/' . $image_name);
        $count++;
    }
    return $wf->toxml();
}
Exemplo n.º 16
0
/**
 * handleDbIssuePdoXml function.
 *
 * @access public
 * @param mixed $dbhandle
 * @return void
 */
function handleDbIssuePdoXml($dbhandle)
{
    $errorInfo = $dbhandle->errorInfo();
    $w = new Workflows('com.vdesabou.spotify.mini.player');
    $w->result(uniqid(), '', 'Database Error: ' . $errorInfo[0] . ' ' . $errorInfo[1] . ' ' . $errorInfo[2], '', './images/warning.png', 'no', null, '');
    $w->result(uniqid(), '', 'There is a problem with the library, try to re-create it.', 'Select Re-Create Library library below', './images/warning.png', 'no', null, '');
    $w->result(uniqid(), serialize(array('', '', '', '', '', '', '', 'update_library', '', '', '', '', '', '', '', '', '', '')), "Re-Create Library", "when done you'll receive a notification. you can check progress by invoking the workflow again", './images/update.png', 'yes', null, '');
    echo $w->toxml();
}
Exemplo n.º 17
0
<?php

/**
 * a workflow for cnBeta.
 * @version 1.0
 * @author David Lin(voidman.me@gmail.com)
 */
require 'vendor/simple_html_dom.php';
require 'vendor/workflows.php';
require 'CnbetaNews.php';
$newsType = 'new';
$query = $query ?: $newsType;
if ($query) {
    if (in_array($query, array('new', 'top10', 'news.top10.week', 'news.top10.month', 'recommend', 'recommend.top10', 'recommend.top10.week', 'dispute', 'dispute.top10', 'dispute.top10.week', 'dispute.top10.month'))) {
        $newsType = $query;
        $cnbetaNews = new CnbetaNews($newsType);
        //$cnbetaNews->showNewsTopicIcon = false;
        $cnbetaNews->show();
    } elseif ($query == 'help') {
        $workflow = new Workflows();
        $workflow->result(1, null, "new", "显示 cnbeta 最新文章", 'icon.png');
        $workflow->result(2, null, "top10 / news.top10.week", "显示 cnbeta 本周十大人气文章", 'icon.png');
        $workflow->result(3, null, "news.top10.month", "显示 cnbeta 本月十大人气文章", 'icon.png');
        $workflow->result(4, null, "recommend", "显示 cnbeta 编辑推荐文章", 'icon.png');
        $workflow->result(5, null, "recommend.top10 / recommend.top10.week", "显示 cnbeta 本周十大推荐新闻", 'icon.png');
        $workflow->result(6, null, "dispute / dispute.top10 / dispute.top10.week", "显示 cnbeta 本周十大争议文章", 'icon.png');
        $workflow->result(7, null, "dispute.top10.month", "显示 cnbeta 本月十大争议文章", 'icon.png');
        echo $workflow->toxml();
    }
}
Exemplo n.º 18
0
$data = json_decode($data);
if (!isset($icon)) {
    $icon = "icon.png";
}
$query = strtolower($query);
$arr = get_defined_functions();
$extras = array();
$extras2 = array();
foreach ($data as $key => $result) {
    $value = $result->title;
    $description = utf8_decode(strip_tags($result->description));
    if (strpos(strtolower($value), $query) === 0) {
        $wf->result($key . $result->title, $result->url, $type . ": " . $result->title, $result->description, $icon);
    } else {
        if (strpos(strtolower($value), $query) > 0) {
            $extras[$key] = $result;
        } else {
            if (strpos($description, $query) !== false) {
                $extras2[$key] = $result;
            }
        }
    }
}
foreach ($extras as $key => $value) {
    $wf->result($key . $result->title, $result->url, $type . ": " . $result->title, $result->description, $icon);
}
foreach ($extras2 as $key => $value) {
    $wf->result($key . $result->title, $result->url, $type . ": " . $result->title, $result->description, $icon);
}
echo $wf->toxml();
Exemplo n.º 19
0
 /**
  * @param string $query
  * @return string
  */
 public function process($query)
 {
     $result = str_replace(array_keys($this->keys), array_values($this->keys), $query);
     $this->workflows->result(md5($query), $result, $result, $this->title, $this->icon, 'yes');
     return $this->workflows->toxml();
 }