protected function _prepareTpl() { // Get the project and repository params $project = $this->param('project'); $repository = $this->param('repository'); $auth_url_return = $this->param('auth_url_return'); if (!$auth_url_return) { $auth_url_return = jUrl::get('view~map:index', array("repository" => $repository, "project" => $project)); } // Get lizmapProject class $assign = array('isConnected' => jAuth::isConnected(), 'user' => jAuth::getUserSession(), 'auth_url_return' => $auth_url_return, "externalSearch" => "", "edition" => false, "measure" => false, "locate" => false, "geolocation" => false, "timemanager" => false, "print" => false, "attributeLayers" => false); try { $lproj = lizmap::getProject($repository . '~' . $project); $configOptions = $lproj->getOptions(); if (property_exists($configOptions, 'externalSearch')) { $assign['externalSearch'] = $configOptions->externalSearch; } } catch (UnknownLizmapProjectException $e) { jLog::logEx($e, 'error'); } $this->_tpl->assign($assign); // Get lizmap services $services = lizmap::getServices(); if ($services->allowUserAccountRequests) { $this->_tpl->assign('allowUserAccountRequests', True); } }
/** * Displays a list of project for a given repository. * * @param string $repository. Name of the repository. * @return Html page with a list of projects. */ function index() { if ($this->param('theme')) { jApp::config()->theme = $this->param('theme'); } $rep = $this->getResponse('html'); // Get lizmap services $services = lizmap::getServices(); // only maps if ($services->onlyMaps) { $repository = lizmap::getRepository($services->defaultRepository); if ($repository && jAcl2::check('lizmap.repositories.view', $repository->getKey())) { $project = lizmap::getProject($repository->getKey() . '~' . $services->defaultProject); if ($project) { // test redirection to an other controller $items = jEvent::notify('mainviewGetMaps')->getResponse(); foreach ($items as $item) { if ($item->parentId == $repository->getKey() && $item->id == $services->defaultProject) { $rep = $this->getResponse('redirectUrl'); $rep->url = $item->url; return $rep; } } // redirection to default controller $rep = $this->getResponse('redirect'); $rep->action = 'view~map:index'; return $rep; } } } // Get repository data $repository = $this->param('repository'); $repositoryList = array(); if ($repository) { if (!jAcl2::check('lizmap.repositories.view', $repository)) { $rep = $this->getResponse('redirect'); $rep->action = 'view~default:index'; jMessage::add(jLocale::get('view~default.repository.access.denied'), 'error'); return $rep; } } $title = jLocale::get("view~default.repository.list.title"); $rep->body->assign('repositoryLabel', $title); $rep->body->assign('isConnected', jAuth::isConnected()); $rep->body->assign('user', jAuth::getUserSession()); if ($services->allowUserAccountRequests) { $rep->body->assign('allowUserAccountRequests', True); } if ($repository) { $lrep = lizmap::getRepository($repository); $title .= ' - ' . $lrep->getData('label'); } $rep->title = $title; $rep->body->assignZone('MAIN', 'main_view', array('repository' => $repository)); $rep->addJSCode("\n \$(window).load(function() {\n \$('.liz-project-img').parent().mouseenter(function(){\n var self = \$(this);\n self.find('.liz-project-desc').slideDown();\n self.css('cursor','pointer');\n }).mouseleave(function(){\n var self = \$(this);\n self.find('.liz-project-desc').hide();\n }).click(function(){\n var self = \$(this);\n window.location = self.parent().find('a.liz-project-view').attr('href');\n return false;\n });\n });\n "); // Js hack to normalize the height of the project thumbnails to avoid line breaks with long project titles $bp = jApp::config()->urlengine['basePath']; $rep->addJSLink($bp . 'js/view.js'); return $rep; }
/** * constructor * project : the project has a lizmapProject Class * params : the params array */ public function __construct($project, $params) { //print_r( $project != null ); $this->project = $project; $this->repository = $project->getRepository(); $this->services = lizmap::getServices(); $params['map'] = realpath($this->repository->getPath()) . '/' . $project->getKey() . ".qgs"; $this->params = lizmapProxy::normalizeParams($params); }
/** * Use DynamicLayers python plugin to get a child project * And redirect to Lizmap view map controller with changed project parameter */ function index() { // Set up redirect response $rep = $this->getResponse('redirect'); $rep->action = 'view~map:index'; $params = jApp::coord()->request->params; $rep->params = $params; // Redirect to normal map if no suitable parameters if (!$params['dlsourcelayer'] or !$params['dlexpression']) { jLog::log('Dynamic layers - no parameters DLSOURCELAYER or DLEXPRESSION'); return $rep; } // Get project path $project = $params['project']; $repository = $params['repository']; $lrep = lizmap::getRepository($repository); $projectTemplatePath = realpath($lrep->getPath()) . '/' . $project . ".qgs"; // Use QGIS python plugins dynamicLayers to get child project $lizmapServices = lizmap::getServices(); $url = $lizmapServices->wmsServerURL . '?'; $qparams = array(); $qparams['service'] = 'dynamicLayers'; $qparams['map'] = $projectTemplatePath; $qparams['dlsourcelayer'] = $params['dlsourcelayer']; $qparams['dlexpression'] = $params['dlexpression']; $rparams = http_build_query($qparams); $querystring = $url . $rparams; // Get remote data $lizmapCache = jClasses::getService('lizmap~lizmapCache'); $getRemoteData = $lizmapCache->getRemoteData($querystring, $this->services->proxyMethod, $this->services->debugMode); $data = $getRemoteData[0]; $mime = $getRemoteData[1]; // Get returned response and redirect to appropriate project page $json = json_decode($data); if ($json->status == 0) { jLog::log('DynamicLayers error : ' . $json->message); } else { $params['project'] = preg_replace('#\\.qgs$#', '', $json->childProject); unset($params['dlsourcelayer']); unset($params['dlexpression']); $rep->params = $params; jLog::log('DynamicLayers message : ' . $json->message . ' - ' . $json->childProject); } return $rep; }
/** * Get parameters and set classes for the project and repository given. * * @return array List of needed variables : $params, $lizmapProject, $lizmapRepository, $lizmapCache. */ protected function getServiceParameters() { // Get the project $project = $this->iParam('project'); if (!$project) { jMessage::add('The parameter project is mandatory !', 'ProjectNotDefind'); return false; } // Get repository data $repository = $this->iParam('repository'); // Get the corresponding repository $lrep = lizmap::getRepository($repository); // Redirect if no rights to access this repository if (!jAcl2::check('lizmap.repositories.view', $lrep->getKey())) { jMessage::add(jLocale::get('view~default.repository.access.denied'), 'AuthorizationRequired'); return false; } // Get and normalize the passed parameters $pParams = jApp::coord()->request->params; $pParams['map'] = realpath($lrep->getPath()) . '/' . $project . ".qgs"; $lizmapCache = jClasses::getService('lizmap~lizmapCache'); $params = $lizmapCache->normalizeParams($pParams); // Define class private properties $this->project = lizmap::getProject($repository . '~' . $project); $this->repository = $lrep; $this->services = lizmap::getServices(); $this->params = $params; $this->lizmapCache = $lizmapCache; // Optionnaly filter data by login if (isset($params['request'])) { $request = strtolower($params['request']); if (in_array($request, array('getmap', 'getfeatureinfo', 'getfeature', 'getprint')) and !jAcl2::check('lizmap.tools.loginFilteredLayers.override', $lrep->getKey())) { $this->filterDataByLogin(); } } return true; }
/** * Get illustration image for a specified project. * @param string $repository Repository of the project. * @param string $project Project key. * @return binary object The image for this project. */ function illustration() { $rep = $this->getResponse('binary'); $rep->doDownload = false; // Get repository data $repository = $this->param('repository'); $lrep = lizmap::getRepository($repository); if (!$lrep) { $ser = lizmap::getServices(); $lrep = lizmap::getRepository($ser->defaultRepository); } if (!jAcl2::check('lizmap.repositories.view', $lrep->getKey())) { $rep = $this->getResponse('redirect'); $rep->action = 'view~default:error'; jMessage::add(jLocale::get('view~default.repository.access.denied'), 'error'); return $rep; } // Get the project $project = $this->param('project'); // default illustration $themePath = jApp::wwwPath() . 'themes/' . jApp::config()->theme . '/'; $rep->fileName = $themePath . 'css/img/250x250_mappemonde.png'; // get project illustration if exists if ($project) { $imageTypes = array('jpg', 'jpeg', 'png', 'gif'); foreach ($imageTypes as $type) { if (file_exists($lrep->getPath() . $project . '.qgs.' . $type)) { $rep->fileName = $lrep->getPath() . $project . '.qgs.' . $type; $rep->mimeType = "image/{$type}"; $rep->setExpires('+60 seconds'); return $rep; } } } return $rep; }
/** * Get WFS data from a "Value Relation" layer and fill the form control for a specific field. * @param string $fieldName Name of QGIS field * * @return Modified form control */ private function fillControlFromValueRelationLayer($fieldName) { // Build WFS request parameters // Get layername via id $relationLayerId = $this->formControls[$fieldName]->valueRelationData['layer']; $_relationayerXml = $this->project->getXmlLayer($relationLayerId); $relationayerXml = $_relationayerXml[0]; $_layerName = $relationayerXml->xpath('layername'); $layerName = (string) $_layerName[0]; $valueColumn = $this->formControls[$fieldName]->valueRelationData['value']; $keyColumn = $this->formControls[$fieldName]->valueRelationData['key']; $filterExpression = $this->formControls[$fieldName]->valueRelationData['filterExpression']; $params = array('SERVICE' => 'WFS', 'VERSION' => '1.0.0', 'REQUEST' => 'GetFeature', 'TYPENAME' => $layerName, 'PROPERTYNAME' => $valueColumn . ',' . $keyColumn, 'OUTPUTFORMAT' => 'GeoJSON', 'GEOMETRYNAME' => 'none', 'map' => $this->repository->getPath() . $this->project->getKey() . ".qgs"); // add EXP_FILTER. Only for QGIS >=2.0 $expFilter = Null; if ($filterExpression) { $expFilter = $filterExpression; } // Filter by login if (!$this->loginFilteredOveride) { $this->filterDataByLogin($layerName); if (is_array($this->loginFilteredLayers)) { if ($expFilter) { $expFilter = " ( " . $expFilter . " ) AND ( " . $this->loginFilteredLayers['where'] . " ) "; } else { $expFilter = $this->loginFilteredLayers['where']; } } } if ($expFilter) { $params['EXP_FILTER'] = $expFilter; // disable PROPERTYNAME in this case : if the exp_filter uses other fields, no data would be returned otherwise unset($params['PROPERTYNAME']); } // Build query $lizmapServices = lizmap::getServices(); $url = $lizmapServices->wmsServerURL . '?'; $bparams = http_build_query($params); $querystring = $url . $bparams; // Get remote data $lizmapCache = jClasses::getService('lizmap~lizmapCache'); $getRemoteData = $lizmapCache->getRemoteData($querystring, $lizmapServices->proxyMethod, $lizmapServices->debugMode); $wfsData = $getRemoteData[0]; $mime = $getRemoteData[1]; if ($wfsData and !in_array(strtolower($mime), array('text/html', 'text/xml'))) { $wfsData = json_decode($wfsData); // Get data from layer $features = $wfsData->features; $data = array(); foreach ($features as $feat) { if (property_exists($feat, 'properties')) { if (property_exists($feat->properties, $keyColumn) && property_exists($feat->properties, $valueColumn)) { $data[(string) $feat->properties->{$keyColumn}] = $feat->properties->{$valueColumn}; } } } $dataSource = new jFormsStaticDatasource(); // orderByValue if (strtolower($this->formControls[$fieldName]->valueRelationData['orderByValue']) == 'true' or strtolower($this->formControls[$fieldName]->valueRelationData['orderByValue']) == '1') { asort($data); } $dataSource->data = $data; $this->formControls[$fieldName]->ctrl->datasource = $dataSource; // required if (strtolower($this->formControls[$fieldName]->valueRelationData['allowNull']) == 'false' or strtolower($this->formControls[$fieldName]->valueRelationData['allowNull']) == '0') { $this->formControls[$fieldName]->ctrl->required = True; } } else { if (!preg_match('#No feature found error messages#', $wfsData)) { $this->formControls[$fieldName]->ctrl->hint = 'Problem : cannot get data to fill this control !'; $this->formControls[$fieldName]->ctrl->help = 'Problem : cannot get data to fill this control !'; } else { $this->formControls[$fieldName]->ctrl->hint = 'No data to fill this control !'; $this->formControls[$fieldName]->ctrl->help = 'No data to fill this control !'; } } }
/** * Load the map page for the given project. * @param string $repository Name of the repository. * @param string $project Name of the project. * @return Page with map and content for the chose Qgis project. */ function index() { if ($this->param('theme')) { jApp::config()->theme = $this->param('theme'); } $rep = $this->getResponse('htmlmap'); $rep->addJSLink(jUrl::get('view~translate:index')); $ok = true; // Get the project $project = filter_var($this->param('project'), FILTER_SANITIZE_STRING); // Get repository data $repository = $this->param('repository'); // Get lizmapRepository class // if repository not found get the default $lrep = null; $lser = lizmap::getServices(); if (!$repository) { $lrep = lizmap::getRepository($lser->defaultRepository); $repository = $lser->defaultRepository; } else { $lrep = lizmap::getRepository($repository); } if (!$lrep or !jAcl2::check('lizmap.repositories.view', $lrep->getKey())) { $rep = $this->getResponse('redirect'); $rep->action = 'view~default:index'; jMessage::add(jLocale::get('view~default.repository.access.denied'), 'error'); return $rep; } // We must redirect to default repository project list if no project given if (!$project) { $lproj = lizmap::getProject($lrep->getKey() . '~' . $lser->defaultProject); if (!$lproj) { jMessage::add('The parameter project is mandatory !', 'error'); $ok = false; } else { $project = $lser->defaultProject; } } // Get lizmapProject class if ($ok) { $lproj = lizmap::getProject($lrep->getKey() . '~' . $project); if (!$lproj) { jMessage::add('The lizmapProject ' . strtoupper($project) . ' does not exist !', 'error'); $ok = false; } } // Redirect if project is hidden (lizmap plugin option) if ($ok and !$this->forceHiddenProjectVisible) { $pOptions = $lproj->getOptions(); if (property_exists($pOptions, 'hideProject') && $pOptions->hideProject == 'True') { jMessage::add(jLocale::get('view~default.project.access.denied'), 'error'); $ok = false; } } // Redirect if error encountered if (!$ok) { $rep = $this->getResponse('redirect'); $rep->params = array('repository' => $lrep->getKey()); $rep->action = 'view~default:index'; return $rep; } // Add js link if google is needed if ($lproj->needsGoogle()) { $googleKey = $lproj->getGoogleKey(); if ($googleKey != '') { $rep->addJSLink('https://maps.google.com/maps/api/js?v=3.5&sensor=false&key=' . $googleKey); } else { $rep->addJSLink('https://maps.google.com/maps/api/js?v=3.5&sensor=false'); } } // Add the jForms js $bp = jApp::config()->urlengine['basePath']; $rep->addJSLink($bp . 'jelix/js/jforms_jquery.js'); $rep->addJSLink($bp . 'jelix/js/jforms/datepickers/default/init.js'); $rep->addJSLink($bp . 'jelix/js/jforms/datepickers/default/ui.en.js'); $rep->addJSLink($bp . 'js/fileUpload/jquery.fileupload.js'); $rep->addJSLink($bp . 'js/bootstrapErrorDecoratorHtml.js'); // Add botom dock js $rep->addJSLink($bp . 'js/bottom-dock.js'); // Pass some configuration options to the web page through javascript var $lizUrls = array("params" => array('repository' => $repository, 'project' => $project), "config" => jUrl::get('lizmap~service:getProjectConfig'), "wms" => jUrl::get('lizmap~service:index'), "media" => jUrl::get('view~media:getMedia'), "nominatim" => jUrl::get('lizmap~osm:nominatim'), "ign" => jUrl::get('lizmap~ign:address'), "edition" => jUrl::get('lizmap~edition:getFeature'), "permalink" => jUrl::getFull('view~map:index'), "dataTableLanguage" => $bp . 'js/dataTables/' . jApp::config()->locale . '.json', "basepath" => $bp, "geobookmark" => jUrl::get('lizmap~geobookmark:index')); // Get optionnal WMS public url list $lser = lizmap::getServices(); if ($lser->wmsPublicUrlList) { $publicUrlList = $lser->wmsPublicUrlList; function f($x) { return jUrl::getFull('lizmap~service:index', array(), 0, trim($x)); } $pul = array_map('f', explode(',', $publicUrlList)); $lizUrls['publicUrlList'] = $pul; } if (jAcl2::check('lizmap.admin.repositories.delete')) { $lizUrls['removeCache'] = jUrl::get('admin~config:removeLayerCache'); } $rep->addJSCode("var lizUrls = " . json_encode($lizUrls) . ";"); $rep->addJSCode("var lizProj4 = " . json_encode($lproj->getAllProj4()) . ";"); $rep->addStyle('#map', 'background-color:' . $lproj->getCanvasColor() . ';'); // Get the WMS information $wmsInfo = $lproj->getWMSInformation(); // Set page title from projet title if ($wmsInfo['WMSServiceTitle'] != '') { $rep->title = $wmsInfo['WMSServiceTitle']; } else { $rep->title = $repository . ' - ' . $project; } // Add date.js for timemanager if ($lproj->hasTimemanagerLayers()) { $rep->addJSLink($bp . 'js/date.js'); } // Assign variables to template $assign = array_merge(array('repositoryLabel' => $lrep->getData('label'), 'repository' => $lrep->getKey(), 'project' => $project, 'onlyMaps' => $lser->onlyMaps), $wmsInfo); // WMS GetCapabilities Url $wmsGetCapabilitiesUrl = jAcl2::check('lizmap.tools.displayGetCapabilitiesLinks', $lrep->getKey()); if ($wmsGetCapabilitiesUrl) { $wmsGetCapabilitiesUrl = $lproj->getData('wmsGetCapabilitiesUrl'); } $assign['wmsGetCapabilitiesUrl'] = $wmsGetCapabilitiesUrl; // Get dockable and minidockable element $assign['dockable'] = $lproj->getDefaultDockable(); $items = jEvent::notify('mapDockable', array('repository' => $repository, 'project' => $project))->getResponse(); $assign['dockable'] = mapDockItemsMerge($assign['dockable'], $items); $assign['minidockable'] = $lproj->getDefaultMiniDockable(); $items = jEvent::notify('mapMiniDockable', array('repository' => $repository, 'project' => $project))->getResponse(); $assign['minidockable'] = mapDockItemsMerge($assign['minidockable'], $items); $assign['bottomdockable'] = $lproj->getDefaultBottomDockable(); $items = jEvent::notify('mapBottomDockable', array('repository' => $repository, 'project' => $project))->getResponse(); $assign['bottomdockable'] = mapDockItemsMerge($assign['bottomdockable'], $items); // Add dockable js foreach (array_merge($assign['dockable'], $assign['minidockable'], $assign['bottomdockable']) as $d) { if ($d->js != '') { $rep->addJsLink($d->js); } } $themePath = jApp::config()->urlengine['basePath'] . 'themes/' . jApp::config()->theme . '/'; $rep->addCssLink($themePath . 'css/main.css'); $rep->addCssLink($themePath . 'css/map.css'); $rep->addCssLink($themePath . 'css/media.css'); // Add dockable css foreach ($assign['dockable'] as $d) { if ($d->css != '') { $rep->addCssLink($d->css); } } // Replace default theme by theme found in // the repository folder media/themes/default/ if ($lrep->getData('allowUserDefinedThemes')) { $repositoryPath = $lrep->getPath(); $cssArray = array('main', 'map', 'media'); $themeArray = array('default', $project); foreach ($cssArray as $k) { foreach ($themeArray as $theme) { $cssRelPath = 'media/themes/' . $theme . '/css/' . $k . '.css'; $cssPath = $lrep->getPath() . '/' . $cssRelPath; if (file_exists($cssPath)) { $cssUrl = jUrl::get('view~media:getCssFile', array('repository' => $lrep->getKey(), 'project' => $project, 'path' => $cssRelPath)); //~ $rep->addCssLink( $cssUrl ); // Use addHeadContent and not addCssLink to be sure it will be loaded after minified code $rep->addHeadContent('<link type="text/css" href="' . $cssUrl . '" rel="stylesheet" />'); } } } // Add JS files found in media/js $jsDirArray = array('default', $project); foreach ($jsDirArray as $dir) { $jsPathRoot = realpath($repositoryPath . '/' . 'media/js/' . $dir); if (is_dir($jsPathRoot)) { foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($jsPathRoot)) as $filename) { $path_parts = pathinfo($filename); if ($path_parts['extension'] == 'js') { $jsPath = realpath($filename); $jsRelPath = 'media/js/' . $dir . str_replace($jsPathRoot, '', $jsPath); $jsUrl = jUrl::get('view~media:getMedia', array('repository' => $lrep->getKey(), 'project' => $project, 'path' => $jsRelPath)); //~ $rep->addJSLink( $jsUrl ); // Use addHeadContent and not addJSLink to be sure it will be loaded after minified code $rep->addContent('<script type="text/javascript" src="' . $jsUrl . '" ></script>'); } } } } } // optionnally hide some tools // header $jsCode = ''; $mapMenuCss = ''; $h = $this->intParam('h', 1); if ($h == 0 or property_exists($pOptions, 'hideHeader') && $pOptions->hideHeader == 'True') { $h = 0; $rep->addStyle('#body', 'padding-top:0px;'); $rep->addStyle('#header', 'display:none; height:0px;'); } // menu = left vertical menu with icons $m = $this->intParam('m', 1); if ($m == 0 or property_exists($pOptions, 'hideMenu') && $pOptions->hideMenu == 'True') { $m = 0; $rep->addStyle('#mapmenu', 'display:none !important; width:0px;'); $rep->addStyle('#dock', 'left:0px; border-left:none;'); } // legend = legend open at startup $l = $this->intParam('l', 1); if ($l == 0 or property_exists($pOptions, 'hideLegend') && $pOptions->hideLegend == 'True') { $l = 0; //~ $rep->addStyle('#dock', 'display:none;'); $jsCode .= "\n \$( document ).ready( function() {\n lizMap.events.on({\n 'uicreated':function(evt){\n \$('#button-switcher').click();\n }\n });\n });\n "; } // navbar $n = $this->intParam('n', 1); if ($n == 0 or property_exists($pOptions, 'hideNavbar') && $pOptions->hideNavbar == 'True') { $rep->addStyle('#navbar', 'display:none !important;'); } // overview-box = scale & overview $o = $this->intParam('o', 1); if ($o == 0 or property_exists($pOptions, 'hideOverview') && $pOptions->hideOverview == 'True') { $rep->addStyle('#overview-box', 'display:none !important;'); } // Apply interface modifications if ($jsCode != '') { $rep->addJSCode($jsCode); } // Hide groups checkboxes if (property_exists($pOptions, 'hideGroupCheckbox') && $pOptions->hideGroupCheckbox == 'True') { $rep->addStyle('#switcher-layers button[name="group"]', 'display:none !important;'); } // Add filter $filterParam = $this->param('filter'); $filter = array(); if ($filterParam) { $fExp = explode(';', $filterParam); foreach ($fExp as $item) { $iExp = explode(':', $item); if (count($iExp) == 2) { $filter[$iExp[0]] = $iExp[1]; } } if (count($filter) > 0) { $rep->addJSCode("var lizLayerFilter = " . json_encode($filter) . ";"); } } // Add styles if needed $stylesParam = $this->param('layerStyles'); $styles = array(); if ($stylesParam) { $fExp = explode(';', $stylesParam); foreach ($fExp as $item) { $iExp = explode(':', $item); if (count($iExp) == 2) { $styles[$iExp[0]] = $iExp[1]; } } if (count($styles) > 0) { $rep->addJSCode("var lizLayerStyles = " . json_encode($styles) . ";"); } } //$assign['auth_url_return'] = jUrl::get('view~default:index'); // switcher-layers-actions javascript $rep->addJSLink($bp . 'js/switcher-layers-actions.js'); $rep->body->assign($assign); // Log $eventParams = array('key' => 'viewmap', 'content' => '', 'repository' => $lrep->getKey(), 'project' => $project); jEvent::notify('LizLogItem', $eventParams); return $rep; }
public static function createVirtualProfile($repository, $project, $layers, $crs) { // Set cache configuration $cacheName = 'lizmapCache_' . $repository . '_' . $project . '_' . $layers . '_' . $crs; // Storage type $ser = lizmap::getServices(); $cacheStorageType = $ser->cacheStorageType; // Expiration time : take default one $cacheExpiration = (int) $ser->cacheExpiration; // Cache root directory $cacheRootDirectory = $ser->cacheRootDirectory; if (!is_writable($cacheRootDirectory) or !is_dir($cacheRootDirectory)) { $cacheRootDirectory = sys_get_temp_dir(); } if ($cacheStorageType == 'file') { // CACHE CONTENT INTO FILE SYSTEM // Directory where to store the cached files $cacheDirectory = $cacheRootDirectory . '/' . $repository . '/' . $project . '/' . $layers . '/' . $crs . '/'; // Create directory if needed if (!file_exists($cacheDirectory)) { mkdir($cacheDirectory, 0750, true); } // Virtual cache profile parameter $cacheParams = array("driver" => "file", "cache_dir" => $cacheDirectory, "file_locking" => True, "directory_level" => "5", "directory_umask" => "0750", "file_name_prefix" => "lizmap_", "cache_file_umask" => "0650", "ttl" => $cacheExpiration); // Create the virtual cache profile jProfiles::createVirtualProfile('jcache', $cacheName, $cacheParams); } else { // CACHE CONTENT INTO SQLITE DATABASE // Directory where to store the sqlite database $cacheDirectory = $cacheRootDirectory . '/' . $repository . '/' . $project . '/'; if (!file_exists($cacheDirectory)) { mkdir($cacheDirectory, 0750, true); } // Create directory if needed $cacheDatabase = $cacheDirectory . $layers . '_' . $crs . '.db'; $cachePdoDsn = 'sqlite:' . $cacheDatabase; // Create database and populate with table if needed if (!file_exists($cacheDatabase)) { copy(jApp::varPath() . "cacheTemplate.db", $cacheDatabase); } // Virtual jdb profile corresponding to the layer database $jdbParams = array("driver" => "pdo", "dsn" => $cachePdoDsn, "user" => "cache", "password" => "cache"); // Create the virtual jdb profile $cacheJdbName = "jdb_" . $cacheName; jProfiles::createVirtualProfile('jdb', $cacheJdbName, $jdbParams); // Virtual cache profile parameter $cacheParams = array("driver" => "db", "dbprofile" => $cacheJdbName, "ttl" => $cacheExpiration); // Create the virtual cache profile jProfiles::createVirtualProfile('jcache', $cacheName, $cacheParams); } }
public static function clearLayerCache($repository, $project, $layer) { // Storage type $ser = lizmap::getServices(); $cacheStorageType = $ser->cacheStorageType; // Cache root directory if ($cacheStorageType != 'redis') { $cacheRootDirectory = $ser->cacheRootDirectory; if (!is_writable($cacheRootDirectory) or !is_dir($cacheRootDirectory)) { $cacheRootDirectory = sys_get_temp_dir(); } // Directory where cached files are stored for the project $cacheProjectDir = $cacheRootDirectory . '/' . $repository . '/' . $project . '/'; $results = array(); if (file_exists($cacheProjectDir)) { // Open the directory and walk through the filenames $handle = opendir($cacheProjectDir); while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { // Get directories and files corresponding to the layer if (preg_match('#(^|_)' . $layer . '($|_)#', $entry)) { $results[] = $cacheProjectDir . $entry; } } } closedir($handle); foreach ($results as $rem) { if (is_dir($rem)) { jFile::removeDir($rem); } else { unlink($rem); } } } } else { // FIXME: removing by layer is not supported for the moment. For the moment, we flush all layers of the project. $cacheName = 'lizmapCache_' . $repository . '_' . $project; self::declareRedisProfile($ser, $cacheName, $repository, $project); jCache::flush($cacheName); } jEvent::notify('lizmapProxyClearLayerCache', array('repository' => $repository, 'project' => $project, 'layer' => $layer)); }
/** * Send an email to the administrator * * @param objet $user jAuth user for the created user */ private function sendEmailToAdmin($user) { $services = lizmap::getServices(); if ($email = filter_var($services->adminContactEmail, FILTER_VALIDATE_EMAIL)) { $mail = new jMailer(); $mail->Subject = jLocale::get("view~user.email.admin.subject"); $mail->Body = jLocale::get("view~user.email.admin.body", array($user->login, $user->email)); $mail->AddAddress($email, 'Lizmap Notifications'); $mail->Send(); } }
/** * Empty a map service cache * @param string $repository Repository for which to remove all tile cache * @return Redirection to the index */ function removeLayerCache() { $repository = $this->param('repository'); $project = $this->param('project'); $layer = $this->param('layer'); // Get config utility $lrep = lizmap::getRepository($repository); $ser = lizmap::getServices(); $lproj = lizmap::getProject($repository . '~' . $project); $project = $lproj->getKey(); // Remove the cache for the layer $cacheRootDirectory = $ser->cacheRootDirectory; $cacheProjectDir = $cacheRootDirectory . '/' . $lrep->getKey() . '/' . $project . '/'; $handle = opendir($cacheProjectDir); $results = array(); // Open the directory and walk through the filenames while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { // Get directories and files corresponding to the layer if (preg_match('#^' . $layer . '_#', $entry) or $entry == $layer) { $results[] = $cacheProjectDir . $entry; } } } closedir($handle); // Remove layer files and folder cache if ($lrep && $lproj) { foreach ($results as $rem) { if (is_dir($rem)) { jFile::removeDir($rem); } else { unlink($rem); } } } jMessage::add(jLocale::get("admin~admin.cache.layer.removed", array($layer))); // Redirect to the index $rep = $this->getResponse("redirect"); $rep->action = "admin~config:index"; return $rep; }
/** * Get the jForm for a repository. * */ public static function constructRepositoryForm($rep, $form) { $services = lizmap::getServices(); $rootRepositories = $services->getRootRepositories(); $repositories = array(); foreach (lizmap::getRepositoryList() as $repo) { if ($rep && $rep->getKey() == $repo) { continue; } $repositories[] = lizmap::getRepository($repo); } // reconstruct form fields based on repositoryPropertyList $propertiesOptions = lizmap::getRepositoryPropertiesOptions(); foreach (lizmap::getRepositoryProperties() as $k) { $ctrl = null; if ($propertiesOptions[$k]['fieldType'] == 'checkbox') { $ctrl = new jFormsControlCheckbox($k); } else { if ($k == 'path' && $rootRepositories != '') { if ($rep == null || substr($rep->getPath(), 0, strlen($rootRepositories)) === $rootRepositories) { $ctrl = new jFormsControlMenulist($k); $dataSource = new jFormsStaticDatasource(); $data = array(); $data[''] = ''; if ($dh = opendir($rootRepositories)) { while (($file = readdir($dh)) !== false) { if ($file == '.' || $file == '..') { continue; } $filePath = $rootRepositories . $file . '/'; if (is_dir($filePath)) { $allreadyUsed = False; foreach ($repositories as $repo) { if ($repo->getPath() == $filePath) { $allreadyUsed = True; break; } } if (!$allreadyUsed) { $data[$filePath] = $file; } } } } $dataSource->data = $data; $ctrl->datasource = $dataSource; } else { $ctrl = new jFormsControlHidden($k); } } else { $ctrl = new jFormsControlInput($k); $ctrl->datatype = new jDatatypeString(); } } $ctrl->required = $propertiesOptions[$k]['required']; $ctrl->label = jLocale::get("admin~admin.form.admin_section.repository." . $k . ".label"); $ctrl->size = 100; $form->addControl($ctrl); } if ($rep) { foreach ($rep->getProperties() as $k) { $v = $rep->getData($k); if ($k == 'path' && $rootRepositories != '' && substr($rep->getPath(), 0, strlen($rootRepositories)) === $rootRepositories) { $v = $rep->getPath(); } $form->setData($k, $v); } } return $form; }
public function getDefaultDockable() { jClasses::inc('view~lizmapMapDockItem'); $dockable = array(); $bp = jApp::config()->urlengine['basePath']; // Get lizmap services $services = lizmap::getServices(); // only maps if ($services->onlyMaps) { $projectsTpl = new jTpl(); $dockable[] = new lizmapMapDockItem('home', jLocale::get('view~default.repository.list.title'), $projectsTpl->fetch('view~map_projects'), 0); } $switcherTpl = new jTpl(); $switcherTpl->assign(array('layerExport' => jAcl2::check('lizmap.tools.layer.export', $this->repository->getKey()))); $dockable[] = new lizmapMapDockItem('switcher', jLocale::get('view~map.switchermenu.title'), $switcherTpl->fetch('view~map_switcher'), 1); //$legendTpl = new jTpl(); //$dockable[] = new lizmapMapDockItem('legend', 'Légende', $switcherTpl->fetch('map_legend'), 2); $metadataTpl = new jTpl(); // Get the WMS information $wmsInfo = $this->getWMSInformation(); // WMS GetCapabilities Url $wmsGetCapabilitiesUrl = jAcl2::check('lizmap.tools.displayGetCapabilitiesLinks', $this->repository->getKey()); if ($wmsGetCapabilitiesUrl) { $wmsGetCapabilitiesUrl = $this->getData('wmsGetCapabilitiesUrl'); } $metadataTpl->assign(array_merge(array('repositoryLabel' => $this->getData('label'), 'repository' => $this->repository->getKey(), 'project' => $this->getKey(), 'wmsGetCapabilitiesUrl' => $wmsGetCapabilitiesUrl), $wmsInfo)); $dockable[] = new lizmapMapDockItem('metadata', jLocale::get('view~map.metadata.link.label'), $metadataTpl->fetch('view~map_metadata'), 2); if ($this->hasEditionLayers()) { $tpl = new jTpl(); $dockable[] = new lizmapMapDockItem('edition', jLocale::get('view~edition.navbar.title'), $tpl->fetch('view~map_edition'), 3, '', $bp . 'js/edition.js'); } return $dockable; }
protected function _prepareTpl() { $protocol = jApp::coord()->request->getProtocol(); $this->_tpl->assign('protocol', $protocol); $domain = jApp::coord()->request->getDomainName(); $this->_tpl->assign('domain', $domain); $this->_tpl->assign('auth_url_return', $this->param('auth_url_return')); $this->_tpl->assign('isConnected', jAuth::isConnected()); // Get lizmap services $services = lizmap::getServices(); if ($services->allowUserAccountRequests) { $this->_tpl->assign('allowUserAccountRequests', True); } jClasses::inc('lizmapMainViewItem'); $maps = array(); // Get repository data $repository = $this->param('repository'); $repositories = array(); if ($repository != null && jAcl2::check('lizmap.repositories.view', $repository)) { $repositories[] = $repository; } else { $repositories = lizmap::getRepositoryList(); } // Get excluded project $excludedProject = $this->param('excludedProject'); foreach ($repositories as $r) { if (jAcl2::check('lizmap.repositories.view', $r)) { $lrep = lizmap::getRepository($r); $mrep = new lizmapMainViewItem($r, $lrep->getData('label')); $lprojects = $lrep->getProjects(); // WMS GetCapabilities Url $wmsGetCapabilitiesUrl = jAcl2::check('lizmap.tools.displayGetCapabilitiesLinks', $lrep->getKey()); foreach ($lprojects as $p) { $pOptions = $p->getOptions(); if (property_exists($pOptions, 'hideProject') && $pOptions->hideProject == 'True') { continue; } if ($wmsGetCapabilitiesUrl) { $wmsGetCapabilitiesUrl = $p->getData('wmsGetCapabilitiesUrl'); } if ($lrep->getKey() . '~' . $p->getData('id') != $excludedProject) { $mrep->childItems[] = new lizmapMainViewItem($p->getData('id'), $p->getData('title'), $p->getData('abstract'), $p->getData('proj'), $p->getData('bbox'), jUrl::get('view~map:index', array("repository" => $p->getData('repository'), "project" => $p->getData('id'))), jUrl::get('view~media:illustration', array("repository" => $p->getData('repository'), "project" => $p->getData('id'))), 0, $r, 'map', $wmsGetCapabilitiesUrl); /*} else { $this->_tpl->assign('auth_url_return', jUrl::get('view~map:index', array( "repository"=>$lrep->getKey(), "project"=>$p->getData('id'), ) ) );*/ } } if (count($mrep->childItems) != 0) { usort($mrep->childItems, "mainViewItemSort"); $maps[$r] = $mrep; } } } $items = jEvent::notify('mainviewGetMaps')->getResponse(); foreach ($items as $item) { if ($item->parentId) { if ($item->parentId . '~' . $item->id == $excludedProject) { continue; } if (!isset($maps[$item->parentId])) { $maps[$item->parentId] = new lizmapMainViewItem($item->parentId, '', ''); } $replaced = false; foreach ($maps[$item->parentId]->childItems as $k => $i) { if ($i->id == $item->id) { $maps[$item->parentId]->childItems[$k] = $item; $replaced = true; } } if (!$replaced) { $maps[$item->parentId]->childItems[] = $item; usort($maps[$item->parentId]->childItems, "mainViewItemSort"); } } else { if (isset($maps[$item->id])) { $maps[$item->id]->copyFrom($item); } else { $maps[$item->id] = $item; } } } usort($maps, "mainViewItemSort"); foreach ($maps as $topitem) { usort($topitem->childItems, "mainViewItemSort"); } $this->_tpl->assign('mapitems', $maps); $this->_tpl->assign('onlyMaps', $this->param('onlyMaps', False)); }
/** * Save the data for one section. * @return Redirect to the index. */ function saveSection() { $repository = $this->param('repository'); $new = (bool) $this->param('new'); $ok = true; // Get services data $services = lizmap::getServices(); // Repository (first take the default one) $lrep = lizmap::getRepository($repository); // what to do if it's a new one! // Get the form $form = jForms::get('admin~config_section'); // token $token = $this->param('__JFORMS_TOKEN__'); if (!$token) { $ok = false; jMessage::add('missing form token'); } // If the form is not defined, redirection if (!$form) { $ok = false; } // Redirection in case of errors if (!$ok) { $rep = $this->getResponse("redirect"); $rep->action = "admin~config:index"; return $rep; } // Rebuild form fields /*foreach(lizmap::getRepositoryProperties() as $k){ if ( $propertiesOptions[$k]['fieldType'] == 'checkbox' ) { $ctrl = new jFormsControlCheckbox($k); } else { $ctrl = new jFormsControlInput($k); } $ctrl->required = $propertiesOptions[$k]['required']; $ctrl->label = jLocale::get("admin~admin.form.admin_section.repository.".$k.".label"); $datatype = new jDatatypeString(); $ctrl->datatype=$datatype; $form->addControl($ctrl); }*/ lizmap::constructRepositoryForm($lrep, $form); if ($lrep) { $form = $this->populateRepositoryRightsFormControl($form, $lrep->getKey(), false); } // Set form data from request data $form->initFromRequest(); // Check the form $ok = true; if (!$form->check()) { $ok = false; } if (!$new && !$lrep) { $form->setErrorOn('repository', jLocale::get("admin~admin.form.admin_section.message.repository.wrong")); $ok = false; } // Check paths if (in_array('path', lizmap::getRepositoryProperties())) { $npath = $form->getData('path'); if ($npath[0] != '/' and $npath[1] != ':') { $npath = jApp::varPath() . $npath; } if (!file_exists($npath) or !is_dir($npath)) { $form->setErrorOn('path', jLocale::get("admin~admin.form.admin_section.message.path.wrong")); $ok = false; } $rootRepositories = $services->getRootRepositories(); if ($rootRepositories != '') { if ($lrep && substr($lrep->getPath(), 0, strlen($rootRepositories)) !== $rootRepositories) { //Can't update path $form->setData('path', $lrep->getData('path')); } else { if ($lrep && substr($lrep->getPath(), 0, strlen($rootRepositories)) === $rootRepositories && substr(realpath($npath), 0, strlen($rootRepositories)) !== $rootRepositories) { $form->setErrorOn('path', jLocale::get("admin~admin.form.admin_section.message.path.not_authorized")); jLog::log('rootRepositories == ' . $rootRepositories . ', repository ' . $lrep->getKey() . ' path == ' . realpath($npath)); $ok = false; } else { if ($lrep == null && substr(realpath($npath), 0, strlen($rootRepositories)) !== $rootRepositories) { $form->setErrorOn('path', jLocale::get("admin~admin.form.admin_section.message.path.not_authorized")); jLog::log('rootRepositories == ' . $rootRepositories . ', new repository path == ' . realpath($npath)); $ok = false; } } } } } if (!$ok) { // Errors : redirection to the display action $rep = $this->getResponse('redirect'); $rep->action = 'admin~config:editSection'; $rep->params['repository'] = $repository; $rep->params['errors'] = "1"; foreach (jApp::coord()->request->params as $k => $v) { if (preg_match('#^' . $this->lizmapClientPrefix . '#', $k)) { $rep->params[$k] = $v; } } if ($new) { $form->setReadOnly('repository', false); } return $rep; } // Repository data $data = array(); foreach (lizmap::getRepositoryProperties() as $prop) { $data[$prop] = $form->getData($prop); // Check paths if ($prop == 'path') { # add a trailing / if needed if (!preg_match('#/$#', $data[$prop])) { $data[$prop] .= '/'; } } } // Save the data if ($new && !$lrep) { $lrep = lizmap::createRepository($repository, $data); } else { if ($lrep) { $modifySection = $lrep->update($data); } } jMessage::add(jLocale::get("admin~admin.form.admin_section.message.data.saved")); // group rights data $this->saveRepositoryRightsFromRequest($form, $repository); // Redirect to the validation page $rep = $this->getResponse("redirect"); $rep->params['repository'] = $repository; if ($new) { $rep->params['new'] = 1; } $rep->action = "admin~config:validateSection"; return $rep; }
/** * Displays map for ajax request. * * @param string $repository. Name of the repository. * @param string $project. Name of the project. * @return Html fragment with a list of projects. */ function map() { $rep = $this->getResponse('htmlfragment'); // Get the project $project = filter_var($this->param('project'), FILTER_SANITIZE_STRING); // Get repository data $repository = $this->param('repository'); // Get lizmapRepository class // if repository not found get the default $lrep = null; if (!$repository) { $lser = lizmap::getServices(); $lrep = lizmap::getRepository($lser->defaultRepository); } else { $lrep = lizmap::getRepository($repository); } if (!jAcl2::check('lizmap.repositories.view', $lrep->getKey())) { jMessage::add(jLocale::get('view~default.repository.access.denied'), 'error'); return $rep; } // We must redirect to default repository project list if no project given if (!$project) { jMessage::add('The parameter project is mandatory !', 'error'); return $rep; } // Get lizmapProject class $lproj = lizmap::getProject($lrep->getKey() . '~' . $project); if (!$lproj) { jMessage::add('The lizmapProject ' . strtoupper($project) . ' does not exist !', 'error'); return $rep; } $lizUrls = array("params" => array('repository' => $repository, 'project' => $project), "config" => jUrl::getFull('lizmap~service:getProjectConfig'), "wms" => jUrl::getFull('lizmap~service:index'), "media" => jUrl::getFull('view~media:getMedia'), "nominatim" => jUrl::getFull('lizmap~osm:nominatim'), "edition" => jUrl::getFull('lizmap~edition:getFeature'), "permalink" => jUrl::getFull('view~map:index')); // Get optionnal WMS public url list $lser = lizmap::getServices(); if ($lser->wmsPublicUrlList) { $publicUrlList = $lser->wmsPublicUrlList; function f($x) { return jUrl::getFull('lizmap~service:index', array(), 0, trim($x)); } $pul = array_map('f', explode(',', $publicUrlList)); $lizUrls['publicUrlList'] = $pul; } if (jAcl2::check('lizmap.admin.repositories.delete')) { $lizUrls['removeCache'] = jUrl::getFull('admin~config:removeLayerCache'); } $content = '<script type="text/javascript" src="' . jUrl::getFull('view~translate:index') . '"/>' . "\n"; $content .= '<script type="text/javascript">// <![CDATA[' . "\n"; $content .= "var lizUrls = " . json_encode($lizUrls) . ";\n"; $content .= 'var lizPosition = {"lon":null, "lat":null, "zoom":null};' . "\n"; $content .= "\$('#map').css('background-color','" . $lproj->getCanvasColor() . "');\n"; $content .= "// ]]></script>"; // Get the WMS information $wmsInfo = $lproj->getWMSInformation(); // Set page title from projet title if ($wmsInfo['WMSServiceTitle'] != '') { $rep->title = $wmsInfo['WMSServiceTitle']; } else { $rep->title = $repository . ' - ' . $project; } $assign = array_merge(array('repositoryLabel' => $lrep->getData('label'), 'repository' => $lrep->getKey(), 'project' => $project), $wmsInfo); $tpl = new jTpl(); $tpl->assign($assign); $content .= $tpl->fetch('view~map'); $rep->addContent($content); return $rep; }