From 0456d52ebd3821c17688a7b23e927223025a8ae4 Mon Sep 17 00:00:00 2001 From: Jakukyo Friel Date: Mon, 9 Dec 2013 08:54:58 +0800 Subject: [PATCH] GitHubGit: add actual action logic It works on 0.9(13.12.1). --- GitHubGit/Action.php | 138 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 GitHubGit/Action.php diff --git a/GitHubGit/Action.php b/GitHubGit/Action.php new file mode 100644 index 0000000..ff78a35 --- /dev/null +++ b/GitHubGit/Action.php @@ -0,0 +1,138 @@ +db->fetchRow($this->db->select()->from('table.users') + ->where('group = ?', 'administrator') + ->order('uid', Typecho_Db::SORT_ASC) + ->limit(1)); + + if (empty($master)) { + return false; + } else if (!$this->user->simpleLogin($master['uid'])) { + return false; + } + + /** add article */ + if (isset($added_files) && is_array($added_files)) { + foreach ($added_files as $added_file) { + + $input = array( + 'do' => 'publish', + 'allowComment' => $this->options->defaultAllowComment, + 'allowPing' => $this->options->defaultAllowPing, + 'allowFeed' => $this->options->defaultAllowFeed + ); + + list($slug) = explode('.', basename($added_file)); + $input['slug'] = $slug; + + $post = $this->db->fetchRow($this->db->select() + ->from('table.contents')->where('slug = ?', $slug)->limit(1)); + if (!empty($post)) { + if ('post' != $post['type']) { + return false; + } else { + $input['cid'] = $post['cid']; + } + } + + $input['category'] = 'default'; + $input['title'] = pathinfo($added_file)['filename']; + $url = preg_replace('#https://#', 'https://raw.', $repository_url) . '/master/' . $added_file; + $input['text'] = file_get_contents($url); + if ($input) { + $this->widget('Widget_Contents_Post_Edit', NULL, $input, false)->action(); + } + + } + } + } +} +db->fetchRow($this->db->select()->from('table.users') + ->where('group = ?', 'administrator') + ->order('uid', Typecho_Db::SORT_ASC) + ->limit(1)); + + if (empty($master)) { + return false; + } else if (!$this->user->simpleLogin($master['uid'])) { + return false; + } + + /** add article */ + if (isset($added_files) && is_array($added_files)) { + foreach ($added_files as $added_file) { + + $input = array( + 'do' => 'publish', + 'allowComment' => $this->options->defaultAllowComment, + 'allowPing' => $this->options->defaultAllowPing, + 'allowFeed' => $this->options->defaultAllowFeed + ); + + list($slug) = explode('.', basename($added_file)); + $input['slug'] = $slug; + + $post = $this->db->fetchRow($this->db->select() + ->from('table.contents')->where('slug = ?', $slug)->limit(1)); + if (!empty($post)) { + if ('post' != $post['type']) { + return false; + } else { + $input['cid'] = $post['cid']; + } + } + + $input['category'] = 'default'; + $input['title'] = pathinfo($added_file)['filename']; + $url = preg_replace('#https://#', 'https://raw.', $repository_url) . '/master/' . $added_file; + $input['text'] = file_get_contents($url); + if ($input) { + $this->widget('Widget_Contents_Post_Edit', NULL, $input, false)->action(); + } + + } + } + } +}