From 2c33b596f9db8613f6d305e0bf8fe63c7a0550f5 Mon Sep 17 00:00:00 2001 From: Jakukyo Friel Date: Mon, 9 Dec 2013 08:38:55 +0800 Subject: [PATCH 1/3] add new plugin `GitHub Git Transmit` Add new typecho post from git/GitHub. --- GitHubGit/Plugin.php | 207 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 GitHubGit/Plugin.php diff --git a/GitHubGit/Plugin.php b/GitHubGit/Plugin.php new file mode 100644 index 0000000..a4e4d27 --- /dev/null +++ b/GitHubGit/Plugin.php @@ -0,0 +1,207 @@ +addInput($basePath->addRule('required', _t('必须填写数据库用户名'))); + } + + /** + * 个人用户的配置面板 + * + * @access public + * @param Typecho_Widget_Helper_Form $form + * @return void + */ + public static function personalConfig(Typecho_Widget_Helper_Form $form){} +} +addInput($basePath->addRule('required', _t('必须填写数据库用户名'))); + } + + /** + * 个人用户的配置面板 + * + * @access public + * @param Typecho_Widget_Helper_Form $form + * @return void + */ + public static function personalConfig(Typecho_Widget_Helper_Form $form){} +} +addInput($basePath->addRule('required', _t('必须填写数据库用户名'))); + } + + /** + * 个人用户的配置面板 + * + * @access public + * @param Typecho_Widget_Helper_Form $form + * @return void + */ + public static function personalConfig(Typecho_Widget_Helper_Form $form){} +} From 0456d52ebd3821c17688a7b23e927223025a8ae4 Mon Sep 17 00:00:00 2001 From: Jakukyo Friel Date: Mon, 9 Dec 2013 08:54:58 +0800 Subject: [PATCH 2/3] 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(); + } + + } + } + } +} From ea8f4bec861c3b2d5552dc61814f6b6d0d6a76fe Mon Sep 17 00:00:00 2001 From: Jakukyo Friel Date: Mon, 9 Dec 2013 09:05:05 +0800 Subject: [PATCH 3/3] GitHubGit: simple documentation --- GitHubGit/README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 GitHubGit/README.md diff --git a/GitHubGit/README.md b/GitHubGit/README.md new file mode 100644 index 0000000..c71d48b --- /dev/null +++ b/GitHubGit/README.md @@ -0,0 +1,51 @@ +Configuration +------------- + +### configure security code + +Open `Plugin.php` in your editor, find this line: + +```php +const github_git = 'curtseyingpiddlesMiguelyeshivahsclarinettists' ; +``` + +Change `github_git` value to something else. + +You can make up anything you like, but please use a long and hard to guess one. + +If the value of `github_git` be guessed by someone else, they can post articles to your blog, if they know how to add GitHub web hooks. + +After editing, save `Plugin.php`. + +### setup GitHub web hook + +In your repository, click `Settings` -> `Service Hooks` -> `WebHook URLs`, add the action url, e.g. + +``` +http://typecho.example.com/action/curtseyingpiddlesMiguelyeshivahsclarinettists +``` + +Install +------- + +Same as other typecho plugins. + +That is: + +- Upload the `GitHubGit` diretory to `usr/plugins` of your typecho directory. +- Enable the plugin at your dashboard. + +Usage +----- + +- Add new posts in your git repository. +- Commit and push to GitHub. + +Done. Your new post will be published in typecho automatically: + +- Use your file name as post title. +- Use your file content as post text. +- Under the default category (which you can change it later). + +Note: if you want some format, you need to use html tags. +Markdown support may be added in future version.