twitter.views.inc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <?php
  2. /**
  3. * @file
  4. * Provide views data and handlers for twitter.module
  5. */
  6. /**
  7. * @defgroup views_twitter_module twitter.module handlers
  8. *
  9. * Includes the ability to create views of just the twitter table.
  10. * @{
  11. */
  12. /**
  13. * Implements hook_views_data().
  14. */
  15. function twitter_views_data() {
  16. // Basic table information.
  17. $data['twitter']['table']['group'] = t('Twitter');
  18. // Advertise this table as a possible base table
  19. $data['twitter']['table']['base'] = array(
  20. 'field' => 'twitter_id',
  21. 'title' => t('Twitter message'),
  22. 'help' => t('Twitter status messages.'),
  23. 'weight' => 10,
  24. );
  25. // Tweet ID
  26. $data['twitter']['twitter_id'] = array(
  27. 'title' => t('Twitter status message ID'),
  28. 'help' => t('The ID of the Twitter status message.'),
  29. 'field' => array(
  30. 'handler' => 'views_handler_field',
  31. 'click sortable' => TRUE,
  32. ),
  33. 'filter' => array(
  34. 'handler' => 'views_handler_filter_numeric',
  35. ),
  36. 'sort' => array(
  37. 'handler' => 'views_handler_sort',
  38. ),
  39. 'argument' => array(
  40. 'handler' => 'views_handler_argument_string',
  41. ),
  42. );
  43. // Twitter reply-to-status id
  44. $data['twitter']['in_reply_to_status_id'] = array(
  45. 'title' => t('In reply to status ID'),
  46. 'help' => t('The ID of the Twitter status this message is replying to.'),
  47. 'field' => array(
  48. 'handler' => 'views_handler_field',
  49. 'click sortable' => TRUE,
  50. ),
  51. 'filter' => array(
  52. 'handler' => 'views_handler_filter_numeric',
  53. 'allow empty' => TRUE,
  54. ),
  55. 'sort' => array(
  56. 'handler' => 'views_handler_sort',
  57. ),
  58. );
  59. // Twitter reply-to-status screen name
  60. $data['twitter']['in_reply_to_screen_name'] = array(
  61. 'title' => t('In reply to user name'),
  62. 'help' => t('The login account of the Twitter user this message is replying to.'),
  63. 'field' => array(
  64. 'handler' => 'views_handler_field',
  65. 'click sortable' => TRUE,
  66. ),
  67. 'filter' => array(
  68. 'handler' => 'views_handler_filter_string',
  69. 'allow empty' => TRUE,
  70. ),
  71. 'sort' => array(
  72. 'handler' => 'views_handler_sort',
  73. ),
  74. 'argument' => array(
  75. 'handler' => 'views_handler_argument_string',
  76. ),
  77. );
  78. // Twitter screen name
  79. $data['twitter']['screen_name'] = array(
  80. 'title' => t('Login name'),
  81. 'help' => t('The login account of the Twitter user.'),
  82. 'field' => array(
  83. 'handler' => 'views_handler_field',
  84. 'click sortable' => TRUE,
  85. ),
  86. 'filter' => array(
  87. 'handler' => 'views_handler_filter_string',
  88. ),
  89. 'sort' => array(
  90. 'handler' => 'views_handler_sort',
  91. ),
  92. 'argument' => array(
  93. 'handler' => 'views_handler_argument_string',
  94. ),
  95. );
  96. // Twitter message timestamp
  97. $data['twitter']['created_time'] = array(
  98. 'title' => t('Created time'),
  99. 'help' => t('The time the Twitter message was posted.'),
  100. 'field' => array(
  101. 'handler' => 'views_handler_field_date',
  102. 'click sortable' => TRUE,
  103. ),
  104. 'sort' => array(
  105. 'handler' => 'views_handler_sort',
  106. ),
  107. 'filter' => array(
  108. 'handler' => 'views_handler_filter_date',
  109. ),
  110. );
  111. // Twitter text
  112. $data['twitter']['text'] = array(
  113. 'title' => t('Message text'),
  114. 'help' => t('The text of the Twitter message.'),
  115. 'field' => array(
  116. 'handler' => 'twitter_views_handler_field_xss',
  117. 'click sortable' => TRUE,
  118. ),
  119. 'filter' => array(
  120. 'handler' => 'views_handler_filter_string',
  121. ),
  122. );
  123. // Twitter source
  124. $data['twitter']['source'] = array(
  125. 'title' => t('Source'),
  126. 'help' => t('The name of the application that posted the Twitter message.'),
  127. 'field' => array(
  128. 'handler' => 'views_handler_field_xss',
  129. 'click sortable' => TRUE,
  130. ),
  131. 'filter' => array(
  132. 'handler' => 'views_handler_filter_string',
  133. ),
  134. 'sort' => array(
  135. 'handler' => 'views_handler_sort',
  136. ),
  137. );
  138. $data['twitter_account']['table']['group'] = t('Twitter');
  139. $data['twitter_account']['table']['join'] = array(
  140. 'twitter' => array(
  141. 'left_field' => 'screen_name',
  142. 'field' => 'screen_name',
  143. ),
  144. 'users' => array(
  145. 'left_field' => 'uid',
  146. 'field' => 'uid',
  147. // 'left_table' => 'twitter_user',
  148. ),
  149. );
  150. // Twitter screen name
  151. $data['twitter_account']['screen_name'] = array(
  152. 'title' => t('Login name'),
  153. 'help' => t('The login account of the Twitter user.'),
  154. 'field' => array(
  155. 'handler' => 'views_handler_field',
  156. 'click sortable' => TRUE,
  157. ),
  158. 'filter' => array(
  159. 'handler' => 'views_handler_filter_string',
  160. ),
  161. 'sort' => array(
  162. 'handler' => 'views_handler_sort',
  163. ),
  164. 'argument' => array(
  165. 'handler' => 'views_handler_argument_string',
  166. ),
  167. );
  168. // Twitter account full name
  169. $data['twitter_account']['name'] = array(
  170. 'title' => t('Full name'),
  171. 'help' => t('The full name Twitter account user.'),
  172. 'field' => array(
  173. 'handler' => 'views_handler_field',
  174. 'click sortable' => TRUE,
  175. ),
  176. 'filter' => array(
  177. 'handler' => 'views_handler_filter_string',
  178. ),
  179. 'sort' => array(
  180. 'handler' => 'views_handler_sort',
  181. ),
  182. 'argument' => array(
  183. 'handler' => 'views_handler_argument_string',
  184. ),
  185. );
  186. // Twitter account description
  187. $data['twitter_account']['description'] = array(
  188. 'title' => t('Description'),
  189. 'help' => t('The description of the Twitter account.'),
  190. 'field' => array(
  191. 'handler' => 'views_handler_field',
  192. 'click sortable' => TRUE,
  193. ),
  194. 'filter' => array(
  195. 'handler' => 'views_handler_field_xss',
  196. ),
  197. 'sort' => array(
  198. 'handler' => 'views_handler_sort',
  199. ),
  200. );
  201. // Twitter account location
  202. $data['twitter_account']['location'] = array(
  203. 'title' => t('Location'),
  204. 'help' => t('The location of the Twitter account.'),
  205. 'field' => array(
  206. 'handler' => 'views_handler_field',
  207. 'click sortable' => TRUE,
  208. ),
  209. 'filter' => array(
  210. 'handler' => 'views_handler_field_xss',
  211. ),
  212. 'sort' => array(
  213. 'handler' => 'views_handler_sort',
  214. ),
  215. );
  216. // Twitter account description
  217. $data['twitter_account']['followers_count'] = array(
  218. 'title' => t('Followers'),
  219. 'help' => t('The number of users following this Twitter account.'),
  220. 'field' => array(
  221. 'handler' => 'views_handler_field_numeric',
  222. 'click sortable' => TRUE,
  223. ),
  224. 'filter' => array(
  225. 'handler' => 'views_handler_filter_numeric',
  226. ),
  227. 'sort' => array(
  228. 'handler' => 'views_handler_sort',
  229. ),
  230. );
  231. // Twitter account profile image
  232. $data['twitter_account']['profile_image_url'] = array(
  233. 'title' => t('Profile image'),
  234. 'help' => t('The image used by the Twitter account.'),
  235. 'field' => array(
  236. 'handler' => 'twitter_views_handler_field_profile_image',
  237. 'click sortable' => TRUE,
  238. ),
  239. );
  240. // Twitter account url
  241. $data['twitter_account']['url'] = array(
  242. 'title' => t('URL'),
  243. 'help' => t('The URL given by the Twitter account user.'),
  244. 'field' => array(
  245. 'handler' => 'views_handler_field_url',
  246. 'click sortable' => TRUE,
  247. ),
  248. 'filter' => array(
  249. 'handler' => 'views_handler_filter_string',
  250. ),
  251. 'sort' => array(
  252. 'handler' => 'views_handler_sort',
  253. ),
  254. );
  255. // Twitter account protected
  256. $data['twitter_account']['protected'] = array(
  257. 'title' => t('Protected status'),
  258. 'help' => t('Whether posts from this Twitter account should be visible to the general public.'),
  259. 'field' => array(
  260. 'handler' => 'views_handler_field_boolean',
  261. 'click sortable' => TRUE,
  262. ),
  263. 'filter' => array(
  264. 'handler' => 'views_handler_filter_boolean_operator',
  265. ),
  266. 'sort' => array(
  267. 'handler' => 'views_handler_sort',
  268. ),
  269. );
  270. // Twitter message timestamp
  271. $data['twitter_account']['last_refresh'] = array(
  272. 'title' => t('Last refresh'),
  273. 'help' => t('The time the Twitter account statuses were retrieved.'),
  274. 'field' => array(
  275. 'handler' => 'views_handler_field_date',
  276. 'click sortable' => TRUE,
  277. ),
  278. 'sort' => array(
  279. 'handler' => 'views_handler_sort',
  280. ),
  281. 'filter' => array(
  282. 'handler' => 'views_handler_filter_date',
  283. ),
  284. );
  285. // Twitter account description
  286. $data['twitter_account']['uid'] = array(
  287. 'title' => t('User ID'),
  288. 'help' => t('The UID of the Twitter account.'),
  289. );
  290. // Twitter account protected
  291. $data['twitter_account']['import'] = array(
  292. 'title' => t('Import status'),
  293. 'help' => t('Whether posts from this Twitter account should be imported automatically.'),
  294. 'field' => array(
  295. 'handler' => 'views_handler_field_boolean',
  296. 'click sortable' => TRUE,
  297. ),
  298. 'filter' => array(
  299. 'handler' => 'views_handler_filter_boolean_operator',
  300. ),
  301. 'sort' => array(
  302. 'handler' => 'views_handler_sort',
  303. ),
  304. );
  305. return $data;
  306. }
  307. /**
  308. * @todo Please document this function.
  309. * @see http://drupal.org/node/1354
  310. */
  311. function twitter_views_data_alter(&$data) {
  312. $data['users']['table']['join']['twitter'] = array(
  313. 'left_table' => 'twitter_account',
  314. 'left_field' => 'uid',
  315. 'field' => 'uid',
  316. );
  317. $data['users']['table']['join']['twitter_account'] = array(
  318. // 'left_table' => 'twitter_user',
  319. 'left_field' => 'uid',
  320. 'field' => 'uid',
  321. );
  322. }
  323. /**
  324. * @}
  325. */