function format_tweets($db, $tweets) { $i = 0; $html = ''; // $html = "<link rel='stylesheet' type='text/css' href='custom/include/social/twitter/twitter.css'>"; $html .= "<div style='height:400px;overflow:scroll'><table width='100%'>"; $html .= '<tr><th><h3>20 Latest Tweets</h3></th></tr>'; $html .= "<tr><td><img style='padding:5px;'; src='" . $tweets[0]['user']['profile_image_url'] . "'><b style='margin-left:5px; font-size:20px;'>" . "@" . $tweets[0]['user']['screen_name'] . "</b></td></tr>"; $html .= "</table>"; foreach ($tweets as $tweet) { $limit = 255; $tweet['text'] = format_feed_tweets($db, $tweet, $limit); if (count($tweet['entities']['hashtags']) > 0) { $tweets['text'] = replace_hashtags($db, $tweet); } if (count($tweet['entities']['user_mentions']) > 0) { $tweet['text'] = replace_users($db, $tweet); } $html .= "<div class='tweet' style='width:30%;float:left;padding:25px;height:100px;'>"; $html .= "<p>" . $tweet['text'] . "</p>"; $html .= "</div>"; $i++; } return $html . '</div>'; }
-Loop through all the tweets. - Replace any URLS for Hrefs first, this needs to be done first as this is what get stored in the DB so duplicate checking would not work otherwise. - Reformat the Date from twitters date format. - Check if the tweet has already been entered into the Activity Stream. - if no duplicates found use insert query to add tweet to activity stream. - Start loop again. */ if (empty($tweets['errors'])) { while ($i < count($tweets)) { $limit = 104; $tweets[$i]['text'] = format_feed_tweets($db, $tweets[$i], $limit); if (count($tweets[$i]['entities']['hashtags']) > 0) { $tweets[$i]['text'] = replace_hashtags($db, $tweets[$i]); } if (count($tweets[$i]['entities']['user_mentions']) > 0) { $tweets[$i]['text'] = replace_users($db, $tweets[$i]); } $date = date("Y-m-d H:i:s", strtotime($tweets[$i]['created_at'])); $image = "<img src=" . $tweets[$i]['user']['profile_image_url_https'] . " style=float:left;padding-right:5px;padding-bottom:5px;/>"; $duplicate_found = duplicate_check($db, $tweets[$i]['text'], $date); if (!$duplicate_found) { $id = create_guid(); $sql = "INSERT INTO sugarfeed (id, name, date_entered, date_modified, modified_user_id, created_by, description, deleted, assigned_user_id, related_module, related_id, link_url, link_type)\n VALUES\n ('" . $id . "',\n '" . $image . "<b>" . $tweets[$i]['user']['name'] . " </b>',\n '" . $date . "',\n '" . $date . "',\n '1',\n '1',\n '" . $tweets[$i]['text'] . "',\n '0',\n '" . $current_user->id . "',\n 'twitter',\n '" . $current_user->id . "',\n NULL,\n NULL);"; $results = $db->query($sql); $i++; } else { $i++; } } } }