public function getProjection()
 {
     if ($this->cacheIsFresh() && $this->hasDBData) {
         // features are converted to lat/lon when stored
         return null;
     }
     return parent::getProjection();
     // returns parent's parser's projection
 }
Exemplo n.º 2
0
 public function searchCampusMap($query) {
     $this->searchResults = array();
 
 	foreach ($this->feeds as $id => $feedData) {
         $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
         $controller->setCategory($id);
         $controller->setDebugMode($GLOBALS['siteConfig']->getVar('DATA_DEBUG'));
         
         if ($controller->canSearch()) {
             $results = $controller->search($query);
             $this->resultCount += count($results);
             $this->searchResults = array_merge($this->searchResults, $results);
         }
 	}
 	
 	return $this->searchResults;
 }
Exemplo n.º 3
0
 public function searchCampusMap($query)
 {
     $this->searchResults = array();
     foreach ($this->feeds as $id => $feedData) {
         $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
         if ($controller->canSearch()) {
             try {
                 $results = $controller->search($query);
                 $this->resultCount += count($results);
                 $this->searchResults = array_merge($this->searchResults, $results);
             } catch (KurogoDataServerException $e) {
                 Kurogo::log(LOG_WARNING, 'encountered KurogoDataServerException for feed config: ' . print_r($feedData, true) . $e->getMessage(), 'maps');
             }
         }
     }
     return $this->searchResults;
 }
    protected function retrieveData($url)
    {
    	if (strpos($url, 'kmz') !== false) {
    	    if (!class_exists('ZipArchive')) {
    	        die("class ZipArchive (php-zip) not supported");
    	    }
            $tmpDir = $GLOBALS['siteConfig']->getVar('TMP_DIR');
    	    $tmpFile = $tmpDir.'/tmp.kmz';

    	    copy($url, $tmpFile);
    	    $zip = new ZipArchive();
    	    $zip->open($tmpFile);
    	    $contents = $zip->getFromIndex(0);
    	    unlink($tmpFile);
    	    return $contents; // this is false on failure, same as file_get_contents
    	} else {
    	    return parent::retrieveData($url);
    	}
    }
Exemplo n.º 5
0
 public function init($args)
 {
     $args['TITLE'] = '';
     // set BASE_URL first so parent doesn't complain
     $this->isPlaces = Kurogo::getOptionalSiteVar('USE_GOOGLE_PLACES', false, 'maps');
     if ($this->isPlaces) {
         $args['BASE_URL'] = self::PLACES_BASE_URL;
         $this->apiKey = Kurogo::getSiteVar('GOOGLE_PLACES_API_KEY', 'maps');
     } else {
         $args['BASE_URL'] = self::GEOCODE_BASE_URL;
         // the Google Maps license requires that geocode results
         // be displayed with a Google Map
         $this->staticMapClass = 'GoogleStaticMap';
         $this->dynamicMapClass = 'GoogleJSMap';
     }
     $this->defaultCenter = Kurogo::getSiteVar('DEFAULT_CENTER', 'maps');
     // TODO: grab the following from config
     //   default lat/lon, radius
     parent::init($args);
 }
    protected function retrieveData($url)
    {
    	if (strpos($url, 'kmz') !== false) {
    	    if (!class_exists('ZipArchive')) {
    	        throw new Exception("class ZipArchive (php-zip) not available");
    	    }
            $tmpDir = Kurogo::getSiteVar('TMP_DIR');
            if (!is_writable($tmpDir)) {
    	        throw new Exception("Temporary directory $tmpDir not available");
            }
    	    $tmpFile = $tmpDir.'/tmp.kmz';

    	    copy($url, $tmpFile);
    	    $zip = new ZipArchive();
    	    $zip->open($tmpFile);
    	    $contents = $zip->getFromIndex(0);
    	    unlink($tmpFile);
    	    return $contents; // this is false on failure, same as file_get_contents
    	} else {
    	    return parent::retrieveData($url);
    	}
    }
Exemplo n.º 7
0
    private function getDataController($categoryPath, &$listItemPath) {
        if (!$this->feeds)
            $this->feeds = $this->loadFeedData();

        if ($categoryPath === NULL) {
            return MapDataController::factory('MapDataController', array(
                'JS_MAP_CLASS' => 'GoogleJSMap',
                'DEFAULT_ZOOM_LEVEL' => $this->getOptionalModuleVar('DEFAULT_ZOOM_LEVEL', 10)
                ));
        
        } else {
            $listItemPath = $categoryPath;
            if ($this->numGroups > 0) {
                if (count($categoryPath) < 2) {
                    $path = implode(MAP_CATEGORY_DELIMITER, $categoryPath);
                    throw new Exception("invalid category path $path for multiple feed groups");
                }
                $feedIndex = array_shift($listItemPath).MAP_CATEGORY_DELIMITER.array_shift($listItemPath);
            } else {
                $feedIndex = array_shift($listItemPath);
            }
            $feedData = $this->feeds[$feedIndex];
            $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
            $controller->setCategory($feedIndex);
            $controller->setDebugMode(Kurogo::getSiteVar('DATA_DEBUG'));
            return $controller;
        }
    }
Exemplo n.º 8
0
    public function initializeForCommand() {

        $this->feedGroups = $this->getFeedGroups();
        $this->numGroups = count($this->feedGroups);

        switch ($this->command) {
            case 'groups':

                $response = array(
                    'total' => $this->numGroups,
                    'returned' => $this->numGroups,
                    'displayField' => 'title',
                    'results' => $this->feedGroups,
                    );

                $this->setResponse($response);
                $this->setResponseVersion(1);
            
                break;
            case 'categories':
                $this->feedGroup = $this->getArg('group', null);
                if ($this->feedGroup !== NULL && !isset($this->feedGroups[$this->feedGroup])) {
                    $this->feedGroup = NULL;
                }

                $categories = array();
                $this->feeds = $this->loadFeedData();
                foreach ($this->feeds as $id => $feedData) {
                    if (isset($feedData['HIDDEN']) && $feedData['HIDDEN']) continue;
                    $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
                    $controller->setCategory($id);
                    $category = array(
                        'id' => $controller->getCategory(),
                        'title' => $controller->getTitle(),
                        );
                    $category['subcategories'] = $controller->getAllCategoryNodes();
                    $categories[] = $category;
                }

                $this->setResponse($categories);
                $this->setResponseVersion(1);
            
                break;
            case 'places':
                $categoryPath = $this->getCategoriesAsArray();
                if ($categoryPath) {
                    $dataController = $this->getDataController($categoryPath, $listItemPath);
                    $listItems = $dataController->getListItems($listItemPath);
                    $places = array();
                    foreach ($listItems as $listItem) {
                        if ($listItem instanceof MapFeature) {
                            $places[] = arrayFromMapFeature($listItem);
                        }
                    }
                
                    $response = array(
                        'total' => count($places),
                        'returned' => count($places),
                        'displayField' => 'title',
                        'results' => $places,
                        );
                
                    $this->setResponse($response);
                    $this->setResponseVersion(1);
                }
                break;
            case 'search':
                $searchTerms = $this->getArg('q');
                if ($searchTerms) {
                    $this->feedGroup = $this->getArg('group', null);
                    if ($this->feedGroup !== NULL && !isset($this->feedGroups[$this->feedGroup])) {
                        $this->feedGroup = NULL;
                    }

                    $mapSearchClass = $GLOBALS['siteConfig']->getVar('MAP_SEARCH_CLASS');
                    if (!$this->feeds)
                        $this->feeds = $this->loadFeedData();
                    $mapSearch = new $mapSearchClass($this->feeds);
        
                    $searchResults = $mapSearch->searchCampusMap($searchTerms);
        
                    $places = array();
                    foreach ($searchResults as $result) {
                        $places[] = arrayFromMapFeature($result);
                    }

                    $response = array(
                        'total' => count($places),
                        'returned' => count($places),
                        'displayField' => 'title',
                        'results' => $places,
                        );
                
                    $this->setResponse($response);
                    $this->setResponseVersion(1);
                }

                break;

            // ajax calls
            case 'staticImageURL':
                $baseURL = $this->getArg('baseURL');
                $mapClass = $this->getArg('mapClass');
                $mapController = MapImageController::factory($mapClass, $baseURL);
                
                $projection = $this->getArg('projection');
                if ($projection) {
                    $mapController->setMapProjection($projection);
                }
                
                $width = $this->getArg('width');
                if ($width) {
                    $mapController->setImageWidth($width);
                }

                $height = $this->getArg('height');
                if ($height) {
                    $mapController->setImageHeight($height);
                }

                $bbox = $this->getArg('bbox', null);
                $lat = $this->getArg('lat');
                $lon = $this->getArg('lon');
                $zoom = $this->getArg('zoom');

                if ($bbox) {
                    $mapController->setBoundingBox($bbox);

                } else if ($lat && $lon && $zoom !== null) {
                    $mapController->setZoomLevel($zoom);
                    $mapController->setCenter(array('lat' => $lat, 'lon' => $lon));
                }
                
                $url = $mapController->getImageURL();
                
                $this->setResponse($url);
                $this->setResponseVersion(1);
            
                break;
            default:
                $this->invalidCommand();
                break;
        }
    }
 protected function init($args) {
     parent::init($args);
     $this->addFilter('f', 'json');
 }
Exemplo n.º 10
0
 private function initializeMap(MapDataController $dataController, $fullscreen = FALSE)
 {
     $placemarks = $dataController->getSelectedPlacemarks();
     $imgController = $this->getImageController();
     foreach ($placemarks as $placemark) {
         $imgController->addPlacemark($placemark);
     }
     // override point for current zoom level
     if (isset($this->args['zoom'])) {
         $zoomLevel = $this->args['zoom'];
     } else {
         $zoomLevel = $dataController->getDefaultZoomLevel();
     }
     // override point for where map should be centered
     if (isset($this->args['center'])) {
         $center = filterLatLon($this->getArg('center'));
     } elseif (isset($this->args['lat'], $this->args['lon'])) {
         $center = array('lat' => $this->getArg('lat'), 'lon' => $this->getArg('lon'));
     }
     if (isset($center)) {
         $imgController->setCenter($center);
     }
     if (isset($zoomLevel) && $zoomLevel !== null) {
         $imgController->setZoomLevel($zoomLevel);
     }
     if (!$fullscreen) {
         $this->assign('fullscreenURL', $this->buildBreadcrumbURL('fullscreen', $this->args, false));
         if (!$imgController->isStatic()) {
             $this->addInlineJavascriptFooter("\n hideMapTabChildren();\n");
         }
     } else {
         $this->assign('detailURL', $this->buildBreadcrumbURL('detail', $this->args, false));
     }
     $this->assign('fullscreen', $fullscreen);
     $this->assign('isStatic', $imgController->isStatic());
     $this->initializeMapElements('mapimage', $imgController);
     // call the function that updates the image size
     if ($imgController->isStatic()) {
         $this->addJavascriptStaticMap();
     } else {
         $this->addJavascriptDynamicMap();
     }
 }
Exemplo n.º 11
0
 private function getDataController($currentCategory = null)
 {
     if (!$this->feeds) {
         $this->loadFeedData();
     }
     if ($currentCategory === null) {
         $drillPath = array();
         $category = $this->getArg('category');
         if (isset($this->feeds[$category])) {
             $currentCategory = $category;
         } else {
             // traces the parent categories that led the user to this category id
             $references = $this->getCategoryReferences();
             foreach ($references as $reference) {
                 if ($currentCategory) {
                     $drillPath[] = $reference;
                 } elseif (isset($this->feeds[$reference])) {
                     $currentCategory = $reference;
                 }
             }
             $drillPath[] = $category;
         }
     }
     $dataController = null;
     if ($feedData = $this->getCurrentFeed($currentCategory)) {
         $dataController = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
         if ($drillPath) {
             $dataController->addDisplayFilter('category', $drillPath);
         }
     }
     return $dataController;
 }
Exemplo n.º 12
0
 public function searchCampusMap($query)
 {
     $controller = MapDataController::factory($this->feedData['CONTROLLER_CLASS'], $this->feedData);
     $this->searchResults = $controller->search($query);
     return $this->searchResults;
 }
Exemplo n.º 13
0
 public function searchCampusMap($query) {
     $this->searchResults = array();
 
 	foreach ($this->feeds as $id => $feedData) {
         $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
         $controller->setDebugMode($GLOBALS['siteConfig']->getVar('DATA_DEBUG'));
         
         if ($controller->canSearch()) {
             $results = $controller->search($query);
             $this->resultCount += count($results);
             foreach ($results as $index => $aResult) {
                 if (is_array($aResult)) {
                     foreach ($aResult as $featureID => $feature) {
                         $this->searchResults[] = array(
                             'title' => $feature->getTitle(),
                             'subtitle' => $feature->getSubtitle(),
                             'category' => $id,
                             'subcategory' => $index,
                             'index' => $featureID,
                         );
                     }
                 } else {
                     $this->searchResults[] = array(
                         'title' => $aResult->getTitle(),
                         'subtitle' => $aResult->getSubtitle(),
                         'category' => $id,
                         'index' => $index,
                         );
                 }
             }
         }
 	}
 	
 	return $this->searchResults;
 }
Exemplo n.º 14
0
    public function initializeForCommand() {

        $this->feedGroups = $this->getFeedGroups();
        $this->numGroups = count($this->feedGroups);

        switch ($this->command) {
            case 'categories':
                $this->feedGroup = $this->getArg('group', null);
                if ($this->feedGroup !== NULL && !isset($this->feedGroups[$this->feedGroup])) {
                    $this->feedGroup = NULL;
                }

                $categories = array();
                $this->feeds = $this->loadFeedData();
                foreach ($this->feeds as $id => $feedData) {
                    if (isset($feedData['HIDDEN']) && $feedData['HIDDEN']) continue;
                    $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
                    $controller->setCategory($id);
                    $category = array(
                        'id' => $controller->getCategory(),
                        'title' => $controller->getTitle(),
                        );
                    $category['subcategories'] = $controller->getAllCategoryNodes();
                    $categories[] = $category;
                }

                $this->setResponse($categories);
                $this->setResponseVersion(1);
            
                break;
            case 'places':
                $categoryPath = $this->getCategoriesAsArray();
                if ($categoryPath) {
                    $dataController = $this->getDataController($categoryPath, $listItemPath);
                    $listItems = $dataController->getListItems($listItemPath);
                    $places = array();
                    foreach ($listItems as $listItem) {
                        if ($listItem instanceof MapFeature) {
                            $aPlace = $this->arrayFromMapFeature($listItem);
                            $aPlace['category'] = $categoryPath;
                            $places[] = $aPlace;
                        }
                    }
                
                    $response = array(
                        'total' => count($places),
                        'returned' => count($places),
                        'displayField' => 'title',
                        'results' => $places,
                        );
                
                    $this->setResponse($response);
                    $this->setResponseVersion(1);
                }
                break;
            case 'search':
                $this->initializeForSearch();

                break;

            // ajax calls
            case 'staticImageURL':
                $baseURL = $this->getArg('baseURL');
                $mapClass = $this->getArg('mapClass');
                $mapController = MapImageController::factory($mapClass, $baseURL);
                
                $projection = $this->getArg('projection');
                if ($projection) {
                    $mapController->setMapProjection($projection);
                }
                
                $width = $this->getArg('width');
                if ($width) {
                    $mapController->setImageWidth($width);
                }

                $height = $this->getArg('height');
                if ($height) {
                    $mapController->setImageHeight($height);
                }

                $bbox = $this->getArg('bbox', null);
                $lat = $this->getArg('lat');
                $lon = $this->getArg('lon');
                $zoom = $this->getArg('zoom');

                if ($bbox) {
                    $mapController->setBoundingBox($bbox);

                } else if ($lat && $lon && $zoom !== null) {
                    $mapController->setZoomLevel($zoom);
                    $mapController->setCenter(array('lat' => $lat, 'lon' => $lon));
                }
                
                $url = $mapController->getImageURL();
                
                $this->setResponse($url);
                $this->setResponseVersion(1);
            
                break;

                case 'geocode':
                    $locationSearchTerms = $this->getArg('q');
                    
                    $geocodingDataControllerClass = $this->getOptionalModuleVar('GEOCODING_DATA_CONTROLLER_CLASS');
                    $geocodingDataParserClass = $this->getOptionalModuleVar('GEOCODING_DATA_PARSER_CLASS');
                    $geocoding_base_url = $this->getOptionalModuleVar('GEOCODING_BASE_URL');

                    $arguments = array('BASE_URL' => $geocoding_base_url,
                                  'CACHE_LIFETIME' => 86400,
                                  'PARSER_CLASS' => $geocodingDataParserClass);

                    $controller = DataController::factory($geocodingDataControllerClass, $arguments);
                    $controller->addCustomFilters($locationSearchTerms);
                    $response = $controller->getParsedData();

                    // checking for Geocoding service error
                    if ($response['errorCode'] == 0) {

                        unset($response['errorCode']);
                        unset($response['errorMessage']);
                        $this->setResponse($response);
                        $this->setResponseVersion(1);
                    }
                    else {
                        $kurogoError = new KurogoError($response['errorCode'], "Geocoding service Erroe", $response['errorMessage']);
                        $this->setResponseError($kurogoError);
                        $this->setResponseVersion(1);
                    }
                    break;
                    
            default:
                $this->invalidCommand();
                break;
        }
    }
Exemplo n.º 15
0
 private function getDataController($index) {
     if ($index === NULL) {
         return MapDataController::factory('MapDataController', array(
             'JS_MAP_CLASS' => 'GoogleJSMap',
             'DEFAULT_ZOOM_LEVEL' => $this->getModuleVar('DEFAULT_ZOOM_LEVEL', 10)
             ));
     
     } else if (isset($this->feeds[$index])) {
         $feedData = $this->feeds[$index];
         $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
         $controller->setDebugMode($GLOBALS['siteConfig']->getVar('DATA_DEBUG'));
         return $controller;
     }
 }
Exemplo n.º 16
0
 private function getDataController($category = null)
 {
     $controller = null;
     if ($feedData = $this->getCurrentFeed()) {
         $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
     }
     return $controller;
 }