示例#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();
 }
示例#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();
}
 /**
  * Get top10 type news.
  *
  * @param $index int
  * @return boolean
  */
 private function getTopTenNews($index)
 {
     if (!$this->htmlDom) {
         return false;
     }
     $i = 0;
     foreach ($this->htmlDom->find('div.newslist') as $element) {
         if ($i != $index) {
             $i++;
             continue;
         } else {
             $iconUrl = static::URL_BASE . ltrim($element->find('dd.desc > img', 0)->src, '/');
             $iconPath = $this->getNewsIconFilePath($iconUrl, static::NEWS_ICON_DIR_TOP10);
             foreach ($element->find('p') as $e) {
                 $urlNode = $e->find('a', 0);
                 $title = $urlNode->plaintext;
                 $title = iconv('GB18030', 'UTF-8', trim($title));
                 $content = '';
                 $url = static::URL_BASE . ltrim($urlNode->href, '/');
                 $id = 0;
                 if (preg_match("/articles\\/([0-9]+).htm/", $url, $matches)) {
                     $id = $matches[1];
                 }
                 if ($title) {
                     $this->workflow->result($id, $url, $title, $content, $iconPath);
                 }
             }
             break;
         }
     }
     return true;
 }
 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();
 }
示例#5
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();
 }
 /**
  * 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();
 }
示例#7
0
文件: leo.php 项目: hoalex/alfredapp
 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);
    }
}
示例#9
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();
 }
示例#10
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();
 }
示例#11
0
<?php

require_once 'workflows.php';
require_once 'sqlitedb.php';
$input = $argv[1];
$w = new Workflows();
$db = new SQLiteDB('autocomplete.db');
$table = array('handle' => 'text PRIMARY KEY');
$db->create_table($table, 'users');
$remaining = 140 - count(str_split(trim($input)));
$w->result('tweet', $input, 'Tweet: ' . $input, 'Remaining: ' . $remaining . '. Press Cmd+Enter to send.', 'icon.png');
$words = explode(' ', $input);
if (preg_match('^@[a-zA-Z0-9-_]{2,}^', end($words))) {
    $search = substr(end($words), 1);
    $matches = $db->select('*')->from('users')->like('handle', $search)->get();
    array_pop($words);
    $words = implode(' ', $words);
    foreach ($matches as $match) {
        $w->result('autoc', $words . ' @' . $match->handle . ' ', $match->handle, '', 'icon.png', 'no', $words . ' @' . $match->handle . ' ');
    }
}
echo $w->toxml();
示例#12
0
<?php

/**
* Name:         Wordreference.com (© WordReference.com) Workflow for Alfred 2
* Author:       Anthony Kevins
* Revised:      14/06/2013
* Version:      0.3
* Note:         Icon Source: A68 - Freelance Graphics Design (http://a68.pl)
*/
require_once 'workflows.php';
$w = new Workflows('wordreference');
$id = $w->get('api', 'settings.plist');
if (!$id) {
    $w->result('wordreference-noapi', 'open http://www.wordreference.com/docs/APIregistration.aspx', 'You must provide a WordReference API to use the workflow', "Get an API using 'getapi', then set it with 'setapi'", 'icon.png', 'yes');
    echo $w->toxml();
    die;
}
$langs = urlencode($argv[1]);
$query = urlencode($argv[2]);
$url = "http://api.wordreference.com/0.8/{$id}/json/{$langs}/{$query}";
$translations = $w->request($url);
$translations = json_decode($translations);
$lang1 = substr($langs, 0, 2);
$lang2 = substr($langs, -2);
$dir = dirname(__FILE__);
$defaultIcon = 'icon.png';
$lang1Icon = file_exists($dir . "/{$lang1}.png") ? "{$lang1}.png" : $defaultIcon;
// where translations are stored in the JSON
$translationPositions = array(array('term0', 'PrincipalTranslations'), array('term0', 'Entries'), array('term0', 'AdditionalTranslations'), array('original', 'Compounds'));
$termIndex = 0;
// for each position check if present and call the walker
示例#13
0
文件: functions.php 项目: bycEEE/env
/**
 * 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();
}
示例#14
0
<?php

include_once "workflows.php";
$wf = new Workflows();
$name = "/tut.*/i";
exec("/Users/richardguay/bin/s3cmd ls", $listdir);
$count = 1;
foreach ($listdir as $dirItem) {
    if (strcmp($dirItem, "") != 0 && preg_match($name, $dirItem) === 1) {
        $wf->result('s3cmd:list' . $count, $dirItem, $dirItem, '', 'icon.png', 'yes', 'auto');
        $count = $count + 1;
    }
}
//
// Add the default list of cleaners.
//
$wf->result('s3c999', '', 'Quit', '', 'icon.png', 'no', '');
echo $wf->toxml();
示例#15
0
}
$query = strtolower(trim($query));
$cdns = json_decode(file_get_contents("cdns.json"));
$output = array();
// all
if (strpos($query, " ") !== false) {
    $parts = explode(" ", $query);
    $cdn_q = array_shift($parts);
    $string = implode($parts);
    foreach ($cdns as $cdn => $params) {
        $count = count($w->results());
        $pos = strpos($cdn, $cdn_q);
        if ($pos !== false && $pos == 0) {
            run($params, $string);
            if ($count == count($w->results())) {
                $w->result("cdn-{$cdn}", $query, 'No libraries found.', $query, "icon-cache/{$cdn}.png", 'no');
            }
        }
    }
}
//
if (count($w->results()) == 0) {
    foreach ($cdns as $cdn => $params) {
        $count = count($w->results());
        run($params, $query);
        if ($count == count($w->results())) {
            $w->result("cdn-{$cdn}", $query, "{$params->name}", 'No libraries found.', "icon-cache/{$cdn}.png", 'no');
        }
    }
}
function load($params)
示例#16
0
}
if (!isset($api)) {
    // repos | starred | gists
    $parts = explode(" ", $query);
    $api = array_shift($parts);
    $query = implode(" ", $parts);
}
if (!isset($icon)) {
    $icon = "icon.png";
}
$username = $w->get('github.username', 'settings.plist');
$password = $w->get('github.password', 'settings.plist');
$proxy = $w->get('github.proxy', 'settings.plist');
$url = "https://api.github.com/users/{$username}/{$api}";
if (!$username) {
    $w->result('git-username', 'https://github.com/willfarrell/alfred-github-workflow', 'Github Username Required', 'Press Enter to see documentation on how to set up.', 'yes', 'icon.png');
} else {
    if ($username && $password) {
        $shell_command = 'sh auth.sh -u ' . escapeshellarg($username) . ' -p ' . escapeshellarg($password) . ' --url ' . escapeshellarg($url);
        if ($proxy) {
            $shell_command .= ' --proxy ' . escapeshellarg($proxy);
            file_put_contents("/tmp/alfred", $shell_command . "\n", FILE_APPEND);
        }
        exec($shell_command, $output, $return_var);
        $data = implode($output);
        $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);
示例#17
0
/**
 *  Chiphell For Alfred Workflows
 *  @author simman
 *  @copyright simman.cc
 */
require_once 'workflows.php';
$wf = new Workflows();
$orig = intval("{query}");
$chh_url = "http://www.chiphell.com/forum.php?fid=" . $orig . "&mod=rss";
$data = $wf->request($chh_url);
$xml = simplexml_load_string($data);
$result_data_array = $xml->channel;
foreach ($result_data_array->item as $val) {
    $icon = "icon.png";
    $wf->result($int++ . '.' . time(), $val->link, $val->title, 'author:' . $val->author . '    pubDate:' . $val->pubDate, $icon);
}
if (count($result_data_array->item) == 0) {
    $wf->result('Chiphell_500', '请确保指令和网络链接正常', '没有响应,请再试一次。', '请确保指令和网络链接正常', 'icon.png');
}
echo $wf->toxml();
//$first_channel = array(
//				array(
//					array('name' => '电脑', 'id' => 'gid=3')
//					array('name' => '业界新闻', 'id' => 'fid=80')
//					array('name' => 'CPU/内存/主板/超频', 'id' => 'fid=36')
//					array('name' => '顶级图形卡', 'id' => 'fid=4')
//					array('name' => '散热器/机箱/电源', 'id' => 'fid=42')
//					array('name' => '水冷/MOD', 'id' => 'fid=127')
//					array('name' => '外设', 'id' => 'fid=147')
//					array('name' => 'NAS/SSD/HDD', 'id' => 'fid=103')
示例#18
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();
示例#19
0
$hsl = tohsl($r, $g, $b, $a);
$name = toname(tohexraw($r, $g, $b));
$rgb = torgb($r, $g, $b, $a);
$rgb_pcnt = torgb_pcnt($r, $g, $b, $a);
$modes = array('hex' => $hex, 'hsl' => $hsl, 'name' => $name, 'rgb' => $rgb, 'rgb_pcnt' => $rgb_pcnt);
if (!$a) {
    $description = array('hex' => 'Hexadecimal format', 'hsl' => 'HSL format', 'name' => 'CSS3 named color', 'rgb' => 'RGB format', 'rgb_pcnt' => 'RGB percent format');
} else {
    $description = array('hex' => 'Hexadecimal format', 'hsl' => 'HSLA format', 'name' => 'CSS3 named color', 'rgb' => 'RGBA format', 'rgb_pcnt' => 'RGBA percent format');
}
$json = jsonrgba($rgba);
foreach ($modes as $this_mode => $result) {
    if ($result == false) {
        continue;
    }
    $w->result("tylereich.colors {$mode} to {$this_mode}", "{$this_mode}|{$json}", $result, $description[$this_mode], $w->cache() . "/{$hexraw}.png", 'yes');
}
echo $w->toxml();
// Normalization functions
function rgb($r = 0, $g = 0, $b = 0, $a = null)
{
    if (preg_match('/%/', $r) || preg_match('/%/', $g) || preg_match('/%/', $b)) {
        $r = str_replace('%', '', $r);
        $g = str_replace('%', '', $g);
        $b = str_replace('%', '', $b);
        $r /= 100;
        $g /= 100;
        $b /= 100;
    } else {
        $r /= 255;
        $g /= 255;
示例#20
0
<?php

require "workflows.php";
$wf = new Workflows();
$filename = "~/.hatebulist";
system('echo ' . $query . ' > ' . $filename);
$wf->result(time(), $query, $query, $query . "を登録します", "icon.png");
echo $wf->toxml();
示例#21
0
<?php

require_once 'workflows.php';
$wf = new Workflows();
$query = trim($argv[1]);
$site = '美团';
$icon = 'icon.png';
$requestOption = array(CURLOPT_POST => true, CURLOPT_HTTPHEADER => array('Content-length:0', 'X-Requested-With:XMLHttpRequest'));
$json = $wf->request("http://www.meituan.com/search/smartbox/" . urlencode($query), $requestOption);
$items = json_decode($json);
$items = $items->data;
foreach ($items as $item) {
    $url = sprintf('http://www.meituan.com/s/?w=%s', urlencode($item));
    $subtitle = sprintf('查看全部与%s有关的团购', $item);
    $wf->result("{$url}", "在美团上搜索: {$item}", "{$subtitle}", $icon);
}
$url = sprintf('http://www.meituan.com/s/?w=', $query);
$results = $wf->results();
if (count($results) == 0) {
    $wf->result($url, 'No Suggestions', 'No search suggestions found. Search 美团 for ' . $query, 'icon.png');
}
echo $wf->toxml();
示例#22
0
// This is set to off in order to escape an error for timezones not being set.
require 'workflows.php';
$w = new Workflows('com.evgeny.golubev.alfred.caffeinate');
$min_avaliable = array(10, 30, 60, 120);
$value = shell_exec("ps -ef|grep caff|grep -v grep");
$regex = "/^([\\w\\W]{0,})([0-9]){1,}([:]{1})([0-9]{2})([APM]{2})([\\w\\W]{1,})(caffeinate){1}([ \\-tdbsi]{0,})([0-9]{0,})/";
$match = preg_match($regex, $value, $matches);
if ($match) {
    $hour = $matches[2];
    $minutes = $matches[4];
    $apm = $matches[5];
    $duration = $matches[9];
    $launch = $hour . ":" . $minutes . $apm;
    $now = shell_exec("date +\"%l:%M%p\"");
    $diff = round(abs(strtotime($now) - strtotime($launch)) / 60);
    $duration = $duration;
    $min = $duration / 60 - $diff;
    if ($min > 0) {
        $w->result('caffeinateoff', 'off', 'Deactivate', 'Caffeinate is active for another ' . $min . ' minutes.', 'icon.png', 'yes');
    } else {
        $w->result('caffeinateoff', 'off', 'Deactivate', 'Caffeinate is currently active for an indefinite period.', 'icon.png', 'yes');
    }
} else {
    if ($match == 0) {
        foreach ($min_avaliable as $min) {
            $w->result('caffeinate' . $min . 'min', 'on ' . $min, 'Activate for ' . $min . ' minutes', 'Activate caffeinate for another ' . $min . ' minutes.', 'icon.png', 'yes');
        }
        $w->result('caffeinateindefinitely', 'on indefinitely', 'Activate indefinitely', 'Activate caffeinate for indefinitely period.', 'icon.png', 'yes');
    }
}
echo $w->toxml();
示例#23
0
}
function get_userinfo()
{
    $filename = "~/.hatebulist";
    $str = exec('cat ' . $filename, $output);
    $userinfo_array = explode(" ", $output[0]);
    return array('user_name' => $userinfo_array[0], 'api_key' => $userinfo_array[1]);
}
$user = get_userinfo();
$user_name = $user['user_name'];
$api_key = $user['api_key'];
#http://d.hatena.ne.jp/i_ogi/20100214/wsse
$url = "http://b.hatena.ne.jp/" . $user_name . "/search/json?q=" . $query . "&sort=date&limit=20";
$nonce = md5(mt_rand());
$created = date(DATE_ISO8601);
$x_wsse = sprintf('UsernameToken Username="******", PasswordDigest="%s", Nonce="%s", Created="%s"', $user_name, base64_encode(sha1($nonce . $created . $api_key, true)), base64_encode($nonce), $created);
$context = stream_context_create(array('http' => array('header' => "X-WSSE: {$x_wsse}\r\n" . "User-Agent: HatebuList.alfredworkflow")));
$file = file_get_contents($url, 0, $context);
$json = json_decode($file);
$dataList = $json;
foreach ($dataList->bookmarks as $data) {
    $entry = $data->entry;
    $title = $entry->title;
    $count = $entry->count;
    $snippet = trimAll($entry->snippet);
    $wf_url = $entry->url;
    $wf_title = $title;
    $wf_description = $snippet;
    $wf->result(time(), $wf_url, $wf_title, $wf_description, 'icon.png');
}
echo $wf->toxml();
示例#24
0
$encodes = array();
// url
$url_encode = urlencode($query);
if ($url_encode != $query) {
    $encodes["URL Encoded"] = $url_encode;
}
// HTML
/*$html_encode = '';
$table = get_html_translation_table(HTML_ENTITIES);
for ($i = 0, $l = sizeof($chars); $i < $l; $i++) {
	$html_encode .= $table[$chars[$i]] ? $table[$chars[$i]] : $chars[$i];
}
$html_encode = htmlentities($html_encode, ENT_QUOTES, 'UTF-8', false);*/
$html_encode = htmlentities($query, ENT_QUOTES, 'UTF-8');
if ($html_encode != $query) {
    $encodes["HTML Encoded"] = $html_encode;
}
// base64
$base64_encode = base64_encode($query);
if ($base64_encode != $query) {
    $encodes["base64 Encoded"] = $base64_encode;
}
$encodes = prepare_output($encodes);
foreach ($encodes as $key => $value) {
    $w->result($key, $value, $value, $key, 'icon.png', 'yes');
}
if (count($w->results()) == 0) {
    $w->result('encode', $query, 'Nothing useful resulted', 'The encoded strings were the same as your query', 'icon.png', 'yes');
}
echo $w->toxml();
// ****************
if (!isset($query)) {
    $query = urlencode("css");
}
$data = json_decode(file_get_contents("data.json"));
$extras = array();
$extras2 = array();
$found = array();
// Fix bug #6
$query = strtolower(trim($query));
foreach ($data as $key => $result) {
    $value = strtolower(trim($result->title));
    $description = utf8_decode(strip_tags($result->description));
    if (strpos($value, $query) === 0) {
        if (!isset($found[$value])) {
            $found[$value] = true;
            $w->result($result->title, $result->url, $result->title . " " . $result->stats, $result->description, "icon.png");
        }
    } else {
        if (strpos($value, $query) > 0) {
            if (!isset($found[$value])) {
                $found[$value] = true;
                $extras[$key] = $result;
            }
        } else {
            if (strpos($description, $query) !== false) {
                if (!isset($found[$value])) {
                    $found[$value] = true;
                    $extras2[$key] = $result;
                }
            }
        }
/**
 * 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();
}
示例#27
0
if (!$w->get('check_for_updates', $s)) {
    $w->set('check_for_updates', 'TRUE', $s);
}
if (!$w->get('update_ignore_date', $s)) {
    $w->set('update_ignore_date', time(), $s);
}
// Check for updates. Initially had coded for checking once a day but Alfred initiated duplicate calls which was screwing up the timing. This check isn't expensive so I'll just do it every time.
if ($w->get('check_for_updates', $s) == 'TRUE') {
    $now = time();
    $r = get_data('https://raw.github.com/nickwynja/darksky-alfred/master/version.json');
    $v = json_decode($r);
    $update_version = (double) $v->updated_version;
    $update_ignore_date = (int) $w->get('update_ignore_date', $s);
    $since_update_ignored = $now - $update_ignore_date;
    if ($update_version > $current_version && $since_update_ignored > 259200) {
        $w->result('download', $v->download_url, "Version {$v->updated_version} of Dark Sky is available. Update now?", "This will take you to the download page.", 'icon.png');
        $w->result('dont-update', 'dont-update', "No thanks. Tell me what the weather's like...", "Check the forcast and ignore updates for a few days.", 'icon.png');
        $w->result('never-update', 'never-update', "Don't ever check for updates.", "Just show me the forecast.", 'icon.png');
        echo $w->toxml();
        die;
    }
}
// Check for user set variables
if ($latitude !== 'FALSE' && $longitude !== 'FALSE') {
    $l->latitude = $latitude;
    $l->longitude = $longitude;
} else {
    // Get location data from IP address
    $ip = get_data('http://ipecho.net/plain');
    $r = get_data('http://freegeoip.net/json/' . $ip);
    $l = json_decode($r);
示例#28
0
    if ($proxy) {
        $shell_command .= ' --proxy ' . escapeshellarg($proxy);
        file_put_contents("/tmp/alfred", $shell_command . "\n", FILE_APPEND);
    }
    exec($shell_command, $output, $return_var);
    $data = implode($output);
    $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.png', 'no');
} else {
    $repos = $repos->repositories;
    foreach ($repos as $repo) {
        $lang = $repo->language ? ' (' . $repo->language . ')' : '';
        $repo->full_name = $repo->username . '/' . $repo->name;
        $w->result('git-' . $repo->full_name, $repo->url, $repo->name . '' . $lang, $repo->description, 'icon.png', 'yes');
    }
    if (count($w->results()) == 0) {
        $w->result('git', null, 'No Repository found', 'No Repository found that match your query', 'icon.png', 'no');
    }
}
echo $w->toxml();
示例#29
0
$icon = PARSER_URL . "classes/" . $type . "/" . $parser->icon;
$data = file_get_contents(PARSER_URL . "data/" . $parser->data_filename);
$wf = new Workflows();
$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);
示例#30
0
<?php

require 'workflow.php';
require 'functions.php';
require 'GoogleMapClient.php';
isset($argv[1]) && ($query = trim($argv[1]));
$workflow = new Workflows();
$res = $workflow->write($query, GoogleMapClient::APIKEY);
$title = $res ? 'success' : 'failure';
$workflow->result($query, $query, $title, 'set google api key failure', 'icon.png');