| 1 | <?php |
|---|
| 2 | // wcf imports |
|---|
| 3 | require_once(WCF_DIR.'lib/page/AbstractPage.class.php'); |
|---|
| 4 | require_once(WCF_DIR.'lib/page/util/menu/PageMenu.class.php'); |
|---|
| 5 | require_once(WCF_DIR.'lib/page/util/menu/GmapMenu.class.php'); |
|---|
| 6 | require_once(WCF_DIR.'lib/data/gmap/GmapApi.class.php'); |
|---|
| 7 | |
|---|
| 8 | /** |
|---|
| 9 | * Returns the abstract page for for the Gooogle Map |
|---|
| 10 | * |
|---|
| 11 | * @package de.gmap.wcf.data.page |
|---|
| 12 | * @author Torben Brodt |
|---|
| 13 | * @license GNU General Public License <http://opensource.org/licenses/gpl-3.0.html> |
|---|
| 14 | */ |
|---|
| 15 | class MapPage extends AbstractPage { |
|---|
| 16 | public $templateName = 'mapOverview'; |
|---|
| 17 | |
|---|
| 18 | /** |
|---|
| 19 | * @see Page::assignVariables() |
|---|
| 20 | */ |
|---|
| 21 | public function assignVariables() { |
|---|
| 22 | parent::assignVariables(); |
|---|
| 23 | |
|---|
| 24 | if($this->fromCache('hasFsockopen') == false) { |
|---|
| 25 | WCF::getTPL()->append('userMessages', '<div class="warning">'.WCF::getLanguage()->get('wcf.map.noConnectivity').'</div>'); |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | WCF::getTPL()->assign(array( |
|---|
| 29 | 'allowSpidersToIndexThisPage' => true, |
|---|
| 30 | 'gmapmenu' => GmapMenu::getInstance() |
|---|
| 31 | )); |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | /** |
|---|
| 35 | * @see Page::show() |
|---|
| 36 | */ |
|---|
| 37 | public function show() { |
|---|
| 38 | |
|---|
| 39 | // skip |
|---|
| 40 | if(!MODULE_GMAP) { |
|---|
| 41 | throw new IllegalLinkException(); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | // set active header menu item |
|---|
| 45 | PageMenu::setActiveMenuItem('wcf.header.menu.map'); |
|---|
| 46 | |
|---|
| 47 | // set gmap menu to home |
|---|
| 48 | GmapMenu::getInstance()->setActiveMenuItem('wcf.gmap.menu.link.index'); |
|---|
| 49 | |
|---|
| 50 | parent::show(); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | /** |
|---|
| 54 | * @return booolean |
|---|
| 55 | */ |
|---|
| 56 | protected function hasFsockopen() { |
|---|
| 57 | try { |
|---|
| 58 | $api = new GmapApi(); |
|---|
| 59 | $data = $api->search('berlin, deutschland'); |
|---|
| 60 | } catch(Exception $e) { |
|---|
| 61 | $data = array(); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | return count($data) > 0; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | /** |
|---|
| 68 | * |
|---|
| 69 | */ |
|---|
| 70 | protected function fromCache($method, $maxLifetime = 1800, $minLifetime = 0) { |
|---|
| 71 | $key = 'gmap.'.$method; |
|---|
| 72 | |
|---|
| 73 | $cacheResource = array( |
|---|
| 74 | 'file' => WCF_DIR.'cache/cache.'.$key.'.php', |
|---|
| 75 | 'cache' => $key, |
|---|
| 76 | 'minLifetime' => $minLifetime, |
|---|
| 77 | 'maxLifetime' => $maxLifetime |
|---|
| 78 | ); |
|---|
| 79 | |
|---|
| 80 | if(($val = WCF::getCache()->getCacheSource()->get($cacheResource)) === null) { |
|---|
| 81 | $val = false; |
|---|
| 82 | $val = $this->$method(); |
|---|
| 83 | WCF::getCache()->getCacheSource()->set($cacheResource, $val); |
|---|
| 84 | } |
|---|
| 85 | return $val; |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | ?> |
|---|