public static function saveLocation($location) { $location_sid = $location->getSID(); $countryInfo = SJB_CountriesManager::getCountryInfoBySID($location->country_sid); $locationField = $location->name . " " . $location->city . " " . $location->state . " " . $location->state_code; if ($countryInfo) { $locationField .= " " . $countryInfo['country_name'] . " " . $countryInfo['country_code']; } $locationField = explode(' ', $locationField); foreach ($locationField as $key => $field) { $field = trim($field); $len = strlen($field); if ($len < 4) { for ($i = $len; $i < 4; $i++) { $field .= '_'; } $locationField[$key] = $field; } } $locationField = implode(' ', $locationField); if (is_null($location_sid)) { return SJB_DB::query("INSERT INTO `locations` (`name`, `longitude`, `latitude`, `city`, `state`, `state_code`, `country_sid`, `location`) VALUES (?s, ?f, ?f, ?s, ?s, ?s, ?n, ?s)", $location->name, $location->longitude, $location->latitude, $location->city, $location->state, $location->state_code, $location->country_sid, $locationField, false); } return SJB_DB::query("UPDATE `locations` SET `name` = ?s, `longitude` = ?f, `latitude` = ?f, `city` = ?s, `state` = ?s, `state_code` = ?s, `country_sid` = ?n, `location` = ?s WHERE `sid` = ?n", $location->name, $location->longitude, $location->latitude, $location->city, $location->state, $location->state_code, $location->country_sid, $locationField, $location->getSID()); }
private static function changeLocationProperties(&$exportProperties, &$exportData) { $locationFieldsInfo = SJB_UserProfileFieldManager::getFieldsInfoByType('location'); foreach ($locationFieldsInfo as $fieldInfo) { if (isset($exportProperties[$fieldInfo['id']])) { unset($exportProperties[$fieldInfo['id']]); $exportLocationProperties[$fieldInfo['id'] . '.Country'] = $fieldInfo['id'] . '.Country'; $exportLocationProperties[$fieldInfo['id'] . '.State'] = $fieldInfo['id'] . '.State'; $exportLocationProperties[$fieldInfo['id'] . '.City'] = $fieldInfo['id'] . '.City'; $exportLocationProperties[$fieldInfo['id'] . '.ZipCode'] = $fieldInfo['id'] . '.ZipCode'; $exportLocationProperties[$fieldInfo['id'] . '.Address'] = $fieldInfo['id'] . '.Address'; ksort($exportLocationProperties); $exportProperties = array_merge($exportProperties, $exportLocationProperties); foreach ($exportData as $userSID => $property) { if (isset($property[$fieldInfo['id']]) && is_array($property[$fieldInfo['id']])) { $propertyLocation = array(); foreach ($property[$fieldInfo['id']] as $locationField => $fieldValue) { if ($locationField == 'Country' && !empty($locationField)) { $countryInfo = SJB_CountriesManager::getCountryInfoBySID($fieldValue); $fieldValue = !empty($countryInfo['country_name']) ? $countryInfo['country_name'] : ''; } elseif ($locationField == 'State') { $stateInfo = SJB_StatesManager::getStateInfoBySID($fieldValue); $fieldValue = !empty($stateInfo['state_name']) ? $stateInfo['state_name'] : ''; } $propertyLocation[$fieldInfo['id'] . '.' . $locationField] = $fieldValue; } unset($property[$fieldInfo['id']]); ksort($propertyLocation); $exportData[$userSID] = array_merge($property, $propertyLocation); } } } } }
public function execute() { ini_set('max_execution_time', 0); $encodingFromCharset = SJB_Request::getVar('encodingFromCharset', 'UTF-8'); $preview = SJB_Request::getVar('preview', false); $importedDataForPreview = array(); $template_processor = SJB_System::getTemplateProcessor(); $errors = null; $start_line = SJB_Request::getVar('start_line', null); $name_column = SJB_Request::getVar('name_column', null); $longitude_column = SJB_Request::getVar('longitude_column', null); $latitude_column = SJB_Request::getVar('latitude_column', null); $city_column = SJB_Request::getVar('city_column', null); $state_column = SJB_Request::getVar('state_column', null); $state_code_column = SJB_Request::getVar('state_code_column', null); $country_sid = SJB_Request::getVar('country_sid', null); $file_format = SJB_Request::getVar('file_format', null); $fields_delimiter = SJB_Request::getVar('fields_delimiter', null); $imported_file_config['start_line'] = $start_line; $imported_file_config['name_column'] = $name_column; $imported_file_config['longitude_column'] = $longitude_column; $imported_file_config['latitude_column'] = $latitude_column; $imported_file_config['city_column'] = $city_column; $imported_file_config['state_column'] = $state_column; $imported_file_config['state_code_column'] = $state_code_column; $imported_file_config['file_format'] = $file_format; $imported_file_config['fields_delimiter'] = $fields_delimiter; $imported_location_count = null; if (isset($_FILES['imported_geo_file']) && !$_FILES['imported_geo_file']['error']) { $fileInfo = $_FILES['imported_geo_file']; $fileFormats = array('csv', 'xls', 'xlsx'); $pathInfo = pathinfo($fileInfo['name']); $fileExtension = isset($pathInfo['extension']) ? strtolower($pathInfo['extension']) : ''; if (!in_array(strtolower($fileExtension), $fileFormats)) { $errors['File'] = 'WRONG_FORMAT'; } if (empty($_FILES['imported_geo_file']['name'])) { $errors['File'] = 'EMPTY_VALUE'; } if (empty($start_line)) { $errors['Start Line'] = 'EMPTY_VALUE'; } elseif (!is_numeric($start_line) || !is_int($start_line + 0)) { $errors['Start Line'] = 'NOT_INT_VALUE'; } if (empty($name_column)) { $errors['Name Column'] = 'EMPTY_VALUE'; } elseif (!is_numeric($name_column) || !is_int($name_column + 0)) { $errors['Name Column'] = 'NOT_INT_VALUE'; } if (empty($longitude_column)) { $errors['Longitude Column'] = 'EMPTY_VALUE'; } elseif (!is_numeric($longitude_column) || !is_int($longitude_column + 0)) { $errors['Longitude Column'] = 'NOT_INT_VALUE'; } if (empty($latitude_column)) { $errors['Latitude Column'] = 'EMPTY_VALUE'; } elseif (!is_numeric($latitude_column) || !is_int($latitude_column + 0)) { $errors['Latitude Column'] = 'NOT_INT_VALUE'; } if (empty($country_sid)) { $errors['Country'] = 'EMPTY_VALUE'; } if (!SJB_ImportFile::isValidFileExtensionByFormat($file_format, $_FILES['imported_geo_file'])) { $errors['File'] = 'DO_NOT_MATCH_SELECTED_FILE_FORMAT'; } if (!SJB_ImportFile::isValidFileCharset($_FILES['imported_geo_file'], $encodingFromCharset)) { $errors['Charset'] = 'CHARSET_INCORRECT'; } if (is_null($errors)) { set_time_limit(0); $file_info = SJB_Array::get($_FILES, 'imported_geo_file'); if (!strcasecmp($file_format, 'excel')) { $import_file = new SJB_ImportFileXLS($file_info); } else { if ($fields_delimiter == 'semicolon') { $fields_delimiter = ';'; } elseif ($fields_delimiter == 'tab') { $fields_delimiter = "\t"; } else { $fields_delimiter = ','; } $import_file = new SJB_ImportFileCSV($file_info, $fields_delimiter); } $import_file->parse($encodingFromCharset); $imported_data = $import_file->getData(); $imported_location_count = 0; $countryInfo = SJB_CountriesManager::getCountryInfoBySID($country_sid); foreach ($imported_data as $key => $importedColumn) { if (empty($importedColumn[$name_column - 1]) || empty($importedColumn[$longitude_column - 1]) || empty($importedColumn[$latitude_column - 1]) || $start_line > $key) { continue; } $name = $importedColumn[$name_column - 1]; $longitude = $importedColumn[$longitude_column - 1]; $latitude = $importedColumn[$latitude_column - 1]; $city = isset($importedColumn[$city_column - 1]) ? $importedColumn[$city_column - 1] : null; $state = isset($importedColumn[$state_column - 1]) ? $importedColumn[$state_column - 1] : null; $state_code = isset($importedColumn[$state_code_column - 1]) ? $importedColumn[$state_code_column - 1] : null; if ($preview) { if (count($importedDataForPreview) >= 10) { break; } $importedDataForPreview[] = array('name' => $name, 'longitude' => $longitude, 'latitude' => $latitude, 'city' => $city, 'state' => $state, 'stateCode' => $state_code, 'country' => $countryInfo['country_name']); } else { $imported_location_count += SJB_LocationManager::addLocation($name, $longitude, $latitude, $city, $state, $state_code, $country_sid, $countryInfo); } } } } elseif ($_SERVER['REQUEST_METHOD'] == 'POST') { $errorSid = isset($_FILES['imported_geo_file']['error']) ? $_FILES['imported_geo_file']['error'] : 0; $errors['File'] = SJB_UploadFileManager::getErrorId($errorSid); } $countries = SJB_CountriesManager::getAllCountriesCodesAndNames(); $template_processor->assign("charSets", SJB_HelperFunctions::getCharSets()); $template_processor->assign("importedGeographicData", $importedDataForPreview); $template_processor->assign("countries", $countries); $template_processor->assign("country_sid", $country_sid); $template_processor->assign("errors", $errors); $template_processor->assign("imported_location_count", $imported_location_count); $template_processor->assign("imported_file_config", $imported_file_config); $template_processor->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); if ($preview) { $template_processor->display("import_geographic_data_preview.tpl"); } else { $template_processor->display("import_geographic_data_form.tpl"); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $action = SJB_Request::getVar('action', 'list'); $countrySID = SJB_Request::getVar('country_sid', false); $errors = array(); $template = 'states.tpl'; $countries = SJB_CountriesManager::getAllCountries(); $paginator = new SJB_StatesPagination(); switch ($action) { case 'move_state': case 'save_order': $template = 'move_state.tpl'; $itemSIDs = SJB_Request::getVar('item_order', array()); try { SJB_StatesManager::saveItemsOrder($paginator->currentPage, $paginator->itemsPerPage, $itemSIDs); $tp->assign('action', $action); } catch (Exception $e) { $errors['SAVING_ORDER'] = $e->getMessage(); } $states = SJB_StatesManager::getAllStates($countrySID); $tp->assign('states', $states); break; case 'activate': $statesSIDs = array_keys(SJB_Request::getVar('states', array())); foreach ($statesSIDs as $stateSID) { SJB_StatesManager::activateStateBySID($stateSID); } $action = 'list'; break; case 'deactivate': $statesSIDs = array_keys(SJB_Request::getVar('states', array())); foreach ($statesSIDs as $stateSID) { SJB_StatesManager::deactivateStateBySID($stateSID); } $action = 'list'; break; case 'delete': $statesSIDs = array_keys(SJB_Request::getVar('states', array())); foreach ($statesSIDs as $stateSID) { SJB_StatesManager::deleteStateBySID($stateSID); } $action = 'list'; break; case 'add_state': $template = 'add_state.tpl'; $formSubmitted = SJB_Request::getVar('action_add', false); $state = new SJB_State($_REQUEST); $addStateForm = new SJB_Form($state); $addStateForm->registerTags($tp); $addValidParam = array('field' => 'country_sid', 'value' => $countrySID); if ($formSubmitted && $addStateForm->isDataValid($errors, $addValidParam)) { $state->addProperty(array('id' => 'country_sid', 'type' => 'list', 'value' => $countrySID, 'is_required' => true, 'is_system' => true)); SJB_StatesManager::saveState($state); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/states/?country_sid=" . $countrySID); } else { $formFields = $addStateForm->getFormFieldsInfo(); $tp->assign('form_fields', $formFields); } break; case 'edit_state': $template = 'edit_state.tpl'; $stateSID = SJB_Request::getVar('state_id', false); $formSubmitted = SJB_Request::getVar('action_add', false); $stateInfo = SJB_StatesManager::getStateInfoBySID($stateSID); if ($stateInfo) { $stateInfo = array_merge($stateInfo, $_REQUEST); $state = new SJB_State($stateInfo); $addStateForm = new SJB_Form($state); $addStateForm->registerTags($tp); $state->setSID($stateSID); $addValidParam = array('field' => 'country_sid', 'value' => $stateInfo['country_sid']); if ($formSubmitted && $addStateForm->isDataValid($errors, $addValidParam)) { SJB_StatesManager::saveState($state); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/states/?country_sid=" . $stateInfo['country_sid']); } else { $formFields = $addStateForm->getFormFieldsInfo(); $tp->assign('form_fields', $formFields); $tp->assign('state_id', $stateSID); } } else { $tp->assign('action', 'edit'); $errors['WRONG_STATE_ID_SPECIFIED'] = 'WRONG_STATE_ID_SPECIFIED'; $template = 'state_errors.tpl'; } break; case 'import_states': $template = 'import_states.tpl'; $fileInfo = isset($_FILES['import_file']) ? $_FILES['import_file'] : null; $tp->assign("uploadMaxFilesize", SJB_UploadFileManager::getIniUploadMaxFilesize()); if ($fileInfo['error']) { $errors[] = SJB_UploadFileManager::getErrorId($fileInfo['error']); } elseif ($fileInfo) { $fileFormats = array('csv', 'xls', 'xlsx'); $pathInfo = pathinfo($fileInfo['name']); $fileExtension = isset($pathInfo['extension']) ? strtolower($pathInfo['extension']) : ''; if (!in_array(strtolower($fileExtension), $fileFormats)) { $errors[] = 'Please choose Excel or csv file'; } else { $importFile = new SJB_ImportFileXLS($fileInfo); $importFile->parse(); $importedData = $importFile->getData(); $state = new SJB_State(); $count = 0; foreach ($importedData as $key => $importedColumn) { if ($key == 1) { $data = array_merge(array(array('state_code', 'state_name')), array($importedColumn)); $importedProcessor = new SJB_ImportedStateProcessor($data, $state); } if (!$importedColumn) { continue; } $stateInfo = $importedProcessor->getData($importedColumn); if (!empty($stateInfo['state_code']) && !empty($stateInfo['state_name'])) { $state = new SJB_State($stateInfo); $state->addProperty(array('id' => 'country_sid', 'type' => 'list', 'value' => $countrySID, 'is_required' => true, 'is_system' => true)); $state->setPropertyValue('active', 1); $stateSID = SJB_StatesManager::getStateSIDByStateCode($stateInfo['state_code'], $countrySID); if ($stateSID) { $state->setSID($stateSID); } else { $count++; } SJB_StatesManager::saveState($state); } } $tp->assign('imported_states_count', $count); $template = 'import_states_result.tpl'; } } break; } if ($action == 'list') { $countryCode = SJB_Settings::getSettingByName('default_country_code'); if (!$countrySID) { $countrySID = SJB_CountriesManager::getCountrySIDByCountryCode($countryCode); } if (!$countrySID) { $allCountries = SJB_CountriesManager::getAllCountries(); foreach ($allCountries as $country) { $countrySID = $country['sid']; break; } } $countryInfo = SJB_CountriesManager::getCountryInfoBySID($countrySID); if ($countryInfo && $countryInfo['country_code'] != $countryCode) { SJB_Settings::updateSetting('default_country_code', $countryInfo['country_code']); } $states = SJB_StatesManager::getAllStates($countrySID, ($paginator->currentPage - 1) * $paginator->itemsPerPage, $paginator->itemsPerPage); $paginator->setItemsCount(SJB_StatesManager::countStates($countrySID)); $tp->assign('states', $states); $tp->assign('paginationInfo', $paginator->getPaginationInfo()); } $tp->assign("countries", $countries); $tp->assign("country_sid", $countrySID); $tp->assign("errors", $errors); $tp->display($template); }
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; }
private function assignCurrentUserCountry() { $user = SJB_UserManager::getCurrentUser(); if ($user) { $locationValue = $user->getPropertyValue('Location'); $country = SJB_Array::get($locationValue, 'Country'); if ($country) { $countryInfo = SJB_CountriesManager::getCountryInfoBySID($country); $this->getTemplateProcessor()->assign('curUserCountryInfo', $countryInfo); } } }