/**
 * 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();
}
 /**
  * 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();
 }
Example #3
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();
 }
 /**
  * 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();
 }
Example #6
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();
 }
Example #7
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();
 }
Example #8
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();
 }
Example #9
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();
}
Example #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();
 }
 function __construct($a = "database.db")
 {
     require_once 'workflows.php';
     $w = new Workflows();
     $this->cache = $w->cache();
     $this->data = $w->data();
     $this->bundle = $w->bundle();
     $this->path = $w->path();
     $this->home = $w->home();
     if (file_exists($this->data . '/' . $a)) {
         $a = $this->data . '/' . $a;
     } elseif (file_exists($this->cache . '/' . $a)) {
         $a = $this->cache . '/' . $a;
     } elseif (file_exists($this->path . '/' . $a)) {
         $a = $this->path . '/' . $a;
     } elseif (file_exists($a)) {
         // do nothing.
     } else {
         $a = $this->data . '/' . $a;
     }
     $this->open($a);
 }
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);
    }
}
<?php

require_once 'workflows.php';
$w = new Workflows();
$w->set('is_spotifious_active', $argv[1], 'settings.plist');
echo "Spotifious activation has been set to  {$argv['1']}";
Example #14
0
<?php

require_once 'workflows.php';
$w = new Workflows();
$current_version = '2.0';
$latitude = isset($argv[1]) ? $argv[1] : '';
// Index 0 is 'darksky.php'
$longitude = isset($argv[2]) ? $argv[2] : '';
$user_unit = isset($argv[3]) ? $argv[3] : '';
function get_data($url)
{
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
// Initialize Settings
$s = 'settings.plist';
$key = $w->get('api_key', $s);
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') {
<?php

// ****************
//error_reporting(0);
require_once 'workflows.php';
$w = new Workflows();
function browserVersion($stats)
{
    $version = 0;
    $support = '';
    foreach ($stats as $key => $val) {
        $key = floatval($key);
        if ($version < $key && $val == 'y') {
            $support = $key . "+";
            break;
        } elseif ($version < $key && strpos($val, 'y x') !== false) {
            $version = $key;
            $support = $key . "-px-";
        } elseif ($version < $key && strpos($val, 'a') !== false) {
            $version = $key;
            $support = $key . "!pa.";
        } elseif ($version < $key && strpos($val, 'p') !== false) {
            $version = $key;
            $support = $key . "w/pl";
        }
    }
    return $support ? $support : "n/a";
}
// cache
if (filemtime("data.json") <= time() - 86400 * 7) {
    $data = json_decode(file_get_contents("https://raw.github.com/Fyrd/caniuse/master/data.json"));
Example #16
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();
<?php

require_once 'workflows.php';
$w = new Workflows();
ini_set('memory_limit', '512M');
//
// Create the library_starred_playlist.json
//
if (!file_exists($w->data() . "/library_starred_playlist.json")) {
    $array_starred_items = array();
    if (file_exists($w->data() . "/library.json")) {
        $json = file_get_contents($w->data() . "/library.json");
        $json = json_decode($json, true);
        foreach ($json as $item) {
            if ($item['data']['starred'] == true) {
                array_push($array_starred_items, $item);
            }
        }
        $w->write($array_starred_items, 'library_starred_playlist.json');
    }
}
//
// Create the playlists.json
//
if (!file_exists($w->data() . "/playlists-tmp.json")) {
    exec('mdfind -name guistate', $results);
    $theUser = "";
    $theGuiStateFile = "";
    foreach ($results as $guistateFile) {
        if (strpos($guistateFile, "Spotify/Users") !== false) {
            $theGuiStateFile = $guistateFile;
Example #18
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();
}
Example #19
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();
Example #20
0
<?php

// ****************
//error_reporting(0);
require_once 'workflows.php';
$w = new Workflows();
function browserVersion($stats)
{
    $version = 0;
    $support = '';
    foreach ($stats as $key => $val) {
        $key = floatval($key);
        if ($version < $key && $val == 'y') {
            $support = $key . "+";
            break;
        } elseif ($version < $key && strpos($val, 'y x') !== false) {
            $version = $key;
            $support = $key . "-px-";
        } elseif ($version < $key && strpos($val, 'a') !== false) {
            $version = $key;
            $support = $key . "!pa.";
        } elseif ($version < $key && strpos($val, 'p') !== false) {
            $version = $key;
            $support = $key . "w/pl";
        }
    }
    return $support ? $support : "n/a";
}
// cache
if (filemtime("data.json") <= time() - 86400 * 7) {
    $data = json_decode(file_get_contents("https://raw.github.com/Fyrd/caniuse/master/data.json"));
Example #21
0
<?php

require_once 'workflows.php';
$w = new Workflows();
if (!isset($query)) {
    $query = "{query}";
}
$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);
Example #22
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();
Example #23
0
<?php

//***********
require_once 'workflows.php';
$w = new Workflows();
if (!isset($query)) {
    $query = <<<EOD
{query}
EOD;
}
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);
Example #24
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();
Example #25
0
<?php

require_once 'workflows.php';
$w = new Workflows();
$q = $argv;
$q = explode(" ", $argv[1], 2);
if ($q[0] == 'token') {
    $w->set('token', $q[1], 'settings.plist');
    echo 'Token added';
} else {
    $post['text'] = $argv[1];
    $token = $w->get('token', 'settings.plist');
    $url = 'https://alpha-api.app.net/stream/0/posts';
    $headers = array('Content-Type: application/json', 'Authorization: Bearer ' . $token);
    connect(1, $url, $headers, $post);
}
function connect($type = 1, $url, $headers, $query)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    if ($type == 1) {
        curl_setopt($ch, CURLOPT_POST, 1);
        if (isset($query)) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query));
        }
    }
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $output = json_decode(curl_exec($ch));
    curl_close($ch);
    if (isset($output->error)) {
Example #26
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
 /** Delete a workflow stage
  */
 public function deleteworkflowAction()
 {
     $this->_flashMessenger->addMessage($this->_noChange);
     if ($this->_request->isPost()) {
         $id = (int) $this->_request->getPost('id');
         $del = $this->_request->getPost('del');
         if ($del == 'Yes' && $id > 0) {
             $workflows = new Workflows();
             $where = 'id = ' . $id;
             $workflows->delete($where);
         }
         $this->_flashMessenger->addMessage(self::DELETED);
         $this->_redirect($this->_redirectUrl . 'workflows');
     } else {
         $id = (int) $this->_request->getParam('id');
         if ($id > 0) {
             $workflows = new Workflows();
             $this->view->workflow = $workflows->fetchRow('id=' . $id);
         }
     }
 }
<?php

require_once 'workflows.php';
$w = new Workflows();
$w->set('max_results', $argv[1], 'settings.plist');
echo "Max results has been set to {$argv['1']}";
Example #29
0
<?php

$parser = ucFirst($type) . "Parser";
define("PARSER_URL", "parsers/autosuggest/");
require_once PARSER_URL . "classes/AutoSuggestParser.php";
require_once PARSER_URL . "classes/" . $type . "/" . $parser . ".php";
require_once 'workflows.php';
$parser = new $parser();
$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;
            }
Example #30
0
<?php

//***********
require_once 'workflows.php';
$w = new Workflows();
if (!isset($query)) {
    $query = <<<EOD
{query}
EOD;
}
$query = urlencode($query);
$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/search/repositories?q=$query"; // preview only
$url = "https://api.github.com/legacy/repos/search/{$query}";
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);
    $repos = json_decode($data);