I'm very new to PHP (I've only been working with it for about 3 months) and most of my experience is simply editing scripts... So, I'm sorta hitting a brick wall with this script I'm (attempting) to write. And, to top it off, it's a component for the Joomla! CMS, so they have their own predefined functions (with little documentation). However, most of the ones I'm using are rather self-explanatory...
Code: Select all
<?php
/**
* @version $Id: jobfider.php 5203 2008-10-29 JoeJ $
* @copyright Copyright (C) 2008 Joseph Johnson. All rights reserved.
* @package JobFinder
* Accepts a field input and then queries Simply Hired Jobs for the information and formats the returned XML.
*/
// no direct access
defined( '_JEXEC' ) or die(mysql_error);
// Check the task paramater and execute the appropriate function
switch( JRequest::getVar( 'task' )) {
case 'query':
doExecuteQuery();
break;
default:
displayQueryEntry();
break;
}
// Process data retrieved from form
function doExecuteQuery() {
// Get query from form posting values
$fldJobType = JRequest::getVar( 'JobType' );
$fldLocaton = JRequest::getVar( 'Location' );
// Eliminate these two lines when you move off of the test server !!!
$fldJobType = "Marketing";
$fldLocation = "Illinois";
// Strip away anything that could be code, carriage returns, and so on.
$fldJobType = preg_replace("/[^a-zA-Z0-9 .?!$()\'\"]/", "", $fldJobType);
$fldLocation = preg_replace("/[^a-zA-Z0-9 .?!$()\'\"]/", "", $fldLocation);
/*
YOU NEED TO REWRITE THE FOLLOWING PORTION SO THAT IT CAN RECEIVE AND FORMAT THE RETURNED DATA FROM SIMPLY HIRED JOBS.
THE DOCUMENTATION IS LOCATED IN /Development/Simply Hired Jobs/ and contains all of the information necessary.
Make sure to rewrite $myUrl, and call the correct functions (as opposed to, function getJob).
*/
$myData = getJob($fldJobType, $fldLocation); // This whole section needs to be redone... Feel free to skip over!
echo "<h1>Your Job Search Results</h1>";
echo "<p>Position: " . $fldJobType . "Location: " . $fldLocation . "<br></p>";
echo "<h2>Results: " . $myData . "</h2>";
echo "<a href=index.php?option=com_jobfinder>" . "Return to Job Search Form" . "</a>";
}
function getJob($usersJobResults, $usersLocation) { // What function should I be using? Change getJob to appropriate function!
$affiliateID = "MYID";
$myUrl = "http://instant.simplyhiredjobs.com/a/jobs/xml-v1/" . "q-" . $fldJobType . "l-" . $fldLocation;
// This is the example URL provided by Simply Hired docs. http://instant.simplyhired.com/a/jobs/xml-v1/q-software/l-CA/si-0
try { @$doc = DOMDocument::load($myUrl);
} catch(DOMException $e) {
echo '<p>' . print_r($e) . '</p>';
}
$q = "";
$l = "";
$params = $doc->getElementsByTagName('r'); // Gets results from returned XML
foreach ($params as $param) {
if (strlen($r) > 0) $r .= ", ";
$r .= $param ->textContent;
}
$params = $doc->getElementsByTagName('jt'); // Gets Job Title from returned XML
foreach ($params as $param) {
if (strlen($jt) > 0) $jt .= ", ";
$jt .= $param ->textContent;
}
$params = $doc->getElementsByTagName('cn'); // Gets Company Name from returned XML
foreach ($params as $param) {
if (strlen($cn) > 0) $cn .= ", ";
$cn .= $param ->textContent;
}
$params = $doc->getElementsByTagName('src'); / /Below is the source of the job; url attribute links to the job posting. Modify so link is clickable!
foreach ($params as $param) {
if (strlen($src) > 0) $src .= ", ";
$src .= $param ->textContent;
}
$params = $doc->getElementsByTagName('loc'); // Location.
foreach ($params as $param) {
if (strlen($loc) > 0) $loc .= ", ";
$loc .= $param ->textContent;
}
$params = $doc->getElementsByTagName('e'); // Excerpt of job description.
foreach ($params as $param) {
if (strlen($e) > 0) $e .= ", ";
$e .= $param ->textContent;
}
return $r . "<BR>";
echo "<p>" . $jt . ", " . $cn . ", " . $loc . "<br>"; // Echos back the Job Type, Company Name and Location for each result...
echo $e . "</p>"; // Echos the job description directly beneath the aforementioned...
}
// Display form for query entry
function displayQueryEntry() {
?>
<h1 class="contentheading">Job Search Form</h1>
<form id="form1" name="form1" method="post" action="index.php?option=com_jobfinder&task=query">
<p>Job Type:
<INPUT type="text" name="JobType" size="80" ><BR>
<p>Prefered Location:
<INPUT type="text" name="Location" size="30" ><BR>
</p>
<p>
<input type="submit" name="Submit" value="Start Searching!" />
</p>
</form>
<?php } ?>
I've googled the error, searched the forums and I'm currently downloading the manual, but I haven't found anything useful, yet... So, I was hoping somebody would be able to tell me what this means. That's the main question.Fatal error: Call to a member function getElementsByTagName() on a non-object in /home/dro/public_html/joomla/components/com_jobfinder/jobfinder.php on line 62
But, while I'm at it... I'm gonna through a few other things out there too:
Is there an easier way to format the returned XML? ...And, the way I'm currently doing it, is that right (or, even close)?
That's essentially the parts that have me stumped. I'd truly, greatly appreciate any help and insight that anyone can offer! Heck, even a link to an article that explains using PHP to work with RSS / XML feeds would be great (or a page reference for the manual)!
----------------------------------
Hrmph... After previewing my post, I must say that it seems pretty self-evident that I'm lost... A tutorial on sending form values to a 3rd party, receiving the resultant XML and properly formatting it would be a God-send! So, off to Google I go...
Anyway, like I said, any help / insight would greatly be appreciated! Thank you for your time and assistance.
Sincerely,
Joseph Johnson
FreeNetCo, Inc.