public function current() { $listing_structure = array(); $info = current($this->array); if (is_numeric($info)) { $sid = $info; $cache = SJB_Cache::getInstance(); $cacheID = md5('ListingIterator::SJB_ListingManager::getObjectBySID' . $sid); if ($cache->test($cacheID)) { $listing = $cache->load($cacheID); } else { $listing = SJB_ListingManager::getObjectBySID($sid); $cache->save($listing, $cacheID, array(SJB_Cache::TAG_LISTINGS)); } $listing->addPicturesProperty(); $cacheId = md5('SJB_ListingTypeManager::getListingTypeIDBySID' . $listing->getListingTypeSID()); if (SJB_MemoryCache::has($cacheId)) { $listing_type = SJB_MemoryCache::get($cacheId); } else { $listing_type = SJB_ListingTypeManager::getListingTypeIDBySID($listing->getListingTypeSID()); SJB_MemoryCache::set($cacheId, $listing_type); } $listing_structure = SJB_ListingManager::createTemplateStructureForListing($listing); $listing_structure = SJB_ListingManager::newValueFromSearchCriteria($listing_structure, $this->criteria); if ($this->user_logged_in) { $listing_structure['saved_listing'] = SJB_SavedListings::getSavedListingsByUserAndListingSid($this->current_user_sid, $listing->getID()); } $listing_structure['activation_date'] = date('Y-m-d H:i:s', strtotime($listing_structure['activation_date'])); $listing_structure['expiration_date'] = date('Y-m-d H:i:s', strtotime($listing_structure['expiration_date'])); $listing_structure['listing_url'] = SJB_System::getSystemSettings('SITE_URL') . "/display-" . strtolower($listing_type) . "/" . $listing->getSID() . "/"; if (isset($listing->details->properties['EmploymentType'])) { $employmentInfo = $listing->details->properties['EmploymentType']->type->property_info; $employmentTypes = array(); $employment = explode(",", $employmentInfo['value']); foreach ($employmentInfo['list_values'] as $type) { $empType = str_replace(" ", "", $type['caption']); $employmentTypes[$empType] = 0; if (in_array($type['id'], $employment)) { $employmentTypes[$empType] = 1; } } $listing_structure['myEmploymentType'] = $employmentTypes; } // GOOGLE MAP SEARCH RESULTS CUSTOMIZATION if ($this->view == 'map') { $zipCode = $listing_structure['Location']['ZipCode']; // get 'latitude' and 'longitude' from zipCode field, if it not set $latitude = isset($listing_structure['latitude']) ? $listing_structure['latitude'] : ''; $longitude = isset($listing_structure['longitude']) ? $listing_structure['longitude'] : ''; if (!empty($zipCode) && empty($latitude) && empty($longitude)) { $result = SJB_DB::query("SELECT * FROM `locations` WHERE `name` = ?s LIMIT 1", $zipCode); if ($result) { $current_coordinates = array($result[0]['latitude'], $result[0]['longitude']); if (in_array($current_coordinates, self::$coordinates)) { self::$index += 0.0001; } $listing_structure['latitude'] = $result[0]['latitude'] + self::$index; $listing_structure['longitude'] = $result[0]['longitude'] + self::$index; self::$coordinates = array_merge(self::$coordinates, array($current_coordinates)); } } elseif (!empty($listing_structure['Location']['City']) && !empty($listing_structure['Location']['State']) && !empty($listing_structure['Location']['Country'])) { $address = $listing_structure['Location']['City'] . ', ' . $listing_structure['Location']['State'] . ', ' . $listing_structure['Location']['Country']; $address = urlencode($address); $cache = SJB_Cache::getInstance(); $parameters = array('City' => $listing_structure['Location']['City'], 'State' => $listing_structure['Location']['State'], 'Country' => $listing_structure['Location']['Country']); $hash = md5('google_map' . serialize($parameters)); $data = $cache->load($hash); if (!$data) { try { $geoCod = SJB_HelperFunctions::getUrlContentByCurl("http://maps.googleapis.com/maps/api/geocode/json?address={$address}&sensor=false"); $geoCod = json_decode($geoCod); if ($geoCod->status == 'OK') { $cache->save($geoCod, $hash); } } catch (Exception $e) { $backtrace = SJB_Logger::getBackTrace(); SJB_Error::writeToLog(array(array('level' => 'E_USER_WARNING', 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'backtrace' => sprintf("BACKTRACE:\n [%s]", join("<br/>\n", $backtrace))))); } } else { $geoCod = $data; } try { if (!is_object($geoCod)) { throw new Exception("Map object nave not been Created"); } if ($geoCod->status != 'OK') { throw new Exception("Status is not OK"); } $location = $geoCod->results[0]->geometry->location; $current_coordinates = array($location->lat, $location->lng); if (in_array($current_coordinates, self::$coordinates)) { self::$index += 0.0001; } $listing_structure['latitude'] = $location->lat + self::$index; $listing_structure['longitude'] = $location->lng + self::$index; self::$coordinates = array_merge(self::$coordinates, array($current_coordinates)); } catch (Exception $e) { $backtrace = SJB_Logger::getBackTrace(); SJB_Error::writeToLog(array(array('level' => 'E_USER_WARNING', 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'backtrace' => sprintf("BACKTRACE:\n [%s]", join("<br/>\n", $backtrace))))); } } } } elseif ($info) { $listing_structure = $info; } return $listing_structure; }
function getChargedTemplateProcessor() { $order_info = $this->criteria_saver->getOrderInfo(); if (isset($this->requested_data['sorting_field'], $this->requested_data['sorting_order'])) { $order_info = array('sorting_field' => $this->requested_data['sorting_field'], 'sorting_order' => $this->requested_data['sorting_order']); } if (!isset($order_info['sorting_field']) && !isset($order_info['sorting_order']) && SJB_Request::getVar('searchId', false)) { $this->requested_data['sorting_field'] = $order_info['sorting_field'] = !empty($this->requested_data['default_sorting_field']) ? $this->requested_data['default_sorting_field'] : null; $this->requested_data['sorting_order'] = $order_info['sorting_order'] = !empty($this->requested_data['default_sorting_order']) ? $this->requested_data['default_sorting_order'] : null; } $this->criteria_saver->setSessionForOrderInfo($order_info); if (isset($_REQUEST['show_brief_or_detailed'])) { $show_brief_or_detailed = $_REQUEST['show_brief_or_detailed']; } elseif ($this->criteria_saver->getBriefOrDetailedSearch()) { $show_brief_or_detailed = $this->criteria_saver->getBriefOrDetailedSearch(); } else { $show_brief_or_detailed = 'detailed'; } $this->criteria_saver->setSessionForBriefOrDetailedSearch($show_brief_or_detailed); $requireApprove = SJB_ListingTypeManager::getWaitApproveSettingByListingType($this->listing_type_sid); if ($requireApprove) { $this->requested_data['status']['equal'] = 'approved'; } $this->requested_data['active']['equal'] = '1'; $this->criteria_saver->setSessionForCriteria(array_merge(array('active' => array('equal' => '1')), $this->criteria_saver->getCriteria(), $this->requested_data)); $this->found_listings_sids = $this->_getListingSidCollectionFromRequest(); $lpp = $this->criteria_saver->getListingsPerPage(); if (!empty($this->requested_data['default_listings_per_page']) && empty($lpp)) { $this->criteria_saver->setSessionForListingsPerPage(intval($this->requested_data['default_listings_per_page'])); } if (isset($this->requested_data['listings_per_page'])) { $this->criteria_saver->setSessionForListingsPerPage(intval($this->requested_data['listings_per_page'])); } $this->criteria_saver->setSessionForCurrentPage(1); if (isset($this->requested_data['page'])) { $this->criteria_saver->setSessionForCurrentPage($this->requested_data['page']); } $this->criteria_saver->setSessionForObjectSIDs($this->found_listings_sids); $this->listing_search_structure = $this->criteria_saver->createTemplateStructureForSearch(); if (empty($this->listing_search_structure['sorting_field'])) { $this->listing_search_structure['sorting_field'] = 'activation_date'; } try { SJB_Event::dispatch('beforeGenerateListingStructure', $this, true); } catch (Exception $e) { if (strpos($e->getMessage(), 'simplyHiredPlugin: Failed to read XML from url -') !== false) { $a = explode('- ', $e->getMessage()); $this->pluginErrors['SIMPLY_HIRED_XML_READ_FAILED'] = $a[1]; } } $listings_structure = array(); if ($this->listing_search_structure['listings_number'] > 0) { $currentUserSID = SJB_UserManager::getCurrentUserSID(); $isUserLoggedIn = SJB_UserManager::isUserLoggedIn(); $listings_structure = new SJB_Iterator(); if (!empty($this->requested_data['view']) && $this->requested_data['view'] == 'map') { $listings_structure->setView('map'); } $listings_structure->setListingsSids($this->getListingSidCollectionForCurrentPage()); $listings_structure->setListingTypeSID($this->listing_type_sid); $listings_structure->setCriteria($this->criteria_saver->criteria); $listings_structure->setUserLoggedIn($isUserLoggedIn); $listings_structure->setCurrentUserSID($currentUserSID); } SJB_Event::dispatch('afterGenerateListingStructure', $listings_structure, true); return $this->_getChargedTemplateProcessor($listings_structure); }