Jump to content

mtorbin

Members
  • Posts

    65
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

mtorbin's Achievements

Member

Member (2/5)

0

Reputation

  1. In case anyone is wondering, I was able to figure it out using jQuery and an open API (though I'd rather use the tinyurl api instead): <html> <head> <script type="text/javascript" src="jQuery.js"></script> </head> <body> <div id="result"></div> <script type="text/javascript"> function TweetThis(bigurl){ $.getJSON( "http://json-tinyurl.appspot.com/?&callback=?", {url: bigurl}, function(data){ alert(data.tinyurl); } ); } TweetThis("http://www.phpfreaks.com/"); </script> </body> </html> Now I just need to convert this to prototype.js and I'm most of the way there. - MT
  2. If you have any other suggestions, I'd love to hear them. I feel like I'm at an impasse here with this.
  3. I definitely checked that but it didn't seem to do what I wanted it to do. I was able to get back the responseText and status, but not the HTML of the actual page. Here is the quick script I tested yesterday: <script type="text/javascript"> new Ajax.Request('http://tinyurl.com/api-create.php?url=http://www.phpfreaks.com/', { onSuccess: function(response) { alert(response.responseText.length); } }); </script> response is an object and the attribute that seemed most appropriate was responseText. As you can see it's returning a length of zero. - MT
  4. Morning folks, I'm trying to transfer my knowledge of php to ajax to accomplish what I believe should be a very easy goal. I am trying to get the contents of an html page loaded into a variable. Normally I would have done this with PHP but in this case, I really need to use AJAX or the Prototype.js framework to accomplish this. Here's what I'd like to do in PHP: <?php $myURL = "http://tinyurl.com/api-create.php?url=http://www.phpfreaks.com/"; $myContents = file_get_contents($myURL); ?> Can something like this be done in AJAX? I've been looking for tutorials but they don't quite cover (from what I've read) what I want to do. Thanks, - MT
  5. Hey all, I am working on a script that will call onMouseOut when the cursor leaves a fixed div but certain actions will be taken only if the cursor is now over a new dynamically placed div. Therefore, I need something like the following but I can't find the right syntax: function doThis() { if(document.getElementById("showMe").onmouseover == true) { // do this } else { // do that } } Any suggestions would be much appreciated. - MT
  6. I got a little closer but now I want to be able to get this data without having to pass it: <html> <head> <title></title> <script type="text/javascript"> function showDivNmbr() { alert(myElement); } </script> <style type="text/css"> #divContainer{width:270px;border:1px #000 solid;overflow:auto;} .singleDiv{text-align:center;width:50px;margin:2px;background-color:#777;color:#fff;cursor:pointer;float:left;} </style> </head> <body> <div id="divContainer"> <div class="singleDiv" onClick="showDivNmbr()" id="div1">one</div> <div class="singleDiv" onClick="showDivNmbr()" id="div2">two</div> <div class="singleDiv" onClick="showDivNmbr()" id="div3">three</div> <div class="singleDiv" onClick="showDivNmbr()" id="div4">four</div> <div class="singleDiv" onClick="showDivNmbr()" id="div5">five</div> <div class="singleDiv" onClick="showDivNmbr()" id="div6">six</div> <div class="singleDiv" onClick="showDivNmbr()" id="div7">seven</div> <div class="singleDiv" onClick="showDivNmbr()" id="div8">eight</div> <div class="singleDiv" onClick="showDivNmbr()" id="div9">nine</div> <div class="singleDiv" onClick="showDivNmbr()" id="div10">ten</div> </div> </body> </html>
  7. Hey all, I'm trying to write a script that will capture the index number of the calling tag (be it an anchor tag, a div, or whatever). As an experiment, I set up the following: <html> <head> <title></title> <script type="text/javascript"> function showDivNmbr(myElement) { alert(myElement); } </script> <style type="text/css"> #divContainer{width:270px;border:1px #000 solid;overflow:auto;} .singleDiv{text-align:center;width:50px;margin:2px;background-color:#777;float:left;} .singleDiv a{color:#fff;text-decoration:none;} </style> </head> <body> <div id="divContainer"> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div1">one</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div2">two</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div3">three</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div4">four</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div5">five</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div6">six</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div7">seven</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div8">eight</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div9">nine</a></div> <div class="singleDiv"><a href="javascript:showDivNmbr(this)" id="div10">ten</a></div> </div> </body> </html> Any suggestions would be most helpful. Thanks, - MT
  8. Ah, got it! I didn't go up high enough on the chain: <?php class VenueData { public function __construct($key,$name) { $searchURL = 'http://ws.audioscrobbler.com/2.0/?method=venue.search&api_key=' . $key . '&limit=1&venue=' . $name; $searchXML = simplexml_load_file($searchURL); foreach($searchXML->results->venuematches->venue as $venue) { print($venue->id . "\n"); } } } ?> - MT
  9. Hey all, I'm probably missing something super easy, but for whatever reason, my simpleXML object call is coming back null. Here is my code: <?php class VenueData { public function __construct($key,$name) { $this->searchURL = 'http://ws.audioscrobbler.com/2.0/?method=venue.search&api_key=' . $key . '&limit=1&venue=' . $name; $this->searchXML = simplexml_load_file($this->searchURL); $this->venueMatches = $this->searchXML->venuematches->{venue}; print(gettype($this->venueMatches) . "\n"); } } ?> Without giving away my key, here is a url that you can use to see the xml that's being pulled back: http://ws.audioscrobbler.com/2.0/?method=venue.search&api_key=b25b959554ed76058ac220b7b2e0a026&venue=arena Please help me figure out what I'm missing here. Thanks, - MT
  10. Ok, so I think I'm good now. I've addressed the object vs. array issue, I believe I've addressed the public/private/protected issue. The circular logic issue is one that I didn't quite understand. Could you explain? I've tested the code below and it definitely works. <?php abstract class TranslateXML { protected $eventData,$eventXML,$currentYear,$currentMonth,$currentDay,$today; function setEventVars($myOBJ,$myCount) { $this->eventData['myGameID'] = $myOBJ[$myCount]->getGameID(); $this->eventData['myHomeTeamName'] = $myOBJ[$myCount]->getTeamName('home'); $this->eventData['myHomeTeamCity'] = $myOBJ[$myCount]->getTeamCity('home'); $this->eventData['myVisitTeamName'] = $myOBJ[$myCount]->getTeamName('visit'); $this->eventData['myVisitTeamCity'] = $myOBJ[$myCount]->getTeamCity('visit'); $this->eventData['myGameDate'] = $myOBJ[$myCount]->getGameDate(); $this->eventData['myGameTime'] = $myOBJ[$myCount]->getGameTime(); $this->eventData['myVenueID'] = $myOBJ[$myCount]->getVenueID(); $this->eventData['myPerfID'] = $myOBJ[$myCount]->getPerfID(); $this->eventData['myGenre'] = $myOBJ[$myCount]->getPcomGenre(); return $this->eventData; } function buildNode($myEvent) { $eventXML .= "\t<event>\n"; $eventXML = "\t\t<event_id>STATS" . $myEvent['myGameID'] . "</event_id>\n"; $eventXML .= "\t\t<event_title>" . $myEvent['myVisitTeamCity'] . ' ' . $myEvent['myVisitTeamName'] . ' (away) vs. ' . $myEvent['myHomeTeamCity'] . ' ' . $myEvent['myHomeTeamName'] . " (home)</event_title>\n"; $eventXML .= "\t\t<perf_id>" . $myEvent['myPerfID'] . "</perf_id>\n"; $eventXML .= "\t\t<addl_perfs></addl_perfs>\n"; $eventXML .= "\t\t<venue_id>" . $myEvent['myVenueID'] . "</venue_id>\n"; $eventXML .= "\t\t<event_desc>" . $myEvent['myVisitTeamCity'] . ' ' . $myEvent['myVisitTeamName'] . ' (away) vs. ' . $myEvent['myHomeTeamCity'] . ' ' . $myEvent['myHomeTeamName'] . " (home) [" . $myEvent['myGameDate'] . ' @' . $myEvent['myGameTime'] . "]</event_desc>\n"; $eventXML .= "\t\t<genres>\n"; $eventXML .= "\t\t\t<genre>" . $myEvent['myGenre'] . "</genre>\n"; $eventXML .= "\t\t</genres>\n"; $eventXML .= "\t\t<showtimes></showtimes>\n"; $eventXML .= "\t\t<schedule>\n"; $eventXML .= "\t\t\t<performance date=\"" . $myEvent['myGameDate'] . "\">" . $myEvent['myGameTime'] . "</performance>\n"; $eventXML .= "\t\t</schedule>\n"; $eventXML .= "\t</event>\n"; return $eventXML; } function compareDates($myGameDate) { $currentYear = date('y'); $currentMonth = date('m'); $currentDay = date('d'); $today = strtotime($currentMonth . "/" . $currentDay . "/20" . $currentYear); $myGameDate = strtotime($myGameDate); if($today <= $myGameDate) {return 'future';} else {return 'past';} } } class StatScheduleXML extends TranslateXML { private $myXML; public function __construct($type,$url) { switch($type) { case 'mlb': include 'class/class.MlbSchedule.php'; $this->myXML = new mlbXML($url); break; case 'nba': include 'class/class.NbaSchedule.php'; $this->myXML = new nbaXML($url); break; case 'nfl': include 'class/class.NflSchedule.php'; $this->myXML = new nflXML($url); break; case 'nhl': include 'class/class.NhlSchedule.php'; $this->myXML = new nhlXML($url); break; } } function getNewXml() {return $this->myXML->getScheduleXml();} } class mlbXML extends StatScheduleXML { public function __construct($url) { $data = simplexml_load_file($url); $counter = 0; $mlbEvents = Array(); $this->scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'baseball-mlb-schedule'}->{'game-schedule'} as $schedule) { $scheduleOBJ = new MlbSchedule($schedule,$data); $mlbEvents[$counter] = $scheduleOBJ; if(($this->compareDates($mlbEvents[$counter]->getGameDate()) == 'future')&&(($mlbEvents[$counter]->getTeamName('home') == "Phillies")||($mlbEvents[$counter]->getTeamName('visit') == "Phillies"))) { $currentOBJ = $this->setEventVars($mlbEvents,$counter); $this->scheduleXML .= $this->buildNode($currentOBJ); } $counter++; } $this->scheduleXML .= "</events>\n"; } function getScheduleXml() { return $this->scheduleXML; } } class nbaXML extends StatScheduleXML { public function __construct($url) { $data = simplexml_load_file($url); $counter = 0; $nbaEvents = Array(); $this->scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'nba-schedule'}->{'game-schedule'} as $schedule) { $scheduleOBJ = new nbaSchedule($schedule,$data); $nbaEvents[$counter] = $scheduleOBJ; if(($this->compareDates($nbaEvents[$counter]->getGameDate()) == 'future')&&(($nbaEvents[$counter]->getTeamName('home') == "76ers")||($nbaEvents[$counter]->getTeamName('visit') == "76ers"))) { $currentOBJ = $this->setEventVars($nbaEvents,$counter); $this->scheduleXML .= $this->buildNode($currentOBJ); } $counter++; } $this->scheduleXML .= "</events>\n"; } function getScheduleXml() { return $this->scheduleXML; } } class nflXML extends StatScheduleXML { public function __construct($url) { $data = simplexml_load_file($url); $counter = 0; $nflEvents = Array(); $this->scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'football-nfl-schedule'}->{'game-schedule'} as $schedule) { $scheduleOBJ = new nflSchedule($schedule,$data); $nflEvents[$counter] = $scheduleOBJ; if(($this->compareDates($nflEvents[$counter]->getGameDate()) == 'future')&&(($nflEvents[$counter]->getTeamName('home') == "Eagles")||($nflEvents[$counter]->getTeamName('visit') == "Eagles"))) { $currentOBJ = $this->setEventVars($nflEvents,$counter); $this->scheduleXML .= $this->buildNode($currentOBJ); } $counter++; } $this->scheduleXML .= "</events>\n"; } function getScheduleXml() { return $this->scheduleXML; } } class nhlXML extends StatScheduleXML { public function __construct($url) { $data = simplexml_load_file($url); $counter = 0; $nhlEvents = Array(); $this->scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'hockey-nhl-schedule'}->{'game-schedule'} as $schedule) { $scheduleOBJ = new nhlSchedule($schedule,$data); $nhlEvents[$counter] = $scheduleOBJ; if(($this->compareDates($nhlEvents[$counter]->getGameDate()) == 'future')&&(($nhlEvents[$counter]->getTeamName('home') == "Flyers")||($nhlEvents[$counter]->getTeamName('visit') == "Flyers"))) { $currentOBJ = $this->setEventVars($nhlEvents,$counter); $this->scheduleXML .= $this->buildNode($currentOBJ); } $counter++; } $this->scheduleXML .= "</events>\n"; } function getScheduleXml() { return $this->scheduleXML; } } ?>
  11. OK, so I'm going through and making the suggested changes. In reference to your protected/private/public comment, we're talking about variables, right? In other words, all of my variables that are not in the abstract class should be declared private, yes? - MT
  12. PLEASE IGNORE THE ABOVE POST: Here is the new code that I was able to get to work properly: <?php abstract class TranslateXML { function setEventVars($myOBJ,$myCount) { $tempOBJ; $tempOBJ->myGameID = $myOBJ[$myCount]->getGameID(); $tempOBJ->myHomeTeamName = $myOBJ[$myCount]->getTeamName('home'); $tempOBJ->myHomeTeamCity = $myOBJ[$myCount]->getTeamCity('home'); $tempOBJ->myVisitTeamName = $myOBJ[$myCount]->getTeamName('visit'); $tempOBJ->myVisitTeamCity = $myOBJ[$myCount]->getTeamCity('visit'); $tempOBJ->myGameDate = $myOBJ[$myCount]->getGameDate(); $tempOBJ->myGameTime = $myOBJ[$myCount]->getGameTime(); $tempOBJ->myVenueID = $myOBJ[$myCount]->getVenueID(); $tempOBJ->myPerfID = $myOBJ[$myCount]->getPerfID(); $tempOBJ->myGenre = $myOBJ[$myCount]->getPcomGenre(); return $tempOBJ; } function buildNode($myOBJ) { $tempData .= "\t<event>\n"; $tempData = "\t\t<event_id>STATS" . $myOBJ->myGameID . "</event_id>\n"; $tempData .= "\t\t<event_title>" . $myOBJ->myVisitTeamCity . ' ' . $myOBJ->myVisitTeamName . ' (away) vs. ' . $myOBJ->myHomeTeamCity . ' ' . $myOBJ->myHomeTeamName . " (home)</event_title>\n"; $tempData .= "\t\t<perf_id>" . $myOBJ->myPerfID . "</perf_id>\n"; $tempData .= "\t\t<addl_perfs></addl_perfs>\n"; $tempData .= "\t\t<venue_id>" . $myOBJ->myVenueID . "</venue_id>\n"; $tempData .= "\t\t<event_desc>" . $myOBJ->myVisitTeamCity . ' ' . $myOBJ->myVisitTeamName . ' (away) vs. ' . $myOBJ->myHomeTeamCity . ' ' . $myOBJ->myHomeTeamName . " (home) [" . $myOBJ->myGameDate . ' @' . $myOBJ->myGameTime . "]</event_desc>\n"; $tempData .= "\t\t<genres>\n"; $tempData .= "\t\t\t<genre>" . $myOBJ->myGenre . "</genre>\n"; $tempData .= "\t\t</genres>\n"; $tempData .= "\t\t<showtimes></showtimes>\n"; $tempData .= "\t\t<schedule>\n"; $tempData .= "\t\t\t<performance date=\"" . $myOBJ->myGameDate . "\">" . $myOBJ->myGameTime . "</performance>\n"; $tempData .= "\t\t</schedule>\n"; $tempData .= "\t</event>\n"; return $tempData; } function compareDates($myGameDate) { $currentYear = date('y'); $currentMonth = date('m'); $currentDay = date('d'); $today = strtotime($currentMonth . "/" . $currentDay . "/20" . $currentYear); $myGameDate = strtotime($myGameDate); if($today <= $myGameDate) {return 'future';} else {return 'past';} } } class StatScheduleXML extends TranslateXML { private $myXML; public function __construct($type,$url) { switch($type) { case 'mlb': include 'class/class.MlbSchedule.php'; $this->myXML = new mlbXML($url); break; case 'nba': include 'class/class.NbaSchedule.php'; $this->myXML = new nbaXML($url); break; case 'nfl': include 'class/class.NflSchedule.php'; $this->myXML = new nflXML($url); break; case 'nhl': include 'class/class.NhlSchedule.php'; $this->myXML = new nhlXML($url); break; } } function getNewXml() {return $this->myXML->getScheduleXml();} } class mlbXML extends StatScheduleXML { public function __construct($url) { $data = simplexml_load_file($url); $counter = 0; $mlbEvents = Array(); $this->scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'baseball-mlb-schedule'}->{'game-schedule'} as $schedule) { $scheduleOBJ = new MlbSchedule($schedule,$data); $mlbEvents[$counter] = $scheduleOBJ; if(($this->compareDates($mlbEvents[$counter]->getGameDate()) == 'future')&&(($mlbEvents[$counter]->getTeamName('home') == "Phillies")||($mlbEvents[$counter]->getTeamName('visit') == "Phillies"))) { $currentOBJ = $this->setEventVars($mlbEvents,$counter); $this->scheduleXML .= $this->buildNode($currentOBJ); } $counter++; } $this->scheduleXML .= "</events>\n"; } function getScheduleXml() { return $this->scheduleXML; } } ?>
  13. That first function inside of TranslateXML (setEventVars) gives me the following errors: Fatal error: Class 'object' not found Googling this just returns a bunch of error pages. Any suggestions?
  14. Thanks again for all of you helping me through this learning curve. Below is what I perceive to be a good start towards a much better (and to Nightslyr's point, a better "smelling") class file. Please give me your thoughts and criticisms: <?php abstract class TranslateXML { function setEventVars($myOBJ,$myCount) { $tempOBJ = new Object(); $tempOBJ->myGameID = $myOBJ[$myCount]->getGameID(); $tempOBJ->myHomeTeamName = $myOBJ[$myCount]->getTeamName('home'); $tempOBJ->myHomeTeamCity = $myOBJ[$myCount]->getTeamCity('home'); $tempOBJ->myVisitTeamName = $myOBJ[$myCount]->getTeamName('visit'); $tempOBJ->myVisitTeamCity = $myOBJ[$myCount]->getTeamCity('visit'); $tempOBJ->myGameDate = $myOBJ[$myCount]->getGameDate(); $tempOBJ->myGameTime = $myOBJ[$myCount]->getGameTime(); $tempOBJ->myVenueID = $myOBJ[$myCount]->getVenueID(); $tempOBJ->myPerfID = $myOBJ[$myCount]->getPerfID(); $tempOBJ->myGenre = $myOBJ[$myCount]->getPcomGenre(); return $tempOBJ; } function buildNode($myOBJ) { $tempData .= "\t<event>\n"; $tempData = "\t\t<event_id>STATS" . $myOBJ->myGameID . "</event_id>\n"; $tempData .= "\t\t<event_title>" . $myOBJ->myVisitTeamCity . ' ' . $myOBJ->myVisitTeamName . ' (away) vs. ' . $myOBJ->myHomeTeamCity . ' ' . $myOBJ->myHomeTeamName . " (home)</event_title>\n"; $tempData .= "\t\t<perf_id>" . $myOBJ->myPerfID . "</perf_id>\n"; $tempData .= "\t\t<addl_perfs></addl_perfs>\n"; $tempData .= "\t\t<venue_id>" . $myOBJ->myVenueID . "</venue_id>\n"; $tempData .= "\t\t<event_desc>" . $myOBJ->myVisitTeamCity . ' ' . $myOBJ->myVisitTeamName . ' (away) vs. ' . $myOBJ->myHomeTeamCity . ' ' . $myOBJ->myHomeTeamName . " (home) [" . $myOBJ->myGameDate . ' @' . $myOBJ->myGameTime . "]</event_desc>\n"; $tempData .= "\t\t<genres>\n"; $tempData .= "\t\t\t<genre>" . $myOBJ->myGenre . "</genre>\n"; $tempData .= "\t\t</genres>\n"; $tempData .= "\t\t<showtimes></showtimes>\n"; $tempData .= "\t\t<schedule>\n"; $tempData .= "\t\t\t<performance date=\"" . $myOBJ->myGameDate . "\">" . $myOBJ->myGameTime . "</performance>\n"; $tempData .= "\t\t</schedule>\n"; $tempData .= "\t</event>\n"; return $tempData; } function compareDates($myGameDate) { $currentYear = date('y'); $currentMonth = date('m'); $currentDay = date('d'); $today = strtotime($currentMonth . "/" . $currentDay . "/20" . $currentYear); $myGameDate = strtotime($myGameDate); if($today <= $myGameDate) {return 'future';} else {return 'past';} } } class StatScheduleXML extends TranslateXML { private $myXML; public function __construct($type,$url) { switch($type) { case 'mlb': include 'class/class.MlbSchedule.php'; $this->myXML = new mlbXML($url); break; case 'nba': include 'class/class.NbaSchedule.php'; $this->myXML = new nbaXML($url); break; case 'nfl': include 'class/class.NflSchedule.php'; $this->myXML = new nflXML($url); break; case 'nhl': include 'class/class.NhlSchedule.php'; $this->myXML = new nhlXML($url); break; } } } class mlbXML extends StatScheduleXML { public function __construct($url) { $data = simplexml_load_file($url); $counter = 0; $mlbEvents = Array(); $scheduleXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<events>\n"; foreach($data->{'sports-schedule'}->{'baseball-mlb-schedule'}->{'game-schedule'} as $schedule) { $scheduleOBJ = new MlbSchedule($schedule,$data); $mlbEvents[$counter] = $scheduleOBJ; if(($this->compareDates($sportSchedules[$counter]->getGameDate()) == 'future')&&(($sportSchedules[$counter]->getTeamName('home') == "Phillies")||($sportSchedules[$counter]->getTeamName('visit') == "Phillies"))) { $currentOBJ = setEventVars($mlbEvents,$counter); $this->scheduleXML .= $this->buildNode($currentOBJ); } $counter++; } $scheduleXML .= "</events>\n"; } } ?> - MT
  15. Mark, thank you! I knew it was something simple.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.