一个markdown编辑器editor.md

Editor.md






Editor.md : The open source embeddable online markdown editor (component), based on CodeMirror & jQuery & Marked.

Features

README & Examples (English)


Editor.md 是一款开源的、可嵌入的 Markdown 在线编辑器(组件),基于 CodeMirror、jQuery 和 Marked 构建。

editormd-screenshot

主要特性

Examples

https://pandao.github.io/editor.md/examples/index.html

Download & install

Github download

Bower install :

  1. bower install editor.md

Usages

HTML:

```html


Apicloud的云推送api, php版

  1. class ApicloudPush
  2. {
  3. public static $api = 'https://p.apicloud.com/api/push/message';
  4. public static $appid = 'A6920463******';
  5. public static $appkey = 'C******8-B6BB-3027-2C93-6C********29';
  6. public static function post($post_data)
  7. {
  8. $appkey = sha1(self::$appid . "UZ" . self::$appkey . "UZ" . time()) . "." . time();
  9. $ch = curl_init ();
  10. curl_setopt ($ch, CURLOPT_HTTPHEADER, [
  11. 'X-APICloud-AppId:'. self::$appid,
  12. 'X-APICloud-AppKey:' . $appkey
  13. ]);
  14. curl_setopt($ch, CURLOPT_POST, count($post_data));
  15. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  16. curl_setopt($ch, CURLOPT_URL, self::$api);
  17. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
  18. ob_start ();
  19. curl_exec ($ch);
  20. $result = ob_get_contents ();
  21. ob_end_clean();
  22. curl_close ($ch);
  23. return $result;
  24. }
  25. }
  26. $title = isset($_GET['title']) ? $_GET['title'] : '测试标题';
  27. $content = isset($_GET['content']) ? $_GET['content'] : '测试内容';
  28. var_dump(ApicloudPush::post([
  29. 'title' => $title,
  30. 'content' => $content,
  31. 'type' => 2, //– 消息类型,1:消息 2:通知
  32. 'platform' => 0, //0:全部平台,1:ios, 2:android
  33. // 'groupName' => 'department', //推送组名,多个组用英文逗号隔开.默认:全部组。eg.group1,group2 .
  34. // 'userIds' => 'shuai' //推送用户id, 多个用户用英文逗号分隔,eg. user1,user2。
  35. ]));

一个翻译github的脚本

把下面的代码另存为github.user.js, 然后拖拽到chrome的插件管理界面, 打开github就可以看到中文的github了

  1. (function() {
  2. var url_has = function(str) {
  3. return location.href.indexOf(str) >= 0;
  4. }
  5. var $ = function(selector) {
  6. return document.querySelectorAll(selector);
  7. };
  8. var replace_dom = function(selector, num, attr, old_string, new_string) {
  9. var selector_str = selector;
  10. if (typeof selector == 'string') {
  11. selector = $(selector);
  12. }
  13. var rep = function(str) {
  14. str = str || '';
  15. if (typeof new_string == 'undefined') {
  16. for (var j in old_string) {
  17. str = str.replace(old_string[j][0], old_string[j][1]);
  18. }
  19. } else {
  20. str = str.replace(old_string, new_string);
  21. }
  22. return str;
  23. }
  24. if (num === 'each') {
  25. for (var i in selector) {
  26. selector[i][attr] = rep(selector[i][attr]);
  27. }
  28. } else if (selector.length && (num in selector) && (attr in selector[num])) {
  29. selector[num][attr] = rep(selector[num][attr]);
  30. }
  31. if (typeof selector_str == 'string') {
  32. setTimeout(function() {
  33. replace_dom(selector_str, num, attr, old_string, new_string);
  34. }, 1000);
  35. }
  36. };
  37. if (!url_has('github.com')) {
  38. return;
  39. }
  40. // 搜索框
  41. replace_dom($('.header-search-input'), 0, 'placeholder', 'Search GitHub', '全站搜索');
  42. // 翻译导航 Pull requests, Issues, Gist
  43. replace_dom($('.header-nav a'), 2, 'innerHTML', 'Gist', '重点');
  44. // 首页的两个大按钮
  45. replace_dom($('.shelf-cta'), 0, 'innerHTML', 'Read the guide', '阅读指南');
  46. replace_dom($('.shelf-cta'), 1, 'innerHTML', 'Start a project', '开始一个项目');
  47. // 首页我贡献的
  48. replace_dom($('[role=navigation] h3'), 0, 'innerHTML', 'Repositories you contribute to', '你有贡献的库');
  49. // 首页我的仓库
  50. replace_dom($('#your_repos'), 0, 'innerHTML', 'Your repositories', '你的仓库');
  51. replace_dom($('#your_repos a'), 0, 'innerHTML', 'New repository', '新建仓库');
  52. replace_dom($('.repo-filter'), 0, 'innerHTML', 'All', '全部');
  53. replace_dom($('.repo-filter'), 1, 'innerHTML', 'Public', '公开');
  54. replace_dom($('.repo-filter'), 2, 'innerHTML', 'Private', '私有');
  55. replace_dom($('.repo-filter'), 3, 'innerHTML', 'Sources', '创建的');
  56. replace_dom($('.repo-filter'), 4, 'innerHTML', 'Forks', '克隆的');
  57. replace_dom($('#your-repos-filter'), 0, 'placeholder', 'Find a repository', '搜索仓库');
  58. // document.querySelector('.file-navigation i').innerHTML = '分支:';
  59. // 翻译提交时间
  60. replace_dom('relative-time,time-ago', 'each', 'innerHTML', [
  61. ['minutes ago', '分钟前'],
  62. ['an hour ago', '1小时前'],
  63. ['hours ago', '小时前'],
  64. ['a day ago', '一天前'],
  65. ['days ago', '天前'],
  66. ['a month ago', '1个月前'],
  67. ['months ago', '个月前'],
  68. [/^on\s(\d+)\sJan/, '1月$1号'],
  69. [/^on\s(\d+)\sFeb/, '2月$1号'],
  70. [/^on\s(\d+)\sMar/, '3月$1号'],
  71. [/^on\s(\d+)\sApr/, '4月$1号'],
  72. [/^on\s(\d+)\sMay/, '5月$1号'],
  73. [/^on\s(\d+)\sJun/, '6月$1号'],
  74. [/^on\s(\d+)\sJul/, '7月$1号'],
  75. [/^on\s(\d+)\sAug/, '8月$1号'],
  76. [/^on\s(\d+)\sSep/, '9月$1号'],
  77. [/^on\s(\d+)\sOct/, '10月$1号'],
  78. [/^on\s(\d+)\sNov/, '11月$1号'],
  79. [/^on\s(\d+)\sDec/, '12月$1号']
  80. ]);
  81. // 翻译提交时间
  82. replace_dom($('.commit-group-title'), 'each', 'innerHTML', [
  83. ['Commits on', '提交时间: '],
  84. [/Jan\s(\d+)\,\s(\d+)/, '$2年1月$1号'],
  85. [/Feb\s(\d+)\,\s(\d+)/, '$2年2月$1号'],
  86. [/Mar\s(\d+)\,\s(\d+)/, '$2年3月$1号'],
  87. [/Apr\s(\d+)\,\s(\d+)/, '$2年4月$1号'],
  88. [/May\s(\d+)\,\s(\d+)/, '$2年5月$1号'],
  89. [/Jun\s(\d+)\,\s(\d+)/, '$2年6月$1号'],
  90. [/Jul\s(\d+)\,\s(\d+)/, '$2年7月$1号'],
  91. [/Aug\s(\d+)\,\s(\d+)/, '$2年8月$1号'],
  92. [/Sep\s(\d+)\,\s(\d+)/, '$2年9月$1号'],
  93. [/Oct\s(\d+)\,\s(\d+)/, '$2年10月$1号'],
  94. [/Nov\s(\d+)\,\s(\d+)/, '$2年11月$1号'],
  95. [/Dec\s(\d+)\,\s(\d+)/, '$2年12月$1号']
  96. ]);
  97. // 创建新仓库页面
  98. replace_dom($('.subhead-heading'), 0, 'innerHTML', 'Create a new repository', '创建一个新的存储库');
  99. replace_dom($('.subhead-description'), 0, 'innerHTML', 'A repository contains all the files for your project, including the revision history.', '一个存储库包含您的项目的所有文件,包括修改历史记录。');
  100. replace_dom($('.owner-reponame label'), 0, 'innerHTML', 'Owner', '所有者');
  101. replace_dom($('.owner-reponame label'), 1, 'innerHTML', 'Repository name', '仓库名称');
  102. replace_dom($('.with-permission-fields .my-3'), 0, 'innerHTML', 'Great repository names are short and memorable. Need inspiration? How about', '一个存储库包含您的项目的所有文件,包括修改历史记录。');
  103. replace_dom($('.select-menu-title'), 0, 'innerHTML', 'Choose another owner', '选择其他所有者');
  104. replace_dom($('[for=repository_description]'), 0, 'innerHTML', 'Description', '描述');
  105. // replace_dom($('.with-permission-fields .form-checkbox label :nth-child(3)'), 0, 'textContent', 'Public', '公开');
  106. replace_dom($('.with-permission-fields .form-checkbox .note'), 0, 'innerHTML', 'Anyone can see this repository. You choose who can commit.', '公开: 任何人都可以看到这个库。你可以选择谁能提交。');
  107. // replace_dom($('.with-permission-fields .form-checkbox label :nth-child(3)'), 0, 'textContent', 'Private', '私有');
  108. replace_dom($('.with-permission-fields .form-checkbox .note'), 1, 'innerHTML', 'You choose who can see and commit to this repository.', '私有: 您选择谁可以看到并提交到这个存储库。');
  109. // 版本库首页
  110. replace_dom($('.header-search-scope'), 0, 'innerHTML', [
  111. ['This repository', '搜索当前仓库'],
  112. ['This organization', '搜索当前组织']
  113. ]);
  114. replace_dom($('.numbers-summary li:nth-child(1) a'), 0, 'innerHTML', 'commits', '次提交');
  115. replace_dom($('.numbers-summary li:nth-child(2) a'), 0, 'innerHTML', 'branch', '个分支');
  116. replace_dom($('.numbers-summary li:nth-child(3) a'), 0, 'innerHTML', 'releases', '个版本');
  117. replace_dom($('.numbers-summary li:nth-child(4) a'), 0, 'innerHTML', 'contributors', '个贡献者');
  118. replace_dom('#context-commitish-filter-field', 0, 'placeholder', [
  119. ['Filter branches/tags', '搜索分支标签'],
  120. ['Find a tag', '搜索标签']
  121. ]);
  122. replace_dom($('h3'), 'each', 'innerHTML', [
  123. ['Watched repositories', '监控的版本库'],
  124. ]);
  125. replace_dom($('button,a,span,i'), 'each', 'innerHTML', [
  126. ['New pull request', '新拉取请求'],
  127. [' Projects', ' 项目'],
  128. [' Pulse', ' 脉冲'],
  129. [' branch', ' 分支'],
  130. ['Graphs', '图表'],
  131. ['Settings', '设置'],
  132. ['Pull requests', '拉取请求'],
  133. ['Change notification settings', '更改通知设置'],
  134. ['Unread', '未读'],
  135. ['Unwatch all', '取消全部监控'],
  136. ['Unwatch', '取消监控'],
  137. ['Not watching', '不监控'],
  138. ['Participating', '参与'],
  139. ['Mark all as read', '标记全部为已读'],
  140. ['All notifications', '所有通知'],
  141. ['Notifications', '通知'],
  142. ['Watching', '监控'],
  143. ['Learn more', '加载更多'],
  144. ['New repository', '新建仓库'],
  145. ['New team', '新建团队'],
  146. ['My teams', '我的团队'],
  147. ['Repositories', '仓库'],
  148. ['People', '成员'],
  149. ['Teams', '团队'],
  150. ['Use SSH', '使用SSH协议'],
  151. ['Use HTTPS', '使用HTTPS协议'],
  152. ['Create new file', '创建新文件'],
  153. ['Upload files', '上传文件'],
  154. ['Find file', '搜索文件'],
  155. ['Issues', '问题'],
  156. ['Code', '代码'],
  157. ['Wiki', '维基'],
  158. ['Contact GitHub', '联系GitHub'],
  159. ['Training', '培养'],
  160. ['Blog', '博客'],
  161. ['Shop', '商店'],
  162. ['About', '关于'],
  163. ['Labels', '标签'],
  164. ['Milestones', '里程碑'],
  165. ['Filters', '搜索'],
  166. ['Clone or download', '克隆或下载'],
  167. ['Branches', '分支'],
  168. ['Branch:', '分支:'],
  169. ['Tags', '标签'],
  170. ['Download ZIP', '下载ZIP压缩包'],
  171. ['Switch branches/tags', '切换分支或标签']
  172. ]);
  173. })();

一个翻译github的脚本

  1. (function() {
  2. var url_has = function(str) {
  3. return location.href.indexOf(str) >= 0;
  4. }
  5. var $ = function(selector) {
  6. return document.querySelectorAll(selector);
  7. };
  8. var replace_dom = function(selector, num, attr, old_string, new_string) {
  9. var selector_str = selector;
  10. if (typeof selector == 'string') {
  11. selector = $(selector);
  12. }
  13. var rep = function(str) {
  14. str = str || '';
  15. if (typeof new_string == 'undefined') {
  16. for (var j in old_string) {
  17. str = str.replace(old_string[j][0], old_string[j][1]);
  18. }
  19. } else {
  20. str = str.replace(old_string, new_string);
  21. }
  22. return str;
  23. }
  24. if (num === 'each') {
  25. for (var i in selector) {
  26. selector[i][attr] = rep(selector[i][attr]);
  27. }
  28. } else if (selector.length && (num in selector) && (attr in selector[num])) {
  29. selector[num][attr] = rep(selector[num][attr]);
  30. }
  31. if (typeof selector_str == 'string') {
  32. setTimeout(function() {
  33. replace_dom(selector_str, num, attr, old_string, new_string);
  34. }, 1000);
  35. }
  36. };
  37. if (!url_has('github.com')) {
  38. return;
  39. }
  40. // 搜索框
  41. replace_dom($('.header-search-input'), 0, 'placeholder', 'Search GitHub', '全站搜索');
  42. // 翻译导航 Pull requests, Issues, Gist
  43. replace_dom($('.header-nav a'), 2, 'innerHTML', 'Gist', '重点');
  44. // 首页的两个大按钮
  45. replace_dom($('.shelf-cta'), 0, 'innerHTML', 'Read the guide', '阅读指南');
  46. replace_dom($('.shelf-cta'), 1, 'innerHTML', 'Start a project', '开始一个项目');
  47. // 首页我贡献的
  48. replace_dom($('[role=navigation] h3'), 0, 'innerHTML', 'Repositories you contribute to', '你有贡献的库');
  49. // 首页我的仓库
  50. replace_dom($('#your_repos'), 0, 'innerHTML', 'Your repositories', '你的仓库');
  51. replace_dom($('#your_repos a'), 0, 'innerHTML', 'New repository', '新建仓库');
  52. replace_dom($('.repo-filter'), 0, 'innerHTML', 'All', '全部');
  53. replace_dom($('.repo-filter'), 1, 'innerHTML', 'Public', '公开');
  54. replace_dom($('.repo-filter'), 2, 'innerHTML', 'Private', '私有');
  55. replace_dom($('.repo-filter'), 3, 'innerHTML', 'Sources', '创建的');
  56. replace_dom($('.repo-filter'), 4, 'innerHTML', 'Forks', '克隆的');
  57. replace_dom($('#your-repos-filter'), 0, 'placeholder', 'Find a repository', '搜索仓库');
  58. // document.querySelector('.file-navigation i').innerHTML = '分支:';
  59. // 翻译提交时间
  60. replace_dom('relative-time,time-ago', 'each', 'innerHTML', [
  61. ['minutes ago', '分钟前'],
  62. ['an hour ago', '1小时前'],
  63. ['hours ago', '小时前'],
  64. ['a day ago', '一天前'],
  65. ['days ago', '天前'],
  66. ['a month ago', '1个月前'],
  67. ['months ago', '个月前'],
  68. [/^on\s(\d+)\sJan/, '1月$1号'],
  69. [/^on\s(\d+)\sFeb/, '2月$1号'],
  70. [/^on\s(\d+)\sMar/, '3月$1号'],
  71. [/^on\s(\d+)\sApr/, '4月$1号'],
  72. [/^on\s(\d+)\sMay/, '5月$1号'],
  73. [/^on\s(\d+)\sJun/, '6月$1号'],
  74. [/^on\s(\d+)\sJul/, '7月$1号'],
  75. [/^on\s(\d+)\sAug/, '8月$1号'],
  76. [/^on\s(\d+)\sSep/, '9月$1号'],
  77. [/^on\s(\d+)\sOct/, '10月$1号'],
  78. [/^on\s(\d+)\sNov/, '11月$1号'],
  79. [/^on\s(\d+)\sDec/, '12月$1号']
  80. ]);
  81. // 翻译提交时间
  82. replace_dom($('.commit-group-title'), 'each', 'innerHTML', [
  83. ['Commits on', '提交时间: '],
  84. [/Jan\s(\d+)\,\s(\d+)/, '$2年1月$1号'],
  85. [/Feb\s(\d+)\,\s(\d+)/, '$2年2月$1号'],
  86. [/Mar\s(\d+)\,\s(\d+)/, '$2年3月$1号'],
  87. [/Apr\s(\d+)\,\s(\d+)/, '$2年4月$1号'],
  88. [/May\s(\d+)\,\s(\d+)/, '$2年5月$1号'],
  89. [/Jun\s(\d+)\,\s(\d+)/, '$2年6月$1号'],
  90. [/Jul\s(\d+)\,\s(\d+)/, '$2年7月$1号'],
  91. [/Aug\s(\d+)\,\s(\d+)/, '$2年8月$1号'],
  92. [/Sep\s(\d+)\,\s(\d+)/, '$2年9月$1号'],
  93. [/Oct\s(\d+)\,\s(\d+)/, '$2年10月$1号'],
  94. [/Nov\s(\d+)\,\s(\d+)/, '$2年11月$1号'],
  95. [/Dec\s(\d+)\,\s(\d+)/, '$2年12月$1号']
  96. ]);
  97. // 创建新仓库页面
  98. replace_dom($('.subhead-heading'), 0, 'innerHTML', 'Create a new repository', '创建一个新的存储库');
  99. replace_dom($('.subhead-description'), 0, 'innerHTML', 'A repository contains all the files for your project, including the revision history.', '一个存储库包含您的项目的所有文件,包括修改历史记录。');
  100. replace_dom($('.owner-reponame label'), 0, 'innerHTML', 'Owner', '所有者');
  101. replace_dom($('.owner-reponame label'), 1, 'innerHTML', 'Repository name', '仓库名称');
  102. replace_dom($('.with-permission-fields .my-3'), 0, 'innerHTML', 'Great repository names are short and memorable. Need inspiration? How about', '一个存储库包含您的项目的所有文件,包括修改历史记录。');
  103. replace_dom($('.select-menu-title'), 0, 'innerHTML', 'Choose another owner', '选择其他所有者');
  104. replace_dom($('[for=repository_description]'), 0, 'innerHTML', 'Description', '描述');
  105. // replace_dom($('.with-permission-fields .form-checkbox label :nth-child(3)'), 0, 'textContent', 'Public', '公开');
  106. replace_dom($('.with-permission-fields .form-checkbox .note'), 0, 'innerHTML', 'Anyone can see this repository. You choose who can commit.', '公开: 任何人都可以看到这个库。你可以选择谁能提交。');
  107. // replace_dom($('.with-permission-fields .form-checkbox label :nth-child(3)'), 0, 'textContent', 'Private', '私有');
  108. replace_dom($('.with-permission-fields .form-checkbox .note'), 1, 'innerHTML', 'You choose who can see and commit to this repository.', '私有: 您选择谁可以看到并提交到这个存储库。');
  109. // 版本库首页
  110. replace_dom($('.header-search-scope'), 0, 'innerHTML', [
  111. ['This repository', '搜索当前仓库'],
  112. ['This organization', '搜索当前组织']
  113. ]);
  114. replace_dom($('.numbers-summary li:nth-child(1) a'), 0, 'innerHTML', 'commits', '次提交');
  115. replace_dom($('.numbers-summary li:nth-child(2) a'), 0, 'innerHTML', 'branch', '个分支');
  116. replace_dom($('.numbers-summary li:nth-child(3) a'), 0, 'innerHTML', 'releases', '个版本');
  117. replace_dom($('.numbers-summary li:nth-child(4) a'), 0, 'innerHTML', 'contributors', '个贡献者');
  118. replace_dom('#context-commitish-filter-field', 0, 'placeholder', [
  119. ['Filter branches/tags', '搜索分支标签'],
  120. ['Find a tag', '搜索标签']
  121. ]);
  122. replace_dom($('h3'), 'each', 'innerHTML', [
  123. ['Watched repositories', '监控的版本库'],
  124. ]);
  125. replace_dom($('button,a,span,i'), 'each', 'innerHTML', [
  126. ['New pull request', '新拉取请求'],
  127. [' Projects', ' 项目'],
  128. [' Pulse', ' 脉冲'],
  129. [' branch', ' 分支'],
  130. ['Graphs', '图表'],
  131. ['Settings', '设置'],
  132. ['Pull requests', '拉取请求'],
  133. ['Change notification settings', '更改通知设置'],
  134. ['Unread', '未读'],
  135. ['Unwatch all', '取消全部监控'],
  136. ['Unwatch', '取消监控'],
  137. ['Not watching', '不监控'],
  138. ['Participating', '参与'],
  139. ['Mark all as read', '标记全部为已读'],
  140. ['All notifications', '所有通知'],
  141. ['Notifications', '通知'],
  142. ['Watching', '监控'],
  143. ['Learn more', '加载更多'],
  144. ['New repository', '新建仓库'],
  145. ['New team', '新建团队'],
  146. ['My teams', '我的团队'],
  147. ['Repositories', '仓库'],
  148. ['People', '成员'],
  149. ['Teams', '团队'],
  150. ['Use SSH', '使用SSH协议'],
  151. ['Use HTTPS', '使用HTTPS协议'],
  152. ['Create new file', '创建新文件'],
  153. ['Upload files', '上传文件'],
  154. ['Find file', '搜索文件'],
  155. ['Issues', '问题'],
  156. ['Code', '代码'],
  157. ['Wiki', '维基'],
  158. ['Contact GitHub', '联系GitHub'],
  159. ['Training', '培养'],
  160. ['Blog', '博客'],
  161. ['Shop', '商店'],
  162. ['About', '关于'],
  163. ['Labels', '标签'],
  164. ['Milestones', '里程碑'],
  165. ['Filters', '搜索'],
  166. ['Clone or download', '克隆或下载'],
  167. ['Branches', '分支'],
  168. ['Branch:', '分支:'],
  169. ['Tags', '标签'],
  170. ['Download ZIP', '下载ZIP压缩包'],
  171. ['Switch branches/tags', '切换分支或标签']
  172. ]);
  173. })();

Atom设置eclipse快捷键

Settings - Keybindings - 点击”your keymap file”

  1. 'atom-text-editor':
  2. 'alt-/': 'autocomplete-plus:activate'
  3. 'atom-text-editor:not([mini])':
  4. 'ctrl-d': 'editor:delete-line'
  5. 'atom-workspace atom-text-editor:not([mini])':
  6. 'alt-up': 'editor:move-line-up'
  7. 'alt-down': 'editor:move-line-down'
  8. '.platform-win32':
  9. 'ctrl-shift-R': 'fuzzy-finder:toggle-file-finder'
  10. 'ctrl-shift-T': 'fuzzy-finder:toggle-file-finder'
  11. '.platform-win32, .platform-win32 .command-palette atom-text-editor':
  12. 'ctrl-p': 'command-palette:toggle'
  13. '.platform-darwin, .platform-win32, .platform-linux':
  14. 'ctrl-l': 'go-to-line:toggle'

cms想法

关于字体图标

后台模块或按钮图标采用 http://www.iconfont.cn/ 的图标,
智能解析iconfont.css提取所有图标

关于模块

新建模块需要设置:
模块标识
模块名称
模块字段 (标识, 名称, 类型, 默认值, 新增验证函数, 更新验证函数)
  // 默认值可读取配置
  // 验证函数自动读取验证辅助类的方法和文档
列表显示字段
  // 字段显示有格式化方式, 自动读取格式化辅助类和文档
详情页显示字段
添加数据界面显示字段
编辑页面显示字段

排序字段和方式(asc|desc|自定义)
搜索字段
删除数据方式 (软删除, 直接删除)

验证辅助类

设计思想

  1. class Validate {
  2. public function username($value, $msg, $params...) {
  3. }
  4. }

分两个, 一个系统, 一个用户自定义

想到的辅助方法:
用户名,密码,邮箱,手机号,不能为空,长度限制,只允许英文,正则

通过获取类的注释, 在需要的地方列出验证方式列表

字段和数据格式化辅助类

设计思想

  1. class Format{
  2. public function toImgTag($value, $params....) {
  3. }
  4. }

分两个, 一个系统, 一个用户自定义

想到的辅助方法:
时间,状态,图片,关联表字段 (表名, 字段名, 分隔符)

通过获取类的注释, 在需要的地方列出格式化辅助方法列表

angularjs的$http发送post请求

刚开始用angularjs的post方法时, 后台总是接收不到数据, 查了资料发现是因为angularjs的post提交方式和jquery的不一样, jquery默认就是模拟form提交数据, 而angularjs则使用的是 request payload, 所有使用$_POST是获取不到数据的, 解放方法:

  1. $http({
  2. url: url,
  3. method: 'post',
  4. headers: {
  5. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  6. },
  7. data: {
  8. order_id: orderId
  9. },
  10. transformRequest: function(obj) {
  11. var str = [];
  12. for (var p in obj) {
  13. str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
  14. }
  15. return str.join("&");
  16. }
  17. }).success(function(data, header, config, status) {
  18. // 正确返回
  19. }).error(function(data, header, config, status) {
  20. //处理响应失败
  21. });

写了个jquery的自动填充form插件

最近发现每次做后台编辑数据的时候, 给表单设置默认值都很麻烦, 这次干脆写了一个jquery插件, 直接自动填充表单, 省去php一个一个的写, 这样代码可读性也好了很多.

jquery.autofill.js

  1. jQuery.fn.extend({
  2. autofill: function (data) {
  3. if (!data || !$.isPlainObject(data)) {
  4. return;
  5. }
  6. for (var name in data) {
  7. if ($.isArray(data[name])) {
  8. var field = $('[name="' + name + '[]"]', this);
  9. field.each(function () {
  10. if (data[name].indexOf($(this).val()) >= 0) {
  11. $(this).attr('checked', 'checked');
  12. }
  13. });
  14. } else {
  15. var field = $('[name="' + name + '"]', this);
  16. field.each(function () {
  17. switch ($(this).attr('type')) {
  18. case 'radio':
  19. if ($(this).val() === data[name].toString()) {
  20. $(this).attr('checked', 'checked');
  21. }
  22. break;
  23. default:
  24. $(this).val(data[name]);
  25. break;
  26. }
  27. });
  28. }
  29. }
  30. }
  31. });

使用方法 ./test.php

  1. <!DOCTYPE HTML>
  2. <html lang="en-US">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <link href="css/bootstrap.css" rel="stylesheet" type="text/css"/>
  7. </head>
  8. <body>
  9. <div class="container">
  10. <form action="?" method="post" id="form">
  11. 姓名: <input type="text" name="name" id="" />
  12. <br />
  13. 年龄: <input type="number" name="age" id="" />
  14. <br />
  15. 性别:
  16. <input type="radio" name="sex" value="1" id="" />
  17. <input type="radio" name="sex" value="0" id="" />
  18. <br />
  19. 省份:
  20. <select name="area" id="">
  21. <option value="-1">选择省份</option>
  22. <option value="shanghai">上海</option>
  23. <option value="beijing">北京</option>
  24. <option value="henan">河南</option>
  25. </select>
  26. <br />
  27. 爱好:
  28. <input type="checkbox" name="hobby[]" value="book" id="" /> 看书
  29. <input type="checkbox" name="hobby[]" value="coding" id="" /> 写代码
  30. <input type="checkbox" name="hobby[]" value="games" id="" /> 打游戏<br />
  31. 简介:
  32. <textarea name="content"></textarea>
  33. <br />
  34. <input type="submit" value="提交" />
  35. </form>
  36. <!-- 这里是数据 -->
  37. <div class="hidden" id="data">
  38. <?php
  39. $data = [
  40. 'name' => 'shuai',
  41. 'age' => '25',
  42. 'area' => 'henan',
  43. 'sex' => 0,
  44. 'hobby' => ['book', 'games'],
  45. 'content' => 'hello world',
  46. ];
  47. echo json_encode($data);
  48. ?>
  49. </div>
  50. </div>
  51. <script src="jquery.min.js" type="text/javascript"></script>
  52. <script src="jquery.autofill.js" type="text/javascript"></script>
  53. <script type="text/javascript">
  54. $(function () {
  55. var data = $.parseJSON($('#data').text());
  56. $('#form').autofill(data);
  57. });
  58. </script>
  59. </body>
  60. </html>

访问

git关于文件权限修改引起的冲突及忽略文件权限的办法

  我们在使用git进行版本管理的时候,有时候只是修改了文件的权限,比如将index.php修改为777,但其实文件内容并没有改变,但是git会认为此文件做了修改,原因是git把文件权限也算作文件差异的一部分了。

 解决办法:

git中可以加入忽略文件权限的配置,在目录中执行以下命令:

  1. $ git config core.filemode false

这样就设置了忽略文件权限。查看下配置:

  1. $ cat .git/config
  2. [core]
  3. repositoryformatversion = 0
  4. filemode = false #看到这一行就说明配置成功
  5. bare = false

sublime text 3 安装后要做的事

1. 安装package control

快捷键: Ctrl + 反撇号, 然后在弹框中输入以下代码回车
如果安装错误可到这个网址查找解决方法: https://packagecontrol.io/installation

  1. import urllib.request,os,hashlib; h = 'df21e130d211cfc94d9b0905775a7c0f' + '1e3d39e33b79698005270310898eea76'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

2. 注册

  1. —– BEGIN LICENSE —–
  2. Michael Barnes
  3. Single User License
  4. EA7E-821385
  5. 8A353C41 872A0D5C DF9B2950 AFF6F667
  6. C458EA6D 8EA3C286 98D1D650 131A97AB
  7. AA919AEC EF20E143 B361B1E7 4C8B7F04
  8. B085E65E 2F5F5360 8489D422 FB8FC1AA
  9. 93F6323C FD7F7544 3F39C318 D95E6480
  10. FCCC7561 8A4A1741 68FA4223 ADCEDE07
  11. 200C25BE DBBC4855 C4CFB774 C5EC138C
  12. 0FEC1CEF D9DCECEC D3A5DAD1 01316C36
  13. —— END LICENSE ——

3. Eclipce快捷键映射

菜单 -> preferences -> 按键绑定 - 用户

  1. [{
  2. "keys": ["shift+enter"],
  3. "command": "run_macro_file",
  4. "args": {
  5. "file": "Packages/Default/Add Line.sublime-macro"
  6. }
  7. }, {
  8. "keys": ["alt+up"],
  9. "command": "swap_line_up"
  10. }, {
  11. "keys": ["alt+down"],
  12. "command": "swap_line_down"
  13. }, {
  14. "keys": ["ctrl+alt+j"],
  15. "command": "join_lines"
  16. }, {
  17. "keys": ["ctrl+alt+down"],
  18. "command": "duplicate_line"
  19. }, {
  20. "keys": ["shift+ctrl+r"],
  21. "command": "show_overlay",
  22. "args": {
  23. "overlay": "goto",
  24. "show_files": true
  25. }
  26. }, {
  27. "keys": ["ctrl+shift+s"],
  28. "command": "save_all"
  29. }, {
  30. "keys": ["ctrl+l"],
  31. "command": "show_overlay",
  32. "args": {
  33. "overlay": "goto",
  34. "text": ":"
  35. }
  36. }, {
  37. "keys": ["shift+ctrl+f4"],
  38. "command": "close_all"
  39. }, {
  40. "keys": ["shift+ctrl+y"],
  41. "command": "lower_case"
  42. }, {
  43. "keys": ["shift+ctrl+x"],
  44. "command": "upper_case"
  45. }, {
  46. "keys": ["ctrl+d"],
  47. "command": "run_macro_file",
  48. "args": {
  49. "file": "Packages/Default/Delete Line.sublime-macro"
  50. }
  51. }]

4. 汉化

运行SublimeText3
点击 菜单 Preferneces -> Browse Packages
会打开 X:\Program Files\Sublime Text\Data\Packages 目录,点击向上并找到X:\Program Files\Sublime Text\Data\Installed Packages目录,从附件中下载汉化包并解压,复制Default.sublime-package到这个目录,无需重启即可直接看到汉化效果。
汉化包下载地址: http://img.xiumu.org/blog-uploads/2013/02/Sublime_Text_CN_3059.zip

5. 插件

  1. phpfmt
  1. {
  2. "enable_auto_align": true,
  3. "format_on_save": true,
  4. "indent_with_space": true,
  5. "option": "value",
  6. "php_bin": "C:/wamp/bin/php/php7.0.4/php.exe",
  7. "psr1": true,
  8. "psr2": true,
  9. "version": 4
  10. }

2、ConvertToUTF8
支持UTF-8编码的插件
3、Bracket Highlighter
用于匹配括号,引号和html标签。对于很长的代码很有用。安装好之后,不需要设置插件会自动生效
4、DocBlockr
DocBlockr可以自动生成PHPDoc风格的注释。它支持的语言有Javascript, PHP, ActionScript, CoffeeScript, Java, Objective C, C, C++
5、Emmet(Zen Coding)
快速生成HTML代码段的插件,强大到无与伦比,不知道的请自行google
6、SideBar Enhancements
这个插件改进了侧边栏,增加了许多功能
7、Themr
主题管理,切换主题的时候,不用自己修改配置文件了,用这个可以方便的切换主题
请参考  http://www.ladyloveit.com/sublime/developers-commonly-used-10-sublime-text-plugin