public function twitterUserTimeLine() { $twit = new Twitter(); $user = $this->params[0]; $count = (int) $this->params[1]; return $twit->getUserTimeLine($user, $count); }
/** * Display the application. */ function doExecute() { // Get config $plugin = JPluginHelper::getPlugin('system', 'plugin_googlemap3'); $jversion = JVERSION; // In Joomla 1.5 get the parameters in Joomla 1.6 and higher the plugin already has them, but need to be rendered with JRegistry if (substr($jversion, 0, 3) == "1.5") { $params = new JParameter($plugin->params); } else { $params = new JRegistry(); $params->loadString($plugin->params); } // Get params $twittername = urldecode(JRequest::getVar('twittername', '')); if ($twittername == "") { $twittername = $params->get('twittername', ''); } $twittertweets = urldecode(JRequest::getVar('twittertweets', '')); if ($twittertweets == "") { $twittertweets = $params->get('twittertweets', '15'); } $line = urldecode(JRequest::getVar('twitterline', '')); if ($line == "") { $line = $params->get('twitterline', ''); } $twitterlinewidth = urldecode(JRequest::getVar('twitterlinewidth', '')); if ($twitterlinewidth == "") { $twitterlinewidth = $params->get('twitterlinewidth', '5'); } $twitterstartloc = urldecode(JRequest::getVar('twitterstartloc', '')); if ($twitterstartloc == "") { $twitterstartloc = $params->get('twitterstartloc', '5'); } $twitter = new Twitter(ltrim(rtrim($twittername))); $tweets = $twitter->getUserTimeLine(ltrim(rtrim($twittertweets)), 1); $profile = $twitter->getProfile(); // Start KML file, create parent node $dom = new DOMDocument('1.0', 'UTF-8'); //Create the root KML element and append it to the Document $node = $dom->createElementNS('http://earth.google.com/kml/2.1', 'kml'); $parNode = $dom->appendChild($node); //Create a Folder element and append it to the KML element $docnode = $dom->createElement('Document'); $parNode = $parNode->appendChild($docnode); $twitterStyleNode = $dom->createElement('Style'); $twitterStyleNode->setAttribute('id', 'tweetStyle'); $twitterIconstyleNode = $dom->createElement('IconStyle'); $twitterIconstyleNode->setAttribute('id', 'tweetIcon'); $twitterIconNode = $dom->createElement('Icon'); $twitterHref = $dom->createElement('href', $params->get('twittericon', '')); $twitterIconNode->appendChild($twitterHref); $twitterIconstyleNode->appendChild($twitterIconNode); $twitterStyleNode->appendChild($twitterIconstyleNode); $docnode->appendChild($twitterStyleNode); if ($line != '') { // Create a line of travelling $twitterStyleNode = $dom->createElement('Style'); $twitterStyleNode->setAttribute('id', 'lineStyle'); $twitterLinestyleNode = $dom->createElement('LineStyle'); $twitterColorNode = $dom->createElement('color', ltrim(rtrim($line))); $twitterLinestyleNode->appendChild($twitterColorNode); $twitterWidthNode = $dom->createElement('width', ltrim(rtrim($twitterlinewidth))); $twitterLinestyleNode->appendChild($twitterWidthNode); $twitterStyleNode->appendChild($twitterLinestyleNode); $docnode->appendChild($twitterStyleNode); } //Create a Folder element and append it to the KML element $fnode = $dom->createElement('Folder'); $folderNode = $parNode->appendChild($fnode); $nameNode = $dom->createElement('name', 'Tweets ' . $twittername); $folderNode->appendChild($nameNode); $tweets = array_reverse($tweets); $prev_location = explode(',', $twitterstartloc); // swap lat and long values. In kml is it different first long then lat $lat = $prev_location[0]; $prev_location[0] = $prev_location[1]; $prev_location[1] = $lat; foreach ($tweets as $tweet) { if ($tweet->coordinates == "") { $tweet->coordinates->coordinates = $prev_location; } else { $prev_location = $tweet->coordinates->coordinates; } } $tweets = array_reverse($tweets); foreach ($tweets as $tweet) { //Create a Placemark and append it to the document $node = $dom->createElement('Placemark'); $placeNode = $folderNode->appendChild($node); //Create an id attribute and assign it the value of id column $placeNode->setAttribute('id', 'tweet_' . $tweet->id_str); //Create name, description, and address elements and assign them the values of //the name, type, and address columns from the results $nameNode = $dom->createElement('name', date('d m Y g:i:s', strtotime($tweet->created_at))); $placeNode->appendChild($nameNode); $styleUrl = $dom->createElement('styleUrl', '#tweetStyle'); $placeNode->appendChild($styleUrl); $descText = ""; $descText .= "<a href='http://www.twitter.com/" . $profile->screen_name . "' target='_blank' title='Follow us'><h4 class='tw_user'><img src='" . $profile->profile_image_url . "' alt='" . $profile->name . "' />" . $profile->name . "</h4></a>"; $descText .= "<span class='tw_text'>" . $twitter->parseText($tweet->text) . "</span>"; $descText .= "<br/><span class='tw_date'>" . $twitter->timeSince($tweet->created_at) . "</span>"; $descNode = $dom->createElement('description', ''); $cdataNode = $dom->createCDATASection($descText); $descNode->appendChild($cdataNode); $placeNode->appendChild($descNode); $pointNode = $dom->createElement('Point'); $placeNode->appendChild($pointNode); $coor_pointNode = $dom->createElement('coordinates', implode(",", $tweet->coordinates->coordinates)); $pointNode->appendChild($coor_pointNode); } if ($line != '' && count($tweets) > 0) { // Create a line of travelling //Create a Placemark and append it to the document $node = $dom->createElement('Placemark'); $placeNode = $folderNode->appendChild($node); //Create an id attribute and assign it the value of id column $placeNode->setAttribute('id', 'tweetline'); //Create name, description, and address elements and assign them the values of //the name, type, and address columns from the results $nameNode = $dom->createElement('name', ''); $placeNode->appendChild($nameNode); $styleUrl = $dom->createElement('styleUrl', '#lineStyle'); $placeNode->appendChild($styleUrl); //Create a LineString element $lineNode = $dom->createElement('LineString'); $placeNode->appendChild($lineNode); $exnode = $dom->createElement('extrude', '1'); $lineNode->appendChild($exnode); $almodenode = $dom->createElement('altitudeMode', 'relativeToGround'); $lineNode->appendChild($almodenode); $coordinates = ""; foreach ($tweets as $tweet) { $coordinates .= " " . implode(",", $tweet->coordinates->coordinates); } //Create a coordinates element and give it the value of the lng and lat columns from the results $coorNode = $dom->createElement('coordinates', $coordinates); $lineNode->appendChild($coorNode); } $kmlOutput = $dom->saveXML(); //assign the KML headers. header('Content-type: application/vnd.google-earth.kml+xml'); echo $kmlOutput; }