Exemplo n.º 1
0
    /**
     * Show the map
     *
     * @return	void
     */
    protected function manage()
    {
        $markers = array();
        /* Rebuild JSON cache if needed */
        if (!\IPS\membermap\Map::i()->checkForCache()) {
            /* We clicked the tools menu item to force a rebuild */
            if (\IPS\Request::i()->isAjax()) {
                \IPS\Output::i()->redirect(\IPS\Http\Url::internal('app=membermap&module=membermap&controller=showmap', NULL, 'membermap'));
            }
        }
        $cacheTime = isset(\IPS\Data\Store::i()->membermap_cacheTime) ? \IPS\Data\Store::i()->membermap_cacheTime : 0;
        $getByUser = intval(\IPS\Request::i()->member_id);
        if (\IPS\Request::i()->filter == 'getByUser' and $getByUser) {
            $markers = \IPS\membermap\Map::i()->getMarkerByMember($getByUser);
        }
        /* Get enabled maps */
        $defaultMaps = \IPS\membermap\Application::getEnabledMaps();
        /* Add/edit marker permissions */
        $groupId = \IPS\membermap\Map::i()->getMemberGroupId();
        $existing = \IPS\membermap\Map::i()->getMarkerByMember(\IPS\Member::loggedIn()->member_id, FALSE);
        $canAdd = \IPS\membermap\Markers\Groups::load($groupId)->can('add');
        $canEdit = $existing ? $existing->canEdit() : false;
        $canDelete = $existing ? $existing->canDelete() : false;
        /* Load JS and CSS */
        \IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('leaflet/leaflet-src.js', 'membermap', 'interface'));
        \IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('leaflet/plugins/Control.FullScreen.js', 'membermap', 'interface'));
        \IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('leaflet/plugins/Control.Loading.js', 'membermap', 'interface'));
        \IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('leaflet/plugins/leaflet-providers.js', 'membermap', 'interface'));
        \IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('leaflet/plugins/leaflet.awesome-markers.js', 'membermap', 'interface'));
        \IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('leaflet/plugins/leaflet.contextmenu-src.js', 'membermap', 'interface'));
        \IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('leaflet/plugins/leaflet.markercluster-src.js', 'membermap', 'interface'));
        \IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('leaflet/plugins/subgroup.js', 'membermap', 'interface'));
        \IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('front_main.js', 'membermap', 'front'));
        \IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('jquery/jquery-ui.js', 'membermap', 'interface'));
        \IPS\Output::i()->cssFiles = array_merge(\IPS\Output::i()->cssFiles, \IPS\Theme::i()->css('membermap.css', 'membermap'));
        \IPS\Output::i()->cssFiles = array_merge(\IPS\Output::i()->cssFiles, \IPS\Theme::i()->css('leaflet.css', 'membermap', 'global'));
        \IPS\Output::i()->cssFiles = array_merge(\IPS\Output::i()->cssFiles, \IPS\Theme::i()->css('jquery-ui.css', 'membermap', 'global'));
        \IPS\Output::i()->cssFiles = array_merge(\IPS\Output::i()->cssFiles, \IPS\Theme::i()->css('plugins.combined.css', 'membermap'));
        \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('__app_membermap');
        \IPS\Output::i()->sidebar['enabled'] = FALSE;
        /* Update session location */
        \IPS\Session::i()->setLocation(\IPS\Http\Url::internal('app=membermap&module=membermap&controller=showmap', 'front', 'membermap'), array(), 'loc_membermap_viewing_membermap');
        /* Things we need to know in the Javascript */
        \IPS\Output::i()->jsVars = array_merge(\IPS\Output::i()->jsVars, array('is_supmod' => \IPS\Member::loggedIn()->modPermission() ?: 0, 'member_id' => \IPS\Member::loggedIn()->member_id ?: 0, 'membermap_canAdd' => $canAdd ?: 0, 'membermap_canEdit' => $canEdit ?: 0, 'membermap_canDelete' => $canDelete ?: 0, 'membermap_cacheTime' => $cacheTime, 'membermap_bbox' => json_decode(\IPS\Settings::i()->membermap_bbox), 'membermap_bbox_zoom' => intval(\IPS\Settings::i()->membermap_bbox_zoom), 'membermap_defaultMaps' => $defaultMaps, 'membermap_mapquestAPI' => \IPS\membermap\Application::getApiKeys('mapquest'), 'membermap_enable_clustering' => \IPS\Settings::i()->membermap_enable_clustering == 1 ? 1 : 0, 'membermap_groupByMemberGroup' => \IPS\Settings::i()->membermap_groupByMemberGroup == 1 ? 1 : 0));
        \IPS\Output::i()->endBodyCode .= <<<EOF
\t\t<script type='text/javascript'>
\t\t\tips.membermap.initMap();
\t\t</script>
EOF;
        \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('map')->showMap($markers, $cacheTime, $canAdd, $canEdit);
    }
Exemplo n.º 2
0
 /**
  * ...
  *
  * @return	array	If returns TRUE, upgrader will proceed to next step. If it returns any other value, it will set this as the value of the 'extra' GET parameter and rerun this step (useful for loops)
  */
 public function step1()
 {
     /* Remove MapQuest.OSM, as it's no longer "free" */
     $maps = json_decode(\IPS\Settings::i()->membermap_activemaps, true);
     if (is_array($maps)) {
         $osm = array_search('MapQuestOpen.OSM', $maps['basemaps']);
         if ($osm !== FALSE) {
             $maps['basemaps'][$osm] = 'OpenStreetMap.France';
             $maps['basemaps'] = array_unique($maps['basemaps'], SORT_REGULAR);
             \IPS\Settings::i()->membermap_activemaps = json_encode($maps);
             \IPS\Db::i()->update('core_sys_conf_settings', array('conf_value' => \IPS\Settings::i()->membermap_activemaps), array('conf_key=?', 'membermap_activemaps'));
             unset(\IPS\Data\Store::i()->settings);
         }
     }
     return TRUE;
 }
Exemplo n.º 3
0
 /**
  * Update default maps
  * @return void
  */
 public function update()
 {
     $maps = \IPS\Request::i()->maps;
     if (!isset($maps['basemaps'])) {
         /* You can't have a map with no basemap. Defaulting to OpenStreetMap.France */
         $maps['basemaps'] = array('OpenStreetMap.France');
     }
     if (!isset($maps['overlays'])) {
         $maps['overlays'] = array();
     }
     \IPS\Settings::i()->membermap_activemaps = json_encode($maps);
     \IPS\Db::i()->update('core_sys_conf_settings', array('conf_value' => \IPS\Settings::i()->membermap_activemaps), array('conf_key=?', 'membermap_activemaps'));
     unset(\IPS\Data\Store::i()->settings);
     if (\IPS\Request::i()->isAjax()) {
         \IPS\Output::i()->output = 1;
         return;
     }
     \IPS\Output::i()->redirect(\IPS\Http\Url::internal("app=membermap&module=membermap&controller=mapmanager"), 'saved');
 }
Exemplo n.º 4
0
 /**
  * Do formatation to the array of markers
  * 
  * @param 		array 	Markers
  * @return		array	Markers
  */
 public function formatMemberMarkers(array $markers)
 {
     $markersToKeep = array();
     $groupCache = \IPS\Data\Store::i()->groups;
     if (is_array($markers) and count($markers)) {
         foreach ($markers as $marker) {
             /* Member don't exists or lat/lon == 0 (Middle of the ocean) */
             if ($marker['member_id'] === NULL or $marker['marker_lat'] == 0 and $marker['marker_lon'] == 0) {
                 \IPS\Db::i()->delete('membermap_markers', array('marker_id=?', $marker['marker_id']));
                 continue;
             }
             $photo = \IPS\Member::photoUrl($marker);
             try {
                 $groupName = \IPS\Lang::load(\IPS\Lang::defaultLanguage())->get('core_group_' . $marker['member_group_id']);
             } catch (\UnderflowException $e) {
                 $groupName = '';
             }
             if (isset($groupCache[$marker['member_group_id']]['g_membermap_markerColour'])) {
                 $markerColour = $groupCache[$marker['member_group_id']]['g_membermap_markerColour'];
             } else {
                 $markerColour = 'darkblue';
             }
             $markersToKeep[] = array('type' => "member", 'lat' => round((double) $marker['marker_lat'], 5), 'lon' => round((double) $marker['marker_lon'], 5), 'member_id' => $marker['marker_member_id'], 'parent_id' => $marker['member_group_id'], 'parent_name' => $groupName, 'popup' => \IPS\Theme::i()->getTemplate('map', 'membermap', 'front')->popupContent($marker, $photo), 'markerColour' => $markerColour);
         }
     }
     return $markersToKeep;
 }
Exemplo n.º 5
0
 /**
  * Run Background Task
  *
  * @param	mixed					$data	Data as it was passed to \IPS\Task::queue()
  * @param	int						$offset	Offset
  * @return	int|null				New offset or NULL if complete
  * @throws	\OutOfRangeException	Indicates offset doesn't exist and thus task is complete
  */
 public function run($data, $offset)
 {
     $currentMemUsage = memory_get_usage(TRUE);
     /* Wipe out the old files on the first run */
     if ($offset === 0) {
         \IPS\membermap\Map::i()->deleteCacheFiles();
     }
     $count = 0;
     $memberMarkers = array();
     $customMarkers = array();
     $selectColumns = array('mm.*', 'mg.*', 'm.member_id', 'm.name', 'm.members_seo_name', 'm.member_group_id', 'm.pp_photo_type', 'm.pp_main_photo', 'm.pp_thumb_photo');
     if (\IPS\Settings::i()->allow_gravatars) {
         $selectColumns[] = 'm.pp_gravatar';
         $selectColumns[] = 'm.email';
         $selectColumns[] = 'm.members_bitoptions';
     }
     /* Remember to update membermap\Map too */
     $_markers = \IPS\Db::i()->select(implode(',', $selectColumns), array('membermap_markers', 'mm'), array('marker_open=1'), 'mg.group_position ASC, mm.marker_id DESC', array($offset, $this->perCycle))->join(array('membermap_markers_groups', 'mg'), 'mm.marker_parent_id=mg.group_id')->join(array('core_members', 'm'), 'mm.marker_member_id=m.member_id');
     foreach ($_markers as $marker) {
         $count++;
         if ($marker['group_type'] == 'member') {
             $memberMarkers[] = $marker;
         } else {
             $customMarkers[] = $marker;
         }
     }
     if ($count > 0) {
         $markers = \IPS\membermap\Map::i()->formatMemberMarkers($memberMarkers);
         $custMarkers = \IPS\membermap\Map::i()->formatCustomMarkers($customMarkers);
         $markers = array_merge($markers, $custMarkers);
         $fileNumber = $offset / $this->perCycle;
         touch(\IPS\ROOT_PATH . '/datastore/membermap_cache/membermap-' . $fileNumber . '.json');
         chmod(\IPS\ROOT_PATH . '/datastore/membermap_cache/membermap-' . $fileNumber . '.json', \IPS\IPS_FILE_PERMISSION);
         \file_put_contents(\IPS\ROOT_PATH . '/datastore/membermap_cache/membermap-' . $fileNumber . '.json', json_encode(array('markers' => $markers, 'memUsage' => (memory_get_usage(TRUE) - $currentMemUsage) / 1024 . 'kB', 'fromQueue' => 1)));
         /* Store the timestamp of the cache to force the browser to purge its local storage */
         \IPS\Data\Store::i()->membermap_cacheTime = time();
     }
     if (!$count) {
         throw new \IPS\Task\Queue\OutOfRangeException();
     }
     return $offset + $count;
 }
Exemplo n.º 6
0
 /**
  * Execute
  *
  * If ran successfully, should return anything worth logging. Only log something
  * worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
  * If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
  * Tasks should execute within the time of a normal HTTP request.
  *
  * @return	mixed	Message to log or NULL
  * @throws	\IPS\Task\Exception
  */
 public function execute()
 {
     if (!\IPS\Settings::i()->membermap_syncLocationField or !\IPS\Settings::i()->membermap_monitorLocationField or !\IPS\Settings::i()->membermap_profileLocationField) {
         $this->enabled = FALSE;
         $this->save();
         return;
     }
     $fieldKey = \IPS\Settings::i()->membermap_profileLocationField;
     $limit = 100;
     $counter = 0;
     $memberMarkerGroupId = \IPS\membermap\Map::i()->getMemberGroupId();
     try {
         $where = array();
         $where[] = array("( pf.field_{$fieldKey} IS NOT NULL OR pf.field_{$fieldKey} != '' )");
         $where[] = array("mm.marker_id IS NULL");
         $where[] = array("m.membermap_location_synced = 0");
         $where[] = array('( ! ' . \IPS\Db::i()->bitwiseWhere(\IPS\Member::$bitOptions['members_bitoptions'], 'bw_is_spammer') . ' )');
         if (\IPS\Settings::i()->membermap_monitorLocationField_groupPerm !== '*') {
             $where[] = \IPS\Db::i()->in('m.member_group_id', explode(',', \IPS\Settings::i()->membermap_monitorLocationField_groupPerm));
         }
         $members = \IPS\Db::i()->select('*', array('core_members', 'm'), $where, 'm.last_activity DESC', array(0, $limit))->join(array('core_pfields_content', 'pf'), 'pf.member_id=m.member_id')->join(array('membermap_markers', 'mm'), 'mm.marker_member_id=m.member_id AND mm.marker_parent_id=' . $memberMarkerGroupId);
         foreach ($members as $member) {
             $lat = $lng = $location = NULL;
             $_member = \IPS\Member::constructFromData($member);
             /* Need to set this to prevent us from looping over the same members with invalid locations over and over again */
             $_member->membermap_location_synced = 1;
             $_member->save();
             $_location = trim($member['field_' . $fieldKey]);
             if (empty($_location)) {
                 continue;
             }
             /* If it's an array, it might be from an address field, which already have the lat/lng data */
             if (is_array(json_decode($_location, TRUE))) {
                 $addressData = json_decode($_location, TRUE);
                 if (is_float($addressData['lat']) and is_float($addressData['long'])) {
                     $lat = floatval($addressData['lat']);
                     $lng = floatval($addressData['long']);
                 }
                 $addressData['addressLines'][] = $addressData['city'];
                 if (count($addressData['addressLines'])) {
                     $location = implode(', ', $addressData['addressLines']);
                 }
             } else {
                 /* Remove HTML, newlines, tab, etc, etc */
                 $_location = preg_replace("/[\\x00-\\x20]|\\xc2|\\xa0+/", ' ', strip_tags($_location));
                 $_location = trim(preg_replace("/\\s\\s+/", ' ', $_location));
                 /* To my understanding we're not allowed to use \IPS\Geolocation, as that uses Google API, and we're not showing the info on a Google Map. */
                 $nominatim = \IPS\membermap\Map::i()->getLatLng($_location);
                 if (is_array($nominatim) and count($nominatim)) {
                     $lat = $nominatim['lat'];
                     $lng = $nominatim['lng'];
                     $location = $nominatim['location'];
                 }
             }
             if ($lat and $lng) {
                 $marker = \IPS\membermap\Markers\Markers::createItem($_member, NULL, new \IPS\DateTime(), \IPS\membermap\Markers\Groups::load($memberMarkerGroupId), FALSE);
                 $marker->name = $_member->name;
                 $marker->lat = $lat;
                 $marker->lon = $lng;
                 $marker->location = $location ?: $_location;
                 $marker->save();
                 /* Add to index */
                 \IPS\Content\Search\Index::i()->index($marker);
                 $counter++;
             }
         }
     } catch (\UnderflowException $e) {
     } catch (\RuntimeException $e) {
         \IPS\Log::log(array($e->getMessage(), $nominatim), 'membermap');
     } catch (\Exception $e) {
         \IPS\Log::log(array($e->getMessage(), $nominatim), 'membermap');
         throw new \IPS\Task\Exception($this, $e->getMessage());
     }
     if ($counter > 0) {
         $foundRows = $members->count();
         return "Synchronised {$counter} out of {$foundRows} member locations";
     } else {
         $this->enabled = FALSE;
         $this->save();
         /* Turn the setting off as well */
         \IPS\Db::i()->update('core_sys_conf_settings', array('conf_value' => 0), array('conf_key=?', 'membermap_syncLocationField'));
         unset(\IPS\Data\Store::i()->settings);
         return;
     }
     return NULL;
 }