feeds.views.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <?php
  2. /**
  3. * @file
  4. * Views integration for Feeds tables.
  5. *
  6. * @see http://drupal.org/project/views
  7. */
  8. /**
  9. * Implements hook_views_data().
  10. */
  11. function feeds_views_data() {
  12. $data = array();
  13. /**
  14. * Expose feeds_source table to views.
  15. */
  16. $data['feeds_source']['table'] = array(
  17. 'group' => 'Feeds source',
  18. 'base' => array(
  19. 'field' => array('feed_nid', 'id'),
  20. 'title' => 'Feeds source',
  21. 'help' => 'The source information for a feed, for example its URL',
  22. ),
  23. );
  24. $data['feeds_source']['feed_nid'] = array(
  25. 'title' => 'Feed node id',
  26. 'help' => 'Contains the node id of a feed node if the feed\'s configuration is attached to a content type, otherwise contains 0.',
  27. 'field' => array(
  28. 'handler' => 'views_handler_field_numeric',
  29. 'click sortable' => TRUE,
  30. ),
  31. 'filter' => array(
  32. 'handler' => 'views_handler_filter_numeric',
  33. 'allow empty' => TRUE,
  34. 'help' => 'Filter on a Feeds Source\'s feed_nid field.',
  35. ),
  36. 'argument' => array(
  37. 'handler' => 'views_handler_argument_numeric',
  38. 'numeric' => TRUE,
  39. 'validate type' => 'nid',
  40. 'help' => 'Argument on a Feeds Source\'s feed_nid field.',
  41. ),
  42. 'sort' => array(
  43. 'handler' => 'views_handler_sort',
  44. 'help' => 'Sort Feeds Source\'s feed_nid field.',
  45. ),
  46. );
  47. $data['feeds_source']['config'] = array(
  48. 'title' => 'Source',
  49. 'help' => 'The resource identifier for this feed. For instance a URL.',
  50. 'field' => array(
  51. 'handler' => 'feeds_views_handler_field_source',
  52. 'click sortable' => FALSE,
  53. ),
  54. );
  55. $data['feeds_source']['imported'] = array(
  56. 'title' => t('Imported date'),
  57. 'help' => t('The date the source was imported last.'),
  58. 'field' => array(
  59. 'handler' => 'views_handler_field_date',
  60. 'click sortable' => TRUE,
  61. ),
  62. 'filter' => array(
  63. 'handler' => 'views_handler_filter_date',
  64. ),
  65. 'argument' => array(
  66. 'handler' => 'views_handler_argument_date',
  67. ),
  68. 'sort' => array(
  69. 'handler' => 'views_handler_sort_date',
  70. ),
  71. );
  72. $data['feeds_source']['table']['join'] = array(
  73. 'node' => array(
  74. 'left_field' => 'nid',
  75. 'field' => 'feed_nid',
  76. 'type' => 'LEFT',
  77. ),
  78. );
  79. /**
  80. * Expose feeds_node_item table to views.
  81. */
  82. $data['feeds_item']['table'] = array(
  83. 'group' => 'Feeds item',
  84. );
  85. $data['feeds_item']['feed_nid'] = array(
  86. 'title' => t('Owner feed nid'),
  87. 'help' => t('The node id of the owner feed node if available.'),
  88. 'field' => array(
  89. 'handler' => 'views_handler_field_numeric',
  90. 'click sortable' => TRUE,
  91. ),
  92. 'filter' => array(
  93. 'handler' => 'views_handler_filter_numeric',
  94. 'allow empty' => TRUE,
  95. 'help' => t('Filter on Feed Items by the Feed they were generated from using the Node Id of the Feed Node.'),
  96. ),
  97. 'argument' => array(
  98. 'handler' => 'views_handler_argument_numeric',
  99. 'numeric' => TRUE,
  100. 'validate type' => 'nid',
  101. 'help' => t('Argument on Feed Items by the Feed they were generated from using the Node Id of the Feed Node.'),
  102. ),
  103. 'sort' => array(
  104. 'help' => t('Sort Feed Items by the Feed they were generated from using the Node Id of the Feed Node.'),
  105. ),
  106. 'relationship' => array(
  107. 'title' => t('Owner feed'),
  108. 'help' => t('Relate a feed item to its owner feed node if available.'),
  109. 'label' => t('Owner feed'),
  110. 'base' => 'node',
  111. 'base field' => 'nid',
  112. ),
  113. );
  114. $data['feeds_item']['url'] = array(
  115. 'title' => t('Item URL'),
  116. 'help' => t('Contains the URL of the feed item.'),
  117. 'field' => array(
  118. 'handler' => 'views_handler_field_url',
  119. 'click sortable' => TRUE,
  120. ),
  121. 'filter' => array(
  122. 'handler' => 'views_handler_filter_string',
  123. 'allow empty' => TRUE,
  124. 'help' => t('Filter on a Feeds Item\'s URL field.'),
  125. ),
  126. 'argument' => array(
  127. 'handler' => 'views_handler_argument_string',
  128. 'numeric' => TRUE,
  129. 'validate type' => 'nid',
  130. 'help' => t('Argument on a Feeds Item\'s URL field.'),
  131. ),
  132. 'sort' => array(
  133. 'help' => t('Sort on a Feeds Item\'s URL field.'),
  134. ),
  135. );
  136. $data['feeds_item']['guid'] = array(
  137. 'title' => t('Item GUID'),
  138. 'help' => t('Contains the GUID of the feed item.'),
  139. 'field' => array(
  140. 'click sortable' => TRUE,
  141. ),
  142. 'filter' => array(
  143. 'handler' => 'views_handler_filter_string',
  144. 'allow empty' => TRUE,
  145. 'help' => t('Filter on a Feeds Item\'s GUID field.'),
  146. ),
  147. 'argument' => array(
  148. 'handler' => 'views_handler_argument_string',
  149. 'numeric' => TRUE,
  150. 'validate type' => 'nid',
  151. 'help' => t('Argument on a Feeds Item\'s GUID field.'),
  152. ),
  153. 'sort' => array(
  154. 'help' => t('Sort on a Feeds Item\'s GUID field.'),
  155. ),
  156. );
  157. $data['feeds_item']['imported'] = array(
  158. 'title' => t('Import date'),
  159. 'help' => t('Contains the import date of the feed item.'),
  160. 'field' => array(
  161. 'handler' => 'views_handler_field_date',
  162. 'click sortable' => TRUE,
  163. ),
  164. 'sort' => array(
  165. 'handler' => 'views_handler_sort_date',
  166. 'help' => t('Sort on a Feeds Item\'s import date field.'),
  167. ),
  168. 'filter' => array(
  169. 'handler' => 'views_handler_filter_date',
  170. 'help' => t('Filter on a Feeds Item\'s import date field.'),
  171. ),
  172. 'argument' => array(
  173. 'handler' => 'views_handler_argument_date',
  174. 'numeric' => TRUE,
  175. 'validate type' => 'nid',
  176. 'help' => t('Argument on a Feeds Item\'s import date field.'),
  177. ),
  178. );
  179. // Add a relationship for each entity type relating the entity's base table
  180. // to the feeds_item table whre feeds_item.entity_type = 'entity_type'.
  181. foreach (entity_get_info() as $entity_type => $info) {
  182. if (!empty($info['base table'])) {
  183. $data['feeds_item']['table']['join'][$info['base table']] = array(
  184. 'left_field' => $info['entity keys']['id'],
  185. 'field' => 'entity_id',
  186. 'type' => 'LEFT',
  187. 'extra' => array(
  188. array(
  189. 'field' => 'entity_type',
  190. 'value' => $entity_type,
  191. ),
  192. ),
  193. );
  194. }
  195. }
  196. /**
  197. * Expose feeds_log table to views.
  198. */
  199. $data['feeds_log']['table'] = array(
  200. 'group' => 'Feeds log',
  201. 'base' => array(
  202. 'field' => array('flid'),
  203. 'title' => t('Feeds log'),
  204. 'help' => t('Logs events during importing, clearing, expiry.'),
  205. ),
  206. );
  207. $data['feeds_log']['flid'] = array(
  208. 'title' => t('Log id'),
  209. 'help' => t('The id of the log message.'),
  210. 'field' => array(
  211. 'handler' => 'views_handler_field',
  212. 'click sortable' => TRUE,
  213. ),
  214. 'filter' => array(
  215. 'handler' => 'views_handler_filter_numeric',
  216. ),
  217. 'argument' => array(
  218. 'handler' => 'views_handler_argument_numeric',
  219. 'numeric' => TRUE,
  220. ),
  221. 'sort' => array(
  222. 'handler' => 'views_handler_sort',
  223. ),
  224. );
  225. $data['feeds_log']['id'] = array(
  226. 'title' => t('Importer id'),
  227. 'help' => t('The id of an importer.'),
  228. 'field' => array(
  229. 'handler' => 'views_handler_field',
  230. 'click sortable' => TRUE,
  231. ),
  232. 'filter' => array(
  233. 'handler' => 'views_handler_filter_string',
  234. 'allow empty' => TRUE,
  235. 'help' => t('Filter on an importer id.'),
  236. ),
  237. 'argument' => array(
  238. 'handler' => 'feeds_views_handler_argument_importer_id',
  239. 'help' => t('Filter on an importer id.'),
  240. ),
  241. 'sort' => array(
  242. 'handler' => 'views_handler_sort',
  243. 'help' => t('Sort by importer id.'),
  244. ),
  245. 'relationship' => array(
  246. 'title' => t('Importer'),
  247. 'help' => t('Relate a log entry to its importer if available.'),
  248. 'label' => t('Importer'),
  249. 'base' => 'feeds_importer',
  250. 'base field' => 'id',
  251. ),
  252. );
  253. $data['feeds_log']['importer_name'] = array(
  254. 'real field' => 'id',
  255. 'title' => t('Importer name'),
  256. 'help' => t('The human readable name of an importer.'),
  257. 'field' => array(
  258. 'handler' => 'feeds_views_handler_field_importer_name',
  259. ),
  260. );
  261. $data['feeds_log']['feed_nid'] = array(
  262. 'title' => t('Feed node id'),
  263. 'help' => t('Contains the node id of a feed node if the feed\'s configuration is attached to a content type, otherwise contains 0.'),
  264. 'field' => array(
  265. 'handler' => 'views_handler_field_numeric',
  266. 'click sortable' => TRUE,
  267. ),
  268. 'filter' => array(
  269. 'handler' => 'views_handler_filter_numeric',
  270. 'allow empty' => TRUE,
  271. 'help' => t('Filter on a Feeds Source\'s feed_nid field.'),
  272. ),
  273. 'argument' => array(
  274. 'handler' => 'views_handler_argument_numeric',
  275. 'numeric' => TRUE,
  276. 'validate type' => 'nid',
  277. 'help' => t('Argument on a Feeds Source\'s feed_nid field.'),
  278. ),
  279. 'sort' => array(
  280. 'handler' => 'views_handler_sort',
  281. 'help' => t('Sort Feeds Source\'s feed_nid field.'),
  282. ),
  283. 'relationship' => array(
  284. 'title' => t('Feed node'),
  285. 'help' => t('Relate a log entry to its feed node if available.'),
  286. 'label' => t('Feed node'),
  287. 'base' => 'node',
  288. 'base field' => 'nid',
  289. ),
  290. );
  291. $data['feeds_log']['log_time'] = array(
  292. 'title' => t('Log time'),
  293. 'help' => t('The time of the event.'),
  294. 'field' => array(
  295. 'handler' => 'views_handler_field_date',
  296. 'click sortable' => TRUE,
  297. ),
  298. 'sort' => array(
  299. 'handler' => 'views_handler_sort_date',
  300. ),
  301. 'filter' => array(
  302. 'handler' => 'views_handler_filter_date',
  303. ),
  304. 'argument' => array(
  305. 'handler' => 'views_handler_argument_numeric',
  306. ),
  307. 'sort' => array(
  308. 'handler' => 'views_handler_sort',
  309. ),
  310. );
  311. $data['feeds_log']['request_time'] = array(
  312. 'title' => t('Request time'),
  313. 'help' => t('The time of the page request of an event.'),
  314. 'field' => array(
  315. 'handler' => 'views_handler_field_date',
  316. 'click sortable' => TRUE,
  317. ),
  318. 'sort' => array(
  319. 'handler' => 'views_handler_sort_date',
  320. ),
  321. 'filter' => array(
  322. 'handler' => 'views_handler_filter_date',
  323. ),
  324. 'argument' => array(
  325. 'handler' => 'views_handler_argument_numeric',
  326. ),
  327. 'sort' => array(
  328. 'handler' => 'views_handler_sort',
  329. ),
  330. );
  331. $data['feeds_log']['type'] = array(
  332. 'title' => t('Type'),
  333. 'help' => t('Type of log message.'),
  334. 'field' => array(
  335. 'handler' => 'views_handler_field',
  336. 'click sortable' => TRUE,
  337. ),
  338. 'filter' => array(
  339. 'handler' => 'views_handler_filter_string',
  340. ),
  341. 'argument' => array(
  342. 'handler' => 'views_handler_argument_string',
  343. ),
  344. 'sort' => array(
  345. 'handler' => 'views_handler_sort',
  346. ),
  347. );
  348. $data['feeds_log']['message'] = array(
  349. 'title' => t('Log message'),
  350. 'help' => t('The message logged by the event.'),
  351. 'field' => array(
  352. 'handler' => 'feeds_views_handler_field_log_message',
  353. 'click sortable' => FALSE,
  354. 'additional fields' => array(
  355. 'variables',
  356. ),
  357. ),
  358. 'filter' => array(
  359. 'handler' => 'views_handler_filter_string',
  360. ),
  361. 'sort' => array(
  362. 'handler' => 'views_handler_sort',
  363. ),
  364. );
  365. $data['feeds_log']['severity'] = array(
  366. 'title' => t('Severity'),
  367. 'help' => t('The severity of the event logged.'),
  368. 'field' => array(
  369. 'handler' => 'feeds_views_handler_field_severity',
  370. 'click sortable' => FALSE,
  371. ),
  372. 'filter' => array(
  373. 'handler' => 'feeds_views_handler_filter_severity',
  374. 'allow empty' => TRUE,
  375. 'help' => t('Filter on the severity of a log message.'),
  376. ),
  377. 'argument' => array(
  378. 'handler' => 'views_handler_argument_numeric',
  379. ),
  380. 'sort' => array(
  381. 'handler' => 'views_handler_sort',
  382. ),
  383. );
  384. $data['feeds_log']['table']['join'] = array(
  385. 'node' => array(
  386. 'left_field' => 'nid',
  387. 'field' => 'feed_nid',
  388. 'type' => 'LEFT',
  389. ),
  390. );
  391. return $data;
  392. }
  393. /**
  394. * Implements hook_views_plugins().
  395. */
  396. function feeds_views_plugins() {
  397. return array(
  398. 'argument validator' => array(
  399. 'feed_nid' => array(
  400. 'title' => t('Feed node id'),
  401. 'handler' => 'feeds_views_plugin_argument_validate_feed_nid',
  402. ),
  403. ),
  404. );
  405. }