<?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)) {
$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); } exec($shell_command, $output, $return_var); $data = implode($output); $data = substr($data, strrpos($data, "X-GitHub-Request-Id"));
<?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
$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') { $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) {
<?php include_once 'functions.php'; require_once 'workflows.php'; $w = new Workflows(); $ret = $w->get('all_playlists', 'settings.plist'); if ($ret == 'true') { $all_playlists = true; } else { $all_playlists = false; } # increase memory_limit ini_set('memory_limit', '512M'); 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 ($all_playlists == false && $item['data']['starred'] == true || $all_playlists == true) { getTrackArtwork($item['data']['uri'], true); getArtistArtwork($item['data']['album']['artist']['name'], true); getTrackArtwork($item['data']['album']['uri'], true); } } } // // playlists // // retrieve playlist uri from playlist name if (file_exists($w->data() . "/playlists.json")) { $json = file_get_contents($w->data() . "/playlists.json"); $json = json_decode($json, true);
<?php include_once 'functions.php'; require_once 'workflows.php'; $query = $argv[1]; # thanks to http://www.alfredforum.com/topic/1788-prevent-flash-of-no-result $query = iconv("UTF-8-MAC", "UTF-8", $query); $w = new Workflows(); # increase memory_limit if (file_exists($w->data() . "/library.json")) { ini_set('memory_limit', '256M'); } // // Get all_playlists from config // $ret = $w->get('all_playlists', 'settings.plist'); if ($ret == false) { // all_playlists not set // set it to default $w->set('all_playlists', 'false', 'settings.plist'); $ret = 'false'; } if ($ret == 'true') { $all_playlists = true; } else { $all_playlists = false; } // // Get is_spotifious_active from config // $ret = $w->get('is_spotifious_active', 'settings.plist');
<?php require_once 'workflows.php'; $w = new Workflows(); /** Configuration */ $username = $w->get('api.username', 'settings.plist'); $group = $w->get('api.group', 'settings.plist'); $bridge_ip = $w->get('api.bridge_ip', 'settings.plist'); $base_path = "/api/{$username}"; $query = $argv[1]; $control = explode(':', $query); $results = array(); /** Convenience Functions */ function result($r) { global $results; if (!isset($r['icon'])) { $r['icon'] = 'icon.png'; } array_push($results, $r); } function api_arg($args) { global $bridge_ip, $base_path; $args['host'] = $bridge_ip; // PUT is the default HTTP method since most API calls use this. if (!isset($args['method'])) { $args['method'] = 'PUT'; } $args['url'] = $base_path . $args['url']; return json_encode($args);
<?php require_once 'workflows.php'; $w = new Workflows(); $location = $w->get('default.location', 'settings.plist'); if ($location) { $key = "67350ed2995fb73f"; $url = "http://api.wunderground.com/api/{$key}/conditions/" . $location . ".json"; $weather = $w->request($url); $weather = json_decode($weather); $weather = $weather->current_observation; date_default_timezone_set($weather->local_tz_long); $hr = date('H', $weather->local_epoch); if ($hr > 18) { $tod = 'night'; } else { $tod = 'day'; } switch (trim($weather->weather)) { case 'Chance of Rain': $icon = 'icons/007.png'; break; case 'Chance of Snow': $icon = 'icons/014.png'; break; case 'Chance of a Thunderstorm': $icon = 'icons/010.png'; break; case 'Light Drizzle': $icon = 'icons/007.png'; break;
<?php require 'workflows.php'; $w = new Workflows(); $apikey = $w->get('apikey', 'settings.plist'); $mode = $argv[1]; $query = $argv[2]; $query = str_replace(' ', '+', $query); $id; $operation; if (!$apikey) { $w->result('', '', 'Error', 'API key has not been set yet. Set it with the command \'apikey\'.', 'icons/error.png'); } else { if (strpos($query, 'id:') === 0) { $queryArray = explode(":", $query); $id = $queryArray[1]; $operation = $queryArray[2]; switch ($operation) { case 'summary': show_summary(); break; case 'epguide': show_epguide(); break; case 'cast': show_cast(); break; } } else { switch ($mode) { case 'trends':