Ejemplo n.º 1
0
 protected function initializeForPage()
 {
     $this->featureIndex = $this->getArg('featureindex', null);
     switch ($this->page) {
         case 'help':
             break;
         case 'index':
             if ($action = $this->getArg('action', false)) {
                 if ($this->feedGroup && $action == 'add') {
                     // TODO have config for different types of cookie expiration times
                     $expireTime = time() + 897298;
                     setcookie(MAP_GROUP_COOKIE, $this->feedGroup, $expireTime, COOKIE_PATH);
                 } else {
                     if ($action == 'remove') {
                         $expireTime = time() - 4096;
                         setcookie(MAP_GROUP_COOKIE, '', $expireTime, COOKIE_PATH);
                     }
                 }
             }
             if ($this->numGroups == 0) {
                 $categories = array(array('title' => $this->getLocalizedString('NO_MAPS_FOUND')));
                 $this->assign('categories', $categories);
             } else {
                 if ($this->feedGroup === null && $this->numGroups > 1) {
                     // show the list of groups
                     foreach ($this->feedGroups as $id => $groupData) {
                         $categories[] = array('title' => $groupData['title'], 'url' => $this->groupURL($id), 'listclass' => $id);
                     }
                     // TODO there should ba a cleaner way to do this
                     $apiURL = FULL_URL_BASE . API_URL_PREFIX . "/{$this->configModule}";
                     $this->addInlineJavascript("\napiURL = '{$apiURL}';\n");
                     $groupAlias = $this->getLocalizedString('MAP_GROUP_ALIAS');
                     $this->assign('browseHint', $this->getLocalizedString('SELECT_A_MAP_GROUP', $groupAlias));
                     $this->assign('categories', $categories);
                     $this->addOnLoad('sortGroupsByDistance();');
                 } else {
                     $groupData = $this->getDataForGroup($this->feedGroup);
                     $this->assign('browseBy', $groupData['title']);
                     if ($this->numGroups > 1) {
                         $groupAlias = $this->getLocalizedString('MAP_GROUP_ALIAS_PLURAL');
                         $clearLink = array(array('title' => "All {$groupAlias}", 'url' => $this->groupURL('')));
                         $this->assign('clearLink', $clearLink);
                     }
                     $categories = $this->assignCategories();
                     /*
                     if (count($categories)==1) {
                         $category = current($categories);
                         $this->redirectTo('category', array('category'=>$category['id']));
                     }
                     */
                 }
             }
             $this->assign('placeholder', $this->getLocalizedString('MAP_SEARCH_PLACEHOLDER'));
             $this->assign('tip', $this->getLocalizedString('MAP_SEARCH_TIP'));
             if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 $this->generateBookmarkLink();
             }
             break;
         case 'bookmarks':
             if (!$this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 $this->redirectTo('index', array());
             }
             $places = array();
             foreach ($this->getBookmarks() as $aBookmark) {
                 if ($aBookmark) {
                     // prevent counting empty string
                     $titles = $this->getTitleForBookmark($aBookmark);
                     $subtitle = count($titles) > 1 ? $titles[1] : null;
                     // TODO split up bookmarks by category
                     $places[] = array('title' => $titles[0], 'subtitle' => $subtitle, 'url' => $this->detailURLForBookmark($aBookmark));
                 }
             }
             $this->assign('places', $places);
             break;
         case 'search':
             $searchTerms = $this->getArg('filter');
             if ($searchTerms) {
                 $this->feedGroup = null;
                 // TODO: redirect if there is one result
                 $args = array_merge($this->args, array('addBreadcrumb' => true));
                 // still need a way to show the Google logo if we use their search
                 $searchResults = $this->searchItems($searchTerms, null, $args);
                 $places = array();
                 foreach ($searchResults as $place) {
                     $places[] = $this->linkForItem($place);
                 }
                 $this->assign('searchTerms', $searchTerms);
                 $this->assign('places', $places);
             } else {
                 $this->redirectTo('index');
             }
             break;
         case 'category':
             $category = $this->getCategory();
             if ($category) {
                 // populate drop-down list at the bottom
                 $this->assignCategories();
                 // build the drill-down list
                 $dataController = $this->getDataController();
                 $dataController->addDisplayFilter('category', $this->getDrillDownPath());
                 $listItems = $dataController->getListItems();
                 if (count($listItems) == 1) {
                     // redirect to a category's children if it only has one item
                     $args = $this->args;
                     if (current($listItems) instanceof Placemark) {
                         $args['featureindex'] = current($listItems)->getId();
                         $this->redirectTo('detail', $args, true);
                     } else {
                         // assume MapFolder
                         $path = $this->getDrillDownPath();
                         $path[] = current($listItems)->getId();
                         $args['path'] = implode(MAP_CATEGORY_DELIMITER, $path);
                         $this->redirectTo('category', $args, false);
                     }
                 }
                 $places = array();
                 foreach ($listItems as $listItem) {
                     if ($listItem instanceof Placemark) {
                         $url = $this->detailURL($listItem->getId(), $category);
                     } else {
                         // for folder objects, getIndex returns the subcategory ID
                         $drilldownPath = array_merge($this->getDrillDownPath(), array($listItem->getId()));
                         $url = $this->categoryURL($category, $drilldownPath, false);
                     }
                     $places[] = array('title' => $listItem->getTitle(), 'subtitle' => $listItem->getSubtitle(), 'url' => $url);
                 }
                 $this->assign('title', $dataController->getTitle());
                 $this->assign('places', $places);
                 if ($this->numGroups > 1) {
                     $categories = $this->assignCategories();
                     if (count($categories) == 1) {
                         $groupAlias = $this->getLocalizedString('MAP_GROUP_ALIAS_PLURAL');
                         $clearLink = array(array('title' => "All {$groupAlias}", 'url' => $this->groupURL('')));
                         $this->assign('clearLink', $clearLink);
                     }
                 }
             } else {
                 $this->redirectTo('index');
             }
             break;
         case 'detail':
             $detailConfig = $this->loadPageConfigFile('detail', 'detailConfig');
             $tabKeys = array();
             $tabJavascripts = array();
             $title = $this->getArg('title');
             $dataController = $this->getDataController();
             $drilldownPath = $this->getDrillDownPath();
             if ($drilldownPath) {
                 $dataController->addDisplayFilter('category', $drilldownPath);
             }
             if ($this->featureIndex !== null) {
                 $feature = $dataController->selectPlacemark($this->featureIndex);
             } elseif (isset($this->args['lat'], $this->args['lon'])) {
                 $lat = $this->args['lat'];
                 $lon = $this->args['lon'];
                 $feature = new BasePlacemark(new MapBasePoint(array('lat' => $lat, 'lon' => $lon)));
                 if (!$title) {
                     $title = "{$lat},{$lon}";
                 }
                 // hacky
                 $dataController->setSelectedPlacemarks(array($feature));
             }
             if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 if (isset($this->args['featureindex'])) {
                     // this is a place from a feed
                     $cookieParams = array('category' => $this->getCategory(), 'featureindex' => $this->featureIndex);
                     $cookieID = http_build_query($cookieParams);
                     $this->generateBookmarkOptions($cookieID);
                 } elseif (isset($this->args['lat'], $this->args['lon'])) {
                     $cookieParams = array('lat' => $this->args['lat'], 'lon' => $this->args['lon']);
                     if ($feature) {
                         $cookieParams['title'] = $feature->getTitle();
                     }
                     $cookieID = http_build_query($cookieParams);
                     $this->generateBookmarkOptions($cookieID);
                 }
             }
             if ($feature) {
                 if (!$title) {
                     $title = $feature->getTitle();
                 }
                 // prevent infinite loop in smarty_modifier_replace
                 // TODO figure out why smarty gets in an infinite loop
                 $address = str_replace("\n", " ", $feature->getSubtitle());
             } else {
                 // TODO put something reasonable here
                 $title = '';
                 $address = $this->getArg('address');
             }
             $this->assign('name', $title);
             $this->assign('address', $address);
             $possibleTabs = $detailConfig['tabs']['tabkeys'];
             foreach ($possibleTabs as $tabKey) {
                 if ($this->generateTabForKey($tabKey, $feature, $dataController, $tabJavascripts)) {
                     $tabKeys[] = $tabKey;
                 }
             }
             $this->assign('tabKeys', $tabKeys);
             $this->enableTabs($tabKeys, null, $tabJavascripts);
             break;
         case 'fullscreen':
             $dataController = $this->getDataController();
             $dataController->selectPlacemark($this->featureIndex);
             $this->initializeMap($dataController, true);
             break;
     }
 }