function isValid($value) { $trAdminFactory = new Translation2AdminFactory(); $trAdmin = $trAdminFactory->createTrAdmin($value); if (strpos(strtolower(get_class($trAdmin)), 'translation2_admin') === false) { $errors[] = 'UPLOADED_LANG_FILE_STRUCTURE_IS_INVALID'; SJB_Logger::error('UPLOADED_LANG_FILE_STRUCTURE_IS_INVALID'); return false; } $file_langs_list = $trAdmin->getLangs(); $import_lang_id = (string) $this->dataReflector->get('languageId'); if (!array_key_exists($import_lang_id, $file_langs_list)) { $errors[] = 'UPLOADED_LANG_FILE_DOESNOT_HAVE_NECESSARY_LANGUAGE'; SJB_Logger::error('UPLOADED_LANG_FILE_DOESNOT_HAVE_NECESSARY_LANGUAGE'); return false; } return true; }
function _validate() { $errors = array(); if (!empty($this->lang_file_data) && $this->lang_file_data['error'] == UPLOAD_ERR_NO_FILE) { $errors[] = 'Please choose language file'; return $errors; } if (!empty($this->lang_file_data) && $this->lang_file_data['error'] == UPLOAD_ERR_INI_SIZE) { $errors[] = 'File size exceeds system limit. Please check the file size limits on your hosting or upload another file'; return $errors; } if (!SJB_WrappedFunctions::is_uploaded_file($this->temp_file_path)) { $errors[] = 'LANG_FILE_UPLOAD_FAILED'; SJB_Logger::error('LANG_FILE_UPLOAD_FAILED'); } if (!SJB_WrappedFunctions::move_uploaded_file($this->temp_file_path, $this->file_path)) { $errors[] = 'UPLOADED_LANG_FILE_CANNOT_BE_MOVED'; SJB_Logger::error('UPLOADED_LANG_FILE_CANNOT_BE_MOVED'); } $fileHelper = $this->i18n->getFileHelper(); $languageID = $fileHelper->getLanguageIDForImportFile($this->file_name); if ($languageID === false) { $errors[] = 'The file format is invalid. Please try another file.'; SJB_Logger::error('The file format is invalid. Please try another file.'); } $lang_file_data = array('languageId' => $languageID, 'lang_file_path' => $this->file_path); $validator = $this->i18n->createImportLanguageValidator($lang_file_data); if (!$validator->isValid()) { $errors = array_merge($errors, $validator->getErrors()); } $fileSystem = new SJB_FileSystem(); if (!empty($errors)) { $fileSystem->deleteFile($this->file_path); } return $errors; }
function getInput($type, $value) { if (!$this->formatterFactory->doesFormatterExist($type)) { SJB_Logger::error('UNDEFINED_TYPE'); return $value; } $formatter = $this->formatterFactory->getFormatter($type); return $formatter->getInput($value); }
function createDateFormatter() { $date_format = $this->context->getDateFormat(); if (empty($date_format)) { SJB_Logger::error('FORMAT IS EMPTY'); $formatter = $this->getNullFormatter(); } else { $formatter = new SJB_DateFormatter(); $formatter->setDateFormat($date_format); } return $formatter; }
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; }
public static function getListingsFromBeyond($params) { $listingTypeID = SJB_ListingTypeManager::getListingTypeIDBySID($params->listing_type_sid); if ($listingTypeID == 'Job' && $GLOBALS['uri'] == '/search-results-jobs/' || $GLOBALS['uri'] == '/ajax/') { $limit = SJB_Settings::getSettingByName('countBeyondListings'); $start = $limit * ($params->listing_search_structure['current_page'] - 1) + 1; if ($limit) { // SET PARAMS FOR REQUEST $criteria = $params->criteria_saver->criteria; $categoryCriteria = isset($criteria['JobCategory']['multi_like']) ? $criteria['JobCategory']['multi_like'] : ''; $category = SJB_Settings::getSettingByName('BeyondIndustryList'); if (!empty($categoryCriteria)) { $categoryFromCriteria = self::getCategory($categoryCriteria); if ($category) { $category = explode('|', $category); $category = array_unique(array_merge($category, $categoryFromCriteria)); } else { $category = $categoryFromCriteria; } $category = implode('|', $category); } $keywords = SJB_Settings::getSettingByName('BeyondKeywords'); foreach ($criteria as $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 ($fieldType === 'location') { if (isset($values['value']) && !empty($values['value'])) { if ($keywords != '') { $keywords .= ' AND '; } $keywords .= $values['value']; } } if ($fieldType === 'like') { if ($keywords != '') { $keywords .= ' AND '; } $keywords .= $values; } } } } 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'))) { 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); $keywords = !empty($keywords) ? "({$keywords})" : ''; $city = ''; if (!empty($criteria['Location_City']['like'])) { $city = urlencode($criteria['Location_City']['like']); } else { if (!empty($criteria['Location_City']['multi_like_and'][0])) { $city = urlencode($criteria['Location_City']['multi_like_and'][0]); } else { if (!empty($criteria['Location']['location']['value'])) { $city = urlencode($criteria['Location']['location']['value']); } } } $state = SJB_Settings::getSettingByName('BeyondState'); if (isset($criteria['Location_State']['multi_like'])) { foreach ($criteria['Location_State']['multi_like'] as $stateSID) { if (!empty($stateSID)) { $stateInfo = SJB_StatesManager::getStateInfoBySID($stateSID); $state = !empty($stateInfo['state_code']) ? $stateInfo['state_code'] : ''; } } } $countryCriteria = isset($criteria['Location_Country']['multi_like'][0]) ? $criteria['Location_Country']['multi_like'][0] : SJB_Settings::getSettingByName('BeyondCountry'); $country = SJB_Settings::getSettingByName('BeyondCountry'); if ($countryCriteria && is_numeric($countryCriteria)) { $countryInfo = SJB_CountriesManager::getCountryInfoBySID($countryCriteria); $country = !empty($countryInfo['country_code']) ? $countryInfo['country_code'] : ''; } $employmentTypeCriteria = isset($criteria['EmploymentType']['multi_like']) ? $criteria['EmploymentType']['multi_like'] : ''; $employmentType = SJB_Settings::getSettingByName('BeyonEmploymentType'); if ($employmentTypeCriteria) { $employmentType = self::getEmploymentType($employmentTypeCriteria); } $zipCode = SJB_Settings::getSettingByName('BeyondZipcode'); if (isset($criteria['Location_ZipCode']['geo']['location']) && !empty($criteria['Location_ZipCode']['geo']['location'])) { $zipCode = $criteria['Location_ZipCode']['geo']['location']; } $educationLevel = SJB_Settings::getSettingByName('BeyonEducationLevel'); $experienceLevel = SJB_Settings::getSettingByName('BeyonExperienceLevel'); $affID = SJB_Settings::getSettingByName('BeyondAffiliateID'); $isIPhone = false; if (class_exists('MobilePlugin')) { $isIPhone = MobilePlugin::isPhone(); } if (str_replace('www.', '', $_SERVER['HTTP_HOST']) === SJB_Settings::getValue('mobile_url') || SJB_Settings::getValue('detect_iphone') && $isIPhone) { $mobileAffID = SJB_Settings::getSettingByName('MobileBeyondAffiliateID'); $affID = $mobileAffID ? $mobileAffID : $affID; } $url = "http://www.beyond.com/common/services/job/search/default.asp?aff={$affID}&kw={$keywords}&kt=3&il={$category}&ct={$country}&st={$state}&zc={$zipCode}&el={$educationLevel}&et={$employmentType}&ex={$experienceLevel}&nw=e&pn={$start}&mx={$limit}&fwhere={$city}"; $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); // close cURL resource, and free up system resources curl_close($ch); $beyondListings = array(); if ($xml !== false) { $doc = new DOMDocument(); $doc->loadXML($xml, LIBXML_NOERROR | LIBXML_NOWARNING); $results = $doc->getElementsByTagName('Item'); if ($results instanceof DOMNodeList) { // if we need just total results number foreach ($results as $node) { $resultXML = simplexml_import_dom($node); $jobKey = (string) $resultXML->SourceInformationID; $location = explode(',', (string) $resultXML->Location); $state = ''; $stateCode = ''; $country = ''; $city = !empty($location[0]) ? $location[0] : ''; if (isset($location[1])) { $location = explode(' ', trim($location[1])); if (!empty($location[0])) { $stateCode = trim($location[0]); $state = self::getState($stateCode); } if (!empty($location[1])) { $country = self::getCountry(trim($location[1])); } } $beyondListings[$jobKey] = array('Title' => (string) $resultXML->Title, 'CompanyName' => (string) $resultXML->CompanyName, 'JobDescription' => (string) $resultXML->ShortDescription, 'JobCategory' => (string) $resultXML->CareerFocus, 'State' => $state, 'Country' => $country, 'City' => $city, 'Location' => array('Country' => $country, 'State' => $state, 'State_Code' => $stateCode, 'City' => $city), 'url' => SJB_System::getSystemSettings('SITE_URL') . '/partnersite/?url=' . base64_encode((string) $resultXML->ApplyURL), 'jobkey' => $jobKey, 'activation_date' => (string) $resultXML->Modified, 'api' => 'beyond', 'code' => '<span id=beyond_at><a href="http://www.beyond.com/">jobs</a> by <a href="http://www.beyond.com/" title="Job Search"><img src="' . SJB_System::getSystemSettings('SITE_URL') . '/system/plugins/beyond_integration_plugin/logo.png" style="border: 0; vertical-align: middle;" alt="Beyond job search"></a></span>'); } } else { SJB_Logger::error('CANT GET BEYOND XML RESULTS'); } } else { SJB_Logger::error('NOT VALID RESPONSE FROM BEYOND'); } self::$beyondListings = $beyondListings; } } return $params; }
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; }
/** * @param string $url */ private static function setListingsUsingUrl($url) { $listings = array(); $xmlString = SJB_HelperFunctions::getUrlContentByCurl($url); if ($xmlString !== false) { $doc = new DOMDocument(); try { $doc->loadXML($xmlString, LIBXML_NOERROR); $results = $doc->getElementsByTagName('item'); if ($results instanceof DOMNodeList) { foreach ($doc->getElementsByTagName('item') as $result) { $result = simplexml_import_dom($result); $listings[] = array('Title' => htmlspecialchars_decode((string) $result->title), 'CompanyName' => (string) isset($result->company) ? $result->company : '', 'JobDescription' => (string) $result->description, 'Location' => array('Country' => isset($result->county) ? (string) $result->county : '', 'State_Code' => isset($result->state) ? (string) $result->state : '', 'City' => (string) $result->city), 'activation_date' => (string) $result->postdate, 'url' => $result->link, 'target' => 'target="_blank" ', 'api' => 'juju', 'code' => '<span id="juju_at"><a href="http://www.juju.com/">jobs</a> by <a href="http://www.juju.com/" title="Job Search"><img src="http://www.job-search-engine.com/assets/images/juju_logo.png" style="width: 54px; height: auto; border: 0; vertical-align: middle;"></a></span>'); } } } catch (ErrorException $e) { SJB_Logger::error($e->getMessage()); } } self::$jujuListings = $listings; }