diff --git a/README.md b/README.md
index 0e7fd74..ace1293 100644
--- a/README.md
+++ b/README.md
@@ -1,30 +1,20 @@
# 斗图神器
-## 下载
+### 下载
-[下载斗图神器](斗图神器.alfredworkflow)
+[下载斗图神器2.0](source/DouTu.alfredworkflow)
-## 检索
+### 使用
-检索关键字: `dt`
+- 检索关键字: `dt 关键字`
+- 检索快捷键:`Comamnd+Shift+D`
-检索快捷键:`Option+Shift+D`
+### 效果图
-下载所有图片关键字: `dadt` ,近10个进程同时下载(慎用!会造成服务器压力)
+ ![效果图](source/preview.gif)
-> 第一次检索的关键字只会显示第一页预览,搜过的关键字图片会自动缓
-
-## 查阅
-
-查看已下载图片数:`ls ~/Pictures/.DouTu | wc -w`
-
-## 配置
-
-图片默认保存在`~/Pictures/.DouTu/`下面,不要了可以直接删掉`rm -rf ~/Pictures/.DouTu`
-
-想修改图片保存路径可以修改`src/Base.php`文件中的第`33`行
-
-## 效果图
-
-![效果图](preview.gif)
+### 说明
+- 斗图神器依赖于[斗图啦](https://www.doutula.com)网站
+- 2.0采用Golang开发,使用Goroutine提升用户体验
+- 添加剪切板交互方式,感谢[Cong YU](https://github.com/imcuttle)贡献方案
\ No newline at end of file
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..e028478
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,5 @@
+module DouTu2.0
+
+go 1.14
+
+require github.com/PuerkitoBio/goquery v1.5.1
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..6b8db65
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,10 @@
+github.com/PuerkitoBio/goquery v1.5.1 h1:PSPBGne8NIUWw+/7vFBV+kG2J/5MOjbzc7154OaKCSE=
+github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
+github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5zzsLTo=
+github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
+golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
diff --git a/icon.png b/icon.png
deleted file mode 100644
index a2aab3f..0000000
Binary files a/icon.png and /dev/null differ
diff --git a/info.plist b/info.plist
deleted file mode 100644
index 579e86d..0000000
--- a/info.plist
+++ /dev/null
@@ -1,433 +0,0 @@
-
-
-
-
- bundleid
- 506abebdae3a5f98fd9822fc4d32b34d
- connections
-
- 03F0F61A-BDC4-4F63-8F6E-DFF5E4D5396A
-
-
- destinationuid
- 3F7DE7ED-1859-4F14-B259-9452CA0F00D4
- modifiers
- 0
- modifiersubtext
-
- vitoclose
-
-
-
- 3F7DE7ED-1859-4F14-B259-9452CA0F00D4
-
- 8CA223B5-2E6B-4109-B106-2CA8ECBBAC5E
-
-
- destinationuid
- 9D5BFA17-D370-4323-9A4D-5ADABAAF3B94
- modifiers
- 0
- modifiersubtext
-
- vitoclose
-
-
-
- destinationuid
- D80EAEA6-CB95-4518-BB10-EBBE3ADCB8A7
- modifiers
- 0
- modifiersubtext
-
- vitoclose
-
-
-
- B2766B5C-9C5D-4BE4-A748-35C43FCD5C7C
-
-
- destinationuid
- 8CA223B5-2E6B-4109-B106-2CA8ECBBAC5E
- modifiers
- 0
- modifiersubtext
-
- vitoclose
-
-
-
- C00A865B-E24F-4449-9800-1773A74848FB
-
-
- destinationuid
- 345B8C39-BF77-4DCB-931B-569A581DC6E9
- modifiers
- 0
- modifiersubtext
-
- vitoclose
-
-
-
- D80EAEA6-CB95-4518-BB10-EBBE3ADCB8A7
-
-
- destinationuid
- E5AA7E2E-2DD6-4C77-9EDC-9C1F671D3453
- modifiers
- 0
- modifiersubtext
-
- vitoclose
-
-
-
- E5AA7E2E-2DD6-4C77-9EDC-9C1F671D3453
-
-
- destinationuid
- C00A865B-E24F-4449-9800-1773A74848FB
- modifiers
- 0
- modifiersubtext
-
- vitoclose
-
-
-
-
- createdby
- Killua Chen
- description
- 斗图啦,收集了成千上万的撕逼斗图表情包,在这里你可以快速找到想要的表情
- disabled
-
- name
- 斗图神器
- objects
-
-
- config
-
- alfredfiltersresults
-
- alfredfiltersresultsmatchmode
- 0
- argumenttrimmode
- 0
- argumenttype
- 0
- escaping
- 102
- keyword
- dt
- queuedelaycustom
- 3
- queuedelayimmediatelyinitially
-
- queuedelaymode
- 0
- queuemode
- 1
- runningsubtext
- 玩命加载中...
- script
- query=$1
-php src/Index.php 'search' "{query}"&
- scriptargtype
- 0
- scriptfile
-
- subtext
- 正在搜索 '{query}'
- title
- 正在搜索 '{query}'
- type
- 0
- withspace
-
-
- type
- alfred.workflow.input.scriptfilter
- uid
- 8CA223B5-2E6B-4109-B106-2CA8ECBBAC5E
- version
- 2
-
-
- config
-
- action
- 0
- argument
- 0
- focusedappvariable
-
- focusedappvariablename
-
- hotkey
- 0
- hotmod
- 0
- leftcursor
-
- modsmode
- 0
- relatedAppsMode
- 0
-
- type
- alfred.workflow.trigger.hotkey
- uid
- B2766B5C-9C5D-4BE4-A748-35C43FCD5C7C
- version
- 2
-
-
- config
-
- concurrently
-
- escaping
- 102
- script
- php src/Index.php 'download'
- scriptargtype
- 0
- scriptfile
-
- type
- 5
-
- type
- alfred.workflow.action.script
- uid
- 9D5BFA17-D370-4323-9A4D-5ADABAAF3B94
- version
- 2
-
-
- config
-
- lastpathcomponent
-
- onlyshowifquerypopulated
-
- removeextension
-
- text
- {query}
- title
- 斗图
-
- type
- alfred.workflow.output.notification
- uid
- 345B8C39-BF77-4DCB-931B-569A581DC6E9
- version
- 1
-
-
- config
-
- concurrently
-
- escaping
- 102
- script
- cp $1 ~/Pictures/dt-placeholder.jpg
- scriptargtype
- 1
- scriptfile
-
- type
- 5
-
- type
- alfred.workflow.action.script
- uid
- E5AA7E2E-2DD6-4C77-9EDC-9C1F671D3453
- version
- 2
-
-
- config
-
- concurrently
-
- escaping
- 102
- script
- src/file-to-clipboard ~/Pictures/dt-placeholder.jpg
-[ $? -eq "0" ] && echo "🌈 Copied" || echo "❎ Failed"
- scriptargtype
- 0
- scriptfile
-
- type
- 5
-
- type
- alfred.workflow.action.script
- uid
- C00A865B-E24F-4449-9800-1773A74848FB
- version
- 2
-
-
- config
-
- concurrently
-
- escaping
- 102
- script
- php src/Index.php 'preview' "{query}"
- scriptargtype
- 0
- scriptfile
-
- type
- 5
-
- type
- alfred.workflow.action.script
- uid
- D80EAEA6-CB95-4518-BB10-EBBE3ADCB8A7
- version
- 2
-
-
- config
-
- concurrently
-
- escaping
- 102
- script
- php src/Index.php 'downloadAll' 1&
-php src/Index.php 'downloadAll' 100&
-php src/Index.php 'downloadAll' 200&
-php src/Index.php 'downloadAll' 300&
-php src/Index.php 'downloadAll' 400&
-php src/Index.php 'downloadAll' 500&
-php src/Index.php 'downloadAll' 600&
-php src/Index.php 'downloadAll' 700&
-php src/Index.php 'downloadAll' 800&
-php src/Index.php 'downloadAll' 900&
-php src/Index.php 'downloadAll' 1000&
- scriptargtype
- 0
- scriptfile
-
- type
- 5
-
- type
- alfred.workflow.action.script
- uid
- 3F7DE7ED-1859-4F14-B259-9452CA0F00D4
- version
- 2
-
-
- config
-
- argumenttype
- 2
- keyword
- dadt
- subtext
- 可能需要一段时间......
- text
- 下载所有图图片-斗图神器
- withspace
-
-
- type
- alfred.workflow.input.keyword
- uid
- 03F0F61A-BDC4-4F63-8F6E-DFF5E4D5396A
- version
- 1
-
-
- readme
- Keywords are one of Alfred's most commonly used and most useful ways of launching actions. Set a keyword and connect it to the action(s) you want to perform.
-
-Type your keyword into Alfred, followed by your input text if needed, and you'll be on your way to boosting your productivity!
- uidata
-
- 03F0F61A-BDC4-4F63-8F6E-DFF5E4D5396A
-
- note
- 下载所有图片
- xpos
- 180
- ypos
- 570
-
- 345B8C39-BF77-4DCB-931B-569A581DC6E9
-
- xpos
- 870
- ypos
- 440
-
- 3F7DE7ED-1859-4F14-B259-9452CA0F00D4
-
- xpos
- 370
- ypos
- 570
-
- 8CA223B5-2E6B-4109-B106-2CA8ECBBAC5E
-
- xpos
- 330
- ypos
- 120
-
- 9D5BFA17-D370-4323-9A4D-5ADABAAF3B94
-
- xpos
- 680
- ypos
- 120
-
- B2766B5C-9C5D-4BE4-A748-35C43FCD5C7C
-
- xpos
- 40
- ypos
- 120
-
- C00A865B-E24F-4449-9800-1773A74848FB
-
- xpos
- 690
- ypos
- 440
-
- D80EAEA6-CB95-4518-BB10-EBBE3ADCB8A7
-
- xpos
- 360
- ypos
- 440
-
- E5AA7E2E-2DD6-4C77-9EDC-9C1F671D3453
-
- xpos
- 530
- ypos
- 440
-
-
- version
- 3.0
- webaddress
- http://larry666.com
-
-
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..b9d3aaa
--- /dev/null
+++ b/main.go
@@ -0,0 +1,113 @@
+package main
+
+import (
+ "encoding/xml"
+ "flag"
+ "fmt"
+ "github.com/PuerkitoBio/goquery"
+ "io/ioutil"
+ "log"
+ "net/http"
+ "os"
+ "strings"
+ "sync"
+ "time"
+)
+
+const QUERY_URL = "https://www.doutula.com/search?keyword="
+const IMG_PATH = "images"
+
+var wg sync.WaitGroup
+
+type Items struct {
+ XMLName xml.Name `xml:"items"`;
+ Version string `xml:"version,attr"`;
+ Encoding string `xml:"encoding,attr"`
+ Item []Item `xml:"item"`;
+}
+
+type Item struct {
+ XMLName xml.Name `xml:"item"`;
+ Uid int64 `xml:"uid,attr"`
+ Arg string `xml:"arg,attr"`
+ Valid string `xml:"valid,attr"`
+ Icon string `xml:"icon"`
+ Title string `xml:"title"`
+ Autocomplete string `xml:"autocomplete,attr"`
+}
+
+func GetXml(list []Item) string {
+ bs := Items{Version: "1.0", Encoding: "UTF-8"}
+ for _, v := range list {
+ v.Uid = time.Now().UnixNano()
+ v.Valid = "yes"
+ bs.Item = append(bs.Item, v)
+ }
+ data, _ := xml.MarshalIndent(&bs, "", " ");
+ return string(data)
+}
+
+func getContent(query string) {
+ url := QUERY_URL + query
+ resp, err := http.Get(url)
+ if err != nil {
+ log.Fatal("网络请求失败:", err)
+ }
+ if resp.StatusCode != 200 {
+ log.Fatalf("网络请求失败: %d %s", resp.StatusCode, resp.Status)
+ }
+ defer resp.Body.Close()
+
+ doc, err := goquery.NewDocumentFromReader(resp.Body)
+ if err != nil {
+ log.Fatal(err)
+ }
+ list := make([]Item, 0)
+ doc.Find(".img-responsive").Each(func(i int, s *goquery.Selection) {
+ url, _ := s.Attr("data-original")
+ name := s.Next().Text()
+ icon := getFileName(url)
+ wg.Add(1)
+ go saveFile(url)
+ list = append(list, Item{Arg: icon, Title: name, Icon: icon})
+ })
+ xml := GetXml(list)
+ wg.Wait()
+ fmt.Println(xml)
+}
+
+func exist(filename string) bool {
+ _, err := os.Stat(filename)
+ return err == nil || os.IsExist(err)
+}
+
+func getFileName(url string) string {
+ url_list := strings.Split(url, "/")
+ return IMG_PATH + "/" + url_list[len(url_list)-1]
+}
+
+func saveFile(url string) string {
+ defer wg.Done()
+ if !exist(IMG_PATH) {
+ _ = os.Mkdir(IMG_PATH, 0777)
+ }
+ filename := getFileName(url)
+ if exist(filename) {
+ return ""
+ }
+ resp, _ := http.Get(url)
+ defer resp.Body.Close()
+ pix, _ := ioutil.ReadAll(resp.Body)
+
+ if err := ioutil.WriteFile(filename, pix, 0777); err != nil {
+ log.Fatal(err)
+ }
+ return filename
+}
+
+func main() {
+ var query string
+ flag.StringVar(&query, "query", "", "查询内容")
+ flag.Parse()
+ getContent(query)
+}
diff --git a/preview.gif b/preview.gif
deleted file mode 100644
index 76f2d79..0000000
Binary files a/preview.gif and /dev/null differ
diff --git a/source/DouTu.alfredworkflow b/source/DouTu.alfredworkflow
new file mode 100644
index 0000000..0a47139
Binary files /dev/null and b/source/DouTu.alfredworkflow differ
diff --git a/source/preview.gif b/source/preview.gif
new file mode 100644
index 0000000..829f53c
Binary files /dev/null and b/source/preview.gif differ
diff --git a/src/Base.php b/src/Base.php
deleted file mode 100644
index 8c22453..0000000
--- a/src/Base.php
+++ /dev/null
@@ -1,83 +0,0 @@
-/';
-
- //检索网址
- protected $search_url = 'https://www.doutula.com/search?keyword=';
-
- //列表页网址
- protected $list_url = 'https://www.doutula.com/photo/list/?page=';
-
- //检索历史路径
- protected $cache_path = 'cache.txt';
-
- public static $is_query;
-
-
- function __construct()
- {
- $this->store_path = '/Users/' . explode('/', __DIR__)[2] . '/Pictures/.DouTu/';
- }
-
- /**
- * get请求
- * @param $url
- * @return mixed
- */
- public function get($url)
- {
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
- return curl_exec($ch);
- }
-
-
- /**
- * 获取图片路径,并检测下载
- * @param $img
- * @param bool $is_download
- * @return string
- * @author Killua Chen
- */
- public function getImgPath($img, $is_download = false)
- {
- $file_path = $this->store_path . md5($img) . '.png';
- if (!file_exists($this->store_path)) {
- mkdir($this->store_path);
- }
- if ($is_download && !file_exists($file_path)) {
- $file = $this->get($img);
- file_put_contents($file_path, $file);
- }
- return $file_path;
- }
-
- /**
- * 检测图片存储路径
- * @author Killua Chen
- */
- public function checkStorePath()
- {
- if (!file_exists($this->store_path)) {
- mkdir($this->store_path);
- }
- }
-
-
-}
-
diff --git a/src/Index.php b/src/Index.php
deleted file mode 100644
index 1c6956f..0000000
--- a/src/Index.php
+++ /dev/null
@@ -1,138 +0,0 @@
-get($this->search_url . $query);
- preg_match_all($this->img_match, $content, $img_list);
- foreach ($img_list[1] as $i => $item) {
- if ($i < 9) {
- $this->getImgPath($item, true);
- }
- }
- preg_match_all($this->name_match, $content, $name_list);
- foreach ($name_list[1] as &$item) {
- $item = substr($item, strpos($item, '>') + 1);
- }
-
- foreach ($img_list[1] as $i => $img) {
- $img_path = $this->getImgPath($img, false);
- $gif = '';//gif标识
- if (strpos($img, '.gif') !== false) {
- $gif = ' - gif';
- } elseif ($is_gif) {
- continue;
- }
- $w->result(time(), $img, $name_list[1][$i] . $gif, '', $img_path, 'yes');
- }
- if (count($w->results()) == 0) {
- $w->result(time(), '', 'Not Found', 'Are you sure for "' . $query . '" ???', 'icon.png', 'no');
- }
-
- if ($fp = fopen($this->cache_path, 'a+')) {
- $startTime = microtime();
- do {
- $canWrite = flock($fp, LOCK_EX);
- if (!$canWrite) {
- usleep(round(rand(0, 100) * 1000));
- }
- } while ((!$canWrite) && ((microtime() - $startTime) < 1000));
- if ($canWrite) {
- fwrite($fp, "$query\n");
- }
- fclose($fp);
- }
-
- echo $w->toxml();
- }
-
- public function first($query)
- {
- require_once 'workflows.php';
- $w = new Workflows();
- $w->result(time(), $query, "Search 斗图啦 for '{$query}'", '键入Return开始检索', 'icon.png', 'yes');
- echo $w->toxml();
- }
-
- /**
- * 预览图片
- * @param $query
- * @author Killua Chen
- */
- public function preview($query)
- {
- $img_path = $this->getImgPath($query, true);
- echo $img_path;
- }
-
- /**
- * 下载检索历史所有图片
- * @author Killua Chen
- */
- public function download()
- {
- $lines = file_get_contents($this->cache_path);
- unlink($this->cache_path);
- $query_list = array_filter(array_unique(explode("\n", $lines)));
- foreach ($query_list as $query) {
- $content = $this->get($this->search_url . $query);
- preg_match_all($this->img_match, $content, $img_list);
- foreach ($img_list[1] as $img) {
- $this->getImgPath($img, true);
- }
- }
-
- }
-
-
- /**
- * 下载所有图片
- * @param int $start
- * @author Killua Chen
- */
- public function downloadAll($start = 1)
- {
- $this->checkStorePath();
- $is_cs = false;//是否重试
- for ($i = $start; $i < $start + 100; $i++) {
- $content = $this->get($this->list_url . $i);
- preg_match_all($this->img_match, $content, $img_list);
- if (count($img_list[1]) < 10) {
- if (!$is_cs) {
- $i--;
- continue;
- }
- break;
- }
- $is_cs = false;
- foreach ($img_list[1] as $img) {
- $this->getImgPath($img, true);
- }
- }
- }
-
-}
-
-$index = new Index();
-@$index->{$argv[1]}($argv[2]);
diff --git a/src/file-to-clipboard b/src/file-to-clipboard
deleted file mode 100755
index 0547ace..0000000
--- a/src/file-to-clipboard
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/usr/bin/env osascript
-on run args
- set the clipboard to POSIX file (first item of args)
-end
\ No newline at end of file
diff --git a/src/workflows.php b/src/workflows.php
deleted file mode 100644
index cf11c6a..0000000
--- a/src/workflows.php
+++ /dev/null
@@ -1,467 +0,0 @@
-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 = $this->home . "/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/" . $this->bundle;
- $this->data = $this->home . "/Library/Application Support/Alfred 2/Workflow Data/" . $this->bundle;
-
- 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(""); // 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'):
- $c->addAttribute('uid', $b[$key]);
- elseif ($key == 'arg'):
- $c->addAttribute('arg', $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'):
- $c->addAttribute('autocomplete', $b[$key]);
- 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)):
- $b = $this->path . "/" . $b;
- 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)):
- $c = $this->path . "/" . $c;
- 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)):
- $b = $this->path . "/" . $b;
- 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;
- }
-
- /**
- * 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)):
- $b = $this->path . "/" . $b;
- 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)
- {
- if (file_exists($a)):
- $a = $this->path . "/" . $a;
- 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))):
- $out = json_decode($out);
- endif;
-
- return $out;
- }
-
- /**
- * 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;
- }
-
-}
\ No newline at end of file
diff --git "a/\346\226\227\345\233\276\347\245\236\345\231\250-Enter\347\211\210.alfredworkflow" "b/\346\226\227\345\233\276\347\245\236\345\231\250-Enter\347\211\210.alfredworkflow"
deleted file mode 100644
index a618f75..0000000
Binary files "a/\346\226\227\345\233\276\347\245\236\345\231\250-Enter\347\211\210.alfredworkflow" and /dev/null differ
diff --git "a/\346\226\227\345\233\276\347\245\236\345\231\250.alfredworkflow" "b/\346\226\227\345\233\276\347\245\236\345\231\250.alfredworkflow"
deleted file mode 100644
index 3d58a0c..0000000
Binary files "a/\346\226\227\345\233\276\347\245\236\345\231\250.alfredworkflow" and /dev/null differ