-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?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'); |