diff --git a/workflows.php b/workflows.php old mode 100644 new mode 100755 index 0b80053..5b25999 --- a/workflows.php +++ b/workflows.php @@ -179,14 +179,14 @@ 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 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' ): @@ -207,6 +207,31 @@ 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 ): + $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; + 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; @@ -249,10 +274,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 +286,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 +318,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; @@ -307,13 +329,13 @@ public function get( $a, $b ) { return false; endif; - 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]; + $out = trim($out); return $out; // Return item value } @@ -383,9 +405,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 +439,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; @@ -446,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, @@ -461,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; @@ -473,5 +495,15 @@ public function result( $uid, $arg, $title, $sub, $icon, $valid='yes', $auto=nul return $temp; } - -} \ No newline at end of file + + public function internet() + { + $internet = @fsockopen("www.google.com",80); + if($internet): + fclose($internet); + return true; + else: + return false; + endif; + } +}