Jump to content

Opening a URL generated by a Script Filter


Recommended Posts

Hey there, I'm trying to build a Kickstarter workflow that uses their suggestion engine and then directs you to the project's URL. I'm using David Ferguson's PHP Workflow library and basing it heavily off of Google Suggest. I'm retrieving the results just fine and I have the URL, but how do I then pass that URL to the Open URL Output item?

require_once('workflows.php');
$wf = new Workflows();

$orig = "{query}";
$json = $wf->request("http://www.kickstarter.com/projects/search.json?search=&term=".urlencode($orig));
$json = json_decode($json);

foreach($json->projects as $project)
{
	$url = (preg_match('/<a href="(.*?)\?ref=live/', $project->card_html, $matches)) ? $matches[1] : '';
	$wf->result( $project->id, $project->name, $project->name, 'View '.$data.' on Kickstarter', 'icon.png');
}

$results = $wf->results();
if ( count( $results ) == 0 )
{
	$wf->result( 'googlesuggest', $orig, 'No Suggestions', 'No search suggestions found. Search Google for '.$orig, 'icon.png' );
}

echo $wf->toxml();
Edited by wesbaker
Link to comment

Ahh, never mind me. I figured it out. The second parameter in 

$wf->result()

is the parameter that gets passed on. Here's the updated code:

require_once('workflows.php');
$wf = new Workflows();

$orig = "{query}";
$json = $wf->request("http://www.kickstarter.com/projects/search.json?search=&term=".urlencode($orig));
$json = json_decode($json);

foreach($json->projects as $project)
{
	$url = (preg_match('/<a href="(.*?)\?ref=live/i', $project->card_html, $matches)) ? 'http://kickstarter.com'.html_entity_decode($matches[1]) : '';
	$funded = (preg_match('/class=".*?funded".*?<strong>(.*?)<\/strong>/is', $project->card_html, $matches)) ? $matches[1] : '';
	$pledged = (preg_match('/class="pledged".*?<strong>(.*?)<\/strong>/is', $project->card_html, $matches)) ? $matches[1] : '';
	$by = (preg_match('/<span>\s*by(.*?)\s*<\/span>/is', $project->card_html, $matches)) ? trim($matches[1]) : '';
$successful = (stripos($project->card_html, 'project-pledged-successful">') !== FALSE) ? TRUE : FALSE;
	$failed = (stripos($project->card_html, 'project-failed') !== FALSE) ? TRUE : FALSE;
	$status = ($successful OR $failed) ? 'Inactive' : 'Active';
	$project->name = html_entity_decode($project->name, ENT_QUOTES);
	$wf->result($project->id, $url, $project->name, "{$status} | by {$by} | {$funded} funded | {$pledged} pledged", 'icon.png');
}

$results = $wf->results();
if ( count( $results ) == 0 )
{
	$wf->result( 'googlesuggest', $orig, 'No Suggestions', 'No search suggestions found. Search Google for '.$orig, 'icon.png' );
}

echo $wf->toxml();

And here's the download.

Edited by wesbaker
Link to comment
  • 3 months later...
  • 4 months later...

Sorry to resurrect this topic, but the workflow is broken (I suspect Kickstarter updated their API?). Any chance of an update, please?

 

No worries, I was having similar problems. Kickstarter didn't actually change anything, I think the problem was related to Alfred's PHP framework, something changed. It's all fixed now since I'm just using native PHP. The downloads above have been updated.

Edited by wesbaker
Link to comment

No worries, I was having similar problems. Kickstarter didn't actually change anything, I think the problem was related to Alfred's PHP framework, something changed. It's all fixed now since I'm just using native PHP. The downloads above have been updated.

 

Thanks again! It's a huge help once more.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...