project.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <?php
  2. # 定义几个常用的选项
  3. $local = array
  4. (
  5. 1 => '关闭',
  6. 2 => '开启',
  7. );
  8. $status = array
  9. (
  10. 1 => '未开始',
  11. 2 => '已完成',
  12. 3 => '队列中',
  13. 4 => '运行中',
  14. );
  15. $request_type = array
  16. (
  17. 1 => 'get',
  18. 2 => 'post',
  19. );
  20. $content_type = array
  21. (
  22. 1 => '普通表单',
  23. 2 => 'JSON格式',
  24. );
  25. $project = function()
  26. {
  27. $array = array
  28. (
  29. -1 => array('id' => '-1', 'name' => '父级项目'),
  30. );
  31. $info = Dever::load('spider/project-main');
  32. if ($info) {
  33. $array += $info;
  34. }
  35. return $array;
  36. };
  37. $cate = function()
  38. {
  39. $info = Dever::load('spider/cate-state');
  40. return $info;
  41. };
  42. $info = Dever::load('manage/project.get');
  43. $path = $info['spider']['path'];
  44. if(isset($info['spider']['setup']))
  45. {
  46. $path = $info['spider']['setup'];
  47. }
  48. return array
  49. (
  50. # 表名
  51. 'name' => 'project',
  52. # 显示给用户看的名称
  53. 'lang' => '采集规则',
  54. 'status' => $status,
  55. 'path' => $path,
  56. # 后台菜单排序
  57. 'order' => 20,
  58. 'desc' => Dever::markdown('**启动守护进程的方法:**
  59. 常规任务:请将 ```* * * * * root php '.$path.'daemon/main.php``` 放到crontab中[建议每分钟执行一次]'),
  60. # 数据结构
  61. 'struct' => array
  62. (
  63. 'id' => array
  64. (
  65. 'type' => 'int-11',
  66. 'name' => '项目ID',
  67. 'default' => '',
  68. 'desc' => '',
  69. 'match' => 'is_numeric',
  70. 'search' => 'order',
  71. //'list' => true,
  72. 'order' => 'desc',
  73. ),
  74. 'cate_id' => array
  75. (
  76. 'type' => 'int-11',
  77. 'name' => '采集源',
  78. 'default' => '1',
  79. 'desc' => '采集源',
  80. 'match' => 'is_numeric',
  81. 'update' => 'select',
  82. 'search' => 'select',
  83. 'option' => $cate,
  84. 'list' => true,
  85. ),
  86. 'name' => array
  87. (
  88. 'type' => 'varchar-100',
  89. 'name' => '名称',
  90. 'default' => '',
  91. 'desc' => '请输入项目名称',
  92. 'match' => 'is_string',
  93. 'update' => 'text',
  94. 'search' => 'order,fulltext',
  95. 'list' => true,
  96. 'edit' => true,
  97. ),
  98. 'project_id' => array
  99. (
  100. 'type' => 'int-11',
  101. 'name' => '上级项目',
  102. //'default' => $id,
  103. 'desc' => '请选择上级分类',
  104. 'match' => 'is_numeric',
  105. //'update' => 'select',
  106. //'search' => 'select',
  107. 'option' => $project,
  108. ),
  109. 'site' => array
  110. (
  111. 'type' => 'text-255',
  112. 'name' => '采集网址-第一行填写首页链接,第二行填写后续的分页部分,分页写成{page=1},分类写成{cate=1}',
  113. 'default' => '',
  114. 'desc' => '采集网址',
  115. 'match' => 'is_string',
  116. 'update' => 'textarea',
  117. //'list' => true,
  118. //'edit' => 'textarea',
  119. ),
  120. 'request_type' => array
  121. (
  122. 'type' => 'tinyint-1',
  123. 'name' => '请求方式',
  124. 'default' => '1',
  125. 'desc' => '请求方式',
  126. 'match' => 'is_numeric',
  127. 'option' => $request_type,
  128. 'list' => true,
  129. 'update' => 'radio',
  130. //'edit' => true,
  131. ),
  132. 'content_type' => array
  133. (
  134. 'type' => 'tinyint-1',
  135. 'name' => '请求媒体类型',
  136. 'default' => '1',
  137. 'desc' => '请求媒体类型',
  138. 'match' => 'is_numeric',
  139. 'option' => $content_type,
  140. 'list' => true,
  141. 'update' => 'radio',
  142. //'edit' => true,
  143. ),
  144. 'collect_rule' => array
  145. (
  146. 'type' => 'varchar-500',
  147. 'name' => '采集详情链接-采集详情页面链接规则,为空则进行单页采集,直接获取整个页面的内容,支持dom解析、json格式,dom解析$(".info .title a").each().attr("href"),json格式$json["data"]',
  148. 'default' => '',
  149. 'desc' => '采集规则',
  150. 'match' => 'option',
  151. 'update' => 'textarea',
  152. //'edit' => true,
  153. //'list' => true,
  154. ),
  155. 'page_num' => array
  156. (
  157. 'type' => 'int-11',
  158. 'name' => '采集页数-值为0则默认采集100页',
  159. 'default' => '0',
  160. 'desc' => '采集页数',
  161. 'match' => 'option',
  162. 'update' => 'text',
  163. ),
  164. 'status' => array
  165. (
  166. 'type' => 'tinyint-1',
  167. 'name' => '状态',
  168. 'default' => '1',
  169. 'desc' => '状态',
  170. 'match' => 'is_numeric',
  171. 'option' => $status,
  172. 'list' => 'Dever::load("spider/lib/project.status", {id})',
  173. 'modal' => '查看详情',
  174. 'update' => 'radio',
  175. //'edit' => true,
  176. ),
  177. 'num' => array
  178. (
  179. 'type' => 'int-11',
  180. 'name' => '采集次数',
  181. 'default' => '0',
  182. 'desc' => '采集次数',
  183. 'match' => 'is_numeric',
  184. ),
  185. 'cur_page' => array
  186. (
  187. 'type' => 'int-11',
  188. 'name' => '当前采集页数',
  189. 'default' => '0',
  190. 'desc' => '当前采集页数',
  191. 'match' => 'is_numeric',
  192. ),
  193. 'sdate' => array
  194. (
  195. 'type' => 'int-11',
  196. 'name' => '下次采集时间',
  197. 'default' => '0',
  198. 'desc' => '下次采集时间',
  199. 'match' => 'is_numeric',
  200. 'callback' => 'maketime',
  201. ),
  202. 'interval' => array
  203. (
  204. 'type' => 'int-11',
  205. 'name' => '采集间隔秒数-填写开始时间之后的间隔采集的秒数,为0则只采集一次',
  206. 'default' => '0',
  207. 'desc' => '采集间隔秒数',
  208. 'match' => 'is_numeric',
  209. 'update' => 'text',
  210. ),
  211. 'header' => array
  212. (
  213. 'type' => 'text-255',
  214. 'name' => 'Header参数-换行为多个参数,格式cookie: 11',
  215. 'default' => '',
  216. 'desc' => 'Header参数',
  217. 'match' => 'option',
  218. 'update' => 'textarea',
  219. //'edit' => true,
  220. //'list' => true,
  221. ),
  222. 'param' => array
  223. (
  224. 'type' => 'varchar-8000',
  225. 'name' => '其他参数-一般为post传入的参数,必须是json格式',
  226. 'default' => '',
  227. 'desc' => '其他参数',
  228. 'match' => 'option',
  229. 'update' => 'textarea',
  230. //'edit' => true,
  231. //'list' => true,
  232. ),
  233. 'push' => array
  234. (
  235. 'type' => 'varchar-2000',
  236. 'name' => '数据推送-采集数据时,会自动往设置好的数据推送接口推送数据,多个用换行隔开,支持http协议和dever协议',
  237. 'default' => '',
  238. 'desc' => '数据推送',
  239. 'match' => 'option',
  240. 'update' => 'textarea',
  241. //'edit' => true,
  242. //'list' => true,
  243. ),
  244. 'reorder' => array
  245. (
  246. 'type' => 'int-11',
  247. 'name' => '排序(数值越大越靠前)',
  248. 'default' => '1',
  249. 'desc' => '请输入排序',
  250. 'match' => 'option',
  251. 'update' => 'text',
  252. 'search' => 'order',
  253. 'list_name' => '排序',
  254. 'list' => true,
  255. 'order' => 'desc',
  256. 'edit' => true,
  257. ),
  258. 'state' => array
  259. (
  260. 'type' => 'tinyint-1',
  261. 'name' => '状态',
  262. 'default' => '1',
  263. 'desc' => '请选择状态',
  264. 'match' => 'is_numeric',
  265. ),
  266. 'cdate' => array
  267. (
  268. 'type' => 'int-11',
  269. 'name' => '更新时间',
  270. 'match' => array('is_numeric', time()),
  271. 'desc' => '',
  272. # 只有insert时才生效
  273. //'insert' => true,
  274. //'list' => 'date("Y-m-d H:i:s", {cdate})',
  275. ),
  276. ),
  277. # 更新表结构
  278. 'alter' => array
  279. (
  280. 2 => array
  281. (
  282. array('update', 'header', 'header', 'text-255 header'),
  283. //array('add', 'config', 'config', 'int-11 1 配置'),
  284. ),
  285. //'version' => 2,
  286. ),
  287. 'manage' => array
  288. (
  289. //'delete' => false,
  290. # 更新数据时,要显示的按钮,这里填写js脚本事件即可。保存当前数据可为固定参数:"save-data",复制数据为:copy-data
  291. 'update_button' => array
  292. (
  293. '提交保存' => 'save-data',
  294. '放弃保存' => "msg({status:1,msg:'yes'})",
  295. //'复制数据' => 'copy-data',
  296. ),
  297. # 不允许编辑
  298. //'edit' => false,
  299. # 列表页的类型
  300. //'list_type' => 'parent',
  301. # 可以删除
  302. 'list_button' => array
  303. (
  304. 'update' => array('编辑', '"project&option_pid={project_id}"'),
  305. 'list_data' => array('查看采集数据', '"data&search_option_pid={id}&oper_save_jump=project&oper_parent=project"'),
  306. 'delete' => '删除',
  307. 'br1' => array('<br /><br />'),
  308. 'list_col' => array('设置采集字段', '"col&search_option_pid={id}&oper_parent=project"', '{status} <= 2'),
  309. 'list_col1' => array('设置自定义字段', '"set&search_option_pid={id}&oper_parent=project"', '{status} <= 2'),
  310. 'br2' => array('<br /><br />'),
  311. 'new' => array('测试采集', Dever::url('lib/api.test', 'spider')),
  312. 'oper1' => array('开始采集', '"spider/lib/api.add?id={id}"', '{status} <= 2'),
  313. ),
  314. ),
  315. # request 请求接口定义
  316. 'request' => array
  317. (
  318. # main 取所有主分类
  319. 'main' => array
  320. (
  321. 'where' => array
  322. (
  323. 'project_id' => -1,
  324. 'state' => 1,
  325. ),
  326. 'type' => 'all',
  327. 'order' => array
  328. (
  329. 'reorder' => 'desc',
  330. 'id' => 'desc',
  331. ),
  332. 'col' => '*|id',
  333. ),
  334. # 获取所有已完成,并且有时间间隔的数据,重新入队
  335. 'getAll' => array
  336. (
  337. 'option' => array
  338. (
  339. 'id' => 'yes',
  340. 'status' => 2,
  341. 'interval' => array('yes', '>='),
  342. 'sdate' => array('yes-sdate', '<='),
  343. 'state' => 1,
  344. ),
  345. 'type' => 'all',
  346. 'order' => array('id' => 'desc'),
  347. 'col' => '*',
  348. ),
  349. 'getOne' => array
  350. (
  351. 'option' => array
  352. (
  353. 'id' => 'yes',
  354. 'status' => array('yes'),
  355. 'sdate' => array('yes-sdate', '<='),
  356. 'state' => 1,
  357. ),
  358. 'type' => 'one',
  359. ),
  360. )
  361. );