public static function getListingsFromSimplyHired($params)
 {
     $listingTypeID = SJB_ListingTypeManager::getListingTypeIDBySID($params->listing_type_sid);
     if ($listingTypeID == 'Job' && $GLOBALS['uri'] == '/search-results-jobs/' || $GLOBALS['uri'] == '/ajax/') {
         $publisherID = SJB_Settings::getSettingByName('simplyHiredPublisherID');
         $limit = SJB_Settings::getSettingByName('countSimplyHiredListings');
         $ip = $_SERVER['REMOTE_ADDR'];
         $userAgent = urlencode(SJB_Request::getUserAgent());
         $start = $limit * ($params->listing_search_structure['current_page'] - 1) + 1;
         $stateIndexes = array('AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MD' => 'Maryland', 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming', 'DC' => 'District of Columbia', 'AS' => 'American Samoa', 'GU' => 'Guam', 'MP' => 'Northern Mariana Islands', 'PR' => 'Puerto Rico', 'UM' => "United's Minor Outlying Islands", 'VI' => 'Virgin Islands');
         $countryCodes = array('United States' => 'us', 'Australia' => 'au', 'Austria' => 'at', 'Belgium' => 'be', 'Brazil' => 'br', 'Canada' => 'ca', 'France' => 'fr', 'Germany' => 'de', 'India' => 'in', 'Ireland' => 'ie', 'Italy' => 'it', 'Mexico' => 'mx', 'Netherlands' => 'nl', 'Spain' => 'es', 'Switzerland' => 'ch', 'United Kingdom' => 'gb');
         // SET PARAMS FOR REQUEST
         $keywords = '';
         $criteria = $params->criteria_saver->criteria;
         $fieldSID = SJB_ListingFieldManager::getListingFieldSIDByID('JobCategory');
         $fieldInfo = SJB_ListingFieldDBManager::getListValuesBySID($fieldSID);
         $fieldList = array();
         foreach ($fieldInfo as $val) {
             $fieldList[$val['id']] = $val['caption'];
         }
         $categoryCriteria = isset($criteria['JobCategory']['multi_like']) ? $criteria['JobCategory']['multi_like'] : '';
         if (!empty($categoryCriteria)) {
             foreach ($categoryCriteria as $category) {
                 if (!empty($fieldList[$category])) {
                     $keywords .= empty($keywords) ? $fieldList[$category] : ' OR ' . $fieldList[$category];
                 }
             }
             if (!empty($keywords)) {
                 $keywords = "({$keywords})";
             }
         }
         foreach ($criteria as $field) {
             if (is_array($field)) {
                 foreach ($field as $fieldType => $values) {
                     if ($fieldType == 'multi_like_and') {
                         foreach ($values as $val) {
                             $keywords .= empty($keywords) ? $val : ' ' . $val;
                         }
                     }
                 }
             }
         }
         if (isset($criteria['keywords']) && !empty($criteria['keywords'])) {
             foreach ($criteria['keywords'] as $key => $item) {
                 if (in_array($key, array('exact_phrase', 'any_words', 'all_words', 'like'))) {
                     $keywords .= $item;
                 }
             }
         }
         $systemKeywords = trim(SJB_Settings::getSettingByName('simplyHiredKeyword'));
         $keywords = $systemKeywords ? '(' . $systemKeywords . ')' . ($keywords ? ' OR (' . $keywords . ')' : '') : $keywords;
         $keywords = preg_replace('/\\s+/', ' ', $keywords);
         $keywords = str_replace(',', '', $keywords);
         $keywords = urlencode(trim($keywords));
         $location = self::getLocation($criteria, 'simplyHiredLocation');
         $radius = SJB_Settings::getSettingByName('simplyHiredMiles');
         if (isset($criteria['Location_ZipCode']['geo']['radius']) && !empty($criteria['Location_ZipCode']['geo']['radius'])) {
             $radius = $criteria['Location_ZipCode']['geo']['radius'];
             if ($radius == 'any') {
                 $radius = '';
             }
         }
         $sortBy = SJB_Settings::getSettingByName('simplyHiredSortBy');
         $siteUrl = SJB_Settings::getSettingByName('simplyHiredSiteUrl');
         $jobAMaticDomain = SJB_Settings::getSettingByName('jobAMaticDomain', false);
         if (!empty($jobAMaticDomain) && $siteUrl == 'simplyhired.com') {
             $jobAMaticDomain = str_replace('http://', '', $jobAMaticDomain);
             $jobAMaticDomain = str_replace('/', '', $jobAMaticDomain);
             $jobAMaticDomain = "&jbd={$jobAMaticDomain}";
         } else {
             $jobAMaticDomain = '';
         }
         if ($siteUrl == 'simplyhired.com') {
             $ssty = 2;
         } else {
             $ssty = 3;
         }
         $url = "http://api.{$siteUrl}/a/jobs-api/xml-v2/q-{$keywords}/l-{$location}/mi-{$radius}/ws-{$limit}/pn-{$params->listing_search_structure['current_page']}/sb-{$sortBy}?pshid={$publisherID}&ssty={$ssty}&cflg=r{$jobAMaticDomain}&clip={$ip}";
         $sxml = new simplexml();
         $xmlString = SJB_HelperFunctions::getUrlContentByCurl($url);
         $simplyhiredListings = array();
         if ($xmlString === false) {
             //				throw new Exception("simplyHiredPlugin: Failed to read XML from url - {$url}");
             SJB_Logger::error("simplyHiredPlugin: Failed to read XML from url - {$url}");
         } else {
             //$tree = $sxml->xml_load_file($url, 'array');
             $tree = $sxml->xml_load_file($xmlString, 'array');
             $totalResults = 0;
             if ($tree !== false) {
                 $results = isset($tree['rs']) ? $tree['rs'] : array();
                 $outputCountry = array_flip($countryCodes);
                 foreach ($results as $node) {
                     if ($tree['rq']['rpd'] == 1) {
                         $node = array($node);
                     }
                     foreach ($node as $key => $result) {
                         $state = (string) $result['loc']['@attributes']['st'];
                         $country = (string) $result['loc']['@attributes']['country'];
                         $simplyhiredListings[$key] = array('Title' => (string) $result['jt'], 'CompanyName' => (string) isset($result['cn']['@content']) ? $result['cn']['@content'] : '', 'JobDescription' => (string) $result['e'], 'Location' => array('Country' => empty($country) ? '' : (isset($outputCountry[strtolower($country)]) ? $outputCountry[strtolower($country)] : ''), 'State' => empty($location[1]) ? '' : (isset($stateIndexes[strtoupper($state)]) ? $stateIndexes[strtoupper($state)] : ''), 'State_Code' => empty($state) ? '' : strtoupper($state), 'City' => (string) $result['loc']['@attributes']['cty']), 'activation_date' => (string) $result['dp'], 'url' => (string) $result['src']['@attributes']['url'], 'api' => 'simplyHired', 'onmousedown' => ' onMouseDown="xml_sclk(this);" ', 'target' => ' target="_blank"', 'onclick' => 'onclick="addStatisticsForSimplyHired();" ', 'code' => '<span style="font-size:10px; position:relative; top:-5px; font-family:Arial,sans-serif;color: #333;"><a style="color: #333; text-decoration:none" href="' . SJB_Request::getProtocol() . '://www.simplyhired.com/">Jobs</a> by</span> <a STYLE="text-decoration:none" href="' . SJB_Request::getProtocol() . '://www.simplyhired.com/"><img src="' . SJB_Request::getProtocol() . '://www.jobamatic.com/c/jbb/images/simplyhired.png" alt="Simply Hired"></a>');
                     }
                 }
             }
         }
         self::$simplyhiredListings = $simplyhiredListings;
     }
     return $params;
 }
Beispiel #2
0
 public static function getListingsFromIndeed($params)
 {
     $listingTypeID = SJB_ListingTypeManager::getListingTypeIDBySID($params->listing_type_sid);
     if ($listingTypeID == 'Job' && $GLOBALS['uri'] == '/search-results-jobs/' || $GLOBALS['uri'] == '/ajax/') {
         $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : $params->listing_search_structure['current_page'];
         $publisherID = SJB_Settings::getSettingByName('IndeedPublisherID');
         $limit = SJB_Settings::getSettingByName('countIndeedListings');
         $ip = $_SERVER['REMOTE_ADDR'];
         $userAgent = urlencode(SJB_Request::getUserAgent());
         $start = $limit * ($page - 1);
         $stateIndexes = array('AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MD' => 'Maryland', 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming', 'DC' => 'District of Columbia', 'AS' => 'American Samoa', 'GU' => 'Guam', 'MP' => 'Northern Mariana Islands', 'PR' => 'Puerto Rico', 'UM' => "United's Minor Outlying Islands", 'VI' => 'Virgin Islands');
         $countryCodes = array('United States' => 'us', 'Argentina' => 'ar', 'Australia' => 'au', 'Austria' => 'at', 'Bahrain' => 'bh', 'Belgium' => 'be', 'Brazil' => 'br', 'Canada' => 'ca', 'Chile' => 'cl', 'China' => 'cn', 'Colombia' => 'co', 'Czech Republic' => 'cz', 'Denmark' => 'dk', 'Finland' => 'fi', 'France' => 'fr', 'Germany' => 'de', 'Greece' => 'gr', 'Hong Kong' => 'hk', 'Hungary' => 'hu', 'India' => 'in', 'Indonesia' => 'id', 'Ireland' => 'ie', 'Israel' => 'il', 'Italy' => 'it', 'Japan' => 'jp', 'Korea' => 'kr', 'Kuwait' => 'kw', 'Luxembourg' => 'lu', 'Malaysia' => 'my', 'Mexico' => 'mx', 'Netherlands' => 'nl', 'New Zealand' => 'nz', 'Norway' => 'no', 'Oman' => 'om', 'Pakistan' => 'pk', 'Peru' => 'pe', 'Philippines' => 'ph', 'Poland' => 'pl', 'Portugal' => 'pt', 'Qatar' => 'qa', 'Romania' => 'ro', 'Russia' => 'ru', 'Russian Federation' => 'ru', 'Saudi Arabia' => 'sa', 'Singapore' => 'sg', 'South Africa' => 'za', 'Spain' => 'es', 'Sweden' => 'se', 'Switzerland' => 'ch', 'Taiwan' => 'tw', 'Turkey' => 'tr', 'United Arab Emirates' => 'ae', 'United Kingdom' => 'gb', 'Venezuela' => 've');
         $countryDomains = array('us' => 'indeed.com', 'ar' => 'ar.indeed.com', 'au' => 'au.indeed.com', 'at' => 'at.indeed.com', 'bh' => 'bh.indeed.com', 'be' => 'be.indeed.com', 'br' => 'indeed.com.br', 'ca' => 'ca.indeed.com', 'cl' => 'indeed.cl', 'cn' => 'cn.indeed.com', 'co' => 'co.indeed.com', 'cz' => 'cz.indeed.com', 'dk' => 'dk.indeed.com', 'fi' => 'indeed.fi', 'fr' => 'indeed.fr', 'de' => 'de.indeed.com', 'gr' => 'gr.indeed.com', 'hk' => 'indeed.hk', 'hu' => 'hu.indeed.com', 'in' => 'indeed.co.in', 'id' => 'id.indeed.com', 'ie' => 'ie.indeed.com', 'il' => 'il.indeed.com', 'it' => 'it.indeed.com', 'jp' => 'jp.indeed.com', 'kr' => 'kr.indeed.com', 'kw' => 'kw.indeed.com', 'lu' => 'indeed.lu', 'my' => 'indeed.com.my', 'mx' => 'indeed.com.mx', 'nl' => 'indeed.nl', 'nz' => 'nz.indeed.com', 'no' => 'no.indeed.com', 'om' => 'om.indeed.com', 'pk' => 'indeed.com.pk', 'pe' => 'indeed.com.pe', 'ph' => 'indeed.com.ph', 'pl' => 'pl.indeed.com', 'pt' => 'indeed.pt', 'qa' => 'qa.indeed.com', 'ro' => 'ro.indeed.com', 'ru' => 'ru.indeed.com', 'sa' => 'sa.indeed.com', 'sg' => 'indeed.com.sg', 'za' => 'indeed.co.za', 'es' => 'indeed.es', 'se' => 'se.indeed.com', 'ch' => 'indeed.ch', 'tw' => 'tw.indeed.com', 'tr' => 'tr.indeed.com', 'ae' => 'indeed.ae', 'gb' => 'indeed.co.uk', 've' => 've.indeed.com');
         // SET PARAMS FOR REQUEST
         $keywords = '';
         $criteria = $params->criteria_saver->criteria;
         $fieldSID = SJB_ListingFieldManager::getListingFieldSIDByID('JobCategory');
         $fieldInfo = SJB_ListingFieldDBManager::getListValuesBySID($fieldSID);
         $fieldList = array();
         foreach ($fieldInfo as $val) {
             $fieldList[$val['id']] = $val['caption'];
         }
         $categoryCriteria = isset($criteria['JobCategory']['multi_like']) ? $criteria['JobCategory']['multi_like'] : '';
         if (!empty($categoryCriteria)) {
             if (!empty($keywords)) {
                 $keywords .= ' or ';
             }
             foreach ($categoryCriteria as $category) {
                 if (!empty($category) && !empty($fieldList[$category])) {
                     $keywords .= $fieldList[$category] . ' or ';
                 }
             }
             $keywords = substr($keywords, 0, strlen($keywords) - 4);
         }
         foreach ($criteria as $fieldName => $field) {
             if (is_array($field)) {
                 foreach ($field as $fieldType => $values) {
                     if ($fieldType === 'multi_like_and') {
                         foreach ($values as $val) {
                             if ($keywords != '') {
                                 $keywords .= " and ";
                             }
                             $keywords .= $val;
                         }
                     }
                 }
             }
         }
         if (isset($criteria['keywords']) && !empty($criteria['keywords'])) {
             foreach ($criteria['keywords'] as $key => $item) {
                 if (in_array($key, array('exact_phrase', 'any_words', 'all_words'))) {
                     if (!empty($keywords)) {
                         $keywords .= ' or ';
                     }
                     $keywords .= $item;
                 }
             }
         }
         if (substr($keywords, -4) == ' or ') {
             $keywords = substr($keywords, 0, strlen($keywords) - 4);
         }
         $keywords = trim($keywords);
         $keywords = urlencode($keywords);
         $location = self::getLocation($criteria);
         if (isset($criteria['Location']['location']['radius']) && !empty($criteria['Location']['location']['radius'])) {
             if ($criteria['Location']['location']['radius'] == 'any') {
                 $radius = '';
             } else {
                 $radius = $criteria['Location']['location']['radius'];
             }
         } else {
             $radius = 0;
         }
         $indeedCountry = SJB_Settings::getSettingByName('IndeedCountry');
         $country = !empty($criteria['Location_Country']['multi_like'][0]) ? $criteria['Location_Country']['multi_like'][0] : $indeedCountry;
         $codes = array_values($countryCodes);
         if (!in_array($country, $codes)) {
             // ok. Country value - not correct Indeed value. Lets try convert it.
             if (is_numeric($country)) {
                 $countryInfo = SJB_CountriesManager::getCountryInfoBySID($country);
                 $country = !empty($countryInfo['country_code']) ? $countryInfo['country_code'] : '';
             }
         }
         $jobType = SJB_Settings::getSettingByName('IndeedJobType');
         $siteType = SJB_Settings::getSettingByName('IndeedSiteType');
         $sort = SJB_Settings::getSettingByName('IndeedSort');
         $highlight = SJB_Settings::getSettingByName('IndeedHighlightKeywords');
         $url = "http://api.indeed.com/ads/apisearch?publisher={$publisherID}&q={$keywords}&l={$location}&sort={$sort}&radius={$radius}&st={$siteType}&jt={$jobType}&start={$start}&limit={$limit}&fromage=&filter=&latlong=1&co={$country}&highlight={$highlight}&chnl=&userip={$ip}&useragent={$userAgent}&v=2";
         $ch = curl_init();
         // set URL and other appropriate options
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         // grab URL and pass it to the browser
         $xml = curl_exec($ch);
         curl_close($ch);
         $indeedListings = array();
         if ($xml !== false) {
             $doc = new DOMDocument();
             try {
                 $doc->loadXML($xml, LIBXML_NOERROR);
                 $results = $doc->getElementsByTagName('results');
                 if ($results instanceof DOMNodeList) {
                     $outputCountry = array_flip($countryCodes);
                     $totalResults = $doc->getElementsByTagName('totalresults')->item(0)->nodeValue;
                     $totalPages = ceil((int) $totalResults / $limit);
                     $pageNumber = $doc->getElementsByTagName('pageNumber')->item(0)->nodeValue;
                     $indeedDomain = !empty($indeedCountry) && isset($countryDomains[$indeedCountry]) ? $countryDomains[$indeedCountry] : $countryDomains['us'];
                     if (strpos($indeedDomain, '.') !== 2) {
                         $indeedDomain = 'www.' . $indeedDomain;
                     }
                     foreach ($results as $node) {
                         foreach ($node->getElementsByTagName('result') as $result) {
                             $resultXML = simplexml_import_dom($result);
                             $jobKey = (string) $resultXML->jobkey;
                             $state = (string) $resultXML->state;
                             $country = (string) $resultXML->country;
                             $indeedListings[$jobKey] = array('Title' => (string) $resultXML->jobtitle, 'CompanyName' => (string) $resultXML->company, 'JobDescription' => (string) $resultXML->snippet, 'Location' => array('Country' => empty($country) ? '' : $outputCountry[strtolower($country)], 'State' => empty($state) ? '' : isset($stateIndexes[strtoupper($state)]) ? $stateIndexes[strtoupper($state)] : $state, 'State_Code' => empty($state) ? '' : strtoupper($state), 'City' => (string) $resultXML->city), 'url' => (string) $resultXML->url, 'onmousedown' => ' onMouseDown="' . (string) $resultXML->onmousedown . '" ', 'target' => ' target="_blank" ', 'jobkey' => $jobKey, 'activation_date' => (string) $resultXML->date, 'api' => 'indeed', 'code' => '<span id="indeed_at"><a href="' . SJB_Request::getProtocol() . '://' . $indeedDomain . '/">jobs</a> by <a href="' . SJB_Request::getProtocol() . '://' . $indeedDomain . '/" title="Job Search"><img src="' . SJB_Request::getProtocol() . '://www.indeed.com/p/jobsearch.gif" style="border: 0; vertical-align: middle;" alt="Indeed job search"></a></span>', 'pageNumber' => $pageNumber, 'totalPages' => $totalPages);
                         }
                     }
                 } else {
                     SJB_Logger::error('CANT GET INDEED XML RESULTS');
                 }
             } catch (ErrorException $e) {
                 SJB_Logger::error($e->getMessage());
             }
         } else {
             SJB_Logger::error('NOT VALID RESPONSE FROM INDEED');
         }
         self::$indeedListings = $indeedListings;
     }
     return $params;
 }
Beispiel #3
0
 private static function getCategory($categories)
 {
     $industryList = (require_once 'industry_config.php');
     $result = array();
     $fieldSID = SJB_ListingFieldManager::getListingFieldSIDByID('JobCategory');
     $fieldInfo = SJB_ListingFieldDBManager::getListValuesBySID($fieldSID);
     $fieldList = array();
     foreach ($fieldInfo as $val) {
         $fieldList[$val['id']] = $val['caption'];
     }
     foreach ($categories as $category) {
         if (!empty($fieldList[$category]) && isset($industryList[$fieldList[$category]])) {
             $result[] = $industryList[$fieldList[$category]];
         }
     }
     return array_unique($result);
 }
 public static function setComplexFields(&$listing_field_info)
 {
     switch ($listing_field_info['type']) {
         case 'list':
         case 'multilist':
             if (!empty($listing_field_info['parent_sid'])) {
                 if ($listing_field_info['id'] == 'Country') {
                     $displayAS = !empty($listing_field_info['display_as']) ? $listing_field_info['display_as'] : 'country_name';
                     $listing_field_info['list_values'] = SJB_CountriesManager::getAllCountriesCodesAndNames(true, $displayAS);
                 }
             } else {
                 $listing_field_info['list_values'] = SJB_ListingFieldDBManager::getListValuesBySID($listing_field_info['sid']);
             }
             break;
         case 'tree':
             $listing_field_info['tree_values'] = SJB_ListingFieldDBManager::getTreeValuesBySID($listing_field_info['sid']);
             $listing_field_info['tree_depth'] = SJB_ListingFieldDBManager::getTreeDepthBySID($listing_field_info['sid']);
             break;
         case 'monetary':
             $listing_field_info['currency_values'] = SJB_CurrencyManager::getActiveCurrencyList();
             break;
         case 'complex':
             $listing_field_info['fields'] = SJB_ListingFieldDBManager::getListingFieldsInfoByParentSID($listing_field_info['sid']);
             $listing_field_info['table_name'] = 'listings';
             break;
         case 'location':
             $listing_field_info['fields'] = SJB_ListingFieldManager::getListingFieldsInfoByParentSID($listing_field_info['sid']);
             break;
         case 'geo':
             if (isset($listing_field_info['parent_sid'])) {
                 $parentID = SJB_DB::queryValue("SELECT `id` FROM `listing_fields` WHERE `sid` = ?n", $listing_field_info['parent_sid']);
                 $listing_field_info['parentID'] = $parentID;
             }
             break;
     }
     $listing_field_info['is_classifieds'] = 1;
 }