twit.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <?php
  2. require_once(DRUPAL_ROOT . '/sites/all/libraries/twitter-api-php/TwitterAPIExchange.php');
  3. function twit_submit_libraries_info() {
  4. $libraries['twitter-api-php'] = array(
  5. 'name' => 'Twitter API Exchange',
  6. 'vendor url' => 'https://github.com/J7mbo/twitter-api-php',
  7. 'files' => array(
  8. 'php' => array('TwitterAPIExchange.php'), //this can be a path to the file location like array('lib/simple.js')
  9. ),
  10. );
  11. return $libraries;
  12. }
  13. /**
  14. *Add new hashtag to taxonomy as hashtag vocabulary type
  15. */
  16. function twit_submit_block_taxonomy_add($term) {
  17. $taxTerm = new stdClass();
  18. $taxTerm->name = $term;
  19. $taxTerm->vid = 6;
  20. taxonomy_term_save($taxTerm);
  21. return $taxTerm->tid;
  22. }
  23. /**
  24. *Check to see if hashtag is already in taxonomy before adding
  25. */
  26. function twit_submit_block_taxonomy_check($term) {
  27. $query = db_select('taxonomy_term_data', 'ttd')
  28. ->fields('ttd', array('tid', 'name'))
  29. ->condition('ttd.name', $term->text);
  30. $query = db_query('SELECT tid FROM taxonomy_term_data WHERE name = :name', array(
  31. ':name' => $term->text)
  32. );
  33. if ($query->rowCount() >= 2) {
  34. dpm($query->rowCount());
  35. $result = $query->fetchObject();
  36. dpm($result);
  37. $tid = $result->tid;
  38. } else {
  39. $tid = twit_submit_block_taxonomy_add($term->text);
  40. }
  41. return $tid;
  42. }
  43. /**
  44. *Update tracking of hashtag trends
  45. */
  46. function twithash_block_update($hashArray, $unixtime, $uid, $ip, $tweetId = NULL, $location = NULL) {
  47. $tmid = null;
  48. if ($location == NULL) {
  49. if ($ip == '127.0.0.1') {
  50. $geo = 1;
  51. } else {
  52. $geo = 1;
  53. }//Handling of non-local IPs to be added later
  54. } else {
  55. $checkLocQuery = db_query(
  56. ' SELECT id FROM twithash_geo
  57. WHERE country = :country
  58. AND city = :city
  59. AND region = :region',
  60. array(
  61. ':country' => 'Canada',
  62. ':city' => $location->city,
  63. ':region' => $location->province,
  64. )
  65. );
  66. $locResult = $checkLocQuery->fetchAll();
  67. if ($checkLocQuery->rowCount() > 0) {
  68. $geo = $locResult[0]->id;
  69. } else {
  70. $locInsert = db_insert('twithash_geo')
  71. ->fields(array(
  72. 'country' => 'Canada',
  73. 'city' => $location->city,
  74. 'region' => $location->province,
  75. ));
  76. $locId = $locInsert->execute();
  77. if ($locId != NULL && $locId > 0) {
  78. $geo = $locId;
  79. }
  80. }
  81. }
  82. $count = count($hashArray);
  83. //Populate twithash_term table with new terms or update number of hits for recurring terms. Simultaneously update twithash_term_update table which
  84. //tracks specific dates for each time a given term is searched.
  85. for ($i = 0; $i<$count; $i++) {
  86. $keyword = $hashArray[$i];
  87. $transaction = db_transaction();
  88. try{
  89. $tID = db_query('insert into twithash_term (term, hits, start) values (:term, 1, :start) on DUPLICATE KEY UPDATE hits = hits + :hits',
  90. array(
  91. ':term' => $keyword,
  92. ':start' => $unixtime,
  93. ':hits' => 1
  94. ),
  95. array('return' => Database::RETURN_INSERT_ID));
  96. //Insert IDs are collected for use in the query_master table, which tracks which different terms were compared up to a maximum
  97. //of 5 terms (the maximum allowed by Google Trends)
  98. if ($tID != 0)
  99. db_insert('twithash_term_update')
  100. ->fields(array(
  101. 't_id' => $tID,
  102. 'hit_time' => $unixtime
  103. ))
  104. ->execute();
  105. $tIDs[] = $tID;
  106. }
  107. catch (Exception $e) {
  108. $transaction->rollback();
  109. throw $e;
  110. }
  111. }
  112. $numTerms = isset($tIDs) ? count($tIDs) : 0;//Get number of terms in query
  113. switch ($numTerms) {//add overall query to twithash_master
  114. case 0:
  115. break;
  116. case 1:
  117. $tmid = db_query('
  118. INSERT INTO twithash_master (uid, query_date, geo, source, tid_1) VALUES (:uid, :query_date, :geo, :source, :tid_1)',
  119. array(
  120. ':uid' => $uid,
  121. ':query_date' => $unixtime,
  122. ':geo' => $geo,
  123. ':source' => 1,
  124. ':tid_1' => $tIDs[0]
  125. ),
  126. array('return' => Database::RETURN_INSERT_ID));
  127. break;
  128. case 2:
  129. $tmid = db_query('insert into twithash_master (uid, query_date, geo, source, tid_1, tid_2) values (:uid, :query_date, :geo, :source, :tid_1, :tid_2)',
  130. array(
  131. ':uid' => $uid,
  132. ':query_date' => $unixtime,
  133. ':geo' => $geo,
  134. ':source' => 1,
  135. ':tid_1' => $tIDs[0],
  136. ':tid_2' => $tIDs[1]
  137. ),
  138. array('return' => Database::RETURN_INSERT_ID));
  139. break;
  140. case 3:
  141. $tmid = db_query('insert into twithash_master (uid, query_date, geo, source, tid_1, tid_2, tid_3) values (:uid, :query_date, :geo, :source, :tid_1, :tid_2, :tid_3)',
  142. array(
  143. ':uid' => $uid,
  144. ':query_date' => $unixtime,
  145. ':geo' => $geo,
  146. ':source' => 1,
  147. ':tid_1' => $tIDs[0],
  148. ':tid_2' => $tIDs[1],
  149. ':tid_3' => $tIDs[2]
  150. ),
  151. array('return' => Database::RETURN_INSERT_ID));
  152. break;
  153. case 4:
  154. $tmid = db_query('insert into twithash_master (uid, query_date, geo, source, tid_1, tid_2, tid_3, tid_4) values (:uid, :query_date, :geo, :source, :tid_1, :tid_2, :tid_3, :tid_4)',
  155. array(
  156. ':uid' => $uid,
  157. ':query_date' => $unixtime,
  158. ':geo' => $geo,
  159. ':source' => 1,
  160. ':tid_1' => $tIDs[0],
  161. ':tid_2' => $tIDs[1],
  162. ':tid_3' => $tIDs[2],
  163. ':tid_4' => $tIDs[3]
  164. ),
  165. array('return' => Database::RETURN_INSERT_ID));
  166. break;
  167. case 5:
  168. $tmid = db_query('insert into twithash_master (uid, query_date, geo, source, tid_1, tid_2, tid_3, tid_4, tid_5) values (:uid, :query_date, :geo, :source, :tid_1, :tid_2, :tid_3, :tid_4, :tid_5)',
  169. array(
  170. ':uid' => $uid,
  171. ':query_date' => $unixtime,
  172. ':geo' => $geo,
  173. ':source' => 1,
  174. ':tid_1' => $tIDs[0],
  175. ':tid_2' => $tIDs[1],
  176. ':tid_3' => $tIDs[2],
  177. ':tid_4' => $tIDs[3],
  178. ':tid_5' => $tIDs[4]
  179. ),
  180. array('return' => Database::RETURN_INSERT_ID));
  181. break;
  182. }
  183. if ($tweetId != NULL && $tmid != NULL) {
  184. $tweetIdQuery = db_insert('twithash_tid')
  185. ->fields(array(
  186. 'tweetId' => $tweetId,
  187. 'thmid' => $tmid))
  188. ->execute();
  189. }
  190. return $tmid;
  191. }
  192. /**
  193. *Provide simple form for visitor to submit tweets
  194. */
  195. function twit_submit_block_form() {
  196. $form = array();
  197. $form['twit_fieldset'] = array(
  198. '#type' => 'fieldset',
  199. '#title' => t('SUBMIT TWEET'),
  200. '#prefix' => '<div id="terms-fieldset-wrapper">',
  201. '#suffix' => '</div>',
  202. '#collapsible' => TRUE,
  203. '#collapsed' => TRUE,
  204. '#ajax' => array(
  205. 'callback' => 'twit_submit_block_submit_callback',
  206. )
  207. // '#attributes' => array('onkeypress' => 'if(event.keyCode==13){ this.form.submit;}'),
  208. );
  209. $form['twit_fieldset']['tweet'] = array(
  210. '#type' => 'textarea',
  211. '#title' => t('Tweet'),
  212. '#description' => t('Please enter Tweet URL'),
  213. '#maxlength' => 80,
  214. '#size' => 25,
  215. '#attributes' => array('onchange' => 'tweetCheck(this.form.tweet.value)',),
  216. );
  217. $form['twit_fieldset']['submit'] = array(
  218. '#type' => 'submit',
  219. '#value' => 'Submit',
  220. '#id' => 'twitSubmitBtn',
  221. '#ajax' => array(
  222. 'callback' => 'twit_submit_block_submit_callback',
  223. )
  224. );
  225. $form['twit-notification'] = array(
  226. '#prefix' => '<div id="twit-notification">',
  227. '#suffix' => '</div>',
  228. );
  229. $form['twit-check'] = array(
  230. '#prefix' => '<div id="twit-check">',
  231. '#suffix' => '</div>',
  232. );
  233. $form['#attached']['js'][] = array(
  234. 'type' => 'inline',
  235. 'data' => drupal_get_path('module', 'twit_submit') . '/twit_submit.js',
  236. 'type' => 'file',
  237. );
  238. return $form;
  239. }
  240. /**
  241. *Form submit handler
  242. */
  243. function twit_submit_form_submit($form, &$form_state) {
  244. twit_submit_block_submit_callback($form, $form_state);
  245. }
  246. function twit_submit_block_submit_callback($form, &$form_state) {
  247. $form_state['rebuild'] = TRUE;
  248. //define Tokens for REST API request
  249. $settings = array(
  250. 'oauth_access_token' => "181287687-FNQLOpVXocD3gP46souGOj4FY1kMPlDzNw795MwQ",
  251. 'oauth_access_token_secret' => "w9KuI6T44w2HX6P8OCcOUDePHdyT6l0iGRCljKuZF9AE9",
  252. 'consumer_key' => "GULWdbfgUBicLUxEAD5a6KeE6",
  253. 'consumer_secret' => "6ereWWc9nkTZCS0TtgCDfW4tcTO3E5Wy5LW1kXk8qSrxL2YBAD"
  254. );
  255. //Acquire tweet ID
  256. $tweetSubmit = $form_state['values']['tweet'];
  257. $tweetIdArr = explode('status/', $tweetSubmit);
  258. $tweetId = $tweetIdArr[1];
  259. if ($tweetId == null) {
  260. return null;
  261. }
  262. $url = 'https://api.twitter.com/1.1/statuses/show.json';
  263. $getfield = '?id='.$tweetId.'&tweet_mode=extended';
  264. $requestMethod = 'GET';
  265. $twitter = new TwitterAPIExchange($settings);
  266. $response = $twitter->setGetfield($getfield)
  267. ->buildOauth($url, $requestMethod)
  268. ->performRequest();
  269. //Decode request
  270. $tresponse_decoded = json_decode($response);
  271. dpm($tresponse_decoded);
  272. //Create datetime object for title, media file path and content date field
  273. $nowtime = new DateTime();
  274. $unixtime = $nowtime->getTimestamp();
  275. $today = date("m.d.y");
  276. //Get screen name for title, media file path and content screen name field
  277. $twit_user = $tresponse_decoded->user->screen_name;
  278. //Check access level of user submitting tweet
  279. global $user;
  280. $ip = $user->data['geoip_location']['ip_address'];//get user's IP
  281. $uid = $user->uid;
  282. //Handler to optionally disable publishing of tweets based on access level
  283. if (in_array('content administrator', $user->roles) || in_array('administrator', $user->roles)) {
  284. $articleStatus = 1;
  285. $articlePromote = 0;
  286. }else{
  287. $articleStatus = 1;
  288. $articlePromote = 0;
  289. }
  290. //Prepare node object
  291. $node = new stdClass();
  292. $node->type = 'tweet';
  293. $node->language = LANGUAGE_NONE;
  294. node_object_prepare($node);
  295. //Define node title
  296. $node->title = $twit_user . '_' . $nowtime->format('Y.m.d.Hi');
  297. //Set basic node data: language, status, promoted, uid, posted/created date and tweet ID
  298. $node->body[$node->language][0]['value'] = $tresponse_decoded->full_text;
  299. $node->body[$node->language][0]['format'] = 'filtered_html';
  300. $node->status = $articleStatus;
  301. $node->promote = $articlePromote;
  302. $node->workbench_access = array('twitcher_tweet' => 'twitcher_tweet');
  303. $node->uid = $uid;
  304. $node->date = date('Y-m-d');//***!This should be changed to previous date variable
  305. $node->created = time();
  306. $node->field_tweet_id[$node->language][0]['value'] = $tresponse_decoded->id;
  307. //Get hashtags, populate taxonomy and set content type to tid
  308. $hashArray = array();
  309. $i = 0;
  310. foreach($tresponse_decoded->entities->hashtags as $key => $h) {
  311. $hashArray[] = $h->text;
  312. $tid = twit_submit_block_taxonomy_check($h);
  313. $node->field_hashtag[$node->language][$i]['tid'] = $tid;
  314. $i++;
  315. }
  316. $twithashUpdate = twithash_block_update($hashArray, $unixtime, $uid, $ip, $tresponse_decoded->id);
  317. if (!empty($tresponse_decoded->entities->user_mentions)) {
  318. $userArray = array();
  319. foreach($tresponse_decoded->entities->user_mentions as $userName) {
  320. $userArray[] = $userName->screen_name;
  321. }
  322. $twitUserUpdate = twituser_block_update($userArray, $unixtime, $uid, $ip, $tresponse_decoded->id);
  323. }
  324. //Set content's link field to urls as displayed within the tweet
  325. $i = 0;
  326. if (!empty($tresponse_decoded->entities->urls)) {
  327. foreach ($tresponse_decoded->entities->urls as $url) {
  328. $node->field_tweet_links[$node->language][$i]['value'] = $tresponse_decoded->entities->urls[$i]->display_url;
  329. $i++;
  330. }
  331. }
  332. if (!empty($tresponse_decoded->user->profile_image_url_https)) {
  333. $node->field_profile_pic[$node->language][0]['value'] = $tresponse_decoded->user->profile_image_url_https;
  334. }
  335. //Check for attached media and create a directory for saving
  336. if (isset($tresponse_decoded->extended_entities->media)) {
  337. if (!is_dir(DRUPAL_ROOT . '/sites/default/files/Tweet_Media/' . $today)) {
  338. mkdir(DRUPAL_ROOT . '/sites/default/files/Tweet_Media/' . $today);
  339. }
  340. //Save each media entity with a unique filename within directory
  341. $i = 0;
  342. foreach($tresponse_decoded->extended_entities->media as $media) {
  343. $ext = substr($media->media_url, -3);
  344. $filename = 'public://Tweet_Media/' . $today . '/' . $twit_user . $unixtime . $i . '.' . $ext;
  345. file_put_contents($filename, file_get_contents($media->media_url));
  346. //Download file and save to Drupal filesystem
  347. $image = file_get_contents($media->media_url);
  348. $file = file_save_data($image, $filename,FILE_EXISTS_REPLACE);
  349. //Associate file with content image field
  350. $node->field_tweet_images[$node->language][$i] = array(
  351. 'fid' => $file->fid,
  352. 'filename' => $file->filename,
  353. 'filemime' => $file->filemime,
  354. 'uid' => 1,
  355. 'uri' => $file->uri,
  356. 'status' => 1
  357. );
  358. $i++;
  359. }
  360. if(!empty($tresponse_decoded->extended_entities->media[0]->video_info->variants)) {
  361. $z = null;
  362. $vidUrl = null;
  363. $bitrate = new stdClass();
  364. $bitrate->value = null;
  365. $bitrate->index = null;
  366. for ($z = 0; $z < $tresponse_decoded->extended_entities->media[0]->video_info->variants; $z++) {
  367. if (!empty($tresponse_decoded->extended_entities->media[0]->video_info->variants[$z]->bitrate) &&
  368. $tresponse_decoded->extended_entities->media[0]->video_info->variants[$z]->content_type === 'video/mp4') {
  369. if ($tresponse_decoded->extended_entities->media[0]->video_info->variants[$z]->bitrate > $bitrate->value) {
  370. $bitrate->value = $tresponse_decoded->extended_entities->media[0]->video_info->variants[$z]->bitrate;
  371. $bitrate->index = $z;
  372. }
  373. }
  374. }
  375. if ($bitrate->index !== null) {
  376. $vidUrl = $tresponse_decoded->extended_entities->media[0]->video_info->variants[$bitrate->index]->url;
  377. }
  378. $destination = 'public://Tweet_Media/' . $today;
  379. if ($vFile = system_retrieve_file($vidUrl, $destination, TRUE, FILE_EXISTS_REPLACE)) {
  380. $node->field_tweet_video[$node->language][0]['value'] = $vFile->uri;
  381. }
  382. }
  383. }
  384. //Set content screen name, date and tweet url
  385. $node->field_screen_name[$node->language][0]['value'] = $twit_user;
  386. $node->field_tweet_date[$node->language][0]['value'] = $unixtime;
  387. $node->field_tweet_date[$node->language][0]['timezone'] = 'America/New_York';
  388. $node->field_tweet_date[$node->language][0]['data_type'] = 'datestamp';
  389. $node->field_tweet_url[$node->language][0]['value'] = $tweetSubmit;
  390. //Set the node path and save
  391. $path = 'tweet/' . $tweetId;
  392. $node->path = array('alias' => $path);
  393. // if(node_save($node)) {
  394. // $commands[] = ajax_command_html('#twit-notification', 'Tweet submitted to Twitcher!');
  395. // }else{
  396. //
  397. // $commands[] = ajax_command_html('#twit-notification', 'Tweet could not be saved.');
  398. // }
  399. try {
  400. node_save($node);
  401. $commands[] = ajax_command_css('#twit-notification', array("display" => "block"));
  402. $commands[] = ajax_command_html('#twit-notification', 'Tweet submitted to Twitcher!');
  403. }catch(Exception $e) {
  404. dpm($e->getMessage());
  405. $commands[] = ajax_command_css('#twit-notification', array("display" => "block"));
  406. $commands[] = ajax_command_html('#twit-notification', 'Tweet could not be saved.');
  407. }
  408. $commands[] = ajax_command_invoke('#edit-tweet', 'val', array(''));
  409. // $commands[] = ajax_command_invoke('#twit-notification', 'addClass', array('twit-active'));
  410. $commands[] = ajax_command_invoke('#twit-notification', 'delay', array(3000));
  411. $commands[] = ajax_command_invoke('#twit-notification', 'fadeOut', array('slow'));
  412. return array('#type' => 'ajax', '#commands' => $commands);
  413. }
  414. /*
  415. * Implements hook_block_info()
  416. */
  417. /**
  418. * @return mixed
  419. */
  420. function twit_submit_block_info() {
  421. $blocks['twit_submit'] = array(
  422. 'info' => t('Submit tweet as article/node!'),
  423. );
  424. return $blocks;
  425. }
  426. /*
  427. * Implements hook_block_view()
  428. */
  429. /**
  430. * @param $delta
  431. * @return array
  432. */
  433. function twit_submit_block_view($delta) {
  434. $block = array();
  435. $twit_form = drupal_get_form('twit_submit_block_form');
  436. switch ($delta) {
  437. case 'twit_submit':
  438. $block['subject'] = t('Widget to submit tweets and save as node');
  439. $block['content'] = drupal_render($twit_form);
  440. break;
  441. }
  442. return $block;
  443. }
  444. /**
  445. * @param $userArray
  446. * @param $unixtime
  447. * @param $uid
  448. * @param $ip
  449. * @param null $tweetId
  450. * @param null $location
  451. * @return DatabaseStatementInterface|int|null
  452. * @throws Exception
  453. */
  454. function twituser_block_update($userArray, $unixtime, $uid, $ip, $tweetId = NULL, $location = NULL) {
  455. $tumid = null;
  456. // watchdog('twituser', var_dump($userArray));
  457. if ($ip == '127.0.0.1' && $location == NULL) {
  458. $geo = 1;
  459. } else {
  460. $location = smart_ip_get_location($ip);
  461. $geo = 1;
  462. }//Handling of non-local IPs to be added later
  463. $count = count($userArray);
  464. //Populate twithash_term table with new terms or update number of hits for recurring terms. Simultaneously update twithash_term_update table which
  465. //tracks specific dates for each time a given term is searched.
  466. for ($i = 0; $i<$count; $i++) {
  467. $userName = $userArray[$i];
  468. $transaction = db_transaction();
  469. try{
  470. $tID = db_query('insert into twituser_name (name, hits, start) values (:name, 1, :start) on DUPLICATE KEY UPDATE hits = hits + :hits',
  471. array(
  472. ':name' => $userName,
  473. ':start' => $unixtime,
  474. ':hits' => 1
  475. ),
  476. array('return' => Database::RETURN_INSERT_ID));
  477. //Insert IDs are collected for use in the query_master table, which tracks which different terms were compared up to a maximum
  478. //of 5 terms (the maximum allowed by Google Trends)
  479. if ($tID != 0)
  480. db_insert('twituser_name_update')
  481. ->fields(array(
  482. 't_id' => $tID,
  483. 'hit_time' => $unixtime
  484. ))
  485. ->execute();
  486. $tIDs[] = $tID;
  487. }
  488. catch (Exception $e) {
  489. $transaction->rollback();
  490. throw $e;
  491. }
  492. }
  493. $numTerms = isset($tIDs) ? count($tIDs) : 0;//Get number of terms in query
  494. switch ($numTerms) {//add overall query to twithash_master
  495. case 0:
  496. break;
  497. case 1:
  498. $tumid = db_query('insert into twituser_master (uid, query_date, geo, source, tid_1) values (:uid, :query_date, :geo, :source, :tid_1)',
  499. array(
  500. ':uid' => $uid,
  501. ':query_date' => $unixtime,
  502. ':geo' => $geo,
  503. ':source' => 1,
  504. ':tid_1' => $tIDs[0]
  505. ),
  506. array('return' => Database::RETURN_INSERT_ID));
  507. break;
  508. case 2:
  509. $tumid = db_query('insert into twituser_master (uid, query_date, geo, source, tid_1, tid_2) values (:uid, :query_date, :geo, :source, :tid_1, :tid_2)',
  510. array(
  511. ':uid' => $uid,
  512. ':query_date' => $unixtime,
  513. ':geo' => $geo,
  514. ':source' => 1,
  515. ':tid_1' => $tIDs[0],
  516. ':tid_2' => $tIDs[1]
  517. ),
  518. array('return' => Database::RETURN_INSERT_ID));
  519. break;
  520. case 3:
  521. $tumid = db_query('insert into twituser_master (uid, query_date, geo, source, tid_1, tid_2, tid_3) values (:uid, :query_date, :geo, :source, :tid_1, :tid_2, :tid_3)',
  522. array(
  523. ':uid' => $uid,
  524. ':query_date' => $unixtime,
  525. ':geo' => $geo,
  526. ':source' => 1,
  527. ':tid_1' => $tIDs[0],
  528. ':tid_2' => $tIDs[1],
  529. ':tid_3' => $tIDs[2]
  530. ),
  531. array('return' => Database::RETURN_INSERT_ID));
  532. break;
  533. case 4:
  534. $tumid = db_query('insert into twituser_master (uid, query_date, geo, source, tid_1, tid_2, tid_3, tid_4) values (:uid, :query_date, :geo, :source, :tid_1, :tid_2, :tid_3, :tid_4)',
  535. array(
  536. ':uid' => $uid,
  537. ':query_date' => $unixtime,
  538. ':geo' => $geo,
  539. ':source' => 1,
  540. ':tid_1' => $tIDs[0],
  541. ':tid_2' => $tIDs[1],
  542. ':tid_3' => $tIDs[2],
  543. ':tid_4' => $tIDs[3]
  544. ),
  545. array('return' => Database::RETURN_INSERT_ID));
  546. break;
  547. case 5:
  548. $tumid = db_query('insert into twituser_master (uid, query_date, geo, source, tid_1, tid_2, tid_3, tid_4, tid_5) values (:uid, :query_date, :geo, :source, :tid_1, :tid_2, :tid_3, :tid_4, :tid_5)',
  549. array(
  550. ':uid' => $uid,
  551. ':query_date' => $unixtime,
  552. ':geo' => $geo,
  553. ':source' => 1,
  554. ':tid_1' => $tIDs[0],
  555. ':tid_2' => $tIDs[1],
  556. ':tid_3' => $tIDs[2],
  557. ':tid_4' => $tIDs[3],
  558. ':tid_5' => $tIDs[4]
  559. ),
  560. array('return' => Database::RETURN_INSERT_ID));
  561. break;
  562. }
  563. if ($tweetId != NULL && $tumid != NULL) {
  564. $tweetIdQuery = db_insert('twituser_tid')
  565. ->fields(array(
  566. 'tweetId' => $tweetId,
  567. 'tumid' => $tumid))
  568. ->execute();
  569. }
  570. return $tumid > 0 ? $tumid : -1;
  571. }