update alfred package manager workflow version
@@ -3,6 +3,6 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>darkthemeuid</key>
|
||||
<string>theme.bundled.moderndark</string>
|
||||
<string>theme.fileimport.BAECBFEC-91C7-4AF2-B452-631DC7F13F80</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 8.2 KiB |
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 181 KiB |
|
Before Width: | Height: | Size: 171 KiB After Width: | Height: | Size: 120 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 49 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 167 KiB After Width: | Height: | Size: 121 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 47 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 110 KiB After Width: | Height: | Size: 74 KiB |
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Alcatraz extends Repo
|
||||
{
|
||||
protected $id = 'alcatraz';
|
||||
protected $url = 'http://alcatraz.io';
|
||||
protected $has_db = true;
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
foreach($this->pkgs as $categories) {
|
||||
// plugins, color_scheme, project_templates, file_templates
|
||||
foreach($categories as $category) {
|
||||
foreach($category as $pkg) {
|
||||
if ($this->check($pkg, $query)) {
|
||||
$this->cache->w->result(
|
||||
$pkg->url,
|
||||
$this->makeArg($pkg->name, $pkg->url),
|
||||
$pkg->name,
|
||||
$pkg->description,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
}
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The search URL here isn’t quiet right, since Alcatraz doesn't have a
|
||||
// a web UI for its "repo"
|
||||
$this->noResults($query, $this->cache->dbs[$this->id]);
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Alcatraz();
|
||||
// echo $repo->search('avia');
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Apm extends Repo
|
||||
{
|
||||
protected $id = 'apm';
|
||||
protected $url = 'https://atom.io';
|
||||
protected $search_url = 'https://atom.io/packages/search?q=';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$data = $this->cache->get_query_regex(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->search_url}{$query}",
|
||||
'/<div class="package-list">([\s\S]*?)<div class="footer-pad">/i'
|
||||
);
|
||||
|
||||
$this->pkgs = explode('<div class="grid-cell">', $data[0]);
|
||||
array_shift($this->pkgs);
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
// make params
|
||||
preg_match('/<h4 class="card-name">([\s\S]*?)<\/h4>/i', $pkg, $matches);
|
||||
$title = trim(strip_tags($matches[1]));
|
||||
|
||||
preg_match(
|
||||
'/<span class="css-truncate-target card-description">([\s\S]*?)<\/span>/i',
|
||||
$pkg,
|
||||
$matches
|
||||
);
|
||||
|
||||
$description = html_entity_decode(trim(strip_tags($matches[1])));
|
||||
|
||||
preg_match('/<a href="[\s\S]*?" class="author">([\s\S]*?)<\/a>/i', $pkg, $matches);
|
||||
$author = trim(strip_tags($matches[1]));
|
||||
// $version = trim(strip_tags($matches[1]));
|
||||
|
||||
$this->cache->w->result(
|
||||
$title,
|
||||
$this->makeArg($title, "{$this->url}/packages/{$title}"),
|
||||
"{$title} ~ by {$author}", // "v{$version}"
|
||||
$description,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Atom();
|
||||
// echo $repo->search('q');
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class AptGet extends Repo
|
||||
{
|
||||
protected $id = 'apt-get';
|
||||
protected $url = 'https://apps.ubuntu.com';
|
||||
protected $search_url = 'https://apps.ubuntu.com/cat/search/?q=';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_regex(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->search_url}{$query}",
|
||||
'/<tr>([\s\S]*?)<\/tr>/i'
|
||||
);
|
||||
|
||||
foreach($this->pkgs as $item) {
|
||||
preg_match('/<p>(.*?)<\/p>/i', $item, $matches);
|
||||
$name = trim(strip_tags($matches[1]));
|
||||
|
||||
preg_match('/<h3>([\s\S]*?)<\/h3>/i', $item, $matches);
|
||||
$description = trim(strip_tags($matches[1]));
|
||||
|
||||
$this->cache->w->result(
|
||||
$name,
|
||||
$this->makeArg($name, "{$this->url}/cat/applications/{$name}"),
|
||||
$name,
|
||||
$description,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new AptGet();
|
||||
// echo $repo->search('leaflet');
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Bower extends Repo
|
||||
{
|
||||
protected $id = 'bower';
|
||||
protected $kind = 'components';
|
||||
protected $url = 'http://bower.io';
|
||||
protected $search_url = 'https://bower.herokuapp.com/packages/search/';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_json(
|
||||
'bower',
|
||||
$query,
|
||||
"{$this->search_url}{$query}"
|
||||
);
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
$url = str_replace("git://", "https://", $pkg->url);
|
||||
$version = "*";
|
||||
$this->cache->w->result(
|
||||
$pkg->url,
|
||||
$this->makeArg($pkg->name, $url, "\"{$pkg->name}\": \"{$version}\""),
|
||||
$pkg->name,
|
||||
$url,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// Only show results up to the $max_return
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->url}/search/?q={$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Bower();
|
||||
// echo $repo->search('leaflet');
|
||||
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Brew extends Repo
|
||||
{
|
||||
protected $id = 'brew';
|
||||
protected $kind = 'plugins';
|
||||
protected $url = 'http://braumeister.org';
|
||||
protected $search_url = 'http://braumeister.org/search/';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
// special case - exact match
|
||||
$redirect_check = $this->cache->get_query_data(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->search_url}{$query}"
|
||||
);
|
||||
|
||||
$exact_match = (
|
||||
$redirect_check === '<html><body>You are being <a href="'.$this->url.'/formula/'.$query.'">redirected</a>.</body></html>'
|
||||
? true
|
||||
: false
|
||||
);
|
||||
|
||||
if ($exact_match) {
|
||||
$this->pkgs = $this->cache->get_query_regex(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->url}/formula/{$query}",
|
||||
'/<div id="content">([\s\S]*?)<div id="deps">/i',
|
||||
1
|
||||
);
|
||||
} else {
|
||||
$this->pkgs = $this->cache->get_query_regex(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->search_url}{$query}",
|
||||
'/<div class="formula (odd|even)">([\s\S]*?)<\/div>/i',
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
if ($exact_match) {
|
||||
// name
|
||||
$title = $query;
|
||||
|
||||
// version
|
||||
preg_match('/<strong class="version spec-stable">([\s\S]*?)<\/strong>/i', $pkg, $matches);
|
||||
$version = trim(strip_tags($matches[0]));
|
||||
|
||||
// details
|
||||
preg_match('/Homepage: <em><a href="(.*?)">(.*?)<\/a>/i', $pkg, $matches);
|
||||
$details = strip_tags($matches[1]);
|
||||
} else {
|
||||
// name
|
||||
preg_match('/<a class="formula" href="(.*?)">(.*?)<\/a>/i', $pkg, $matches);
|
||||
$title = strip_tags($matches[0]);
|
||||
|
||||
// version
|
||||
preg_match('/<strong class="version spec-stable">([\s\S]*?)<\/strong>/i', $pkg, $matches);
|
||||
$version = trim(strip_tags($matches[0]));
|
||||
|
||||
// url
|
||||
preg_match('/Homepage: <a href="(.*?)">(.*?)<\/a>/i', $pkg, $matches);
|
||||
$details = strip_tags($matches[1]);
|
||||
}
|
||||
|
||||
$this->cache->w->result(
|
||||
$title,
|
||||
"{$this->url}/formula/{$title}",
|
||||
"{$title} v{$version}",
|
||||
$details,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Brew();
|
||||
// echo $repo->search('pk');
|
||||
@@ -1,116 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
ini_set('memory_limit', '-1');
|
||||
error_reporting(0);
|
||||
|
||||
require_once('Workflows.php');
|
||||
|
||||
class Cache {
|
||||
public $cache_age = 14;
|
||||
public $dbs = array(
|
||||
"alcatraz" => "https://raw.githubusercontent.com/mneorr/alcatraz-packages/master/packages.json",
|
||||
"apple" => "http://cocoadocs.org/apple_documents.jsonp", // CocoaDocs
|
||||
"cocoa" => "http://cocoadocs.org/documents.jsonp",
|
||||
"grunt" => "http://gruntjs.com/plugin-list.json",
|
||||
"gulp" => "http://npmsearch.com/query?fields=name,keywords,rating,description,author,modified,homepage,version,license&q=keywords:gulpplugin,gulpfriendly&size=9999&sort=rating:desc&start=0",
|
||||
"raspbian" => "http://archive.raspbian.org/raspbian/dists/wheezy/main/binary-armhf/Packages",
|
||||
"yo" => "http://yeoman-generator-list.herokuapp.com/"
|
||||
);
|
||||
public $query_file = "queries";
|
||||
|
||||
public function __construct() {
|
||||
$this->w = new Workflows();
|
||||
|
||||
$q = $this->w->read($this->query_file.'.json');
|
||||
$this->queries = $q ? (array)$q : array();
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
$this->w->write($this->queries, $this->query_file.'.json');
|
||||
}
|
||||
|
||||
public function get_query_data($id, $query, $url) {
|
||||
if (!$query) { return array(); }
|
||||
return $this->w->request($url);
|
||||
}
|
||||
|
||||
public function get_db($id) {
|
||||
if (!array_key_exists($id, $this->dbs)) { return array(); }
|
||||
$name = $id;
|
||||
|
||||
$pkgs = $this->w->read($name.'.json');
|
||||
$timestamp = $this->w->filetime($name.'.json');
|
||||
if (!$pkgs || $timestamp < (time() - $this->cache_age * 86400)) {
|
||||
$data = $this->w->request( $this->dbs[$id] );
|
||||
if (substr($this->dbs[$id], -5) == 'jsonp') { $data = preg_replace('/.+?([\[{].+[\]}]).+/','$1',$data); } // clean jsonp wrapper
|
||||
|
||||
$this->w->write($data, $name.'.json');
|
||||
$pkgs = json_decode( $data );
|
||||
} else if (!$pkgs) {
|
||||
$pkgs = array();
|
||||
}
|
||||
return $pkgs;
|
||||
}
|
||||
|
||||
public function get_query_json($id, $query, $url) {
|
||||
if (!$query) { return array(); }
|
||||
$name = $id.'.'.$query;
|
||||
|
||||
$pkgs = $this->w->read($name.'.json');
|
||||
$timestamp = $this->w->filetime($name.'.json');
|
||||
if (!$pkgs || $timestamp < (time() - $this->cache_age * 86400)) {
|
||||
$data = $this->w->request($url);
|
||||
if (substr($url, -5) == 'jsonp') { $data = preg_replace('/.+?([\[{].+[\]}]).+/','$1',$data); } // clean jsonp wrapper
|
||||
$this->w->write($data, $name.'.json');
|
||||
$this->queries[$name] = time();
|
||||
$pkgs = json_decode( $data );
|
||||
} else if (!$pkgs) {
|
||||
$pkgs = array();
|
||||
}
|
||||
return $pkgs;
|
||||
}
|
||||
|
||||
public function get_query_regex($id, $query, $url, $regex, $regex_pos = 1) {
|
||||
if (!$query) { return array(); }
|
||||
$name = $id.'.'.$query;
|
||||
|
||||
$pkgs = $this->w->read($name.'.json');
|
||||
$timestamp = $this->w->filetime($name.'.json');
|
||||
if (!$pkgs || $timestamp < (time() - $this->cache_age * 86400) || 1) { // update - Add || 1 for debuggin
|
||||
$data = $this->w->request($url);
|
||||
preg_match_all($regex, $data, $matches);
|
||||
$data = $matches[$regex_pos];
|
||||
$this->w->write($data, $name.'.json');
|
||||
$pkgs = is_string($data) ? json_decode( $data ) : $data;
|
||||
$this->queries[$name] = time();
|
||||
} else if (!$pkgs) {
|
||||
$pkgs = array();
|
||||
}
|
||||
return $pkgs;
|
||||
}
|
||||
|
||||
public function update_db($id) {
|
||||
$data = $this->w->request( $this->dbs[$id] );
|
||||
|
||||
// clean jsonp wrapper
|
||||
$data = preg_replace('/.+?({.+}).+/','$1',$data);
|
||||
|
||||
$this->w->write($data, $id.'.json');
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function clear() {
|
||||
// remove db json files
|
||||
foreach($this->dbs as $key => $url) {
|
||||
$this->w->delete($key.'.json');
|
||||
|
||||
}
|
||||
|
||||
// remove query json files
|
||||
foreach($this->queries as $key => $timestamp) {
|
||||
$this->w->delete($key.'.json');
|
||||
}
|
||||
$this->queries = array();
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Chef extends Repo
|
||||
{
|
||||
protected $id = 'chef';
|
||||
protected $kind = 'cookbooks';
|
||||
protected $url = 'https://supermarket.chef.io';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_json(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->url}/api/v1/search?q={$query}"
|
||||
)->items;
|
||||
|
||||
foreach ($this->pkgs as $pkg) {
|
||||
if ($this->check($pkg, $query, 'cookbook_name', 'cookbook_description')) {
|
||||
$title = $pkg->cookbook_name;
|
||||
|
||||
// add author to title
|
||||
if (isset($pkg->cookbook_maintainer)) {
|
||||
$title .= " by {$pkg->cookbook_maintainer}";
|
||||
}
|
||||
|
||||
$this->cache->w->result(
|
||||
$pkg->cookbook_name,
|
||||
$this->makeArg(
|
||||
$pkg->cookbook_name,
|
||||
"{$this->url}/cookbooks/{$pkg->cookbook_name}"
|
||||
),
|
||||
$title,
|
||||
$pkg->cookbook_description,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
}
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->url}/cookbooks/{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Chef();
|
||||
// echo $repo->search('apt');
|
||||
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Cocoa extends Repo
|
||||
{
|
||||
protected $id = 'cocoa';
|
||||
protected $kind = 'libraries';
|
||||
protected $url = 'http://cocoadocs.org';
|
||||
protected $search_url = 'http://cocoadocs.org/?q=';
|
||||
protected $has_db = true;
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
// For debugging, uncommenting this will bypass the cached copy
|
||||
// of the repo
|
||||
// $this->pkgs = $this->cache->get_query_json(
|
||||
// $this->id,
|
||||
// $query,
|
||||
// "http://cocoadocs.org/?q=you/{$query}"
|
||||
// );
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
|
||||
// make params
|
||||
if ($this->check($pkg, $query, 'name', 'summary')) {
|
||||
$title = $pkg->name;
|
||||
if (isset($pkg->main_version)) { $title .= " (v{$pkg->main_version})"; }
|
||||
if (isset($pkg->user)) { $title .= " ~ {$pkg->user}"; }
|
||||
|
||||
$url = (isset($pkg->url)) ? $pkg->url : $pkg->doc_url;
|
||||
$details = (isset($pkg->summary)) ? $pkg->summary : $pkg->framework;
|
||||
|
||||
$icon = (isset($pkg->url)) ? 'xcode' : "{$this->id}";
|
||||
|
||||
$this->cache->w->result(
|
||||
$pkg->name,
|
||||
$this->makeArg($pkg->name, $url),
|
||||
$title,
|
||||
$details,
|
||||
"icon-cache/{$icon}.png"
|
||||
);
|
||||
}
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Cocoa();
|
||||
// echo $repo->search('test');
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Composer extends Repo
|
||||
{
|
||||
protected $id = 'composer';
|
||||
protected $url = 'https://packagist.org';
|
||||
protected $search_url = 'https://packagist.org/search/?q=';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_regex(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->search_url}{$query}",
|
||||
'/<li data-url="(.*?)">([\s\S]*?)<\/li>/i',
|
||||
2
|
||||
);
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
|
||||
// make params
|
||||
preg_match('/<a(.*?)<\/a>/i', $pkg, $matches);
|
||||
$title = strip_tags($matches[0]);
|
||||
|
||||
preg_match('/<p class="package-description">([\s\S]*?)<\/p>/i', $pkg, $matches);
|
||||
$details = strip_tags($matches[1]);
|
||||
|
||||
$this->cache->w->result(
|
||||
$title,
|
||||
$this->makeArg($title, "{$this->url}/packages/{$title}"),
|
||||
$title,
|
||||
$details,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Composer();
|
||||
// echo $repo->search('c');
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Crates extends Repo
|
||||
{
|
||||
protected $id = 'crates';
|
||||
protected $kind = 'libraries';
|
||||
protected $url = 'http://crates.io';
|
||||
protected $search_url = 'https://crates.io/api/v1/crates?page=1&per_page=100&q=';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_json(
|
||||
'crates',
|
||||
$query,
|
||||
"{$this->search_url}{$query}"
|
||||
)->crates;
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
$url = str_replace("git://", "https://", $pkg->repository);
|
||||
$this->cache->w->result(
|
||||
$pkg->id,
|
||||
$this->makeArg($pkg->name, $url, "\"{$pkg->name}\"=\"{$pkg->max_version}\""),
|
||||
$pkg->name,
|
||||
count($pkg->description) ? trim($pkg->description) : $url,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// Only show results up to the $max_return
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->url}/search?q={$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Crates();
|
||||
// echo $repo->search('glob');
|
||||
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Docker extends Repo
|
||||
{
|
||||
protected $id = 'docker';
|
||||
protected $kind = 'images';
|
||||
protected $url = 'https://hub.docker.com';
|
||||
protected $search_url = 'https://index.docker.io/v1/search?q=';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_json(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->search_url}{$query}"
|
||||
);
|
||||
|
||||
foreach($this->pkgs->results as $pkg) {
|
||||
|
||||
// make params
|
||||
$title = $pkg->name;
|
||||
$repository = ($pkg->is_official ) ? '_' : 'r';
|
||||
$url = $this->url . '/'. $repository . '/'. $pkg->name;
|
||||
$description = $pkg->description;
|
||||
|
||||
$this->cache->w->result(
|
||||
$title,
|
||||
$this->makeArg($title, $url),
|
||||
$title.' ~ '.$pkg->star_count,
|
||||
$description,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Docker();
|
||||
// echo $repo->search('ng');
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Gems extends Repo
|
||||
{
|
||||
protected $id = 'gems';
|
||||
protected $kind = 'gems';
|
||||
protected $url = 'https://rubygems.org';
|
||||
protected $search_url = 'https://rubygems.org/search?utf8=%E2%9C%93&query=';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_json(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->url}/api/v1/search?query={$query}"
|
||||
);
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
if ($this->check($pkg, $query, 'name', 'info')) {
|
||||
$title = $pkg->name;
|
||||
|
||||
$this->cache->w->result(
|
||||
$title,
|
||||
$this->makeArg($title, $pkg->project_uri),
|
||||
$title,
|
||||
$pkg->info,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
}
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Gems();
|
||||
// echo $repo->search('cap');
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Gradle extends Repo
|
||||
{
|
||||
protected $id = 'gradle';
|
||||
protected $kind = 'libraries';
|
||||
protected $url = 'https://bintray.com/bintray/jcenter';
|
||||
protected $search_url = 'https://bintray.com/search?query=';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_json(
|
||||
$this->id,
|
||||
$query,
|
||||
"https://api.bintray.com/search/packages/maven?q=*{$query}*"
|
||||
)->response->docs;
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
|
||||
// make params
|
||||
$title = "{$pkg->a} (v{$pkg->latestVersion})";
|
||||
$url = "{$this->url}/{$pkg->id}/view";
|
||||
$details = "GroupId: {$pkg->id}";
|
||||
|
||||
$this->cache->w->result(
|
||||
$pkg->a,
|
||||
$this->makeArg($pkg->id, $url, "{$pkg->id}:{$pkg->latestVersion}"),
|
||||
$title,
|
||||
$details,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Gradle();
|
||||
// echo $repo->search('leaflet');
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Grunt extends Repo
|
||||
{
|
||||
protected $id = 'grunt';
|
||||
protected $kind = 'plugins';
|
||||
protected $url = 'http://gruntjs.com';
|
||||
protected $search_url = 'http://gruntjs.com/plugins/';
|
||||
protected $has_db = true;
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
foreach($this->pkgs->aaData as $pkg) {
|
||||
|
||||
// make params
|
||||
if ($this->check($pkg, $query, 'name', 'ds')) {
|
||||
// remove grunt- from title
|
||||
$title = str_replace('grunt-', '', $pkg->name);
|
||||
|
||||
// add author to title
|
||||
if (isset($pkg->author)) {
|
||||
$title .= " by {$pkg->author}";
|
||||
}
|
||||
$url = "https://www.npmjs.org/package/{$pkg->name}";
|
||||
|
||||
// Uncomment to skip deprecated plugins
|
||||
// if (strpos($plugin->description, "DEPRECATED") !== false) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
$this->cache->w->result(
|
||||
$pkg->name,
|
||||
$this->makeArg($pkg->name, $url),
|
||||
$title,
|
||||
$pkg->ds,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Grunt();
|
||||
// echo $repo->search('contrib');
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Hex extends Repo
|
||||
{
|
||||
protected $id = 'hex';
|
||||
protected $kind = 'components';
|
||||
protected $url = 'https://hex.pm';
|
||||
protected $search_url = 'https://hex.pm/api/packages?search=';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_json(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->search_url}{$query}"
|
||||
);
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
$url = str_replace('api/', '', $pkg->url);
|
||||
$this->cache->w->result(
|
||||
$pkg->url,
|
||||
$this->makeArg($pkg->name, $url),
|
||||
$pkg->name, $url,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Hex();
|
||||
// echo $repo->search('test');
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Maven extends Repo
|
||||
{
|
||||
protected $id = 'maven';
|
||||
protected $kind = 'libraries';
|
||||
protected $url = 'http://search.maven.org';
|
||||
protected $search_url = 'http://search.maven.org/#search%%7Cga%%7C1%%7C';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_json(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->url}/solrsearch/select?q={$query}&rows=10&wt=json"
|
||||
)->response->docs;
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
|
||||
// make params
|
||||
$title = "{$pkg->a} (v{$pkg->latestVersion})";
|
||||
$url = "{$this->url}/#artifactdetails%%7C{$pkg->g}%%7C{$pkg->a}%%7C{$pkg->latestVersion}%%7C{$pkg->p}";
|
||||
$details = "GroupId: {$pkg->id}";
|
||||
|
||||
$this->cache->w->result(
|
||||
$pkg->a,
|
||||
$this->makeArg($pkg->a, $url),
|
||||
$title,
|
||||
$details,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Maven();
|
||||
// echo $repo->search('leaflet');
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Npm extends Repo
|
||||
{
|
||||
protected $id = 'npm';
|
||||
protected $url = 'https://npms.io';
|
||||
protected $search_url = 'https://api.npms.io/v2/search?q=';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_json(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->search_url}{$query}&size={$this->max_return}"
|
||||
);
|
||||
|
||||
foreach($this->pkgs->results as $pkg) {
|
||||
$p = $pkg->package;
|
||||
$name = $p->name;
|
||||
|
||||
$this->cache->w->result(
|
||||
$this->id,
|
||||
$this->makeArg($name, $p->links->npm, "{$p->name}: {$p->version}"),
|
||||
$name,
|
||||
$p->description,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Npm();
|
||||
// echo $repo->search('gr');
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Pear extends Repo
|
||||
{
|
||||
protected $id = 'pear';
|
||||
protected $url = 'http://pear.php.net';
|
||||
protected $search_url = 'http://pear.php.net/search.php?q=';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_regex(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->search_url}{$query}",
|
||||
'/<li>([\s\S]*?)<\/li>/i'
|
||||
);
|
||||
|
||||
array_shift($this->pkgs); // remove register link
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
|
||||
// make params
|
||||
// name
|
||||
preg_match('/<a(.*?)>(.*?)<\/a>/i', $pkg, $matches);
|
||||
$title = strip_tags($matches[0]);
|
||||
|
||||
// url
|
||||
$details = strip_tags(substr($pkg, strpos($pkg, ":")+2));
|
||||
|
||||
$this->cache->w->result(
|
||||
$title,
|
||||
$this->makeArg($title, "{$this->url}/package/{$title}"),
|
||||
$title,
|
||||
$details,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Pear();
|
||||
// echo $repo->search('test');
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Puppet extends Repo
|
||||
{
|
||||
protected $id = 'puppet';
|
||||
protected $url = 'https://forge.puppetlabs.com';
|
||||
protected $search_url = 'https://forgeapi.puppetlabs.com/v3/modules?query=';
|
||||
protected $kind = 'modules';
|
||||
|
||||
public function search($query) {
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_json(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->search_url}{$query}&limit={$this->max_return}"
|
||||
)->results;
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
$name = "{$pkg->owner->username}/{$pkg->name}";
|
||||
$version = $pkg->current_release->version;
|
||||
$description = $pkg->current_release->metadata->summary;
|
||||
|
||||
$this->cache->w->result(
|
||||
$name,
|
||||
$this->makeArg($name, "{$this->url}/{$name}"),
|
||||
"{$name} ~ v{$version}",
|
||||
$description,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Puppet();
|
||||
// echo $repo->search('nginx');
|
||||
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Pypi extends Repo
|
||||
{
|
||||
protected $id = 'pypi';
|
||||
protected $url = 'https://pypi.python.org';
|
||||
protected $search_url = 'https://pypi.python.org/pypi?%3Aaction=search&submit=search&term=';
|
||||
protected $min_query_length = 3;
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_regex(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->search_url}{$query}",
|
||||
'/<tr class="(.*?)">([\s\S]*?)<\/tr>/i',
|
||||
2
|
||||
);
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
|
||||
// make params
|
||||
// name
|
||||
preg_match('/<a href="(.*?)">(.*?)<\/a>/i', $pkg, $matches);
|
||||
$title = str_replace(" ", " ", strip_tags($matches[0]));
|
||||
$url = strip_tags($matches[1]);
|
||||
|
||||
preg_match_all('/<td>([\s\S]*?)<\/td>/i', $pkg, $matches);
|
||||
$downloads = strip_tags($matches[1][1]);
|
||||
$details = strip_tags($matches[1][2]);
|
||||
|
||||
$this->cache->w->result(
|
||||
$title,
|
||||
$this->makeArg($title, "{$this->url}{$url}"),
|
||||
"{$title} {$downloads}",
|
||||
$details,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// $repo = new Pypi();
|
||||
// echo $repo->search('lib');
|
||||
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Repo.php');
|
||||
|
||||
class Raspbian extends Repo
|
||||
{
|
||||
protected $id = 'raspbian';
|
||||
protected $url = 'http://www.raspbian.org';
|
||||
protected $search_url = 'https://packages.debian.org/wheezy/';
|
||||
protected $has_db = true;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Clean up & update cached DB
|
||||
$pkgs = explode("\n\n", $this->pkgs);
|
||||
array_pop($pkgs); // remove file end
|
||||
|
||||
$this->pkgs = [];
|
||||
for ($i = 0, $l = count($pkgs); $i < $l; $i++) {
|
||||
$pkg = explode("\n", $pkgs[$i]);
|
||||
// TODO: Figure out why `new stdClass()` doesn't work
|
||||
$new_pkg = (object) array();
|
||||
foreach ($pkg as $datum) {
|
||||
$data = explode(': ', $datum);
|
||||
$new_pkg->$data[0] = $data[1];
|
||||
}
|
||||
$this->pkgs[] = $new_pkg;
|
||||
}
|
||||
}
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
if ($this->check($pkg, $query, 'Package', 'Description')) {
|
||||
$title = $pkg->Package;
|
||||
|
||||
// add version to title
|
||||
if (isset($pkg->Version)) {
|
||||
$title .= " ~ v{$pkg->Version}";
|
||||
}
|
||||
// add author to title
|
||||
if (isset($pkg->Maintainer)) {
|
||||
preg_match("/([^\\n]+?) <[^\\n]+?>/i", $pkg->Maintainer, $matches);
|
||||
$title .= " ~ by {$matches[1]}";
|
||||
}
|
||||
$url = "{$this->search_url}{$pkg->Package}";
|
||||
|
||||
$this->cache->w->result(
|
||||
$pkg->Package,
|
||||
$this->makeArg($pkg->Package, $url),
|
||||
$title,
|
||||
$pkg->description,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
}
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Raspbian();
|
||||
// echo $repo->search('lib');
|
||||
@@ -1,192 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
|
||||
class Repo
|
||||
{
|
||||
/**
|
||||
* The ID of the Repo we will search
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* The text to display when returning a "nothing found" message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $kind = 'packages';
|
||||
|
||||
/**
|
||||
* The URL to the repo itself
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* The minimum number of characters to require before attempting a search
|
||||
*
|
||||
* Increase this for slow repositories
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $min_query_length = 1;
|
||||
|
||||
/**
|
||||
* The maximum number of results to return to Alfred
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $max_return = 25;
|
||||
|
||||
/**
|
||||
* Whether or not the Repo in question has a cached DB
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $has_db = false;
|
||||
|
||||
/**
|
||||
* The Cache object, used to share search code amongst Repos
|
||||
*
|
||||
* @var \WillFarrell\AlfredPkgMan\Cache
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* An object or array of each package/item found from searching the Repo
|
||||
*
|
||||
* @var StdObject|Array
|
||||
*/
|
||||
protected $pkgs;
|
||||
|
||||
/**
|
||||
* Factory method to create a particular type of Repo
|
||||
*
|
||||
* @param string $id The ID of the Repo subclass
|
||||
* @param boolean $has_db Determine whether we use the cached DB to search
|
||||
* or search the repo live via an HTTP request
|
||||
* @param array $options An associative array, containing only keys that
|
||||
* match the properties existing in this class
|
||||
* @return Class One of the many Repo subclasses
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->cache = new Cache();
|
||||
|
||||
if ($this->has_db) {
|
||||
// get DB here if not dynamic search
|
||||
$data = $this->cache->get_db($this->id);
|
||||
$this->pkgs = $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a pipe-delimited string for use in key-modified actions
|
||||
*
|
||||
* @param string $id The unique ID of a package/repo item
|
||||
* @param string $url The URL to the package/item in question
|
||||
* @param string $pkgstr The package string used in a config file ie `"$pkgname": "$version"`
|
||||
* @return string A pipe-delimited string of these values
|
||||
* Corresponds to `id | url | pkgstr` in Alfred
|
||||
*/
|
||||
protected function makeArg($id, $url, $pkgstr = null)
|
||||
{
|
||||
if ($pkgstr == null) { $pkgstr = $id; }
|
||||
return "{$id}|{$url}|{$pkgstr}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the query meets the minimum length defined
|
||||
*
|
||||
* Prevents searching a repo with very short strings, and provides a
|
||||
* "minimum length not met" result to Alfred
|
||||
*
|
||||
* @param string $query The query being searched
|
||||
* @return boolean True if the query meets the minimum, false otherwise
|
||||
*/
|
||||
protected function hasMinQueryLength($query)
|
||||
{
|
||||
$has_min_length = true;
|
||||
|
||||
if ( strlen($query) === 0 ) {
|
||||
$has_min_length = false;
|
||||
} elseif (strlen($query) < $this->min_query_length) {
|
||||
$this->cache->w->result(
|
||||
"{$this->id}-min",
|
||||
$query,
|
||||
"Minimum query length of {$this->min_query_length} not met.",
|
||||
'',
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
$has_min_length = false;
|
||||
}
|
||||
|
||||
return $has_min_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a specified package's name or description matches,
|
||||
* case-insensitively, the specified query
|
||||
*
|
||||
* @param StdObject $pkg Package object/array
|
||||
* @param string $query The query to filter for
|
||||
* @return boolean False if the query does not match name or
|
||||
* description, true otherwise
|
||||
*/
|
||||
protected function check(
|
||||
$pkg,
|
||||
$query,
|
||||
$name_key = 'name',
|
||||
$desc_key = 'description'
|
||||
) {
|
||||
if (stripos($pkg->$name_key, $query) !== false
|
||||
|| (isset($pkg->$desc_key) && stripos($pkg->$desc_key, $query) !== false)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a "no results" message to Alfred
|
||||
*
|
||||
* @param string $query The query being searched
|
||||
* @return void
|
||||
*/
|
||||
protected function noResults($query, $search_url)
|
||||
{
|
||||
if (count($this->cache->w->results()) == 0) {
|
||||
$this->cache->w->result(
|
||||
"{$this->id}-search",
|
||||
$search_url,
|
||||
"No {$this->kind} were found that matched \"{$query}\"",
|
||||
"Click to see the results for yourself",
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the results into an XML string for Alfred to consume, adding
|
||||
* a final "visit the website" item
|
||||
*
|
||||
* @return string XML string representation of the array
|
||||
*/
|
||||
public function xml()
|
||||
{
|
||||
$this->cache->w->result(
|
||||
"{$this->id}-www-".time(),
|
||||
"{$this->url}/",
|
||||
'Go to the website',
|
||||
"{$this->url}",
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
return $this->cache->w->toxml();
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Rpm extends Repo
|
||||
{
|
||||
protected $id = 'rpm';
|
||||
protected $url = 'http://rpmfind.net';
|
||||
protected $search_url = 'http://rpmfind.net/linux/rpm2html/search.php?query=';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$this->pkgs = $this->cache->get_query_regex(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->search_url}{$query}",
|
||||
'/<tr bgcolor=\'\'>([\s\S]*?)<\/tr>/i'
|
||||
);
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
// make params
|
||||
preg_match('/<a href=[\'"](.*?)[\'"]>(.*?)<\/a>/i', $pkg, $matches);
|
||||
$title = strip_tags($matches[2]);
|
||||
$url = strip_tags($matches[1]);
|
||||
|
||||
preg_match_all('/<td>([\s\S]*?)<\/td>/i', $pkg, $matches);
|
||||
$dist = trim(strip_tags($matches[1][2]));
|
||||
$details = trim(strip_tags($matches[1][1]));
|
||||
|
||||
$this->cache->w->result(
|
||||
$title,
|
||||
$this->makeArg($title, $url),
|
||||
$title,
|
||||
"{$dist} - {$details}",
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Rpm();
|
||||
// echo $repo->search('r');
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Stpm extends Repo
|
||||
{
|
||||
protected $id = 'stpm';
|
||||
protected $url = 'https://packagecontrol.io';
|
||||
protected $search_url = 'https://packagecontrol.io/search/';
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
$data = $this->cache->get_query_regex(
|
||||
$this->id,
|
||||
$query,
|
||||
"{$this->search_url}{$query}",
|
||||
'/<ul class="packages results">([\s\S]*?)<\/ul>/i'
|
||||
);
|
||||
|
||||
$this->pkgs = explode('<li class="package">', $data[0]);
|
||||
array_shift($this->pkgs);
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
// make params
|
||||
preg_match('/<h3>([\s\S]*?)<\/h3>/i', $pkg, $matches);
|
||||
$title = trim(strip_tags($matches[1]));
|
||||
|
||||
preg_match(
|
||||
'/<div class="description">([\s\S]*?)<\/div>/i',
|
||||
$pkg,
|
||||
$matches
|
||||
);
|
||||
|
||||
$description = html_entity_decode(trim(strip_tags($matches[1])));
|
||||
|
||||
preg_match('/<span class="author">([\s\S]*?)<\/span>/i', $pkg, $matches);
|
||||
$author = trim(strip_tags($matches[1]));
|
||||
// $version = trim(strip_tags($matches[1]));
|
||||
|
||||
$this->cache->w->result(
|
||||
$title,
|
||||
$this->makeArg($title, "{$this->url}/packages/{$title}"),
|
||||
"{$title} ~ {$author}", // "v{$version}"
|
||||
$description,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, "{$this->search_url}{$query}");
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Atom();
|
||||
// echo $repo->search('q');
|
||||
@@ -1,529 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* Name: Workflows
|
||||
* Description: This PHP class object provides several useful functions for retrieving, parsing,
|
||||
* and formatting data to be used with Alfred 2 Workflows.
|
||||
* Author: David Ferguson (@jdfwarrior)
|
||||
* Revised: 6/6/2013
|
||||
* Version: 0.3.3
|
||||
*/
|
||||
class Workflows {
|
||||
|
||||
private $cache;
|
||||
private $data;
|
||||
private $bundle;
|
||||
private $path;
|
||||
private $home;
|
||||
private $results;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Class constructor function. Initializes all class variables. Accepts one optional parameter
|
||||
* of the workflow bundle id in the case that you want to specify a different bundle id. This
|
||||
* would adjust the output directories for storing data.
|
||||
*
|
||||
* @param $bundleid - optional bundle id if not found automatically
|
||||
* @return none
|
||||
*/
|
||||
function __construct( $bundleid=null )
|
||||
{
|
||||
$this->path = exec('pwd');
|
||||
$this->home = exec('printf "$HOME"');
|
||||
|
||||
if ( file_exists( 'info.plist' ) ):
|
||||
$this->bundle = $this->get( 'bundleid', 'info.plist' );
|
||||
endif;
|
||||
|
||||
if ( !is_null( $bundleid ) ):
|
||||
$this->bundle = $bundleid;
|
||||
endif;
|
||||
|
||||
$this->cache = getenv('alfred_workflow_cache');
|
||||
$this->data = getenv('alfred_workflow_data');
|
||||
|
||||
if ( !file_exists( $this->cache ) ):
|
||||
exec("mkdir '".$this->cache."'");
|
||||
endif;
|
||||
|
||||
if ( !file_exists( $this->data ) ):
|
||||
exec("mkdir '".$this->data."'");
|
||||
endif;
|
||||
|
||||
$this->results = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Accepts no parameter and returns the value of the bundle id for the current workflow.
|
||||
* If no value is available, then false is returned.
|
||||
*
|
||||
* @param none
|
||||
* @return false if not available, bundle id value if available.
|
||||
*/
|
||||
public function bundle()
|
||||
{
|
||||
if ( is_null( $this->bundle ) ):
|
||||
return false;
|
||||
else:
|
||||
return $this->bundle;
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Accepts no parameter and returns the value of the path to the cache directory for your
|
||||
* workflow if it is available. Returns false if the value isn't available.
|
||||
*
|
||||
* @param none
|
||||
* @return false if not available, path to the cache directory for your workflow if available.
|
||||
*/
|
||||
public function cache()
|
||||
{
|
||||
if ( is_null( $this->bundle ) ):
|
||||
return false;
|
||||
else:
|
||||
if ( is_null( $this->cache ) ):
|
||||
return false;
|
||||
else:
|
||||
return $this->cache;
|
||||
endif;
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Accepts no parameter and returns the value of the path to the storage directory for your
|
||||
* workflow if it is available. Returns false if the value isn't available.
|
||||
*
|
||||
* @param none
|
||||
* @return false if not available, path to the storage directory for your workflow if available.
|
||||
*/
|
||||
public function data()
|
||||
{
|
||||
if ( is_null( $this->bundle ) ):
|
||||
return false;
|
||||
else:
|
||||
if ( is_null( $this->data ) ):
|
||||
return false;
|
||||
else:
|
||||
return $this->data;
|
||||
endif;
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Accepts no parameter and returns the value of the path to the current directory for your
|
||||
* workflow if it is available. Returns false if the value isn't available.
|
||||
*
|
||||
* @param none
|
||||
* @return false if not available, path to the current directory for your workflow if available.
|
||||
*/
|
||||
public function path()
|
||||
{
|
||||
if ( is_null( $this->path ) ):
|
||||
return false;
|
||||
else:
|
||||
return $this->path;
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Accepts no parameter and returns the value of the home path for the current user
|
||||
* Returns false if the value isn't available.
|
||||
*
|
||||
* @param none
|
||||
* @return false if not available, home path for the current user if available.
|
||||
*/
|
||||
public function home()
|
||||
{
|
||||
if ( is_null( $this->home ) ):
|
||||
return false;
|
||||
else:
|
||||
return $this->home;
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Returns an array of available result items
|
||||
*
|
||||
* @param none
|
||||
* @return array - list of result items
|
||||
*/
|
||||
public function results()
|
||||
{
|
||||
return $this->results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Convert an associative array into XML format
|
||||
*
|
||||
* @param $a - An associative array to convert
|
||||
* @param $format - format of data being passed (json or array), defaults to array
|
||||
* @return - XML string representation of the array
|
||||
*/
|
||||
public function toxml( $a=null, $format='array' ) {
|
||||
|
||||
if ( $format == 'json' ):
|
||||
$a = json_decode( $a, TRUE );
|
||||
endif;
|
||||
|
||||
if ( is_null( $a ) && !empty( $this->results ) ):
|
||||
$a = $this->results;
|
||||
elseif ( is_null( $a ) && empty( $this->results ) ):
|
||||
return false;
|
||||
endif;
|
||||
|
||||
$items = new SimpleXMLElement("<items></items>"); // Create new XML element
|
||||
|
||||
foreach( $a as $b ): // Lop through each object in the array
|
||||
$c = $items->addChild( 'item' ); // Add a new 'item' element for each object
|
||||
$c_keys = array_keys( $b ); // Grab all the keys for that item
|
||||
foreach( $c_keys as $key ): // For each of those keys
|
||||
if ( $key == 'uid' ):
|
||||
if ( $b[$key] === null || $b[$key] === '' ):
|
||||
continue;
|
||||
else:
|
||||
$c->addAttribute( 'uid', $b[$key] );
|
||||
endif;
|
||||
elseif ( $key == 'arg' ):
|
||||
$c->addAttribute( 'arg', $b[$key] );
|
||||
$c->$key = $b[$key];
|
||||
elseif ( $key == 'type' ):
|
||||
$c->addAttribute( 'type', $b[$key] );
|
||||
elseif ( $key == 'valid' ):
|
||||
if ( $b[$key] == 'yes' || $b[$key] == 'no' ):
|
||||
$c->addAttribute( 'valid', $b[$key] );
|
||||
endif;
|
||||
elseif ( $key == 'autocomplete' ):
|
||||
if ( $b[$key] === null || $b[$key] === '' ):
|
||||
continue;
|
||||
else:
|
||||
$c->addAttribute( 'autocomplete', $b[$key] );
|
||||
endif;
|
||||
elseif ( $key == 'icon' ):
|
||||
if ( substr( $b[$key], 0, 9 ) == 'fileicon:' ):
|
||||
$val = substr( $b[$key], 9 );
|
||||
$c->$key = $val;
|
||||
$c->$key->addAttribute( 'type', 'fileicon' );
|
||||
elseif ( substr( $b[$key], 0, 9 ) == 'filetype:' ):
|
||||
$val = substr( $b[$key], 9 );
|
||||
$c->$key = $val;
|
||||
$c->$key->addAttribute( 'type', 'filetype' );
|
||||
else:
|
||||
$c->$key = $b[$key];
|
||||
endif;
|
||||
else:
|
||||
$c->$key = $b[$key];
|
||||
endif;
|
||||
endforeach;
|
||||
endforeach;
|
||||
|
||||
return $items->asXML(); // Return XML string representation of the array
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Remove all items from an associative array that do not have a value
|
||||
*
|
||||
* @param $a - Associative array
|
||||
* @return bool
|
||||
*/
|
||||
private function empty_filter( $a ) {
|
||||
if ( $a == '' || $a == null ): // if $a is empty or null
|
||||
return false; // return false, else, return true
|
||||
else:
|
||||
return true;
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Save values to a specified plist. If the first parameter is an associative
|
||||
* array, then the second parameter becomes the plist file to save to. If the
|
||||
* first parameter is string, then it is assumed that the first parameter is
|
||||
* the label, the second parameter is the value, and the third parameter is
|
||||
* the plist file to save the data to.
|
||||
*
|
||||
* @param $a - associative array of values to save
|
||||
* @param $b - the value of the setting
|
||||
* @param $c - the plist to save the values into
|
||||
* @return string - execution output
|
||||
*/
|
||||
public function set( $a=null, $b=null, $c=null )
|
||||
{
|
||||
if ( is_array( $a ) ):
|
||||
if ( file_exists( $b ) ):
|
||||
if ( file_exists( $this->path.'/'.$b ) ):
|
||||
$b = $this->path.'/'.$b;
|
||||
endif;
|
||||
elseif ( file_exists( $this->data."/".$b ) ):
|
||||
$b = $this->data."/".$b;
|
||||
elseif ( file_exists( $this->cache."/".$b ) ):
|
||||
$b = $this->cache."/".$b;
|
||||
else:
|
||||
$b = $this->data."/".$b;
|
||||
endif;
|
||||
else:
|
||||
if ( file_exists( $c ) ):
|
||||
if ( file_exists( $this->path.'/'.$c ) ):
|
||||
$c = $this->path.'/'.$c;
|
||||
endif;
|
||||
elseif ( file_exists( $this->data."/".$c ) ):
|
||||
$c = $this->data."/".$c;
|
||||
elseif ( file_exists( $this->cache."/".$c ) ):
|
||||
$c = $this->cache."/".$c;
|
||||
else:
|
||||
$c = $this->data."/".$c;
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( is_array( $a ) ):
|
||||
foreach( $a as $k => $v ):
|
||||
exec( 'defaults write "'. $b .'" '. $k .' "'. $v .'"');
|
||||
endforeach;
|
||||
else:
|
||||
exec( 'defaults write "'. $c .'" '. $a .' "'. $b .'"');
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Read a value from the specified plist
|
||||
*
|
||||
* @param $a - the value to read
|
||||
* @param $b - plist to read the values from
|
||||
* @return bool false if not found, string if found
|
||||
*/
|
||||
public function get( $a, $b ) {
|
||||
|
||||
if ( file_exists( $b ) ):
|
||||
if ( file_exists( $this->path.'/'.$b ) ):
|
||||
$b = $this->path.'/'.$b;
|
||||
endif;
|
||||
elseif ( file_exists( $this->data."/".$b ) ):
|
||||
$b = $this->data."/".$b;
|
||||
elseif ( file_exists( $this->cache."/".$b ) ):
|
||||
$b = $this->cache."/".$b;
|
||||
else:
|
||||
return false;
|
||||
endif;
|
||||
|
||||
exec( 'defaults read "'. $b .'" '.$a, $out ); // Execute system call to read plist value
|
||||
|
||||
if ( $out == "" ):
|
||||
return false;
|
||||
endif;
|
||||
|
||||
$out = $out[0];
|
||||
return $out; // Return item value
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Read data from a remote file/url, essentially a shortcut for curl
|
||||
*
|
||||
* @param $url - URL to request
|
||||
* @param $options - Array of curl options
|
||||
* @return result from curl_exec
|
||||
*/
|
||||
public function request( $url=null, $options=null )
|
||||
{
|
||||
if ( is_null( $url ) ):
|
||||
return false;
|
||||
endif;
|
||||
|
||||
$defaults = array( // Create a list of default curl options
|
||||
CURLOPT_RETURNTRANSFER => true, // Returns the result as a string
|
||||
CURLOPT_URL => $url, // Sets the url to request
|
||||
CURLOPT_FRESH_CONNECT => true
|
||||
);
|
||||
|
||||
if ( $options ):
|
||||
foreach( $options as $k => $v ):
|
||||
$defaults[$k] = $v;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
array_filter( $defaults, // Filter out empty options from the array
|
||||
array( $this, 'empty_filter' ) );
|
||||
|
||||
$ch = curl_init(); // Init new curl object
|
||||
curl_setopt_array( $ch, $defaults ); // Set curl options
|
||||
$out = curl_exec( $ch ); // Request remote data
|
||||
$err = curl_error( $ch );
|
||||
curl_close( $ch ); // End curl request
|
||||
|
||||
if ( $err ):
|
||||
return $err;
|
||||
else:
|
||||
return $out;
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Allows searching the local hard drive using mdfind
|
||||
*
|
||||
* @param $query - search string
|
||||
* @return array - array of search results
|
||||
*/
|
||||
public function mdfind( $query )
|
||||
{
|
||||
exec('mdfind "'.$query.'"', $results);
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cache file
|
||||
*
|
||||
* @author @willfarrell
|
||||
* @param string $a Path to the file to delete
|
||||
* @return void
|
||||
*/
|
||||
public function delete( $a )
|
||||
{
|
||||
if ( file_exists( $a ) ):
|
||||
if ( file_exists( $this->path.'/'.$a ) ):
|
||||
unlink($this->path.'/'.$a);
|
||||
endif;
|
||||
elseif ( file_exists( $this->data."/".$a ) ):
|
||||
unlink($this->data."/".$a);
|
||||
elseif ( file_exists( $this->cache."/".$a ) ):
|
||||
unlink($this->cache."/".$a);
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Accepts data and a string file name to store data to local file as cache
|
||||
*
|
||||
* @param array - data to save to file
|
||||
* @param file - filename to write the cache data to
|
||||
* @return none
|
||||
*/
|
||||
public function write( $a, $b )
|
||||
{
|
||||
if ( file_exists( $b ) ):
|
||||
if ( file_exists( $this->path.'/'.$b ) ):
|
||||
$b = $this->path.'/'.$b;
|
||||
endif;
|
||||
elseif ( file_exists( $this->data."/".$b ) ):
|
||||
$b = $this->data."/".$b;
|
||||
elseif ( file_exists( $this->cache."/".$b ) ):
|
||||
$b = $this->cache."/".$b;
|
||||
else:
|
||||
$b = $this->data."/".$b;
|
||||
endif;
|
||||
|
||||
if ( is_array( $a ) ):
|
||||
$a = json_encode( $a );
|
||||
file_put_contents( $b, $a );
|
||||
return true;
|
||||
elseif ( is_string( $a ) ):
|
||||
file_put_contents( $b, $a );
|
||||
return true;
|
||||
else:
|
||||
return false;
|
||||
endif;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Returns data from a local cache file
|
||||
*
|
||||
* @param file - filename to read the cache data from
|
||||
* @return false if the file cannot be found, the file data if found. If the file
|
||||
* format is json encoded, then a json object is returned.
|
||||
*/
|
||||
public function read( $a, $array = false )
|
||||
{
|
||||
if ( file_exists( $a ) ):
|
||||
if ( file_exists( $this->path.'/'.$a ) ):
|
||||
$a = $this->path.'/'.$a;
|
||||
endif;
|
||||
elseif ( file_exists( $this->data."/".$a ) ):
|
||||
$a = $this->data."/".$a;
|
||||
elseif ( file_exists( $this->cache."/".$a ) ):
|
||||
$a = $this->cache."/".$a;
|
||||
else:
|
||||
return false;
|
||||
endif;
|
||||
|
||||
$out = file_get_contents( $a );
|
||||
if ( !is_null( json_decode( $out ) ) && !$array ):
|
||||
$out = json_decode( $out );
|
||||
elseif ( !is_null( json_decode( $out ) ) && !$array ):
|
||||
$out = json_decode( $out, true );
|
||||
endif;
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the file modification time
|
||||
*
|
||||
* @author @willfarrell
|
||||
* @param string $a Path to a file
|
||||
* @return integer Returns the file modification time, or false
|
||||
*/
|
||||
public function filetime( $a )
|
||||
{
|
||||
if ( file_exists( $a ) ):
|
||||
if ( file_exists( $this->path.'/'.$a ) ):
|
||||
return filemtime($this->path.'/'.$a);
|
||||
endif;
|
||||
elseif ( file_exists( $this->data."/".$a ) ):
|
||||
return filemtime($this->data.'/'.$a);
|
||||
elseif ( file_exists( $this->cache."/".$a ) ):
|
||||
return filemtime($this->cache.'/'.$a);
|
||||
endif;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Helper function that just makes it easier to pass values into a function
|
||||
* and create an array result to be passed back to Alfred
|
||||
*
|
||||
* @param $uid - the uid of the result, should be unique
|
||||
* @param $arg - the argument that will be passed on
|
||||
* @param $title - The title of the result item
|
||||
* @param $sub - The subtitle text for the result item
|
||||
* @param $icon - the icon to use for the result item
|
||||
* @param $valid - sets whether the result item can be actioned
|
||||
* @param $auto - the autocomplete value for the result item
|
||||
* @return array - array item to be passed back to Alfred
|
||||
*/
|
||||
public function result( $uid, $arg, $title, $sub, $icon, $valid='yes', $auto=null, $type=null )
|
||||
{
|
||||
$temp = array(
|
||||
'uid' => $uid,
|
||||
'arg' => $arg,
|
||||
'title' => $title,
|
||||
'subtitle' => $sub,
|
||||
'icon' => $icon,
|
||||
'valid' => $valid,
|
||||
'autocomplete' => $auto,
|
||||
'type' => $type
|
||||
);
|
||||
|
||||
if ( is_null( $type ) ):
|
||||
unset( $temp['type'] );
|
||||
endif;
|
||||
|
||||
array_push( $this->results, $temp );
|
||||
|
||||
return $temp;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
namespace WillFarrell\AlfredPkgMan;
|
||||
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
class Yo extends Repo
|
||||
{
|
||||
protected $id = 'yo';
|
||||
protected $kind = 'generators';
|
||||
protected $url = 'http://yeoman.io';
|
||||
protected $search_url = 'http://yeoman.io/generators/';
|
||||
protected $has_db = true;
|
||||
|
||||
public function search($query)
|
||||
{
|
||||
if (!$this->hasMinQueryLength($query)) {
|
||||
return $this->xml();
|
||||
}
|
||||
|
||||
foreach($this->pkgs as $pkg) {
|
||||
// make params
|
||||
if ($this->check($pkg, $query)) {
|
||||
$title = $pkg->name;
|
||||
|
||||
// add author to title
|
||||
if (isset($pkg->owner)) {
|
||||
$title .= " by {$pkg->owner}";
|
||||
}
|
||||
|
||||
$this->cache->w->result(
|
||||
$pkg->name,
|
||||
$this->makeArg($pkg->name, $pkg->website),
|
||||
$title,
|
||||
$pkg->description,
|
||||
"icon-cache/{$this->id}.png"
|
||||
);
|
||||
}
|
||||
|
||||
// only search till max return reached
|
||||
if ( count ( $this->cache->w->results() ) == $this->max_return ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->noResults($query, $this->search_url);
|
||||
|
||||
return $this->xml();
|
||||
}
|
||||
}
|
||||
|
||||
// Test code, uncomment to debug this script from the command-line
|
||||
// $repo = new Yo();
|
||||
// echo $repo->search('ang');
|
||||
@@ -1,12 +0,0 @@
|
||||
<?php
|
||||
// ****************
|
||||
//error_reporting(0);
|
||||
require_once('Cache.php');
|
||||
require_once('Repo.php');
|
||||
|
||||
$cache = new WillFarrell\AlfredPkgMan\Cache();
|
||||
|
||||
$cache->clear();
|
||||
|
||||
//$cache->w->result( 'cachedb', 'NA', 'Downloading... ', 'You\'ll get a notification when it\'s done. It should be soon.', 'icon.png', 'no' );
|
||||
// ****************
|
||||
@@ -1,12 +0,0 @@
|
||||
<?php
|
||||
// ****************
|
||||
//error_reporting(0);
|
||||
require_once('Cache.php');
|
||||
|
||||
$cache = new Cache();
|
||||
|
||||
foreach($cache->dbs as $key => $url) {
|
||||
$cache->update_db($key);
|
||||
}
|
||||
// ****************
|
||||
?>
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"WillFarrell\\AlfredPkgMan\\": "src/"
|
||||
}
|
||||
},
|
||||
"description": "https://github.com/willfarrell/alfred-pkgman-workflow",
|
||||
"require": {
|
||||
"php": ">=7.1",
|
||||
"ext-json": "*",
|
||||
"ext-curl": "*",
|
||||
"joetannenbaum/alfred-workflow": "^0.1.2",
|
||||
"samdark/hydrator": "^1.0.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^2.18"
|
||||
},
|
||||
"version": "4.1.0",
|
||||
"name": "willfarrell/alfred-pkgman-workflow"
|
||||
}
|
||||
2147
synced/Alfred.alfredpreferences/workflows/user.workflow.20EF45FD-4209-46C0-83A6-10900A0338A9/composer.lock
generated
Normal file
|
Before Width: | Height: | Size: 296 KiB After Width: | Height: | Size: 146 KiB |
|
Before Width: | Height: | Size: 186 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 8.2 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 86 KiB After Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 47 KiB |
|
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 7.6 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 192 KiB After Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 45 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 682 B |
|
After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 607 KiB |