From f53469e020965cadb96f33490200c09a0fca56c4 Mon Sep 17 00:00:00 2001 From: Tyler Eich Date: Fri, 15 Feb 2013 20:27:31 -0500 Subject: [PATCH 1/5] Updated with new files from @jdfwarrior --- workflows.php | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) mode change 100644 => 100755 workflows.php diff --git a/workflows.php b/workflows.php old mode 100644 new mode 100755 index 0b80053..046cccd --- a/workflows.php +++ b/workflows.php @@ -249,10 +249,9 @@ public function set( $a=null, $b=null, $c=null ) { if ( is_array( $a ) ): if ( file_exists( $b ) ): - $temp = $this->path.'/'.$b; - if ( $b == $temp ): - $b = $this->path."/".$b; - endif; + 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 ) ): @@ -262,9 +261,8 @@ public function set( $a=null, $b=null, $c=null ) endif; else: if ( file_exists( $c ) ): - $temp = $this->path.'/'.$c; - if ( $c == $temp ): - $c = $this->path."/".$c; + if ( file_exists( $this->path.'/'.$c ) ): + $c = $this->path.'/'.$c; endif; elseif ( file_exists( $this->data."/".$c ) ): $c = $this->data."/".$c; @@ -295,11 +293,10 @@ public function set( $a=null, $b=null, $c=null ) public function get( $a, $b ) { if ( file_exists( $b ) ): - $temp = $this->path.'/'.$b; - if ( $b == $temp ): - $b = $this->path."/".$b; + if ( file_exists( $this->path.'/'.$b ) ): + $b = $this->path.'/'.$b; endif; - elseif ( file_exists( $this->data."/".$b ) ): + elseif ( file_exists( $this->data."/".$b ) ): $b = $this->data."/".$b; elseif ( file_exists( $this->cache."/".$b ) ): $b = $this->cache."/".$b; @@ -383,9 +380,8 @@ public function mdfind( $query ) public function write( $a, $b ) { if ( file_exists( $b ) ): - $temp = $this->path.'/'.$b; - if ( $b == $temp ): - $b = $this->path."/".$b; + if ( file_exists( $this->path.'/'.$b ) ): + $b = $this->path.'/'.$b; endif; elseif ( file_exists( $this->data."/".$b ) ): $b = $this->data."/".$b; @@ -418,9 +414,8 @@ public function write( $a, $b ) public function read( $a ) { if ( file_exists( $a ) ): - $temp = $path.'/'.$a; - if ( $a === $temp ): - $a = $this->path."/".$a; + if ( file_exists( $this->path.'/'.$a ) ): + $a = $this->path.'/'.$a; endif; elseif ( file_exists( $this->data."/".$a ) ): $a = $this->data."/".$a; From ca491b11b104f56ac0ea6a9fe9200b98329fe2e9 Mon Sep 17 00:00:00 2001 From: Tyler Eich Date: Sat, 16 Feb 2013 16:38:46 -0500 Subject: [PATCH 2/5] Added a function to check for an internet connection --- workflows.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/workflows.php b/workflows.php index 046cccd..ff3e082 100755 --- a/workflows.php +++ b/workflows.php @@ -468,5 +468,15 @@ public function result( $uid, $arg, $title, $sub, $icon, $valid='yes', $auto=nul return $temp; } - + + public function internet() + { + $internet = @fsockopen("www.google.com",80); + if($internet): + fclose($internet); + return true; + else: + return false; + endif; + } } \ No newline at end of file From 007b8fe5a7120dd79c7e6e954bcfe89f18b02ef8 Mon Sep 17 00:00:00 2001 From: Tyler Eich Date: Fri, 9 May 2014 11:48:31 -0400 Subject: [PATCH 3/5] Initial subtitle processing --- workflows.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/workflows.php b/workflows.php index ff3e082..d2a6ae4 100755 --- a/workflows.php +++ b/workflows.php @@ -29,6 +29,8 @@ function __construct( $bundleid=null ) { $this->path = exec('pwd'); $this->home = exec('printf $HOME'); + var_dump($this); + var_dump(file_exists('info.plist')); if ( file_exists( 'info.plist' ) ): $this->bundle = $this->get( 'bundleid', 'info.plist' ); @@ -179,7 +181,7 @@ public function toxml( $a=null, $format='array' ) { $items = new SimpleXMLElement(""); // Create new XML element - foreach( $a as $b ): // Lop through each object in the array + foreach( $a as $b ): // Loop 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 @@ -207,6 +209,18 @@ public function toxml( $a=null, $format='array' ) { else: $c->$key = $b[$key]; endif; + elseif ( $key == 'subtitle' ): + if ( gettype($b[$key]) == 'array' ): + $subtitle_types = ['shift', 'fn', 'ctrl', 'alt', 'cmd']; + $subtitles = $b[$key]; + $subtitle_keys = array_keys( $subtitles ); + foreach( $subtitle_keys as $subtitle_key ): + $c->$key = $subtitle[$subtitle_key]; + if ( in_array( $subtitle_key, $subtitle_types ) ): + $c->$key->addAttrubite( 'mod', $subtitle_key ); + endif; + endforeach; + endif; else: $c->$key = $b[$key]; endif; @@ -303,14 +317,17 @@ public function get( $a, $b ) { else: return false; endif; + var_dump($b); - exec( 'defaults read "'. $b .'" '.$a, $out ); // Execute system call to read plist value + $out = `defaults read "$b" $a`; // Execute system call to read plist value if ( $out == "" ): return false; endif; - $out = $out[0]; + var_dump($out); + $out = trim($out); + var_dump($out); return $out; // Return item value } @@ -479,4 +496,5 @@ public function internet() return false; endif; } -} \ No newline at end of file +} +$w = new Workflows(); \ No newline at end of file From 8c4ceac9680f8a0cafcd6797a102990c2cd9f29d Mon Sep 17 00:00:00 2001 From: Tyler Eich Date: Fri, 9 May 2014 16:15:56 -0400 Subject: [PATCH 4/5] Working version of subtitle modifiers --- workflows.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/workflows.php b/workflows.php index d2a6ae4..1275015 100755 --- a/workflows.php +++ b/workflows.php @@ -29,8 +29,6 @@ function __construct( $bundleid=null ) { $this->path = exec('pwd'); $this->home = exec('printf $HOME'); - var_dump($this); - var_dump(file_exists('info.plist')); if ( file_exists( 'info.plist' ) ): $this->bundle = $this->get( 'bundleid', 'info.plist' ); @@ -188,7 +186,7 @@ public function toxml( $a=null, $format='array' ) { if ( $key == 'uid' ): $c->addAttribute( 'uid', $b[$key] ); elseif ( $key == 'arg' ): - $c->addAttribute( 'arg', $b[$key] ); + $c->addChild( 'arg', $b[$key]); elseif ( $key == 'type' ): $c->addAttribute( 'type', $b[$key] ); elseif ( $key == 'valid' ): @@ -210,16 +208,18 @@ public function toxml( $a=null, $format='array' ) { $c->$key = $b[$key]; endif; elseif ( $key == 'subtitle' ): - if ( gettype($b[$key]) == 'array' ): + if ( gettype($b[$key]) == 'array' ): $subtitle_types = ['shift', 'fn', 'ctrl', 'alt', 'cmd']; $subtitles = $b[$key]; $subtitle_keys = array_keys( $subtitles ); foreach( $subtitle_keys as $subtitle_key ): - $c->$key = $subtitle[$subtitle_key]; - if ( in_array( $subtitle_key, $subtitle_types ) ): - $c->$key->addAttrubite( 'mod', $subtitle_key ); + $subtitle_element = $c->addChild( 'subtitle', $subtitles[$subtitle_key]); + if ( in_array( $subtitle_key, $subtitle_types, true ) ): + $subtitle_element->addAttribute( 'mod', $subtitle_key ); endif; endforeach; + else: + $c->$key = $b[$key]; endif; else: $c->$key = $b[$key]; @@ -317,7 +317,6 @@ public function get( $a, $b ) { else: return false; endif; - var_dump($b); $out = `defaults read "$b" $a`; // Execute system call to read plist value @@ -325,9 +324,7 @@ public function get( $a, $b ) { return false; endif; - var_dump($out); $out = trim($out); - var_dump($out); return $out; // Return item value } @@ -497,4 +494,3 @@ public function internet() endif; } } -$w = new Workflows(); \ No newline at end of file From 81ee13b71f01de41f541163648394f55f4dee9dc Mon Sep 17 00:00:00 2001 From: Tyler Eich Date: Fri, 9 May 2014 16:58:15 -0400 Subject: [PATCH 5/5] Added to documentation, element support --- workflows.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/workflows.php b/workflows.php index 1275015..5b25999 100755 --- a/workflows.php +++ b/workflows.php @@ -208,12 +208,13 @@ public function toxml( $a=null, $format='array' ) { $c->$key = $b[$key]; endif; elseif ( $key == 'subtitle' ): - if ( gettype($b[$key]) == 'array' ): + if ( gettype( $b[$key] ) == 'array' ): $subtitle_types = ['shift', 'fn', 'ctrl', 'alt', 'cmd']; $subtitles = $b[$key]; $subtitle_keys = array_keys( $subtitles ); + foreach( $subtitle_keys as $subtitle_key ): - $subtitle_element = $c->addChild( 'subtitle', $subtitles[$subtitle_key]); + $subtitle_element = $c->addChild( 'subtitle', $subtitles[$subtitle_key] ); if ( in_array( $subtitle_key, $subtitle_types, true ) ): $subtitle_element->addAttribute( 'mod', $subtitle_key ); endif; @@ -221,6 +222,16 @@ public function toxml( $a=null, $format='array' ) { else: $c->$key = $b[$key]; endif; + elseif ( $key == 'text' && gettype($b[$key]) == 'array' ): + $text_types = ['copy', 'largetype']; + $texts = $b[$key]; + $text_keys = array_keys( $texts ); + + foreach( $text_keys as $text_key ): + if ( in_array( $text_key, $text_types ) ): + $c->addChild( 'text', $texts[$text_key] )->addAttribute( 'type', $text_key ); + endif; + endforeach; else: $c->$key = $b[$key]; endif; @@ -455,13 +466,14 @@ public function read( $a ) * @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 $sub - The subtitle text for the result item; can be an array of mod values or a string * @param $icon - the icon to use for the result item * @param $valid - sets whether the result item can be actioned + * @param $text - array with keys 'copy' and/or 'largetype' and their respective string values * @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 ) + public function result( $uid, $arg, $title, $sub, $icon, $valid='yes', $text=null, $auto=null, $type=null ) { $temp = array( 'uid' => $uid, @@ -470,10 +482,11 @@ public function result( $uid, $arg, $title, $sub, $icon, $valid='yes', $auto=nul 'subtitle' => $sub, 'icon' => $icon, 'valid' => $valid, + 'text' => $text, 'autocomplete' => $auto, 'type' => $type ); - + if ( is_null( $type ) ): unset( $temp['type'] ); endif;